akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int n = sc.nextInt();
			int q = sc.nextInt();
			if ((n | q) == 0) {
				break;
			}

			@SuppressWarnings("unchecked")
			TreeSet<Integer>[] set = new TreeSet[n];
			for (int i = 0; i < n; i++) {
				set[i] = new TreeSet<Integer>();
				int k = sc.nextInt();
				for (int j = 0; j < k; j++) {
					set[i].add(sc.nextInt());
				}
			}

			int maxNum = 0, maxCnt = 0;
			for (int i = 1; i <= 100; i++) {
				int cnt = 0;
				for (int j = 0; j < n; j++) {
					if (set[j].contains(i)) cnt++;
				}
				if (maxCnt < cnt) {
					maxNum = i;
					maxCnt = cnt;
				}
			}

			if (maxCnt < q) {
				System.out.println(0);
			} else {
				System.out.println(maxNum);
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 61004
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a, b = map(int, input().split())
    p = list(map(int, input().split()))
    group_1 = list()
    group_2 = list()
    group_3 = list()

    for pi in p:
        if pi <= a:
            group_1.append(pi)
        elif pi > b:
            group_3.append(pi)
        else:
            group_2.append(pi)

    print(min(len(group_1), len(group_2), len(group_3)))


if __name__ == '__main__':
    main()


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

int main() {
    int a, b, k;
  	cin >> a >> b >> k;
  	for(int i = a; i <= min(b, a+k-1); i++){
    	cout << i << endl;
    }
  	for(int i = max(b-k+1, a+k); i <= b; i++){
    	cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main()
{
	// freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
    	cout<<"Yes";
    else
    	cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
 
int main(){
    vector<int> v;
    int num;
    for(int i = 0;i<10;i++){
        cin>>num;
        v.push_back(num);
    }
 
    sort(v.begin(),v.end(),greater<int>());
 
 
 
    for(int i = 0;i<3;i++)
        cout<<v.at(i)<<endl;
    return 0;
}

Measured memory_bytes: 3128
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main(){
	long long A, B, K;
	cin >> A >> B >> K;
	long long TK, AO;
	if (A >= K) {
		TK = A - K;
		AO = B;
	}
	else {
		TK = 0;
		K -= A;
		AO = B - K;
		if (AO < 0) {
			AO = 0;
		}
	}
	cout << TK << " " << AO << endl;
}

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

int main(){
	string s; cin >> s;
	ll n = s.size();
	ll sum = 0; ll total = 0;
	vl num(n); rep(i,n)num[i] = s[i] - '0';
	rep(tmp,(1 << n - 1)){
		bitset<9> p(tmp);
		rep(i,n){
			sum == 0 ? sum += num[i] : sum = sum * 10 + num[i];
			if(i + 1 == n || p.test(i)){
				total += sum;
				sum = 0;
			}
		}
	}
	cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int A,B,C;
  cin>>A>>B>>C;
 
  if(C-A+B>0){
  cout<<C-A+B<<endl;
  }
  else{
  cout<<0<<endl;
  }
  return 0;
}


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

int main(void){
	int n, m, i, j, count;
	char u[256][11], t[11], c;
	scanf("%d%*c",&n);
	for(i = 0;i < n;i++){
		j = 0;
		while((c = getchar()) != '\n')
			u[i][j++] = c;
		u[i][j] = '\0';
	}

	scanf("%d%*c",&m);
	count = 0;
	for(i = 0;i < m;i++){
		j = 0;
		while((c = getchar()) != '\n')
			t[j++] = c;
		t[j] = '\0';
		for(j = 0;j < n;j++)
			if(!strcmp(t,u[j])) break;
		if(j != n){
			if(count % 2 == 1)
				printf("Closed by ");
			else
				printf("Opened by ");
			count++;
		}
		else
			printf("Unknown ");
		puts(t);
	}
	return 0;
}

Measured memory_bytes: 1040
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int K;
    cin >> K;

    vector<vector<int>> cache(K + 1, vector<int>(K + 1));

    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            cache[i][j] = __gcd((unsigned int)i, (unsigned int) j);
        }
    }


    int64 S = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            int val = cache[i][j];
            for (int k = 1; k <= K; k++) {
                S += cache[val][k];
            }
        }
    }
    cout << S << "\n";

    return 0;
}


Measured memory_bytes: 3772
from collections import defaultdict as d

