akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>

uint32_t numList[200000];
uint32_t numListSorted[200000];

int cmpfunc(const void * a, const void * b) {
	return *(uint32_t *)a - *(uint32_t *)b;
}

static void printMedians(const uint32_t * const numList, const uint32_t * const numListSorted, const uint32_t listSize) {
	const uint32_t medianLeft = numListSorted[listSize / 2 - 1];
	const uint32_t medianRight = numListSorted[listSize / 2];

	for (uint32_t idx = 0; idx < listSize; idx++) {
		if (numList[idx] <= medianLeft) {
			printf("%I32u\n", medianRight);
		}
		else {
			printf("%I32u\n", medianLeft);
		}
	}
}

int main(void) {
	uint32_t listSize;

	scanf("%I32u\n", &listSize);

	for (uint32_t idx = 0; idx < listSize - 1; idx++) {
		scanf("%I32u ", &(numList[idx]));
	}
	scanf("%I32u", &(numList[listSize - 1]));
	memcpy(numListSorted, numList, sizeof(uint32_t)*listSize);

	qsort(numListSorted, listSize, sizeof(uint32_t), cmpfunc);

	printMedians(numList, numListSorted, listSize);

	return 0;
}

Measured memory_bytes: 8172
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
int n, x, a[N], b[N];
int main() {
    scanf("%d%d", &n, &x);
    if (x == n) {
        puts("Yes");
        for (int i = 1; i < 2 * n; i++) printf("%d\n", i);
    } else if (x == 1 || x == 2 * n - 1)
        puts("No");
    else {
        puts("Yes");
        for (int i = 1; i < 2 * n; i++) b[i] = 1;
        if (x == 2 * n - 2) {
            a[n] = 2 * n - 1;
            b[2 * n - 1] = 0;
            a[n + 1] = x;
            b[x] = 0;
            a[n + 2] = 1;
            b[1] = 0;
            a[n - 1] = 2;
            b[2] = 0;
        } else {
            a[n] = 1;
            b[1] = 0;
            a[n + 1] = x;
            b[x] = 0;
            a[n + 2] = 2 * n - 1;
            b[2 * n - 1] = 0;
            a[n - 1] = 2 * n - 2;
            b[2 * n - 2] = 0;
        }
        int j = 1;
        for (int i = 1; i < 2 * n; i++) {
            if (!b[i]) continue;
            while (a[j]) j++;
            a[j] = i;
        }
        for (int i = 1; i < 2 * n; i++) printf("%d\n", a[i]);
    }
    return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[3001][3001];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
    ll n1=s1.size();
    ll n2=s2.size();
    for(int i=0;i<=n1;i++)
    {
        for(int j=0;j<=n2;j++)
            dp[i][j]=0;
    }
    for(int i=1;i<=n1;i++)
    {
        for(int j=1;j<=n2;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            } else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    ll x=n1,y=n2;
    vector<char> g;
    while(1)
    {
        if(dp[x][y]==dp[x][y-1])
        {
            y--;
        }
        else
        {
            if(dp[x-1][y]==dp[x][y])
            {
                x--;
            } else{
                g.push_back(s2[y-1]);
                x--;
                y--;
            }
        }

        if(x==0 || y==0)
            break;
    }
    for(int i=g.size()-1;i>=0;i--)
        cout<<g[i];
    return 0;
}

Measured memory_bytes: 70656
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    S = input().strip()
    X, Y = read_values()
    F = list(map(len, S.split("T")))

    S = {F[0]}
    if len(F) >= 2:
        for x in F[2::2]:
            SS = set()
            for s in S:
                SS.add(s + x)
                SS.add(s - x)
            S = SS

    if not X in S:
        print("No")
        return
    
    S = {0}
    if len(F) >= 1:
        for x in F[1::2]:
            SS = set()
            for s in S:
                SS.add(s + x)
                SS.add(s - x)
            S = SS
    
    if not Y in S:
        print("No")
        return 
    
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 4688
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll a, b, c; cin >> a >> b >> c;
	ll kek = c - a - b;
	if (kek < 0) {
		cout << "No\n";
	} else {
		ll ab = a * b;
		ll lol = 4 * ab;
		kek *= kek;
		if (lol < kek) {
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	}
	return 0;
}

/*


*/

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long gcd(long long a,long long b); 
main(){
  long long a,b,GCD,LCM;
  while(cin >> a >> b){
    GCD = gcd( a , b );
    LCM = (a * b)/GCD;
    cout << GCD << ' ' << LCM << endl;
  }
}
long long gcd(long long a,long long b){
  if(b == 0)return a;
  return gcd( b , a % b );
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
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; }

int main(){
    int k;cin>>k;
    string s;cin>>s;
    string x;
    if(s.size()<=k){
        cout<<s<<endl;
    }
    else {
        for (int i = 0; i < k; i++) {
            x += s[i];
        }
        cout<<x<<"..."<<endl;
    }
}

Measured memory_bytes: 3640
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String s = String.join("", sc.nextLine().split(" "));
		System.out.println(Integer.parseInt(s)%4==0 ? "YES" : "NO");
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35824
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //i について全探索する
    for (int i = 0; i < N; i++)
    {
        //A[i+1] ... A[N] の値を更新する
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}


Measured memory_bytes: 4052
#include<iostream>
#include<string>
using namespace std;
#define MAX 1100
#define INF ((int)1e9+9)

int main(){
	int A[MAX], B[MAX], n, m, t;
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>A[i];
	}
	
	cin>>m;
	
	for(int i = 0; i < m; i++){
		cin>>B[i];
	}
	
	for(int i = 0; i < n && i < m; i++){
		if(B[i] > A[i]){
			cout<<1<<endl;
			return 0;
		} else if(B[i] < A[i]){
			cout<<0<<endl;
			return 0;
		}
	}
	
	cout<<(m>n)<<endl;
	
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		while (a % 2 == 0) {
			a /= 2;
			ans++;
		}
	}
	cout << ans << '\n';

	return 0;
}


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

