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

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

void solve(void) {

	int N, W;
	cin >> N >> W;

	vi w(N), v(N);

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

	vector<vector<ll>> dp(N+1, vector<ll>(W+1));

	for(int i = 1; i <= N; i++) {
		for(int j = 1; j <= W; j++) {
			dp[i][j] = dp[i-1][j];
			if(w[i-1] <= j) {
				dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]);
			}
		}
	}

	cout << dp[N][W] << '\n';
}

int main(void) {

	solve();
	return 0;
}


Measured memory_bytes: 80256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 50 + 2 ;
int n , a[N] , b[N] ;

int mat[N][N] , dist[N][N] ;
ll ans ;

inline void dijk (int S) {
	memset(dist[S] , 63 , sizeof dist[S]) ;

	set <pii> st ;

	dist[S][S] = 0 ;
	st.insert({0 , S}) ;

	while (_sz(st)) {
		int v = st.begin() -> S , d = dist[S][v] ;
		st.erase(st.begin()) ;

		for (int u = 0 ; u <= 50 ; u ++) {
			if (max(dist[S][v] , mat[v][u]) < dist[S][u]) {
				st.erase({dist[S][u] , u}) ;
				dist[S][u] = max(dist[S][v] , mat[v][u]) ;
				st.insert({dist[S][u] , u}) ;
			}
		}
	}
}

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

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

	for (int i = 0 ; i < n ; i ++)
		if (2 * b[i] >= a[i] && a[i] != b[i]) return cout << "-1\n" , 0 ;

	memset(mat , 63 , sizeof mat) ;

	for (int k = 50 ; k > 0 ; k --)
		for (int a = 50 ; a >= k ; a --)
			mat[a][a % k] = k ;
	
	while (1) {
		for (int x = 0 ; x <= 50 ; x ++) dijk(x) ;

		int mx = 0 ;
		for (int i = 0 ; i < n ; i ++)
			mx = max(mx , dist[a[i]][b[i]]) ;

		if (!mx) break ;

		for (int a = 50 ; a >= mx ; a --)
			mat[a][a % mx] = 0 ;

		ans |= (1ll << mx) ;
	}

	cout << ans << '\n' ;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll N;
    cin >> N;
    vector<pll> v;
    REP(i, N) {
        ll x, l;
        cin >> x >> l;
        v.push_back(pll(x - l, x + l));
    }
    sort(v.begin(), v.end(), [](pll a, pll b) { return a.second < b.second; });
    ll ans = 0;
    ll right = -INF;
    REP(i, N) {
        if (right > v[i].first)
            continue;
        ans++;
        right = v[i].second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
num_data = input().split(' ')
num = [int(num_data[i]) for i in range(2)]
data = 1
key = 0
while(1):
    if(data * 8 // 100 ==num[0] and num[1] == data // 10):
        break
    data += 1
    if(data >= 1250):
        key = 1
        break

if(key == 1):
	print(-1)
else:
  	print(data)


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  vvi p(n, vi(n, -1));
  rep(i, n) {
    int a;
    cin >> a;
    rep(j, a) {
      int x, y;
      cin >> x >> y;
      x--;
      y = 1 - y;
      p[i][x] = y;
    }
  }
  dumpv(p, n, n);
  int ans = n;
  rep(x, (1 << n)) {
    int cnt = 0;
    int ok = 1;
    rep(j, n) {
      if (x & (1 << j)) cnt++;
      rep(i, n) {
        if (x & (1 << i)) continue;
        if (p[i][j] == -1) continue;
        if (p[i][j] != ((x >> j) & 1)) {
          ok = 0;
          break;
        }
      }
      if (!ok) break;
    }
    if (ok) {
      ans = min(ans, cnt);
    }
    dump(n, ok, x, cnt, ans);
  }
  cout << n - ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll x,y;
  cin >> x >> y;
  ll ans=0;
  if(x==1) ans+=300000;
  if(x==2) ans+=200000;
  if(x==3) ans+=100000;
  if(y==1) ans+=300000;
  if(y==2) ans+=200000;
  if(y==3) ans+=100000;
  if(x==y&&x==1) ans+=400000;
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    long[] val = new long[n+1];
    for(int i=0;i<n+1;i++){
      val[i] = 0;
    }
    int[] a = new int[n];
    
    int tmp;
      
    for(int i=0;i<n;i++){
      tmp = sc.nextInt();
      a[i] = tmp;
      val[tmp] += 1;
    }
    
    long ans =0;
    for(int k=1;k<n+1;k++){
      ans += val[k]*(val[k]-1)/2;
    }
    
    long g =0;
    for(int j=0;j<n;j++){
      g = val[a[j]] -1 ;
      System.out.println(ans - g);
    }
      
      
   
  }
}

Measured memory_bytes: 96528
N=int(input())
A=[0]*N
B=[0]*N
ans=0
for i in range(N):
    A[i],B[i]=map(int, input().split())
for i in range(N):
    #print(ans)
    A[N-i-1]+=ans
    if A[N-i-1]%B[N-i-1]!=0:
        ans+=B[N-i-1]-A[N-i-1]%B[N-i-1]
