akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

ll mod = 1000003;

// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
long long unsigned int PowMod( long long unsigned int base, long long unsigned int index, long long unsigned int modulo = mod ){
    if( index == 0 ) return 1;
    // O( log(index) )
    if( index % 2 ){
        return base * PowMod(base, index - 1, modulo) % modulo;
    }else{
        long long unsigned int Phalf = index / 2;
        long long unsigned int half = PowMod(base, Phalf, modulo);
        return half * half % modulo;
    }
}
// }}}

int main() {

    int Q;
    Scd(Q);

    vector< ll > fac(mod+3);

    fac[0] = 1;
    ll ii = 1;
    Rep(i,mod){
        fac[i+1] = fac[i] * (ii++);
        fac[i+1] %= mod;
    }

    ll x,d,n;
    Rep(i,Q){
        Scll3(x,d,n);

        if( d == 0 ) printf ("%llu\n", PowMod(x,n) );
        else{
            int k = 0;
            k = x * PowMod( d, mod-2 ) % mod;
            if( k + n - 1> mod ) printf ("0\n");
            else{

                ll ans;
                ans = fac[n+k-1] % mod;
                ans = ans * PowMod( d, n ) % mod;
                ans = ans * PowMod( fac[k-1], mod-2 ) %mod;


                printf ("%llu\n", ans );

            }
        }

    }

    return 0;
}



Measured memory_bytes: 8704
#include <stdio.h>

using namespace std;

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x >= r && x <= W-r) && (y >= r && y <= H-r))
		printf("Yes\n");
	else{
		printf("No\n");
	}
}



Measured memory_bytes: 2684
import java.util.*;

public class Main {
    private final static int M = 1000000007;

    private static long solve(int N, int[][] edges) {
        List<Integer>[] adj = new List[N];
        int[] degree = new int[N];

        for (int i = 0; i < N; i++) adj[i] = new ArrayList<>();
        for (int[] edge: edges) {
            adj[edge[0]-1].add(edge[1]-1);
            adj[edge[1]-1].add(edge[0]-1);
            degree[edge[0]-1] += 1;
            degree[edge[1]-1] += 1;
        }

        long[] white = new long[N];
        long[] black = new long[N];
        Arrays.fill(white, 1);
        Arrays.fill(black, 1);
        
        boolean[] done = new boolean[N];
        boolean[] added = new boolean[N];
        Queue<Integer> q = new ArrayDeque<>();

        for (int i = 0; i < N; i++)
            if (degree[i] < 2) {
                q.add(i);
            }

        int node = -1;
        while (!q.isEmpty()) {
            node = q.poll();

            for (int next: adj[node]) {
                if (done[next]){
                  white[node] = (white[node] * ((white[next] + black[next])%M)) % M;
                  black[node] = (black[node] * white[next]) % M;
                } else {
                  degree[next] -= 1;

                  if (degree[next] < 2 && !added[next]) {
                    q.add(next);
                    added[next] = true;
                  }
                }
            }
            done[node] = true;            
        }
      
        return  (white[node] + black[node]) % M;
    }

    public static long run(Scanner scanner) {
        int N = scanner.nextInt();
        int[][] edges = new int[N-1][2];
        for (int i=0; i < N-1; i++)
            edges[i] = new int[] { scanner.nextInt(), scanner.nextInt() };

        return solve(N, edges);
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println(run(scanner));
        }
        //Tests.run();
    }
}


Measured memory_bytes: 104436
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	cout<<max({a+b,a-b,a*b})<<endl;
}


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

