akhauriyash/Code-Regression huggingface dataset:
import sys
N=int(input())
listAB=[]
for i in range(N):
  A,B=map(int,input().split())
  listAB+=[[B,A]]  
listAB.sort()
sumA=listAB[0][1]
for i in range(N-1):
  if listAB[i][0]<sumA:
    print("No")
    sys.exit()
  sumA+=listAB[i+1][1]
if listAB[N-1][0]<sumA:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 35596
#include <cstdio>
#include <algorithm>
using namespace std;

int r, c;
int a[10000][10];
int b[10000][10];
int d[10000];
int t;
int ans;

int main(){
	while(1){
		scanf("%d %d", &r, &c);
		if(r == 0 && c == 0) break;
		ans = 0;
		for(int i=0; i<r; i++)
			for(int j=0; j<c; j++)
				scanf("%d", &a[j][i]);
		
		for(int i=0; i<1<<r; i++){
			
	//		printf("i=%d\n", i);

			for(int j=0; j<c; j++) d[j] = 0;
			t = 0;

			for(int j=0; j<r; j++){
				if((i>>j&1) == 1) for(int k=0; k<c; k++) b[k][j] = a[k][j];
				else for(int k=0; k<c; k++) b[k][j] = 1 - a[k][j];

	/*			for(int n=0; n<c; n++){
					printf("%d\t", b[n][j]);
				}
				printf("\n");
	*/
			}

			for(int i=0; i<r; i++)
				for(int j=0; j<c; j++)
					d[j] += b[j][i];
	/*
			for(int i=0; i<c; i++) printf("%d\t", d[i]);
			printf("\n");
	*/
			for(int i=0; i<c; i++)
				t += max(d[i], r-d[i]);
			ans = max(ans, t);
		}

		printf("%d\n", ans);
	}
	return 0;
}

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

int main() {
  int n, x;
  string S;
  cin >> S;
  x = 0;
  n = S.size();
  for (int i = 0; i < n / 2; i++) {
    if (S.at(2 * i) == '1') {
      x++;
    }
    if (S.at(2 * i + 1) == '0') {
      x++;
    }
  }
  if (n % 2 == 1) {
    if (S.at(n - 1) == '1') {
      x++;
    }
  }
  if (x <= n / 2) {
    cout << x << endl;
  }
  else {
    cout << n - x << endl;
  }
}


Measured memory_bytes: 512
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int cnt_order(int N, veci A) {
    veci res(N);
    REP(i,N) res[i] = i+1;

    int cnt = 1;
    do {
        bool ok = true;
        REP(i,N) if(res[i] != A[i]) ok = false;
        if(ok) {
            break;
        }
        else cnt++;
    }while(next_permutation(res.begin(),res.end()));
    return cnt;
}

