akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_BeginnerContest_121
{
    class Program
    {

        struct ShopData
        {
            public long price;
            public int cnt;
        }
        static void Main(string[] args)
        {
            int[] dataArr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int shopCnt = dataArr[0];
            int getCnt = dataArr[1];

            List<ShopData> dataList = new List<ShopData>();

            for (int i = 0; i < shopCnt; i++)
            {
                long[] tmpArr = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                ShopData sd = new ShopData();
                sd.price = tmpArr[0];
                sd.cnt = (int)tmpArr[1];
                dataList.Add(sd);
            }
            dataList.Sort((a, b) => a.price.CompareTo(b.price));

            long retPrice = 0;
            for (int i = 0; i < shopCnt; i++)
            {
                if (dataList[i].cnt < getCnt)
                {
                    retPrice += dataList[i].cnt * dataList[i].price;
                    getCnt -= dataList[i].cnt;
                }
                else
                {
                    retPrice += getCnt * dataList[i].price;
                    break;
                }
            }

            Console.WriteLine(retPrice);

        }
    }
}



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

long long modplus(long long &a,long long &b){
    a=a%1000000007;
    b=b%1000000007;
    a=(a+b)%1000000007;
    return (a+b)%1000000007;
}

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> alphacnt(26,0);
    long long ans=0;
    for(auto c:s){
        long long t=1;
        for (int i = 0; i < 26; ++i) {
            if(c-'a'==i)continue;
            else {
                t=t*(alphacnt[i]+1);
                t=t%1000000007;
            }
        }
        ++alphacnt[c-'a'];
        modplus(ans,t);
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
/* ABC142-A
   Takatan */

#include<stdio.h>
#include<math.h>
int main(void){
    double number, odd;

    scanf( "%lf" , &number); /* 入力 */
    odd = ceil(number/2); /* 奇数の個数を算出 */
    printf( "%f\n" , (odd/number)); /* 出力 */
    return 0;
}

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

int main(){
  char b; cin >> b;
  if(b == 'A') cout << 'T' << endl;
  if(b == 'T') cout << 'A' << endl;
  if(b == 'C') cout << 'G' << endl;
  if(b == 'G') cout << 'C' << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int x;
    cin >> x;
    vi a;
    a.push_back(1);
    rem(i, 2, 32)
    {
        int p = 2;
        //cout << "\n";
        //cout << "i : " << i << "\n";
        while (1)
        {
            int x = pow(i, p);

            //cout << "x : " << x << "\n";
            if (x <= 1000)
            {
                a.push_back(x);
                p++;
            }
            else
                break;
        }
    }

    int ans = -1;
    for (const auto &e : a)
    {
        //cout << "e : " << e << "\n";

        if (e <= x)
        {
            ans = max(e, ans);
            //cout << "ans : " << ans << "\n";
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <complex>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
#define INF 1e9
#define MOD 1e9 + 7
using namespace std;

template<typename T> void cmin(T &a, T b) { a = min(a, b); }
template<typename T> void cmax(T &a, T b) { a = max(a, b); }

using P = complex<double>;
const double PI = acos(-1);
const double EPS = 1e-9;
// P p(a,b)=a+bi -> 点p(a,b)
namespace std {
  bool operator<(const P &a, const P &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); }
  bool operator==(const P &a, const P &b) { return a.real() == b.real() && a.imag() == b.imag(); }
} // namespace std
// i倍すれば反時計回りに90度回転
P turn(P p, double t) { // t度回転
  return p * exp(P(.0, t * PI / 180.0)); //ベクトルにe^θiをかける
}

//内積
double dot(P a, P b) { return real(conj(a) * b); }
//外戚
double cross(P a, P b) { return imag(conj(a) * b); }

//////////////////////////////////////
// 直線(Line) 線分(Segment)          //
// L l(a,b);で直線ab                 //
// l[0]=a l[1]=b                    //
// e.g. L line(P(x1,y1),P(x2,y2));  //
//////////////////////////////////////
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a);
    push_back(b);
  }
};

//円(Circle)
// C c(P(a,b)r); 中心(a,b) 半径rの円
struct C {
  P c;
  double r;
  C(const P &c, double r) : c(c), r(r) {}
};
//点pから直線aに推薦を下ろした足
P projection(L a, P p) {
  double t = dot(p - a[0], a[0] - a[1]) / norm(a[0] - a[1]);
  return a[0] + t * (a[0] - a[1]);
}
//点pを直線aで折り返した点
P reflection(L a, P p) { return p + 2.0 * (projection(a, p) - p); }

signed main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  L line(P(a, b), P(c, d));
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    P p(x, y);
    P ans = reflection(line, p);
    printf("%.10lf %.10lf\n", ans.real(), ans.imag());
  }
  return 0;
}



Measured memory_bytes: 3292
N = int(input())
abc = []
for n in range(N):
    abc.append(list(map(int, input().split())))

# initialize
dp = [[-float("inf")]*3 for i in range(N+1)]
for i in range(3):
    dp[0][i] = 0

# dp    
for i in range(N+1):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            try:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abc[i][k])
            except:
                pass

print(int(max(dp[-1])))


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

