akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int x;
    cin >> x;
    int n;
    cin >> n;
    vi p(n);
    in(n,p);
    
    set<int> s;
    rep(i,n) s.insert(p[i]);
    
    int ans = 200;
    
    reps(i,-200,200) if(!s.count(i)){
        if(abs(ans-x) > abs(x-i)) ans = i;
    }
    
    cout << ans << endl;
    
    
    

    return 0;
}


Measured memory_bytes: 3668
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] N = sc.next().toCharArray();
    int count = 0;
    char prevC = 'a';
    for (char c : N) {
      if (c == prevC) {
        count++;
        if (count >= 3) {
          break;
        }
      } else {
        count = 1;
      }
      prevC = c;
    }
    System.out.println(count >= 3 ? "Yes" : " No");
  }
}

Measured memory_bytes: 23764
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 100001
#define int long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,a[N],b[N];
main()
{
	re(n);
	for(int i=1;i<=n;++i)
		re(a[i]),re(b[i]);
	int ans=0;
	for(int i=n;i;--i)
		if((a[i]+ans)%b[i])
			ans+=b[i]-(a[i]+ans)%b[i];
	printf("%lld\n",ans);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  string a,b;
  cin >> a;
  rep(i,a.length()){
    if(a[i]=='0')b+='0';
    if(a[i]=='1')b+='1';
    if(a[i]=='B'&&b.length()!=0)b.pop_back();
  }
  cout << b;
}

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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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

const int N = 1e5 + 5;
vi adj[N];
int w[N];
set<pair<ll, int> > s;
vii ans;
ll D[N];
int n;

ll sum;

void dfs(int u, int par, int lvl) {
    sum += lvl;
    for (int nxt : adj[u]) {
        if (nxt == par)continue;
        dfs(nxt, u, lvl + 1);
    }
}


int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    range(i, 1, n) {
        w[i] = 1;
        cin >> D[i];
        //D[i] += 5;
        s.insert({D[i], i});
    }

    while (SZ(s) > 1) {
        auto it = prev(s.end());
        ll have = it->fr;
        int idx = it->sc;
        ll need = have - (n - 2 * w[idx]);
        auto c = s.lower_bound({need, -1});
        if (c == s.end() || it == c || c->fr != need) {
            cout << -1 << endl;
            return 0;
        }
        w[c->sc] += w[idx];
        ans.push_back({idx, c->sc});
        s.erase(it);
    }

    for (auto edge : ans) {
        adj[edge.fr].push_back(edge.sc);
        adj[edge.sc].push_back(edge.fr);
    }

    dfs(s.begin()->sc, -1, 0);
    if (sum != s.begin()->fr) {
        cout << -1 << endl;
        return 0;
    }

    for (auto edge: ans)cout << edge.fr << " " << edge.sc << endl;

    return 0;

}

Measured memory_bytes: 14456
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,x,y,ans,a1,a2,a3;
    cin>>a>>b>>c>>x>>y;
    a1=a*x+b*y;
    a2=2*c*max(x,y);
    if(x>y)
    {
        a3=y*c*2+(x-y)*a;
    }
    else a3=x*c*2+(y-x)*b;
    ans=min(a1,min(a2,a3));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 1 << 32
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


