akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++)
#define FORD(i, a, b) for (int i = (a), i##_len = (b); i > i##_len; i--)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int main() {
    int n, q;
    cin >> n;
    vector<tuple<int, int>> vw(n);
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        vw[i] = make_tuple(a, b);
    }
    cin >> q;
    vector<tuple<int, int>> vl(q);
    REP(i, q) {
        int a, b;
        cin >> a >> b;
        vl[i] = make_tuple(a, b);
    }

    int former = min(1024, n);
    vector<vector<int>> former_dp(former, vector<int>(100001, -1));
    vector<set<int>> former_set(former);

    former_dp[0][0] = 0;
    former_dp[0][get<1>(vw[0])] = get<0>(vw[0]);
    former_set[0].insert(0);
    former_set[0].insert(get<1>(vw[0]));

    FOR(i, 1, former) {
        int v, w;
        tie(v, w) = vw[i];
        auto& anc_dp = former_dp[(i - 1) / 2];
        auto& now_dp = former_dp[i];
        auto& anc_set = former_set[(i - 1) / 2];
        auto& now_set = former_set[i];
        for (auto j : anc_set) {
            now_dp[j] = anc_dp[j];
            now_set.insert(j);
        }
        for (auto j : anc_set) {
            if (w + j <= 100000) {
                now_dp[w + j] = max(now_dp[w + j], anc_dp[j] + v);
                now_set.insert(w + j);
            }
        }
    }

    REP(i, former) {
        int m = 0;
        auto& now_dp = former_dp[i];
        FOR(j, 1, 100001) {
            m = max(m, now_dp[j]);
            now_dp[j] = m;
        }
    }

    for (auto temp : vl) {
        int v, l;
        tie(v, l) = temp;
        if (v <= former) {
            cout << former_dp[v - 1][l] << endl;
            continue;
        }
        vector<tuple<int, int>> later;
        int vv = v;
        while (vv > former) {
            later.push_back(vw[vv - 1]);
            vv >>= 1;
        }
        auto& anc_dp = former_dp[vv - 1];
        int m = later.size();
        int ans = 0;
        REP(i, pow(2, m)) {
            int v_sum = 0;
            int w_sum = 0;
            int ii = i;
            for (auto temp : later) {
                int j, k;
                tie(j, k) = temp;
                if (ii & 1) {
                    v_sum += j;
                    w_sum += k;
                }
                ii >>= 1;
            }
            if (w_sum > l) { continue; }
            ans = max(ans, v_sum + anc_dp[l - w_sum]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 440264
// バグ有

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
	int W, N;
	char d;
	int counter = 1;
	int takara[1000][2];
	while(1) {
		cin >> W;
		if (W == 0) {
			break;
		}
		cin >> N;
		for (int i = 0; i < N; i++) {
			cin >> takara[i][0] >> d >> takara[i][1];
		}
		vector< vector<int> > dp(W+1, vector<int> (N+1));
		for (int i = 0; i <= N; i++) {
			for (int j = 0; j <= W; j++) {
				dp[j][i] = 0;
			}
		}
		for (int i = 0; i <= N; i++) {
			for (int j = 0; j <= W; j++) {
				if (i == 0) {
					continue;
				}
				if (j < takara[i-1][1]) {
					dp[j][i] = dp[j][i-1];
				} else {
					dp[j][i] = max(dp[j][i-1], dp[j-takara[i-1][1]][i-1] + takara[i-1][0]);
				}
			}
		}
		int MAX[2];
		MAX[0] = 0;
		MAX[1] = 10000;
		for (int i = 0; i <= W; i++) {
			if (MAX[0] == dp[i][N]) {
				MAX[1] = min(MAX[1],i);
			} else if (MAX[0] < dp[i][N]){
				MAX[0] = dp[i][N];
				MAX[1] = i;
			}
		}
		cout << "Case " << counter << ':' << endl << MAX[0] << endl << MAX[1] << endl;
		counter++;
	}
	return 0;
}

Measured memory_bytes: 5032
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n)   FOR(i,0,n)
typedef pair< ll,ll > cp2;
typedef pair<ll,cp2 > cp3;
#define fi first
#define se second
#define sec se.fi
#define thr se.se
const ll mod = 1000000007;
//              123456789

template<int SZ>
class SegMax {
	public:
		cp2 seg[2*SZ];
		
		SegMax(){
			fill( seg, seg+2*SZ, cp2( 0, 0 ) );
		}
		
		void ffill(){
			fill( seg, seg+2*SZ, cp2( -mod, -mod ) );
		}
		
		void upd( int p, cp2 value ){
			for( seg[p += SZ] = value; p > 1; p >>= 1 ) seg[p>>1] = max( seg[p], seg[p^1] );
		}
		
		cp2 query( int l, int r ){
			cp2 res = cp2( -mod, -mod );
			for( l += SZ, r += SZ; l < r; l >>= 1, r >>= 1 ){
				if( l&1 ) res = max( res, seg[l++] );
				if( r&1 ) res = max( res, seg[--r] );
			}
			return res;
		}
};




int N;
int d;
int x, y, b;
cp3 P[212345];

SegMax< 1<<18 >Xmin;
SegMax< 1<<18 >Ymin;
SegMax< 1<<18 >Xmax;
SegMax< 1<<18 >Ymax;

int B[212345];

int main(){
	
	cin>>N>>d;
	
	
	Xmin.ffill();
	Ymin.ffill();
	
	REP( i, N ){
		scanf("%d %d %d", &x, &y, &b );	
		P[i] = cp3( b, cp2( x, y ) );
		B[i] = b;
	}
	
	
	sort( P, P+N );
	sort( B, B+N );
	
	REP( i, N ){
		x = P[i].thr;
		y = P[i].sec;
		Xmin.upd( i, cp2( -x, 0 ) );
		Xmax.upd( i, cp2(  x, 0 ) );
		Ymin.upd( i, cp2( -y, 0 ) );
		Ymax.upd( i, cp2( y , 0 ) );
	}
	
	int key;
	ll ans = 0;
	
	
	
	REP( i, N ){
		key = B[i];
		x = lower_bound( B, B+N, key )-B;
		y = lower_bound( B, B+N, key+d+1 )-B;
		//cout<<x<<"-"<<y<<endl;
		cp2 t1 = Xmin.query( x, y );
		cp2 t2 = Xmax.query( x, y );
		cp2 t3 = Ymin.query( x, y );
		cp2 t4 = Ymax.query( x, y );
		
		//printf("%lld %lld %lld %lld\n", t1.fi, t2.fi, t3.fi, t4.fi);
		
		ll num = (t1.fi+t2.fi)*(t4.fi+t3.fi);
		ans = max( num, ans );
		//cout<<num<<endl;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 41760
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

class Pile{
	int id;
	long value;
	bool isLeader;
	long ans = 0;
	this(int id, long v){
		this.id = id;
		this.value = v;
		this.isLeader = false;
		}
	string toString(){
		return id.to!string ~ "(" ~ value.to!string ~ (isLeader? "*": "") ~ ")";
		}
	}

void main(){
	long n = readln.chomp.to!long;
	long[] as = readln.chomp.split.map!(to!long).array;
	
	Pile[] piles;
	long[long] valuecount;
	
	long leadervalue = 0;
	bool[long] leadervalueset;
	
	for(int i = 0; i < as.length; i ++){
		long a = as[i];
		Pile p = new Pile(i, a);
		piles ~= p;
		if(a > leadervalue){
			p.isLeader = true;
			leadervalue = p.value;
			leadervalueset[p.value] = 1;
			}
		}
	
	
	long[] ks = leadervalueset.keys.sort!("a > b")().array;
	long[long] nextvalue;
	for(int i = 0; i < ks.length; i ++){
		if(i < ks.length - 1) nextvalue[ks[i]] = ks[i + 1];
		else nextvalue[ks[i]] = 0;
		}
	
	debug piles.map!(p => p.toString()).join(" ").writeln;
	
	piles.sort!(
			"(a.value == b.value)? (a.isLeader && !b.isLeader): a.value > b.value"
			)().array;
	
	debug piles.map!(p => p.toString()).join(" ").writeln;
	
	long[long] stonecount;
	long donepilescount = 0;
	for(int i = 0; i < piles.length; i ++){
		Pile p = piles[i];
		if(p.isLeader){
			leadervalue = p.value;
			stonecount[p.value] += i * (p.value - nextvalue[p.value]);
			}
		stonecount[leadervalue] += p.value - nextvalue[leadervalue];
		}
	
	piles.sort!("a.id < b.id")();
	
	long[] ans = piles.map!(p => p.isLeader? stonecount[p.value]: 0).array;
	foreach(a; ans) a.writeln;
	
	}

Measured memory_bytes: 30268
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

t = 0
n = 0
for i in range(N):
    if a[i] < n:
        t += a[i]
        a[i] = 0
    else:
        t += n
        a[i] -= n
    if a[i] < b[i]:
        t += a[i]
        n = b[i] - a[i]
    else:
        t += b[i]
        n = 0

if a[N] < n:
    t += a[N]
else:
    t += n

print(t)


Measured memory_bytes: 19156
#include <bits/stdc++.h>
#include <string>
#define MAX 200
using namespace std;
 
int s[MAX], top = 0;
 
void initialize() {
    top = 0;
}
 
bool empty() {
    if (top == 0) return true;
    else return false;
}
 
bool full() {
    if (top >= MAX - 1) return true;
    else return false;
}
 
bool push(int x) {
    if (full()) return false;
    top++;
    s[top] = x;
    return true;
}
 
int pop() {
    if (empty()) return 0;
    top--;
    return s[top + 1];
}
 
int calc(int a, string x, int b) {
    if (x == "+") return a + b;
    else if (x == "-") return a - b;
    else if (x == "*") return a * b;
  else cout <<" error" << endl;
}
 
int main() {
    string hoge;
  int i;
    do{
        cin >> hoge;
        if(cin.eof()){
            cout << s[top] << endl;
            return 0;
        }
        if(hoge[0] == '+' || hoge[0] == '-' || hoge[0] == '*') {
int f,g;
f=pop();
g=pop();
            i = calc(g, hoge, f);
            push(i);
        }
        else {
            i  = atoi(hoge.c_str());
            push(i);
        }
    }while(1);
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 n,k;
    cin >> n >> k;
    vector<int64> a(n), f(n);
    REP(i,n)cin >> a[i];
    REP(i,n)cin >> f[i];
    sort(ALL(a));
    sort(ALL(f), greater<int64>());
    vector<pll> score(n);
    REP(i,n)score[i] = pll(a[i] * f[i], f[i]);
    sort(ALL(score),greater<pll>());
    int64 l = -1, r = score[0].first;
    while(r - l > 1){
        int64 m = (l + r + 1) / 2;
        int64 training = 0;
        REP(i,n){
            training += max<int64>(0, (score[i].first - m + score[i].second - 1) / score[i].second);
        }
        if(training > k){
            l = m;
        }else{
            r = m;
        }
    }
    ANS(r);
    return 0;
}

Measured memory_bytes: 6528
n = int(input())
mod = 10**9+7
dp = [1]*(n+1)
if n <= 2:
    print(0)
    exit()
for i in range(3):
    dp[i] = 0

for j in range(3, 10):
    if j <= n:
        dp[j] = 1

for i in range(3, n+1):
    for j in range(3, n):
        if i+j <= n:
            dp[i+j] += dp[i]
            dp[i+j] %= mod
print(dp[-1])


Measured memory_bytes: 65832
#include <bits/stdc++.h>
using namespace std;
#define N 210
#define ll long long
#define mod 998244353
int n,ans;
struct poi
{
	int x,y;
	poi(){}
	poi(int x,int y):x(x),y(y){}
	friend poi operator - (const poi &r1,const poi &r2)
	{return poi(r1.x-r2.x,r1.y-r2.y);}
	friend int operator ^ (const poi &r1,const poi &r2)
	{return r1.x*r2.y-r2.x*r1.y;}
}a[N];
int qpow(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=(ll)ret*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}
	return ret;
}
int ni(int x){return qpow(x,mod-2);}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
	ans=(qpow(2,n)-1-n+mod)%mod;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			int num=2;
			for(int k=1;k<=n;k++)
				if(k!=i&&k!=j&&((a[k]-a[i])^(a[k]-a[j]))==0)num++;
			int v1=(qpow(2,num)-num-1+mod)%mod,v2=num*(num-1)/2;
			v1=(ll)v1*ni(v2)%mod;
			ans=(ans-v1+mod)%mod;
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
c = [list(map(int, input().split())) for _ in range(3)]
b = [c[0][0], c[0][1], c[0][2]]
a = [0, c[1][0] - b[0], c[2][0] - b[0]]
for i in range(3):
    for j in range(3):
        if c[i][j] != (a[i] + b[j]):
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
/** Seek God..Trust God..Praise God..**/

#include<bits/stdc++.h>
using namespace std;


#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
    return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////



/*
long long  Prime[3000000],nPrime;
long long  mark[10000002];

void seive(long long int n)
{
	long long int i,j,limit=sqrt(n*1.0)+2;
	mark[1]=1;
	for(i=4; i<=n ;i+=2)
	mark[i]=1;
	Prime[nPrime++]=2;
	for(i=3; i<=n; i+=2)
	{
		if(!mark[i])
		{
			Prime[nPrime++]=i;
			if(i<=limit)
			{
				for(j=i*i; j<=n ;j+=i*2)
				{
					mark[j]=1;
				}
			}
		}
	}
}
*/


int main()
{
    FASTIO;


    int n;

    cin >> n;

    ll arr[n+1];

    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }


    ll cnt = 0;


    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {

            for (int k = j + 1; k < n; k++)


                if (
                    arr[i] + arr[j] > arr[k]
                    && arr[i] + arr[k] > arr[j]
                    && arr[k] + arr[j] > arr[i] && arr[i]!=arr[j] && arr[i]!=arr[k] && arr[j]!=arr[k])
                    cnt++;
        }
    }
    cout << cnt << endl;





    return 0;
}


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

