akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
p=[list(map(int,input().split())) for i in range(n)]
q=[list(map(int,input().split())) for i in range(m)]
for x in range(n):
  c=[]
  for y in range(m):
    c.append(abs(p[x][0]-q[y][0])+abs(p[x][1]-q[y][1]))
  print(c.index(min(c))+1)

Measured memory_bytes: 3064
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.file;
 
int main() {
        int[] hs;
        string l;
        while((l = readln()).length >= 2) printf("%d\n", to!string(to!int(l.split()[0]) + to!int(l.split()[1])).length);
        return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Christmas Eve Eve
            int n = int.Parse(Console.ReadLine());

            var prices = ReadLines(n);

            var query = prices.OrderByDescending(x => x).ToList();
            int sum = query[0] / 2 + query.Skip(1).Sum();

            Console.WriteLine(sum);
        }

        static List<int> ReadLines(int count = 0)
        {
            //[summary]コンソールの値を読み込む
            var list = new List<int>();

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string s = Console.ReadLine().TrimEnd();
                count = int.Parse(s);
            }

            for (int i = 0; i < count; i++)
            {
                string s = Console.ReadLine().TrimEnd();
                list.Add(int.Parse(s));
            }

            return list;
        }
    }
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K<=A){
    cout << 1*K << endl;
  }
  int D, E, F, G;
  if(K>A){
    E=A*1;
    D=K-A;
    if(D<=B){
      cout << E << endl;
    }
    else{
      F=D-B;
      G=F*-1;
      cout << E+G <<endl;
    }
  }
        
        
      
  
}

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

typedef long long ll;
typedef unsigned long long ull;
#define fr first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()

using namespace std;

