akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> F(N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 10; ++j) {
      int f;
      cin >> f;
      F[i] |= (f << j);
    }
  vector<vector<int>> P(N, vector<int>(11));
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 11; ++j) cin >> P[i][j];
  int ans = -1 << 30;
  for (int i = 1; i < (1 << 10); ++i) {
    int t = 0;
    for (int j = 0; j < N; ++j) t += P[j][__builtin_popcount(F[j] & i)];
    ans = max(ans, t);
  }
  cout << ans << endl;
  return 0;
}

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

const int maxn = 3e5;
int n, a[maxn + 3], m[2], b[2][maxn + 3], c[maxn + 3];

void add(int x, int y) {
	for (int i = x; i <= maxn; i += i & -i) c[i] += y;
}

int sum(int x) {
	int y = 0;
	for (int i = x; i; i ^= i & -i) y += c[i];
	return y;
}

int solve(int a[], int n) {
	int res = 0;
	for (int i = n; i; i--) res += sum(a[i]), add(a[i], 1);
	memset(c, 0, sizeof(c));
	return res;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) {
		if ((a[i] ^ i) & 1) puts("No"), exit(0);
		b[i & 1][++m[i & 1]] = a[i];
	}
	puts((solve(b[0], m[0]) + solve(b[1], m[1])) * 3 - solve(a, n) ? "No" : "Yes");
	return 0;	
}

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

int main(){
    int n;
    cin >> n;
    char c[11];
    pair<pair<string,int>,int> p[101];

    for (int i=0;i<n;i++){
        int temp;
        scanf("%s%d",c,&temp);
        p[i]=make_pair(make_pair(c,-temp),i+1);
    }
    sort(p,p+n);
    for (int j=0;j<n;j++)printf("%d\n",p[j].second);
}


Measured memory_bytes: 3792
N = int(input())

ans = 0
ctable = [[0 for _ in range(10)] for _ in range(10)]

for n in range(1, N+1):
    first = int(str(n)[0])
    last = int(str(n)[-1])
    ctable[first][last] += 1

for i in range(10):
    for j in range(10):
        ans += ctable[i][j] * ctable[j][i]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[])
{
    while (1)
    {
        int x, y, s;
        cin >> x >> y >> s;
        if (x + y + s == 0) return 0;
        int ans = 0;
        for (int i = 1; i < s; ++i)
        {
            for (int j = 1; j < s; ++j)
            {
                if (i * (100 + x) / 100 + j * (100 + x) / 100 == s)
                {
                    ans = max(ans, i * (100 + y) / 100 + j * (100 + y) / 100);
                }
            }
        }
        cout << ans << "\n";
    }

    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  ll MOD = 1000000000+7;
  string s;
  cin >> n;
  cin >> s;
  ll abc[30];
  REP(i,30) abc[i] = 1;
  ll ans = 1;
  REP(i,n){
    abc[s[i]-'a']++;
  }
  REP(i,(ll)('z'-'a'+1)){
    ans *= abc[i];
    ans %= MOD;
  }
  ans -= 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#define NMAX 100002
#define INF (int)1e9
using namespace std;
int N,K,H[NMAX],dp[NMAX] ={};

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

	for (int i = 1; i < N; ++i)
	{
		dp[i] = INF;
		for (int j = 1; j <= min(i,K); ++j)
		{
			dp[i] = min(dp[i],dp[i-j]+abs(H[i]-H[i-j]));
		}
	}
	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    a, b, c, d = map(int, input().split())
    while a > 0 and c > 0:
        c -= b
        if c <= 0:
            print("Yes")
            exit()
        a -= d
        if a <= 0:
            print("No")
            exit()
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 9872
N,M = map(int,input().split())
H = list(map(int, input().split()))
R = [[0] for x in range(N)] 
for x in range(M):
    A,B = map(int,input().split())
    R[A-1].append(B-1)
    R[B-1].append(A-1)
ans =0
for x in range(N):
    ii =True
    for y in R[x][1:]:
        if H[x]<=H[y]:
            ii =False
            break
    if ii ==True:
        ans +=1
        
print(ans)

Measured memory_bytes: 32868
n=int(input())
arr=[input() for _ in range(n)]
dic={}
for i in range(n): #各単語の出現回数を数える
 if arr[i] not in dic:
   dic[arr[i]]=1
 else:
   dic[arr[i]]+=1
largest=max(dic.values()) #最大の出現回数を求める
ans=[]
for keys in dic.keys():
 if dic[keys]==largest: #出現回数が最も多い単語を集計する
   ans.append(keys)
ans=sorted(ans) #単語を辞書順に並べ替えて出力する
for words in ans:
 print(words)

Measured memory_bytes: 38452
N = int(input())
ABC = 'abcdefghijklmnopqrstuvwxyz'
ans = []

while(1):
    if(N%26 == 0):
        ans.append(N%26) #その時の桁数
        N = int(N/26) -1#残り
    else:
        ans.append(N%26) #その時の桁数
        N = int(N/26) #残り
    #0になったら
    if N == 0:
        break
        
A = ""
ans.reverse()

for i in ans:
    if i == 0:
        A += 'z'
    else:
        A += ABC[i-1]
        
print(A)

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
//#define MOD 100000007
int N;
int k;
using Graph = vector<vector<pair<int,long long>>>;
vector<long long> color(100000,0);
vector<bool> ans(100000,false);

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};


