akhauriyash/Code-Regression huggingface dataset:
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
    t = readline() |> split |> parseMap
    m = readline() |> parseInt
    at = sum(t)
    for i in 1:m
    	p,x = readline() |> split |> parseMap
    	println(at-t[p]+x)
    end
end

main()

Measured memory_bytes: 110836
#include<iostream>
#include<algorithm>

using namespace std;

const int MAX = 301;
const int UMAX = 1001;
typedef pair<int,int> P;

struct team{
  int I,U,A,P;
  bool passed;
};

int UNUM[UMAX],pass,n;
team T[MAX];
P p[3] = {P(10,3),P(20,2),P(26,1)};

void T_sort(){

  for(int i = 0; i < n; i++)
    for(int j = i; j < n; j++)
      if(T[i].A < T[j].A || (T[i].A == T[j].A && T[i].P > T[j].P) ||
	 (T[i].A == T[j].A && T[i].P == T[j].P && T[i].I > T[j].I))
	swap(T[i],T[j]);
}

void solve(){
  
  for(int R = 0; R < 3; R++)
    for(int i = 0; pass < p[R].first && i < n; i++){
      if(T[i].passed == false && UNUM[T[i].U] < p[R].second){
	cout << T[i].I << endl;
	T[i].passed = true;
	UNUM[T[i].U]++;
	pass++;
      }
    }
}

