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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, a, b;
  cin >> n >> a >> b;
  
  if(n == 1){
    if(a == b) cout << 1 << '\n';
    else cout << 0 << '\n';
    return 0;
  }
  
  if(a > b){
    cout << 0 << '\n';
    return 0;
  }
  
  ll d, u;
  d = a * (n - 1) + b;
  u = b * (n - 1) + a;
  
  cout << u - d + 1 << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    for(int i=0;i<tx-sx;i++)cout<<"R";
    for(int i=0;i<ty-sy;i++)cout<<"U";
    for(int i=0;i<tx-sx;i++)cout<<"L";
    for(int i=0;i<ty-sy;i++)cout<<"D";
    cout<<"D";
    for(int i=0;i<=tx-sx;i++)cout<<"R";
    for(int i=0;i<=ty-sy;i++)cout<<"U";
    cout<<"L";
    cout<<"U";
    for(int i=0;i<=tx-sx;i++)cout<<"L";
    for(int i=0;i<=ty-sy;i++)cout<<"D";
    cout<<"R"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
dp = [[0 for _ in range(3)] for _ in range(n)]
lis = list(map(int, input().split()))
dp[0][0] = lis[0]
dp[0][1] = lis[1]
dp[0][2] = lis[2]
for i in range(1,n):
  lis = list(map(int, input().split()))
  for j in range(3):
    for k in range(3):
      if j==k:
        continue
      dp[i][k] = max(dp[i-1][j]+lis[k], dp[i][k])

print(max(dp[-1]))

Measured memory_bytes: 28624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int x, y, z;
	cin >> x >> y >> z;

	x -= 2 * z;
	if(x < y){
		cout << 0 << endl;
		return 0;
	}

	x -= y;

	cout << x / (y + z) + 1 << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;



int main()
{
    fastInp;

    ll h, w, n;
	cin >> n >> h >> w;

	cout << (n - h + 1) * (n - w + 1);

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;

vector<int> G[100050];

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

int N,M;
cin >> N >> M;

rep(i,M) {
    int u,v;
    cin >> u >> v;
    --u; v--;
    G[u].push_back(v);
}
int s,t;
cin >> s >> t;
--s; --t;

vvl dist(N, vl(3, -1));
dist[s][0] = 0;
queue<pii> que;
que.push({s, 0});

while(!que.empty()) {
    pii cur = que.front();
    que.pop();
    int v = cur.fi;
    int r = cur.se;
    for(auto nv : G[v]) {
        int nr = (r + 1) % 3;
        if(dist[nv][nr] == -1) {
            dist[nv][nr] = dist[v][r] + 1;
            que.push({nv, nr});
        }
    }
}

if(dist[t][0] == -1) cout << -1 << endl;
else cout << dist[t][0] / 3 << endl;

return 0;
}

Measured memory_bytes: 11264
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] line1 = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		long[] points = Stream.of(sc.nextLine().split(" ", 0)).mapToLong(Long::parseLong).toArray();
		sc.close();
		long ans = Math.abs(points[0] - line1[1]);
		Main main = new Main();
		for (int i = 1; i < line1[0]; i++) {
			ans = main.GCD(ans, Math.abs(points[i] - line1[1]));
		}
		System.out.println(ans);
	}

	public long GCD(long num1, long num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	}


}

Measured memory_bytes: 47452
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int g[N][N],f[N][N];
typedef pair <int ,int >PII;
int main()
{
	cin.tie(0);ios::sync_with_stdio(0);
	int n;
	string s;
	cin>>s;
	int r=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='R')r++;
	}
	if(r==0||r==3||r==1)printf("%d\n",r);
	else if(r==2)
	{
		if(s[1]=='R')printf("2\n");
		else puts("1");
	}

	return 0;
}

//多写注释 理清思路 理解题意 think twice




Measured memory_bytes: 3736
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c,d;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>a>>b>>c;
  if((b+c)%2==0){
    cout <<abs(b,c)/2<<'\n';
  }
  else{
    if(b>c) swap(b,c);
    
    cout <<min(abs(c,1LL),abs(b,a))-((c-b)/2)<<'\n';
  }
  return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007

ll power(ll a, ll e){
    if(e==0) return 1;
    if(e%2==0){
        ll r = power(a, e/2);
        return r * r % MOD;
    } else {
        ll r = power(a, e/2);
        return r * r % MOD * a % MOD;
    }
}

ll Inv(ll a){
    return power(a, MOD-2);
}

ll Fact(ll a){
    ll r = 1;
    for(int i=2; i<=a; i++)
        r = r * i % MOD;
    return r;
}


int gcd(int a, int b){
    while(b){
        int t = a;
        a = b;
        b = t%b;
    }
    return a;
}