int main() {
    int N;
    cin >> N;
    veci res(N),P(N),Q(N);
    REP(i,N) cin >> P[i];
    REP(i,N) cin >> Q[i];
    cout << abs(cnt_order(N,P)-cnt_order(N,Q)) << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int n,k; cin >> n >> k;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];
	int m = min(n,k);
	ll ans = 0;
	rep(a,m+1){
		rep(b,m+1){
			if(a+b > n || a+b > k) continue;
			ll res = 0;
			priority_queue<ll> q;
			rep(i,a){
				ll tmp = v[i];
				res += tmp;
				if(tmp < 0)
					q.push(-tmp);
			}
			rep(i,b){
				ll tmp = v[n-i-1];
				res += tmp;
				if(tmp < 0)
					q.push(-tmp);
			}
			Rep(k-a-b){
				if(q.empty()) break;
				res += q.top();
				q.pop();
			}
			ans = max(ans, res);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>

using namespace std;

int n,m,star,d;

bool C(vector<string> &s){
	int cu = m;
	for (int i = 0; i < d; i++){
	if(cu != 0)
		if(s[i][cu - 1] == '1'){
			cu--; continue;
		}
	if(cu != n - 1)
		if(s[i][cu] == '1'){
			cu++; continue;
		}
	}

	return cu == star;
}

void solve()
{
	cin>>m>>star>>d;
	m--; star--;
	vector<string> s(d);
	for (int i = 0; i < d; i++){
		cin>>s[i];
	}

	if(C(s)){
		puts("0");
		return;
	}
	for (int i = 0; i < d; i++){
		for (int j = 0; j < n - 1; j++){
			if(j != 0)
				if(s[i][j-1] == '1') continue;
			if(s[i][j] == '1') continue;
			if(j != n - 2)
				if(s[i][j+1] == '1') continue;
			s[i][j] = '1';
			if(C(s)){
				printf("%d %d\n",i + 1,j + 1);
				return ;
			}
			s[i][j] = '0';
		}
	}

	puts("1");
}

int main(){
	while(cin>>n,n){
		solve();
	}
    return 0;
}

Measured memory_bytes: 0
import math

square_list = [i**2 for i in range(1, 10**5)]

def integer_squareroot(x):
    imin = 0
    imax = x
    while imin <= imax:
        imid = (imin + imax) // 2
        imid_squared = imid ** 2
        if imid_squared <= x:
            imin = imid + 1
        else:
            imax = imid - 1

    return imin - 1


a, b, c = map(int, input().split())
if 4 * a * b < (c-a-b) ** 2 and c - a - b > 0:
    print("Yes")
else:
    print("No")

# for i in range(3):
#     if A[i] in square_list:
#         A[i] = integer_squareroot(A[i])
#     else:
#         A[i] = math.sqrt(A[i])

# if A[0] + A[1] + 1e-11 < A[2]:
#     print("Yes")
# elif A[0] + A[1] < A[2]:
#     print("Yes")
# else:
#     print("No")

Measured memory_bytes: 7192
#include<stdio.h>
int main(void)
{
        int i = 1,j,x[10000],y[10000];
        while(1){
                scanf("%d %d",&x[i],&y[i]);
                if(x[i] == 0 && y[i] == 0){
                        break;
                }
                i++;
        }
        for(j = 1;j <= i-1;j++){
                if(x[j] < y[j]){
                        printf("%d %d\n",x[j],y[j]);
                }else{
                        printf("%d %d\n",y[j],x[j]);
                }
        }
        return 0;
}

Measured memory_bytes: 624
#include <iostream>

using namespace std;
long n,a[100005][4],f[100005][4];
int main() {
    cin >> n;
    for (long i=1; i<=n; i++) {
        for (long j=1; j<=3; j++) cin >> a[i][j];
    }
    f[0][1] = 0;
    f[0][2] = 0;
    f[0][3] = 0;
    for (long i=1; i<=n; i++) {
        for (long j=1; j<=3; j++) {
            if (j==1) {
                f[i][j] = max(a[i][j] + f[i-1][j+1], a[i][j] + f[i-1][j+2]);
            }
            if (j==2) {
                f[i][j] = max(a[i][j] + f[i-1][j-1], a[i][j] + f[i-1][j+1]);
            }
            if (j==3) {
                f[i][j] = max(a[i][j] + f[i-1][j-1], a[i][j] + f[i-1][j-2]);
            }
        }
    }
    cout << max(f[n][1],max(f[n][2],f[n][3]));
    return 0;
}


Measured memory_bytes: 6528
import java.util.*;

public class Main {
    public static int ans[] ;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
//        int a = sc.nextInt();
//        int b = sc.nextInt();
//        int c = sc.nextInt();
//        String s = sc.next();
//        Long x = sc.nextLong();
        int ks[] = new int[k];
        int list[] = new int[10-k];
        ans = new int[String.valueOf(n).length()+1];
        String s;
        for(int i=0;i<k;i++){
            ks[i] = sc.nextInt();
        }
        int count=0;
        for(int i=0;i<10;i++){
            boolean f = true;
            for(int j=0;j<k;j++){
                if(ks[j]==i){
                    f=false;
                    break;
                }
            }
            if(f){
                list[count] = i;
                count++;
            }
        }

        for(int i=0;i<String.valueOf(n).length()+1;i++){
            ans[i]=0;
        }

        do{
            plus(ans.length-1,count);
            s = "";
            for(int i=0;i<String.valueOf(n).length()+1;i++){
                if(ans[i]!=0) {
                    s += list[ans[i] - 1];
                }
            }
        }while(Integer.valueOf(s)<n);
        System.out.println(s);
    }
    public static void plus(int n,int count){
        ans[n]++;
        if(ans[n]==count+1){
            ans[n]=1;
            plus(n-1,count);
        }
    }
}


Measured memory_bytes: 26196
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<int>> a(h,vector<int>(w));
    vector<P> ans_bfo,ans_aft;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>a.at(i).at(j);
    int i=0,j=0;
     while(1){//i==hになるまで回す
               if(i>=h)break;
               if(a.at(i).at(j)%2==1){//奇数の場所を見つける
                int bfo_i=i,bfo_j=j;
               // cout<<bfo_i<<" "<<bfo_j<<endl;
                vector<P> tmp,tmp2;
                tmp.push_back(P(i,j));
                if((i%2==1&&j==0)||(i%2==0&&j==w-1))i++;
                else if(i%2==0)j++;
                else if(i%2==1)j--; 
                tmp2.push_back(P(i,j));
                if(i>=h||j>=w)break;
                while(1){//ジグザグ
               if(i%2==0){while(j+1<w&&a.at(i).at(j)%2==0){tmp.push_back(P(i,j));tmp2.push_back(P(i,j+1));j++;}}
               else{while(j-1>=0&&a.at(i).at(j)%2==0){tmp.push_back(P(i,j));tmp2.push_back(P(i,j-1));j--;}}
               // cout<<i<<" "<<j<<endl;
                if(i+1<h&&a.at(i).at(j)%2==0){tmp.push_back(P(i,j));tmp2.push_back(P(i+1,j));i++;}
                else break;
                //cout<<"aaa"<<endl;
                }
               // cout<<i<<" "<<j<<endl;
                if(a.at(i).at(j)%2==0)break;
                a.at(bfo_i).at(bfo_j)--;a.at(i).at(j)++;
                for(int k=0;k<tmp.size();k++){
                    ans_bfo.push_back(tmp.at(k));
                    ans_aft.push_back(tmp2.at(k));
                }
               }
            if((i%2==1&&j==0)||(i%2==0&&j==w-1))i++;
            else if(i%2==0)j++;
            else if(i%2==1)j--;  
        }
    cout<<ans_bfo.size()<<endl;
    for(int i=0;i<ans_bfo.size();i++){
        cout<<ans_bfo.at(i).fi+1<<" "<<ans_bfo.at(i).se+1<<" "<<ans_aft.at(i).fi+1<<" "<<ans_aft.at(i).se+1<<endl;
    }
  /* for(int i=0;i<h;i++){for(int j=0;j<w;j++){
        cout<<a.at(i).at(j)<<" ";
    }cout<<endl;}*/
}

