akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

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

    if (a == "H" && b == "H") cout << "H" << endl;
    else if (a == "H" && b == "D") cout << "D" << endl;
    else if (a == "D" && b == "H") cout << "D" << endl;
    else if (a == "D" && b == "D") cout << "H" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>

template<typename T>inline bool check_min(T a,T &b){return a<b?b=a,1:0;}

namespace fuck
{
	const int N=101000,M=N*2,INF=23333;
	int begin[N],next[M],to[M],w[M];
	int f[N];
	int k,e;
	void add(int x,int y,int z)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		w[e]=z;
	}
	void spfa()
	{
		std::queue<int> Q;
		f[1]=0,Q.push(1);
		for(int p,q;!Q.empty();)
		{
			p=Q.front(),Q.pop();
			for(int i=begin[p];i;i=next[i])
				if(check_min(f[p]+w[i],f[q=to[i]]))
					Q.push(q);
		}
	}
	void solve()
	{
		scanf("%d",&k);
		for(int i=1;i<k;i++)
			add(i,(i+1)%k,1),add(i,i*10%k,0);
		for(int i=0;i<k;i++)
			f[i]=INF;
		spfa();
		printf("%d\n",f[0]+1);
	}
}

int main()
{
	fuck::solve();
	return 0;
}


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

int main()
{
    int n,x,y;
    map<int,int>cnt;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++){ 
        for(int j=i+1;j<=n;j++){ 
           int d=min({abs(i-j),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y)});
            cnt[d]++;
        }
    }
    for(int i=1;i<=n-1;i++){ 
        cout<<cnt[i]<<'\n';
    }
   
   
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<algorithm>
#include<bits/stdc++.h>
#include<utility>
#define ll long long 
using namespace std;

int main(void) {
	ll n,i,c=0;
	string s;
	cin>>n>>s;
	for(i=0;i<n-2;){
	    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
	    c++;
	    i+=3;}
	    else
	    i++;
	}
	cout<<c;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    int N;
    cin >> N;
    int B[N-1];
    rep(i,N-1){
        cin >> B[i];
    }

    int A[N];
    A[0] = B[0];
    A[N-1] = B[N-2];
    for(int i = 1;i<N-1;i++){
        A[i] = min(B[i],B[i-1]);
        
    }
    ll sum = 0;
    rep(i,N){
//        printf("%d ",A[i]);
        sum+=A[i];
    }
//    printf("\n");
    
    cout <<sum << endl;
    return 0;
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;


const i64 MAXN = 20;

i64 n;
i64 a[MAXN];
i64 b[MAXN];

inline i64 val(pair<i64, bool> p) {
    if (!p.second) {
        return a[p.first];
    }
    else {
        return b[p.first];
    }
}

inline i64 val(vector<i64>& r) {
    //stringstream ss;
    //for (auto t : r) {
    //    ss << t << " ";
    //}
    //cerr << ss.str() << endl;

    i64 R = 0;
    set<i64> q;
    for (i64 i = 0; i < n; i++) {
        for (i64 j = 0; j < i; j++) {
            if (r[j] > r[i]) {
                R += 1;
            }
        }
    }
    return R;
}

