akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

#define M 1000003/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ 
  return key%M; 
}

int h2(int key){
  return (1+key%(M-20));
 }

int find(char str[]){
  int i=0,j;
  int key;
  
  key=(int)getKey(str);
  
  while(1){
    j=(h1(key)+i*h2(key))%M;
    if(strcmp(H[j],str)==0) return 1;
    else if(H[j][0]=='\0' || i>=M) return 0;
    else i++;
  }
}

int insert(char str[]){
  int i=0,j;
  int key;

  key=(int)getKey(str);


  while(1){
    j=(h1(key)+i*h2(key))%M;
    if(H[j][0]=='\0'){
      strcpy(H[j],str);
      return j;
    }
    else i++;
  }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
n = int(input())
p = [int(i) for i in input().split()]
count = 0
for i in range(1,n-1):
    num = [p[i-1],p[i],p[i+1]]
    if p[i] != min(num) and p[i] !=max(num):
        count += 1
print(count)

Measured memory_bytes: 38384
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x != None: x, y = x.left if key < x.key else x.right, x
    if y == None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def find(target):
    result = root
    while result and target != result.key:
        result = result.left if target < result.key else result.right
    return result != None

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    elif e[0] == 'f': print(['no','yes'][find(int(e[5:]))])
    else: print(inorder(root)); print(preorder(root))


Measured memory_bytes: 55684
#include <iostream>
#include <cmath>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int size = s.size();
  int n[size];
  for (int i = 0; i < size; ++i) {
    n[i] = s[i]-'0';
  }
  int m = pow(2, size-1);
  u64 sum = 0;
  for (int i = 0; i < m; ++i) {
    u64 num = 0;
    u64 cur = n[0];
    int cnt = 1;
    for (int j = 1; j <m; j*=2) {
      if (i/j%2) {
        num+=cur;
        cur = n[cnt];
      } else {
        cur = cur*10+n[cnt];
      }
      cnt++;
    }
    num+=cur;
    sum+=num;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 384
def main():
    N = int(input())
    P = [int(input()) for _ in [0] * N]

    num = [[j, i] for i, j in enumerate(P)]
    num.sort()
    cnt, maxcnt = 1, 1
    for i in range(N - 1):
        if num[i][1] < num[i+1][1]:
            cnt += 1
            maxcnt = max(maxcnt, cnt)
        else:
            cnt = 1
    print(N - maxcnt)

main()


Measured memory_bytes: 38796
#include<stdio.h>
#define N 50

void paint_map(
    int h,int w,int map[N][N],
    int x,int y){
  if(x==-1 || y==-1 || x==h || y==w)
    return ;
  if(map[x][y]==0)
    return ;

  map[x][y]=0;

  paint_map(h,w,map,x-1,y-1);
  paint_map(h,w,map,x-1,y);
  paint_map(h,w,map,x-1,y+1);
  paint_map(h,w,map,x,y-1);
  paint_map(h,w,map,x,y+1);
  paint_map(h,w,map,x+1,y-1);
  paint_map(h,w,map,x+1,y);
  paint_map(h,w,map,x+1,y+1);
}

int main(void){
  int i,j;
  int w,h;
  int map[N][N];
  int count;

  for(;;){
    scanf("%d%d",&w,&h);
    if(w==0 && h==0)
      break;

    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
        scanf("%d",&map[i][j]);

    count=0;
    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
        if(map[i][j]){
          count++;
          paint_map(h,w,map,i,j);
        }

    printf("%d\n",count);
  }

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
  int cnt =0, n;
  cin>>n;
  for(int i=0;i<=25;i++){for(int j=0;j<=15;j++){if(4*i+7*j==n)cnt++;}}
  if(cnt>0)cout<<"Yes"<<endl;else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
s = S()
ans = 0
before = ''
for i in range(N):
    if before != s[i]:
        before = s[i]
        ans +=1
print(ans)

Measured memory_bytes: 69076
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
vector<int> ki[220000];
vector<int> point;
void dfs(int now,int last = -1){
	for(int next:ki[now]){
		if(next == last)continue;
		point[next] += point[now];
		dfs(next,now);
	}
}

signed main(){
	int n,q;cin >> n >> q;
	point.resize(n);
	rep(i,n-1){
		int a,b;cin >> a >> b;
		--a;--b;
		ki[a].push_back(b);
		ki[b].push_back(a);
	}
	rep(i,q){
		int p,x;cin >> p >> x;
		p--;
		point[p] += x;
	}
	dfs(0);
	rep(i,n)cout << point[i] << endl;

	return 0;
}

Measured memory_bytes: 25616
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500+b*100+c*50 == X:
                ans += 1

print(ans)


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

int main() {
	int N, X;
	cin >> N >> X;
	int a[110];
	for(int i=0; i<N; ++i) cin >> a[i];
	sort(a, a + N);
	int p=0;
	while(p<N-1 && X>=a[p]){
	        X -= a[p];
	        ++p;
	}
	if(p==N-1 && X==a[p]) ++p;
	cout << p << endl;
	return 0;
}


Measured memory_bytes: 256
H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
Q=int(input())
LR=[tuple(map(int,input().split())) for _ in range(Q)]

pos=[None]*(H*W)
for i in range(H):
  for j in range(W):
    pos[A[i][j]-1] = (i, j)

d=[0]*(H*W)
for i in range(D, H*W):
  px,py = pos[i-D]
  x, y = pos[i]
  d[i]=d[i-D] + abs(x-px) + abs(y-py)

for l, r in LR:
  print(d[r-1]-d[l-1])

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
        const char* c = strchr(na + 1, ',');
        cerr.write(na, c - na) << " : " << arg1 << " , ";
        __f(c + 1, args...);
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)), V.erase(unique(all(V)), V.end())
typedef pair <int,int> pii;
typedef long long LL;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int inf = 1e9;
const long long INF = 1e18;
const int N = 2e5 + 5;

int n, a[ N ];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    #ifdef LOCAL
        //freopen("input.txt", "r", stdin);
    #endif // LOCAL
    int t = 1; //cin >> t;
    for (int tc = 1; tc <= t; tc++) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        int id = 1;
        int can = 0;
        for (int i = 1; i <= n; i++) {
            if (a[i] == id) {
                id++;
                can++;
            }
        }
        if (can == 0) cout << -1 << endl;
        else cout << n - can << endl;
    }
    return 0;
}







Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <functional>
using namespace std;