int lcm(int a, int b){
    return a*b/gcd(a, b);
}


int main(){
    ll a, b, c; cin >> a >> b >> c;
    if(a+b+1>=c){
        cout << b + c << endl;
    }else{
        cout << a + 2*b + 1 << endl;
    }
    
    
    
    return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin>>n;
	int mat[n][3];
	int dp[n][3];
	for(int i=0;i<n;i++)
	{
		cin>>mat[i][0]>>mat[i][1]>>mat[i][2];
	}
	dp[0][0] = mat[0][0];
	dp[0][1] = mat[0][1];
	dp[0][2] = mat[0][2];
	for(int i=1;i<n;i++)
	{
		dp[i][0] = max(dp[i-1][1] + mat[i][0], dp[i-1][2] + mat[i][0]);
		dp[i][1] = max(dp[i-1][0] + mat[i][1], dp[i-1][2] + mat[i][1]);
		dp[i][2] = max(dp[i-1][0] + mat[i][2], dp[i-1][1] + mat[i][2]);
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
}

Measured memory_bytes: 5960
#include <stdio.h>

int main(void){
  int N,s;
  int min = 1000;
  int sum = 0;
  scanf("%d",&N);

  for(int i = 0;i < N;i++){
    scanf("%d",&s);
    if(min > s && s%10 != 0) min = s;
    sum += s;
  }
  
  if(sum%10 != 0) printf("%d\n",sum);
  else if(min%10 != 0) printf("%d",sum-min);
  else printf("0\n");

  return 0;
}

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

int main() {
    int n,m,x;
    cin>>n>>m>>x;
    vector<ll> cnt(m);
    vector<int> c(n);
    ll ans = -1;
    ll candi = 0;
    ll judge2 = 1;
    int a[n][m];
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            cin>>a[i][j];
        }
    }
    vector<int> judge(n);
    /*rep(i,n){
        judge[i] = 0;
    }*/
    for(int bit = 0; bit < (1<<n); ++bit){
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S.push_back(i);
            }
        }
        for (int i = 0; i < (int)S.size(); ++i) {
            judge[S[i]] = 1;
        }
        /*rep(i,n){
            cout<<judge[i]<<" ";
        }
        cout<<endl;*/
        rep(i,n){
            if(judge[i]==1){
                rep(j,m){
                    cnt[j] += a[i][j];
                }
                candi += c[i];
            }
        }
        rep(i,m){
            if(x > cnt[i]){
                judge2 = 0;
            }
        }
        if(judge2 == 1){
            if(ans!=-1)
            ans = min(ans,candi);
            else
            ans = candi;
        }
        judge2 = 1;
        candi = 0;
        rep(i,m){
            cnt[i] = 0;
        }
        rep(i,n){
            judge[i] = 0;
        }
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
#!/usr/bin/env python3
import sys
a = 'YYMM'
b = 'MMYY'
c = 'AMBIGUOUS'
d = 'NA'

def solve(S: str):
    if 1 <= int(S[:2]) <= 12:
        if 1 <= int(S[2:]) <= 12:
            print(c)
        else:
            print(b)
    else:
        if 1 <= int(S[2:]) <= 12:
            print(a)
        else:
            print(d)
    return


# Generated by 1.1.4 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()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a * b;
        int length = a * 2 + b * 2;
        System.out.println(area +" "+length);
    }
}



Measured memory_bytes: 26128
n = int(input())
a = list(map(int, input().split()))

x = 1
flag = False
INF = 10**18
if 0 in a:
    print(0)
else:
    for i in range(n):
        if flag == False:
            x *= a[i]
        if x > INF:
            flag = True
    
    if flag:
        print(-1)
    else:
        print(x)


Measured memory_bytes: 21624
import math
import itertools

X = int(input())

list = [0]

for i in range(1000):
    val = i**5
    list.append(val)