i64 solve(i64 m) {
    map<i64, map<i64, vector<i64>>> e;
    for (i64 i = 0; i < n; i += 1) {
        pair<i64, i64> p = { i, (m & (1ll << i) ? 1 : 0) };
        e[val(p)][p.second].push_back(p.first);
    }

    vector<i64> r;
    i64 ts = 0;
    for (auto& u : e) {
        auto& t = u.second;

        vector<i64> c[2];
        for (auto v : t[0]) {
            c[v % 2].push_back(v);
        }
        for (auto v : t[1]) {
            c[(v + 1) % 2].push_back(v);
        }

        i64 z[2] = { 0, 0 };
        i64 tt = (t[0].size() + t[1].size());
        z[0] = tt / 2 + tt % 2;
        z[1] = tt / 2;
        if (ts % 2) {
            swap(z[0], z[1]);
        }

        if (c[0].size() != z[0] || c[1].size() != z[1]) {
            return inf;
        }

        sort(c[0].data(), c[0].data() + c[0].size());
        sort(c[1].data(), c[1].data() + c[1].size());

        for (i64 i = 0; i < t[0].size() + t[1].size(); i++) {
            r.push_back(c[(ts + i) % 2][i / 2]);
        }


        ts += t[0].size() + t[1].size();
    }

    return val(r);
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;
    for (i64 i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (i64 i = 0; i < n; i++) {
        cin >> b[i];
    }

    i64 R = inf;
    for (i64 m = 0; m < (1ll << n); m++) {
        R = min(R, solve(m));
    }
    cout << ((R == inf) ? -1 : R) << endl;

    return 0;
}

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



int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int h,n,a,sum=0;
    cin>>h>>n;
    for(int i=0;i<n;i++)
    {
    	cin>>a;
    	sum+=a;
	}
	if(sum>=h)
	{
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
    
	return 0;
	
	
}

Measured memory_bytes: 256
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;

template<class T>
using vec2d = std::vector<std::vector<T>>;


template<class T>
vec2d<T> makeVec2d(const int n1, const int n2, const T initValue) {
  return vec2d<T>(n1, vec<T>(n2, initValue));
}


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


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


const int MOD = (int)1e9 + 7;

void solve(istream& in, ostream& out) {
  auto h = next<int>(in);
  auto w = next<int>(in);
  vec2d<int> f = makeVec2d<int>(h, w, 0);
  vec<string> s(h);
  FOR(i, h) {
    s[i] = next<string>(in);
  }
  f[0][0] = 1;
  FOR(i, h) {
    FOR(j, w) {
      int ni = i + 1, nj = j + 1;
      if (ni < h && s[ni][j] == '.') {
        f[ni][j] += f[i][j];
        if (f[ni][j] >= MOD) {
          f[ni][j] -= MOD;
        }
      }
      if (nj < w && s[i][nj] == '.') {
        f[i][nj] += f[i][j];
        if (f[i][nj] >= MOD) {
          f[i][nj] -= MOD;
        }
      }
    }
  }
  out << f[h-1][w-1] << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 5248
#include <stdio.h>
int main (int argc, char * argv[])
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b");
        printf("\n");
    }else if(a>b){
        printf("a > b");
        printf("\n");

    }else if(a==b){
        printf("a == b");
        printf("\n");

    }
    return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>    //pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define ll long long
#define rep(init, i, n) for (ll i = init; i < (n); i++)
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end())
#define PI 3.14159265358979323846264338327950L
//コード自動整形 Shift + Option + F @vscode
using namespace std;
using vec = vector<ll>;

ll facctorialMethod(ll k); //階乗を出力する
/////main/////
int main()
{
    ll mod = 998244353;
    ll N, K, li, ri;
    cin >> N >> K;
    vec L(K), R(K);
    vec dp(N + 1, 0), dpsum(N + 1, 0);

    rep(0, i, K)
    {
        cin >> L.at(i) >> R.at(i);
    }

    dp.at(1) = 1;
    dpsum.at(1) = 1;
    rep(2, x, N + 1)
    {
        rep(0, i, K)
        {
            li = x - R.at(i);
            ri = x - L.at(i);
            /*
            cout << "li=" << li << endl;
            cout << "ri=" << ri << endl;
            */
            if (ri < 0)
                continue;
            li = max(li, (ll)1);

            //
            /*
            cout << "i=" << i << endl;
            cout << "R.at(" << i << ")=" << R.at(i) << endl;
            cout << "L.at(" << i << ")=" << L.at(i) << endl;
            cout << "li=" << li << endl;
            cout << "dp.at(" << x << ")=" << dp.at(x) << endl;
            */
            dp.at(x) += dpsum.at(ri);
            dp.at(x) -= dpsum.at(li - 1);
            dp.at(x) += mod;
            dp.at(x) %= mod;
            /*
            cout << "dpsum.at(" << ri << ")=" << dpsum.at(ri) << endl;
            cout << "dpsum.at(" << li - 1 << ")=" << dpsum.at(li - 1) << endl;
            cout << "dp.at(" << x << ")=" << dp.at(x) << endl;
            */
        }
        //cout << dp.at(x) << endl;
        dpsum.at(x) = dpsum.at(x - 1) + dp.at(x);
        /*
        cout << "dpsum.at(" << x << ")=" << dpsum.at(x) << endl;
        */
        dpsum.at(x) %= mod;
    }

    /*rep(0, x, N) rep(0, i, K) rep(L.at(i), j, R.at(i) + 1)
    {
        if (x + j < N)
        {
            dp.at(x + j) += dp.at(x);
            dp.at(x + j) %= mod;
        }
    }*/
    /*rep(0,i,N){cout<<dpsum.at(i)<<endl;
    }*/
    cout << dp.at(N) << endl;
}
/////main/////

/////function/////
ll facctorialMethod(ll k)
{
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

Measured memory_bytes: 6344
#include<iostream>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;

  	string out;
  	if (a==b) {
      if (a==c) {
        out = "No";
      } else {
        out = "Yes";
      }
    } else {
      if (a!=c && b!=c) {
        out = "No";
      } else {
        out = "Yes";
      }
    }
  
  	cout << out << endl;
    return 0;
}

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

