akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n, to[maxn], cnt[maxn];
std::set<int> s[maxn];
std::queue<int> q;
int sg[maxn];
inline void check(int x, int type) {
	static int cnt[maxn];
	static std::set<int> s[maxn];
	rep(i, 1, n) cnt[i] = ::cnt[i], s[i] = ::s[i];
	q.push(to[x]), s[to[x]].insert(sg[x]), cnt[x] = 0;
	for(;!q.empty();) {
		int x = q.front(); q.pop(); sg[x] = 0;
		for(;s[x].count(sg[x]);) ++ sg[x];
		s[to[x]].insert(sg[x]);
		if(--cnt[to[x]] == 0) q.push(to[x]);
	}
	if(type ? !s[x].count(sg[x]) : s[x].count(sg[x] - 1)) {
		cout << "POSSIBLE" << '\n';
		exit(0);
	}
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 1, n) {
		cin >> to[i];
		++ cnt[to[i]];
	}
	rep(i, 1, n) if(!cnt[i]) {
		q.push(i);
	}
	for(;!q.empty();) {
		int x = q.front(); q.pop();
		for(;s[x].count(sg[x]);) ++ sg[x];
		s[to[x]].insert(sg[x]);
		if(--cnt[to[x]] == 0) q.push(to[x]);
	}
	rep(i, 1, n) if(cnt[i]) {
		for(;s[i].count(sg[i]);) ++ sg[i];
		check(i, 1);
		++ sg[i];
		check(i, 0);
		break;
	}
	cout << "IMPOSSIBLE" << '\n';
}


Measured memory_bytes: 39552
from sys import stdin
import bisect

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

while True:
    if len(li) < 2:
        break
    for i in range(1,len(li)):
        li[i] %= li[0]
    li.sort()
    li = li[bisect.bisect_right(li,0):]
print(li[0])

Measured memory_bytes: 14484
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 1000119
int num[maxn],tree[maxn],booll[maxn],nnn[maxn],N,ww;;
//num数组保存原数列，tree树状数组，nnn保存结果
struct tt
{
    int l,r;//左右边界
    int pos;//原位置（因为我们要离线排序后处理）
};
tt ask[maxn];
bool cmp(tt x,tt y)
{ 
    return x.r<y.r;
    //快排大法好，没有什么是快排解决不来哦
    //实在不行就加上一个cmp
}
int lowbit(int n) 
{
    return n&(-n);
    //树状数组核心操作×1
}
void add(int n,int now)
{
    while(n<=N)
    {
        tree[n]+=now;
        n+=lowbit(n);
    }
    //树状数组核心操作×2-->更新操作
}
int sum(int n)
{
    int ans=0;
    while(n!=0)
    {
        ans+=tree[n];
        n-=lowbit(n);
    }
    return ans;
    //树状数组核心操作×3———>查询操作
}
int main()
{
        scanf("%d",&N);scanf("%d",&ww);
        for(int i=1;i<=N;i++)
            scanf("%d",&num[i]);
        
        for(int i=1;i<=ww;i++)
        {
            scanf("%d%d",&ask[i].l,&ask[i].r);
            ask[i].pos=i; //存储初始位置
        }
        sort(ask+1,ask+1+ww,cmp);//按r排序
        int next=1;
        for(int i=1;i<=ww;i++)
        {
            for(int j=next;j<=ask[i].r;j++)
            {
                if(booll[num[j]]) 
                    add(booll[num[j]],-1);
                 //之前打过标记，在之前的位置加上-1，保证无重复
                add(j,1);
                booll[num[j]]=j;
            }
            next=ask[i].r+1;
            //更新下一次查询的位置
            nnn[ask[i].pos]=sum(ask[i].r)-sum(ask[i].l-1);
            //按询问编号存储每组询问的结果
        }
    for(int i=1;i<=ww;i++)
      printf("%d\n",nnn[i]);
    return  0;
}

Measured memory_bytes: 17436
#include "bits/stdc++.h"
using namespace std;
int main(){
	int r, D, x;
	cin >> r >> D >> x;
	vector<int> a(11);
	a[0] =x;
	for(int x = 1; x<=10; x++){
		a[x] = r*a[x-1] - D;
	}
	sort(a.begin(), a.end());
	for(int x= 1; x<=10; x++){
		cout << a[x] << endl;
	}
}


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

#define MAX_N (10)
#define MAX_M (10)

int main(int argc, char *argv[]) {
  // read inputs
  int N, M, ks[MAX_M], xss[MAX_M][MAX_N], ps[MAX_M];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d", &ks[i]);
    for (int l = 0; l < ks[i]; l++) {
      scanf("%d", &xss[i][l]);
      xss[i][l]--;  // NOTE : modified input
    }
  }
  for (int i = 0; i < M; i++) {
    scanf("%d", &ps[i]);
  }

  // search all
  int ans = 0;
  for (int S = 0; S < (1 << N); S++) {
    int is_all_on = 1;
    for (int i = 0; i < M; i++) {
      // check if light bulb i will light up
      const int k = ks[i], p = ps[i];
      int num = 0;
      for (int l = 0; l < k; l++) {
        const int x = xss[i][l];
        if ((S & (1 << x)) != 0) {
          num++;
        }
      }
      if (num % 2 != p) {
        is_all_on = 0;
        break;
      }
    }
    if (is_all_on) {
      ans++;
    }
  }
  printf("%d\n", ans);
  
  return 0;
}


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

