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

using namespace std;

#define INP "solve"
#define OUT "solve"

const int QQ = 3e5 + 10;
const int maxN = 2e5;
const int maxM = 3e5 + 10;
const int oo = 2e9;
const int module = 1e9 + 7;
const long double du = 1e-9;

void doc() {
    freopen(INP ".inp","r",stdin);
    freopen(OUT ".out","w",stdout);
}

int IT[maxN * 4];
void up(int i, int L, int R, int u, int val) {
    if (L > u || R < u) return;
    if (L == R) {
        IT[i] = val;
        return;
    }
    int mid = (L + R) >> 1;
    up(i << 1, L, mid, u, val);
    up(i << 1 | 1, mid + 1, R, u, val);
    IT[i] = max(IT[i << 1], IT[i << 1 | 1]);
}
int Get(int i, int L, int R, int u, int v) {
    if (L > v || R < u) return 0;
    if (L >= u && R <= v) return IT[i];
    int mid = (L + R) >> 1;
    int Left = Get(i << 1, L, mid, u, v);
    int Right = Get(i << 1 | 1, mid + 1, R, u, v);
    return max(Left, Right);
}
int n;
int Next(int x, int L, int R) {
    int Res = L;
    int tmp = L;
    while (L <= R) {
        int mid = (L + R) >> 1;
        if (Get(1, 1, n, tmp + 1, mid) < x) {
            Res = mid;
            L = mid + 1;
        }
        else R = mid - 1;
    }
    return Res;
}
int Prev(int x, int L, int R) {
    int Res = R;
    int tmp = R;
    while (L <= R) {
        int mid = (L + R) >> 1;
        if (Get(1, 1, n, mid, tmp - 1) < x) {
            Res = mid;
            R = mid - 1;
        }
        else L = mid + 1;
    }
    return Res;
}
void solve() {
    cin >> n;
    int P[n + 1], L[n + 1], R[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> P[i];
        up(1, 1, n, i, P[i]);
    }
    for (int i = 1; i <= n; i++) {
        L[i] = i;
        int k = i - 1;
        while (k >= 1 && P[i] > P[k]) {
            L[i] = L[k];
            k = L[k] - 1;
        }
    }
    for (int i = n; i >= 1; i--) {
        R[i] = i;
        int k = i + 1;
        while (k <= n && P[i] > P[k]) {
            R[i] = R[k];
            k = R[k] + 1;
        }
    }
    long long Res = 0;
    for (int i = 1; i <= n; i++) {
        int Le = L[i];
        int Ri = R[i];
        if (Le == 1 && Ri == n) continue;
        int nRi = Next(P[i], Ri + 1, n);
        int pLe = Prev(P[i], 1, Le - 1);
        if (Le != 1) Res += 1LL * (Le - pLe) * (Ri - i + 1) * P[i];
        if (Ri != n) Res += 1LL * (nRi - Ri) * (i - Le + 1) * P[i];
        //cout << Res << '\n';
    }
    cout << Res;
}
int main(int argc,char *argv[]) {
    //srand(time(nullptr));
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //doc();
    solve();
}


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

int bitcount(int x) {
    int ans = 0;
    while (x > 0) {
        ans += x & 1;
        x >>= 1;
    }
    return ans;
}

int bit(int x, int pos) {
    return (x >> pos) & 1;
}

// Insert bit i to position pos of number x
int insertBit(int x, int pos, int i) {
    int y = x & ((1 << pos) - 1);
    x ^= y;
    x <<= 1;
    x ^= y;
    if (i) x |= 1 << pos;
    return x;
}

// Delete pos-th bit of number x
int deleteBit(int x, int pos) {
    int y = x & ((1 << pos) - 1);
    x ^= y;
    x &= ~(1 << pos);
    x >>= 1;
    x ^= y;
    return x;
}

// find the position of the bit(0->n-1) that a and b is different
int findp(int n, int a, int b) {
    for (int i = 0; i < n; i++) {
        if (bit(a, i) != bit(b, i))
            return i;
    }
    return -1;
}

