akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<map>
#define PI 3.141592653589793238
#define INF -1
#define ll long long
using namespace std;

int main()
{
	int tmp, n;
	int bingo[3][3] = { 0 };

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> tmp;
			bingo[i][j] = tmp;
		}
	}

	cin >> n;
	for (int k = 0; k < n; k++) {
		cin >> tmp;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (bingo[i][j] == tmp) {
					bingo[i][j] = 0;
					break;
				}
			}
		}
	}

	for (int i = 0; i < 3; i++) {
		if (bingo[i][0] == 0 && bingo[i][1] == 0 && bingo[i][2] == 0) {
			printf("Yes");
			return 0;
		}
		if (bingo[0][i] == 0 && bingo[1][i] == 0 && bingo[2][i] == 0) {
			printf("Yes");
			return 0;
		}
	}

	if (bingo[0][0] == 0 && bingo[1][1] == 0 && bingo[2][2] == 0) {
		printf("Yes");
		return 0;
	}
	if (bingo[2][0] == 0 && bingo[1][1] == 0 && bingo[0][2] == 0) {
		printf("Yes");
		return 0;
	}

	printf("No");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ri register int 
#define For(i,j,k) for(ri i=j;i<=k;i=-~i)
inline int v_in(){
    int f=1,sum=0;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){sum=(sum<<3)+(sum<<1)+(ch^48);ch=getchar();}
    return sum*f;
}
const int M=3e3+5;
int n,tot,a[M],sum,ans[M*M];bitset<M*M>b;
int main(){
	n=v_in();For(i,1,n)sum+=(a[i]=v_in());
	b[0]=1;For(i,1,n)b|=(b<<a[i]);
	For(i,1,sum)if(b[i])ans[++tot]=i;
	printf("%d\n",ans[(1+tot)/2]);
	return 0;
}

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

const int N = 123456;

int a[N];