if X % 2 == 0 and X // 2 in list:
    print(int(math.pow(X//2, 1/5)), -int(math.pow(X//2, 1/5)))
elif X in list:
    print(int(math.pow(X, 1/5)), 0)
else:
    for i in itertools.combinations(list, 2):
        # print(i)
        if i[0] + i[1] == X:
            print(int(math.pow(i[0], 1/5)), -int(math.pow(i[1], 1/5)))
            break
        elif i[0] - i[1] == X:
            print(int(math.pow(i[0], 1/5)), int(math.pow(i[1], 1/5)))
            break
        elif i[0] + i[1] == X:
            print(int(math.pow(i[0], 1/5)), -int(math.pow(i[1], 1/5)))
            break
        elif i[1] - i[0] == X:
            print(int(math.pow(i[1], 1/5)), int(math.pow(i[0], 1/5)))
            break

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

int main(void){
	int N;
	cin >> N;
	int X[N];
	rep(i,N) cin >> X[i];
	sort(X,X+N);
	int p = 1e+6;
	for (int i = X[0]; i <= X[N-1]; i++) {
		int tmp = 0;
		rep(j,N) tmp += (X[j]-i)*(X[j]-i);
		p = min(tmp,p); 
	}
	cout << p << endl;

return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <tuple>

using namespace std;
typedef long long ll;

int main() {
    ll n, d, a; cin >> n >> d >> a;
    vector<tuple<ll, ll>> enemies(n);

    for (int i = 0; i < n; i++) {
        ll x, h; cin >> x >> h;
        enemies[i] = make_tuple(x, h);
    }

    sort(enemies.begin(), enemies.end());
    ll last_idx = 0;
    vector<ll> index;
    vector<ll> sum;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll x = get<0>(enemies[i]);
        ll h = get<1>(enemies[i]);
        // 累積和から今のダメージを計算
        auto it = lower_bound(index.begin(), index.end(), x);
        ll dmg = 0;
        if (it == index.end()) {
            dmg = 0;
            //cout << "prev dmg1: 0" << endl;
        } else if (it == index.begin()) {
            dmg = sum[last_idx - 1];
            //cout << "prev dmg2: " << dmg << endl;
        } else {
            int idx = it - index.begin();
            dmg = sum[last_idx -1] - sum[idx - 1];
            //cout << "prev dmg3: " << dmg << endl;
        }
        // 爆弾をふらす回数を計算して、詰める
        h = h - dmg;
        if (h <= 0) {
            continue;
        }
        ll attack_num = (h % a == 0 ? h / a : h / a + 1);
        //cout << "enemy: " << h << ", power: " << a << endl;
        //cout << "attack: pos = " << x + d << ", num = " << attack_num << endl;
        ans += attack_num;
        index.push_back(x + 2 * d);
        if (sum.size() == 0) {
            sum.push_back(attack_num * a);
        } else {
            ll len = sum.size();
            sum.push_back(attack_num * a + sum[len-1]);
        }
        last_idx++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    string str;
    int sum = 0, num;
    
    while (getline(cin, str)) {
        for (int i = 0; i < (int)str.size(); i++) {
            if (isdigit(str[i])) continue;
            else {
                str[i] = ' ';
            }
        }

        stringstream ss(str);
        while (ss >> num) {
            sum += num;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class FenwickTree {
  public:
    FenwickTree(int size):
        m_data(size, 0) {}

    int size() const {
        return m_data.size();
    }

    void update(int position, int64_t value) {
        for (; position < size(); position += (position & -position))
            m_data[position] = max(m_data[position], value);
    }

    int64_t query(int position) const {
        int64_t best = 0;
        for (; position; position -= (position & -position))
            best = max(best, m_data[position]);
        return best;
    }

  private:
    vector<int64_t> m_data;
};

int main() {
    ios::sync_with_stdio(false);

    int N; cin >> N;

    vector<int> H(N), A(N);
    for (int i = 0; i < N; ++i)
        cin >> H[i];
    for (int i = 0; i < N; ++i)
        cin >> A[i];

    FenwickTree F(N + 1);
    int64_t answer = 0;
    for (int i = 0; i < N; ++i) {
        int64_t now = F.query(H[i]) + A[i];
        F.update(H[i], now);
        answer = max(answer, now);
    }

    cout << answer << "\n";
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);

  int A = 0;
  int ans = 1;

  for (int i = 1; i < N; i++) {
    A = max(A, vec.at(i - 1));
    if (vec.at(i) >= A) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll x,y,a,b,c,p[100005],q[100005],r[100005],ans,l1,l2,now,cnt;
int main()
{
    //IOS;
    cin>>x>>y>>a>>b>>c;
    for(int i=1;i<=a;i++)
    {
        cin>>p[i];
    }
    for(int i=1;i<=b;i++)
    {
        cin>>q[i];
    }
    for(int i=1;i<=c;i++)
    {
        cin>>r[i];
    }
    sort(p+1,p+1+a);
    sort(q+1,q+1+b);
    sort(r+1,r+1+c);
    for(int i=1;i<=x;i++)
    {
        ans+=p[a-i+1];
    }
    for(int i=1;i<=y;i++)
    {
        ans+=q[b-i+1];
    }
    l1=a-x+1;
    l2=b-y+1;
    now=c;
    while(1)
    {
        if(p[l1]>=r[now]&&q[l2]>=r[now])
        {
            break;
        }
        if(now==0)
        {
            break;
        }
        if(l1<=a&&l2<=b)
        {
            if((r[now]-p[l1])>(r[now]-q[l2]))
            {
                ans-=p[l1];
                ans+=r[now];
                l1++;
            }
            else
            {
                ans-=q[l2];
                ans+=r[now];
                l2++;
            }
        }
        else if(l1<=a&&l2>b)
        {
            if(p[l1]<=r[now])
            {
                ans-=p[l1];
                ans+=r[now];
                l1++;
            }
        }
        else if(l1>a&&l2<=b)
        {
            if(q[l2]<=r[now])
            {
                ans-=q[l2];
                ans+=r[now];
                l2++;
            }
        }
        else
        {
            break;
        }
        now--;
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 2560
import scala.io.StdIn._

object Main extends App {
  val n = readInt()

  require(2 <= n && n <= 10)

  var i = 0
  var j = 0.0
  while (i < n) {
    val Seq(x, u) = readLine().split(" ").toSeq
    u match {
      case "JPY" => j = j + x.toInt.toDouble
      case "BTC" => j = j + x.toDouble * 380000.0
    }
    i = i + 1
  }
  println(j)
}


Measured memory_bytes: 54736
// 確率の逆数が試行回数の期待値になる
#include <bits/stdc++.h>
using namespace std;
double n;
vector<int> c(4, 0);
double dp[330][330][330];
bool flag[330][330][330];

double f(int c1, int c2, int c3) {
    if(flag[c1][c2][c3]) return dp[c1][c2][c3];
    flag[c1][c2][c3] = true;
    double fans = 1.0 / (1.0 - (double)(n-c1-c2-c3)/n);
    /*cout << c1 << c2 << c3 << endl;
    printf("%.10f\n", fans);*/
    if(c1 > 0) fans += f(c1-1, c2, c3) * c1 / n / (1.0 - (double)(n-c1-c2-c3)/n);
    if(c2 > 0) fans += f(c1+1, c2-1, c3) * c2 / n / (1.0 - (double)(n-c1-c2-c3)/n);
    if(c3 > 0) fans += f(c1, c2+1, c3-1) * c3 / n / (1.0 - (double)(n-c1-c2-c3)/n);
    return dp[c1][c2][c3] = fans;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        c.at(a)++;
    }

    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= n; ++j) {
            for(int k = 0; k <= n; ++k) {
                dp[i][j][k] = 0.0;
                flag[i][j][k] = false;
            }
        }
    }

    flag[0][0][0] = true;

    double ans = f(c.at(1), c.at(2), c.at(3));
    printf("%.14f\n", ans);

    /*for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= n; ++j) {
            for(int k = 0; k <= n; ++k) {
                printf("%.10f ", dp[i][j][k]);
            }
            cout << endl;
        }
    }*/
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n-1){
		cin >>a[i+1];
	}
	VI ans(n, 1);
	rep2(i, 1, n){
		ans[a[i]-1] += ans[i];
	}
	//for(auto x :ans) cerr<<x<<" "; dbg();
	for(auto x :ans) cout<<x-1<<"\n";
	return 0;
}


Measured memory_bytes: 4776
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

   


 
int i, j, N;
cin >> N;
int count;
int ans = 0;
for(i=1;i<=N;i++){
    count = 0;
    if(i%2==1){
  	    for(j = 1; j<=i; j++){
            if(i%j == 0){
       		    count++;
            }
        }
        //if(i==105)cout<<count;

    if(count==8)ans++;
    }
}

  cout<<ans<<endl;
 


    return 0;
}

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

using namespace std;

int a[200005];
map<int,int> l;
int main() {
 int n;
 cin >> n;
 long long ans = 0;
 for (int i = 1; i <= n; i++) {
    cin >> a[i];
    l[i + a[i]]++;
    ans += l[i - a[i]];
 }
 cout << ans;
 return 0;
}


Measured memory_bytes: 21328
//-----------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int)n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
//-----------------------------------------------------------------------------

int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    cinsc;
}

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

int main(){
  //  in_o();
    double l;
    cin>>l;
    double ans=l*l*l/27;
    cout << fixed << setprecision(9) << ans;
    return 0;
}


Measured memory_bytes: 3780
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll sum = 0;
	rep2(i, 1, n + 1) {
		if (i % 3 != 0 && i % 5 != 0)sum += i;
	}
	cout << sum;
}

Measured memory_bytes: 3600
menus = []
for _ in range(5):
    menus.append(int(input()))

*d, = map(lambda x: 0 if x%10 == 0 else 10-x%10, menus)

ans = 0
for _m, _d in zip(menus, d):
    ans += _m+_d

print(ans-max(d))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	string n;
	cin>>n;
	for(int i=0;i<3;i++){
		if(n[i]=='9') cout<<1;
		if(n[i]=='1') cout<<9;
	}
	re 0;
}

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

long long a, b, k, c;
int main() {
	cin >> a >> b >> k;
	for(int i=0; i<k; i++) {
		if(i%2==0) {
			if(a&1) a--;
			c = a/2;
			a -= c;
			b += c;
		} else {
			if(b&1) b--;
			c = b/2;
			b -= c;
			a += c;
		}
	}
	cout << a << ' ' << b;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<functional>
using namespace std;

int c[100];
signed main(){
	int a, b; scanf("%d%d", &a, &b);//日数　種類数
	for (int d = 0; d < b; d++)scanf("%d", &c[d]);
	sort(c, c + b,greater<int>());
	int sum = 0;
	for (int i = 1; i < b; i++) {
		sum += c[i];
	}
	printf("%d\n", max(0, c[0] - sum - 1));
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
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;}
template <class T> inline T gcd(T a, T b) {if(a==0) return b; return gcd(b%a,a);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd(a,b);}
template <class T> inline T sum(vector<T> &vec) {T res=0; for (int i = 0; i < vec.size(); i++) res += vec[i]; return res;}
template <class T> inline T mpow(T a, T b) {if(b==0)return 1; T c = mpow(a,b/2);if(b%2==1)return c*c*a; return c*c;}
const int INF = 1 << 30;
const long long INFLL = 1LL << 60;
typedef pair<int, int> P;

#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define FOR(i,n) for (int (i)=0;(i)<(n);(i)++)
#define REPB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define FORB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define SORT(A) sort((A).begin(),(A).end())


int main() {
    int N,M; cin >> N >> M;
    if (N == M) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }


}


Measured memory_bytes: 256
import java.util.*;

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

	String str = sc.next();

	String rts = "";
	for(int i=str.length()-1; i>=0; i--){
	    String s = str.substring(i,i+1);
	    rts += s;
	}

	System.out.println(rts);
    }
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)