vector<int> F(int n, int a, int b) {
    if (n == 1) {
        return vector<int> {a, b};
    }

    int p = findp(n, a, b);
    int val = bit(a, p);
    
    int x = deleteBit(a, p);
    int y = deleteBit(b, p);
    
    int z = x ^ 1;    

    vector<int> u = F(n - 1, x, z);
    vector<int> v = F(n - 1, z, y);

    vector<int> res;
    for (auto i : u)
        res.push_back(insertBit(i, p, val));
    for (auto i : v)
        res.push_back(insertBit(i, p, val ^ 1));

    return res;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    
    if ((bitcount(a) & 1) == (bitcount(b) & 1)) {
        cout << "NO\n";
        return 0;
    }
    
    cout << "YES\n";
    
    vector<int> ans = F(n, a, b);
    for (auto i : ans) {
        cout << i << ' ';
    }
    cout << endl;

    // checker
    // if (ans.size() != 1 << n) return cout << "Incorrect len\n", 0;
    // for (int i = 1; i < 1 << n; i++) {
    //     int x = ans[i];
    //     int y = ans[i - 1];
    //     int cnt = 0;
    //     for (int j = 0; j < n; j++) {
    //         cnt += bit(x, j) ^ bit(y, j);
    //     }
    //     if (cnt != 1) return cout << "Wrong\n", 0;
    // }
    // cout <<  "Correct\n";
}



Measured memory_bytes: 1628
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll t, i, x, j, y, 	z = 0, k, n;
	cin >> n >> k;

	ll a[n];

	rep(i, 0, n, 1) {
		cin >> a[i];
		debug(a[i]);
		z = max(z, a[i]);
	}

	debug(z);


	ll lo = 1, hi = hell;

	function<long long(ll)> check = [&](ll val) {
		ll res = 0, i;

		rep(i, 0, n, 1) {
			if (a[i] > val) {
				res += a[i] / val;
			}
		}


		return res;
	};


	while (lo <= hi) {
		ll mid = (lo + hi) / 2;

		if (check(mid) <= k) {
			z = min(z, mid);
			hi = mid - 1;
		}
		else lo = mid + 1;
	}

	ce(z);
	debug(z);
}



Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long

int32_t main() {
	Fast_IO

	int a, b, c; cin >> a >> b >> c;
	int k; cin >> k;
	int ans = 0;
	if (a <= k) {
		k -= a;
		ans += a;
	}
	else {
		ans += k;
		k = 0;
	}

	if (k > 0) {
		if (b <= k) {
			k -= b;

		}
		else {
			k = 0;
		}
	}

	if (k > 0) {
		if (c <= k) {
			k -= c;
			ans -= c;
		}
		else {
			ans -= k;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3648
#include<iostream>

using namespace std;
#define N 500001


//counter
int counter=0;

//Merge function
void Merge(int A[],int left,int mid,int right){
  
  int n1,n2,i,j;
  int L[N],R[N];

  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }

  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }

  //L[n1]=SENTINEL,R[n2]=SENTINEL
  L[n1]=999999998;
  R[n2]=999999998;

  i=0;
  j=0;
  for(int k=left;k<right;k++){
    //counter++
    counter++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
  }

}
//MergeSort function
void MergeSort(int A[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    MergeSort(A,left,mid);
    MergeSort(A,mid,right);
    Merge(A,left,mid,right);
  }

}


int main(){

  int num,i;
  int data[N];
  //load number
  cin >>num;
  //load data
  for(i=0;i<num;i++){
    cin >>data[i];
  }
  //execute merge sort
  MergeSort(data,0,num);
  //print
  for(i=0;i<num;i++){
    cout <<data[i];
    if(i!=num-1)cout <<" ";
  }
  cout <<endl;
  cout <<counter<<endl;
  return 0;

}

Measured memory_bytes: 4780
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

vector<LL> t(4*200005);

void add(int v,int l,int r,int pos,LL val)
{
	if (l == r)
	{
		t[v] = val;
		return;
	}

	int m = (l + r) >> 1;

	if (pos <= m)
		add(v * 2, l, m, pos, val);
	else
		add(v * 2 + 1, m + 1, r, pos, val);

	t[v] = max(t[v * 2], t[v * 2 + 1]);
}

LL get(int v,int l,int r,int pos)
{
	if (l == r)
		return t[v];
	int m = (l + r) >> 1;
	if (pos <= m)
		return get(v * 2, l, m, pos);
	else
		return max(t[v * 2], get(v * 2+1, m + 1, r, pos));
}

int n,h[200005];
LL a[200005],ans;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d", h + i);
	for (int i = 0; i < n; i++)
		scanf("%lld", a + i);
	for (int i = 0; i < n; i++)
	{
		a[i] += get(1, 0, n, h[i]-1);
		ans = max(ans, a[i]);
		add(1, 0, n, h[i], a[i]);
	}
	cout << ans << endl;
	return 0;
}

/*



*/

Measured memory_bytes: 8832
n=int(input())
a=list(map(int,input().split()))

li=[0]*(n+1)

for i in range(n):
    li[i+1]=li[i]+a[i]

all=sum(a)

