akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define B 10007
#define mod 100000007

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

string S,T;
vector<int> col;
vector<int> mem,nxt;
vector<int> ind;

bool dfs(int i){
  col[i]=1;
  if(nxt[i]==-1){
    col[i]=2;
    return true;
  }
  if(col[nxt[i]]==1)return false;
  if(col[nxt[i]]==0&&!dfs(nxt[i]))return false;
  col[i]=2;
  return true;
}

int dfs2(int i){
  if(mem[i]!=-1)return mem[i];
  if(nxt[i]==-1)return 0;
  else return mem[i]=dfs2(nxt[i])+1;
}

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

  cin>>S>>T;
  {
    string sS;
    while(sS.size()<T.size()){
      sS+=S;
    }
    S=sS;
  }

  int N=S.size();
  int M=T.size();
  vector<ll> Sh(N+1,0),Th(N+1,0);
  nxt.resize(N,-1); ind.resize(N,0);
  rep(i,N)Sh[i+1]=(Sh[i]+S[i]*mod_pow(B,i)%mod)%mod;
  rep(i,M)Th[i+1]=(Th[i]+T[i]*mod_pow(B,i)%mod)%mod;

  auto extract = [&](ll l,ll r,bool f) {
    if(!f) return (Sh[r]-Sh[l]+mod)*mod_pow(mod_pow(B,mod-2),l)%mod;
    else return (Th[r]-Th[l]+mod)*mod_pow(mod_pow(B,mod-2),l)%mod;
  };

  rep(i,N){
    if(i+M<=N){
      if(extract(i,i+M,false)==extract(0,M,true)){
        nxt[i]=(i+M)%N;
      }
    }else{
      int l=N-i;
      if(extract(i,N,false)==extract(0,l,true)&&extract(0,M-l,false)==extract(l,M,true)){
        nxt[i]=(i+M)%N;
      }
    }
  }

  ind.resize(N,0);
  rep(i,N)if(nxt[i]!=-1)ind[nxt[i]]++;

  col.resize(N,0);
  rep(i,N){
    if(col[i]!=0)continue;
    if(!dfs(i)){
      cout<<-1<<endl;
      return 0;
    }
  }
  mem.resize(N,-1);
  int res=0;
  rep(i,N){
    if(ind[i]>0)continue;
    maxch(res,dfs2(i));
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 37424
#include <bits/stdc++.h>
#define int     int64_t
#define ii      pair<int,int>
#define pb      push_back
using namespace std;

int32_t main() {
    std::ios::sync_with_stdio(false);
	int h,w,n; cin >> h >> w >> n;
	set<ii> st;
	for(int i=0,a,b;i<n;i++){
	    cin >> a >> b; --a, --b;
	    st.insert({a,b});
	}
	vector<int> hist(10,0);
	for(auto &cell : st){
	    for(int i=0;i<3;i++){
	        for(int j=0;j<3;j++){
	if(cell.first - i < 0 || cell.second - j < 0 || cell.first - i + 2 >= h || cell.second - j + 2 >= w) continue;
	           int sum = 0;
	           for(int x=0;x<3;x++){
	               for(int y=0;y<3;y++) sum += st.find({cell.first-i+x, cell.second-j+y}) != st.end();
	           }
	           ++hist[sum];
	        }
	    }
	}
	int sum = 0;
	for(int i=1;i<=9;i++) hist[i] /= i, sum += hist[i];
	cout << (h-2) * (w-2) - sum << endl;
	for(int i=1;i<=9;i++) cout << hist[i]<<endl;
	return 0;
}


Measured memory_bytes: 6528
X, K, D = map(int, input().split())

if X < 0:
    X *= -1

n = X // D
m = X % D

if n >= K:
    ans = X - K * D
else:
    if n % 2 == K % 2: ans = m
    else:
        ans = m - D
print(abs(ans))

Measured memory_bytes: 9172
def main():
    A, B = map(int, input().split())
    S = input()

    ab = S.split('-')
    if len(ab) == 2 and len(ab[0]) == A and len(ab[1]) == B:
        if ab[0].isdigit() and ab[1].isdigit():
            print('Yes')
            return
    print('No')

main()


Measured memory_bytes: 3316
h,w=map(int,input().split())
g=[[*input()] for _ in range(h)]
from collections import *
a=0
for sx in range(h):
  for sy in range(w):
    if g[sx][sy]=='#': continue
    d=[[-1]*w for _ in range(h)]
    d[sx][sy]=0
    q=deque([(sx,sy)])
    while q:
      x,y=q.popleft()
      t=d[x][y]+1
      for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
        nx,ny=x+dx,y+dy
        if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]<0:
          d[nx][ny]=t
          q.append((nx,ny))
          a=max(a,t)
