akhauriyash/Code-Regression huggingface dataset:
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
//#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;

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

    ll a,b,c,n,f=0,mini=INF;
    double sum=0,maxi=0;
    string str,sub;
    ll h,w;
    ll m,k;
    cin>>n>>k;
    vector<double> v(n);
    rep(i,n) {
        cin>>v[i];
        v[i]=(v[i]+1)/2;
    }
    rep(i,k) sum+=v[i];
    for(ll i=k;i<n;i++){
        maxi=max(maxi,sum);
        sum-=v[i-k];
        sum+=v[i];
    }
    maxi=max(maxi,sum);
    printf("%.10lf",maxi);
    return 0;
}


Measured memory_bytes: 1792
while True:
    x,n = map(int,input().split())
    c = 0
    if x == n == 0:break
    for i in range(1,x+1):
        for j in range(i+1,x+1):
            for k in range(j+1,x+1):
                if i + j + k == n:
                    c += 1
    print(c)



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

int main() {
  int64_t N,M,K,ans=0;
  cin>>N>>M>>K;
  vector<int64_t> A(N+1);
  vector<int64_t> B(M+1);
  A.at(0)=0;
  B.at(0)=0;
  rep(i,N){
    int64_t a;
    cin>>a;
    A.at(i+1)=a;
    A.at(i+1)+=A.at(i);
  }
  rep(i,M){
    int64_t a;
    cin>>a;
    B.at(i+1)=a;
    B.at(i+1)+=B.at(i);
  }
  int64_t j=M;
  rep(i,N+1){
    if(A.at(i)>K) break;
    int64_t temp=K-A.at(i);
    while(B.at(j)>temp){
      j--;
    }
    ans=max(ans,i+j);
  }
  cout<<ans;
}


Measured memory_bytes: 6424
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n : i32 = s.trim().parse().ok().unwrap();
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let a : i32 = t.trim().parse().ok().unwrap();

    println!("{}", n*n-a);

}


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

int ans = 0;
int N, M;
vector<int> k, p;
vector<vector<int>> s;

set<vector<int>> tmp;

void dfs(vector<int> a, int d) {
	if (d == N) return;
	a[d] = 0;

	int i;

	if (!tmp.count(a)) {
		//	条件を満たすか
		for (i = 0; i < M; ++i) {
			int sum = 0;
			for (int j = 0; j < k[i]; ++j) {
				if (a[s[i][j] - 1]) ++sum;
			}
			if (p[i] != sum % 2) break;
		}
		if (i == M) ++ans;
	}

	tmp.insert(a);

	a[d] = 1;

	//	条件を満たすか

	if (!tmp.count(a)) {
		for (i = 0; i < M; ++i) {
		int sum = 0;
		for (int j = 0; j < k[i]; ++j) {
			if (a[s[i][j] - 1]) ++sum;
		}
		if (p[i] != sum % 2) break;
	}
	if (i == M) ++ans;
	}

	tmp.insert(a);

	a[d] = 0;
	dfs(a, d + 1);
	a[d] = 1;
	dfs(a, d + 1);
}

int main() {
	cin >> N >> M;
	vector<int> a(N);
	k = vector<int>(M);
	s = vector<vector<int>>(M);
	p = vector<int>(M);
	for (int i = 0; i < M; ++i) {
		cin >> k[i];
		s[i] = vector<int>(k[i]);
		for (int j = 0; j < k[i]; ++j) cin >> s[i][j];
	}
	for (int i = 0; i < M; ++i) cin >> p[i];
	dfs(vector<int>(N), 0);
	cout << ans;
}

Measured memory_bytes: 384
/**
 *      purpose : AGC 29 A
 *      author  : kyomukyomupurin
 *      created : 
**/

#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(__null);
    
    string s; cin >> s;

    int sizes = (int) s.size();
    int ss[sizes] = {};  // how many 'B' in left
    if (s[0] == 'B') ss[0] = 1;

    for (int i = 1; i < sizes; ++i){
        if (s[i] == 'B') {
            ss[i] = ss[i - 1] + 1;
        }
        else {
            ss[i] = ss[i - 1];
        }
    }

    int64 cnt = 0;

    for (int i = 0; i < sizes; ++i){
        if (s[i] == 'W'){
            cnt += ss[i];
        }
    }
    /*
    for (int i = 0; i < sizes; ++i){
      print(ss[i]);
    
    }
    */
    print(cnt);
    
    return 0;
}

Measured memory_bytes: 1300
import sys
sys.setrecursionlimit(4100000)

x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())))
q = sorted(list(map(int,input().split())))
r = list(map(int,input().split()))
ans = 0

for k in range(1,x+1):
    r.append(p[-k])
for v in range(1,y+1):
    r.append(q[-v])

rs = sorted(r)

for i in range(1,x+y+1):
    ans += rs[-i]
print(str(ans))

Measured memory_bytes: 23200
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M, R = na()
r = na()
g = [[0] * N for _ in range(N)]
for i in range(M):
    a, b, c = na()
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c

g = np.array(g)
d = shortest_path(g)

R = len(r)
ans = inf
for x in itertools.permutations(r):
    tmp = 0
    for i in range(R-1):
        tmp += d[x[i] - 1][x[i+1] - 1]
    ans = min(ans, tmp)