void init(){
  pass = 0;
  fill(UNUM,UNUM+UMAX,0);
}
int main(){
  while(cin >> n && n){
    init();
    for(int i = 0; i < n; i++){
      cin >> T[i].I >> T[i].U >> T[i].A >> T[i].P;
      T[i].passed = false;
    }
    T_sort();
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
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;}

ll all_num[51];
ll p_num[51];

void func(){
    rep(i, 51){
        if(i == 0){
            all_num[0] = 1;
            p_num[0] = 1;
        }else{
            all_num[i] = all_num[i-1]*2+3;
            p_num[i] = p_num[i-1]*2 + 1;
        }
    }
}

ll cal(ll N,ll X){
    if(N == 0){
        if(X == 1) return 1;
        if(X == 0) return 0;
    }
    /*
    B
    N-1
    P
    N-1
    B
    */
    if(X == 1){ return 0 ;}
    else if(1 < X && X <= (1 + all_num[N-1])){return cal(N-1, X-1);}
    else if(X == (2 + all_num[N-1])){return 1LL + p_num[N-1];}
    else if( (2 + all_num[N-1]) < X && X <= (2 + 2*all_num[N-1])){return p_num[N-1] + 1LL + cal(N-1, X-2-all_num[N-1]);}
    else if( X == (3 + 2*all_num[N-1])){return p_num[N];}

}

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

    func();
    ll N , X;
    cin >> N >> X;

    ll ans = cal(N,X);

    cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n;
	cin>>n;
	if(n==2){
		cout << 1;
		return 0;
	}
	ll ans=2;
	for(ll i=2;i<=sqrt(n);i++){
		ll mod=i;
		ll now;
			now=n;
			ll mod2=i;
			while(now%mod==0){
				now/=mod;
			}
			if(now%mod==1){
				ans++;
			}
			mod=n/i;
			if(mod2!=mod){
			now=n;
			while(now%mod==0){
					now/=mod;
			}
			if(now%mod==1){
				ans++;
			}			
			}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m=1000000000;
  cin>>n;
  for(int i=1;i<=n/2;i++){
    int j=n-i,k=i,c=0;
    while(j!=0){
      c+=j%10;
      j/=10;
    }
    while(k!=0){
      c+=k%10;
      k/=10;
    }
    m=min(c,m);
  }
  cout<<m;
}

Measured memory_bytes: 256
s = input()
Q = int(input())
reverse = False
top = []
bottom = []
for _ in range(Q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        reverse = not reverse
    else:
        if (reverse and query[1] == "1") or (not reverse and query[1] == "2"):
            bottom.append(query[2])
        else:
            top.append(query[2])

ans = "".join(reversed(top)) + s + "".join(bottom)
if reverse:
    print(ans[::-1])
else:
    print(ans)

Measured memory_bytes: 6284
import java.util.Scanner;

public class Main {

	final static int Row = 12;
	final static int Col = 12;
	
	static int[][] field = new int[Row+2][Col+2];
	
	enum Direction{
		Right(0,1),Down(1,0),Left(0,-1),Up(-1,0);
		
		int r,c;
		
		Direction(int r,int c){
			this.r=r;
			this.c=c;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while( sc.hasNext()) {
			for(int r=1;r<=Row;r++) {
				String str=sc.nextLine();
				if("".equals(str))str=sc.nextLine();
				char[] value = str.toCharArray();
				for(int c=1;c<=Col;c++) {
					field[r][c]=Character.getNumericValue(value[c-1]);
				}
			}
			System.out.println(CountIslands());
			
		}
	}
	
	static int CountIslands(){
		int islandCount=0;
		for(int r=1;r<=Row;r++) {
			for(int c=1;c<=Col;c++) {
				if(FourDirectionSearch(r,c)) {
					islandCount++;
				}
			}
		}
		return islandCount;
		
	}
	
	static boolean FourDirectionSearch(int r,int c){
		if(field[r][c]==1) {
			field[r][c]=0;
			
			for(Direction d:Direction.values()) {
				FourDirectionSearch(r+d.r,c+d.c);
			}
			
			return true;
		}
		return false;
		
	}

}



Measured memory_bytes: 26432
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    long N, count;
    cin >> N;

    int max = N;
    count = sqrt(N);

    for (int i = 1; i <= count; i++)
    {
        if (N % i == 0)
        {
            max = N / i;
        }
    }

    string str = to_string(max);
    cout << str.size() << endl;
    return 0;
}


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

using namespace std;

int main(){
	int x, y, s;
	while(cin>>x>>y>>s, x|y|s){
		int ans = 0;
		for(int i=1; i<s; i++){
			int p, q;
			for( p = (i * 100) / (100+x) -1; p*(100+x)<(i+1)*100; p++);
			p--;
			for( q = ((s-i) * 100) / (100+x) -1; q*(100+x)<(s-i+1)*100; q++);
			q--;
			if( p*(100+x)/100 + q*(100+x)/100 != s ) continue;
			int _p = p * (100+y) / 100;
			int _q = q * (100+y) / 100;
			ans = max(ans, _p+_q);
//			cout << p << " " << q << " " << _p+_q <<  endl;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int n,m;

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

  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    if(i<n/2-1+n%2)cout<<0;
    else cout<<m;
  }
  
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3080
n=int(input())
a=list(map(int,input().split()))
count=0
countall=0
hflag=0
tflag=0
gflag=0
wflag=0
bflag=0
yflag=0
dflag=0
rflag=0
for i in a:
    if 1<= i <=399 and hflag==0:
        count+=1
        hflag=1
    elif 400 <=i<=799 and tflag==0:
        count+=1
        tflag=1
    elif 800<=i<=1199 and gflag==0:
        count+=1
        gflag=1
    elif 1200<=i<=1599 and wflag==0:
        count+=1
        wflag=1
    elif 1600<=i<=1999 and bflag==0:
        count+=1
        bflag=1
    elif 2000<=i<=2399 and yflag==0:
        count+=1
        yflag=1
    elif 2400<=i<=2799 and dflag==0:
        count+=1
        dflag=1
    elif 2800<=i<=3199 and rflag==0:
        count+=1
        rflag=1
    elif i>=3200:
        countall+=1
if count==0:
    print("{} {}".format(1,count+countall))
else:
    print("{} {}".format(count,count+countall))

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

int cmpnum(const void * n1, const void * n2)
{
	if (*(int *)n1 > *(int *)n2)
	{
		return -1;
	}
	else if (*(int *)n1 < *(int *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  qsort(a, n, sizeof(int), cmpnum);
  int alice = 0;
  int bob = 0;
  for (int i = 0; i < n; i++) {
    if (i%2 == 0) {
      alice += a[i];
    } else {
      bob += a[i];
    }
  }
  printf("%d\n", alice-bob);

  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int f[210000000];
int main(void)
{
	int a,s,d[1000],high,low,ba,naka,nokori,kore,g,h,i,j,z,x,c,v;
	while(1){
		scanf("%d %d",&a,&s);
		if(a==0&&s==0)
			break;
		d[0]=0;
		for(i=1;i<=a;i++){
			scanf("%d",&d[i]);
		}
		g=0;
		for(i=0;i<=a;i++){
			for(j=i;j<=a;j++){
				f[g]=d[i]+d[j];
				g++;
			}
		}
		sort(f,f+g);
		/*for(i=0;i<g;i++)
			printf("%d\n",f[i]);*/
		kore=0;
		for(i=0;i<g;i++){
			v=0;
			low=0;
			high=g-1;
			nokori=s-f[i];
		//	printf("%d %d\n",i,nokori);
			if(nokori>=0){
				while(1){
					if(low>high)
						break;
					naka=(low+high)/2;
				//	printf("%d = %d %d %d %d %d\n",i,f[high],f[naka],f[low],f[i],nokori);
					if(nokori>f[naka]){
						low=naka+1;
					//	printf("%d %d %d low\n",i,nokori,f[naka]);
					}
					if(nokori<f[naka]){
						high=naka-1;
					//	printf("%d %d %d high\n",i,nokori,f[naka]);
					}
					if(nokori==f[naka]){
						ba=f[naka];
						v=1;
						break;
					}
				}
				if(v==0)
					ba=f[low-1];
				//printf("%d\n",f[i]+ba);
				if(kore<f[i]+ba){
					kore=f[i]+ba;
				//	printf("   %d\n",kore);
				}
			}
		}
		printf("%d\n",kore);
	}
	return 0;
}

Measured memory_bytes: 3004
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int n = vs[0];
			int k = vs[1];
			Sushi[] sushi = new Sushi[n];
			for (int i = 0; i < n; i++) {
				vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
				sushi[i] = new Sushi() { neta = vs[0], value = vs[1] };
			}
			sushi = sushi.OrderByDescending(p => p.value).ToArray();

			HashSet<int> neta = new HashSet<int>();
			Stack<Sushi> stack = new Stack<Sushi>();
			long sum = 0, ans = 0;
			for (int i = 0; i < n; i++) {
				Sushi item = sushi[i];
				if (i < k) {
					if (!neta.Contains(item.neta)) {
						neta.Add(item.neta);
					} else {
						stack.Push(item);
					}
					sum += item.value;
					ans = sum + (long)neta.Count * neta.Count;
					//System.Diagnostics.Debug.WriteLine($"({item.neta},{item.value}) {ans}={sum}+{neta.Count}^2");
				} else {
					if (!neta.Contains(item.neta)) {
						if (stack.Count == 0) {
							break;
						}
						neta.Add(item.neta);
						sum += item.value;
						Sushi item2 = stack.Pop();
						sum -= item2.value;
						ans = Math.Max(ans, sum + (long)neta.Count * neta.Count);
						//System.Diagnostics.Debug.WriteLine($"-({item2.neta},{item2.value})+({item.neta},{item.value}) {sum + neta.Count * neta.Count}={sum}+{neta.Count}^2");
					}
				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}

	public class Sushi
	{
		public int neta;
		public int value;
	}
}


Measured memory_bytes: 29244
#include<bits/stdc++.h>
using namespace std;
// Reference : Erichto + https://www.youtube.com/watch?v=1HiJ332iZQU
long double dp[301][301][301];

long double solve(int ones, int twos, int threes, int n) {
	// cout<<"At "<<ones <<" "<< twos <<" "<< threes<<endl;
	if(ones + twos + threes == 0) {
		// cout<<"Base:"<<0<<endl;
		return 0;
	}
	if(dp[ones][twos][threes] != -1) {
		// cout<<"Cache:"<<dp[ones][twos][threes]<<endl;
		return dp[ones][twos][threes];
	}
	long double coeff1 = (long double)ones / (long double)(ones + twos + threes);
	long double coeff2 = (long double)twos / (long double)(ones + twos + threes);
	long double coeff3 = (long double)threes / (long double)(ones + twos + threes);
	long double ans = (long double) n/ (long double) (ones + twos + threes);
	dp[ones][twos][threes] = ans + 
				coeff1 * (ones == 0 ? 0 : solve(ones - 1, twos, threes, n)) + 
				coeff2 * (twos == 0 ? 0 : solve(ones + 1, twos - 1, threes, n)) + 
				coeff3 * (threes == 0 ? 0 : solve(ones, twos + 1, threes - 1, n ));
	// cout<<"Returning" << dp[ones][twos][threes]<<endl;
	return dp[ones][twos][threes];
}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int a[n];
	int cnt[4]={0};
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	for(int i = 0; i <= 300; ++i) {
		for(int j = 0; j <= 300; ++j) {
			for(int k = 0; k <= 300; ++k) {
				dp[i][j][k] = -1;
			}
		}
	}
	cout<<fixed<<setprecision(20)<<solve(cnt[1], cnt[2], cnt[3], n);
}

Measured memory_bytes: 430008
#include<cstdio>
int x[200005], y[200005];
int d[200005], p[200005];
int pos[200005];
int size[200005];
int stack[200005];
int bit[200005];

int find(int u){
    if(p[u]==u) return u;
    else return p[u] = find(p[u]);
}

int merge(int u,int v){
    int x = find(u), y = find(v);
    if(x!=y){
        p[y] = x;
        size[x] += size[y];
        return 1;
    }
    else return 0;
}

void change(int p,int v,int n){
    while(p<=n){
        bit[p] += v;
        p += p&-p;
    }
}

int ask(int p){
    int res = 0;
    while(p!=0){
        res += bit[p];
        p -= p&-p;
    }
    return res;
}
//>u
int getNext(int u,int n){
    int base = ask(u);
    if(u+1>n || ask(n)==base) return -1;
    else{
        int need = base+1;
        int L = u+1, R = n;
        int res = -1;
        while(L<=R){
            int M = (L+R)/2;
            if(ask(M)>=need){
                res = M;
                R = M-1;
            }
            else L = M+1;
        }
        return res;
    } 
}

void solve(int n){
    for(int i = 1; i <= n; i++) p[i] = i, size[i] = 1, change(i,1,n);
    int prefix = n+1;
    for(int i = 1; i <= n; i++){
        int u = d[i];
        if(u>prefix){}
        else{
            prefix = u;
            int next = getNext(u,n);
            while(next!=-1){
                //printf("next = %d\n",next);
                int j = pos[next];
                if(merge(i,j)){
                    //printf("i = %d, j = %d\n",i,j);
                    next = getNext(next,n);
                }
                else break;
            }
        }
        change(u,-1,n);
    }
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++){ 
        scanf("%d",&x[i]);
        scanf("%d",&y[i]);
        d[x[i]] = y[i];
    }
    for(int i = 1; i <= n; i++) pos[d[i]] = i;
    solve(n);
    for(int i = 1; i <= n; i++){
        int u = find(x[i]);
        printf("%d\n",size[u]);
    }

    return 0;
}


Measured memory_bytes: 7568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    char s[15];cin >> s;
    ll count=0;
    rep(i,15){
        if(s[i]=='x'){
            count++;
        }
    }
    if(count<8){
        cout << "YES" << endl;   
    }else{
        cout << "NO" << endl;    
    }
}



Measured memory_bytes: 256
#include<stdio.h>

int min(int a, int b){
	if(a<b){return a;}else{return b;}
}

int main(void){
	int N,s[100],sum,m,p;
	int i;
	scanf("%d", &N);
	for(i=0;i<N;i++){
		scanf("%d", &s[i]);
	}

	/*まず和を求める*/
	sum = 0;
	for(i=0;i<N;i++){
		sum = sum + s[i];
	}

	if(sum%10 != 0){
		printf("%d\n", sum);
		return 0;
	}

	/*和が10の倍数だった場合、10の倍数でないもののうち最小のものを探す*/
	m = 101;

	for(i=0;i<N;i++){
		if(s[i]%10 != 0){
			m = min(m,s[i]);
		}
	}
	if(m == 101){
		/*全部10の倍数*/
		printf("0\n");
		return 0;
	}else{
		printf("%d\n", sum - m);
		return 0;
	}


}

Measured memory_bytes: 128
//Prefix sum of OEIS A002487
//a(0)=0, a(1)=1; a(2n) = a(n), a(2n+1) = a(n) + a(n+1)
//s(2*n+1) = 3*s(n) + a(n+1)
#include<bits/stdc++.h>
using namespace std;
#define i128 __int128_t
#define i64 long long int
map<i128,i128> A;
i128 a(i128 x){
	if(x <= 1)return x;
	if(A.count(x))return A[x];
	if(x%2==0)return a(x/2);
	return A[x] = a(x/2)+a(x/2+1);
}
i128 s(i128 x){
	if(x <= 1)return x;
	if(x%2==0)return s(x+1)-a(x+1);
	return 3*s(x/2)+a(x/2+1);
}
int main(){
	i64 n;
	cin >> n;
	cout << (int)(s((i128)(n+1)) % 1000000007) << endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
int main(){
  //drkenの解答を参考に
  
  string s;
  cin>>s;
  ll n=s.length();
  ll ans=0;
  for(int bit=0;bit<(1<<(n-1));bit++){
    //bit<(1<<n-1)のような書き方はbit全探索でよく使う。
    //https://atcoder.jp/contests/APG4b/tasks/APG4b_ac 参照
    ll tmp=0;
    for(int i=0;i<n-1;i++){
      tmp*=10;
      tmp+=s[i]-'0';
      if(bit & (1<<i))ans+=tmp,tmp=0;//if文の作業を中括弧使わずに２つ以上行う場合コロンでかける
    }
    tmp*=10;
    tmp+=s.back()-'0';
    ans+=tmp;
  }
  cout<<ans<<endl;
  
    
    
  return 0;
}


Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            //var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = input[0];
            int B = input[1];
            int K = input[2];
            var ans = new SortedSet<int>();
            for(var i = A; i < A + K; i++)
            {
                if (i <= B)
                {
                    ans.Add(i);
                }
            }
            for(var i = B; i > B - K; i--)
            {
                if (i >= A)
                {
                    ans.Add(i);
                }
            }

            foreach(var x in ans)
            {
                Console.WriteLine(x);
            }
            

            //Console.Out.Flush();

        }
    }

    

    public class Calculation
    {

    }

    public class Graph
    {
       
    }
}




Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
vector<int> xx,yy;
const int maxn=1e5+7;
struct q{
	int x,y;
}N[maxn];
int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		xx.push_back(x);
		yy.push_back(y);
	}
	sort(xx.begin(),xx.end());
	sort(yy.begin(),yy.end());
	cout<<max(-xx[m-1]+yy[0]+1,0)<<endl;
	
}