int c(string a){
	a[2] = ' ';
	stringstream ss(a);
	int h,m;
	ss >> h >> m;
	return h * 60 + m;
}
vector< pair<int,int> > ls,tc,ch;
int main(){
	int a;
	cin >> a;
	for(int i = 0 ; i < a ; i++){
		string s;
		cin >> s;
		s[5] = ' ';
		stringstream ss(s);
		string x,y;
		ss >> x >> y;
		ls.push_back({c(x),c(y)});
	}
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		int k;
		cin >> k;
		while(k--){
			string s;
			cin >> s;
			s[5] = ' ';
			stringstream ss(s);
			string x,y;
			ss >> x >> y;
			tc.push_back({c(x),c(y)});	
		}
	}
	int m;
	cin >> m;
	for(int i = 0 ; i < m ; i++){
		int k;
		cin >> k;
		while(k--){
			string s;
			cin >> s;
			s[5] = ' ';
			stringstream ss(s);
			string x,y;
			ss >> x >> y;
			ch.push_back({c(x),c(y)});	
		}
	}
	int ans = 0;
	for(int i = 0 ; i < ls.size() ; i++){
		int x = 0 , y = 0;
		for(int j = 0 ; j < tc.size() ; j++){
			if( tc[j].first <= ls[i].first && ls[i].second <= tc[j].second )
				x++;
		}
		for(int j = 0 ; j < ch.size() ; j++){
			if( ch[j].first <= ls[i].first && ls[i].second <= ch[j].second )
				y++;
		}
		ans += min(x,y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1428
A = []
for i in range(3):
  A.append(list(map(int, input().split())))
n = int(input())
for k in range(n):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = 0
if A[0][0]==A[0][1]==A[0][2]==0 or A[1][0]==A[1][1]==A[1][2]==0 or A[2][0]==A[2][1]==A[2][2]==0 or A[0][0]==A[1][0]==A[2][0]==0 or A[0][1]==A[1][1]==A[2][1]==0 or A[0][2]==A[1][2]==A[2][2]==0 or A[0][0]==A[1][1]==A[2][2]==0 or A[2][0]==A[1][1]==A[0][2]==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(A: int, B: int):

    for i in range(2000):
        if int(i * 0.08) == A \
           and int(i*0.1) == B:
            print(i)
            return
    print(-1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>

int gcd(int a, int b);
int main(void)
{
	int a, b;
	
	while (scanf("%d", &a) != EOF){
		scanf("%d", &b);
				
		printf("%d %d\n", gcd(a, b), a / gcd(a, b) * b);
	}
	
	return (0);
}

int gcd(int a, int b)
{
	int temp;
	
	if (a <= b){
		temp = a;
		a = b;
		b = temp;
	}
	
	while (1){
		if (b == 0){
			return (a);
		}
		
		temp = b;
		b = a % b;
		a = temp;
	}
}

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

int main() 
{
	map<int, int> m;
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		int x;cin >> x;
		m[x]++;
	}
	if(m.size()%2)
		cout << m.size();
	else
		cout << m.size()-1;
	return 0;
}

Measured memory_bytes: 4992
import sys
import collections
import bisect


def main():
    n, k = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x: x[0])
    cnt = 0
    for i in range(len(ab)):
        cnt += ab[i][1]
        if cnt >= k:
            print(ab[i][0])
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 28896
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int t;
	if(n <= k) printf("Yes\n");
	else if(n % 500 == 0) printf("Yes\n");
	else if(n%500 <= k) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main() {
	string S;
	cin >> S;
	char stone='0';
	int counter = -1;
	for (char c : S) {
		if (c != stone) counter++;
		stone = c;
	}
	cout << counter << endl;
	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int a[4] = {};
    int ans = 0;
    rep(i,4){ char ch; cin >> ch; a[i] = ch-'0'; }

    for(int bit = 0; bit < (1<<3); bit++) {
        ans = a[0];
        for(int i = 0; i < 3; i++) {
            if(bit & (1<<i)) ans += a[i+1];
            else ans -= a[i+1];
            //debug(a[i+1]);
        }
        //debug(ans);
        if(ans == 7) {
            cout << a[0] << (bit&(1<<0)?'+':'-');
            cout << a[1] << (bit&(1<<1)?'+':'-');
            cout << a[2] << (bit&(1<<2)?'+':'-');
            cout << a[3] << '=' << 7 << '\n';
            goto XX; 
        }
    }
    XX: return 0;
}

Measured memory_bytes: 256
s = int(input())

def f(n):
    if n % 2 == 0: return n//2
    else: return 3*n + 1

memo = [False]*(10**6+1)
memo[s] = True
prev = s
for m in range(2,10**6+1):
    now = f(prev)
    if memo[now] == True:
        print(m)
        break
    else:
        memo[now] = True
    prev = now


Measured memory_bytes: 46064
/********************/
/* K B G D E L T A */
/*     DA-IICT      */
/********************/
 
#include<bits/stdc++.h>
using namespace std;
using   ll=long long;
using   ld=long double;
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define F(i,n)         for(ll i=0;i<n;i++)
#define rep(i,a,b)     for(ll i=a;i<b;i++)
#define repp(i,a,b)    for(ll i=a;i>=b;i--)
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
#define N              1e6+1
 
void solve()
{
	ll n,k,q,sum=0,x;
	
	cin>>n>>k>>q;
	
	vector<ll> a(n+1,0);
	
	while(q--)
	{
		cin>>x;
		a[x]++;
		sum++;
	}
	
	for(int i=1;i<=n;i++)
	{
		if(k+a[i]-sum<=0)
		{
			cout<<"No\n";
		}
		else
		{
			cout<<"Yes\n";
		}
	}
}
 
signed main(){
 
    fast;
 
    ll t=1;
    
    //cin>>t;
 
    while(t--)
    {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(void){
    double r;
    double s;
    double l;
    double pi = 3.141592653589793;
    scanf("%lf",&r);
    s =pi*r*r;
    l =pi*2*r;
    printf("%f %f\n",s,l);
    return 0;
}


Measured memory_bytes: 2044
N = int(raw_input())
a = map(int, raw_input().split())

dp = [0]*N

if a[0] == 1:
    dp[0] = 1

for i in range(N-1):
#    print i, a[i+1], dp[i]                                                                            
    if a[i+1] == dp[i] + 1:
        dp[i+1] = dp[i] + 1
    else:
        dp[i+1] = dp[i]


ans = N - dp[-1]
if ans > N -1:
    print "-1"
else:
    print ans


Measured memory_bytes: 21760
#!/usr/bin/env ruby

attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end
X = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
N = attrs[0][0]

puts X[N.to_i-1]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int SIZ = s.size();
  bool N,E,W,S;
  N = E = W = S = false;
  for(int i = 0;i < SIZ;i++){
    if(s[i] == 'W')W = true;
    if(s[i] == 'E')E = true;
    if(s[i] == 'S')S = true;
    if(s[i] == 'N')N = true;
    if(N == true && E == true && W == true && S == true)break;
  }
  if(N == true && E != true && W != true && S == true)cout << "Yes" << endl;
  else if(N != true && E == true && W == true && S != true)cout << "Yes" << endl;
  else if(N == true && E == true && W == true && S == true)cout << "Yes" << endl;
  else cout << "No" << endl;
}
    

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

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    char x;
    cin >> x;
    if(x >= 65 && x <= 91)
        cout << 'A';
    else
        cout << 'a';
}









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

int main() {
    int n; cin >> n;
    int a[n];
    vector<int> buka(n, 0);
    rep(i, n-1){
        cin >> a[i];
        buka[a[i]-1]++;
    } 
    rep(i, n) cout << buka[i] << endl;
    

}

Measured memory_bytes: 4764
import java.util.Scanner
import java.lang.Math.*

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val s = scn.next()
	val arr = Array(3){ mutableListOf<Int>() }
	s.forEachIndexed{i, c ->
		val t = when(c){'R'->0 'G'->1 else->2}
		arr[t].add(i)
	}
	arr.sortBy{it.size}
	var ans = 0L
	arr[0].forEach { r ->
		arr[1].forEach { g ->
			val b1 = min(r, g) - abs(r-g)
			val b2 = max(r, g) + abs(r-g)
			val b3 = if((r-g)%2==0) (r+g)/2 else -1
			var bcnt = arr[2].size
			if (arr[2].binarySearch(b1)>=0) bcnt--
			if (arr[2].binarySearch(b2)>=0) bcnt--
			if (arr[2].binarySearch(b3)>=0) bcnt--
			ans+=bcnt
		}
	}
	println(ans)
}