typedef long long ll;

int main(void)
{
	std::map<ll, ll> mii;
	int n;
	std::cin>>n;
	ll pref[n+1];
	memset(pref,0,sizeof(pref));
	for(int i=1;i<=n;i++)
	{
		ll t;
		std::cin>>t;
		pref[i] = pref[i-1] + t;
	}
	ll ctr = 0;
	for(int i=1;i<=n;i++)
	{
		mii[pref[i]]++;
		if(!pref[i])
		ctr++;	
	}	
	for(std::map<ll, ll>::iterator it = mii.begin(); it != mii.end(); it++)
	{
		ll t = it->second;
		if(t < 2)
		continue;
		else ctr += (t*t-t)/2;
	}	
	std::cout<<ctr<<"\n";
	return 0;
}

Measured memory_bytes: 14336
import sys
input = sys.stdin.readline

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def main():
    a, b = map(int, input().split())
    print(a // gcd(a, b) * b)
    


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 2000


int main(){
	long long a[N];
	f(i, N)a[i] = 0;
	vector<int>b;
	vector<int>c;
	int n,k;
	long long x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	x = 0;
	y = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		if (a[i] > 0){
			if (i % 2 == 0)x += a[i];
			else y += a[i];
		}
	}
	if (x == 0 && y == 0){
		x = -1000000000000;
		y = 0;
		f(i, n){
			if (x < a[i]){
				x = a[i];
				y = i;
			}
		}
		b.push_back(y);
		z = x;
	}
	else if (x < y){
		z = y;
		f(i, n){
			if (i % 2 == 1){
				if (a[i]>0)b.push_back(i);
			}
		}
	}
	else{
		z = x;
		f(i, n){
			if (i % 2 == 0){
				if (a[i]>0)b.push_back(i);
			}
		}
	}
	k = b.size();
	for (int i = n; i > b[k-1]+1; i--){
		c.push_back(i);
	}
	f(i,b[0]){
		c.push_back(1);
	}
	f(i, k - 1){
		f(j, ((b[i + 1] - b[i]) / 2) - 1){
			c.push_back(3);
		}
		c.push_back(2);
	}
	printf("%lld\n",z);
	printf("%d\n", c.size());
	f(i, c.size()){
		printf("%d\n", c[i]);
	}


	return 0;
}