int main() {
    int K; cin >> K;
    vector<int> l = {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};
    cout << l[K-1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <stack>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <cctype>
#include <memory.h>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<bool> vec;
typedef vector<vec> mat;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define bits(n) (1 << n)
#define sqr(x) ((x) * (x))

const int INF = 1 << 29;
const double EPS = 1e-10;

mat mul(const mat &A, const  mat &B){
  mat C(A.size(), vec(B[0].size(), false));
  for(int i = 0; i  < (int)A.size(); i++){
    for(int j = 0; j  < (int)B[0].size(); j++){
      for(int k = 0; k < (int)B.size(); k++){
	if(A[i][k] & B[k][j]) C[i][j] = true;;
      }
    }
  }
  return C;
}

mat matpow(const mat &A, ll n){
  if(n == 1) return A;
  if(n % 2) return mul(A, matpow(A, n - 1));
  return matpow(mul(A, A), n / 2);
}

void print(mat &A){
  for(int i = 0; i < (int)A.size(); i++){
    for(int j = 0; j < (int)A[0].size(); j++) cout << A[i][j] << " " ;
    cout << endl;
  }
}


int to[300];
int from[300];

int main(){
  ll N, M, Z, a, b;
  while(cin >> N >> M >> Z && (N || M || Z)){
    for(int i = 0; i < M; i++){
      cin >> a >> b;
      from[2*i] = to[i*2+1] = --a;
      to[2*i] = from[i*2+1]= --b;
    }
    from[2*M] = -1; to[2*M] = 0;
    mat A(2 * M + 1, vec(2 * (M + 1), false));
    
    for(int i = 0; i <= 2 * M; i++){
      for(int j = 0; j <= 2 * M; j++){
	if(to[i] == from[j] && from[i] != to[j]){
	  A[i][j] = true;
	}
      }
    }
    
    A = matpow(A, Z);
    //    print(A);
    bool f = false;
    for(int i = 0; i <= 2 * M; i++){
      for(int j = 0; j <= 2 * M; j++){
	if(i == j) continue;
	if(A[i][j] && to[i] == 0 && to[j] == N - 1) f = true;
      }
    }
    cout << (f ? "yes" : "no") << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[1000010],b[1000010],c[1000010];
int main()
{
	int n,x=0,z;
	scanf("%d",&n);
	z=n;
	while(n)
	{
		x+=n%10;
		n/=10;
	}
	if(z%x)
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}
}

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

int main() {
    double N, T, A;
    cin >> N >> T >> A;
    vector <double> H(N);
    for (int i=0; i<N; i++) cin >> H.at(i);
    float res = 10000000;
    int ans = 0;
    for (int i=0; i<N; i++) {
        H.at(i) = T - H.at(i) * 0.006;
        H.at(i) = abs(A-H.at(i));
        if (H.at(i)<res) {
            res = H.at(i);
            ans = i+1;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
S = input() + "#"

L = []
#L2 = []
cnt = 1
for i in range(1,N+1) :
    if S[i] != S[i-1] :
        L.append(cnt)
        #L2.append(cnt-1)
        cnt = 1
    else :
        cnt += 1

#print(L)

ans = 0

calc = sum(L) - len(L)

if len(L) <= 2*K + 1 :
    ans = sum(L)-1
else :
    su = sum(L[0:0+2*K+1])
    d = su
    c = calc + d - 1 - (d - (2*K+1))
    ans = max(ans,c)

    for i in range(2*K+1,N) :
        if i >= len(L) : break
        #d = sum(L[i:i+2*K+1])
        d += L[i]
        d -= L[i - (2*K+1)]
        c = calc + d - 1 - (d - (2*K+1))
        ans = max(ans, c)
        #print(i,i*2+1,c,calc,d)

print(ans)


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

#define N 100
#define INFTY 10000001
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dijkstra(int n, int d[], int M[N][N]) {
  int i, vertex, min_d, color[N];
  // 初期状態
  for (i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;

  while (1) {
    // S - V でコスト最小の頂点を選ぶ
    vertex = -1;
    min_d = INFTY;
    for (i = 0; i < n; i++) {
      if (color[i] == GRAY && d[i] < min_d) {
        min_d = d[i];
        vertex = i;
      }
    }
    // S = V の場合は終了
    if (vertex == -1) break;

    // vertexをSに追加
    color[vertex] = BLACK;

    // S-Vに属し、vertexに隣接する頂点のコストを更新
    for (i = 0; i < n; i++) {
      if (color[i] != BLACK && M[vertex][i] < INFTY) {
        color[i] = GRAY;
        if (d[i] > d[vertex] + M[vertex][i]) {
          d[i] = d[vertex] + M[vertex][i];
        }
      }
    }
  }
}

int main() {
  int i, j, n, u, k, v, c, d[N], M[N][N];

  cin >> n;
  // 隣接行列を作る
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      M[i][j] = INFTY;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    for (j = 0; j < k; j++) {
      cin >> v >> c;
      M[u][v] = c;
    }
  }

  dijkstra(n, d, M);

  for (i = 0; i < n; i++) cout << i << " " << d[i] << endl;    

  return 0;
}



Measured memory_bytes: 3120
#include<stdio.h>
int main()
{
    int n,m,k,x,y,i,j,c=0,d=0;
    scanf("%d",&n);
    int A[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&A[i]);
    }
    for(j=1; j<=n; j++)
    {
        if(j!=A[j-1])
        {
            m=j;
            for(k=j; k<=n; k++)
            {
                if(m==A[k])
                {
                    x=A[j-1];
                    A[j-1]=A[k];
                    A[k]=x;
                    c++;
                }

            }
        }



    }
    if(c==1||c==0)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }




}


Measured memory_bytes: 128
N = int(input())
H = list(map(int, input().split()))

def flower(lst=H):
    if not lst:
        return 0
    ans = min(lst)
    lst = list(map(lambda x:x-ans, lst))
    indexes = [-1]
    indexes.extend([i for i, j in enumerate(lst) if j == 0])
    m = len(indexes)
    indexes.append(len(lst))
    for i in range(m):
        ans += flower(lst[indexes[i]+1:indexes[i+1]])
    return ans

print(flower())


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  for (int i = 0; i < M; i++) {
    cin >> p.at(i) >> S.at(i);
  }
  
  int AC = 0, WA = 0;
  vector<bool> flag(N, false);
  vector<int> WAnum(N, 0);
  for (int i = 0; i < M; i++) {
    if (flag.at(p.at(i) - 1) == false) {
      if (S.at(i) == "WA") {
        WAnum.at(p.at(i) - 1) += 1;
      }
      else {
        AC += 1;
        flag.at(p.at(i) - 1) = true;
        WA += WAnum.at(p.at(i) - 1);
      }
    }
  }
  
  cout << AC << " " << WA << endl;
}


Measured memory_bytes: 6528
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int a, b;
  unused = scanf("%d %d", &a, &b);

  if((a+b)%2==0) printf("%d", (a+b)/2);
  else printf("%d", ((a+b)/2)+1);
  return 0;
}

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

static const int N=100;

int main() {
    int n, p[N+1], m[N+1][N+1];
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> p[i-1] >> p[i];
    }
    
    for (int i=0; i<=n; i++) m[i][i] = 0;
    for (int l=2; l<=n; l++) {
        for(int i=1; i<=n-l+1; i++) {
            int j = i+l-1;
            m[i][j] = (1 << 21);
            for (int k=i; k<=j-1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }
    
    cout << m[1][n] << endl;
    
    return 0;
}


Measured memory_bytes: 3132
n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[0]*n
def mm(x):
    return h[x-1]
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]==h[b-1]:
        l[a-1]+=1
        l[b-1]+=1
    elif h[a-1]>h[b-1]:
        l[b-1]+=1
    else:
        l[a-1]+=1
print(l.count(0))

Measured memory_bytes: 20016
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

// snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

// combination c(N);
// mint ans = c(N,n);
// cout << ans.x << endl;
// Nとnはll型(mintではない)
// -------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i=0; i<N; i++){
        cin >> S[i];
    }
    vector<int> cnt(5,0);
    string str = "MARCH";
    for(int i=0; i<N; i++){
        for(int j=0; j<5; j++){
            if(str[j] == S[i].front()){
                cnt[j]++;
            }
        }
    }
    ll ans = 0;
    for(int bit=0; bit<(1<<5); bit++){
        if(__builtin_popcount(bit) == 3){
            ll temp = 1;
            for(int i=0; i<5; i++){
                if(bit & (1<<i)){
                    temp *= cnt[i];
                }
            }
            ans += temp;
        }
    }
    cout << ans << enld;
    return 0;
}