n, m = map(int, input().split())
h = list(map(int, input().split()))
adj = d(list)
s = set()
for j in range(m):
	a, b = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)
	s.add(a)
	s.add(b)

res = 0
for i in range(1, n+1):
	if i not in s:
		res += 1
for k, v in adj.items():
	f = 1
	for i in adj[k]:
		if h[k-1] <= h[i-1]:
			f = 0
	if f:
		res += 1
print(res)

Measured memory_bytes: 36468
S = list(input())
N = len(S)

B = ['0' for i in range(N)]
W = ['1' for i in range(N)]
for i in range(0,N,2):
    B[i] = '1'
    W[i] = '0'

X = 0
Y = 0
for i in range(N):
    if S[i] != B[i]:
        X += 1
    if S[i] != W[i]:
        Y += 1

print(min(X,Y))

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

long long fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理 from: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// factorial
long long fact(int n) {
    if (n == 1) return fac[n] = 1;
    if (fac[n]) return fac[n];
    return fac[n] = (fact(n - 1) * n) % MOD;
}

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

    int n, T;
    cin >> n >> T;
    vi c(n), t(n);
    rep(i, n) cin >> c[i] >> t[i];

    int ans = INF;
    rep(i, n) {
        if (t[i] <= T) chmin(ans, c[i]);
    }

    if (ans == INF)
        out("TLE");
    else
        out(ans);
}


Measured memory_bytes: 256
N, A, B = (int(i) for i in input().split())

def f(A, B):
  return (B - A) // 2

if (B - A) % 2 == 0:
    ans = f(A, B)
else:
    # Aが1に向かうとき
    ans_a = A + f(1, B - A)
    # BがNに向かうとき
    ans_b = (N - B + 1) + f(A + N - B +1, N)
    # 
    
    ans = min(ans_a, ans_b)
    
print(ans)

Measured memory_bytes: 3064
import copy


def bubbleSort(sort_list, N):

    before = copy.deepcopy(sort_list)

    for i in range(0, N):
        for j in range(N - 1, i, -1):
            if int(sort_list[j][1]) < int(sort_list[j - 1][1]):
                tmp = sort_list[j]
                sort_list[j] = sort_list[j - 1]
                sort_list[j - 1] = tmp

    print(' '.join(sort_list))
    print(checkStable(before, sort_list))


def selectionSort(sort_list, N):
    before = copy.deepcopy(sort_list)

    for i in range(0, N):
        minj = i

        for j in range(i, N):
            if int(sort_list[j][1]) < int(sort_list[minj][1]):
                minj = j

        if minj != i:
            tmp = sort_list[i]
            sort_list[i] = sort_list[minj]
            sort_list[minj] = tmp

    print(' '.join([str(i) for i in sort_list]))
    print(checkStable(before, sort_list))


def checkStable(before_list, sorted_list):

    for val in sorted_list:
        same_list = [
            i for i in sorted_list if (int(val[1]) == int(i[1])) and val != i
        ]
        if len(same_list) == 0:
            continue

        for data in same_list:
            bef = before_list.index(val) - before_list.index(data)
            aft = sorted_list.index(val) - sorted_list.index(data)

            if (bef > 0 and aft < 0) or (bef < 0 and aft > 0):
                return 'Not stable'

    return 'Stable'


if __name__ == "__main__":
    N = int(input())
    sort_list = input().split()

    sort_list2 = copy.deepcopy(sort_list)
    bubbleSort(sort_list, N)
    selectionSort(sort_list2, N)



Measured memory_bytes: 6348
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

Measured memory_bytes: 3668
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	LL n,k;
    cin>>n>>k;
    LL m=n%k;
    LL ans=m;
    cout<<min(ans,k-ans)<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 1 << 30;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    vector<char> v(n);
    rep(i,n){
        cin >> v[i];
    }
    auto target = v;
    sort(target.begin(),target.end());
    ll diff = 0;
    rep(i,n){
        if(target[i] != v[i])diff++;
    }
    cout << (diff +1)/2 << "\n";
    //ll cost = 0;
    //rep(i,n){
    //    if(v[i] == 'W'){
    //        ll pos = n;
    //        per(j,n-1)if(v[j] == 'R'){
    //            pos = j;break;
    //        }
    //        if(pos != n){
    //            swap(v[i],v[pos]);
    //            diff -= 2;
    //        }else{
    //            v[i] = 'R';
    //            diff--;
    //        }
    //        ++cost;
    //    }
    //    if(diff <= 0)break;
    //}
    //cout << cost << endl;
    return 0;
}

