akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, m;
    map<string, ll> red, blue;
    cin >> n;
    rep(i, n){string s; cin >> s; blue[s]++;}
    cin >> m;
    rep(i, m){string s; cin >> s;  red[s]++;}
    ll ans = 0;
    for(auto x : blue){
        ans = max(ans, x.second-red[x.first]);
    }
    cout << ans << endl;
}   

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

const int N_MAX = pow(10,5);
ll fac[N_MAX+1] ={};

ll c_fac(int n) {
  if (fac[n]!=0) return fac[n];
  if (n==0) return fac[n]=1;
  return fac[n] = (c_fac(n-1)*n)%MOD;
}

int main() {
  int N; cin >> N;
  string S; cin >> S;
  ll result = 1, plus = 0;
  rep(i,2*N) {
    char now = (i%2==0) ? 'B' : 'W';
    if (S[i]==now) plus++;
    else { result *= plus; result %=MOD; plus--; }
    if (plus<0) break;
  }
  if (plus!=0) result = 0;
  else { result *= c_fac(N); result %= MOD; }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 2948
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N; cin >> N;
  map<int, int> a;
  int A;
  ll tot = 0;
  rep(i,N) {
    cin >> A;
    a[A]++;
    tot += A;
  }
  int Q; cin >> Q;
  rep(i,Q){
    int B, C;
    cin >> B >> C;
    a[C] += a[B];
    tot += (C-B)*a[B];
    cout << tot << endl;
    a.erase(B);
  }
  

  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 6484
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    ll n; cin >> n;
    map<ll,ll> mp;
    mp[0] = 1;
    ll ruiseki = 0;
    rep(i,n){
        ll a; cin >> a;
        ruiseki += a;
        if(mp.count(ruiseki)){
            mp.at(ruiseki)++;
        }else{
            mp[ruiseki] = 1;
        }
    }
    ll ans = 0;
    for(auto i:mp){
        ans += (i.second)*(i.second - 1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define CS
long long int ll;
using namespace std;
int main(){
    speed;
    long long int n;
    cin>>n;
    vector<string>v;
    for(long long int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    long long int sum=0,cnt=1;
    for(long long int i=1;i<n;i++)
    {
        if(v[i]==v[i-1])
            cnt++;
        else
        {
            sum+=((cnt-1)*cnt)/2;
            cnt=1;
        }
    }
    sum+=((cnt-1)*cnt)/2;
    cout<<sum<<endl;
}







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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1005;
int n,m,a[maxn][maxn];
vector<pair<pair<int,int>,pair<int,int>>> moves;

void mv(int i, int j) {
  int i2=i,j2=j;
  if (i%2==0) {
    if (j==m-1) {
      i2++;
    } else {
      j2++;
    }
  } else {
    if (j==0) {
      i2++;
    } else {
      j2--;
    }
  }

  if (i2>=0 && i2<n && j2>=0 && j2<m) {
    moves.push_back({ {i+1,j+1}, {i2+1,j2+1} });
    a[i2][j2]++;
  }
}

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

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

  for (int i=0; i<n; i++) {
    if (i%2==0) {
      for (int j=0; j<m; j++) {
	if (a[i][j]%2) {
	  mv(i,j);
	}
      }
    } else {
      for (int j=m-1; j>=0; j--) {
	if (a[i][j]%2) {
	  mv(i,j);
	}
      }
    }
  }

  cout<<moves.size()<<endl;
  for (auto p: moves) {
    cout<<p.first.first<<" "<<p.first.second<<" "<<p.second.first<<" "<<p.second.second<<endl;
  }
  

  return 0;
}


Measured memory_bytes: 6128
#include<iostream>
#include<cstdio>
int inSort(int A[],int n,int g){
  int i,j,v;
  int cnt=0;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j-=g;
      ++cnt;
    }
    A[j+g]=v;
  }
  return cnt;
}
void shSort(int A[],int n){
  int i,j,k,l,G[20];

  int m=0; for(i=1;i<=n;i=i*3+1) G[m++]=i;

  int c=0; for(i=m-1;0<=i;i--) c+=inSort(A,n,G[i]);

  printf("%d\n%d",m,G[m-1]);
  for(i=m-2;0<=i;i--) printf(" %d",G[i]);
  printf("\n%d\n",c);
  for(i=0;i<n;i++) printf("%d\n",A[i]);
}
int main(){
  int i,n,A[1000000];
  std::cin>>n;
  for(i=0;i<n;i++) std::cin>>A[i];
  shSort(A,n);
  return 0;
}

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

int main(){
    int k,n;
    cin >> k >> n;
    vector<int> cum(2*n);
    rep(i,n){
        int a;
        cin >> a;
        cum[i] = a;
        cum[n+i] = k+a;
    }
    n;
    int res = 1001001001;
    rep(i,n){
        res=min(res,cum[i+n-1]-cum[i]);
    }
    cout << res << endl;
}


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

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a;
    string ans = "IMPOSSIBLE\n";
    for(int i = 0;i < m;i++){
        int x,y;
        cin >> x >> y;
        if(x == 1)a.push_back(y);
        if(y == n)a.push_back(x);
    }
    sort(a.begin(), a.end());
    for(int i = 1;;i++){
        if(!a[i])break;
        if(a[i-1] == a[i]){
            ans = "POSSIBLE\n";
            break;
        }
    }
    cout << ans ;
    return 0;
}



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