void bfs(Graph &data, int t)
{
    for(int i = 0;i<(int)data[t].size();i++)
    {
        if(!ans[data[t][i].first])
        {
            ans[data[t][i].first] = true;
            color[data[t][i].first] = (color[t] + data[t][i].second)%2;
            bfs(data,data[t][i].first);
        }
    }
    return;
}

int main()
{
    cin >> N;
    
    Graph data(N);
    
    for(int i=0;i<N-1;i++)
    {
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        pair<int,long long> p = make_pair(b,c);
        pair<int,long long> q = make_pair(a,c);
        data[a].push_back(p);
        data[b].push_back(q);
    }
    
    ans[0] = true;
    bfs(data,0);
    
    for(int i = 0;i<N;i++)
    {
        cout << color[i]%2 << endl;
        
    }
    
    
    //cout << ans << endl;
    
    return 0;
}

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

Measured memory_bytes: 13980
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n;
  ll x;
  cin >> n >> x;
  vector<ll> a;
  for(int i = 0; i < n; i++){
    ll y;
    cin >> y;
    a.pb(y);
  }
  ll res = 0;
  for(int i = 1; i < n; i++){
    if(a[i - 1] + a[i] > x){
      res += a[i - 1] + a[i] - x;
      a[i] = max((ll)0, x - a[i - 1]);
    }
  }
  cout << res << endl;
	return 0;
}


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