class Segtree:
    def __init__(self, A, ide_ele, segfunc, initialize=True):
        self.n = len(A)
        self.size = 2 ** (self.n - 1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        if initialize:
            self.data = [ide_ele] * self.size + A + [ide_ele] * (self.size - self.n)
            for i in range(self.size - 1, 0, -1):
                self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
        else:
            self.data = [ide_ele] * (2 * self.size)

    def update(self, k, x):
        k += self.size
        self.data[k] = x
        while k > 0:
            k = k >> 1
            self.data[k] = self.segfunc(self.data[2 * k], self.data[2 * k + 1])

    def query(self, l, r):
        L, R = l + self.size, r + self.size
        s = self.ide_ele
        while L < R:
            if R & 1:
                R -= 1
                s = self.segfunc(s, self.data[R])
            if L & 1:
                s = self.segfunc(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s

n = I()
P = LI()
D = {P[i]: i for i in range(n)}
p_even = [P[i] if not i & 1 else INF for i in range(n)]
p_odd = [P[i] if i & 1 else INF for i in range(n)]
st_even = Segtree(p_even, INF, min)
st_odd = Segtree(p_odd, INF, min)
hq = [(st_even.query(0, n), 0, n)]
ans = []
for _ in range(n // 2):
    v1, l, r = heappop(hq)
    p1 = D[v1]
    if not l & 1:
        st1, st2 = st_odd, st_even
    else:
        st1, st2 = st_even, st_odd
    v2 = st1.query(p1, r)
    p2 = D[v2]
    st2.update(p1, INF)
    st1.update(p2, INF)
    if l != p1:
        heappush(hq, (st2.query(l, p1), l, p1))
    if p1 + 1 != p2:
        heappush(hq, (st1.query(p1 + 1, p2), p1 + 1, p2))
    if p2 + 1 != r:
        heappush(hq, (st2.query(p2 + 1, r), p2 + 1, r))
    ans += [v1, v2]


print(*ans)




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

#define is_uruu leapyear
#define ll long long
#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,a) for(int i=0;i<(a);++i)



int main(){
 
	ll count1=0, count2=0;
	int current, n, a[100005];
	cin >> n;
	FOR(i, 0, n) cin >> a[i];
	
	
	current = max(1, a[0]);
	if(a[0] < 1) count1 += abs(a[0])+1;
	FOR(i, 0, n-1){
		if(current < 0){
			current += a[i+1];
			if(current <= 0){
				count1 += abs(current)+1;
				current = 1;
			}
		}
		else if(current > 0){
			current += a[i+1];
			if(current >= 0){
				count1 += abs(current)+1;
				current = -1;
			}
		}
	}
	
	
	current = min(-1, a[0]);
	if(a[0] > -1) count2 += abs(a[0])+1; 
	FOR(i, 0, n-1){
		if(current < 0){
			current += a[i+1];
			if(current <= 0){
				count2 += abs(current)+1;
				current = 1;
			}
		}
		else if(current > 0){
			current += a[i+1];
			if(current >= 0){
				count2 += abs(current)+1;
				current = -1;
			}
		}
	}

  
	cout << min(count1, count2) << endl;
  
    return 0;
}

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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);

#define endl "\n";


#define mod 1000000007
#define loop(i,s,n)  for(ll i=s;i<n;i++)
#define test  ll t; cin>>t; while(t--)
#define p push_back
typedef long long ll;
int main()
{
    
ll n,i,j,k,count=0,sum=1;
cin>>n;
k=n;
ll a[n]={0};
ll b[n]={0};
j=0;
ll f=1;
while(n--)
{cin>>a[j]>>b[j];
j++;}

for(i=0;i<k-2;i++)
{if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])
{cout<<"Yes";
f=0;
break;}}
if(f==1)
{cout<<"No";}
return 0;
}




Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main 
{

	
	static class Entry implements Comparable<Entry>
	{
		int u,d,c,t;
		
		public Entry(int u,int d,int c,int t)
		{
			this.u = u;
			this.d = d;
			this.c = c;
			this.t = t;
		}

		@Override
		public int compareTo(Entry o) {
			
			return -1*(this.t - o.t);
		}
	}
	public static void main(String[]args)throws Throwable
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); int e = sc.nextInt();
		PrintWriter out = new PrintWriter(System.out);
		int col[] = new int[n];
		ArrayList<Integer> Graph[] = new ArrayList[n];
		for(int i = 0 ; i < n ; ++i)
			Graph[i] = new ArrayList();
		for(int i = 0 ; i < e ; ++i)
		{
			int u = sc.nextInt() - 1; int v = sc.nextInt() - 1;
			Graph[u].add(v);
			Graph[v].add(u);
		}
		boolean seen[][] = new boolean[n][11];
		PriorityQueue<Entry> pq = new PriorityQueue();
		int q = sc.nextInt();
		int time = 0;
		while(q-- > 0)
		{
			int v = sc.nextInt() - 1;
			int d = sc.nextInt();
			int c = sc.nextInt();
			pq.add(new Entry(v,d,c,time++));
			
		}
		
		while(!pq.isEmpty())
		{
			Entry en = pq.poll();
			if(seen[en.u][en.d])
				continue;
			
			seen[en.u][en.d] = true;
			if(col[en.u] == 0)
			col[en.u] = en.c;
			if(en.d <= 0)
				continue;
			for(Integer v : Graph[en.u])
			{
				if(seen[v][en.d - 1])
					continue;
				pq.add(new Entry(v,en.d - 1,en.c,en.t));
			}
		}
		out.print(col[0]+"\n");
		for(int i = 1 ; i < n ; ++i)
		{
			out.print(col[i]+"\n");
		}
		
		out.flush();
		out.close();
		
	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;


		Scanner(InputStream s)  { br = new BufferedReader(new InputStreamReader(s)); }

		String next() throws IOException
		{

			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();

		}
		int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); }



	}
}