int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  if(K<=A) cout<<K<<endl;
  else if(K<=A+B) cout<<A<<endl;
  else cout<<(2*A)+B-K<<endl;
  
}
  

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)(1e18)

template<typename M>
struct segment_tree{
	typedef function<M(M, M)> F;
	int size;
	vector<M> val;
	F f;
	M e;

	segment_tree(int N, vector<M> &data, F f, M e) : f(f), e(e){
		size = 1;
		while(size < N) size *= 2;
		val.assign(2 * size, e);
		for(int i = 0; i < N; i++) val[size + i] = data[i];
		for(int i = 0; i < size; i++) val[size + i] = e;
		for(int i = size - 1; i > 0; i--) val[i] = f(val[2 * i], val[2 * i + 1]);
	}

	void update(int k, M x){
		k += size;
		val[k] = x;
		while(k /= 2) val[k] = f(val[2 * k], val[2 * k + 1]);
	}

	M query(int l, int r){
		M L = e, R = e;
		for(l += size, r += size; l < r; l /= 2, r /= 2){
			if(l & 1) L = f(L, val[l++]);
			if(r & 1) R = f(val[--r], R);
		}
		return f(L, R);
	}
};

int mini(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int N, L, i, j;
	scanf("%lld%lld", &N, &L);
	vector<int> l(N), r(N);
	vector<int> event(0);
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &l[i], &r[i]);
		event.push_back(l[i]);
		event.push_back(r[i]);
	}
	sort(event.begin(), event.end());
/*	for(i = 1, j = 1; j < 2 * N; j++){
		if(event[j] != event[j - 1]){
			event[i] = event[j];
			i++;
		}
	}
	event.erase(event.begin() + i, event.end());
*/	L = 0;
	for(i = 0; i < N; i++){
		l[i] = lower_bound(event.begin(), event.end(), l[i]) - event.begin();
		r[i] = lower_bound(event.begin(), event.end(), r[i]) - event.begin();
		L = max(L, r[i]);
	}
/*	printf("L = %lld\n", L);
	for(i = 0; i < N; i++){
		printf("(%lld, %lld)\n", l[i], r[i]);
	}
*/	vector<vector<int>> corl(L + 1, vector<int>(0));
	for(i = 0; i < N; i++){
		corl[r[i]].push_back(l[i]);
	}
	vector<int> data(L + 1, inf);
//	data[0] = 0;
	segment_tree<int> dp(L + 1, data, mini, inf);
	dp.update(0, 0);
//	printf("dp[0] = %lld\n", dp.query(0, 1));
	for(i = 1; i <= L; i++){
//		printf("i = %lld\n", i);
		int now = inf;
		for(j = 0; j < corl[i].size(); j++){
//			printf("corl[i][%lld]\n", corl[i][j]);
			now = min(now, dp.query(corl[i][j], i) + 1);
		}
//		printf("test3\n");
		dp.update(i, now);
//		printf("%lld\n", dp.query(i, i + 1));
	}
//	printf("test5\n");
	printf("%lld ", dp.query(L, L + 1));

	vector<int> A(L + 1, 0);
	for(i = 0; i < N; i++){
		A[l[i]]++;
		A[r[i]]--;
	}
	int minA = A[0];
	for(i = 1; i < L; i++){
		A[i] += A[i - 1];
		minA = min(minA, A[i]);
	}
/*	for(i = 0; i <= L; i++){
		printf("A[%lld] = %lld\n", i, A[i]);
	}
*/	printf("%lld\n", N - minA + 1);
	return 0;
}


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

using namespace std;

int main(){
    vector<int> x(2);
    for(int i = 0; i < 2; i++){
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    cout << x[1] - x[0] << endl;
    return 0;
}


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

bool is_match(int num, int lower, int upper){
	int sum = 0;

	while(num > 0){
		sum += num % 10;
		num /= 10;
	}

	if(sum >= lower && sum <= upper){
		return 1;
	}
	else
		return 0;
}

int main() {
	int N, upper, lower, ans;

	cin >> N >> lower >> upper;
	ans = 0;

	for(int num = 1; num <= N; num++){
		if(is_match(num, lower, upper)){
			//ans += 1;
			ans += num;
		}
	}

 	 cout << ans << endl;
}


Measured memory_bytes: 256
H,W,N=map(int, input().split())
D={}
for i in range(N):
  a,b=map(int, input().split())
  a-=1
  b-=1
  for j in range(3):
    for k in range(3):
      x,y=a-j,b-k
      if 0<=x and x+2<H and 0<=y and y+2<W:
        d=(x,y)
        if d not in D:
          D[d]=1
        else:
          D[d]+=1
A=[0]*10
for i in D.values():
  A[i]+=1
A[0]=(W-2)*(H-2)-sum(A)
for i in A:
  print(i)

Measured memory_bytes: 186940
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 163577857
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;if(m<0) return 0;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a;
    if(a==0)
        return b; 
    return gcd(b, a % b);  
      
}
#define MAXN 2005
int main()
{
    fastio();
  
    ll n,c=0,k=100;
    cin>>n;
    while(k<n)
    {
        k = k + k/100;
        c++;
    }
    cout<<c<<endl;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 2e3 + 9, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int n;

pii a[N];

ll dp[N][N];

ll solve(int i, int l){
    if(i == n)  return 0;

    ll &ret = dp[i][l];
    if(~ret)    return ret;

    ret = (ll)a[i].F * abs(a[i].S - l) + solve(i + 1, l + 1);
    ret = max(ret, (ll)a[i].F * abs(a[i].S - (n - 1 - (i - l))) + solve(i + 1, l));

    return ret;
}

int main(){
    init();

    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a[i].F;
        a[i].S = i;
    }
    sort(a, a + n); reverse(a, a + n);

    memset(dp, -1, sizeof dp);

    cout << solve(0, 0);
}