int main() {

	int n;
	cin >> n;
	unordered_set<int> s;
	for (int i = 0; i < n; i++) {
		scanf("%d", a+i);
		s.insert(a[i]);
	}

	int x = s.size();
	int ans = x&1 ? x : x-1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4772
from string import ascii_lowercase as alph

def gen_pattern(N, pre="", m=-1):
  for i, c in enumerate(alph[:m+2]):
    pat = pre+c
    if len(pat) == N:
      yield pat
    else:
      yield from gen_pattern(N, pat, max(i,m))

for pattern in gen_pattern(int(input())):
  print(pattern)


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

int main(){
    int A, B, X;
    if(scanf("%d %d %d", &A, &B, &X) == 3) {
        if (A <= X && A + B >= X) {
            printf("%s\n", "YES");
        } else {
            printf("%s\n", "NO");
        }
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N)]
cd = [tuple(map(int, input().split())) for _ in range(M)]

for a, b in ab:
    m = min(abs(a-c)+abs(b-d) for c, d in cd)
    
    for i in range(M):
        if abs(a-cd[i][0])+abs(b-cd[i][1])==m:
            print(i+1)
            break


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

int n, m, x;
void solve(){
	cin >> n >> m >> x;
	int cost[n];
	int a[n][m];
	int i, j;
	
	for(i=0;i<n;i++){
		cin >> cost[i];
		for(j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	int r = 1<<n;
	long long ans = 1e16+5;
	bool ok = 0;
	for(int comb = 0; comb < r; comb++){
		vector<int> b(m);
		bool skill=1;
		int cos = 0;
		for(i=0;i<n;i++){
			if((comb>>i)&1){
				cos += cost[i];
				for(j=0;j<m;j++){
					b[j] += a[i][j];
				}
			}
		}
		for(i=0;i<m; i++){
			if(b[i] < x){
				skill = 0;
				break;
			}
		}
		if(skill && cos < ans){
			ok = 1;
			ans = cos;
		}
	}
	if(ok){
		cout << ans;
	}else {
		cout << -1;
	}
	return;
}

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define int long long
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main() {
cout << std::fixed << std::setprecision(20);
  long double x, y;
  long double h,m;
  cin >>x>>y>> h >> m;
  long double rad = M_PI*2.0*(h / 12.0 + m / 60.0 / 12.0 -m / 60.0);
  cout << sqrtl(powl(x,2)+powl(y,2)-(long double)(2*x*y)*cosl(rad));
}

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


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

using namespace std;

int main(int argc, char *argv[]) {
    string m;
    int n;
    int c[1<<20];
    
    cin >> n >> m;

    c[0] = 0;
    for (int i = 1; i < n; i++) if (m[i] == 'E') c[0]++;
    for (int i = 1; i < n; i++) {
        c[i] = c[i-1];
        if (m[i-1] == 'W') c[i]++;
        if (m[i] == 'E') c[i]--;
    }

    int ans = c[0];
    for (int i = 1; i < n; i++) ans = min(ans, c[i]);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3844
#include "bits/stdc++.h"
using namespace std;

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

    for (int i = 0; i < 3; i++) {
        if (S[i] == '1') {
            S[i] = '9';
        }
        else if (S[i] == '9') {
            S[i] = '1';
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 768
NK = input().split()
S = set()

N = int(NK[0])
K = int(NK[1])

for i in range(K):
    n = int(input())
    L = input().split()

    for x in L:
        if x in S:
            pass
        else:
            S.add(x)

print(N - len(S))



Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define    ll long long
#define    pb          push_back
#define    m_p(a,b)    make_pair(a,b)
#define    inp(x)      scanf("%d",&x)
#define    lnp(x)      scanf("%lld",&x)
#define    ff          first
#define    ss          second
#define    srt(v)      sort(v.begin(),v.end())

ll dp[200000];
ll arr[200000];
ll n,k;

ll solve(ll i)
{
    if(i == n) return 0;
    if(dp[i] != -1) return dp[i];
    ll ret1 = 1000000000;
    for(ll j = 1;j <= k;j++){
        if(i+j <= n){
            ret1 = min(ret1,abs(arr[i] - arr[i+j]) + solve(i+j));
        }
    }
    dp[i] = ret1;
    return dp[i];
}

int main()
{
    lnp(n);lnp(k);
    for(ll i = 1;i <= n;i++){
        lnp(arr[i]);
    }
    memset(dp,-1,sizeof dp);
    ll ans = solve(1);
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 7296
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,D[51];
	int Dnum[13]={};
	scan(N);
	Dnum[0]=1;
	rep(i,N){
		scan(D[i]);
		Dnum[D[i]]++;
	}
	int flag=0;
	rep(t,13){
		if(t==0||t==12){
			if(Dnum[t]>=2) flag=2;
		}
		else{
			if(Dnum[t]>=3) flag=2;
		}
	}
	if(flag==2){
		prin(0);
	}
	else{
		int Dnumb=0;
		rep1(t,12){
			if(t==1){
				if(Dnum[t]>=1) flag=1;
				Dnumb=Dnum[t];
			}
			else if(t==12){
				if(Dnum[t]>max(0,1-Dnumb)) flag=1;
			}
			else{
				if(Dnum[t]>2-Dnumb) flag=1;
				Dnumb=Dnum[t];
			}
		}
		if(flag){
			prin(1);
		}
		else{
			int sminmax=0;
			rep(bit,(1<<N)){
				vint Dv;
				Dv.push_back(0);
				rep(i,N){
					if(bit&(1<<i)){
						Dv.push_back(D[i]);
					}
					else{
						Dv.push_back(24-D[i]);
					}
				}
				sort(Dv.begin(),Dv.end());
				int smin=INF;
				rep(i,N+1){
					if(i==N){
						smin=min(smin,24+Dv[0]-Dv[N]);
					}
					else{
						smin=min(smin,Dv[i+1]-Dv[i]);
					}
				}
				sminmax=max(sminmax,smin);
			}
			prin(sminmax);
		}
	}
	return 0;
}


Measured memory_bytes: 256
'use strict'

function main(s) {

  s = s.split('\n');
  const x = Number(s[0].split(' ')[2]);
  const a = s[1].split(' ').map(x => Number(x));
  const toN = a.filter(num => x < num).length;
  const to0 = a.filter(num => x > num).length;
  const ans = Math.min(to0, toN);

  console.log(ans);
}

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


Measured memory_bytes: 7372
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    char[] c = s.toCharArray();

    //iranai tokoro wo kiriotosu
    int start = -1;
    int end = n-1;
    for(int i = 0;i<n;i++){
      if(c[i]=='W'){
        start=i;
        break;
      }
    }
    if(start == -1){
      System.out.println(0);
      return;
    }
    for(int i = n-1;i>=0;i--){
      if(c[i]=='R'){
        end=i;
        break;
      }
    }
    if(start>=end){
      System.out.println(0);
      return;
    }

    //kanngaeteiku
    //hani no aka siro kazoeru
    int total = end - start + 1;
    int white = 0;
    int red;
    for(int i = start;i<=end;i++){
      if(c[i]=='W')white++;
    }
    red = total - white;
    //tiisihou ni atehameru
    int ans = 0;
    if(red<=white){
      for(int i = 0;i<red;i++){
        if(c[start + i]=='W')ans++;
      }
      System.out.println(ans);
    }else{
      for(int i = 0;i<white;i++){
        if(c[end - i]=='R')ans++;
      }
      System.out.println(ans);
    }
  }
}


Measured memory_bytes: 40736
mod = 10 ** 9 + 7

x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    exit()

if x > 2 * y or y > 2 * x:
    print(0)
    exit()

cnt = (x + y) // 3
x_cnt = x - cnt
y_cnt = y - cnt
min_cnt = min(x_cnt, y_cnt)

def nCr(n, r, mod):
    return g1[n] * g2[r] * g2[n - r] % mod

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, cnt + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

print(nCr(cnt, min_cnt, mod))

Measured memory_bytes: 82448
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int dp[N];

signed main(){
    IOS;
    int n;
    cin >> n;
    dp[1] = 1;
    for (int i = 2; i <= n; i++)
        dp[i] = inf;
    for (int i = 2; i <= n; i++) {
        dp[i] = min(dp[i], dp[i-1] + 1);
        for (int j = 6; j <= i; j*=6) {
            dp[i] = min(dp[i], dp[i-j] + 1);
        }
        for (int j = 9; j <= i; j*=9) {
            dp[i] = min(dp[i], dp[i-j] + 1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
((input: string): void => {
    const [_, v, c]: number[][] = input.trim().split(/\n/).map(
        v => v.split(" ").map(Number)
    );
    const hoge = v.map( (v, i) => v - c[i] ).filter(v => v > 0)
    console.log(hoge.length==0 ? 0 : hoge.reduce( (a, b) => a+b ));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
void insert_sort(vector<int> & v,int n, int g, int &cnt){
    int value,j;
    for(int i = g;i<n;i++){
         value = v[i];
         j = i-g;
         while(j>=0 && v[j]>value){
             v[j+g] = v[j];
             j = j-g;
             cnt++;
         }
         v[j+g] = value;
    }

}
int main(){
    int cnt = 0;
    int N, temp, m;
    cin>>N;
    vector<int> rt;
    while(cin>>temp){
        rt.push_back(temp);
    }
    m = N <= 4 ? 1 : log((N-1))/log(4) + 1;
    cout<<m<<endl;
    for(int i = m-1;i>=0;i--){
        temp = pow(4,i);
        insert_sort(rt,N,temp,cnt);
        cout<<temp;
        if(i!=0)
            cout<<" ";
    }
    cout<<endl;
    cout<<cnt<<endl;
    for(int i : rt){
        cout<<i<<endl;
    }

}


Measured memory_bytes: 7080
def powmod(x, n,mod):
  if n == 0:
   return 1
  K = 1
  while n > 1:
   if n % 2 != 0:
    K = K * x%mod
    x = x ** 2%mod
    n = (n - 1) // 2
   else:
    x = x ** 2%mod
    n = n // 2%mod

  return K * x # 指数を割り続け n が 1 に至ったら終了
L=input()
S=len(L)-1
if S==0:
 print(3)
else:
 ans=1
 ct=0
 for i in range(S+1):
  if int(L[i])==1:
   ans+=((powmod(3, S-i,10**9+7)+1)*powmod(2, ct,10**9+7))%(10**9+7)
   ans%=(10**9+7)
   ct+=1
 print(ans)


Measured memory_bytes: 44396
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort()
MIN=A[1]
for i in range(MIN,0,-1):
  miss=0
  for k in range(N):
    if A[k]%i != 0:
      miss+=1
      if miss==2:
        break
    if k==N-1:
      ans=i
      print(ans)
      sys.exit()

Measured memory_bytes: 14076
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    a = list(map(int, input().split()))

    num = 1
    count = 0

    for i in a:
        if i == num:
            num += 1
        else:
            count += 1
    
    if num == 1:
        print(-1)
    else:
        print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 77516
h, w = gets.split.map(&:to_i)
hw = []
h.times{|i|
  hw[i] = gets.chomp
}
r, c = gets.split.map(&:to_i)
exit if r > h || c > w

hash = Hash.new { |ha,k| ha[k] = [] }

if r <= c then
  rc_hash = {}
  rc = []
  r.times{|i|
    rc[i] = gets.chomp
    rc_hash[rc[i]] = 0 unless rc_hash[rc[i]]
    rc_hash[rc[i]] += 1
  }

  idx = rc.index(rc_hash.min {|a, b| a[1] <=> b[1] }[0])

  idx.upto(h-r+idx){|i|
    0.upto(w-c){|j|
      hash[hw[i][j,c]] << "#{i} #{j}"
    }
  }
  key = rc[idx]
  if hash[key] then
    if hash.size == 1 and rc_hash.size == 1 then
      # uniform mode
      hash[key].each{|ij|
        i, j = ij.split.map(&:to_i)
        ans = true
        unless hw[i-idx][j,c] == rc[0] then
          ans = false
        end
        puts "#{i-idx} #{j}" if ans
      }
    else
      hash[key].each{|ij|
        i, j = ij.split.map(&:to_i)
        ans = true
        r.times{|k|
          unless hw[i-idx+k][j,c] == rc[k] then
            ans = false
            break
          end
        }
        puts "#{i-idx} #{j}" if ans
      }
    end
  end
 else
   #transpose mode
  mat = Array.new(w){Array.new(h)}
  h.times{|i|
    tmp = hw[i].split("")
    w.times{|j|
      mat[j][i] = tmp[j]
    }
  }
  wh = []
  w.times{|j|
    wh[j] = mat[j].join
  }
  mat = Array.new(c){Array.new(r)}
  r.times{|i|
    tmp = gets.chomp.split("")
    c.times{|j|
      mat[j][i] = tmp[j]
    }
  }
  cr_hash = {}
  cr = []
  c.times{|j|
    cr[j] = mat[j].join
    cr_hash[cr[j]] = 0 unless cr_hash[cr[j]]
    cr_hash[cr[j]] += 1
  }
  idx = cr.index(cr_hash.min {|a, b| a[1] <=> b[1] }[0])
  key = cr[idx]
  0.upto(h-r){|i|
    idx.upto(w-c+idx){|j|
      hash[wh[j][i,r]] << "#{i} #{j}"
    }
  }
  if hash[key] then
    hash[key].each{|ij|
      i, j = ij.split.map(&:to_i)
      ans = true
      c.times{|k|
        unless wh[j-idx+k][i,r] == cr[k] then
          ans = false
          break
        end
      }
      puts "#{i} #{j-idx}" if ans
    }
  end
end

Measured memory_bytes: 275992
n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    x,y,z=map(int,input().split())
    a.append(x)
    b.append(y)
    c.append(z)

INF=float("inf")
dpa=[-INF]*n
dpb=[-INF]*n
dpc=[-INF]*n
dpa[0]=a[0]
dpb[0]=b[0]
dpc[0]=c[0]

for i in range(1,n):
    dpa[i]=a[i]+max(dpb[i-1],dpc[i-1])
    dpb[i]=b[i]+max(dpc[i-1],dpa[i-1])
    dpc[i]=c[i]+max(dpa[i-1],dpb[i-1])
    
print(max(dpa[-1],dpb[-1],dpc[-1]))
    




Measured memory_bytes: 28436
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	string s; cin >> s;
	if(s[2]==s[3] && s[4] == s[5])cout << "Yes" << endl;
	else cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int k=0,ans=0;
  char c[3];
  scanf("%s",c);
  for(int i=0;i<3;i++){
    if(c[i]=='R'){k++;}
    else{k=0;}
    if(ans<k){ans=k;}
  }
  printf("%d\n",ans);
}
    
    

Measured memory_bytes: 1708
import java.util.*;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[N-1];
        int[] b = new int[N-1];
        for (int i=0; i<N-1; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        Ans ans = solve(N, a, b);

        System.out.println(ans.K);
        for (int i=0; i<N-1; i++) {
            System.out.println(ans.c[i]);
        }
    }

    private static Ans solve(int N, int[] a, int[] b) {
        Ans ans = new Ans(N);

        List<Integer[]>[] list = new ArrayList[N];
        for (int i=0; i<N; i++) {
            list[i] = new ArrayList<>();
        }
        for (int i=0; i<N-1; i++) {
            list[a[i]-1].add(new Integer[]{i, b[i]-1});
            list[b[i]-1].add(new Integer[]{i, a[i]-1});
        }

        Queue<Integer> queue = new ArrayDeque();
        int[] color = new int[N];
        color[0] = 1;
        queue.add(0);
        while (queue.size() > 0) {
            int node = queue.poll();
            int coloring = 0;

            // System.err.println("node=" + (node+1));
            for (int i=0; i<list[node].size(); i++) {
                int edge = list[node].get(i)[0];
                int connect = list[node].get(i)[1];

                if (color[connect] != 0) {
                    // System.err.println("skip connection to " + (connect+1));
                    continue;
                }
                coloring++;
                if (node != 0 && color[node] == coloring) coloring++;

                // System.err.println("edge=" + edge + ", connect=" + (connect+1) + ", color[" + (node+1) + "]=" + color[node] + ", coloring=" + coloring);
                color[connect] = coloring;
                ans.c[edge] = coloring;

                queue.add(connect);
            }

            ans.K = Math.max(ans.K, coloring);
        }

        return ans;
    }

    public static class Ans {
        public int K;
        public int[] c;

        public Ans(int N) {
            K = 0;
            c = new int[N-1];
        }
    }
}

Measured memory_bytes: 92188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

int main(void){
    Cin(int, a);
    Cin(int, b);
    Cin(int, c);
    Cin(int, d);
    Cout(max(a-b, 0));
}

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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	string s;
	cin >> s;

	int n;
	n = s.size();
	
	if(s[n-1] == 's'){
		cout << s << "es" << endl;
	}else{
		cout << s << "s" << endl;
	}
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int N = 20;
int a[N][N];
ll dp[1<<N];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) scanf("%d", &a[i][j]);

	for (int mask = 1; mask < (1<<n); mask++) {
		for (int i = 0; i < n; i++)
			for (int j = i+1; j < n; j++)
				if ((mask & (1<<i)) && (mask & (1<<j))) dp[mask] += a[i][j];
	}

	for (int mask = 1; mask < (1<<n); mask++) {
		for (int x = mask; x > 0; x = (x-1) & mask)
			dp[mask] = max(dp[mask], dp[x] + dp[mask^x]);
	}
	printf("%lld\n", dp[(1<<n) - 1]);
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll n,h,d;
    cin >> n >> h >> d;
    ll x = 0;
    ll zx = 1;
    for (int i = 1; i < n+1; i++) {
        zx *= i;
        zx %= 1000000007;
        x += zx;
        x %= 1000000007;
    }
    vector<ll> z(h+1);
    z.at(0) = 1;
    z.at(1) = x;
    ll zzx = x;
    for (int i = 2; i < d + 1; i++) {
        zzx *= x + 1;
        zzx %= 1000000007;
        z.at(i) = zzx;
    }
    for (int i = d + 1; i < h+1; i++) {
        z.at(i) = z.at(i - 1)+z.at(i-1)*modinv(x,1000000007) - z.at(i - 1 - d)+1000000007;
        z.at(i) %= 1000000007;
        z.at(i) *= x;
        z.at(i) %= 1000000007;
    }
    cout << z.at(h)*modinv(x,1000000007)%1000000007*zx%1000000007 << endl;
}

Measured memory_bytes: 8064
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N,K,h[112345];

int main() {

	scanf("%d%d", &N,&K);
	rep(i, N) scanf("%d", &h[i]);

	int ans = 0;
	rep(i, N) if (h[i] >= K) ans++;

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

	return 0;
}


Measured memory_bytes: 640
nums=[]

for i in range(5):
    x=int(input())
    nums.append(x)

k=int(input())

for i in range(len(nums)):
    for j in range(i+1,len(nums)):
        if abs(nums[i]-nums[j])>k:
            print(":(")
            exit()

print("Yay!")


Measured memory_bytes: 2940
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let x = read1::<usize>();
    if x < 1200 {
        println!("ABC");
    } else {
        println!("ARC");
    }
}

Measured memory_bytes: 4352
#include<cstdio>
#include<stack>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int cell[100][100];
int dx[] = {1, 0,  0, -1};
int dy[] = {0, 1, -1,  0};
int n,m;
int ans;

void debug(){
	puts("--------------------------");
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			printf("%s",cell[i][j]?"o":" ");
		}puts("");
	}
}

void func(int c, int x, int y){
	if(c>ans){
		ans=c;
	}
//	debug();
	for(int i = 0; i < 4; i++){
		if(x+dx[i] >= 0 && x+dx[i] < n && y+dy[i] >= 0 && y+dy[i] < m && cell[x+dx[i]][y+dy[i]]){
			cell[x][y]=0;
			func(c+1,x+dx[i], y+dy[i]);
			cell[x][y]=1;
		}
	}
	
}


int main(void){
	while(scanf("%d%d", &m, &n),m){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				scanf("%d", &cell[i][j]);
			}
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				if(cell[i][j])func(1, i, j);
			}
		}
		
		
		printf("%d\n", ans);
		ans=0;
	}
	return 0;
	
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k=sc.nextInt();
        String s = sc.next();

        if(s.length()<=k) System.out.println(s);
        else System.out.println(s.substring(0,k)+"...");

    }
}