struct Weighted_Union_Find {
    std::vector<int> par;
    std::vector<int> rank;
    std::vector<long long> wdiff;
    //初期化
    void init( int n ) {
        par.resize( n );
        rank.resize( n );
        wdiff.resize( n );
        for ( int i = 0; i < n; ++i ) {
            par[ i ] = i;
            rank[ i ] = 0;
            wdiff[ i ] = 0;
        }
    }
    
    //木の根を探す
    int find( int s ) {
        if ( par[ s ] == s ) {
            return s;
        }
        int r = find(par[ s ]);
        wdiff[s] += wdiff[par[s]];
        return par[s] = r;
    }
    
    long long weight(int x) {
        find(x); // 経路圧縮
        return wdiff[x];
    }

    long long diff(int x, int y) {
        return weight(y) - weight(x);
    }

    //結合
    bool unite( int x, int y, long long w ) {
        w += weight(x);
        w -= weight(y);
        x = find( x );
        y = find( y );
        if ( x == y ) {
            return false;
        }
        if ( rank[ x ] < rank[ y ] ) {
            std::swap(x, y);
            w = -w;
        }
        if ( rank[x] == rank[y] ) ++rank[x];
        par[y] = x;
        wdiff[y] = w;
        return true;
    }
    
    //二つの数の根が同じかどうか
    bool same( int x, int y ) {
        return find( x ) == find( y );
    }
    
    //サイズを返す
    unsigned int size() {
        return par.size();
    }
};

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    Weighted_Union_Find wuf;
    wuf.init(n);
    while(q--){
        int query;
        cin >> query;
        if(query){
            int x, y;
            cin >> x >> y;
            if(!wuf.same(x, y)){
                cout << "?\n";
            }else{
                cout << wuf.diff(x, y) << "\n";
            }
        }else{
            int x, y, z;
            cin >> x >> y >> z;
            wuf.unite(x, y, z);
        }
    }
}


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

using namespace std;
using ll = long long;

template <typename T, typename = typename std::enable_if<
                          std::is_integral<T>::value, T>::type>
vector<pair<T, int>> prime_factorize(T n) {
  vector<pair<T, int>> cnts{};
  if (n == 1) {
    return cnts;
  }

  T a = 2;
  while (n >= a * a) {
    int cnt = 0;
    while (n % a == 0) {
      n /= a;
      cnt++;
    }

    if (cnt > 0) {
      cnts.push_back({a, cnt});
    }

    a++;
  }

  if (n != 1) {
    cnts.push_back({n, 1});
  }

  return cnts;
}

