akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector <tuple<string,int,int>> score(N);
 for(int i=0; i<N; i++){
    string s; //shi no namae
    int a; //tokuten
    cin >> s >> a;
    score.at(i) = make_tuple(s,-a,i+1); //ookiijun nanode "a" ni "-" wo tsukeru
  }
  sort(score.begin(),score.end());
  for(int i=0; i<N; i++){
    string s;
    int a,b;
    tie(s,a,b) = score.at(i);
    cout << b << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	private static class Dice {
		private String top;
		private String bottom;
		private String front;
		private String back;
		private String left;
		private String right;

		public Dice(
				String top,
				String front,
				String right,
				String left,
				String back,
				String bottom)
		{
			this.top = top;
			this.front = front;
			this.right = right;
			this.left = left;
			this.back = back;
			this.bottom = bottom;
		}

		public String operationE() {
			String tmp = this.top;
			this.top = this.left;
			this.left = this.bottom;
			this.bottom = this.right;
			this.right = tmp;

			return this.top;
		}

		public String operationN() {
			String tmp = this.top;
			this.top = this.front;
			this.front = this.bottom;
			this.bottom = this.back;
			this.back = tmp;

			return this.top;
		}

		public String operationS() {
			String tmp = this.top;
			this.top = this.back;
			this.back = this.bottom;
			this.bottom = this.front;
			this.front = tmp;

			return this.top;
		}

		public String operationW() {
			String tmp = this.top;
			this.top = this.right;
			this.right = this.bottom;
			this.bottom = this.left;
			this.left = tmp;

			return this.top;
		}

		public String getTop() {
			return top;
		}

		public String getBottom() {
			return bottom;
		}

		public String getFront() {
			return front;
		}

		public String getBack() {
			return back;
		}

		public String getLeft() {
			return left;
		}

		public String getRight() {
			return right;
		}

		public boolean equal(Dice dice) {
			for (int i = 0; i < 4; i++) {
				dice.operationS();

				for (int j = 0; j < 4; j++) {
					dice.operationW();

					if (this.compare(dice)) {
						return true;
					}
				}
			}

			dice.operationW();

			for (int i = 0; i < 4; i++) {
				dice.operationS();

				for (int j = 0; j < 4; j++) {
					dice.operationW();

					if (this.compare(dice)) {
						return true;
					}
				}
			}

			return false;
		}

		public boolean compare(Dice dice) {
			if (this.getTop().equals(dice.getTop()) &&
				this.getBottom().equals(dice.getBottom()) &&
				this.getFront().equals(dice.getFront()) &&
				this.getBack().equals(dice.getBack()) &&
				this.getRight().equals(dice.getRight()) &&
				this.getLeft().equals(dice.getLeft()))
			{
				return true;
			}
			return false;
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int diceNum = Integer.parseInt(br.readLine());

		Dice[] diceList = new Dice[diceNum];

		for (int i = 0; i < diceNum; i++){
			String[] label = br.readLine().split(" ");
			Dice dice = new Dice(label[0], label[1], label[2], label[3], label[4], label[5]);
			diceList[i] = dice;
		}

		for (int i = 0; i < diceNum - 1; i++){
			for (int j = i + 1; j < diceNum; j++){
				if(diceList[i].equal(diceList[j])) {
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 25972
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N = 0;
    int cnt1 = 0,cnt2 = 0,cnt3 = 0,cnt4 = 0;
    cin >> N;
    string S[N];
    for(int i=0;i<N;i++){
        cin>>S[i];
    }

    for(int i=0;i<N;i++){
        if(S[i] == "AC"){
            cnt1++;
        }
        if(S[i] == "WA"){
            cnt2++;
        }
        if(S[i] == "TLE"){
            cnt3++;
        }
        if(S[i] == "RE"){
            cnt4++;
        }
    }

    cout << "AC x " << cnt1 << endl;
    cout << "WA x " << cnt2 << endl;
    cout << "TLE x " << cnt3 << endl;
    cout << "RE x " << cnt4 << endl; 
    return 0;
}

Measured memory_bytes: 6704
from collections import defaultdict
from itertools import combinations

D = defaultdict(list)
N = int(input())
for i in range(N):
    s = input().strip()
    if s[0] in ('M', 'A', 'R', 'C', 'H'):
        D[s[0]].append(s)

if len(D.keys()) < 3:
    print(0)
    exit()

C = combinations(list(D.keys()), 3)

ans = 0
for c in C:
    ans += len(D[c[0]]) * len(D[c[1]]) * len(D[c[2]])

print(ans)


Measured memory_bytes: 10544
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n=int(input())
l=list(map(int,input().split()))
a=lcm_list(l)
ans_l = []
for i in l:
    ans_l.append(a//i)
print(int(sum(ans_l)%(10**9+7)))

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

const int MAX = 1001;

int V,d;
int memo[MAX];

void fib(){
  memo[0] = 1 , memo[1] = 2;
  for(int i = 2 ; i < MAX ; i ++){
    memo[i] = (memo[i-1]+memo[i-2])%MAX;
  }
}

int main(void){
  while(cin>>V>>d){
    fib();
    sort(memo,memo+V+1);
    int cnt = 1;
    for(int i = 2 ; i <= V ; i++){
      if(memo[i-1]+d<=memo[i])cnt++;
    }
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 1180
// abc139_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  string s, t;
  int count = 0;
  cin >> s >> t;
  for (int i = 0; i < 3; i++) {
    if(s[i]==t[i]) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int a,b;
int main()
{
	cin>>a>>b;
	int ma=a+b;
	ma=max(ma,a-b);
	ma=max(ma,a*b);
	cout<<ma<<endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
for ($p = 0; $p <= log($n + 0.1, 9); $p++) {
	$es[] = 9 ** $p;
}
for ($p = 1; $p <= log($n + 0.1, 6); $p++) {
	$es[] = 6 ** $p;
}
rsort($es);
$q = new SplMaxHeap();
$q->insert(0);
for ($t = 1; $t <= $n; $t++) {
	$q2 = new SplMaxHeap();
	while (!$q->isEmpty()) {
		$i = $q->extract();
		foreach ($es as $e) {
			$x = $i + $e;
			if ($x > $n || isset($f[$x])) continue;
			if ($x == $n) exit("$t");
			$q2->insert($x);
			$f[$x] = 1;
		}
	}
	$q = $q2;
}

Measured memory_bytes: 13048
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	String str=scan.next();
	String ans="AC";
	if(str.charAt(0)!='A') {
		ans="WA";
	}
	int cc=0;
	for(int i=1;i!=str.length();i++) {
		char ch=str.charAt(i);
		if(Character.isUpperCase(ch)) {
			if(ch!='C') {
			ans="WA";
			}
			if(i==str.length()-1) {
				ans="WA";
			}
			if(i==1) {
				ans="WA";
			}
			cc++;
		}
	}
	System.out.println(cc==1?ans:"WA");
}
}

Measured memory_bytes: 22612
#include <iostream>
#define ll long long int
using namespace std;
ll max(ll x, ll y) {
   return (x > y) ? x : y;
}
ll knapSack(ll W, ll w[], ll v[], ll n) {
  ll i, wt;
   ll K[n + 1][W + 1];
   for (i = 0; i <= n; i++) {
      for (wt = 0; wt <= W; wt++) {
         if (i == 0 || wt == 0)
         K[i][wt] = 0;
         else if (w[i - 1] <= wt)
            K[i][wt] = max(v[i - 1] + K[i - 1][wt - w[i - 1]], K[i - 1][wt]);
         else
        K[i][wt] = K[i - 1][wt];
      }
   }
   return K[n][W];
}
int main() {
   ll n, W;
   cin >> n>>W;
   ll v[n], w[n];
   for (int i = 0; i < n; i++) {
      cin >> w[i];
      cin >> v[i];
   }
   cout << knapSack(W, w, v, n);
   return 0;
}

Measured memory_bytes: 82484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;

int main(){
	ll a, b, k; cin >> a >> b >> k;
	cout << max(a - k, (ll)0) << " " << max(b - max(k - a, (ll)0), (ll)0) << endl;;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

const int mod = 1000000007;
struct mint {
    ll x; // using long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, m;
    cin>>n>>m;
    vl ss(n), ts(m);
    cin>>ss>>ts;

    vector<vector<mint>> dp(n + 1, vector<mint>(m + 1));
    rep(i, n) {
        rep(j, m) {
            dp[i + 1][j + 1] = dp[i + 1][j];
            if (ss[i] == ts[j]) {
                dp[i + 1][j + 1] += dp[i][j] + 1;
            }
        }
        rep(j, m) dp[i + 1][j + 1] += dp[i][j + 1];
    }
    cout<<dp[n][m] + 1<<endl;
}

Measured memory_bytes: 31616
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int C[N-1], S[N-1], F[N-1];
  for(int i=0;i<N-1;++i) cin>>C[i]>>S[i]>>F[i];
  int ans[N];
  for(int i=0;i<N;++i) {
    ans[i] = 0;
    for(int j=i;j<N-1;++j) {
      if(ans[i]<=S[j]) ans[i] = S[j]+C[j];
      else ans[i] += (F[j]-ans[i]%F[j])%F[j]+C[j];
    } 
  }
  for(int i=0;i<N;++i) cout<<ans[i]<<endl;
}



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

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

  vector<vector<int>> vec(m);

  rep(i,m) {
    int k;
    cin >> k;
    vec[i].resize(k);
    rep(j,k) {
      cin >> vec[i][j];
      --vec[i][j];
    }
  }

  vector<int> p(m);
  rep(i,m) cin >> p[i];

  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    bool ok = true;
    for (int j = 0; j < m; j++) {
      int c = 0;
      for (int id : vec[j]) {
        if ((i >> id) & 1) c++;  
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    if (ok) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    vec A(N);
    Rep (i, N) {
        cin >> A[i];
    }

    sort(A.begin(), A.end(), greater<ll>());
    ll ok = P-1;

    auto solve = [&](ll a){
        ll cnt = 0;
        Rep (i, N) {
            if (A[a]+M < A[P-1]) return false;

            if (i < P-1 || a <= i) {
                cnt += M;
            } else {
                cnt += max((ll)0, A[a]+M-A[i]);
            }
        }
        if (cnt >= M*V) return true;
        else return false;
    };

    if (solve(N-1)) {
        cout << N << endl;
        return 0;
    }

    ll ng = N-1;
    while (abs(ok-ng) > 1) {
        ll mid = (ok+ng)/2;
        if (solve(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok+1 << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<string, int>> p;
    map<string, int> d;

    for (int i = 0; i < N; i++) {
        string name;
        int score;
        cin >> name >> score;
        // sort用(secondは降順)
        p.push_back(make_pair(name, -score));
        // 入力順序を逆引きするためのmap
        d[name + to_string(-score)] = i + 1;
    }
    sort(p.begin(), p.end());
    for (pair<string, int> x : p) {
        string name;
        int score;
        tie(name, score) = x;
        cout << d[name + to_string(score)] << endl;
    }
}

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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    bool ans = true;
    for (int i = 0; i < n; i++) {
        if (a.at(i) % 2 != 0) {
            continue;
        }
        if (a.at(i) % 3 == 0 || a.at(i) % 5 == 0) {
            continue;
        }
        ans = false;
    }
    if (ans) {
        cout << "APPROVED" << endl;
    }
    else {
        cout << "DENIED" << endl;

    }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T &a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T &a, T b) {
	a = std::min(a, b);
}

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)
			return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)
		return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i;
		res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m = mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)
		return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod ;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int> engine(MIN, MAX);
	return engine(mt32);
}
struct BIT{
	vector<int>bit;
	int n;
	BIT(int x){
		bit.resize(x,0);
		n=x;
	}
	void add(int x,int y){
		while(x<=n){
			bit[x]+=y;
			x+=x&-x;
		}
	}
	int sum(int x){
		int res=0;
		while(x>0){
			res+=bit[x];
			x-=x&-x;
		}
		return res;
	}
};
/*--------Library Zone!--------*/


int n;
vector<int>G[1005];
int point[1005];
bool used[1005];
int dp[1005];
void dfs(int x){
	used[x]=true;
	vector<P>v;
	int sum=0;
	for(int i:G[x]){
		if(!used[i]){
			dfs(i);
			v.push_back({dp[i],point[i]});
			sum+=dp[i]+point[i];
		}
	}
	bitset<5005>bit;
	bit.set(0);
	for(P p:v){
		bit=(bit<<p.first)|(bit<<p.second);
	}
	for(int i=point[x];i>=0;i--){
		if(bit[i]){
			dp[x]=sum-i;
			goto ok;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;exit(0);
	ok:;
}
signed main() {
	cin>>n;
	REP(i,n){
		int a;cin>>a;a--;
		G[a].push_back(i);
	}
	rep(i,n)cin>>point[i];
	dfs(0);
	cout<<"POSSIBLE"<<endl;
}


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

namespace ConsoleApp62 {
    class Program {
        static void Main(string[] args) {
            var X = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int A = X[0];
            int B = X[1];

            Console.WriteLine(Math.Ceiling((double)(B - A) / (A - 1)) + 1);
        }
    }
}


Measured memory_bytes: 13268
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    r=INT()
    print(r*3.1415*2)
if __name__ == '__main__':
    do()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define int long long
const int maxn=101,maxm=1e5+5;
int n,W;
int w[maxn],f[maxn][maxm],v[maxn];

main()
{
   //a freopen("test.inp","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>W;
    forinc(i,1,n) cin>>w[i]>>v[i];
    memset(f,127,sizeof f);
    int oo=f[0][0];
    forinc(i,0,100000) f[0][i]=0;
    forinc(i,1,n) f[i][0]=0;
    f[1][v[1]]=w[1];
    forinc(i,2,n)
    forinc(j,0,100000)
    {
        f[i][j]=f[i-1][j];
        if(j>=v[i]) f[i][j]=min(f[i][j],f[i-1][j-v[i]]+w[i]);
    }

    fordec(j,100000,0)
    {
        if(f[n][j]<=W)
        {
            cout<<j;
            break;
        }
    }
}




Measured memory_bytes: 79232
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void io(){ ios_base::sync_with_stdio(false);cin.tie(NULL);  cout.tie(NULL);}
int main()
{
    //io();
    ll tt;
    tt=1;
    cout<<fixed;
    while(tt--)
    {
        ll n;
        cin>>n;
        vector<ll> gr[n];
        for(int i=0;i<n-1;i++)
        {
            ll x;
            cin>>x;x--;
            gr[x].push_back(i);
        }
        for(int i=0;i<n;i++)
            cout<<gr[i].size()<<"\n";
    }
}


Measured memory_bytes: 14492
N,M=map(int, input().split())
#N人，全M種類
A=[]
for i in range(N):
  a=list(map(int, input().split()))
 # k = a[0]
  a = a[1:]
  #a[0]=K(K種類好きなものがある）
  #a[1,2,3,...]=好きな食べ物の種類
  A.append(a)

ans = 0
for i in range(1,M+1): #[1-M] アイテムi : 1,2,3,...,M

  # パターン1
  found = True
  for j in range(N): # human j : 0,...,N-1
      if (not i in A[j]): # [1,2,3]
          found = False
          break
  if found == True:
      ans += 1

print (ans)


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

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

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n,ma,mb;
	cin >> n >> ma >> mb;
	int a[n], b[n], c[n];
	FOR(i,0,n)cin >> a[i] >> b[i] >> c[i];
	int dp[n+1][401][401];
	FOR(i,0,n+1)FOR(j,0,401)FOR(k,0,401)dp[i][j][k] = INF;
	dp[0][0][0] = 0;
	FOR(i,0,n){
		FOR(j,0,401)FOR(k,0,401){
			if(dp[i][j][k] == INF)continue;
			dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
			dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
		}
	}
	int ans = INF;
	for(int i = 1; (i * ma < 401) && (i * mb < 401); i++){
		ans = min(ans, dp[n][i * ma][i * mb]);
	}
	if(ans == INF)ans = -1;
	ANS(ans);
	return 0;
}


Measured memory_bytes: 25984
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,min,max=0,i;
  int *b;
  scanf("%d",&a);
  b=(int *)malloc(sizeof(int) * a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  min=b[0];
  max=b[1]-b[0];
  for(i=1;i<a;i++){
    if(max<b[i]-min)max=b[i]-min;
    if(min>b[i])min=b[i];     
  }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2528
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int mod = 1e9 + 7;
int n, a[10010], d;
ll dp[10010][100][2]; // current, mod, mask
void update(ll &x, ll y) { x += y; if(x >= mod) x -= mod; }
int main()
{
    char ch = getchar();
    while(ch >= '0' && ch <= '9') a[n++] = ch - '0', ch = getchar();
    read(d);
    dp[0][0][1] = 1;
    rep(i, 0, n - 1) rep(j, 0, d - 1) {
        update(dp[i + 1][(j + a[i]) % d][1], dp[i][j][1]);
        rep(k, 0, a[i] - 1) update(dp[i + 1][(j + k) % d][0], dp[i][j][1]);
        rep(k, 0, 9) update(dp[i + 1][(j + k) % d][0], dp[i][j][0]);
    }
    printf("%lld\n", (dp[n][0][0] + dp[n][0][1] + mod - 1) % mod);
    return 0;
}

Measured memory_bytes: 15872
def bitcount(bit):
    return bin(bit).count("1")

s = []
kmask = []
n,m = map(int,input().split())

for i in range(m):
    s.append( list(map(int,input().split())) )
p = list(map(int,input().split()))

for i in s:
    mask = 0
    for j in i[1:]:
        mask |= 1<<(j-1)        
    kmask.append(mask)

result = 0
for i in range(1<<n):
    ok = True
    for mask,odd in zip(kmask,p):
        bc = bitcount(i&mask)
        if((bc&1)!=odd):
            ok = False
            break
    if ok:
        result += 1

print(result)

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

int main() {
  int N;
  cin >> N;
  vector<ll> friendly(N);
  for (int i = 0; i < N; i++) cin >> friendly[i];
  sort(friendly.begin(), friendly.end());
  reverse(friendly.begin(), friendly.end());
  ll ans = friendly[0];
  for (int i = 1; i < N-1; i++) {
    ans += friendly[(i+1)/2];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4792
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int res[100010];
int cnt[100010];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int x=a[0];
	int y=a[1];
	int c=0;
	int b=0;
	for(int i=1;i*i<=x;i++){
		if(x%i==0){
			res[c]=i;
			c++;
			res[c]=x/i;
			c++;
		}
	}
	sort(res,res+c);
	for(int i=1;i*i<=y;i++){
		if(y%i==0){
			cnt[b]=i;
			b++;
			cnt[b]=y/i;
			b++;
		}
	}
	sort(cnt,cnt+b);
	int ans=-1;
	int ans2=-1;
	for(int i=c-1;i>=0;i--){
		int ans3=0;
		for(int j=0;j<n;j++){
			if(a[j]%res[i]!=0){
				ans3++;
			}
		}
		if(ans3==0||ans3==1){
			ans=res[i];
			break;
		}
	}
	for(int i=b-1;i>=0;i--){
		int ans3=0;
		for(int j=0;j<n;j++){
			if(a[j]%cnt[i]!=0){
				ans3++;
			}
		}
		if(ans3==0||ans3==1){
			ans2=cnt[i];
			break;
		}
	}
	cout<<max(ans,ans2)<<endl;
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int rem = n%1000;

    if(rem == 0) cout << "0" << endl;
    else cout << 1000 - rem << endl;

    return 0;
}



Measured memory_bytes: 3636
#include <stdio.h>

int main(){
  int k, n, distance;
  int max = 0, sum = 0;

  scanf("%d %d", &k, &n);
  int house[n] = {0};

  for(int i = 0; i < n; i++){
    scanf("%d", &distance);
    house[i] = distance;
    if(i != 0){
      sum += house[i] - house[i-1];
      if((house[i]-house[i-1])>max){
	max = house[i] - house[i-1];
      }
    }
  }

  sum += (k-house[n-1]+house[0]);
  if(max < (k-house[n-1]+house[0])) max = (k-house[n-1])+house[0];
    

  printf("%d\n", sum-max);
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto e : a) cout << e << ' ';
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);

using namespace std;
const int N = 2e5 + 2;
string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main()
{
    fast;
    int n; cin >> n;
    string s; cin >> s;
    string ans = "";
    for(auto e : s)
    {
        int now = (int)e - 'A';
        ans += alp[(now + n)%26];
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

h,w = mi()
a = [input() for i in range(h)]

print("#"*(w+2))

for i in range(h):
    print("#",end="")
    for j in range(w):
        print(a[i][j],end="")
    print("#")
print("#"*(w+2))


Measured memory_bytes: 4340
s = gets.chomp
r = 0
if s[0] == "0"
  for i in 1...s.size
    if i.odd? && s[i] == "0"
      r += 1
    elsif i.even? && s[i] == "1"
      r += 1
    end
  end
else
  for i in 1...s.size
    if i.odd? && s[i] == "1"
      r += 1
    elsif i.even? && s[i] == "0"
      r += 1
    end
  end
end

p r

Measured memory_bytes: 1916
#!/usr/bin/env python3
import sys
from collections import deque, Counter


def solve(N: int, A: "List[int]"):
    d_A = Counter(A)
    s = sorted(d_A.keys())
    if s[0] == 1:
        print((d_A[1] == 1)*1)
        return
    
    is_d = [0]*(2*10**6)

    for s_t in s:
        lim = 10**6 // s_t +1
        for i in range(1,lim):
            is_d[i*s_t] +=1
    
    ans = 0
    for s_t in s:
        if (d_A[s_t] == 1) and (is_d[s_t]==1):
            ans+=1
    print(ans)


        

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 125228
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[] qac = new boolean[n+1];
        int[] qwa = new int[n+1];
        int ac = 0;
        int wa = 0;

        for(int i = 0;i < m;i++){
            int sub = sc.nextInt();
            String res = sc.next();
            if(res.equals("AC")){
                qac[sub] = true;
            }else{
                if(!qac[sub])
                    qwa[sub]++;
            }
        }
        for(int i = 1;i < n+1;i++){
            if(qac[i]){
                ac++;
                wa += qwa[i];
            }
                
        }
        System.out.println(ac+" "+wa);
    }
}

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


int main()
{
    string s;
    cin >> s;
    ll blacks = 0;
    ll ans = 0;
    for (ll i = 0; i < s.length(); i++) {
        if (s[i] == 'B') {
            blacks++;
        } else {
            ans += blacks;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3768
#include <stdio.h>
#include <math.h>

int main(){
    int N,L,sum=0,ans=0;
    scanf("%d %d",&N,&L);
    for(int i=1;i<N+1;i++){
        sum+=L+i-1;
    }
    if(L>=0){
        printf("%d",sum-L);
        return 0;
    }
    if(L+N-1<0){
        printf("%d",sum-(L+N)+1);
    }else{
        printf("%d",sum);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTA(a,n) sort(a,a+n)
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
  string s;
  cin >> s;
  string ans="None";
    //処理
  for(char i='a'; i<='z'; i++){
    bool check = true;
  	REP(j,0,s.length()){
    	if(i==s[j]) check=false;
    }
  	if(check){
      ans = i;
      break;
    }
  }
    //出力
	cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 512
// g++ A.cpp -Wall -Wextra -Woverflow -Wshadow -O2
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>
 
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = 100005;

int n;
int v[MAXN];
int cnt[MAXN][2];
int best[2][2];
int num[2][2];
int main() {
  ios::sync_with_stdio(false); 
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    cnt[v[i]][i % 2]++;
  }
  int ans = n;
  for (int s = 0; s < 2; s++) {
    for (int i = 0; i < MAXN; i++) {
      if (best[s][1] < cnt[i][s]) {
        best[s][1] = cnt[i][s];
        num[s][1] = i;
      }
      if (best[s][1] > best[s][0]) {
        swap(best[s][1], best[s][0]);
        swap(num[s][1], num[s][0]);
      }
    }
  }
  if (num[0][0] != num[1][0]) {
    ans -= (best[0][0] + best[1][0]);
  } else {
    ans -= max(best[0][0] + best[1][1], best[0][1] + best[1][0]);
  }
  cout << ans << '\n';
}

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

template <typename InputIterator>
typename InputIterator::value_type
summation(InputIterator first, InputIterator last) {
  using T = typename InputIterator::value_type;
  T *p = new T();
  const auto sum = std::accumulate(first, last, *p);
  delete p;
  return sum;
}
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<std::string> s(n);
  std::cin >> s;
  std::vector<std::vector<int>> c(26, std::vector<int>(n, 0));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < s[i].size(); j++) {
      c[s[i][j] - 'a'][i]++;
    }
  }

  std::vector<int> al(26);

  for (int i = 0; i < 26; i++) {
    al[i] = *std::min_element(c[i].cbegin(), c[i].cend());
  }

  std::string ans("");

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < al[i]; j++) {
      ans.push_back(static_cast<char>('a' + i));
    }
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr auto INF = INT_MAX / 2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {
	
	int n;
	cin >> n;
	V<string> w(n);
	set<string> set;
	rep(i, n) {
		cin >> w[i];
		set.insert(w[i]);
	}
	bool ok = true;
	rep(i, n - 1)if (w[i][w[i].size() - 1] != w[i + 1][0])ok = false;

	if (ok && set.size() == n)cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 384
n,m,x = map(int,input().split())

min_ = 10**8

costs = []
effects = []

for i in range(n):
  ca = list(map(int, input().split()))
  costs.append(ca[0])
  effects.append(ca[1:])

for i in range(2**n):
  now_cost = 0
  now_effects = [0]*m
  for j in range(n):  # このループが一番のポイント
    if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
      for k in range(m):
        now_effects[k] += effects[j][k]
      now_cost += costs[j]

  ok=True    
  for k in range(m):
    if now_effects[k] < x:
      ok=False
      break
  if ok:
    min_ = min(min_,now_cost)

if min_ == 10**8:
  print(-1)
  exit()
print(min_)


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define Task "B"

using namespace std;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    for(int i = 0; i<s.size(); ++i){
        if (((i+1) % 2) && (s[i] == 'L')){
            cout << "No";
            return 0;
        }
        if (((i+1)%2 == 0) && (s[i] == 'R')){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int k=0;
	while(1)
	{
		if(k==0)
		{
			c-=b;
			if(c<=0)
			{
				cout<<"Yes";
				break;
			}
			k=1;
		}else{
			a-=d;
			if(a<=0)
			{
				cout<<"No";break;
			}
			k=0;
		}
	}
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(void) {
	char moji[101];
	int i;
	int count;
	int math;
	scanf("%s",moji);

	for (i = 0; i < 101;i++) {
		if (moji[i] == '\0') {
			count = i;
			math = i - 2;
			break;
		}
	}

	printf("%c%d%c\n",moji[0],math,moji[count-1]);
	return 0;
}

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

using namespace std;

int main() {
  // input
  string s;
  cin >> s;

  for (int i=0; i<3; i++){
    if (s[i]=='1'){
      s.at(i)='9';
    }else if(s[i]=='9'){
      s.at(i)='1';
    }
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        Set<Integer> set = new HashSet<>();
        for(int i = 0; i < n; ++i) {
            set.add(Integer.parseInt(sc.next()));
        }
        String ans = (set.size() == n) ? "YES" : "NO";
        System.out.println(ans);
    }
}

Measured memory_bytes: 70380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, k, q;
    cin >> n >> k >> q;
    ll bar = max(0LL, q-k+1);
    map<ll, ll> cnt;
    rep(i, 0, q) {
        ll a;
        cin >> a;
        a--;
        cnt[a]++;
    }
    rep(i, 0, n) {
        if (cnt[i] >= bar) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 6912
a,b=map(int,input().split())
n=[1,3,5,7,8,10,12]
m=[4,6,9,11]
o=[2]
p=[n,m,o]
if (a in n and b in n) or (a in m and b in m) or (a in o and b in o):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a;i < b; i++)

int main() {

	int n;
	cin >> n;

	ll count = 0;

	map<string, int> data;

	vector<string> s(n);

	queue<string> q;

	rep(i, 0, n) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
		if (data[s[i]] == 0) q.push(s[i]);
		data[s[i]]++;
	}
	
	while (!q.empty()) {
		string str = q.front();
		if (data[str] > 1) {
			ll x = data[str];
			x *= (x - 1);
			x /= 2;
			count += x;
		}
		q.pop();
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 23680
/* be name khoda */

// #define stream_enable
// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 100010;

ll n;
vi subt[maxn];
ll dp[maxn];

void dfs(ll x) {
    vi vec;
    for (auto y : subt[x]) {
        dfs(y);
        vec.eb(dp[y]);
    }
    sort(all(vec), greater<ll>());
    fori (i, (ll) subt[x].size()) {
        smax(dp[x], vec[i] + i + 1);
    }
}

void MAIN() {

    cin >> n;
    fori (i, n - 1) {
        ll p; cin >> p; --p;
        subt[p].eb(i + 1);
    }
    dfs(0);
    cout << dp[0] << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
4
4
4
1
    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 13952
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

int main() {
    llong a, b;

    cin >> a >> b;

    if (a / 10 == 0 && b / 10 == 0) {
        cout << a * b << endl;
    }
    else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long  a[5],f[5],p[5],n,b[5],ans;
bool cmp( int a, int b ){ return f[a]<f[b]; }
int main(){
	for( int i = 1; i <= 4; i++ ) scanf("%d", &a[i]),p[i]=i; scanf("%d", &n); n *= 4;
	f[1] = a[1]*8; f[2] = a[2]*4; f[3] = a[3]*2; f[4] = a[4];
	sort(p+1,p+5,cmp);
	int tail = 1;
	for( int i = 1; i <= 4; i++ ){
		if( p[i] == 4 ) b[p[i]] = 8;
		else if( p[i] == 3 ) b[p[i]] = 4;
		else b[p[i]] = p[i];
	}
	while(n){
		int x = n/b[p[tail]];
		ans += (long long)x*a[p[tail]];
		n %= b[p[tail]];
		tail++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
ulong[] generate_prime_list(T)(T N) if(isIntegral!T) {
	ulong[] prime_list = [2];
	bool not_prime = false;
	foreach(i; 3..N.to!ulong+1) {
		auto p = i.to!float.sqrt.ceil.to!ulong;
		foreach(j; prime_list) {
			if(j > p) break;
			if(i % j == 0) {
				not_prime = true;
				break;
			}
		}
		if(!not_prime) prime_list ~= i;
		not_prime = false;
	}
	return prime_list;
}

void main() {
	auto X = ri;
	auto arr = generate_prime_list(100010);
	foreach(v; arr) {
		if(X > v) continue;
		else {
			v.writeln;
			return;
		}
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll MOD = ll(1e9+7);
constexpr int MAX_X = 1e5+5;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> cnt(MAX_X,0), ev(m,0), od(m,0);
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        cnt[x]++;
    }
    for(int i=0;i<MAX_X;i++){
        od[i%m] += cnt[i]&1;
        ev[i%m] += cnt[i]-cnt[i]%2;
    }
    int ans = 0;
    for(int i=0;i<m;i++){
        int j = (m-i%m)%m;
        if(i != j){
            int k = min(od[i]+ev[i], od[j]+ev[j]);
            ans += k;
            if(od[i] < k){
                ev[i] -= k-od[i];
                od[i] = 0;
            }
            else{
                od[i] -= k;
            }
            if(od[j] < k){
                ev[j] -= k-od[j];
                od[j] = 0;
            }
            else{
                od[j] -= k;
            }
        }
        else{
            ans += (od[i]+ev[i])/2;
            od[i] = 0;
            ev[i] = 0;
        }
    }
    for(int i=0;i<m;i++){
        ans += ev[i]/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<iostream>
using namespace std;
int q;long long sum,a,b,m=100000000000;bool flag;
int main()
{
    cin>>q;
    while(q--)
    {
        cin>>a>>b;
        sum+=b;
        if(m>b&&b<a)
            m=b;
        if(a!=b)
            flag=1;
    }
    if(flag)
        cout<<sum-m;
    else cout<<0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

const int timeLimit = 1980;

i64 xor128()
{
  static i64 x = 123456789, y = 362436069, z = 521288629, w = 88675123;
  i64 t = (x ^ (x << 11));
  x = y;
  y = z;
  z = w;
  return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

i64 D;
i64 c[26];
i64 s[365][26];
vector<i64> ans;

i64 eval(vector<i64> &ans)
{
  i64 score = 0;
  i64 last[26] = {};
  for (i64 i = 0; i < D; i++)
  {
    score += s[i][ans[i]];
    last[ans[i]] = i + 1;
    for (i64 j = 0; j < 26; j++)
      score -= c[j] * (i + 1 - last[j]);
  }
  return score;
}

void solve()
{
  chrono::system_clock::time_point start = chrono::system_clock::now();
  chrono::system_clock::time_point end = start + chrono::milliseconds(timeLimit);
  i64 bestScore = 0, loop = 0;
  // while (chrono::system_clock::now() < end)
  i64 M;
  cin >> M;
  for (i64 i = 0; i < M; i++)
  {
    i64 t[3] = {xor128() % D, xor128() % 26};
    cin >> t[0] >> t[1];
    t[0]--;
    t[1]--;
    t[2] = ans[t[0]];
    ans[t[0]] = t[1];
    i64 score = eval(ans);
    cout << score << endl;
    if (bestScore < score)
    {
      bestScore = score;
    }
    // else
    // {
    //   ans[t[0]] = t[2];
    // }
    loop++;
  }
  cerr << "score: " << bestScore + (i64)(1e6) << endl
       << "loop: " << loop << endl;
}

void input()
{
  cin >> D;
  for (i64 i = 0; i < 26; i++)
    cin >> c[i];
  for (i64 i = 0; i < D; i++)
    for (i64 j = 0; j < 26; j++)
      cin >> s[i][j];
  ans.resize(D);
  for (i64 i = 0; i < D; i++)
  {
    cin >> ans[i];
    ans[i]--;
  }
}

void output()
{
  for (i64 i = 0; i < D; i++)
    cout << ans[i] + 1 << endl;
}

int main()
{
  input();
  solve();
  // output();
  return 0;
}


Measured memory_bytes: 3696