/* if(bfo_j>j){
                    for(int k=bfo_j;k>j;k--){
                        ans_bfo.push_back(P(bfo_i,k));
                        ans_aft.push_back(P(bfo_i,k-1));
                    }
                }
                else{
                    for(int k=bfo_j;k<j;k++){
                        ans_bfo.push_back(P(bfo_i,k));
                        ans_aft.push_back(P(bfo_i,k+1));
                    }
                }
                for(int k=bfo_i;k<i;k++){
                    ans_bfo.push_back(P(k,j));
                    ans_aft.push_back(P(k+1,j));
                }*/

Measured memory_bytes: 5356
#include <iostream>

using namespace std;
long long par[200010],sz[200010] = {},sz2[200010] = {},e[200010],ans = 0;
int init(int n){
	for(int i=0;i<n;i++){
		par[i] = i; sz[i] = 1;
	}
	for(int i=n;i<2*n;i++){
		par[i] = i; sz[i] = 1; sz2[i] = 1;
	}
}

int find(int x){
	if(par[x]==x) return x;
	return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x); y = find(y);
	if(x==y){
		e[x]++; return;
	}
	if(sz[x]<sz[y]) swap(x,y);
	sz[x] += sz[y]; sz2[x] += sz2[y]; par[y] = x; e[x] += e[y] + 1;
}

bool same(int x, int y){
	return find(x)==find(y);
}
int main(){
	int i,n;
	cin >> n;
	init(100000);
	for(i=0;i<n;i++){
		int x,y; cin >> x >> y;
		x--; y--;
		unite(x,y + 100000);
	}
	for(i=0;i<200000;i++){
		if(par[i]==i){
			if(sz[i]==1) continue;
			ans += (sz[i] - sz2[i])*sz2[i] - e[i];
		}
	}
	cout << ans << endl;
}
	

Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vll = vector<long long>;
using vpi = vector<pair<int, int>>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)

const char nl = '\n';
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

    int n; cin >> n;
    deque<int> dq;
    F0R (i, n) {
        int a; cin >> a;
        if (i % 2) {
            dq.push_back(a);
        } else {
            dq.push_front(a);
        }
    }
    if (n % 2 == 0) {
        reverse(all(dq));
    }
    F0R (i, n) cout << dq[i] << " ";
    cout << nl;

    return 0;
}


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

ll gcd(ll m, ll n){
    ll tmp;
    while(m%n){
        tmp = n;
        n = m % n;
        m = tmp;
    }
    return n;
}

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

    int n, x;
    cin >> n >> x;
    vector<int> a(n+1);
    rep(i, n) cin >> a[i];
    
    a[n] = x;
    sort(a.begin(), a.end());
    
    int res = a[1] - a[0];
    rep(i, n){
        res = gcd(res, a[i+1] - a[i]);
    }

    cout << res << endl;

    return 0;
}

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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	int d=0;
	for (int i=1; i<=100; i++){
		d=d+a;
		if (d%b==c){
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
}

Measured memory_bytes: 256
from operator import itemgetter
N,M = [int(x) for x in input().split()]
li = []
for _ in range(N):
    li.append([int(x) for x in input().split()])
li.sort(key=itemgetter(0))
cost = 0
num = 0
flag = True
for i in li:
    if(flag):
        if(num+i[1]>M):
            cost+=(M-num)*i[0]
            flag = False
        else:
            cost+=i[1]*i[0]
            num+=i[1]
print(cost)


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

using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int count=1;
    n-=k;
    count+=(n/(k-1));
    if(n%(k-1)!=0)count++;
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		//int n = sc.nextInt();
		//String s = sc.next();
		long a = sc.nextLong();
		long v = sc.nextLong();
		long b = sc.nextLong();
		long w = sc.nextLong();
		long t = sc.nextLong();
		
		if(b < a) {
			long ta = a-v*t;
			long tb = b-w*t;
			if(ta <= tb) {
				System.out.println("YES");
					return;
			} else {
				System.out.println("NO");
				return;
			}

		}
		
		long ta = a+v*t;
		long tb = b+w*t;
		
		if(ta >= tb) {
			System.out.println("YES");

		} else {
			System.out.println("NO");

		}

		//double n = sc.nextDouble();
		
		//for(int i = 0; i < ; i++)

		//System.out.println("Yes");
		//System.out.println("No");
		

	}
}


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