ans=abs(all-li[1]*2)
for i in range(2,n):
    ans=min(ans, abs(all-li[i]*2))
    # print(ans)
    # print(all)
    # print(li[i])
print(ans)

Measured memory_bytes: 76880
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int k;
  string s;
  cin >> k;
  cin >> s;
  if(s.size() <= k){
    cout << s << endl;
  }
  else{
    cout << s.substr(0,k) << "..." << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
require 'prime'
q = gets.to_i
ln = []
pn = []

Prime.each(10 ** 5) do |p|
  pn << p
  a = (p + 1) / 2
  i = pn.bsearch_index {|x| x >= a }
  if pn[i] == a
    ln << p
  end
end

q.times do
  l, r = gets.chomp.split.map(&:to_i)
  lb = ln.bsearch_index {|x| x >= l } || ln.size
  ub = ln.bsearch_index {|x| x > r } || ln.size
  puts ub - lb
end

Measured memory_bytes: 14772
#include <bits/stdc++.h>//toINFandByd
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
using namespace std;
typedef long long ll;

void solve(){
    char c;
    cin >> c;
    if(islower(c)){
        cout << "a" << endl;
    }
    else{
        cout << "A" << endl;
    }
}   

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3608
#include <iostream>
# include<string>

using namespace std;

int main() {
	string ramen;
	cin >> ramen;
	int nedan = 700;
	if (ramen[0] == 'o')  nedan += 100;
	if (ramen[1] == 'o')  nedan += 100; 
	if (ramen[2] == 'o')  nedan += 100;

	cout << nedan << endl;

}

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

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

    queue<int64_t> que;
    
    for(int i = 1; i < 10; i++) que.push(i);

    for(int i = 0; i < k - 1; i++) {
        int64_t v = que.front();
        que.pop();
        if(v % 10 != 0) que.push(v * 10 + v % 10 - 1);
        que.push(v * 10 + v % 10);
        if(v % 10 != 9) que.push(v * 10 + v % 10 + 1);
    }

    cout << que.front() << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int dp[11000];

int main(){
  int A,B;
  cin>>A>>B;
  cout<<(A+B)%24<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int a[][100],int x[][100],int y[][100],int p,int q,int r){  
  if(0){
  }else if(a[p][q]==-1){
    a[p][q]=r;
    if(f(a,x,y,x[p][q],y[p][q],r))
      return 1;
    else
      return 0;
  }else if(a[p][q]==r){
    return 1;
  }else{
    return 0;
  }
}
int main(){
  int i,j,k;
  int a[100][100],x[100][100],y[100][100],n;
  while(cin>>n&&n){
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
	cin>>x[j][i]>>y[j][i];
    memset(a,-1,sizeof(a));
    k=0;
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	if(f(a,x,y,j,i,n*i+j))
	  k++;
      }
    }
    cout<<k<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;
typedef long long int ll;

ll n,a,b,r=0;



int main(){
    scanf("%lld %lld %lld",&n,&a,&b);
    printf("%lld\n",max(r,b*(n-2)-a*(n-2)+1));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double x[200], y[200];
vector<pair<double, int> > e;
double pi = acos(-1.0);
void add(double x) {
	if (x < -pi / 2) {
		e.push_back(make_pair(-pi, 1));
		e.push_back(make_pair(x + pi / 2, -1));
		e.push_back(make_pair(x + 3 * pi / 2, 1));
		e.push_back(make_pair(pi, -1));
	} else if (x > pi / 2) {
		e.push_back(make_pair(-pi, 1));
		e.push_back(make_pair(x - 3 * pi / 2, -1));
		e.push_back(make_pair(x - pi / 2, 1));
		e.push_back(make_pair(pi, -1));
	} else {
		e.push_back(make_pair(x - pi / 2, 1));
		e.push_back(make_pair(x + pi / 2, -1));
	}
}
int n;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
	}
	for (int i = 0; i < n; i++) {
		e.clear();
		for (int j = 0; j < n; j++) {
			if (i == j) {
				continue;
			}
			double ag = atan2(y[j] - y[i], x[j] - x[i]);
			add(ag);
		}
		sort(e.begin(), e.end());
		double b = -pi;
		double s = 0;
		int cnt = 0;
		for (int i = 0; i < e.size(); i++) {
			if (cnt == 0) {
				s += e[i].first - b;
			}
			b = e[i].first;
			cnt += e[i].second;
		}
		if (cnt == 0) {
			s += pi - b;
		}
		printf("%.15f\n", s / (2 * pi));
	}
	return 0;
}

Measured memory_bytes: 512
import sys
s = list(input())
t = list(input())