int main()
{
	int n,tmp,sum=0;
	std::vector<int> v,c_sum;

	std::cin >> n;

	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		sum+=tmp;
		v.push_back(tmp);
		c_sum.push_back(sum);
	}

	int minimum=99999999;
	for(int x: c_sum){
		int diff = x - (c_sum.back()-x);
		diff = abs(diff);
		if(diff<minimum)
			minimum=diff;
	}

	cout << minimum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,M; cin>>N>>M;
    map<int,set<pair<int,int>>> mp;
    rep(m,0,M){
        int p,y; cin>>p>>y;
        mp[p].insert(make_pair(y,m));
    }

    vector<pair<int,int>> ans(M);
    for(auto m:mp){
        int i=0;
        for(auto s:m.second){
            i++;
            ans.at(s.second)=make_pair(m.first,i);
        }
    }

    for(auto a:ans){
        cout<<setfill('0')<<right<<setw(6)<<a.first;
        cout<<setfill('0')<<right<<setw(6)<<a.second<<endl;;
    }
}

Measured memory_bytes: 16384
#include <iostream>
#include <vector>
using namespace std;
//---------------------------------------
int BubbleSort(vector<int>& a);
void Show(const vector<int> a, const int bs_count);
//---------------------------------------

int main(void)
{
	int n;
	vector<int> a;
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		int num;
		cin >> num;
		a.push_back(num);
	}
	
	int bs_count = BubbleSort(a); //????????????(??????????????????)
	Show(a, bs_count);
	
	return 0;
}

//------------------------------------------
int BubbleSort(vector<int>& a){
	
	int bs_count = 0;
	
	for(int i = 0; i <= a.size() -1; i++){
		for(int j = a.size() -1; j >= i+1; j--){
			if(a[j] < a[j-1]){
				int temp = a[j];
				a[j] = a[j-1];
				a[j-1] = temp;
				bs_count++;
			}
		}
	}
	return bs_count;
}
//--------------------------------------------
void Show(const vector<int> a, const int bs_count){
	for(int i = 0; i < a.size() - 1; i++){
		cout << a[i] << ' ';
	}
	cout << a[a.size() - 1] << endl;
	
	cout << bs_count << endl;
	
}

Measured memory_bytes: 3124
answers = Array.new
n = $stdin.gets.chomp.to_i
1.upto( n ){
	digit = []
	s = $stdin.gets.chomp
	list = s.split(//).map{|n| n.to_i}
	min = list.sort{ |a,b| a <=> b }.inject{ |memo,item| memo * 10 + item}
	max = list.sort{ |a,b| b <=> a }.inject{ |memo,item| memo * 10 + item}
	answers << (max - min)
}
answers.each{ |a| puts a }


Measured memory_bytes: 6096
//vvk
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;
ll res;
ll a[N][3];
string s;
void solve(){
    ll n;
    cin >> n >> s;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'R') res = 0;
        else if(s[i] == 'G') res = 1;
        else res = 2;
        if(i > 0) {
            for(int j = 0; j < 3; j++) a[i][j] += a[i - 1][j];
        }
        a[i][res]++;
    }
    /*for(int i = 0; i <= n; i++) {
        cout << a[i][0] << " " << i << "\n";
    }*/
    ll ans = 0;
    for(int i = 1; i + 1 < n; i++) {
        if(s[i] == 'R') { 
            ans += (a[i -1][1] * (a[n - 1][2] - a[i][2]));
            ans += (a[i - 1][2] * (a[n - 1][1] - a[i][1]));
        }
        else if(s[i] == 'G') { 
            ans += (a[i - 1][2] * (a[n - 1][0] - a[i][0]));
            ans += (a[i - 1][0] * (a[n - 1][2] - a[i][2]));
        }
        else { 
            ans += (a[i - 1][0] * (a[n - 1][1] - a[i][1]));
            ans += (a[i - 1][1] * (a[n - 1][0] - a[i][0]));
        }
    }
    set < char > st;
    for(int i = 0; i + 1 < n ; i++) {
        for(int j = 1 ; j <= n/2; j++) {
            st.clear();
            if(i + 2 * j >= n) {
                break;
            }
            st.insert(s[i]);
            st.insert(s[i + j]);
            st.insert(s[i + 2 * j]);
            if(ll(st.size()) == 3) {
                ans--;
            }
        }
    }
    cout << ans << "\n";
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3752
package main