int main()
{
	ll n,k;
	cin>>n>>k;
	ll m = 0;
	ll maxM = (n-1)*(n-2)/2;
	if( maxM < k )
	{
		cout << -1<< endl;
		return 0;
	}
	
	vector<pair<ll,ll>> edge;
	REP(i,n-1) edge.push_back( {0, i + 1} );

	ll left = maxM - k;
	ll a = 1, b = 2;
	REP( i, left )
	{
		edge.push_back( {a, b} );
		if( b == n - 1 )
		{
			++a;
			b = a + 1;
		}
		else
		{
			++b;
		}
	}

	cout << edge.size() << endl;
	REP(i,edge.size())
		cout << edge[i].first+1 << " " << edge[i].second+1 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#define MAX_N 100
using namespace std;

int main() {
  int F[MAX_N];
  int P[MAX_N][11];
  int N;
  int bit, tmp, dw32;
  long long ans, sum;
  
  cin>>N;
  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++){
      cin>>tmp;
      F[i]|=(tmp<<j);
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<11;j++){
      cin>>P[i][j];
    }
  }
  ans=-10000000000;
  for(int i=1;i<(1<<10);i++){
    sum=0;
    for(int j=0;j<N;j++){
      dw32=(i&F[j]);
      dw32 = ((dw32 & 0xAAAAAAAA) >>  1) + (dw32 & 0x55555555);
      dw32 = ((dw32 & 0xCCCCCCCC) >>  2) + (dw32 & 0x33333333);
      dw32 = ((dw32 & 0xF0F0F0F0) >>  4) + (dw32 & 0x0F0F0F0F);
      dw32 = ((dw32 & 0xFF00FF00) >>  8) + (dw32 & 0x00FF00FF);
      dw32 = ((dw32 & 0xFFFF0000) >> 16) + (dw32 & 0x0000FFFF);
      sum+=P[j][dw32];
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
ll lcm(ll x,ll y)
{
	return (x*y)/__gcd(x,y);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll j,l,m,h,w,f,n,k,b,ans;
    	cin>>n>>l;
    	ans=0;
    	ll a[n+1];
    	a[0]=0; h=mod;
    	repi(i,1,n)
    	a[i]=l+i-1;
    	repi(i,1,n)
    	a[i]+=a[i-1];
    	
    	k=a[n];
    	repi(i,1,n)
    	{
    		b=a[i-1]+a[n]-a[i];
    		if(abs(b-k)<h)
    		{
    			h=abs(b-k);
    			m=i;
			}
		}
		cout<<a[m-1]+a[n]-a[m];
    }
	return 0;
}

Measured memory_bytes: 256
def solve
  s = gets.chomp
  tmp = s[0]
  cnt = 0
  (1..(s.length - 1)).each do |i|
    cnt += 1 if tmp != s[i]
    tmp = s[i]
  end

  if cnt >= 1
    print 'Yes'
  else
    print 'No'
  end
end
solve


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

struct Dice{
  vector<int> asp;
  string dir;
};

void rot(vector<int> &asp, char ch){
  switch(ch){
    case 'N': asp={asp[1],asp[5],asp[2],asp[3],asp[0],asp[4]};
              break;
    case 'E': asp={asp[3],asp[1],asp[0],asp[5],asp[4],asp[2]};
              break;
    case 'S': asp={asp[4],asp[0],asp[2],asp[3],asp[5],asp[1]};
              break;
    case 'W': asp={asp[2],asp[1],asp[5],asp[0],asp[4],asp[3]};
              break;
  }
}



int main(){
  Dice d1;
  for(int i=0; i<6; i++){
    int x;
    cin >> x;
    d1.asp.push_back(x);
  }
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    int top, frt;
    cin >> top >> frt;
    while(d1.asp[0] != top){
      if(top==d1.asp[2]) rot(d1.asp, 'W');
      else if(top==d1.asp[3]) rot(d1.asp,'E');
      else rot(d1.asp, 'N');
    }
    if(frt==d1.asp[1]) cout << d1.asp[2];
    else if(frt==d1.asp[2]) cout << d1.asp[4];
    else if(frt==d1.asp[3]) cout << d1.asp[1];
    else cout << d1.asp[3];
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3144
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)%2)
typedef long long ll;
typedef long double ld;
const ll oo=2*1000*1000*1000;
const int _cnt=1000*1000;
const int _p=1000*1000*1000+7;
int o(int x) { return x%_p; }
int gcd(int a,int b) { return b?gcd(b,a%b):a; }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
using namespace std;