char s[100005];
int n;
vector< pair<int, int> > seg;
vector< pair<int, int> > val;

void split_segment()
{

    int r = 0, l = 0;
    for (int i = 1; i + 1 <= n;) 
    {
        if (s[i] == 'R' && s[i + 1] == 'L') 
        {
            val.emplace_back(i, i + 1);
            r = i; 
            l = i + 1;
            while (r - 1 >= 1 && s[r - 1] == 'R') --r;
            while (l + 1 <= n && s[l + 1] == 'L') ++l;
            seg.emplace_back(r, l);
            i = l + 1;
        }
        else 
        {
            ++i;
        }
    }
}

void print_result()
{
    for (int i = 0; i < seg.size(); ++i) 
    {
        int total = seg[i].second - seg[i].first + 1;
        int val1 = total / 2;
        int val2 = total - val1;
        if (val1 > val2) swap(val1, val2);
        
        int l_left = val[i].first - seg[i].first;
        int r_left = seg[i].second - val[i].second;

        if (l_left % 2 == 0) 
        {
            swap(val1, val2);
        }

        for (int k = 0; k < l_left; ++k) printf("0 ");
        printf("%d %d ", val1, val2);
        for (int k = 0; k < r_left; ++k) printf("0 ");
    }
}

int main()
{
    scanf("%s", s + 1);
    n = strlen(s + 1);

    split_segment();
    print_result();

    return 0;
}

