akhauriyash/Code-Regression huggingface dataset:
import heapq
import sys
def main():
    N = int(sys.stdin.readline())
    A = list(map(int,sys.stdin.readline().split()))
    front = A[:N]
    back = list(map(lambda x:x*(-1),A[2*N:]))
    heapq.heapify(front)
    heapq.heapify(back)
    s1 = sum(front)
    s2 = sum(back)
    s1_list = [s1]
    ans = 0
    for i in range(N,2*N):
        a = A[i]
        heapq.heappush(front,a)
        min_front = heapq.heappop(front)
        s1 = s1-min_front+a
        s1_list.append(s1)
    ans = s2 +s1_list.pop()
    for i in reversed(range(N,2*N)):
        b = -A[i]
        heapq.heappush(back,b)
        min_back = heapq.heappop(back)
        s2 = s2-min_back+b
        ans = max(ans,s2+s1_list.pop())
    print(ans)

if __name__ == "__main__":
    main()

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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

vector<LL> InputVec(LL size) {
	vector<LL> vec((size_t)size);
	REP(i, size) {
		cin >> vec[(size_t)i];
	}
	return vec;
}

void chmin(LL& a, LL b) {
	a = min(a, b);
}
void chmax(LL& a, LL b) {
	a = max(a, b);
}


LL tbl[1000000][3];

LL value[1000000][3];

int main()
{
	LL N;
	cin >> N;
	REP(i, N) {
		REP(j, 3) {
			cin >> value[i][j];
			tbl[i][j] = 0;
		}
	}

	REP(j, 3) {
		tbl[0][j] = value[0][j];
	}

	REP(i, N - 1) {
		REP(j, 3) {
			REP(k, 3) {
				if (j == k) {
					continue;
				}

				chmax(tbl[i + 1][j], tbl[i][k] + value[i+1][j]);
			}
		}
	}

	LL result = 0;
	REP(j, 3) {
		chmax(result, tbl[N - 1][j]);
	}

	cout << result << endl;

	return 0;
}


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

typedef long long ll;

#define rep(var,n) for(int var=0;var<(n);++var)

int main(){

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

  int ret=0;
  int n,k; cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];

  sort(h.begin(),h.end());
  rep(i,n){
    if(h[i]>=k){
      ret = n-i;
      break;
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef __int128 lll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const ll inf=2e18;
const int lim=70,N=75;
ll f[N][N][N][2],val[N][N][N][2],num[N][N][N];
ll A,B,C,D,n;

void cmin(ll &x,lll y){
	if(y<x) x=y;
}

void rmain(){
	read(n);
	read(A),read(B);
	read(C),read(D);
	memset(f,0x3f,sizeof f);
	per(i,lim,0) per(j,lim,0) per(k,lim,0){
		if(!num[i][j][k]) continue;
		ll owo=num[i][j][k];
		val[i][j][k][0]=n%owo;
		val[i][j][k][1]=(owo-n%owo)%owo;
		cmin(f[i][j][k][0],(lll)n/owo*D+i*A+j*B+k*C);
		cmin(f[i][j][k][1],f[i][j][k][0]+D);
		REP(t,2){
			if(f[i+1][j][k][t]<inf){
				REP(p,2){
					cmin(f[i][j][k][t^p],f[i+1][j][k][t]
						+(lll)(val[i+1][j][k][t]/owo+p)*D);
				}
			}
			if(f[i][j+1][k][t]<inf){
				REP(p,2){
					cmin(f[i][j][k][t^p],f[i][j+1][k][t]
						+(lll)(val[i][j+1][k][t]/owo+p)*D);
				}
			}
			if(f[i][j][k+1][t]<inf){
				REP(p,2){
					cmin(f[i][j][k][t^p],f[i][j][k+1][t]
						+(lll)(val[i][j][k+1][t]/owo+p)*D);
				}
			}
		}
	}
	cout<<min(f[0][0][0][0],f[0][0][0][1])<<endl;
}

int main(){
	rep(i,0,lim) rep(j,0,lim) rep(k,0,lim){
		ll val=1;	
		REP(t,i){
			if(val>inf/2) val=0;
			val*=2;
		}
		REP(t,j){
			if(val>inf/3) val=0;
			val*=3;
		}
		REP(t,k){
			if(val>inf/5) val=0;
			val*=5;
		}
		num[i][j][k]=val;
	}
	int T; read(T);
	while(T--) rmain();
	return 0;
}

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

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define FORR(i,a,b) for (int i = a; i <= b; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

const int MX = 105;
int n, x, a[MX];
ll sum = 0;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}

	sort(a, a+n);

	int i = n;
	while (sum > x) {
		i--;
		sum -= a[i];
	}

	if (sum == x) cout << i << endl;
	else cout << min(i, n-1) << endl;

	return 0;
}

Measured memory_bytes: 256
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
	for(int i=1;i<=5;i++)
	{
		cin>>x;
		if(x==0)
		{
			cout<<i;
			return 0;
		}
		
	}
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n; cin >> n;
    vi l(n); rep(i,n) cin >> l[i];
    sort(all(l));
    int cnt = 0;
    for(int i = 0; i < n-2; i++) {
        for(int j = i+1; j < n-1; j++) {
            for(int k = j+1; k < n; k++) {
                if(l[k] < l[j]+l[i]) cnt++;
            }
        }
    }

    cout << cnt << '\n';

}

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

