akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=100005;

struct Bit{
	ll sum[N],dt[N];
	int n;
	
	il void ins(int p,ll v1,ll v2){
		for(;p<=n;p+=p&-p) sum[p]+=v1,dt[p]+=v2;
	}
	
	il ll qsum(int p){
		ll s1=0,s2=0;
		for(int i=p;i;i^=i&-i) s1+=sum[i],s2+=dt[i];
		return s1+s2*p;
	}
}bit;

il void ins(int l,int r,int d){
	if(l>r) return;
	bit.ins(l,-1ll*d*(l-1),d);
	bit.ins(r+1,1ll*d*r,-d);
}

il ll qsum(int l,int r){
	return bit.qsum(r)-bit.qsum(l-1);
}

int a[N],n,q;
ll tot;

int main(){
	scanf("%d%d",&q,&n);
	bit.n=n;
	rep(i,1,q) scanf("%d",a+i);
	rep(i,1,q-1){
		int x=a[i],y=a[i+1];
		tot+=(x<=y?y-x:y+n-x);
		if(x+1<y){
			ins(x+2,y,1);
			ins(y+1,y+1,x+1-y);
		}else if(x>y){
			ins(x+2,n,1);
			ins(1,1,n-x);
			ins(2,y,1);
			ins(y+1,y+1,x+1-y-n);
		}
	}
	ll mx=0;
	rep(i,1,n) getmax(mx,qsum(1,i));
	printf("%lld\n",tot-mx);
	return 0;
}


Measured memory_bytes: 2176
S = gets.chomp
N = S.size
K = gets.to_i
dp = Array.new(N+1).map{Array.new(K+1).map{Array.new(2, 0)}}
dp[0][0][0] = 1
# binding.pry
N.times do |i| # 各桁毎に
  (K+1).times do |j|
    2.times do |k|
      nd = S[i].to_i # 現在の桁の値
      10.times do |d| # 0~9の各値
        ni = i + 1 # 次の桁
        nj = j
        nk = k
        nj += 1 if d != 0
        next if nj > K
        if k == 0
          next if d > nd
          nk = 1 if d < nd
        end
        dp[ni][nj][nk] += dp[i][j][k]
      end
    end
  end
end
# p dp
ans = dp[N][K][0] + dp[N][K][1]
puts ans

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

public class C
{
    public int c { get; set; }
}

public class Info
{
    public int node { get; set; }
    public string via { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var map = new bool[n, n];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]) - 1;
            var b = int.Parse(line[1]) - 1;
            map[a, b] = true;
            map[b, a] = true;
        }
        var c = new C();
        goBfs(map, c);
        Console.WriteLine(c.c);
    }
    public static void goBfs(bool[,] map, C c)
    {
        var n = map.GetLength(0);
        var q = new Stack<Info>();
        q.Push(new Info { node = 0, via = "" });
        while (q.Count() > 0)
        {
            var a = q.Pop();
            if (a.via.Length + 1 == n && !a.via.Contains(a.node.ToString())) { c.c++; goto next; }
            for (int i = 0; i < n; i++)
                if (map[a.node, i] && !(a.via + a.node.ToString()).Contains(i.ToString()))
                    q.Push(new Info { node = i, via = a.via + a.node.ToString() });
            next:;
        }
    }
}

Measured memory_bytes: 15440
/*************************************************************************
  >         File: B.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Mon 10 Oct 2016 12:54:14 PM CST
*************************************************************************/
#include <bits/stdc++.h>

#define NO std::cout << "No" << std::endl; 
#define YES std::cout << "Yes" << std::endl;

int main() {
  std::ios::sync_with_stdio(0);
  int n, a, b;
  std::cin >> n >> a >> b;
  std::string s;
  std::cin >> s;
  int x = 0, y = 0;
  for (int i = 0; i < (int) s.size(); ++i) {
    if (s[i] == 'c') {
      NO
    }
    else if (s[i] == 'a') {
      if (x + y < a + b) {
        YES
        x++;
      }
      else {
        NO
      }
    }
    else {
      if (x + y < a + b && y < b) {
        YES
        y++;
      }
      else {
        NO
      }
    }
  }


  return 0;
}


Measured memory_bytes: 848
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void chmax(int &a, int b) { if (a < b) a = b; }