void file_put(){
	freopen("filename.in","r",stdin);
	freopen("filename.out","w",stdout);
}

int a,b,c; 

int main(){
	//file_put();
	
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",a+b+c-max(a,max(b,c)));
  
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Scan(&arr[i])
	}
	sort.Slice(arr, func(i, j int) bool {
		if arr[i] > arr[j] {
			return true
		}
		return false
	})
	alice, bob := 0, 0
	for i, v := range arr {
		if i%2 == 0 {
			alice += v
		} else {
			bob += v
		}
	}
	fmt.Println(alice - bob)
}


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


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

void solve()
{
    int n;
    cin>>n;
    long long sum = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
    {
        for(int k=1;k<=n;k++)
    {
       sum+=gcd(i,gcd(j,k));
    }
       
    }
       
    }
    cout<<sum<<endl;
}

int main()
{
    int t;
    t=1;
    while(t--)
        solve();
}


Measured memory_bytes: 3624
// ~maqsat~

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
	fre("");
	ACCELERATE;

	int n;
    string s;
    cin >> n >> s;
    
    string ans;
    ans.pb(s[0]);
    for(int i = 1; i < n; i++) {
        if(s[i] != ans.back()) ans.pb(s[i]);
    }
    cout << sz(ans);
	return 0;
}