for i in range(len(s) - 1, len(t) - 2, -1):
    j = 0
    tmps = s.copy()
    while s[i - j] == '?' or s[i - j] == t[len(t) - 1 - j]:
        tmps[i - j] = t[len(t) - 1 - j]
        j += 1
        if len(t) - 1 - j < 0:
            for k in range(len(tmps)):
                if tmps[k] == '?':
                    tmps[k] = 'a'
            print(''.join(tmps))
            sys.exit(0)

print('UNRESTORABLE')

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
using namespace std;

int num[1000];

int main() {
	int A, B, K;
	scanf("%d%d%d", &A, &B, &K);
	int max;
	if(A >= B) {
		max = A;
	} else {
		max = B;
	}
	int cou = 0;
/*
	return 0;//*/
	for(int i = 1; i <= max; ++i) {
/*
		cout << "error" << endl;//*/ 
		if(A % i == 0 && B % i == 0) {
			num[cou++] = i;
		}
/*
		cout << i << endl;//*/
	}
	cou -= K;
	cout << num[cou];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3005;
double arr[MAXN];
double dp[MAXN][MAXN];
bool vis[MAXN][MAXN];
double memo(int i, int n){
    if(n < 0) return 0;
    if(i < 0) return n == 0;
    if(vis[i][n]) return dp[i][n];
    vis[i][n] = true;
    return dp[i][n] = memo(i - 1, n - 1) * arr[i] + memo(i - 1, n) * (1 - arr[i]);
}
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    double ans = 0;
    for(int i = (n + 1) / 2; i <= n; i++){
        ans += memo(n - 1, i);
    }
	cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 79232
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	x,y = readline() |> split |> parseMap
	k = 0
	while x<=y
		x =x*2
		k += 1
	end
	println(k)
end

main()

Measured memory_bytes: 171852
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
using namespace std;
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
 
int main(){
  int N, K;
  cin >> N >> K;
  ll x[100010];
  ll px[100010];
  ll mx[100010];
  FOR(i, 0, N) cin >> x[i];
  FOR(i, 0, N) {
    if(x[i]<0) {
      px[i] = 2*x[i];
      mx[i] = x[i];
    }else{
      px[i] = x[i];
      mx[i] = 2*x[i];
    }
  }
  
  ll min_p = 10000000000000000;
  ll min_m = 10000000000000000;
  ll sum;
  
  FOR(i, 0, N-K+1){
    if(px[i+K-1]*px[i] < 0) sum = px[i+K-1] - px[i];
    else if(px[i+K-1]*px[i] >= 0 && px[i] >= 0) sum = px[i+K-1];
    else sum = -px[i];
    
    if(min_p > sum) min_p = sum;
  }
  	
  
  FOR(i, 0, N-K+1){
    if(mx[i+K-1]*mx[i] < 0) sum = mx[i+K-1] - mx[i];
    else if(mx[i+K-1]*mx[i] >= 0 && mx[i] >= 0) sum = mx[i+K-1];
    else sum = -mx[i];
    
    if(min_m > sum) min_m = sum;
  }
  
   

  cout << min(min_p, min_m) << endl;
}



Measured memory_bytes: 2560
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int n;
    std::cin >> n;

    std::vector<std::unordered_map<std::string, long long>> dp(n + 1);

    auto is_ok = [](std::string last_four) {
        for (int i = 0; i < 4; i++) {
            std::string t = last_four;
            if (i < 3) {
                std::swap(t[i], t[i + 1]);
            }

            if (t.find("AGC") != std::string::npos) {
                return false;
            }
        }
        return true;
    };
    auto dfs = [&](auto f, int idx, std::string last_three) -> long long {
        if (idx == n) {
            return 1;
        }

        if (dp[idx].find(last_three) != dp[idx].end()) {
            return dp[idx][last_three];
        }

        long long value = 0;
        for (auto c : { 'A', 'C', 'G', 'T' }) {

            if (is_ok(last_three + c)) {
                value += f(f, idx + 1, last_three.substr(1, 2) + c) % mod;
                value %= mod;
            }
        }

        dp[idx][last_three] = value;
        return value;
    };

    std::cout << dfs(dfs, 0, "TTT") << std::endl;
}


Measured memory_bytes: 896
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,fac[li];
int cev;
string s;
vector<int> v;