Measured memory_bytes: 58388
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
static const double PI = 3.141592653589793;
const ll INF = 100000000000000;
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;

vector<vector<ll>> vec(100005);
ll p(ll n, ll r) {
	ll a = 1;
	for (ll i = 0; i < r; i++) {
		a *= (n - i) % mod;
		a %= mod;
	}
	return a % mod;
}
ll k;
ll dfs(int x, int b) {
	if (vec[x].size() >= k )return 0;
	ll sum = 1;
	sum *= p(k - 2, vec[x].size() - 1);
	sum %= mod;
	for (int y : vec[x]) {
		if (y != b) {
			sum *= dfs(y, x);
			sum %= mod;
		}
	}
	return sum%mod;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll a, b, n;
	cin >> n >> k;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	ll sum = (k*p(k - 1, vec[1].size())%mod) % mod;
	if (vec[1].size() >= k)sum = 0;
	for (int y : vec[1]) {
		sum *= dfs(y, 1);
		sum %= mod;
	}

	cout << sum % mod << endl;
	return 0;
}


Measured memory_bytes: 10368
n = int(input())

if n == 0:
    print(0)
    exit()

s = ""

while True:
    if n == 0:
        break
    if n%2 == 0:
        s += "0"
        n = n//(-2)
    else:
        s += "1"
        n = (n-1)//(-2)

print(s[::-1])


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

struct pable {
    int up, down, left, right;
    pable(int up, int down, int left, int right)
        : up(up), down(down), left(left), right(right) {}
    pable() {}
};

pable square[202];
int N, n, d;
bool is_search[202];