tuple<int, int, int> get(int a, int b, int c) {
    int x = (a + b - c);
    int y = (a - b + c);
    int z = (-a + b + c);
    if (x % 2 || y % 2 || z % 2) {
        return {-1, -1, -1};
    }
    return {x / 2, y / 2, z / 2}; 
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    while (cin >> n) {
        // (x + y) ** 2 + (x + z) ** 2 + (y + z) ** 2 == 2 * n
        for (int num = 2; num <= 2 * n; num += 2) {
            int cnt = 0;
            for (int i = 2; i * i < num; i++) {
                for (int j = 2; i * i + j * j < num; j++) {
                    int remain = num - i * i - j * j;
                    if (remain <= 0) continue;
                    int k = sqrt(remain);
                    if (k * k == remain) {
                        auto[x, y, z] = get(i, j, k);
                        if (x >= 1 && y >= 1 && z >= 1) {
                            cnt++;
                        }
                    }
                }
            }
            cout << cnt << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3524
#include "bits/stdc++.h"
using namespace std;
int main(){
    string s;
    cin >> s;
    vector<int> a(26,0);
    int i,n=s.size();
    for(i=0;i<n;i++) a.at(s.at(i)-'a')++;
    for(i=0;i<26;i++){
        if(a.at(i)%2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10桁出力 cout << setprecision(10) << double;
#include <queue>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	LL n, x;
	cin >> n >> x;

	vector<LL> a(n, 0);

	FOR(i, 0, n) {
		a[i] = IN<LL>();
	}

	LL ans = 0;

	LL i = 0;
	while (i < n-1) {
		if (a[i] + a[i + 1] > x) {	// 500 2 3   ans 3 0 2
			// over
			LL tmp = a[i + 1];

			if (x - a[i] >= 0) {
				a[i + 1] = x - a[i];
				ans += tmp - a[i + 1];
			}
			else {
				ans += (-1)*(x-a[i]) + a[i+1];
				a[i + 1] = 0;
				a[i] = (-1)*(x - a[i]);
				


				//a[i] -= (-1)*a[i + 1];
				//ans += a[i + 1] + tmp;

				//a[i + 1] = 0;
			}
		}
		i++;
	}
	cout << ans << endl;
	/*FOR(i, 0, n) {
		cout << "a[" << i << "]=" << a[i] << endl;
	}*/

	return 0;
}

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

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

///////////////////////

int const N = 2e3 + 41;
int const INF = 1e9 + 41;

int n;
int a[N], b[N], r[N], l[N];
string s1, s2;
int ans = INF;

void answer(int v){
	cout << v << endl;
	exit(0);
}

void read(){
	cin >> s1 >> s2;
	if(s1 == s2) answer(0);
	int cnt = 0;
	fr(i, 0, sz(s2)) if(s2[i] == '1') ++cnt;
	if(cnt == 0) answer(-1);
	n = sz(s1);
	fr(i, 0, n) a[i] = s1[i] - '0', b[i] = s2[i] - '0';
}

vector<pii> v;

int getSufMax(int val){
	int l = -1;
	int r = sz(v);
	while(r-l>1){
		int m = (l+r)/2;
		if(v[m].first > val) r = m;
		else l = m;
	}
	if(r == sz(v)) return 0;
	else return v[r].second;
}

int getMinWay(int a, int b){
	if(a > b) swap(a, b);
	int ret = b - a;
	ret = min(ret, a + n - b);
	return ret;
}

void solveLR(){
	fr(fs, 0, n){
		v.clear();
		int cntFlip = 0;
		fr(i, 0, n){
			int p = (i - fs + n) % n;
			if(b[p] != a[i]){
				++cntFlip;
				v.pb(mp(l[i], r[i]));
			}
		}
		sort(v.begin(), v.end());
		fdr(i, 0, sz(v)){
			if(i + 1 < sz(v)) v[i].second = max(v[i].second, v[i+1].second);
		}
		fr(ls, 0, n){
			int rs = getSufMax(ls);
			int fp = (rs - ls) % n;
			if(fp < 0) fp += n;
			int cur = cntFlip;
			if(rs > 0){
				cur += ls * 2;
				cur += rs;
				fp = (fp + ls) % n;
			}else{
				cur += ls;
			}
			cur += getMinWay(fp, (0 - fs + n) % n);
			ans = min(ans, cur);
		}
	}
}

void solveRL(){
	fr(fs, 0, n){
		v.clear();
		int cntFlip = 0;
		fr(i, 0, n){
			int p = (i + fs + n) % n;
			if(b[p] != a[i]){
				++cntFlip;
				v.pb(mp(r[i], l[i]));
			}
		}
		sort(v.begin(), v.end());
		fdr(i, 0, sz(v)){
			if(i + 1 < sz(v)) v[i].second = max(v[i].second, v[i+1].second);
		}
		fr(rs, 0, n){
			int ls = getSufMax(rs);
			int fp = (rs - ls) % n;
			if(fp < 0) fp += n;
			int cur = cntFlip;
			if(ls > 0){
				cur += rs * 2;
				cur += ls;
				fp = (fp - rs + n) % n;
			}else{
				cur += rs;
			}
			cur += getMinWay(fp, (0 + fs) % n);
			ans = min(ans, cur);
		}
	}
}


void solve(){
	fr(i, 0, n){
		while(b[(i + r[i]) % n] == 0){
			++r[i];
		}
		while(b[(i - l[i] + n) % n] == 0){
			++l[i];
		}
	}
	solveLR();
	solveRL();
	answer(ans);
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	read();
	solve();



	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

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


Measured memory_bytes: 256
n = int(input())
H = list(map(int, input().split()))
H2 = [0]*n
H3 = [0]*n

for i in range(n):
  H2[i] = H[i] - i 
  H3[i] = - (H[i] + i)
#Hb - iB = - (iA + Ha)
#-(Ha - iA) = Hb + iB

import collections 
c2 = collections.Counter(H2)
c3 = collections.Counter(H3)

ans = 0
for k2 in c2:
  if k2 in c3:
    ans += c3[k2] * c2[k2]
print(ans)  
#iB - iA = Ha + Hb
#iA - iB = Ha + Hb
#Hb - iB = - (iA + Ha)
#-(Ha - iA) = Hb + iB

Measured memory_bytes: 127476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N, M;
    cin >> N >> M;
    int p[M];
    string S[M];
    for (int i = 0; i < M; i++) {
        cin >> p[i] >> S[i];
        p[i]--;
    }
    int flag[N]{};
    int k[N]{};
    for (int i = 0; i < M; i++) {
        if (flag[p[i]] == 0) {
            if (S[i] == "WA") {
                k[p[i]]++;
            } else {
                flag[p[i]] = 1;
            }
        }
    }
    int t1 = 0;
    int t2 = 0;
    for (int i = 0; i < N; i++) {
        if (flag[i] == 1) {
            t1++;
            t2 += k[i];
        }
    
    }
    cout << t1 << " " << t2 << "\n";
    return 0;
}

Measured memory_bytes: 6912
N = int(input())
HXY = []
for i in range(N):
    x,y,h = map(int, input().split())
    HXY.append((h,x,y))



HXY.sort(reverse=True)

for cx in range(101):
    for cy in range(101):
        H = HXY[0][0] + abs(HXY[0][1] - cx) + abs(HXY[0][2] - cy)
        is_valid = True
        for h,x,y in HXY:
            if h == max(H - abs(x - cx) - abs(y - cy), 0):
                continue
            else:
                is_valid = False
                break
        if is_valid:
            print(cx, cy, H)
            exit()
             

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

using namespace std;

#define pb push_back
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define mem(a) memset(a,0,sizeof(a))
#define all(x) x.begin(),x.end()
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

const int mn = 5e5 + 5;
const int mod = 1e9 + 7;

struct edge {
    int to, dist;
};

int n, m;
map<pii, int> h;
int cnt;
vector<edge> g[mn];
int ans;

inline void add_edge(int u, int v, int w) {
    int u1, v1;
    pii p{u, w};
    if (!h.count(p)) {
        h[p] = ++cnt;
        g[cnt].pb({u, 1});
        g[u].pb({cnt, 1});
    }
    u1 = h[p];
    p = make_pair(v, w);
    if (!h.count(p)) {
        h[p] = ++cnt;
        g[cnt].pb({v, 1});
        g[v].pb({cnt, 1});
    }
    v1 = h[p];
    g[u1].pb({v1, 0});
    g[v1].pb({u1, 0});
}

struct node {
    int id, dist;

    bool operator<(const node &p) const {
        return dist > p.dist;
    }
};

int dist[mn];
priority_queue<node> q;

void dijk(int s, int t) {
    memset(dist, 1, sizeof dist);
    q.push({s, dist[s] = 0});
    while (!q.empty()) {
        node u = q.top();
        q.pop();
        if (dist[u.id] < u.dist) continue;
        for (auto &i:g[u.id]) {
            int nxtdist = i.dist + u.dist;
            if (dist[i.to] > nxtdist) {
                dist[i.to] = nxtdist;
                q.push({i.to, nxtdist});
            }
        }
    }
}

int main() {
#ifdef LOCAL
    freopen("../1.txt", "r", stdin);
    freopen("../2.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &m);
    cnt = n;
    for (int i = 1; i <= m; i++) {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        add_edge(u, v, w);
    }
    dijk(1, n);
    ans = dist[n];
    if (ans > 1e7) {
        ans = -2;
    }
    printf("%d\n", ans/2);
}


Measured memory_bytes: 58108
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

int N;
int A[100010];
std::vector<std::vector<int>> win;

int dfs(int pos) {
    if(win[pos].size() == 0) {
        return 0;
    }
    
    std::vector<int> height;
    height.reserve(win[pos].size());
    
    for(auto& w : win[pos]) {
        height.push_back(dfs(w));
    }
    std::sort(height.begin(), height.end(), std::greater<int>());
    
    for(int i = 0; i < height.size(); ++i) {
        height[i] += i + 1;
    }
    
    return *std::max_element(height.begin(), height.end());
}

int main() {
    std::cin >> N;
    
    win.resize(N);
    for(int i = 1; i < N; ++i) {
        std::cin >> A[i];
        --A[i];
        win[A[i]].push_back(i);
    }
    
    std::cout << dfs(0) << std::endl;
}

Measured memory_bytes: 20224
// ayy
// ' lamo
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld; //CARE
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
const ld eps=1e-8;
const int inf=1e9+99;
const ll linf=1e18+99;
const int P=1e9+7;













int32_t main() {
	string S; cin>>S;
	for(int i=0;i<=(int)S.size()-2;i++) if(S.substr(i,2)=="AC") return cout<<"Yes"<<endl,0;
	cout<<"No"<<endl;
}













Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#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 ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<double,double>;
using vvi = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
    int x; cin >> x;
    cout << (x == 1 ? 0:1) << endl;
}



Measured memory_bytes: 3604
"""
NTC here
"""


#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

profile = 0
pypy = 1


def iin(): return int(input())


def lin(): return list(map(int, input().split()))



def main():
    T = 1
    while T:
        T -= 1
        n = iin()
        a = lin()
        ans = [1 for i in range(n) if a[i]%2 and i%2==0]
        print( sum(ans) if ans else 0)




    
        










    




                

        

 
 
 
 
 
 
# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
if pypy:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
    input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
if __name__ == "__main__":
    if profile:
        import cProfile
        cProfile.run('main()')
    else:
        main()


Measured memory_bytes: 62704
#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
    long i,j;
    long n;
    long q;
    long cnt = 0;
    static long S[10000];
    static long T[500];

    scanf("%ld",&n);
    for (i = 0; i < n; i++) {
        scanf("%ld",&S[i]);
    }

    scanf("%ld",&q);
    for (i = 0; i < q; i++) {
        scanf("%ld",&T[i]);
    }

    for (i = 0; i < q; i++) {
        for (j = 0; j < n; j++) {
            if(T[i] == S[j]) {
                cnt++; break;
            }
        }
    }

    printf("%ld\n",cnt);

    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

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

void solve() {
  int primes[] = {3, 13, 23, 43, 53, 73, 83, 103, 113, 163, 173, 193, 223, 233, 263, 283, 293, 313, 353, 373, 383, 433, 443, 463, 503, 523, 563, 593, 613, 643, 653, 673, 683, 733, 743, 773, 823, 853, 863, 883, 953, 983, 1013, 1033, 1063, 1093, 1103, 1123, 1153, 1163, 1193, 1213, 1223, 1283, 1303};
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    printf("%d ", primes[i]);
  } 
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3752
fun main(arr:Array<String>) {
    val (q,h,s,d) = readLine()!!.split(" ").map { it.toLong() }
    val n = readLine()!!.toLong()

    val oneL = listOf(q*4, h*2, s).min()!!
    val twoL = listOf(oneL*2, d).min()!!

    var ans = (n/2)*twoL
    if(n%2!=0L) {
        ans+=oneL
    }
    println(ans)
}


Measured memory_bytes: 36020
N = int(raw_input())
a = [int(raw_input()) for _ in range(N)]

flag = [False] * N

current = 1
count = 0

for i in range(N):
    count += 1
    current = a[current - 1]
    if current == 2:
        break
    elif i == (N - 1):
        count = -1
    elif flag[current - 1]:
        count = -1
        break
    else:
        flag[current - 1] = True

print(count)

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

using namespace std;
using ll=long long;

int main()
{
    int n;cin >>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        int co=0;
        for(int j=1;j<=i;j++){
            if(i%j==0)co++;
        }
        if(co==8&&i%2==1)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
ac, wa, tle, re = 0, 0, 0, 0
N.times do
    s = gets.chomp
    if s == "AC"
        ac += 1
    elsif s == "WA"
        wa += 1
    elsif s == "TLE"
        tle += 1
    else
        re += 1
    end
end

puts "AC x #{ac}"
puts "WA x #{wa}"
puts "TLE x #{tle}"
puts "RE x #{re}"
  

Measured memory_bytes: 14132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 205;
int n,g[N][N]; ll f;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
            g[i][j]=__gcd(i,j);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
            for(int k=1;k<=n;++k) f+=g[g[i][j]][k];
    printf("%lld\n",f);
}

Measured memory_bytes: 3884
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int H = intArray[0];
            int N = intArray[1];
            int[] Power = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int sum = Power.Sum();
            if(H <= sum)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 35964
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    rep(i, s.size() - 1){
        if(s.substr(i, 2) == "AC") {
            output("Yes");
            return 0;
        }
    }
    output("No");
    return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, K, S;
  cin >> N >> K >> S;
  const int MX = 1000000000;
  for(int i = 0; i < K; i++) cout << S << " ";
  for(int i = K; i < N; i++) cout << (S == MX ? MX - 1 : MX) << " ";
  cout << endl;
}

Measured memory_bytes: 1280
import java.util.Scanner;
public class Main {
	public static void main (String[]args) {
		Scanner teclado = new Scanner (System.in);
		int a;
		int b;
		a=teclado.nextInt();
		b=teclado.nextInt();
		
		if(a >=0 && a <=100 && b%2==0 && b >=2 && b <=1000) {
			if(a >= 13 ) {
				System.out.println(b);
			}else if(a >=6 && a <= 12) {
				System.out.println(b/2);
			}else {
				System.out.println(0);
			}
		}
		
		
	}
}




Measured memory_bytes: 22868
/******************************************
* AUTHOR : SARTHAK GUPTA *
* NICK : SOPHOZAAR *
* INSTITUTION : BIT MESRA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int n, m;
std::vector<int> adj[N];
int longest[N];

void dfs(int x) {
	if(longest[x])
		return;

	for(int i = 0; i < adj[x].size(); i++) {
		dfs(adj[x][i]);
		longest[x] = max(longest[x], longest[adj[x][i]]);
	}

	longest[x]++;

}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);

cin >> n >> m;
for(int i = 0; i < m; i++) {
	int x, y;
	cin >> x >> y;
	adj[x].push_back(y);
}

for(int i = 1; i <= n; i++) {
		dfs(i);
}
int result = 0;
for(int i = 1; i <= n; i++) {
	result = max(result, longest[i]);
}
cout << result - 1 << "\n";


return 0;
}

Measured memory_bytes: 8192
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,m,K;

int ned[22][22][2];

int f[(1<<19)+5],g[(1<<19)+5];

void Work(){
	f[0]=1;
	REP(i,0,m-1)
		REP(j,0,n-1){
			memcpy(g,f,sizeof(f));memset(f,0,sizeof(f));
			REP(sta,0,(1<<n)-1)if(g[sta]){
				int c=(sta>>j)&1;
				if(c){
					if(!ned[i][j][0])(f[sta]+=g[sta])%=mod;
				}
				else{
					if(!ned[i][j][1])(f[sta]+=g[sta])%=mod;
					if(!ned[i][j][0]){
						int nxt=sta;
						nxt&=((1<<n)-1)^((1<<j)-1);
						int pos=nxt&(-nxt);
						nxt=sta^pos;
						nxt^=1<<j;
						(f[nxt]+=g[sta])%=mod;
					}
				}
			}
		}
	int ans=0;
	REP(sta,0,(1<<n)-1)(ans+=f[sta])%=mod;
	iout(ans);
}

void Init(){
	read(n,m,K);n--;
	REP(i,1,K){
		int x,y,z;
		read(x,y,z);
		ned[x-1][y-1][z]=1;
	}
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 4352
//★#1014918 Solution for 0557: A First Grader by daiota
#include<iostream>
using namespace std;
 
int a[110];
long long dp[110][25];
int main(){
	int i,j;
	int N;
	cin >> N;
	for(i=1; i<=N; i++) {cin >> a[i];}
	dp[1][a[1]] = 1;
	for(i=2; i<N; i++){
		for(j=0; j<=20; j++){
			if(j-a[i] >=  0) dp[i][j] += dp[i-1][j-a[i]];
			if(j+a[i] <= 20) dp[i][j] += dp[i-1][j+a[i]];
		}
	}
	cout << dp[N-1][a[N]] << endl;
	return 0;
}



Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        
        if (n % 2 != 0) {
            System.out.println(0);
            return;
        }
        
        long count = 0;
        long now = 2;
        while (true) {
            now *= 5;
            if (now > 1000000000000000000L) break;
            
            count += n / now;
        }
        
        System.out.println(count);
    }
}

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

struct name{
  string s;
  name(string x):s(x){}

  bool operator<(const name a)const{
    if(s.size()==a.s.size())return s<a.s;
    return s.size()<a.s.size();
  }
};

int main(){
  int n,num;
  string s;

  std::ios::sync_with_stdio(false);

  cin >> n;
  map<name,int> m;
  for(int i=0;i<n;i++){
    cin >> s >> num;
    m[name(s)] += num;
  }

  map<name,int>::iterator it;
  for(it = m.begin();it != m.end();it++){
    cout << (*it).first.s << " " << (*it).second << endl;
  }
}

Measured memory_bytes: 1232
A_11,A_12,A_13 = map(int, input().split())
A_21,A_22,A_23 = map(int, input().split())
A_31,A_32,A_33 = map(int, input().split())
N=int(input())
b = []
for _ in range(N):
    b.append(int(input()))

A_11j,A_12j,A_13j,A_21j,A_22j,A_23j,A_31j,A_32j,A_33j=[0,0,0,0,0,0,0,0,0]
r=[]
if A_11 in b:
  A_11j=1
if A_12 in b:
  A_12j=1
if A_13 in b:
  A_13j=1
if A_21 in b:
  A_21j=1
if A_22 in b:
  A_22j=1
if A_23 in b:
  A_23j=1
if A_31 in b:
  A_31j=1
if A_32 in b:
  A_32j=1
if A_33 in b:
  A_33j=1

  
if(A_11j==1)&(A_12j==1)&(A_13j==1):
  r="Yes"
elif(A_21j==1)&(A_22j==1)&(A_23j==1):
  r="Yes"
elif(A_31j==1)&(A_32j==1)&(A_33j==1):
  r="Yes"
elif(A_11j==1)&(A_21j==1)&(A_31j==1):
  r="Yes"
elif(A_12j==1)&(A_22j==1)&(A_32j==1):
  r="Yes"
elif(A_13j==1)&(A_23j==1)&(A_33j==1):
  r="Yes"
elif(A_11j==1)&(A_22j==1)&(A_33j==1):
  r="Yes"
elif(A_13j==1)&(A_22j==1)&(A_31j==1):
  r="Yes"
else:
  r="No"
  
print(r)

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

int main() {
	int n, m;
	while (cin >> n >> m, n, m) {
		int g[500][500] = {};

		for (int i = 0;i < m;i++) {
			int a, b;
			cin >> a >> b;
			g[a - 1][b - 1] = 1;
			g[b - 1][a - 1] = 1;
		}

		bool fri[500];
		for (int i = 0;i < 500;i++) { 
			fri[i] = false;
			if (g[0][i] == 1)fri[i] = true;
		}

		vector<int>v;
		for (int i = 0;i < n;i++) {
				for (int j = 0;j < n;j++) {
					if (fri[i] == true && g[i][j] == 1) {
						v.push_back(j);
					}
				}
		}

		int a = v.size();
		for (int i = 0;i < a;i++) {
			if (v[i] != 0) {
				fri[v[i]] = true;
			}
		}

		int ans = 0;
		for (int i = 0;i < 500;i++) {
			if (fri[i] == true)
			{
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4080
N, M = map(int, input().split())
B = []
for i in range(M):
    (a, b) = map(int, input().split())
    B.append((a, b))
B = sorted(B, key=lambda x: x[0])


def update(x, y):
    if x[0] == y[0]:
        return (x[0], min(x[1], y[1]))
    if x[1] <= y[0]:
        return False
    else:
        return (y[0], min(x[1], y[1]))


now = B[0]
count = 0
for i in range(1, M):
    ans = update(now, B[i])
    # print(ans)
    if ans:
        now = ans
    else:
        count += 1
        now = B[i]
count += 1
print(count)


Measured memory_bytes: 19060
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1100000000;
const int H_MAX = 10000;
const int N_MAX = 1000;

int main() {
	int h, n;
	cin >> h >> n;
	int dp[H_MAX+1];
	dp[0] = 0; fill(dp+1, dp+h+1, INF);
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		for (int j = 1; j <= h; j++) {
			dp[j] = min(dp[j], b+dp[max(0, j-a)]);
		}
	}
	int ans = dp[h];
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int a,b,c;
	int k = 0;
	cin >> a >> b >> c;
	while(!(a == b && a == c) && !(a % 2) && !(b % 2) && !(c % 2))
	{
		k++;
		int tmp_a = (b+c)/2;
		int tmp_b = (a+c)/2;
		c = (a+b)/2;
		a = tmp_a;
		b = tmp_b;
	}
	if((a % 2) || (b % 2) || (c % 2))
		cout << k << endl;
	else
		cout << -1 << endl; 
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
    x=0;char c=getchar();bool f=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
    if(x<0){putchar('-'),write(-x);}
    else{if(x>9)write(x/10);putchar('0'+x%10);}
}





string s;


signed main(){
	cin>>s;
	for(int i=0;i<s.size();i++) cout<<'x';
}

Measured memory_bytes: 256
#include <iostream>
#include<utility>
using namespace std;
pair<int,int> ex_gcd(int a,int b)
{
	int x1=1,y1=0,z1=a;
	int x2=0,y2=1,z2=b;
	int q,sto;
	while(z2!=0)
	{
		q=z1/z2;
		x1-=q*x2;
		y1-=q*y2;
		z1-=q*z2;
		
		sto=x1;
		x1=x2;
		x2=sto;
		sto=y1;
		y1=y2;
		y2=sto;
		sto=z1;
		z1=z2;
		z2=sto;
	}
	return make_pair(x1,y1);
}
int main() {
	int a,b;
	cin>>a>>b;
	pair<int,int> s=ex_gcd(a,b);
	cout<<s.first<<" "<<s.second<<endl;
	return 0;
}

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

int main() {
    long long int n, count = 0, ans = 0;
    map<string, int> mp;
    cin >> n;
    string s_;
    for(int i = 0; i < n; ++i) {
        cin >> s_;
        sort(s_.begin(), s_.end());
        mp[s_]++;
    }

    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        n = iter->second;
        if(n >= 2) {
            ans += n*(n-1)/2;   // nC2 -> n(n-1)/2
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 11136
SS=list(input())
T=list(input())

SS.reverse()
T.reverse()

flag=0
for i in range(len(SS)-len(T)+1):
    if flag==0:
        for j in range(len(T)):
            if SS[i+j]==T[j] or SS[i+j]=='?':
                if j==len(T)-1:
                    flag=1
                    for k in range(len(T)):
                        SS[i+k]=T[k]
                    break
            else:
                break
            #if flag==1:
            #    break

ans=''
SS.reverse()
if flag==1:
    for i in range(len(SS)):
        if SS[i]=='?':
            SS[i]='a'
        ans+=SS[i]
else:
    ans='UNRESTORABLE'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int nmax = 40, abmax = 10, inf = 1000000;

int a[nmax], b[nmax], c[nmax];
int dp[nmax + 1][nmax * abmax + 1][nmax * abmax + 1];

int main() {
  int n, ma, mb;
  cin >> n >> ma >> mb;

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

  for (int i = 0; i <= n; ++i) {
    for (int ca = 0; ca <= nmax * abmax; ++ca) {
      for (int cb = 0; cb <= nmax * abmax; ++cb) {
        dp[i][ca][cb] = inf;
      }
    }
  }

  dp[0][0][0] = 0;

  for (int i = 0; i < n; ++i) {
    for (int ca = 0; ca <= nmax * abmax; ++ca) {
      for (int cb = 0; cb <= nmax * abmax; ++cb) {
        if (dp[i][ca][cb] == inf) continue;
        dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
        dp[i + 1][ca + a[i]][cb + b[i]] =
            min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
      }
    }
  }

  int ans = inf;
  for (int ca = 1; ca <= nmax * abmax; ++ca) {
    for (int cb = 1; cb <= nmax * abmax; ++cb) {
      if (ca * mb == cb * ma) ans = min(ans, dp[n][ca][cb]);
    }
  }

  if (ans == inf) ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 25984
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
vector<string> split(const string &s, char delim) {
	vector<string> elems;
	string item;
	for (char ch : s) {
		if (ch == delim) {
			if (!item.empty())
				elems.push_back(item);
			item.clear();
		} else {
			item += ch;
		}
	}
	if (!item.empty())
		elems.push_back(item);
	return elems;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}

// 本体

void updatemp(map<P, P> &mp, P key, bool is1) {
	if (mp.find(key) == mp.end()) {
		mp[key] = P(0, 0);
	}
	if (is1) {
		mp[key].first++;
	} else {
		mp[key].second++;
	}
}

int main() {
	IOS();
	ll n;
	cin >> n;
	map<P, P> mp;
	ll zero = 0;
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			zero++;
		} else if (a == 0) {
			updatemp(mp, P(1, 0), true);
		} else if (b == 0) {
			updatemp(mp, P(1, 0), false);
		} else {
			ll za = abs(a), zb = abs(b);
			ll na = za / gcd(za, zb), nb = zb / gcd(za, zb);
			if ((a > 0 && b > 0) || (a < 0 && b < 0)) { // 第1or第3象限
				updatemp(mp, P(na, nb), true);
			} else { // 第2or第4象限
				updatemp(mp, P(nb, na), false);
			}
		}
	}
	ll nonzero = 1;
	for (const auto &[_, val] : mp) {
		nonzero *= (powm(2, val.first, MOD) + powm(2, val.second, MOD) - 1) % MOD;
		nonzero %= MOD;
	}
	dump((nonzero + zero - 1 + MOD) % MOD);
}

Measured memory_bytes: 19204
def main():
    s = input().strip()

    while len(s):
        if s[-5:] in ("dream", "erase"):
            s = s[:-5]
        elif s[-6:] == "eraser":
            s = s[:-6]
        elif s[-7:] == "dreamer":
            s = s[:-7]
        else:
            print("NO")
            return

    print("YES")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,p;
cin>>n>>p;
string str;
cin>>str;
int ans=0;
if(p==2)
{
    for(int i=0;i<n;i++)
    {
        int x=str[i]-'0';
        if(x%2==0)
        {
            ans+=i+1;
        }
    }
}
else if(p==5)
{
    for(int i=0;i<n;i++)
    {
        int x=str[i]-'0';
        if(x%5==0)
        {
            ans+=i+1;
        }
    }
}
else
{
    int r=1;
    int t=0;
    map<int,int> mp;
    mp[0]=1;
    for(int i=n-1;i>=0;i--)
    {
        int x=str[i]-'0';
        t=x*r+t;
        t%=p;
        ans+=mp[t];
        mp[t]++;
        r*=10;
        r%=p;
    }



}
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1044
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

long double xyz(int n) {
    long double ans = 1;
    for(int i = 0; i < n; i++) {
        ans /= 2.0;
    }
    
    return ans;
}

int abc(int n, int k) {
    int tmp = n;
    int cnt = 0;
    while(tmp < k) {
        tmp *= 2;
        cnt++;
    }
    return cnt;
}

int main() {
    int n, k;
    cin >> n >> k;
    
    long double ans = 0.0;
    for(int i = 1; i <= n; i++) {
        ans += xyz(abc(i, k));
    }
    ans /= (double)n;
    
    cout << setprecision(12) << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	string a,b,c;
	cin>>a>>b>>c;
	if(a.substr(a.length()-1,1)==b.substr(0,1) &&b.substr(b.length()-1,1)==c.substr(0,1)){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 384