print(ans)

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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int sum = 0;
    if(A + B <= C*2) {
        sum = A*X + B*Y;
    } else if(X >= Y) {
        if(A <= C*2) {
            sum = C*2*Y + A*(X-Y);
        } else {
            sum = C*2*X;
        }
    } else {
        if(B <= C*2) {
            sum = C*2*X + B*(Y-X);
        } else {
            sum = C*2*Y;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){
        var n = long.Parse(Console.ReadLine());
        var hash = Console.ReadLine().Split(' ').Select(long.Parse).Distinct().ToList();
        if(hash.Count < n){
            Console.WriteLine("NO");
        }else{
            Console.WriteLine("YES");
        }
    }
}


Measured memory_bytes: 45340
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
const ll nmax=8;
bool graph[nmax][nmax];
ll dfs(ll v,ll N,bool visited[nmax]){
   bool all_visited=true;
   for(ll i=0;i<N;++i){
     if(visited[i]==false)all_visited=false;
   }
   if(all_visited){
     return 1;
    }
ll ret=0;
for(ll i=0;i<N;++i){
  if(graph[v][i]==false) continue;
  if(visited[i]) continue;
  visited[i]=true;
  ret+=dfs(i,N,visited);
  visited[i]=false;
  }
  return ret;
} 
int main()
{
  ll A;
  ld C,B,N;
  cin>>A>>B>>N;
  C=A;
  if(B<=N)cout<<floor(A-A/B)<<endl;
  else cout<<floor(A*N/B)-A*floor(N/B)<<endl;
}

/// g++ code.cpp//
// ./a.out //


Measured memory_bytes: 3820
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static List<Set<Integer>> setList = new ArrayList<>();
	static boolean resBool;
	static Integer[] res;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		for (int i = 0; i <= N; i++) {
			Set<Integer> set = new HashSet<>();
			setList.add(set);
		}
		for (int i = 0; i < M; i++) {
			int tmp1 = sc.nextInt();
			int tmp2 = sc.nextInt();
			setList.get(tmp1).add(tmp2);
			setList.get(tmp2).add(tmp1);
		}
		resBool = true;
		res = new Integer[N + 1];
		res[0] = 99;
		res[1] = 99;
		getRes(new ArrayList<>(Arrays.asList(1)));

		if (resBool) {
			System.out.println("Yes");
			for (int i = 2; i <= N; i++) {
				System.out.println(res[i]);
			}
		} else {
			System.out.println("No");
		}
	}

	private static void getRes(List<Integer> array) {
		List<Integer> dist = new ArrayList<>();
		for (int i : array) {
			for (int j : setList.get(i)) {
				if (res[j] == null) {
					dist.add(j);
					res[j] = i;
				}
			}
		}
		if (!Arrays.asList(res).contains(null)) {
			return;
		}
		if (dist.isEmpty()) {
			resBool = false;
			return;
		}
		getRes(dist);
	}
}