inline int add(int x,int y){
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

inline int mul(int x,int y){
	return (x%mod)*(y%mod)%mod;
}

inline int fp(int x,int y){
	if(y==0)return 1;
	if(y==1)return x;
	int q=fp(x,y/2);
	q=mul(q,q);
	if(y%2==1)q=mul(q,x);
	return q;
}

main(void){
	scanf("%lld %lld",&n,&k);
	if(k==1){printf("0\n");return 0;}
	fac[0]=1;
	for(int i=1;i<=n*2;i++){
		fac[i]=mul(fac[i-1],i);
	}
	//~ cout<<mul(fac[1],fp(1,mod-2))<<endl;
	FOR{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+n+1);
	FOR{
		if(n-i>=k-1){
			cev=add(mod,add(mod,add(cev,-mul(a[i],mul(fac[n-i],fp((mul(fac[k-1],fac[n-i-(k-1)])),mod-2))))));
		}
		//~ cout<<cev<<endl;
		
		if(i-1>=k-1){
			//~ cout<<i<<endl;
			cev=add(cev,mul(a[i],mul(fac[i-1],fp((mul(fac[k-1],fac[i-1-(k-1)])),mod-2))));
		}
		//~ cout<<cev<<endl;
	}
	printf("%lld\n",cev);
	return 0;
}



Measured memory_bytes: 5888
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }



main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    int n = sz(s);
    int m = sz(t), ans = INF;
    for (int i = 0; i + m - 1 < n; i++) {
        int res = 0;
        for (int j = 0, c = i; j < m; j++, c++) {
            res += s[c] != t[j];
        }
        umin(ans, res);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3668
package main

import "fmt"

func main() {
	var W, H, x, y float64
	fmt.Scan(&W, &H, &x, &y)

	flg := 0
	if x == W/2 && y == H/2 {
		flg = 1
	}

	fmt.Println((W*H)/2, flg)
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
	int n,i,tekn;
	int buf,sum;
	while(1){
		scanf("%d",&n);
		if(n == 0){break;}
		tekn = n / 4;
		sum = 0;
		for(i = 0; i < tekn; i++){
			scanf("%d",&buf);
			sum += buf;
		}
		printf("%d\n",sum);
	}


	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>

int main() {
	int a,n,min = 1001,max = -1;
	scanf("%d",&n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d",&a);
		if ( min > a) {
			min = a;
		}
		if ( max < a) {
			max = a;
		}
	}
	printf("%d",max - min);
}

Measured memory_bytes: 1684
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	string s;
	cin>>s;
	rep(i,s.size()-1){
		if(s.substr(i,2)=="AC"){
			cout<<"Yes"<<endl;return 0;
		}
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k;
	string s;
	cin >> n >> k;
	FOR(i,0,n){
		cin >> s;
		cout << s << endl << s << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3624
#![allow(dead_code, unused_imports)]
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;
use std::str::FromStr;

type Error = Box<dyn std::error::Error>;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

struct Scanner {
    buff: Vec<String>,
    pos: usize,
}


impl Scanner {
    pub fn new() -> Self {
        Scanner {
            buff: Vec::new(),
            pos: 0,
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T {
        while self.buff.len() <= self.pos {
            self.pos = 0;
            self.buff = read_line().split_whitespace().map(|s| s.to_owned()).collect();
        }

        let result = self.buff[self.pos].parse::<T>();
        self.pos += 1;
        result.ok().unwrap()
    }

    pub fn next_line(&mut self) -> String {
        let result  = read_line().trim().to_owned();
        self.buff.clear();
        self.pos = 0;

        result
    }

    pub fn next_vec<T: FromStr>(&mut self) -> Vec<T> {
        self.buff.clear();
        self.pos = 0;
        read_line().trim().split_whitespace().map(|s| s.parse().ok().unwrap()).collect()
    }
    
    pub fn next_line_chars(&mut self) -> Vec<char> {
        let result  = read_line().trim().chars().collect();
        self.buff.clear();
        self.pos = 0;

        result
    }
}

fn func(a: &Vec<Vec<i64>>) -> Option<i64> {
    let mut es = Vec::new();
    let mut ans = 0;
    let n = a.len();
    for i in 0..n {
        for j in i+1..n {
            es.push((a[i][j], i, j));
        }
    }
    es.sort();
    let mut visited = vec![vec![false; n]; n];
    for &(v, i, j) in es.iter() {
        visited[i][j] = true;
        visited[j][i] = true;

        let mut flag = false;
        for k in 0..n {
            if k != i && k != j && visited[i][k] && visited[k][j] {
                if a[i][k] + a[k][j] < v {
                    return None;
                }
                if a[i][k] + a[k][j] == v {
                    flag = true;
                    break;
                }
            }
        }
        if !flag {
            ans += v;
        }
    }

    Some(ans)
}


fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.next();

    let mut a = Vec::new();
    for i in 0..n {
        let line: Vec<i64> = sc.next_vec();
        a.push(line);
    }

    match func(&a) {
        Some(v) => { println!("{}", v); },
        None => { println!("-1"); },
    }

}


Measured memory_bytes: 4788
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);

const int N=500001;

int dp[100001][2][101];
string k;
int d,n,ans;

int rec(int pos,int sum,int flag){
	if(dp[pos][flag][sum]!=-1)return dp[pos][flag][sum];
	dp[pos][flag][sum]=0;
	if(pos==n){
		if(sum%d==0)return dp[pos][flag][sum]=1;
		return dp[pos][flag][sum]=0;
	}
	int ans=0;
	int LMT=k[pos]-'0';
	if(flag)LMT=9;
	for(int i=0;i<=LMT;i++){
		if(flag){
			add(dp[pos][flag][sum],rec(pos+1,(sum+i)%d,flag));
		}
		else{
			if(i<LMT){
				add(dp[pos][flag][sum],rec(pos+1,(sum+i)%d,1));
			}
			else{
				add(dp[pos][flag][sum],rec(pos+1,(sum+i)%d,flag));
			}
			
		}
			
	}
	return dp[pos][flag][sum];
}
	


void solve(){
	cin>>k>>d;
	n=k.length();
	for(int i=0;i<=n;i++){
		for(int j=0;j<d;j++){
			dp[i][1][j]=dp[i][0][j]=-1;
		}
	}
	cout<<(rec(0,0,0)-1+mod)%mod;
	
}
	
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;	
}


Measured memory_bytes: 9600
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			char[][] table = new char[n][2];
			for (int i = 0; i < n; i++) {
				table[i][0] = sc.next().charAt(0);
				table[i][1] = sc.next().charAt(0);
			}
			int m = sc.nextInt();
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < m; i++) {
				char c = sc.next().charAt(0);
				for (int j = 0; j < n; j++) {
					if (table[j][0] == c) {
						c = table[j][1];
						break;
					}
				}
				sb.append(c);
			}
			System.out.println(sb);
		}
		sc.close();
	}
}

