akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
ll mod=1e9+7;
ll dp[2001][2001];
const int M=2000*2000;
ll f[M],g[M],inv[M];
void precalc(){
	f[0]=1;
	rep1(i,M) f[i]=f[i-1]*i%mod;
	inv[1]=1;
	for(int i=2;i<=M;i++) inv[i]=mod-mod/i*inv[mod%i]%mod;
	g[0]=1;
	rep1(i,M) g[i]=g[i-1]*inv[i]%mod;
}
ll C(int x,int y){
	return f[x]*g[y]%mod*g[x-y]%mod;
}
void add(ll &x,ll y){
	x+=y;
	x%=mod;
}
int main(){
	int N,K;
	cin>>N>>K;
	if(N==2&&K==2){
		puts("4");
		return 0;
	}
	precalc();
	if(K==1){
		puts("1");
		return 0;
	}
	dp[1][0]=1;
	rep1(i,N) rep(j,i+1){
//		printf("dp[%d][%d]=%lld\n",i,j,dp[i][j]);
		if(i!=N) add(dp[i+1][j],dp[i][j]);
		if(j!=i){
			int left=N*K-i-j*(K-1)-1;
			add(dp[i][j+1],dp[i][j]*C(left,K-2));
		}
	}
	ll ans=dp[N][N];
	rep1(i,N) ans=ans*i%mod;
	cout<<ans<<endl;
}


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

using namespace std;

int main () {

    string a;
    cin >> a;

    if(a == "A" ||  a == "B" || a == "C" || a == "D" || a == "E" || a == "F" || a == "G" || a == "H" || a == "I" || a == "J" || a == "K" || a == "L" || a == "M" || a == "N" || a == "O" || a == "P" || a == "Q" || a == "R" || a == "S" || a == "T" || a == "U" || a == "V" || a == "W" || a == "X" || a == "Y" || a == "Z") {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,k,ans=0,d,x; cin>>n>>k;
  int s[n];
  rep(i,n)s[i]=0;
  
  rep(i,k){
    cin>>d;//cout<<d<<endl;
    rep(j,d){
      cin>>x;
      s[x-1]++;
      //cout<<s[x]<<endl;
    }
  }
  rep(i,n){if(s[i]==0)ans++;}

  cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>

int main(int argc, char** argv) {
  std::string S, T, U;
  int A, B;
  std::cin >> S >> T >> A >> B >> U;
  if (S == U) --A;
  else if (T == U) --B;
  std::cout << A << ' ' << B << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define f(a, b, c, d) for(ll a = b; a < c; a += d)

void solve()
{
	string n;
	cin >> n;
	ll sum = 0;
	for (char c : n)
	{
		sum += c - '0';
	}
	if (sum % 9 == 0)
		cout << "Yes";
	else
		cout << "No";
}

signed main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll t = 1;
	//cin >> t;
	while (t--)
		solve();
}

Measured memory_bytes: 3728
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
using namespace std;
signed main()
{
    fast;
   
    int n,i,ans=0;
    string s;
    cin>>n>>s;
    for(i=0;i<n;)
    {
    	int j = i;
    	while(s[i]==s[j] and j<n)
    	{
    		j++;
    	}
        ans++;
        i = j;
    }
    cout<<ans;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
  int n,i,s=0,m=0,p;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&p);
    s+=p;
    if(m<p)m=p;
  }
  printf("%d",s-m/2);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a, b, k;
	cin >> a >> b >>k;
	if(a >= k){
		a -= k;
		k = 0;
	}
	else {
		k -= a;
		a = 0;
	}
	if(b >= k){
		b -= k;
	}
	else b = 0;
	cout << a << " " << b;
	return 0;
}

Measured memory_bytes: 256
def line_mainte(A,h):
    output = []
    for i in range(len(A)-1):
        if A[i] % 2 != 0:
            A[i] -= 1
            A[i+1] += 1
            output.append(str(h)+" "+str(i+1)+" "+str(h)+" "+str(i+2))
    return (len(output),output)

def row_mainte(A,w):
    output = []
    for i in range(len(A)-1):
        if A[i] % 2 != 0:
            A[i] -= 1
            A[i+1] += 1
            output.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))
    return (len(output),output)

H,W = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(H)]

count,procedure = 0,[]
for i in range(H):
    tmp = line_mainte(a[i],i+1)
    count += tmp[0]
    procedure += tmp[1]
row_W = [a[i][W-1] for i in range(H)]
tmp = row_mainte(row_W,W)
count += tmp[0]
procedure += tmp[1]

print(count)
for i in range(len(procedure)):
    print(procedure[i])


Measured memory_bytes: 16472
#include <iostream>
 
#include <string>
#include <map>
#include <algorithm>
#include <cassert>
#include <cstdio>
 
using namespace std;
#define N 40
#define TEST 0
 
 
    string a[N];
    int b[N],c[N];
    string d[N][N];
    int edges[N][N];
    int n;
 
typedef long long i64;
int maxv;
i64 maxi;
 
i64 edg[N];
 