Measured memory_bytes: 3780
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 01:35:28 2020

@author: shinba
"""
n = int(input())
p = list(map(int,input().split()))

ans = 1
m = p[0]

for i in range(1,n):
    if p[i] < m:
        ans += 1
        m = p[i]

print(ans)



Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    LL r, d, x;
    cin >> r >> d >> x;
    rep(i, 10){
        x = r*x-d;
        cout << x << endl;
    }
}

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

long long int a,b,c,d,e=0,i,j,k,l;
vector<long long >v;
cin>>a;
for(i=1;i<=a;i++)
{
 cin>>b;v.push_back(b);
}
for(i=0;i<a;i++)
{
  k=v[i];
  l=0;
  x:
  if(k%2==0)
  {
  k=k/2;l++;goto x;
  }
 if(i==0)e=l;
 else e=min(e,l);

}cout<<e<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define l(s) s.size()
struct node
{
	string n;
	int s;
	int idx;
}a[105];
bool cmp(node a,node b)
{
	return a.n<b.n||a.n==b.n&&a.s>b.s;
}
int n;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i].n>>a[i].s,a[i].idx=i+1;
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++)
		cout<<a[i].idx<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,b,c,x;
	cin >> a >> b >> c;
	x = a^b^c;
	cout << (((x==a||x==b||x==c)&&(!(x==a&&x==b&&x==c)))?"Yes":"No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char c;
    while(~scanf("%c",&c)){
        getchar();
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
            printf("vowel\n");
            //printf("Since %c is a vowel, print vowel.\n",c);
        }
        else{
            printf("consonant\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N, X, m[100], ans = 0;
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> m[i];
        X -= m[i];
        ans++;
    }
    ans += X / *min_element(m, m + N);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<random>
#include<unordered_set>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod=1000000007;
const int big=1e9-10;
const llint red=0xE869120;
const llint pro=1002001;
const long double pai=3.141592653589793238462643383279;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int main(void){
	llint n,m,i,j,mae,no,kotae=0,gen=0;cin>>n>>m;
	vector<llint>imo(2*m+10);
	vector<llint>pla(2*m+10);
	vector<llint>ans(2*m+10);
	cin>>mae;
	for(i=0;i<n-1;i++){
		cin>>no;
		if(no<mae){no+=m;}
		imo[mae+2]++;
		imo[no+1]--;
		ans[no+1]-=no-mae-1;
		kotae+=no-mae;
		if(no>m){no-=m;}
		mae=no;
	}
	//for(i=1;i<imo.size();i++){cout<<imo[i]<<" ";}cout<<endl;
	for(i=1;i<imo.size();i++){pla[i]+=pla[i-1]+imo[i];}
	for(i=1;i<pla.size();i++){ans[i]+=ans[i-1]+pla[i];}
	for(i=1;i<=m;i++){
		if(i+m+m<ans.size()){maxeq(gen,ans[i]+ans[i+m]+ans[i+m+m]);}
		else{maxeq(gen,ans[i]+ans[i+m]);}
	}
	cout<<kotae-gen<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1000000000;

ll fac[201];
ll dp[201][176];//dp[i][j]iまでの素数の積でj個の約数をもつ積の数・。・？

int main()
{

   int n;
   cin >> n;
   if(n<10){cout<<0<<endl;return 0;}
   for(int i = 2;i<=n;i++)
   {
      int K = i;
      int k=K;
      for(int j = 2;j*j<=K;j++)
      {
         while(K%j==0)
         {
            fac[j]++;
            K/=j;
         }
      }
      if(K!=1)fac[K]++;
   }
   vector<int> fac2;
   rep(i,101)
   {
      if(fac[i]!=0)fac2.push_back(fac[i]);
   }
   dp[0][1]=1;
   rep(i,fac2[0])
   {
      if(i<74)dp[0][i+2]=1;
   }

   for(int i = 0;i<fac2.size()-1;i++)
   {
      for(int j =0;j<= fac2[i+1];j++)
      { 
         for(int k = 1;k<76;k++)
         {
            if(k*(j+1)<76)
            dp[i+1][(k)*(j+1)]+=dp[i][k];
         }
      }
   }

   cout<<dp[fac2.size()-1][75]<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
int main()
{
	int x, a, b, A, B;

	cin >> x;
	cin >> a;
	cin >> b;

	A = abs(x - a);
	B = abs(x - b);

	if (A < B)
		cout << "A";
	else
		cout << "B";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int n;
vector<vector<int>> g(100010);
vector<int> dp(100010);

int dfs(int v){
  if(g[v].empty()) return dp[v]=0;
  int ret=0;
  vector<int> now;
  for(auto itr:g[v]) now.push_back(dfs(itr));
  sort(begin(now),end(now));
  rep(i,len(now)){
    ret=max(now[i]+(int)len(now)-(int)i,ret);
  }
  return dp[v]=ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  FOR(i,2,n+1){
    int a;
    cin>>a;
    g[a].push_back(i);
  }
  cout<<dfs(1)<<endl;
  //FOR(i,1,n+1) cout<<i<<" "<<dp[i]<<endl;
}

Measured memory_bytes: 15488
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_V 100000
#define MAX_E 500000
#define INF INT_MAX / 2

struct Edge { int from, to, cost; };
Edge es[MAX_E];

int d[MAX_V];
int V, E;

void shortest_path(int s) {
	fill_n(d, MAX_V, INF);
	d[s] = 0;
	while (1) {
		bool update = false;
		for (int i = 0; i < E; i++) {
			Edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update) break;
	}
}

int main() {
	int r;
	cin >> V >> E >> r;
	for (int i = 0; i < E; i++)
		cin >> es[i].from >> es[i].to >> es[i].cost;
	shortest_path(r);
	for (int i = 0; i < V; i++)
		if (d[i] == INF)
			cout << "INF" << endl;
		else
			cout << d[i] << endl;
	return 0;
}

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

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

	bool res = true;
	int ans;
	while (res)
	{
		sort(monster.begin(), monster.end());
		int min = monster[0];
		for (int i = 1;i < monster.size();i++)
		{
			monster[i] %= min;
		}
		monster.erase(remove(monster.begin(), monster.end(), 0), monster.end());
		ans = min;
		if (monster.size() == 1)
		{
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
# 解説放送

def main():
    S = input()
    N = len(S)
    K = int(input())

    dp = [[[0] * 2 for _ in range(K + 1)] for _ in range(N + 1)]
    dp[0][0][0] = 1
    # dp[i][j][k]
    # i桁目まで決めてj個の非0を使って
    # k=0: そこまでの桁はSと一致
    # k=1: すでにS未満が確定

    for i, c in enumerate(S):  # 100
        for j in range(K + 1):  # 4
            for k in range(2):  # 2
                nd = int(c)
                for d in range(10):  # 10
                    ni, nj, nk = i + 1, j, k
                    if d != 0: nj += 1  # 次の桁の値dとして0以外を採用すると非0の個数njが増える
                    if nj > K: continue  # 非0の数字を使用してよい上限を超えており、加算対象ではない
                    if k == 0:  # そこまでSと一致しているとき
                        if d > nd: continue  # 次の桁の値dがS[i]を超えており、採用するとSを超えるため、加算対象ではない
                        if d < nd: nk = 1  # 次の桁の値dがs[i]を下回っており、採用すると未満が確定する
                    dp[ni][nj][nk] += dp[i][j][k]

    print(sum(dp[N][K]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

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

    string s1 = s.substr(0, n), s2 = s.substr(n, n);
    reverse(ALL(s2));

    map<pair<string, string>, ll> mp;
    REP(mask,1<<n){
        string p, q;
        REP(i,n){
            if ((mask >> i) & 1) p += s2[i];
            else q += s2[i];
        }
        mp[make_pair(p, q)]++;
    }

    ll ans = 0;
    REP(mask,1<<n){
        string p, q;
        REP(i,n){
            if ((mask >> i) & 1) p += s1[i];
            else q += s1[i];
        }
        if (mp.count(make_pair(p, q))) ans += mp[make_pair(p, q)];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 48128
#!/usr/bin/env python
# -*- coding: utf-8 -*-

n = int(input())
p = list(map(int, input().split()))

count = 0
for j in range(n-2):
    if (p[j] < p[j+1] < p[j+2]) or (p[j+2] < p[j+1] < p[j]):
        count += 1
print(count)


Measured memory_bytes: 38468
#include<iostream>
// #include <math.h>
using namespace std;
long long mod = 1000000007;

long long pow(long long x,long long y){
    long long res=1;
    for(long long i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}
int main(){
  long long n;
  long long ans;
  cin >> n;
  ans = pow(10,n)  - pow(9,n) - pow(9,n) + pow(8,n);
  ans = ans % mod;
  ans=(ans+mod)%mod;
  cout << ans << endl;
//   cout << (634095802 +2511445);
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <assert.h>
#include <string.h>

using namespace std;

typedef long long ll;

int M;
int main() {
  scanf("%d", &M);
  printf("%d\n", 48 - M);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

void compress(vector<int>& x1, vector<int>& x2, map<int, int>& unzip) {
  vector<int> xs;
  rep(i, x1.size()) {
    xs.push_back(x1[i]);
    xs.push_back(x2[i]);
  }

  sort(all(xs));
  xs.erase(unique(all(xs)), xs.end());

  vector<int> nx1, nx2;

  rep(i, x1.size()) {
    nx1.push_back(lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin());
    nx2.push_back(lower_bound(xs.begin(), xs.end(), x2[i]) - xs.begin());
    unzip[nx1.back()] = x1[i];
    unzip[nx2.back()] = x2[i];
  }
  x1 = nx1, x2 = nx2;
}

int a[333][333][333];

int main() {

  int N, K; cin >> N >> K;
  vector<int> x1(N), y1(N), z1(N), x2(N), y2(N), z2(N);
  rep(i, N) {
    cin >> x1[i] >> y1[i] >> z1[i]
        >> x2[i] >> y2[i] >> z2[i];
  }

  map<int, int> ux, uy, uz;
  compress(x1, x2, ux);
  compress(y1, y2, uy);
  compress(z1, z2, uz);

  rep(i, N) {
    REP(x, x1[i], x2[i])
    REP(y, y1[i], y2[i])
    REP(z, z1[i], z2[i])
      a[x][y][z] ++;
  }

  ll ans = 0;
  rep(x, ux.size()-1) rep(y, uy.size()-1) rep(z, uz.size()-1) {
    if(a[x][y][z] >= K) {
      ans += (ll)(ux[x+1] - ux[x]) * (uy[y+1] - uy[y]) * (uz[z+1] - uz[z]);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 14820
n, a, b = [int(i) for i in input().split()]
a_distance = a-1
b_distance = n-b
ab_distance = b - a

if ab_distance % 2 == 0:
  result = ab_distance//2
else:
  if a_distance < b_distance:
    result = a_distance + (ab_distance-1)//2 + 1
  else:
    result = b_distance + (ab_distance-1)//2 + 1
print(result)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cis(s);
    string ans;
    if (s=="Sunny") ans = "Cloudy";
    if (s=="Cloudy") ans = "Rainy";
    if (s=="Rainy") ans = "Sunny";
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define HERE cout<<"    "<<"HERE"<<en

int main(){
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  
  int x,y;
  x=(n/a+1-(n%a==0))*b;
  y=(n/c+1-(n%c==0))*d;
  
  cout<<((x>y) ? y : x)<<en
}




Measured memory_bytes: 3112
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
using Graph =vector<vector<int>>;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
typedef vector<vector<char>> cmat;

int H,W;
bool b=false;
mat dist(100,vec(100,-1));
cmat c(100,vector<char>(100));
struct BFS{
    queue<pair<int,int>> que;
    int dy[4]={0,1,0,-1};
    int dx[4]={1,0,-1,0};

    BFS(pair<int,int> p){
        que.push(p);
        dist[p.first][p.second]=0;
    }

    void func(){
        while(!que.empty()){
            pair<int,int> p=que.front();
            for(int i=0;i<4;++i){
                pair<int,int> next_p;
                next_p.first=p.first+dy[i];
                next_p.second=p.second+dx[i];
                
                if(next_p.first<0||next_p.second<0||next_p.first>=H||next_p.second>=W)continue;
                if(dist[next_p.first][next_p.second]!=-1)continue;
                if(c[next_p.first][next_p.second]=='#')continue;

                que.push(next_p);
                dist[next_p.first][next_p.second]=dist[p.first][p.second]+1;
                if(next_p.first==H-1 && next_p.second==W-1)
                    b=true;
            }
            que.pop();
            func();
        }
    }
};

int main(){
    cin>>H>>W;
    pair<int,int> start;
    start={0,0};
    
    int black=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>c[i][j]; 
            if(c[i][j]=='#')black++;
        }
    }
    
    BFS bfs(start);
    bfs.func();
    if(b)cout<<H*W-black-dist[H-1][W-1]-1<<endl;
    else cout<<-1<<endl;
    
    return 0;
}

Measured memory_bytes: 384
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports)]

use std::cmp::*;
use std::collections::*;

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        X : usize,
        Y : usize,
        Z : usize,
        K : usize,
        A : [usize; X],
        B : [usize; Y],
        C : [usize; Z],
    }

    let (mut a, mut b, mut c) = (A, B, C);
    a.sort();
    a.reverse();
    b.sort();
    b.reverse();
    c.sort();
    c.reverse();

    let mut cakes = BinaryHeap::new();
    let (ia, ib, ic) = (0usize, 0usize, 0usize);
    cakes.push((a[ia] + b[ib] + c[ic], ia, ib, ic));
    let mut exists = HashMap::new();
    exists.insert((ia, ib, ic), true);

    for _ in 0..K {
        let n = cakes.pop().unwrap();
        println!("{}", n.0);

        let (ia, ib, ic) = (n.1, n.2, n.3);
        let (nia, nib, nic) = (min(ia + 1, X - 1), min(ib + 1, Y - 1), min(ic + 1, Z - 1));

        if !exists.contains_key(&(nia, ib, ic)) {
            exists.insert((nia, ib, ic), true);
            cakes.push((a[nia] + b[ib] + c[ic], nia, ib, ic));
        }
        if !exists.contains_key(&(ia, nib, ic)) {
            exists.insert((ia, nib, ic), true);
            cakes.push((a[ia] + b[nib] + c[ic], ia, nib, ic));
        }
        if !exists.contains_key(&(ia, ib, nic)) {
            exists.insert((ia, ib, nic), true);
            cakes.push((a[ia] + b[ib] + c[nic], ia, ib, nic));
        }
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define  pb(x) push_back(x)
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define mod 1000000007
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
//i ll be the king
int main()
{
	sync;
	ll n;
	cin>>n;
	ll arr[n];
	input(arr,n);
	sort(arr,arr+n);
	ll minm=arr[n/2-1],maxm=arr[n/2];
	cout<<maxm-minm;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
vector<tuple<long long,long long,long long> > v;
long long q,h,s,d,n,cnt=0;
int main(){
	scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
	n*=4;
	v.push_back(make_tuple(q*8,1,q));
	v.push_back(make_tuple(h*4,2,h));
	v.push_back(make_tuple(s*2,4,s));
	v.push_back(make_tuple(d*1,8,d));
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		cnt+=(n/get<1>(v[i]))*get<2>(v[i]);
		n%=get<1>(v[i]);
	}
	printf("%lld",cnt);
}

Measured memory_bytes: 256
/* ABC159 D
 *
 */
#include<iostream>
#include<vector>
#include<set>

using namespace std;

int main(){
  int n; cin >> n;
  vector<int> v(n+1);
  vector<set<int>> s(n+1);
  for(int i=1;i<n+1;i++){
    cin >> v[i];
    s[v[i]].insert(i);
  }
  //計算
  long res = 0;
  for(int i=1;i<n+1;i++){
    long tmp = s[i].size();
    if(tmp!=0) {
      res += tmp*(tmp-1)/2;
    }
  }
  //出力
  for(int i=1;i<n+1;i++){
    long tmp = s[v[i]].size();
    cout << (res - (tmp*(tmp-1)/2) + ((tmp-1)*(tmp-2)/2)) << endl;
  }
  return 0;
}


Measured memory_bytes: 22144
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<cmath>

using namespace std;

long long ipow(long long b, long long idx){
    long long ans = 1;
    for(long long i = 0; i < idx; i++){
        ans *= b;
        if(ans > 1000000000000LL) return 100000000000000LL;
    }
    return ans;
}

int main(void){
    long long N, P;
    cin >> N >> P;
    long long ans = 1;
    if(N == 1){
        cout << P << endl;
        return 0;
    }
    for(long long n = 2; ipow(n, N) <= P; n++){
        if(P % ipow(n, N) == 0){
            P /= ipow(n, N);
            ans *= n;
            n--;
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long int ll;

int N;
vector<string> s;
vector<vector<char> > chvv;

int main(){
	cin >> N;

	s = vector<string>(N);
	for(int i=0; i<N; ++i){
		string str;
		cin >> str;
		s[i] = str;
	}

	chvv = vector<vector<char> >();
	for(int i=0; i<N; ++i){
		string str = s[i];
		vector<char> chv;
		copy(str.begin(), str.end(), back_inserter(chv));
		sort(chv.begin(), chv.end());
		chvv.push_back(chv);
	}

	sort(chvv.begin(), chvv.end());
	chvv.push_back(vector<char>());

	ll lcount = 0;
	ll gcount = 0;
	vector<char> prev = chvv[0];
	for(int i=1; i<N+1; ++i){
		//cerr << "i: " << i << endl;
		if(prev == chvv[i]){
			//cerr << "pathA" << endl;
			//cerr << "lcount: " << lcount << endl;
			++lcount;
		}
		else{
			//cerr << "pathB" << endl;
			//cerr << "lcount: " << lcount << endl;
			if(lcount != 0){
				//cerr << "pathB2" << endl;
				//cerr << "diff: " << (lcount * (lcount+1) / 2) << endl;
				gcount += (lcount * (lcount+1) / 2); //nCr(n: lcount, r: 2);
				//cerr << "gcount: " << gcount << endl;
				lcount = 0;
			}
			prev = chvv[i];
		}
	}
	
	for(int i=0; i<N; ++i){
		for(int j=0; j<chvv[i].size(); ++j){
			//cerr << chvv[i][j];
		}
		//cerr << endl;
	}

	cout << gcount << endl;
}


Measured memory_bytes: 15152
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]

for i in ab:
  nearst = 10 ** 9
  for j in range(m - 1, -1, -1):
    mandist = abs(i[0] - cd[j][0]) + abs(i[1] - cd[j][1])
    if mandist <= nearst:
      nearst = mandist
      num = j + 1
  print(num)

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

#define MOD 1000000007

long long pow2(long long a, long long b){
    long long ret = 1;
    while(b > 0){
        if(b % 2 == 1){
            ret = ret * a % MOD;
        }
        a = a * a % MOD;
        b /= 2;
    }
    return ret;
}
 
long long mul(int s, int e){
    long long ret = 1;
    for(int i = s; i <= e; i++){
        ret = ret * i % MOD;
    }
    return ret;
}
 
long long fact(int n){
    return mul(1, n);
}
 
long long nCr(int n, int r){
    return mul(n-r+1, n) * pow2(fact(r), MOD-2) % MOD;
}

int main()
{
    int x, y;
    cin >> x >> y;

    if((x + y) % 3 == 0)
    {
        if((x + y) / 3 <= x && x <= (x + y) * 2 / 3 && (x + y) / 3 <= y && y <= (x + y) * 2 / 3)
        {
            cout << nCr((x + y) / 3, x - (x + y) / 3) << endl;
        }
        else
        {
            cout << 0 << endl;
        }
        
    }
    else
    {
        cout << 0 << endl;
    }
    
}

Measured memory_bytes: 3612
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.ReadLine();
        string str = Console.ReadLine();

        int red = 0, blue = 0;

        foreach (char c in str)
        {
            if (c == 'R') red++;
            else blue++;
        }

        if (red > blue) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>

/*typedef struct DJIK {
	long long P, Cost;
	DJIK(long long P, long long Cost) :
		P(P),
		Cost(Cost) {};
	bool operator<(const DJIK &ano) const {
		return Cost < ano.Cost;
	}
	bool operator>(const DJIK &ano) const {
		return Cost > ano.Cost;
	}
}DJIK;
typedef struct Route {
	int b, c;
	Route(int b, int c) :
		b(b),
		c(c) {};
}Route;

std::vector<Route> S[1000];
long long went[1000];
bool isLoop(int Pos, long long Cost) {
	if (went[Pos] != 0x7fffffffffffffffll && went[Pos] < Cost)
		return true;
	went[Pos] = Cost;
	for (int i = 0; i < S[Pos].size(); i++)
		if (isLoop(S[Pos][i].b, Cost + S[Pos][i].c))
			return true;
	went[Pos] = 0x7fffffffffffffffll;
	return false;
}
int main() {
	int N, M, a, b, c;
	scanf("%d %d", &N, &M);
	for (int i = 0; i < M; i++) {
		scanf("%d %d %d", &a, &b, &c);
		S[a - 1].emplace_back(b - 1, c);
	}
	for (int i = 0; i < 1000; i++)
		went[i] = 0x7fffffffffffffffll;
	if (isLoop(0, 0)) {
		printf("inf\n");
	} else {
		long long DP[1000];
		for (int i = 0; i < 1000; i++)
			DP[0] = 0x8000000000000000ll;
		std::priority_queue<DJIK, std::vector<DJIK>, std::greater<DJIK>> queue;
		queue.emplace(0, 0);
		while (!queue.empty()) {
			DJIK cur = queue.top();
			queue.pop();

			for (Route r : S[cur.P]) {
				long long new_cost = cur.Cost + r.c;

				if (DP[r.b] < new_cost) {
					DP[r.b] = new_cost;
					queue.emplace(r.b, new_cost);
				}
			}
		}
		printf("%lld\n", DP[N - 1]);
	}
}*/
int main() {
	long long N, K, a, b, M[100001];
	for (int i = 0; i <= 100000; i++)
		M[i] = 0ull;
	scanf("%lld %lld", &N, &K);
	for (int i = 0; i < N; i++) {
		scanf("%lld %lld", &a, &b);
		M[a] += b;
	}
	long long count;
	int ID;
	for (ID = 1, count = 0; count < K; ID++)
		count += M[ID];
	printf("%d\n", --ID);
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  string S; cin >> S; int N = S.size();
  bool kuri = false; int ans = 0;
  for(int i=S.size()-1; i>=0; i--){
    int K = S[i] - '0';
    if(kuri) K++;
    kuri = false;
    if(K<5){
      ans+=K;
    }
    else if(K>5){
      ans+=(10-K);
      kuri = true;
    }
    else if(K==5){
      if(i>0){
        int M = S[i-1] - '0';
        if(M>=5) kuri = true;
      }
      ans+=5;
    }
    if(i==0 && kuri) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1412
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

int ctoi(char c) { return c - '0'; }
char itoc(int i) { return '0' + i; }

string putX(string str, int x) {
  for(int i = 0; i < str.length(); ++i) {
    if(str[i] == 'X') str[i] = itoc(x);
  }
  return str;
}

string put0(string str, unsigned int length) {
  while(str.length() < length) {
    str.insert(0, "0");
  }
  return str;
}

string calc(string s1, string s2) {
  if(s1.length() < s2.length())      s1 = put0(s1, s2.length());
  else if(s1.length() > s2.length()) s2 = put0(s2, s1.length());

  int buf = 0;
  string res = "";
  for(int i = s1.length()-1; i >= 0; --i) {
    int a = ctoi(s1[i]) + ctoi(s2[i]) + buf;
    buf = a / 10;
    res.insert(0, string(1, itoc(a%10)));
  }
  if(buf != 0) res.insert(0, string(1, itoc(buf)));
  return res;
}

void solve(string s1, string s2, string s3) {
  for(int x = 0; x <= 9; ++x) {
    if( x == 0 && 
	(s1.length() != 1 && s1[0] == 'X' ||
	 s2.length() != 1 && s2[0] == 'X' ||
	 s3.length() != 1 && s3[0] == 'X') ) continue;
    if(calc(putX(s1, x), putX(s2, x)) == putX(s3, x)) {
      cout << x << endl;
      return;
    }
  }
  cout << "NA" << endl;
}

main() {
  string str;
  while(getline(cin, str)) {
    string s1(""), s2(""), s3("");
    stringstream ss;
    char c;
    ss << str;
    while((ss >> c) && c != '+') s1 += c;
    while((ss >> c) && c != '=') s2 += c;
    while(ss >> c) s3 += c;
    solve(s1, s2, s3);
  }
}

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

using namespace std;

int main(int argc, char const *argv[])
{
  int red_count=0, white_count=0, result = 0;
  string S;
  cin >> S;
  for(int i=0;i < S.length(); i++){
    if(S[i] == '0'){
      red_count++;
    }else{
      white_count++;
    }
  }
  result = 2 * min(red_count,white_count);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n-1;i>s;i--)
#define rep_re(i,s,n)for(ll i = n-1;i>=s;i--)
ll MOD = 1e9 + 7;

ll a[100000];
int main() {
	ll n, k, s; cin >> n >> k >> s;

	ll cnt = 0;
	rep(i, 0, n) a[i] = ((s+1) % 1000000000) + 1;
	rep(i, 0, n) {
		if (cnt++ == k)break;
		a[i] = s;
	}

	rep(i, 0, n) {
		cout << a[i];
		if (i != n - 1) {
			cout << " ";
		}
	}
}


Measured memory_bytes: 2048