Measured memory_bytes: 38532
#include<bits/stdc++.h>
using namespace std;
char s[100000*2+5];
int ys[10000+5];
int n,P;
int main(){
    cin>>n>>P;
    long long sum=0;
    scanf("%s",s);
    int t=1,v=0;
    if(P==2||P==5){
        for(int i=0;i<n;i++)
            if((s[i]-'0')%P==0)
                sum+=i+1;
    }
    else{
        ys[0]=1;
        for(int i=n-1;i>=0;i--){
            v+=t*(s[i]-'0');
            v%=P;
            sum+=ys[v];
            ys[v]++;
            t*=10;
            t%=P;
        }
    }

    printf("%lld\n",sum);

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define all(i) i.begin(),i.end()
#define fix(i) fixed<<setprecision((i))
#define Max( i , j ) (i)=max((i),(j))
#define Min( i , j ) (i)=min((i),(j))
#define pii pair<int,int>
using namespace std;

const long long maxn = 1e3+100;
const long long INF = 3e18+1191;
const long long mod = 1e9+7;

int n,a[maxn];

int32_t main()
{
  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

  cin>>n;

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

  sort(a,a+n);

  bool flag = 1;

  int x = 0 , y = 0;

  for(int i = n-1;i>=0;i--)
    {
      if(flag)
	x+=a[i];
      else
	y+=a[i];
      flag = !flag;
    }
  cout<<(x-y)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

VL Y(51),P(51);

ll solve(ll N,ll X){
  if(N==0) return 1;
  if(X==1) return 0;
  if(X<=Y[N-1]+1) return solve(N-1,X-1);
  if(X==Y[N-1]+2) return P[N-1]+1;
  if(X<=Y[N]-1) return P[N-1]+1+solve(N-1,X-2-Y[N-1]);
  return P[N];
}

int main(){
  ll N,X;
  cin>>N>>X;
  Y[0]=1;
  P[0]=1;
  rep(i,50) Y[i+1]=Y[i]*2+3;
  rep(i,50) P[i+1]=P[i]*2+1;
  cout<<solve(N,X)<<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 pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int m,k;cin >> m >> k;
  if(m==1){
    string ans = "-1";
    if(k==0) ans = "0 0 1 1";
    cout << ans << endl;
    return 0;
  }
  if(k>=(1<<m)){
    cout << -1 << endl;
    return 0;
  }
  for(int i = 0; i < (1<<m); ++i){
    if(i==k) continue;
    cout << i << ' ';
  }
  cout << k << ' ';
  for(int i = (1<<m)-1; i>=0; --i){
    if(i==k) continue;
    cout << i << ' ';
  }
  cout << k << endl;
}



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

int main(){
  int n,m,c;
  cin >> n >> m >> c;
  vector<int> b(m);
  int ans = 0;
  for(int i = 0; i < m; i++){
    cin >> b[i];
  }
  for(int i = 0; i < n; i++){
    vector<int> a(m);
    int sum = 0;
    for(int i = 0; i < m; i++){
      cin >> a[i];
      sum += a[i] * b[i];
    }
    if(sum + c > 0){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int diff = a - b;

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

    ll ng = 0, ok = 1e10;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;

        ll count = 0;
        for (auto &x:h) {
            count += max(0LL, (x - (b * mid) + diff - 1) / diff);
        }

        if (count <= mid)ok = mid;
        else ng = mid;
    }

    cout << ok << endl;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    int a,b,c;
    cin >> a >> b >> c;
    if(c >= a && c <= b)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}   

Measured memory_bytes: 256
using System;

class B{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    int T = Ar[0], A = Ar[1];
    int[] place = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    double temp = 6000000000000;
    int ans = 0;
    for (int i = 0; i < N; i++){
      if (temp > Math.Abs(A - (T - (place[i] * 0.006)))){
        temp = Math.Abs(A - (T - (place[i] * 0.006)));
        ans = i + 1;
      }
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 27708
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long int> A(N);
    vector<long long int> S(N+1, 0);
    for(int n=0; n<N; n++) {
        cin >> A[n];
        S[n+1] = S[n]+A[n];
    }
    long long int sum;
    long long int sabs;
    long long int ans=1e15;
    for(int i=0; i<2; i++) {
        sum=0;
        sabs=0;
        for(int n=1; n<=N; n++) {
            if(S[n]+sum>0) {
                if(i==n%2) {
                    sabs += S[n]+sum+1;
                    sum += -1-(S[n]+sum);
                }
            } else if(S[n]+sum<0) {
                if(i!=n%2) {
                    sabs += 1-(S[n]+sum);
                    sum += 1-(S[n]+sum);
                }
            } else {
                if(i==n%2) {
                    sabs += 1;
                    sum += -1;
                } else {
                    sabs += 1;
                    sum += 1;
                }
            }
        }
        ans = min(ans, sabs);
    }
    
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin >> a >> b >> k;
  vector<int> v;
  for(int i=1;i<=100;i++){
    if(a % i == 0 && b % i == 0)
      v.push_back(i);
   	sort(v.begin(), v.end(), greater<int>() );
  }
  cout << v[k-1] << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int f1[100005], f2[100005];

int main()
{
    int n, nr, max1f1=-1, max2f1=-1, max1f2=-1, max2f2=-1;
    int index1f1, index2f1, index1f2, index2f2;
    scanf("%d", &n);

    for(int i=1; i<=n; i++)
    {
        scanf("%d", &nr);
        if(i%2==1)
            f1[nr]++;
        if(i%2==0)
            f2[nr]++;
    }

    for(int i=1; i<=100002; i++)
    {
        if(f1[i] > max1f1)
        {
            max2f1 = max1f1;
            index2f1 = index1f1;

            max1f1 = f1[i];
            index1f1 = i;
        }
        else
        {
            if(f1[i] > max2f1)
            {
                max2f1 = f1[i];
                index2f1 = i;
            }
        }
    }

    for(int i=1; i<=100002; i++)
    {
        if(f2[i] > max1f2)
        {
            max2f2 = max1f2;
            index2f2 = index1f2;

            max1f2 = f2[i];
            index1f2 = i;
        }
        else
        {
            if(f2[i] > max2f2)
            {
                max2f2 = f2[i];
                index2f2 = i;
            }
        }
    }

    if(index1f1 == index1f2)
    {
        if(max2f1 < max2f2)
        {
            //Choose 2f2 and 1f1
            printf("%d\n", n/2-max1f1 + n/2-max2f2);
        }
        else
        {
            //Choose 2f1 and 1f2
            printf("%d\n", n/2-max2f1 + n/2-max1f2);
        }
    }
    else
    {
        //Choose 1f1 and 1f2
        printf("%d\n", n/2-max1f1 + n/2-max1f2);
    }
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define ll long long
#define ii pair<string,int>ii;

string IntToStr(int tmp){
    ostringstream out;
    out << tmp;
    return out.str();
}

int main()
{
    int n;
    cin>>n;
    cout<<"ABC"<<n<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
#include<complex>

using namespace std;

typedef complex<double> P;

vector<P> pl();

char *p;

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

vector<P> plf(){
  p++;
  if(*p=='('){
    auto l=pl();
    p++;
    return l;
  }else{
    int x=strtol(p,&p,10);
    p++;
    int y=strtol(p,&p,10);
    p++;
    return {P(x,y)};
  }
}

vector<P> pl(){
  auto l=plf();
  while(*p=='@'){
    p++;
    auto r=plf();
    if(l.size()<r.size()){
      swap(l,r);
    }
    if(l.size()==1){
      l.push_back(r[0]);
    }else if(r.size()==1){
      l={l[0]+(r[0]-l[0])*polar(1.,(arg(l[1]-l[0])-arg(r[0]-l[0]))*2)};
    }else{
      l={l[0]+(l[1]-l[0])/cross(l[1]-l[0],r[1]-r[0])*cross(r[0]-l[0],r[1]-r[0])};
    }
  }
  return l;
}
    

int main(){
  for(char s[123];cin>>s,s[0]!='#';){
    p=s;
    auto r=pl()[0];
    cout<<fixed<<r.real()<<' '<<r.imag()<<endl;
  }
}

Measured memory_bytes: 1336
#include<stdio.h>
int main()
{
	int d;
	scanf("%d", &d);
	int c[30];
	int i;
	for (i = 0; i < 26; i++)
		scanf("%d", &c[i]);
	int j;
	int s[400][30];
	for (i = 0; i < d; i++)
		for (j = 0; j < 26; j++)
			scanf("%d", &s[i][j]);
	int ans;
	for (i = 0; i < d; i++)
	{
      printf("%d\n",i%26+1);
	}
	return 0;
}


Measured memory_bytes: 1784
#include <stdio.h>

int main(void){
	int i, j, k, n, a[100], tmp;
	scanf("%d",&n);
	for(i = 0;i < n;i++)
		scanf("%d",&a[i]);
	for(i = 0;i < n;i++){
		printf("%d",a[i]);
		if(i != n - 1) printf(" ");
	}
	printf("\n");
	for(i = 1;i < n;i++){
		tmp = a[i];
		for(j = i - 1;j >= 0 && a[j] > tmp;j--)
				a[j + 1] = a[j];
		a[j + 1] = tmp;
		for(j = 0;j < n;j++){
			printf("%d",a[j]);
			if(j != n - 1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1032
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep(i,a,b) for(int i=a;i<b;i++) 
#define vi vector<int>
#define pb push_back


ll solve(vi vec,int p)
{
	if(p<0) return 0; 
	vi have0,have1;
	
	rep(i,0,vec.size())
	{
		if(vec[i]&1<<p) have1.pb(vec[i]);
		else have0.pb(vec[i]);
	}
	
	if(have1.size()==0) return solve(have0,p-1);
	if(have0.size()==0) return solve(have1,p-1);
	
	return pow(2,p)+min(solve(have0,p-1),solve(have1,p-1));
}


int main()
{
    int n,k;
    cin>>n>>k;
    
    int arr[n+1]={0};
    int a=0,b=0;
    rep(i,0,k)
    {
    	int x;
    	string s;
    	
    	cin>>x>>s;
    	
    	if(s=="WA")
    	{
    		if(arr[x]!=1) arr[x]--;
		}
		else 
		{
			if(arr[x]!=1) a++,b-=arr[x],arr[x]=1;
		}
	}
	
	cout<<a<<" "<<b<<endl;
    
    return 0;
}

Measured memory_bytes: 640
/*
 * 给定一个二叉树的前序遍历和中序遍历的结果。
 * 输出该二叉树后序遍历的结点序列.
 * Preorder按照　根>左子树>右子树　顺序递归遍历　例如:{1,2,3,4,5,6,7,8,9}
 * Inorder按照 左子树>根>右子树　顺序递归遍历  例如:{3,2,5,4,6,1,8,7,9}
 * 可以生成如下的二叉树
 *                            (1)
 *                 (2)                    (7)
 *            (3)       (4)            (8)   (9)
 *                   (5)   (6)
 * 首先按Preorder遍历的顺序依次访问各结点.访问过程中,我们能通过in得知各子树内Inorder遍历的顺序,从而重建以当前结点c为根的左子树与右子树.
 * 也就是说,设Preorder遍历的当前结点为c,c在in中的位置为m,m左侧就是c的左子树,右侧就是右子树,然后同理递归.
 * 例如当前结点为1,其在in中的位置为 3 2 5 4 6 [1] 8 7 9,那么当前树的根就是1,左右子树就是 3 2 5 4 6和8 7 9.
 * 接下来在3 2 5 4 6 组成的树中,Preorder遍历的下一个结点2是根(3 [2] 5 4 6), 3 和5 4 6是两个子树.
 * 如果用in的下标l和r表示Preorder当前访问的子树的范围(不包含r),那么这个递归函数可以用如下方法实现.
 * reconstruction(l,r)
 *    if l >= r
 *       return
 *    c = next(pre) //Preorder遍历的下一个结点
 *    M = in.find(c) //在Inorder中的位置
 *
 *    reconstruction(l,m) //重建左子树
 *    reconstruction(m+1,r) //重建右子树
 *
 *    print c //以Posrorder遍历的顺序输出c
 */

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int n,pos;
vector<int> pre ,in, post;

void rec(int l,int r){
    if(l>=r) return;
    int root = pre[pos++];
    int m = distance(in.begin(),find(in.begin(),in.end(),root));
    rec(l,m);
    rec(m+1,r);
    post.push_back(root);
}

void solve(){
    pos = 0;
    rec(0,pre.size());
    for(int i=0;  i<n; i++){
        if(i) cout<<" ";
        cout<<post[i];
    }
    cout<<endl;
}


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

    for (int i=0; i<n; i++){
        cin>>k;
        pre.push_back(k);
    }


    for(int i=0; i<n; i++){
        cin>>k;
        in.push_back(k);
    }

    solve ();
    return 0;
}


Measured memory_bytes: 3168
import sys

stdout = sys.stdout
rr = lambda: input().strip()
rri = lambda: int(rr())
rrm = lambda: list(map(int, rr().split()))


n = rri()
a = rri()
b = rri()
c = rri()
d = rri()
e = rri()

tiny = min([a,b,c,d,e])
plus = n // tiny
if n % tiny == 0:
    plus -= 1
print(5 + plus)

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

						

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,b;
	cin>>a>>b;
	a=3*a+b;
	cout<<(a/2);
   
}
	
	

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int a[600000];
int b[600000];
int c[600000];
signed main(){
  int n;
  cin >> n;
  REP(i,n) cin >> a[i];
  b[0] = 0;
  FOR(i,n){
    b[i] = a[i-1] - b[i-1];
  }
  b[0] = (b[n]-b[0])/2;
  FOR(i,n){
    b[i] = a[i-1] - b[i-1];
  }
  REP(i,n-1) cout << b[i]*2 << " ";
  cout << 2*b[n-1] << endl;
  return 0;
}


Measured memory_bytes: 5376
/*  ABC146_B */
#include <stdio.h>
#include <string.h>
int main()
{
    char s[10001];
    int n;
 
    scanf("%d %s",&n,s);
 
    int len = strlen(s);
    for (int i=0; i<len; i++)
    {
        printf("%c",(s[i]-'A'+n)%26 + 'A');
    }
    
}


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

int N;
int h[110];

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> h[i];
    }

    int cnt = 0;

    while (true)
    {
        int i = 0;

        while (i < N && h[i] == 0)
        {
            if (i == N - 1 && h[i] == 0)
            {
                cout << cnt << endl;
                return 0;
            }
            i++;
        }

        while (i < N && h[i] > 0)
        {
            h[i]--;
            i++;
        }
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

void BubbleSort(int N,vector<string> &v){
  int len = (int)v.size();

  for(int i = 0 ; i < len-1 ; i++){
    for(int j = N-1 ; j > i ; j--){
      if(v[j][1] < v[j-1][1]) swap(v[j],v[j-1]);
    }
  }  

  for(int i = 0 ; i < len ; i++){
    if(i == len-1) cout << v[i] << endl;
    else cout << v[i] << " ";
  }
  cout << "Stable" << endl;
}

void SelectionSort(int N,vector<string> v,vector<string> B){
  int len = (int)v.size();

  for(int i = 0 ; i < len ; i++){
    int mini = i;
    for(int j = i ; j < len ; j++){
      if(v[j][1] < v[mini][1]) mini = j;
    }
    swap(v[i],v[mini]);
  }

  for(int i = 0 ; i < len ; i++){
    if(i == len-1) cout << v[i] << endl;
    else cout << v[i] << " ";
  }
  if(v == B) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
}

int main(){
  int n;

  cin >> n;
  vector<string> A(n),B(n),S(n);

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

  B = A;
  BubbleSort(n,B);

  S = A;
  SelectionSort(n,S,B);

  return 0;
}

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

int N,Ans=1<<30;
char A[2005],B[2005];
int L[2005],R[2005],Mx[2005];

void Solve(){
	int i,j,mx,cnt;
	for(i=0;i<N;i++){
		for(R[i]=0;B[(i+R[i])%N]=='0';R[i]++);
		for(L[i]=0;B[(i-L[i]+N)%N]=='0';L[i]++);
	}
	for(i=0;i<N;i++){
		memset(Mx,0,sizeof(Mx));
		for(cnt=j=0;j<N;j++)
			if(A[j]!=B[(j+i)%N])
				Mx[L[j]]=max(Mx[L[j]],R[j]),cnt++;
		for(j=N-1,mx=0;~j;j--){
			Ans=min(Ans,2*j+mx+abs(mx-i)+cnt);
			mx=max(mx,Mx[j]);
		}
	}
}

int main(){
	int i,cnta=0,cntb=0;
	scanf("%s%s",A,B);
	N=strlen(A);
	for(i=0;i<N;i++){
		cnta+=(A[i]=='1');
		cntb+=(B[i]=='1');
	}
	if(!cntb){
		printf("%d\n",-(cnta>0));
		return 0;
	}
	Solve();
	reverse(A,A+N);
	reverse(B,B+N);
	Solve();
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 384
a,b,c,x,y = [int(i) for i in input().split()]
chk = []
if x>y:
  chk.append(a*(x-y)+c*y*2)
  chk.append(c*x*2)
else:
  chk.append(b*(-x+y)+c*x*2)
  chk.append(c*y*2)
chk.append(a*x+b*y)
chk.append(a*x+c*y*2)
chk.append(c*x*2+b*y)
print(min(chk))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(void){
    double r;
    cin>>r;
    
    double pi =acos(-1);
    cout<<fixed<<setprecision(6);
    double area = r * r * pi;
    double cir =(r+r) * pi;
    cout<<area<<" "<<cir<<endl;
}



Measured memory_bytes: 3272
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, x; cin >> n >> x;
    vll a(n);
    for (ll i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    for (ll i = 1; i < n; i++) {
        ll tmpa = a[i] + a[i - 1];
        ll eat = tmpa - x;
        if (eat < 0) continue;
        ans += eat;
        a[i] -= min(a[i], eat);
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int> a(n + 1);
	vector<int> b(n + 1);
	set<int> b2;

	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = n; i > 0; i--) {
		int s = 0;
		for (int j = i * 2; j <= n; j += i) {
			s += b[j];
		}
		s += a[i];
		b[i] = s % 2;
		if (b[i] == 1) b2.insert(i);
	}
	
	cout << b2.size() << endl;;
	for (int i : b2) {
		cout << i << endl;
	}

	return 0;
}


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

using namespace std;

int main()
{
    string s,t,u;
    long a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    
    if(u==s)
    {
        cout<<a-1<<" ";
        cout<<b;
    }
    else
    {
        cout<<a<<" ";
        cout<<b-1;
    }

    return 0;
}


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

#define all(x) begin(x), end(x)
#define cina(s, n, a) for(int quer = s; quer < n; quer++) cin >> a[quer]
#define mod(a, b) (abs(b) + (a % abs(b))) % abs(b)
#define setp(x) fixed << setprecision(x)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const int N = 100500; // are you sure?

void solve(){
    int a, b, x;
    cin >> a >> b >> x;
    cout << ((x >= a) && (x <= a + b) ? "YES" : "NO");
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}


Measured memory_bytes: 256