int main()
{

    int a, b;
    cin >> a >> b;
    cout << (((a+b)%2==0)?(a+b)/2:(a+b)/2+1) << "\n";
    return 0;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

def prime_factorize(n):
  ret = []
  for i in range(2, int(n ** (1 / 2)) + 1):
    if i > n:break
    cnt = 0
    while n % i == 0:
      n //= i
      cnt += 1
    if cnt > 0:  
      ret.append((i, cnt))
  if n != 1:
    ret.append((n, 1))
  return ret

lis = prime_factorize(N)

ans = 0

for v, cnt in lis:
    i = 1
    while cnt >= i:
        cnt -= i
        i += 1   
    ans += i - 1
print(ans) 

Measured memory_bytes: 63288
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

vector<pair<int, int>> primeFactorization(int n) {
    int k = n;
    vector<pair<int, int>> ret;
    for (int i = 2; i <= sqrt(n); i++) {
        int cnt = 0;
        while(k % i == 0) {
            k /= i; // 重複を許さないならここを while に
            cnt++;
        }
        if (cnt) ret.push_back({i, cnt});
    }
    if(k > 1) ret.push_back({k, 1});
    return ret;
}

const int MAXN = 200000;
long long int fact[MAXN], inv[MAXN];

void init_fact() {
    fact[0] = 1;
    for(int i=1; i<MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }

    inv[MAXN - 1] = mod_pow(fact[MAXN - 1], MOD-2);
    for(int i=MAXN - 2; i>=0; i--) {
        inv[i] = (inv[i+1] * (i+1)) % MOD;
    }
}

Int combination_mod(Int n, Int r) {
    if(n < r) return 0;
    if(r == 0 || r == n) return 1;
    Int a = fact[n];
    Int b = fact[n-r];
    Int c = fact[r];

    Int x = a, y = (b * c) % MOD;
    return ( x * mod_pow(y, MOD-2) ) % MOD;
}

int main(){
    cin.tie(0);
    
    init_fact();
    int N, M;
    cin >> N >> M;
    Int ans = 1;
    auto factor = primeFactorization(M);
    for (int i = 0; i < factor.size(); i++){
        int cnt = factor[i].second;
        Int tmp = combination_mod(N+cnt-1, cnt);
        tmp %= MOD;
        ans = (ans * tmp) % MOD;
    }
    cout << ans << endl;
} 


Measured memory_bytes: 3328
import java.util.Scanner;
import java.io.*;

public class Main{

     public static void main(String []args){
        
        try{
        Scanner stdIn = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String str = br.readLine();
        
        char[] charArray = str.toCharArray();
        
        String bstr = br.readLine();
        int b = Integer.parseInt(bstr);
        
        String newStr = "";
        for (int i = 0;i < charArray.length;i += b) {
	        
	        newStr += charArray[i];
	       
        }
        System.out.println(newStr);
        
        }catch(IOException e){
             System.out.println("Exception :" + e);
        }
        
     }
}


Measured memory_bytes: 26068
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int n , s , m;
    s = 0;
    m = 0;
    int l = 0;
    cin >> n;
    
    for(int i=9; i>-1; i--){
        l = n/pow(10,i+1);
        m = (n/pow(10,i)) - l*10;
        s = s + m;
    }
    
    if(n % s == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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

int main()
{
	int N;
	int h[12],L[12];
	while (cin >> N) {
		if (N == 0)
			break;
		for (int i = 0; i < 12; i++) {
			cin >> h[i]>>L[i];
		}
		int cont = 0;
		for (int i = 0; i < 12; i++) {
			cont += h[i] - L[i];
			if (cont >= N) {
				cout << i+1 << endl;
				break;
			}
		}
		if (cont < N)
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    vector<multiset<int>> idx(26);
    int n = s.size(), m = t.size();
    rep(i,n){
        idx[s[i] - 'a'].insert(i);
    }
    int cnt = 0;
    int now = -1;
    rep(i,m){
        int j = t[i] - 'a';
        auto itr = idx[j].lower_bound(now + 1);
        if (idx[j].empty()){
            cout << -1 << ENDL;
            return 0;
        }
        if (itr==idx[j].end()){
            cnt++;
            now = *idx[j].begin();
        }
        else{
            now = *itr;
        }
    }
    cout << (ll)n * (ll)cnt + (ll)now + 1ll << ENDL;
}


Measured memory_bytes: 5200
from typing import List


class RollingHash:
    """Rolling Hash"""

    __slots__ = ["_length", "_base", "_mod", "_hash", "_power"]

    def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):
        self._length = len(source)
        self._base = base
        self._mod = mod
        self._hash = self._build_hash_from_zero(source)
        self._power = self._build_base_power()

    def _build_hash_from_zero(self, source: str) -> List[int]:
        """Compute hash of interval [0, right)."""
        res = [0] * (self._length + 1)
        for i, c in enumerate(source, 1):
            res[i] = (res[i - 1] * self._base + ord(c)) % self._mod
        return res

    def _build_base_power(self) -> List[int]:
        """Compute mod of power of base."""
        res = [1] * (self._length + 1)
        for i in range(1, self._length + 1):
            res[i] = res[i - 1] * self._base % self._mod
        return res

    def get_hash(self, left: int, right: int):
        """Return hash of interval [left, right)."""
        return (
            self._hash[right] - self._hash[left] * self._power[right - left]
        ) % self._mod


def abc141_e():
    # https://atcoder.jp/contests/abc141/tasks/abc141_e
    N = int(input())
    S = input().rstrip()

    rh = RollingHash(S)
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg = False
        memo = set()
        for i in range(N - 2 * mid + 1):
            memo.add(rh.get_hash(i, i + mid))
            if rh.get_hash(i + mid, i + 2 * mid) in memo:
                flg = True
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter

    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    abc141_e()


Measured memory_bytes: 11264
#include <iostream>
#include <vector>
using namespace std;

long long int getValue(vector<long long int>dp,int index){
    return dp[index]==0?1:dp[index];
}
int main()
{
    long long int  n;
    cin>>n;
    vector<long long int>dp(26,0);
    for(int i=0;i<n;i++)
    {
        string element;
        cin>>element;
        dp[element[0]-'A']++;
    }
    vector<long long int>result;
    result.push_back(dp[12]);
    result.push_back(dp[0]);
    result.push_back(dp[17]);
    result.push_back(dp[2]);
    result.push_back(dp[7]);
    long long int finalresult=0;
    for(int i=0;i<5;i++)
    {
        long long int temp=1;
        for(int j=i+1;j<5;j++)
        {
            for(int k=j+1;k<5;k++)
            {   
                temp=result[i]*result[j]*result[k];
                finalresult+=temp;
            }
            
        }
    }
    cout<<finalresult;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int count = 0;

		for (int i = 1; i <= n.length(); i++) {
			count += Integer.parseInt(n.substring(i-1, i));
		}

		if (count % 9 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}

Measured memory_bytes: 49832
fn main() {
    let n = read::<usize>();

    let v = read_vec::<u32>();
    let d = v[0];
    let x = v[1];

    let mut av = vec![];
    for _ in 0..n {
        let a = read::<u32>();
        av.push(1 + (d - 1) / a);
    }
    let ans = x + av.into_iter().sum::<u32>();
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.util.*
object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val N=readLine()!!.toInt()
    val A=readLine()!!.split(" ").map(String::toLong)
    assert(A.size==N)
    var dictionary:HashMap<Long,Int> =HashMap()
    A.distinct().forEach {dictionary.put(it,0)}
    var candicate:MutableList<Long> = mutableListOf()
    for(a in A) {
      dictionary.put(a,dictionary.get(a)!! + 1)
      if (dictionary.get(a)!! %2==0) {
        candicate.add(a)
      }
    }
    // println(A.filter{a-> A.indexOfFirst {v->v==a}!=A.indexOfLast{v->v==a}}.distinct().sortedDescending().let{ if(it.size<2) {0} else {it[0]*it[1]} })
      println(candicate.sortedDescending().let{ when(it.size) {
        0 -> 0
        1 -> it[0]*it[0]
        else -> it[0]*it[1]
      } })
  }
}


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

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

    int64_t sum = 0;
    for (int i = 0; i < n; i++){
        int64_t num;
        cin >> num;
        sum += num - 1;
    }

    cout << sum << endl;
}

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

int main()
{
	string table[6] = { "abcde", "fghij", "klmno", "pqrst", "uvwxy", "z.?! " };
	string s;
	int a,b;
	while (cin>>s)
	{
		int flg = 1;
		string ans;
		if (s.size()%2)		//??????????????????????\???°?????´???
		{
			cout << "NA" << endl;
		}
		else
		{
			for (int i = 0; i < s.size(); i += 2)
			{
				if ((s[i] < '1') || (s[i] > '6') || (s[i + 1] < '1') || (s[i + 1] > '5'))
				{
					flg = 0;		//??????????????????????????§???????????´???
				}
			}

			if (flg)
			{
				for (int i = 0; i < s.size(); i+=2)		//????????????????????¨????????????????????´???
				{
					a = s[i] - '0'-1;
					b = s[i + 1] - '0'-1;
					ans += table[a][b];
				}
				cout << ans <<endl;
			}
			else
			{
				cout << "NA" <<endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1196
#pragma GCC optimize("Ofast")
#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 ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (true) {
        int H; cin >> H;
        if (!H) break;
        vector<vector<int>> S(H, vector<int>(5));
        rep(i,H) rep(j,5) cin >> S[i][j];

        int ans = 0;
        while (true) {
            bool ok = false;
            rep(i,H) {
                if (S[i][0] && S[i][0] == S[i][1] && S[i][1]==S[i][2] && S[i][2]==S[i][3] && S[i][3]==S[i][4]) {
                    ok = true;
                    ans += 5*S[i][0];
                    rep(j,5) S[i][j] = 0;
                } else if (S[i][0] && S[i][0] == S[i][1] && S[i][1]==S[i][2] && S[i][2]==S[i][3]) {
                    ok = true;
                    ans += 4*S[i][0];
                    rep(j,4) S[i][j] = 0;
                } else if (S[i][1] && S[i][1]==S[i][2] && S[i][2]==S[i][3] && S[i][3]==S[i][4]) {
                    ok = true;
                    ans += 4*S[i][1];
                    rep(j,4) S[i][j+1] = 0;
                } else {
                    rep(j,3) {
                        if (S[i][j] && S[i][j]==S[i][j+1] && S[i][j+1] == S[i][j+2]) {
                            ok = true;
                            ans += 3*S[i][j];
                            rep(k,3) S[i][j+k] = 0;
                        }
                    }
                }
            }

            rep(j,5) {
                for (int i = H-1; i >= 0; --i) {
                    if (S[i][j]==0) {
                        int k = i-1;
                        while (k >= 0 && S[k][j]==0) --k;
                        if (k==-1) break;
                        S[i][j] = S[k][j];
                        S[k][j] = 0;
                    }
                }
            }
            /*
            rep(i,H) {
                rep(j,5) cout << S[i][j] << " ";
                cout << ln;
            }
            cout << ln;
            */
            if (!ok) break;
        }

        cout << ans <<ln;
    }
}


Measured memory_bytes: 3128
n, x = map(int, input().split())

position = 2**(n+2)-3
result = 0
while x > 0:
    position = (position-1)//2
    if x == position*2+1:
        result += position + 1
        x = 0
    elif x == position+1:
        result += position//2 + 1
        x = 0
    elif x > position:
        x -= position
        result += position//2+1
    x -= 1
    position -= 1
print(result)

Measured memory_bytes: 3064
import math
n, d = list(map(int, input().split()))
count = 0
for i in range(n):
  x, y = list(map(int, input().split()))
  z = (x * x) + (y * y)
  #print(z)
  dc = math.sqrt(z)
  #print(dc)
  if dc <= d:
    count += 1
print(count)

Measured memory_bytes: 9204
def read_inputs
  scores = []
  loop do
    n = gets.to_i
    break if n == 0
    scores << Scores.new(gets.split(" ").map(&:to_f))
  end
  scores
end

class Scores
  def initialize(scores)
    @scores = scores
  end

  def standard_deviation
    m = average
    alpha = @scores.reduce(0) {|a, b| a + (b - m) ** 2} / @scores.size
    Math.sqrt(alpha)
  end

  private

  def average
    @scores.reduce(:+) / @scores.size
  end
end

scores = read_inputs
puts scores.map{|s| "%.8f"%s.standard_deviation}.join("\n")

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

using ll = long long;
ll gcd(ll a, ll b) {
   if (b == 0) return a;
   return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
   return a / gcd(a, b) * b;
}

int main() {
   int n;
   cin >> n;
   ll ans = 1;
   for (int i = 0; i < n; i++) {
      ll t;
      cin >> t;
      ans = lcm(ans, t);
   }

   cout << ans << endl;

   return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int64_t D, T, S;

int main() {
  std::cout << std::fixed << std::setprecision(20);


  cin >> D >> T >> S;

  if( (double)((double)D / (double)S) > T ){
    cout << "No" << endl;
    return 0;
  }else{
    cout << "Yes" << endl;
    return 0;
  }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=310;
const int mod=998244353;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,a[N],f[N][N*N];

int main() {
	cin>>n;int sum=0;
	for(int i=1;i<=n;i++) a[i]=gi(),sum+=a[i];
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<N*N;j++)
			if(f[i-1][j]) {
				f[i][j]=(f[i][j]+2ll*f[i-1][j])%mod;
				f[i][j+a[i]]=(f[i][j+a[i]]+f[i-1][j])%mod;
			}
	int ans=0;
	for(int i=(sum+1)/2;i<N*N;i++) ans=(ans+3ll*f[n][i])%mod;
	if(!(sum&1)) {
		memset(f,0,sizeof(f));f[0][0]=1;
		for(int i=1;i<=n;i++)
			for(int j=0;j<N*N;j++)
				if(f[i-1][j]) {
					f[i][j]=(f[i][j]+f[i-1][j])%mod;
					f[i][j+a[i]]=(f[i][j+a[i]]+f[i-1][j])%mod;
				}
		ans=(ans-3ll*f[n][sum/2]%mod+mod)%mod;
	}
	int tmp=1;
	for(int i=1;i<=n;i++) tmp=3ll*tmp%mod;
	cout<<(tmp-ans+mod)%mod;
	return 0;
}


Measured memory_bytes: 116608
using System;

namespace AtCoderABC123
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] antena=new int[5] ;
            for(int i = 0; i < 5; i++) {
                string[] line = Console.ReadLine().Split(' ');
                antena[i] = int.Parse(line[0]);
            }
            string[] line2 = Console.ReadLine().Split(' ');
            int k = int.Parse(line2[0]);

            bool flg = true;

            for(int i=0; i < 5; i++)
            {
                for(int j = i+1 ; j < 5; j++)
                {
                    if (antena[j] - antena[i] > k)
                    {
                        flg = false;
                    }
                }
            }
            if (flg)
            {
                Console.Write("Yay!");
            }else
                Console.Write(":(");
        }
    }
}