Measured memory_bytes: 1524
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int a, b;
	cin >> a >> b;
	bool f = true;
	if (a == 2 || b == 2)f = false;
	else if ((a == 4 || a == 6 || a == 9 || a == 11) != (b == 4 || b == 6 || b == 9 || b == 11))f = false;
	//cout << min(min(a + b, b + c), c + a) << endl;
	printf((f) ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
<?php
while (fscanf(STDIN, "%d%d", $N, $M) && ($N | $M)) {
  $D = $P = array();
  
  for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d%d", $d, $p);
    $D[] = $d;
    $P[] = $p;
  }
  
  $arr = array($D, $P);
  array_multisort($arr[1], SORT_DESC, $arr[0]);
  
  $ans = 0;
  for ($i = 0; $i < $N; $i++) {
    $v = max(0, $arr[0][$i] - $M);
    $M = max(0, $M - $arr[0][$i]);
    $ans += $v * $arr[1][$i];
  }

  print $ans . "\n";
}

Measured memory_bytes: 12140
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <sstream>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int ball[10];

bool dfs(int b, int c, int k){
	if (k >= 10) return true;
	if (b > ball[k] && c > ball[k]) return false;
	if (b < ball[k] && c > ball[k]) return dfs(ball[k], c, k+1);
	if (b > ball[k] && c < ball[k]) return dfs(b, ball[k], k+1);
	return dfs(ball[k], c, k+1) || dfs(b, ball[k], k+1);
}