pable solve(int x, pable p) {
    //cout << "now is " << x << endl;    
    is_search[x] = true;
    pable tmp, ret = p;
    if (square[x].left != -1 && is_search[square[x].left] == false) {
        tmp = solve(square[x].left, pable(p.up, p.down, p.left + 1, p.right - 1));
        if (ret.up < tmp.up) ret.up = tmp.up;
        if (ret.down < tmp.down) ret.down = tmp.down;
        if (ret.left < tmp.left) ret.left = tmp.left;
        if (ret.right < tmp.right) ret.right = tmp.right;
    }
    if (square[x].right != -1 && is_search[square[x].right] == false) {
        tmp = solve(square[x].right, pable(p.up, p.down, p.left - 1, p.right + 1));
        if (ret.up < tmp.up) ret.up = tmp.up;
        if (ret.down < tmp.down) ret.down = tmp.down;
        if (ret.left < tmp.left) ret.left = tmp.left;
        if (ret.right < tmp.right) ret.right = tmp.right;
    }
    if (square[x].up != -1 && is_search[square[x].up] == false) {
        tmp = solve(square[x].up, pable(p.up + 1, p.down - 1, p.left, p.right));
        if (ret.up < tmp.up) ret.up = tmp.up;
        if (ret.down < tmp.down) ret.down = tmp.down;
        if (ret.left < tmp.left) ret.left = tmp.left;
        if (ret.right < tmp.right) ret.right = tmp.right;
    }
    if (square[x].down != -1 && is_search[square[x].down] == false) {
        tmp = solve(square[x].down, pable(p.up - 1, p.down + 1, p.left, p.right));
        if (ret.up < tmp.up) ret.up = tmp.up;
        if (ret.down < tmp.down) ret.down = tmp.down;
        if (ret.left < tmp.left) ret.left = tmp.left;
        if (ret.right < tmp.right) ret.right = tmp.right;
    }
        
    return ret;
}

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

    while (cin >> N, N) {
        fill(square, square + N, pable(-1, -1, -1, -1));
        memset(is_search, false, sizeof(is_search));
        for (int i = 0; i < N-1; ++i) {
            cin >> n >> d;
            if (d == 0) {
                square[n].left = i+1;
                square[i+1].right = n;
            } else if (d == 1) {
                square[n].down = i+1;
                square[i+1].up = n;
            } else if (d == 2) {
                square[n].right = i+1;
                square[i+1].left = n;
            } else if (d == 3) {
                square[n].up = i+1;
                square[i+1].down = n;
            }
        }
        pable ans = solve(0, pable(0, 0, 0, 0));
        int width, height;
        width = ((ans.left > 0) ? ans.left : 0) + ((ans.right > 0) ? ans.right : 0) + 1;
        height = ((ans.up > 0) ? ans.up : 0) + ((ans.down > 0) ? ans.down : 0) + 1;
        //cout << "ans is ";
        cout << width << " " << height << endl;
    }

    return 0;
}

Measured memory_bytes: 3172
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);
    vector<ll> C(N+1), D(N+1);
    for(int i=0; i<N; i++) {
        int v; scanf("%d", &v);
        C[v]++;
    }
    for(int i=1; i<=N; i++) D[ C[i] ]++;

    vector<ll> S1(N+2), S2(N+2);
    for(int i=1; i<=N; i++) {
        S1[i+1] = S1[i] + i * D[i];
    }
    for(int i=N; i>=1; i--) {
        S2[i] = S2[i+1] + D[i];
    }

    vector<ll> F;
    for(int i=1; i<=N; i++) {
        F.emplace_back((S1[i] + i * S2[i]) / i);
    }

    /*
    for(int i=0; i<N; i++) fprintf(stderr, "%lld ", F[i]);
    fprintf(stderr, "\n");
    */

    int ptr = N-1;
    for(int i=1; i<=N; i++) {
        while(ptr >= 0 and F[ptr] < i) ptr--;
        printf("%d\n", ptr + 1);
    }
    return 0;
}


Measured memory_bytes: 15856
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int h = Integer.parseInt(scanner.next());
        int a = Integer.parseInt(scanner.next());

        int tmp_int = 1;
        for (int i=a; i < h; i+=a) {
            tmp_int++;
        }
        System.out.println(tmp_int);
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;

bool isPrimary(int num) {
    return(num % 2 != 0 && num % 13 != 0);
}
char calc(int a, int b, char chr) {
    int num = chr - 'a';
    char ret = 'a' + ((num * a + b) % 26);
    return(ret);
}

int main(void) {
    int num; string input;
    cin >> num; //cout << num << endl;
    cin.ignore(1, '\n');
    for(int r = 0; r < num; r++) {
        getline(cin, input); //cout << input << endl;
        bool found = false;
        for(int a = 0; !found; a++) {
            if(!isPrimary(a)) continue;
            for(int b = 0; b < 26 && !found; b++) {
                for(int r = 0; r < input.length(); r++) {
                    if(!isalpha(input[r])) continue;
                    input[r] = calc(a, b, input[r]);
                }
                if((input.find("this") != string::npos) || (input.find("that") != string::npos)) {
                    found = true;
                }
            }
        }
        cout << input << endl;
    }
    return(0);
}

Measured memory_bytes: 1204
/* in the name of Anton */

/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#ifdef ARYANC403
    #include "/home/aryan/codes/PastCodes/template/header.h"
#else
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
    #pragma GCC optimize ("-ffloat-store")
    #include<iostream>
    #include<bits/stdc++.h>
    #define dbg(args...)
#endif

using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;