print(a)

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

int main(){
    long long n, k;
    cin >> n >> k;
    vector<pair<int,int>> ab(n);

    for (auto i = 0; i < n; i++)
    {
        int a_i, b_i;
        cin >> a_i >> b_i;
        ab[i] =  pair<int, int>(a_i, b_i);
    }

    int ans;

    sort(ab.begin(), ab.end());
    for (auto i = 0; i < n; i++)
    {
        if(ab[i].second>=k){
            ans = ab[i].first;
            break;
        }
        k -= ab[i].second;
    }
    cout << ans << endl;

    
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))

void run(void){
  int n,w;
  scanf("%d%d",&n,&w);
  int64 *dp=(int64 *)calloc(w+1,sizeof(int64));
  while(n--){
    int a,v;
    scanf("%d%d",&a,&v);
    for(int i=w;i>=a;i--){
      dp[i]=MAX(dp[i],dp[i-a]+v);
    }
  }
  printf("%lld\n",dp[w]);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int n;
	cin >> n;
	vector<pair<int,int>> a(n);
	REP(i,n) cin >> a[i].first;
	REP(i,n) cin >> a[i].second;
	
	ll d[2]={};
	for(auto x:a){
		if(x.first > x.second) d[0] += x.first - x.second;
		if(x.first < x.second) d[1] += (x.second - x.first)/2;
	}
	
	if(d[0]==0 && d[1]==0){
		cout << "Yes\n";
		return 0;
	}
	
	if(d[0] <= d[1]){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	 
	
	return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int N, min=200001, count=0;
	cin >> N;
	vector<int> P(N);
	rep(i, N) cin >> P.at(i);

	rep(i, N)
	{
		if(P.at(i)<=min)
		{
			min = P.at(i);
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 1024
def main():
    N = int(input())
    s_dict = {}
    for i in range(N):
        inp = input()
        if inp not in s_dict.keys():
            s_dict[inp] = 1
        else:
            s_dict[inp] += 1
    M = int(input())
    t_dict = {}
    for i in range(M):
        inp = input()
        if inp not in t_dict.keys():
            t_dict[inp] = 1
        else:
            t_dict[inp] += 1
    ans = 0
    for word in s_dict.keys():
        blue = s_dict[word]
        red = t_dict[word] if word in t_dict.keys() else 0
        get = blue - red
        if get > ans:
            ans = get
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
    string str;
    string s, p, buf;
    cin >> s;
    cin >> p;
    buf = s + s;
    if(buf.find(p)!=string::npos){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

ll powll(ll in, ll count) {
	ll reg = 1;
	for (ll i = 0; i < count; ++i)
		reg *= in;
	return reg;
}

signed main()
{
	fastio();
	int a, b;
	cin >> a >> b ;

	if (a <= b)
		cout << a << endl;
	else
		cout << a - 1 << endl;
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <string>
#define nmax 100005
using namespace std;
string s;
int a[nmax], b[nmax], n, m;
int st[nmax], dr[nmax];

int main()
{
    int i, j, t;
    getline(cin, s);
    j = 0;
    for (i = 1; i < s.size(); i++) {
        if (s[i] != s[i-1]) {
            n++;
            a[n] = (i - 1 - j + 1);
            b[n] = s[i-1] - '0';
            j = i;
        }
    }
    n++;
    a[n] = (i - j);
    b[n] = s[i-1] - '0';


    m = s.size();
    for (i = 1; i <= n; i++)
        st[i] = a[i] + st[i - 1];
    for (i = n; i >= 1; i--)
        dr[i] = a[i] + dr[i + 1];

    j = 0;
    int sol = 100000;
    for (i = 1; i<= n; i++)
        sol = min(sol, max(max(dr[i + 1], st[i-1]), min(st[i], dr[i])));
    cout<<sol<<'\n';

    return 0;
}

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

int main(){
	int K,X;
	cin >> K >> X;
	for(int i=X-K+1;i<X+K;i++){
		if(i<-1000000 || i>1000000)continue;
		cout << i;
		if(i==X+K-1 || i==1000000)cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
l_c = len(C)
ans = 0
for b in B:
    n_a = bisect.bisect_left(A, b)
    n_c = l_c - bisect.bisect_right(C, b)
    ans += n_a*n_c
print(ans)


Measured memory_bytes: 22720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

template<class T> struct SintMIN{
    int n;
    T e;
    vector<T> dat;

    SintMIN(T n_,T e_){
        n=1;e=e_;
        while(n<n_) n*=2;
        dat.resize(2*n-1,e);
    }

    void ud(int be,int en,T t,int k,int l,int r){
        if(r<=be||en<=l) return ;
        if(be<=l&&r<=en){
            dat[k]=min(dat[k],t);
            return;
        }
        ud(be,en,t,k*2+1,l,(l+r)/2);
        ud(be,en,t,k*2+2,(l+r)/2,r);
    }

    void ud(int be,int en,T t){
        ud(be,en,t,0,0,n);
    }

    T gt_sub(int k){
        if(k==0) return dat[k];
        return min(dat[k],gt_sub((k-1)/2));
    }

    T gt(int i){
        return gt_sub(i+n-1);
    }
};

template<class T> void cc(vector<T> a,map<T,int>& nm,vector<int>& c){
    sort(a.begin(),a.end());
    fr(i,a.size()){
        if(i<a.size()-1&&a[i]==a[i+1]) continue;
        nm[a[i]]=c.size();
        c.pb(a[i]);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N=0,M,q,A,B,C;
    map<ll,int> nm;vector<ll> a;vector<int> c;
    cin>>M>>q;
    vector<ll> d(q);
    vector<pair<ll,pair<ll,ll>>> xst;
    fr(i,M){
        cin>>A>>B>>C;
        if(B<C) continue;
        if(A<C) A=C;
        xst.emplace_back(C,mp(A,B));
        a.pb(xst[N].ft);
        if(A>C) a.pb(A-C);
        a.pb(B-C);
        N++;
    }
    fr(i,q){
        cin>>d[i];
        a.pb(d[i]);
    }
    a.pb(0);
    sort(a.begin(),a.end());
    cc(a,nm,c);
    SintMIN<int> sg(c.size(),1e9+1);
    fr(i,N){
        sg.ud(nm[-(xst[i].ft-xst[i].sd.ft)],nm[-(xst[i].ft-xst[i].sd.sd)],xst[i].ft);
    }
    fr(i,q){
        ll ans=sg.gt(nm[d[i]]);
        if(ans==1e9+1) cout<<-1<<endl;
        else cout<<ans<<endl;
    }
}

Measured memory_bytes: 77324
#include<stdio.h>

int main(){
  int n,ans=0;
  scanf("%d",&n);
  int p[n];
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  for(int i=1;i<n-1;i++){
    if((p[i-1]<p[i] && p[i]<p[i+1]) || (p[i-1]>p[i] && p[i]>p[i+1])){
      ans+=1;
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N = one_int()
A=many_int()

dicts={i+1:0 for i in range(N)}

for a in A:
    dicts[a] += 1

for i in range(N):
    print(dicts[i+1])

Measured memory_bytes: 38744
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int N = sc.nextInt();
        String S = sc.next();
        HashMap<Character, Integer> cnt = new HashMap<>();
        for (char c : S.toCharArray()) {
            int s = cnt.getOrDefault(c, 0) + 1;
            cnt.put(c, s);
        }

        int m = 0;
        for (int i = 0; i < N; i++) {
            for (int l = 1; l < N; l++) {
                if (i + 2 * l >= N) continue;
                if (S.charAt(i) != S.charAt(i + l) && S.charAt(i + l) != S.charAt(i + 2 * l) && S.charAt(i) != S.charAt(i + 2 * l)) {
                    m++;
                }
            }
        }

        out.println(1L * cnt.getOrDefault('R', 0) * cnt.getOrDefault('G', 0) * cnt.getOrDefault('B', 0) - m);

        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 38564
#include <iostream>
#include <vector>
#include <unordered_set>
#include <cstring>

using namespace std;

const int INF = 1e9 + 5;

int main() {

    int n;
    scanf("%d", &n);
    int k;
    scanf("%d", &k);
    vector<int> h(n);
    for(int& x : h) {
        scanf("%d", &x);
    }
    vector<int> dp(n, INF);

    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 1; j <= k; j++ ) {
            if (i - j >= 0) {
                dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            }
        }
    }

    cout << dp[n-1] << endl;


    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

#define N (1<<18)
int seg[2][1<<19];
void Init(){
  lol(i,N*2)lol(j,2)seg[j][i]=mod;
}
void Update(int i,int x,int flip){
  i+=N-1;
  seg[flip][i]=x;
  while(i){
    i=(i-1)/2;
    seg[flip][i]=min(seg[flip][i],x);
  }
}
int qry(int left,int right,int k,int a,int b,int flip){
  if(left<=a&&b<=right)return seg[flip][k];
  if(right<=a||b<=left)return mod;
  int m=(a+b)/2;
  return min(qry(left,right,k*2+1,a,m,flip),qry(left,right,k*2+2,m,b,flip));
}
int rmq(int left,int right,int flip){
  return qry(left,right+1,0,0,N,flip);
}

int n;
int p[200010];
int at[200010];

struct P{
  int valL,valR;
  int placeL,placeR;
  int left,right,flip;
  bool operator< (const P &P1)const{
    return valL<P1.valL;
  };
  bool operator> (const P &P1)const{
    return valL>P1.valL;
  };
};
priority_queue<P,vector<P>,greater<P> >Q;
void Qpush(int left,int right,int flip){
  if(left>right)return;
  int valL=rmq(left,right,flip);
  int placeL=at[valL];
  int valR=rmq(placeL,right,1-flip);
  int placeR=at[valR];
  P tmp;
  tmp.valL=valL,tmp.valR=valR;
  tmp.placeL=placeL,tmp.placeR=placeR;
  tmp.left=left,tmp.right=right,tmp.flip=flip;
  Q.push(tmp);
}

int main(){
  Init();
  cin>>n;
  lol(i,n){
    cin>>p[i];
    at[p[i]]=i;
    Update(i,p[i],i%2);
  }
  Qpush(0,n-1,0);
  bool first=true;
  while(!Q.empty()){
    P now=Q.top();Q.pop();
    if(!first)cout<<" ";first=false;
    cout<<now.valL<<" "<<now.valR;
    Qpush(now.left,now.placeL-1,now.flip);
    Qpush(now.placeL+1,now.placeR-1,1-now.flip);
    Qpush(now.placeR+1,now.right,now.flip);
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 8436
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int BIG_INT = 1000000000;
const ll BIG_NUM = 1000000000000000000;

bool isBigX;
int sigX;
int sigY;

void printXY(int x, int y) {
	if (isBigX) {
		cout << sigX * x << " " << sigY * y << endl;
	}
	else {
		cout << sigY * y << " " << sigX * x << endl;
	}
}


int main() {
	int k, x, y;
	cin >> k >> x >> y;

	isBigX = abs(x) >= abs(y);
	if (abs(x) < abs(y)) {
		swap(x, y);
	}

	sigX = (x >= 0 ? 1 : -1);
	sigY = (y >= 0 ? 1 : -1);

	x = sigX * x;
	y = sigY * y;



	if (k % 2 == 0 && (x + y) % 2 == 1) {
		cout << -1 << endl;
		return 0;
	}

	if (x + y < k) {
		if ((x + y) % 2 == 1) {
			cout << 3 << endl;
			printXY(x, x - k);
			printXY(x + (k + x - y) / 2, (x - k + y) / 2);
			printXY(x, y);

			return 0;
		}
		else {
			cout << 2 << endl;
			printXY((x + y) / 2, (x + y) / 2 - k);
			printXY(x, y);
			return 0;
		}
	}


	int c = (k - (x + y) % k) % k;
	
	int n;
	if (c % 2 == 0) {
		n = (x + y) / k;
		

	}
	else {
		n = (x + y) / k + 1;
	}

	if ((x + y) % k != 0) {
		n++;
	}
	cout << n << endl;
	int x1, y1;
	x1 = 0;
	y1 = -k;
	while (y1 > -(k * n - x - y) / 2) {
		printXY(x1, y1);
		y1 -= k;
	}
	x1 = (-(k * n - x - y) / 2) - y1;
	y1 = -(k * n - x - y) / 2;
	
	while (x1 < x) {
		printXY(x1, y1);
		x1 += k;
	}

	y1 += (x1 - x);
	x1 = x;
	
	while (y1 <= y) {
		printXY(x1, y1);
		y1 += k;
	}
}



Measured memory_bytes: 2304
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[][] c = new int[10][10];
		int[][] A = new int[H][W];
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				c[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				A[i][j] = sc.nextInt();
			}
		}

		//わしゃわしゃ
		for(int k = 0; k < 10; k++) {
			for(int i = 0; i < 10; i++) {
				for(int j = 0; j < 10; j++) {
					// i -> j において、kを通ったらどう？
					c[i][j] = Math.min(c[i][j], c[i][k] + c[k][j]);
				}
			}
		}

		int sum = 0;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if(Math.abs(A[i][j]) != 1) {
					sum += c[A[i][j]][1];
				}
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 48744
def main():
    import collections
    import math
    n=int(input())
    a=list(map(int, input().split()))
    c=collections.Counter(a)
    cnt=list(c.items())
    ans=0
    comb=[]
    for i in range(len(cnt)): #各出現数字のAi_C_2を計算
        buf=(cnt[i][1]**2-cnt[i][1])//2
        comb.append(buf)
        ans+=buf
    for ai in a:
        print(ans-c[ai]+1)

if __name__=='__main__':
    main()

Measured memory_bytes: 29340
#include <stdio.h>

#define N 20
#define Q 200

int solve(int,int);

int A[N];
int n,flag=0;
main(){
  int i,q;
  int M[Q];

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M[i]);
  }
  
  for(i=0;i<q;i++){
    solve(0,M[i]);
    if(flag==0)printf("no\n");
    else printf("yes\n");
    flag=0;
  }
  return 0;
}

int solve(int i,int m){
  if(m==0){
    flag=1;
    return 1;
  }
  else if(i<n){
    solve(i+1,m-A[i]);
    solve(i+1,m);
  }
}

Measured memory_bytes: 580
#include <iostream>
#include <cstdio>
#include<algorithm>
using namespace std;
 
void qst(int *x, int begin, int end)
{
    if (begin >= end) {
        return;
    }
    int pivot = x[end];
    int i = begin;
    int j = end;
    while (true) {
        for (;;++i){
            if (x[i] <= pivot) break;
        }
        for (;;--j) {
            if (i == j) {
                goto nextfunc;
            }
            if (x[j] > pivot) break;
        }
        int tmp = x[i];
        x[i] = x[j];
        x[j] = tmp;
    }
    nextfunc:
    x[end] = x[i];
    x[i] = pivot;
    qst(x, begin, i -1);
    qst(x, i + 1, end);
    return;
}
 
 
int main ()
{
    int n;
    int m;
    cin >> n >> m;
    int x[m];
    int sum = 0;
    for (int i = 0; i < m; ++i) {
        
        scanf("%i",&x[i]);
        
    }
    /*
    if (m == 1) {
        cout << 0;
        return 0;
    }
    */
    qst(x, 0, m - 1);
    sum = x[0] - x[m - 1];
    int dif[m - 1];
    for (int i = 0; i < m - 1;++i) {
        dif[i] = x[i] - x[i + 1];
    }
    qst(dif, 0 , m - 2);
    for (int i = 0; i < n - 1&& i < m - 1; ++i){
        sum -= dif[i];
    }
    cout << sum;
}

Measured memory_bytes: 1024
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui32 = unsigned int;
constexpr ll INFLL = 1e18;

#define CHECK_IMPL1(cond)              \
if (!(cond)) {                         \
    DEBUG("expected cond: " << #cond); \
    assert(cond);                      \
}

#define CHECK_IMPL2(cond, message)                                            \
if (!(cond)) {                                                                \
    DEBUG("expected cond: " << #cond << " failed with message: " << message); \
    assert(cond);                                                             \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << "\n";
#else
#define DEBUG(message)
#endif

int sign(ll value) {
  if (value > 0) {
    return 1;
  } else if (value < 0) {
    return -1;
  }
  return 0;
}

struct Solver {
  ll solve(int start) {
    ll ans = 0;
    ll s = 0;
    for (int i = 0; i < n; i++) {
      s += a[i];
      if (sign(s) != start) {
        ans += abs(start - s);
        s = start;
      }
      start *= -1;
    }
    return ans;
  }

  void solve() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << min(solve(-1), solve(1)) << "\n";
  }

  int n;
  vector<int> a;
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef __APPLE__
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int t = 1;
//  cin >> t;
  for (int i = 1; i <= t; i++) {
    Solver().solve();
  }
  return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int P = 1000003;
ll power(ll x, ll t) {
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % P) {
		if(t & 1) {
			ret = ret * x % P;
		}
	}
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	vector<ll> fac(P);
	fac[0] = 1;
	for(int i = 1; i < P; ++i) {
		fac[i] = fac[i - 1] * i % P;
	} 
	int q;
	cin >> q;
	while(q--) {
		ll x, d, n;
		cin >> x >> d >> n;
		if(d == 0) {
			cout << power(x, n) << '\n';
			continue;
		}
		x = x * power(d, P - 2) % P;
		if(x + n - 1 >= P) {
			cout << 0 << '\n';
		} else {
			cout << fac[x + n - 1] * power(fac[x - 1], P - 2) % P * power(d, n) % P << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 8704
'''
Created on 2020/09/02

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N=int(pin())
  A=list(map(int,pin().split()))
  cnt=0
  for i in A:
    if i%2==0:
      cnt+=1
  print(3**N-2**cnt)
  return
main()
#解説AC

Measured memory_bytes: 9188
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String o = sc.next();
		String e = sc.next();
		String m = "";
		for (int i = 0 ; i < o.length() ; i++) {
			m += o.charAt(i);
			if (i == e.length()) {
				break;
			}else {
				m += e.charAt(i);
			}
		}
		System.out.println(m);
	}
}

Measured memory_bytes: 21844
import numpy
N, D = map(int, input().split())
listX = []

for i in range(N):
    x = list(map(int, input().split()))
    listX.append(x)

cnt = 0
for i in range(N):
    for j in range(N):
        if i<j:
            u = numpy.array(listX[i]) - numpy.array(listX[j])
            distance = numpy.linalg.norm(u)
            if distance.is_integer():
                cnt += 1
                
print(cnt)

Measured memory_bytes: 12424
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

struct edge{
    int v;
    ll cost;
    edge() = default;
    edge(int v, ll cost) : v(v), cost(cost) {}
};
vector<edge> graph[100005];
vector<int> coloring(100005, -1);

void dfs(int u, int color = 0, int parent = -1){
    coloring[u] = color;

    for(int i = 0; i < graph[u].size(); ++i){
        int v = graph[u][i].v;
        if(v == parent) continue;
        ll cost = graph[u][i].cost;
        if(cost % 2 == 0)   dfs(v, color, u);
        else    dfs(v, color ^ 1, u);
    }
}

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

    int n;
    cin >> n;
    for(int i = 0; i < n - 1; ++i){
        int u, v;
        ll w;
        cin >> u >> v >> w;
        --u, --v;
        graph[u].push_back(edge(v, w));
        graph[v].push_back(edge(u, w));
    }
    dfs(0);
    for(int i = 0; i < n; ++i)  cout << coloring[i] << "\n";
}

Measured memory_bytes: 11392
--http://www.nct9.ne.jp/m_hiroi/light/lua07.html
Stack = {}

function Stack.new()
  local obj = { buff = {} }
  return setmetatable(obj, {__index = Stack})
end

function Stack:push(x)
  table.insert(self.buff, x)
end

function Stack:pop()
  return table.remove(self.buff)
end

function Stack:top()
  return self.buff[#self.buff]
end

function Stack:isEmpty()
  return #self.buff == 0
end

--------------------------------------------------------

local n,k=io.read("*n","*n")
local edge={}
for i=1,n do
    edge[i]={}
end
for i=1,n-1 do
    local a,b=io.read("*n","*n")
    edge[a][b]=false
    edge[b][a]=false
end

local pattern=k
local stack=Stack.new()
stack:push(1)

while not stack:isEmpty() do
    local not_painted=0
    local a=stack:pop()
    for b,_ in pairs(edge[a]) do
        if not edge[a][b] then
            edge[a][b]=true
            edge[b][a]=true
            stack:push(b)
            not_painted=not_painted+1
        end
    end
    local available_colors
    if a==1 then
        available_colors=k-1
    else
        available_colors=k-2
    end
    for i=1,not_painted do
        pattern=pattern*available_colors%1000000007
        available_colors=available_colors-1
    end
end
print(pattern)

Measured memory_bytes: 12980
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const ll LINF = (ll)1 << 60;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
 
struct Unionfind{
  vector<int> rank,p;
  vector<int> bu;
  Unionfind(){}
  Unionfind(int size){
    rank.resize(size,0);
    p.resize(size,0);
    bu.resize(size,-1);
    for(int i=0;i<size;i++){
      makeSet(i);
    }
  }
 
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
 
  bool same(int x,int y){
    if(findSet(x)==findSet(y)){
      if(bu[x]==-1){
        bu[x]=bu[y];
        return(true);
      }
      else if(bu[y]==-1){
        bu[y]=bu[x];
        return(true);
      }
      if(bu[x]!=bu[y]){
        return(false);
      }
      return(true);     
    }
  }
 
  bool unite(int x,int y){
    return(link(findSet(x),findSet(y)));
  }
 
  bool link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
    }
    else{
      p[x]=y;
       
      if(rank[x]==rank[y]){
        rank[y]++;
      }
    }
    if(bu[y]==-1){
      bu[y]=bu[x];
      return(true);
    }
    else if(bu[x]==-1){
      bu[x]=bu[y];
      return(true);
    }
    if(bu[x]!=bu[y]){
      return(false);
    }
    return(true);    
  }
 
  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
 
  bool bukatu(int c,int x){
    if(bu[findSet(c)]==-1){
      bu[findSet(c)]=x;
      return(true);
    }
    else if(bu[findSet(c)]!=x){
      return(false);
    }
    return(true);
  }
};
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n,m,k;
  cin>>n>>m>>k;
  Unionfind uf(n+10);
  rep(i,k){
    int fg,a,b;
    cin>>fg>>a>>b;
    if(fg==1){
      if(!uf.unite(a,b)){
        cout<<i+1<<'\n';
        return(0);
      }
    }
    else{
      if(!uf.bukatu(a,b)){
        cout<<i+1<<'\n';
        return(0);
      }
    }
  }
  cout<<0<<'\n';
  return(0);
}


Measured memory_bytes: 4156
// 最大公約数
_gcd = function(m, n, t) {
    if (n == 0) {
        return m
    }
	while (m % n !== 0) {
		t = n;
		n = m % n;
		m = t;
	}
	return n;
}

input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift() * 1
A = lines.shift().split(' ')

B = [0]
for (i=0; i<N; i++) {
    B[i+1] = _gcd(B[i], A[i])
}

C = []
C[N] = 0
for (i=N-1; i >=0; i--) {
    C[i] = _gcd(C[i+1], A[i])
}

max = 0
for (i=0; i<N; i++) {
    gcd = _gcd(B[i], C[i+1])
    if (max < gcd) {
        max = gcd
    }
}

console.log(max)


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


int main()
{   //freopen("in.txt","r",stdin);

    std::ios_base::sync_with_stdio(0);cin.tie(NULL);

    string s;
    cin>>s;
    stack <char> st;
    st.push('?');
    int sz = s.size();
    for(int i=0;i<s.size();i++){
        if((st.top()=='0' && s[i]=='1')  ||  (st.top()=='1'&& s[i]=='0')){
            st.pop();
        }else st.push(s[i]);
    }
    cout<<sz-st.size()+1<<endl;
    return 0;

}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;

  string ss = s + s;
  map<char, vi> ss_m;
  for (int i = 0; i < ss.length(); i++) {
    ss_m[ss[i]].push_back(i + 1);
  }

  vi t_i(t.length() + 1, 0);
  for (int i = 0; i < t.length(); i++) {
    auto& v = ss_m[t[i]];
    if (v.size() == 0) {
      cout << -1 << endl;
      return 0;
    }
    // for (int j = 0; j < v.size(); j++) {
    //   if (t_i[i] < v[j]) {
    //     t_i[i + 1] = (v[j] > s.length()) ? v[j] - s.length() : v[j];
    //     break;
    //   }
    // }
    auto it = lower_bound(v.begin(), v.end(), t_i[i] + 1);
    t_i[i + 1] = (*it > s.length()) ? *it - s.length() : *it;
  }
  // for (int i = 0; i < t_i.size(); i++) {
  //   printf("%d ", t_i[i]);
  // }
  // printf("\n");

  ll ans = 0;
  for (int i = 1; i < t_i.size(); i++) {
    if (i == t_i.size() - 1) {
      // printf("last\n");
      ans += t_i[i];
    } else {
      if (t_i[i] >= t_i[i + 1]) {
        ans += s.length();
        // printf("ans=%d\n", ans);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2124
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        for(int i = 1; i <= N; i++){
            if (Integer.toString(i).length()% 2 == 1)
                ans ++;
        }System.out.println(ans);
    }

}

Measured memory_bytes: 28500
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

ll lcm(ll a, ll b)
{
   return a *(b/gcd(a, b));
}

int main() {
    int N;
    ll ans = 1;
    ll x;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> x;
        ans = lcm(ans, x);
    }

    cout << ans << endl;
}


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

        int n,v,j;
        int[] A;
    public void run(){
        Scanner sc =  new Scanner(System.in);
            n = sc.nextInt();
            A = new int[n];
            
            for(int i=0; i < n; i++) A[i] = sc.nextInt();
        
            trace();
        
            //insetion sort
        for (int i=1;i<n;i++){
            v=A[i];
            j=i-1;
            while(j>=0&&A[j]>v){
                A[j+1]=A[j];
                j--;
            }
            A[j+1]=v;     
            trace();
        }
      
    }
        
        void trace(){         
                for (int i= 0;i<n;i++){
                    if (i > 0) System.out.print(" ");
                        System.out.print(A[i]);
                    }
                
                System.out.println();  
        }

           public static void main(String[] args){     
               new Main().run();
    } 
}

Measured memory_bytes: 26068
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    intmax_t N;
    cin >> N;

    if (N == 1) {
        cout << 0 << "\n";
        return 0;
    }

    intmax_t res = 0;
    for (intmax_t i = 1; i * i <= N; ++i) {
        if (N / i == N % i) {
            res += i;
        } else if (N / (i + 1) == N % (i + 1)) {
            res += i + 1;
        } else if (N / (N / i - 1) == (N % (N / i - 1))) {
            res += (N / i - 1);
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#ifdef debug
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define vec vector
#define ALL(x) begin(x), end(x)

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    ll a, b, c, k;

    cin >> a >> b >> c >> k;

    if(k & 1) {
        cout << b - a << "\n";
    }else {
        cout << a - b << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template <typename T> using order_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1, typename T2> using order_map = tree <T1, T2, less <T1>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T> bool MIN(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool MAX(T &a, T b) { return a < b ? (a = b, true) : false; }

#define ll              long long int
#define endl            '\n'
#define pii             pair <int, int>
#define pll             pair <ll, ll>
#define mk              make_pair
#define ff              first
#define ss              second
#define all(a)          (a).begin(), (a).end()
#define rall(a)         (a).rbegin(), (a).rend()
#define eb              emplace_back
#define pb              push_back
#define LINE            __LINE__

static const int maxn = 1000 + 5;
static const int logn = 19;

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);

      auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
      mt19937 mt_rand(seed);

      function <ll(ll, ll)> Rand = [&](ll l, ll r) {
            ll rnd = uniform_int_distribution <ll> (l, r)(mt_rand);
            return rnd;
      };

      int a, b, c;
      cin >> a >> b >> c;
      int k;
      cin >> k;
      int mini = min(a, k);
      int ans = mini;
      k -= mini;
      mini = min(b, k);
      k -= mini;
      mini = min(c, k);
      ans -= mini;
      k -= mini;
      cout << ans << endl;

      #ifndef ONLINE_JUDGE
            cerr << endl << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
      #endif // ONLINE_JUDGE
}


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

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

  if(S.size() % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }

  for(int i = 0; i < S.size() / 2 + 1; i++) {
    if(i % 2 == 0) {
      if(S.at(i) != 'h') {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if(S.at(i) != 'i') {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = int;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
    ll n, m; cin >>n>> m;
    vector<vector<ll> >a(4), sum(4);
    ll w0, v0; cin >>w0>> v0;
    a[0].push_back(v0);
    for(int i = 1; i < n; ++i){
        ll w, v; cin >>w>> v;
        a[w-w0].push_back(v);
    }
    for(int i = 0; i < 4; ++i){
        sort(a[i].begin(), a[i].end(), greater<ll>() );
        sum[i].push_back(0);
        for(int j = 0; j < a[i].size(); ++j){
            sum[i].push_back(sum[i][j]+a[i][j]);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= a[0].size(); ++i){
        ll tmp = sum[0][i];
        for(int j = 0; j <= a[1].size(); ++j){
            tmp += sum[1][j];
            for(int k = 0; k <= a[2].size(); ++k){
                tmp += sum[2][k];
                for(int l = 0; l <= a[3].size(); ++l){
                    tmp += sum[3][l];
                    ll w = (i+j+k+l)*w0;
                    w += j + 2*k +3*l;
                    if(w<= m){
                        ans=max(ans, tmp);
                    }
                    tmp -= sum[3][l];
                }
                tmp -= sum[2][k];
            }
            tmp -= sum[1][j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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

	int N, P;
	cin >> N >> P;

	LL A[2] = {};
	A[0] = 1;
	REP(i, N){
		LL a;
		cin >> a;
		if(a % 2 == 0){
			A[0] *= 2;
			A[1] *= 2;
		}
		else{
			LL tmp = A[0];
			A[0] += A[1];
			A[1] += tmp;

		}
	}
//	cerr << A[0] << " " << A[1] << endl;
	if(P == 0) cout << A[0] << endl;
	else cout << A[1] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int i = 1;
  int n;
  scanf("%d", &n);
  while(i <= n) {
    if (i % 3 == 0) {
      printf(" %d", i);
    } else {
      int tmp = i;
      while (tmp) {
        if (tmp % 10 == 3) {
          printf(" %d", i);
          break;
        }
        tmp /= 10;
      }
    }
    i++;
  }
  printf("\n");
  return 0;
}



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

int main(){
	int a;
	vector<int> vc;
	for(int i=0 ; i<10 ; ++i ){
		cin >> a;
		vc.push_back( a );
	}
	sort( vc.begin() , vc.end() );
	cout << vc[9]+vc[8]+vc[7] << " ";
	vc.clear();
	for(int i=0 ; i<10 ; ++i ){
		cin >> a;
		vc.push_back( a );
	}
	sort( vc.begin() , vc.end() );
	cout << vc[9]+vc[8]+vc[7] << endl;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c, d, e, k;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;
    string y = "Yay!";
    string n = ":(";
    if ((e-a)<=k) {
        cout << y << endl;
    } else {
        cout << n << endl;
    }
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void solve(){
  int n;
  cin >> n;
  vector<ll>a(3*n);
  forn(i,3*n)cin >>a[i];
  sort(rall(a));
  ll sm = 0;
  rep(i, 1, 2 * n + 1) if (i%2)sm += a[i];
  cout << sm;

}

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

1
1000000000000000000


*/

Measured memory_bytes: 5508
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define sp std::fixed<<std::setprecision
#define MOD 1000000007
#define MAX 1e18
#define N 1000005
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n , sum = 0;
    cin >> n;
    ll a[n] , ans[n] = {0};
    for( int i = 0 ; i < n ; i++ )
    {
        cin >> a[i];
        if( i % 2 == 0 )
            sum += a[i];
        else
            sum -= a[i];
    }
    ans[0] = sum;
    for( int i = 1 ; i < n ; i++ )
        ans[i] = 2 * a[i - 1] - ans[i - 1];
    for( int i = 0 ; i < n ; i++ )
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944