const int N = 55;

int h, w;
string grid[N];
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

bool valid(int x, int y) {
	return (x >= 0 and x < h and y >= 0 and y < w);
}

int main () {
	cin >> h >> w;
	for (int i = 0; i < h; i++)
		cin >> grid[i];
	bool ok = 1;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			if (grid[i][j] == '.') continue;
			int nums = 0;
			for (int k = 0; k < 4; k++) {
				if (valid(i+dx[k], j+dy[k]))
					nums += (grid[i+dx[k]][j+dy[k]] == '#');
			}
			if (nums == 0) 
				ok = 0;
		}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func eulerPhi(n int) int {
	res := n
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			res = res / i * (i - 1)
			for ; n%i == 0; n /= i {
			}
		}
	}
	if n != 1 {
		res = res / n * (n - 1)
	}
	return res
}

func main() {
	n := 0
	fmt.Scan(&n)
	fmt.Println(eulerPhi(n))
}



Measured memory_bytes: 1140
import math
n,d = map(int, input().split())
x = [0] * n
for i in range(n):
    x[i] = list(map(int, input().split()))
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        temp = 0
        for k in range(d):
            temp = temp + (x[i][k]-x[j][k])**2
        temp = math.sqrt(temp)
        if temp.is_integer() == True:
            count += 1
print(count)

Measured memory_bytes: 9092
#include<cstdio>
#include<cmath>
using namespace std;
long long n,ans;
int s;
int main(){
    scanf("%lld",&n);
    for(int i=sqrt(n);i>0;--i)
        if(n%i==0){
            ans=n/i;
            break;
        }
    while(ans>0){
        ++s;
        ans/=10;
    }
    printf("%d\n",s);
    return 0;
}


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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define no cout << "No" << endl
#define yes cout << "Yes" << endl
#define tc ll t; cin >> t; while (t--)
#define sz(c) (ll) (c).size()
#define trav(x,c) for(auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rll(c) (c).rbegin(), (c).rend()
#define _for(i,a,n) for(ll i = a ; i < n; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);

int main() {
    godspeed;
    ll n, m, x; cin >> n >> m;

    while(m--) {
        cin >> x;
        n -= x;
    }

    if(n <= 0) yes;
    else no;   
}

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

using namespace std;

int main(){
    
    string s;
    cin >> s;
    int ans = 0;
    
    for (int i = 0; i < (s.length()); i++) {
        if(s.substr(i,1) == "A" || s.substr(i,1) == "C" || s.substr(i,1) == "G" || s.substr(i,1) == "T"){
            int an = 1;
            for (int j = 1; j < (s.length()-i); j++) {
                if(s.substr(i+j,1) == "A" || s.substr(i+j,1) == "C" || s.substr(i+j,1) == "G" || s.substr(i+j,1) == "T"){
                    an += 1;
                }else{
                    break;
                }
            }
            if(an > ans){
                ans = an;
                
            }
            
        }
        
        
    }

    cout << ans << endl;
    
    


    return 0;
    
}


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

int d[201][201];
int r[9];
int res;
bool used[9];
int N, M, R;

void dfs(int c, int las, int dist){
    if(c == R + 1){
        if(res > dist){
            res = dist;
        }
        return;
    }

    for(int i = 1; i <= R; i++){
        if(!used[i]){
            used[i] = true;
            if(las == -1){
                dfs(c+1, i, 0);
            }else{
                dfs(c+1, i, dist + d[r[las]][r[i]]);
            }
            used[i] = false;
        }
    }
}

int main(void){

    scanf("%d%d%d", &N, &M, &R);

    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            if(i != j){
                d[i][j] = 1000000000;
            }
        }
    }

    for(int i = 1; i <= R; i++){
        scanf("%d", &r[i]);
    }

    for(int i = 1; i <= M; i++){
        int A, B, C;
        scanf("%d%d%d", &A, &B, &C);
        if(d[A][B] > C){
            d[A][B] = d[B][A] = C;
        }
    }

    for(int k = 1; k <= N; k++){
        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= N; j++){
                if(d[i][j] > d[i][k] + d[k][j]){
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }

    res = 1000000000;

    dfs(1, -1, 0);

    printf("%d\n", res);

    return 0;
}

Measured memory_bytes: 1892
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<vector<int> > edge(n,vector<int>());
	REP(i,n){
		int v;cin>>v;v--;int t;cin>>t;
		while(t--){
			int u;cin>>u;u--;
			edge[v].push_back(u);
		}
	}
	queue<pair<int,int> > que;
	int mindist[103];
	fill_n(mindist,n,INF);
	mindist[0] = 0;
	que.push(make_pair(0,0));
	while(!que.empty()){
		pair<int,int> v = que.front();
		que.pop();
		v.second++;
		REP(i,edge[v.first].size()){
			if(v.second < mindist[edge[v.first][i]]){
				mindist[edge[v.first][i]] = v.second;
				que.push(make_pair(edge[v.first][i],v.second));
			}
		}
	}
	REP(i,n){
		cout << i+1 << ' ';
		if(mindist[i]==INF)cout << -1 << endl;
		else	cout << mindist[i] << endl;
	}
  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h> 
