akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    ll n, x;
    cin >> n >> x;
    ll ans = n;
    ll h = max(n-x, x);
    ll l = min(n-x, x);
    while(true)
    {
        ll num = h / l;
        if(h % l == 0)
        {
            ans += l * 2 * num - l;
            break;
        }
        ans += l * 2 * num;
        ll tmp = h;
        h = l;
        l = tmp % l;
    }
    cout << ans << endl;
}


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

using ll = long long;

const int MAXM = 25;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M; ll C; cin >> N >> M >> C;
	vector<ll> B(M);
	for (ll& b : B) cin >> b;

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ll tot = 0;
		for (int j = 0; j < M; j++) {
			ll A; cin >> A;
			tot += A * B[j];
		}
		ans += (tot > -C);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;




int main() {
int N;
ll count=0;
cin>>N;
map<string,int> map;
rep(i,N){
  string s;
  cin>>s;
  sort(all(s));
  count+=map[s];
  map[s]++;
  
}
cout<<count<<endl;
return 0;
}

Measured memory_bytes: 11380
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
	ll a,b,c,k;cin>>a>>b>>c>>k;
	if (k % 2 == 1){
		if (abs(b - a) <= pow(10,18)){
			cout << b - a << endl;
		}
		else{
			cout << -1 << endl;
		}
	}
	else{
		if (abs(a - b) <= pow(10,18)){
			cout << a - b << endl;
		}
		else{
			cout << -1 << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int m[2], d[2];
	REP(i, 2) cin >> m[i] >> d[i];
	cout << (m[0] != m[1]) << endl;
	return 0;
}


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

int main () {
  int A , B;
  cin >> A >> B;
  
  if((B - 1) % (A - 1) == 0){
    cout << (B - 1) / (A - 1) << endl;
  }

  else{
    cout << (B - 1) / (A - 1) + 1 << endl;
  }
}

Measured memory_bytes: 256
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

#include<bits/stdc++.h>
using namespace std;

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    sss            " "
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;

int main() {ikarus_101

    ll n,m,i,j,k,x;

    cin >> n >> x;
    vll v(n);vin(v);
    ll tot = 0;
    rep(i,n)
    {
        tot += v[i];
        if(tot > x) break;
    }
    cout << i+1 << nn;












    return 0;
}


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

int main()
{
    long long int n; cin>>n;
    vector<int> arr;
    for(int i=0;i<n;i++)
    {
        int x; cin>>x;
        arr.push_back(x);
    }
    int dp[n+1];
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
    // cout<<dp[0]<<" "<<dp[1]<<" ";
    for(int i=2;i<n;i++)
    {
        int cost_1 = dp[i-1] + abs(arr[i]-arr[i-1]);
        int cost_2 = dp[i-2]+ abs(arr[i]-arr[i-2]);
        // cout<<min(cost_1,cost_2)<<" ";
        dp[i] = min(cost_1,cost_2);
    }

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

}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#define N 45
using namespace std;
int n,l[N],L[N],ans;
int d[5]={5,7,5,7,7};
string s;

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=1;i<=n;i++){
      cin>>s,l[i]=s.size();
      L[i]=L[i-1]+l[i];
    }
    ans=0;
    for(int i=1;i<=n;i++){
      int idx=0,s=i;
      for(int j=i;j<=n;j++){
	if(L[j]-L[s-1]==d[idx])idx++,s=j+1;
	if(!ans&&idx==5)ans=i;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

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

LL N, X[101];

int main() {
    cin >> N;
    LL Y = INF, Z = 0;
    REP (i, N) {
        cin >> X[i];
        if (X[i] < Y) {
            Y = X[i];
        }
        if (X[i] > Z) {
            Z = X[i];
        }
    }
    LL min = 1e18;
    FOR (i, Y, Z + 1) {
        LL P = i;
        LL S = 0;
        REP (j, N) {
            S += (X[j] - P) * (X[j] - P);
        }
        if (S < min) {
            min = S;
        }
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;

long gcd(long a, long b) {
    if(a < b) {
        swap(a, b);
    }
    while(b > 0) {
        long r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main()
{
    long x, y;
    cin >> x >> y;
    cout << gcd(x, y) << endl;
}




Measured memory_bytes: 3096
#include <stdio.h>

#define min(a, b)   (((a) < (b))?(a):(b))

int n1[1000000];
int n2[1000000];

int main(void)
{
    int a;
    int i, j, k;
    int n;
    
    for (i = 0; i < 1000000; i++){
        j = 1;
        while (1){
            n = j * (j + 1) * (j + 2) / 6;
            if ((i + n) >= 1000000){
                break;
            }
            if (n1[i + n] == 0){
                n1[i + n] =  n1[i] + 1;
            }
            else {
                n1[i + n] = min(n1[i + n], n1[i] + 1);
            }
            if (n % 2 == 1){
                if (n2[i + n] == 0){
                    n2[i + n] =  n2[i] + 1;
                }
                else {
                    n2[i + n] = min(n2[i + n], n2[i] + 1);
                }
            }
            j++;
        }
    }

    
    while (1){
        scanf("%d", &a);
        if (a == 0){
            break;
        }
        printf("%d %d\n", n1[a], n2[a]);
    }
    
    return (0);
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var w = int.Parse(Console.ReadLine());

            var result = new StringBuilder();
            for(var i=0; i<(int)Math.Ceiling(S.Length/(double)w); i++)
            {
                result.Append(S[i * w]);
            }
            Console.WriteLine(result.ToString());
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<list>
#include<algorithm>
using namespace std;

int main() {
  int q, x;
  char com[20];
  list<int> v;
  scanf("%d", &q);
  for ( int i = 0; i < q; i++ ) {
    scanf("%s", com);
    if ( com[0] == 'i' ) {
      scanf("%d", &x);
      v.push_front(x);
    } else if ( com[6] == 'L' ) {
      v.pop_back();
    } else if ( com[6] == 'F' ) {
      v.pop_front();
    } else if ( com[0] == 'd' ) {
      scanf("%d", &x);
      for ( list<int>::iterator it = v.begin(); it != v.end(); it++ ) {
        if ( *it == x ) {
          v.erase(it);
          break;
        }
      }
    }
  }
  int i = 0;
  for ( list<int>::iterator it = v.begin(); it != v.end(); it++ ) {
    if ( i++ ) printf( " " );
    printf("%d", *it);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 33928
a=list(map(int,input().split()))
a=sorted(a)

c=a[0]%2+a[1]%2+a[2]%2
ans=0
if(c==0 or c==3):
    ans+=a[2]-a[0]+a[2]-a[1]
    ans//=2
else:
    if(c==1):
        for i in range(3):
            if(a[i]%2==0):
                a[i]+=1
    elif(c==2):
        for i in range(3):
            if(a[i]%2!=0):
                a[i]+=1
    ans+=1
    ans+=(a[2]-a[0]+a[2]-a[1])//2

print(ans)

Measured memory_bytes: 3064
function main(lines) {
    const input = lines-0
    var output = []
    for(var i=1; i*i<= input; i++){
        var a = input/i
        var b = input/a
        output.push( Math.max(a.toString().length, b.toString().length) )
    }
    console.log(output.sort(function(a,b){return a-b})[0] )
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 23220
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 200005;
const int INF = (LL)1e9 + 5;

string s;
int dp[MAXN][30];
char add[MAXN][30] = {0};

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> s;
	for (int i = 0; i < 26; i++) {
		dp[s.size()][i] = 1;
	}
	
	for (int i = s.size() - 1; i >= 0; i--) {
		int pos = min_element(dp[i + 1], dp[i + 1] + 26) - dp[i + 1];
		int len = dp[i + 1][pos];
//		cout << "LEN " << i + 1 << " = " << len << "\n";
		for (int j = 0; j < 26; j++) {
			if (s[i] == j + 'a') {
				dp[i][j] = len + 1;
				add[i][j] = pos + 'a';
//				cout << i << " " << (char)('a' + j) << " comes from " << len << " " << (char)('a' + pos) << "\n";
			}
			else {
				dp[i][j] = dp[i + 1][j];
				add[i][j] = 0;
			}
		}
	}
	
	string ans;
	int cur = min_element(dp[0], dp[0] + 26) - dp[0];
	ans.push_back(cur + 'a');
	for (int i = 0; i < s.size(); i++) {
		if (add[i][cur] != 0) {
//			cout << (char)(cur + 'a') << " match at " << i << " " << s[i] << "\n";
			assert(s[i] == cur + 'a');
			ans.push_back(add[i][cur]);
			cur = add[i][cur] - 'a';
		}
	}
	
	cout << ans << "\n";
	
	return 0;
	
	/**** Note MAXN ****/
}


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

using ll = long long;

int main(){

	vector<ll> x(2);
	vector<ll> y(2);
	for(int i=0;i<2;i++) cin >> x[i];
	for(int i=0;i<2;i++) cin >> y[i];

	ll ans=-1000000000000000000;
	ll now;
			
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			now = x[i]*y[j];
			//cout << now << endl;
			ans=max(ans,now);
		}
	}
	
	cout << ans << endl;

}



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

int a,b,c;

int f(int x, int y) {
    if (x==0 && y==0) return 0;
    else if (x==0) return min(y*b, 2*y*c);
    else if (y==0) return min(x*a, 2*x*c);
    else {
        if (2*c < a+b) {
            if (x >= y) return 2*y*c + f(x-y, 0);
            else return 2*x*c + f(0, y-x);
        }
        else return a*x + b*y;
    }
}

int main() {
    //ios_base::sync_with_stdio(false); cin.tie(false);
    //freopen("input.txt", "r", stdin);
    int x, y;
    cin >> a >> b >> c >> x >> y;
    cout << f(x,y);
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)

Measured memory_bytes: 8976
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

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

    int time;
    string mozi;

    if(a >= b){
        time = a;
        mozi = to_string(b);
    } else {
        time = b;
        mozi = to_string(a);
    }

    string ans;
    for(int i=0; i < time; i++){
        ans += mozi;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
  
int main(){
  
  int n;
  cin>>n;
 if(n==25){
 cout <<"Christmas" << endl;
 }
 if(n==24){
     cout << "Christmas Eve" << endl;
 }
 if(n==23){
     cout << "Christmas Eve Eve" << endl;
 }
 if(n==22){
     cout << "Christmas Eve Eve Eve" << endl;
 }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n, k, sum=0;;
  cin >> n >> k;
  vector<int> p;
  for(int i=0; i<n; i++){
    int item;
    cin >> item;
    p.push_back(item);
  }
  sort(p.begin(), p.end());
  for(int i=0; i<k; i++){
    sum += p[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3576
# input
s = int(input())

# check
lim = 1000001
# 初項が 4 or 2 or 1 なら
# 4, 2, 1, 4, 2, 1, …
# となるので、答えは4になる
if s == 1 or s == 2:
  print(4)
else:

    c4 = 0
    c = 1
    for m in range(2, lim):
        # 4の出現回数をカウントする
        if s == 4:
            c4 += 1

        # 2回4が出てきたら終了
        if c4 == 2:
            print(c)
            exit()

        # 指示された操作
        if s % 2 == 0:
            s //= 2
        else:
            s = 3 * s + 1

        # 項番をインクリメント
        c += 1

Measured memory_bytes: 3060
n = int(input())
A = [int(input()) for i in range(n)]

if A[0] != 0:
    print(-1)
    exit()

for i in range(1, n):
    if A[i] > A[i-1]+1:
        print(-1)
        exit()

ans = 0
for i in reversed(range(1, n)):
    if A[i-1] == A[i]-1:
        ans += 1
    else:
        ans += A[i]

print(ans)


Measured memory_bytes: 11176
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
const int M=160*80+1;
int dp[81][81][M];
int a[81][81];
int b[81][81];

int main()
{
	IOS;
	cin>>n>>m;
	forn(i,n)forn(j,m) cin>>a[i][j];
	forn(i,n)forn(j,m) cin>>b[i][j];
	x = abs(a[0][0]-b[0][0]);
	dp[0][0][x]=1;
	forn(i,n){
		forn(j,m){
			forn(k,M){
				if(dp[i][j][k]){
					dp[i+1][j][k+abs(a[i+1][j]-b[i+1][j])]=1;
					dp[i+1][j][abs(k-abs((a[i+1][j]-b[i+1][j])))]=1;

					dp[i][j+1][k+abs(a[i][j+1]-b[i][j+1])]=1;
					dp[i][j+1][abs(k-abs((a[i][j+1]-b[i][j+1])))]=1;				
				}
			}
		}
	}
	int ans=0;
	forn(i,M){
		if(dp[n-1][m-1][i]){
			ans=i;
			break;
		}
	}
	cout<<ans<<ln;
}

Measured memory_bytes: 326784
values = input().split()

num_animals = int(values[0])
num_legs = int(values[1])

max_possible_legs = num_animals*4
min_possible_legs = num_animals*2

if num_legs%2 != 0:
    print ("No")

elif (num_legs <= max_possible_legs) and (num_legs >= min_possible_legs):
    print("Yes")

else:
    print("No")

Measured memory_bytes: 9128
c = []
c << gets.split.map(&:to_i)
c << gets.split.map(&:to_i)
c << gets.split.map(&:to_i)

if c[0][0] - c[1][0] == c[0][1] - c[1][1] && c[0][0] - c[1][0] == c[0][2] - c[1][2] && c[1][0] - c[2][0] == c[1][1] - c[2][1] && c[1][0] - c[2][0] == c[1][2] - c[2][2]
  puts "Yes"
else
  puts "No"
end


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

int main()
{
  ll N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  vector<ll> A(N), B(N), C(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i) >> B.at(i) >> C.at(i);
  }

  vector<vector<vector<ll>>> dp(44, vector<vector<ll>>(444, vector<ll>(444, INF)));
  dp.at(0).at(0).at(0) = 0;
  for (ll i = 0; i < N; i++)
  {
    for (ll a = 0; a < 404; a++)
    {
      for (ll b = 0; b < 404; b++)
      {
        chmin(dp.at(i + 1).at(a).at(b), dp.at(i).at(a).at(b));
        chmin(dp.at(i + 1).at(a + A.at(i)).at(b + B.at(i)), dp.at(i).at(a).at(b) + C.at(i));
      }
    }
  }

  ll ans = INF;
  for (ll i = 0; i <= N; i++)
  {
    for (ll k = 1; k <= 440 / max(Ma, Mb); k++)
    {
      ll tmp = dp.at(i).at(k * Ma).at(k * Mb);
      chmin(ans, tmp);
    }
  }
  cout << ((ans == INF) ? -1 : ans) << endl;
}

Measured memory_bytes: 70400
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 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 mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k) {
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= MOD;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= MOD;
    }
    return x * modinv(y, MOD) % MOD;
}

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

    int n, k;
    int ans = 0;

    int kiroku[100005];

    cin >> n >> k;
    rep(i, k + 1) kiroku[i] = i;
    for (int i = 1; i <= k; i++) {
        int a = 1, cnt = 0;
        while (a * a <= i) {
            if (i % a == 0) {
                cnt += kiroku[a];
                cnt += kiroku[i / a];
                if (a == i / a) cnt -= kiroku[a];
            }
            a++;
        }
        int now = i - (cnt - i);
        kiroku[i] = now;
        //cout << i << " " << now << endl;
        ans += mod_pow(k / i, n, MOD) * now % MOD;
        ans %= MOD;
    }
    if (ans <= 0) {
        ans *= -1;
        ans %= MOD;
        ans = MOD - ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4412
N, Q = map(int, input().split())
S = input()

T = [0] * N
for i in range(1, N):
  if S[i] == "C" and S[i-1] == "A":
    T[i] = 1
  T[i] += T[i-1]
#print("T:", T)

for q in range(Q):
  l, r = map(int, input().split())
  l -= 1
  r -= 1
  print(T[r] - T[l])

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  if (N % 2 == 0) return Pow(A * A % MOD, N / 2);
  return Pow(A * A % MOD, N / 2) * A % MOD;
}

int Solve(ll A, ll B){
  ll ans = 1;
  for (ll i = 1; i <= A + B; i++){
    ans *= i; ans %= MOD;
  }
  ll now = 1;
  for (ll i = 1; i <= A; i++){
    now *= i; now %= MOD;
  }
  ans *= Pow(now, MOD - 2); ans %= MOD;
  now = 1;
  for (ll i = 1; i <= B; i++){
    now *= i; now %= MOD;
  }
  ans *= Pow(now, MOD - 2); ans %= MOD;
  cout << ans << endl;

  return 0;
}

int main(){
  ll X, Y; cin >> X >> Y;

  if ((-1 * X + 2 * Y) % 3 != 0 || (2 * X - Y) % 3 != 0){
    cout << 0 << endl;
    return 0;
  }

  ll A = (-1 * X + 2 * Y) / 3;
  ll B = (2 * X - Y) / 3;

  if (A < 0 || B < 0){
    cout << 0 << endl;
    return 0;
  }

  Solve(A, B);

  return 0;
}


Measured memory_bytes: 3644
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints

A.sort!


alice = 0
bob = 0
A.each.with_index do |a, i|
  if i % 2 == 0
    alice += a
  else
    bob += a
  end
end

puts (alice - bob).abs



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

using namespace std;

int fn(int n){
    int ans;
    if (n % 2 == 0) {
        ans = n / 2;
    }else{
        ans = 3 * n + 1;
    }
    return ans;
}

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

    int count = 1;
    int count4 = 0;
    if(s == 1 || s == 2 || s == 4){
        count = 4;
    }else{
        while(count4 < 2){
            if(fn(s) == 4){
                count ++;
                count4 += 1;
            }else{
                count ++;
            }
            s = fn(s);
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int n , a[100005];
int main()
{
	scanf("%d" , &n);
	for(int i = n ; i ; i --)
		scanf("%d" , a + i);
	for(int i = 2 ; i <= n ; i ++)
	{
		if(a[i] - a[i - 1] > 1) 
			return puts("No") & 0;
		if(a[i] > a[i - 1])
			a[i] --;
	}
	return puts("Yes") & 0;
}

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

int main(){
  int N,H;cin>>N>>H;
  int maxA=0;
  vector<int>b(N);
  for(int i=0;i<N;i++){
    int A;
    cin>>A>>b.at(i);
    maxA=max(maxA,A);
  }
  
  sort(b.begin(),b.end(),greater<int>());
  
  int res=0;
  
  for(int i=0;i<N && H>0;i++){
    if(b.at(i)>maxA){
      res++;
      H-=b.at(i);
    }
    else
      break;
  }
  
  if(H>0){
    res+=H/maxA;
    if(H%maxA!=0)
      res++;
  }
  
  cout<<res;
}

Measured memory_bytes: 640
N = int(input())
a = [int(input()) for _ in range(N)]
a.sort()
ans = 0
now = 0
cnt = 0
for x in a:
    if x == now:
        cnt += 1
        continue
    if cnt % 2 == 1:
        ans += 1
    cnt = 1
    now = x
if cnt % 2 == 1:
    ans += 1
print(ans)

Measured memory_bytes: 7488
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

vector<vector<int>> product(vector<vector<int>>& A,vector<vector<int>>& B){
    int N=A.size();
    if(N==0){return {{0}};}
    int M=A[0].size();
    if(M==0){
        return {{0}};
    }
    
    int L=B.size();
    if(L==0){return {{0}};}
    int K=B[0].size();
    if(K==0 || M!=L){
        return {{0}};
    }
    //N*K M回

    vector<vector<int>> R;
    for(int i=0;i<N;i++){
        R.push_back({});
        for(int j=0;j<K;j++){
            R[i].push_back(0);
        }
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<K;j++){
            for(int k=0;k<M;k++){
                R[i][j]+=A[i][k]*B[k][j];
                R[i][j]%=MOD;
            }
        }
    }
    
    return R;
}


signed main(void){
    int N,K;
    vector<vector<int>> A,I;
    vector<vector<int>> D[100];
    int a;
    cin >> N >> K;
    REP(i,N){
        A.push_back({});
        REP(j,N){
            cin >> a;
            A[i].push_back(a);
        }
    }
    REP(i,N){
        I.push_back({});
        REP(j,N){
            I[i].push_back(i==j?1:0);
        }
    }
    D[0]=A;
    for(int i=0;(1ll<<i)<=K;i++){
        D[i+1]=product(D[i],D[i]);
    }
    int k=K,l=0;
    while(k>0){
        if(k%2==1){
            I=product(I,D[l]);
        }
        k/=2;
        l++;
    }
    
    int Ans=0;
    REP(i,N){
        REP(j,N){
            //cout << I[i][j] << " ";
            Ans=(Ans+I[i][j])%MOD;
        }
    }
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 2048
//答案参考

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	
	int a[100000];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	
	if(n==k) cout<<1<<endl;
	else if((n-k)%(k-1)==0) cout<<(n-k)/(k-1)+1<<endl;
	else cout<<(n-k)/(k-1)+2<<endl;
	
	
	return 0;
}		

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll m4 = 0, m2 = 0, m0 = 0;
    rep(i, N) {
        if (A[i] % 4 == 0) ++m4;
        else if (A[i] % 2 == 0) ++m2;
        else ++m0;
    }

    if (m4 + 1 == m0 && N == (m4 + m0)) cout << "Yes" << endl;
    else if (m4 < m0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3980
import sys
input = sys.stdin.readline
import numpy as np
MOD = 10**9+7

n, c = map(int, input().split())
A = np.array(tuple(map(int, input().split())))
B = np.array(tuple(map(int, input().split())))
E = np.zeros((n, c+1), dtype=np.int64)
for j in range(c+1):
  cum = np.array(tuple(pow(k, j, MOD) for k in range(401))).cumsum()%MOD
  E[:, j] = cum[B] - cum[A-1]

dp = np.zeros((n+1, c+1), dtype=np.int64)
dp[0, 0] = 1
for i, e in enumerate(E):
  for j, f in enumerate(e):
    dp[i+1, j:] += dp[i, :c+1-j]*f
    dp[i+1, j:] %= MOD
ans = dp[n, c]
print(ans)

Measured memory_bytes: 15056
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


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




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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,dp[2002][2002];
vii v;
int go(int pos,int l,int r){
    if(pos==sz(v)) return 0;
    int &ans=dp[pos][l];
    if(ans!=-1) return ans;
    return ans=max(go(pos+1,l+1,r)+v[pos].x*abs(v[pos].y-l),go(pos+1,l,r-1)+v[pos].x*abs(v[pos].y-r));
}
void solve(){
    cin>>n;
    rep(i,0,n){
        int x;
        cin>>x;
        v.pb({x,i});
    }
    sort(all(v));
    reverse(all(v));
    memset(dp,-1,sizeof dp);
    cout<<go(0,0,n-1)<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 35172
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
 
N = (int(input()))
A = [int(i) for i in input().split()]

A1 = [0] * (N)
A2 = [0] * (N)
A3 = [0] * (N)
A1[0] = A[0]
A2[N-1] = A[N-1]

for i in range(N):
  if i==0 : continue
  A1[i] = gcd(A1[i-1],A[i])
  A2[N-1-i] = gcd(A2[N-i],A[N-1-i])
  
for i in range(N):
  if i==0 : A3[i] = A2[i+1] ; continue
  if i==N-1 : A3[i] = A1[i-1] ; continue
  A3[i] = gcd(A1[i-1],A2[i+1])

print(max(A3))

Measured memory_bytes: 14428
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;
static const long long mod = 1000000007;

int main() {
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  ll cur = 26, len = 1;
  string ans = "";
  while(true){
    if(n <= cur){
      n--;
      do {
        ans += 'a' + (n % 26);
        n /= 26;
      } while(n > 0);
      while(len>(ll)ans.size()){
        ans += 'a';
      }
      break;
    }
    n -= cur;
    cur *= 26;
    len++;
  }

  Reverse(ans);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

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

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

int main(){
	int N;
	cin >> N;
	int a = N%10;
	if (a == 3) cout << "bon" << endl;
	else if (a == 0 || a == 1 || a == 6 || a == 8) cout << "pon" << endl;
	else cout << "hon" << endl;

}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main() {
    char ch[10];
    cin>>ch;
    if(ch[0]=='S') {
        cout<<"Cloudy"<<endl;
    }
    else if(ch[0]=='C') {
        cout<<"Rainy"<<endl;
    }
    else if(ch[0]=='R') {
        cout<<"Sunny"<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void kakunin1(int kaki[][100], int w, int h) {
	for (int i = 1; i <= h; i++) {
		for (int j = 0; j < w; j++) {
			cout << " " << kaki[i][j];
		}
		cout << endl;
	}
	return;
}
int main() {
	int n;
	while (cin >> n&&n) {
		int w, h;
		cin >> w >> h;
		int kaki[100][100] = { {} };
		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			kaki[y][x] = 1;
		}
		//kakunin1(kaki, w, h);
		int s, t;
		cin >> s >> t;
		int cnt = 0;
		for (int x1 = 1; x1 <= w - s + 1; x1++) {
			for (int y1 = 1; y1 <= h - t + 1; y1++) {
				int cntkari = 0;
				for (int x2 = 0; x2 < s; x2++) {
					for (int y2 = 0; y2 < t; y2++) {
						//cout << " " << kaki[y2][x2];
						cntkari += kaki[y1 + y2][x1 + x2];
					}
					//cout << endl;
				}
				//cout << endl;
				cnt = max(cnt, cntkari);
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := scanInt()
	s := scanText()

	r := strings.Count(s, "R")
	g := strings.Count(s, "G")
	b := strings.Count(s, "B")

	ans := r * g * b

	for i := 1; i < n; i++ {
		for j := 1; j <= n; j++ {
			gi := i + j
			bi := gi + j
			if bi > n {
				break
			}
			if s[i-1:i] != s[gi-1:gi] && s[bi-1:bi] != s[gi-1:gi] && s[i-1:i] != s[bi-1:bi] {
				ans--
			}
		}
	}
	fmt.Println(ans)
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n - 1; i++) {
			++array[sc.nextInt() - 1];
		}
		for (int i = 0; i < n; i++) {
			System.out.println(array[i]);
		}
	}
}


Measured memory_bytes: 60144
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#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) {
	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);
}
/*--------Library Zone!--------*/


string s;
int ha[200005];
int mi[1 << 26];
int dp[200005];
signed main() {
	cin >> s;
	rep(i, s.size()) {
		ha[i] ^= 1 << (s[i] - 'a');
		ha[i + 1] = ha[i];
	}
	mi[0] = 0;
	REP(i, 1 << 26)mi[i] = mod;
	rep(i, s.size())dp[i] = mod;
	rep(i, s.size()) {
		chmin(dp[i], mi[ha[i]] + 1);
		rep(j, 26) {
			chmin(dp[i], mi[ha[i] ^ (1 << j)] + 1);
		}
		chmin(mi[ha[i]], dp[i]);
	}
	cout << dp[s.size() - 1] << endl;
}


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

namespace AtCoderCs
{
   class Program
   {
       static void Main()
       {

           // Num...問題文における 'K' 
           Num = int.Parse(Console.ReadLine());

           // digit...桁数
           var digit = 0;

           // i...カウンター('i == Num' になった時の
           // 'LunLun' 値が計算結果
           i = 0;

           // 'LunLunGetter(int, int)'内で計算を行う
           // 'i == Num' になった時ループを抜けて終了する
           for (; LunLunGetter(digit, -1); digit++) ;


       }

       static int[] LunLun = new int[0];
       static int Num;
       static int i;
       static bool LunLunGetter(int targetDigit, int previousDigit = -1)
       {
           
           // targetDigit...使用する桁数（というか最大インデックス）
           // 実際に使用する桁数は 'targetDigit + 1'
           // previousDigit...ひとつ前の'LunLunGetter'が計算していた数値のある桁数
           // （というかやっぱり0から始まるインデックス）

           // start, end...このメソッドが計算する桁で取りうる値の最小・最大値
           // nowDigit...このメソッドが計算する桁（というかインデックス）

           int start, end;
           var nowDigit = previousDigit + 1;

           // 一桁目（インデックス的には0）から計算する場合
           if (nowDigit == 0)
           {

               // LunLunを初期化しなくちゃいけないから初期化
               LunLun = new int[targetDigit + 1];

               // 一桁目は0以外何でもよいから1以上10未満
               start = 1; end = 10;

           }
           else
           {

               // それ以外は前の桁の数値に依存するからここでswitch
               switch (LunLun[previousDigit])
               {
               case 0:

                   // 0以上2未満
                   start = 0; end = 2;
                   break;
               
               case 9:

                   // 8以上10未満
                   start = 8; end = 10;
                   break;

               default:

                   // その数より1小さい奴以上2大きい奴未満
                   start = LunLun[previousDigit] - 1;
                   end = LunLun[previousDigit] + 2;
                   break;
               }
           }

           // 検証
           for (LunLun[nowDigit] = start; LunLun[nowDigit] < end; LunLun[nowDigit]++)
           {

               // 目的の桁数に達していない場合
               if (targetDigit != nowDigit)
               {

                   // 次の桁を調べる 'LunLunGetter' を呼び出し、その中で値が出力完了した場合は終了する
                   if (!LunLunGetter(targetDigit, nowDigit)) return false;                   
               }
               else
               {

                   // 目的の桁に達した場合
                   // ルンルン数として数える
                   i++;

                   // ルンルン数取得が終了した場合
                   if (i == Num)
                   {

                       LunLun.ToList().ForEach(x => Console.Write(x));
                       return false;

                   }

               }

           }

           return true;

       }

   }
}

Measured memory_bytes: 13396
n,k,q = map(int, input().split())
a = []
for _ in range(q):
    a.append(int(input()))
ans = [k-q for x in range(n)]

for i in range(q) :
  ans[a[i]-1] += 1
  
for i in range(n) :
  if ans[i] > 0 :
    print('Yes')
  else : 
    print('No')

Measured memory_bytes: 11764
/*
#include <iostream>
#include <vector>
using namespace std;

using ll = long long;
const int limit = 100010;
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v]=d;
  for(auto &e:tree[v]){
    if(e.to==p) continue;
    dfs(e.to, v, d+e.cost);
  }
}

int main(){
  int n;
  cin >> n;
  for(int i = 0;i<n-1;++i){
    int a, b,c;
    cin >> a >> b >> c;
    a--,b--;
    tree[a].push_back({b,c});
    tree[b].push_back({a,c});
  }

  int q,k;
  cin >> q >> k;
  k--;

  dfs(k,-1,0);
  for(int i = 0;i<q;++i){
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << depth[x]+depth[y] << endl;
  }
  return 0;
}*/

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
#define ll  long long

struct E{
  vector<ll> to;
  vector<ll> cost;
};

ll N,Q,K;
//vector<E> Tree(100001);
E Tree[100001];
vector<ll> x,y;

ll re[100001]={0};


void solve(ll parent, ll co){
  if(re[parent]==0)
    {
      re[parent] = co;
      for(ll i = 0,l = Tree[parent].to.size(); i<l ; i++){
	if(Tree[parent].to[i]==K)continue;
	solve(Tree[parent].to[i],Tree[parent].cost[i]+co);
      }
    }
}

int main(){

  cin >> N;
  N--;
  for(ll i = 0;i<N;i++){
    ll ina,inb,inc;
    cin >> ina >> inb >> inc;

    Tree[ina].to.push_back(inb); Tree[ina].cost.push_back(inc);
    Tree[inb].to.push_back(ina); Tree[inb].cost.push_back(inc);
  }

  cin >> Q >> K;
  for(ll i = 0;i<Q;i++){
    ll inx, iny;
    cin >> inx >> iny;
    x.push_back(inx);
    y.push_back(iny);
  }
  /*
  //一応木の形を確認  
  for(ll i =0;i<=5;i++){
    cout << "i" << i << ":" ;
    for(ll j =0;j< Tree[i].cost.size();j++){
      cout << Tree[i].cost[j] << " " ;
    }
    cout << endl;
  }
  */
  solve(K,0);

  for(ll i = 0;i<Q;i++){
    cout << re[x[i]]+re[y[i]] << endl;
  }
  return 0;
}


Measured memory_bytes: 19948
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <numeric>
using namespace std;
#define MAX_N 400

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 long long INF = 1LL << 60;

// Input
int N;
int C[MAX_N], V[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> V[i];
    for (int i = 0; i < N; i++) cin >> C[i];

    int ans = 0;
    int cost = 0;
    for (int i = 0; i < N; i++) {
        if (V[i] > C[i]) {
            ans += V[i];
            cost += C[i];
        }
    }

    // Ans
    cout << ans-cost << endl;
}


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

int main(){
  int n,m;
  cin >> n >> m;
  if(m == n) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
loop do
  s = gets.chomp
  break if s=='.'
  s = s.scan(/[\(\)\[\]]/).join
  1000.times do
    s.gsub!('()','')
    s.gsub!('[]','')
  end
  if s.size == 0
    puts 'yes'
  else
    puts 'no'
  end
end

Measured memory_bytes: 8808