const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
#ifdef ARYANC403
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
#endif
}

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a,b;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    n=T;
    a.clear();b.clear();
    cin>>n;
    repA(i,1,n)
    {
        in=i;
        cin>>in;
        if(i&1)
            a.pb(in);
        else
            b.pb(in);
    }

    if(n&1)
    {
        reverse(all(a));
    }
    else
    {
        reverse(all(b));
        a.swap(b);
    }

    for(auto x:a)
        cout<<x<<" ";
    for(auto x:b)
        cout<<x<<" ";
    cout<<endl;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 5172
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;
int main(){
	int a,b,ans;
	cin>>a>>b;
	ans=(a+b)/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3048
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N;
vi A;

int main(){
    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];

    int amin = *min_element(all(A));
    int amax = *max_element(all(A));

    int ans = INF;
    rep(n, amin, amax + 1) {
        int sqsum = 0;
        rep(i, N) sqsum += (n - A[i]) * (n - A[i]);
        chmin(ans, sqsum);
    }

    write(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//4/
typedef unsigned long long ull;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i < (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fill_2(a,b)  memset(a, 0, sizeof (a));memset(b, 0, sizeof (b));
#define fill_n(a) memset(a,-1,sizeof(a))
#define fst first
#define snd second
#define mpr make_pair
#define pb push_back
#define mod 1000000007
#define endl "\n"
//#define int long long
 
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, pii> pip;
typedef pair<pii, ll> ppi;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<ll,ll> mpl;
 
inline ll exp(ll x,ll n){ll r=1;x=x%mod;while(n){if(n%2)r=(r*x)%mod;x=(x*x)%mod;n=n/2;}return r;}
inline ll mmi(ll a){return exp(a,mod-2)%mod;}
inline ll fact(ll n){ll res=1;repA(i,1,n+1){res=(res*i)%mod;}return res;}
inline ll inv_fact(ll n){ll par=fact(n);ll res=mmi(par);return res;}

struct triplet{ll a,b,c;};
bool operator < (const triplet &t1,const triplet &t2){
	if(t1.a<t2.a)return true;
	if(t1.a==t2.a && t1.b <t2.b)return true;
	if(t1.a==t2.a && t1.b ==t2.b && t1.c<t2.c)
		return true;return false;}
 

pair<ll,pii > ex_gcd(ll a,ll b)
{   if(b==0){return mpr(a,mpr(1,0));}
    pip p=ex_gcd(b,a%b);
	ll gcd=p.fst;ll x1=p.snd.fst;ll y1=p.snd.snd;
    ll x=y1;ll y=x1-(a/b)*y1;
	return mpr(gcd,mpr(x,y));
} 


int main()
{
	IOS;
	ll x,y,a,b,c;
	//cout<<"hi"<<endl;
	cin>>x>>y>>a>>b>>c;
	ll sum=x+y;
	ll p[a];
	ll q[b];
	ll r[c];
	//cout<<"ip"<<endl;
	repA(i,0,a) cin>>p[i];
	repA(i,0,b)  cin>>q[i];
	repA(i,0,c)  cin>>r[i];
    //cout<<"hello"<<endl;
	ll rr=0;
	ll bb=0;
	ll n=0;
	 vector<pair<ll,ll> > v;
	 repA(i,0,a)
	 {
	 	v.pb(mpr(p[i],0));
	 }
	 repA(i,0,b)
	 {
	 	v.pb(mpr(q[i],1));
	 }
	 repA(i,0,c)
	 {
	 	v.pb(mpr(r[i],2));
	 }
	 sort(v.rbegin(),v.rend());
	 ll ans=0;
	 ll idx=0;
	 //vector<pair<ll,ll> > vv;
	 while(rr+bb+n< sum)
	 {   //cout<<v[idx].fst<<" "<<v[idx].snd<<endl;

          if(rr<x && v[idx].snd==0)
          	{rr++;ans+=v[idx].fst;}
          else if(bb<y && v[idx].snd==1)
          	 {bb++;ans+=v[idx].fst;}
          else if(v[idx].snd==2)
          	 {n++;ans+=v[idx].fst;}
         //cout<<rr<<" "<<bb<<" "<<n<<endl;
          //vv.pb(mpr(v[i].fst,v[i].snd));
          //ans+=v[idx++].fst;
          	idx++;
	 }
	 cout<<ans<<endl;


}

Measured memory_bytes: 12908
#include<bits/stdc++.h>
using namespace std;
int main()
{
   // freopen("inputfile.txt","r",stdin);
    int t;cin>>t;
   int a=0,b=0,c=0,d=0;
    while(t--)
    {
        string s;cin>>s;
        if(s=="AC")a++;
        else if(s=="WA")b++;
        else if(s=="TLE")c++;
        else d++;
    }
    printf("AC x %d\n",a);
    printf("WA x %d\n",b);
    printf("TLE x %d\n",c);
    printf("RE x %d\n",d);
    return 0;
}


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

namespace abc160_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());

            //500円硬貨1枚と5円硬貨100枚は同じ価値ではない
            //できる限り500円硬貨を手に入れた方が嬉しさが高くなる
            Console.WriteLine(((X / 500) * 1000) + (((X % 500) / 5) * 5));

            Console.Read();
        }
    }
}


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