int main(int argc, const char *argv[]) {
  ll n;
  cin >> n;

  auto f = prime_factorize(n);
  ll ans = 0;
  for (auto &p : f) {
    ll sum = 0, cur = 1, cnt = 0;
    while (sum < p.second) {
      sum += cur++;
      cnt++;
    }

    if (sum > p.second) {
      sum--;
      cnt--;
    }

    ans += cnt;
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3604
import scala.io.StdIn.readLine
object Main {
    def main(args: Array[String]) {
        val input = readLine().split(" ").map(_.toInt)
        rectangle(input(0), input(1))
    }
    def rectangle(a: Int, b: Int) {
                println(a * b + " " + (2 * a + 2 * b))
    }
}


Measured memory_bytes: 43628
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

# 累積和
cumsum = [0] * (N + 1)
for i in range(N):
    if i + 1 < N and S[i] == "A" and S[i + 1] == "C":
        cumsum[i + 1] = cumsum[i] + 1
    else:
        cumsum[i + 1] = cumsum[i]

# クエリ
for q in LR:
    l = q[0] - 1
    r = q[1] - 1
    print(cumsum[r] - cumsum[l])


Measured memory_bytes: 29680
n, p = map(int, input().split())
s = input()
ans = 0
if p == 2 or p == 5:
    if p == 2:
        ok = [0, 2, 4, 6, 8]
    else:
        ok = [0, 5]
    for i, c in enumerate(s):
        if int(c) in ok:
            ans += i+1
    print(ans)
    exit()

s = s[::-1]
cum = [0] * (n+1)
keta = 1
for i, c in enumerate(s):
    cum[i+1] = cum[i] + keta * int(c)
    cum[i+1] %= p
    keta = (keta * 10) % p
counter = [0] * p
for c in cum:
    counter[c] += 1
for c in counter:
    ans += c * (c-1)//2
print(ans)

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

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rep(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long int ll;
using graph = vector<vector<int>>;
using edgedp = vector<vector<pair<int,ll>>>;
constexpr int INF=1000000;
//constexpr int MOD=998244353;
constexpr int MOD=1e9+7;

int calc_pw(ll n, ll p){
    if(n/p==0){
        return 0;
    }else{
        return calc_pw(n/p,p)+1;
    }
}


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a/d > c/b){
        cout << "Yes" << "\n";
    }else if(a/d==c/b){
        if(a%d==0 && c%b!=0){
            cout << "No" << "\n";                
        }else{
            cout << "Yes" << "\n";
        }
    }else{
        if((a/d+1)==c/b){
                if(a%d!=0 && c%b==0){
                    cout << "Yes" << "\n";
                }else{
                    cout << "No" << "\n";
                }
            }else{
                cout << "No" << "\n";
        }
    }
}   




Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
long long int sum_1(long long int *p,int i);
long long int sum_2(long long int *q,int i,int n);
int main(void)
{
 long long int x=0,y=0,min,Lmin,j;
 int i,n;
 scanf("%d",&n);
 long long int a[n],f,h;
 for(i=0;i<n;i++)
 {
  scanf("%lld",&a[i]);
  if(i<n-1) x+=a[i];
 }
  y=a[n-1];
  min=llabs(x-y);
 for(i=n-2;i>0;i--)
 {
  x-=a[i];
  y+=a[i];
  Lmin=llabs(x-y);
  if(Lmin<min) min=Lmin;
 }
   printf("%lld",min);
}

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

int main() {
	long long n, a = 99999, b, c;
	cin >> n;
	for(int i = 1; i < n; i++){
		int j = n - i;
		int k = i;
		b = 0;
		while(j != 	0){
			b += j % 10;
			j = j / 10;
		}
		while(k != 0){
			b += k % 10;
			k = k / 10;
		}
		
		if(a > b){
			a = b;
		}
	}
	
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n,m;
    cin>>n>>m;
    vector<ll> v(n);
    vector<ll> cnt(m,0),cnt2(m,0);
    map<ll,ll> mp;
    rep(i,n){
        cin>>v[i];
        mp[v[i]]++;
        cnt[v[i]%m]++;
    }
    
    for(auto x:mp){
        cnt2[x.first%m]+=x.second/2;
    }

    ll ans=0;
    for(int i=1;i<m;i++){
        if(i*2!=m){
            ll tmp=min(cnt[i],cnt[m-i]);
            ans+=tmp;
            cnt[i]-=tmp;
            cnt[m-i]-=tmp;
        }
        else{
            ans+=cnt[i]/2;
            cnt[i]%=2;
        }
    }
    ans+=cnt[0]/2;
    cnt[0]%=2;

    for(int i=0;i<m;i++){
        ans+=min(cnt2[i]*2,cnt[i])/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 ll N; cin >> N;
  for(ll x = 1; x<= 3500; x++){
    for(ll y = 1; y <= 3500; y++){
      ll a= N*x*y; ll b = 4*x*y - N*(x+y);
      if( b>0 && a%b == 0){ cout << x << " " << y << " " << a/b << endl;return 0;}
    }
  }
  
  return 0;}

Measured memory_bytes: 256
from collections import deque

n = int(input())
edge = [[] for i in range(n)]

for i in range(n):
    S = input()
    for j in range(n):
        if S[j] == '1':
            edge[i].append(j)


def is_bipartite(num_of_node, edge):
    colors = [-1]*num_of_node
    start = 0
    todo = deque([[start, 0]])

    while todo:
        node, color = todo.popleft()
        new_color = 1 - color

        for new_node in edge[node]:
            if colors[new_node] == -1:
                colors[new_node] = new_color
                todo.append([new_node, new_color])

            elif colors[new_node] == color:
                return False

            else:
                continue
    return True


def get_max_distance(start, num_of_node, edge):
    distances = [-1] * num_of_node
    distances[start] = 1
    todo = deque([[start, 1]])

    while todo:
        node, dis = todo.popleft()

        for new_node in edge[node]:
            if distances[new_node] == -1:
                distances[new_node] = dis + 1
                todo.append([new_node, dis+1])
            else:
                continue

    return max(distances)


if is_bipartite(n, edge):
    print(max([get_max_distance(x, n, edge) for x in range(n)]))
else:
    print(-1)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,ans=0;
  string S;
  cin >> N >> S;
  vector<vector<ll>> A(3,vector<ll>(1000,0));
  rep(i,N){
    for(ll j=2;j>=0;j--){
      if(j==0){
        A.at(j).at(S.at(i)-'0')=1;
      }else{
        rep(k,(ll)pow(10,j)){
          if(A.at(j-1).at(k)==1){
            A.at(j).at(10*k+S.at(i)-'0')=1;
          }
        }
      }
    }
  }
  rep(i,1000){
    if(A.at(2).at(i)==1){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3832
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  1000005
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,a;
    vector<ll>v;
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>a;
        v.pb(a);
    }
    reverse(all(v));
    ll ans=2,ans1=2,temp;
    for(ll i=0;i<n;i++){
        temp=ans/v[i];
        if(ans%v[i])
            temp++;
        ans=v[i]*temp;
        temp=ans1/v[i];
        temp++;
        ans1=(v[i]*temp)-1;
    }
    temp=ans;
    reverse(all(v));
    for(ll i=0;i<n;i++){
        temp-=(temp%v[i]);
    }
    if(temp!=2){
        cout<<-1;
        return 0;
    }
    cout<<ans<<" "<<ans1;
    //cout<<ans<<" "<<ans+v[0]-1;



    return 0;
}



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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0, a; i < n; ++i) {
    cin >> a;
    mp[a]++;
  }
  bool ok = false;
  int m = (int)mp.size();
  if (m == 1) {
    if (mp[0] == n) ok = true;
  } else if (m == 2) {
    debug(mp, next(mp.begin())->second);
    if (n % 3 == 0 && mp[0] == n / 3 && next(mp.begin())->second == n - n / 3)
      ok = true;
  } else if (m == 3) {
    if (n % 3 == 0) {
      int x = 0;
      bool ok1 = true;
      for (auto&& [num, cnt] : mp) {
        if (cnt != n / 3) ok1 = false;
        x ^= num;
      }
      if (ok1 && x == 0) ok = true;
    }
  }
  if (ok) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}