Measured memory_bytes: 96788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,power,sum=0;
    cin>>n;
    string a=to_string(n);
    if(a.size()%2==0)
        power=a.size()/2;
    else
    {
        power=(a.size()-1)/2;
        x=pow(10,a.size()-1);
        sum+=(n-x+1);
    }
    sum+=9*(pow(100,power)-1)/99;
    cout<<sum<<endl;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()

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

    int ans = 1000000;

    REPN(i, 1, n) {
        int a = n - i;
        int b = i;
        int tmp = 0;
        while(a > 0) {
            tmp += a % 10;
            a /= 10;
        }
        while(b > 0) {
            tmp += b % 10;
            b /= 10;
        }
        ans = min(tmp, ans);
    }

    cout << ans << endl;

    return 0;
}

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


 int main(){
   int a,b,c,d,e,k;
   cin>>a>>b>>c>>d>>e>>k;

   int ab=abs(a-b);
   int ac=abs(a-c);
   int ad=abs(a-d);
   int ae=abs(a-e);
   int bc=abs(b-c);
   int bd=abs(b-d);
   int be=abs(b-e);
   int cd=abs(c-d);
   int ce=abs(c-e);
   int de=abs(d-e);

   if(ab>k||ac>k||ad>k||ae>k||bc>k||bd>k||be>k||cd>k||ce>k||de>k){
     cout<<":(";
   }else{
     cout<<"Yay!";
   }

   return 0;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
  int N,M;
  cin >> N >> M;
  int64_t sum = 0;
  int A;
  rep(i,M){
    cin >> A;
    sum += A;
  }
  if(N >= sum){
    cout << N - sum << endl;
  }
  else{
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
  long long int a, b, x, y, z, m, n;

  while(scanf("%lld %lld", &a, &b) != EOF){
	x = a;
	y = b;

	if (b > a){
		x = b;
		y = a;
	}

while(x != y){
		z = y;
		y = x - y;
		x = z;

		if (y > x){
			m = x;
			x = y;
			y = m;
		}	
	}	

	n = a * b / y;

    printf("%lld %lld\n", y, n); 
  }
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

void solve(int n,int m){
    vector<int> cnt(n);
    int cur=m;
    int idx=0;
    while(1){
        if(cur){
            ++cnt[idx];
            --cur;
        }
        else if(cnt[idx]){
            cur+=cnt[idx];
            cnt[idx]=0;
        }
        if(cnt[idx]==m){
            cout<<idx<<endl;
            return;
        }
        idx=(idx+1)%n;
    }
}

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


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
	string s, t, ans;
	cin >> s >> t;

	for(long long i = 0;i < t.size();i++)
		ans.push_back(t[i]);
	
	for (long long i = 0; i < s.size(); i++)
		ans.push_back(s[i]);



	cout << ans << std::endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  if(n%2==0){
    for(int i=n-1;i>=0;i=i-2){
      cout << a[i] << ' ';
    }
    for(int i=0;i<n;i=i+2){
      cout << a[i] << ' ';
    }
  }
  else{
    for(int i=n-1;i>=0;i=i-2){
      cout << a[i] << ' ';
    }
    for(int i=1;i<n;i=i+2){
      cout << a[i] << ' ';
    }
  }
}


Measured memory_bytes: 2944
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer s = Integer.parseInt(sc.next());

        // 主処理
        List<Integer> list = new ArrayList<>();
        list.add(s);

        int result = 0;
        boolean doContinue = true;
        for (int i = 0; doContinue; i++) {
            if (s % 2 == 0) {
                if (list.contains(s / 2)) {
                    result = i + 2;
                    doContinue = false;
                } else {
                    s = s / 2;
                    list.add(s);
                }
            } else {
                if (list.contains(3 * s + 1)) {
                    result = i + 2;
                    doContinue = false;
                } else {
                    s = 3 * s + 1;
                    list.add(s);
                }
            }
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <map>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, i, a[200003], ans, p;
    ll bi[35] = {};
    map<int, int> m;

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

    sort(a, a + n, greater<int>());

    bi[0] = 1;
    i = 0;
    while (bi[i] < 1e9) {
        bi[i + 1] = bi[i++] * 2;
    }

    ans = 0;
    for (i = 0; i < n; i++) {
        if (m[a[i]] == 0) {
            continue;
        }
        m[a[i]]--;
        p = lower_bound(bi, bi + 31, a[i] + 1) - bi;
        if (m[bi[p] - a[i]] > 0) {
            ans++;
            m[bi[p] - a[i]]--;
        }
    }

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

    return 0;
}

Measured memory_bytes: 19712
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		sc.close();
		int mn = 100000;
		for (i = 1; i < n; i++) {
			int tmp = sum(i) + sum(n - i);
			if(tmp<mn) {
				mn = tmp;
			}
		}
		out.println(mn);
	}
	public static int sum(int n) {
		int ret = 0;
		while(n>0) {
			ret+=n%10;
			n/=10;
		}
		return ret;
	}
}


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