int main() {
    int N;
    cin >> N;
    
    int cnt = 0;
    rep(i, N) {
        int temp;
        temp = (int)log10(i+1) + 1;
        if(temp%2) cnt++;
    }

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

Measured memory_bytes: 256
def shortests(n, x, y):
	short_lengths = {}
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			shortest = min(j - i, abs(i - x) + abs(j - y) + 1, abs(i - y) + abs(j - x) + 1)
			if shortest in short_lengths:
				short_lengths[shortest] += 1
			else:
				short_lengths[shortest] = 1
	for leng in range(1, n):
		if leng not in short_lengths:
			print(0)
		else:
			print(short_lengths[leng])

inputs = input().split(' ')
inputs = [int(x) for x in inputs]
n = inputs[0]
x = inputs[1]
y = inputs[2]

shortests(n, x, y)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
int main() {
    using namespace std;
    int t;
    cin>>t;
    if (t>399&&t<600)
        cout<<8;
    else if (t>599&&t<800)
        cout<<7;
    else if (t>799&&t<1000)
        cout<<6;
    else if (t>999&&t<1200)
        cout<<5;
    else if (t>1199&&t<1400)
        cout<<4;
    else if (t>1399&&t<1600)
        cout<<3;
    else if (t>1599&&t<1800)
        cout<<2;
    else if (t>1799&&t<2000)
        cout<<1;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

#define N 100

void insertionSort(int *, int);

int main()
{
  int i,n;
  int A[N];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
    for(i=0;i<n;i++)
    {
        printf("%d",A[i]);
        if(i!=n-1)
        printf(" ");
      }
      printf("\n");
  insertionSort(A,n);
}

void insertionSort(int *a,int n)
{
  int i,j,k,v;
  for(i=1;i<=n-1;i++)
    {
      v = a[i];
      j = i - 1;
      while((j >= 0) && (a[j] > v))
        {
          a[j+1] = a[j];
          j--;
        }
      a[j+1] = v;
      for(k=0;k<n;k++)
      {
          printf("%d",a[k]);
          if(k!=n-1)
          printf(" ");
        }
      printf("\n");
    }

}


Measured memory_bytes: 2068
from collections import deque

class Graph(): #non-directed
    def __init__(self, n, edge, indexed=1):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0] - indexed].append(e[1] - indexed)
            self.graph[e[1] - indexed].append(e[0] - indexed)
            self.deg[e[0] - indexed] += 1
            self.deg[e[1] - indexed] += 1

N, M = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]

g = Graph(N, E)
used = [0 for _ in range(N)]

res = deque([E[0][0], E[0][1]])
used[res[0] - 1] = 1
used[res[-1] - 1] = 1

flag_lt = True
flag_rt = True
while flag_lt or flag_rt:
    lt = res[0] - 1
    rt = res[-1] - 1
    if flag_lt:
        for adj in g.graph[lt]:
            if not used[adj]:
                used[adj] = 1
                res.appendleft(adj + 1)
                break
        else:
            flag_lt = False
    if flag_rt:
        for adj in g.graph[rt]:
            if not used[adj]:
                used[adj] = 1
                res.append(adj + 1)
                break
        else:
            flag_rt = False

print(len(res))
print(*res)

Measured memory_bytes: 107824
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int N;cin>>N;
  int p, m=200001, ans=0;
  rep(i,N){
    cin>>p;
    if(p<m)ans++;
    m = min(m, p);
  }
  cout<<ans<<endl;
}

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

struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  void print(){
    for(auto x:par)
        cout<<x<<" ";
    cout<<endl;
  }
};
int main(){
    int n,m;
    cin>>n>>m;
    vector<int[2]> sides(m);
    for(int i = 0; i<m; i++)
        cin>>sides[i][0]>>sides[i][1];
    int count=0;
    for(int i = 0; i<m; i++){
        UnionFind un(n);
        for(int j = 0; j<m; j++){
            if(j==i)
                continue;
            un.unite(sides[j][0]-1,sides[j][1]-1);
        }
        if(!un.same(sides[i][0]-1,sides[i][1]-1))
            count++;
    }
    cout<<count;
}

Measured memory_bytes: 256
let n, a, b =
  let l = stdin.ReadLine().Split(' ') |> Array.map int
  l.[0], l.[1], l.[2]

let s = stdin.ReadLine()

[0 .. s.Length - 1]
|> List.scan (
    fun (pass, bCnt, msg) i ->
    let c = s.[i]
    match c with
    | 'a' ->
      if pass < a + b then
        (pass + 1, bCnt, "Yes")
      else
        (pass, bCnt, "No")
    | 'b' ->
      if pass < a + b && bCnt < b then
        (pass + 1, bCnt + 1, "Yes")
      else
        (pass, bCnt + 1, "No")
    | _ ->
        (pass, bCnt, "No")
  ) (0, 0, "")
|> List.iter (fun (_, _, msg) -> stdout.WriteLine msg)

Measured memory_bytes: 30928
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
V<ll> a,sum;
 ll n,m;
 bool dbag;
bool C(ll mid){
    ll cnt=0,res=0;
    ll d;
    for(int i=0;i<n;i++){
        d=mid-a[i];
        ll t=a.end()-lower_bound(all(a),d);
        cnt+=t;
    }
    if(cnt>=m){
        return true;
    }
    return false;
}
ll make(ll mid){
    ll cnt=0,res=0,d;
for(int i=0;i<n;i++){
        d=mid-a[i];
        ll t=a.end()-lower_bound(all(a),d);
        cnt+=t;
        res+=a[i]*t+sum[n]-sum[n-t];
        }
        return res-mid*(cnt-m);// 被りの処理,cntはmを下回らない m<=n^2が制約であるため
    }
