akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int cnt[60];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        cnt[a]++;
        cnt[b]++;
    }
    rep(i, N) {
        cout << cnt[i] << endl;
    }

    return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    int res = 0;
    vector<int> a(M);
    for (int i = 0; i < M; ++i) {
        cin >> a[i];
        if (a[i] > M) ++res;
    }
    cout << res << endl;
}




Measured memory_bytes: 3104
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

H, W, M = MAP()
hw = [LIST() for _ in range(M)]

cnt_h = [0]*(H+1)
cnt_w = [0]*(W+1)

for h, w in hw:
	cnt_h[h] += 1
	cnt_w[w] += 1

h_max = max(cnt_h)
y = [0]*(H+1)
c_y = 0
for i in range(H+1):
	if cnt_h[i] == h_max:
		y[i] += 1


w_max = max(cnt_w)
x = [0]*(W+1)
for i in range(W+1):
	if cnt_w[i] == w_max:
		x[i] += 1

c = 0
for h, w in hw:
	if y[h] == 1 and x[w] == 1:
		c += 1

if c == sum(x)*sum(y):
	print(w_max+h_max-1)
else:
	print(w_max+h_max)





Measured memory_bytes: 133952
import itertools

n,m,q = map(int,input().split())
num = [list(map(int,input().split())) for i in range(q)]

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length
ans = 0

for i in range(length):#組み合わせの数回す
    sum = 0
    for j in range(q):
       if a[i][num[j][1]-1] - a[i][num[j][0]-1]  == num[j][2]:
            sum += num[j][3]
    ans = max(sum,ans)
print(ans)

Measured memory_bytes: 22272
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	
	priority_queue<long> que;
	long a[100000] = {};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		que.push(a[i]);
	}
	
	long temp;
	while(m--) {
		temp = que.top();
		que.pop();
		temp /= 2;
		que.push(temp);
	}
	
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += que.top();
		que.pop();
	}
	
	cout << sum;
}


Measured memory_bytes: 2168
import sys
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())

D = [-1] * N

for _ in range(M):
    s, c = map(int, input().split())

    if D[s-1] == -1 or D[s-1] == c:
        D[s-1] = c
    else:
        print('-1')
        exit()

if D[0] == -1 and N > 1:
    D[0] = 1
elif D[0] == -1 and N == 1:
    D[0] = 0
elif D[0] == 0 and N != 1:
    print('-1')
    exit()

ans = []

for d in D:
    if d == -1:
        ans.append(str(0))
    else:
        ans.append(str(d))

# print(ans)
print(''.join(ans))


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i, 0, n)cin >> a[i];
    ll ans = 0;
    ll digit = 1;
    rep(i, 0, 60){
        ll even = 0;
        ll odd = 0;
        rep(j, 0, n){
            if(a[j] & (1LL<<i))odd++;
            else even++;
        }
        ans += (odd*even%mod)*digit%mod;
        ans %= mod;
        digit = 2*digit%mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5448
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,m,a[100010],x,y,ans=0;
vector <pii> v;

int main()
{
	cin>>n>>m;
	rep(i,n) scanf("%lld",&a[i]);
	rep(i,m)
	{
		scanf("%lld%lld",&x,&y);
		v.pb({y,x});
	}
	sort(v.begin(),v.end());
	sort(a,a+n);
	int now=0;
	for(int i=m-1;i>=0;i--)
	{
		bool ok=true;
		rep(j,v[i].se)
		{
			if(now<n)
			{
				a[now]=max(a[now],v[i].fi);
				now++;
			}
			else
			{
				ok=false;
				break;
			}
		}
		if(!ok) break;
	}
	rep(i,n) ans+=a[i];
	cout<<ans<<endl;
	rt0;
}

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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n%2 == 1)
    {
        cout << "No";
        return 0;
    }
    for (int i = 0; i < n / 2;i++)
    {
        if(s[i] != s[n/2+i])
        {
            cout << "No";
            return 0;
        }
        
    }
    cout << "Yes";
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from heapq import heappop, heappush, heapify, heappushpop
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

X, Y = MAP()
i = 0
while 1:
	tmp = X*2**(i-1)
	if tmp > Y:
		break
	i += 1
print(i-1)
	

Measured memory_bytes: 3892
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>

int f(int n){
  if(n%4==0) return n;
  if(n%4==1) return 1;
  if(n%4==2) return n+1;
  if(n%4==3) return 0;

}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int a,b;
  cin>>a>>b;

  cout<<(f(b)^f(max(0LL,a-1)))<<endl;


}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

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