Measured memory_bytes: 5760
from collections import defaultdict
n,m = map(int,input().split())
d = defaultdict(list)
for i in range(m):
  p,y = map(str,input().split())
  p = '0' * (6-len(p)) + p
  d[p].append([int(y),i])
ans = [0] * m
for p in d:
  c = 0
  for t in sorted(d[p]):
    c += 1
    ans[t[1]] = p + '0' * (6-len(str(c))) + str(c)
print('\n'.join(ans))

Measured memory_bytes: 52704
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

ll a, b, c, d;
map<ll, ll> vals;
ll GetMin(initializer_list<ll> v) { return *min_element(v.begin(), v.end()); }

ll solve(const ll n);

ll GetValFor(const ll n, const ll v, const ll div) {
  ll rem1 = n % div;
  ll rem2 = div - rem1;
  ll ans = rem1 * d + v + solve((n - rem1) / div);
  if (rem1 != 0) {
    ans = min(ans, rem2 * d + v + solve((n + rem2) / div));
  }
  return ans;
}

// ll recC = 0;
ll solve(const ll n) {
  // recC++;
  if (n == 0) {
    return 0;
  }
  if (n == 1) {
    return d;
  }
  if (vals.find(n) != vals.end())
    return vals[n];
  ll vv = GetMin({GetValFor(n, a, 2), GetValFor(n, b, 3), GetValFor(n, c, 5)});
  if ((double)n < (double)vv / d)
    vv = d * n;
  return vals[n] = vv;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  ll n;
  cin >> t;
  while (t--) {
    cin >> n >> a >> b >> c >> d;
    vals.clear();
    cout << solve(n) << "\n";
  }
  // cerr << recC << endl;
}

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