Measured memory_bytes: 35372
#include <iostream>

using namespace std;
const int maxn = 200;
char s[maxn][maxn];
int main()
{
    int h,w,k;
    cin>>h>>w>>k;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin>>s[i][j];
        }
    }
    //h表示有多少个二进制位
    int e = 1<<h+w;
    int ans = 0;
    //枚举要选中的行和列
    for(int i=0;i<e;i++)
    {
        char s2[maxn][maxn];
        for(int r=1;r<=h;r++ )
        {
            for(int c=1;c<=w;c++)
            {
                s2[r][c] = s[r][c];
            }
        }
        int x = i;
        int b[maxn];
        int h2 = h+w;
        while(x)
        {
            b[h2--] = x&1;
            x>>=1;
        }
        for(int r=1;r<=h;r++ )
        {
            if(b[r])
            {
                 for(int c=1;c<=w;c++)
             {
                 s2[r][c] = '.';
             }
            }
        }
         for(int r=h+1;r<=h+w;r++ )
        {
            if(b[r])
            {
                 for(int c=1;c<=h;c++)
             {
                 s2[c][r-h] = '.';
             }
            }
        }
        int cnt = 0;
        for(int r=1;r<=h;r++ )
        {
            for(int c=1;c<=w;c++)
            {
                if(s2[r][c]=='#') cnt++;
            }
        }
        if(cnt==k) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3640
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a=sorted(a)
f=sorted(f,reverse=True)


def is_lessthanK(X):
  ans=0
  for A,F in zip(a,f):
    if A*F>X:
      ans+=A-X//F
    if ans > k:
      return False
  return True


ng=-1
ok=a[-1]*f[0]
while ok-ng>1:
  mid=(ok+ng)//2
  if is_lessthanK(mid):
    ok=mid
  else:
    ng=mid
print(ok)



Measured memory_bytes: 40524
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s=="Sunny"){
        cout <<"Cloudy";}
    else if (s=="Cloudy"){
        cout << "Rainy";}
    else if (s=="Rainy"){
        cout <<"Sunny";}
        return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題

int main(){
int n,a,b;
cin>>n>>a>>b;
string s;
cin>>s;
int join=0,os=0;
rep(i,n){
    if(s[i]=='a'){
        if(join<a+b){
            cout<<"Yes"<<endl;
            join++;
        }else{
            cout<<"No"<<endl;
        }
    }else if(s[i]=='b'){
        if(join<a+b&&os<b){
            cout<<"Yes"<<endl;
            join++;
            os++;
        }else{
            cout<<"No"<<endl;
        }
    }else{
        cout<<"No"<<endl;
    }



}

  return 0;
}


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

int main()
{
    int N, M, Q, L, R, p, q;
    cin >> N >> M >> Q;

    vector<vector<int>> ac(N + 1, vector<int> (N + 1, 0));
    for(int i = 0; i < M; i++) scanf("%d%d", &L, &R), ac[L][R]++;

    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            ac[i][j] += ac[i - 1][j];
            ac[i][j] += ac[i][j - 1];
            ac[i][j] -= ac[i - 1][j - 1];
        }
    }

    for(int i = 0; i < Q; i++){
        scanf("%d%d", &p, &q);
        printf("%d\n", ac[q][q] - ac[p - 1][q] - ac[q][p - 1] + ac[p - 1][p - 1]);
    }

    return 0;
}


Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;} 
int main(void)
{
  int n,a[200000]={0},b[200000]={0};
  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  for(int i=0;i<n;i++)
    b[a[i]-1]++;
  for(int i=0;i<n;i++)
    printf("%d\n",b[i]);
  
}


Measured memory_bytes: 3296
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)

for i in A:
    D[i] += 1
S = 0
for i in range(1,N+1):
    tmp = D[i]
    S += tmp*(tmp-1)//2