Measured memory_bytes: 1276
#include<cstdio>
#include<cstdlib>
#include<ctime>
int last[500];
long long s[500][30];
long long c[30];
int tt[500];
int out[500];

long long getD(int d){
    for(int i = 1; i <= 26; i++) last[i] = 0;
    long long cur = 0;
    for(int i = 1; i <= d; i++){
        int t = tt[i];
        cur += s[i][t];
        last[t] = i;
        for(int j = 1; j <= 26; j++) cur -= c[j]*(i-last[j]);
    }
    return  cur;
}

int main(){
    srand(time(NULL));
    int d;
    scanf("%d",&d);
    for(int i = 1; i <= 26; i++) scanf("%lld",&c[i]);
    for(int i = 1; i <= d; i++){
        for(int j = 1; j <= 26; j++) scanf("%lld",&s[i][j]);
    }
    for(int i = 1; i <= d; i++){
        int find = 1; long long add = c[1]*(last[1])+s[i][1];
        for(int j = 2; j <= 26; j++){
            long long cur = c[j]*last[j]+s[i][j];
            if(cur>add || (cur==add && rand()%2)) find = j, add = cur;
        }
        last[find] = i;
        out[i] = find;
    }
    for(int i = 1; i <= d; i++) printf("%d\n",out[i]);
    return 0;
}


