akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,k,a[SZ],ans=0,md[SZ]; Edg
void dfs(int x,int s=0)
{
	for esb(x,e,b)
		dfs(b,1),md[x]=max(md[x],md[b]);
	++md[x];
	if(md[x]>k-s) ++ans,md[x]=0;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i);
	if(a[1]!=1)
		++ans,a[1]=1;
	for(int i=2;i<=n;++i)
		if(a[i]>1) ad_de(a[i],i);
	for(int i=2;i<=n;++i)
		if(a[i]==1) dfs(i);
	printf("%d\n",ans);
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll M = 1e9 + 7;
vector<ll> v[200005];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  for (int i = 2; i <= n; ++i)
  {
    ll x;
    cin >> x;
    v[x].push_back(i);
  }
  for (int i = 1; i <= n; ++i)
  {
    cout << v[i].size() << endl;
  }
}

Measured memory_bytes: 14468
//Δ_D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 5005;
const int M = N*N;
int n,a[3],b[3];
LL f[M];
int main()
{
	int i,j;
	LL o;
	cin>>n;
	for(i=0;i<3;i=i+1)
		cin>>a[i];
	for(i=0;i<3;i=i+1)
		cin>>b[i];
	memset(f,0,sizeof(f));
	for(i=0;i<3;i=i+1)
		for(j=a[i];j<=n;j=j+1)
			f[j]=max(f[j],f[j-a[i]]+b[i]);
	o=0;
	for(i=0;i<=n;i=i+1)
		o=max(o,f[i]+n-i);
	n=o;
	memset(f,0,sizeof(f));
	for(i=0;i<3;i=i+1)
		for(j=b[i];j<=n;j=j+1)
			f[j]=max(f[j],f[j-b[i]]+a[i]);
	o=0;
	for(i=0;i<=n;i=i+1)
		o=max(o,f[i]+n-i);
	cout<<o;
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;

int X[111111];

signed main(){
    cin>>N>>M;
    rep(i,M)cin>>X[i];sort(X,X+M);

    vint v;
    rep(i,M-1)v.pb(X[i+1]-X[i]);
    sort(all(v));reverse(all(v));
    cout<<X[M-1]-X[0]-accumulate(v.begin(),v.begin()+min(M-1,N-1),0ll)<<endl;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<char>> a(y,vector<char>(x))
#define vec1(a,n) vector<int> a(n);rep(i,n)cin>>a[i]

vector<int> ta={1,0,-1,0};
vector<int> su={0,1,0,-1};
using p=pair<int,int>;

int main(){
  int h,w,x,y,nx,ny;
  cin>>h>>w;
  vec2(a,h,w);
  rep(i,h)rep(j,w) cin>>a[i][j];
  int count_black=0;
  rep(i,h)rep(j,w){if(a[i][j]=='#') count_black ++;}
  vector<vector<int>> seen(h,vector<int>(w,0));
  
  int sx=0,sy=0;
  queue<p> bfs;
  bfs.push(p(sy,sx));
  
  while(!bfs.empty()){
     y=bfs.front().first;
     x=bfs.front().second;
    bfs.pop();
     
     rep(i,4){
        ny=y+ta[i];nx=x+su[i];
        if(nx<0||ny<0||nx>=w||ny>=h) continue;
        if(nx==sx && ny==sy) continue;
        if(seen[ny][nx]!=0) continue;
        if(a[ny][nx]=='#') continue;
        seen[ny][nx] =seen[y][x]+1;
        bfs.push(p(ny,nx));
     }
  }
  if(seen[h-1][w-1]==0){cout<<-1<<endl;return 0;}
  int ans =h*w-count_black-seen[h-1][w-1]-1;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 250000
#define mod 1004535809
#define mod2 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
char s[MN+5];
map<int,int> mp,mp2;long long ans;
int n,pw[MN*2+5],invpw[MN*2+5],pw2[MN*2+5],invpw2[MN*2+5];
int Ha[MN+5],pos[MN+5],ha[MN+5];
inline int PW(int x){return x>=0?pw[x]:invpw[-x];}
inline int PW2(int x){return x>=0?pw2[x]:invpw2[-x];}
int main()
{
	n=read();scanf("%s",s+1);pw[0]=invpw[0]=pw2[0]=invpw2[0]=1;
	for(int i=1;i<=n*2;++i) 
		pw[i]=786433LL*pw[i-1]%mod,invpw[i]=317967460LL*invpw[i-1]%mod,
		pw2[i]=5767169LL*pw2[i-1]%mod2,invpw2[i]=170959791LL*invpw2[i-1]%mod2;
	for(int i=1;i<=n;++i)
	{
		if(s[i]=='<'||s[i]=='>') 
			pos[i]=pos[i-1]+(s[i]=='<'?-1:1),
			ha[i]=ha[i-1],Ha[i]=Ha[i-1];
		else pos[i]=pos[i-1],
			ha[i]=(ha[i-1]+1LL*(s[i]=='+'?1:mod-1)*pw[pos[i]+n])%mod,
			Ha[i]=(Ha[i-1]+1LL*(s[i]=='+'?1:mod2-1)*pw2[pos[i]+n])%mod2;
	}
	for(int i=n;i;--i)
	{
		++mp[(ha[n]-ha[i]+mod)%mod];++mp2[(Ha[n]-Ha[i]+mod2)%mod2];
		ans+=min(mp[(1LL*ha[n]*(mod+1-PW(pos[i-1]))+mod-ha[i-1])%mod],
			     mp2[(1LL*Ha[n]*(mod2+1-PW2(pos[i-1]))+mod2-Ha[i-1])%mod2]);
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 58112
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[101] = {'\0'};
    char p[101] = {'\0'};
    int len_s;
    int len_p;
    int i;
    int j;
    int k;
    int flg;

    scanf("%s", s);
    scanf("%s", p);

    len_s = strlen(s);
    len_p = strlen(p);

    for ( i = 0; i < len_s; i++ ) {
        flg = 1;
        k = i;
        for ( j = 0; j < len_p; j++ ) {
            if ( s[k % len_s] != p[j] ) {
                flg = 0;
                break;
            }
            k++;
        }

        if ( flg ) {
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");
    return 0;
}


Measured memory_bytes: 2112
n, m, t = map(int, input().split())
a_list = list(map(int, input().split()))
ans = 0
ans += max(0, a_list[0] - m)
before = a_list[0]
for i in range(1, n):
    ans += max(0, a_list[i]-before-m*2)
    before = a_list[i]
ans += max(0, t-before-m)
print(ans)



Measured memory_bytes: 5596
#include<stdio.h>

int main(void){
    int a[200] = {0}, b[200] = {0};
    int count[200] = {0};
    int i;
    for(i = 0; scanf("%d", &a[i]) != EOF; i++){
        scanf("%d", &b[i]);
        int sum = a[i] + b[i];
        do{
            sum /= 10;
            count[i]++;
        }while(sum);
    }
    for(i = 0; count[i]; i++)
    printf("%d\n", count[i]);
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    string s;cin >> s;
    vector<int> e(n+1),w(n+1);
    for(int i=0;i<n;i++){
        if(s[i]=='W'){
            w[i+1]=w[i]+1;
        }
        else{
            w[i+1]=w[i];
        }
    }
    for(int i=n-1;i>=0;i--){
        if(s[i]=='E'){
            e[i]=e[i+1]+1;
        }
        else{
            e[i]=e[i+1];
        }
    }
    int ans=inf;
    for(int i=0;i<n;i++){
        chmin(ans,w[i]+e[i+1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2964
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;
#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define pf          push_front
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define all(a)      a.begin(),a.end()
#define mp          make_pair
#define MAX         10001
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

ll gcd(ll a, ll b)
{
      if(!b) return a;
      return gcd(b,a%b);
}

int mark[MAX];

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      int n;
      cin>>n;

      for(int iter=1; iter<=n; iter++){

            for(int i=1; (i*i)<=iter; i++){

                  for(int j=1; (j*j)<=iter; j++){

                        for(int k=1; (k*k)<=iter; k++){

                              int temp=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i);
                              if(temp==iter){
                                    mark[iter]++;
                                    break;
                              }
                              if(temp>iter){break;}
                        }
                  }
            }
      }

      for(int i=1; i<=n; i++){
            cout<<mark[i]<<endl;
      }


      bye;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
const long double PI = 3.141592653589793238462643383279502884197;
const int MAX = 2 * 1e5;

int N, dp[MAX + 5];
int cnt, sum[2], now[MAX + 5][2];
string X;

int f(int val);

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

	memset(dp, -1, sizeof(dp));

	cin >> N >> X;

	for (auto& c : X) cnt += c - '0';

	if (cnt > 1) sum[0] = (X[0] - '0') % (cnt - 1);
	sum[1] = (X[0] - '0') % (cnt + 1);

	for (int i = 1; i < N; i++) {
		if (cnt > 1) sum[0] = (2 * sum[0] + X[i] - '0') % (cnt - 1);
		sum[1] = (2 * sum[1] + X[i] - '0') % (cnt + 1);
	}

	if (cnt > 1) now[N - 1][0] = 1 % (cnt - 1);
	now[N - 1][1] = 1 % (cnt + 1);

	for (int i = N - 2; i >= 0; i--) {
		if (cnt > 1) now[i][0] = 2 * now[i + 1][0] % (cnt - 1);
		now[i][1] = 2 * now[i + 1][1] % (cnt + 1);
	}

	for (int i = 0; i < N; i++) {
		int pcnt = cnt, val = 0;

		if (X[i] == '0') {
			pcnt++;
			val = sum[1] + now[i][1];
		}
		if (X[i] == '1') {
			pcnt--;
			if (pcnt == 0) {
				cout << 0 << '\n';
				continue;
			}
			val = sum[0] - now[i][0];
		}

		cout << f(((val % pcnt) + pcnt) % pcnt) + 1 << '\n';
	}

	return 0;
}

int f(int val) {
	int& ret = dp[val];
	if (ret != -1) return ret;
	if (val == 0) return ret = 0;

	int pcnt = 0;
	for (int i = 0; (1 << i) <= val; i++)
		if (val & (1 << i)) pcnt++;

	return ret = f(val % pcnt) + 1;
}

Measured memory_bytes: 6076
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define inf 1000000000007;
typedef long long ll;
int main(){
	fast;
	string s; cin>>s;
	if(s[0]==s[1]&&s[1]==s[2])cout<<"No";
	else
		cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;
const int N=1e5+10;
struct SEG{
    vector<long long int> v,f;
    int size;
    void init(int n){
        size=n;
        v.resize(size*4,0);
        f.resize(size*4,0);
        return ;
    }
    void add(int n,int pos,int l,int r,int x){
        if(pos>=r){
            f[n]+=x;
            v[n]+=(r-l+1)*(long long int)x;
        }
        else if(pos>=l){
            int mid=(l+r)>>1;
            if(f[n]!=0){
                v[n*2+1]+=(mid-l+1)*f[n];
                v[n*2+2]+=(r-mid)*f[n];
                f[n*2+1]+=f[n];
                f[n*2+2]+=f[n];
                f[n]=0;
            }
            add(n*2+1,pos,l,mid,x);
            add(n*2+2,pos,mid+1,r,x);
            v[n]=v[n*2+1]+v[n*2+2];
        }
        return ;
    }
    long long int ask(int n,int pos,int l,int r){
        if(pos>=r)return v[n];
        else if(pos<l)return 0;
        else{
            int mid=(l+r)>>1;
            if(f[n]!=0){
                v[n*2+1]+=(mid-l+1)*f[n];
                v[n*2+2]+=(r-mid)*f[n];
                f[n*2+1]+=f[n];
                f[n*2+2]+=f[n];
                f[n]=0;
            }
            return ask(n*2+1,pos,l,mid)+ask(n*2+2,pos,mid+1,r);
        }
    }
};
vector<int> graph[N];
int top[N],dep[N],to[N],size[N],p[N],val[N];
SEG b[N];
void dfs(int now){
    int temp=0;
    size[now]=1;
    for(int i:graph[now]){
        p[i]=now;
        dep[i]=dep[now]+1;
        dfs(i);
        if(size[i]>temp){
            temp=size[i];
            to[now]=i;
        }
        size[now]+=size[i];
    }
}
void init(int now){
    if(graph[now].empty()&&top[now]!=now)b[top[now]].init(dep[now]-dep[top[now]]);
    for(int i:graph[now]){
        if(i==to[now])top[i]=top[now];
        else top[i]=i;
        init(i);
    }
    return ;
}
void fix(int n,int w){
    while(n>0){
        if(top[n]!=n)b[top[n]].add(0,dep[n]-dep[top[n]]-1,0,b[top[n]].size-1,w);
        if(top[n]!=0)val[top[n]]+=w;
        n=p[top[n]];
    }
    return ;
}
long long int query(int n){
    long long int ans=0;
    while(n>0){
        if(n!=top[n])ans+=b[top[n]].ask(0,dep[n]-dep[top[n]]-1,0,b[top[n]].size-1);
        if(top[n]!=0)ans+=val[top[n]];
        n=p[top[n]];
    }
    return ans;
}
int main(){
    int n,k,temp,q;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&k);
        for(int j=0;j<k;j++){
            scanf("%d",&temp);
            graph[i].push_back(temp);
        }
    }
    p[0]=-1;
    dep[0]=0;
    top[0]=0;
    dfs(0);
    init(0);
    scanf("%d",&q);
    while(q--){
        scanf("%d",&k);
        if(k==0){
            scanf("%d%d",&k,&temp);
            fix(k,temp);
        }
        else{
            scanf("%d",&temp);
            printf("%lld\n",query(temp));
        }
    }
}



Measured memory_bytes: 29296
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int zh=2,v1,a[N];
int add(int i,int j)
{
	zh++;
	printf("+ %d %d %d\n",i,j,zh);
	a[zh]=a[i]+a[j];
	//printf("%d\n",a[zh]);
	return zh;
}
int small(int i,int j)
{
	zh++;
	printf("< %d %d %d\n",i,j,zh);
	a[zh]=a[i]<a[j];
	//printf("%d\n",a[zh]);
	return zh;
}
int qp(int i,int x)
{
	while(x--)
		i=add(i,i);
	return i;
}
int neg(int i)
{
	return small(i,v1);
}
int sub(int i,int j)
{
	int dif=add(2,2);
	i=add(i,v1);
	for(int k=29;k>=0;k--)
	{
		int p=qp(v1,k);
		int fl=small(add(j,p),i);
		j=add(j,qp(fl,k));
		dif=add(dif,qp(fl,k));
	}
	return dif;
}
int ifel(int i,int j)
{
	return sub(j,qp(neg(i),30));
}
int mul(int i,int j)
{
	i=add(i,v1);
	int ans=add(2,2),x=add(2,2);
	for(int k=29;k>=0;k--)
	{
		int p=qp(v1,k);
		int fl=small(add(x,p),i);
		int fl2=ifel(fl,j);
		fl=qp(fl,k);
		x=add(x,fl);
		ans=add(ans,qp(fl2,k));
	}
	return ans;
}
int main()
{
	puts("45171");
	a[0]=2,a[1]=3;
	v1=small(2,add(0,1));
	int k=mul(0,1);
	printf("+ %d %d %d\n",k,2,2);
	return 0;
}

Measured memory_bytes: 3900
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	VI a(4,0);
	rep(i,6){
		int p; cin>>p; a[p-1]++;
	}
	sort(ALL(a));
	if(a[0]==1&&a[1]==1&&a[2]==2&&a[3]==2) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    long ar[n];
    for(int i = 0;i < n;i++)scanf("%ld",&ar[i]);
    long long cost1 = 0,cost2 = 0,difsum1 = 0,difsum2 = 0;
    long long cus_ar1[n];
    cus_ar1[0] = ar[0];
    for(int i = 1;i < n;i++)cus_ar1[i] = cus_ar1[i-1] + ar[i];
    long long cus_ar2[n];
    for(int i = 0;i < n;i++)cus_ar2[i] = cus_ar1[i];
    for(int i = 0;i < n;i++){
        cus_ar1[i] += difsum1;
        cus_ar2[i] += difsum2;
        if(i % 2){
            if(cus_ar1[i] >= 0){
                cost1 += cus_ar1[i] + 1;
                difsum1 -= cus_ar1[i] + 1;
            }
            if(cus_ar2[i] <= 0){
                cost2 += (-cus_ar2[i] + 1);
                difsum2 += (-cus_ar2[i] + 1);
            }
        }else{
            if(cus_ar1[i] <= 0){
                cost1 += (-cus_ar1[i] + 1);
                difsum1 += (-cus_ar1[i] + 1);
            }
            if(cus_ar2[i] >= 0){
                cost2 += cus_ar2[i] + 1;
                difsum2 -= cus_ar2[i] + 1;
            }
        }
    }
    printf("%lld",(cost1<cost2?cost1:cost2));
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
vector<int> G[N];
int dep[N],ans[N];
void dfs(int u,int fa) {
    for(auto v:G[u]) {
        if(v==fa) continue;
        dep[v]=dep[u]+1;
        dfs(v,u);
    }
}
int main() {
    //freopen("in.txt","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i=1,u,v;i<n;i++) {
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1,-1);
    vector<int> A,B,V[3],Ans[2];
    for(int i=1;i<=n;i++) {
        if(dep[i]&1) A.push_back(i);
        else B.push_back(i);
    }
    for(int i=1;i<=n;i++) {
        V[i%3].push_back(i);
    }
    if(A.size()>=V[1].size()&&B.size()>=V[2].size()) {
        for(auto it:V[1]) Ans[0].push_back(it);
        for(auto it:V[2]) Ans[1].push_back(it);
        int t=A.size()-V[1].size();
        for(int i=0;i<t;i++) Ans[0].push_back(V[0][i]);
        for(int i=t;i<V[0].size();i++) Ans[1].push_back(V[0][i]);
    }
    else if(A.size()<V[1].size()) {
        for(int i=0;i<A.size();i++) Ans[0].push_back(V[0][i]);
        for(int i=A.size();i<V[0].size();i++) Ans[1].push_back(V[0][i]);
        for(auto it:V[1]) Ans[1].push_back(it);
        for(auto it:V[2]) Ans[1].push_back(it);
    }
    else {
        for(int i=0;i<B.size();i++) Ans[1].push_back(V[0][i]);
        for(int i=B.size();i<V[0].size();i++) Ans[0].push_back(V[0][i]);
        for(auto it:V[1]) Ans[0].push_back(it);
        for(auto it:V[2]) Ans[0].push_back(it);
    }
    for(int i=0;i<A.size();i++) {
        ans[A[i]]=Ans[0][i];
    }
    for(int i=0;i<B.size();i++) {
        ans[B[i]]=Ans[1][i];
    }
    for(int i=1;i<=n;i++) {
        printf("%d%c",ans[i],i==n?'\n':' ');
    }
    return 0;
}

Measured memory_bytes: 21236
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete



main = takeWhile (any (/=0)) . map (map readInt . words) . lines <$> getContents >>= mapM_ (putStrLn . cond "yes" "no" . even . apply2 (*))




Measured memory_bytes: 4140
#include<stdio.h>
int main(void){
	#define N 1000000007
	long n, k;
	long x = 0;
	scanf("%ld", &n);
	scanf("%ld", &k);
	for(long i=k; i<=n+1; i++){
		long current_diff = (i*(n-i+1) + 1);
		x = (x+current_diff)%N;
	}
	printf("%ld\n", x);
	return 0;
}

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

using namespace std;

const int MAXN = 505050;

int N,K;
int arr[MAXN];
int pos[MAXN];
int mpos[MAXN];
int temppos[MAXN];

void merge(int a,int b,int c){
	int i = a,j = b+1,k = a;
	mpos[b] = pos[b];
	for(int l=b-1;l>=a;l--){
		mpos[l] = min(pos[l],mpos[l+1]);
	}
	while(i<=b&&j<=c){
		if(mpos[i] < pos[j] + K){
			temppos[k++] = pos[i++];
		}
		else temppos[k++] = pos[j++];
	}
	while(i<=b) temppos[k++] = pos[i++];
	while(j<=c) temppos[k++] = pos[j++];
	for(int k=a;k<=c;k++){
		pos[k] = temppos[k];
	}
}

void msort(int s,int e){
	if(s==e) return;
	int m = (s+e)>>1;
	msort(s,m); 
	msort(m+1,e);
	merge(s,m,e);
}



int main(){
	scanf("%d %d",&N,&K);
	for(int i=1;i<=N;i++){
		int temp;
		scanf("%d",&temp);
		pos[temp] = i;
	}
	msort(1,N);
	for(int i=1;i<=N;i++){
		arr[pos[i]] = i;
	}
	for(int i=1;i<=N;i++){
		printf("%d\n",arr[i]);
	}
	return 0;
}


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

int main(){
    ll x,k,d; cin >> x >> k >> d;
    ll a=x%d;
    ll e=abs(x)/d;
    if (e>=k){
        if (x<0){
            cout << abs(x+d*k) << "\n";
        }
        else{
            cout << abs(x-d*k) << "\n";
        }
    }
    else{
        if ((k-e)%2==0) cout << abs(a) << "\n";
        else {
            if (a<0){
                cout << abs(a+d) << "\n";
            }
            else {
                cout << abs(a-d) << "\n";
            }
        }
    }
}



Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll;
#define pb push_back
#define endl        '\n'
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    int n;
    cin>>n;
    if(n>=82) cout<<"No";
    else if(n==11||n==13||n==17||n==19||n==23||n==29||n==31||n==37||n==41||n==43||n==47||n==53||n==59||n==61||n==67||n==71||n==73||n==79||n==83||n==89||n==97)
cout<<"No";
else if(n==22||n==26||n==33||n==34||n==38||n==44||n==46||n==50||n==51||n==52||n==55||n==58||n==60||n==62||n==65||n==66||n==68||n==69||n==70||n==74||n==75||n==76||n==77||n==78||n==80)
    cout<<"No";
else cout<<"Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
using namespace std;
using ll = long long;

signed main() {
    IO;
	ll n;
	cin >> n;
	ll mo = 1000, st = 0;
	vector<ll> a(n + 5, 0);
	for(int i = 1; i <= n; ++i) cin >> a[i];
	for(ll i = 1; i <= n; ++i) {
		if(a[i] <= a[i + 1]) {
			st += mo / a[i];
			mo -= (mo / a[i]) * a[i];
		}
		else {
			mo += st * a[i];
			st = 0;	
		}
	}
	cout << mo;
    return 0;
}

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

struct point{ int x, y, id; };

point init(int pos_x, int pos_y, int index)
{
	point p; 
	p.x = pos_x, p.y = pos_y, p.id = index; 
	return p; 
}

bool cmp_x(const point &P1, const point &P2){ if(P1.x != P2.x){ return P1.x < P2.x; } return P1.y < P2.y; }
bool cmp_y(const point &P1, const point &P2){ if(P1.y != P2.y){ return P1.y < P2.y; } return P1.x < P2.x; }
bool cmp_id(const point &P1, const point &P2){ return P1.id < P2.id; }

void kd_tree(point *P, int *S, int *T, int *U, int left, int right, int d)
{
	if(right - left < 2) return;

	int mid = ((left + right) >> 1);
	int a = left, b = mid + 1;

	if((d & 1) == 0){
		for(int i = left; i < right; i++){
			if(cmp_x(P[T[i]], P[S[mid]])){
				U[a++] = T[i];
			}else if(P[S[mid]].id == P[T[i]].id){
				U[mid] = T[i];
			}else{
				U[b++] = T[i];
			}
		}
		for(int i = left; i < right; i++){ T[i] = U[i]; }

	}else{
		for(int i = left; i < right; i++){
			if(cmp_y(P[S[i]], P[T[mid]])){
				U[a++] = S[i];
			}else if(P[T[mid]].id == P[S[i]].id){
				U[mid] = S[i];
			}else{
				U[b++] = S[i];
			}
		}
		for(int i = left; i < right; i++){ S[i] = U[i]; }
	}
	kd_tree(P, S, T, U, left, mid, d + 1);
	kd_tree(P, S, T, U, mid + 1, right, d + 1);
}

int cnt;

void find_pt(point *P, int *Q, int *S,  int sx, int tx, int sy, int ty, int left, int right, int d)
{
	if(left >= right) return;

	int mid = ((left + right) >> 1);
	point p = P[S[mid]];
	int a = p.x, b = p.y;

	if(sx <= a && a <= tx && sy <= b && b <= ty){
		Q[cnt] = p.id, cnt++;
	}

	if((d & 1) == 0){
		if((left < mid) && (sx < a || (sx == a && sy <= b))){ find_pt(P, Q, S, sx, tx, sy, ty, left, mid, d + 1); }
		if((mid + 1 < right) && (a < tx || (a == tx && b <= ty))){ find_pt(P, Q, S, sx, tx, sy, ty, mid + 1, right, d + 1); }
	}else{
		if((left < mid) && (sy < b || (sy == b && sx <= a))){ find_pt(P, Q, S, sx, tx, sy, ty, left, mid, d + 1); }
		if((mid + 1 < right) && (b < ty || (b == ty && a <= tx))){ find_pt(P, Q, S, sx, tx, sy, ty, mid + 1, right, d + 1); }
	}
	return;
}

int main()
{
	point *P;
	int *S, *T, *U;
	int Q[100];
	int i, pos_x, pos_y, n;
	scanf("%d", &n);

	P = new point [n];
	S = new int [n], T = new int [n], U = new int [n];

	for(i = 0; i < n; i++){
		scanf("%d %d", &pos_x, &pos_y);
		P[i] = init(pos_x, pos_y, i);
	}
	sort(P, P + n, cmp_x);
	for(i = 0; i < n; i++){ S[i] = P[i].id; }
	sort(P, P + n, cmp_y);
	for(i = 0; i < n; i++){ T[i] = P[i].id; }
	sort(P, P + n, cmp_id);

	kd_tree(P, S, T, U, 0, n, 0);

	int sx, tx, sy, ty, q;
	scanf("%d", &q);
	while(q){
		cnt = 0;
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		find_pt(P, Q, S, sx, tx, sy, ty, 0, n, 0);
		sort(Q, Q + cnt);
		for(int i = 0; i < cnt; i++){ printf("%d\n", Q[i]); }
		printf("\n");
		q--;
	}
	delete [] P;
	delete [] S, delete [] T, delete [] U;

	return 0;
}

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

int main()
{
     int n,m;
    cin>>n>>m;
    int a[n],sum=0,sum1=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum=sum+a[i];
        }
       double vote= double(sum/double(4*m));

       for(int i=0;i<n;i++){
        if(a[i]>=vote){
            sum1++;
           }
        }

        if(sum1>=m){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }

}




Measured memory_bytes: 256
#!/usr/bin/env pypy3
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import bisect


def main():
    mod=10**9+7
    
    N=I()
    A=[[] for _ in range(3)]
    for i in range(3):
        A[i]=LI()
        A[i].sort()
        
    BC=[0]*N
    
    for j in range(N):
        BC[j]=N-bisect.bisect_right(A[2], A[1][j])
                                    
    S=[0]*(N+1)
    for i in range(N):
        S[i+1]=S[i]+BC[i]
        
    ans=0
    for i in range(N):
        ans+=S[-1] - S[bisect.bisect_right(A[1],A[0][i])]
        
    print(ans)
    

main()


Measured memory_bytes: 92644
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    string s;
    int N;
    cin >> N;
    //vector<vector<int>> data(3, vector<int>(4));
    //初期値0
    //vector<int> data(i, 0);
    vl a(N);
    rep(i, 0, N) {
        cin >> a[i];
    }
    ll res = 0;
    ll mx = 0;
    rep(i, 0, N-1) {
        if (a[i] >= a[i+1]) {
            ++mx;
            if (i+1 == N-1) {
                res = max(mx, res);
            }
        } else {
            res = max(mx, res);
            mx = 0;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine().Substring(0,S.Length);
            Console.WriteLine(S == T ? "Yes" : "No");

        }
    }
}

Measured memory_bytes: 17384
s = input()
Aid = 0
Zid = 0

for i in range(len(s)):
  if s[i] == "Z":
    Zid = i
for i in range(len(s)):
  if s[len(s)-i-1] == "A":
    Aid = len(s)-i-1

print(Zid - Aid +1)


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

int main()
{
	int n;
	int ans[4000];
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		int i,j;
		for(i=0,j=0;i<n;i++)
		{
			int num[4000];
			int flag=1;
			double a[4000],b[4000];
			double ans_max[4000];
			
			cin >> num[i] >> a[i] >> b[i] ;
			ans_max[i]=a[i]/10000.0*b[i];
			for(int l=i-1;l>=0;l--)
			{
				if(num[l]==num[i])
				{
//					cout << "in" << endl;
					ans_max[i]+=ans_max[l];
					break;
				}
			}
			
//			cout << "ans_max[" << i << "]:" << ans_max[i] << " num:" << num[i] << endl;
			
			if(ans_max[i]>=100.0)
			{
				for(int k=0;k<j;k++)
				{
					if(ans[k]==num[i])
						flag=0;
				}
				if(flag==1)
				{
					ans[j]=num[i];
					j++;
				}
			}
		}
		
		if(j!=0)
		{
			for(int i=0;i<j;i++)
			{
				cout << ans[i] << endl;
			}
		}
		else
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[2000005]={0};
int main()
{
    ll n,t;
    cin >> n >>t;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    n=max(0ll,n-t);
    ll ans = 0;
    for(int i=0;i<n;i++)
        ans+=a[i];
    cout << ans  << endl;
    return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

ll mod=1e9+7;

const int nax=5005;

vector<ll> facs(nax);
vector<ll> inv(nax);

ll bin_exp(ll n,ll k){
    if(k==0)return 1;
    if(k==1)return n;
    ll c=1;
    if(k%2!=0){
        c=n;
        k-=1;
    }
    ll temp=bin_exp(n,k/2);
    temp=(temp*temp)%mod;
    temp=(temp*c)%mod;
    return temp;
}

ll egcd(ll a,ll b, ll &x, ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x_t,y_t;
    ll d=egcd(b,a%b,x_t,y_t);
    x=y_t;
    y=x_t-y_t*(a/b);
    return d;
}

void fill(){
    facs[1]=1;
    facs[0]=1;
    for(ll i=2;i<nax;i++){
        facs[i]=i*facs[i-1];
        facs[i]%=mod;
    }
    ll x,y;
    for(ll i=0;i<nax;i++){
        ll f=egcd(facs[i],mod,x,y);
        inv[i]=x;
    }
    return;
}

ll c_with_rep(int n,int r){
    if(n==0 || r==1)return 1;
    //if(n==1)return r;
    debug(n,r);
    //dis n objects among r returns n+r-1Cr-1
    ll ret=facs[n+r-1];
    debug(ret,facs[n+r-1]);
    ret=(ret*inv[n])%mod;
    ret=(ret+mod)%mod;
    debug(ret,inv[n]);
    ret=(ret*inv[r-1])%mod;
    ret=(ret+mod)%mod;
    debug(ret,inv[r-1]);
    return ret;
}

int main(){
    fill();
    int n,k;
    scanf("%d%d",&n,&k);
    int red=n-k;
    vector<ll> ans(k+1);
    for(int i=1;i<=red;i++){
        debug("Using these spaces:",i);
        ll red_ways=c_with_rep(red-i,i);
        if(i!=1){
            ans[i-1]=(ans[i-1]+red_ways*c_with_rep(k-i+1,i-1))%mod;
        }
        debug(ans);
        if(k<i)break;
        ll blue_ways=c_with_rep(k-i,i);
        ans[i]=(ans[i]+red_ways*blue_ways*2)%mod;
        if(k<i+1)continue;
        blue_ways=c_with_rep(k-i-1,i+1);
        ans[i+1]=(ans[i+1]+red_ways*blue_ways)%mod;
        debug(ans);
    }
    if(n==k)ans[1]=1;
    for(int i=1;i<=k;i++){
        cout<<(ans[i]+mod)%mod<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3768
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e+5;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

void solve() {
    int a, b;
    cin >> a >> b;
    int x = a + b;
    x = x % 2 ? x / 2 + 1 : x / 2;
    cout << x << endl;
}

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


Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
BA = [[] for i in range(N)]
for i in range(N):
    a,b = LI()
    BA[i] = (b,a)

BA.sort()
part_A = [0 for i in range(N)]
for i in range(N):
    B,A = BA[i]
    part_A[i] = A + part_A[i-1]

for i in range(N):
    B,A = BA[i]
    if B - part_A[i] < 0:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 97352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    VL x(3);
    cin>>x[0]>>x[1]>>x[2];
    SORT(x);
    PUTS((x[0]==x[1] && x[0]!=x[2]) || (x[1]==x[2] && x[0]!=x[2]) ? "Yes":"No");
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        k: usize,
        a: usize,
        b: usize,
    }
    if b <= a + 2 || a >= k {
        println!("{}", k + 1);
        return;
    }
    let c = (k + 1 - a) / 2;
    println!("{}", (b - a) * c + k + 1 - 2 * c);
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
	int f=0;
	int N,r1=0,r2=0,r3=0,r4=0;
	cin >> N;
	
	r1 = (N - (N % 1000))/1000;
	r2 = (N -r1*1000- (N % 100))/100;
	r3 = (N-r1*1000-r2*100 - (N % 10))/10;
	r4 = N-r1*1000-r2*100-r3*10;
	if ((r1 == r2) && (r2==r3)) {
		f++;
	}
	if ((r2 == r3) && (r3 == r4)) {
		f++;
	}
	if (f >= 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

int main(int argc, char const *argv[])
{
	int a,b;
	cin>>a>>b;
	if (a*b%2==0)
	{
		cout<<"Even\n";
	}
	else
	{
		cout<<"Odd\n";
	}
	return 0;
}


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

int main()
{
  int n, q, i, j, k = 0, key = 0;
  int *S, *T;

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

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

  for(j = 0; j < q; j++){
    for(i = 0; i < n; i++){
      if(T[j] == S[i]){
	k++;
	break;
      }
    }
  }
  printf("%d\n", k);

  return 0;
}

Measured memory_bytes: 636
def linear_search(l, key):
    _l = l + [key]

    i = 0
    while key != _l[i]:
        i += 1

    if i == len(_l) - 1:
        return -1

    return i


if __name__ == '__main__':
    n = input()
    s = input().split()
    q = input()
    t = input().split()

    ans = 0
    for c1 in t:
        if linear_search(s, c1) >= 0:
            ans += 1

    print(ans)

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

typedef long long ll;

ll func(ll b, ll n) {
    if (n < b) return n;
    return func(b, n/b) + n%b;
}

int main(void) {
    ll n, s; cin >> n >> s;

    ll ans = -1;
    for (ll b = 2; b*b <= n; b++) {
        if (func(b, n) == s) {
            ans = b;
            break;
        }
    }
    if (n == s) ans = n+1;

    if (ans < 0) {
        vector<ll> candidate;
        for (ll b = 1; b*b <= n-s; b++) {
            if ((n-s)%b == 0) candidate.push_back((n-s)/b + 1);
        }
        sort(candidate.begin(), candidate.end());
        for (ll b : candidate) {
            if (func(b, n) == s) {
                ans = b;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
import bisect

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

num = []
for i in range(min(a), max(a) - 1):
    num.append(bisect.bisect_right(a, i + 2) - bisect.bisect_left(a, i))
if len(num) == 0:
    print(n)
else:
    print(max(num))

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

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef long double ld;
typedef vector<long double> vld;
typedef vector<vector<long double>> mld;
typedef vector<bool> vbl;
typedef vector<vector<bool>> mbl;
#define minimize(a, b) (a = min(a, b))
#define maximize(a, b) (a = max(a, b))
const long long MOD = 1e9 + 7;

template <typename Type>
istream &operator>>(istream &in, vector<Type> &vec) {
   ll n = vec.size();
   for (int i = 0; i < n; i++)
       in >> vec[i];
   return in;
}
template <typename Type>
ostream &operator<<(ostream &out, vector<Type> &vec) {
    for (auto val : vec)
        out << val << " ";
    out << endl;
    return out;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, a, b; cin >> n >> a >> b;
    if (a % 2 == b % 2) cout << abs(b - a) / 2 << endl;
    else cout << min(a / 2 + b / 2, (n - a + 1) / 2 + (n - b + 1) / 2) << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG //提出時に消す
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

ll modPow(ll a, ll n, ll p) {
  if (n == 0) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n-1, p)) % p;
  ll t = modPow(a, n/2, p);
  return (t * t) % p;
}

struct prime_n {
  ll p = -1;
  bool isPrime = true;
};

int struct_prime(vector<prime_n>&primes) {
  primes[0].isPrime = false;
  primes[1].isPrime = false;
  int cnt = 0;
  for (int i = 0; i < primes.size(); i++) {
    if (!primes[i].isPrime) continue;
    primes[i].p = i;
    cnt++;
    for (int k = 2 * i; k < primes.size(); k += i) {
      primes[k].isPrime = false;
    }
  }
  return cnt;
}

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  vector<prime_n> primes(1000000);
  struct_prime(primes);
  vector<ll> lcmfactor(1000000, 0);
  for (int i = 0; i < n; i++) {
    ll k = a[i];
    if (primes[a[i]].isPrime) {
      lcmfactor[a[i]] = max(lcmfactor[a[i]], 1LL);
      continue;
    }
    for (int j = 0; j <= (int)sqrt(a[i]); j++) {
      if (!primes[j].isPrime) continue;
      ll cnt = 0;
      while (k % j == 0) {
        cnt++;
        k /= j;
      }
      lcmfactor[j] = max(lcmfactor[j], cnt);
    }
    lcmfactor[k] = max(lcmfactor[k], 1LL);
    //if (primes[a[i]].isPrime) lcmfactor[a[i]] = max(lcmfactor[a[i]], 1LL);
  }
  //cout << "fin" << endl;
  //vector<map<ll, ll>> factor(n, map<ll, ll>());
  //map<ll, ll> lcmfactor;
  /*vector<ll> lcmfactor(s);
  for (int i = 0; i < n; i++) {
    ll k = a[i];
    for (int j = 0; j < s; j++) {
      ll p = primes[j];
      ll cnt = 0;
      if (k == 1) break;
      while (k % p == 0) {
        //factor[i][p]++;
        cnt++;
        k /= p;
      }
      lcmfactor[j] = max(lcmfactor[j], cnt);
    }
  }*/
  //cout << "fin" << endl;

  /*for (int i = 0; i < n; i++) {
    for (ll p: primes) {
      lcmfactor[p] = max(lcmfactor[p], factor[i][p]);
    }
  }
  cout << "fin" << endl;

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll temp = 1;
    for (ll p: primes) {
      //for (ll j = 0; j < lcmfactor[p] - factor[i][p]; j++) {
      //  temp *= p;
      //  temp %= MOD;
      //}
      temp *= modPow(p, lcmfactor[p] - factor[i][p], MOD);
      temp %= MOD;
    }
    ans += temp;
    ans %= MOD;
  }

  cout << ans << endl;*/
  ll lcm = 1;
  for (int j = 0; j < 1000000; j++) {
    //cout << p << " " << lcmfactor[p] << " "<< modPow(p, lcmfactor[p], MOD) << endl;
    //if (lcmfactor[j] == 0) continue;
    lcm *= modPow(j, lcmfactor[j], MOD);
    lcm %= MOD;
  }

  //cout << lcm << endl;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (lcm * modPow(a[i], MOD-2, MOD));
    ans %= MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define F_(i,a,b) for (int i=(a);i>=(b);--i)
#define G(i,u) for(int i=head[u];i;i=nxt[i])

template<typename T> int max(T& a, T b) { return a>b?a:a=b; }
template<typename T> int min(T& a, T b) { return a<b?a:a=b; }

int main() {
	int n, k;
	scanf ("%d%d", &n, &k);
	n -= k;
	printf("%d\n", (int)(1 + ceil(1.0f*n/(k-1))));
	return 0;
} 

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

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;i++){
        sum+=a[i];
    }
cout<<sum;

}


Measured memory_bytes: 3636