for i in A:
    tmp = D[i]
    print(S-tmp*(tmp-1)//2+(tmp-1)*(tmp-2)//2)

Measured memory_bytes: 100812
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n,m;cin>>n>>m;
    ll k[n];
    ll a[n][m];
    ll b[m+1];
    for(ll i=1;i<=m;i++){
        b[i]=0;
    }
    for(ll i=0;i<n;i++){
        cin>>k[i];
        for(ll j=0;j<k[i];j++){
            cin>>a[i][j];
            b[a[i][j]]++;
        }
    }
    ll ans=0;
    for(ll i=1;i<=m;i++){
        if(b[i]==n){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <math.h>
using namespace std;


int main(){
	int n, max, p = 2;
	scanf("%d", &n);
	max = (int)sqrt(n) + 1;
	printf("%d:", n);
	while(p <= max) {
		if (n % p == 0) {
			n /= p;
			printf(" %d", p);
			continue;
		}
		p++;
	}
	if (n > 1) {
		printf(" %d", n);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 2740
using System;
using System.Linq;

namespace Aizu {
    class OnlineJudge {
        static void Main() {
            var output = new System.Text.StringBuilder();
            for (int[] i; (i = Array.ConvertAll(Console.ReadLine().Split(), int.Parse))[0] != 0;) {
                var wrong = new int[i[0], i[1]];
                var correct = new int[i[0]];
                var penalty = new int[i[0]];
                for (int j = i[2]; j > 0; --j) {
                    var input = Console.ReadLine().Split();
                    var data = input.Take(3).Select(int.Parse).ToArray();
                    --data[0]; --data[1];
                    if (input[3] == "CORRECT") {
                        penalty[data[0]] += wrong[data[0], data[1]] * 1200 + data[2];
                        ++correct[data[0]];
                    }
                    else {
                        ++wrong[data[0], data[1]];
                    }
                }
                foreach (var team in Enumerable.Range(0, i[0]).Select(p => new { t = p + 1, c = correct[p], p = penalty[p] }).OrderByDescending(p => p.c).ThenBy(p => p.p).ThenBy(p => p.t)) {
                    output.AppendLine(string.Format("{0} {1} {2}", team.t, team.c, team.p));
                }
            }
            Console.Write(output.ToString());
        }
    }
}

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

int main(){
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	printf("%lf\n", sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)));

	return 0;

}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, s, n) for(int i = s; i < n; i++)
#define rRep(i, n) for(int i = n - 1; i >= 0; i--)

int32_t main() {
	FAST
	int a, b;
	cin >> a >> b;

	bool can = true;
	if(a > 9 || b > 9)
		can = false;
	if(can)
		cout << a*b << endl;
	else 
		cout << -1 << endl;
}


Measured memory_bytes: 256
#EducationalDP-1
n = int(input())
h_list = list(map(int,input().split()))
inf  = float("inf")
dp = [inf for i in range(n + 3)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(h_list[1] - h_list[0])
for i in range(3,n + 1):
  dp[i] = min(dp[i -2] + abs(h_list[i-1] - h_list[i - 3]), dp[i - 1] + abs(h_list[i-1] - h_list[i - 2]))
print(dp[n])

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

# 解説PDFの通りに実装
#
# 途中まで全探索、途中までは2桁の場合のみ考えればよい
# ことに自力では気付けなかった

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys


def get_sum(base, n):
    nums = []
    while n > 0:
        nums.append(n % base)
        n //= base
    return sum(nums)


def solve(N, S):
    if S == N:
        return S + 1
    for base in range(2, int(math.sqrt(N)) + 2):
        if S == get_sum(base, N):
            return base
    for p in range(int(math.sqrt(N)) + 1, 0, -1):
        q = S - p
        if (N - q) % p == 0:
            base = (N - q) // p
            if base <= 1 or q < 0 or q >= base:
                continue
            return base
    return -1


N = int(input())
S = int(input())
print(solve(N, S))


Measured memory_bytes: 5684
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		ArrayList<Integer> height = new ArrayList<Integer>();
		Scanner sc = new java.util.Scanner(System.in);
		for (int i = 0; i < 10; i++) {
			height.add(sc.nextInt());
		}

		Collections.sort(height);

		for (int i = 9; i > 6; i--) {
			System.out.println(height.get(i));
		}

	}

}

Measured memory_bytes: 26348
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {

		Scanner n = new Scanner(System.in);

		String S = n.next();
		String T = n.next();

		String[] S_list = S.split("");
		String[] T_list = T.split("");


		int count = 0;
		for(int i=0;i<S.length();i++) {
			if(S_list[i].equals(T_list[i])) {

			}else {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 67684
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <unordered_map>
#include <queue>
#include <map>
#include <sstream>
#include <set>
#include <cstdlib>
#include <ctime>
#include <unordered_set>
#include <bitset>
#include <chrono>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
//#pragma GCC optimize(3, "Ofast", "inline")
#define MAX_INF 0x3f3f3f3f
template <class T, class C>
void print(C name, T a)
{
	cout << name << ": " << a << endl;
}
template <class T>
T gcd(T a, T b)
{
	return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b, ll p)
{
	ll ans = 1;
	a %= p;
	while (b)
	{
		if (b & 1)
			ans = ans * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return ans;
}
template <typename _Tp>
void read(_Tp &x)
{
	char ch;
	bool flag = 0;
	x = 0;
	while (ch = getchar(), !isdigit(ch))
		if (ch == '-')
			flag = 1;
	while (isdigit(ch))
		x = x * 10 + ch - '0', ch = getchar();
	if (flag)
		x = -x;
}
template <class T>
void print(T x)
{
	if (x < 0)
	{
		x = -x;
		putchar('-');
	}
	if (x > 9)
		print(x / 10);
	putchar(x % 10 + '0');
}
const ll mod = 998244353;
const ll inf = 1e18;
ll add(ll x, ll t)
{
	x %= mod;
	t %= mod;
	return (x + t) % mod;
}
ll del(ll ans, ll x)
{
	ans %= mod;
	ans += mod;
	x %= mod;
	return (ans - x) % mod;
}
ll mul(ll ans, ll x)
{
	ans %= mod;
	x %= mod;
	return (ans * x) % mod;
}
#define fir(i, a, b) for (int i = a; i <= b; i++)
const int maxn = 1e4 + 20, N = 2010, M = 3000 + 10;
int p[maxn];
ll c[maxn];
vector<vector<ll>> sum;
bool flag[maxn];
int main()
{
	int n, k;
	cin >> n >> k;
	fir(i, 1, n)
		scanf("%d", &p[i]);
	fir(i, 1, n)
		scanf("%lld", &c[i]);
	memset(flag, true, sizeof(flag));
	for (int i = 1; i <= n; i++)
	{
		if (flag[i])
		{
			vector<ll> val;
			val.push_back(0);
			int t = i;
			vector<int> id;
			while (flag[t])
			{
				val.push_back(val.back() + c[t]);
				flag[t] = false;
				id.push_back(t);
				t = p[t];
			}
			for (auto it : id)
				flag[it] = true;
			sum.push_back(val);
		}
	}
	ll ans = -1e18;
	for (int i = 0; i < sum.size(); i++)
	{
		int size = sum[i].size() - 1;
		ll temp = 0;
		if (k <= size||sum[i].back()<0)
		{
			for(int j=1;j<=min(size,k);j++)
			ans=max(ans,sum[i][j]);
		}
		else
		{
				temp+=(k/size-1)*sum[i].back();
				for(int j=0;j<=size;j++)
				ans=max(ans,temp+sum[i][j]);

				temp=0;
				temp+=(k/size)*sum[i].back();
				for(int j=0;j<=min(size,k%size);j++)
				ans=max(ans,temp+sum[i][j]);
		}
	}
	cout << ans << endl;
}

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

int point[150];
int number[51];

int main(void) {
	
	int i, j;
	int city;
	int road;
	int flag;

	scanf("%d%d", &city, &road);

	for (i = 0; i < 2 * road; i++) {
		scanf("%d", &point[i]);
	}



	for (i = 0; i <= 50; i++) {
		number[i] = 0;
	}

	for (i = 0; i < 2 * road; i++) {
		for (j = 1; j <= city; j++) {
			flag = point[i] - j;
			if (flag == 0) {
				number[j - 1] = number[j - 1] + 1;
				break;
			}
		}
	}

	for (i = 0; i <= city - 1; i++) {
		printf("%d\n", number[i]);
	}
	
	return 0;

}

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

#define VARIETY 10

int main(void){
  int i, j, n, input;
  int *ice;

  // テ」ツつ「テ」ツつ、テ」ツつケテゥツ?催・ツ按療」ツつ津ァツ「ツコテ、ツソツ敕」ツ?凖」ツつ?
  ice = (int *)malloc(sizeof(int) * VARIETY);
  
  // テ」ツつ「テ」ツつ、テ」ツつケテ」ツ?ョテァツキツ湘ヲツ閉ーテ」ツつ津・ツ?・テ・ツ環?
  scanf("%d", &n);
  while(n != 0){
    // テ」ツつ「テ」ツつ、テ」ツつケテゥツ?催・ツ按療」ツ?ョテ・ツ按敕ヲツ慊淌・ツ個?
    for(i = 0; i < VARIETY; i++){
      ice[i] = 0;
    }

    // ティツゥツウテァツエツーテ・ツ?・テ・ツ環?
    for(i = 0; i < n; i++){
      scanf("%d", &input);
      ice[input]++;
    }

    // テ・ツ」ツイテ、ツクツ甘ァツ・ツィテ」ツつ津・ツ?コテ・ツ環?
    for(i = 0; i < VARIETY; i++){
      if(ice[i] == 0){ printf("-"); }
	for(j = 0; j < ice[i]; j++){
	  printf("*");
	}
	printf("\n");
    }

    // テヲツャツ。テ」ツ?ョテ」ツつ「テ」ツつ、テ」ツつケテ」ツ?ョテァツキツ湘ヲツ閉ーテ」ツつ津・ツ?・テ・ツ環?
    scanf("%d", &n);
  }

  // テゥツ?佚・ツ淞淌ィツァツ」テヲツ板セ
  free(ice);

  return 0;
}

Measured memory_bytes: 572
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String S = in.readLine();
		char c = S.charAt(S.length() - 1);
		switch (c) {
		case '3':
			System.out.println("bon");
			break;
		case '0':
		case '1':
		case '6':
		case '8':
			System.out.println("pon");
			break;
		default:
			System.out.println("hon");

		}

	}

	void calc() {
	}

	void showResult() {
	}

}


Measured memory_bytes: 32468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  int vec[200010];
  for(int i = 0; i < N; i++){
   cin >> vec[i]; 
  }
  bool ans = 1;
std::sort(vec, vec+N);
  for(int i = 0; i < N-1; i++){
    int check = 0;
    if(vec[i] == vec[i+1]) check++;
    if(check != 0) ans = 0;
  }
  if(ans == 1) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
}


Measured memory_bytes: 1024
#include <iostream>
//#include <cstring>
//#include <cctype>
//#include <ctime>
using namespace std;


int main(){
    int total;
    char str[1001];
    while (1) {
        scanf("%s",str);
        if (str[0] == '0' && !str[1]) break;
        total = 0;
        for(int i = 0;str[i]; i++){
            total += str[i] - '0';
        }
        cout << total << "\n";

    }
    return 0;
}

Measured memory_bytes: 1144
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
string to_string_keta(const long long int l, const int keta) {
	ostringstream oss;

	oss << std::setw(keta) << std::setfill('0') << l;

	return oss.str();
}

int main() {
	int num = 0;
	int N;

	while (cin >> N) {
		if (num) {
			cout << "Case " << num << ":" << endl;
			for (int i = 0; i < 10; ++i) {
				N *= N;
				string st = to_string_keta(N, 8);
				N = stoi(st.substr(2, 4));
				cout << N << endl;
			}
		}
		num++;
	}
	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

map<int, int> mp;

void prime_factor(int n){
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            ++mp[i];
            n/=i;
        }
    }
    if(n!=1) mp[n]++;//
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 1, n + 1){
        prime_factor(i);
    }
    int ans = 1;
    for(auto it = mp.begin(); it != mp.end(); it++){
        (ans *= it -> second + 1) %= mod;
    }
    cout << ans << endl;
}

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