Measured memory_bytes: 1824
#include<iostream>
using namespace std;
string s,s1,s2;
int t,n,m,tmp,cnt=0;
int a[500001];
int x[500001],y[500001];
void merge_sort(int l,int r){
	 int mid,n1,n2;
	 if (r-l==1) return;
	 mid=(l+r)/2; 
	 merge_sort(l,mid);
	 merge_sort(mid,r);
	 n1=mid-l; n2=r-mid;
	 for (int i=0; i<n1; i++)
	     x[i]=a[l+i];
	 for (int i=0; i<n2; i++)
	     y[i]=a[mid+i];
	 x[n1]=2000000001; y[n2]=2000000001;
	 int i=0,j=0;
	 for (int k=l; k<r; k++){
	 	 if (x[i]<y[j])
	 	 	a[k]=x[i++];
	 	 else{
	 	 	a[k]=y[j++];
		  }
	 	  cnt++;
	 }
   
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    for (int i=0; i<n; i++)
        cin>>a[i];
    merge_sort(0,n);
    cout<<a[0];
    for (int i=1; i<n; i++)
        cout<<' '<<a[i];
    cout<<'\n';
    cout<<cnt<<endl;
	return 0;
} 


Measured memory_bytes: 7080
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define LL long long

int main(){
	// sengen
	int n,m;
	// nyuryoku
	cin >> n >> m;
	int ans = n-1;
	dsu d(n);
	int a[m],b[m];
	for(int i=0;i<m;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		if(!d.same(a[i],b[i])){
			d.merge(a[i],b[i]);
			ans--;
		}
	}
	// keisan
	cout << ans << endl;
	// syutsuryoku
}

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