int main() {
  
  int N;
  set <string> s;
  cin >> N;
  for (int i ; i < N; i++){
    string S;
    cin >> S;
    s.insert(S);
   
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 19228
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,k,*a = [int(i) for i in read().split()]



def check(x,k):
    #k回切って最短を長さ x 以下にできるならOK 
    v = 0
    for ai in a:
        v += (ai-1)//x
    return v <= k


ok = 10**9
ng = 0
while ok-ng > 1:
    mid = (ok+ng)//2
    if check(mid,k): ok = mid
    else: ng = mid

print(ok)



Measured memory_bytes: 96328
x,y,z,k=gets.split(' ').map(&:to_i)
#h=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
a=gets.split(' ').map(&:to_i)
b=gets.split(' ').map(&:to_i)
c=gets.split(' ').map(&:to_i)

xy = Array.new
k_count = 0
for i in 0..x-1
  for j in 0..y-1
    xy.push(a[i]+b[j])
    #break if k_count >=k
  end
end

xy.sort!.reverse!
xy_new = Array.new
=begin
while k_count<k && xy[k_count]
  xy_new[k_count]=xy[k_count]
  k_count+=1
end
=end
u = [k,x*y].min

xy_new = xy[0..u]
#puts xy_new
#puts xy
#c.sort!.reverse!

=begin
count =0
xy_count = 0
z_count = 0
while count<k
  if z_count >=z
      z_count=0
      xy_count+=1
  end
  ans = (xy[xy_count])+(c[z_count])
  z_count+=1
  count += 1
  puts ans
end
=end

abc = Array.new

for i in 0..(xy_new.length-1)
  for j in 0..z-1
    abc.push(xy_new[i]+c[j])
  end
end

abc.sort!.reverse!
=begin
if k<x*y*z
  k=x*y*z
end
=end
for i in 0..k-1
  puts abc[i]
end


Measured memory_bytes: 70148
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }

template<class T>
vector<T> getPrime(T n) {
	T k = sqrt(n);
	vector<T> dst;
	vector<bool> used(n + 1);
	for (T i = 2; i <= k; ++i) {
		if (used[i] == false) {
			for (T j = i * 2; j <= n; j += i) {
				used[j] = true;
			}
		}
	}
	for (T i = 2; i <= n; ++i) {
		if (used[i] == false) {
			dst.push_back(i);
		}
	}

	return dst;
}

template<class T>
bool isPrime(T n) {
	if (n == 2)
		return true;

	if (n < 2 || n % 2 == 0)
		return false;

	for (T i = 3, k = sqrt(n); i <= k; i += 2) {
		if (n % i == 0)
			return false;
	}

	return true;
}

int main() {
	int n, a, ans = 0;
	cin >> n;
	while (n--) {
		cin >> a;
		if (isPrime(a))
			ans++;
	}

	cout << ans << endl;

	return 0;
}

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

#define mem(arr, i) fill(arr, arr + sizeof(arr), i)
#define MEM(arr, i) memset(arr, i, sizeof(arr))
#define Push push_back
#define Pair make_pair
#define ALL(x) x.begin(), x.end()
#define X first
#define Y second
#define ACCEL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef pair<pll,lli> p3l;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<p3l> v3L;
typedef vector<vcL> vvL;
typedef greater<lli> gcL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv(maxN+5, 1);
vcL fac(maxN+5, 1);

void ADD(lli &x, lli y) {
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = (x % mod + mod) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if (e & 1) MUL(ans, b);
		MUL(b, b);
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow(n, mod - 2);
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if (a < b) return 0;

	MUL(ans, inv[fac[a - b]]);
	MUL(ans, inv[fac[b]]);
	MUL(ans, fac[a]);

	return ans;
}

lli Lucas(lli n, lli m) {
	if (m == 0) return 1;
	return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas(n, m);
}

/// coding area ///

const lli maxn = 1E5;

void precal() {

	return;
}

bool cmp(pll a, pll b) {
	if (a.Y == b.Y) return a.X < b.X;
	else return a.Y > b.Y;
}

void solve() {
	lli n, m;
	cin >> n >> m;
	
	vPL work(n);
	for (auto &x : work) {
		cin >> x.X >> x.Y;
	}
	
	sort(ALL(work), cmp);
	
	bool fit[100000 + 5];
	memset(fit, false, sizeof(fit));
	// at most do M jobs, do i's job at time i
	
	vcL nxt(100000 + 5);
	vcL lst(100000 + 5);
	
	for (int i = 0; i < 100005; ++i) {
		nxt[i] = i + 1;
		lst[i] = i - 1;
	}
	
	lli ans = 0;
	
	for (int i = 0; i < n; ++i) {
//		cout << work[i].X << ' ' << work[i].Y << '\n';
		int time = work[i].X;
		while (fit[time]) {
//			cout << "time : " << time << " don't fit\n";
			int tmp = time;
			time = nxt[time];
			if (fit[time]) nxt[tmp] = nxt[nxt[tmp]];
			if (time > m) break;
		}
		
		if (time <= m) {
//			cout << "work : " << i << " at time : " << time << '\n';
			fit[time] = true;
			if (lst[time] >= 0) nxt[lst[time]] = nxt[time];
			if (nxt[time] <= m) lst[nxt[time]] = lst[time];
			ans += work[i].Y;
		}
	}
	
	cout << ans << '\n';
}

int main() {
//	freopen("input.txt", "r", stdin);
	
	precal();
	int t = 1;
	#ifdef LOCAL
		t = 1;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}



Measured memory_bytes: 6656
#include "bits/stdc++.h"

using namespace std;

int main() {
   int N;
   cin >> N;
   string S;
   cin >> S;
   bool flag = true;
   if(N % 2 == 0){
       for(int i = 0; i < N / 2; i++){
           if(S.at(i) != S.at(i + N / 2)) flag = false;
       }
   }else flag = false;

   if(flag) puts("Yes");
   else puts("No");
}

Measured memory_bytes: 256
using System;

namespace AtCoderBeginnerContest118_2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);

            bool[] fav = new bool[M];

            for (int i = 0; i < M; i++)
                fav[i] = true;
            
            for(int i=0;i<N;i++)
            {
                bool[] buf = new bool[M];

                s = Console.ReadLine().Split(' ');
                int K = int.Parse(s[0]);

                for(int j=1;j<s.Length;j++)
                {
                    int a = int.Parse(s[j])-1;
                    buf[a] = true;
                }

                for(int j = 0; j < M; j++)
                {
                    if (!buf[j])
                        fav[j] = false;
                }
            }

            int counter = 0;

            for (int j = 0; j < M; j++)
            {
                if (fav[j])
                    counter++;
            }

            Console.WriteLine(counter.ToString());
        }
    }
}


