akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

ll f(ll h, ll w){
    ll ret = h * w;
    if(h % 3 == 0){
        ret = 0LL;
    }
    else {
        chmin(ret, w);
    }

    rep(x, 1, w){
        ll S = x * h;

        ll a = (w - x) * (h / 2);
        ll b = (w - x) * (h / 2 + h % 2);

        ll diff = max(S, max(a, b)) - min(S, min(a, b));
        chmin(ret, diff);
    }

    return ret;
}

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

    ll h, w; cin >> h >> w;
    
    ll res = min(f(h, w), f(w, h));
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#coding:utf-8

class MakeTree():
    def __init__(self, key, p=None, l=None, r=None):
        self.key = key
        self.p = p
        self.l = l
        self.r = r
 
def Insert(root,value):
    y = None
    x = root
    z = MakeTree(value)

    while x != None:
        y = x
        if x.key > z.key:
            x = x.l
        else:
            x = x.r
    z.p = y

    if y == None:
        root = z
    elif z.key < y.key:
        y.l = z
    else:
        y.r = z
    return root


def Find(u, target):
    y = None
    x = u
    while x != None and target != x.key:
        y = x
        if x.key > target:
            x = x.l
        else:
            x = x.r
    if x == None:
        print("no")
    else:
        print("yes")
            
    

def inParse(u):
    if u == None:
        return
    inParse(u.l)
    global inParseList
    inParseList.append(u.key)
    inParse(u.r)

def preParse(u):
    if u == None:
        return
    global preParseList
    preParseList.append(u.key)
    preParse(u.l)
    preParse(u.r)


root = None       
n = int(input())
inParseList = []
preParseList = []
for i in range(n):
    order = list(input().split())
    if order[0] == "insert":
        root = Insert(root, int(order[1]))
        
    elif order[0] == "print":
        inParse(root)
        preParse(root)
        print(" " + " ".join([str(i) for i in inParseList]))
        print(" " + " ".join([str(i) for i in preParseList]))
        preParseList = []
        inParseList = []
        
    elif order[0] == "find":
        Find(root, int(order[1]))






        



Measured memory_bytes: 121624
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
  
	int n;
	cin >> n;
	set<int> a;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		a.insert(x);
	}
	int m;
	cin >> m;
	for(int i = 0; i < m; i++){
		int x;
		cin >> x;
		if(a.count(x))a.erase(x);
	}
	for(auto i:a)cout << i << '\n';
    return 0;
}



Measured memory_bytes: 12500
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    vector<int> v[26];
    int ans = 0;
    for (int i = 0; i < s.size(); i++){
        v[s[i]-'a'].push_back(i);
    }
    int cur = 0;
    for (int i = 0; i < t.size(); i++){
        int x = t[i]-'a';
        if (v[x].size() == 0){
            printf("-1");
            return 0;
        }
        vector<int>::iterator it = lower_bound(v[x].begin(),v[x].end(),cur);
        if (it != v[x].end()){
            cur = *it + 1;
        }
        else{
            ans++;
            cur = v[x][0] + 1;
        }
    }
    printf("%lld\n",(long long)ans*(s.size())+cur);
}


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

int main(){
    int N;
    long long ans = 0, sum =0;
    int mod = 1000000000+7;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
        sum += a.at(i);
        sum %= mod;
    }
    for (int i = 0; i < N-1; i++) {
        sum -= a.at(i);
        if(sum<0) sum += mod;
        ans += sum * a.at(i);
        ans %= mod;
    }
    cout << ans << endl;
}
/*

*/


Measured memory_bytes: 4044
a, b = map(int,input().split())
a_list = []
b_list = []
flag = 0

for i in range(1,1009):
    if int(i*1.08)-i == a:
        a_list.append(i)

for j in a_list:
    if int(j*1.1)-j == b:
        print(j)
        flag = 1
        break

if flag != 1:
    print('-1')