inline int read(){
	int x=0,f=1;char ch;
	for(ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}

int main(){
	int n=read(),i=read();
	printf("%d\n",n-i+1);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<set>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    vector<tuple<string,string,char,int> > v;
    map<string,int> s,b;
    map<char,vector<int> > c;
    set<string> names;
    for(int i=0;i<n;i++){
      string name,o;
      char com;
      int p;
      cin>>name>>o>>com>>p;
      names.insert(name);
      if(o=="BUY"){
	int x=-1;
	for(int j=0;j<v.size();j++){
	  if(get<0>(v[j])!=name&&get<1>(v[j])!=o&&get<2>(v[j])==com&&get<3>(v[j])<=p&&(x<0||get<3>(v[j])<get<3>(v[x]))){
	    x=j;
	  }
	}
	if(x<0){
	  v.emplace_back(name,o,com,p);
	}else{
	  int m=(p+get<3>(v[x]))/2;
	  s[get<0>(v[x])]+=m;
	  b[name]+=m;
	  c[com].push_back(m);
	  v.erase(begin(v)+x);
	}
      }else{
	int x=-1;
	for(int j=0;j<v.size();j++){
	  if(get<0>(v[j])!=name&&get<1>(v[j])!=o&&get<2>(v[j])==com&&get<3>(v[j])>=p&&(x<0||get<3>(v[j])>get<3>(v[x]))){
	    x=j;
	  }
	}
	if(x<0){
	  v.emplace_back(name,o,com,p);
	}else{
	  int m=(p+get<3>(v[x]))/2;
	  b[get<0>(v[x])]+=m;
	  s[name]+=m;
	  c[com].push_back(m);
	  v.erase(begin(v)+x);
	}
      }
    }
    for(auto e:c){
      cout<<e.first<<' '<<*min_element(begin(e.second),end(e.second))<<' '<<accumulate(begin(e.second),end(e.second),0)/e.second.size()<<' '<<*max_element(begin(e.second),end(e.second))<<endl;
    }
    cout<<"--"<<endl;
    for(auto e:names){
      cout<<e<<' '<<b[e]<<' '<<s[e]<<endl;
    }
    cout<<"----------"<<endl;
  }
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define re register
#define N 100007
using namespace std;
struct node{
	int u,d;
};
struct edge{
	int to,next;
}e[N<<1];
inline int read(){
    int x=0,w=0;char ch=getchar();
    while (!isdigit(ch))w|=ch=='-',ch=getchar();
    while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    return w?-x:x;
}
int cnt,head[N],dis[N],vis[N],r[N],s[N],d[N],c[N],col[N],tot,n,m,ttt;
inline void add(int u,int v){
	e[++cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}
void dfs(int u,int d,int c){
	if (!d||d<=r[u])return;
	r[u]=d;
	if (!col[u])col[u]=c;
	for (int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		dfs(v,d-1,c);
	}
}
signed main(){
	n=read();m=read();
	for (int i=1;i<=m;++i){
		int u=read(),v=read();
		add(u,v);add(v,u);
	}
	int Q=read();
	for (int i=1;i<=Q;++i){
		s[i]=read(),d[i]=read(),c[i]=read();
	}
	for (int i=Q;i;--i){
		dfs(s[i],d[i]+1,c[i]);
	}
	for (int i=1;i<=n;++i)printf("%d\n",col[i]);
    return 0;
}


Measured memory_bytes: 5248
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main() {
	int a[3], cnt = 0;
	rep(i, 3)
		cin >> a[i];
	sort(a, a + 3);

	if (!(a[0] % 2 == a[1] % 2 && a[1] % 2 == a[2] % 2))
	{
		if (a[0]%2 == a[1]%2)
		{
			a[0] += 1;
			a[1] += 1;
		}
		else if (a[1]%2 == a[2]%2)
		{
			a[1] += 1;
			a[2] += 1;
		}
		else {
			a[0] += 1;
			a[2] += 1;
		}
		cout << (2 * a[2] - a[0] - a[1] + 2) / 2;
	}
	else
		cout << (2 * a[2] - a[0] - a[1]) / 2;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int array[10];
  int N;
  int sum=0;
  cin>>N;
  for(int i=0;i<N;i++)
    cin>>array[i];
  sort(array,array+N);
  for(int i=0;i<N-1;i++)
    sum+=array[i];
  sum+=(array[N-1]/2);
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
int N;

void solve() {
    cin >> N;
    ll A[N];
    for (int i = 0; i < N; ++i) { cin >> A[i]; }

    ll ans = 0;
    for (int i = 0; i < 60; ++i) {
        ll odd = 0;
        for (int j = 0; j < N; ++j) {
            if (A[j] >> i & 1) odd++;
        }
        ll even = N - odd;
        ll x = even * odd % MOD;
        for (int j = 0; j < i; ++j) { x = 2 * x % MOD; }
        ans += x;
        ans %= MOD;
    }

    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string n;
    cin >> n;
    
    int count = 0;
    int i = 0;
    
    for (i = 0 ; i < n.size(); ++i)
        if (n[i] == '2')
            count = count + 1;
        
    
    
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector>

using namespace std;

int main()
{
  int N, D;
  cin >> N >> D;

  vector< vector<int> > x(N, vector<int>(D));
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j < D; ++j)
    {
      cin >> x[i][j];
    }
  }

  int count = 0;
  for (int i = 0; i < N; ++i)
  {
    for (int j = i+1; j < N; ++j)
    {
      
      int sum = 0;
      for (int k = 0; k < D; ++k)
      {
        int diff = x[i][k] - x[j][k];
        sum += diff * diff;
      }

      double root = sqrt(sum);
      if (floor(root) == root) ++count;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
from sys import stdin


def main():

    S = stdin.readline().rstrip()
    S_len = len(S)

    sum = 0
    s = S[0]
    x = 1

    while True:
        if len(s) == 1:
            if s == S[x]:
                s = s + S[x]
            else:
                sum += 1
                s = S[x]
        else:
            sum += 2
            x += 1

            if x >= S_len:
                break
            s = S[x]
        x += 1

        if x >= S_len:
            sum += 1
            break

    print(sum)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n;
  cin >> n;
  vector<mint> a(n);
  rep(i, n) cin >> a[i];
  mint ans = 0;
  vector<mint> b(n);
  b[n-1] = a[n-1];
  for (int i = n-2; i > 0; i--) {
    b[i] = b[i+1] + a[i];
  }
  rep(i, n-1) {
    ans += a[i]*b[i+1];
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 6404
#include <iostream>
using namespace std;
int main()
{
    int n,k,a=1,ctr=0;
    cin>>n>>k;

    while(a<=k&&n!=0)
    {
        a*=2;
        n--;
    }
    while(n!=0)
    {
        a+=k;
        n--;
    }

 cout<<a<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;
const int mod = 1000000007;

vii f(const vi & a) {
  vii v(a.size(), pii(1, 1000000000));
  v[0] = pii(a[0], a[0]);
  for (int i = 1; i < a.size(); ++i) {
    if (a[i] > a[i-1]) {
      v[i] = pii(a[i], a[i]);
    } else {
      v[i].second = a[i];
    }
  }
  return v;
}

int len(pii x, pii y) {
  return max(0, min(x.second, y.second) - max(x.first, y.first) + 1);
}

int main() {
  int n;
  cin >> n;
  vi a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  ll res = 1;
  vii x = f(a);
  reverse(b.begin(), b.end());
  vii y = f(b);
  for (int i = 0; i < n; ++i) {
    res = res * len(x[i], y[n-i-1]) % mod;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2560
def main(l,r)
  min = 2020
  l.upto(r-1) do |i|
    (i+1).upto(r).each do |j|
      mod = (i*j)%2019
      min = mod if min >= mod
      break if min == 0
    end
    break  if min == 0
  end
  return min
end

L, R = gets.chomp.split.map(&:to_i)
p main(L, R)

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

const int MAX_S = 3010, MAX_T = 3010;
int dp[MAX_S][MAX_T] = {};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    string s,t; cin >> s >> t;
    //memset(dp,0,sizeof(dp));
    int slen = s.length();
    int tlen = t.length();
    REP(i,slen+1) dp[0][i] = 0;
    REP(i,tlen+1) dp[i][0] = 0;
    FOR(i,1,slen+1){
        FOR(j,1,tlen+1){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    
    string ans = "";
    int ni = slen, nj = tlen;
    while(ni > 0 && nj > 0){
        //if(dp[ni][nj] == dp[ni-1][nj-1] + 1){
        //    ans += s[ni-1];
        //    ni--;
        //    nj--;
        //}else{
        //    if(dp[ni][nj] == dp[ni-1][nj]){
        //        ni--;
        //    }else{
        //        nj--;
        //    }
        //}
        if(s[ni-1] == t[nj-1]){
            ans += s[ni-1];
            ni--; nj--;
        }
        else if(dp[ni][nj] == dp[ni-1][nj]){
            ni--;
        }else if(dp[ni][nj] == dp[ni][nj-1]){
            nj--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;


}


Measured memory_bytes: 35584
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

long  long MOD = 1e9 + 7;

int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    vector<long long>X(N);
    for (int i = 0; i < N; i++)cin >> X[i];

    long long ans = 0;
    for (int i = 0; i < N-1; i++) {
        if ((X[i + 1] - X[i])*A < B)ans += (X[i + 1] - X[i])*A;
        else ans += B;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  char a,b,c;
  cin>>a>>b>>c;
  int a_=(a-'0')*100;
  int b_=(b-'0')*10;
  int c_=(c-'0');
  //cout<<a_<<" "<<b_<<" "<<c_<<endl;
  int x=a_+b_+c_;

  if(x%4==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll; typedef long double db;
const int N = 5e5 + 5, M = 1e9 + 7;

vector<int> G[N];
int ans[N];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  memset(ans, -1, sizeof ans);
  priority_queue<pair<int, int>> que;
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int u, w;
    cin >> u >> w;
    ans[u] = w;
    que.push({-w, u});
  }
  while (que.size()) {
    int u;
    tie(ignore, u) = que.top();
    que.pop();
    for (int v : G[u]) {
      if (ans[v] > -1) {
        if (abs(ans[v] - ans[u]) != 1) {
          cout << "No";
          return 0;
        }
      } else {
        ans[v] = ans[u] + 1;
        que.push({-ans[v], v});
      }
    }
  }
  cout << "Yes\n";
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << '\n';
  }
}


Measured memory_bytes: 21408
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9+7LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

ll w[214514];

void solve()
{
    IN(n);
    VIN(ll, v, n-1);
    rep(i, n)
    {
        w[v[i]-1]++;
    }
    rep(i, n)
    {
        cout << w[i] << endl;
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 6368
n, a = map(int, input().split())
x = list(map(lambda x: int(x) - a, input().split()))
d = {0: 1}
for i in x:
    for j, k in list(d.items()):
        d[i + j] = d.get(i + j, 0) + k
ans = d[0] - 1
print(ans)


Measured memory_bytes: 3188
import java.util.*;
public class Main {
	//定義関数から参照できる変数定義はこの辺
	static int N;
	static int wk;
	static int Max=0;
	static int Min=1000000000;
	static int ans=0;

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		for(int i=1;i<=N;i++){
			wk=sc.nextInt();
			Max=Math.max(Max,wk);
			Min=Math.min(Min,wk);
		}

		ans=Max-Min;


		System.out.println(ans);
		//System.out.print(ans);
    }
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;
  cin >> a;
  string s;
  cin >> s;
  if(a >= 3200) cout << s << endl;
  else cout << "red" << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    long long n, k, x;
    vector<long long> v;
    cin >> n >> k;
    while(n--)
    {
        cin >> x;
        v.push_back(x);
    }
    if(v.size()<=k) cout << "0" << endl;
    else
    {
        sort(v.begin(), v.end());
        n=v.size();
        x=0;
        for(long i=0;i<n-k;i++) x+=v[i];
        cout << x << endl;
    }
    return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;

typedef vector< int > Array;
typedef vector< Array > Matrix;

int N, M;
int mass[1010];
int dice[1010];

void solve() {
	int pos = 1;
	
	for_(i,0,M) {
		pos += dice[i];
		pos += mass[pos];
		
		if (pos >= N) {
			cout << i + 1 << endl;
			return;
		}
	}
}

int main() {
	while (cin >> N >> M, N) {
		for_(i,0,N) cin >> mass[i + 1];
		for_(i,0,M) cin >> dice[i];
		solve();
	}
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
#define ll long long
#include <cstdint>

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c <= a + b)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;

int main() {
  int N, K; cin >> N >> K;
  vector<int> v;
  while (N > 0) {
    v.push_back(N % K);
    N /= K;
  }
  cout << v.size() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef vector<vector<int>> graph;


int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    int n; cin>>n; int a[n],b[n];
    for (int i = 0; i < n; i++){
        cin>>a[i];b[i]=a[i];
    }
    sort(a,a+n); int key=0;
    for (int i = 0; i < n; i++){
        if(a[i]!=b[i])key++;
    }
    cout<<((key==2||key==0)?"YES":"NO")<<endl;
}
   

Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int n,k,h=0,ans,a=0;
	scanf("%d",&n);
	scanf("%d",&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&h);
		if(h>=(k-h))
		{
			ans = 2*(k-h);
		}
		else
		{
			ans = 2*h;
		}
		a = a + ans;
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int d[151515],p[151515],c[151515];
double dp[151515],memo[151515];
bool done[151515];
vector<int> g[151515];

double treedp(int v, int pr){
	int i;
	if(d[v]>=0){
		return dp[v];
	}
	d[v] = d[pr]+1;
	p[v] = pr;
	c[v] = 0;
	dp[v] = 0.0;
	for(i=(g[v].l_ength()-1); i>=0; --i){
		if(g[v][i] == pr){
			continue;
		}
		dp[v] += treedp(g[v][i],v);
		++c[v];
	}
	if(!c[v]){
		return dp[v];
	}
	dp[v] /= ((double)(c[v]));
	dp[v] += 1.0;
	return dp[v];
}

double solve(int v){
	if(done[v]){
		return memo[v];
	}
	done[v] = true;
	if(p[v]==0){
		if(c[0]>1){
			memo[v] = ((treedp(0,p[0])-1.0)*((double)(c[0]))-treedp(v,0))/((double)(c[0]-1))+1.0;
		}else{
			memo[v] = 0.0;
		}
		return memo[v];
	}
	memo[v] = ((treedp(p[v],p[p[v]])-1.0)*((double)(c[p[v]]))-treedp(v,p[v])+solve(p[v]))/((double)(c[p[v]]))+1.0;
	return memo[v];
}

int main(void){
	int n,i,v,u;
	fill(d,d+151515,-1);
	fill(done,done+151515,false);
	cin >> n;
	for(i=1; i<n; ++i){
		cin >> v >> u;
		--v; --u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	printf("%.15lf\n",treedp(0,n));
	for(i=1; i<n; ++i){
		printf("%.15lf\n",(treedp(i,p[i])*((double)(g[i].l_ength()-1))+solve(i)+1.0)/((double)(g[i].l_ength())));
	}
	return 0;
}


Measured memory_bytes: 20096
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, K = list(map(int, sys.stdin.readline().split()))
if K == 1:
    print(0)
else:
    print(N - K)


Measured memory_bytes: 23588
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r,d,x,i,c=0;
	cin>>r>>d>>x;
	for(i=1;i<=10;i++)
	{
		c+=(r*x)-d;
		x=c;
		c=0;
		cout<<x<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pi;

//#define cerr if(0) cout	

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string a,b; 
	int x,y;
	cin >> a >> b >> x >> y;
	string t;
	cin >> t;
	if (t==a) --x;
	else --y;
	cout << x << ' ' <<  y;
    return 0;
}


Measured memory_bytes: 256
s=input()
l=len(s)
a=[[0,0,0] for i in range(l)]
num=1
for i in range(l):
    if s[i]=='A':
        a[i][0]=a[i-1][0]+1*num
        a[i][1]=a[i-1][1]
        a[i][2]=a[i-1][2]
    elif s[i]=='B':
        a[i][0]=a[i-1][0]
        a[i][1]=a[i-1][1]+a[i-1][0]
        a[i][2]=a[i-1][2]
    elif s[i]=='C':
        a[i][0]=a[i-1][0]
        a[i][1]=a[i-1][1]
        a[i][2]=a[i-1][2]+a[i-1][1]
    elif s[i]=='?':
        
        a[i][0]=a[i-1][0]*3+1*num
        a[i][1]=a[i-1][1]*3+a[i-1][0]
        a[i][2]=a[i-1][2]*3+a[i-1][1]
        
        num=(num*3)%1000000007


    a[i][0]=a[i][0]%1000000007
    a[i][1]=a[i][1]%1000000007
    a[i][2]=a[i][2]%1000000007
print(a[-1][2])

Measured memory_bytes: 22860