print(int(ans))






Measured memory_bytes: 38672
#include<iostream>
using namespace std;
int main(){
string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(s==u){
  a--;
  }else if(t==u){
  b--;
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  string s; cin >> s;
  string ans = "Yes";
  for (int i = 1; i <= s.size(); i++) {
    if (i % 2 == 0) {
      if (s[i - 1] == 'R') {
        ans = "No";
        break;
      }
    } else {
      if (s[i - 1] == 'L') {
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# frozen_string_literal: true

h, w, k = gets.split.map(&:to_i)
c = h.times.map { gets.chomp.chars }
def blacks(c)
  count = 0
  c.each do |e|
    count += e.count('#')
  end
  count
end
def ddup(a, b)
  a.each do |e|
    b.push e.dup
  end
  b
end
count = 0
(0..(2**h - 1)).each do |x|
  (0..(2**w - 1)).each do |y|
    cc = []
    ddup(c, cc)
    (0..(h - 1)).each do |i|
      cc[i] = [','] * w if x[i] == 1
      (0..(w - 1)).each do |j|
        cc[i][j] = ',' if y[j] == 1
      end
    end
    count += 1 if blacks(cc) == k
  end
end
puts count


Measured memory_bytes: 14392
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <string.h>
#include <math.h>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef long double ld;
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define ri(a) scanf("%d",&a)
#define rii(a,b) ri(a),ri(b)
#define riii(a,b,c) rii(a,b),ri(c)
#define lri(a) scanf("%lld",&a)
#define lrii(a,b) lri(a),lri(b)
#define pb push_back
#define _1 first
#define _2 second

const int INF = 0x3f3f3f3f;
const ll INFLL = 1e18;
const int MOD = 998244353; //1000000007;
const int alphabet = 26;
const int MAXINT = 2e5+1;

ll n, m, k, f[MAXINT], finv[MAXINT];

ll C( ll a, ll b ){ return f[a]*finv[b]%MOD*finv[a-b]%MOD; }

ll POW( ll p, ll q ){
    ll r = 1;
    while(q){
        if( q%2==1 ) r = (r*p)%MOD;
        p = (p*p)%MOD; q /= 2;
    }
    return r;
}

int main(){
    f[0] = finv[0] = 1;
    FOR(i,1,MAXINT) f[i] = ( f[i-1]*i )%MOD, finv[i] = POW(f[i],MOD-2);

    cin >> n >> m >> k;

    ll ans = 0;
    FOR(i,0,k+1){
        ans += m*C(n-1,i)%MOD*POW(m-1,n-1-i);
        ans %= MOD;
    }
    cout << ans << endl;
}

/*

*/  

Measured memory_bytes: 6760
program sample
    implicit none
  
    integer(8) :: i,j,m,n,a,b,c
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) a,b,c
   if ((a-c)*(b-c)<0)then
    write(*,*)'Yes'
   else
    write(*,*)'No'
   endif
   
        
    stop
end program sample
  



Measured memory_bytes: 2828
N, M, C = [int(item) for item in input().split()]

B = [int(item) for item in input().split()]
A = [[int(item) for item in input().split()] for i in range(N)]

correct = 0

for a in A:
  ok = 0
  for item_a, item_b in zip(a, B):
    ok += item_a * item_b
  ok += C
  if ok > 0:
    correct += 1
    
print(correct)

Measured memory_bytes: 3188
#include<iostream>
#include<float.h>
#include<cfloat>
#include<string>
#include<ctype.h>
#include<algorithm>
#include<errno.h>
#include<cerrno>
#include<assert.h>
#include<cassert> 
#include<map>
#include<memory.h>
#include<cctype>
#include<ctype.h>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<new>
#include<memory>
#include<cmath>
#include<queue>
#include<cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int main()
{int n,k;
 cin>>k>>n;
 int i;
 int j;
 int l;
 for(i=0;i<=k;i++){
 for(j=0;j<=k-i;j++){
 l=k-i-j;
 if(10000*i+5000*j+1000*l==n)
 {
  cout<<i<<" "<<j<<" "<<l<<endl;
  return 0;
  }
  }
 }
 cout<<"-1 -1 -1"<<endl; 
 return 0;
}

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  for (int i = 0; i < N; i++) cin >> x[i];
  vector<int> y(M);
  for (int i = 0; i < M; i++) cin >> y[i];
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  bool can = false;
  if (x[N-1] < y[0]) {
    for (int i = x[N-1]+1; i <= y[0]; i++) {
      if (i > X && i <= Y) {
        can = true;
        break;
      }
    }
  }
  if (can) cout << "No War" << endl;
  else cout << "War" << endl;
}


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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(i, n)  for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

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

    int ans = 0;
    int t = 0;

    int len = s.length();

    for(int i = 0; i < len; ++i) {
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            t++;
            ans = max(ans, t);
        }else {
            t = 0;
        }
    }

    cout << ans;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=599078

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(),(c).end()
int n,k;
vector<int> x1,x2,y1_,y2,z1,z2;
vector<int> fx,fy,fz;
int grid[101][101][101];

int main(){
    cin>>n>>k;
    x1.resize(n);
    x2.resize(n);
    y1_.resize(n);
    y2.resize(n);
    z1.resize(n);
    z2.resize(n);
    fx.resize(n*2);
    fy.resize(n*2);
    fz.resize(n*2);
    rep(i,n){
        cin>>x1[i]>>y1_[i]>>z1[i]>>x2[i]>>y2[i]>>z2[i];
        fx[i*2]=x1[i];
        fx[i*2+1]=x2[i];
        fy[i*2]=y1_[i];
        fy[i*2+1]=y2[i];
        fz[i*2]=z1[i];
        fz[i*2+1]=z2[i];
    }
    sort(all(fx)); fx.erase(unique(all(fx)),fx.end());
    sort(all(fy)); fy.erase(unique(all(fy)),fy.end());
    sort(all(fz)); fz.erase(unique(all(fz)),fz.end());
    memset(grid,0,sizeof(grid));
    rep(i,n){
        int clx=lower_bound(all(fx),x1[i])-fx.begin();
        int crx=lower_bound(all(fx),x2[i])-fx.begin();
        int cly=lower_bound(all(fy),y1_[i])-fy.begin();
        int cry=lower_bound(all(fy),y2[i])-fy.begin();
        int clz=lower_bound(all(fz),z1[i])-fz.begin();
        int crz=lower_bound(all(fz),z2[i])-fz.begin();
        loop(iz,clz,crz)loop(iy,cly,cry)loop(ix,clx,crx){
            grid[iz][iy][ix]++;
        }
    }
    unsigned long long ans=0;
    rep(ix,fx.size())rep(iy,fy.size())rep(iz,fz.size()){
        if(grid[iz][iy][ix]>=k){
            ans+=(unsigned long long)(fx[ix+1]-fx[ix])*(fy[iy+1]-fy[iy])*(fz[iz+1]-fz[iz]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5236
/*
    author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

ll dp[22][(1<<22)];
int solve(vector<vector<int>>& compat, int i, int womenSubset, int N)
{
    if(i == N+1)
    {
        if(womenSubset == 0)
            return 1;
        return 0;
    }

    if(dp[i][womenSubset] != -1)
        return dp[i][womenSubset];
    ll ans = 0;
    for(int women = 0; women < N; women++)
    {
        bool available = (((1<<women)&(womenSubset)) == 0) ? 0 : 1;
        if(available && compat[i][women + 1])
        {
            ans = (ans + solve(compat, i+1, womenSubset ^ (1<<women), N)) % mod;
        }
    }
    return dp[i][womenSubset] = ans;
}

int main() {
   int n;
   cin >> n;
   vector<vector<int>> compat(n+1, vector<int>(n+1));
   memset(dp, -1, sizeof dp);
   for(int i = 1; i<=n; i++)
        for(int j = 1; j <= n; j++)
            cin >> compat[i][j];
   cout<<solve(compat, 1, ((1<<(n)) - 1), n);
   return 0;
}


Measured memory_bytes: 724532
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int M=N;
  int Y=0;
  for(int i=0;i<9;i++){
    if(M/10==0){
      Y=Y+M;
      break;
    }
    else{
      Y=Y+M%10;
      M=M/10;
    }
  }
  if(N%Y==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

using namespace std;
using ll = long long;

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

  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> s[i][j];

  auto bfs = [&](int sx, int sy, int gx, int gy) {
    queue<tuple<int, int, int>> q;
    q.push({sx, sy, 0});
    vector<vector<bool>> visit(h, vector<bool>(w, false));
    vector<pair<int, int>> dirs = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
    while (!q.empty()) {
      auto [x, y, d] = q.front();
      q.pop();
      if (visit[y][x])
        continue;
      visit[y][x] = true;
      if (x == gx && y == gy)
        return d;
      for (auto [dx, dy] : dirs) {
        int nx = dx + x;
        int ny = dy + y;
        if (nx < 0 || nx >= w || ny < 0 || ny >= h)
          continue;
        if (s[ny][nx] == '#')
          continue;
        q.push({nx, ny, d + 1});
      }
    }
    exit(1);
  };

  int ans = 0;
  for (int sx = 0; sx < w; sx++) {
    for (int sy = 0; sy < h; sy++) {
      for (int gx = 0; gx < w; gx++) {
        for (int gy = 0; gy < h; gy++) {
          if (s[sy][sx] == '#' || s[gy][gx] == '#')
            continue;
          ans = max(ans, bfs(sx, sy, gx, gy));
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
		cin.tie(0);							     \
		cout.tie(0);
#define sz(arr) (ll)arr.size()

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
const double PI = 4.0 * atan(1.0);

ll powmod(ll a, ll b, const ll MOD) { ll res = 1; a %= MOD; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % MOD; a = a * a % MOD; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }


//ll f[200005];
//ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }

ll div_floor(ll a, ll b) {
	return a / b - (((a ^ b) < 0) and a % b);
}
ll div_ceil(ll a, ll b) {
	return a / b + (((a ^ b) >= 0) and a % b);
}

int main() {
	//#ifndef ONLINE_JUDGE
	//	(void)freopen("input.txt", "r", stdin);
	//	(void)freopen("output.txt", "w", stdout);
	//#endif // !ONLINE_JUDGE
	fastio;
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	ll lo = -1e18;
	ll hi = 1e18;
	ll ans = 0;
	while (lo <= hi) {
		ll mid = (lo + hi) / 2;
		ll count = 0;
		for (int i = 0; i < N; ++i) {
			if (A[i] == 0) {
				if (mid >= 0)
					count += N - 1;
			}
			else if (A[i] > 0) {
				ll x = div_floor(mid, A[i]);
				ll idx = ll(upper_bound(A.begin(), A.end(), x) - A.begin());
				if (idx > i)
					count += idx - 1;
				else
					count += idx;
			}
			else { // A[i] < 0
				ll x = div_ceil(mid, A[i]);
				ll idx = ll(lower_bound(A.begin(), A.end(), x) - A.begin());
				if (idx > i)
					count += N - idx;
				else
					count += N - idx - 1;

			}
		}
		//assert(count % 2);
		count /= 2;
		if (count >= K)
			ans = mid, hi = mid - 1;
		else
			lo = mid + 1;

	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1792
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int mod=1e9+7;
const int M=202;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int n;
char s[M+1][M+1];
bool vis[M+1];
bool seen[M+1];
bool prv[M+1];
vector<int>adj[M+1];
int flag=0;
vector<int>vec;
int dfs(int u)
{
    vis[u]=1;
    vec.pb(u);
    for(auto v:adj[u])
    {
        if(vis[v]==0)
        {
            dfs(v);
        }
    }
}
int Magic(int st,vector<int>&yo)
{
   int ret=0;
   memset(seen,0,sizeof seen);
   memset(prv,0,sizeof prv);
   vector< vector<int> >boxes;
   vector<int>tmp,nw;
   tmp.pb(st);
   seen[st]=true;
   prv[st]=true;
   boxes.pb(tmp);
   while(1)
   {
       nw.clear();
       for(auto x:boxes.back())
       {
          for(auto y:adj[x])
          {
              if(seen[y]==false)
              {
                  nw.pb(y);
                  seen[y]=true;
              }
              if(prv[y]==true)
              {
                  return -1;
              }
          }
       }
       memset(prv,0,sizeof prv);
       for(auto x:nw)prv[x]=true;
       if(nw.size()==0)break;
       boxes.pb(nw);
   }
   for(auto x:yo)
   {
       if(seen[x]==false)
       {
           return -1;
       }
   }
   return boxes.size();
}
int solve(vector<int>&yo)
{
    int ret=-1;
    for(auto x:yo)
    {
        ret=max(ret,Magic(x,yo));
    }
    if(ret==-1)flag=1;
    return ret;
}
 main()

{
    scanf("%d",&n);
    f(i,0,n-1)
    {
        scanf("%s",s[i]);
    }
    f(i,1,n)
    {
        f(j,1,n)
        {
            if(s[i-1][j-1]=='1')
            {
                adj[i].pb(j);
            }
        }
    }
    int ses=0;
    f(i,1,n)
    {
        if(vis[i]==0)
        {
            vec.clear();
            dfs(i);
            ses+=solve(vec);
        }
    }
    if(flag==1)
    {
       printf("-1\n");
    }
    else
    {
        printf("%d\n",ses);
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      cout << fixed << setprecision(20);
    }
} iosetup;

int main() {
  string s; cin >> s;
  string s1, s2;
  int n = s.size();
  int cnt = 0;
  if (n % 2 == 0) {
    s1 = s.substr(0, n/2);
    s2 = s.substr(n/2, n/2);
    reverse(s2.begin(), s2.end());
    for (int i = 0; i < n / 2; ++i) {
      if (s1[i] != s2[i]) ++cnt;
    }
  } else if (n % 2 == 1) {
    s1 = s.substr(0, (n-1)/2);
    s2 = s.substr((n-1)/2 + 1, (n-1)/2);
    reverse(s2.begin(), s2.end());
    for (int i = 0; i < s1.size(); ++i) {
      if (s1[i] != s2[i]) ++cnt;
    }
  }
  cout << cnt << '\n';
}


Measured memory_bytes: 256
s = input()
t = input()
lent = len(t)
tcount = 0
snow = 0
count = 0
flag = True
if t[0] not in s:
    print(-1)
else:
    snow = s.index(t[0])
    while True:
        tcount += 1
        if tcount == lent:
            break
        if t[tcount] in s[snow+1:]:
            snow = s[snow+1:].index(t[tcount])+snow+1
        elif t[tcount] in s:
            snow = s.index(t[tcount])
            count += 1
        else:
            flag = False
            break
    if flag:
        print(count*len(s) + snow+1)
    else:
        print(-1)

Measured memory_bytes: 3316
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

int se[110],sc[110],e[110],c[110];
int dp[110][1010][2];
int mx[1010];

int main() {
	int limit,n,m,x;
	IL{
		cin>>limit>>n>>m>>x;
		if(limit==0&&n==0&&m==0&&x==0)break;
		string name;
		rep(i,n){
			cin>>name>>se[i]>>sc[i];
		}
		rep(i,m){
			cin>>name>>e[i]>>c[i];
		}
		memset(dp,0,sizeof(dp));
		rep(i,m){
			repn(k,0,i+1){
				repn(j,0,limit){
					if(j<e[i]||k==0||k>1&&dp[k-1][j-e[i]][0]==0)dp[k][j][1]=dp[k][j][0];
					else dp[k][j][1]=max(dp[k][j][0],dp[k-1][j-e[i]][0]+c[i]);
				}
			}
			repn(k,0,i+1)repn(j,0,limit){
				dp[k][j][0]=dp[k][j][1];
				dp[k][j][1]=0;
			}
		}
		memset(mx,0,sizeof(mx));
		repn(i,0,limit){
			repn(j,x,m){
				chmax(mx[i],dp[j][i][0]);
			}
debug<<i<<" "<<mx[i]<<endl;
		}
		int res=0;
		rep(i,n)repn(j,i+1,n-1){
			if(limit<se[i]+se[j])continue;
			chmax(res,mx[limit-se[i]-se[j]]+sc[i]+sc[j]);
		}
		rep(i,n){
			if(limit<se[i])continue;
			chmax(res,mx[limit-se[i]]+sc[i]);
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1860
#include <iostream>

using namespace std;

int main() {
    int n = 0;
    cin >> n;

    int64_t Ln = 2;
    int64_t Ln1 = 1;
    int64_t Ln2 = 0;

    switch (n)
    {
    case 0:
        Ln2 = Ln;
        break;
    case 1:
        Ln2 = Ln1;
        break;
    default:
        break;
    }

    for (int i = 0; i < n - 1; i++) {
        Ln2 = Ln + Ln1;
        Ln = Ln1;
        Ln1 = Ln2;
    }
    cout << Ln2 << endl;
}

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

//    int n=132;
//    bitset<16>binar(n);
//    int a = bitset<16>(binar).to_ulong();
//    cout<<a;

#define int long long
#define pb push_back
#define rep(i,b) for ( int i = 0; i < b; i++)
#define all(c) (c).begin(),(c).end()

using namespace std;

signed main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
  	cin>>a[i];
  }
  map<int,int> m;
  int val =0;
  rep(i,n){
  	val = val+ m[i-a[i]];
  	m[i+a[i]]++;
  }
  cout<<val;
}
        
        
    

    





Measured memory_bytes: 27320
#include <stdio.h>
#include <cmath>
#include <algorithm>

int main(){
	int n,k,S,max,count;

	while(true){
		scanf("%d %d",&n,&k);
		if(n == 0 && k == 0)break;
		max = -1000000001;
		S = 0;
		count = 0;
		int array[n];
		for(int i = 0; i < n; i++){
			scanf("%d",&array[i]);
			count++;
			if(count == k){
				S += array[i];
				max = (max >= S)?max:S;
			}else if(count >  k){
				S -= array[i-k];
				S += array[i];
				max = (max >= S)?max:S;
			}else{
				S += array[i];
			}
		}
		printf("%d\n",max);
	}

	return 0;
}

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

class Main{

  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(br.readLine());
    int[] a = new int[N];

    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(br.readLine());
    }

    int min = a[0];
    int max = a[1]-a[0];

    for(int i = 0; i < N-1; i++){
      if(i == N - 1){
        min = minv(min, a[i-1]);
        max = maxv(max, a[i] - min);
      }else{
        min =  minv(min, a[i]);
        max = maxv(max, a[i+1] - min);
      }
    }


    System.out.println(max);
  }

  public static int minv(int min, int a){
    if(min >= a){
      return a;
    }else{
      return min;
    }
  }

  public static int maxv(int max, int a){
    if(max <= a)return a;
    else return max;
  }

}

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


typedef struct{
	int distance;
	int next_n;
	int *next;
} GRAPH_T;


int main()
{
	int vertex_n;
	GRAPH_T *graph;
	int ring_queue[100];
	int front, rear;
	int id, next_id , n;
	int i, j;


	scanf("%d", &vertex_n);

	graph = (GRAPH_T *)malloc(sizeof(GRAPH_T) *(vertex_n + 1));

	for(i = 0; i < vertex_n; i++){
		scanf("%d %d", &id, &n);
		graph[i + 1].distance = -1;
		graph[i + 1].next_n = n;

		if(n != 0){
			graph[i + 1].next = (int *)malloc(sizeof(int) * n);
			for(j = 0; j < n; j++){
				scanf("%d", &id);
				graph[i + 1].next[j] = id;
			}
		}
	}

	// test
/*	printf("\n");
	for(i = 0; i < vertex_n; i++){
		printf("%d %d", graph[i + 1].distance, graph[i + 1].next_n);
		for(j = 0; j < graph[i + 1].next_n; j++)
			printf(" %d", graph[i + 1].next[j]);
		printf("\n");
	}
*/

	// BFS
	front = rear = 0;
	graph[1].distance = 0;
	ring_queue[rear++] = 1;
	while(front != rear){
		id = ring_queue[(front++) % 100];
		n = graph[id].next_n;

		for(i = 0; i < n; i++){
			next_id = graph[id].next[i];
			if(graph[next_id].distance == -1 || graph[next_id].distance > graph[id].distance + 1){
				graph[next_id].distance = graph[id].distance + 1;
				ring_queue[(rear++) % 100] = graph[id].next[i];
			}
		}
	}

	for(i = 0; i < vertex_n; i++)
		printf("%d %d\n", i + 1, graph[i + 1].distance);

	return 0;
}


Measured memory_bytes: 2080
<?php

fscanf(STDIN, "%d", $n);

function dfs($x) {
    global $n;

    if ($x > $n) {
        return 0;
    }

    // check
    $x_arr = array_unique(str_split($x));
    sort($x_arr);
    $count = $x_arr == [3, 5, 7] ? 1 : 0;

    $count += dfs(10 * $x + 3);
    $count += dfs(10 * $x + 5);
    $count += dfs(10 * $x + 7);

    return $count;
}

echo dfs(0);


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
bool sma(string a, string b) {
  int i = 0;
  while(a[i] == b[i] && i < a.size()) i ++;
  if (i == a.size() - 1) return true;
  return (int)a[i] < (int)b[i];
}
int main () {
  string S, T;
  cin >> S >> T;
  string ans = "";
  for (int i = 0; i < 50; i ++) ans += "z";
  string def = ans;
  int N = S.size();
  int n = T.size();
  for (int i = 0; i <= N - n; i ++) {
    string a = S;
    bool ok = true;
    for (int j = i; j < i + n; j ++) {
      if (a[j] != T[j - i] && a[j] != '?') ok = false;
      else if (a[j] == '?') a[j] = T[j - i];
    }
    if (!ok) continue;
    for (int j = 0; j < N; j ++) {
      if (a[j] == '?') a[j] = 'a';
    }
    if (sma(a, ans)) ans = a;
    //cout << a << ' ' << ans << endl;
  }
  if (ans == def) cout << "UNRESTORABLE" << endl;
  else cout << ans << endl;
  //if (sma("ku", "kuma")) cout << "OK";
  //if (sma("ma", "ku")) cout << "NG";
}




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

int main() {
	int N;
	int K;
	int obj = 1;
	cin >> N >> K;
	
	for (int i = 0; i < N; i++) {
		if ((obj+K) <= (2*obj)) {
			obj += K;
		} else {
			obj *= 2;
		}
	}
	cout << obj << endl;
	
}


Measured memory_bytes: 3576
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	ll N,D;
	cin >> N >> D;
	vector<LP> point(N);	
	rep(i,N)cin >> point[i].first >> point[i].second;
	ll ans = 0;
	ll to = D*D;
	rep(i,N){
		ll dif = point[i].first*point[i].first + point[i].second * point[i].second;
		if(dif <= to)++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6428
import java.util.*;
import java.io.*;

import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	
	int n;
	int[] cost, dp;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		cost = new int[n];
		for (int i=0;i<n;i++) cost[i] = sc.nextInt();
		
		System.out.println(solve());
//		debug(dp);
	}
	
	int solve() {
		dp = new int[n]; fill(dp, INF); dp[0] = 0;
		PriorityQueue<P> q = new PriorityQueue<P>();
		q.add(new P(0, 0));
		
		for (;;) {
			P cur = q.remove();
			if (cur.p == n-1) return cur.c;
			
			if (cost[cur.p] != 0) {
				if (dp[cur.p + cost[cur.p]] > cur.c) {
					dp[cur.p + cost[cur.p]] = cur.c;
					q.add(new P(cur.p + cost[cur.p], cur.c));
				}
			}
			else {
				for (int i=1;i<=6;i++) {
					int next = min(n-1, cur.p + i);
					if (dp[next] > cur.c + 1) {
						dp[next] = cur.c + 1;
						q.add(new P(next, cur.c + 1));
					}
				}
			}
		}
	}
	
	class P implements Comparable<P>{
		int p, c;
		P(int p, int c) {
			this.p = p;
			this.c = c;
		}
		@Override
		public int compareTo(P o) {
			// TODO ティツ?ェテ・ツ仰陛ァツ板淌ヲツ按静」ツ?陛」ツつ古」ツ?淌」ツδ。テ」ツつステ」ツδε」ツδ嘉」ツδサテ」ツつケテ」ツつソテ」ツδ?
			if (c != o.c)
				return c - o.c;
			return o.p - p;
		}
	}
	

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 64280
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    double x[3],y[3],xp,yp;
    while (cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>xp>>yp) {
        double c[3];
        c[0] = (x[1]-x[0]) * (yp-y[1]) - (y[1]-y[0]) * (xp-x[1]);
        c[1] = (x[2]-x[1]) * (yp-y[2]) - (y[2]-y[1]) * (xp-x[2]);
        c[2] = (x[0]-x[2]) * (yp-y[0]) - (y[0]-y[2]) * (xp-x[0]);
        
        if ((c[0]>0 && c[1]>0 && c[2]>0)||(c[0]<0 && c[1]<0 && c[2]<0)) {
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    
}

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

int main() {
  int N,M;
  cin >> N;
  vector<string> s(N);
  
  for(int i = 0; i < s.size(); i++){
    cin >> s.at(i);
  }
  
  cin >> M;
  vector<string> t(M);
  for(int i = 0; i < t.size(); i++){
    cin >> t.at(i);
  }
  
  vector<int> cnt(N);
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < s.size(); j++){      
      if(s.at(i) == s.at(j)){
        cnt.at(i)++;
      }
    }
    
    for(int j = 0; j < t.size(); j++){
      if(s.at(i) == t.at(j)){
        cnt.at(i)--;
      }
    }
  }
  
  int ans = cnt.at(0);
  for(int i = 1; i < cnt.size(); i++){
    if(ans < cnt.at(i)){
      ans = cnt.at(i);
    }
  }
  
  if(ans < 0){
    cout << 0 << endl;
  }else{
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll tyo=(ll)1e12*2;
using namespace std;

int main(){
  string S,t="";
  ll cnt=0,n=0;
  cin>>S;
  while(n<S.size()){
    string A;
    A=S.substr(n,1);
    if(t!=A){
      n++;
    }else{
      A=S.substr(n,2);
      if(A.size()!=2) cnt--;
      n+=2;
    }
    cnt++;
    t=A;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	lnh := len([]rune(s))
	t := make(map[string]string, lnh)
	for _, v := range []rune(s) {
		if _, ok := t[string(v)]; !ok {
			t[string(v)] = "うんこ"
		}
	}
	if len(s) == len(t) {
		fmt.Println("yes")
	} else {
		fmt.Println("no")
	}
}


Measured memory_bytes: 512
/*
 * FileName:     A
 * CreatedDate:  2020-05-03 20:57:18 +0900
 * LastModified: 2020-05-03 21:01:56 +0900
 */

#include <stdio.h>
#include <string.h>
int main(void){
    char s[4];
    scanf("%s",s);
    if(strcmp(s,"ABC")==0){
        printf("ARC\n");
        return 0;
    }
    printf("ABC\n");
    return 0;
}


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

#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i = (int)(begin), i##_end = (int)(end); i < i##_end; ++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x

int main(void){
	char S[201];
	cin >> S;

	while(1){
		S[strlen(S) - 1] = '\0';
		if(strlen(S) % 2 == 0 && strncmp(S, S + strlen(S) / 2, strlen(S) / 2) == 0){
			printf("%d\n", strlen(S));
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll n;cin >> n;
	VLL a(n);
	ll ans = 0;
	ll max = 1;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		ans += a[i]-1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, cnt[202020];

void solve() {
}

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

    cin >> N;
    FOR (N - 1) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    FOR (i, 1, N + 1)
        cout << cnt[i] << endl;

    solve();
    return 0;
}


Measured memory_bytes: 5152
a,b = map(int,input().split())
n = [str(i) for i in input()]

flg ="Yes"

if n[a] != "-":
    flg ="No"

ls = [str(x) for x in range(10)]
s = set(ls)

if  (set(n[0:a]) | set(n[a+1:a+b+2])) <=s:
    pass
else:
    flg = "No"

print(flg)


Measured memory_bytes: 38384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt(), m = in.nextInt();

    boolean[] ac = new boolean[n];
    int[] wa = new int[n];

    for (int i = 0; i < m; i++) {
      int p = in.nextInt();
      String s = in.next();

      if (s.equals("AC")) {
        ac[p - 1] = true;
      } else if (!ac[p - 1]) {
        wa[p - 1]++;
      }
    }

    int correct = 0, penalty = 0;

    for (int i = 1; i <= n; i++) {
      if (ac[i - 1]) {
        correct++;
        penalty += wa[i - 1];
      }
    }

    System.out.println(correct + " " + penalty);

    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }

  static void print(int[] arr) {
    Arrays.stream(arr).forEach(i -> System.out.print(i + " "));
    System.out.println();
  }

  public static int[] mergeSort(int[] a) {
    if (a.length <= 1)
      return a;

    int mid = a.length / 2;
    int[] left = new int[mid];
    int[] right = new int[a.length - mid];

    for (int i = 0; i < mid; ++i)
      left[i] = a[i];

    for (int i = mid; i < a.length; ++i)
      right[i - mid] = a[i];

    return merge(mergeSort(left), mergeSort(right));
  }

  public static int[] merge(int[] l, int[] r) {
    int[] merged = new int[l.length + r.length];

    int i = 0, j = 0, k = 0;
    while (i < l.length && j < r.length) {
      if (l[i] <= r[j])
        merged[k++] = l[i++];
      else
        merged[k++] = r[j++];
    }

    while (i < l.length)
      merged[k++] = l[i++];
    while (j < r.length)
      merged[k++] = r[j++];

    return merged;
  }

}



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

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N), B(N);
    for (int i=0; i<N; i++) cin >> A[i];
    int S = accumulate(A.begin(), A.end(), 0);
    vector<int> divisors;
    for (int i=1; i*i<=S; i++) {
        if (S % i == 0) {
            divisors.push_back(i);
            if (i*i != S) divisors.push_back(S / i);
        }
    }
    sort(divisors.begin(), divisors.end(), greater<int>());
    for (int d: divisors) {
        for (int i=0; i<N; i++) B[i] = A[i] % d;
        sort(B.begin(), B.end());
        int move = N - accumulate(B.begin(), B.end(), 0) / d; 
        if (accumulate(B.begin(), B.begin() + move, 0) <= K) {
            cout << d << endl;
            return 0;
        }
    }
}

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

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
//~ const int mod = (int)1e9 + 7;
const int mod = 998244353;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

string conv(int a){stringstream ss;ss << a;string str = ss.str();return str;}
string conv(char a){stringstream ss;ss << a;string str = ss.str();return str;}
int conv(string a){stringstream geek(a); int x = 0; geek >> x;   return x;}


vector< int > g[10010];
bool vis[10010];
int c[10010];
int ans[10010];
int n;
void add(int i, int j){
	g[i].pb(j);
	g[j].pb(i);
}

void bfs(int source){
	clr(vis,false);
	int k = n;
	queue<int> q;
	q.push(source);
	while(!q.empty()){
		int x = q.front();
		q.pop();
		vis[x] = true;
		ans[x] = c[k];
		k--;
		rep(i,0,sz(g[x])-1){
			if(!vis[g[x][i]]){
				q.push(g[x][i]);
			}
		}
		
	}
	
}

int main(void) 
{	
	cin>>n;
	int a , b;
	rep(i,1,n-1){
		cin>> a >> b;
		add(a,b);
	}
	rep(i,1,n)
		cin>>c[i];
	
	sort(c+1,c+1+n);
	
	bfs(1);
	
	int sum = 0;
	rep(i,1,n-1)
		sum += c[i];
	
	cout<<sum<<endl;
	
	rep(i,1,n){
		cout<<ans[i]<<" ";
	}
	
	return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());

    int medi = n / 2 - 1;
    int ans = 0;
    if (d[medi] == d[medi + 1]) {
        ans = 0;
    } else {
        ans = d[medi + 1] - d[medi];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

		String str = sc.next();

		int dp[] = new int[str.length() + 1];
		dp[1] = 1;
		if(str.length() >= 2){
			if(str.charAt(0) == str.charAt(1)){
				dp[2] = 1;
			}
			else {
				dp[2] = 2;
			}
		}

		for(int i = 3; i <= str.length(); i++){
			if(str.charAt(i - 1) == str.charAt(i - 2)){
				dp[i] = dp[i - 3] + 2;
			}
			else {
				dp[i] = dp[i - 1] + 1;
			}

//			System.out.println(dp[i]);
		}

		System.out.println(dp[str.length()]);
	}

}


Measured memory_bytes: 32140
#include <iostream>
#include <vector>
#include <limits>
 
using namespace std;
 
class Die {
  public:
  int f1, f2, f3, f4, f5, f6;
    Die(int f1, int f2, int f3, int f4, int f5, int f6)
      :f1{f1}, f2{f2}, f3{f3}, f4{f4}, f5{f5}, f6{f6} {}
  Die N() {  // "North roll"
    return Die(f2, f6, f3, f4, f1 ,f5);
  } 
  Die E() {  // "East roll"
    return Die(f4, f2, f1, f6, f5, f3);
  } 
  Die rotCW() { // Clockwise rotation in place
                 // while preserving top and bottom
    return Die(f1, f3, f5, f2, f4, f6);
  }

};

bool operator==(Die d, Die d2) {
  return (d2.f1 == d.f1 and 
      d2.f2 == d.f2 and d2.f4 == d.f4 and d2.f5 == d.f5 and d2.f6 == d.f6
      and d.f3 == d2.f3);
}

bool eq_under_rotation(Die d, Die d2) {
  // brute force: try all configurations
  for (int i = 0; i < 6; ++i) {
    Die dd = d;
    for (int j = 0; j < 6; ++j) {
      Die ddd = dd;
      for (int k = 0; k < 6; ++k) {
        if (ddd == d2) {
          return true;
        }
        ddd = ddd.rotCW();
      }
      dd = dd.E();
    }
    d = d.N();
  }
  return false;
}

// post: prints "Yes" if all given dice are different
//       "No" if there are two dice equal under rotation
int main()
{
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  vector<Die> dice;
  int f1, f2, f3, f4, f5, f6;
  while (cin >> f1 >> f2 >> f3 >> f4 >> f5 >> f6) {
    Die din = Die(f1, f2, f3, f4, f5, f6);
    for (Die d : dice) {
      if (eq_under_rotation(d, din)) {
        cout << "No\n";
        return 0;
      }
    }
    dice.push_back(din);
  }
  cout << "Yes\n";
}


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

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

	int n;
	cin>>n;
	vector<int> dp(3,0);
	for(int k = 0; k < n; k++)
	{
		vector<int> new_dp(3,0);
		vector<int> c(3);
		for(int i = 0; i < 3; i++)
		{
			cin>>c[i];
		}
		for(int i = 0; i < 3; i++)
		{
			for(int j = 0; j < 3; j++)
			{
				if(i != j && (new_dp[j] < dp[i] + c[j]))
				{
					new_dp[j] = dp[i] + c[j];
				}
			}
		}
		dp = new_dp;
	}
	cout<<max(dp[0],max(dp[1],dp[2]))<<endl;
	return 0;
}

Measured memory_bytes: 256