akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair
#define X first
#define Y second

const int MAXN = 25000;

int t[4*MAXN], p[MAXN];
int a[MAXN], b[MAXN];
pair<int,int> ans[MAXN];

void update(int v,int tl,int tr, int pos)
{
    if (tl == tr)
    {
        t[v] = 1;
    }
    else
    {
        int tm = (tl + tr) / 2;
        if (tm >= pos)
        {
            update(v*2,tl,tm,pos);
        }
        else
        {
            update(v*2+1,tm+1,tr,pos);
        }
        t[v] = t[v*2] + t[v*2+1];
    }
}


int query(int v, int tl, int tr, int l, int r)
{
    if (tl == l && tr == r)
    {
        return t[v];
    }
    else
    {
        int tm = (tl + tr) / 2;
        if (tm >= r) return query(v*2, tl, tm, l, r);
        if (tm < l) return query(v*2+1, tm+1, tr, l, r);
        return query(v*2,tl,tm,l,tm) + query(v*2+1,tm+1,tr,tm+1,r);
    }
}



int main()
{
    ios_base::sync_with_stdio(false);

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    int n;
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> p[i];
    }

    for (int i=1;i<=n;i++)
    {
        a[i] = i * 25000;
        b[i] = (n - i + 1) * 25000;
    }

    for (int i=1;i<=n;i++)
    {
        ans[p[i]].X = a[p[i]] + query(1, 1, n, 1, p[i]);
        ans[p[i]].Y = b[p[i]] + query(1, 1, n, p[i], n);
        update(1,1,n,p[i]);
    }

    for (int i=1;i<=n;i++)
    {
        if (i > 1) cout << " ";
        cout << ans[i].X;
    }
    cout << endl;

    for (int i=1;i<=n;i++)
    {
        if (i > 1) cout << " ";
        cout << ans[i].Y;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 1280
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
typedef long long int ll;
using namespace std;
#define maxN 1000005
#define mod 1000000007

//ll all[maxN]= {};
int n;
string s;

void solve() {
	ll ans=0;
	ll r,g,b;
	r=g=b=0;
	for(int i=0; i<s.length(); i++) {
		if(s[i]=='R'){
			r++;
		}else if (s[i]=='G'){
			g++;
		}else if(s[i]=='B'){
			b++;
		}
	}
	ans=r*g*b;
	for(int i=0;i<s.length();i++){
		for(int j=i+1;j<s.length();j++){
			int temp =2*j-i;
			if(temp<s.length()){
				if(s[i]!=s[j]&&s[i]!=s[temp]&&s[j]!=s[temp]){
					ans--;
				}
			}
		}
	}
	cout<<ans<<endl;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>s;
	solve();
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>

using namespace std;

const int maxN = 1000009;
int N;
char sir[maxN];
pair < int, int > segm[maxN];

/*pair < int, int > shift (pair < int, int > a, int b)
{
    return {a.first + b, b.first + b};
}*/

pair < int, int > uni (pair < int, int > a, pair < int, int > b)
{
    return {max (a.first, b.first), min (a.second, b.second)};
}

bool ok (int D)
{
    for (int par = 0; par < 2; par ++)
    {
        ///L = 2 * K + par for some K
        ///I'll have for all i, where s[i] = number of 1 in the prefix of i
        ///L <= i - 2 * s[i] <= L + D
        ///2K + par <= i - 2 * s[i] <=> 2 * s[i] <= i - 2K - par <=> s[i] <= (i - par) / 2 - K
        ///i - 2 * s[i] <= 2 * K + par + D <=> 2 * s[i] >= i - 2 * K - par - D <=> s[i] >= (i - par - D) / 2 - K
        int fixedS = 0, nr = 0;
        segm[0] = {-4 * N, 4 * N};
        for (int i=0; i<=N; i++)
        {
            int l, r = ((i == 0 && par == 1) ? -1 : (i - par) / 2);
            if ((i - par - D) % 2 == 0)
                l = (i - par - D) / 2;
            else
                l = (i - par - D + 1) / 2;
//            printf ("[%d, %d]\n", l, r);
            if (sir[i] == '?')
            {
                nr ++;
                segm[nr] = {l - fixedS, r - fixedS};
            }
            else
            {
                if (i > 0 && sir[i] == '1')
                    fixedS ++;
                segm[nr] = uni (segm[nr], {l - fixedS, r - fixedS});
            }
        }
        ///considering s2[i] = the number of 1s in the first i question marks,
        ///we have s2[i] is in segm[i] - K
        for (int i=1; i<=nr; i++)
            segm[i].first = max (segm[i].first, segm[i - 1].first),
            segm[i].second = min (segm[i].second, segm[i - 1].second + 1);
        bool isOk = 1;
        for (int i=0; i<=nr; i++)
            if (segm[i].first > segm[i].second)
                isOk = 0;
        if (isOk)
            return 1;
    }
    return 0;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

//for (int i=-10; i<=10; i++)
  //  printf ("%d -> %d, %d\n", i, i / 2, i - 2 * (i / 2));

scanf ("%s", sir + 1), N = strlen (sir + 1);
/*printf ("%d\n", ok (1));
return 0;*/
int p = 0, u = N, mij, ras;
while (p <= u)
{
    mij = (p + u) >> 1;
    if (ok (mij))
        ras = mij, u = mij - 1;
    else
        p = mij + 1;
}
printf ("%d\n", ras);
return 0;
}


Measured memory_bytes: 12604
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int, int>p;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
struct LazySegmentTree {
private:
	int n;
	vector<int> node, lazy;
	vector<bool> lazyFlag;

public:
	LazySegmentTree(vector<int> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, INT_MAX);
		lazyFlag.resize(2 * n - 1, false);

		for (int i = 0; i<sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}

	void lazyEvaluate(int k, int l, int r) {
		if (lazyFlag[k]) {
			node[k] = lazy[k];
			if (r - l > 1) {
				lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
				lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
			}
			lazyFlag[k] = false;
		}
	}

	void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = x;
			lazyFlag[k] = true;
			lazyEvaluate(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	int find(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return INT_MAX;
		if (a <= l && r <= b) return node[k];
		int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};
long long mod = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(16);
	long long w, h, x, y;
	cin >> w >> h >> x >> y;
	int cnt;
	if ((w % 2 == 0) && (h % 2 == 0) && w / 2 == x&&h / 2 == y)cnt = 1;
	else cnt = 0;
	cout << (double)w*h / 2 <<" "<< cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

//const int MAX=110;
//const char key[8]="keyence";
string key="keyence";
string S;

int main(){
     cin >> S;
     int size=S.size();
     int i,j;
     for (i=0; i<size; ++i){
             if(key[i]!=S[i]) break;
     }
     for (j=0; j<size; ++j){
           if(key[6-j]!=S[size-1-j]) break;
     }
     if(i+j>=7) cout << "YES" << endl;
     else cout << "NO" << endl;
     return 0;
}



Measured memory_bytes: 256
# ABC116C - Grand Garden
n = int(input())
lst = list(map(int, input().rstrip().split())) + [0]
ans = 0
cur = 0
for n, m in zip(lst, lst[1:]):
    if cur < n:
        cur = n
    if cur > m:
        ans += cur - m
        cur = m
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;

int main() {
	string a, b;
  cin >> a >> b;
  for (int i = 0; i < a.length(); ++i){
  	if (a[i] !=b[i]){
    	cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 
typedef struct{
  string first;
  int second;
  int id;
}PSI;

bool comp(PSI& l, PSI& r){
  if(l.first == r.first) return l.second > r.second;
  return l.first < r.first;
}

int main(void){
  int N;cin >> N;
  vector<PSI> v(N);
  int i;REP(i,N){
    cin >> v[i].first >> v[i].second;
    v[i].id = i+1;
  }
  sort(v.begin(),v.end(),comp);
  REP(i,N) cout << v[i].id << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	void swap(int *,int *);
  	int x, y, z;
  
  	scanf("%d %d %d",&x,&y,&z);
  	
  	swap(&x, &y);
  	swap(&x, &z);
  
  	printf("%d %d %d\n",x, y ,z);
  
  	return 0;
}

void swap(int *a,int *b)
{
	int temp;
  	temp = *a;
  	*a = *b;
  	*b = temp;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int n;
    cin >> n;
    int data[n - 1];
    int ans = 0;
    for (int i = 0; i < n - 1; i++)
    {
        cin >> data[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (i == 0)
            ans += data[i];
        else if (i == n - 1)
            ans += data[i - 1];
        else
            ans += min(data[i], data[i - 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static IEnumerable<string> Solve(int A, int B)
        {
            char[][] rows = new char[100][];
            for (int i =  0; i <  50; ++i) { rows[i] = Enumerable.Repeat('#', 100).ToArray(); }
            for (int i = 50; i < 100; ++i) { rows[i] = Enumerable.Repeat('.', 100).ToArray(); }
            for (int i = 0; i < A - 1; ++i)
            {
                int x = (i % 50) * 2;
                int y = (i / 50) * 2;
                rows[y][x] = '.';
            }
            for (int i = 0; i < B - 1; ++i)
            {
                int x = (i % 50) * 2;
                int y = (i / 50) * 2;
                rows[99 - y][x] = '#';
            }
            return Array.ConvertAll(rows, row => new string(row));
        }
        static void Main(string[] args)
        {
            int[] v = ReadInts();
            Console.WriteLine("100 100");
            foreach (string s in Solve(v[0], v[1])) { Console.WriteLine(s); }
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=long long;

int main() {
  int N,K; cin >>N >>K;
  cout <<ceil((double)(N-1)/(K-1)) <<endl;
  return 0;
}


Measured memory_bytes: 3768
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int diff=b-a;
    int fact=diff*(diff+1)/2-b;
    cout << fact << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> flags;
typedef class unionfindtree{
private:
	std::vector<int> par,rank;
public:
	void init(int n){
		for(int i=0;i<n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		if(find(x)==find(y)) return true;
		else return false;
	}
	void uni(int x,int y){
		x=find(x);
		y=find(y);
		if(rank[x]>=rank[y]){
			par[y]=x;
			rank[x]=rank[x]+1;
		}else if(rank[x]<rank[y]){
			par[x]=y;
			rank[y]=rank[y]+1;
		}
	}
}UFT;
struct input_data{
	int id1;
	int id2;
	bool operator<(const input_data& rhs)const{
		if(min(id1,id2)<min(rhs.id1,rhs.id2)) return true;
		if(min(id1,id2)==min(rhs.id1,rhs.id2) && max(id1,id2)<max(rhs.id1,rhs.id2)) return true;
		return false;
	}
};
vector<input_data> d;
UFT uft;
void input(int m){
  for(int i=0;i<m;i++){
    int id1,id2;
    cin>>id1>>id2;
  	input_data ind={id1,id2};
  	d.push_back(ind);
  }
	stable_sort(d.begin(),d.end());
}

void reuni(int n){
	for(input_data ind:d){
		if(!uft.same(ind.id1,ind.id2)){
			uft.uni(ind.id1,ind.id2);
		}
	}
}

void cc(int q){
  for(int i=0;i<q;i++){
	  int id1,id2;
  		cin>>id1>>id2;
  		if(uft.same(id1,id2)) flags.push_back(1);
  	else flags.push_back(0);
  }
}
int main(){
  int n,m;
  cin>>n>>m;
  input(m);
	uft.init(n);
	reuni(n);
	int q;
	cin>>q;
	cc(q);
	for(int f:flags){
		if(f) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}



Measured memory_bytes: 4900
#include <bits/stdc++.h>
//#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;
typedef pair<ll,int> Pli;

//-----------------------------------------------------------------------------

ll n,k,ans;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>n>>k;
	if(k==0) {
		cout<<n*n<<endl;
		return 0;
	}
	FOR(i,k+1,n+1) {
		ll a=(i-1)-(k-1);
		ll tmp=n/i;
		ll amari=n%i;
		amari-=(k-1);
		if(amari>=0) ans+=amari;
		ans+=a*tmp;
		//cout<<a<<' '<<tmp<<' '<<amari<<endl;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int n;
	unsigned long long a, b;
	cin >> n >> a >> b;
	int from;
	cin >> from;
    unsigned long long ans = 0;
	for (int i = 1; i < n; i++) {
		int to;
		cin >> to;
		if (a * (to - from) < b) {
			ans += a * (to - from);
		}
		else {
			ans += b;
		}
		from = to;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int result;

int main(){
  int i,n,data[20];
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++)scanf("%d",&data[i]);
    result=1000000;
    printf("%d\n",search(n,data,0,0,0));
  }
  return 0;
}

int search(int n,int data[],int i,int a,int b){

  if(i<n){
    search(n,data,i+1,a+data[i],b);
    search(n,data,i+1,a,b+data[i]);
  }
  else if(abs(a-b)<result)result=abs(a-b);

  return result;
}

Measured memory_bytes: 596
//#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
# define rep(i, n) for (long long i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  long long n;
  cin >> n;

  vector<long long> a(n);
  vector<bool> b(n);
  rep(i, n) cin >> a[i];

  long long sum = 0;
  rep (i, n) sum += a[i];

  long long ans = 1001001001001001;
  long long suma = 0;
  long long sumb;

  rep (i, n-1) {
    suma += a[i];
    sumb = (sum - suma);
    ans = min(abs(suma-sumb), ans);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
def count_take(val)
    current = 1
    count = 0
    while val >= current
        val -=current
        current += 1
        count += 1
    end
    count
end

require 'prime'
n = gets.to_i
if n == 1
    puts 0
    exit
end

puts Prime.prime_division(n).map{|it| it[1]}.map{|it|
    count_take(it)
}.inject(:+)



Measured memory_bytes: 14484
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007


int main(){
    ll N, H, W; cin >> N >> H >> W;
    ll ans = 0;
    while(N--){
        int a, b; cin >> a >> b;
        if(a>=H && b>=W) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	for {
		var m, f, r int
		var score string
		fmt.Scan(&m, &f, &r)
		if m == -1 && f == -1 && r == -1 {
			break
		}
		if m == -1 || f == -1 || m+f < 30 {
			score = "F"
		} else if m+f >= 80 {
			score = "A"
		} else if m+f >= 65 {
			score = "B"
		} else if m+f >= 50 || r >= 50 {
			score = "C"
		} else if m+f >= 30 {
			score = "D"
		}
		fmt.Println(score)
	}
}



Measured memory_bytes: 1120
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	int N;
	string S;
	cin >> N >> S;

	if (N % 2 == 1)
	{
		cout << "No" << endl;
		return 0;
	}

	int half = N / 2;
	for (int i = 0; i < half; i++)
	{
		if (S[i] != S[half + i])
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
import bisect
import heapq
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M=mi()
    
    L,R,_L = [],[],[]
    for i in range(M):
        a,b=mi()
        L.append((a,i))
        R.append((b,i))
        _L.append(a)

    L.sort()
    R.sort()
    _L.sort()

    heapq.heapify(L)    
    heapq.heapify(R)

    # print(L,R)
    l_e = 0
    ans = 0
    seen = set()
    while R:
        # print("R",R)
        r,j = heapq.heappop(R)
        if j in seen: continue

        li = bisect.bisect_left(_L,r)
        # print("A",_L[li])
        if li > 0:
            li -= 1
        # if li < len(_L) and _L[li] == r:
        #     li -= 1
        # elif not li < len(_L):
        #     li -= 1

        # print(r,"li",li,_L[li],l_e)
        for i in range(l_e,li+1):
            seen.add(L[i][1])

        l_e = li
        ans += 1

    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 107312
#include<bits/stdc++.h>

using namespace std;

int main()
{
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int cnt=0;
  for(int a=0;a<=A;a++){
    int x_a=X-500*a;
    if(x_a<0) continue;
    for(int b=0;b<=B;b++){
      int x_b=x_a-100*b;
      if(x_b<0) continue;
      if(x_b/50<=C) cnt++;
    }
  }
  
  cout<<cnt;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long n,k,a,i,m=1000000007;
main(){cin>>n>>k;for(i=k;n+1>=i;i++)a=(a+((n*(n+1)-(n-i+1)*(n-i)-i*(i-1))/2+1))%m;cout<<a<<endl;}

Measured memory_bytes: 3584
#!/usr/bin/env python3
import sys


def solve(n: int, a: "List[int]"):
    mx = max(a)
    a.sort()
    l = -1
    r = n
    while r - l > 1:
        m = (r + l) // 2
        if a[m] > (mx + 1) // 2:
            r = m
        else:
            l = m
    target = (mx + 1) // 2
    if r == n - 1 or abs(target - a[l]) < abs(target - a[r]):
        print(mx, a[l])
    else:
        print(mx, a[r])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15556
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli p, a;
    cin >> a >> p;
    p += a * 3;
    out(p / 2);
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    multiset<int> st;
    int cnt = 1;

    rep(i,n) {
        int c = a[i];
        if (st.empty()) {
            st.insert(c);
        }
        else {
            auto itr = st.lower_bound(c);
            if (itr == st.begin()) {
                st.insert(c);
            }
            else {
                st.erase(prev(itr));
                st.insert(c);
            }
        }
    }

    cout << st.size() << '\n';
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
 
using namespace std;
 
using i64 = long long;
#define forn(a, e) for (i64 a = 0; a < (i64)(e); a++)
#define forr(a, s, e) for (i64 a = s; a < (i64)(e); a++)
#define fore(e, a) for (auto& e : a)
 
#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif
 
using iip = pair<int, int>;
using llp = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;
 
template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }
 
template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }
 
template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
template<typename T, size_t N>
istream& operator>>(istream& is, array<T, N>& c) { for (auto& e : c) is >> e; return is; }
 
template<typename ...T>
istream& read(T&... args) { return (cin >> ... >> args); }
 
static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }
 
constexpr int INF = 1e9;
// constexpr int MXB = 4;
constexpr int MXB = 9;
using bin = bitset<MXB>;
constexpr i64 M = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    rande.seed(chrono::steady_clock::now().time_since_epoch().count());

    i64 n;
    while (read(n)) {
        i64 ans = INF;
        for (i64 i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                i64 l1 = to_string(i).size();
                i64 l2 = to_string(n / i).size();
                uin(ans, max(l1, l2));
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3764
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
long long mod = (long long)1e9+7;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

int main(){
  long long N;
  int a, b;
  scanf("%lld",&N);
  scanf("%d",&a);
  scanf("%d",&b);

  long long ans = modpow(2, N, mod);
  //printf("ans=%lld\n", ans);
  long long minus1 = 1, minus2 = 1;
  for (int i=0; i<a; i++){
    minus1 *= (N-i);
    minus1 %= mod;
  }
  for (int i=1; i<=a; i++){
    minus1 *= modinv(i, mod);
    minus1 %= mod;
  }
  for (int i=0; i<b; i++){
    minus2 *= (N-i);
    minus2 %= mod;
  }
  for (int i=1; i<=b; i++){
    minus2 *= modinv(i, mod);
    minus2 %= mod;
  }
  //printf("minus1=%lld\n", minus1);
  //printf("minus2=%lld\n", minus2);
  ans -= minus1;
  ans -= minus2;
  ans -= 1;
  while(ans<0){
    ans += mod;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

void solve(int n,int m,int s){
    int dp[50][3010]={0};
    
    dp[0][0]=1;
    
    for(int i=1;i<=m;i++){
        for(int j=n*n-1;j>=0;j--){
            for(int k=0;k<=s-i;k++){
                dp[j+1][k+i]=(dp[j+1][k+i]+dp[j][k])%100000;
            }
        }
    }
    
    printf("%d\n",dp[n*n][s]%100000);
    
    return;
}


int main(){
    int n,m,s;
    
    while(1){
        scanf("%d%d%d",&n,&m,&s);
        if(n+m+s==0) break;
        solve(n,m,s);
    }
    
    return 0;
}

Measured memory_bytes: 1780
//Hello Wolrd
//There is Special Pig Jiong in the world.
#include<cstdio>
#include<cstring> 
#include<cstdlib> 
#include<algorithm>
#include<bitset> 
using namespace std;
#define gc getchar
#define pc putchar
inline int read(){int x=0,f=1;char c=gc();for(;c<'0'||c>'9';c=gc())if(c=='-')f=-1;for(;c>='0'&&c<='9';c=gc())x=x*10+c-48;return x*f;}
inline void write(int x){if(x < 0) putchar('-'),x = -x;if (x>=10) write(x / 10);putchar((x % 10)+'0');}
inline void writeln(int x){write(x);puts("");}
const int oo = 0x3f3f3f3f;const int inf = oo;
#define mem(x,v) memset(x,v,sizeof(x))
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,a,b) for(register int i=(a);i<(b);++i)
#define file(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define N 500005
int t[N],sx,sy,tx,ty;
int main(){
	int n = read();
	sx = 0,sy = 0;
	t[0]=0;
	for (int i=1;i<=n;i++){
		t[i] = read();tx = read(),ty = read();
		int Min = abs(sx-tx) + abs(sy-ty);
		if(Min>t[i]-t[i-1] || ((t[i]-t[i-1]-Min)&1)){
			puts("No");
			return 0;
		}
		sx = tx;sy = ty;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;

    ll prev_a, prev_b;
    cin >> prev_a >> prev_b;
    ll ans = prev_a + prev_b;
    rep(i, N - 1) {
        long double a, b;
        cin >> a >> b;
        ll m = max(ceil(prev_a / a), ceil(prev_b / b));
        a *= m, b *= m;

        ans = a + b;
        prev_a = a, prev_b = b;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a[3],i;
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    cout<<a[2]*10+a[1]+a[0];
    return 0;
}


Measured memory_bytes: 256
from bisect import *

n = int(input())
l = sorted(list(map(int, input().split())))

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        lower = max(j+1, bisect_right(l, b-a))
        upper = bisect_left(l, a+b)
        cnt += upper-lower

print(cnt)

Measured memory_bytes: 48912
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<queue>
#include<functional>
using namespace std;

const int MAXN = 100100;
int a[MAXN];

int main() {
	string s;
	cin >> s;
	int r = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'p') {
			--r;
		}
	}
	cout << s.length() / 2 + r << endl;
	return 0;
}



Measured memory_bytes: 512
// algo.cpp: 定义应用程序的入口点。
//
#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;
struct UnionFind {
    vector<int> par, sz;
    int n_tree;

    explicit UnionFind(int n) : par(n), sz(n, 1), n_tree(n) { //0-indexed
        iota(par.begin(), par.end(), 0);
    }

    int n_cluster() const {
        return n_tree;
    }

    int size(int x) {
        return sz[root(x)];
    }

    int root(int x) {
        return x == par[x] ? x : par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x), ry = root(y);
        if (rx != ry) {
            par[rx] = ry;
            --n_tree;
            sz[ry] += sz[rx];
            return true;
        }
        return false;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool is_root(int x) const {
        return par[x] == x;
    }
};
int gcd(int x, int y) {
    return y == 0 ? x : gcd(y, x % y);
}
int main() {
#ifdef LOCAL
    // 如何使用相对路径？
    ifstream in("in.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int> dp(n);
    dp[0] = a[0] == 1;
    for (int i = 1; i < n; ++i) {
        if (dp[i - 1] == a[i] - 1) dp[i] = dp[i - 1] + 1;
        else dp[i] = dp[i - 1];
    }
    cout << (dp.back() == 0 ? -1 : n - dp.back()) << endl;
        
#if defined LOCAL
    cout << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); i++)
using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    int x=0;
    rep(i,4){
        if(s[i]=='+'){
            x++;
        }else if(s[i]=='-'){
            x--;
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#include <vector>
#include <queue>
using namespace std;

int main(){
    int A, B, C;
    int X, Y;
    cin >> A >> B >> C >> X >> Y;

    if( A+B <= 2*C ){
        cout << A*X + B*Y << endl;
        return 0;
    }

    int min_c = min({X, Y}) * 2;
    int max_c = max({X, Y}) * 2;

    long long ans = A*X + B*Y;
    for(int c_count=min_c; c_count<max_c+1; c_count++){
        long long price = A*max({X-c_count/2,0}) + B*max({Y-c_count/2,0}) + c_count*C;
        if(ans > price){
            ans = price;
        }
    }

    cout << ans << endl;
    return 0;

}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int d;
vector<int> c(26), last(26, -1);
vector<vector<int>> s;

void input() {
    cin >> d;
    s = vector<vector<int>>(d, vector<int>(26));

    for (int& i : c) cin >> i;
    for (auto& v : s)
        for (int& i : v) cin >> i;
}

int f(int contest, int day) {
    int k = 0;
    for (int i = 0; i < 26; ++i) {
        if (i == contest) k += s[day][i];
        k -= c[i] * (day - last[i]);
    }
    return k;
}

int main() {
    input();
    int sum    = 0;
    int margin = 50;
    vector<int> p(26);
    for (int i = 0; i < 26; ++i) p[i] = i;
    sort(p.begin(), p.end(), [&](int a, int b) { return c[a] > c[b]; });
    for (int day = 0; day < d; ++day) {
        int mf = f(p[0], day) + c[p[0]] * (day - last[p[0]]), mi = p[0];
        if (day - last[p[0]] <= margin)
            for (int i = 1; i < 26; ++i) {
                int fi = f(p[i], day) + c[p[i]] * (day - last[p[i]]);
                if (day - last[p[i]] > margin) {
                    mi = p[i];
                    break;
                }
                if (mf < fi) mf = fi, mi = p[i];
            }
        cout << mi + 1 << endl;
        last[mi] = day;
    }
}


Measured memory_bytes: 3660
#include <iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;

    if ((a == 1 && b == 2) || (a == 2 && b == 1)) {
        cout << "3" << endl;
    }  else if((a == 2 && b == 3) || (a == 3 && b == 2)) {
        cout << "1" << endl;
    }else{
        cout << "2" << endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9+5;
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    int n,W;
    cin>>n>>W;
    vector<int> v(n);
    vector<int> w(n);
    for(int i = 0; i < n; i++) cin>>w[i]>>v[i];
    int dp[n+1][W+1];
    memset(dp,0,sizeof(dp));
    for(int i = 0; i <= n; i++) dp[i][0] = 0;
    for(int j = 0; j <= W; j++) dp[0][j] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= W; j++){
            if(w[i-1] <= j){
                dp[i][j] = max(dp[i-1][j], v[i-1]+dp[i-1][j-w[i-1]]);
            }
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][W];

}

Measured memory_bytes: 79232
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    long[] X1=new long[N];
	    long[] X2=new long[N];

	    for(int i=0; i<N;i++) {
	    	X1[i]=gl();
	    	X2[i]=X1[i];
	    }

	    Arrays.sort(X2);

	    long a1=X2[N/2 - 1];
	    long a2=X2[N/2];
	    for(int i=0; i<N;i++) {
	    	int index = Arrays.binarySearch(X2, X1[i]);
            if(index<N/2) {
            	System.out.println(a2);
            } else {
            	System.out.println(a1);
            }
	    }
	    //System.out.print(sum);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 63828
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Mirshodjon Mirjonov
 */

#include<bits/stdc++.h>

using namespace std;

//int mpow(int base, int exp);
//void ipgraph(int n, int m);
//void dfs(int u, int par);

//=======================

//vi g[N];
//int a[N];

class BJudgeStatusSummaryEditorial {
public:
	void solve(std::istream& in, std::ostream& out) {
        int t;
        in >> t;
        int a = 0,b = 0,c = 0,d = 0;
        while(t--) {
            string s;
            in >> s;
            if(s == "AC") a++;
            else if(s == "WA") b++;
            else if(s == "TLE") c++;
            else d++;
        }
        out << "AC x " << a << endl;
        out << "WA x " << b << endl;
        out << "TLE x " << c << endl;
        out << "RE x " << d << endl;
	}
};
/*
 ******* Advanced Contests *******
int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
        if (exp & 1) result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}
*/

int main() {
	BJudgeStatusSummaryEditorial solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#define INF 10000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int M[100][100];

void dijkstra(int n) {
	int i, u, minv, d[100], color[100];

	for (i = 0; i < n; i++) {
		d[i] = INF;
		color[i] = WHITE;
	}
	d[0] = 0;
	while (1) {
		minv = INF;
		u = -1;
		for (i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1)break;
		color[u] = BLACK;
		for (i = 0; i < n; i++) {
			if (color[i] != BLACK && M[u][i] != INF) {
				if (d[i] > d[u] + M[u][i]) {
					d[i] = d[u] + M[u][i];
					color[i] = GRAY;
				}
			}
		}
	}
	for (i = 0; i < n; i++) {
		printf("%d ", i);
		if (d[i] == INF) {
			printf("%d\n", -1);
		}
		else {
			printf("%d\n", d[i]);
		}
	}
}

int main() {
	int n, i, j, u, k, c, v;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) M[i][j] = INF;
	}

	for (i = 0; i < n; i++) {
		scanf("%d %d", &u, &k);
		for (j = 0; j < k; j++) {
			scanf("%d %d", &v, &c);
			M[u][v] = c;
		}
	}
	dijkstra(n);
}


Measured memory_bytes: 2052
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  
  for(int i = 1; i < 10; i++){
    if(!(n % i) && (n / i < 10)){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func bsort(a []byte) []byte {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := 0; j < n-1-i; j++ {
			if a[j+1] < a[j] {
				a[j+1], a[j] = a[j], a[j+1]
			}
		}
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)
	set := make(map[string]int)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		sc.Scan()
		t := []byte(sc.Text())
		set[string(bsort(t))]++
	}
	// fmt.Println("n", n, "set", set)
	ans := 0
	for _, v := range set {
		if v > 1 {
			ans += (v * (v - 1)) / 2 // nC2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8576
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

ll n, m, q;
Vec a, b, c, d, x;

ll dfs(ll f){
	ll res = 0;
	if(x.size() == n){
		rep(i, q){
			if(x[b[i]] - x[a[i]] == c[i]) res += d[i];
		}
		return res;
	}

	REPN(i, f, m){
		x.pb(i);
		chmax(res, dfs(i));
		x.pop_back();
	}
	return res;
}

int main(void){
	cin >> n >> m >> q;
	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
	rep(i, q) a[i]--, b[i]--;

	Vec x(n, 1);
	ll ans = dfs(1);
	co(ans);

	return 0;
}


Measured memory_bytes: 3636
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	string ans = "NO";
	rep(i, 10000) {
		if (a*i % b == c) {
			ans = "YES";
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()

    lim = 10 ** 5

    ans = 0
    for i in range(max(1, k + 1), n + 1):
        tmp1 = (i - k) * (n // i)
        tmp2 = max(n % i - max(k - 1, 0), 0) if n % i else 0
        ans += tmp1 + tmp2
        # print(i, tmp1, tmp2, ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 64620
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class Dijkstra{
	using Point = pair<ll,ll>;
	vector<ll> dist;
public:
	void CalcShortestPath(int start,ConnectNodeInfo& connect){
		dist.resize(connect.size(),1LL<<60);
		fill(ALL(dist),1LL<<60);
		dist[start] = 0;

		priority_queue<Point,vector<Point>,greater<Point>> Q;
		Q.emplace(0,start);
		while(!Q.empty()){
			auto p = Q.top();
			Q.pop();
			int v = p.second;
			if(dist[v]<p.first){
				continue;
			}
			for(auto e:connect[v]){
				if(dist[e.first]>dist[v]+e.second){
					dist[e.first] = dist[v]+e.second;
					Q.emplace(dist[e.first],e.first);
				}
			}
		}
	}
	ll GetDistance(int i){
		return dist[i];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(true){
		int N=in(),M=in();
		if(!N && !M) break;

		ConnectNodeInfo cost_connect(M),time_connect(M);
		REP(i,N){
			int u=in()-1,v=in()-1,c=in(),t=in();
			cost_connect.AddNonDirectionalConnection(u,v,c);
			time_connect.AddNonDirectionalConnection(u,v,t);
		}
		int Q=in();
		Dijkstra DIJ;
		LOOP(Q){
			int s=in()-1,g=in()-1,r=in();
			if(!r){
				DIJ.CalcShortestPath(s,cost_connect);
				out(DIJ.GetDistance(g));
			}
			else{
				DIJ.CalcShortestPath(s,time_connect);
				out(DIJ.GetDistance(g));
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3340
#include <bits/stdc++.h>
using namespace std;

int main() {
  int H,W;
  cin >> H >> W;
  
  vector<vector<char>> data(H+2,vector<char>(W+2,'#'));
  
 
 vector<vector<char>> data1(H,vector<char>(W));
   for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> data1.at(i).at(j);
    }
  }
   
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      data.at(i+1).at(j+1) = data1.at(i).at(j);
    }
  }
  for(int i = 0; i < H+2; i++){
    for(int j = 0; j < W+2; j++){
      cout << data.at(i).at(j);
      if(j == W+1){
        cout << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, i;
  cin >> n >> i;
  cout << n-i+1 << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<iostream>

using namespace std;

//void sort(char a[], int x,int y)
//{
//	int i, j;
//	int R = y, L = x + 1, m = x;
//	char t;
//	if (x == y)return;
//	while (L < R)
//	{
//		while (a[L] <= a[m] && L < R)
//			L++;
//		while (a[R] >= a[m] && L < R)
//			R--;
//		if (L == R) { t = a[m]; a[m] = a[L]; a[L] = t;
//
//		}
//	}
//}
int main()
{
	int a=0, num=0;
	char d[10] = { 0 };
	cin >> d;
	while (d[a])
	{
		if (d[a] == '1')num++;
		a++;
	}
	cout << num << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504