Measured memory_bytes: 11092
<?php
	fscanf(STDIN, "%d %d",$A ,$B);

	$plus = $A + $B;
	$minus = $A - $B;
	$mult = $A * $B;

	$max = $plus;
	if ($minus > $max) {
      $max = $minus;
    }

	if ($mult > $max) {
      $max = $mult;
    }
	echo ($max);
?>

Measured memory_bytes: 3700
/*#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



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

int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;

int sum = 0;

vector<int> value;
vector<int> weight;

int dp[110][10010];

int data_[210][2] = { -2 };

void input(void) {
	CI n;
	return;
}


int main(void) {
	input();
	double money = 100000;
	
	for (int i = 0; i < n; i++) {
		money *= 1.05;
	}
	
	if ((int)money % 1000 >= 500) {
		CO (int)(money - ((int)(money) % 1000) + 1000) E
	}
	else {
		CO (int)(money - ((int)(money) % 1000)) E
	}

	

	return 0;
}

*/

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



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

int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
long long int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;

int sum = 0;

vector<int> value;
vector<int> weight;

int dp[110][10010];

int data_[210][2] = { -2 };

void input(void) {
	CI n;
	return;
}


int main(void) {
	input();

	
	for (int i = n - 1; i > 1; i--) {
		n  *= i;
	}

	CO n E

	return 0;
}

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