import (
  "fmt"
)

func main() {
  var k, a, b int
  var yen int = 0
  var biscuit uint64 = 1
  fmt.Scan(&k)
  fmt.Scan(&a)
  fmt.Scan(&b)
  var isNoSell = b - a <= 2
  for i := 0; i < k; i++ {
    if (isNoSell) {
      biscuit++
    } else {
      if yen > 0 {
        yen -= 1
        biscuit += uint64(b)
      } else if biscuit >= uint64(a) && i < k - 1 {
        biscuit -= uint64(a)
        yen += 1
      } else {
        biscuit++
      }
    }
  }
  fmt.Println(biscuit)
}

Measured memory_bytes: 512
S = [s for s in input()]
T = [t for t in input()]
S.sort()
T.sort(reverse=True)
ALP = "abcdefghijklmnopqrstuvwxyz"

for s, t in zip(S, T):
    if s == t:
        continue
    elif ALP.index(s) < ALP.index(t):
        print("Yes")
        break
    else:
        print("No")
        break
else:
    if len(S) < len(T):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3060
function main()
  n = parse(Int, readline())
  arr = parse.(Int, split(readline()))

  if n == 2
    println(max(arr[1], arr[2]))
    return
  end
  if n == 3
    println(max(arr[1] + arr[3], arr[2]))
    return
  end

  is_odd = n % 2 > 0
  dp = zeros(Int, n, 3)

  dp[1, 1]                     = arr[1]
  dp[2, 1], dp[2, 2]           = arr[1],          arr[2]
  dp[3, 1], dp[3, 2], dp[3, 3] = arr[1] + arr[3], arr[2],                       max(arr[1], arr[3])
  dp[4, 1], dp[4, 2], dp[4, 3] = arr[1] + arr[4], max(arr[1], arr[2]) + arr[4], arr[4]

  for (i, a) in enumerate(arr)
    if i < 5
      continue
    end
    dp[i, 1] = dp[i - 2, 1] + a
    dp[i, 2] = max(dp[i - 2, 2], dp[i - 3, 1]) + a
    if is_odd
      dp[i, 3] = max(dp[i - 2, 3], dp[i - 3, 2], dp[i - 4, 1]) + a
    end
  end

  println(
    is_odd ? max(dp[n - 2, 1], dp[n - 1, 2], dp[n, 3]) : max(dp[n, 2], dp[n - 1, 1])
  )
end

main()


Measured memory_bytes: 204112
A, B, K = [int(i) for i in input().split()]

if (B+1-A)/2 <= K:
    # 数列の半分よりKが大きければ、素直に全部printする
    [print(n) for n in range(A, B+1)]
else:
    [print(n) for n in range(A, A+K)]
    [print(n) for n in range(B+1-K, B+1)]


Measured memory_bytes: 3060
#include<stdio.h>
         
        int main()
        {
        	char S[10];
        	scanf("%s", S);
         
        	int ans = 0;
        	for (int i = 0; i < 4; ++i) {
        		if (S[i] == '+') ++ans;
        		else --ans;
        	}
        	printf("%d\n", ans);
        	return 0;
        }

Measured memory_bytes: 128
#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);
    }
    int  ans      = 0;
    bool is_break = false;
    while (true) {
        for (auto& a : A) {
            if (a % 2 != 0) {
                is_break = true;
                break;
            }
            a /= 2;
        }
        if (is_break) { break; }
        ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3600
import java.util.*;
import java.lang.*;
 
public class Main {
    public static void main(String[] args) {

        Scanner sc  = new Scanner(System.in);


        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());


        int[] test  = new int[1000000];        
        for(int i = 0; i < 2 * M; i++){
            int c = Integer.parseInt(sc.next());
            test[c]++;
        }

        for(int i = 1; i < N+1 ; i++){
            System.out.println(test[i]);
        }

        System.out.println();
    }

}

Measured memory_bytes: 26708
#include<iostream>

using namespace std;