int main(){
 cin>>n>>m;
 a.resize(n),sum.assign(n+1,0);
 for(int i=0;i<n;i++)cin>>a[i];
 sort(all(a));
 for(int i=0;i<n;i++)sum[i+1]=a[i]+sum[i];
 //for(int i=0;i<n;i++)cout<<a[i]<<" ";
 //cout<<endl;
 ll ok=0,ng=1e18,mid;
 while(ng-ok>1){
     mid=(ok+ng)/2;
    if(C(mid))ok=mid;
    else ng=mid;
 }
 cout<<make(ok)<<endl;
}



Measured memory_bytes: 1920
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(void){
    vvi a(3, vi(3));
    for(vi &vr : a) for(int &v : vr) cin >> v;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        int b;
        cin >> b;
        for(vi &vr:a)for(int &v:vr)if(b==v) v = 0;
    }
    bool suc = false;
    for(int i=0; i<3; i++){
        if(a[i][0]==0 && a[i][1]==0 && a[i][2]==0) suc = true;
        if(a[0][i]==0 && a[1][i]==0 && a[2][i]==0) suc = true;
    }
    if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0) suc = true;
    if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0) suc = true;
    if(suc)cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

struct res{
    ll w,l;
};

bool asc( const res& left, const res& right ) {
    return left.w == right.w ? left.l < right.l : left.w < right.w;
}

struct numdep{
    ll num;
    ll dep = 0;
};
static const ll MAX = 100001;
vector <numdep> children[MAX];
ll parent[MAX] = {};
ll dep[MAX] = {};

void calcD (ll s){
    vector <ll> v;
    for (ll i=0;i<children[s].size();i++){
        if(dep[children[s][i].num] == 0){
            calcD(children[s][i].num);
        }
        v.push_back(dep[children[s][i].num]);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    ll ret = 0;
    for(ll i=0;i<v.size();i++){
        if(ret < v[i] + i + 1){
            ret = v[i] + i + 1;
        }
    }
//    cout << s << " " << ret << endl;
    dep[s] = ret;
}

int main(){
    

    ll n;
    cin >> n;
    vector <res> v;
    for (ll i=0;i<n-1;i++){
        res r;
        r.l = i+2;
        cin >> r.w;
        numdep p;
        p.num = r.l;
        children[r.w].push_back(p);
        parent[r.l] = r.w;
        v.push_back(r);
    }
//    for (ll i=1;i<=n;i++){
//        cout << i << " " << parent[i] << endl;
//    }
//    cout << endl;
//    for (ll i=1;i<=n;i++){
//        cout << i;
//        for (ll j=0;j<children[i].size();j++){
//            cout << " " << children[i][j].num;
//        }
//        cout << endl;
//    }
//    cout << endl;
    for (ll i=1;i<=n;i++){
        if(children[i].size() == 0){
            dep[i] = 1;
        }
    }
    calcD(1);
//    cout << endl;
//    for (ll i=1;i<=n;i++){
//        cout << i << " " << dep[i] << endl;
//    }
    cout << dep[1]-1 << endl;

}

Measured memory_bytes: 16624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 200;
const int MOD = 1e9 + 7;
ll v[N];
int n;
ll mul(ll a, ll b) {
    return ((a % MOD) * (b % MOD)) % MOD;
}
ll add(ll a, ll b) {
    return ((a % MOD) + (b % MOD)) % MOD;
}
ll bpow(ll a, ll b) {
    ll ret = 1;
    while(b) {
        if(b & 1) {
            ret = mul(ret, a);
        }
        a = mul(a, a);
        b >>= 1;
    }
    return ret;
}
int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) {
        scanf("%lld", &v[i]);
    }
    if(n == 1) {
        printf("%lld\n", (v[0] * 2) % MOD);
        return 0;
    }
    sort(v, v + n);
    reverse(v, v + n);
    ll pw = bpow(2, n - 1);
    ll pit = bpow(2, n - 2);
    ll ans = 0;
    ll it = pw;
    for(int i = 0; i < n; ++i) {
        ll cur = mul(v[i], it);
        ans = add(ans, cur);
        it += (pit);
    }
    pw = bpow(2, n);
    ans = mul(ans, pw);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define F first
#define S second
#define mod 1000000007
using namespace std;