static const ll INF = 1e15;
static const ll mod = 1e9+7;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> vs(n);
    rep(i, n) cin >> vs[i];
    ll h = 0;
    ll sum = 0;
    rep(i, n) {
        auto diff = h - vs[i];
        sum += max(0LL, diff);
        chmax(h, vs[i]);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4840
// Hovalhagh
// Ya Aziz & Hakim
// AliReza Kaboli

#include <bits/stdc++.h>

using namespace std;

int main() {
	int cnt = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size() / 2; ++i) {
		if (s[i] != s[s.size() - i - 1])
			++cnt;
	}
	cout << cnt << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int a,b,c,k,aa,bb,cc;
long long int x = 1000000000000000000;
int main(){
    cin>>a>>b>>c>>k;
    aa=a-b;
    if(k%2==1)aa=aa*-1;
    if(abs(aa)>x)cout<<"Unfair"<<endl;
    else cout<<aa<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n,k;cin>>n>>k;
    vector<int> f(n+10);
    priority_queue<P> q;
    priority_queue<P,vector<P>,greater<P>> q2;
    for(int i=0;i<n;i++){
        int t,d;cin>>t>>d;
        q.push(P(d,t));
    }
    int co=0;
    ll x=0,s=0,ans=0;
    while(co<k){
        P p=q.top();q.pop();
        q2.push(p);
        s+=p.first;
        if(f[p.second]==0)x++;
        f[p.second]++;
        co++;
    }
    ans=s+x*x;
    while(!q.empty()){
        P p=q.top();q.pop();
        if(f[p.second])continue;
        ll m=-1;
        while(!q2.empty()){
            P p2=q2.top();q2.pop();
            if(f[p2.second]>1){
                f[p2.second]--;
                m=p2.first;
                break;
            }
        }
        if(m==-1)break;
        x++;
        f[p.second]++;
        s+=p.first;
        s-=m;
        ans=max(ans,s+x*x);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5232
'use strict'
 
 
 
function Main(input) {
  input = input.trim().split('\n')
  const N = parseInt(input[0])
  const array = input[1].split(' ')
  const S = array[0]
  const T = array[1]
  let ans = ''
  for(let i = 0; i < N; ++i) {
    ans += S[i]
    ans += T[i]
  }
 
  console.log(ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7496
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <string>
#include <sstream>
using namespace std;


int main() {
	vector<vector<int>> data(3, vector<int>(3));
	int n;
	vector <int> b(10);

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> data.at(i).at(j);
		}
	}

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> b.at(i);
	}

	for (int z = 0; z < n; z++) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (b.at(z) == data.at(i).at(j)) {
					data.at(i).at(j) = 0;
				}
			}
		}
	}
	int bingo_count = 0;

	for (int i = 0; i < 3; i++) {
		int a = count(data.at(i).begin(), data.at(i).end(), 0);
		if (a == 3) {
			bingo_count++;
			break;
		}
	}

	for (int i = 0; i < 3; i++) {
		if (data[0][i] == data[1][i] && data[1][i] == data[2][i] && data[2][i] == data[1][i]) {
			bingo_count++;
		}
	}

	if (data[0][0] == data[1][1] && data[2][2] == data[1][1] && data[0][0] == data[2][2]) {
		bingo_count++;
	}

	if (data[0][2] == data[1][1] && data[2][0] == data[1][1] && data[0][2] == data[2][0]) {
		bingo_count++;
	}

	string str;
	if (bingo_count >= 1) {
		str = "Yes";
	}
	else {
		str = "No";
	}
	
	cout << str;
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,w,s_w,s_v; cin>>n>>w;
    vector<vector<ll>> dp(n+1,vector<ll>(w+1,-1));
    dp[0][0]=0;
    rep(i,n){
        cin>>s_w>>s_v;
        rep(j,w+1){
            if(dp[i][j]==-1) continue;
            if(j<=w-s_w){
                if(dp[i+1][j+s_w]<dp[i][j]+s_v)
                dp[i+1][j+s_w]=dp[i][j]+s_v;
            }
            if(dp[i+1][j]<dp[i][j])
            dp[i+1][j]=dp[i][j];
        }
    }
    ll ans=0;
    rep(i,w+1) ans=max(ans,dp[n][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 80256
#include <stdio.h>
int main (void){
int a,b,r,d;
 
scanf("%d",&a) ;
scanf("%d",&b);
double f ;
 d=a/b ;
 r=a%b ;
 f=(double)a/(double)b ;
 printf("%d %d %lf",d,r,f) ;
 return 0;
 }    

Measured memory_bytes: 632
#include<stdio.h>
int main(void)
{
	int m,d,d1,d10,cnt,i,j;
	cnt=0;
	scanf("%d %d",&m,&d);
	for(i=1;i<=m;i++){
		for(j=1;j<=d;j++){
			d1=j%10;
			d10=j/10;
			if(d1>=2&&d10>=2&&d1*d10==i){
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main() {
  int n;
  int max = 0;
  long goukei = 0;
  cin >> n ;
  vector<int> a(n);
 
  for(int i = 0; i < n; i++) cin >> a[i];
 
  max = a[0];
  for(int i = 1; i < n; i++){
      if(a[i] > max){
          max = a[i];
      }else{
          goukei += (max - a[i]);
      }
  }

  cout << goukei << endl;
    
}

Measured memory_bytes: 3988
H, W, A, B = list(map(int, input().split()))

if A != 0 and B != 0:
    S = [1] * A + [0] * (W - A)
    T = [0] * A + [1] * (W - A)
    for _ in range(B):
        print(''.join(map(str, S)))
    for _ in range(H - B):
        print(''.join(map(str, T)))

elif A != 0 and B == 0:
    S = [1] * A + [0] * (W - A)
    for _ in range(H):
        print(''.join(map(str, S)))

elif A == 0 and B != 0:
    S = [1] * W
    T = [0] * W
    for _ in range(B):
        print(''.join(map(str, S)))
    for _ in range(H - B):
        print(''.join(map(str, T)))

else:
    S = [1] * W
    for _ in range(H):
        print(''.join(map(str, S)))

Measured memory_bytes: 42332
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int n, w, h, ww, hh;
	while (cin >> n, n)
	{
		cin >> w >> h;
		int tree[128][128];
		clear(tree, 0);
		while (n--)
		{
			int x, y;
			cin >> x >> y;
			--x, --y;
			tree[y][x] = 1;
		}
		cin >> ww >> hh;

		int sum[128][128];
		clear(sum, 0);
		for (int i = 0; i < h; ++i)
			for (int j = 0; j < w; ++j)
				sum[i + 1][j + 1] = sum[i][j + 1] + (sum[i + 1][j] - sum[i][j]) + tree[i][j];

		int res = 0;
		for (int i = 0; i + hh <= h; ++i)
			for (int j = 0; j + ww <= w; ++j)
				max_swap(res, sum[i + hh][j + ww] - (sum[i][j + ww] + sum[i + hh][j]) + sum[i][j]);
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#!/usr/bin/python
# -*- coding: utf-8 -*-
s = raw_input()
t = raw_input()
dd1 = {}
dd2 = {}
flag = True
for i in xrange(len(s)):
    c1, c2 = s[i], t[i]
    if dd1.get(c1, c2) != c2:
        flag = False
        break
    if dd2.get(c2, c1) != c1:
        flag = False
        break
    dd1[c1] = c2
    dd2[c2] = c1
print 'Yes' if flag else 'No'

Measured memory_bytes: 3072
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int X;
    cin >> X;
    if (X == 3 || X == 5 || X == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

#define MOD 1000000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int n, v[55], resp=0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            resp+=v[i]*v[j];
        }
    }
    cout << resp << endl;
    return 0;
}

Measured memory_bytes: 3600
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(a: int, b: int, x: int):
    B = b//x + 1
    A = (a-1)//x + 1
    print(B-A)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    solve(a, b, x)


if __name__ == '__main__':
    main()


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

using namespace std;
#define endl "\n"
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> pii;
const int N = 10;
int h, w, k, res;
char a[N][N];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> h >> w >> k;
    for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) cin >> a[i][j];
    for (int i = 0; i < (1 << h); ++i)
    for (int j = 0; j < (1 << w); ++j) {
        int cnt = 0;
        for (int i1 = 1; i1 <= h; ++i1) if (((1 << (i1 - 1)) & i) == 0)
        for (int j1 = 1; j1 <= w; ++j1)
            if (a[i1][j1] == '#' && (((1 << (j1 - 1)) & j) == 0))
                ++cnt;
        if (cnt == k) ++res;
    }
    cout << res;
    return 0;
}


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

int main(){
    long long n;
    cin>>n;
    long long ans;
    long long s=(long long)round(sqrt(n));
    if(s*s==n)ans=2*s-2;
    else{
        for(int i=s;i>0;i--){
            if(n%i==0){
                ans=i+n/i-2;
                break;
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
// AOJ 1510 Independent Research
// 2018.1.14 bal4u

#include <stdio.h>
#include <string.h>

char map[2][5][5][7];
int a[27], b[27];
int mv[26][3] = {{-1,-1,-1},{-1,-1,0},{-1,-1,1},{-1,0,-1},{-1,0,0},{-1,0,1},{-1,1,-1},{-1,1,0},{-1,1,1},
	             {0,-1,-1},{0,-1,0},{0,-1,1},{0,0,-1},{0,0,1},{0,1,-1},{0,1,0},{0,1,1},
	             {1,-1,-1},{1,-1,0},{1,-1,1},{1,0,-1},{1,0,0},{1,0,1},{1,1,-1},{1,1,0},{1,1,1}};
				 
int main()
{
	int cno, n, m, x, y, z, i;
	int t, xx, yy, zz, s, k1, k2;

	cno = 0;
	while (scanf("%d", &n) && n > 0) {
		for (z = 0; z < 5; z++) {
			for (y = 0; y < 5; y++) scanf("%s", map[0][z][y]);
		}
		memset(a, 0, sizeof(a)), memset(b, 0, sizeof(b));
		
		scanf("%d", &m); while (m--) scanf("%d", &t), a[t] = 1;
		scanf("%d", &m); while (m--) scanf("%d", &t), b[t] = 1;
		for (k1 = 0, k2 = 1; n--; k1 = k2, k2 = !k2) {
			for (z = 0; z < 5; z++) for (y = 0; y < 5; y++) for (x = 0; x < 5; x++) {
				s = 0;
				for (i = 0; i < 26; i++) {
					xx = x + mv[i][0], yy = y + mv[i][1], zz = z + mv[i][2];
					if (xx >= 0 && xx < 5 && yy >= 0 && yy < 5 && zz >= 0 && zz < 5) s += map[k1][zz][yy][xx] & 1;
				}
				if (map[k1][z][y][x] & 1) map[k2][z][y][x] = b[s] + '0';
				else 			          map[k2][z][y][x] = a[s] + '0';
			}
		}
		if (cno) putchar('\n');
		printf("Case %d:\n", ++cno);
		for (z = 0; z < 5; z++) {
			if (z > 0) putchar('\n');
			for (y = 0; y < 5; y++) puts(map[k1][z][y]);
		}
	}
	return 0;
}
		


Measured memory_bytes: 1804
#include <stdio.h>

int main(){
  int a,b,c;
  
  scanf("%d %d %d",&a,&b,&c);
  
  if(a==b && a!=c || b==c && b!=a || c==a && c!=b){
    printf("Yes");
  } else {
    printf("No");
  }
}

Measured memory_bytes: 128
N, K = map(int, input().split())
lis = list(map(int, input().split()))
sort_lis = sorted(lis)
p = 10**9+7
fac_lis = [[0] for i in range(N)]
fac_lis[0] = 1
max_ans = 0
min_ans = 0

for i in range(1,N):
  fac_lis[i] = fac_lis[i-1]*(i+1)%p

def combi(n,k):
  if n == k:
    return 1
  else:
    return fac_lis[n-1]*pow(fac_lis[k-1], p-2, p)*pow(fac_lis[n-k-1], p-2, p) % p

for i in range(K-1,N):
  max_ans += sort_lis[i]*combi(i, K-1)
  max_ans %= p
  
for i in range(N-K+1):
  min_ans += sort_lis[i]*combi(N-(i+1), K-1)
  min_ans %= p

ans = (max_ans - min_ans) % p
print(ans)

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

using namespace std;

const int N = 105;

int n;
int d[2][N];
pair<int, long long> res;
vector<int> G[N];
vector<int> vec[N];

void dfs(bool t, int u, int p) {
	for (auto v : G[u]) if (v != p) {
		d[t][v] = d[t][u] + 1, dfs(t, v, u);
	}
}

pair<int, long long> solve(int x, int y) {
	d[0][x] = d[1][y] = 1, dfs(0, x, x), dfs(1, y, y);
	int r1 = 0;
	for (int i = 1; i <= n; ++i) vec[i].clear();
	for (int i = 1; i <= n; ++i) {
		int tmp = min(d[0][i], d[1][i]);
		r1 = max(r1, tmp), vec[tmp].push_back(i);
	}
	long long r2 = vec[r1].size(), cur = 1;
	for (int i = r1 - 1; i >= 1; --i) {
		int mx = 0;
		for (auto j : vec[i]) {
			mx = max(mx, (int)G[j].size() - 1);
		}
		for (auto j : vec[i]) {
			r2 += (mx - (G[j].size() - 1)) * cur;
		}
		cur = cur * mx;
	}
	return make_pair(r1, r2);
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < (n - 1); ++i) {
		int u, v; cin >> u >> v;
		G[u].push_back(v), G[v].push_back(u);
	}
	res = {(int)1e9, (long long)1e18};
	for (int i = 1; i <= n; ++i) {
		res = min(res, solve(i, i));
		for (auto j : G[i]) res = min(res, solve(i, j));
	}
	cout << res.first << ' ' << res.second << '\n';
}

Measured memory_bytes: 256
N, K = map(int, input().split())
height = list(map(int,input().split()))
min_jump = [0,abs(height[0]-height[1])]

for num in range(2,N): #num is index of stone
  jump = 10**9
  if num < K:
    for n in range(num): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump.append(jump)
  else:
    for n in range(K): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump.append(jump)
print(min_jump[N-1])


Measured memory_bytes: 89924
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace std;

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int h, w;
  cin >> h >> w;
  map<char, int> mp;
  rep(i, 0, h) {
    string a;
    cin >> a;
    rep(j, 0, w) mp[a[j]]++;
  }
  int kc = 0;
  if(h == 1 && w == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  int hc = 4;
  if(h == 1 || w == 1) hc = 2;
  if(h % 2 == 1 || w % 2 == 1) kc = 1;
  if(h % 2 == 1 && w % 2 == 1) kc = 2;
  int ok = 0, k = 0, o = 0;
  rep(i, 0, 26) {
    if(mp.count('a' + i)) {
      if(mp['a' + i] >= hc) ok++;
      if(mp['a' + i] % 4 == 2) o++;
      if(mp['a' + i] % 2 == 1) k++;
    }
  }
  if(k > 1) {
    cout << "No" << endl;
    return 0;
  }
  if(!kc) {
    if(!k && ok && o == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }else if(kc == 1){
    if(h % 2 == 1) {
      if(o <= w / 2) cout << "Yes" << endl;
      else cout << "No" << endl;
    }else {
      if(o <= h / 2) cout << "Yes" << endl;
      else cout << "No" << endl;
    }
  }else {
    if(o <= w / 2 + h / 2) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


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

int main() {
  int H, W;
  string S;
  cin >> H >> W;
  for (int i=0; i<W+2; i++) cout << '#';
  cout << endl;
  for (int i=0; i<H; i++) {
    cin >> S;
    cout << '#' << S << '#' << endl;
  }
  for (int i=0; i<W+2; i++) cout << '#';
  cout << endl;
}


Measured memory_bytes: 256
///******* In the name of Allah *******///

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int m,n,i,j,k,ans,flag = 0;
    char a[113];
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    if(n%2!=0)
    {
        cout<<"No"<<endl;
    }
    else if(n%2==0)
    {
        ans = n/2;
        for(i=1,j=ans+1;i<=ans;i++,j++)
        {
            if(a[i]==a[j])
            {
                flag++;
            }
        }
        if(flag==ans)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}


//2
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){

ios::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin>>n;
cin>>s;
vector<int> a(n);

long long int a1=0;
long long int a2=0;
long long int a3=0;

for(int i=0;i<(int)s.size();i++){
if(s[i]=='R'){
a[i]=0;
a1++;
}
if(s[i]=='G'){
a[i]=1;
a2++;
}
if(s[i]=='B'){

a[i]=2;
a3++;
}

}



long long int res=1*a1*a2*a3;
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
int beg=j;
int mid=i;
int end=i+(i-j);
if(end<n){
if(a[beg]==a[mid])continue;
if(a[beg]==a[end])continue;
if(a[mid]==a[end])continue;
res--;
}

}
}


cout<<res<<endl;

}

//cout << fixed << setprecision(5) <<(n*2)*M_PI << endl;



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

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [(usize, usize); n]
    }
    let d = 1000000007;
    let mut st = vec![1; 8001];
    for i in 1..8001 {
        st[i] = st[i - 1] * i % d;
    }
    let sti: Vec<usize> = st.iter().map(|&x| inv_m(x, d)).collect();
    let mut dp = vec![vec![0; 4001]; 4001];
    for &(a, b) in &v {
        dp[2000 - a][2000 - b] += 1;
    }
    for i in 1..4001 {
        dp[0][i] = (dp[0][i] + dp[0][i - 1]) % d;
        dp[i][0] = (dp[i][0] + dp[i - 1][0]) % d;
    }
    for i in 1..4001 {
        for j in 1..4001 {
            dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % d;
        }
    }
    let mut ans = 0;
    for &(a, b) in &v {
        ans = (ans + dp[2000 + a][2000 + b] + d - st[2 * (a + b)] * sti[2 * a] % d * sti[2 * b] % d) % d;
    }
    ans = (ans * inv_m(2, d)) % d;
    println!("{}", ans);
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}

fn inv_m(n: usize, d: usize) -> usize {
    pow_m(n, d - 2, d)
}


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

using namespace std;

int main(void)
{
    int n, q;
    string s;
    cin >> n >> q;
    
    cin >> s;
    // cout << s.length() << endl;
    
    vector<pair<int, int>> lr;
    for (size_t i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        lr.push_back(pair<int, int>(l, r));
    }
    int list[s.length()];

    int count = 0;
    list[0] = count;
    for (size_t i = 1; i < s.length(); i++)
    {
        if(s.substr(i-1, 2) == "AC") count++;
        list[i] = count;
    }
    
    for (size_t i = 0; i < lr.size(); i++)
    {
        pair<int, int> buf = lr[i];
        cout << list[buf.second - 1] - list[buf.first -1] << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 2292
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	string S;
	cin>>N>>S;
	long long c=
		count(S.begin(),S.end(),'R')*
		count(S.begin(),S.end(),'G')*
		count(S.begin(),S.end(),'B');
		
	for(int i=0;i<N-2;i++){
		char I=S[i];
		for(int d=1;i+d+d<N;d++){
			char J=S[i+d];
			char K=S[i+d+d];
			if(I!=J && J!=K && K!=I)c--;
		}
	}
		
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = [0] * n
b = 1
for i in range(n):
	a[i] = list(map(int, input().split()))
for i in range(n - 1):
	for j in range(i + 1, n):
		for k in range(4):
			t = a[i][0]
			a[i][0] = a[i][1]
			a[i][1] = a[i][5]
			a[i][5] = a[i][4]
			a[i][4] = t
			for u in range(4):
				v = a[i][1]
				a[i][1] = a[i][2]
				a[i][2] = a[i][4]
				a[i][4] = a[i][3]
				a[i][3] = v
				if a[i] == a[j]:
					b = 0
		for k in range(4):
			t = a[i][0]
			a[i][0] = a[i][2]
			a[i][2] = a[i][5]
			a[i][5] = a[i][3]
			a[i][3] = t
			for u in range(4):
				v = a[i][1]
				a[i][1] = a[i][2]
				a[i][2] = a[i][4]
				a[i][4] = a[i][3]
				a[i][3] = v
				if a[i] == a[j]:
					b = 0
if b:
	print("Yes")
else:
	print("No")



Measured memory_bytes: 5612
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
    int n[60]={0};
    int sum;
    for(int a=0;a<10;a++)
    {
        for(int b=0;b<10;b++)
        {
            for(int c=0;c<10;c++)
            {

                for(int d=0;d<10;d++)
                {
                    sum=a+b+c+d;
                    n[sum]++;
                }
            }

        }
    }
    int num;
    while(scanf("%d",&num)!=EOF)
        printf("%d\n",n[num]);


    return 0;
}



Measured memory_bytes: 3204
def actual(N, M, K, A):
    # 各人のAの積集合の要素数が答え
    s = set(A[0])

    for a in A[1:]:
        s &= set(a)

    return len(s)


N, M = map(int, input().split())

K = []
A = []

for _ in range(N):
    ka = list(map(int, input().split()))
    K.append(ka[0])
    A.append(ka[1:])

print(actual(N, M, K, A))


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

typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


//===

const ll mod = static_cast<ll>(1e9 + 7);



int main() {
	int N;
	cin >> N;
	vector<Pll> xy(N);
	for (int i = 0; i < N; ++i) {
		cin >> xy[i].first >> xy[i].second;
	}

	vector<Pll> d;
	set<Pll> ds;
	for (int i = 0; i < N - 1; ++i) {
		for (int j = i + 1; j < N; ++j) {
			Pll tmp,mtmp;
			tmp.first = xy[i].first - xy[j].first;
			tmp.second = xy[i].second - xy[j].second;

			mtmp.first = -tmp.first;
			mtmp.second = -tmp.second;

			auto it1 = ds.find(tmp);
			auto it2 = ds.find(mtmp);
			if (it1 == ds.end()) {
				ds.insert(tmp);
				d.push_back(tmp);
			}
			if (it2 == ds.end()) {
				ds.insert(mtmp);
				d.push_back(mtmp);
			}
		}
	}

	set<Pll> s;
	for (int i = 0; i < N; ++i) {
		s.insert(xy[i]);
	}

	int ans = 10000000;
	for (auto val : d) {
		int ans_tmp = 0;
		for (int i = 0; i < N; ++i) {
			Pll next_xy;
			next_xy.first = xy[i].first + val.first;
			next_xy.second = xy[i].second + val.second;
			auto it = s.find(next_xy);
			if (it == s.end()) ++ans_tmp;
		}
		ans = min(ans, ans_tmp);
	}


	cout << (N == 1 ? 1 :ans) << endl;
}

Measured memory_bytes: 512
import itertools
import numpy as np
n,m,q = map(int, input().split())
array = np.array(list(itertools.combinations_with_replacement(range(1,m+1),n)))
result = np.zeros((len(array)), dtype="int")
for i in range(q):
    temp = 0
    a,b,c,d = map(int, input().split())
    where = array[:,b-1] - array[:,a-1] == c
    result[where] += d
print(max(result))

Measured memory_bytes: 46660
def middle(lst):
    _lst = lst
    _lst.sort()
    return _lst[-2]

def min_times(lst):
    data = lst
    times = 0
    idx_even = []
    idx_odd = []
    for i, v in enumerate(data):
        if v % 2 == 0:
            idx_even.append(i)
        else:
            idx_odd.append(i)
    odd_len = len(idx_odd)
    if odd_len in (0, 3):
        times += (max(data) - middle(data)) / 2
        times += (max(data) - min(data)) / 2
    if odd_len == 2:
        for i in idx_odd:
            data[i] += 1
        return min_times(data) + 1
    if odd_len == 1:
        for i in idx_even:
            data[i] += 1
        return min_times(data) + 1
    return times

use_data = [int(i) for i in raw_input().split()]

print(min_times(use_data))

Measured memory_bytes: 27884
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)
#define INF 100000000000 // long only


int main(){
  long x;
  scanf("%ld",&x);
  int max=2000;
  long a[max],b[max];
  F(i,0,max){
    a[i]=i;
    b[i]=pow(i,5);
  }
  F(i,0,max){
    F(j,0,max){
      if(b[i]-b[j]==x){
        printf("%ld %ld\n",a[i],a[j]);
        return 0;
      }else if(b[i]+b[j]==x){
        printf("%ld %ld\n",a[i],-a[j]);
        return 0;
      }

    }
  }
  return 0;
}

Measured memory_bytes: 2716
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> button (n);
  for (int i; i<n; i++) {
    string s;
    cin >> s;
    button[i] = stoi(s);
  }
  int count = 1;
  int x = button.at(0);
  while(true){
    if (count == n){
      cout << -1 << endl;
      break;
    }
    else{
      if(x==2){
        cout << count << endl;
        break;
      }
      else{
        count ++;
        x = button.at(x-1);
      }
    }
  }
}    

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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;

main(){
  int n,m; cin >> n >> m;
  vs a(n),b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];

  rep(i,n-m+1) rep(j,n-m+1) rep(k,m){
    if(b[k] != a[i+k].substr(j,m)) break;
    if(k==m-1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)
    elif op == '?':
        break


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

int main(){
    int N, count=0;
    string S;
    cin >> N >> S;
    for(int i=0; i<N-2; i++){
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,a[200200];
vector<long long> v;
map<int,int> m;
long long dd=0;
int bbb(int n)
{
	int s=1;
	while(true)
	{
		s*=2;
		if(s>n)
		  break;
	}
	return s;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		m[a[i]]++;
		if(a[i]>dd)
		  dd=a[i];
    }
    long long s=1,ans=0;
	sort(a,a+n);
	for(int i=n-1;i>=0;i--)
	{
		if(m[a[i]]<=0)continue;
		int x=a[i];
		int y=bbb(x)-x;
		if(m[y])
		{
			m[x]--;
			m[y]--;
			if(m[y]>=0)
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 20608
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

#define ll long long

#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)


using namespace std;

void solve();

int main(){

	solve();
	return 0;

}

void solve(){
	while (1) {
		vector<int> x;
		vector<int> y;
		x.clear();	y.clear();
		x.push_back(0);
		y.push_back(0);

		int n;
		cin >> n;
		if (n == 0)return;

		REP(i, n-1) {

			int ni, di;
			cin >> ni >> di;

			switch (di)
			{
			case 0:
				x.push_back(x[ni] - 1);
				y.push_back(y[ni]);
				break;
			case 1:
				x.push_back(x[ni]);
				y.push_back(y[ni] - 1);
				break;
			case 2:
				x.push_back(x[ni] + 1);
				y.push_back(y[ni]);
				break;
			case 3:
				x.push_back(x[ni]);
				y.push_back(y[ni] + 1);
				break;
			default:
				break;
			}

		}

		sort(x.begin(), x.end());	sort(y.begin(), y.end());

		cout << x[x.size()-1]-x[0] + 1 << ' ' << y[y.size()-1]-y[0]+ 1 << endl;
	}
}

Measured memory_bytes: 3116
N = int(raw_input())
Restaurant = {}
for i in xrange(N):
    city, score  = raw_input().split()
    if city in Restaurant.keys():
        Restaurant[city].append((int(score), i+1))
    else:
        Restaurant[city] = [(int(score), i+1)]

city_sort = sorted(Restaurant.keys())
for city in city_sort:
    score_sort = sorted(Restaurant[city], key=lambda x:x[0], reverse=True)
    for score in score_sort:
        print score[1]
        

Measured memory_bytes: 2568
import bisect
N = int(input())
A = [0 for i in range(N)]
for i in range(N):
    A[i] = int(input())
now = [-A[0]]
 
for i in range(1, N):
 
    index = bisect.bisect_right(now, -A[i])
    if index == len(now):
        now.append(-A[i])
    else:
        now[index] = -A[i]
print(len(now))

Measured memory_bytes: 11032
#include <bits/stdc++.h>
using namespace std;
//long long a[200005];
int main ()
{
    ///without test case
    long long int a,b,c,d,t,n,i,j;
    string s;
    cin >>s;
    b= s.size();
    for(i=0;i<b;i++)
    {
        cout<<"x";
    }
    cout<<"\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N,M,Q;
    cin >> N >> M >> Q;
    vector<int> a(Q);
    vector<int> b(Q);
    vector<int> c(Q);
    vector<int> d(Q);
    REP(i,Q)cin >> a[i] >> b[i] >> c[i] >> d[i];
    queue<string> tan;
    REP(i,M){
        tan.push(to_string(i));
    }
    REP(i,N-1){
        int si = tan.size();
        REP(l,si){
            string tmp = tan.front();
            tan.pop();
            for(int a = tmp[tmp.size()-1] - '0';a <= M - 1;a++){
                tan.push(tmp + to_string(a));
            }
        }
    }
    ll score = 0;
    int coco = tan.size();
    REP(i,coco){
        ll tmpsc = 0;
        string tmpo = tan.front();
        tan.pop();
        REP(l,Q){
            if(tmpo[b[l]-1] - tmpo[a[l]-1] == c[l])tmpsc+=d[l];
        }
        chmax(score,tmpsc);
    }
    cout << score << "\n";
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
//動画解説写し
int main(){
  long long n;
  cin>>n;
  vector<pair<long long,int>>fs;
  for(long long i=2;i*i<=n;++i){
    int x=0;
    while(n%i==0){
      n/=i;
      ++x;
    }
    fs.emplace_back(i,x);
  }
  if(n!=1)fs.emplace_back(n,1);
  int ans=0;
  for(auto p:fs){
    int x=p.second;
    int b=1;
    while(b<=x){
      x-=b;
      b++;
      ++ans;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 19760
#include<stdio.h>
#define INF 10000000;

int sum,i,j,k;

int matrixChainMultiplication(int p[],int n){
  int m[n+1][n+1];
  for(i=1;i<=n;i++) m[i][i]=0;

  for(int l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INF;
      for(k=i;k<j;k++){
	sum = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	if(m[i][j] > sum)m[i][j]=sum;
	}
    }
  }
  return m[1][n];
}

int main(){
  int n;
  scanf("%d",&n);
  int p[n+1];
  for(i=0;i<n;i++){
    scanf("%d%d",&j,&k);
    p[i]=j;
    p[i+1]=k;
  }
  printf("%d\n",matrixChainMultiplication(p,n));
  return 0;
  
}



Measured memory_bytes: 2148
#include <iostream>
using namespace std;
int a[200005],qwq[500005],now;
int qaq=200000;
int main(int argc, char** argv) {
	int n;
	long long ans=0;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
		if(a[i]<=n) ans+=qwq[qaq+a[i]-now];
		if(a[i]<=n) ++qwq[qaq-a[i]-now];
		++now;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

  
int main()
{
  ll N;
  cin >> N;
  vector<vector<int>> A(N,vector<int>(2));
  vector<vector<int>> B(N,vector<int>(2));
  REP(i, N){
    REP(j, 2){
      cin >> A.at(i).at(j);
    }
    B.at(i).at(0)=A.at(i).at(0)+A.at(i).at(1);
    B.at(i).at(1)=A.at(i).at(0)-A.at(i).at(1);
  }
  
  sort(ALL(B));
  int now = B.at(0).at(0);
  int cnt = 1;
  FOR(i,1,N){
    if(now<=B.at(i).at(1)){
      cnt++;
      now=B.at(i).at(0);
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 11136
// https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(h,w);
    ll p= ceil(w,2);
    ll ans= h/2*w;
    if(h!=1 && w!=1) out(((h%2==0)?ans:ans+p));
    else out(1);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Volume0 {
	class Program {
		public static void Main() {
			List<int> result = new List<int>();
			string line;
			while((line = Console.ReadLine()) != null) {
				string[] input = line.Split(new char[]{','}).ToArray();
				int s = int.Parse(input[0]);
				double w = double.Parse(input[1]);
				double h = double.Parse(input[2]);
				if (BMI(h, w) >= 25) result.Add(s);
			}

			result.ForEach(Console.WriteLine);
		}

		private static double BMI(double height, double weight) {
			return weight / height / height;
		}
	}
}



Measured memory_bytes: 9488