using namespace std;
#define int long long
typedef vector<int> vi;

signed main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l = 0, r = n-1;
    int cnt = 0;
    while (l < r)
    {
        while (l < n and s[l] == 'R')
            l++;
        while (r >= 0 and s[r] == 'W')
            r--;
        if (l < r)
        {
            swap(s[l], s[r]);
            l++;
            r--;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

const int MOD = 1e9 + 7;

inline int add(int x, int y){
	int res = x + y;	
	while(res >= MOD)res-=MOD;
	return res;
}

inline int mul(int x,int y){
	return (1LL * x * y) % MOD;
}

int modpow(int x,int p){
	int res = 1;
	while(p){
		if(p&1)gmul(res,x);
		gmul(x,x);
		p/=2;
	}
	return res;
}

inline int invert(int x){
	return modpow(x,MOD - 2);
}

const int N = 1e6;

int fac[N], inv[N];

void init(int n){
	fac[0] = inv[0] = 1;
	for(int i = 1;i < n; ++i){
		fac[i] = mul(fac[i-1], i);	
		inv[i] = invert(fac[i]); 
	}
}

int comb(int n,int k){
	return mul(fac[n],mul(inv[k], inv[n-k]));	
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,k;
	cin >> n >> k;
	bool zero = false;
	vi pos, neg, tot;
	rep(i,0,n){
		int x;
		cin >> x;
		if(x == 0)zero = 1;
		else if(x < 0){
			neg.push_back(x);	
		}
		else{
			pos.push_back(x);	
		}

		if(x != 0)tot.push_back(abs(x));
	}
	sort(pos.rbegin(),pos.rend());
	sort(all(neg));
	bool pospos = false;
	int curbest = 0;
	for(int i = 0;i <= neg.size() && i <= k; i+=2){
		if(pospos == false){
			if(k - i <= int(pos.size())){
				pospos = true;	
				curbest = 1;
				rep(j,0,k-i)gmul(curbest, pos[j]);
				rep(j,0,i)gmul(curbest, MOD+neg[j]);
			}
		}
		else{
			if(k - i <= int(pos.size())){
				ll div = 1LL * pos[k-i] * pos[k-i+1];
				ll m = 1LL * neg[i-2] * neg[i-1];
				if(div < m){
					// update	
					gmul(curbest, invert(div % MOD));
					gmul(curbest, m % MOD);
				}
			}
		}
	}
	if(pospos){
		cout << curbest << '\n';
	}
	else if(zero){
		cout << 0 << '\n';
	}
	else{
		sort(all(tot));
		int res = 1;
		rep(i,0,k)gmul(res,tot[i]);
		res = (MOD - res) % MOD;
		cout << res << '\n';
	}
}


Measured memory_bytes: 5404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
using ping = pair<ll, ll>;

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    ll total = 0;
    for (int i = 0; i < N; i++) {
      cin >> A[i];
      total += A[i];
    }
      ll cnt = 0;
      for (int i = 0; i < N; i++) {
        if (A[i] * 4 * M < total) continue;
        else
          cnt++;
      }
    if(cnt>=M)cout << "Yes" << endl;
    else cout <<"No" << endl;
    return 0;
}

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

int main(void){
	int n;
	cin >> n;
	vector<int> l(n);
	for(int i = 0; i < n; ++i){
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	long long ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j = i+1; j < n; ++j){
			int left = -1;
			int right = n;
			int key1 = max(l[i]-l[j], l[j]-l[i]);
			int key2 = l[i]+l[j];
			while (right - left > 1) {
        		int mid = left + (right - left) / 2;

        		if (l[mid] > key1) right = mid;
        		else left = mid;
    		}
    		int ll = right;
    		left = -1;
			right = n;
    		while (right - left > 1) {
        		int mid = left + (right - left) / 2;

        		if (l[mid] >= key2) right = mid;
        		else left = mid;
    		}
    		int rr = left;
    		ll = max(ll, j);
    		ans += max(rr-ll, 0);
    		// cout << i << " " << j << " ";
    		// cout << l[ll] << " " << l[rr] << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
int m,p;

while(cin>>m>>p && m!=0){
int a[55]={0};
int no=0,is=p;
while(1){
if(is>0){
is--;
a[no]++;
}
else if(a[no]>0){
is=is+a[no];
a[no]=0;
}
//cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<is<<" "<<no<<endl;
if(a[no]==p) break;

no=no+1;
no=no%m;

//cout<<no<<" "<<is<<endl;

}
cout<<no<<endl;
}

return 0;
}

Measured memory_bytes: 1160
n,y=map(int,input().split())

ans=0
for i in range(n+1):
    for j in range(n-i+1):
        k=n-i-j
        if 10000*i+5000*j+1000*k==y:
            ans+=1
            print(str(i),str(j),str(k))
            break
    else:
        continue
    break
if ans==0:
    print("-1 -1 -1")

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
using namespace std;




void solve(string A){
	long long tot = 1ll * A.size() * (A.size()+1) / 2;
	map<char,long long> c;
	for(int i = 0 ; i < A.size() ; i++){
		c[A[i]]++;
		tot -= c[A[i]];
	}
	cout << tot + 1 << endl;
}

int main(){	
	string A;
	cin >> A;
	solve(A);
	return 0;
}



Measured memory_bytes: 772
#include <stdio.h>
#include <math.h>

int Prime(int x)
{
  int z;
  if(x == 2) return 1;
  if(x < 2 || x%2 == 0) return 0;
  z = 3;
  while(z <= sqrt(x)){
    if(x%z == 0) return 0;
    z += 2;
  }
  return 1;
}

int main()
{

  int n, i, num[10000], count=0;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &num[i]);
    if(Prime(num[i]) == 1) count++;
  }

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

Measured memory_bytes: 2672
#include<bits/stdc++.h>
using namespace std;
int a[100005][4];
int dp[100005][4];
int n;
 
int func(int ind, int flag) {
 
	if (ind == n) return 0;
 
	if (dp[ind][flag] != -1) return dp[ind][flag];
 
	int maxi = 0;
	if (flag == 0) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 1) {
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 2) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
	}
 
	return dp[ind][flag] = maxi;
}
 