int main()
{
    int x;
    cin>>x;
    
    set<int> s;
    int a=1;
    
    double an= (sqrt(8.0*(double)x+1)-1)/2;
    
    if(an!=(int)an)an+=1;
    cout<<(int)an<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 100005;
struct Inteval {
	int x, y;
}I[maxn];
bool cmp(Inteval a, Inteval b)
{
	if (a.x != b.x) return a.x > b.x;
	else return a.y < b.y;
}
int main()
{
	int n;
	scanf("%d", &n);
	int cent, r;
		for (int i = 0; i < n; i++)
		{
			scanf("%d%d",&cent ,&r );
			I[i].x = cent - r;
			I[i].y = cent + r;
		}
		sort(I, I + n, cmp);
		int ans = 1, lastX = I[0].x;
		for (int i = 1; i < n; i++)
		{
			if (I[i].y <= lastX) {
				lastX = I[i].x;
				ans++;
			}
		}
		printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 896
// #define _GLIBCXX_DEBUG // for STL debug (optional)

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
void dump_func() { cerr << endl; }
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
#define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	int tmp = 0;
	int a = false;
	int d1, d2;
	for (int i = 0; i < n; i++)
	{
		cin >> d1 >> d2;
		if (d1 == d2)
		{
			tmp += 1;
			a = tmp >= 3 || a;
		}
		else
		{
			tmp = 0;
			continue;
		}
	}
	cout << (a ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, X;
	char C, D[4] = { 'S', 'H', 'C', 'D' };
	bool A[52] = {};
	map<char, int> mp;
	mp['S'] = 0, mp['H'] = 1, mp['C'] = 2, mp['D'] = 3;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> C >> X;
		A[mp[C] * 13 + X - 1] = true;
	}
	for (int i = 0; i < 52; i++) {
		if (!A[i]) {
			cout << D[i / 13] << " " << i % 13 + 1 << endl;
		}
	}
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
//#pragma GCC diagnostic warning "-std=c++11"
#pragma GCC optimize("O3")
using namespace std;
#define ll long long 
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define MAX ((ll)(1e18+100))
#define MX ((ll)(1e6+90))
#define ARRS ((ll)(2e5+100))
#define MOD ((ll)(1e9+7))
#define EP ((double)(1e-9))
#define EPS ((double)(1e-8))
#define pb push_back
#define PI ((double)3.141592653)
#define LG 21


ll q,a,b,k;

int main(){
	ll n,k,p;
	cin>>n;
	ll s=0;
	ll pas=MAX;
	for(int i=0; i<n; i++){
		cin>>k>>p;
		s+=k;
		if(k>p)pas=min(pas,p);
	}
	cout<<max(0ll,s-pas);
}






Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

map<pair<long long int,long long int>, long long int>m;

long long int f(long long int n, long long int x) {
	if (n < 0 || x < 0)return 0;
	if (m.find({ n, x }) != m.end())return m[{n, x}];
	m[{n, x}] = f(n / 2, x / 2);
	if (n&&x) {
		m[{n, x}] += f((n - 1) / 2, (x - 1) / 2);
	}
	if (n > 1) {
		m[{n, x}] += f(n / 2 - 1, x);
	}
	m[{n, x}] %= MOD;
	return m[{n, x}];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	m[{0, 0}] = 1;
	cin >> N;
	cout << f(N, N) << endl;


	return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


bool isPalindrome(string s){

  //if((s.size() % 2) != 1){
  //  return false;
  //}
  
  int n = s.size()/2;
  int ii;

  for(ii=0;ii<n;ii++){
    if(s[ii] != s[s.size()-ii-1]){
      return false;
    }
  }
  
  return true;
}

int main(){
  lll ii,jj,kk;
  vector<int> ret;

  string s;

  cin >> s;

  string first,last;
  int n = s.size();
  int start = (n+3)/2 - 1;
  first = "";
  last  = "";

  for(ii=0;ii<(n-1)/2;ii++){
    first += s[ii];
    last  += s[start+ii];
  }

  //cout << first << endl;
  //cout << last << endl;
  
  if(isPalindrome(first) && isPalindrome(last) && isPalindrome(s)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


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

int main() {
    string s,t="";
    cin>>s;
    for(int i=0; i<s.size(); i++) {
        if(s[i] == '0') t += '0';
        if(s[i] == '1') t += '1';
        if(s[i] == 'B' && t != "") t.pop_back();
    }
    cout<<t<<"\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  string s; cin >> s;
  for(char c: s){
  	if(c=='7'){
      cout << "Yes\n";
      return 0;
  }
  }
	
    cout << "No\n";
  
  return 0;
}

Measured memory_bytes: 3652
n = gets.chomp.to_i

# 9 ^ i + 6 ^ j + k

ans = n

0.upto(n) do |i|
  x = 0
  a = i
  b = n - i
  while a > 0
    x += a % 6
    a /= 6
  end
  while b > 0
    x += b % 9
    b /= 9
  end
  ans = [ans, x].min
end

puts ans

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

int main()
{
	int N, n[15], i;
	for (i = 0; i < 15; i++)
		n[i] = 0;
	cin >> N;
	for (i = 0; N;i++) {
		n[i] = (N + 1) % 3 - 1;
		N = (N - n[i]) / 3;
	}
	for (i--; i >= 0;i--) {
		if (n[i] == 1)
			cout << '+';
		else if (n[i] == 0)
			cout << '0';
		else
			cout << '-';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1156