void rec(i64 bits,int sum){
    if(sum<=maxv){
        return;
    }
    if((bits&1LL)==0LL)return;
    bool clique=true;
    int minind=100000;
    int mini=-1;
    for(int i=0;i<n;i++){
        if((bits&(1LL<<i))==0)continue;
        int ind=0;
	i64 is=bits&edg[i];
        for(int j=0;j<n;j++){
            if((is&(1LL<<j)))
                ind+=1;
        }
	if(bits!=(is|(1LL<<i)))
		clique=false;
        if(minind>ind){
            mini=i;
            minind=ind;
        }
    }
    if(mini==-1)assert(!"error mini==-1");
    int sub1=b[mini];
    i64 set1=1LL<<mini;
    set1|=bits&edg[mini];
    for(int i=0;i<n;i++){
        if((set1&(1LL<<i))==0)continue;
        if(i==mini)continue;
        if(set1&(1LL<<i)){
            sub1+=b[i];
        }
    }
    if(!clique){
        rec(set1,sub1);
        rec(bits&~(1LL<<mini),sum-b[mini]);
        return;
    }
    //clique
    if(maxv<sub1){
        maxv=max(maxv,sub1);
        maxi=bits;
    }
}
 
 
 
int main(void){
    int di[N][N];
    while(1){
        cin>>n;
        if(TEST)cerr<<"n="<<n<<endl;
        if(n==0)break;
        map<string,int> m;
        for(int i=0;i<n;i++){
            cin>>a[i]>>b[i]>>c[i];
            for(int j=0;j<c[i];j++){
                cin>>d[i][j];
            }
        }
        int cnt=0;
        for(int i=0;i<n;i++){
            m.insert(pair<string,int>(a[i],i));
        }
        for(int i=0;i<n;i++){
            fill_n(edges[i],n,1);
            edges[i][i]=0;
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<c[i];j++){
                di[i][j]=m[d[i][j]];
                edges[i][di[i][j]]=0;
            }
	    i64 s=0;
	    for(int j=0;j<n;j++){
		s|=edges[i][j]?1LL<<j:0;
	    }
	    edg[i]=s;
        }
        if(TEST){
            for(int i=0;i<n;i++){
                for(int  j=0;j<n;j++){
                    cerr<<edges[i][j]<<" ";
                }
                cout<<":"<<b[i]<<endl;
            }
        }
        maxv=0;
        int sum=0;
        for(int i=0;i<n;i++){
            sum+=b[i];
        }
        rec((1LL<<n)-1,sum);
        cout<<maxv<<endl;
        if(TEST){
            fprintf(stderr,"set=%llx\n",maxi);
        }
    }
    return 0;
}

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