using namespace std;

int main() {

    int n;
    cin>>n;

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

    vector<int> dp(n);
    //Min total cost for each stone
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);

    for(i=2;i<n;i++) {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));

    }

    cout<<dp[n-1]<<endl;

    return 0;
    
}


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

using namespace std;

string str;
map<string, int> mp;

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> str; 
        sort(str.begin(), str.end());
        mp[str]++;
    }
    int i = 0;
    long long ans = 0;
    for(auto it : mp){
        ans += 1ll * it.second * (it.second - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr int N_MAX = 1000000;

ll fact[N_MAX+1], rfact[N_MAX+1];

ll perm(ll n, ll r){
    return (fact[n] * rfact[r]) % MOD;
}

ll comb(ll n, ll r){
    return (perm(n, r) * rfact[n-r]) % MOD;
}

void init(ll n){
    fact[0] = fact[1] = 1;
    rfact[0] = rfact[1] = 1;
    for(int i=2;i<=n;++i) {
        fact[i] = (fact[i-1] * (ll)i) % MOD;
        rfact[i] = 1;
        ll k = MOD-2;
        ll a = fact[i];
        while(k > 0){
            if(k & 1){
                rfact[i] *= a;
                rfact[i] %= MOD;
            }
            a *= a;
            a %= MOD;
            k  >>= 1;
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int x, y;
    cin >> x >> y;

    if((x+y) % 3) {
        cout << 0 << endl;
        return 0;
    }

    int move_cnt = (x+y) / 3;
    int xi = 0, yi = 0;
    for(;xi<=move_cnt;++xi) {
        yi = move_cnt - xi;
        if(xi * 2 + yi == x && xi + yi * 2 == y) {
            break;
        }
    }

    init(move_cnt);
    cout << comb(move_cnt, xi) << endl;

}


Measured memory_bytes: 14592
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

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

using namespace std;

template <class T>
T peak_and_pop(std::queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.front());
    q.pop();
    return t;
}

struct edge_t {
    edge_t(int n, int d):next(n),distance(d){}
    int next = 0;
    int distance = 0;
};

constexpr int unknown = 0;

struct node_t {
    int num = unknown;
    vector<int> same_node;
    vector<int> different_node;
};

void solution()
{
    int n,m;
    cin >> n >> m;
    vector<node_t> nodes(n);

    const auto connect = [&](int u, int v, int w){
        if(w % 2 == 0){
            nodes[u].same_node.push_back(v);
            nodes[v].same_node.push_back(u);
        }else{
            nodes[u].different_node.push_back(v);
            nodes[v].different_node.push_back(u);
        }
    };

    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        connect(x-1, y-1, z);
    }

    int cost = 0;
    queue<int> visit_queue;
    rep(i,n){
        if(nodes[i].num == unknown){
            nodes[i].num = 1;
            visit_queue.push(i);
            cost += 1;
        }
        while(!visit_queue.empty()){
            auto& node = nodes.at(peak_and_pop(visit_queue));
            assert(node.num != unknown);
            for(auto& j : node.same_node){
                if(nodes[j].num == unknown){
                    nodes[j].num = node.num;
                    visit_queue.push(j);
                }
            }
            for(auto& j : node.different_node){
                if(nodes[j].num == unknown){
                    nodes[j].num = node.num == 2 ? 1 : 2;
                    visit_queue.push(j);
                }
            }
        }
    }
    cout << cost << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 10368
from collections import deque

def bfs(sy,sx):
  queue = deque([[sy,sx]])
  d[sy][sx] = 0
  while queue:
    y,x = queue.popleft()
    for i,j in [(-1,0),(1,0),(0,-1),(0,1)]:
      dy,dx = y+i,x+j
      if dy < 0 or h <= dy: continue
      elif dx < 0 or w <= dx: continue
      elif s[dy][dx] == "#": continue
      elif d[dy][dx] != -1: continue
      d[dy][dx] = d[y][x] + 1
      queue.append([dy,dx])

h,w = map(int, input().split())
s = [input() for _ in range(h)]

if s[0][0] == "#" or s[h-1][w-1] == "#":
  print(-1)
  exit()

d = [[-1]*w for _ in range(h)]
bfs(0,0)
if d[h-1][w-1] == -1: print(-1)
else:
  t = 0
  for i in s: t += i.count("#")
  print(h*w - t - d[h-1][w-1] -1)

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
  lint a, b, c, d;
  cin >> a >> b >> c >> d;

  lint ans = -3e18;
  for(auto x : {a, b})
  for(auto y : {c, d}) {
    ans = max(x*y, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp  make_pair
#define ff first
#define ss second
#define pq priority_queue
#define sf scanf
int inf = (1e9) + 7;




int main(){
	int occ[26];
	memset(occ,0,sizeof(occ));


	string s;
	cin >> s;
	for (int i = 0; i < s.size(); ++i)
	{
		occ[s[i]-'a']++;
	}

	for (int i = 0; i < 26; ++i)
	{
		if(occ[i] == 0)
		{
			printf("%c\n",i+'a');
			return 0;
		}
	}
	printf("None\n");

}	

Measured memory_bytes: 512
def getval():
    n = int(input())
    h = list(map(int,input().split()))
    return n,h 

def main(n,h):
    dp = [0,abs(h[1]-h[0])]
    for i in range(1,n-1):
        x = dp[-1]+abs(h[i+1]-h[i])
        y = dp[-2]+abs(h[i+1]-h[i-1])
        dp.append(min(x,y))
    print(dp[-1])
        
if __name__=="__main__":
    n,h = getval()
    main(n,h)


Measured memory_bytes: 20448
<?php
$a = ints();
if($a[0] == 1 && $a[1] == 1){
  echo 300000+300000+400000,"\n";
}else{
  $sum = 0;
  foreach($a as $b){
    if($b==1)$sum+=300000;
    if($b==2)$sum+=200000;
    if($b==3)$sum+=100000;
  }
  echo $sum,"\n";
}

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 4728
#include<stdio.h>
const long long mod=1e9+7;
long long pre[200005];
/*快速幂板子*/
long long qmul(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res%mod;
}
/*组合数板子*/
long long C(int a,int b)
{
    long long res=1,i,j;
    for(i=1,j=a;i<=b;i++,j--)
    {
        res=res*j%mod;
        res=res*qmul(i,mod-2)%mod;
    }
    return res;
}
int main()
{
	long long n,a,b,ans;
	pre[0]=1;
    for(int i=1;i<=200005;i++)pre[i]=pre[i-1]*i%mod;
	scanf("%lld%lld%lld",&n,&a,&b);
	ans=(qmul(2,n)-1)-C(n,a)-C(n,b);
	while(ans<0)ans+=mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
const int INF = 1e8;
int main() {
	int N;
	int A;
	cin >> N;
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		sum += A - 1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
/*ALDS1_2_B*/

void SelectionSort(int array[],int N)
{
	int i,j;
	int minj;
	int temp;
	int count=0;
	
	for(i=0;i<N;i++){
		minj=i;
		for(j=i;j<N;j++){
			if(array[j]<array[minj]){
				minj=j;
			}
		}
		if(minj != i){
			temp=array[i];
			array[i]=array[minj];
			array[minj]=temp;
			count++;
		}
	}
	
	for(i=0;i<N;i++){
		printf("%d",array[i]);
		if(i!=N-1)printf(" ");
		else printf("\n");
	}
	printf("%d\n",count);
}

int main(void)
{
	int array[100]={0};
	int N;
	int i;
	
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&array[i]);
	}
	
	SelectionSort(array,N);
}


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

n = int(input())
t_bef, x_bef, y_bef, flag = 0, 0, 0, 0
travel = []
for i in range(n):
    travel.append([int(x) for x in input().split()])

for j in travel:
    t, x, y = j[0], j[1], j[2]
    check = (t - t_bef) - abs(x_bef - x) - abs(y_bef - y)
    t_bef, x_bef, y_bef = t, x, y
    if check < 0:
        print('No')
        flag = 1
        break
    if check % 2 != 0:
        print('No')
        flag = 1
        break
if flag == 0:
    print('Yes')

Measured memory_bytes: 21108
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

using D = double;

int main(){
    int n;
    cin >> n;
    D ans = (D)0.0;
    rep(i, n) {
        D d;
        string s;
        cin >> d >> s;
        if(s == "BTC") ans += d * 380000.0;
        else ans += d;
    }
    cout << fixed << setprecision(15);
    cout << ans << endl;
    return 0;
}

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

int main(){
    ll n,h;cin>>n>>h;
    ll ans=0;
    ll max_a=0;
    ll max_a_b=0;
    vector<ll> b;
    for(int i=0;i<n;i++){
        ll aa,bb;cin>>aa>>bb;
        if(max_a<aa){
            max_a=aa;
            b.push_back(max_a_b);
            max_a_b=bb;
        }
        else if(max_a==aa){
            if(max_a_b>bb){
                b.push_back(max_a_b);
                max_a_b=bb;
            }
            else b.push_back(bb);
        }
        else b.push_back(bb);
    }
    sort(b.begin(),b.end(),greater<ll>());
    for(int i=0;i<n-1;i++){
        if(b[i]<max_a) break;
        h-=b[i];
        ans++;
        if(h<=0) break;
    }
    if(h>0){
        h-=max_a_b;
        ans++;
    }
    while(true){
        if(h<=0) break;
        h-=max_a;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1400
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] ans = new int[n];
    
    for(int i = 0; i < n - 1; i++){
      int a = sc.nextInt();
      ans[a - 1] += 1;
    }

    for(int i = 0; i < n; i++){
      System.out.println(ans[i]);
    }
  }
}


Measured memory_bytes: 62276
#include <iostream>
#include <algorithm>

#define P_MAX 1000*1000

using namespace std;

int main(){
	int a, d, n;
	static bool prime[P_MAX];
	fill(prime, prime+P_MAX, true);
	prime[0] = prime[1] = false;
	for(int i=2; i<P_MAX; i++){
		if(prime[i]) for(int j=i+i; j<P_MAX; j+=i) prime[j] = false;
	}

	while(1){
		cin >> a >> d >> n;
		if(!a && !d && !n) break;
		int count=0;
		for(int i=a; i<P_MAX; i+=d){
			if(prime[i]){
				if(++count==n){
					cout << i << endl;
					break;
				}
			}
		}
	}
	return 0;
}



Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n;
int h[100005];

signed main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++) cin>>h[i];
  
  h[0]--;
  
  int flg = 1;
  
  for(int i=1;i<n;i++){
    
    if( h[i] > h[i-1] ) h[i]--;
    
    if( h[i-1] > h[i] ) flg = 0;
    
  }
  
  if( flg ) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}


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

#define M 1000000/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M/* your task */; }
int h2(int key){ return 1+(key%(M-1))/* your task */; }

int find(char str[]){
  int key, i, h;
  key = getKey(str);
  for(i = 0 ; ; i++){
    h = (h1(key) + i * h2(key))%M;
    if(strcmp(H[h], str) == 0 ) return 1;
    else if(strlen(H[h]) == 0 ) return 0;
  }
  return 0;
  /* your task */
}

int insert(char str[]){
  /* your task */
  int key, i, h;
  key = getKey(str);
  for(i = 0 ; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0 ) return 1;
    else if(strlen(H[h]) == 0 ){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

  int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
      scanf("%s %s", com, str);

      if ( com[0] == 'i' ){
        insert(str);
      } else {
        if (find(str)){
          printf("yes\n");
        } else {
          printf("no\n");
        }
      }
    }

    return 0;
  }



Measured memory_bytes: 15412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define nl '\n'
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

using vi = vector<int>;
using vll = vector<ll>;
#define allOf(x) (x).begin(), (x).end()

template <typename P, typename Q>
ostream&operator<<(ostream&os, const pair<P, Q>&p)
{return os << '(' << p.first << ", " << p.second << ')';}
template <typename K, typename V>
ostream&operator<<(ostream&os, const map<K, V>&v)
{os << '['; for(const auto&it:v) (os << it) << ", "; return os << ']';}
template <typename T> ostream&operator<<(ostream&os, const set<T>&v)
{os << '['; for(const auto&it:v) (os << it) << ", "; return os << ']';}
template <typename T> ostream&operator<<(ostream&os, const vector<T>&v)
{os << '['; for(const auto&it:v) os << it << ", "; return os << ']';}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



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

  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);

  cout << a[2] * 10 + a[1] + a[0] << endl;

  return 0;
}