Measured memory_bytes: 592
import java.util.Arrays;
import java.util.Scanner;


public class Main {
		
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final String one = sc.next();
			final String two = sc.next();
			
			if("0".equals(one) && "0".equals(two)){
				break;
			}
			
			char[] one_c = one.toCharArray();
			char[] two_c = two.toCharArray();
			
			int hit_count = 0, blow_count = 0;
			
			for(int i = 0; i < one_c.length; i++){
				for(int j = 0; j < two_c.length; j++){
					if(one_c[i] == two_c[j]){
						if(i == j){
							hit_count++;
						}else{
							blow_count++;
						}
						
						break;
					}
				}
			}
			
			System.out.println(hit_count + " " + blow_count);
			
			
		}
		
		
	}
}

Measured memory_bytes: 12000
def main():
    S = input()
    K = int(input())
    N = len(S)
    for i in range(N):
        if S[i] != '1':
            can = S[i]
            cannum = i + 1
            break
    if set(S) == {'1'} or K < cannum:
        print(1)
    else:
        print(can)

if __name__ == '__main__':
    main()

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

int main(){
	int sum1[100000],n,a;
	memset(sum1,0,sizeof(sum1));
	for(int i=2;i<100;i++){
		for(int j=1;j<1000;j++){
			a=((i-1)+2*j)*i/2;
			if(a<10000){
				sum1[a] += 1;
			}
		}
	}
	while(true){
		cin>>n;
		if(n==0){
			goto Exit;
		}
		else{
			cout<<sum1[n]<<endl;
		}
	}
	Exit:
	return 0;
}