int main() {
    int N; string S; cin >> N >> S;

    int res = 0;
    vector<vector<int> > dp(N+1, vector<int>(N+1, 0));
    for (int i = N-1; i >= 0; --i) {
        for (int j = N-1; j > i; --j) {
            if (S[i] == S[j]) chmax(dp[i][j], dp[i+1][j+1] + 1);
            chmax(res, min(dp[i][j], j-i));
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 98176
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

class UnionFind{
public:
	vector<int>T;
	vector<int>p;
	UnionFind(int n){
		T.resize(n);
		p.resize(n);
		for(int i=0;i<n;i++){
			p[i]=i;
		}
	}
	
	int getParent(int n){
		if(p[n]==n)return n;
		return getParent(p[n]);
	}
	bool isSame(int n,int m){
		return getParent(n)==getParent(m);
	}
	void unite(int n,int m){
		int rx=getParent(n);
		int ry=getParent(m);
		p[rx]=ry;
	}
};
	
int main(){
	init();
	ll N;
	cin>>N;
	vector<ll>A(3*N);
	for(int i=0;i<3*N;i++){
		cin>>A[i];
	}
	//sum of [0,i)
	ll d[3*N];
	d[N]=0;
	priority_queue<ll>fque;
	for(int i=0;i<N;i++){
		d[N]+=A[i];
		fque.push(A[i]*-1);
	}
	for(int i=N;i<2*N;i++){
		d[i+1]=d[i]+A[i];
		fque.push(A[i]*-1);
		d[i+1]+=fque.top();
		fque.pop();
		//cout<<"["<<0<<","<<i+1<<")"<<d[i]<<endl;
	}
	reverse(A.begin(),A.end());
	ll e[3*N];
	e[N]=0;
	priority_queue<ll>sque;
	for(int i=0;i<N;i++){
		e[N]+=A[i];
		sque.push(A[i]);
	}
	for(int i=N;i<2*N;i++){
		e[i+1]=e[i]+A[i];
		sque.push(A[i]);
		e[i+1]-=sque.top();
		sque.pop();
	}
	ll ans=-1*INF;
	for(int i=N;i<=2*N;i++){
		ans=max(ans,d[i]-e[3*N -i]);
	}
	cout<<ans<<endl;
}


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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main() {
  int A,B,C; cin >> A >> B >> C;
  ll X,Y; cin >> X >> Y;
  if (A+B < C*2) {
    dump(A*X + B*Y);
  } else if (X > Y) {
    if (A > C*2) {
      dump(C*2*X);
    } else {
      dump((X-Y)*A + (C*2*Y));
    }
  } else {
    if (B > C*2) {
      dump(C*2*Y);
    } else {
      dump((Y-X)*B +(C*2*X));
    }
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> ac(n);
    vector<int> wa(n);
    for (int i = 0; i < m; ++i) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if (ac[p]) continue;
        if (s == "AC") {
            ac[p] = true;
        } else {
            ++wa[p];
        }
    }
    int ans_ac = 0, ans_wa = 0;
    for (int i = 0; i < n; ++i) {
        if (!ac[i]) continue;
        ++ans_ac;
        ans_wa += wa[i];
    }
    cout << ans_ac << " " << ans_wa << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

#define MOD 1000000007
int main(){
    ll n;
    cin >> n;
    ll c[n+1];
    rep(i, n)cin >> c[i+1];

    ll back[200200] = {};
    ll dp[200200] = {};
    dp[0] = 1;
    for(int i = 1; i <= n; ++i){
        if(back[c[i]] == 0)dp[i] = dp[i-1];
        else dp[i] = (dp[i-1]+dp[back[c[i]]])%MOD;
        back[c[i]] = i;
        while(c[i+1] == c[i])dp[i+1]=dp[i],i++;
    }
    // rep(i, n+1)cout << dp[i] << ", ";cout << endl;
    cout << dp[n];
    
}

Measured memory_bytes: 4992
c = [list(map(int, input().split())),
     list(map(int, input().split())),
     list(map(int, input().split()))]

if (sum(c[0]) + sum(c[1]) + sum(c[2])) % 3 != 0:
    print('No')
    exit()

if c[0][0] + c[1][1] + c[2][2] != c[2][0] + c[1][1] + c[0][2]:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long int;

// じゃんけんに勝つ手を返す
// 0・・グー
// 1・・チョキ
// 2・・パー
int f(char n) {
    switch (n)
    {
    case 'r':
        return 2;
    case 's':
        return 0;
    case 'p':
        return 1;
    }
}

int main(void)
{
    int N, K;
    int R, S, P;
    string T;

    cin >> N >> K >> R >> S >> P >> T;

    int point = 0;
    map<int, int> m;
    for (int i = 0; i < N; i++)
    {
        int hand = f(T[i]);
        m[i] = hand;
        if (i >= K)
        {
            if (m[i - K] == hand)
            {
                m[i] = -1;
                continue;
            }
        }

        if (hand == 0)
            point += R;
        else if (hand == 1)
            point += S;
        else if (hand == 2)
            point += P;
    }

    cout << point << endl;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if(a == 2 || b == 2)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  int n; cin >> n;
  // if(n >= 5){
  //   cout << 0 << endl;
  //   return 0;
  // }
  vector<vecstr > dp(n);
  dp[0].push_back("a");
  for(int i = 0 ; i < n - 1 ; i ++ ){
    for(int j = 0; j < dp[i].size(); j ++){
      string s = dp[i][j];
      char tmp = s[i];
      for(int k = 0; k < i; k++){
	tmp = max(s[k],tmp);
      }
      // for(char c = 'a'; c <= tmp + 1; c++){
      for(char c = 'a'; c <= tmp + 1; c++){
	dp[i + 1].push_back(s + c);
      }
    }
  }
  sort(all(dp[n - 1]));
  for(int i = 0; i < dp[n - 1].size(); i ++){
    cout << dp[n - 1][i] << endl;
  }
}


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

const int MAXN = 2e5 + 10;

long long a[MAXN], b[MAXN];

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        b[i] += b[i - 1];
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (a[i] > k) {
            break;
        }
        int l = 0, r = m, cur = 0;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (b[mid] + a[i] <= k) {
                cur = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        ans = max(ans, i + cur);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6744
from itertools import accumulate


def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    a = list(accumulate(A))
    answer = N

    for i in range(N - 2, -1, -1):
        if a[i] * 2 < A[i + 1]:
            answer = N - (i + 1)
            break

    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14428
#include <iostream>
#include <string>
#include <unordered_set>
#include <algorithm>
using namespace std;

typedef long long ll;

string reverse(const string& s) {
    string r;
    for(int i = s.length() - 1; i >= 0; i--) {
        r.push_back(s[i]);
    }
    return r;
}

void solve() {
    string s;
    cin >> s;
    unordered_set<string> ans;
    for(int split = 1; split < s.length(); split++) {
        string first = s.substr(0, split);
        string second = s.substr(split, s.length() - split);
        string first_r = reverse(first);
        string second_r = reverse(second);
        ans.emplace(first + second);
        ans.emplace(first + second_r);
        ans.emplace(first_r + second);
        ans.emplace(first_r + second_r);
        ans.emplace(second + first);
        ans.emplace(second_r + first);
        ans.emplace(second + first_r);
        ans.emplace(second_r + first_r);
    }
    cout << ans.size() << endl;
}

int main() {
    int m;
    cin >> m;
    for(int i = 0; i < m; i++) {
        solve();
    }
}


Measured memory_bytes: 3092
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.IntStream;

public class Main{
	public static void main(String[]$) throws IOException{
		new Main().solve();
	}
	static FastScanner s=new FastScanner(System.in);
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static int gInt() throws IOException{return s.nextInt();}
	static long gLong() throws IOException{return s.nextLong();}
	static long gDouble() throws IOException{return s.nextLong();}

	private void solve() throws IOException{
		int a=gInt(),b=gInt(),c=gInt();
		System.out.println(a==b?c:a==c?b:a);
	}

	static void yesno(boolean f) {
		yesno(f,"Yes","No");
	}
	static void yesno(boolean f,String yes,String no) {
		System.out.println(f?yes:no);
	}
}
class FastScanner{
	private final BufferedInputStream	in;
	private static final int			bufSize	=1<<16;
	private final byte					buf[]	=new byte[bufSize];
	private int							i		=bufSize;
	private int							k		=bufSize;
	private final StringBuilder			str		=new StringBuilder();

	FastScanner(InputStream in){
		this.in=new BufferedInputStream(in,bufSize);
	}
	int nextInt() throws IOException{
		return (int)nextLong();
	}
	long nextLong() throws IOException{
		int c;
		long x=0;
		boolean sign=true;
		while((c=nextChar())<=32)
			;
		if(c=='-'){
			sign=false;
			c=nextChar();
		}
		if(c=='+'){
			c=nextChar();
		}
		while(c>='0'){
			x=x*10+(c-'0');
			c=nextChar();
		}
		return sign?x:-x;
	}
	int nextChar() throws IOException{
		if(i==k){
			k=in.read(buf,0,bufSize);
			i=0;
		}
		return i>=k?-1:buf[i++];
	}
	String next() throws IOException{
		int c;
		str.setLength(0);
		while((c=nextChar())<=32&&c!=-1)
			;
		if(c==-1){
			return null;
		}
		while(c>32){
			str.append((char)c);
			c=nextChar();
		}
		return str.toString();
	}
	String nextLine() throws IOException{
		int c;
		str.setLength(0);
		while((c=nextChar())<=32&&c!=-1)
			;
		if(c==-1){
			return null;
		}
		while(c!='\n'){
			str.append((char)c);
			c=nextChar();
		}
		return str.toString();
	}
}

Measured memory_bytes: 24532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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

int main()
{   
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll res = 0;
    ll sum = 0;

    int right = 0;
    rep(left,n){
        while(right < n && ((sum ^ a[right]) == (sum + a[right])) ){
            sum += a[right];
            right++;
        }
        if(left == right) right++;
        else sum -= a[left];
        res += right - left;
    }    
    cout << res << endl;
}


Measured memory_bytes: 1920
N = gets.to_i

d = gets.split.map(&:to_i)

i = 1

cunt = 0

for num in 0 .. N-1
	if d[num] != i
		cunt += 1
	else
		i += 1
	end
end

if (d.include?(1))
  puts cunt
else
	puts -1
end

Measured memory_bytes: 15364
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

map<int,vi> link;
map<int,int> add;
vi ans;
vector<bool> visited;

void dfs(int v, int a) {
    // printf("v:%d a:%d\n",v,a);
    a += add[v];
    ans[v] += a;
    visited[v] = true;
    for(auto c : link[v]) {
        if(visited[c]) continue;
        dfs(c,a);
    }
}

int main() {
    int n,k; cin >> n >> k;
    vi A(n);
    rep(i,n) cin >> A[i];
    // k--;
    int ans = ((n-1)+(k-2)) / (k-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	
	 a := make([]int, n+1)
	 b := make([]int, n)
	 
	 for i := range a {
	 	fmt.Scan(&a[i])
	 }
	 
	 for i := range b {
	 	fmt.Scan(&b[i])
	 }
	 
	 ans := 0
	 for i := 0; i < n; i++ {
	 	if a[i] <= b[i] {
	 		ans += a[i]
	 		b[i] -= a[i]
	 		a[i] = 0
			//fmt.Printf("i=%d, ans=%d\n", i, ans)
			diff := min(b[i],a[i+1])
	 		a[i+1] -= diff
        	ans += diff
	 	} else {
	 		ans += b[i]
	 		a[i] = a[i] - b[i]
	 	}
       //fmt.Printf("i=%d, ans=%d\n", i, ans)
	 }
	 fmt.Println(ans)
}

func min(a, b int)int {
	if a < b {
		return a
	}
	return b
}

Measured memory_bytes: 6492
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define SE second
#define FI first
#define MP(x,y) make_pair(x,y)
const int MAXN = 500010;
const int MOD = 1000000007;
int to[MAXN][2],dep[MAXN];
long long no[MAXN][3];
inline void cal(int h,int n)
{
    int a=to[h][0],b=to[h][1];
    no[h][0]=no[h][1]=no[h][2]=0;
    if(h==n)
    {
        no[h][2]=1;
        return ;
    }
    no[h][2]=no[a][2]+no[b][2];
    no[h][1]=no[a][1]+no[b][1]+no[h][2];

    no[h][0]=no[h][1];
    no[h][0]=min(no[h][0],no[a][1]+no[a][2]+no[b][0]+1);
    no[h][0]=min(no[h][0],no[b][1]+no[b][2]+no[a][0]+1);
    no[h][0]=min(no[h][0],no[a][0]+1+no[b][0]+1+dep[h]);
    return ;
}
int main()
{
    //freopen("/home/moor/Code/output","r",stdin);
    int n;
    while(scanf("%d",&n)==1)
    {
        dep[1]=0;
        for(int i=1;i<=n-1;++i)
        {
            scanf("%d%d",&to[i][0],&to[i][1]);
            dep[to[i][0]]=dep[i]+1;
            dep[to[i][1]]=dep[i]+1;
        }
        for(int i=n;i>=1;--i)
            cal(i,n);
        cout<<no[1][0]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 18780
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    int mn = n+1, r = 0;
    for (int i = 0; i < n; i++) {
        int p = gi();
        if (p < mn)
            r++;
        mn = MIN(mn, p);
    }

    printf("%d\n", r);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	int x, a;
	cin >> x >> a;
	int ans = 0;
	if (x < a) ans = 0;
	else ans = 10;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    ll ans = 0LL;
    vector<ll> cal(n + 1);
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (auto t : mp)
    {
        ll val = 1LL * t.second * (t.second - 1LL) / 2LL;
        cal[t.first] = val;
        ans += cal[t.first];
    }
    for (int i = 0; i < n; i++)
    {
        ll tmp = ans - cal[a[i]];
        tmp += 1LL * (mp[a[i]] - 1) * (mp[a[i]] - 2) / 2LL;
        cout << tmp << "\n";
    }
    return 0;
}


Measured memory_bytes: 9856
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<string> temp;
  for(int i=1;i<=k;i++){
    for(size_t j=0;j<s.size();++j){
      temp.push_back(s.substr(j,i));
    }
  }
  SORT(temp);
  temp.erase(unique(temp.begin(),temp.end()),temp.end());
  cout << temp[k-1] <<endl;
  return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

typedef long double Real;

int n;
ll k;
ll a[252521];

// struct frac{
//   ll x,y;
//   frac(){x=0;y=0;}
//   frac(ll x,ll y):x(x),y(y){}
//   bool operator<(const struct &that){return x*that.y < that.x*y;}
// };
ll s[125252];

ll solve(int l,int r){
  if(r-l==1){
    return (ll)(a[l]>=0);
  }
  int mid = (l+r)/2;
  ll ret = solve(l,mid) + solve(mid,r);
  // merge
  int lena = mid-l;
  int lenb = r-mid;
  ll yo = 0;
  REP(i,lenb){
    yo += a[mid+i];
    s[i] = yo;
  }
  sort(s,s+lenb);
  // REP(i,lenb){
  //   DEBUG(s[i].first);
  //   DEBUG(s[i].second);
  // }
  yo = 0;
  REP(i,lena){
    yo += a[mid-1-i];
    ll cnt = i+1;
    int low = -1, high = lenb;
    while(low+1<high){
      int y = (low+high)/2;
      if(yo + s[y] >= 0){
        high = y;
      }else{
        low = y;
      }
    }
    ret += lenb-1-low;
    // DEBUG(mid-1-i);
    // DEBUG(yo);
    // DEBUG(cnt);
    // DEBUG(low);
    // DEBUG(lenb-1-low);
  }
  // printf("[%d,%d) -> %lld\n",l,r,ret);
  return ret;
}

int main(){
  scanf("%d%lld",&n,&k);
  REP(i,n)scanf("%lld",a+i);
  REP(i,n)a[i] -= k;
  ll ans = solve(0,n);
  printf("%lld\n",ans);
  return 0;
}


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

label=[-1]*N
Edge=[[] for _ in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    Edge[A-1].append(B-1)
    Edge[B-1].append(A-1)
out=0
for i in range(N):
    S=0
    for ii in Edge[i]:
        S=max(S,H[ii])
    if S<H[i]:
        out+=1
print(out)
# out=0
# for i in range(N):
#     if label[i]==-1:
#         S=0
#         CN=0
#         stack=[i]
#         while stack:
#             T=stack.pop()
#             label[T]=0
#             for ii in Edge[i]:
#                 if label[ii]==-1:
#                     stack.append(ii)
#                     label[ii]=0
#             if S<H[T]:
#                 S=H[T]
#                 CN=1
#             elif S==H[T]:
#                 CN=0
#         out+=CN
# print(out)

Measured memory_bytes: 93608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace _2012 {
    class Program {
        static double solve(int e) {
            int x=0,y=0,z=0,ans=1000000;
            while (z*z*z <= e) {
                y = 0;
                while (y*y <= e-z*z*z) {
                    x = e-z*z*z-y*y;
                    ans = Math.Min(x+y+z, ans);
                    y++;
                }
                z++;
            }
            return ans;
        }
        static void Main(string[] args) {
            while (true) {
                var e = int.Parse(Console.In.ReadLine());
                if (e == 0) { break; }
                Console.WriteLine(solve(e));
            }
        }
    }
}

Measured memory_bytes: 5784
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second 
int main()
{	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll n; cin>>n;
	ll a[n],f=0;
	for(ll i=0;i<n;i++) { cin>>a[i]; if(a[i]==1) f=1;}
	if(f){
	ll c=1,ans=0;
	for(ll i=0;i<n;i++)
	{
		if(a[i]==c) c++;
		else ans++;
	}
	cout<<ans<<endl;
	}
	else cout<<"-1"<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++){
    cin >> L[i];
  }
  int ans = 0;
  for (int i = 0; i < N - 2; i++){
    for (int j = i + 1; j < N - 1; j++){
      for (int k = j + 1; k < N; k++){
        if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i] && L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]) ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int N = sc.nextInt();
			while (N-- > 0) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				int b = sc.nextInt();
				int p = sc.nextInt();

				int min = x * b + y * p;
				int ans;
				if (b >= 5 && p >= 2) {
					ans = (int) (min * 0.8);
				} else {
					int div = x * b + y * p;
					while (b++ < 5) {
						div += x;
					}
					while (p++ < 2) {
						div += y;
					}
					ans = (int) (Math.min(min, div * 0.8));
				}
				System.out.println(ans);
			}
		}
	}
}

Measured memory_bytes: 23452
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        double sum = 0;
        double a = 0;
        double b = 0;
        int res = 0;
        for(int i = 0; i< n; i++){
            a = Double.parseDouble(sc.next());
            b = Double.parseDouble(sc.next());
            sum = Math.sqrt(a * a + b * b);
            if(k >= sum){
                res++;
            }
        }
        
        System.out.println(res);
    
    }
}


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

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

void add_self (int & a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}

int mul (int a, int b) {
	return (int) (((ll) a * b) % mod);
}

int power (int a, int k) {
	int ans = 1;
	while (k >= 1) {
		if (k & 1) ans = mul (ans, a);
		a = mul (a, a);
		k >>= 1;
	}
	return ans;
}

int inverse (int a) {
	return power (a, mod - 2);
}

int main() {
	int n, k, s;
	ios_base::sync_with_stdio (false);
	cin >> n >> k >> s;
	for (int i = 0; i < k; i++) {
		cout << s << " ";
	}
	int rest = (s == inf) ? 1 : inf;
	for (int i = k; i < n; i++) {
		cout << rest << " ";
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 1280
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <string>
#include <vector>
using namespace std;
 
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define reps(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
 
string n, a, b, c;
int i, j, k;

char next(char p){
    if (p == 'a') {
        ++i;
        if (i == a.size()) {
            return 'A';
        }
        else {
            return next(a[i]);
        }
    } else if (p == 'b') {
        ++j;
        if (j == b.size()) {
            return 'B';
        }
        else {
            return next(b[j]);
        }   
    } else {
        ++k;
        if (k == c.size()) {
            return 'C';
        }
        else {
            return next(c[k]);
        }   
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> a >> b >> c;

    i = -1;
    j = -1;
    k = -1;

    cout << next('a') << '\n';
    return 0;
}

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

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i = 0; i < a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

mint fanc[100010];

mint choose2(int n, int a){
    return fanc[n]/(fanc[n-a]*fanc[a]);
}

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    fanc[0]=1;
    rep(i,100010)fanc[i+1]=fanc[i]*(i+1);
    mint ans=0;
    rep(i,n){
        if(i>=k-1)ans+=choose2(i,k-1)*a[i];
        if(n-1-i>=k-1)ans-=choose2(n-1-i,k-1)*a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4588
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[100010];
	while(~scanf("%s",s)){
		int ant=0;
		for(int i=0;i<strlen(s)-1;i++){
			if(s[i]==s[i+1]){
				continue;
			}else{
				ant++;
			}
		}
		printf("%d\n",ant);
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	ll N, K, Q;
	cin >> N >> K >> Q;
	vector<ll> A(Q);
	rep(i, Q) {
		cin >> A[i];
		A[i] -= 1;
	}
	vector<ll> score(N, 0);
	//相対的にみりゃ勝ったやつが1点とってる
	//スコア+K-Q>0なら勝利（スコアは上記相対のやつ）
	rep(i, Q) {
		score[A[i]]++;
	}
	rep(i, N) {
		if (score[i] + K - Q > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

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

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int main()
{
    int n,i,j,k;
    long long unsigned ans=0,tmp1,tmp2;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            tmp1=gcd(i,j);
            for(k=1; k<=n; k++)
            {
                tmp2=gcd(tmp1,k);
                ans+=tmp2;

            }
        }

    }
    cout<<ans<<endl;

    return 0;
}






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

int main() 
{
    ulong N;
    cin>>N;

    vector<vector<ulong>> AB(10,vector<ulong>(10));

    for (ulong i = 1; i < N+1; i++)
    {
        ulong a=i;
        ulong b=i%10;
        while(a>9)
        {
            a/=10;
        } 
        AB[a][b]++;
    }
    

    ulong ans = 0;
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            ans+=AB[i][j]*AB[j][i];
        }    
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    div1 = 0
    div2 = 0
    div4 = 0
    for a in A:
        if a % 4 == 0:
            div4 += 1
        elif a % 2 == 0:
            div2 += 1
        else:
            div1 += 1
    #141
    #141...4141
    #141...414222...222
    #22
    #444...444222...222
    if div2 == 0:
        return "Yes" if div1-1 <= div4 else "No"
    else:
        return "Yes" if div1 <= div4 else "No"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 14480
#include <cstdio>

int main(){
  int n;
  scanf("%d", &n);
  int a[n];
  int ans = 0;
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
    for(int j = 0; j < i; j++){
      if(a[j] == a[i]){
        ans--;
        break;
      }
    }
    ans++;
  }
  printf("%d\n", ans);
}
  

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <bitset>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define PII pair <ll,ll>
#define N 100007
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

double dp[3001][3001], A[3001], res;

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> A[i];
    }
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            if(i == 0) {
                dp[i][j] = (j == 0)? 1.0 : 0.0;
            }
            else if(j == 0) {
                dp[i][j] = dp[i-1][j] * (1.0 - A[i]);
            }
            else if(j <= i) {
                dp[i][j] = dp[i-1][j] * (1.0 - A[i]) + dp[i-1][j-1] * A[i];
            }
            else {
                dp[i][j] = 0.0;
            }
            if(i == n && j > n/2) {
                res += dp[i][j];
            }
        }
    }
    cout << setprecision(9) << res;
    return 0;
}

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF (1 << 29)

using namespace std;

struct Point{
	double x, y;
};

int main(){
	int n, d;
	cin >> n >> d;

	vector<Point> p(n);

	for(int i = 0; i < n; i++){
		cin >> p[i].x >> p[i].y;
	}

	int cnt = 0;
	for(auto p : p){
		if(sqrt(p.x*p.x + p.y*p.y) <= d) cnt++;
	}

	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 6472
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int H, N;
        cin >> H >> N;
        vector<Int> A(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        Int sum = accumulate(all(A), 0ll);

        if (sum >= H) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

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

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

    int tmp;
    vi ans(N, 0);
    rep(i, N-1) {
        cin >> tmp;
        ans[tmp-1]++;
    }

    rep(i, N) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 4052
#include <functional>
#include <iostream>
#include <vector>

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

int main() {
  int N, M;
  std::cin >> N >> M;
  int inf = 1 << 30;
  std::vector<std::vector<int>> G(N);
  for (int i = 0; i < M; ++i) {
    int x, y;
    std::cin >> x >> y;
    G[y - 1].push_back(x - 1);
  }

  std::vector<int> dp(N, -inf);
  std::function<int(int)> rec = [&](int v) -> int {
    if (dp[v] != -inf)
      return dp[v];

    if (G[v].empty())
      return dp[v] = 0;

    int res = -inf;
    for (auto u : G[v])
      chmax(res, rec(u) + 1);
    return dp[v] = res;
  };

  int res = -inf;
  for (int v = 0; v < N; ++v)
    chmax(res, rec(v));
  std::cout << res << std::endl;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
#define RI register int
const int mod=1e9+7,N=100005;
int n,m,A,B,ans;
int fac[N<<1],ni[N<<1];
int qm(int x) {return x>=mod?x-mod:x;}
int ksm(int x,int y) {
	int re=1;
	for(;y;y>>=1,x=1LL*x*x%mod) if(y&1) re=1LL*re*x%mod;
	return re;
}
int C(int d,int u) {return 1LL*fac[d]*ni[u]%mod*ni[d-u]%mod;}
int main()
{
	scanf("%d%d%d%d",&n,&m,&A,&B);
	fac[0]=1;for(RI i=1;i<=n+m;++i) fac[i]=1LL*fac[i-1]*i%mod;
	ni[n+m]=ksm(fac[n+m],mod-2);
	for(RI i=n+m-1;i>=0;--i) ni[i]=1LL*ni[i+1]*(i+1)%mod;
	ans=C(n+m-2,n-1);
	for(RI i=1;i<=B;++i) {
		int kl=C(n-A+i-1,i-1);
		if(i>1) kl=qm(kl-C(n-A+i-2,i-2)+mod);
		ans=qm(ans-1LL*kl*C(A+m-i-1,A-1)%mod+mod);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int x,a,b;
    scan(x);
    scan(a);
    scan(b);

    auto ans = a + (x - a) / b * b;
    ans = x - ans;
    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    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: 256
import sys
#from fractions import gcd
from math import gcd
from itertools import combinations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

K = int(read())
ans = 0

for a in range(1, K + 1):
    for b in range(1, K + 1):
        acc = gcd(a, b)
        for c in range(1, K + 1):
            acc_ = gcd(acc, c)
            ans += acc_
print(ans)


Measured memory_bytes: 68896
N,K,C = map(int,input().split())
S = input()

left, right = [], []
d = 0
while d < N and len(left) < K:
    if S[d] == 'o':
        left.append(d)
        d += C + 1
    else:
        d += 1
d = N - 1
while d >= 0 and len(right) < K:
    if S[d] == 'o':
        right.append(d)
        d -= C + 1
    else:
        d -= 1
right.sort()

ans = []
for i in range(K):
    if left[i] == right[i]:
        ans.append(left[i])

for c in ans:
    print(c+1)

Measured memory_bytes: 22252
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int n;
    cin >> n;
    double v[n];
    for (int i=0; i<n; i++) {
        cin >> v[i];
    }
    sort(v, v+sizeof(v)/sizeof(v[0]));
    double kachi = 0;
    kachi += v[0]/pow(2,n-1);
    for (int i=1; i<n; i++) {
        kachi += v[i]/pow(2,n-i);
    }
    cout << kachi << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
ll mod=1000000007 ;
int main() {

    ll n ,i;
    scanf("%lld",&n) ;
    ll a[n+10] ,ans=0;
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]) ;

    for(i=0;i<62;i++){
            ll ck = (1LL<<i) ;
            ll on=0 ;
            for(ll j=0;j<n;j++) if(a[j]&ck) on++ ;
            ck%=mod ;
            ll to = (on*(n-on) ) %mod ;
            ans+= (to*ck) ;
            ans%=mod ;
          //  cout << i << ' ' << to << endl  ;

    }
    cout << ans%mod << endl ;


}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long long int ll;
typedef long double  ld;
using namespace std;
const int M=1e9+7;
int main()
{
   ll c;cin>>c;
   ll ans=0;
   ans=c/500;
   c-=ans*500;
   ans=ans*1000;
   ans+=((c/5)*5);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define N 100010

using namespace std;

int r,c,n,top;
int s[N<<1],cnt[4];
struct data{int o,d;}f[4][N];

bool operator<(data a,data b){return a.d<b.d;}

bool check(int x,int y){return (x==0 || x==r || y==0 || y==c);}

void put(int x,int y,int o){
	if(y==0 && x!=0){f[0][++cnt[0]].o=o; f[0][cnt[0]].d=x;}
	if(y!=0 && x==r){f[1][++cnt[1]].o=o; f[1][cnt[1]].d=y;}
	if(y==c && x!=r){f[2][++cnt[2]].o=o; f[2][cnt[2]].d=r-x;}
	if(y!=c && x==0){f[3][++cnt[3]].o=o; f[3][cnt[3]].d=c-y;}
}

bool solve(){
	int i,j;
	for(i=0;i<4;i++)
		for(j=1;j<=cnt[i];j++)
		if(f[i][j].o==s[top]) top--; else s[++top]=f[i][j].o;
	return !top;
}

int main(){
	int i,x1,y1,x2,y2;
	scanf("%d%d%d",&r,&c,&n);
	
	for(i=1;i<=n;i++){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(check(x1,y1) && check(x2,y2)){put(x1,y1,i); put(x2,y2,i);}
	}
	for(i=0;i<4;i++) sort(f[i]+1,f[i]+cnt[i]+1);
	
	if(solve()) puts("YES"); else puts("NO");
	return 0;
}

Measured memory_bytes: 2048