Measured memory_bytes: 114624
fun main(args: Array<String>) {
    val (N, D, A) = readInputLine().split(" ").map { it.toLong() }
    val mons = Array(N.toInt()) { val (X, H) = readInputLine().split(" ").map { it.toLong() }; Pair(X, H)}
    mons.sortBy { it.first }

    val damage = LongArray(N.toInt() + 1)

    var ans = 0L

    for ((i, m) in mons.withIndex()) {
        if (i != 0) {
            damage[i] += damage[i - 1]
        }

        if (damage[i] < m.second) {
            val cnt = (m.second - damage[i]) / A + if ((m.second - damage[i]) % A != 0L) 1L else 0L
            damage[i] += cnt * A
            damage[upperBound(mons, m.first + D * 2)] -= cnt * A
            ans += cnt
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}

fun upperBound(arr: Array<Pair<Long, Long>>, value: Long): Int {
    var l = -1
    var r = arr.size

    while (r - l > 1) {
        val mid = (r + l) / 2
        if (arr[mid].first > value) {
            r = mid
        } else {
            l = mid
        }
    }

    return r
}

Measured memory_bytes: 134816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int f(char c){
    if(c=='R') return 1;
    return 3;
}

int main(){
    string x;
    cin >>x;
    int n = x.size();

    int ans = 0;
    int dir = 0;
    int s = 0;

    while(s<n){
        int e = s;
        int ct[4]={};
        while(e<n){
            (dir += f(x[e])) %= 4;
            if(x[e]=='R') ++ct[dir];
            ++e;
            if(dir==0) break;
        }
        s = e;

        int add = 1;
        rep(i,4)if(ct[i]==0) add = 0;
        ans += add;
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
  int n;cin >> n;
  string s,t;cin >> s >> t;
  for(int i=0; i<n; i++){
    cout << s.at(i) << t.at(i);
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
lst = []
for i in range(n):
    x,l = map(int,input().split())
    if x-l < 0:
        # [右端の位置,左端の位置]
        lst.append([x+l,0])
    else:
        lst.append([x+l,x-l])
lst.sort()


# 最初のロボットの選択
now = lst[0][0]
cnt = 1


for i in range(1,n):
    if now <= lst[i][1]:
        now = lst[i][0]
        cnt += 1

print(cnt)

Measured memory_bytes: 24484
#include <stdio.h>
#include <stdlib.h>
#define N 100000
#define L 10

// define the structure
typedef struct Process {
  char name[10];
  int time;
} Processor;

int main() {
  int i, n, q;
  int cnt = 0;
  int qhead = 0, qtail;
  Processor pr[N];

  // input each process
  scanf("%d %d", &n, &q);
  for(i = 0; i < n; i++) {
    if(scanf("%s %d", pr[i].name, &pr[i].time) == EOF) break;
  }

  qtail = i;
  // simulate
  while(1) {
    if (pr[qhead].time <= q) {
      // complete the process
      cnt += pr[qhead].time;
      printf("%s %d\n", pr[qhead].name, cnt);
      // dequeue
      qhead++;
      if(qhead == N - 1) qhead = 0;
    }
    else {
      pr[qhead].time -= q;
      cnt += q;   
      // engueue
      if(qtail == N - 1) qtail = 0;
      pr[qtail++] = pr[qhead];
      // dequeue
      qhead++;
      if(qhead == N - 1) qhead = 0;
    }
    // all complete
    if(qhead == qtail) break;
  }
  
  return 0;
}



Measured memory_bytes: 3280
mountain = []
for i in range(10):
    mountain.append(int(input()))

for i in range(3):
    for j in range(i,10):
        if mountain[i] < mountain[j]:
            buff_mt = mountain[i]
            mountain[i] = mountain[j]
            mountain[j] = buff_mt

for i in range(3):
    print(mountain[i])


Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  string S,T;
  cin>>S;
  cin>>T;
  int N=S.size();
  rep(i,N) if(S[i]!=T[i]){
    cout<<"No"<<endl;
    return 0;
  }

  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL a[200005];
LL ans=0;
int main()
{
	LL n;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(a[i]<a[i-1])
		{
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 5380
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i,j,k;
    cin>>a>>b;
    double answer=0;
    for(i=1;i<a+1;i++){
        double x;
        x=1;
        int d=i;
        while(1){
            if(b<=d)
            break;
            d=d*2;
            x=x*2;
        }
        answer=answer+1/x;
    }
   answer=answer/a;
   cout<<setprecision(10)<<answer<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a=0,n,v[50],c[50],d[25];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    for(int i=0;i<n;i++){
        d[i]=v[i]-c[i];
    }
    
    
    for(int i=0;i<n;i++){
        
        if(d[i]>=0){
            a=d[i]+a;
        }
        
        
    }
    std::cout << a << std::endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  a += b;
  if(a > 23){
    a -= 24;
  }
  
  cout << a << "\n";
}

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

int main() {
    string a, b;
    cin >> a >> b;

    if (a == "H") {
        if (b == "H") cout << "H" << endl;
        else cout << "D" << endl;
    }
    else if (a == "D") {
        if (b == "H") cout << "D" << endl;
        else cout << "H" << endl;
    }
    return 0;

}

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

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var X = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var min = long.MaxValue;
        for (int i = 1; i <= 100; i++)
        {
            var sum = X.Select(x => x - i).Sum(d => d * d);
            min = Math.Min(min, sum);
        }

        Console.WriteLine(min);
    }
}

Measured memory_bytes: 13396
# A - One Card Poker

# 一枚ポーカーの勝敗を判定し出力する


card_A, card_B = map(int, input().split())

if card_A == 1:
    card_A = 14

if card_B == 1:
    card_B = 14

if card_A > card_B:
    print('Alice')
elif card_A < card_B:
    print('Bob')
elif card_A == card_B:
    print('Draw')


Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
int main()
{

int n;
 cin>>n;
char h[10001];
  cin>>h;
  
  
 for(int i=0;i<strlen(h);i++)
 { 
   if(((h[i])+n)>'Z')
      cout<<char(h[i]+n-26);
   else
     cout<<char(h[i]+n);
 
 
 
 }


return 0;
}


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

using namespace std;

#define MAX_N 1010

struct P{
  int p,l;
};

P p[MAX_N];
string s[MAX_N];
bool used[MAX_N];
int N;

void init(int N){
  for(int i = 0 ; i < N ; i++){
    p[i].p = i;
  }
}

bool find(int x,int target){
  if(p[x].p == target){
    return true;
  }
  if(p[x].p == x){ return false; }
  return find(p[x].p,target);
}

void make(int n,int parent,int root,int depth){
  set<int> children;
  if(used[n]){ return; }
  used[n] = true;
  p[n].p = parent; p[n].l = depth;
  for(int i = n+1 ; i < N ; i++){
    int len = s[i].size();
    if(depth+1 >= len){ continue; }
    if(s[i][depth] != '.'){ break; }
    if(s[i][depth] == '.' && s[i][depth+1] != '.'){
      children.insert(i);
      make(i,n,root,depth+1);
    }
  }
}

int main(){
  int M;
  while(cin >> N >> M, N){
    map<string,int> mp;
    int cur = 0;
    init(N); cin.ignore();
    for(int i = 0 ; i < N ; i++){
      getline(cin,s[i]);
      for(int j = 0 ; j < (int)s[i].size() ; j++){
        if(s[i][j] != ' '){
          mp[s[i].substr(j)] = cur++;
          break;
        }
        s[i][j] = '.';
      }
      used[i] = false;
    }
    for(int i = 0 ; i < N ; i++){
      if(used[i]){ continue; }
      if(s[i][0] != '.'){
        make(i,i,i,0);
      }
    }
    string ord,a,b,c;
    for(int i = 0 ; i < M ; i++){
      getline(cin,ord);
      stringstream ss(ord);
      ss >> a;
      ss >> ord; ss >> ord;
      ss >> c;
      ss >> ord;
      ss >> b;
      b.resize(b.size()-1);
      bool ans = false;
      if(c == "parent"){
        if(p[mp[b]].p == mp[a]){
          ans = true;
        }
      }else if(c == "child"){
        if(p[mp[a]].p == mp[b]){
          ans = true;
        }
      }else if(c == "ancestor"){
        if(p[mp[a]].l < p[mp[b]].l && find(mp[b],mp[a])){
          ans = true;
        }
      }else if(c == "descendant"){
        if(p[mp[a]].l > p[mp[b]].l && find(mp[a],mp[b])){
          ans = true;
        }
      }else{
        if(p[mp[a]].l == p[mp[b]].l && p[mp[a]].p == p[mp[b]].p){
          ans = true;
        }
      }
      cout << (ans ? "True" : "False") << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1440
#include<iostream>
using namespace std;
int main(){
  int n,i,asum,bsum,a_card,b_card;
  cin >> n;
  while(n!=0){
    asum=0; bsum=0;
    for(i=0;i<n;i++){
      cin >>a_card>>b_card;
      if(a_card>b_card){
	asum+=a_card+b_card;
      }else if(a_card<b_card){
	bsum+=a_card+b_card;
      }else{
	asum+=a_card;
	bsum+=b_card;
      }
    }
      cout << asum<<" "<<bsum<<endl;
      cin >>n;
  }
}



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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n;
    while (cin >> n, n) {
        vector<pair<int,ll>> s(4000, {inf, 0});
        vector<bool> ip(4000,false);
        REP(i,n) {
            ll e,p,q;
            cin >> e >> p >> q;
            e--;
            if (ip[e]) {
                s[e].se += p*q;
            }
            else {
                s[e] = make_pair(i,p*q);
                ip[e] = true;
            }
        }
        vector<pair<int,int>> ans;
        REP(i, 4000) {
            if (s[i].se >= 1000000) {
                ans.pb({s[i].fi, i+1});
            }
        }
        sort(ALL(ans));
        REP(i,ans.size()) cout << ans[i].se << endl;
        if (ans.size() == 0) cout << "NA" << endl;
    }
    return 0;
}


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

int main(){
int x  , y;
char op;
 
while(1){
cin >> x >>  op  >> y;
if( op == '?' ) break;

if ( op == '+' ) cout << x + y << endl;
else if ( op == '-' ) cout << x - y << endl;
else if ( op == '*' ) cout << x * y << endl;
else if ( op == '/' ) cout << x / y << endl;
}

return 0 ;
}

Measured memory_bytes: 1160
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	v := make([]int, n)
	for i := range v {
		fmt.Scan(&v[i])
	}
	c := make([]int, n)
	for i := range c {
		fmt.Scan(&c[i])
	}

	ret := 0
	for i := 0; i < n; i++ {
		if v[i]-c[i] > 0 {
			ret += (v[i] - c[i])
		}
	}
	fmt.Println(ret)
}


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

using LL = long long;

int N;
string S;
vector<LL> J, I, JO, OI;

LL count() {
  J = I = JO = OI = vector<LL>(N + 1);
  for(auto i = 0; i < N; ++i) {
    J[i+1] += J[i];
    I[i+1] += I[i];
    if(S[i] == 'J') ++J[i+1];
    if(S[i] == 'I') ++I[i+1];
  }

  for(auto i = 0; i < N; ++i) {
    JO[i+1] += JO[i];
    if(S[i] == 'O') JO[i+1] += J[i];
  }

  for(auto i = N-1; 0 <= i; --i) {
    OI[i] += OI[i+1];
    if(S[i] == 'O') OI[i] += I[N] - I[i+1];
  }

  LL res = 0;
  for(auto i = 0; i < N; ++i) if(S[i] == 'J') res += OI[i+1];
  return res;
}

LL dif(auto i, auto c) {
  if(c == 'J') return OI[i];
  if(c == 'O') return J[i] * (I[N] - I[i]);
  if(c == 'I') return JO[i];
}

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

  LL ans = 0;

  auto init = count();
  for(auto c: {'J', 'O', 'I'}) for(auto i = 0; i <= N; ++i) ans = max(ans, init + dif(i, c));

  cout << ans << endl;
}

Measured memory_bytes: 6304
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		boolean prime[] = new boolean[1000000];
		for(int i=0;i<prime.length;i++)prime[i]=true;
		prime[0]=false;prime[1]=false;
		for(int s=0;s<prime.length;s++){
			if(prime[s])
				for(int i=s+s;i<prime.length;i+=s)prime[i]=false;
		}
		while(in.hasNext()){
			int n = in.nextInt();
			if(n==0)break;
			int result=0;
			for(int i=2;i<=n;i++)if(prime[i]&&prime[i-2])result = i;
			System.out.println(result-2+" "+result);
		}
	}
}

Measured memory_bytes: 35564
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
typedef long long ll;
using namespace std;

bool AC(char b1, char b2)
{
	if (b1 == 'A' && b2 == 'C')
		return true;
	else return false;
}

int main() {
	ll N, a[5], num_min, ans, p;
	num_min = pow(10, 15);
	int i;
	cin >> N;
	for (i = 0; i < 5; i++)
	{
		cin >> a[i];
		num_min = min(num_min, a[i]);
	}
	p = N % num_min;
	if (p == 0)
	{
		ans = N / num_min;
	}
	else ans = N / num_min + 1;
	ans += 4;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

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

	LL n, k;
	cin >> n >> k;
	n = n % k;
	n = min(abs(n - k), n);
	cout << n << '\n';
}


Measured memory_bytes: 256
use proconio::input;
fn main() {
    input!{
        n:usize,
    }
    let mut A=vec![];
    let mut B=vec![];
    for _ in 0..n{
        input!{
            a:i64,b:i64,
        }
        A.push(a);B.push(b);
    }
    A.sort();B.sort();
    if n%2==1{
        let mi=A[n/2];
        let ma=B[n/2];
        println!("{}",ma-mi+1);
    }
    else{
        let mi=A[n/2-1]+A[n/2];
        let ma=B[n/2-1]+B[n/2];
        println!("{}",ma-mi+1);
    }
}

Measured memory_bytes: 9756
#include<stdio.h>
int main()
{
	int S,h,m,s;
	scanf("%d",&S);

		h=(S/3600);
		S=S-3600*h;

	m=(S/60);
	S=S-60*m;

	s=S;
	printf("%d:%d:%d\n",h,m,s);	
	

	return 0;
}

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

int main(){
    using namespace std;
    unsigned long N, Q;
    cin >> N >> Q;
    vector<unsigned long> c(N);
    for(auto&& i : c){
        cin >> i;
        --i;
    }
    vector<tuple<unsigned long, unsigned long, unsigned long>> queries(Q);
    {
        unsigned long cnt{0};
        for(auto&& [i, l, r] : queries){
            cin >> l >> r;
            --l;
            i = cnt++;
        }
    }
    constexpr unsigned long B{700};
    sort(begin(queries), end(queries), [&B](const auto& lhs, const auto& rhs){
        const auto& [i, li, ri] = lhs;
        const auto& [j, lj, rj] = rhs;
        return li / B == lj / B ? (li / B) & 1 ? ri > rj : ri < rj : li < lj;
    });
    unsigned long nl{0}, nr{0}, now{0};
    vector<unsigned long> cnt(N), ans(Q);
    for(const auto& [i, l, r] : queries){
        while(nr < r)now += !cnt[c[nr++]]++;
        while(nr > r)now -= !--cnt[c[--nr]];
        while(nl < l)now -= !--cnt[c[nl++]];
        while(nl > l)now += !cnt[c[--nl]]++;
        ans[i] = now;
    }
    for(const auto& i : ans)cout << i << endl;
    return 0;
}

Measured memory_bytes: 27140
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
	int N,A,B;
	string S;
	cin >> N >> A >> B;
	cin >> S;
	A+=B;
	for(int i=0;i<N;i++) {
		if(S[i]=='c') {
			puts("No");
			continue;
		}
		if(S[i]=='a') {
			if(A>0)
				puts("Yes"), A--;
			else
				puts("No");
		}
		else { // 'b'
			if(A>0 && B>0)
				puts("Yes"), A--, B--;
			else
				puts("No");
		}
	}
	return 0;
}


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

long long N, P;

typedef pair<long long, long long> PP;
vector<PP> vp;

int main() {
	cin >> N >> P;

	long long rt = (long long)sqrt( (double)P );
	long long n = P;
	for( long long i = 2; i <= rt; i++ ) {
		long long j;
		for( j = 0; n % i == 0; j++ ) {
			n /= i;
		}
		if( j ) {
			vp.push_back( make_pair( i, j ) );
		}
	}
	if( n > rt ) {
		vp.push_back( make_pair( n, 1 ) );
	}
	long long sz = vp.size();
	long long ans = 1;
	for( long long i = 0; i < sz; i++ ) {
		long long n = vp[i].second;
		while( n >= N ) {
			ans *= vp[i].first;
			n -= N;
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
    int n, m,ans =0;
    cin >> n >> m;
    vector<vector<int>> data(n*m, vector<int>(n*m));
    vector<int> like(m*n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i).at(0);
        for (int j = 0; j < data.at(i).at(0); j++){
            cin >> data.at(i).at(j+1);
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < data.at(i).at(0); j++){
            like.at(data.at(i).at(j+1)-1) ++;
        }
    }
    for (int i = 0; i < m; i++){
        if(like.at(i) == n) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6836
/**********************************************************************/
/********                                                      ********/
/********                     Writer:孙~~                      ********/
/********                       Lang:C++                       ********/
/********                     Status:Unknow                    ********/
/********                                                      ********/
/**********************************************************************/
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

const int INF=0x3f3f3f3f;
//const int SIZE=;
const double EPS=1e-6;

int main(){
	/*main function start*/
	long long k,a,b;
	cin>>k>>a>>b;
	long long ans;
	if(b-a>1){
		k-=a-1;
		int more=k%2;
		ans=a+k/2*(b-a)+more;
	}
	else{
		ans=k+1;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

int main()
{
	int n, l;
	cin >> n >> l;
	vector<pair<int, int>> apple(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		apple[i].second = l + i;
		apple[i].first = abs(l + i);
		sum += apple[i].second;
	}
	sort(apple.begin(), apple.end());

	sum -= apple[0].second;
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String op = sc.next();
        int b = sc.nextInt();
if(op.equals("+")){
    System.out.println(a+b);
}else if(op.equals("-")){
    System.out.println(a-b);
}


    }
}


Measured memory_bytes: 23124
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#define MAX 110000
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
class union_find{
  int n;
  vector<int> par,rk,size;
  public:
  union_find(int max_n){
    n = max_n+1;
    for(int i=0;i<=n;i++){
      par.emplace_back(i);
      rk.emplace_back(0);
      size.emplace_back(1);
    }
  }
  int root(int x){
    vector<int> nodes;
    while(x!=par[x]){
      nodes.emplace_back(x);
      x = par[x];
    }
    for(auto v:nodes){
      par[v] = x;
    }
    return x;
  }
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x==y) return;
    if(rk[x]<rk[y]){
      par[x] = y;
      size[y] += size[x];
    }else{
      par[y] = x;
      if(rk[x]==rk[y]) rk[x]++;
      size[x] += size[y];
    }
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  int treesize(int x){
    return size[root(x)];
  }
};
vector<ll> a(MAX),b(MAX),c(MAX),d(MAX);
vector<ll> G[MAX];
union_find uf(MAX);
ll ans[MAX]={};
bool used[MAX] = {};
void dfs(ll v,ll prev){
  if(used[v]) return;
  used[v] = true;
  uf.unite(v,prev);
  for(auto nv:G[v]){
    dfs(nv,v);
  }
}
signed main(){
  init_io();
  ll n,m,k;
  cin >> n >> m >> k;
  for(int i=0;i<m;i++){
    cin >> a[i] >>  b[i];
    a[i]--;
    b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  for(int i=0;i<n;i++){
    dfs(i,i);
  }
  for(int i=0;i<k;i++){
    cin >>c[i] >> d[i];
    c[i]--;
    d[i]--;
    if(uf.same(c[i],d[i])){
      ans[c[i]]--;
      ans[d[i]]--;
    }
  }
  for(int i=0;i<n;i++){
    ans[i] = ans[i] + (uf.treesize(i)-1)- G[i].size();
    cout << ans[i];
    if(i==n-1) cout << endl;
    else cout << " ";
  }
}


Measured memory_bytes: 15084
#include<iostream>

using namespace std;

int main(void){
	int n, b[100];

	cin >> n;
	for(int i = 0; i < n - 1; i++) cin >> b[i];

	int out = 0;
	for(int i = 0; i < n; i++){
		int l, r;
		if(i == 0){
			l = 100000;
		}else{
			l = b[i-1];
		}
		if(i == n-1){
			r = 100000;
		}else{
			r = b[i];
		}
		if(l > r){
			out += r;
		}else{
			out += l;
		}
	}

	cout << out << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b,ans=0;
  cin >> a >> b;
  ans+=a-1;
  ans+=b-1;
  ans+=2;
  ans-=__gcd(a,b)-1;
  cout << ans << endl;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool valid(vector<ll>&v,ll cans,ll k){
    ll ans=0;
    for(ll i=0;i<v.size();i++){
        ans+=(v[i]-1)/cans;
    }
    return ans<=k;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vector<ll>v(n);
    for(ll i=0;i<n;i++)cin>>v[i];
    ll s=1,e=1e9;
    ll ans;
    while(s<=e){
        ll m=(s+e)/2;
        if(valid(v,m,k)){
            ans=m;
            e=m-1;
        }
        else s=m+1;
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;
typedef long long int ll;

int main(void){
  int N;
  cin >> N;
  vector<ll> v;
  for(int i=0;i<N;i++){
    ll tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(),v.end(),greater<int>());
  ll ans = 0;
  for(int n=1;n<N;n++){
    if(n == 1){
    	ans = ans + v[0];
    }else{
    	ans = ans + v[n/2];
    }
    //cout << n/2 << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5368
#include "bits/stdc++.h"
#define MAXN 200005
using namespace std;
char str[MAXN];
int main()
{
    int len,i;
    long long ans=0,sum=0;
    scanf("%s",str);
    len=strlen(str);
    for(i=0;i<len;i++)
    {
        if(str[i]=='B')
        {
            sum++;
        }
        else if(str[i]=='W')
        {
            ans+=sum;
        }
    }
    printf("%lld\n",ans);
    return 0;
}
             


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

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

	int	n;
	cin >> n;

	vector<int>	V(n);
	vector<int>	V1(n);
	vector<int>	V2(n);
	rep(i, n)
		V.at(i) = i + 1;
	rep(i, n)
		cin >> V1.at(i);
	rep(i, n)
		cin >> V2.at(i);
	int	order;
	order = 0;
	int	a;
	int	b;
	bool	fa;
	bool	fb;
	fa = false;
	fb = false;
	do
	{
		order++;
		if (V == V1)
		{
			a = order;
			fa = true;
		}
		if (V == V2)
		{
			b = order;
			fb = true;
		}
	}
	while (next_permutation(V.begin(), V.end()) && !(fa && fb));
	cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void B_sort(int data[], int n) {
  int tmp;
  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      if (data[i] < data[j]) {
        tmp = data[i];
        data[i] = data[j];
        data[j] = tmp;
      }
    }
  }
}

int ave(int data[], int n) {
  int i;
  int sum = 0;
  int ave;
  for (i = 0; i < n; i++) {
    sum += data[i];
  }
  if (n >= 2) {
    ave = sum/(n-2);
  }
  else {
    ave = sum;
  }
  return ave;
}

int main(void) {
  int n[100] = {0};
  int s[100][100] =  { {0} };
  int i = 0, j = 0;
  
  while (1) {
    scanf("%d", &n[i]);
    if (n[i] == 0) {
      break;
    }
    for (j = 0 ; j < n[i]; j++) {
      scanf("%d", &s[i][j]);
    }
    i++;
  }
  
  i = 0;
  j = 0;

  while (n[i] != 0) {
    B_sort(s[i], n[i]);

    s[i][0] = 0;
    s[i][n[i]-1] = 0;

    printf("%d\n", ave(s[i], n[i]));
    i++;
  }

  return 0;
}

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

int main()
{
  uint64_t n, k;
  cin >> n >> k;
  uint bc[64] {};
  vector<uint64_t> a(n);
  for (auto&& e : a) {
    cin >> e;
    auto x = e;
    for (auto&& b : bc) {
      b += x & 1;
      x >>= 1;
    }
  }
  uint64_t v{0};
  for (auto s = 63; s >= 0; s--) {
    auto u = 1ULL << s;
    if (v + u <= k && bc[s] * 2 <= n) {
      v += u;
    }
  }
  uint64_t ans{0};
  for (const auto& e : a) {
    ans += v ^ e;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
N = int(input())
*A, = map(int, input().split())

j = 0
s = 0; t = 0
ans = 0
for i in range(N):
    while j < N and (s + A[j]) == (t ^ A[j]):
        s += A[j]; t ^= A[j]
        j += 1
    s -= A[i]; t -= A[i]
    ans += j-i
    if i == j:
        j += 1
print(ans)

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

int main(){
    int a,b;
    char op;
    
    while(1){
        cin>>a>>op>>b;
        if(op=='?'){
            break;
        }
        switch (op)
        {
        case '+':
            cout<<a+b<<endl;
            break;
        case '-':
            cout<<a-b<<endl;
            break;
        case '*':
            cout<<a*b<<endl;
            break;
        case '/':
            cout<<a/b<<endl;
            break;
        default:
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll a,b,c; cin >> a >> b >> c;
    ll sum = a + b + c;
    ll cnt = 0;
    if(a % 2 == 0 && a == b && b == c){cout << -1 << endl;return 0;}
    auto update = [&](){
        if(a % 2 || b % 2 || c % 2)return false;
        a = (sum - a) / 2;
        b = (sum - b) / 2;
        c = (sum - c) / 2;
        return true;
    };

    while (update())
    {
        cnt++;
    }
    

    cout << cnt << endl;
}

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

int main() {
    long long N, A[400000], cnt, ans = 0, mod = 1000000007, d = 1;
    cin >> N;
    for (long long i = 0; i < N; ++i) {
        cin >> A[i];
    }

    for (long long i = 0; i < 60; ++i) {
        cnt = 0;
        for (int j = 0; j < N; ++j) {
            if (A[j] & 1) {
                ++cnt;
            }
            A[j] = A[j] >> 1;
        }
        ans += ((cnt * (N - cnt)) % mod) * d % mod;
        d = d * 2 % mod;
    }

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

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
const int N = 200100;
int g[N];

int32_t main(){
	fastio;
  int n;
  cin>>n;
  for(int i=2;i<=n;i++){
    int p;
    cin>>p;
    g[p]++;
  }
  for(int i=1;i<=n;i++)cout<<g[i]<<endl;
}

Measured memory_bytes: 5172
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

main = do
  [n, k] <- mapM readIO . words =<< getLine
  ps <- getIntList
  print $ sum $ take k $ sort ps

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

typedef long long int ll;
typedef long double ld;

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define rep1(i, n)    for(ll i = 1; i <= (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
//#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define bpc(a) __builtin_popcount(a)
#define ff first 
#define ss second  
#define mk0(a) memset(a,0,sizeof(a))
#define mk_1(a) memset(a,-1,sizeof(a))

const ll MAX=1e5+5;
const ll MAX1=1e2+5;
const ll INF=1e15+2;
const ll MOD=1e9+7;

#define pb push_back
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi pair<ll,ll>
#define map1 unordered_map

inline ll nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}

inline ll read(){ll ret=0;bool f=0;char ch=nc();while(ch>'9'|| ch<'0') f^=ch=='-',ch=nc();
while(ch<='9'&& ch>='0') ret=ret*10+ch-'0',ch=nc();return f?-ret:ret;}

ll power(ll base,ll ind,ll mod){ll res=1;while(ind){if(ind&1)res=(res*base)%mod;base=(base*base)%mod;ind>>=1;}return res;}

ll inv(ll den,ll mod){return power(den,mod-2,mod);}

int main()
{
    faster;
	/*#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif*/
	string s;
    cin>>s;
    ll c[2];
    mk0(c);
    for(int i=0;i<sz(s);++i)
    {
        if(s[i]=='A')c[0]++;
        else if(s[i]=='B')c[1]++;
    }
    if(c[0]==0 or c[1]==0)
        cout<<"No\n";
    else
        cout<<"Yes\n";    
}

Measured memory_bytes: 256
dur=int(input())
c=list(map(int,input().split()))
d=[0]*26
r=1.2
for i in range(dur):
  t=0
  s=list(map(int,input().split()))
  m=-1<<64
  for j in range(26):
    alt=s[j]+r*c[j]*(i+1-d[j])+sum([-r*c[k]*(i+1-d[k]) for k in range(26)])
    if alt>m:
      m=alt
      t=j
  print(t+1)
  d[t]=i+1


Measured memory_bytes: 69544
s = input()
if s[:7] == 'keyence' or s[len(s) - 7:] == 'keyence':
    print('YES')
    exit()
elif s[:6] == 'keyenc' and s[-1:] == 'e':
    print('YES')
    exit()
elif s[:5] == 'keyen' and s[-2:] == 'ce':
    print('YES')
    exit()
elif s[:4] == 'keye' and s[-3:] == 'nce':
    print('YES')
    exit()
elif s[:3] == 'key' and s[-4:] == 'ence':
    print('YES')
    exit()
elif s[:2] == 'ke' and s[-5:] == 'yence':
    print('YES')
    exit()
elif s[0] == 'k' and s[-6:] == 'eyence':
    print('YES')
    exit()
else:
    print('NO')


Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C(I) cout<<I<<endl


ll n,m,a,b,c,x,y,aa[100010],ba[100010];
bool r,br,ar;
string s;
char ca,cb;


int main(){
    int qa[]={0,0,2,0,1,0,1,0,0,1,0,1,0};
    cin>>a>>b;
    C((qa[a]==qa[b] ? "Yes":"No"));
    
    
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

static class CodeJam
{
    static int Mod(long n, int K)
    {
        return (int)(((n % K) + K) % K);
    }

    static long Solve(int N, int K, int[] A)
    {
        long sum = 0;
        var cnts = new Dictionary<int, int>();
        var S = new long[N + 1];
        for (int i = 0; i < N; ++i) { S[i + 1] = S[i] + A[i]; }
        for (int j = 1; j <= N; ++j)
        {
            {
                int i = j - 1;
                int n = Mod(S[i] - i, K);
                if (!cnts.ContainsKey(n)) { cnts[n] = 0; }
                ++cnts[n];
            }
            if (j >= K)
            {
                int i = j - K;
                int n = Mod(S[i] - i, K);
                if (cnts.ContainsKey(n)) { --cnts[n]; }
            }
            {
                int n = Mod(S[j] - j, K);
                if (cnts.ContainsKey(n)) { sum += cnts[n]; }
            }
        }
        return sum;
    }

    static void Main(string[] args)
    {
        int[] V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(Solve(V[0], V[1], A));
    }
}


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

int main(void)
{
    int n;
    string s;
    cin >> n;
    cin >> s;

    int c1 = 0;
    int c2 = 0;
    int minc;

    for (int i = 0; i < n; i++) {
        if (s[i] == '.') {
            c1++;
        }
    }

    minc = c1;
    for (int i = 0; i < n; i++) {
        if (s[i] == '.') {
            c1 -= 1;
        } else {
            c2 += 1;
        }
        if (minc > c1 + c2) {
            minc = c1 + c2;
        }
    }
    cout << minc << endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    if B[i] < A[i]:
        ans += B[i]
        A[i] -= B[i]
    else:
        ans += A[i]
        B[i] -= A[i]
        if B[i] < A[i+1]:
            ans += B[i]
            A[i+1] -= B[i]
        else:
            ans += A[i+1]
            A[i+1] = 0
print(ans)


Measured memory_bytes: 18476