Measured memory_bytes: 1556
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;


int main() {

	string S;

	cin >> S;

	if(S=="Sunny")
		cout << "Cloudy" << endl;
	if (S == "Cloudy")
		cout << "Rainy" << endl;
	if (S == "Rainy")
		cout << "Sunny" << endl;

	

	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    lli n,i,k;
    cin>>n>>k;
    lli a[n],aa[n];
    for(i=0;i<n;i++)
        cin>>a[i];
        aa[0]=0;
        for(i=1;i<=k && i<=n;i++)
        {
            aa[i]= abs(a[i]-a[0]);
        }
        for(i=k+1;i<n;i++)
        {   aa[i]= abs(a[i]-a[i-1])+aa[i-1];
            for(int j=i-1;j>= i-k;j--)
                aa[i]=min(aa[i],abs(a[i]-a[j])+aa[j]);
        }
        cout<<aa[n-1];

	return 0;
}
//4
//10 30 40 20


Measured memory_bytes: 1792
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
  ($line:expr, $name:ident, $t:tt) => {
    let $name = value!($line, $t);
  };
}

macro_rules! values_def {
  ($lines:expr, $n:expr, $name:ident, $t:tt) => {
    let $name = {
      let mut vec = Vec::new();
      for i in 0..$n {
        let mut next = $lines.next().unwrap().split_whitespace();
        vec.push(value!(next, $t));
      }
      vec
    };
  };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
  let mut input = String::new();
  io::stdin().read_to_string(&mut input).unwrap();
  let output = solve(input.trim().to_string());
  println!("{}", output);
}

fn solve(input: String) -> String {
  input!(input=>(n:usize)(list:[@]));
  let mut sum = Vec::with_capacity(n);
  sum.resize(n, 0);
  for x in list {
    sum[x] += 1;
  }
  sum
    .into_iter()
    .map(|x| x.to_string())
    .collect::<Vec<_>>()
    .join("\n")
    .to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}
tests! {
  test1: "5\n1 1 2 2\n" => "2\n2\n0\n0\n0\n",
  test2: "10\n1 1 1 1 1 1 1 1 1\n" => "9\n0\n0\n0\n0\n0\n0\n0\n0\n0\n",
  test3: "7\n1 2 3 4 5 6\n" => "1\n1\n1\n1\n1\n1\n0\n",
}