/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; 
  cin >>n;
  string a;
  cin>>a;
  long long key=0;
  for(int i=0; i<n;i++) 
  {
    set<char> cs;
    for(int j=0;j<=i;j++) 
	{
      cs.insert(a[j]);
    }
    set<char> acc;
    for(int j=i+1; j<n; j++) 
	{
      if(cs.find(a[j])!=cs.end()) acc.insert(a[j]);
    }
    key=max(key,(long long)acc.size());
  }
  cout <<key<<'\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

class mod {
public:
    mod() {m_n = 0;}
    mod(ll n) {if (n >= 0) m_n = n % MOD; else m_n = n % MOD + MOD;}
    friend bool operator== (const mod& a, const mod& b) {return a.m_n == b.m_n;}
    friend bool operator!= (const mod& a, const mod& b) {return !(a == b);}
    friend mod operator+ (const mod& a, const mod& b) {return (a.m_n + b.m_n) % MOD;}
    friend mod& operator+= (mod& a, const mod& b) {return a = a + b;}
    friend mod operator- (const mod& a) {return -a.m_n;}
    friend mod operator- (const mod& a, const mod& b) {return (a.m_n + (-b.m_n)) % MOD;}
    friend mod& operator-= (mod& a, const mod& b) {return a = a - b;}
    friend mod operator* (const mod& a, const mod& b) {return (a.m_n * b.m_n) % MOD;}
    friend mod& operator*= (mod& a, const mod& b) {return a = a * b;}
    friend mod mod_pow(const mod& n, ll r) {
        if (r == 0) {
            return 1;
        } else if (r < 0) {
            return mod_pow(n, (MOD - 2) * (-r));
        } else if (r % 2 == 0) {
            mod tmp = mod_pow(n, r / 2);
            return tmp * tmp;
        } else {
            return n * mod_pow(n, r - 1);
        }
    }
    friend mod operator/ (const mod& a, const mod& b) {return a * mod_pow(b, -1);}
    friend mod& operator/= (mod& a, const mod& b) {return a = a / b;}
    friend ostream& operator<< (ostream& os, const mod& n) {os << n.m_n; return os;}
    friend istream& operator>> (istream& is, mod& n) {ll tmp; is >> tmp; n = mod(tmp); return is;}
private:
    ll m_n;
};