Measured memory_bytes: 11092
n = int(input())
k = int(input())
def f(n,k):
  m = len(str(n))
  if n < 10^4:
    s = 0
    for i in range(1,n+1):
      if sum([1 for j in str(i) if j!="0"])==k:
        s += 1
  else:
    if k==1:
      s = n//(10**(m-1)) + 9*(m-1)
    elif k==2:
      s = (n//(10**(m-1))-1)*9*(m-1) + f(n%(10**(m-1)),1) + 9*9*(m-1)*(m-2)//2
    elif k==3:
      s = (n//(10**(m-1))-1)*9*9*(m-1)*(m-2)//2 + f(n%(10**(m-1)),2) + 9*9*9*(m-1)*(m-2)*(m-3)//6
  return s
print(f(n,k))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  string s;
  cin >> s;
  int n = s.size();

  const int MOD = 1e9+7;
  ll dp[100100][4] = {};
  dp[0][0] = 1;
  string abc = "ABC";

  rep(i, n) {
    rep(j, 4) {
      dp[i+1][j] = (dp[i+1][j] + dp[i][j]*(s[i]=='?' ? 3 : 1)%MOD);
    }
    rep(j, 3) {
      if (s[i] == abc[j] || s[i] == '?') {
        dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j])%MOD;
      }
    }
  }
  cout << dp[n][3] << endl;

  //cerr << endl;
  //rep(i, 4) {
  //  rep(j, n+1) cerr << dp[j][i] << " ";
  //  cerr << endl;
  //}
}