int main(){
    int n;
    cin >> n;
    REP(i, n){
    	REP(j, 10){
    		cin >> ball[j];
    	}
    	if (dfs(0, 0, 0)) cout << "YES" << endl;
    	else cout << "NO" << endl;
    }
}


Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, a[1000], b, c[1000];
int main() {
	cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < m; i++) {
		cin >> b;
		for(int j = 0; j < n; j++) {
			if(a[j] <= b) {
				c[j]++; break;
			}
		}
	}
	cout << (max_element(c, c + n) - c + 1) << endl;
}

Measured memory_bytes: 3104
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>

using namespace std;

/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
/// 最小公倍数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }



int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i = 0; i < N; i++){
      cin >> L[i];
  }
   sort(L.begin(),L.end());
   
   if(accumulate(L.begin(),L.end(),0) -L[N-1] > L[N-1]) cout << "Yes" << endl;
   else cout << "No" << endl;

   }
 


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

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)
#define sz(s) ((int) (s).size())

const int MOD = 998244353;

int dp[305][100000];
int dp2[305][100000];
int n, a[305];

int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    cin >> n;
    int sum  = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    bool flag = (sum % 2 == 0);
    sum = (sum - 1) / 2 + 1;
    dp[0][0] = 1;
    dp2[0][0] = 1;
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        ans = 1LL * ans * 3 % MOD;
        for (int j = 0; j <= 90000; j++) {
            dp2[i][j] = dp2[i - 1][j];
            dp[i][j] = dp[i - 1][j] * 2 % MOD;
            if (j >= a[i]) {
                dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i]]) % MOD;
                dp2[i][j] = (dp2[i][j] + dp2[i - 1][j - a[i]]) % MOD;
            }
        }
    }
    int tmpAns = 0;
    for (int i = sum; i <= 90000; i++) {
        tmpAns = (tmpAns + dp[n][i]) % MOD;
    }
    tmpAns = 1LL * tmpAns * 3 % MOD;
    if (flag) tmpAns = (tmpAns - 3LL * dp2[n][sum]) % MOD;
    if (tmpAns < 0) tmpAns += MOD; 
    ans = (ans - tmpAns) % MOD;
    if (ans < 0) ans += MOD;
    cout << ans;
    return 0;
}

Measured memory_bytes: 237312
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

vi fac,boo;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>n;
    fac.resize(n+3,1);
    boo.resize(n+4);
    for(int i=0;i<=n;i++){
        boo[i] = i;
    }
    for(ll i=2;i*i<=n;i++){
        if(fac[i]==1){
            for(ll j=i;j<=n;j+=i){
                x = 0;
                while(boo[j]%i==0){
                    boo[j]/=i;x++;
                }
                fac[j]*=(x+1);
            }
        }
    }
    for(int i=2;i<=n;i++){
        if(boo[i]!=1){
            fac[i]*=2;
        }
    }
    z = 0;
    for(int i=1;i<=n;i++){
        z+=fac[i]*i;
    }
    cout<<z;
    
    


    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int MOD= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
ll mod=998244353;
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(){
    ll n,a,b,k;
    cin >>n>>a>>b>>k;
    COMinit();
    ll ans=0;
    for (int i = 0; i <=n; ++i) {
        if((k-a*i)%b==0){
            ll j=(k-a*i)/b;
            ans+=(COM(n,i)*COM(n,j))%mod;
        }
        ans%=mod;
    }
    cout <<ans <<endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> data(n);
	for(int i=0;i<n;++i){
		cin >>data[i];
	}
	
	int cnt = 1;
	int res_inv = 0;
	for(int i=0;i<n;++i){
		if(data[i] == cnt){
			res_inv++;
			cnt++;
		}
	}
	
	if(res_inv == 0) cout << -1 <<endl;
	else cout << n - res_inv <<endl;
	
	
	return 0;
}



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

int linersearch(int[],int,int);