#define FACT_MAX 5000
mod fact[FACT_MAX], fact_inv[FACT_MAX];
void prep_fact(int N)
{
    fact[0] = 1;
    for (int n = 1; n <= N; ++n) {
        fact[n] = n * fact[n-1];
    }
}
void prep_fact_inv(int N)
{
    for (int n = 0; n <= N; ++n) {
        fact_inv[n] = mod_pow(fact[n], -1);
    }
}
void prep(int N)
{
    prep_fact(N);
    prep_fact_inv(N);
}
mod comb(int n, int k) {if (n < 0 || k < 0 || k > n) return 0; else return fact[n] * fact_inv[n-k] * fact_inv[k];}
mod multi_choose(int n, int k) {return comb(n + k - 1, k);}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    prep(2*N);
    for (int i = 1; i <= K; ++i) {
        if (N-K < i-1) {
            cout << 0 << endl;
        } else  {
            mod b = multi_choose(i, K-i);
            mod r = multi_choose(i+1, N-K-i+1);
            cout << b * r << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  string s;
  cin >> s;
  int n = s.length();
  ll tot = 1;
  VL freq(26);
  REP(i, 0, n) {
    freq[s[i] - 'a'] += 1;
  }
  REP(i, 0, 26) {
    REP(j, i + 1, 26) {
      tot += freq[i] * freq[j];
    }
  }
  cout << tot << endl;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){

int aaa[200];
int ii=0;

while(cin>>aaa[ii]){
ii++;
}

for(int i=0;i<ii;i++){
if(aaa[i]==0){
for(int j=i-1;;j--){
if(aaa[j]!=0){
cout<<aaa[j]<<endl;
aaa[j]=0;
break;
}
}
}
}


}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  map<int, int> m;
  rep(i,n) {
    m[a[i]]++;
  }
  int ans = 0;
  rep(i,n) {
    int t = m[a[i]] + m[a[i]-1] + m[a[i] + 1];
    ans = max(ans, t);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5120
#include <iostream>

using namespace std;

int main()
{
    int age;
    int cost;
    cin>>age;
    cin>>cost;


    if (age > 12)
    {
        cost=cost;
        cout<<cost;
    }

    else if (5 < age && age < 13)
    {
        cost=cost/2;
        cout<<cost;
    }
    else if (age<6)
    {
        cost=0;
        cout<<cost;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define all(v) v.begin(),v.end()
#define fi first
#define se second
const int inf = 1e9;

string str;
int a[100002][4], b[4], n;
void ins(int p, int x, int y, int z){
	a[0][p] = x;a[1][p] = y;a[n-1][p] = z;
}
signed main(){
	scanf("%lld", &n);
	cin >> str;
	if(str[0] == 'o'){
		ins(0, 1, 1, 1);
		ins(1, 1, 2, 2);
		ins(2, 2, 1, 2);
		ins(3, 2, 2, 1);
	}else{
		ins(0, 1, 1, 2);
		ins(1, 1, 2, 1);
		ins(2, 2, 1, 1);
		ins(3, 2, 2, 2);
	}
	repi(i,1,n){
		rep(j,4){
			int x = a[i-1][j], y = a[(i+1)%n][j];
			if(str[i] == 'o'){
				if(a[i][j] == 1){
					if(y != 0 && y != x)b[j] = 1;
					a[(i+1)%n][j] = x;
				}else{
					if(y != 0 && y == x)b[j] = 1;
					a[(i+1)%n][j] = x==1 ? 2 : 1;
				}
			}else{
				if(a[i][j] == 2){
					if(y != 0 && y != x)b[j] = 1;
					a[(i+1)%n][j] = x;
				}else{
					if(y != 0 && y == x)b[j] = 1;
					a[(i+1)%n][j] = x==1 ? 2 : 1;
				}
			}
		}
	}
	int f = 0;
	rep(i,4){
		if(b[i] == 0){
			rep(j,n){
				char c = a[j][i]==1 ? 'S' : 'W';
				printf("%c", c);
			}
			printf("\n");
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 3712
# D
h, w = gets.split.map(&:to_i)

c = []
10.times do |i|
  c << gets.split.map(&:to_i)
end

wall = []
h.times do |i|
  wall << gets.split.map(&:to_i)
end

# W-F でコストを最短に
10.times do |k|
  10.times do |i|
    10.times do |j|
      c[i][j] = [c[i][j], c[i][k] + c[k][j]].min
    end 
  end
end

ret = 0
wall.each do |a|
  a.each do |b|
    unless b == -1 || b == 1
      ret += c[b][1]
    end
  end
end

STDOUT.puts ret


Measured memory_bytes: 2556
class SegmentTree
  def initialize(arg, e)
    if arg.is_a?(Integer)
      v = Array.new(arg){ e }
    elsif arg.is_a?(Array)
      v = arg
    else
      raise ArgumentError
    end

    @e  = e
    @op = Proc.new { yield(_1, _2) }

    @n = v.size
    @log = ceil_pow2(@n)
    @leaf_size = 1 << @log
    @d = Array.new(@leaf_size * 2) { e }
    v.each_with_index { |v_i, i| @d[@leaf_size + i] = v_i }
    (@leaf_size - 1).downto(1) { |i| update(i) }
    self
  end

  def set(q, x)
    raise ArgumentError if (q < 0 || @n <= q)
    q += @leaf_size
    @d[q] = x
    1.upto(@log) { |i| update(q >> i) }
  end

  def get(q)
    raise ArgumentError if (q < 0 || @n <= q)
    d[leaf_size + q]
  end

  def prod(l, r)
    sml = @e
    smr = @e
    l += @leaf_size
    r += @leaf_size

    while l < r
      if l[0] == 1
        sml = @op.call(sml, @d[l])
        l += 1
      end
      if r[0] == 1
        r -= 1
        smr = @op.call(@d[r], smr)
      end
      l /= 2
      r /= 2
    end

    @op.call(sml, smr)
  end

  def all_prod
    d[1]
  end

  def max_right(l)
    return @n if l == @n

    f = Proc.new { yield(_1) }

    l += @leaf_size
    sm = @e
    loop do
      l /= 2 while l % 2 == 0
      unless f.call(@op.call(sm, @d[l]))
        while l < @leaf_size
          l *= 2
          if f.call(@op.call(sm, @d[l]))
            sm = @op.call(sm, @d[l])
            l += 1
          end
        end
        return l - @leaf_size
      end
      sm = @op.call(sm, @d[l])
      l += 1
      break if (l & -l) == l
    end

    @n
  end

  private

  def update(k)
    @d[k] = @op.call(@d[2 * k], @d[2 * k + 1])
  end

  def inspect
    t = 0
    res = "SegmentTree\n  "
    a = @d[1, @d.size - 1]
    a.each_with_index do |e, i|

      res << e.to_s << " "
      if t == i && i < @leaf_size
        res << "\n  "
        t = t * 2 + 2
      end
    end
    res
  end
end

def ceil_pow2(n)
  x = 0
  x += 1 while (1 << x) < n
  x
end

SegTree = SegmentTree
Segtree = SegmentTree

INF = (1 << 60) - 1

_, q = gets.to_s.split.map{ |t| t.to_i }
a    = gets.to_s.split.map{ |t| t.to_i }

st = Segtree.new(a, -INF) { [_1, _2].max }

q.times do
  query = gets.to_s.split.map{ |t| t.to_i }
  if query[0] == 1
    _, x, v = query
    st.set(x - 1, v)
  elsif query[0] == 2
    _, l, r = query
    puts st.prod(l - 1, r)
  else
    _, x, v = query
    puts st.max_right(x - 1) { _1 < v } + 1
  end
end


Measured memory_bytes: 38860
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int n, q;
    char s[100001];
    int count[100001]; //その文字より前に含まれるACの数
    int l, r;
    int i;
    int ans[100000];

    scanf("%d %d", &n, &q);
    scanf("%s", s);

    count[0] = 0;
    for (i = 1; i <= n; i++) {
        count[i] = count[i - 1];
        if (s[i - 1] == 'A' && s[i] == 'C') {
            count[i]++;
        }
    }    

    for (i = 0; i < q; i++) {
        scanf("%d %d", &l, &r);
        ans[i] = count[r - 1] - count[l - 1];
    }

    for (i = 0; i < q; i++) {
        printf("%d\n", ans[i]);
    }

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    cin >> s;
    for (int i = 0; i <= sz(s); ++i) {
        for (int j = i; j <= sz(s); ++j) {
            string t;
            for (int k = 0; k < sz(s); ++k) {
                if (i <= k && k < j) continue;
                t += s[k];
            }
            if (t == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define SZ(x) (int((x).size()))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
const int maxn=2e5+5;
long long ans;
int n,tot,all;
int f[maxn],g[maxn],cnt[maxn],mx[maxn],se[maxn],high[maxn],low[maxn];
char s[maxn];
vector<int>e[maxn];
void dfs1(int x,int fa){
	mx[x]=f[x]=0;
	cnt[x]=(s[x]=='1');
	rep2(i,0,SZ(e[x])){
		int y=e[x][i];
		if(y==fa)continue;
		dfs1(y,x);
		f[x]=max(f[y]+1,f[x]);
		if(f[y]+1>mx[x])se[x]=mx[x],mx[x]=f[y]+1;
		else if(f[y]+1>se[x])se[x]=f[y]+1;
		cnt[x]+=cnt[y];
	}
}
void dfs2(int x,int fa){
	rep2(i,0,SZ(e[x])){
		int y=e[x][i];
		if(y==fa)continue;
		g[y]=max((f[y]+1==mx[x]?se[x]:mx[x]),g[x])+1;
		dfs2(y,x);
	}
}
void dfs3(int x,int fa){
	if(g[x]>mx[x])se[x]=mx[x],mx[x]=g[x];
	else if(g[x]>se[x])se[x]=g[x];
	high[x]=min(se[x]+1,mx[x]-1);
	low[x]=high[x]+1;
	rep2(i,0,SZ(e[x])){
		int y=e[x][i];
		if(y==fa)continue;
		dfs3(y,x);
		if(cnt[y])low[x]=min(low[x],f[y]+1);
	}
	if(all-cnt[x])low[x]=min(low[x],g[x]);
	if(s[x]=='1')low[x]=0;
}
int main(){
	scanf("%d",&n);
	rep(i,1,n-1){
		int x,y;scanf("%d%d",&x,&y);
		e[x].pb(y);e[y].pb(x);
	}
	scanf("%s",s+1);
	rep(i,1,n)all+=(s[i]=='1');
	dfs1(1,0);dfs2(1,0);dfs3(1,0);
	rep(x,1,n)ans+=high[x]-low[x]+1;
	printf("%lld\n",ans+1);
	return 0;
}

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

int main(){
	int n, t_score=0, h_score=0;
	string taro, hanako;
	cin >> n;

	for(int i=0; i<n; i++){
		cin >> taro >> hanako;
	
		if(taro > hanako){
			 t_score += 3;
		} else if(taro == hanako) {
			t_score += 1; h_score+=1;
		} else if(taro < hanako){
			h_score += 3;
		}
	}
	cout << t_score << " " << h_score << endl;
	return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b=1,c[1000]={0},i,k,n=1,ans=1;
	scanf("%d",&a);
	for(i=2;i<=sqrt(a);i++)
	{
		n=i;
		while(n<=a)
		{
			if(n*i>a)
			{
				break;
			}
			n*=i;
			ans=max(ans,n);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	int balance = 0;
	for (int i = 0; i < n; i++) {
		string buf; cin >> buf;
		if (buf == "A")balance++;
		else balance--;

		if (balance < 0) {
			cout << "NO" << endl;
			return 0;
		}
	}

	if (balance == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;	
	}
	
	return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

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

    vector<vector<int>> vec(m);
    for(int i=0;i<n;i++){
        if(m-a[i]>=0) vec[m-a[i]].push_back(b[i]);
    }
    ll res=0;
    priority_queue<int> que;
    for(int i=m-1;i>=0;i--){
        for(auto x:vec[i]) que.push(x);
        if(!que.empty()){
            res+=que.top(); que.pop();
        }
    }
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 6400
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;


int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    
    int64_t cnt = 0;
    int64_t n_of_A = 0;
    for (int64_t i = 0; i < s.size(); i++) {
        if (s.at(i) == 'A') n_of_A++;
        else if (i < s.size() - 1 && s.at(i) == 'B' && s.at(i + 1) == 'C') {
            cnt += n_of_A;
            i++;
        } else n_of_A = 0;
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 720
n,m = map(int,input().split())
sc = []
for i in range(m):
    sc.append(list(map(int,input().split())))
sc.sort()
for i in range(m):
    if n != 1 and sc[i][0] == 1 and sc[i][1] == 0:
        print('-1')
        exit()
for i in range(m-1):
    if sc[i][0] == sc[i+1][0]:
        if sc[i][1] != sc[i+1][1]:
            print('-1')
            exit()
   
ans = [1]
for i in range(n-1):
    ans.append(0)
 
for i in range(m):
    ans[sc[i][0]-1] = sc[i][1]

if m == 0 and n == 1:
    print(0)
    exit()
ans = map(str,ans)
print(''.join(ans))

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

int findpre(ll x, vector<ll>& pre) {
    if (pre[x] == x) {
        return x;
    } else {
        ll p = findpre(pre[x], pre);
        pre[x] = p;
        return p;
    }
}

int main() {

    ll N, M;
    vector<ll> A, B;    
    cin >> N >> M;
    for (ll i = 0; i < M; ++i) {
        ll a, b;
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }
    
    vector<ll> pre(N + 1);
    for (ll i = 1; i <= N; ++i) {
        pre[i] = i;
    }
    vector<ll> size(N + 1, 1);
    vector<ll> ans(M + 1, N * (N - 1) / 2);
    ll tot = 0;
    for (ll i = M - 1; i >= 0; --i) {
        ans[i] -= tot;
        ll a = A[i];
        ll b = B[i];
        ll pa = findpre(a, pre);
        ll pb = findpre(b, pre);
        if (pa == pb) {
            continue;
        }
        tot += size[pa] * size[pb];
        size[pa] += size[pb];
        size[pb] = 0;
        pre[pb] = pa;
    }
    
    for (ll i = 0; i < M; ++i) {
        cout << ans[i] << endl;
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


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

  int X;
  cin >> X;
  while(true){
    if(IsPrime(X)){
      cout << X << endl;
      break;
    }else{
      X++;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,x,y,a,b,c,d,x1,x2,y1,y2,l,f;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	x1=n/a;
	y1=n/c;
	l=n%a;
	f=n%c;
	if(l>=1){
		x1=x1+1;
	}
	if(f>=1){
		y1=y1+1;
	}
	x2=x1*b;
	y2=y1*d;
	if(x2<=y2){
			printf("%d\n",x2);
	}
	else if(y2<=x2){
			printf("%d\n",y2);
	}
	return 0;
}


Measured memory_bytes: 2744
#include <iostream>

using namespace std;

int main(void)
{
	char c;
	cin >> c;
	switch (c) {
	case 'a':
	case 'o':
	case 'e':
	case 'i':
	case 'u':
		cout << "vowel" << endl;
		break;
	default:
		cout << "consonant" << endl;
		break;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

// MOD確認

ll tableF[200010];
ll tableI[200010];

ll modfact(ll a,ll m){
   if(tableF[a] != -1){
      return tableF[a];
   }
   if(a == 1){
      tableF[a] = 1;
      return tableF[a];
   }
   ll res = 1;
   res = a * modfact(a-1,m);
   res %= m;
   tableF[a] = res;
   return res;
}

ll modpow(ll a,ll n,ll m){//modpow(a,n,m) := a ^ n (mod m)
  ll res = 1;
  while(n > 0){
    if(n & 1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a,ll p){//modinv(a,p) := pを法とするaの逆元(※pは素数でなければならない)
    ll res = modpow(a,p-2,p);
    return res;
}

ll modCON(ll n,ll r,ll m){
   if(n < 200010){
   ll res = 1;
   if(n < 0 || r < 0 || n < r){
      return 1;
   }
   res *= tableF[n];
   res %= m;
   res *= tableI[r];
   res %= m;
   res *= tableI[n-r];
   res %= m;
   return res;
   }else{
   ll res = 1;//tableを持ってないときよう
   for(int i = 1;i <= n;i++){
      res *= i;
      res %= m;
   }
   for(int i = 1;i <= r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   for(int i = 1;i <= n-r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   return res;
   }
}

void modfill(ll m){//忘れない　約200ms
   fill(tableF,tableF+200010,-1);
   fill(tableI,tableI+200010,-1);
   tableF[0] = 1;
   tableI[0] = 1;
   for(int i = 1;i < 200010;i++){
      tableF[i] = modfact(i,m);
      tableI[i] = modinv(tableF[i],m);
   }
}

int main(){
    modfill(MOD);
    ll N,M,K;
    cin >> N >> M >> K;
    ll ans = 0;
    rep(i,K+1){
        ans += (modCON(N-1,i,MOD) * M) % MOD * modpow(M-1,N-1-i,MOD);
        ans %= MOD; 
    }
    cout << ans << endl;
} 


Measured memory_bytes: 6768