int main(void)
{
  int x,y; cin>>x>>y;
  int g[]={1,3,1,2,1,2,1,1,2,1,2,1};
  
  cout<<((g[x-1]==g[y-1])?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k, s;
  cin >> k >> s;

  int ans = 0;
  for(int x=0; x<=k; x++) {
    for(int y=0; y<=k; y++) {
      int z = s - (x + y);
      if(0 <= z && z <= k) {
        // cout << x << ' ' << y << ' '<< z << endl;
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

constexpr int inf = 1e9 + 7;
constexpr int mod = 1e9 + 7;

using ll = long long;

ll modpow(ll a, ll n) {
    ll result = 1;
    ll base = a;
    ll mask = 1;
    while (mask <= n) {
        if (n & mask) (result *= base) %= mod;
        mask <<= 1;
        (base *= base) %= mod;
    }
    return result;
}

int main() {

    int n;
    cin >> n;

    ll ans = 0LL;

    ans = modpow(10, n) - modpow(9, n) * 2 + modpow(8, n);

    ans += 10LL * mod;
    ans %= mod;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
o = input()
e = input()
ans = ''
if len(o) == len(e):
    for i in range(len(o)):
        ans += o[i] + e[i]
else:
    for i in range(len(e)):
        ans += o[i] + e[i]
    ans += o[len(o) - 1]
print(ans)

Measured memory_bytes: 3060
n,k,*v=map(int,open(0).read().split())
m=0
r=range
for i in r(n+1):
 for j in r(min(k-i+1,n-i+1)):
  t=sorted(v[:i]+v[-j:]*(j>0))[::-1];c=k-i-j
  while t and c and t[-1]<0:t.pop();c-=1
  m=max(m,sum(t))
print(m)

Measured memory_bytes: 41324
import java.util.Scanner;
class Main{
    public static void main(String[] args){
	final Scanner sc=new Scanner(System.in);
	int count = 0;
	int i=sc.nextInt();
	while(i!=0){
	    count++;
	    System.out.println("Case "+count+": "+i);
	    i=sc.nextInt();
	}
    }
}

Measured memory_bytes: 33064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);


struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 19;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}


void solve() {
	int n, m; cin >> n >> m;
	vector<vector<int>> G(n);
	rep(i, m) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> ans(n, -1);
	ans[0] = 0;
	queue<int> q;
	vector<bool> used(n, false);
	used[0] = true;
	q.push(0);
	while (!q.empty()) {
		int v = q.front(); q.pop();
		for (int to : G[v]) {
			if (used[to])continue;
			ans[to] = v;
			used[to] = true;
			q.push(to);
		}
	}
	rep(i, n)if (ans[i] < 0) {
		cout << "No\n"; return;
	}
	cout << "Yes\n";
	rep1(i, n - 1) {
		cout << ans[i] + 1 << "\n";
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init_f();
	//init();
	//int t; cin >> t;rep(i,t)
	solve();
	stop
		return 0;
}


Measured memory_bytes: 18504
n, m = map(int, input().split())
s = [int(input()) for _ in range(m)]
s.append(n+1)

dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1

for i in range(n - 1):
    dp[i + 2] = dp[i + 1] + dp[i]
mae = 0
ans = 1
for i in s:
    if i == mae:
        ans=0
    else:
        ans *= dp[i - 1 - mae]

    mae = i + 1
print(ans % (10 ** 9 + 7))



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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

	int N, P; cin >> N >> P;

	int odd = 0;
	int even = 0;
	rep (i, N){
		int a; cin >> a;
		odd += (int)(a % 2 == 1);
	} // end rep
	even = N - odd;

	ll res = 0LL;
	if (odd == 0){
		if (P == 0){
			res = (1LL<<N);
		}else{
			res = 0LL;
		} // end if
	}else{
		res = (1LL<<(N-1));
	} // end if

	cout << res << endl;
		
	return 0;
}

Measured memory_bytes: 256
import functools
import fractions

def blcm(x, y):
	return (x*y)//fractions.gcd(x, y)

def slcm(numbers):
	return functools.reduce(blcm, numbers)
	
input()
numbers=list(map(int, input().split()))
num=slcm(numbers)-1
nums=[num%i for i in numbers]
print(sum(nums))


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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

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

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}


void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int n ;
int a[ 2 ][ 100 ] ;

int main(){

   cin >> n ;
   forn( int , i , 0 , n ){
     cin >> a[ 0 ][ i ] ;
   }

   forn( int , i , 0 , n ){
     cin >> a[ 1 ][ i ] ;
   }

   int mx = 0 ;

   forn( int , i , 0 , 1 << n ){
      int sum1 , sum2 ;
      sum1 = sum2 = 0 ;
      forn( int , j , 0 , n ){
         if( i & ( 1 << j ) ){
            sum1 += a[ 1 ][ j ] ;
            sum2 += a[ 0 ][ j ] ;
         }
      }

      mx = max( sum2- sum1 , mx ) ;

   }

    cout << mx ;

   return 0 ;
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N;
map<ll, int> M;
ll ret;
vector<ll> vec;

int main() {
	cin >> N;

	rep(i, N) {
		ll x;
		cin >> x;
		M[x]++;
	}

	for (auto p : M) {
		if (p.se >= 2) {
			vec.pb(p.fi);
		}
		if (p.se >= 4) {
			ret = max(ret, p.fi * p.fi);
		}
	}

	if (vec.size() >= 2) {
		int sz = vec.size();
		ret = max(ret, vec[sz - 1] * vec[sz - 2]);
	}
	cout << ret << endl;

	return 0;
}

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

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
const ll Mod = (1e9 + 7) * 2;

int n;
ll a[200010];
ll sum, ans;

int main() {
	fast;

	cin >> n;

	for(int i=1; i<=n; i++) {
		cin >> a[i];
		sum += a[i];
		sum %= Mod;

		ans += Mod - a[i] * a[i] % Mod;
		ans %= Mod;
	}

	ans += sum * sum % Mod;
	ans %= Mod;

	cout << ans / 2;
}

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

import heapq

lefts = a[:n]
lefts_sums = [sum(lefts)]
heapq.heapify(lefts)

for x in range(n, 2 * n):
    l = heapq.heappop(lefts)
    if l < a[x]:
        heapq.heappush(lefts, a[x])
        lefts_sums.append(lefts_sums[-1] - l + a[x])
    else:
        heapq.heappush(lefts, l)
        lefts_sums.append(lefts_sums[-1])

rights = [-_a for _a in a[2 * n:]]
rights_sums = [sum(rights)]
heapq.heapify(rights)

for x in reversed(range(n, 2 * n)):
    r = heapq.heappop(rights)
    if r < -a[x]:
        heapq.heappush(rights, -a[x])
        rights_sums.append(rights_sums[-1] - r - a[x])
    else:
        heapq.heappush(rights, r)
        rights_sums.append(rights_sums[-1])

rights_sums = rights_sums[::-1]
ans = -float('inf')
for i in range(len(lefts_sums)):
    ans = max(ans, lefts_sums[i] + rights_sums[i])
# print(lefts_sums, rights_sums)
print(ans)


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

using namespace std;
#define int long long int

signed main() {
int n;
cin>>n;
vector<int> A;
for (int i=0;i<n;i++)
{
    int d;
    cin>>d;
    A.push_back(d);
    
    
}
unordered_map<int,int>mp;
reverse(A.begin(),A.end());
int count=0;
for (int i=n-1;i>=0;i--)
{
    if (mp.find(A[i]+i)==mp.end())
    {
        mp[i-A[i]]++;
    }
    else
    {
        count+=mp[A[i]+i];
        mp[i-A[i]]++;
    }
}
cout<<count;
}



Measured memory_bytes: 12940
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;

int digitsum(int N){
  if(N<=0) return 0;
  int digit=1+floor(log10(N)),res=0;
  for(int i=digit-1;i>=0;i--){
    int mono=N/pow(10,i);
    res+=mono;
    N-=mono*pow(10,i);
  }
  return res;
}
int main(void){
  int N,ans=INF;
  cin >> N;
  for(int i=1;i<=N/2+1;i++){
    int res=digitsum(i)+digitsum(N-i);
    ans=min(ans,res);
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
'use strict'

/////////////////////////////////////
//コピペスペース//////////////////////

//定数
const INF  =  900719925474099 // Math.floor(Number.MAX_SAFE_INTEGER / 10);

//スペース区切りの数字列を数字の配列にして返す
function mapint(line){return line.split(' ').map((v)=>parseInt(v));}

function lower_bound(d,a,b,e){
    for(var c;1<b-a;)
        d[c=0|(a+b)/2]<e ? a=c : b=c;
    return d[a]<e?b:a
};

const N109 = 1000000000;
const MOD = N109+7;

//コピペスペース//////////////////////
/////////////////////////////////////

function Main(input){
	let s = input.trim();
	let n = s.length;

	let p = new Array(n).fill(0);
	let ans = new Array(n).fill(1);
	for(let i=0;i<n-1;i++){
		if(s[i]=='R'&&s[i+1]=='L'){
			p[i] = 1;
			p[i+1] = 1;
			i++;
		}
	}
	let j;
	for(let i=0;i<n-2;i++){
		if(p[i]==1)	continue;

		if(s[i]=='R'){
			ans[i+2] += ans[i];
			ans[i]=0;
		}
	}
	for(let i=n-1;i>1;i--){
		if(p[i]==1) continue;

		if(s[i]=='L'){
			ans[i-2] += ans[i];
			ans[i]=0;
		}
	}
	console.log(ans.join(' '));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 16176
import copy
import bisect
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
l1n=[-1 for _ in range(N)]
l2n=[-1 for _ in range(N)]
idab=0
idbc=0
buf1=[]
flag1=0
buf2=[]
flag2=0
i=0
#print(A)
#print(B)
#print(C)
exc=0
mulsum=[0]*N
"""
while i<N:
    if (idab!=N)and(A[i]>=B[idab]):
        flag1=1
        idab=idab+1
    elif flag1==1:
        l1n[i]=idab-1
        i=i+1
    else:
        i=i+1
    #print(l1n)
    #input()
#print(l1n)
i=0
while i<N:
    if (idbc!=N)and(B[i]>=C[idbc]):
        flag2=1
        idbc=idbc+1
    elif flag2==1:
        l2n[i]=idbc-1
        i=i+1
    else:
        i=i+1
    #print(l2n)
    #input()
#print(l1n,l2n)
#print(sum(l1n)+N,sum(l2n)+N)
mulsum[0]=l2n[0]+1
for i in range(N-1):
    mulsum[i+1]=mulsum[i]+(l2n[i+1]+1)
#print(mulsum)
for i in range(N):
    if l1n[i]!=-1:
        exc=exc+mulsum[l1n[i]]
        #print(exc)
print(pow(N,3)-(sum(l1n)+N)*N-(sum(l2n)+N)*N+exc)
"""
aok=0
cok=0
#Bの要素を固定してA[i]<B[j]かつB[j]<C[k]なるi,j,kの組みを探す
#print(A,B,C)
cnt=0
for i in range(N):
    piv=B[i]
    aok=bisect.bisect_right(A,piv-1)
    cok=bisect.bisect_left(C,piv+1)
    cnt=cnt+aok*(N-cok)
    #print(aok,A,cok,C)
print(cnt)



Measured memory_bytes: 115164
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;

int main() {
    int N; cin >> N;
    vector<vector<int> > inp(N);
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            int x; cin >> x;
            inp[i].push_back(x);
        }
    }
    vector<int> score(N);
    for(int g = 0; g < 3; g++) {
        unordered_map<int, int> counter;
        for(int i = 0; i < N; i++) {
            counter[inp[i][g]]++;
        }
        for(int i = 0; i < N; i++) {
            if(counter[inp[i][g]] == 1) score[i] += inp[i][g];
        }
    }

    for(int s : score) {
        cout << s << endl;
    }
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;

char str[N];
ll ans = 0,L;

inline ll read() {
	ll x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline ll lowbit(ll x) { return x & (-x); }

struct Trie {
	int ch[N][2],flag[N];
	int cnt;
	inline void Insert(char S[]) {
		int len = strlen(S + 1),pos = 0;
		For(i,1,len) {
			if(!ch[pos][S[i] - '0']) ch[pos][S[i] - '0'] = ++cnt;
			pos = ch[pos][S[i] - '0'];
		}
		flag[pos] = true;
	}
	inline void dfs(int x,int dep) {
		if(!ch[x][0]) ans ^= lowbit(L - dep);
		if(!ch[x][1]) ans ^= lowbit(L - dep);
		if(ch[x][0] && !flag[ch[x][0]]) dfs(ch[x][0],dep + 1);
		if(ch[x][1] && !flag[ch[x][1]]) dfs(ch[x][1],dep + 1);
	}
}T;

int main() {

	int n = read();L = read();
	For(i,1,n) {
		scanf("%s",str + 1);
		T.Insert(str);
	}
	T.dfs(0,0);
	puts(ans ? "Alice" : "Bob");
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void insert(vector<pair<char, int>> &v, pair<char, int> c){
    if(c.second == 0) return;
    if(v.empty() || v.back().first != c.first) v.emplace_back(c);
    else v.back().second += c.second;
}

int main() {
    vector<pair<char, int>> A, B, C;
    char c;
    int cnt = 1;
    while(cin >> c, c != '$'){
        int x; cin >> x;
        A.emplace_back(c, x);
        cnt++;
    }
    while(cin >> c, c != '$'){
        int x; cin >> x;
        B.emplace_back(c, x);
        cnt--;
    }
    while(cin >> c, c != '$'){
        int x; cin >> x;
        C.emplace_back(c, x);
    }
    int n = A.size(), m = B.size(), p = C.size();
    for (int i = 0; i < cnt; ++i) {
        int ok = 1;
        for (int j = 0; j < m; ++j) {
            if(A[i+j].first != B[j].first) {
                ok = 0;
                break;
            }
            if(j == 0 || j+1 == m){
                if(A[i+j].second < B[j].second) {
                    ok = 0;
                    break;
                }
            }else {
                if(A[i+j].second != B[j].second){
                    ok = 0;
                    break;
                }
            }
        }
        if(ok){
            for (int j = 0; j < m; ++j) {
                A[i+j].second -= B[j].second;
            }
            vector<pair<char, int>> ans;
            for (int j = 0; j <= i-(m == 1); ++j) {
                insert(ans, A[j]);
            }
            for (int k = 0; k < p; ++k) {
                insert(ans, C[k]);
            }
            for (int j = i+1-(m == 1); j < n; ++j) {
                insert(ans, A[j]);
            }
            for (auto &&l : ans) {
                cout << l.first << " " << l.second << " ";
            }
            puts("$");
            return 0;
        }

    }
    for (auto &&l : A) {
        cout << l.first << " " << l.second << " ";
    }
    puts("$");
    return 0;
}


Measured memory_bytes: 3148
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<string>
#define x first
#define y second

using namespace std;
const int N = 300050;
int n, m, a[N], vm[N], v[N];
bool st[N];

void update(int i, int u)
{
	v[i] = max(v[i], u);
	for(;i <= 300001; i += i & -i) vm[i] = max(vm[i], u);
}
int query(int l, int r)
{
	int x = 0;
	while(l <= r)
	{
		int nxt = r - (r & -r);
		if(nxt < l)
		{
			x = max(x, v[r]);
			--r;
		}
		else
		{
			x = max(x, vm[r]);
			r = nxt;
		}
	}
	return x;
}

int main()
{
	cin >> n >> m;
	for(int i = 0; i < n; ++i)
	{
		int a;
		scanf("%d", &a);
		int l = max(a + 1 - m, 1), r = min(a + 1 + m, 300001);
//		printf("a = %d, (l, r) = (%d, %d), q = %d \n", a, l, r, query(l, r));
		update(a + 1, query(l, r) + 1);
	}
	cout << query(1, 300001) << endl;
	return 0;
}


Measured memory_bytes: 6072
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N,num;
  cin >> N;

  vector<int> x(N),y(N),h(N);
  for(int i = 0;i < N;i++) {
    cin >> x.at(i) >> y.at(i) >> h.at(i);
    if(h.at(i) > 0) num = i;
  }

  for(int i = 0;i <= 100;i++) {
    for(int j = 0;j <= 100;j++) {
      int H = abs(x.at(num)-i) + abs(y.at(num)-j) + h.at(num);
      bool can = true;
      for(int k = 0;k < N;k++) {
        if(h.at(k) != 0 && H != abs(x.at(k)-i) + abs(y.at(k)-j) + h.at(k)) can = false;
        if(h.at(k) == 0 && H > abs(x.at(k)-i) + abs(y.at(k)-j)) can = false;
      }
      
      if(can) {
          cout << i << " " << j << " " << H << endl;
          return 0;
      }
    }
  }

}



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

int main() {
  long long n;
  cin >> n;
  long long sum = n*(1+n)/2;
  long long nt = n / 3;
  long long three = nt * (2*3 + (nt-1)*3)/2;
  long long nf = n / 5;
  long long five = nf * (2*5 + (nf-1)*5)/2;
  long long nft = n / 15;
  long long fifteen = nft * (2*15 + (nft-1)*15)/2;
  long long ans = sum - three - five + fifteen;
  cout << ans;
}

Measured memory_bytes: 3596
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=998244353;
const ll inf=1e18;
const ld pai=acos(-1);
int n;
ld a[3009];
ld dp[3009][3009];
ld bt(int id,int crnt){
	if(id==n){
		if(crnt>n-crnt)return (ld)1;
		return (ld)0;
	}
	ld &ret=dp[id][crnt];
	if(ret!=-1)return ret;
	ret=bt(id+1,crnt+1)*a[id]+bt(id+1,crnt)*(1-a[id]);
	return ret;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j]=-1;
		}
	}
	cout<<setprecision(9)<<fixed<<bt(0,0)<<endl;
}


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

int N;
int A[200000];
int B[200000];

signed main() {
  cin >> N;
  for(int i=0; i<N-1; i++) cin >> A[i];

  for(int i=0; i<N; i++) {
    B[A[i]-1]++;
  }
  for(int i=0; i<N; i++) cout << B[i] << endl;

}


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

#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 allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//
typedef unsigned long long ull;
const ull BASE = 1e9 + 7;
ull mul[20];

ull makeHash(const string& S) {
	int n = S.size();
	ull res = 0;
	for_(i,0,n) res = res * BASE + S[i];
	return res;
}

int N;
string S;

typedef pair< ull, ull > HashPair;
map< HashPair, lint > hash_count;

void makeHashCount() {
	for_(T,0,1<<N) {
		string X = "", Y = "";
		for_(i,0,N) {
			if ((T >> i) & 1) X += S[i]; // red
			else Y += S[i]; // blue
		}
		reverse(allof(Y));
		//cerr << X << " " << Y << endl;
		ull hashX = makeHash(X), hashY = makeHash(Y);
		hash_count[HashPair(hashX, hashY)]++;
	}
}

void solve() {
	makeHashCount();
	//cerr << "---" << endl;
	lint ans = 0;
	for_(T,0,1<<N) {
		string X = "", Y = "";
		for_(i,0,N) {
			if ((T >> i) & 1) X += S[i+N]; // red
			else Y += S[i+N]; // blue;
		}
		reverse(allof(Y));
		ull hashX = makeHash(X), hashY = makeHash(Y);
		ans += hash_count[HashPair(hashY, hashX)];
		//cerr << X << " " << Y << " " << hash_count[HashPair(hashY, hashX)] << endl;
	}
	cout << ans << endl;
}

int main() {
	cin >> N;
	cin >> S;	
	solve();
}
//--------------8---------------->> coding space <<-----------------8-------------//


Measured memory_bytes: 33024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
using namespace std;

int main()
{
    int N, P;
    cin >> N >> P;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        A[i] = A[i] & 1;
    }
    long long ans = 0;
    if (!(count(A.begin(), A.end(), 1)))
    {
        if (!P)
        {
            ans = pow(2, N);
        }
    }
    else
    {
        ans = pow(2, N - 1);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*
AizuOnline A0030
Sum of Integers
*/
#include <stdio.h>
#define DEBUG 0
#define min(x,y) (((x)>(y))?(y):(x))

int bunpai(int m,int n,int s)
{
  int i,sum;
  int minval,maxval;
#if DEBUG
  printf("m,n,s=%d,%d,%d\n",m,n,s);
#endif

  if(m == 0)
    {
      if(s == 0)
	return(1);
      else
	return(0);
    }

  minval = m*(m-1)/2;
  maxval = m*(2*n-m+1)/2;

  if(s == minval || s == maxval)
    {
#if DEBUG
    printf("*");
#endif
    return(1);
    }
  if(s < minval)
    return(0);
  if(s > maxval)
    return(0);

  sum = 0;
  for(i = m-1;i <= min(s,n);i++)
    {
      sum += bunpai(m-1,i-1,s-i);
    }
  return(sum);
}

main()
{

  int n,s; 
  while(EOF != scanf("%d %d",&n,&s) && (n || s))
    {
      printf("%d\n",bunpai(n,9,s));
    }
return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _boost ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fi first
#define se second
#define clz __builtin_clz
#define clzll __builtin_clzll
#define bp __builtin_popcount
#define _unique(x) sort((x).begin(),(x).end()),(x).erase(unique((x).begin(), (x).end()),(x.end()))
#define all(x) (x).begin(),(x).end()
#define _rand(i,j) uniform_int_distribution<int>(i, j)(rng___)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;
template < typename _T, typename _T2> string to_string(pair<_T,_T2> x) {return "<"+to_string(x.fi)+", "+to_string(x.se)+">";}
template < typename _T> string to_string(vector<_T> vec) {string s="[ "; for(auto el:vec)s+=to_string(el)+", "; s[s.size()-1]=']';s[s.size()-2]=' '; return s;}
template < typename _T> string to_string(set<_T> vec) {string s="{ "; for(auto el:vec)s+=to_string(el)+", "; s[s.size()-1]='}';s[s.size()-2]=' '; return s;}
template < typename _T, typename _T2> string to_string(map<_T,_T2> vec) {string s="{ "; for(auto el:vec)s+="mp["+to_string(el.fi)+"]= "+to_string(el.se)+", "; s[s.size()-1]='}';s[s.size()-2]=' '; return s;}
template < typename _T > inline void _DBG(const char *s, _T x){cerr << s << " = " << to_string(x) << "\n";}
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a){while(*s != ',') cerr << *s++;cerr << " = " << to_string(x) << "\n";_DBG(s + 1, a...);}
#ifdef LOCAL
#define _print(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define _print(...) ;//cout<<2;//(__VA_ARGS__)
#endif
mt19937 rng___(chrono::steady_clock::now().time_since_epoch().count());


const LL MOD = 998244353;//1e9+7;
const LL LLINF = 1e18+7;
const int N=1e5+8;

pair<int,PII> dp[3009][3009];
int main()
{
    _boost;
    string s,t;
    cin>>s>>t;
    for(int i=1;i<=s.size();i++)dp[i][0]={0,{i-1,0}};
    for(int j=1;j<=t.size();j++)dp[0][j]={0,{0,j-1}};
    for(int i=1;i<=s.size();i++)
    {
        for(int j=1;j<=t.size();j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]={dp[i-1][j-1].fi+1,{i-1,j-1}};
            }
            else if(dp[i-1][j].fi>dp[i][j-1].fi)
            {
                dp[i][j]={dp[i-1][j].fi,{i-1,j}};
            }
            else dp[i][j]={dp[i][j-1].fi,{i,j-1}};
        }
    }
    string ans="";
    PII cur={s.size(),t.size()};
    while(cur!=make_pair(0,0))
    {
        PII nxt=dp[cur.fi][cur.se].se;
        //_print(cur);
        if(nxt.fi!=cur.fi&&nxt.se!=cur.se) ans+=s[cur.fi-1];
        cur=nxt;
    }
    reverse(all(ans));
    cout<<ans;
}




Measured memory_bytes: 106112
s=list(map(int,list(input())))
so=[]
se=[]
for i in range(len(s)):
    if i%2==0:
        so.append(s[i])
    if i%2!=0:
        se.append(s[i])

tso=sum(so)
tse=sum(se)

if tso>tse:
    print(-(-len(s)//2)-tso+tse)

else:
    print(len(s)//2+tso-tse)


Measured memory_bytes: 5276
#include<iostream>
#include<string>
using namespace std;
int main(){
    int N;
    long long res=1,a=1000000007;
    cin >> N;
    for(int i=1;i<=N;i++){
        res = (res*i)%a;
    }
    cout << res << endl;
        
    return 0;
}

Measured memory_bytes: 256
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int a[N], b[N], c[N];
int par[N];

int get_root(int u);
bool merge(int u, int v);

int main() {
	fast_cin();
	int n, q; ll m;
	cin >> n >> m >> q;
	for (int i = 0; i < n; ++i) {
		par[i] = i;
	}
	bool any_cycle = false;
	ll components = n;
	for (int i = 1; i <= q; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		if (c[i] == 0) {
			components -= merge(a[i], b[i]);
		} else {
			any_cycle = true;
		}
	}
	bool ok = true;
	for (int i = 1; i <= q; ++i) {
		if (c[i] == 1) {
			if (get_root(a[i]) == get_root(b[i])) {
				ok = false;
				break;
			}
		}
	}
	ll min_edges = (any_cycle ? n : n - 1);
	ll max_edges = (n - components) + (components * (components - 1)) / 2;
	ok &= (min_edges <= m and m <= max_edges);
	if (ok) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}

int get_root(int u) {
	if (u != par[u]) {
		par[u] = get_root(par[u]);
	}
	return par[u];
}

bool merge(int u, int v) {
	u = get_root(u);
	v = get_root(v);
	if (u == v) {
		return false;
	}
	par[u] = v;
	return true;
}


Measured memory_bytes: 1792