int main(){
  int i, count=0, n, q, *S, *T;
  scanf("%d",&n);
  S = (int *)malloc(sizeof(int) * n);
  for(i=0; i<n; i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  T = (int *)malloc(sizeof(int) * q);
  for(i=0; i<q; i++)
    scanf("%d",&T[i]);

  for(i=0; i<q; i++)
    if(linersearch(S,n,T[i]))
      count++;
  printf("%d\n",count);
  return 0;
}

int linersearch(int A[],int len,int key){
  int i;
  for(i=0; i<len; i++)
    if(A[i] == key)
      return 1;
  return 0;
}

Measured memory_bytes: 636
N,M = map(int,input().split())
A = []
B = []
for m in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
from collections import defaultdict as ddict
route = ddict(list)
for i in range(M):
    route[A[i]].append(B[i])
    route[B[i]].append(A[i])
for i in range(1,N+1):
    if route[i] == []:
        print("No")
        exit()
ans = [0 for i in range(N+1)]
from collections import deque
Q = deque([1])
while Q:
    q = Q.popleft()
    for r in route[q]:
        if ans[r] == 0:
            ans[r] = q
            Q.append(r)
print("Yes")
print(*ans[2:],sep="\n")

Measured memory_bytes: 43700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long[] frol = new long[n];
		long[] fror = new long[n];
		
		long[] min1 = new long[n];
		long[] max1 = new long[n];
		
		long[] min2 = new long[n];
		long[] max2 = new long[n];
		
		for(int i = 0; i < n; i++)
		{
			frol[i] = sc.nextLong();
			max1[i] = frol[i];
			if(i == 0 || frol[i] != frol[i-1])
			{ //new value
				min1[i] = frol[i];
			}
			else
			{ //old value (no new record)
				min1[i] = 1;
			}
		}
		for(int i = 0; i < n; i++)
		{
			fror[i] = sc.nextLong();
		}
		
		
		for(int i = n-1; i >= 0; i--)
		{
			max2[i] = fror[i];
			if(i == n-1 || fror[i] != fror[i+1])
			{ //new value
				min2[i] = fror[i];
			}
			else
			{ //old value (no new record)
				min2[i] = 1;
			}
		}
		
		long MOD = 1000000007l;
		long score = 1;
		for(int i = 0; i < n; i++)
		{
			long min = Math.max(min1[i], min2[i]);
			long max = Math.min(max1[i], max2[i]);
			
			if(min > max)
			{
				System.out.println(0);
				return;
			}
			else
			{
				score = (score * (max-min+1))%MOD;
			}
		}
		while(score<0)score+=MOD;
		System.out.println(score);
		
	}

}


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

typedef long long ll;

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }

    map<int,int> mp;
    for(int i=0;i<N;i++){
        mp[A.at(i)]=i+1;
    }
    for(int i=1;i<N;i++){
        cout<<mp[i]<<" ";
    }
    cout<<mp[N]<<endl;
}

Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  int p[n];
  for(int i=0;i<n;i++)cin>>p[i];
  int ans=0;
  for(int i=1;i<n-1;i++){
    if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1]))ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
    long long n, a[100010];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    
    long long ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans += (a[i] + a[i + 1]) / 2;
        
        if ((a[i] + a[i + 1]) % 2 == 0) a[i + 1] = 0;
        else {
            if (a[i + 1] > 0) a[i + 1] = 1;
            else a[i + 1] = 0;
        }
    }
    
    if (n == 1) ans = a[0] / 2;
    cout << ans << endl;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"strconv"
	"strings"
)

type ByValue []float64

func (s ByValue) Len() int           { return len(s) }
func (s ByValue) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s ByValue) Less(i, j int) bool { return s[i] < s[j] }

func input() string {
	var s string
	_, _ = fmt.Scan(&s)
	return s
}

func inputLn() string {
	var s string
	_, _ = fmt.Scanln(&s)
	return s
}

func inputByScanner(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func convListStrToInt(strList []string) []int {
	intList := make([]int, len(strList))
	for k, v := range strList {
		intV, _ := strconv.Atoi(v)
		intList[k] = intV
	}
	return intList
}

func convListStrToFloat(strList []string) []float64 {
	intList := make([]float64, len(strList))
	for k, v := range strList {
		intV, _ := strconv.Atoi(v)
		intList[k] = float64(intV)
	}
	return intList
}

func main() {
	m, _ := strconv.Atoi(input())
	d, _ := strconv.Atoi(input())

	res := 0
	for i := 1; i <= m; i++ {
		for j := 10; j <= d; j++ {
			dList := convListStrToInt(strings.Split(strconv.Itoa(j), ""))
			prod := 1
			if dList[0] >= 2 && dList[1] >= 2 {
				for _, v := range dList {
					prod *= v
				}
				if i == prod {
					res++
				}
			}
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main()
{
	int x,y,z;
	cin>>x>>y>>z;
	printf("%d %d %d\n",z,x,y);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	double a,b,x;
	scanf("%lf%lf%lf",&a,&b,&x);
	if(x>=a*a*b/2)printf("%.10lf",atan(2*(a*a*b-x)/(a*a*a))*180/acos(-1));
		else printf("%.10lf",atan((a*b*b)/(2*x))*180/acos(-1));
} 

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

public class Solution
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        for (int i = 1; i < 50000; i++)
        {
            if ((int)(i * 1.08) == n)
            {
                Console.WriteLine(i);
                return;
            }
        }

        Console.WriteLine(":(");
    }
}

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

int main() {
    int n, a[105];
    ll dp[105][21]{}, ans=0;
    cin >> n;
    REP(i,n) cin >> a[i];
    dp[0][a[0]] = 1;
    for(int i=1;i<n-1;i++){
        for(int j=0;j<=20;j++){
            if(j+a[i]<=20) dp[i][j+a[i]] += dp[i-1][j];
            if(j-a[i]>=0) dp[i][j-a[i]] += dp[i-1][j];
        }
    }
    cout << dp[n-2][a[n-1]] << endl;
    return 0;
}



Measured memory_bytes: 3112
#include<stdio.h>


int main(){

  int n, i, j, cnt, sum;

  while(scanf("%d", &n), n){
    sum=0;
    cnt=0;
    for(j=1;j<n;j++){
      for(i=j;i<n;i++){
        sum+=i;
        if(sum==n){
          cnt++;
          sum=0;
          break;
        }else if(sum>n){
          sum=0;
          break;
        }
      }
    }
    printf("%d\n", cnt);
  }

  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Problem ThanhYeuThu = new Problem();
		ThanhYeuThu.solve();
	}
	static class Problem {
		public void solve() {
			Scanner sc = new Scanner(System.in);
			String S = sc.next();
			String T = sc.next();
			int n = S.length();
			int m = T.length();
			int DP[][] = new int[n + 1][m + 1];
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++) {
					if (S.charAt(i - 1) == T.charAt(j - 1)) {
						DP[i][j] = DP[i - 1][j - 1] + 1;
					}
					else {
						DP[i][j] = Math.max(DP[i - 1][j], DP[i][j - 1]);
					}
				}
			}
			TruyVet(S,T,n,m,DP);
		}
		private void TruyVet(String S,String T,int u,int v,int DP[][]) {
			if (u == 0 || v == 0) {
				return;
			}
			if (S.charAt(u - 1) == T.charAt(v - 1)) {
				TruyVet(S,T,u - 1,v - 1,DP);
				System.out.print(S.charAt(u - 1));
			}
			else {
				if (DP[u][v] == DP[u - 1][v]) TruyVet(S,T,u - 1,v,DP);
				else TruyVet(S,T,u,v - 1,DP);
			}
		}
	}

}