int main() {
    int n, d; cin >> n >> d;
    int t = 2 * d + 1;
    if (n % t == 0) {
        cout << n / t << endl;
    } else {
        cout << n / t + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
//int a[200005], b[200005];
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    int v = 1<<28;
    int ans = 0;
    for ( int v = (1<<28); v; v>>=1) {
        // 上位bitから順に判定
        rep(i, n) a[i] &= (v * 2 - 1);
        rep(i, n) b[i] &= (v * 2 - 1);
//        sort(a, a+n); sort(b, b+n);
        sort(a.begin(), a.end()); sort(b.begin(), b.end());
        int t = 0;
        int j = 0;
        int k = 0;
        int l = 0;
//        for ( int i = n - 1, j = 0, k = 0, l = 0; i >= 0; i-- ) {
        for ( int i = n - 1; i >= 0; i-- ) {
            while( j < n && a[i]+b[j] < v) j++;
            while( k < n && a[i]+b[k] < 2 * v) k++;
            while( l < n && a[i]+b[l] < 3 * v) l++;
            t += k + ( n - j - l);
            t &= 1;
        }
        if (t) ans |= v;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;
const int MOD = 1000000007;

typedef std::pair<int, int> P;

int n, m;
int a[1000];
int b[1000];
int ans = 1;
std::set<P> ast, bst;



signed main(){
	scanf("%ld %ld", &n, &m);
	for(int i = 0; i < n; i++){
		scanf("%ld", &a[i]);
	}
	for(int i = 0; i < m; i++){
		scanf("%ld", &b[i]);
	}
	
	std::sort(a, a+n, std::greater<int>());
	std::sort(b, b+m, std::greater<int>());
	
	for(int i = 0; i < n; i++){
		ast.insert(P(a[i], i));
	}
	for(int i = 0; i < m; i++){
		bst.insert(P(b[i], i));
	}
	
	for(int i = n*m; i > 0; i--){
		//printf("%ld\n", i);
		auto ita = ast.lower_bound(P(i, 0));
		auto itb = bst.lower_bound(P(i, 0));
		int product;
		//printf("  (%ld %ld)\n", ita->first, itb->first);
		if(ita == ast.end() || itb == bst.end()){
			product = 0;
		}else if(i == ita -> first && i == itb -> first){
			//printf("    pass1\n");
			product = 1;
		}else if(ita -> first == i){
			//printf("    pass2\n");
			if(itb == bst.end()){
				product = 0;
			}else{
				product = itb -> second + 1;
			}
		}else if(itb -> first == i){
			//printf("    pass3\n");
			if(ita == ast.end()){
				product = 0;
			}else{
				product = ita -> second + 1;
			}
		}else{
			//printf("    pass4\n");
			//printf("  (%ld, %ld), (%ld, %ld)\n", ita->first, ita->second, itb->first, itb->second);
			product = (ita -> second + 1) * (itb -> second + 1) - (n*m - i);
		}
		//printf("  pro:%ld\n", product);
		ans *= (product % MOD);
		ans %= MOD;
	}
	printf("%ld\n", ans);
	return 0;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	string s;
	cin >> s;
	for(auto x : s)
		if(x == '1')
			cout << 9;
		else
			cout << 1;
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
program Traveling
    implicit none
    integer(4):: n,i
    integer(4),allocatable:: t(:),x(:),y(:),d(:)

    read*, n
    allocate(t(n),x(n),y(n),d(n))

    do i=1,n
        read*, t(i),x(i),y(i)
    end do

    d(:) = x(:)+y(:)


    do i=1,n
        if (t(i) < d(i) .or. (mod(t(i),2) /= mod(d(i),2))) then
            print*, 'No'
            stop
        end if
    end do

    print*, 'Yes'


end program Traveling

Measured memory_bytes: 1792
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
int a[2010];
int b[4010];
int c[4010];
int n;
ll ans;
int main()
{
	cin>>n;
	zero(b);
	zero(c);
	rep(i,n)
	{
		cin>>a[i];
		b[a[i]]++;
	}
	c[1]=b[1];
	rep3(i,2,4010)
	{
		c[i]=c[i-1]+b[i];
	}
	/*rep(i,1010)
	{
		cout<<i<<":"<<c[i]<<endl;
	}*/
	sort(a,a+n);
	ans=0;
	rep(i,n)
	{
		rep(j,n)
		{
			if(i==j) continue;
			int x=max(a[i],a[j])-min(a[i],a[j]);
			int y=a[i]+a[j]-1;
			int now=c[y]-c[x];
			if(a[i]>x&&a[i]<=y)
			{
				now--;
			}
			if(a[j]>x&&a[j]<=y)
			{
				now--;
			}
			if(now>0)
			{
				ans+=now;
			}
		}
	}
	cout<<ans/6;
	return 0;
}

Measured memory_bytes: 256
using System;
    using System.Text;
    using System.Collections.Generic;
    using static System.Math;
    using System.Linq;
    using static System.Array;

    namespace ConsoleApp2
    {
        class Program
        {


            static void Main(string[] args)
            {
                var X = long.Parse(Console.ReadLine());
                var tmp = 100L;
            var count = 0;
                while(tmp < X)
            {
                tmp = (long)(1.01*tmp);
                count++;
            }


                Console.WriteLine(count);
            }
        }
    }


Measured memory_bytes: 27508
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
using namespace std;
 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007
 

void solver()
{
	ll n,r;
	cin>>n>>r;
	
	if(n>=10)cout<<r;
	else cout<< r + (10-n)*100;	
	
	
}

signed main() 
{
	speed;
	
	ll q=1;
	//cin>>q;
	
	while(q--)
		solver();
		
 	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


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

int main() {
  int n;
  std::cin >> n;
  int t[n], x[n], y[n];
  for (int i = 0; i < n; i++) {
    std::cin >> t[i] >> x[i] >> y[i];
  }
  if (t[0] % 2 != (x[0] + y[0]) % 2 || t[0] < (x[0] + y[0])) {
    std::cout << "No" << "\n";
    return 0;
  }
  for (int i = 1; i < n; i++) {
    if (abs(t[i] - t[i - 1]) % 2 != (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) % 2 || abs(t[i] - t[i - 1]) < (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]))) {
      std::cout << "No" << "\n";
      return 0;
    }
  }
  std::cout << "Yes" << "\n";
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



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

int x[210];
int y[210];

int main() {
    //freopen( "C:\\Users\\t2ladmin\\Dropbox\\Contest\\input.in", "r", stdin );
    
	int N;
	while (cin >> N) {
		if (N == 0) break;
		memset(x, 0, sizeof(x));
		memset(y, 0, sizeof(y));

		int posx = 0, posy = 0;
		int minx = 0, maxx = 0, miny = 0, maxy = 0;

		int n, d;
		for (int i = 0; i < N-1; ++i) {
			cin >> n >> d;
			posx = x[n] + dx[d];
			posy = y[n] + dy[d];
			x[i+1] = posx;
			y[i+1] = posy;
			minx = min(minx, posx);
			maxx = max(maxx, posx);
			miny = min(miny, posy);
			maxy = max(maxy, posy);
		}

		cout << maxy-miny+1 << " " << maxx-minx+1 << endl;
	}
    
    return 0;
}


Measured memory_bytes: 1160
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.range;
import std.functional;

void main() {
  auto N = readln.split[0].to!int;

  int[] items;
  items ~= 1;
  int tmp = 6;
  while(tmp <= N) {
    items ~= tmp;
    tmp *= 6;
  }
  tmp = 9;
  while(tmp <= N) {
    items ~= tmp;
    tmp *= 9;
  }
  items.sort!"a<b";

  auto dp = new int[1+N];
  dp[0] = 0;
  foreach(i; 1..(1+N)) {
    auto m = int.max;
    foreach(item; items) {
      if(item > i) break;
      m = min(m, 1 + dp[i-item]);
    }
    dp[i] = m;
  }

  dp[N].writeln;
}


Measured memory_bytes: 2556
import java.util.*;

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

        int sum = 0;
        int sumN = 1;
        int prevL = 0;

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        ArrayList<Integer> ary = new ArrayList<>();
        ary.add(0);

        for (int i = 1 ; i < n + 1 ; i ++) {
            int l = Integer.parseInt(sc.next());
            sum = prevL + l;
            if (sum <= x) {
                ary.add(0);
            }
            prevL = sum;
        }
        System.out.print(ary.size());
    }
}

Measured memory_bytes: 23252
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sum = 0
for i in range(n):
    sum += b[a[i]-1]
    if((i < n-1) and (a[i] < n) and (a[i+1] == a[i] + 1)):
        sum += c[a[i]-1]

print(sum)

Measured memory_bytes: 38384
a,b=(int(x) for x in input().split())


if b%2==0 and 2<=b<=1000:
  
  if 0<=a<=5:
    
    print(0)
  
  elif 6<=a<=12:
    
    print(int(b/2))
    
  elif 13<=a<=100:
    
    print(b)


Measured memory_bytes: 2940
N = int(input())
T, A = [int(ta) for ta in input().split()]
H = [int(h) for h in input().split()]
mn_T = 1000
ans = 0
for n in range(N):
  abs_T = abs(A-(T-H[n]*0.006))
  if abs_T < mn_T:
    mn_T = abs_T
    ans = n+1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
    int X;
    cin >> X;

    vector<bool> dp(X + 1, false);
    dp[0] = true;

    vector<int> v;
    for (int i = 0; i < 6; i++)
        v.push_back(100 + i);

    for (int i = 0; i < X; i++) {
        if (dp[i] == false)
            continue;

        for (int j = 0; j < (int)v.size(); j++) {
            int index = i + v[j];
            if (index > X)
                continue;

            dp[index] = true;
        }
    }

    if (dp[X] == true)
        cout << 1 << endl;
    else
        cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  long long K, A, B;
  cin >> K >> A >> B;

  long long ret = 0;
  long long b_op;
  if ((K - A + 1) % 2 == 0)
    b_op = (K - A + 1) * (B - A) / 2;
  else
    b_op = ((K - A + 1) - 1) * (B - A) / 2 + 1;
  if (b_op > K) {
    ret += b_op + A;
  } else {
    ret += K + 1;
  }

  cout << ret << endl;

  return 0;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    ll n, check = 0, x, y, cnt = 0 ;
    cin >> n ;
    for (int i = 0; i < n; i++) {
        cin >> x >> y ;
        if (x == y) cnt++ ;
        else cnt = 0 ;
        if (cnt == 3) {
            check = 1 ;
        }
    }
    if (check)  cout << "Yes\n" ;
    else    cout << "No\n" ;

    return 0 ;
}


Measured memory_bytes: 3628
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
c = dict(c)
c = sorted(c.items(), key=lambda x:x[0], reverse=True)
h = 0
w = 0
for i in range(len(c)):
  if c[i][1] >= 2 and h == 0:
    h = c[i][0]
    if c[i][1] >= 4:
      w = c[i][0]
  elif c[i][1] >= 2 and w == 0:
    w = c[i][0]
ans = h * w
print(ans)

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

int main(int argc, char const *argv[])
{
  int N;
  cin >> N;
  vector<int> T(N);
  for(int i = 0; i < N; i++)
    cin >> T[i];
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for(int i = 0 ; i < M; i++)
    cin >> P[i] >> X[i];

  int sum = 0;

  for(int i = 0; i < N; i++)
    sum += T[i];

  for(int i = 0; i < M; i++)
    cout << sum - T[P[i]-1] + X[i] << endl;
  return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


int dp[5001][5000] = {false};
int a[5000];
signed main(void){
  int i, j, k;
  int2(n, kk);
  rep(i, n)scanf("%d", a+i);
  sort(a, a + n);

  int l = 0, r = n;
  bool is = false;
  for(;l != r;){
    if(l + 1 >= r){
      is = true;
      i = l;
    }else i = (l + r) / 2;
    bool yn = (a[i] >= kk);
    rep(j, n + 1)rep(k, kk)dp[j][k] = false;
    dp[0][0] = true;
    rep(j, n){
      rep(k, kk)dp[j + 1][k] = dp[j][k];
      if(i != j)per(k, kk)if(dp[j][k] && k + a[j] < kk){
        dp[j + 1][k + a[j]] = true;
        if(k + a[j] + a[i] >= kk){
          yn = true;
          j = n;k = 0;
        }
      }
    }
    //pri3(l, i, r);
    if(is){
      if(yn)pri(l);
      else pri(r);
      break;
    }
    if(yn)r = i;
    else l = i;
  }
  return 0;
}


Measured memory_bytes: 97920
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 0;

ll x[10];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	for(ll i = 1; i <= 5; i++){
		cin >> x[i];
		if(x[i] == 0){
			cout << i << '\n';
			return 0;
		}
	}
}


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

int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N-1; j >= i+1; j--) {
      if (A[j] < A[j-1]) {
        swap(A[j], A[j-1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  int sw = bubbleSort(A, N);
  for (int i = 0; i < N; i++) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];

	bool ng = false;
	rep(i, n)if (i + 1 < a[i])ng = true;
	if (ng) { cout << -1 << endl;return 0; }

	vi ans(0);

	rep(i, n) {

		bool find = false;
		vi aa(0);
		rep(j, a.size()) {
			if (!find && a[a.size() - 1 - j] == a.size() - j) {
				ans.push_back(a.size() - j);
				find = true;
			}
			else aa.push_back(a[a.size() - 1 - j]);
		}

		reverse(all(aa));
		a = aa;

	}

	reverse(all(ans));

	if (ans.size() < n)cout << -1 << endl;
	else rep(i, n)cout << ans[i] << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

int g[102][102];

int main(void){
    int n,k;
    cin>>n>>k;
    if((n-1)*(n-2)<2*k){
        cout<<-1<<endl;
        return 0;
    }
    else{
        for(int i=1;i<n;i++){
            g[i][n]=1;
            g[n][i]=1;
        }
    }
    int m=(n-1)*(n-2)/2;
    int index1=1;
    int index2=2;
    while(m!=k){
        g[index1][index2]=1;
        g[index2][index1]=1;
        m--;
        index2++;
        if(index2==n){
            index1++;
            index2=index1+1;
        }
    }
    cout<<(n-1)*(n-2)/2-k+n-1<<endl;
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            if(g[i][j])cout<<i<<" "<<j<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

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

	int ans = a[0];
	for(int i = 0;i < n;i++){
		ans = gcd(ans,a[i]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <stack>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

void printarray(int n, int a[])
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;
}

void printpairaraay(int n, pair<int, int> a[])
{
    int x, y;
    for (int i = 0; i < n; i++)
    {
        x = a[i].first;
        y = a[i].second;
        cout << x << " " << y << "\n";
    }
    cout << endl;
}

void swaprange(int b, int t, int e, int a[])
{
    for (int i = 0; i < e - b; i++)
    {
        swap(a[b + i], a[i + t]);
    }
}

int my_binarysearch(int n, int a[], int x)
{
    int ret = 0;
    if (distance(lower_bound(a, a + n, x), upper_bound(a, a + n, x)) != 0)
        ret = 1;
    return ret;
}

int main()
{
    int n, m, x, r;
	r = 0;
    cin >> n;
    int a[n];

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

    cin >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> x;
    	cout << distance( a, lower_bound(a, a + n, x) ) << endl;
    }


    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3488
#include <iostream>
using namespace std;
void trace(int A[], int N){
    int i;
    for(i=0; i<N; i++){
        if(i>0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(int A[], int N){
    for(int i=1; i<N; i++){
        int v = A[i];
        int j = i-1;
        
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, N);
    }
}

int main(void){
    int N;
    int A[101];
    
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];
    
    trace(A, N);
    insertionSort(A, N);
    
    return 0;
}



Measured memory_bytes: 3112
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
} read;

const int maxn = 6005;
ll f[maxn][maxn << 1];
ll inv[maxn];

int main () {
	int n = read * 3, mod = read;

	inv[1] = 1;
	for (int i = 2; i <= n; i ++)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;

	f[0][maxn + 0] = 1;
	f[1][maxn + 1] = inv[1];
	f[2][maxn + 2] = inv[2];
	f[2][maxn - 1] = inv[2];
	for (int s = 3; s <= n; s ++)
		for (int i = maxn - s; i <= maxn + s; i ++)
			f[s][i] = (f[s - 1][i - 1] + f[s - 3][i] + f[s - 2][i + 1]) * inv[s] % mod;

	ll ans = 0;
	for (int i = maxn; i <= maxn + n; i ++)
		ans += f[n][i];
	ans %= mod;
	for (int i = 1; i <= n; i ++)
		(ans *= i) %= mod;
	printf("%lld\n", ans);
}


Measured memory_bytes: 561408
#include <iostream>
int main()
{
	//整数の入力
	int a, b, c;
	std::cin >> a >> b;

	if (a <= b) {
		c = a;
	}
	else if (a > b) {
		c = a - 1;
	}

	//出力

	std::cout << c << std::endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
xy = [0] * N
for i in range(N):
    xy[i] = tuple(map(int, input().split()))

case = [N]
for x,y in xy:
    for xx, yy in xy:
        if x == xx and y == yy:
            continue
        score = N
        xs = xx - x
        ys = yy - y
        for xxx,yyy in xy:
            if x == xxx and y == yyy:
                continue
            if (xxx - xs,yyy - ys) in xy:
                score -= 1
        case.append(score)
print(min(case))

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

int main(){
    int N; cin >> N;
    int A[N]; int tmp = 0; int idx = 0; 
  	rep(i,N){
      cin >> A[i];
      if(tmp < A[i]){ tmp = A[i]; idx = i; }
    }
  	sort(A,A+N,greater<int>());
    rep(i,N){
        if(i == idx) cout << A[1] << endl;
        else cout << A[0] << endl;
    }
}


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

int main(){
  int n,m,ans=0; cin>>n>>m;
  vector<bool> on(n,false);
  vector<vector<int>> s(m);
  vector<int> con(m);
  for(int i=0;i<m;i++){
    int k; cin>>k;
    for(int j=0;j<k;j++){
      int a; cin>>a;
      s[i].push_back(a);
      s[i][j]--;
    }
  }for(int i=0;i<m;i++){
    cin>>con[i];
  }for(int bit=0;bit<(1<<n);bit++){
    for(int i=0;i<n;i++){
      on[i]=false;
      if(bit & (1<<i)){
        on[i]=true;
      }
    }bool flag=true;
    for(int i=0;i<m;i++){
      int num=0;
      for(int j=0;j<s[i].size();j++){
        if(on[s[i][j]]){
          num++;
        }
      }if(num%2!=con[i]){
        flag=false;
        continue;
      }
    }if(flag){
       ans++;
    }
  }cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  double r;
  cin >> r;
  cout << 2 * 3.14159265358979 * r;
  return 0;
}


Measured memory_bytes: 3780
import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
a = [v[i] for i in range(n) if i%2]
b = [v[i] for i in range(n) if i%2==0]
cnt_a = Counter(a)
cnt_b = Counter(b)
max_a = cnt_a.most_common()[0][1]
max_b = cnt_b.most_common()[0][1]

str_a = cnt_a.most_common()[0][0]
str_b = cnt_b.most_common()[0][0]

max_2a = 0
max_2b = 0

for i in cnt_a:
    if str_a != i  and cnt_a[i] > max_2a:
        max_2a = cnt_a[i]

for i in cnt_b:
    if str_b != i  and cnt_b[i] > max_2b:
        max_2b = cnt_b[i]

if str_a != str_b:
    print(n//2 - max_a + n//2 - max_b)
else:
    tmp_a = n//2 - max_2a + n//2 - max_b
    tmp_b = n//2 - max_a + n//2 - max_2b
    print(min(tmp_a,tmp_b))

Measured memory_bytes: 20036
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
 
class Main
{
	static class Pair
	{
		int first, second;
		public Pair(int f, int s)
		{
			first = f;
			second = s;
		}
		
		public String toString()
		{
			return first + " " + second;
		}
	}
	
	static class PairComparator implements Comparator <Pair>
	{
		public int compare(Pair p1, Pair p2)
		{
			if(p1.first < p2.first)
				return -1;
			if(p1.first > p2.first)
				return 1;
			if(p1.second < p2.second)
				return -1;
			if(p1.second > p2.second)
				return 1;
			return 0;
		}
	}
	
	static int log2(double a)
	{
		return (int)(Math.log(a) / Math.log(2));
	}
	
	static long gcd(long a, long b)
	{
		long r;
		while((r = a % b) > 0)
		{
			a = b;
			b = r;
		}
		return b;
	}
	
	static class TrieNode
	{
		TrieNode z, o;
		boolean end;
		long count;
		
		public TrieNode()
		{
			 z = null;
			 o = null;
			 count = 0;
			 end = false;
		}
		
		
	}
	
	public static void main(String[] args) throws IOException
	{
		int n = in.nextInt();
		if(n / 10 == 9 || n % 10 == 9)
			sop("Yes");
		else
			sop("No");
	}
    
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	
    static FastReader in = new FastReader();
  
    public static void sop(Object o)
    {
    	System.out.print(o);
    }
}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

struct UnionFind{
	vector<int> par,rank;
	UnionFind(int n) :par(n + 1),rank(n + 1,1){
		for(int i = 1;i <= n;i++) par [i] = i;
	}
	int find(int x){
		return par [x] == x ? x : par [x] = find(par [x]);
	}
	bool unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x == y) return false;
		if(rank [x] < rank [y]) swap(x,y);
		rank [x] += rank [x] == rank [y];
		par [y] = x;
		return true;
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
};

int N;
vector< pair<int,int> > X,Y;
struct edge{
	int a,b,len;
	bool operator<(const edge& other){
		return len < other.len;
	}
};
vector<edge> G;
const int INF = 2e9;

int main()
{
	scanf("%d",&N);
	X.assign(N,make_pair(0,0));
	Y.assign(N,make_pair(0,0));
	FOR(i,0,N){
		scanf("%d%d",&X [i].first,&Y [i].first);
		X [i].second = Y [i].second = i;
	}
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	FOR(i,0,N - 1){
		G.push_back(edge{X [i].second,X [i + 1].second,X [i + 1].first - X [i].first});
		G.push_back(edge{Y [i].second,Y [i + 1].second,Y [i + 1].first - Y [i].first});
	}
	sort(G.begin(),G.end());

	UnionFind uf(N);
	ll ans = 0;
	int cnt = 1;
	for(int i = 0;i < G.size() && cnt < N;i++){
		if(uf.same(G [i].a,G [i].b) == false){
			uf.unite(G [i].a,G [i].b);
			ans += G [i].len;
			cnt++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 6388
#include <stdio.h>

int main(void){
  int A,B,C,D,E,F;
  scanf("%d%d%d",&A,&B,&C);
  scanf("%d%d%d",&D,&E,&F);

  int water,sugar;
  double noudo,maxnoudo;
  int ans[2] = {A*100,0};

  for(int a = 0;a*A*100 <= F;a++){
    for(int b = 0;(a*A+b*B)*100 <= F;b++){
      if(a == 0 && b == 0) continue;
      water = (a*A+b*B)*100;
      for(int c = 0;water+c*C <= F;c++){
        for(int d = 0;water+c*C+d*D <= F;d++){
          sugar = c*C+d*D;
          if(water/100*E < sugar) continue;
          noudo = 100.0*sugar/(water+sugar);
          if(maxnoudo < noudo){
            maxnoudo = noudo;
            ans[0] = water+sugar;
            ans[1] = sugar;
          }
        }
      }
    }
  }

  printf("%d %d\n",ans[0],ans[1]);

  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <stdio.h>

int main() {
	int N;
	int a[100];
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &a[i]);
	}
	std::sort(a, a + N);
	int ans = 1;
	for (int i = 1; i < N; ++i) {
		if (a[i - 1] < a[i]) {
			++ans;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    int n;
    string s;
    cin >> n >> s;
    int R[n + 1], G[n + 1], B[n + 1];
    R[0] = G[0] = B[0] = 0;
    for (int i = 1; i <= n; i++) {
        R[i] = R[i - 1];
        G[i] = G[i - 1];
        B[i] = B[i - 1];
        if (s[i - 1] == 'R') R[i]++;
        else if (s[i - 1] == 'G') G[i]++;
        else B[i]++;
    }
    ll ans = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            if (s[i] == s[j]) continue;
            bool r = false, g = false, b = false;
            if (s[i] == 'R' || s[j] == 'R') r = true;
            if (s[i] == 'G' || s[j] == 'G') g = true;
            if (s[i] == 'B' || s[j] == 'B') b = true;
            if (!r) {
                int t = j - i;
                ans += R[n];
                if (1 <= j + t + 1 && j + t + 1 <= n) {
                    ans -= R[j + t + 1];
                    ans += R[j + t + 1] - (R[j + t + 1] - R[j + t]);
                }
                ans -= R[j + 1];
            } else if (!g) {
                int t = j - i;
                ans += G[n];
                if (1 <= j + t + 1 && j + t + 1 <= n) {
                    ans -= G[j + t + 1];
                    ans += G[j + t + 1] - (G[j + t + 1] - G[j + t]);
                }
                ans -= G[j + 1];
            } else {
                int t = j - i;
                ans += B[n];
                if (1 <= j + t + 1 && j + t + 1 <= n) {
                    ans -= B[j + t + 1];
                    ans += B[j + t + 1] - (B[j + t + 1] - B[j + t]);
                }
                ans -= B[j + 1];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
import numpy as np
N, Ma, Mb = map(int, input().split())
ls = []
dp = np.full((1001,1001),float('inf'))
dp[0][0] = 0
for i in range(N):
  a,b,c = map(int, input().split())
  dp[a:,b:] = np.minimum(dp[:1001-a,:1001-b]+c, dp[a:,b:])
ans = float('inf')
for i in range(1,1001):
  if i*Ma>1000 or i*Mb>1000:
    break
  if dp[i*Ma,i*Mb]<ans:
    ans = dp[i*Ma,i*Mb]
if ans==float('inf'):
  ans = -1
print(int(ans))

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

struct StTrgLen
{
  StTrgLen() : m_nLenA(0), m_nLenB(0), m_nLenC(0) { }

  int m_nLenA;
  int m_nLenB;
  int m_nLenC;
};

struct StMatrl
{
  StMatrl() : m_nLenA(0), m_nLenB(0), m_nLenC(0) { }

  int m_nLenA;
  int m_nLenB;
  int m_nLenC;
};

void input(StTrgLen& roTrgLen, vector<int>& rvnMatLen)
{
  int nMatLenSiz;
  cin >> nMatLenSiz >> roTrgLen.m_nLenA >> roTrgLen.m_nLenB >> roTrgLen.m_nLenC;
  rvnMatLen.resize(nMatLenSiz);

  for (int& rnMatLen : rvnMatLen)
    cin >> rnMatLen;
}

int dfs(int nDpth, StTrgLen oTrgLen, StMatrl oMatrl, const vector<int>& cnrvnMatLen)
{
  if (nDpth == cnrvnMatLen.size())
    if ( oMatrl.m_nLenA && oMatrl.m_nLenB && oMatrl.m_nLenC )
      return  abs(oTrgLen.m_nLenA - oMatrl.m_nLenA)
            + abs(oTrgLen.m_nLenB - oMatrl.m_nLenB) 
            + abs(oTrgLen.m_nLenC - oMatrl.m_nLenC);
    else
      return 1 << 30; 

  int nMinMp = 0; 
  int nAddMp;

  nMinMp = dfs(nDpth + 1, oTrgLen, oMatrl, cnrvnMatLen);

  StMatrl oMatrlA(oMatrl);
  nAddMp = oMatrlA.m_nLenA ? 10 : 0;
  oMatrlA.m_nLenA += cnrvnMatLen[nDpth];
  nMinMp = min(nMinMp, dfs(nDpth + 1, oTrgLen, oMatrlA, cnrvnMatLen) + nAddMp);

  StMatrl oMatrlB(oMatrl);
  nAddMp = oMatrlB.m_nLenB ? 10 : 0;
  oMatrlB.m_nLenB += cnrvnMatLen[nDpth];
  nMinMp = min(nMinMp, dfs(nDpth + 1, oTrgLen, oMatrlB, cnrvnMatLen) + nAddMp);

  StMatrl oMatrlC(oMatrl);
  nAddMp = oMatrlC.m_nLenC ? 10 : 0;
  oMatrlC.m_nLenC += cnrvnMatLen[nDpth];
  nMinMp = min(nMinMp, dfs(nDpth + 1, oTrgLen, oMatrlC, cnrvnMatLen) + nAddMp);

  return nMinMp;
}

int calcMinCostTrgLen(StTrgLen oTrgLen, const vector<int>& cnrvnMatLen)
{
  StMatrl oMatrl;

  return dfs(0, oTrgLen, oMatrl, cnrvnMatLen);
}
 
int main()
{
  StTrgLen oTrgLen;
  vector<int> vnMatLen;

  input(oTrgLen, vnMatLen);
  cout << calcMinCostTrgLen(oTrgLen, vnMatLen) << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int A;
  double ans=0;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> A;
    ans += 1.0/(double)A;
  }
  cout << 1.0/ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int f=0,t=0,o=0;
  for(int i=0;i<n;i++){
    if(a[i]%4==0) f++;
    else if(a[i]%2==0) t++;
    else o++;
  }
  if(t+f==n){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(t>0) o++;
  if(f+1>=o) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;

int main()
{
    set<int > s;
    int q;
    cin>>q;
    int b,tp1;
    while(q--){
        cin>>tp1;
        if(tp1){
                cin>>b;
            if(s.find(b)!=s.end()){
                cout<<"1\n";
            }
            else{
                cout<<"0\n";
            }
        }
        else{
            cin>>b;
            s.insert(b);
            cout<<s.size()<<"\n";
        }
    }

}




Measured memory_bytes: 12380
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[1001][1001];

int main(){
	int n; cin >> n;
	while (n--){
		string X, Y; cin >> X >> Y;
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= X.size(); ++i){
			for (int j = 1; j <= Y.size(); ++j){
				if (X[i-1] == Y[j-1]) dp[i][j] = max(dp[i][j-1],max(dp[i-1][j],dp[i-1][j-1]+1));
				else dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
			}
		}
		cout << dp[(int)X.size()][(int)Y.size()] << '\n';
	}
}

Measured memory_bytes: 5124
#include<stdio.h>
#include<algorithm>
using namespace std;


static const int N = 200000;

int main(){
  int n;
  int A[N+1];
  scanf("%d", &n);

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

  int maxP = -2000000000;
  int minP = A[0];
  for(int i = 1; i < n; i++) {
    maxP = max(maxP, A[i] - minP);
    minP = min(minP, A[i]);
  }

  printf("%d\n", maxP);
  return 0;
}

Measured memory_bytes: 3496
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
using namespace std;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read(){
	   int x = 0;char c = getchar();
	   while (!isdigit(c)) c = getchar();
	   while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0' , c = getchar();
	   return x;
}
inline void write(int x){
	   if (!x){
          ptc('0');
          return;
	   }
	   int dg[20] , len = 0;
	   while (x) dg[len++] = x % 10 , x /= 10;
	   while (len--) ptc(dg[len]+'0');
}
inline void writeln(int x){
	   write(x);
	   ptc('\n');
}
const int N = 1e5 + 10;
const int M = 2e2 + 10;

int par[M << 1] , sz[M << 1];
int find(int x){
	if (par[x] != x){
		return par[x] = find(par[x]);
	}
	return par[x];
}
void merge(int x,int y){
//	printf("[] %d %d %d %d\n",x,y,find(x),find(y));
	x = find(x) , y = find(y);
	if (x != y){
		par[x] = y;
	}	
	sz[y]++;
}
int ind[M << 1] , outd[M << 1] , okay[M << 1];
int n , h;

int main(){
	scanf("%d%d",&n,&h);
	for (int i = 1;i <= h << 1;i++) par[i] = i;
	for (int i = 1;i <= n;i++){
		int A , B , C , D;
		scanf("%d%d%d%d",&A,&B,&C,&D);
		int l = C ? C : A + h , r = D ? D + h : B;
		merge(l , r);
		
//		printf("%d -> %d\n",l,r);
		outd[l]++;
		ind[r]++;
	}
	
	for (int i = 1;i <= h;i++){
		if (ind[i] < outd[i]) return puts("NO") , 0;
	}
	
	for (int i = 1 + h;i <= h << 1;i++){
		if (ind[i] > outd[i]) return puts("NO") , 0;
	}
//	printf("%d %d\n",ind[2],outd[2]);
	
	for (int i = 1;i <= h << 1;i++)
	if (ind[i] != outd[i] || !sz[find(i)]) {
//		printf("__ %d %d\n",i,find(i));
		okay[find(i)] = 1;
	}
	
	for (int i = 1;i <= h << 1;i++) if (!okay[find(i)]) {
//		printf("[%d]\n",i);
		return puts("NO") , 0;
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 384