using namespace std;

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

	if (S.size() <= K) {
		cout << S << endl;
	}
	else {
		S = S.erase(K).append("...");
		cout << S << endl;
	}

	return 0;
}

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

int main(){
    int x , a, b;
    cin >> x >> a >> b;
    int t = b - a;
    if(b <= a){
        cout << "delicious";
    }
    else if(b - a<= x){
        cout << "safe";
    }
    else {
        cout << "dangerous";
    }

}

Measured memory_bytes: 3592
import java.util.Scanner;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.Arrays;
import java.util.Stack;

public class Main {
	static Scanner scn = new Scanner(System.in);
	static int max=Integer.MIN_VALUE;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
			int n,k,sum=0,max=0,j=0;
			n=scn.nextInt();
			k=scn.nextInt();
			sum=n*k;
			if(n>9||k>9)
			{
				System.out.println("-1");
			}
			else 
				System.out.println(sum);
		
	}
	
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include<chrono>
#define ll long long
using namespace std;
vector<ll>bit;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> N;
	for (int n = 3; n <= N; n += 2) {
		int tmp = 0;
		for (int i = 1; i*i <= n; i++) {
			if (n%i == 0)tmp += 2;
			if (i*i == n)tmp--;
		}
		if (tmp == 8)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

MOD = 10**9 + 7


def main():
	# ans_ = []
	# ans_.append(ans)
	# print(("\n").join(map(str, ans_)))
	n, x, t = read()
	print(ceil(n/x)*t)






if __name__ == "__main__":
	main()

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

int main() {
  string o, e;
  cin >> o >> e;
  
  string ans;
  rep(i,e.size()) {
    ans += o.at(i);
    ans += e.at(i);
  }
  
  if (o.size() > e.size()) ans += o.at(o.size()-1);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
def partition(arr,p,r)
  x=arr[r]
  i= p - 1
  #puts arr
  for j in p..r-1
    if(arr[j] <= x)
      i+=1
      arr[i],arr[j]=arr[j],arr[i]
    end
  end
  arr[i+1],arr[r]=arr[r],arr[i+1]
  @num=i+1
end
n=gets.to_i
arr=gets.split.map(&:to_i)
partition(arr,0,n-1)
0.upto(n-2) do |i|
  if i!=@num
    print "#{arr[i]} "
  else
    print "[#{arr[i]}] "
  end
end
puts "#{arr[n-1]}"

Measured memory_bytes: 16728
N=gets.to_i
V=gets.split.map(&:to_i)
C=gets.split.map(&:to_i)
# p N
# p V
# p C
sum = 0
N.times do |i|
    if V[i] > C[i]
        sum += V[i] - C[i]
    end
end
puts sum

Measured memory_bytes: 1788
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String atcoder = sc.next();
		char x = sc.next().charAt(0);
		System.out.print("A");
		System.out.print(x);
		System.out.println("C");
	}
}

Measured memory_bytes: 9556
def main():
  N,M=map(int,input().split())
  Inf=10**8
  dp=[Inf]*(2**N)
  dp[0]=0
  for i in range(M):
    a,b=map(int,input().split())
    tmp=list(map(int,input().split()))
    open_tresure=list(1<<j-1 for j in tmp)
   # print(open_tresure)
    op_tr=sum(open_tresure)
    for j in range(2**N):
      key=op_tr | j
      dp[key]=min(dp[key],dp[j]+a)
  if dp[-1]==Inf:
    print(-1)
  else:
    print(dp[-1])

main()


Measured memory_bytes: 3188
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	
	ll n,m,k;
	cin>>n>>m>>k;
	ll arr[n][m];
	rep(i,0,n)
	{
		string x;
		cin>>x;
		rep(j,0,m)
		{			
			arr[i][j]=(x[j]-'0');			
		}
	}
	ll res=1e18;
	rep(i,0,(1<<(n))+1)
	{
		// ll i=3;
		std::vector<ll> idx;
		ll cnt=0;		
		rep(j,0,n-1)
		{
			if((1<<j) & (i))
			{
				idx.pb(j);
				cnt++;
			}
		}
		std::vector<pii> fr;
		ll curr=0;		
		rep(j,0,idx.size())
		{
			if(j==0)
			{
				fr.pb({0,idx[0]});
				curr=idx[j]+1;
				// continue;
			}
			if(j!=0)
			{
				fr.pb({curr,idx[j]});
				curr=idx[j]+1;
			}
			if(j==(idx.size()-1))
			{
				fr.pb({curr,n-1});
				continue;
			}
			
		}
		ll cj=0;
		ll fl=0;
		if(fr.size()==0)
		{
			fr.pb({0,n-1});
		}
		// cout<<i<<endl;
		// for(auto ii:fr)
		// {
		// 	cout<<ii.F<<" "<<ii.S<<endl;
		// }
		// cout<<endl;
		while(1)
		{
			ll mn=1e18;
			cnt++;
			for(auto j:fr)
			{
				ll c1=-1;
				ll ss=0;
				rep(kk,cj,m)
				{
					rep(ii,j.F,j.S+1)
					{
						ss+=arr[ii][kk];
					}
					if(ss<=k)
						c1=kk;
					else
						break;
				}
				if(c1==-1)
				{
					fl=1;
					break;
				}
				mn=min(mn,c1);
			}
			if(fl)
				break;

			cj=mn+1;
			// cout<<i<<" "<<cj<<endl;
			if(cj>=m)
				break;
		}
		if(!fl)
		{
			res=min(res,cnt);
		}
		// cout<<endl;



	}
	cout<<max(0ll,res-1);







}