Measured memory_bytes: 256
a, b, c = map(int,input().split())
array = [a,b,c]
array.sort()
ans = 0
d = array[2] - array[1]
e = array[2] - array[0]
ans += (d // 2) + (e // 2)
if d % 2 == 0 and e % 2 == 0:
    print(ans)
elif d % 2 == 0 or e % 2 == 0:
    print(ans+2)
else:
    print(ans+1)

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskF solver = new TaskF();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskF {
		final int MOD = (int) (1e9 + 7);

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			long[] d = new long[n];
			long[] s = new long[n];
			d[0] = n % MOD;
			s[0] = d[0];
			for (int i = 1; i < n; i++) {
				// Place a "1".
				d[i] = d[i - 1];
				// Place x,y > 1.
				d[i] = (d[i] + (long) (n - 1) * (n - 1) % MOD) % MOD;
				// Place x>1, followed by x ones.
				d[i] = (d[i] + sum(s, i - n - 1, i - 2 - 1)) % MOD;
				s[i] = (s[i - 1] + d[i]) % MOD;
			}
			out.println(d[n - 1]);
		}

		private long sum(long[] s, int l, int r) {
			if (l > r) {
				return 0;
			}
			if (r < 0) {
				return (r - l + 1) % MOD;
			}
			long res;
			if (l < 0) {
				res = sum(s, 0, r) - l;
			} else {
				res = s[r] - (l == 0 ? 0 : s[l - 1]);
			}
			res %= MOD;
			if (res < 0) {
				res += MOD;
			}
			return res;
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 38604
#include "bits/stdc++.h"
using namespace std;

int main(void) {
	int x;
	cin >> x;

	int ans = -1, bp;

	for(int b=1;b<=32;b++) {
		for(int p=2;p<=10;p++) {
			bp = pow(b,p);
			if(bp <= x) ans = max(ans, bp);
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
typedef struct node{
  int p;
  int left;
  int right;
 

}Node;
int D[MAX];
Node node[MAX];
void depth(int,int);
int main(){
  int n,i,num,j,cnum,tmp,l;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    node[i].p=-1;
    node[i].left=-1;
    node[i].right=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d",&num);
    scanf("%d",&cnum);
    for(j=0;j<cnum;j++){
      scanf("%d",&tmp);
      if(j==0){
	node[num].left=tmp;
      }
      else
	{
	  node[l].right=tmp;
	}
      l=tmp;
      node[tmp].p=num;
    }   
  }
  for(i=0;i<n;i++){
    if(node[i].p==-1){
      depth(i,0);
    }
  }
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,node[i].p,D[i]);
    if(node[i].p==-1){
      printf("root, ");
      printf("[");
      for(j=0,tmp=node[i].left;tmp!=-1;tmp=node[tmp].right,j++){
	if(j==0){
	  printf("%d",tmp);
	}
	else printf(", %d",tmp);
      }
      printf("]\n");
    }
    else if(node[i].left==-1){
      printf("leaf, ");
      printf("[]\n");
    }
    else{
      printf("internal node, ");
      printf("[");
      for(j=0,tmp=node[i].left;tmp!=-1;tmp=node[tmp].right,j++){
	if(j==0){
	printf("%d",tmp);
	}
	else printf(", %d",tmp);
      }
      printf("]\n");
    }
  }
 
}
void depth(int u, int p){
  D[u]=p;
  if(node[u].right!=-1){
    depth(node[u].right,p);
  }
  if(node[u].left!=-1){
    depth(node[u].left,p+1);
  }

}



Measured memory_bytes: 6364
#再帰ver

N=int(input())
K=int(input())

from collections import defaultdict
dd = defaultdict(int)


#NN以下，KKが非zero要素を残り使っても良い回数
def rep(NN,KK):
    if KK<0:
        return 0
    
    ha=NN*10+KK
    if dd[ha]!=0:
        return dd[ha]
    
    if NN<0:
        return 0
    
    if NN==0:
        if KK==0:
            return 1
        return 0
        
    
    na=NN//10
    nb=NN%10
    if nb==0:
        dd[ha]=rep(na,KK)+rep(na-1,KK-1)*9
        return dd[ha]
    else:
        dd[ha]=rep(na,KK)+rep(na,KK-1)*nb+rep(na-1,KK-1)*(9-nb)
        return dd[ha]
    
print(rep(N,K))
    






Measured memory_bytes: 38768
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
using namespace std;

long int get_gcd(long int A, long int B)
{
    long int tmp, gcd;

    if (B > A)
        swap(A, B);

    gcd = B;

    tmp = A % gcd;
    while (tmp != 0)
    {
        A = gcd;
        gcd = tmp;
        tmp = A % gcd;
    }

    return gcd;
}


map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main()
{
    long int A, B, gcd, count;
    double MAX;
    count = 1;

    cin >> A >> B;

    gcd = get_gcd(A,B);

    for(auto p : prime_factor(gcd)) count++;

    cout << count << "\n";
 
}

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

int main() 
{
    int n, a[3]; cin >> n >> a[0] >> a[1] >> a[2];
    vector<char> ans;
    vector<string> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        string s = v[i];
        int x = s[0]-'A';
        int y = s[1]-'A';
        if (a[x] > a[y]) swap(x,y);
        if (a[x] == 0 && a[y] == 0) {
            cout << "No\n";
            return 0;
        }
        else if (a[x] < a[y]) {
            ans.push_back('A'+x);
            a[x]++;
            a[y]--;
        }
        else if (a[x] == a[y]) {
            int which = x;
            if (i < n-1 && (v[i+1][0]-'A' == y || v[i+1][1]-'A' == y)) {
                which = y;
            }
            if (which == y) swap(x,y);
            ans.push_back('A'+x);
            a[x]++;
            a[y]--;
        }
        else assert(false);
    }
    cout << "Yes\n";
    for (auto c: ans) {
        cout << c << '\n';
    }
}


Measured memory_bytes: 6740
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


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


    ll tempans = 0;
    ll bits[60]={};
    for(int i=0; i<N; i++){
        ll temp = A[i];
        for(int k=0; k<60; k++){
            bits[k] += temp%2;
            temp/=2;
        }
    }

    for(int i=0; i<60; i++){
        ll temp = ((ll)1<<i);
        temp %= MOD;
        temp *= (bits[i]*(N-bits[i]))%MOD;
        temp %= MOD;
        tempans += temp;
        tempans %= MOD;
    }
    cout<<tempans<<endl;
}

Measured memory_bytes: 2560
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    int n,a;
    cin >> n >> a;
    int arr[a],sum=0;
    fff(i,a) {
    cin >> arr[i];
    sum+=arr[i];
    }
    
    if(sum>=n)
    cout << "Yes";
    else
    cout << "No";

	return 0;
    
}

Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>
using namespace std;

stack <int> st;