Measured memory_bytes: 3664
#include <stdio.h>

long long int gcd(long long int x,long long int y)
{
	if(x<y)return gcd(y,x);
	else return ((x%y==0) ? y : gcd(y,x%y));
}


int main()
{
	long long int a,b,c,d,g,lcm;
	long long int n,m,o=0;
	//nは[a,b]区間中のcで割り切れる整数の個数
	//mは[a,b]区間中のdで割り切れる整数の個数
	
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	a--;
	g=gcd(c,d);
	n=(b/c)-(a/c);
	m=(b/d)-(a/d);
	
	lcm=c*d/g;
	o=(b/lcm)-(a/lcm);
	
	//printf("%lld,%lld,%lld,%lld\n",lcm,n,m,o);
	printf("%lld",((b-a)-n-m+o));
	return 0;
}



Measured memory_bytes: 128
h, w = gets.chomp.split.map { |x| x.to_i }
x = []
h.times do |i|
  z = gets.chomp.split('')
  x.push(z)
end
h.times do |i|
  w.times do |j|
    if x[i][j] == '.'
      c = 0
      c += 1 if i>0 and x[i-1][j] == '#'
      c += 1 if i>0 and j>0 and x[i-1][j-1] == '#'
      c += 1 if i>0 and j<w-1 and x[i-1][j+1] == '#'
      c += 1 if i<h-1 and x[i+1][j] == '#'
      c += 1 if i<h-1 and j>0 and x[i+1][j-1] == '#'
      c += 1 if i<h-1 and j<w-1 and x[i+1][j+1] == '#'
      c += 1 if j>0 and x[i][j-1] == '#'
      c += 1 if j<w-1 and x[i][j+1] == '#'
      x[i][j] = c
    end
  end