Measured memory_bytes: 83664
#include <cstdio>
#include <cstring>
const int N=500005;
int nxt1[N],nxt2[N];
char s1[N],s2[N];
inline void getnxt(char *s,int *t){
	int n=strlen(s+1);
	for (int i=2,k=0;i<=n;i++){
		while (k&&s[k+1]!=s[i]) k=t[k];
		if (s[k+1]==s[i]) k++;t[i]=k;
	}
}
int main (){
	scanf ("%s",s1+1);
	int n=strlen(s1+1),cnt=0,f=1;
	for (int i=2;i<=n;i++) if (s1[i]!=s1[i-1]) f=0;
	if (f){
		printf ("%d\n1",n,1);
		return 0;
	}
	getnxt(s1,nxt1);
	for (int i=1;i<=n;i++) s2[i]=s1[n-i+1];
	getnxt(s2,nxt2);
	if ((!nxt1[n])||(n%(n-nxt1[n])!=0)) {
		puts("1\n1");
		return 0;
	}
	for (int i=1;i<n;i++)
		if (((!nxt1[i])||(i%(i-nxt1[i])!=0))&&((!nxt2[n-i])||((n-i)%(n-i-nxt2[n-i])!=0))) cnt++;
	printf ("2\n%d",cnt);
	return 0;
}

Measured memory_bytes: 4992
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string

let () =
  let ans = Array.make n 0 in
  List.iter (fun i -> ans.(i - 1) <- ans.(i - 1) + 1) a;
  Array.iter (Printf.printf "%d\n") ans

Measured memory_bytes: 30784
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
const int inf = 2e9;

int ipow(int a, int p){
    int res = 1;
    for(int i=0; i<p; i++){
        res *= a;
    }
    return res;
}

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n == 0) break;

        vector<int> a(n),w(m);
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        for(int i=0; i<m; i++){
            cin >> w[i];
        }
        set<int> diff;
        for(int i=0; i<ipow(3, m); i++){
            int tmp = i;
            int b[3] = {};
            for(int j=0; j<m; j++){
                b[tmp%3] += w[j];
                tmp /= 3;
            }
            diff.insert(abs(b[1]-b[0]));
        }

        vector<int> b;
        for(int i: a){
            if(diff.find(i) == diff.end()){
                b.push_back(i);
            }
        }
        if(b.empty()){
            cout << 0 << endl;
            continue;
        }
        int ans = inf;
        for(int e: diff){
            for(int s=-1; s<2; s+=2){
                int d = abs(b[0]+s*e);
                bool ok = true;
                for(int i: b){
                    if(diff.find(abs(i-d)) == diff.end() and diff.find(i+d) == diff.end()){
                        ok = false;
                        break;
                    }
                }
                if(ok){
                    ans = min(ans, d);
                }
            }
        }
        if(ans == inf){
            cout << -1 << endl;
        }else{
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4492
#include <stdio.h>
#include <vector>
using namespace std;
struct node{
    int l;
    int r;
    int parent;
    int s;
    int depth;
    int d;
    int height;
};
int max(int a,int b){
    if(a>b)return a;
    return b;
}
void build(int now,node tree[]){
    int l=-1,r=-1,d=0;
    if(tree[now].l!=-1){
        tree[tree[now].l].depth=tree[now].depth+1;
        build(tree[now].l,tree);
        l=tree[tree[now].l].height;
        d++;
    }
    if(tree[now].r!=-1){
        tree[tree[now].r].depth=tree[now].depth+1;
        build(tree[now].r,tree);
        r=tree[tree[now].r].height;
        d++;
    }
    tree[now].height=max(l,r)+1;
    tree[now].d=d;
    return ;
}
int main(){
    int n,temp;
    node tree[100];
    scanf("%d",&n);
    for(int i=0;i<n;i++)tree[i].parent=-1;
    for(int i=0;i<n;i++){
        scanf("%d",&temp);
        scanf("%d%d",&tree[temp].l,&tree[temp].r);
        if(tree[temp].l!=-1){
            tree[tree[temp].l].parent=temp;
            tree[tree[temp].l].s=tree[temp].r;
        }
        if(tree[temp].r!=-1){
            tree[tree[temp].r].parent=temp;
            tree[tree[temp].r].s=tree[temp].l;
        }
    }
    for(int i=0;i<n;i++){
        if(tree[i].parent==-1){
            tree[i].s=-1;
            tree[i].depth=0;
            build(i,tree);
        }
    }
    for(int i=0;i<n;i++){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,tree[i].parent,tree[i].s,tree[i].d,tree[i].depth,tree[i].height);
        if(tree[i].parent==-1)printf("root\n");
        else if(tree[i].l==tree[i].r&&tree[i].l==-1)printf("leaf\n");
        else printf("internal node\n");
    }
    
}