using namespace std;

template<class Abel> struct UnionFind{
	vector<int> par;
	vector<int> rank;
	vector<Abel> diff_weight;

	UnionFind(int n = 1, Abel SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(int n = 1, Abel SUM_UNITY = 0) {
		par.resize(n);
		rank.resize(n);
		diff_weight.resize(n);
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		} else { 
			int r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	Abel weight(int x) {
		root(x);
		return diff_weight[x];
	} 

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	} 

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, int w) {
		w += weight(x);
		w -= weight(y);
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) {
			swap(x,y);
			w = -w;
		}
		if (rank[x] == rank[y]) rank[x]++;
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}
};

int N,M;

inline void solve(){
	UnionFind<int> uf(N);
	for (int i = 0; i < M; ++i) {
		int l,r,d; cin>>l>>r>>d;
		if (uf.issame(--l, --r)) {
			int diff = uf.diff(l, r);
			if (diff != d) {
				cout<<"No"<<endl;
				return;
			}
		} else {
			uf.merge(l, r, d);
		}
	}
	cout<<"Yes"<<endl;
	return;
}

inline void input(){
	cin>>N>>M;
	return;
}

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

	input();
	solve();
	return 0;
}


Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();
        int d = sc.NextInt();

        int answer = Math.Min(a, b) + Math.Min(c, d);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