int digit_num(int num){
  int ret = 1;
  int base = 10;
  int rest = num / base;
  
  while(rest != 0){
    ret++;
    rest /= base;
  }
  
  return ret;
}

int main(){
  vector<int> ans;
  int a, b;
  
  while(cin >> a && cin >> b) ans.push_back(digit_num(a + b));
  
  for(int i = 0; i < (int)ans.size(); i++) cout << ans[i] << endl;
  
  return 0;
}

Measured memory_bytes: 3000
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
 
/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */
 
/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
signed main() {
  deque<char> deq;
  string s;cin >> s;
  rep(i, s.size()) {
    deq.push_back(s[i]);
  }
  int count = 0;
  int q;cin >> q;
  rep(i, q) {
    int a;cin >> a;
    if(a==1) count++;
    else {
      int k;char c;cin >> k >> c;
      if((count+k)&1) {
        deq.push_front(c);
      }
      else {
        deq.push_back(c);
      }
    }
  }
  s="";
  for(auto c:deq) s+=c;
  if(count&1)reverse(all(s));
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 4316
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let a=nin()
  out(3*a*a)
}
main()

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

int main(){
  
  int arr[3][3];
  rep(i, 3){
    rep(j, 3){
      cin >> arr[i][j];
    }
  }

  int a1 = 0;
  int b1 = arr[0][0];
  int b2 = arr[0][1];
  int b3 = arr[0][2];
  int a2 = arr[1][0] - b1;
  int a3 = arr[2][0] - b1;

  if(a2 + b2 == arr[1][1] && a2 + b3 == arr[1][2] && a3 + b2 == arr[2][1] && a3 + b3 == arr[2][2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;  

}

Measured memory_bytes: 256
dish=[]
d1=[]
dif=[]
for i in range(5):
    dish.append(int(input()))
for j in range(5):
    d1.append((-(-dish[j]//10))*10)
for k in range(5):
    dif.append(d1[k]-dish[k])
    
print(sum(d1)-max(dif))


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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


ll gcd(ll x, ll y) {
    if (x > y) swap(x, y);
    ll m = 1;
    while (m != 0) {
        m = y % x;
        y = x;
        x = m;
    }
    return y;
}

struct Drag {
    int a, b, c;
};


std::istream &operator>>(std::istream &in, Drag &o) {
    cin >> o.a >> o.b >> o.c;
    return in;
}

map<P, int> pairing(vector<Drag> &v) {
    int n = v.size();

    map<P, int> m;

    rep(i, 1 << n) {
        vector<Drag> uses;
        rep(j, n) if ((i >> j) & 1) uses.push_back(v[j]);

        Drag d = {0, 0, 0};
        for (Drag u : uses) d.a += u.a, d.b += u.b, d.c += u.c;

        P p(d.a, d.b);
        if (m.find(p) == m.end()) m[p] = d.c;
        else
            cmin(m[p], d.c);

    }
    return m;
}

int main() {
    int n, m1, m2;
    cin >> n >> m1 >> m2;

    vector<P> rates;
    rep(i, 100) if (i > 0) {
            rates.push_back(P(m1 * i, m2 * i));
        }

    vector<Drag> drags(n);
    rep(i, n) cin >> drags[i];

    vector<Drag> drags1, drags2;
    rep(i, n) (i % 2 ? drags1 : drags2).push_back(drags[i]);

    auto p1 = pairing(drags1);
    auto p2 = pairing(drags2);

    ll ans = INF;

    for (auto &e : p1) {

        P p = e.first;

        int a1 = p.first;
        int b1 = p.second;
        int c1 = e.second;

        for (P rate : rates) {
            int ta = rate.first - a1;
            int tb = rate.second - b1;

            if (p2.find(P(ta, tb)) == p2.end()) continue;
            cmin(ans, (ll) c1 + p2[P(ta, tb)]);

        }

    }

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


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

using namespace std;

class Node {
public:
	int id;
	Node *pLeft;
	Node *pRight;

	Node() {
		id = -1;
		pLeft = pRight = NULL;
	}
};

Node* NodeExist[25];

Node* addNode(Node *p, int id) {
	if (id == -1) {
		return NULL;
	}

	p = NodeExist[id];
	if (p == NULL) {
		p = new Node();
		NodeExist[id] = p;
		p->id = id;
	}
	
	return p;
}

void solve(int id, int left, int right) {
	Node* p = NULL;

	if (NodeExist[id] == NULL) {
		p = addNode(p, id);
	}
	else {
		p = NodeExist[id];
	}

	p->pLeft = addNode(p->pLeft, left);
	p->pRight = addNode(p->pRight, right);
}

void showTreeByPreorder(Node *p) {

	cout << " " << p->id;
	if (p->pLeft != NULL) {
		showTreeByPreorder(p->pLeft);
	}
	if (p->pRight != NULL) {
		showTreeByPreorder(p->pRight);
	}
}

void showTreeByInorder(Node *p) {

	if (p->pLeft != NULL) {
		showTreeByInorder(p->pLeft);
	}
	cout << " " << p->id;
	if (p->pRight != NULL) {
		showTreeByInorder(p->pRight);
	}
}

void showTreeByPostorder(Node *p) {

	if (p->pLeft != NULL) {
		showTreeByPostorder(p->pLeft);
	}
	if (p->pRight != NULL) {
		showTreeByPostorder(p->pRight);
	}
	cout << " " << p->id;
}

void freeNode(Node *p) {
	if (p == NULL) {
		return;
	}
	if (p->pLeft != NULL) {
		freeNode(p->pLeft);
	}
	if (p->pRight != NULL) {
		freeNode(p->pRight);
	}

	delete p;
	p = NULL;
}

int RootId[25];

int main() {
	int n, id, left, right, rootId;

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

	for (int i = 0; i < n; ++i) {
		cin >> id >> left >> right;
		if (RootId[id] == id) {
			RootId[id] = id;
		}
		if (left != -1) {
			RootId[left] = id;
		}
		if (right != -1) {
			RootId[right] = id;
		}

		solve(id, left, right);
	}
	
	for (int i = 0; i < n; ++i) {
		if (RootId[i] == i) {
			rootId = i;
			break;
		}
	}

	cout << "Preorder" << endl;
	showTreeByPreorder(NodeExist[rootId]);

	cout << endl << "Inorder" << endl;
	showTreeByInorder(NodeExist[rootId]);

	cout << endl << "Postorder" << endl;
	showTreeByPostorder(NodeExist[rootId]);
	cout << endl;

	freeNode(NodeExist[rootId]);

	return 0;
}


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

using namespace std;

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

    int m ;
    cin >> m;
    string t[m];

    for(int i =0; i < m; i++){
        cin >> t[i];
    }
  
  int ans = 0;
  for(int i=0;i<n;i++){
      int count=0;
    for(int j=i;j<n;j++){
      if(s[i]==s[j])count++;
    }
    for(int k=0;k<m;k++){
      if(s[i]==t[k])count--;
    }
    if(ans<count)ans = count;
  }
    cout << ans << endl;       
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define ll long long
#define umapii unordered_map <int,int>
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define endl '\n'
#define all(v) (v).begin(),(v).end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define MP(a,b) make_pair(a,b)
#define debug(x)       cerr<< #x << " : " << x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[i].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/
ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;
int main(){
    IOS;
    int n;
    ll k;
    cin >> n >> k;
    vector<bool> vis(n + 1 , 0);
    vector<ll> dis(n + 1, -1);
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int s = 1;
    vis[s] = 1;
    int nx = -1;
    dis[s] = 0;
    while(k != 0){
        nx = a[s];
        if(vis[nx]) break;
        vis[nx] = 1;
        dis[nx] = 1 + dis[s];
        --k;
        s = nx;
    }
    if(k == 0){
        cout << s << endl;
        return 0;
    } 
    int  len = (dis[s] - dis[nx] + 1);
    k--;
    s = nx;
    int move = (k % len);
    for(int i = 0; i < move; i++){
        s = a[s];
    }
    cout << s << '\n';
    #ifdef LOCAL
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
    // g++ -DLOCAL -std=c++17 f.cpp
}


Measured memory_bytes: 5576
a,b,c =map(int,input().split())
if a==1 and b==0 and c==0:
    print("Close")
elif a==0 and b==1 and c==0:
    print("Close")
elif a==0 and b==0 and c==1:
    print("Open")
elif a==1 and b==1 and c==0:
    print("Open")
elif a==0 and b==0 and c==0:
    print("Close")
else:
    print("Again")


Measured memory_bytes: 5596
#include <stdio.h>
int main()
{
  char c;
  int n;
  while((scanf("%c",&c))!=EOF){
    if(c == '@'){
      scanf("%c",&c);
      n = c - '0';
      scanf("%c",&c);
      while(n-- > 0){
	printf("%c",c);
      }
    }else{
      printf("%c",c);
    }
  }
  return 0;
}

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

int sum_digit(string num) {
    int sum = 0;
    for (auto ch : num) sum += (int)(ch - '0');
    return sum;
}

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

    while (true) {
        string num;
        cin >> num;
        if (num == "0")
            break;
        else
            cout << sum_digit(num) << endl;
    }
    return 0;
}


Measured memory_bytes: 3224
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<ll, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

const int N = (int)1e5 + 9;
bool can[N][2];
int cnt[N];

int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    can[1][1] = true;
    for(int i = 2 ; i <= n; i ++ )
        can[i][0] = true;
    for(int i = 1; i <= n ; i ++ )
        cnt[i] = 1;
    int x, y;
    for(int i = 1; i <= m ; i ++ ){
        cin >> x >> y;
        if(can[x][0] && can[x][1]){
            if(cnt[x] == 1){
                can[x][0] = false;
                can[x][1] = false;
            }
            can[y][0] = true;
            can[y][1] = true;
        }
        else if(can[x][1]){
            can[x][1] = false;
            can[y][1] = true;
        }
        else{
            can[x][0] = false;
            can[y][0] = true;
        }
        cnt[x] -- ;
        cnt[y] ++ ;
    }
    int res = 0;
    for(int i = 1; i <= n ; i ++ )
        res += can[i][1];
    cout << res;
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
int H,W,n,Sx,Sy;
char s1[200005];
char s2[200005];
void solve(int l,int r,int mx,int p,char c1,char c2){
	Rep(i,n,1){
		if (s2[i]==c1) r=min(r+1,mx);
		if (s2[i]==c2) l=max(l-1,1);
		if (s1[i]==c1) l++;
		if (s1[i]==c2) r--;
		//printf("%d %d\n",l,r);
		if (l>r){
			puts("NO");
			exit(0);
		}
	}
	if (p<l||p>r){
		puts("NO");
		exit(0);
	}
}
int main(){
	scanf("%d%d%d%d%d",&H,&W,&n,&Sx,&Sy);
	scanf("%s%s",s1+1,s2+1);
	solve(1,H,H,Sx,'U','D');
	solve(1,W,W,Sy,'L','R');
	puts("YES");
} 

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

void dump(ll *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

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

	int n,k;
	cin >> n >> k;

	int a[n];
	ll rui[n+1]={};
	ll seirui[n+1]={};
	rep(i,n){
		cin >> a[i];
		rui[i+1]=rui[i]+a[i];
		if(a[i]>0) seirui[i+1]=seirui[i]+a[i];
		else	seirui[i+1]=seirui[i];
	}
	ll ans=0;
	for(int i=1;i<=n-k+1;i++){
//		cout << seirui[n]-seirui[i+k-1]+seirui[i-1]+max(0LL,rui[i+k-1]-rui[i-1]) << "\n";
		ans = max(ans,seirui[n]-seirui[i+k-1]+seirui[i-1]+max(0LL,rui[i+k-1]-rui[i-1]));
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,i,j,k,c=0,d;
	cin>>n;
	long long a[n];
	cin>>a[0];
	for(i=1;i<n;i++){
		cin>>a[i];
		d=a[i-1]-a[i];
		if(d>0){
			a[i]+=d;
			c+=d;
		}
	}
	cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 5172
// C++ program for implementation of Ford Fulkerson algorithm 
#include <iostream> 
#include <limits.h> 
#include <string.h> 
#include <queue> 
#include <set>
using namespace std; 

#include <stdio.h>

int main(int argc, char *argv[]) {
   long long int n=0,b=0,a=0;
   long long int tot=0;
   cin>>n>>b>>a;
   long long ans=n/(a+b)*b+min(b,n%(a+b));
  
  cout<<ans<<endl;
   return(0);
}
   


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

const int MAXN = 3010;

string s,t;
int dp[MAXN][MAXN],N,M;
stack<char> resposta;

int solve(int a,int b){

	if(a < 0 || b < 0) return 0;

	if(dp[a][b] != -1) return dp[a][b];

	if(s[a] == t[b]) return dp[a][b] = 1 + solve(a-1,b-1);

	return dp[a][b] = max(solve(a-1,b),solve(a,b-1));

}

void build(int a,int b){

	if(a < 0 || b < 0) return;

	if(s[a] == t[b]){
		resposta.push(s[a]);
		build(a-1,b-1);
		return;
	}

	if(solve(a-1,b) > solve(a,b-1)) build(a-1,b);
	else build(a,b-1);

}

int main(){

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

	cin >> s;
	cin >> t;

	N = (int)s.size();
	M = (int)t.size();

	build(N-1,M-1);

	while(!resposta.empty()){
		cout << resposta.top();
		resposta.pop();
	}
	cout << endl;

	return 0;

}

Measured memory_bytes: 39264