Measured memory_bytes: 68972
A, B, C = map(int, input().split())

V = A * B * C

ans = 10 ** 9 ** 3
ans = min(ans, abs(-(-A//2) * B * C - (A//2) * B * C))
ans = min(ans, abs(-(-B//2) * A * C - (B//2) * A * C))
ans = min(ans, abs(-(-C//2) * A * B - (C//2) * A * B))

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
typedef pair<int,int> pii;
int h,w;
int dist[1005][1005];
char mp[1005][1005];
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};

int bfs(){
  memset(dist,-1,sizeof(dist));
  queue<pii> que;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(mp[i][j]=='#'){
	que.push(make_pair(i,j));
	dist[i][j]=0;
      }
    }
  }
  while(!que.empty()){
    pii now=que.front();
    que.pop();
    int ny=now.first;
    int nx=now.second;
    for(int i=0;i<4;i++){
      int ty=ny+dy[i];
      int tx=nx+dx[i];
      if(0<=ty && ty<h && 0<=tx && tx<w){
	if(mp[ty][tx]=='.' && dist[ty][tx]==-1){
	  dist[ty][tx]=dist[ny][nx]+1;
	  mp[ty][tx]='#';
	  que.push(make_pair(ty,tx));
	}
      }
    }
  }
  int maxi=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      maxi=max(maxi,dist[i][j]);
    }
  }
  return maxi;
}
int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>mp[i][j];
    }
  }
  cout<<bfs()<<"\n";
  return 0;
}


Measured memory_bytes: 13328
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){

  string s[]={""," .,!?", "cab", "fde", "igh", "ljk", "omn", "spqr", "vtu", "zwxy"};
  int m[]={0, 5, 3, 3, 3, 3, 3, 4, 3, 4};
  string b;
  int n, cnt;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>b;
    cnt=0;
    for(int j=0;j<b.size();j++){
      if(b[j]=='0'){
	if(cnt){
	  cout<<s[b[j-1]-'0'][cnt%m[b[j-1]-'0']];
	  cnt=0;
	}
      }else cnt++;
    }
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3152
fun main(args: Array<String>) {
    val line = readLine()!!.trim()
    val (x: Int, y:Int) = line.split(" ").map {it.toInt() }

    val turtoles2 = (y - 2 * x)

    if (turtoles2 % 2 == 0 && 2 * x >= turtoles2 && turtoles2 >= 0) {
        println("Yes")
    } else {
        println("No")
    }
}


Measured memory_bytes: 36352
string = input()
x, y = map(int, input().split())

xy = True
x_s = []
y_s = []
cnt = 0
for s in string:
    if s == "F":
        cnt += 1
    else:
        if xy:
            x_s.append(cnt)
            xy = False
        else:
            y_s.append(cnt)
            xy = True
        cnt = 0
if xy:
    x_s.append(cnt)
    xy = False
else:
    y_s.append(cnt)
    xy = True
x_can = [False for _ in range(8001)]
y_can = [False for _ in range(8001)]

x_can[x_s[0]] = True
for xx in x_s[1:]:
    for i in range(8000, xx - 1, -1):
        if x_can[i - xx]:
            x_can[i] = True

y_can[0] = True
for yy in y_s:
    for i in range(8000, yy - 1, -1):
        if y_can[i - yy]:
            y_can[i] = True
            
x_pos = (x + sum(x_s))
y_pos = (y + sum(y_s))
if x_pos % 2 == 1 or y_pos % 2 == 1:
    print("No")
elif x_can[x_pos // 2] and y_can[y_pos // 2]:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 74468
/*
 Educational Dp Contest Atcoder
 
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

const ll MOD =998244353;
const ll hell=1000000007;
const int INF=1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=1e5+5;
int dp[N][101];int a[101],vl[101];
void solve()
{
    int n,w;
    cin>>n>>w;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>vl[i];
    for(int i=1;i<=w;i++)
        for(int j=1;j<=n;j++)
        {
            dp[i][j]=dp[i][j-1];
            if(a[j]<=i)
                dp[i][j]=max(dp[i][j],dp[i-a[j]][j-1]+vl[j]);
        }
    cout<<dp[w][n]<<endl;

}

int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 79232
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e2+5;
const int M = 1e5+5;
const int mod = 1e9+7;

int n;
int k;
int mn;
int pile[N];
bool has[M];
bool vis[M][2];
bool mem[M][2];

//taro's trn is 1
bool go(int stones , int trn){
    //cout << stones << " " << trn << endl;
    if(stones < mn){
        return 0;
    }
    if(vis[stones][trn])
        return mem[stones][trn];
    bool state = 0;
    for(int i = n; i >= 1; i--){
        if(pile[i] <= stones){
            state |= !go(stones - pile[i] , 1 - trn);
        }
    }
    vis[stones][trn] = true;
    return mem[stones][trn] = state;
}

int main(){
    scanf("%d%d" , &n , &k);
    mn = 1e5+5;
    for(int i = 1; i <= n; i++){
        scanf("%d" , &pile[i]);
        mn = min(mn , pile[i]);
    }
    if(go(k , 1)){
        puts("First");
    } else {
        puts("Second");
    }
}


Measured memory_bytes: 5376
fun main(args: Array<String>) {
    val (N, A, B) = listOfInt()
    val C = A - B
    var H = Array(N) { nextInt() }
    fun ceil(a: Long, m: Int) = (a + m - 1) / m
    var ans = 1000000001L
    var left = 0L
    fun isOK(t: Long): Boolean {
        var r = t
        for (n in 0 until N)
            if (H[n] > B * t) {
                r -= ceil(H[n] - B * t, C)
                if (r < 0) return false
            }
        return true
    }
    while (Math.abs(ans - left) > 1) {
        val mid = (ans + left) / 2
        if (isOK(mid)) ans = mid 
        else left = mid
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}


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

int main(){
  using pii= pair<int, int>;
  int N;
  cin >> N;

  vector<pii> bots(N);
  for(int i=0; i<N; i++){
    cin >> bots.at(i).first >> bots.at(i).second;
  }

  auto comp= [](pii a, pii b){
    bool ans= (a.first+ a.second != b.first+ b.second) ? (a.first+ a.second < b.first+ b.second)
                                                       : (a.first- a.second > b.first- b.second);
    return ans;
  };
  sort(bots.begin(), bots.end(), comp);

  int ans= 0;
  int arm= INT_MIN;
  for(auto bot:bots){
    if(arm <= bot.first- bot.second){
      ans++;
      arm= bot.first+ bot.second;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
int main(){
	int A, B;
	scanf("%d %d",&A,&B);
	if((A+B)>16){
		printf(":(\n");
	}
	if(A>8 || B>8){
		printf(":(\n");
	}
	else{
		printf("Yay!\n");
	}
	

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N-1; i++)
  {
     int X;cin>>X;
     vec[X-1]++;
  }
  for (int i = 0; i < N; i++)
  {
    cout<<vec[i]<<endl;
  }
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 4780
N, K = map(int, input().split())
st = {}

for i in range(N):
    a, b = map(int, input().split())
    st[a] = st.get(a, 0)
    st[a] += b

st_sorted = sorted(st.items(), key=lambda x:x[0])

num = 0
for i in range(len(st_sorted)):
    num += st_sorted[i][1]
    if num >= K:
        print(st_sorted[i][0])
        exit()

Measured memory_bytes: 15044
#include <bits/stdc++.h>
#define ll long long

using namespace std;

string s, t;

ll Dp[101][4][2][2];

ll Solve(int idx, int k, int less, int more)
{
    if (k < 0) return 0;
    if (idx == s.size())
        return k == 0; 

    ll &ret = Dp[idx][k][less][more];
    if (ret + 1) return ret;

    int numL = t[idx] - '0';
    int numR = s[idx] - '0';
    int L = (more ? 0 : numL);
    int R = (less ? 9 : numR);

    ret = 0;
    for (int i = L; i <= R; i++)
        ret += Solve(idx + 1, k - (i != 0), less | (i < numR), more | (i > numL));
    return ret;
}

int main()
{
    cin >> s;
    int k;  cin >> k;

    for (int i = 1; i < s.size(); i++)
        t.push_back('0');
    t += "1";

    memset(Dp, -1, sizeof Dp);

    cout << Solve(0, k, 0, 0) << '\n';

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
	Scanner scan=new Scanner(System.in);
	String a=scan.next();
	boolean bool=false;
	for(int i=0;i<a.length();i++) {
		for(int j=0;j<a.length()-i+1;j++) {
			String str1=a.substring(0,j);
			String str2=a.substring(j+i,a.length());
			String str=str1+str2;
			if(str.equals("keyence")) {
				bool=true;
			}
		}
	}
	System.out.println(bool?"YES":"NO");
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <cstring>
int main(int argc, char* pArgv[])
{
	std::string n, m;
  	std::cin >> n >> m;
	std::string a, b;
	int countN = std::atoi(n.c_str());
	int countM = std::atoi(m.c_str());
 	for (int i = 0; i < countN; i ++) {
      a += m;
    }
 	for (int i = 0; i < countM; i ++) {
      b += n;
    }
  	std::cerr << "a=" << a << ", b=" << b << std::endl;
  
  	std::cout << (a < b ? a : b) << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int x,y,s,a=0,b,h1=0,h2=0,sum=0,hh1,hh2;
  while(1){
  scanf("%d %d %d",&x,&y,&s);
  if(x==0&&y==0&&s==0)
    break;
  for(a=1;a<=s/2;a++){
    b=s-a;
    if((100*a)%(100+x)!=0){
    h1=a*100/(100+x)+1;
    }
    else
    h1=a*100/(100+x);
    if((b*100)%(100+x)!=0)
    h2=b*100/(100+x)+1;
    else
    h2=b*100/(100+x);
    hh1=h1*(100+x)/100;
    hh2=h2*(100+x)/100;
    if(hh1!=a){
      h1=0;
      h2=0;
    }
    if(hh2!=b){
      h1=0;
      h2=0;
    }
    h1=h1*(100+y)/100;
    h2=h2*(100+y)/100;
    if(sum<h1+h2){
      sum=h1+h2;
    }
  }
  printf("%d\n",sum);
  sum=0;
  }
  return(0);
}

Measured memory_bytes: 600
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>
using namespace std;
using i64 = int64_t;
int main() {
    i64 n, k;
    cin >> n >> k;
    vector<pair<i64, i64>> ps;
    i64 a = k + n - 1;
    for (i64 b = k + n; b < k + 2 * n; a -= 1, b += 2) {
        ps.emplace_back(a, b);
    }
    for (i64 b = k + n + 1; b < k + 2 * n; a -= 1, b += 2) {
        ps.emplace_back(a, b);
    }
    sort(begin(ps), end(ps), [](auto p, auto q) {
        return p.first + p.second < q.first + q.second;
    });
    for (i64 i = 0, c = k + 2 * n; i < n; ++i, ++c) {
        i64 a, b;
        tie(a, b) = ps[i];
        if (a + b > c) {
            cout << -1 << endl;
            return 0;
        }
    }
    for (i64 i = 0, c = k + 2 * n; i < n; ++i, ++c) {
        i64 a, b;
        tie(a, b) = ps[i];
        cout << a << ' ' << b << ' ' << c << '\n';
    }
    return 0;
}

Measured memory_bytes: 3952
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n = int(input())
s = [input() for i in range(n)]
s = set(s)
print(len(s))

Measured memory_bytes: 53472
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    string s;
    cin>>s;
    int ans=s.back()-'0';
    if(ans==3)
    {
        cout<<"bon";
    }
    else if(ans==0 || ans==1 || ans==6 || ans==8)
    {
        cout<<"pon";
    }
    else
    {
        cout<<"hon";
    }
    
}


Measured memory_bytes: 3628