end
h.times do |i|
  puts x[i].join("")
end


Measured memory_bytes: 2172
#include <iostream>
#include <vector>
using namespace std;

int N, K;
vector<long long> x;

int main() {
    cin >> N >> K;
    x.resize(N); for (int i = 0; i < N; ++i) cin >> x[i];
    long long res = 1LL<<60;
    for (int i = 0; i + K - 1 < N; ++i) {
        long long left = x[i], right = x[i + K - 1];
        res = min(res, min(abs(left), abs(right)) + right - left);
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


#define REP(i, n) for(int i = 0; i < int(n); ++i)

signed main() {

	int n;
	std::cin >> n;

	std::string s;
	std::cin >> s;

	std::vector<int> w(n + 1, 0);
	std::vector<int> e(n + 1, 0);

	REP(i, n) {
		w[i + 1] = w[i] + (s[i] == 'W');
		e[i + 1] = e[i] + (s[i] == 'E');
	}

	int ans = 1 << 30;
	REP(i, n) {
		int t = e[n] - e[i + 1] + w[i];
		ans = std::min(ans, t);
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll mod = static_cast<ll>(1e9) + 7;

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

    const ll ans = (N / 2) - (N & 1 ? 0 : 1);

    cout << max(0LL, ans) << endl;

    return 0;
}


Measured memory_bytes: 256
while True:
    a,b = input().split()
    if a == b == "0":
        break
    count = 0
    for i in range(4):
        if a[i] == b[i]:
            count += 1
    print(count,end = " ")
    newcount = 0
    for j in range(4):
        if a[j] == b[0] or a[j] == b[1] or a[j] == b[2] or a[j] == b[3]:
            newcount += 1
    print(newcount - count)
    


Measured memory_bytes: 5572
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_A&lang=jp
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b;
  cin>>a>>b;
  if(a<b)printf("a < b\n");
  else if(a>b)printf("a > b\n");
  else printf("a == b\n");
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <utility>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
pair<pair<string,int>,int> p[110];

int main() {
	int n; cin >> n;
	rep(i,n) {
		int t;
		string in;
		cin >> in >> t;
		p[i]=make_pair(make_pair(in,-t),i);
	}
	sort(p,p+n);
	rep(i,n) {
		cout << p[i].second+1 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  char c;cin>>c;
  cout<<(char)(c+1)<<endl;
    return 0;
}

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

int main(void) {
  int r, D, x;
  cin >> r >> D >> x;
  int y=0;
  
  for(int i=1; i<=10; i++){
    y = r*x - D;
    cout << y << endl;
    x=y;
  }
  
  return 0;
}

Measured memory_bytes: 256
A,B,K = map(int,input().split())
a = [A+i for i in range(K)]
b = [B-i for i in range(K)]
ab = a+b
ab = [i for i in ab if A <= i <= B]
ab = sorted(list(set(ab)))
for i in range(len(ab)):
    print(ab[i])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int n;
  ll a[100000], b[100000];
  cin >> n ;
  ll cnt = 0;
  for(int i=0;i<n;i++)
    cin >> a[i] >> b[i];
  for(int i=n-1;i>=0;i--)
    cnt += (b[i] - ((a[i] + cnt) % b[i])) % b[i];
  cout << cnt << endl;  
}

Measured memory_bytes: 1792
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int backup = N;
    int fx = 0;
    while(N>0){
      fx += N%10;
      N = N/10;
    }
    String ans = "No";
    if(backup%fx==0) ans = "Yes";
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
package main

import "fmt"

func main() {
	var K, sum int
	fmt.Scan(&K)
	w := make([][]int, K+1)
	for i := 0; i < len(w); i++ {
		w[i] = make([]int, K+1)
		for j := 0; j < len(w[i]); j++ {
			w[i][j] = gcd(i, j)
		}
	}
	for a := 1; a <= K; a++ {
		for b := 1; b <= K; b++ {
			for c := 1; c <= K; c++ {
				sum += gcd(w[a][b], c)
			}
		}
	}
	fmt.Println(sum)
}
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

int64_t power(int64_t x, int64_t n) {
  int64_t ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}

int64_t rev(int64_t x) {
  return power(x, mod - 2);
}


int main() {
  int N, A[100000];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int64 po = 1;
  for(int i = 1; i <= N; i++) (po *= i) %= mod;

  int64 re[100001] = {};
  for(int i = 0; i < N; i++) re[i] = rev(i + 1);
  for(int i = 1; i < N; i++) (re[i] += re[i - 1]) %= mod;

  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    (ret += A[i] * re[i]) %= mod;
    (ret += A[i] * re[N - i - 1]) %= mod;
    (ret += mod - A[i]) %= mod;
  }
  cout << ret * po % mod << endl;
}


Measured memory_bytes: 1408
#include <stdio.h>

int N, A, B;

int main(void){
        scanf("%d%d%d", &N , &A, &B);
        if(0<N<21&&0<A<51&&0<B<51){
            if(N*A <= B){
                printf("%d\n",N*A);
            }else{
                printf("%d\n",B);
            }
        }
    return 0;
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(){
    int n;
    cin >> n;
    VI vec(n);
    REP(i, n){cin >> vec.at(i);}
    REP(i, n) {dump(vec.at(i))}
    VI vec2(n-1);
    REP(i, n-1){
        vec2.at(i) = vec.at(i + 1);
        
    }
    int maxa  = *max_element(ALL(vec2));
    int maxt = *max_element(ALL(vec));
    int maxtindex = distance(vec.begin(), max_element(ALL(vec)));
    VI vec3(n-1);
    REP(i, n-1){
        if(i < maxtindex){
            vec3.at(i) = vec.at(i);
        }
        if(i >= maxtindex){
            vec3.at(i) = vec.at(i + 1);
        }
    }
    REP(i, n-1){dump(vec3.at(i)) }
    int secmaxt = *max_element(ALL(vec3));
    int secmaxtindex = distance(vec3.begin(), max_element(ALL(vec3)));
    REP(i, n){
        if(i != maxtindex){
            cout << maxt << endl;
        }
        else if(i == maxtindex){
            cout << secmaxt << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 3968
use std::collections::HashMap;

fn main() {
  
  let nk = read::<i64>();
  let a = read::<i64>();
  
  let mut cnts: HashMap<i64, i64> = HashMap::new();
  for x in a {
    if let Some(c) = cnts.get(&x) {
      cnts.insert(x, c+1);
    } else {
      cnts.insert(x, 1);
    }
  }
  let mut cs: Vec<i64> = cnts.values().map(|&x| x).collect();
  cs.sort();
  let m = cs.len();
  let mut sum = 0;
  let mut cnt = 0;
  let l = (m as i64) - nk[1];
  for c in cs {
    if l <= cnt {
      break;
    }
    sum += c;
    cnt += 1;
  }
  println!("{}", sum);
  
}

fn read<T: std::str::FromStr>() -> Vec<T> {
  gets().split_whitespace().filter_map(|s|s.parse().ok()).collect()
}

fn gets() -> String {
  let mut line = String::new();
  std::io::stdin().read_line(&mut line).ok();
  line.trim().to_string()
}


Measured memory_bytes: 12176