Measured memory_bytes: 2760
a,b=map(int,input().split())
if (a<=0 and b>=0) or (b<=0 and a>=0):
    print("Zero")
elif a>0 and b>0:
    print("Positive")
else:
    if (b-a)%2==1:
        print("Positive")
    else:
        print("Negative")

Measured memory_bytes: 61856
#import <Foundation/Foundation.h>
#include <stdio.h>

int buf;
NSInteger intinput(void){
    scanf("%d",&buf);
    NSInteger ret = buf;
    return ret;
}

void output(NSString *s,NSString *sep){
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
    [fileHandle writeData:[s dataUsingEncoding:NSUTF8StringEncoding]];
    [fileHandle writeData:[sep dataUsingEncoding:NSUTF8StringEncoding]];
    [fileHandle closeFile];
}

NSMutableArray* to_numarray(NSString *s){
    NSMutableArray *l = [NSMutableArray arrayWithArray:[s componentsSeparatedByString:@" "]];
    NSInteger buf = 0;
    for(int i=0;i<[l count];i++){
        buf = [[l objectAtIndex:i] integerValue];
        [l replaceObjectAtIndex:i withObject:[NSNumber numberWithInteger:buf]];
    }
    return l;
}

int main(int argc, const char * argv[]) {
    NSInteger a = intinput();
    NSInteger b = intinput();
    NSInteger v = (a+b)/2;
    if((a+b)%2){v++;}
    NSString *result = [NSString stringWithFormat:@"%ld",v];
    output(result,@"\n");
    return 0;
}


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

int main(){
    int n, taro_point = 0, hanako_point = 0;
    string taro_card, hanako_card;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> taro_card >> hanako_card;
        if (taro_card == hanako_card){
            taro_point++;
            hanako_point++;
        }else if(taro_card > hanako_card){
            taro_point += 3;
        }else{
            hanako_point += 3;
        }
    }
    cout << taro_point << " " << hanako_point << endl;
    return 0;
}


Measured memory_bytes: 3168
class Solution:
    def main(self):
        N = int(input())
        H = list(map(int, input().split()))
        i = 0
        res = 0
        final = 0
        while i < N-1:
            if H[i] >= H[i+1]:
                res += 1
                i += 1
            else:
                res = 0
                i += 1
            # print(res)
            final = max(res, final)
        print(final)

if __name__ == '__main__':
    Solution().main()