Measured memory_bytes: 9092
x,y=map(int,input().split())
MAX_NUM = 2*10**6 + 1
MAX_NUM//=3
MAX_NUM+=1
pr = 10**9+7
fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]
fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % pr
    inv[i] = pr - inv[pr%i] * (pr // i) % pr
    finv[i] = finv[i-1] * inv[i] % pr
def c(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % pr) % pr
if (x+y)%3:
    print(0)
else:
    n=(x+y)//3
    x-=n
    y-=n
    print(c(x+y,x))


Measured memory_bytes: 82300
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ff first 
#define ss second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define testcase(t) int t;cin>>t;while(t--)
#define mp(x,y) make_pair(x,y)
#define in(x) insert(x)
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define PI 3.14159265358979323846
#define SP(x) setprecision(x)
#define reflex ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define M 1000000007
#define sz(a) (int)a.size()
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(x) x.resize(distance(x.begin(), unique(all(x))))
#define mem(arr,val) memset(arr,val,sizeof(arr)) //For "0" and "-1"                  
#define inp0(a,n) rep(i,0,n-1) cin>>a[i];
#define inp1(a,n) rep(i,1,n) cin>>a[i]; 
#define prll(x) printf("%lld",x)
#define nth_ele(v,n) nth_element(v.begin(), v.begin()+n ,v.end())//O(N)
#define DEBUG(x) cerr << (#x) << ": " << (x) << endl
#define DEBUGV(x) for(auto IT:x) cout<<IT<<" "; cout<<endl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll gcd(ll n1, ll n2){if(n2!=0) return gcd(n2, n1%n2);else return n1;}
ll powerM(ll a,ll b){if(b==0) return 1;  if(b==1) return a%M; ll x=powerM(a,b/2)%M; if(b&1){return ((((a%M)*(x%M))%M)*(x%M))%M;}return ((x%M)*(x%M))%M;}
ll power(ll a,ll b){if(b==0) return 1;  if(b==1) return a; ll x=power(a,b/2); if(b&1){return ((((a)*(x)))*(x));}return ((x)*(x));}
 
const ll INF=1e18; 
const int SIZE = 200005;

int main(){
	int n;
	cin>>n;
	ll h[n];
	inp0(h,n)
	ll dp[n+2]={0};
	dp[n-2]=abs(h[n-2]-h[n-1]);
	nrep(i,0,n-2){
		dp[i] = min(abs(h[i]-h[i+1])+dp[i+1], abs(h[i]-h[i+2])+dp[i+2]);
	}
	cout<<dp[0]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0;
  cin >> N;
  vector<ll>A(N);
  rep(i,N){
    cin >> A[i];
  }
  sort(A.begin(), A.end()); //小さい順
  reverse(A.begin(), A.end());
  if(A.size() == 2){
    cout << A[0] << " " << A[1];
    return 0;
  }
  cout << A[0] << " ";
  ll a = A[0]/2;
  ll ans = 10000000000000000;
  rep(i,N-1){
    ans = min(ans,abs(a-A[i+1]));
  }
  rep(i,N){
    if(ans + a == A[i]){
      cout << ans + a;
      return 0;
    }
  }
  cout << a-ans;
}

Measured memory_bytes: 4028
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
    `(let ((it ,expr))
       ,then
       ,else))

(defun func (x &optional (acc 0))
  (if (zerop x)
      acc
      (func (floor x 10) (+ (* acc 10) (mod x 10)))))

(defun main (a b)
  (loop for i from a to b
        when (= i (func i))
          sum 1))

#-swank
(princ (main (read) (read)))



Measured memory_bytes: 20920
#include <stdio.h>
 
int main()
{
 long long a, b, n, m, r;
 while(scanf("%lld%lld", &a, &b) != EOF){
  if(a>b){
   n=a;
   m=b;
  }else{
   n=b;
   m=a;
  }
  while((r=n%m)!=0){
   n=m;
   m=r;
  }
  printf("%lld %lld\n", m, a*b/m);
 }
 return(0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define MOD 1000000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
inline ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll char_to_ll(char c) { return (int)(c - '0'); }
inline ll string_to_ll(string s) { return atoi(s.c_str()); }
inline bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    int n;
    cin >> n;
   if(n%1000 == 0){
       cout << 0 << endl;
   }else{
       cout << 1000 - n%1000 << endl;
   }

    return 0;
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <list>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define xx first
#define yy second
#define $1 first
#define $2 second

bool good[100001] = { false, };

void solveCase() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll n, m; cin >> n >> m;
	vector<ll> h; h.resize(n + 1);
	for (int i = 1; i <= n; i++) cin >> h[i];
	for (int i = 0; i < m; i++) {
		ll a, b; cin >> a >> b;
		if (h[a] >= h[b]) {
			good[b] = true;
		}
		if (h[b] >= h[a]) {
			good[a] = true;
		}
	}
	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (!good[i]) res++;
	}
	cout << res;
}

int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	solveCase();
}

Measured memory_bytes: 4004
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <queue>
typedef long long ll;
#define rep(i,n) for(int i = 0;i<n;++i)
#define repnc(bit,k,n) for (int bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;
using Graph = vector<vector<int> >;

/* next combination */
int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}

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

void initialize(vector<vector<int> > &dep, int r, int c){
  dep = vector<vector<int> >(r);
  rep(y,r){
    rep(x,c){
      dep[y].push_back(-1);
    }
  }
  return;
}
int main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
  int r,c,n;cin >> r >> c;
  vector<vector<char> >map(r);
  vector<vector<int> >dep(r);
  queue<vector<int> >que;
  int count = -1;
  rep(y,r){
    rep(x,c){
      char temp;
      cin >> temp;
      if(temp=='.')count++;
      map[y].push_back(temp);
    }
  }
  int ans=0;
  initialize(dep, r, c);
  int S[2] = {0,0};
  dep[S[1]][S[0]]=0;
  que.push({S[0],S[1]});
  while(!que.empty()){
    vector<int> cur = que.front();
    que.pop();
    rep(i,4){
      int x = cur[0]+dx[i];
      int y = cur[1]+dy[i];
      if(x<0||x>=c||y<0||y>=r)continue;
      if(map[y][x]=='#')continue;
      if(dep[y][x]!=-1)continue;
      dep[y][x]=dep[cur[1]][cur[0]]+1;
      que.push({x,y});
    }
  }
  if(dep[r-1][c-1]==-1)ans=-1;
  else ans = count - dep[r-1][c-1];
  cout << ans<< '\n';
  return 0;
}

Measured memory_bytes: 3196
#include<iostream>

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
	IOS;
	int x,y,z;
	while(cin>>x>>y>>z){
		x=x-2*z;
		int ans;
		ans=x/(y+z);
		if(x % (y+z) == y){
			ans+=1;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
l = [0]*(10**5+1)
s = 0
for i in a:
    l[i]+=1
    s+=i

q = int(input())
for i in range(q):
    b,c = list(map(int,input().split()))
    s += (c-b)*l[b]
    l[c]+=l[b]
    l[b]=0
    print(s)


Measured memory_bytes: 20880
# Dinic's algorithm
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

score = 0
INF = float('inf')
graph = Dinic(n+2)

for i in range(n):
    if a[i]>0:
        graph.add_edge(i+1,n+1,a[i])
        score += a[i]
    elif a[i]<0:
        graph.add_edge(0,i+1,-a[i])

for i in range(1,n//2+1):
    for j in range(2*i,n+1,i):
        graph.add_edge(i,j,INF)

print(score-graph.flow(0,n+1))

Measured memory_bytes: 74492
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int N;
LL K;
LL A[100005], B[100005];
LL ans = 0;

void check(LL Limit) {
	LL now = 0;
	for (int i = 1; i <= N; i++) {
		if ((Limit & A[i]) == A[i]) {
			now += B[i];
		}
	}
	ans = MAX(ans, now);
	//printf("%lld\n", Limit);
}

int main()
{
	scanf("%d %lld", &N, &K);
	for (int i = 1; i <= N; i++) {
		scanf("%lld %lld", &A[i], &B[i]);
	}

	check(K);
	for (LL i = 1; i < 30; i++) {
		if (K & (1LL << i));
		else continue;

		LL temp = ((K >> (i+1))<<(i+1)) | ((1LL << i) - 1);
		check(temp);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1792
#include <vector>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
bool is_prime(int n, int k = 3)
{
    if(n < k * k) { return true; }
     
    if(n % k == 0) { return false; }
     
    return is_prime(n, k + 2);
}
 
int main()
{
    vector<int> prime = {2};
     
    for(int i = 3; i < 101300; i += 2)
    {
        if(is_prime(i))
        {
            prime.push_back(i);
        }
    }
     
    int n, m;
     
    while(true)
    {
        scanf("%d", &n);
        scanf("%d", &m);
         
        if(n == -1 && m == -1) { break; }
         
        int ptr = distance(prime.begin(), lower_bound(prime.begin(), prime.end(), n + 1));
         
        vector<int> c; int r = min(30, m) - 1;
        
        for(int i = ptr + r; i >= ptr; i--)
        {
            for(int j = ptr + r; j >= i; j--)
            {
                c.push_back(prime[i] + prime[j]);
            }
        }
        
        sort(c.begin(), c.end());
         
        printf("%d\n", c[m - 1]);
    }
     
    return 0;
}

Measured memory_bytes: 3272
#include <iostream>
#include <stdio.h>
#define MAX(x, y) (((x)>(y))?(x):(y))
#define MIN(x, y) (((x)<(y))?(x):(y))

using namespace std;

int main(void){
	
	int N;
	int a[101];
	int color[9];
	
	cin >> N;
	for(int i = 0; i < N; i++) cin >> a[i];
	
	for(int i = 0; i < 9; i++) color[i] = 0;
	
	for(int i = 0; i < N; i++){
		if(a[i] >= 3200) a[i] = 3200;
		color[ a[i] / 400 ] ++;
	}
	
	int cnt = 0;
	for(int i = 0; i < 8; i++){
		if( color[i] ) cnt++;
	}
	
	int min = MAX( cnt, 1 );
	int max = cnt + color[8];//MIN( cnt + color[8], 8 );
	
	printf("%d %d\n", min, max);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  // a, b共に8個までなら重ならない
  if(( a + b ) <= 16){
    if(a > 8 || b > 8){
      cout << ":(" << endl;
    }else{
      cout << "Yay!" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
    char a[3];
    cin >> a;
    int i = 0;
    for(int i = 0;i < 2;i++)
    {
        if(a[i] == a[i + 1] && a[i + 1] == a[i + 2])
        {
            cout << "Yes" << endl;
            return 0;
        }
        else
        {
            continue;
        }
    }
    cout << "No" <<endl;
    return 0;
}

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

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vector<int>p(n, k - q);
	rep(i, q) {
		int a;
		cin >> a;
		--a;
		p[a]++;
	}
	rep(i, n) {
		if (p[i] <= 0)puts("No");
		else puts("Yes");
	}
}

Measured memory_bytes: 1024
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


x = int(input())

d = make_divisors(x)

for i in d:
    for a in range(100000):
        b = a - i
        if a ** 5 - b ** 5 == x:
            print(a, b)
            exit()

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

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int c5=0;
		int c7=0;
		int a=sc.nextInt();
		if(a==7) c7++;
		else if(a==5) c5++;
		
		int b=sc.nextInt();
		if(b==7) c7++;
		else if(b==5) c5++;
		
		int c=sc.nextInt();
		if(c==7) c7++;
		else if(c==5) c5++;
		
		if(c5==2&&c7==1) System.out.println("YES");
		else System.out.println("NO");
		

	}

}


Measured memory_bytes: 27012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;
int main() {
    string s;
    cin >> s;
    cout << (s[0] == s[1] && s[1] == s[2] ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int r, d, x; cin >> r >> d >> x;
  REP (i, 10) {
    x = r * x - d;
    cout << x << endl;
  }
}


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

const int sz = 2e5+10;




 
 
int main()
{
    
    int t;
    t=1;
    // cin>>t;
    for(int cs=1;cs<=t;cs++)
    {
 
        ll n;
        cin>>n;
        cout<<pow(n,3)<<endl;


 
    }
    return 0;
} 

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

int main() {
  int N; cin >> N;
  int d[100];
  for ( int i = 0; i < N; i++ ) cin >> d[i];
  sort(d,d+N,greater<int>());
  int cnt = 1;
  for ( int i = 0; i < N-1;i++ ) {
    if ( d[i] > d[i+1] ) cnt++;
  }

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


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

int main(){
  int n;

  while(cin>>n,n){
    int t[n+1][n+1];
    memset(t,0,sizeof(t));
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        cin>>t[i][j];
        t[i][n] += t[i][j];
        t[n][j] += t[i][j];
        t[n][n] += t[i][j];
      }
    }

    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
        printf("%5d",t[i][j]);
      }
      printf("\n");
    }
  }
}

Measured memory_bytes: 0
import bisect
a,b,q=map(int,input().split())
s=[]
t=[]
for i in range(a):
    s.append(int(input()))
for i in range(b):
    t.append(int(input()))
s.append(10**11)
t.append(10**11)

for i in range(q):
    x=int(input())
    ss=bisect.bisect(s,x)
    tt=bisect.bisect(t,x)
    ans=[]
    for i in [s[ss-1],s[ss]]:
        for j in [t[tt-1],t[tt]]:
            ans.append(abs(x-i)+abs(i-j))
            ans.append(abs(x-j)+abs(i-j))
    print(min(ans))
    


Measured memory_bytes: 74712
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> to(n);
    for(int i=0; i<n; ++i){
        cin >> to[i];
        -- to[i];
    }

    int ans = 0;
    if(to[0] != 0){
        to[0] = 0;
        ++ ans;
    }

    vector<int> cnt(n, 0);
    for(int i=0; i<n; ++i)
        ++ cnt[to[i]];
    queue<int> q;
    for(int i=0; i<n; ++i){
        if(cnt[i] == 0)
            q.push(i);
    }

    vector<int> len(n, 1);
    while(!q.empty()){
        int a = q.front();
        q.pop();
        if(to[a] == 0)
            continue;
        if(a == to[a]){
            ++ ans;
            continue;
        }

        if(len[a] == k)
            ++ ans;
        else
            len[to[a]] = max(len[to[a]], len[a] + 1);

        -- cnt[to[a]];
        if(cnt[to[a]] == 0)
            q.push(to[a]);
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int N;
  map<string, int> pall;
  cin >> N;
  
  for(int i = 0; i < N; i++) {
    string S;
    cin >> S;
    pall[S] += 1;
  }
  
  int max = 0;
  for(auto itr = pall.begin(); itr != pall.end(); ++itr) {
    if(itr->second > max) {
      max = itr->second;
    }
  }  
  

  for(auto itr = pall.begin(); itr != pall.end(); ++itr) {
    if(max == itr->second) {
    	cout << itr->first << endl;
    }
  }  
  return 0;
}

Measured memory_bytes: 19216
/**
    BISMILLAH
    @Author : Arham
*/
#include <bits/stdc++.h>
#define endl "\n"
#define found true
#define infinity 30
#define not_found false
#define FOR(limit) for(int i = 0; i < limit; i++)
#define __FOR(limit) for(int j = 0; j < limit; j++)
#define __FOR__(limit) for(int k = 1; k <= limit; k++)
#define hello(a) a ? "Yes" : "No"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define F first
#define S second
// getline (cin, string);
typedef long long lld;
using namespace std;
void solving_f();
int main() {
    ios_base::sync_with_stdio(not_found);
//    cin.tie(0);
//    cout.tie(0);

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    solving_f();

    return not_found;
}
void solving_f() {
    int temp;
    cin >> temp;
    int count;
    if(temp >= infinity)
        count = found;
    else
        count = not_found;
    string s = hello(count);
    cout << s << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
#define INF (1 << 29)
using namespace std;
typedef long long ll;

int main() {
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r;
  rep(i, R) {
    int tmp_r; cin >> tmp_r; tmp_r --;
    r.push_back(tmp_r);
  }
  sort(r.begin(), r.end());
  int d[200][200];
  rep(i, N) {
    rep(j, N) d[i][j] = INF;
    d[i][i] = 0;
  }
  rep(i, M) { 
    int A, B, C; cin >> A >> B >> C; A--; B--;
    d[A][B] = C; d[B][A] = C;
  }

  rep(k, N) rep(i, N) rep(j, N) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
  // for(int i=0; i<N; i++) { for(int j=0; j<N; j++) cout << d[i][j]; cout << endl; }

  int result = INF;
  do {
    int dist = 0;
    for(int i=0; i<r.size()-1; i++) dist += d[r[i]][r[i+1]];
    result = min(result, dist);
  } while(next_permutation(r.begin(), r.end()));
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 384
n = int(input())
r = [int(input()) for _ in range(n)]
min = r[0]
max = r[1]-r[0]
for i in range(1,n):
    if max < r[i]-min:
        max = r[i]-min
    if min > r[i]:
        min = r[i]
print(max)



Measured memory_bytes: 13596
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

struct BinaryIndexedTree
{
  vector< int > data;
  BinaryIndexedTree(int sz)
  {
    data.assign(++sz, 0);
  }
  int Query(int a)
  {
    int ret = 0;
    for(++a; a > 0; a -= a & -a) (ret += data[a]) %= mod;
    return(ret);
  }
  void Add(int k, int x)
  {
    for(++k; k < data.size(); k += k & -k) (data[k] += x) %= mod;
  }
};

int main()
{
  int N, L, x[5000], a[5000];
  vector< BinaryIndexedTree > dp(5001, BinaryIndexedTree(5005));

  cin >> N >> L; ++L;
  for(int i = 0; i < N; i++) {
    cin >> x[i]; ++x[i];
  }
  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }
  dp[0].Add(0, 1);
  for(int i = 0; i < N; i++) {
    if(a[i] == 0) {
      dp[i + 1].Add(x[i], dp[i].Query(x[i] - 1));
    } else for(int j = L - 1; j >= x[i]; j--) {
      if((j - x[i]) % a[i] == 0) {
        dp[i + 1].Add(j, dp[i].Query(j - 1));
      }
    }
  }
  cout << dp[N].Query(L) << endl;
}

Measured memory_bytes: 98956
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int a[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N);
	pair<double, int> ans = { mod,0 };
	for (int i = 0; i < N - 1; i++) {
		ans = min(ans, { abs((double)a[N - 1] / 2 - a[i]),a[i] });
	}
	cout << a[N - 1] << " " << ans.second << endl;
}


Measured memory_bytes: 4016
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		if(a.charAt(a.length()-1)==b.charAt(0)&&b.charAt(b.length()-1)==c.charAt(0)){
			System.out.println("YES");
		}
		else System.out.println("NO");

	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <map>
#include <cstring>

struct card {
    int number;
    char suit;
    int order;
};

void swap(int i, int j, card a[]) {
    card tmp = a[i];
    a[i] = a[j];
    a[j] = tmp;
}

int main() {
    int n;
    std::cin >> n;
    int orders[9];
    for (int i=0; i<9; i++) {
        orders[i] = 0;
    }
    card a[n];
    for (int i=0; i<n; i++) {
        std::cin >> a[i].suit >> a[i].number;
        a[i].order = orders[a[i].number];
        orders[a[i].number]++;
    }
    card b[n];
    memcpy(b, a, n * sizeof(card));
    
    // Bubble sort
    for (int i=0; i<n; i++) {
        for (int j=n-1; j>i; j--) {
            if ( a[j-1].number > a[j].number ) {
                swap(j, j-1, a);
            }
        }
    }
    for (int i=0; i<n-1; i++) {
        std::cout << a[i].suit << a[i].number << " ";
    }
    std::cout << a[n-1].suit << a[n-1].number << std::endl;
    
    // Check stability
    int bubble_orders[9];
    for (int i=0; i<9; i++) {
        bubble_orders[i] = 0;
    }
    std::string str = "Stable";
    for (int i=0; i<n; i++) {
        if ( bubble_orders[a[i].number] > a[i].order ) {
            str = "Not stable";
        } else {
            bubble_orders[a[i].number] = a[i].order;
        }
    }
    std::cout << str << std::endl;
    
    // Selection sort
    for (int i=0; i<n; i++) {
        int mini = i;
        for (int j=i+1; j<n; j++) {
            if ( b[mini].number > b[j].number ) {
                mini = j;
            }
        }
        swap(mini, i, b);
    }
    for (int i=0; i<n-1; i++) {
        std::cout << b[i].suit << b[i].number << " ";
    }
    std::cout << b[n-1].suit << b[n-1].number << std::endl;
    
    // Check stability
    int selection_orders[9];
    for (int i=0; i<9; i++) {
        selection_orders[i] = 0;
    }
    std::string str2 = "Stable";
    for (int i=0; i<n; i++) {
        if ( selection_orders[b[i].number] > b[i].order ) {
            str2 = "Not stable";
        } else {
            selection_orders[b[i].number] = b[i].order;
        }
    }
    std::cout << str2 << std::endl;
}

Measured memory_bytes: 3144
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;
 
typedef int ll;
 
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define endl '\n'
 
typedef pair<int,int>pii;
typedef pair<int,pair<int,int> > piii;
 
const int mod=1e9+7;
 
int POWER[65];
int power(int a, int b) {int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
int inv(int x) {return power(x,mod-2);}
 
void precompute() {
	POWER[0]=1;
	for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL;
}
 
int gcd(int a, int b) {
   if (b == 0)
   return a;
   return gcd(b, a % b);
}
int r,c,k;
int mat[3005][3005];
int DP[3005][3005][4];

int go(int x, int y, int lef) {
	if(x>r || y>c)	return 0;
	if(x==r && y==c) {
		if(lef==0)	return 0;
		return mat[x][y];
	}

	if(DP[x][y][lef]!=-1)	return DP[x][y][lef];

	int ret=0;
	if(lef) {
		ret=max(ret, go(x+1, y, 3)+mat[x][y]);
		ret=max(ret, go(x, y+1, lef));
		ret=max(ret, go(x, y+1, lef-1)+mat[x][y]);
	} else {
		ret=max(ret, go(x+1, y, 3));
		ret=max(ret, go(x, y+1, lef));
	}

	return DP[x][y][lef]=ret;
}
 
ll main() {
	// freopen("Task.in", "r", stdin);freopen("Task.out", "w", stdout);

	cin>>r>>c>>k;

	for (int i=0; i<k; i++) {
		int u, v, cost;
		cin>>u>>v>>cost;

		mat[u][v]=cost;
	}

	memset(DP, -1, sizeof(DP));
	cout<<go(1, 1, 3)<<endl;
}

Measured memory_bytes: 356684
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

x = sum(b)
for A, B in zip(a, a[1:]):
  if B == A + 1:
    x += c[A - 1]

print(x)


Measured memory_bytes: 3060
x, y, a, b, c = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
Pl = 0
Ql = 0
Rb = 0

P.sort(reverse = True)
Q.sort(reverse = True)
R.sort(reverse = True)

P = P[0:x]
Q = Q[0:y]

#while (P[-1 - Pl] < R[0 + Rb] or Q[-1 - Ql] < R[0 + Rb]):
#while (P[-1 - Pl] < R[0 + Rb] or Q[-1 - Ql] < R[0 + Rb]) and (Pl != len(P) or Ql != len(Q)):
while Pl != len(P) or Ql != len(Q):
    if Pl == len(P):
        if Q[-1 - Ql] < R[0 + Rb]:
            Q[-1 - Ql] = R[0 + Rb]
            Ql = Ql + 1
        else:
            break
    elif Ql == len(Q):
        if P[-1 - Pl] < R[0 + Rb]:
            P[-1 - Pl] = R[0 + Rb]
            Pl = Pl + 1
        else:
            break

    elif Q[-1 - Ql] >= P[-1 - Pl] and P[-1 - Pl] < R[0 + Rb]:
        P[-1 - Pl] = R[0 + Rb]
        Pl = Pl + 1
    elif P[-1 - Pl] > Q[-1 - Ql] and Q[-1 - Ql] < R[0 + Rb]:
        Q[-1 - Ql] = R[0 + Rb]
        Ql = Ql + 1

    else:
        break

    Rb = Rb + 1
    if Rb == len(R):
        break

print(sum(P) + sum(Q))

Measured memory_bytes: 23328
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    ll sum = 0;
    ll A[N];
    F0R(i, N) {
        cin >> A[i]; sum ^= A[i];
    }
 
    sum ^= A[0] ^ A[1];
    ll total = A[0] + A[1];
 
    ll dp[2]; dp[0] = -1e15; dp[1] = 0;
 //   cout << sum << nl;
    F0Rd(bit, 45) {
        if (sum & (1ll << bit)) {
 
            if (A[0] & (1ll << bit)) {
                dp[0] += (1ll << bit);
                ckmax(dp[0], dp[1]);
                dp[1] += (1ll << bit);
            } else {
                dp[0] += (1ll << bit);
            }
            total -= (1ll << bit);
        } else {
            if (total >= (1ll << (bit+1))) {
                if (!(A[0] & (1ll << bit))) {
                    dp[1] = -1e15;
                }
                dp[0] += (1ll << bit);
                dp[1] += (1ll << bit);
                total -= 1ll << (bit+1);
            } else {
                if (A[0] & (1ll << bit)) {
                    ckmax(dp[0], dp[1]);
                }
            }
        }
//        cout << bit << " " << dp[0] << " " << dp[1] << nl;
    }
 
    if (total == 0 && (dp[0] > 0 || dp[1] > 0)) {
        cout << A[0]-max(dp[0], dp[1]) << nl;
    } else {
        cout << -1 << nl;
    }
 
 
	
	return 0;
}


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

using namespace std;

int n,m;

vector<int> adj[100005];
int dfs_memo[100005];
bool vis[100005];

int dfs(int u){

    if(adj[u].empty()){
        return 0;
    }

    if(vis[u]){
        return dfs_memo[u];
    }

    for(auto v :adj[u]){
        dfs_memo[u]=max(dfs_memo[u],1+dfs(v));
    }

    vis[u]=true;
    return dfs_memo[u];
}

int main() {
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
    }

    int ans=0;
    for(int i =1;i<=n;i++) {
        ans=max(dfs(i),ans);
    }

    cout << ans;

    return 0;
}

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

#define INF 1000000000
 
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

int compare_long(const void *a, const void *b) {
	return *(long*)a - *(long*)b;
}

int main() {
	long N;
	long A, B, C;
	long data[5];
	long i, j;
	long ans = 0;
	
	scanf("%ld %ld %ld", &A, &B, &C);
	data[0] = A; data[1] = B; data[2] = C;
	
	qsort(data, 3, sizeof(long), compare_long);
	
	if(data[0] % 2 == 0 || data[1] % 2 == 0 || data[2] % 2 == 0) {
		printf("0\n");
	} else {
		printf("%ld\n", data[0] * data[1]);
	}
	
	return 0;
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define upto(a, b, i) for(int i = (a),b_ =(b); i <= b_; ++i)
#define uptil(a, b, i) for(int i = (a),b_ =(b); i < b_; ++i)
#define downto(a, b, i) for(int i = (a),b_ =(b); i >= b_; --i)
#define downtil(a, b, i) for(int i = (a),b_ =(b); i > b_; --i)
#define times(n, i) uptil(0, (n), i)
#define rtimes(n, i) downto((n) - 1,0, i)
#define size(a) ((int)(a).size())
#define ln << endl
#define sp << " "

template<class T> using vec = vector<T>;
template<class T> using vvec = vec<vec<T>>;

void solve() {
  int N,X; cin >> N>>X;
  int k=0;
  times(N, i) {
    int L; cin >> L;
    k += L;
    if(k > X) {
      cout << (i + 1) ln;
      goto next_case;
    }
  }
  cout << N + 1 ln;
  next_case:;
}

signed main() {
  cout << fixed << setprecision(20);
  cerr << fixed << setprecision(6);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x)     (x).begin() , (x).end()
typedef long long int ll;
using namespace std;

const ll     mod = 1e9+7;
const double eps = 1e-9;

int n;
void solve() {
	cin >> n;
	if(n%2==0 || n%5==0) {
		cout << -1 << "\n";
		return;
	}
	int cnt=1,cur=7%n;
	bitset<1000002>res;
	res[cur%n]=1;
	while(1) {
		if(cur==0) {
			break;
		}
		cur = ((cur * 10)%n + 7%n)%n;
		if(res[cur]) {
			cout << -1 << "\n";
			return;
		}
		res[cur]=1;
		cnt ++;
	}
	cout << cnt << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--)
        solve();
    return  0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
    using namespace std;
     
    long double x[100];
    long double y[100];
    int n;
     
    #define POW(x) ((x)*(x))
     
    long double len(int i, int j){
        return sqrtl(POW(x[i]-x[j]) + POW(y[i]-y[j]));
    }
     
    long double solve(long double cx, long double cy, long double r){
     
        for(int i = 0;i < n;i++){
            if(sqrtl(POW(x[i]-cx) + POW(y[i]-cy)) > r+0.00000001){
                return LDBL_MAX;
            }
        }
        return r;
    }
     
    int main(){
        cin >> n;
     
        for(int i = 0;i < n;i++){
            cin >> x[i] >> y[i];
        }
     
        long double ans = LDBL_MAX;
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(i != j){
                    ans = min(ans, solve((x[i]+x[j])/2, (y[i]+y[j])/2, len(i, j)/2));
     
                    for(int k = 0;k < n;k++){
                        if(i != k && j != k){
                            long double ox, oy, a, b, c, d;
                            long double r1, r2, r3;
                            long double stat;
                            long double cx, cy, r;
     
                            a = x[j] - x[i];
                            b = y[j] - y[i];
                            c = x[k] - x[i];
                            d = y[k] - y[i];
     
                            if((a != 0 && d != 0) || (b != 0 && c != 0)){
                                ox = x[i] + (d * (a * a + b * b) - b * (c * c + d * d)) / (a * d - b * c) / 2;
                                if(b > LDBL_EPSILON){
                                    oy = (a * (x[i] + x[j] - ox - ox) + b * (y[i] + y[j])) / b / 2;
                                }else{
                                    oy = (c * (x[i] + x[k] - ox - ox) + d * (y[i] + y[k])) / d / 2;
                                }
                                r1 = sqrtl(POW(ox-x[i]) + POW(oy-y[i]));
                                r2 = sqrtl(POW(ox-x[j]) + POW(oy-y[j]));
                                r3 = sqrtl(POW(ox-x[k]) + POW(oy-y[k]));
     
                                cx = ox;
                                cy = oy;
                                r = (r1 + r2 + r3) / 3;
                                ans = min(ans, solve(cx, cy, r));
                            }
                        }
                    }
                }
            }
        }
     
        if(ans == LDBL_MAX){
            abort();
        }else{
            printf("%.12Lf\n", ans);
        }
     
        return 0;
    }

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
    ll div = 1000000007;
    ll n, ans = 1;
    cin >> n;

    REP(i, n) {
        ans = (ans * (i + 1)) % div;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e2+5;
int n;
double x, d, ans;
int main()
{
    scanf("%d%lf%lf", &n, &x, &d);
    for(int i = n<<1; i; i -= 2) ans += (2*x+(i-1)*d)/2, x = ((i+2)*x+5*d)/i, d = (i+4)*d/i;
    printf("%.9lf\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
main(){
  long long int x,rem=0,sum=0;
  cin>>x;
  while(x>=5){
    if(x>=500) {sum+=(x/500)*1000;
    x=x%500;}
    else {sum+=(x/5)*5;
    x=x%5;}



  }
  cout<<sum<<endl;





}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int n;
int a[100];

int calc(int t){
	int rst = 0;
	REP(i,n) rst += (a[i]-t) * (a[i]-t);
	return rst;
}
int main(){
	cin >> n;
	REP(i,n) cin >> a[i];
	int ans = calc(0);
	for(int i = -100; i <= 100; i++){
		ans = min(ans,calc(i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256