Measured memory_bytes: 16252
#include <bits/stdc++.h>
using namespace std;
#define M 200010
#define MOD 1000000007
#define LL long long
#define ULL unsigned long long
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while('0'<=ch&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int F[M],fa[M],c[M][2],V[M];
inline int Find(int x){
	return fa[x]==x?x:fa[x]=Find(fa[x]);
}
struct Node{
	int id;
	inline bool operator < (const Node& rhs) const {
		return 1ll*c[id][0]*c[rhs.id][1]>1l*c[rhs.id][0]*c[id][1]
				||(1ll*c[id][0]*c[rhs.id][1]==1l*c[rhs.id][0]*c[id][1]&&id>rhs.id);
	}
	inline bool operator == (const Node& rhs) const {
		return id==rhs.id;
	}
};
set<Node> Q;
inline void put(){
	set<Node>::iterator it;
	for(it=Q.begin();it!=Q.end();++it){
		printf("%d ",it->id);
	}
	puts("");
}
int main() {
	int n=read();
	rep(i,2,n)F[i]=read();
	rep(i,1,n){
		V[i]=read();
		c[i][V[i]]++;
	}
	rep(i,2,n){
		Q.insert((Node){i});
	}
	rep(i,1,n)fa[i]=i;
	LL ans=0;
	while(!Q.empty()){
		//cerr<<"fdfdf___________________"<<endl;
		//cerr<<" "<<Q.size()<<endl;
		int x=Find(Q.begin()->id);Q.erase(Q.begin());
		//cerr<<" "<<Q.size()<<endl;
		
		//cerr<<x<<endl;
		
		if(x==1)break;
		int px=Find(F[x]);
		//put();
		Q.erase((Node){px});
		//cerr<<" "<<px<<endl;
		//cerr<<px<<" "<<x<<endl;
		ans+=1ll*c[px][1]*c[x][0];
		fa[x]=px;c[px][0]+=c[x][0];c[px][1]+=c[x][1];
		if(px!=1)Q.insert((Node){px});
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 14208
#include<stdio.h>

int main(void)

{
	char S[3];
	char T[3];

	int i=0;

	scanf("%s",S);
	scanf("%s",T);

	if(S[0]==T[0])
		i++;
	if(S[1]==T[1])
		i++;
	if(S[2]==T[2])
		i++;

	printf("%d",i);
		

return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[])
{
  vector<int> nums{
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
  };
  int k;
  cin >> k;
  cout << nums[k - 1] << "\n";
  return 0;
}

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

int main()
{
    int n,m; cin >> n >> m;
    vector<int> prob(n+1,0); // 問題nをACしたかメモする配列
    string tmps;
    int tmp;
    vector<int> x(n+1); // 初めてACするまでにWAした回数。
    rep(i,m) {
        cin >> tmp >> tmps;
        if(tmps == "AC") prob[tmp] = 1; // 問題tmpがACだったらACしたかメモする配列probにメモ
        else {
            if (prob[tmp] == 0) { // ACしていない問題でWAだった場合ペナルティを配列xに加算
                x[tmp]++;
            }
        }
    }
    int ansc = 0, ansp = 0;
    rep(i,n+1) {
        if(prob[i] == 0) x[i] = 0; // prob[i] == 0つまり問題iをACしていなかったらその問題のペナルティをリセット
        
        ansc += prob[i];
        ansp += x[i];
    }

    cout << ansc << " " << ansp << endl;
}

Measured memory_bytes: 4060
#include <iostream>

using namespace std;

int main()
{

 int a , b;
    cin>> a>> b;
    if(a==1 && b!=1)
        {
        cout<<"Alice";
    }
    else if (b==1 && a!=1)
    {
        cout<<"Bob";
    }
    else if (a>=2 && a<=13 && b>=2&&b<=13 && a>b)
        {
        cout<<"Alice";
    }
    else if (b>=2 && b<=13 && a>=2&&b<=13 && b>a)
        {
        cout<<"Bob";
    }
    else{
    cout<<"Draw";
    }
    return 0;
}


Measured memory_bytes: 256
input_line = raw_input()
temp_list = input_line.split()
w = int(temp_list[0])
h = int(temp_list[1])
x = int(temp_list[2])
y = int(temp_list[3])
r = int(temp_list[4])
 
if x >= r and y >=  r and (w-x) >= r and (h-y) >= r:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 4644
main :: IO ()
main = do
  _ <- getLine
  as <- map read . words <$> getLine
  print $ counter as

counter
  :: [Int] -> Int
counter ns = helper ns 0
  where
    helper
      :: [Int] -> Int -> Int
    helper ms k
      | all even ms = helper (map (`div` 2) ms) $! (k+1)
      | otherwise   = k


Measured memory_bytes: 1020
class Node:
    def __init__(self, num, parent, children):
        self.id = num
        self.parent = -1
        self.depth = 0
        self.type = None
        self.children = children
        
    def show_info(self):
        print('node {0}: parent = {1}, depth = {2}, {3}, {4}'.format(self.id,
                                                                     self.parent,
                                                                     self.depth,
                                                                     self.type,
                                                                     self.children))


def set_node(i_s):
    i_l = list(map(int, i_s.split()))
    num = i_l[0]
    children = i_l[2:]
    node = Node(num, -1, children)
    T[num] = node
    for n in children:
        T[-1] -= n

def set_pdt(n_i, parent, depth):
    node = T[n_i]
    node.parent = parent
    node.depth = depth
    if node.children:
        node.type = 'internal node'
        for n in node.children:
            set_pdt(n, n_i, depth + 1)
    else:
        node.type = 'leaf'


import sys

n = int(sys.stdin.readline())

T = [None] * n

T.append(int(n * (n - 1) / 2))

for x in sys.stdin.readlines():
    set_node(x)

set_pdt(T[-1], -1, 0)

T[T[-1]].type ='root'

for n in T[:-1]:
    n.show_info()

Measured memory_bytes: 55668
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1e18;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }

	long long factorial(long long n) {
		if (n <= 1)
			return 1;
		else {
			return n * factorial(n - 1);
		}
	}

	long long COM(long long n, long long r) {
		long long  top = n;
		for (int i = 0; i < r - 1; i++) {
			top = top * (--n);
		}
		long long  bottom = factorial(r);
		return top / bottom;
	}

int main() {  
    int n; cin >> n;
    map<int, ll> mp; vector<int> A(n);
    rep(i, n){
        cin >> A[i];
        mp[A[i]]++;
    }
    ll sum = 0;
    for(auto m: mp){
        ll num = m.second;
        sum += COM(num, 2);
    }
    rep(i, n){
        int num = mp[A[i]];
        ll res = sum - COM(num, 2) + COM(num-1, 2);
        cout << res << ln;
    }  
}

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

int main(){
  string S;
  cin >> S;
  
  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256