const ll MOD = 1000000007;

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

    int n;
    cin >> n;
    ll ans = 0;
    vector<vector<int> > g(n + 1);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<ll> comp(n + 1, 0);
    vector<bool> marked(n + 1, false);
    ll sum = 0;

    for (int i = 1; i <= n; i++) {
        ll val = 1;
        for (int ot : g[i])
            if (marked[ot]) val--;
        comp[i] = val;
        sum += (n + 1 - i) * val;
        marked[i] = true;
    }

    ans = sum;

    for (int i = 1; i < n; i++) {
        //eliminate i
        sum -= (n + 1 - i) * comp[i];
        for (int ot : g[i]) {
            if (ot > i) {
                comp[ot]++;
                sum += (n + 1 - ot);
            }
        }
        ans += sum;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 16628
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    long long int a, b, x;
    long long int p, q, min, max, ans;
    
    cin >> a >> b >> x;
    
    ans = (b - a + 1) / x;
    
    if(a % x == 0) {
        p = a / x;
    } else {
        p = a / x + 1;
    }
    min = x * p;
    
    q = b / x;
    max = x * q;
    
    if((min-a)+(b-max) <= x-2) {
        ans++;
    }
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



signed main() {
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    
    
    s[k-1] += 32;
    
    mes(s);
    
    
    
    
    
   
    
    
}


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

int main(){
    string a,b;
    int c;
    cin >> a >> b;
    a = a + b;
    c = stoi(a);

    for (int i = 1; i <= 316; i++)
    {
        if (c == i*i)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }

int n, q, a[20], m;
bool used[20];

bool dfs(int sum, int d) {
	if (sum == m)
		return true;
	if (d == n || sum > m)
		return false;

	for (int i = d; i < n; ++i) {
		used[i] = true;
		if (dfs(sum + a[i], i + 1))
			return true;
		used[i] = false;
	}

	return false;
}

int main() {
	cin >> n;
	REP(i, n)
		cin >> a[i];
	cin >> q;
	while (q--) {
		cin >> m;
		if (dfs(0, 0))
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}

	return 0;
}

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

int main(){
	int n;
	vector<int> prime;
	bool num[1000001];
	for(int i = 0; i < 1000001; i++){
		num[i] = true;
	}
	num[0] = false;
	num[1] = false;

	for(int i = 2; i <= 1000; i++){
		for(int j = i*2; j <= 1000000; j += i){
			if(!num[j]){
				continue;
			}
			num[j] = false;
		}
	}

	while(cin >> n){
		int count = 0;
		for(int i = 0; i <= n; i++){
			if(num[i]){
				count++;
			}
		}
		cout << count << endl;
	}

	return(0);
}

Measured memory_bytes: 2136
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	int x,a,b;cin>>x>>a>>b;
	if(abs(x-a)<abs(x-b)) cout<<"A"<<endl;
	else cout<<"B"<<endl;
}


Measured memory_bytes: 256
S = input()
Slist = list(S)
def cut(l, i): #iは重複して追加される部分つまり1+25と1+2+5の1に当たる
    n = len(l)
    if n == 1:
        return int(l[0])+i #一桁になったらそれ以上分割しない
    if n == 0:
        return 0
    else: #そのままでは返せない
        sum = int(''.join(l))+i #全く分割しないパターン
        for jj in range(n-1):
            #sum = 0
            j=jj+1 #1~n-1
            #sum += cut(l[j:n], int(''.join(l[0:j]))) + i
            sum += cut(l[j:n], int(''.join(l[0:j]))+i)
            #print("nowsum:"+str(k)+" (i):"+str(i)+ "(j):"+str(j)+" (sum):"+str(sum))
        return int(sum)
        
print(cut(Slist, 0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define cps2(x, y) sort(all(x), y), (x).erase(unique(all(x)), end(x))
#define mem(x, y) memset(& x, y, sizeof(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	string s; cin >> s;
	if (s.back() == 's') s += "es";
	else s.pb('s');
	cout << s;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
    int N;
    cin >> N;
    vector<lint> a(N);
    string s;
    cin >> s;
    REP(i, N) {
        a[i] = s[i] - '0' - 1;
    }
    vector<lint> ncr(N);
    REP(i, N) {
        int a = N-1;
        int b = i;
        while(true) {
            if(a%2 == 0 && b%2 == 1) {
                ncr[i] = 0;
                break;
            }
            if(a == 1) {
                ncr[i] = 1;
                break;
            }
            a /= 2;
            b /= 2;
        }
        //cout << ncr[i] << endl;
    }
    vector<lint> cnt(3);
    REP(i, N) {
        cnt[a[i]]++;
    }
    if(cnt[1] == 0) {
        lint sum = 0;
        REP(i, N) {
            sum = (sum + (a[i]/2) * ncr[i]) % 2;
        }
        if(sum == 0) {
            cout << 0 << endl;
        } else {
            cout << 2 << endl;
        }
    } else {
        lint sum = 0;
        REP(i, N) {
            sum = (sum + (a[i]%2) * ncr[i]) % 2;
        }
        if(sum == 0) {
            cout << 0 << endl;
        } else {
            cout << 1 << endl;
        }
    }
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXXY 1000001
ll facs[MAXXY*2+1];

// x^n in mod
ll modpow(ll x, ll n, ll mod){
  if(n==0) return 1;

  if(n%2==0){
    return modpow(x*x%mod, n/2, mod) % mod;
  }else{
    return x * modpow(x, (n-1), mod) % mod;
  }
}

// n! in mod
ll fac(ll n){
  return facs[n];
}

// nCr in mod
ll comb(ll n, ll r){
  if(n<0 || n<r || r<0)return 0;
  ll fn = fac(n);
  ll fr = fac(r);
  ll fn_r = fac(n-r);
  
  ll d = (modpow(fr, MOD-2, MOD) * modpow(fn_r, MOD-2, MOD)) % MOD;
  ll u = fn%MOD;
  
  ll result = u * d % MOD;
 
  return result;
}

int main(){
  ll x,y;cin>>x>>y;
  ll total = (x+y)/3;
  facs[0]=1;
  rep(i, total+1)facs[i+1] = (facs[i]*(i+1))%MOD;
  if((x+y)%3 || y>2*x || x>2*y){ cout<<0<<endl; return 0; }

  ll r;
  rep1(i, total) if(i*2+total-i==x)r=i;

  cout<<comb(total, r)<<endl;

  return 0;
}



Measured memory_bytes: 6400
#include <stdio.h>

#define mod 1000000007

int main(){
    long long int n,ans,u = 1,x = 1,ab = 1;
    scanf("%lld", &n);
    for(int i = 0; i < n; i++){
        u = (u * 10) % mod;
        x = (x * 9) % mod;
        ab = (ab * 8) % mod;
    }
    ans = (u - (2 * x) % mod + ab) % mod;
    if(ans<0) ans += mod;
    printf("%lld\n", ans);
}

Measured memory_bytes: 1708
#include<stdio.h>
#include<iostream>
#include<stack>
#include<algorithm>
#define MAX 1400

using namespace std;

struct Rectangle { int height; int pos; };

int getLargestRectangle(int size, int buffer[]) {
    stack<Rectangle> S;
    int maxv = 0;
    buffer[size] = 0;
    
    for (int i = 0; i <= size; i++) {
        Rectangle rect;
        rect.height = buffer[i];
        rect.pos = i;
        if (S.empty()) {
            S.push(rect);
        } else {
            if (S.top().height < rect.height) {
                S.push(rect);
            } else if (S.top().height > rect.height) {
                int target = i;
                while (!S.empty() && S.top().height >= rect.height) {
                    Rectangle pre = S.top(); S.pop();
                    int area = pre.height * (i - pre.pos);
                    maxv = max(maxv, area);
                    target = pre.pos;
                }
                rect.pos = target;
                S.push(rect);
            }
        }
    }
    return maxv;
}

int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];

int getLargestRectangle() {
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            if (buffer[i][j]) {
                T[i][j] = 0;
            } else {
                T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
            }
        }
    }
    
    int maxv = 0;
    for (int i = 0; i < H; i++) {
        maxv = max(maxv, getLargestRectangle(W, T[i]));
    }
    
    return maxv;
}