int main() {
 
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}
 
	memset(dp, -1, sizeof dp);
 
	cout << func(0, 0);
 
	return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    int a[H][W];
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) cin >> a[i][j];
    }

    int N = 0, x1[H * W], y1[H * W], x2[H * W], y2[H * W];
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W - 1; ++j) {
            if (a[i][j] % 2) {
                --a[i][j]; ++a[i][j + 1];
                y1[N] = i + 1; x1[N] = j + 1;
                y2[N] = i + 1; x2[N] = j + 2;
                ++N;
            }
        }
    }
    for (int i = 0; i < H - 1; ++i) {
        if (a[i][W - 1] % 2) {
            --a[i][W - 1]; ++a[i + 1][W - 1];
            y1[N] = i + 1; x1[N] = W;
            y2[N] = i + 2; x2[N] = W;
            ++N;
        }
    }

    cout << N << endl;
    for (int i = 0; i < N; ++i) {
        cout << y1[i] << ' ' << x1[i] << ' ' << y2[i] << ' ' << x2[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a%3==0)
	{
		cout<<"Possible"<<endl;
		return 0;
	}
	if(b%3==0)
	{
		cout<<"Possible"<<endl;
		return 0;
	}
	if((a+b)%3==0)
	{
		cout<<"Possible"<<endl;
		return 0;
	}
	cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<map>
#include<queue>
#include<assert.h>
#include<stdio.h>
#include<stack>
#include<cstring>
#include<fstream>
using namespace std;
int main()
{
	int n, s[105] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	cin >> n;
	cout << s[n - 1] << endl;
	return 0;
}

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

bool judge(int N, const vector<int> &S){
  int L = S.size();
  vector<int> V;
  vector<bool> A(L,false);
  A[0] = true;
  V.push_back(S[0]);
  for(int i = 0; i < N; ++i){
    sort(V.rbegin(), V.rend());
    size_t l = 0;
    vector<int> V_;
    for(int j = 0; j < (1<<N); ++j){
      if(A[j]) continue;
      if(S[j] >= V[l]) continue;
      ++l;
      A[j] = true;
      V_.push_back(S[j]);
      if(l == V.size()) break;
    }
    if(l != V.size()) return false;
    V.insert(V.end(),V_.begin(),V_.end());
  }
  bool ret = true;
  for(auto e : A) ret &= e;
  return ret;
}

int main(){
  int N;
  cin >> N;
  vector<int> S(1<<N);
  for(int i = 0; i < (1<<N); ++i)
    cin >> S[i];
  sort(S.rbegin(), S.rend());
  // for(auto e : S)
  //   cerr << e << " " ;
  // cerr << endl;
  if(judge(N,S)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3440
#include <stdio.h>

int main(){
   long n,k,a,b,j,ans;
 
   scanf("%ld %ld",&a,&b);
   while ((k=a%b)>0) {
      a=b;b=k;
   }
   ans=1;
   for (k=2;b>1 && b>=k*k;) {
      for (j=0;b%k==0;j++) b=b/k;
      if (j>0) ans++;
      if (k==2) k++;
      else      k+=2;
   }
   if (b>=k) ans++;
   printf("%ld\n",ans);
   return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long a, long long b){
    if(a<=0 && b >=0){
        cout<<"Zero"<<endl; return;
    }
    else if( a > 0){
        cout << "Positive"<<endl; return;
    }
    else if( b< 0){
        if( (b-a)%2 ){
            cout << "Positive"<<endl; return;
        }
        else{
            cout << "Negative"<<endl; return;
        }
    }
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b;
    while(~scanf("%d%d",&a,&b))
	{
		if((a+b)%3==0||a%3==0||b%3==0) printf("Possible\n");
		else printf("Impossible\n");
	}
	return 0;
}


Measured memory_bytes: 128
# -*- coding:utf-8 -*-

def calc(S, T):
    # 差を計算する
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1
    return ans


def solve():
    s = input()
    S = [moji for moji in s]
    T = input()

    # 文字の置き換えをして、差が減ってなかったら無理？
    
    diff = calc(S, T)
    if diff == 0:
        print("Yes")
        return

    pre_diff = diff

    while True:
        # c1, c2を決める
        for i in range(len(S)):
            if S[i] != T[i]:
                c1 = S[i]
                c2 = T[i]
                break
        
        # 文字を置き換える
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
        
        # 差を計算する
        diff = calc(S, T)
        if diff == 0:
            print("Yes")
            return
        elif diff < pre_diff:
            pre_diff = diff
            continue
        else:
            print("No")
            return


if __name__ == "__main__":
    solve()

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

int N;
ll A[MAXN];
ll dp[MAXN][2][2];

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

	if(N % 2 == 0)
	{
			dp[0][0][0] = 0;
			for(int i = 1; i <= N; ++i)
			{
					if(i % 2 == 0)
					{
							dp[i][1][0] = max(dp[i][1][0], dp[i-1][0][0] + A[i]);
							dp[i][0][0] = max(dp[i][0][0], dp[i-1][1][1]);
					}
					else
					{
						dp[i][0][0] = max(dp[i][0][0], dp[i-1][1][0]);
						dp[i][0][0] = max(dp[i][0][0], dp[i-1][0][0]);
						dp[i][1][1] = max(dp[i][1][1], dp[i-1][0][0] + A[i]);
					}
			}
		
	}
	else
	{
		dp[0][0][1] = 0;
			for(int i = 1; i <= N; ++i)
			{
					if(i % 2 == 0)
					{
							dp[i][0][0] = max(dp[i][0][0], dp[i-1][1][0]);
							dp[i][0][0] = max(dp[i][0][0], dp[i-1][0][0]);
							dp[i][0][1] = max(dp[i][0][1], dp[i-1][1][1]);
							dp[i][1][1] = max(dp[i][1][1], dp[i-1][0][0] + A[i]);
					}
					else
					{
						dp[i][0][0] = max(dp[i][0][0], dp[i-1][1][1]);
						dp[i][0][0] = max(dp[i][0][0], dp[i-1][0][1]);
						dp[i][1][0] = max(dp[i][1][0], dp[i-1][0][0] + A[i]);
						dp[i][1][1] = max(dp[i][1][1], dp[i-1][0][1] + A[i]);
					}
			}
	}
	if(N % 2 == 0)
		cout<<max(dp[N][1][0], dp[N][0][0])<<endl;
	else
		cout<<max(dp[N][0][0], dp[N][1][0])<<endl;
}


Measured memory_bytes: 11448
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/
double dist(double a, double b) {
	return a*a + b*b;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  double X = 0, Y = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    X += x[i];
    Y += y[i];
  }
  X /= n, Y /= n;
	double P = 0.1, d;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			double e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
  
  cout.precision(9);
  cout << fixed << sqrtl(d) << '\n';
}


Measured memory_bytes: 256
def check(N, H):
    max_mount = 0
    count = 0
    mountList = H
    
    for i in mountList:
        if i >= max_mount:
            count += 1
            max_mount = i
    print(count)

N = int(input())
H = [int(i) for i in input().split()]
check(N, H)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define m 1000000007
#define ll long long int
int main()
{
    int h,w;
    cin>>h>>w;
    char c[h][w];
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            cin>>c[i][j];
    vector<vector<ll> >dp(h,vector <ll> (w));
    dp[0][0]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(c[i][j]=='.'){
                if(i+1<h && c[i+1][j]=='.')
                    dp[i+1][j]=(dp[i+1][j]+dp[i][j])%m;
                if(j+1<w && c[i][j+1]=='.')
                    dp[i][j+1]=(dp[i][j+1]+dp[i][j])%m;
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  int a,b; cin >> a >> b;
  int g = gcd(a,b);
  ll ans = (ll)a*b/g;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))

import sys

INT_MAX = sys.maxsize

ans = INT_MAX
for i in range(1, len(W)):
    a = sum(W[:i])
    b = sum(W[i:])
    ans = min(ans, abs(a-b))
    
print(ans)
    

Measured memory_bytes: 38512
n=int(input())
a=list(map(int,input().split()))
b={}
for i in range(len(a)):
    b[a[i]]=i
a.sort()
x=[]
for i in range(n):
    if i!=b[a[i]]:
        x.append([i,b[a[i]]])
if(len(x)>2):
    print("NO")
elif(len(x)==2 and x[0][0]!=x[1][1]):
    print('NO')
else:
    print("YES")

Measured memory_bytes: 38256
#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#include <unordered_set>

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int res = 0;
	for (int i = 1; i < n; i++) {
		if (s[i - 1] == s[i]) {
			int j = i;
			while (j < n && s[j] == s[j - 1]) j++;
			i = j;
		}
		res++;
	}

	if (s[n - 1] != s[n - 2]) res++;

	cout << res;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <stdlib.h>
 
using namespace std;
 
int w, h;
int mindepth = 0;
int d[4][2] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } }; 