int main(void) {
 int cal1,cal2;
 string s;

 while(cin >> s) {
  if(s[0] == '+') {
    cal1 = st.top(); st.pop();
    cal2 = st.top(); st.pop();
    st.push(cal2+cal1);
  } else if(s[0] == '-') {
    cal1 = st.top(); st.pop();
    cal2 = st.top(); st.pop();
    st.push(cal2-cal1);
  } else if(s[0] == '*') {
    cal1 = st.top(); st.pop();
    cal2 = st.top(); st.pop();
    st.push(cal2*cal1);
  } else if(s[0] == ' ') {
    continue;
  } else {
    st.push(atoi(s.c_str()));
  }
 }
 cout << st.top() << endl;
 return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e6;

int main()
{
    int n;
    cin>>n;
    int l[n];
    int sum=0;
    rep(i,n)
    {
        cin>>l[i];
        sum+=l[i];
    }
    sort(l,l+n);
    if(sum-l[n-1]>l[n-1])
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())

if a<=0<=b:
    X=[a,0,b]
else:
    X=[a,b]

if c<=0<=d:
    Y=[c,0,d]
else:
    Y=[c,d]

M=[x*y for x in X for y in Y]
print(max(M))


Measured memory_bytes: 61848
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int X;
  cin >> X;
  rep(i, X + 1)
  {
    int rest = X - i * 100;
    if (0 <= rest && rest <= 5 * i) // 100n <= X <= 100n + 5nであればいい
    {
      cout << 1 << endl;
      return 0;
    }
    if (rest < 0)
      break;
  }
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int MAX = 100;
typedef pair<int,int> P;

int n;
int in[MAX][MAX];
P ans[MAX][MAX];

void row(int m){
  int s = (1<<20);

  for(int i = 0; i < n; i++)
    s = min(s,in[m][i]);

  for(int i = 0; i < n; i++)
    if(s == in[m][i]) ans[m][i].first = true;

    
}
void column(int m){

  int l = -1;

  for(int i = 0; i < n; i++)
    l = max(l,in[i][m]);

  for(int i = 0; i < n; i++)
      if(l == in[i][m]) ans[i][m].second = true;

}

void init(){
  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++)
      ans[i][j] = P(false,false);

}
int main(){
  while(cin >> n && n){
    init();
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
	cin >> in[i][j];


    for(int i = 0; i < n; i++){
      row(i);
      column(i);
    }

    vector<int> V;

    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
	if(ans[i][j] == P(true,true)) V.push_back(in[i][j]);

    if(V.size() == 0) cout << "0" << endl;
    else if(V.size() == 1) cout << V[0] << endl;
    else{
      sort(V.begin(),V.end());
      vector<int> :: iterator ite = V.begin();
      while(ite != V.end()){
	cout << *ite << endl;
	ite = upper_bound(V.begin(),V.end(),*ite);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1304
#include <iostream>
#include <iterator>
#include <algorithm>
#include <map>
using namespace std;


int main(void){
    // Your code here!
    char a;
    cin >> a;
    if(a == 'A'){
        cout << "T";
    }else if(a == 'C'){
        cout << "G";
    }else if(a == 'G'){
        cout << "C";
    }else if(a == 'T'){
        cout << "A";
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        ll t,a;
        t=a=1;
        rep(i,n){
            ll T,A;
            cin>>T>>A;
            ll x=max((T+t-1)/T,(a+A-1)/A);
            t=T*x;
            a=A*x;
        }
        cout<<a+t<<endl;
    }

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n,i,t;
    scanf("%d",&n);
    for(i=100000;n>0;n--){
        i*=1.05;
        t=i%1000;
        if(t>0){
            i=i+1000-t;
        }
    }
    printf("%d\n",i);
}

Measured memory_bytes: 1860
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
  n <- readInt
  a <- readInts
  print $ maximum a - minimum a

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(auto i=0; i<(n); i++)

const int mod = 1000000007;

int a[505][505];

int h,w;
pair<int, int> next(int x, int y) {
  if (x%2 == 0) {
    if (y == w-1) {
      return {x+1, y};
    } else {
      return {x, y+1};
    }
  } else {
    if (y == 0) {
      return {x+1, y};
    } else {
      return {x, y-1};
    }
  }
}

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

  cin >> h >> w;

  rep(i, h) rep(j, w) {
    cin >> a[i][j];
  }

  int res = 0;
  vector<pair<pair<int, int>, pair<int, int>>> resV;

  pair<int, int> p = {0, 0};
  pair<int, int> p_n = next(p.first, p.second);
  while(p_n.first < h) {
    if (a[p.first][p.second]%2) {
      a[p.first][p.second]--;
      a[p_n.first][p_n.second]++;
      res++;
      resV.push_back({{p.first+1, p.second+1}, {p_n.first+1, p_n.second+1}});
    }
    p = p_n;
    p_n = next(p.first, p.second);
  }


  cout << res << endl;
  rep(i, res) {
    printf("%d %d %d %d\n", resV[i].first.first, resV[i].first.second, resV[i].second.first, resV[i].second.second);
  } 
}


Measured memory_bytes: 5232
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,j,len,n;
	char s[11],a[11];
	scanf("%s",s);
	len=strlen(s);
	j=0;
	for(i=0;i<len;i++){
		if(s[i]=='0'||s[i]=='1'){
			a[j]=s[i];
			j++;
		}
		else if(j>0){
			j--;
		}
	}
	for(i=0;i<j;i++){
		printf("%c",a[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
int n,m;
int a[100001];
int fa[100001];
int us[100001],val[100001],num[100001],re[100001],p,cnt;
int gf(int x){return fa[x]==x?x:(fa[x]=gf(fa[x]));}
long long ans=0;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1,x,y;i<=m;i++) scanf("%d%d",&x,&y),x++,y++,fa[gf(y)]=gf(x);
	for(int i=1;i<=n;i++) if(fa[i]==i) cnt++;
	if(n<cnt*2-2) return !puts("Impossible");
	if(cnt==1) return !puts("0");
	for(int i=1;i<=n;i++) val[i]=2147483647;
	for(int i=1;i<=n;i++){
		int x=gf(i);
		if(a[i]<val[x]) val[x]=a[i],num[x]=i;
	}
	for(int i=1;i<=n;i++){
		if(val[i]<2147483647) ans+=1ll*val[i];
		if(num[i]) us[num[i]]=1;
	}
	for(int i=1;i<=n;i++) if(!us[i]) re[++p]=a[i];
	std::sort(re+1,re+p+1);
	for(int i=1;i<=cnt-2;i++) ans+=1ll*re[i];
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

string A, B, C;

int main(){

	cin >> A >> B >> C;
	
	if (A[A.length() - 1] == B[0] && B[B.length()-1] == C[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,a[1001],cnt=0,f=0;
  long int s=0;
  cin>>N>>M;
  for(int i=1;i<=N;i++)
  {
    cin>>a[i];
    s+=a[i];
  }
  
  for(int i=1;i<=N;i++)
  {  if (a[i]>=((float)s/(4*M)))
   { cnt++;
      if(cnt==M){f=1;break;}}
  }

  if (f==1)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


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

int main() {
	// your code goes here
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a.at(i);
	}
	int usable = 0;
	int pos = 0; //今参照してる場所の記録用
	for(int i=1; i<=n; i++){ //iは探す対象
		bool f = false;
		for(int j=pos; j<n; j++){ //前から順番に参照していく
			if(a.at(j) == i){ //発見したら
				pos = j+1;
				f = true;
				usable = i;
				break;
			}
			
		}
		if(f == false && i==1){
			cout << -1 << endl;
			return 0;
		}
		else if(f == false){break;}
	}
	cout << n - usable << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  bool reverse_ = false;
  int Q,F,T;
  string s;
  cin >> S;
  cin >> Q;
  for(int i = 0;i < Q;i++){
  	cin >> T;
    if(T == 1){
      reverse_ = !reverse_;
      continue;
    }else if(T == 2){
      cin >> F >> s;
      if(F == 1 && !reverse_ || F == 2 && reverse_){
      	S.insert(0,s);
      }else if(F == 1 && reverse_ || F == 2 && !reverse_){
      	S.append(s);
      }
    }
  }
  if(reverse_) reverse(S.begin(),S.end());
  
  cout << S << endl;
}

Measured memory_bytes: 900
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

typedef pair<int, int> P;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int W, H;
vector<string> field;

int main() {
	while (cin >> W >> H, W || H) {
		field = vector<string>(H);
		vector<P> targets;
		P pos;
		for (int i = 0 ; i < H; i++) {
			cin >> field[i];
			for (int j = 0; j < W; j++) {
				if (field[i][j] == '*') {
					targets.emplace_back(j, i);
				}
				else if (field[i][j] == 'o') {
					pos = P(j, i);
				}
			}
		}

		int ans = -1;
		queue<pair<P, P>> que;
		que.push(make_pair(P(0, 0), pos));
		bool visited[W][H][1<<11];
		memset(visited, 0, sizeof(visited));
		while (!que.empty()) {
			auto& cur = que.front();
			int step = cur.first.first;
			int bit = cur.first.second;
			int x = cur.second.first;
			int y = cur.second.second;
			que.pop();
			if (visited[x][y][bit]) continue;
			visited[x][y][bit] = true;
			if (bit == (1 << (targets.size())) - 1) {
				ans = step;
				//cout << bit << endl;
				break;
			}
			for (int i = 0; i < 4; i++) {
				int nx = x + dx[i];
				int ny = y + dy[i];
				if (!(0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] != 'x')) continue;
				int nbit = bit;
				if (field[ny][nx] == '*') {
					nbit = nbit | (1 << (find(targets.begin(), targets.end(), P(nx, ny)) - targets.begin()));
				}
				for (int i = 0; i < targets.size(); i++) {
					que.push(make_pair(P(step + 1, nbit), P(nx, ny)));
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 5280
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

class SegmentTree:
  __slots__ = ['ide','n','seg','segfunc']

  def __init__(self,size,func,element):
    self.segfunc = func
    self.ide = element
    # self.size = sizeを超える最小の2冪の数
    self.n = 2 ** (n-1).bit_length()
    # 全てのnodeの数は(2*n-1)個
    # 上にn-1個,最下段にn個
    self.seg = [self.ide] * (2*self.n-1)

  def apply(self,array):
    arraysize = len(array)
    # 配列埋め込み
    for i in range(arraysize):
      self.seg[self.n-1+i] = array[i]
    # 上にあげる
    for i in range(self.n-2,-1,-1):
      self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2])

  def update(self,k,x):
    k += self.n -1
    self.seg[k] = x
    while k:
      k = (k-1)//2
      self.seg[k] = self.segfunc(self.seg[2*k+1],self.seg[2*k+2])

  def query(self,l,r):
    # 半開区間[l,r)
    l += self.n-1; r += self.n-1
    vl = vr = self.ide
    while l < r:
      if l & 1 == 0:
        vl = self.segfunc(vl,self.seg[l])
        l += 1
      if r & 1 == 0:
        vr = self.segfunc(vr,self.seg[r-1])
      l = (l-1)//2; r = (r-1)//2
    return self.segfunc(vl,vr)

  def query2(self, p, q):
      if q <= p:
          return self.ide
      p += self.n - 1
      q += self.n - 2
      res = self.ide
      while q - p > 1:
          if p & 1 == 0:
              res = self.segfunc(res, self.seg[p])
          if q & 1 == 1:
              res = self.segfunc(res, self.seg[q])
              q -= 1
          p = p // 2
          q = (q - 1) // 2 
      if p == q:
          res = self.segfunc(res, self.seg[p])
      else:
          res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
      return res
    

def segor(a,b):
  return a|b

n = int(input())
st = SegmentTree(n,segor,0)
S = input()
data = [0] * n
for i,si in enumerate(S):
  k = ord(si)-ord("a")
  data[i] = 1 << k
st.apply(data)
Q = int(input())
for _ in range(Q):
  typo,a,b = input().split()
  if typo == "1":
    st.update(int(a)-1,1 << (ord(b)-ord("a")))
  if typo == "2":
    print(bin((st.query2(int(a)-1,int(b))))[2:].count("1"))
  


Measured memory_bytes: 76164
#include <bits/stdc++.h>
#include<unordered_map>
#define lli long long int
using namespace std;

int main() {

	std::ios::sync_with_stdio(0);
	std::cin.tie(0);

	//freopen("text.in", "r", stdin);
	//freopen("text.out", "w", stdout);
	
	int a[(int)2e5 + 1], n;
	cin >> n;
	int max = 0, place = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (a[i] > max) {
			max = a[i];
			place = i;
		}
	}
	if (n == 1)return cout << a[0] << '\n', 0;
	for (int i = 0; i < n; ++i) {
		if (i != place)cout << max << " ";
		else {
			int temp = max;
			a[i] = 0;
			cout << *max_element(a + 0, a + n) << " ";
			a[i] = temp;
		}
	}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 2432
from copy import copy
import numpy as np
N,S=map(int,input().split())
A=list(map(int,input().split()))
dp=np.zeros(S+100,np.int64)
dp[0]=1
for i in range(N):
    buf=copy(dp)
    dp=2*dp
    dp[A[i]:]+=buf[:-A[i]]
    dp%=998244353
print(dp[S]%998244353)


Measured memory_bytes: 27504
#include<bits/stdc++.h>
using namespace std;
#define int long long
main()
{
    int n;
    cin>>n;
    int a[n+5],ans=0;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        while(a[i]%2==0)
        {
            a[i]/=2;
            ans++;
        }

    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3720
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int main()
{
	int n,k;
	while(cin>>n>>k,n)
	{
		int b[k],t;
		rep(i,k)cin>>b[i];
		rep(i,n)rep(j,k)cin>>t,b[j]-=t;
		rep(i,k)if(b[i]<0)
		{
			cout<<"No"<<endl; goto END;
		}
		cout<<"Yes"<<endl; END:;
	}
	
	return 0;
}

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

signed main() {
  string s;
  cin >> s;
  for (int i = s.size()-1; i > 6; i--) {
    if (s[i-7] == 'F' && s[i-6] == 'E' && s[i-5] == 'S' && s[i-4] == 'T' && s[i-3] == 'I' && s[i-2] == 'V' && s[i-1] == 'A' && s[i] == 'L') {
      for (int j = 0; j < s.size()-8; j++) {
	cout << s[j];
      }
      cout << endl;
      break;
    }
  }
  
  return 0;
}


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

int main(){
    int n;cin>>n;
    map<int,int> m;
    
    int a;
    for(int i=0; i<n; i++){
        cin>>a;
        m[a]++;
    }
    
    vector<int> b(1000001,0);
    int ans = 0;
    for(auto p : m){
        int x = p.first;
        int c = p.second;
        for(int i=x; i<=1000000; i+=x){
            b[i] += c;
        }
        if(b[x]==1)ans++;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16240
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  char b;
  cin >> b;
  unordered_map<char,char> mp;
  mp['A'] = 'T';
  mp['T'] = 'A';
  mp['C'] = 'G';
  mp['G'] = 'C';

  cout << mp[b] << endl;
  return 0;
}


Measured memory_bytes: 256
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');
let input = '';

process.stdin.on('data', function(chunk) {
  input += chunk;
}).on('end', function() {
  input = input.trim().split(" ").map(v => parseInt(v));
  const N = input[0];
  const L = input[1];
  const array = [];
  for (let i = 0; i < N; i++) {
    array[i] = L + i;
  }
  let tmp = 0;
  for (let i = 0; i < N; i++) {
    tmp = Math.abs(array[tmp]) > Math.abs(array[i]) ? i : tmp;
  }
  const sum = array.reduce((pre, curr) => pre + curr, 0);
  const result = sum - array[tmp];
  console.log(result);
});

Measured memory_bytes: 7500
#include <bits/stdc++.h> // for sorting 
#include <iostream> 
typedef long long int ll;
using namespace std; 
#define mod 1000000007

ll maxProductSubarrayOfSizeK(ll A[], ll n, ll k) 
{ 
	sort(A, A + n); 
	ll product = 1; 
    if (A[n - 1] == 0 && (k & 1)) 
		return 0; 
    if (A[n - 1] <= 0 && (k & 1)) { 
		for (int i = n - 1; i >= n - k; i--) {
			product *= A[i]%mod; product%=mod;} 
		return product%mod; 
	} 
    int i = 0; 
	int j = n - 1; 
	if (k & 1) { 
		product *= A[j]; 
		product%=mod;
		j--; 
		k--; 
	} 
	k >>= 1; 

	for (int itr = 0; itr < k; itr++) { 

		// product from left pointers 
		ll left_product = A[i] * A[i + 1]; 

		// product from right pointers 
		ll right_product = A[j] * A[j - 1]; 

		if (left_product > right_product) { 
            left_product%=mod;
			product *= left_product; 
			product%=mod;
			i += 2; 
		} 
		else { 
            right_product%=mod;
			product *= right_product; 
			product%=mod;
			j -= 2; 
		} 
	} 

	// Finally return product 
	return product%mod;
} 

// Driver Code to test above function 
int main() 
{ 
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
 	cout << (maxProductSubarrayOfSizeK(arr, n, k)+mod)%mod; 

	return 0; 
} 


Measured memory_bytes: 5160
l, r = map(int, input().split())
d = (r -l)%2019
if r -l >=2018:
    print(0)
    exit(0)
ans = 2018
l = l%2019
for i in range(l, l+d):
    for j in range(i+1, l+d+1):
        if (i*j)%2019 < ans:
            ans =(i*j)%2019
print(ans)

Measured memory_bytes: 9132
//#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
//#include <string.h>
using namespace std;

int main(){
    int k,n;
    cin >>k>>n;
    vector<int>a(n);
    rep(i,n)
    cin >>a.at(i);
    int start =0;
    int max = k-a[n-1]+a[0];
    for(int i=1;i<n;i++){
        int x = a[i]-a[i-1];
        if(x > max){
            max = x;
            start = i;
        }
    }

    cout << k-max << endl;
    
    
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;

bool check(int N, vector<int> digit) {
	while(N!=0) {
		if(digit[N%10] == 1) return false;
		N /= 10;
		
	}
	return true;
}


int main() {
	int N, K;
	cin >> N >> K;
	vector<int> digit(10, 0);
	vector<int> input;
	for(int i=0; i<K; i++) {
		int p;
		cin >> p;
		digit[p] = 1;
	}
	
	for(int i=N; ; i++){
		if(check(i, digit)) {
			cout << i << endl;
			return 0;
		}
 		
	}
	
	return 0;
	
	return 0;
}


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

#define EPS (1e-7)
#define INF (99999999999L)
#define PI (acos(-1))

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

using ll = long long;

int main() {
  int n; cin >> n;
  vector<ll> a(n), b(n);
  REP(i,n) cin >> a[i] >> b[i];
  ll ans = 0;
  for (int i = n-1; i >= 0; --i) {
    if ((a[i]+ans)%b[i] == 0) continue;
    ans += b[i] - (a[i]+ans)%b[i];
  }
  cout << ans << endl;
  return 0;
}


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

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

  vector<long long> m(5);
  for(int i = 0;i < 5;i++){
    cin >> m[i];
  }

  sort(m.begin(),m.end());

  long long ret = 5 + n/m[0];
  if(n%m[0] == 0)ret--;

  cout << ret << endl;
}

  



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int n;
	cin >> n;
	int a[n+1]={};
	for(int i=1; i<n+1; i++){
		cin >> a[i];
	}
	int m=0;
	int cnt = 0;
	int b[200010]={};
	for(int i=n; i>0; i--){
		for(int j=i; j<=n; j+=i){
			cnt += b[j];
		}
		cnt %= 2;
		if(a[i]!=cnt){
			b[i] = 1;
			m++;
		}
		cnt = 0;
	}
	cout << m << endl;
	for(int i=1; i<n+1; i++){
		if(b[i]) cout << i << endl;
	}
}

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

using namespace std;

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a == 1) a = 14;
	if (b == 1) b = 14;
	if (a > b) printf("Alice");
	else {
		if (a < b) printf("Bob");
		else printf("Draw");
	}
	return 0;
}

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

int main(){
    int n, i, sum = 0;
    int *a, *b, *c;
    scanf("%d", &n);
    a = (int *)malloc(n * sizeof(int));
    b = (int *)malloc(n * sizeof(int));
    c = (int *)malloc((n - 1) * sizeof(int));
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    };
    for(i = 0; i < n; i++){
        scanf("%d", &b[i]);
    };
    for(i = 0; i < (n - 1); i++){
        scanf("%d", &c[i]);
    };
    sum += b[a[0] - 1];
    //printf("%d", b[a[0] - 1]);
    /*for(i = 0; i < n; i++){
        printf("a[%d] = %d, b[%d] = %d c[%d] = %d\n", i, a[i], i, b[i], i, c[i]);
    }*/
    //printf("sum = %d\n", sum);
    for(i = 1; i < n; i++){
        sum += b[(a[i] - 1)];
        //printf("%d turn : sum = %d\n", i, sum);
        if(a[i] - a[i - 1] == 1){
            sum += c[a[i - 1] - 1];
            //printf("** add = %d, sum = %d\n", c[a[i - 1] - 1], sum);
        }
    }
    printf("%d", sum);
}

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

int main()
{
    //freopen("a.inp","r",stdin);
    int a, b, ans = 2019;
    cin >> a >> b;
    b = min(2019, b - a/2019 * 2019);
    a%= 2019;
    for(int i=a; i<b; ++i) for(int j=i+1; j<=b; ++j)
        ans = min(ans, (i*j) % 2019);
    cout << ans;
}


Measured memory_bytes: 256
n=int(input())
m=len(str(n))
r=0

def dfs(i,s):
    global r
    if len(set(s))==3 and int(s)<=n:
        r+=1
    if i==m:
        return
    dfs(i+1,'3'+s)
    dfs(i+1,'5'+s)
    dfs(i+1,'7'+s)

dfs(0,'')
print(r)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    string s;
    cin >> s;

    printf("%c", s[0]);
    int cnt = s.size() - 2;
    printf("%d", cnt);
    printf("%c\n", s[s.size() - 1]);
    return (0);
}

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

int main (void) {
    int n;
    int f[100002] = {};
    int a, i;
    int max=0;

    scanf("%d", &n);

    for ( i = 0 ; i < n ; i++ ) {
        scanf("%d" , &a);
        f[a] ++;
    }


    for ( i = 1 ; i < 100000 ; i++ ) {
        a = f[i-1] + f[i] + f[i+1];
        if ( a > max ) max = a;
    }

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


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

int main(){
  int64_t N, K;
  cin >> N >> K;
  vector<vector<int64_t>> vec(N, vector<int64_t>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  
  sort(vec.begin(),vec.end());
  
  int64_t cnt = 0;
  for(int k=0; k<N; k++){
    cnt += vec.at(k).at(1);
    if(cnt >= K){
      cout << vec.at(k).at(0);
      break;
    }
  }
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if(a >= 13)
  {
    cout << b << endl;
  }
  else if(a <= 5)
  {
    cout << 0 << endl;
  }
  else
  {
    cout << b/2 << endl;
  }
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
ans = float('inf')
for c_2 in range(10**5 + 1):
    a = max(X - c_2, 0)
    b = max(Y - c_2, 0)
    ans = min(ans, a * A + b * B + c_2 * C * 2)
print(ans)

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

/**
 * Print out Array with a template.
 */
template <class T>
void printArray(T Array, int N)
{
    for (int i = 0; i < N; ++i)
    {
        if (i > 0) cout << " ";
        cout << Array[i];
    }
    cout << endl;
}

/**
 * Swap the value of a and b.
 */
void swap(int & a, int & b)
{
    int tmp = a;
    a = b;
    b = tmp;
}

/**
 * SelectionSort
 * From start to the end, each turn gets the minimum value
 * at the right position.
 * @param A [Array]
 * @param N [Size of the array]
 */
void selectionSort(int A[], int N)
{
    int exchange_count = 0;
    for (int i = 0; i < N; ++i)
    {
        int min_index = i;
        for (int j = i; j < N; ++j)
        {
            if (A[j] < A[min_index])
            {
                min_index = j;
            }
        }
        if (i != min_index)
        {
            exchange_count++;
            swap(A[i], A[min_index]);
        }
    }
    printArray(A, N);
    cout << exchange_count << endl;
}

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

    selectionSort(A, N);

    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <tuple>
#include <cmath>
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;

vector<int> G[100000];
int color[100000];//0:empty,1:black,-1:white
int N;

void dfs2(int v, int pre, int col){
    color[v]=col;
    for(auto to:G[v]){
        if(to!=pre&&color[to]==0) dfs2(to,v,col);
    }
    return;
}

int dfs1(int v, int pre, int depth){
    if(v==N-1){
        color[v]=-1;
        for(auto to:G[v]){
            if(to!=pre) dfs2(to,v,-1);
        }
        return depth;
    }
    if(G[v].size()==1&&v!=0) return -1;
    for(auto to:G[v]){
        if(to!=pre){
            int length = dfs1(to,v,depth+1);
            if(length!=-1){
                int col;
                if(depth<=length/2){
                    col=1;
                }else{
                    col=-1;
                }
                // cout<<v+1<<' '<<col<<endl;
                color[v]=col;
                for(auto to2:G[v]){
                    if(to2!=pre&&color[to2]==0) dfs2(to2,v,col);
                }
                return length;
            }
        }
    }
    return -1;
}

int main(){
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs1(0,-1,0);
    int cnt = 0;
    for(int i=0;i<N;i++){
        // cout<<i+1<<' '<<color[i]<<endl;
        cnt+=color[i];
    }
    // cout<<cnt<<endl;
    if(cnt>0){
        cout<<"Fennec"<<endl;
    }else{
        cout<<"Snuke"<<endl;
    }

    return 0;
}

Measured memory_bytes: 15488
#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;

int main(){
	int n, num[] = {0,1,2,3,5,7,8,9};
	while(cin >> n, n) {
		long long a=0, d=1;
		while(n) {
			a += num[n%8]*d;
			d *= 10;
			n /= 8;
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 1156