Measured memory_bytes: 384
n = int(input())
n = n % 10
if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
    print("hon")
elif n == 0 or n == 1 or n == 6 or n == 8:
    print("pon")
else:
    print("bon")


Measured memory_bytes: 9160
main = do
  s <- getContents
  let v = map (map read . words) . lines $ s
  let w = map solve v
  let x = map (\x-> if x then "YES" else "NO") $ w
  mapM_ putStrLn x

solve::[Double] -> Bool
solve [xa,ya,xb,yb,xc,yc,xd,yd] =
  abs(dot u v)/len(u)/len(v) < eps
  where u = (xb-xa, yb-ya)
        v = (xd-xc, yd-yc)
        dot (a,b) (c,d) = a*c + b*d
        len (a,b) = sqrt(a^2+b^2)
        eps=1e-13

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

int main(){
  int n,m;
  cin>>n>>m;
  bool emerged[n],checked[n];
  for(int i=0;i<n;i++){
    emerged[i]=false;
    checked[i]=false;
  }
  int e[m];
  for(int i=0;i<m;i++){
    cin>>e[i];
    emerged[e[i]-1]=true;
  }
  for(int i=m-1;i>=0;i--)
    if(!checked[e[i]-1]){
      cout<<e[i]<<endl;
      checked[e[i]-1]=true;
    }
  for(int i=0;i<n;i++)
    if(!emerged[i])
      cout<<i+1<<endl;
}


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

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

	int n = s.size();
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'A') {
			s[i] = 'T';
		}
		else if (s[i] == 'C') {
			s[i] = 'G';
		}
		else if (s[i] == 'G') {
			s[i] = 'C';
		}
		else if (s[i] == 'T') {
			s[i] = 'A';
		}
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
ans=0
c=[]
for i in range(n):
	x,y=map(int,input().split())
	ans+=x
	c.append(x+y)
c.sort()
c.reverse()
for i in range(n):
	if i%2!=0:
		ans-=c[i]
print(ans)


Measured memory_bytes: 7388
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 998244353;

vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            if(i % 2 == 1){
                res.push_back(i);
            }
            if(i != n/i){
                if(n/i % 2 == 1){
                    res.push_back(n/i);
                }
            }
        }
    }
    //sort(res.begin(), res.end());
    return res;
}