bool isValid( int x, int y ) {
	return !( x < 0 || y < 0 || x >= w || y >= h ); 
}

void dfs_search( vector< vector< int > > map, int x, int y, int depth ) {
	if( depth >= 10 || depth >= mindepth ) return;
	for( int i = 0; i < 4; i++ ) {
		vector< vector< int > > currentmap = map;
		int cx = x, cy = y;
		if( !isValid( cx + d[i][1], cy + d[i][0] ) || currentmap[cy + d[i][0]][cx + d[i][1]] == 1 ) continue;
		for( ;isValid( cx, cy ); cx += d[i][1], cy += d[i][0] ) {
			if( currentmap[cy][cx] == 1 ) {
				currentmap[cy][cx] = 0;
				dfs_search( currentmap, cx - d[i][1], cy -  d[i][0], depth + 1 );
				break;
			}
			if( currentmap[cy][cx] == 3 ) {
				mindepth = depth + 1;
				break;
			}
		}
	}
	
}

int main(void){
 
	while( true ) {
		cin >> w >> h;
		if( !( w | h ) ) break;
		mindepth = 1 << 30;
		vector< vector< int > > startmap( h, vector< int >( w, 0 ) );
		int sx, sy;
		for( int i = 0; i < h; i++ ) {
			for( int j = 0; j < w; j++ ) {
				cin >> startmap[i][j];
				if( startmap[i][j] == 2 ) {
					startmap[i][j] = 0;
					sx = j; sy = i;
				}
			}
		}
		dfs_search( startmap, sx, sy, 0 );
		if( mindepth == ( 1 << 30 ) ) mindepth = -1;
		cout << mindepth << endl;
	}

	return 0;
}