Measured memory_bytes: 14480
#include<stdio.h>
int main(){
  long int x[100001];
  long int n,k,i,a,b;
  scanf("%ld%ld",&n,&k);
  for(i=0;i<100001;i++)x[i]=0;
  for(i=0;i<n;i++){scanf("%ld%ld",&a,&b);x[a]+=b;}
  for(i=0;i<100001;i++){k-=x[i];if(k<=0){printf("%ld",i);return 0;}}
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int d=scan.nextInt();
		int x[][]=new int[n][d];
		for(int i=0;i<n;i++) {
			for(int j=0;j<d;j++) {
				x[i][j]=scan.nextInt();
			}
		}
		scan.close();

		int cnt=0;
		for(int i=0;i<n-1;i++) {
			for(int j=i+1;j<n;j++) {
				int a =0;
				for(int k=0;k<d;k++) {
					a+= (x[i][k]-x[j][k])*(x[i][k]-x[j][k]) ;
				}
				if(Math.sqrt(a) == (int)Math.sqrt(a) ) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21844
#define P(x) cout << #x " = " << x << endl
#define PP(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define PPP(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl

#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

int x[5];
int k;
int main()
{
    for (int i = 0; i < 5; ++i) {
        cin >> x[i];
    }
    cin >> k;
    bool ok = true;
    for (int i = 0; i < 5; ++i) {
        for (int j = 0; j < 5; ++j) {
            if (abs(x[i] - x[j]) > k) {
                ok = false;
            }
        }
    }
    cout << (ok ? "Yay!" : ":(") << endl;
}

Measured memory_bytes: 888
n = int(input())
a = list(map(int,input().split()))
nagasa = sum(a)
now = 0
for i in range(n):
    if now + a[i] < nagasa/2:
        now += a[i]
    elif now + a[i] == nagasa/2:
        print(0)
        exit()
    elif now + a[i] > nagasa/2:
        print(min(nagasa-2*now,2*(now+a[i])-nagasa))
        exit()

Measured memory_bytes: 26764
def is_int(s):
    try:
        i = int(s)
    except:
        return False
    return True

str = input().split()

if (len(str) > 2):
    print("Too many arguments.")
    exit()
elif (len(str) < 2):
    print("Too few arguments.")
    exit()
elif (not is_int(str[0])):
    print("H is not a number.")
    exit()
elif (not is_int(str[1])):
    print("W is not a number.")
    exit()

H = int(str[0])
W = int(str[1])

str = input().split()

if (len(str) > 2):
    print("Too many arguments.")
    exit()
elif (len(str) < 2):
    print("Too few arguments.")
    exit()
elif (not is_int(str[0])):
    print("h is not a number.")
    exit()
elif (not is_int(str[1])):
    print("w is not a number.")
    exit()

h = int(str[0])
w = int(str[1])

if (H < 1 or H > 20):
    print("Out of range at H.")
    exit()
elif (W < 1 or W > 20):
    print("Out of range at W.")
    exit()
elif (h < 1 or h > 20 or h > H):
    print("Out of range at h.")
    exit()
elif (w < 1 or w > 20 or w > W):
    print("Out of range at w.")
    exit()

print((H - h) * (W - w))

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

int main()
{
	int a[10],k;
	for(int i=0;i<5;i++){
		cin>>a[i];
	}
	cin>>k; int su = 0,flag = 0;
		su = a[4] - a[0];
		if(su>k){
			flag = 1;
		}
	if(flag == 0){
		cout<<"Yay!"<<endl; 
	}else {

		cout<<":("<<endl; 
	}
	return 0;
}

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

int main(void)
{
    int r;

    scanf("%d" , &r);

    if(r<1200)
        printf("ABC\n");
    else if(r>=2800)   
        printf("AGC\n");
    else
        printf("ARC\n");
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;
void visit(int u){
    int v;
    color[u]=GRAY;
    d[u]=++tt;
    for(v=0;v<n;v++){
        if(M[u][v]==0)continue;
        if(color[v]==WHITE){
            visit(v);
        }
    }
    color[u]=BLACK;
    f[u]=++tt;
}
void dfs(){
    int u;
    for(u=0;u<n;u++)color[u]=WHITE;
    tt=0;
    for(u=0;u<n;u++){
        if(color[u]==WHITE)visit(u);
    }
    for(u=0;u<n;u++){
        printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}

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


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  vi v(n);
  vi c(n);
  rep(i,n){
    cin >> v[i];
  }
  rep(i,n){
    cin >> c[i];
  }
  ll ans = 0;
  rep(i,n){
    if(v[i]-c[i]>0){
      ans += v[i] - c[i];
    }
  }
  print(ans);
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> time(n - 1, vector<int> (3));
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> time.at(i).at(j);
        }
    }
    for (int i = 0; i < n - 1; i++) {
        int a = 0;
        a += time.at(i).at(1) + time.at(i).at(0);
        for (int j = i + 1; j < n - 1; j++) {
            if (a <= time.at(j).at(1)) {
                a = time.at(j).at(1);
            }
            else {
                int c = a / time.at(j).at(2);
                if (a % time.at(j).at(2) != 0) c++;
                a = c * time.at(j).at(2);
                }
            a += time.at(j).at(0);
        }
        cout << a << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc128/tasks/abc128_b
// implementation
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

struct restaurant {
    string name;
    int score;
    int index;

    int opCmp(restaurant rhs) const {
        if(name == rhs.name)
            return rhs.score - score;
        return cmp(name, rhs.name);
    }
}

void main() {
    const int n = readln.chomp.to!int;
    restaurant[] restaurants;

    for(int i = 1; i <= n; i++) {
        string name;
        int score;
        readf("%s %s\n", &name, &score);
        restaurant r = restaurant(name, score, i);
        restaurants ~= r;
    }

    restaurants.sort;

    foreach(r; restaurants)
        r.index.writeln;
}



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

int exp();
int term();
int factor();
int number();
int digit();

string str;

int p,len,val;

int exp(){
  int val = term();
  while( str[p] == '+' || str[p] == '-' ){
    if( str[p] == '+' ){
      p++;
      val += term();
    }else if( str[p] == '-' ){
      p++;
      val -= term();
    }
  }
  return val;
}

int term(){
  int val=factor();
  while( str[p] == '*' || str[p] == '/' ){
    if( str[p] == '*' ){
      p++;
      val *= factor();
    }else if( str[p] == '/' ){
      p++;
      val /= factor();
    }
  }
  return val;
}

int factor(){
  int val;
  if( str[p] == '(' ){
      p++;
      val =  exp();
      p++;
  }else{
    val = number();
  }

  return val;
}

int number(){
  int val = 0;
  while( digit() ){
    int num = str[p] - '0';
    val = val * 10 + num;
    p++;
  }
  return val;
}

int digit(){
  if( str[p] == '1' || str[p] == '2' || str[p] == '3' || str[p] == '4' ||
      str[p] == '5' || str[p] == '6' || str[p] == '7' || str[p] == '8' ||
      str[p] == '9' || str[p] == '0' ) return 1;
  return 0;
}

  
int main(){
  int n; cin >> n;
  
  for(int i = 0; i < n; i++ ){
    p = 0;
    cin >> str;
    
    int ans = exp();      
    
    cout << ans << endl;
    
  }
  
  return 0;
}

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


const int MAX = 1000001;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main()
{
    int X, Y; cin >> X >> Y;
    if ((X + Y) % 3 != 0 || Y > 2 * X || X > 2 * Y) {
        cout << "0" << endl;
        return 0;
    }


    double XpYd3 = (X + Y) / 3;
    int m = Y - XpYd3;
    int n = X - XpYd3;

    COMinit();
    
    long long ans = COM(m+n, m)%MOD;
    cout << ans << endl;
}


Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;


int main(){
	int n, y;
	cin >> n >> y;
	for (int i = 0; i <= 2000; i++){
		for (int j = 0; i+j <= 2000; j++){
			for (int k = 0; i+j+k <= 2000; k++){
				if (i+j+k == n && i*1000 + j*5000 + k*10000 == y){
					cout << k << " " << j << " " << i << endl;
					return 0;
				}
			}	
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}



Measured memory_bytes: 3628