int main() {
    int N;
    cin >> N;
    int cnt = 0;
    for(int i = 3; i <= N; i++){
        vector<ll> a = divisor(i);
        if(a.size() == 8){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
''' Hey stalker :) '''
INF = 10**10
def main():
    #print = out.append
    ''' Cook your dish here! '''
    n = get_int()
    points = defaultdict(list)
    dp = [0]
    for _ in range(n):
        x, l = get_list()
        points[x+l].append(max(0, x-l))
        if max(0, x-l) not in points:
            points[max(0, x-l)] = []
    indexOfPoint = {0: 0}
    for i, point in enumerate(sorted(points)):
        indexOfPoint[point] = i+1
        dp.append(dp[-1])
        for cp in points[point]:
            dp[-1] = max(dp[-1], 1 + dp[indexOfPoint[cp]])
        continue
    print(dp[-1])


''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
#print(*out, sep='\n')


Measured memory_bytes: 123844
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double t = 0;
		for(int i = 0; i < N; i++)
			t += (double)1/sc.nextInt();
		System.out.println(1/t);

	}

}


Measured memory_bytes: 21844
def solve():
    N = int(input())
    word_count = {}
    max_count = 0
    for i in range(N):
        word = input()
        word_count[word] = word_count.get(word, 0) + 1
        max_count = max(word_count[word], max_count)
    ans_words = []
    for w,c in word_count.items():
        if c == max_count:
            ans_words.append(w)
    print('\n'.join(sorted(ans_words)))

if __name__ == "__main__":
    solve()

Measured memory_bytes: 36648
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
using namespace std;

int top, S[1000];

void push(int x){
    S[++top] = x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a, b, N;
    top = 0;
    char s[100];
    while (scanf("%s", s) != EOF){
        if (s[0] == '+'){
            a = pop();
            b = pop();
            push(a + b);
        }
        else if (s[0] == '-'){
            b = pop();
            a = pop();
            push(a - b);
        }
        else if (s[0] == '*'){
            a = pop();
            b = pop();
            push(a * b);
        }
        else{
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <cctype>
#include <sstream>
using namespace std;

int main()
{

    string s;

    cin >> s;

    long long x = 0;
    long long n=s.length();
    for (int i = 0; i <n; i++)

        x += (int)s[i] - '0';

    if (x % 9 == 0)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int n,power=1;cin>>n;
    for(int i=1;i<=n;++i) power=(power*i)%MOD;
    cout<<power;
    return 0;
}
    

Measured memory_bytes: 256
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

bcount = [0] * (n+1)

bsum = 0
for i in range(n)[::-1]:
        bsum += n - bisect.bisect_right(c, b[i])
        bcount[i] = bsum

result = 0
for i in range(n):
        result += bcount[bisect.bisect_right(b, a[i])]

print(result)

Measured memory_bytes: 108184
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: u32,
        b: u32,
    }
    let mut a = a;
    let mut b = b;
    let mut ans = 0;
    if a > b {
        ans += a;
        a = a - 1;
    } else {
        ans += b;
        b = b - 1;
    }
    if a > b {
        ans += a;
    } else {
        ans += b;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <bitset>

using namespace std;

int main(int argc, const char *argv[])
{
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }

  int ans = h + w + 1;
  for (int bit = 0; bit < (1 << (h - 1)); bit++) {
    bitset<16> bs(bit);
    int x = 0, split_cnt = bs.count();
    bool ok = true;
    while (x < w && ok) {
      bool exceeded = false;
      vector<int> white_cnts(bs.count() + 1, 0);
      int left = x;
      for (; !exceeded && x < w; x++) {
        for (int y = 0, cur = 0; y < h; y++) {
          white_cnts[cur] += s[y][x] - '0';
          exceeded = exceeded || white_cnts[cur] > k;
          cur += bs[y];
        }
      }

      if (exceeded) {
        split_cnt++;
        x--;
      }

      ok = !exceeded || left != x;
    }

    ans = ok ? min(ans, split_cnt) : ans;
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

main() {
    IOS;
    int H,W,D; cin >> H >> W >> D;
    int score[100000];
    vector<pair<int,int>> p(100000);
    rep(i,H) rep(j,W) {
        int a; cin >> a;
        a--;
        p[a].first=i; p[a].second=j;
    }
    rep(i,D){
        for(int j=i;j<=H*W;j+=D){
            if(j==i) score[j]=0;
            else{
            score[j]=score[j-D]+abs(p[j].first-p[j-D].first)
            +abs(p[j].second-p[j-D].second);
            }
        }
    }
    int Q; cin >> Q;
    rep(i,Q){
        int L,R; cin >> L >> R;
        L--; R--;
        cout << score[R]-score[L] << endl;
    }
}


Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
bool dp[5010],cop[5010];
vector<int> v[1010];
int index[1010];
int par[1010];
int x[1010],y[1010];
queue<int> Q;
int main(){
	int n;
	cin>>n;
	lol(i,n)index[i]=0;
	par[0]=-1;
	for(int i=1;i<n;i++){
		cin>>par[i];par[i]--;
		index[par[i]]++;
		v[par[i]].push_back(i);
	}
	for(int i=0;i<n;i++){
		if(index[i]==0)Q.push(i);
	}
	lol(i,n){
		cin>>x[i];
	}
	while(!Q.empty()){
		int i=Q.front();Q.pop();
		if(i==-1)break;
		
		lol(k,5010)dp[k]=false;
		dp[0]=true;
		int sum=0;
		int visize=v[i].size();
		for(int k=0;k<visize;k++){
			lol(r,5010)cop[r]=false;
			int tmp=v[i][k];
			sum+=x[tmp];
			for(int r=0;r+x[tmp]<5010;r++){
				cop[r+x[tmp]]|=dp[r];
			}
			for(int r=0;r+y[tmp]<5010;r++){
				cop[r+y[tmp]]|=dp[r];
			}
			lol(r,5010)dp[r]=cop[r];
		}
		int maxi=-1;
		for(int k=0;k<=min(sum,x[i]);k++)if(dp[k])maxi=k;
		y[i]=sum-maxi;
		//cout<<"%"<<i<<" "<<x[i]<<" "<<y[i]<<" "<<sum<<" "<<maxi<<endl;
		if(y[i]<0||maxi==-1){
			cout<<"IMPOSSIBLE"<<endl;
			return 0;
		}
		
		index[par[i]]--;
		if(index[par[i]]==0){
			Q.push(par[i]);
		}
	}
	cout<<"POSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[5001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, K, a[5001];
	scanf("%d %d", &N, &K);
	for (i = 0; i < N; i++) scanf("%d", &(a[i]));
	merge_sort(a, N);
	
	char dp[2][5001][5001] = {};
	int j, k, n, ans = 0;
	for (n = N - 1; n >= 0 && a[n] >= K; n--) ans++;
	for (i = 0, dp[0][0][0] = 1; i <= n; i++) {
		for (k = 0; k < a[i]; k++) dp[0][i+1][k] = dp[0][i][k];
		for (; k <= K; k++) dp[0][i+1][k] = dp[0][i][k] | dp[0][i][k-a[i]];
	}
	for (i = n, dp[1][n+1][0] = 1; i >= 0; i--) {
		for (k = 0; k < a[i]; k++) dp[1][i][k] = dp[1][i+1][k];
		for (; k <= K; k++) dp[1][i][k] = dp[1][i+1][k] | dp[1][i+1][k-a[i]];
	}
	for (i = 0; i <= n; i++) {
		for (j = 0, k = K - 1; j < K; j++) {
			if (dp[0][i][j] == 0) continue;
			for (; k >= 0 && (j + k >= K || dp[1][i+1][k] == 0); k--);
			if (k >= 0 && j + k >= K - a[i]) {
				ans++;
				break;
			}
		}
	}
	printf("%d\n", N - ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 50600
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,k,cnt=0;
    for(i=0;i<3;i++){
    	cin>>k;
    	if(k==7){
    		cnt++;
		}
	}
	if(cnt==1){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
int main()
{
	int R,G,A;
	scanf("%d",&R);
	scanf("%d",&G);
	A=G*2-R;
	printf("%d\n",A);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    char s[3];
    int x;
    scanf("%s", s);
    if(strcmp(s,"SUN")==0){
        x=7;
    }
    if(strcmp(s,"MON")==0){
        x=6;
    }
    if(strcmp(s,"TUE")==0){
        x=5;
    }
    if(strcmp(s,"WED")==0){
        x=4;
    }
    if(strcmp(s,"THU")==0){
        x=3;
    }
    if(strcmp(s,"FRI")==0){
        x=2;
    }
    if(strcmp(s,"SAT")==0){
        x=1;
    }
    printf("%d\n",x);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String[] values = line.split(" ");

        String A = values[0];
        String B = values[1];
        line = scanner.nextLine();
        values = line.split(" ");
        int AC = Integer.parseInt(values[0]);
        int BC = Integer.parseInt(values[1]);
        line = scanner.nextLine();
        values = line.split(" ");
        String sute = values[0];
        if (A.equals(sute)) {
            System.out.println((AC - 1) + " " + BC);
        } else if (B.equals(sute))  {
            System.out.println(AC + " " + (BC - 1));
        } else {
            System.out.println(AC + " " + BC);
        }
     }
}

Measured memory_bytes: 23636
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;


public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        //int n=sc.nextInt();
        //Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=sc.nextInt();
        int n=sc.nextInt();int l=sc.nextInt();
        int min=1000000000;int sign=1;int sum=0;
        for(int i=0;i<n;i++) {
        	sum+=l+i;
        	if(Math.abs(l+i)<min) {
        		min=Math.abs(l+i);
        		if(l+i<0)sign=-1;
        		else
        			sign=1;
        	}
        }
        sum-=min*sign;
        pw.println(sum);
        pw.flush();
    }
    static StringBuilder tosb(int[]in) {
    	StringBuilder s=new StringBuilder();
    	for(int i=0;i<in.length;i++) {
    		s.append(in[i]+" ");
    	}
    	return s;
    }
    static StringBuilder tosb(long[]in) {
    	StringBuilder s=new StringBuilder();
    	for(int i=0;i<in.length;i++) {
    		s.append(in[i]+" ");
    	}
    	return s;
    }
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

int main(){
    vl t(2); cin >> t[0] >> t[1];
    vl a(2),b(2);
    cin >> a[0] >> a[1] >> b[0] >> b[1];
    ll da = t[0]*a[0]+t[1]*a[1];
    ll db = t[0]*b[0]+t[1]*b[1];
    if(da==db) puts("infinity");
    else{
        if(da>db){
            swap(a,b);
            swap(da,db);
        }
        ll ans = 0;
        if(a[0]>b[0]){
            ll dist = (a[0]-b[0])*t[0];
            ans = (dist/(db-da)+1)*2-1;
            if(dist%(db-da)==0) ans--;
        }
        cout << ans << endl;
    }
}


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

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

    ll ti[N];
    for(int i = 0; i < N; i++)
    {
        cin >> ti[i];
    }
    
    ll ans = 0;
    for(int i = 0; i < N; i++)
    {
        if(ti[i+1]-ti[i] < T) ans += ti[i+1]-ti[i];
        else ans += T;
    }
    cout << ans <<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
ll a[N];
ll f[N];

int main(){
	int n; ll k; scanf("%d%lld", &n, &k);
	REP(i, n) scanf("%lld", a+i);
	REP(i, n) scanf("%lld", f+i);
	sort(f, f+n);
	sort(a, a+n, greater<ll>());
	
	ll mi = -1, mx = 1'123456'789012LL; // mi -> ng, mx -> ok
	while(mx - mi > 1){
		ll md = (mi + mx) / 2;
		ll cnt = 0;
		REP(i, n){
			ll to = md / f[i];
			cnt += max(a[i] - to, 0LL);
		}
		if(cnt <= k){
			mx = md;
		}else{
			mi = md;
		}
	}
	printf("%lld\n", mx);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

typedef pair<int, int> pii;
const int N = 303;
const int inf = (int)1e15;

int n, k, h[N], f[N][N];

int Cost(int i, int j) {
    if(h[i] >= h[j]) return 0;
    return h[j] - h[i];
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) cin >> h[i];
    fill_n(&f[0][0], N * N, inf);
    ++n; f[1][0] = h[1]; f[0][0] = 0;
    for(int i = 2; i <= n; ++i) {
        for(int j = 0; j <= k; ++j) {
            f[i][j] = f[i - 1][j] + Cost(i - 1, i);
            for(int t = i - 2; t >= 0; --t) {
                if(i - t - 1 > j) break;
                f[i][j] = min(f[i][j], f[t][j - i + t + 1] + Cost(t, i));
            }
        }
    }
    int res = inf;
    for(int i = 0; i <= k; ++i) res = min(res, f[n][i]);
    cout << res;
}


Measured memory_bytes: 1024