Measured memory_bytes: 1340
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

k = int(input())
temp = [[xgcd(i, j) for i in range(1, k+1)] for j in range(1, k+1)]
ans = 0
for a in range(k):
    for b in range(k):
        t = temp[a][b]
        for c in range(k):
            ans += temp[t-1][c]
print(ans)

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

int main(){
  string b;
  cin >> b;
  
  if(b=="A"){
    cout << "T" ;
  }
  else if(b=="T"){
    cout << "A" ;
  }
  else if(b=="C"){
    cout << "G" ;
  }else{
    cout << "C";
  }
}

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

int main(){
  char c;
  int s[26]={};
  for(;cin>>c;) s[c-'a']++;
  fr(i,26){
    if(s[i]<1){
      cout<<(char)('a'+i)<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int h=0,m=0,s=0;
	scanf("%d",&s);
	if(s>=60*60){
		h=s/60/60;s=s%(60*60);
	}
	if(s>=60){
		m=s/60;s=s%60;
	}
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

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

#define int long long

using namespace std;

signed main(void)
{
	ios_base::sync_with_stdio(false);
	
	cin.tie(0);
	
	int n;
	
	cin >> n;
	
	cout << (n >= 30 ? "Yes\n" : "No\n");
	
	return 0;
} 

Measured memory_bytes: 3688
import java.util.Scanner;

//M-SOLUTIONS プロコンオープン
//A - Security
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();

		char pre = ' ';
		for (int i = 0; i < S.length(); i++) {
			if (S.charAt(i) == pre) {
				System.out.println("Bad");
				return;
			}
			pre = S.charAt(i);
		}

		System.out.println("Good");

	}
}


Measured memory_bytes: 23252
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	myout(one[0] * one[1]);
}


Measured memory_bytes: 30112
// And you curse yourself for things you never done

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 2e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;

int visi[maxn]; //////

vector< pair<char, pair<int, pii> > > ANSP;

int ZERO, ONE;

int NEW();

int sum(int a, int b, int c = -1){
    if(c == -1)
	c = NEW();
    ANSP.PB({'+', {a, {b, c}}});
    
    visi[c] = visi[a] + visi[b];
    
    return c;
}
int comp(int a, int b, int c = -1){    
    if(c == -1)
	c = NEW();
    ANSP.PB({'<', {a, {b, c}}});

    visi[c] = visi[a] < visi[b];
    
    return c;
}
int comp2(int a, int b, int c = -1){
    if(c == -1)
	c = NEW();
    comp(b, a, c);
    comp(c, ONE, c);
    return c;
}