int main() {
    scanf("%d %d", &H, &W);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf("%d", &buffer[i][j]);
        }
    }
    cout << getLargestRectangle() << endl;
    
    return 0;
}


Measured memory_bytes: 18404
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

int main() {
    ll a , b, k;
    cin >> a >> b >> k;

    for (ll i = min(a,b); i > 0; --i) {
        if (a % i == 0 && b % i == 0) {
            if (k == 1) {
                cout << i << endl;
                return 0;
            } else {
                --k;
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<string> S(N);
  vector<ll> T(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> S.at(i) >> T.at(i);
  }
  string X;
  cin >> X;
  ll x;
  for (ll i = 0; i < N; i++)
  {
    if (S.at(i) == X)
      x = i;
  }

  ll ans = 0;
  for (ll i = x + 1; i < N; i++)
  {
    ans += T.at(i);
  }
  cout << ans << endl;
}

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

int N;
int A[210];

int main() {
    cin >> N;
    for (int i=0; i<N; ++i) cin >> A[i];
    
    int counter = 0;
    
    while (true) {
        bool exist_odd = false;
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;
        }
        if (exist_odd) break;
        
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        
        ++counter;
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
tmp = list(map(int,input().split()))
n, k = tmp[0],tmp[1]
if k == 0:
  print(n**2)
  quit()
ans = 0
for i in range(k+1,n+1):
  t = n // i
  ans += (i-k) * t
  l = n - t * i - k
  if l >= 0:
    ans += (l + 1)
print(ans)

Measured memory_bytes: 3060
import java.io.*;
import java.util.Scanner;

public class Main {

	private static int h;
	private static int w;
	static boolean[][] access;
	static boolean[][] map;
	static int cnt;
	
	static void Search(int x, int y){
		if(!access[x][y]){
			cnt++;
			access[x][y]=true;
			if(x+1<h&&map[x+1][y]){
				Search(x+1,y);
			}
			if(y+1<w&&map[x][y+1]){
				Search(x,y+1);
			}
			if(x-1>=0&&map[x-1][y]){
				Search(x-1,y);
			}
			if(y-1>=0&&map[x][y-1]){
				Search(x,y-1);
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		Scanner stdIn = new Scanner(System.in);

		while(true){
			w = stdIn.nextInt();
			h = stdIn.nextInt();
			if(w==0&&h==0){
				return;
			}
			access = new boolean[h][w];
			map = new boolean[h][w];
			int x = -1, y = -1;
			for(int i=0;i<h;i++){
				char[] tmp = stdIn.next().toCharArray();
				for(int j=0;j<w;j++){
					if(tmp[j]=='.'){
						map[i][j]=true;
					}
					else if(tmp[j]=='@'){
						x = i;
						y = j;
					}
				}
			}
			cnt = 0;
			Search(x,y);
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 12000
using System;

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

            int ab = int.Parse(str[0]);
            int bc = int.Parse(str[1]);
 
            Console.WriteLine("{0}", ab * bc / 2);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n;
int sum(int x) {
	int ans = 0;
	while (x) {
		ans += x % 10;
		x /= 10;
	}
	return ans;
}
signed main() {
	cin >> n;
	int ans = inf;
	for (int i = 1; i < n; i++) {
		ans = min(ans, sum(i) + sum(n - i));
	}
	cout << ans << endl;
	endre;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main()
{
    string s, a = "2019/04/30", ans = "Heisei";
    cin >> s;

    rep(i, s.size())
    {
        if (s > a)
            ans = "TBD";
    }

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

Measured memory_bytes: 256
// Author : Mohamed sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
int main()
{
	string x, y;
	cin >> x >> y;
	int ans = 1e9;
	for (int i = 0; i < SZ(x); i++)
	{
		if (i + SZ(y) > SZ(x))break;
		int cur = 0;
		for (int j = 0; j < SZ(y); j++)
		{
			cur += (x[i + j] != y[j]);
		}
		ans = min(ans, cur);
	}
	cout << ans <<"\n";
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int DIGIT_DP(string &str,int P)
{
  vector<vector<vector<int> > > DP(str.size()+1,vector<vector<int> > (2,vector<int>(P,0)));

  DP[0][0][0] = 1;//振り分けるための1
  int L =str.size();
  for (int i = 0; i < L; i++)
  {
    // DEBUG("call","\n");
    int D =str[i] - '0';
    for (int j = 0; j < 2; j++)
    {
      for (int k = 0; k < P; k++)
      {
        for (int d = 0; d <= (j?9:D); d++)//jがfalseならDまで（未満フラグが立ってないもの） jがtrueなら強制的に桁のMAXまで見る。
        {
          DP[i+1][j||(d<D)][(k+d)%P] += DP[i][j][k];
          DP[i+1][j||(d<D)][(k+d)%P] %=MOD;
          /*
          第2インデックス d<Dか未満フラグが立ってるものに関してはDP1にDPの値が入るそうでないものはゼロ
          第3インデックス 0は有効な数字(すでに禁止文字が出ているものk==1)や現在の桁d == 4やd==9が発生しているものは1に入る。
          */
        }
        
      }
      
    }

    
  }
      return DP[L][0][0] + DP[L][1][0] -1;
}

 

void solve(void)
{
  string K;
  int D;
  cin>>K;
  cin>>D;
  
  cout<<(DIGIT_DP(K,D)+MOD)%MOD<<endl;
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

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

int main() {
    int n, m; cin >> n >> m;
    priority_queue<int> q;
    int a;
    rep(i, n){
        cin >> a;
        q.push(a);
    }

    rep(i, m){
        q.push(q.top() / 2);
        q.pop();
    }

    long long val = 0;
    while(!q.empty()){
        val += q.top();
        q.pop();
    }
    cout << val << endl;
    return 0;
}


Measured memory_bytes: 892
def comb(n, k)
  (n-k+1..n).reduce(:*) / (1..k).reduce(:*)
end

n, a, b = gets.split.map(&:to_i)
vs = gets.split.map(&:to_i).sort_by{|x|-x}
piv = vs[a-1]
greater = vs.count{|x| x>piv}
ct = vs.count(piv)
if greater==0
  puts piv
  puts (a..b).map{|i| comb(ct, i)}.reduce(:+)
else
  puts "%.15f" % vs[0...a].reduce(:+).quo(a)
  puts comb(ct, a-greater)
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int H,W;
  cin>>H>>W;
  
  vector<vector<char>> vec(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>vec[i][j];
    }
  }
  
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int check=0;
      if(vec[i][j]=='.'){
        vec[i][j]='0';
        for(int dx=-1;dx<=1;dx++){
          for(int dy=-1;dy<=1;dy++){
          int nx=i+dx,ny=j+dy;
          if(0<=nx&&nx<H&&0<=ny&&ny<W&&vec[nx][ny]=='#'){
            vec[i][j]++;
          }
          }
        }
      }
    }
  }
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<vec[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
char s[N];
int main(){
	long long n;
	scanf("%s",s);
	scanf("%d",&n);
	double wei=0;
	for(int i=0;i<strlen(s);i++){
		wei+=pow((s[i]-'0'),5*10e+15);
		if(n<=wei){
			printf("%c\n",s[i]);
			return 0;
		}
	}
    return 0;
}

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


bool prime[1000000];
int wei[1000000], sqrt_N = 1000;
int mod = 1e9 + 7;
int main()
{
        int n;
        cin >> n;

        int N, i, j, k;

        for (i = 1; i <= 5; i += 4){
                for (j = i; j <= sqrt_N; j += 6){
                        for (k = 1; k <= sqrt_N && (N = 4 * k * k + j * j) <= N; ++k){
                                if (N > 1000000) break;
                                prime[N] = !prime[N];
                        }
                        for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
                                if (N > 1000000) break;
                                prime[N] = !prime[N];
                        }
                }
        }
        for (i = 2; i <= 4; i += 2){
                for (j = i; j <= sqrt_N; j += 6){
                        for (k = 1; k <= sqrt_N && (N = 3 * k * k + j * j) <= N; k += 2){
                                if (N > 1000000) break;
                                prime[N] = !prime[N];
                        }
                        for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
                                if (N > 1000000)break;
                                prime[N] = !prime[N];
                        }
                }
        }
        for (i = 3; i <= sqrt_N; i += 6){
                for (j = 1; j <= 2; ++j){
                        for (k = j; k <= sqrt_N && (N = 4 * k * k + i * i) <= N; k += 3){
                                if (N > 1000000) break;
                                prime[N] = !prime[N];
                        }
                }
        }
        for (i = 5; i <= sqrt_N; ++i){
                if (prime[i]){
                        for (j = i * i; j <= N; j += i * i){
                                prime[j] = false;
                        }
                }
        }
        prime[2] = prime[3] = true;

        for (i = 2; i < 1000000; ++i){
                wei[i] += wei[i - 1];
                if (prime[i]) wei[i]++;
        }

        long long ans = 1;
        for (i = 0; i <= n; i++){
                if (!prime[i]) continue;

                int cnt = 1;
                for (j = 1; j <= n; j++){
                        int x = j;
                        while (x % i == 0){
                                x /= i;
                                cnt++;
                        }
                }

                ans = (ans * (cnt % mod)) % mod;
        }

        cout << ans << endl;
}



Measured memory_bytes: 5120
def main():
    x = int(input())
    q500, r = divmod(x, 500)
    q5, r = divmod(r, 5)
    ret = q500 * 1000 + q5 * 5
    print(ret)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 2940
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

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

	int r = 0, l = 0;
	rep(i, n) {
		if (s[i] == ')') {
			if (r > 0)r--;
			else l++;
		}
		else
			r++;
	}

	rep(i, l)
		s = '(' + s;
	rep(i, r)
		s += ')';
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n;
  scanf("%d\n", &n);
  char s[n];
  for (int i = 0; i < n; i++) {
    scanf("%c", &s[i]);
  }
  int count = 0;

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

  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define MAX 200000
#define SENTINEL 2000000000

typedef long long llong;

int L[MAX/2+2],R[MAX / 2+2];

llong merge(int A[],int n,int left,int mid,int right){
	int i,j,k,n1,n2;
	llong cnt = 0;
	n1 = mid-left;
	n2 = right-mid;
	
	for(i=0;i<n1;i++)L[i]=A[left+i];
	for(i=0;i<n2;i++)R[i]=A[mid +i];
	
	L[n1]=R[n2]=SENTINEL;
	
	i=j=0;
	for(k=left;k<right;k++){
		if(L[i]<= R[j]){
			A[k]=L[i++];
		}else{
			A[k]=R[j++];
			cnt+= n1-i;
		}
	}
	return cnt;
}

llong mergeSort(int A[],int n,int left,int right){
	int mid;
	llong v1, v2, v3;
	if(left+1<right){
		mid=(left + right)/2;
		v1= mergeSort(A, n, left, mid);
		v2= mergeSort(A, n, mid, right);
		v3= merge(A, n, left, mid, right);
		return v1+v2+v3;
	}
	else{ return 0;}
	
}
	
int main(){
	int n,i;
	int A[MAX];
	
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &A[i]);
	}
	
	llong ans = mergeSort(A,n,0,n);
	printf("%ld\n", ans);
	
	return 0;
}




Measured memory_bytes: 3356
#include"bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

int main() {
	int a, b;
	cin >> a >> b;
	bool ans = false;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)ans = true;
	if (ans) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> a(n);
    lint x = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 2; i < n; ++i) {
        x ^= a[i];
    }
    map<array<lint, 2>, lint> cache;
    function<lint(lint, lint, lint)> dfs = [&](lint a, lint b, lint x) {
        if (((a & 1) ^ (b & 1)) != (x & 1))
            return inf;
        if (a == 1 || a == 0) {
            if ((a ^ b) == x)
                return 0LL;
            else
                return inf;
        }
        lint c = inf, d = inf;
        if (a != 0)
            c = dfs((a - 1) >> 1, (b + 1) >> 1, x >> 1) * 2 + 1;
        d                    = dfs((a) >> 1, (b) >> 1, x >> 1) * 2;
        return cache[{a, b}] = min({inf, c, d});
    };
    lint ret = dfs(a[0], a[1], x);
    if (ret == inf)
        cout << -1 << "\n";
    else
        cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int ball[10],f;

int hukasa(int cup1,int cup2,int no){
	//cout << "NOW no:" << no << endl;
	if(no>=10)return 1;
	else if((ball[no]<cup1)&&(ball[no]<cup2))return 0;
	
	if(cup1<ball[no])return hukasa(ball[no],cup2,no+1);
	if(cup2<ball[no])return hukasa(cup1,ball[no],no+1);
}
int main(){
	int n;
	cin>>n;
	while(n!=0){
		f = 0;
		for(int i=0;i<10;i++){
			cin>>ball[i];
			}
		f = hukasa(0,0,0);
		//cout << "f is " << f << endl;
		if(f==1)cout << "YES" << endl;
		else cout<<"NO"<<endl;
		n-=1;
}
}

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

int dp[3005][3005];
int main(){
    string S,T;
    cin>>S>>T;
    for(int i=1;i<=S.size();i++){
        for(int j=1;j<=T.size();j++){
            if(S.at(i-1)==T.at(j-1))dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
        }
    }
    int i=S.size(),j=T.size();
    int p=dp[i][j];
    set<int> a;
    while(p){
        if(dp[i-1][j]==p)i--;
        else if(dp[i][j-1]==p)j--;
        else{
            a.insert(i);
            i--;j--;p--;
        }
    }
    auto itr=a.begin();
    while(itr!=a.end()){
        cout<<S.at(*itr-1);
        itr++;
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 35584
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node find(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
  return;
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


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

int main(){

    int s;
    cin >> s;

    map<int, int> pos;
    pos[s]++;

    int a_buf, a = s;
    int ans = 1;
    while(1){
        a_buf = a;
        if (a_buf%2 == 0) a = a_buf/2;
        else a = a_buf*3+1;
        pos[a]++;
        ans++;

        if (pos[a] == 2) break;
    }

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

Measured memory_bytes: 256
/*
Abdullah All Rawaha Anik
American International University - Bangladesh
18-*****-1
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define mp make_pair
#define  pb push_back
#define pf push_front
#define ll long long
const ll MAXN = 1e5+7;
ll arr[MAXN];
pii A[MAXN];
ll power(ll x, ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
ll bigmod(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    ll x,y;
    cin>>x>>y;
    string g;
    cin>>g;
    if(g==a)
    {
        cout<<x-1<<" "<<y;
    }
    else
        cout<<x<<" "<<y-1;
    return 0;
}



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

int main(){
    int n, cnt = 0;
    cin >> n;
    vector<int> p(n);
    for(int i = 0;i < n;++i){
        cin >> p[i]; 
    }
    for(int i = 1;i < n-1;++i){
        if(p[i-1] < p[i] && p[i] < p[i+1]){
            ++cnt;
        }else if(p[i-1] > p[i] && p[i] > p[i+1]){
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())

a = [0]
for i in range(1,10**5):
    a.append(a[-1]+i)
    if a[-1] >= n:
        break

if n != a[-1]:
    print('No')
    exit()

print('Yes')

k = len(a)
print(k)

s = [[] for _ in [0]*k]

cnt = 1
for i in range(1,k):
    ind = 0
    while cnt <= a[i]:
        s[i].append(cnt)
        s[ind].append(cnt)
        cnt += 1
        ind += 1

for i in range(k):
    print(len(s[i]),end=' ')
    for e in s[i]:
        print(e,end=' ')
    print('')


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	// cin.tie(0); // tie
	// ios::sync_with_stdio(false); // sync
	int N, M, P;
	while (cin >> N >> M >> P, N != 0 || M != 0 || P != 0) {
		int ticket = 0;
		int a[N];
		rep(i, N) {
			cin >> a[i];
			ticket += a[i];
		}

		if (a[M - 1] == 0) {
			cout << '0' << endl;
			continue;
		}

		int prize = 100 * ticket;
		prize -= prize * (double(P) / 100.0);

		int ans = prize / a[M - 1];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll ans=0,n;
void dfs(ll num,bool thr,bool fiv,bool sev){
    if(thr and fiv and sev and num<=n) ans++;
    if(num>n) return;
    dfs(num*10+3,true,fiv,sev);
    dfs(num*10+5,thr,true,sev);
    dfs(num*10+7,thr,fiv,true);
}

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

    cin>>n;
    dfs(0,false,false,false);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<numeric>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<ll,ll>PLL;
typedef long double ld;

int main(){
	map<int,vector<int> >mp;
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		int num;
		cin>>num;
		mp[num].push_back(i);
	}
	for(int i=1;i<=n;i++){
		cout<<mp[i].size()<<endl;
	}


	return 0;
}

Measured memory_bytes: 25428
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s;
    cin>>s;
    char ss = s[s.size()-1];
    if(ss=='3') cout<<"bon"<<endl;
    else if (ss=='0'||ss=='1'||ss=='6'||ss=='8') cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
    return 0;
}



Measured memory_bytes: 3652
from sys import stdin
from collections import deque
V, E = map(int, stdin.readline().split())
adj_list = deque([[] for _ in [0] * V])
is_visited = [False] * V
for _ in [0] * E:
    s, t = map(int, stdin.readline().split())
    adj_list[s].append(t)
out = deque()
def dfs(u):
    is_visited[u] = True
    for v in adj_list[u]:
        if not is_visited[v]:
            dfs(v)
    out.appendleft(u)
for s in range(V):
    if not is_visited[s]:
        dfs(s)
print(*out, sep='\n')

Measured memory_bytes: 11240
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
cur = 0
l = []
while cur <= len(A)-2:
    if A[cur] == A[cur+1]:
        l.append(A[cur])
        cur += 1
    cur += 1
if len(l) < 2:
    print(0)
else:
    print(l[0] * l[1])

Measured memory_bytes: 14252
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CInterpretation solver = new CInterpretation();
        solver.solve(1, in, out);
        out.close();
    }

    static class CInterpretation {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            int m = in.nextInt();
            UnionFindTree uf = new UnionFindTree(n);
            ArrayList<Integer>[] lang = new ArrayList[m];

            for (int i = 0; i < m; i++) {
                lang[i] = new ArrayList<>();
            }

            // しゃべれるものを追加
            for (int i = 0; i < n; i++) {
                int k = in.nextInt();
                for (int j = 0; j < k; j++) {
                    lang[in.nextInt() - 1].add(i);
                }
            }

            // 各言語にunion
            for (int i = 0; i < m; i++) {
                for (int j = 1; j < lang[i].size(); j++) {
                    uf.union(lang[i].get(0), lang[i].get(j));
                }
            }


            // 判定
            for (int i = 1; i < n; i++) {
                if (!uf.same(0, i)) {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");

        }

    }

    static class UnionFindTree {
        private int[] parent;
        private int[] height;
        private int[] size;

        public UnionFindTree(int size) {
            this.parent = new int[size];
            this.height = new int[size];
            this.size = new int[size];

            for (int i = 0; i < size; i++) {
                makeSet(i);
            }
        }

        private void makeSet(int i) {
            parent[i] = i;
            height[i] = 0;
            size[i] = 1;
        }

        public int find(int x) {
            if (x != parent[x]) {
                parent[x] = find(parent[x]);
            }
            return parent[x];
        }

        public void union(int x, int y) {

            int rootX = find(x);
            int rootY = find(y);

            if (rootX == rootY) { //既に結合済み
                return;
            }

            if (height[rootX] > height[rootY]) {
                parent[rootY] = rootX;
                size[rootX] += size[rootY];

            } else if (height[rootX] < height[rootY]) {
                parent[rootX] = rootY;
                size[rootY] += size[rootX];

            } else {
                parent[rootY] = rootX;
                size[rootX] += size[rootY];
                height[rootX]++;
            }
        }

        public boolean same(int x, int y) {
            return find(x) == find(y);
        }

    }
}



Measured memory_bytes: 96640
N, K = map(int, input().split())
p = list(map(int, input().split()))

from collections import deque

exv = list()

for a in p:
    exv.append((1+a)/2)

sm = 0
mx = 0

q = deque()

for a in range(N):
    sm += exv[a]
    q.appendleft(exv[a])
    if len(q) > K:
        sm -= q.pop()
    if len(q) == K:
        mx = max(mx,sm)

print('{:.12f}'.format(mx))

Measured memory_bytes: 24816
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import groupby, accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

if sum(x%2==1 for x in A)%2 == 1:
	print("NO")
else:
	print("YES")


Measured memory_bytes: 16180
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra()
{
    int minv; // 最小のコスト
    int d[MAX], color[MAX]; // d[n]は始点からnまでの最短コスト，color[v]はvの訪問状態

    for (int i = 0; i < n; i++) {
        // 最短コストと訪問状態の初期化
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0; // 始点から始点までの最短コストは0
    color[0] = GRAY; // 始点を訪問済みにする
    while (1) {
        minv = INFTY; // 最小コストをINFで初期化
        int u = -1; // 現在の頂点を初期化
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) { // 訪問するコストが最小コストより小さく，未訪問のとき
                u = i; // 現在の頂点を変える
                minv = d[i]; // 最小コストを変える
            }
        }
        if (u == -1) {
            break;
        }
        color[u] = BLACK; // 最小コストの頂点へ進み，訪問済みとする
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) { // vに訪問済みでなくu->vへのコストがINFでないとき
                if (d[v] > d[u] + M[u][v]) { // 「vへの最小コスト」より「現在までのコストと現在地からvまでのコストを加えたもの」のほうが小さい時
                    d[v] = d[u] + M[u][v]; // vまでのコストを更新
                    color[v] = GRAY; // vへ訪問済みとする
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main()
{
    cin >> n;
    //
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = INFTY;
        }
    }

    int k, c, u, v;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}



Measured memory_bytes: 3148