Measured memory_bytes: 7160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

class UnionFind {
public:
    vector<int> par;
    int num;

    UnionFind(int n) : par(n, -1), num(n) {};

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int size(int x) {
        return -par[root(x)];
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        num--;
        return true;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (!uf.same(a, b)) uf.unite(a, b);
    }
    int ans = 0;
    rep(i, 0, n) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4056
def dfs(v, cnt):
    D[v] = cnt
    cnt += 1
    for c in edge[v]:
        if D[c] == -1:
            cnt = dfs(c, cnt)
    F[v] = cnt
    cnt += 1
    return cnt


V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
    u, _, *v = map(lambda x: int(x)-1, input().split())
    edge[u] = sorted(v)
D, F = [-1] * V, [-1] * V
c = 1
for i in range(V):
    if D[i] == -1:
        c = dfs(i, c)
for i, (d, f) in enumerate(zip(D, F)):
    print(i+1, d, f)

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

int main() {
    
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    for(int i=0;i<N;i++){
        int v =A.at(i);
        for(int j=i-1;j>=0;j--){
            if(v<A.at(j)){
                A.at(j+1)=A.at(j);
            }
            else {A.at(j+1)=v;
                break;
            }
            if(j==0) A.at(0)=v;
                
            }
        
        for(int j=0;j<N;j++){
            cout<<A.at(j);
            if(j<N-1) cout<<" ";
            if(j==N-1) cout<<endl;
        }
    
    }
            
    }



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

int main() {
	int x;
	int y;
	int last_digit;
	int length=0;
	long long count1=0;
	long long count2=0;
	long long count=0;
	cin >>x;
	y=x;
	if (x<10)
	{
		cout <<x;
		return 0;
	}
	while (x>0)
	{
		length++;
		x/=10;
	}
	last_digit = y/(pow(10,length-1));
	x = last_digit*(pow(10,length-1));
	for (int i=1; i<10; i++)
	{
		count1=0;
		for (int k=1; k<=length;k++)
		{
			if (k==1)
			{
				count1++;
			}
			else if (k!=length)
			{
				count1+=pow(10,k-2);
			}
			else
			{
				if (i<last_digit)
				{
					count1+=pow(10,k-2);
				}
				else if (i==last_digit)
				{
					if ((x+i)<=y)
						count1+= ((y-x-i)/10)+1;
				}
			}
		}
		count+=count1*count1;
	}
	
	for (int i=1; i<10; i++)
	{
		for (int j=i+1; j<10;j++)
		{
			count1=0;
			count2=0;
			for (int k=2; k<=length;k++)
			{
				if (k!=length)
				{
					count1+=pow(10,k-2);
					count2+=pow(10,k-2);
				}
				else
				{
					if (i<last_digit)
					{
						count1+=pow(10,k-2);
					}
					else if (i==last_digit)
					{
						if (x+j<=y)
							count1+= ((y-x-j)/10)+1;
					}
					if (j<last_digit)
					{
						count2+=pow(10,k-2);
					}
					else if (j==last_digit)
					{
						if (x+i<=y)
							count2+= ((y-x-i)/10)+1;
					}
				}
			}
			count+=count1*count2*2;
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[200][200];

int main() {
  clr(d,0);
  ll h,w;
  cin>>h>>w;
  rep(y,0,h){
    string s;
    cin>>s;
    rep(x,0,w){
      if(s[x]=='#'){
        d[y+100][x+100]=1;
      }
    }
  }
  ll flag1 = 1;
  rep(y,1,199){
    rep(x,1,199){
      ll flag = 1;
      if(d[y][x]==1){
        if(d[y-1][x]==1)flag=0;
        if(d[y+1][x]==1)flag=0;
        if(d[y][x-1]==1)flag=0;
        if(d[y][x+1]==1)flag=0;
        if(flag==1)flag1 = 0;
      }
    }
  }
  if(flag1==1){
      cout << "Yes" << endl;
  }
  else{
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;
using P = pair<ll,ll>;

int main(){

  ll N, M;
  cin >> N >> M;
  vector<P> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(), p.end());

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if(M <= 0) break;
    int num = min(M, p[i].second);
    ans += num * p[i].first;
    M -= num;
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 4792
use strict;
use warnings;
package ZAlgorithm;
sub z_algorithm(@){
	my$n=@_;
	my@z=($n);
	my$i=1;
	my$j=0;
	while($i<$n){
		$j++while$i+$j<$n&&$_[$j]eq$_[$i+$j];
		$z[$i]=$j;
		if($j==0){
			$i++;
			next;
		}
		my$k=1;
		while($i+$k<$n&&$k+$z[$k]<$j){
			$z[$i+$k]=$z[$k];
			$k++;
		}
		$i+=$k;
		$j-=$k;
	}
	return@z;
}
package main;
my$N=<>;
my@A=map int,split$",<>;
my@B=map int,split$",<>;
my@T;
for(0..$N-1){
	$T[$_]=$B[$_]^$B[($_+1)%$N];
	$T[$_+$N]=$T[$_+2*$N]=$A[$_]^$A[($_+1)%$N];
}
my@z=ZAlgorithm::z_algorithm(@T);
for(0..$N-1){
	print$_,$",$A[$_]^$B[0],$/if$z[$_+$N]>=$N;
}


Measured memory_bytes: 134276
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define mo 1000000007
using namespace std;
//Conditional Operator (condition?true part:false part) eg : cout<<(y<=3?"YES":"NO")<<endl;a
ll getmul(ll n){ll int k{0};while(n>0){k+=n%10;n=n/10;}return k;}//Sum OF n DIGITS
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int sum{0};
  for(int i=1;i<=n;i++){
    if(arr[i-1]%2!=0&&i%2!=0)
      sum++;
  }
  cout<<sum<<endl;
 return 0; 
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
#define EPS 1e-10

int main(void){

  int i;
  int l[10],v[2];
  double len[10];
  double time;

  while(1){
    if(scanf("%d,",&l[0])==EOF)break;
    len[0] = l[0];
    for(i=1;i<10;i++){
      scanf("%d,",&l[i]);
      len[i] = len[i-1]+l[i];
    }
    scanf("%d,",&v[0]);
    scanf("%d ",&v[1]);

    time = len[9]/(v[0] + v[1]);

    for(i=0;i<10;i++){
      if( time*v[0] - len[i] < EPS){
	printf("%d\n",i+1);
	break;
      }
    }

  }

  return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

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


Measured memory_bytes: 3232
s = list(input())
s1 = int(s[0] + s[1])
s2 = int(s[2] + s[3])
if 0 < s1 <= 12 and 0 < s2 <= 12:
    print("AMBIGUOUS")
elif 0 < s1 <= 12:
    print("MMYY")
elif 0 < s2 <= 12:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 2940
#include<stdio.h>
main()
{
	long int n, x, a[110], i, j, s;
	scanf("%ld%ld", &n, &x);
	for (i=0; i<n; i++)
	{
		scanf("%ld", &a[i]);
	}
	for (i=n-1; i>0; i--)
	{
		for (j=0; j<i; j++)
		{
			if (a[i]<a[j])
			{
				s=a[i];
				a[i]=a[j];
				a[j]=s;
			}
		}
	}
	for (i=0, s=0; x>0; i++)
	{
		if (a[i]<=x)
		{
			x=x-a[i];
			s++;
		}
		if (i==n-1)
		break;
	}
	if (s==n && x>0)
	{
		s=s-1;
	}
	printf("%ld\n", s);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#define MOD 1000000007
using namespace std;
const int MAXN = 100005;
int n,a[MAXN],b[MAXN],limit[MAXN],sure[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",a+i);
        if(a[i]>a[i-1])limit[i]=1,sure[i]=a[i];
        else limit[i]=a[i];
    }
    for(int i=1;i<=n;++i)scanf("%d",b+i);
    for(int i=n;i>0;--i){
        if(b[i]>b[i+1]){
            if((sure[i] && b[i]!=sure[i]) || (!sure[i] && b[i]>limit[i])){puts("0");return 0;}
            limit[i]=1;
        }
        else limit[i]=min(limit[i],b[i]);
    }
    long long ans=1;
    for(int i=1;i<=n;++i)
        ans=ans*limit[i]%MOD;
    cout<<ans<<endl;
    return 0;
}

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

#define ll long long

int main()
{
    ll k, n;
    std::cin >> k >> n;

    std::vector<ll> A(n);
    ll diff = 0;

    for(ll i=0; i < n; i++) {
        std::cin >> A[i];
        if(i > 0) {
            if((A[i]-A[i-1]) > diff) {
                diff = A[i]-A[i-1];
            }
        }
    }

    ll x = k + A[0] - A[n-1];
    if(x > diff) {
        diff = x;
    }
    
    std::cout << k-diff << std::endl;
}

Measured memory_bytes: 4816
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int freq=0;
  int d1,d2;
  vector<pair<int,int>> A;
  for(int i=0;i<n;i++)
  {
  	int a,b;
  	cin>>a;
  	cin>>b;
  	A.push_back({a,b});
  }
  d1=A[0].first;
  d2=A[0].second;
  int flag=0;
  for(int i=0;i<A.size();i++)
  {
  	if(A[i].first==A[i].second)
  	{
  		freq++;
	}
	else
	{
		freq=0;
	}
	if(freq>=3)
	flag=1;
  }
  if(flag==1)
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
}

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

int main() {
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K; cin >> K;
    cout << a[K-1] << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using LL = long long;
using ULL = unsigned long long;
using namespace std;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  std::cin >> n;
  VEC<int> v(n);
  std::map<int, int> even, odd;
  REP(i, 0, n) {
    std::cin >> v[i];
    if (i % 2 == 0) {
      even[v[i]]++;
    } else {
      odd[v[i]]++;
    }
  }

  VEC<pair<int, int>> e(even.size()), o(odd.size());
  int i = 0;
  for (auto c : even) {
    e[i] = make_pair(c.second, c.first);
    ++i;
  }
  i = 0;
  for (auto c : odd) {
    o[i] = make_pair(c.second, c.first);
    ++i;
  }
  sort(ALL(e));
  reverse(ALL(e));
  sort(ALL(o));
  reverse(ALL(o));

  if (e[0].second == o[0].second) {
    int e1 = e[0].first;
    int e2 = (e.size() > 1 ? e[1].first : 0);
    int o1 = o[0].first;
    int o2 = (o.size() > 1 ? o[1].first : 0);
    std::cout << min(n - e1 - o2, n - e2 - o1) << endl;

  } else {
    std::cout << n - e[0].first - o[0].first << std::endl;
  }

  return 0;
}


Measured memory_bytes: 6144
import sys
stdin=sys.stdin

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()

n=ip()
a=[]
b=[]
ans=0
for i in range(n):
  s=sp()
  if s[0]=='B':
    b.append(i)
  if s[-1]=='A':
    a.append(i)
  for j in range(len(s)-1):
    if s[j]=='A' and s[j+1]=='B':
      ans+=1
      
c=len(list(set(a)&set(b)))
a_rest=len(a)-c
b_rest=len(b)-c
if c==0:
  omake=min(a_rest,b_rest)
else:
  if a_rest==b_rest==0:
    omake=c-1
  else:
    omake=c+min(a_rest,b_rest)
  
print(ans+omake)




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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n;
    cin >> n;
    int a;
    int cnt = 1, ans = 0;
    rep(i, n) {
        cin >> a;
        if(a == cnt)
            cnt++;
        else
            ans++;
    }
    if(cnt == 1) ans = -1;
    cout << ans << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

int main(){
  int n;
  long long x;
  cin >> n >> x;
  long long a_prev;
  cin >> a_prev;
  long long a_new;
  long long ans = 0;
  if(a_prev > x){
    ans = a_prev - x;
    a_prev = x;
  }
  for(int i = 1; i < n; i++){
    cin >> a_new;
    if(a_prev + a_new <= x){
      a_prev = a_new;
    }else{
      ans += a_prev + a_new - x;
      a_new = x - a_prev;
      a_prev = a_new;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N;
Graph G;
vector<int> color;

int dfs1(int p, int v, int dist){
  // 今見ている頂点がvで0からの距離がdist
  // p から来た
  // N-1までの距離が返されるので適切に処理

  if (v == N-1) return dist;

  bool leaf = true;
  int res = 0;
  for (auto nv : G[v]){
    if (nv == p) continue;
    leaf = false;
    int tmp = dfs1(v, nv, dist+1);
    chmax(res, tmp);
  }
  // N-1に到達するパスでなければ適当に0を返す
  if (res == 0) return 0;
  // N-1に到達するパスならN-1と0の距離を返す
  // そして自分がFennec側ならcolorに1を、Snuke側ならcolorに-1を入れる
  // (Fennec) 0, 1, ..., dist-1, dist (Snuke)
  // 距離が偶数：0, 1, 2 | 3, 4
  // 距離が奇数：0, 1, 2 | 3, 4, 5
  color[v] = dist <= res/2 ? 1 : -1;
  return res;
}

void dfs(int p, int v){
  // 今見ている頂点がvで pから来た
  for (auto nv : G[v]){
    if (nv == p) continue;
    if (color[nv] != 0) continue; // 既に色が塗られている
    color[nv] = color[v];
    dfs(v, nv);
  }
}

int main() {
  cin >>N;
  G.assign(N, vector<int>());
  rep(i, N-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  color.assign(N, 0);
  color[0] = 1;
  color[N-1] = -1;
  // color[i] := マスiの色
  // 1ならFennec, -1ならSnuke

  // まずお互いの行けるところをなくすように動く
  // 乃ちお互いが最短距離でぶつかりに行く
  // マス0 と マスN-1 を結ぶ最短のパスについて、色を塗っていく
  dfs1(0, 0, 0);

  // で、両者がぶつかるまで色を塗ったのであとは濡れるところを塗っていく感じ
  rep(i, N){
    if (color[i] == 0) continue;
    dfs(i, i);
  }

  // で、色を数えて勝敗を決する
  int fen = 0;
  int snu = 0;
  rep(i, N){
    if (color[i] == 1) fen++;
    else snu++;
  }
  cout <<(fen > snu ? "Fennec" : "Snuke") <<endl;
}


Measured memory_bytes: 13952
/**********************************************************************/
/********                                                      ********/
/********                     Writer:孙~~                      ********/
/********                       Lang:C++                       ********/
/********                     Status:Unknow                    ********/
/********                                                      ********/
/**********************************************************************/
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;
#define max(a,b,c) (max(a,max(b,c)))
#define max(a,b,c,d) (max(max(a,b,c),d))

const int INF=0x3f3f3f3f;
const int SIZE=105;

int a[SIZE];
vector<int> blocks;

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
	}
	int tmp=1;
	for(int i=1;i<n;i++){
		if(a[i]!=a[i-1]){
			blocks.push_back(tmp);
			tmp=0;
		}
		tmp++;
	}
	blocks.push_back(tmp);
	int ans=0;
	for(int i=0;i<blocks.size();i++){
		ans+=blocks[i]/2;
	}
	printf("%d",ans);
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define sn(n) scanf("%d",&n)
#define pr(n) printf("%d",n)
#define pn printf("\n")
#define ll long long
#define p 1000000005
using namespace std;
int n,m;
int main()
{
    char s[10];
    scanf("%s",s);
    if(strlen(s)==2)
        printf("%s\n",s);
    else
    {
        for(int i=2;i>=0;i--)
            printf("%c",s[i]);
        pn;
    }
    return 0;
}


/*

Lucas(卢卡斯)定理

ll pow_quick(ll a, ll b)

{

    ll  ans =1;

    while(b)

    {

        if(b &1)  ans = ans * a % p;

        b>>=1;

        a = a*a % p;

    }

    return  ans;

}

ll C(ll n, ll m)

{

    if(m > n)  return 0;

    ll ans = 1;
    for(ll i=1; i<=m; i++)
    {
        ll a = (n+i-m)%p;

        ll b = i%p;

        ans = (ans*(a*pow_quick(b,p-2)%p))%p;

    }
    return ans;
}

ll Lucas(ll n, ll m )

{

    if(m ==0)  return 1;

    else return  (C(n%p, m%p)*Lucas(n/p, m/p))%p;

}


*/


Measured memory_bytes: 256
s = list(input())
if sorted(s, reverse=True) == s and len(s) == 26:
    print(-1)
    quit()
for i in range(0, 26):
    if chr(97 + i) not in s and len(s) != 26:
        print(''.join(s) + chr(97+i))
        quit()

while len(s) > 0:
    while ord(s[-1]) < ord('z'):
        s[-1] = chr(ord(s[-1])+1)
        if len(s) == len(set(s)):
            print(''.join(s))
            quit()
    del s[-1]

Measured memory_bytes: 3064
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int n, p;
int[] a;

void main() {
    scan(n, p);
    a = readln.split.to!(int[]);

    int lim = n * 100;

    auto dp = new long[](lim + 1);
    dp[0] = 1L;

    foreach (i ; 0 .. n) {
        foreach_reverse (j ; a[i] .. lim + 1) {
            dp[j] += dp[j - a[i]];
        }
    }

    long ans;

    foreach (i ; 0 .. lim + 1) {
        if ((i & 1) == p) {
            ans += dp[i];
        }
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 380
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::{BTreeMap,BTreeSet};
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! tf {
    ($c:expr, $t:expr, $f:expr) => {{
        if $c { $t } else { $f }
    }};
}

fn main() {
    let mut xs = read_vec_i64();
    xs.sort();
    let res = xs[2] * 10 + xs[1] + xs[0];
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    //ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


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

string taro,hana,card[2];
int N,Tp,Hp;

int main(){
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> taro >> hana;
        if(taro == hana){
            Tp++; Hp++;
            continue;
        }
        card[0] = taro; card[1] = hana;
        sort(card, card +2);
        if(card[1] == taro) Tp+=3;
        else Hp+=3;
    }

    cout << Tp << " " << Hp << endl;
    return 0;
}

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

int main(void){
	int x,y;
	cin >> x >> y;
	
	while(true){
		if(x < y)swap(x,y);
		if(y == 0)break;
		x %= y;
	}

	cout << x << endl;
	return 0;
}

Measured memory_bytes: 3096
import java.util.*;
class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int N = sc.nextInt();
        int Boss[]=new int[N+1];
        int Count[]=new int[N+1];
        int i ;
        for(i=1;i<=(N-1);i++){
            Boss[i]= sc.nextInt();
        }
        for(i=1;i<N;i++){
                Count[Boss[i]]++;
            }
        for(i=1;i<=N;i++)
        System.out.println(Count[i]);
    }
}

Measured memory_bytes: 62220
#include<stdio.h>
int a[100000];
int main()
{
	int h,n,i=0,j;
	scanf("%d %d",&h,&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
	{
		h=h-a[i];
		if(h<=0)
			break;
	}
	if(i==n)
	printf("No");
	else 
	printf("Yes");
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
const int maxn=2e3+7;
const int mod=1e9+7;
/*Almost copy pasted part :)*/

int32_t main(){
    string s;
    cin>>s;
    int n=s.size();
    bool A=0;
    bool B=0;
    for(int i=0;i<n;i++){
        if(s[i]=='A')A=1;
        else B=1;
    }
    cout<<(A&&B ? "Yes":"No")<<endl;
}

Measured memory_bytes: 256
def div(N):
    div = set()
    for i in range(1, int(N ** 0.5 + 0.5) + 1):
        if N % i == 0:
            div.add(i)
            div.add(N // i)
    return len(div)


N = int(input())
ans = 0
for x in range(1, N + 1, 2):
    if div(x) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3060
import collections
N,C=map(int,input().split())
cost=[list(map(int,input().split())) for _ in range(C)]
table=[list(map(int,input().split())) for _ in range(N)]
l=[[] for _ in range(3)]
costs=[[] for _ in range(3)]

for i in range(N):
    for j in range(N):
        l[(i+j)%3].append(table[i][j])
#print(l)
c1=collections.Counter(l[0])
c2=collections.Counter(l[1])
c3=collections.Counter(l[2])
costs=[[] for _ in range(3)]
for i in range(C):
    for j in range(3):
        buf=0
        for k in l[j]:
            buf=buf+cost[k-1][i]
        costs[j].append(buf)
#print(costs)
mi=float("inf")
for i in range(C):
    for j in range(C):
        for k in range(C):
            if (i!=j)and(j!=k)and(i!=k):
                mi=min(mi,costs[0][i]+costs[1][j]+costs[2][k])
print(mi)

Measured memory_bytes: 56796
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

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

	int a,b;
	cin >> a >> b;

	if(a <= 8 && b <= 8) cout << "Yay!\n";
	else				cout << ":(\n";

	
	return 0;
}

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


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
  int p;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node k){
   Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
 Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;



  
  while (x != NIL){
    y = x; // 親を設定
    if(z->key < x->key)
    x = x->left; // 左の子へ移動
    else 
      x = x->right; // 右の子へ移動
	       }
  z->parent = y;

  if(y == NIL) // T が空の場合
    root = z;
  else if (z->key < y->key)
    y->left = z ;// z を y の左の子にする
  else 
      y->right = z ;// z を y の右の子にする
  





}

void inorder(Node u){
  if(u== NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
  
}

void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int i,n,x;
  char com[20];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
      
  }

  return 0;

}







  
  
  /*
  insert(T, z)
     y = NIL // x の親
     x = 'T の根'
     while x ≠ NIL
        y = x // 親を設定
         if z.key < x.key
             x = x.left // 左の子へ移動
        else 
            x = x.right // 右の子へ移動
    z.p = y

    if y == NIL // T が空の場合
        'T の根' = z
    else if z.key < y.key
        y.left = z // z を y の左の子にする
    else 
        y.right = z // z を y の右の子にする

  */



Measured memory_bytes: 25124
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MAX = 1000000;
const int MOD = 1000000007;

int dp[3005][3005];

int main(){
  int n,t; cin >> n >> t;
  vector<P> p(n);
  rep(i,n) cin >> p[i].first >> p[i].second;
  sort(p.begin(),p.end());
  
  int ans = 0;
  rep(i,n){
    rep(j,t){
      chmax(dp[i+1][j],dp[i][j]); //p[i]を食べない場合
      int nj = p[i].first + j;
      if(nj < t) chmax(dp[i+1][nj], dp[i][j] + p[i].second); //p[i]を食べる場合
    }
    int tmp = dp[i][t-1] + p[i].second;
    chmax(ans,tmp);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 35456
S = input()
ac=0
if S[0]=="A" and S.count("A")==1 and "C" in S[2:-1] and S[2:-1].count("C") == 1 :
    s = S.replace("A","a").replace("C","c")
    t = s.lower()
    if s == t :
        print("AC")
        ac=1
if ac == 0 :
    print("WA")
    
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define FR(i,a,b) for(int i = (a);i<(b);i++)
#define RF(i,a,b) for(int i = (a);i>(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 505
#define M 51
#define INF 100000000000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
inline int Max(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^a;
}

int b[N*N];
vector<pair<int,int> >v;
int main()
{
    int n;
    while(cin>>n)
    {
        int sq_n = n*n;
        v.clear();
        FOR(i,1,n)
        {
            int x;
            cin>>x;
            v.PB(MP(x,i));
        }
        int cnt = 0;
        int f = 1;
        int back_p = sq_n+1;
        MST(b,-1);
        sort(v.begin(),v.end());
        for(auto it = v.rbegin();it!=v.rend();++it)
        {
            int p = it->FT;
            int k = it->SD;
            if(sq_n-p-cnt<n-k)
            {
                f = 0;
                break;
            }
            int num = n-k;
            cnt+=num+1;
            while(num>0)
            {
                back_p--;
                if(b[back_p]!=-1)continue;
                b[back_p] = k;
                num--;
            }
            b[p] = k;
        }
        int front_p = 0;
        for(auto it = v.begin();it!=v.end();++it)
        {
            int p = it->FT;
            int k = it->SD;
            int num = k-1;
            while(num>0)
            {
                front_p++;
                if(front_p>=p)
                {
                    f = 0;
                    break;
                }
                if(b[front_p]!=-1)continue;
                b[front_p] = k;
                num--;
            }
        }
        if(!f)cout<<"No"<<endl;
        else
        {
            cout<<"Yes"<<endl;
            FOR(i,1,sq_n)cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 2176
n = gets.chomp.to_i
c = gets.chomp.split("")
arr = []
aka = []
siro = []
count_aka = 0
count_siro = 0 
c.each_with_index do |item,j|
    if item == "R"
        aka << j
        count_aka += 1
    elsif item == "W"
        siro << j
        count_siro += 1
    end
end
count = 0
aka.each do |k|
    if count_aka - 1 >= k
        count += 1
    end
end
sa = count_aka - count #動かす数

arr =  [sa,count_aka,count_siro].min
puts [arr,0].max

Measured memory_bytes: 32604
import java.util.Scanner;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class Main{
  
  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    double n, d;
    n = sc.nextDouble();
    d = sc.nextDouble();
    
    System.out.println((int)Math.ceil(n/(2*d+1)));
    
    
    
    
    
    
//    System.out.println(time);
    
    
  }
}

Measured memory_bytes: 25044