vector<int> VEC;
void init(){
    for(int i = 3; i < 200000; i++)
	VEC.PB(i);
    ZERO = NEW();
    int tmp1 = comp(ZERO, 0);
    int tmp2 = comp(ZERO, 1);
    sum(tmp1, tmp2, tmp1);
    ONE = comp(ZERO, tmp1);
}
int NEW(){
    assert(sz(VEC));
    int ans = VEC.back();
    VEC.pop_back();
    return ans;
}
void FREE(int x){
    sum(ZERO, ZERO, x);
    VEC.PB(x);
}
int _and(int a, int b, int c = -1){    
    if(c == -1)
	c = NEW();
    int tmp = NEW();
    sum(a, b, tmp);
    comp(ONE, tmp, c);
    FREE(tmp);
    return c;
}
void PW(int pos, int k){
    for(int i = 0; i < k; i++)
	sum(pos, pos, pos);
}

const int Log = 31; ///////

int Mul(int a, int b, int c = -1){// a = 0 or 1
    if(c == -1)
	c = NEW();    
    int tmp = NEW();
    for(int lg = Log-1; lg >= 0; lg--){
	sum(ZERO, a, tmp);
	PW(tmp, lg);
	sum(tmp, c, tmp);
	comp2(tmp, b, tmp);
	_and(tmp, a, tmp);
	PW(tmp, lg);
	sum(tmp, c, c);
    }
    FREE(tmp);
    return c;
}

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

    init();
    
    int tmp = NEW(), c = NEW();
    for(int lg = Log-1; lg >= 0; lg--){
	sum(ZERO, ONE, tmp);
	PW(tmp, lg);
	sum(tmp, c, tmp);
	comp2(tmp, 0, tmp);

	int tmp2 = Mul(tmp, 1);
	
	PW(tmp, lg);
	sum(tmp, c, c);

	PW(tmp2, lg);
	sum(tmp2, 2, 2);
    }
    //    FREE(tmp), FREE(Counter);    
    cout << sz(ANSP) << "\n";
    for(auto x : ANSP){
	cout << x.F << " " << x.S.F << " " << x.S.S.F << " " << x.S.S.S << "\n";
    }    
    return 0;
}


Measured memory_bytes: 5404
# your code goes here
import numpy as np
buf = input().split()
n = int(buf[0])
m = int(buf[1])

l = np.zeros((m, 2))
for i in range(m):
	buf = input().split()
	for j in range(2):
		l[i][j] = int(buf[j])
l = l[l[:,1].argsort(), :]
#print(l)
sum = 0
c1 = 0
c2 = 0
for i in range(m):
	b1 = l[i][0]
	b2 = l[i][1]
	if(b1 >= c2):
		sum += 1
		c1 = b1
		c2 = b2
	elif(b2 < c2):
		c2 = b2
	#print(c1, c2, sum)
print(sum)


Measured memory_bytes: 20960
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

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

class TaskC {
 public:
  void solve(std::istream &in, std::ostream &out) {
    int A, B, C, D, E, F;  // input
    in >> A >> B >> C >> D >> E >> F;
    A *= 100;
    B *= 100;

    int water = min(A, B), sugar = 0;  // output
    int mx_density = 0;

    for (int i = 0; A * i <= F; i++) {
      for (int j = 0; A * i + B * j <= F; j++) {
        int w = A * i + B * j;  // temporary water
        if (w == 0) {
          continue;
        }

        // sugar <= water * E && water + sugar <= F
        for (int k = 0; (C * k <= (w / 100) * E) && (w + C * k <= F); k++) {
          for (int l = 0;
               (C * k + D * l <= (w / 100) * E) && (w + C * k + D * l <= F);
               l++) {
            int s = C * k + D * l;  // temporary sugar

            int density = s * 10000 / (w + s);
            if (density > mx_density) {
              mx_density = density;
              water = w;
              sugar = s;
            }
          }
        }
      }
    }

    out << water + sugar << " " << sugar;
  }
};