int main() {
    int N;
    std::cin >> N;
    
    int cnt = 0;
    if      (               N <     10) { cnt = N;                       }
    else if (    10 <= N && N <=    99) { cnt = 9;                       }
    else if (   100 <= N && N <=   999) { cnt = 9 + N - 100 + 1;         }
    else if (  1000 <= N && N <=  9999) { cnt = 9 + 900;                 }
    else if ( 10000 <= N && N <= 99999) { cnt = 9 + 900 + N - 10000 + 1; }
    else if (100000 == N              ) { cnt = 9 + 900 + 90000;         }

    std::cout << cnt << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<set>
#include<cmath>
using namespace std;
set<int> s;
int main()
{
	int n,x,i,len,xx;
	scanf("%d%d",&n,&x);
	for(i=0;i<n;++i)
	{
		scanf("%d",&xx);
		len=abs(xx-x);
		s.insert(len);
	}
	set<int>::iterator it=s.begin();
	int maxn=*it,tmp1,tmp2;

	while(1)
	{
		tmp1=*it;
		++it;
		if(it==s.end()) break;
		tmp2=*it;
		
		while(1)
		{
			if(tmp1%maxn==0&&tmp2%maxn==0)
			break;
			--maxn;
		}
	}
	printf("%d",maxn);
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    int r;
    cin >> r;
    cout << r*r << endl;
    return 0;
}


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

long long int mod = pow(10,9) + 7;

void E(long long int a,long long int e){
    if(a>=mod || a<0){
        cout << e << endl;
    }
}

long long int pow_mod(long long int a,long long int n,long long int res){
    if(n==0){return res;}
    if(n & 1){
        res = (res*a)%mod;
    }
    a = (a * a)%mod;
    n = n >> 1;
    return pow_mod(a,n,res);

}

int main(){
    int N,K;
    cin >> N >> K;
    long long int H[K];
    for(int i=0;i<K;i++){
        H[i] = 0;
    }

    for(int i=K;i>1;i--){
        int t = K/i;
        if(t==1){H[i] = 1;}
        else{
            long long int sum = 0;
            for(int j=2;j<=t;j++){
                sum = (sum + H[i*j])%mod;
            }
            H[i] = (pow_mod(t,N,1) - sum)%mod;

        }  
    
    }

    long long int an =0;
    an += pow_mod(K,N,1);
    for(int i=2;i<=K;i++){
        an = (an + (H[i]*(i-1))%mod)%mod;
    }

    cout << an << endl;




    return 0;
}

Measured memory_bytes: 4384
# A - Traveling Budget

A = int(input())
B = int(input())
C = int(input())
D = int(input())

if A <= B:
    if C <= D:
        answer = A + C
    else:
        answer = A + D
elif C <= D:
    answer = B + C
else:
    answer = B + D

print(answer)


Measured memory_bytes: 9100
#include <cstdio> 
#include <iostream> 
#include <string.h>
#include <math.h>
using namespace std;
int main(){
		int A[3];
		int ans = 300;
		cin >> A[0] >> A[1] >> A[2];
		for(int i =0; i<3; i++){
				int cost=0;
				cost += fabs(A[i]-A[(i+1)%3]);
				cost += fabs(A[i]-A[(i+2)%3]);
				if(cost < ans)ans = cost;
		}
		cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
s = input()
l = [0]
r = [0]
l_cnt = 0
r_cnt = 0
for i in range(n-1):
    if s[i] == 'W':
        l_cnt += 1
    if s[n-i-1] == 'E':
        r_cnt += 1
    l.append(l_cnt)
    r.append(r_cnt)
print(min(l[i]+r[n-i-1] for i in range(n)))

Measured memory_bytes: 17624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

#define ll long long

int main(void){
    int n;
    cin >> n;
    int flag = 0;

    for(int i = 1;i < 10;++i){
        if(n%i == 0 && n/i < 10){
            flag = 1;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

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

ll llbs(ll x) {
  if(x < 0) return -x;
  return x;
}

int main() {
  int N; cin >> N;
  vector<ll> a(N);
  for(int i = 0; i < N; i++) cin >> a.at(i);
  ll sumO = 0, sumE = 0, countO = 0, countE = 0;
  for(int i = 0; i < N; i++) {
    ll O = a.at(i), E = a.at(i);
    if(i % 2 == 0) {
      if(sumE + E <= 0) {
        countE += llbs(1 - (sumE + E));
        E = 1 - sumE;
      }
      if(sumO + O >= 0) {
        countO += llbs(-1 - (sumO + O));
        O = -1 - sumO;
      }
    } else {
      if(sumO + O <= 0) {
        countO += llbs(1 - (sumO + O));
        O = 1 - sumO;
      }
      if(sumE + E >= 0) {
        countE += llbs(-1 - (sumE + E));
        E = -1 - sumE;
      }
    }
    sumE += E;
    sumO += O;
  }
  cout << min(countE, countO) << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));
  rep(i, n){
    int in;
    cin >> in;
    a.at(0).at(i) = in;
  }
  int sum = 0;
  rep(i, n){
    int in;
    cin >> in;
    sum += in;
    a.at(1).at(i) = in;
  }
  int ans = 0, now = 0;
  rep(i, n){
    now += a.at(0).at(i);
    int add = now + sum;
    ans = max(ans, add);
    sum -= a.at(1).at(i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
bool zs[100005];
int ans[100005],l,r;
main(){
	memset(zs,1,sizeof(zs));
	zs[0]=zs[1]=false;
	for (int i=2;i<=100000;++i)
		for (int j=i*2;j<=100000;j+=i)
			zs[j]=false;
	for (int i=1;i<=100000;++i)
		if (zs[i]&&zs[(i+1)/2]&&i!=2) ans[i]=ans[i-1]+1;
		else ans[i]=ans[i-1];
	int t;
	cin>>t;
	while(t--) {
		cin>>l>>r;
		cout<<ans[r]-ans[l-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cout << v << " ";  \
  }                    \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N;
  map<string, int> mp;
  REP(i, N) {
    string s;
    cin >> s;
    mp[s]++;
  }
  cin >> M;
  REP(i, M) {
    string s;
    cin >> s;
    mp[s]--;
  }
  int maxAns = 0;
  FORA(e, mp) {
    if (e.second > 0) chmax(maxAns, e.second);
  }
  print(maxAns);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int t=0;t<T;t++) {
			String s = sc.next();
			int n = s.length();
			int sum = 0;
			for(int i=0;i<n;i++) {
				sum += s.charAt(i) - '0';
			}
			int turn = n + (sum-1)/9;
			if (turn % 2 == 0) {
				System.out.println("Fabre wins.");
			}else{
				System.out.println("Audrey wins.");
			}
		}
	}

}

Measured memory_bytes: 20860
from collections import deque
H, W = map(int, input().split())
sy,sx = 1,1
gy,gx = H,W
sy-=1
sx-=1
gy-=1
gx-=1
con = [[1,0],[0,1],[-1,0],[0,-1]]
m=[]
d = [[0]*W for _ in range(H)]
for i in range(H):
    a= input()
    m.append(a)
q = deque()
q.append((sy,sx))
d[sy][sx] = 1
s = 0
while len(q)>0:
    y,x = q.popleft()
    if y == gy and x == gx:
        break
    for dx,dy in con:
        if  y+dy>=0 and x+dx >= 0 and y+dy < H and x+dx < W:
            if d[y+dy][x+dx] == 0 and m[y+dy][x+dx] =="#":
                q.append((y+dy,x+dx))
                d[y+dy][x+dx]+=d[y][x]+1
for i in range(H):
    for j in range(W):
        if m[i][j] == "#":s+=1
if H+W < d[gy][gx] or s > d[gy][gx]:
    print("Impossible")
else:print("Possible")


Measured memory_bytes: 3316
import sys
sys.setrecursionlimit(10 ** 7)

N = input()

# DP
INF = pow(10, 8)
L = len(N)
dp = [[INF] * 2 for _ in range(L+2)]
dp[0][0] = 0

# reverse
N = N[::-1] + '0'


for i in range(L+1):
    for j in range(2):
        # 繰り下がりも加味
        n = int(N[i])
        n += j

        # 更新後のdp
        ni = i + 1

        # 10通りから探索
        for a in range(10):
            nj = 0
            b = a - n

            # 繰り下がりあり
            if b < 0:
                b += 10
                nj = 1

            dp[ni][nj] = min(dp[i][j] + a + b, dp[ni][nj])

ans = min(dp[L+1][0], dp[L+1][1])

print(ans)


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

public class Program
{
    public void Proc()
    {
        string inpt = Reader.ReadLine();
        inpt = inpt.Replace('9', 'a');
        inpt = inpt.Replace('1', '9');
        inpt = inpt.Replace('a', '1');
        Console.WriteLine(inpt);

    }




    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"

191

";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 11092
n,ki=map(int,input().split())
v=list(map(int,input().split()))

m=min(n,ki)
ans=0

for i in range(m+1):
    for j in range(i+1):
        q=[]
        tmp=0
        for k in range(j):
            if len(v)>0:
                q.append(v[k])
        for kz in range(i-j):
            if len(v)>0:
                q.append(v[n-1-kz])
        tmp=sum(q)
        q.sort()
        for l in range(ki-i):
            if l<len(q) and q[l]<0:
                tmp-=q[l]
        ans=max(ans,tmp)
        
print(ans)

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a-c) <= d) 
		cout << "Yes\n";
	else if (abs(a-b) <= d && abs(b-c) <= d)
		cout << "Yes\n";
	else
		cout  << "No\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second

vector<char> u;
vector<vector<int>> g;
vector<int> dp;

void dfs(int s){
	u[s] = true;
	for(int to : g[s]) {
		if(!u[to])
			dfs(to);
			
		dp[s] = max(dp[s], dp[to]+1);	
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	u.resize(n, false);
	g.resize(n);
	dp.resize(n, 0);
	forn(i, m){
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].pb(v);
	}
	
	for(int i = 0; i < n; i++){
		if(!u[i])
			dfs(i);
	}
	int ans = 0;
	forn(i, n) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;

}



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

int main() {
	int a, b, c, d, l, r;

	cin >> a >> b >> c >> d;

	l = a + b;
	r = c + d;

	if (l > r) {
		cout << "Left" << endl;
	}
	else if (l == r) {
		cout << "Balanced" << endl;
	}else if(l < r){
		cout << "Right" << endl;
	}


}

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

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	cout << a[n - 1];
	for (int i = n - 2; i >= 0; i--){
		cout << " " << a[i];
	}
	cout << '\n';

	return 0;
}


Measured memory_bytes: 3112