int main() {
  TaskC solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
//#define MOD 1000000007
#define MOD 2019

int main() {
    ll L, R;
    cin >> L >> R;


    ll ans, r, l;
    if(R - L >= MOD) {
        ans = 0;
    } else {
        r = R % MOD;
        l = L % MOD;
        if (l >= r) {
            ans = 0;
        } else {
            ans = MOD;
            for(ll i = l; i < r; i++) {
                for(ll j = i + 1; j <= r; j++) {
                    ans = min(ans, i * j % MOD);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
"use strict";

function main(input) {
  function burgerLength(n) {
    let result = [1];

    for (let i = 1; i <= n; i++) {
      let prevLength = result[result.length - 1];
      result.push(prevLength * 2 + 3);
    }

    return result;
  }
  let burgerLengths = burgerLength(50);

  function burgers(n, x) {
    if (x === 0) {
      return 0;
    }

    if (n === 0 && x > 0) {
      return 1;
    }

    // n > 0
    if (x === 1) {
      return 0;
    } else if (x <= burgerLengths[n - 1] + 1) {
      return burgers(n - 1, x - 1);
    } else if (x <= burgerLengths[n] - 1) {
      return (
        (burgerLengths[n - 1] + 1) / 2 +
        1 +
        burgers(n - 1, x - burgerLengths[n - 1] - 2)
      );
    } else {
      return (burgerLengths[n] + 1) / 2;
    }
  }

  const inputs = input.split("\n").filter(x => x !== "");

  let N = Number(inputs[0].split(" ")[0]);
  let X = Number(inputs[0].split(" ")[1]);

  console.log(burgers(N, X));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
n=0
a=[]
i=1
ii=1
l=0
tasu=0
rk=[]
bk=[]
n=int(input())
for x in input().split(" "):
    a.append(int(x))

a.sort()

print(a[int(len(a)/2)]-a[int(len(a)/2)-1])

Measured memory_bytes: 14428
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FASTIO \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr);

ll dp[101][100001];

ll max_profit(ll w[], ll v[], ll W, ll n) {
    if(n ==0 or W== 0)
        return 0;

    if(dp[n][W]) return dp[n][W];
    
    if(w[n-1] <= W) {
        return dp[n][W] = max(max_profit(w, v, W-w[n-1], n-1)+v[n-1], max_profit(w, v, W, n-1));
    }
    else
        return dp[n][W] = max_profit(w, v, W, n-1);
}

void solve() {
    ll n, W;
    cin>>n>>W;
    
    ll w[n];
    ll v[n];

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

    memset(dp, 0, sizeof(dp[0][0])*101*100001);

    cout<<max_profit(w, v, W, n);   
}

int main() {
    FASTIO;
    solve();
    return 0;
}

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

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

  int N, T, A;
  vector<int> H(1010);
  cin >> N >> T >> A;
  for(int i = 0; i < N; i++) {
    cin >> H[i];
  }

  double MIN = 99999;
  int index = 0;
  for(int i = 0; i < N; i++) {
    if(abs(A - (T - H[i] * 0.006)) < MIN) {
      MIN = abs(A - (T - H[i] * 0.006));
      index = i;
    }
  }
  cout << index + 1 << endl;
}


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

LL a[N];
LL k;

int main()
{
	cin >> k;
	for (int i = 1; i <= 50LL; i ++ ) a[i] = i + k / 50LL;
	for (int i = 1; i <= 50LL - k % 50LL; i ++ ) a[i] -- ;
	
	puts("50");
	for (int i = 1; i <= 50LL; i ++ ) cout << a[i] << ' ';
	puts("");
    return 0;
}

Measured memory_bytes: 3632
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		long[] pref = new long[N];
		long[] suff = new long[N];
		long[] arr = new long[N];
		for (int i = 0; i < N; i++) {
			arr[i] = input.nextLong();
		}
		pref[0]=arr[0]; //Prefix and suffix sums using a dp approach
		suff[N-1]=arr[N-1];
		for (int i = 1; i < N; i++) {
			long prev = pref[i-1];
			long cur = arr[i];
			pref[i]=GCD(prev,cur);
		}
		for (int i = N-2; i >=0; i--) {
			long prev = suff[i+1];
			long cur = arr[i];
			suff[i]=GCD(prev,cur);
		}
		long ans = pref[N-1]; //Assuming max GCD is GCD of entire tuple to begin with
		ans=Math.max(ans, suff[1]);//Excluding first number
		ans=Math.max(ans, pref[N-2]);//Excluding last number
		for (int cur = 1; cur < N-1; cur++) {
			int prefIndex = cur-1;
			int suffIndex = cur+1;
			long L = pref[prefIndex];
			long R = suff[suffIndex];
			ans=Math.max(ans, GCD(L,R)); //Excluding intermediate elements
		}
		System.out.println(ans);
	}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a, b);
		return GCD(Math.max(a, b)%Math.min(a, b),Math.min(a, b));
	}
}

Measured memory_bytes: 62840
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

struct UnionFind{
private:
  vector<int> par, rank, sizes;
public:
  UnionFind(int n) : par(n, -1), rank(n, 0), sizes(n, 1){}
  int find(int x) { return (par[x] < 0) ? x : (par[x] = find(par[x])); }
  bool unite(int x, int y){
    x = find(x), y = find(y);
    if(x==y) return false;
    else if(rank[x]<rank[y]){
      par[x] = y;
      sizes[y] += sizes[x];
    } else if(rank[x]>rank[y]){
      par[y] = x;
      sizes[x] += sizes[y];
    } else{
      par[y] = x;
      rank[x] += 1;
      sizes[x] += sizes[y];
    }
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sizes[find(x)]; }
};

int main() {
  int n, m; cin>>n>>m;
  vector<pair<int, int>> ab(m);
  rep(i, m) {
    int a, b; cin>>a>>b; --a; --b;
    ab[i].first = a; ab[i].second = b;
  }

  vector<long long> ans(m);
  UnionFind uf(n);
  RREP(i, m, 0) {
    if (uf.find(ab[i].first) != uf.find(ab[i].second)) {
      ans[i] = (long long)uf.size(ab[i].first) * uf.size(ab[i].second);
      uf.unite(ab[i].first, ab[i].second);
    }
  }
  rep(i, m-1) ans[i+1] += ans[i];
  rep(i, m) print(ans[i]);

  return 0;
}

Measured memory_bytes: 4096