akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,q,h,w,t,ans=INF;
vl v,v1,v2;
vp p;
string s;
ll solve(){
	if(n==1)return 1;
   rep(i,n){
       rep(j,i){
           x=p[i].first-p[j].first;
           y=p[i].second-p[j].second;
           a=0;
           rep(k,n){
               rep(l,k){
                   if(p[k].first-p[l].first==x&&p[k].second-p[l].second==y){
                       a++;
                   }
               }
           }
           ans=fminl(n-a,ans);
       }
   }

   return ans;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n){
        cin>>a>>b;
        p.emplace_back(a,b);
    }

    sort(all(p));
    cout<<solve()<<endl;
}

Measured memory_bytes: 256
"use strict";

const main = arg => {
  arg = arg.trim().split("\n");
  const N = parseInt(arg[0]);
  const A = arg[1].split(" ").map(n=>parseInt(n));
  
  let answer = 0;
  
  const map = [...Array(100001)].fill(0);
  
  for(let i=0; i<N; i++) {
      if(A[i] > 100000) {
        answer++;
      } else {
        map[A[i]]++;
      }
  }
  
  for(let i=0; i<map.length; i++) {
    if(i > map[i]) answer += map[i];
    if(i < map[i]) answer += map[i] - i;
  }
  
  console.log(answer);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29684
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

double a, b, x;

void solve()
{
    if (x > a*a*b/2) {
        double tan = (a * a * a) / (2 * (a * a * b -x));
        double ans = atan(tan) * 180 / M_PI;
        cout << fixed << setprecision(12) << 90. - ans << endl;
    } else if (x < a*a*b/2){
        double tan = (2 * x) / (a * b * b);
        double ans = atan(tan) * 180 / M_PI;
        cout << fixed << setprecision(12) << 90. - ans << endl;
    } else {
        cout << fixed << setprecision(12) << 45. << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> x;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if ((A == 5 && B == 5 && C == 7)||(A == 5 && B == 7 && C == 5)||(A == 7 && B == 5 && C == 5)) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,sum;
    cin >> n >> sum;
    string res = "";
    for(int i=0; i<n+1; i++){
        for(int j=0; j<n-i+1; j++){
            if(10000*i + 5000*j + 1000*(n-i-j) == sum){
                res = to_string(i) + " " + to_string(j) + " " + to_string(n-i-j);
                break;
            }
        }
        if(res != "") break;
    }
    if(res == "") res = "-1 -1 -1";
    cout << res << endl;
}


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

typedef long long int ll;
int main(){
	ll h,w;cin>>h>>w;
	if(h == 1 || w == 1)cout<<"1"<<endl;
	else if(w&1){
		ll l1 = (w-1)/2+1;
		ll l2 = w - l1;
		if(h&1){
			ll r1 = (h-1)/2+1;
			ll r2 = h - r1;
			printf("%lld\n",l1*r1+l2*r2);
		}else{
			ll r1 = h / 2;
			printf("%lld\n",l1*r1+l2*r1);
		}
	}else{
		ll l = w / 2;
		printf("%lld\n",l*h);
	}
}

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

using namespace std;

typedef long long LL;

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

int pw[10];

vector<int> get_digits(int x) {
	vector<int> d;
	while (x > 0) {
		d.push_back(x % 10);
		x /= 10;
	}
	reverse(d.begin(), d.end());
	return d;
}

vector<int> dn, da;

vector<array<array<LL, 2>, 2>> dp;

LL solve(int i, bool st, bool eq) {
	LL& ans = dp[i][st][eq];
	if (ans != -1) {
		return ans;
	}
	ans = 0;
	if (i == (int)dn.size() - 1) {
		if (!st) {
			return ans = da[0] == da.back();
		} else {
			return ans = !eq || da[0] <= dn.back();
		}
	}
	REP(d, 10) {
		if (eq && d > dn[i]) continue;
		if (!st && d != 0 && d != da.back()) continue;
		ans += solve(i + 1, st || d > 0, eq && d == dn[i]);
	}
	return ans;
}

int main() {
	pw[0] = 1;
	FOR(i, 1, 10)
		pw[i] = pw[i - 1] * 10;
	int n;
	cin >> n;
	if (n < 10) {
		cout << n << '\n';
		return 0;
	}
	dn = get_digits(n);
	dp.resize((int)dn.size());
	LL ans = 0;
	FOR(a, 1, n + 1) {
		if (a % 10 == 0) continue;
		REP(i, (int)dn.size()) REP(j, 2) REP(k, 2) dp[i][j][k] = -1;
		da = get_digits(a);
		ans += solve(0, false, true);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		

		int ans=(n%k==0)?0:1;
		System.out.println(ans);

	}
}


Measured memory_bytes: 21588
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree <pair <ll, int>, null_type, less <pair <ll, int> >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"

#define left fsdsdfoisf
#define sum dpsdfioppsf
#define assign xcvjlkdjfio
#define trie fksdfkjkfnjuiv
#define next sidlfjsfkl
#define merge sdfksdkfsldf

//#define int long long

using namespace std;

void dout() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 1e5 + 7;
int n, m, dp[N];
vector <int> q[N], r[N], ord;
bool used[N];

void dfs(int v) {
    used[v] = true;
    for (auto i : q[v]) {
        if (!used[i]) {
            dfs(i);
        }
    }
    ord.pb(v);
}

void solve(int tc) {
    // check for (int i = 0; i < n; j++)
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        q[x].pb(y);
        r[y].pb(x);
    }
    for (int i = 1; i <= n; i++) {
        if (!used[i]) {
            dfs(i);
        }
    }
    reverse(all(ord));
    int res = 0;
    for (int i = 1; i <= n; i++) {
        int v = ord[i - 1];
        for (auto j : r[v]) {
            dp[v] = max(dp[v], dp[j] + 1);
        }
        res = max(res, dp[v]);
    }
    cout << res;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}


Measured memory_bytes: 14204
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int d = scan.nextInt();
		int t = scan.nextInt();
		int s = scan.nextInt();

		if((double)d/s > t){
			System.out.print("No");
		}else{
			System.out.print("Yes");
		}
	}
}


Measured memory_bytes: 35624
fun main(args:Array<String>):Unit {
    val m = readLine()!!.trim().split(' ').map(String::toInt)[1]
    val demands = Array(m){
        val (a, b) = readLine()!!.trim().split( ' ').map(String::toInt).sorted()
        Pair(a, b)
    }.sortedBy(Pair<Int, Int>::second)
    var count = 0
    var leftLand = 0
    demands.forEach {
        val (left, right) = it
        if (leftLand <= left){
            ++count
            leftLand = right
        }
    }
    println(count)
}

Measured memory_bytes: 63152
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
using namespace std;

int main(void) {
	int n, a, b;
	cin >> n;
	a = 800 * n;
	a -= (n / 15) * 200;
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

vector<int> H;
bool search(const vector<vector<int>> &G, int v) {
  for (auto next_v : G[v]) {
    if (H[v] <= H[next_v]) return false; 
  }
  return true;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for (int i = 0; i < N; i++) {
    int j;
    cin >> j;
    H.push_back(j);
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  int res = 0;
  for (int i = 0; i < N; i++) {
    if (search(G, i)) res++;
  }
  cout << res << endl;
  return 0;
}

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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        set<int> taro, hanako;
        int x, h = 0, t = 0;
        for(int i = 0; i < n; i++)  cin >> x, taro.emplace(x), t += x;
        for(int j = 0; j < m; j++)  cin >> x, hanako.emplace(x), h += x;
        int diff = h-t;
        if(abs(diff) % 2 == 1){
            cout << -1 << endl;
            continue;
        }
        diff /= 2;
        int ansa = -1, ansb = -1;
        for(int k : taro){
            if(hanako.count(k+diff)){
                ansa = k, ansb = k+diff;
                break;
            }
        }
        if(ansa == -1)  cout << -1 << endl;
        else            cout << ansa << " " << ansb << endl;
    }
    return 0;
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 998244353
#define INF 1000000000000000

int solve(int a,int b,int i,int left,int right,vector<int> &tree){
  if(b<=left||right<=a){
    return 0;
  }
  if(a<=left&&right<=b){
    return tree.at(i);
  }
  return solve(a,b,2*i+1,left,(left+right)/2,tree)+solve(a,b,2*i+2,(left+right)/2,right,tree);
}

void plus_tree(vector<int> &tree,int i){
  tree.at(i)++;
  while(i>0){
    i=(i-1)/2;
    tree.at(i)=tree.at(2*i+1)+tree.at(2*i+2);
  }
}

int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }

  vector<ll> sum(N+1,0);
  for(int i=0;i<N;i++){
    sum.at(i+1)=sum.at(i)+a.at(i);
  }

  vector<ll> B(N+1);
  for(ll i=0;i<N+1;i++){
    B.at(i)=sum.at(i)-i*K;
  }
  vector<ll> C=B;
  sort(C.begin(),C.end());
  map<ll,int> m;
  int x=0;
  for(int i=0;i<N+1;i++){
    if(i==0){
      m[C.at(i)]=x;
    }else{
      if(C.at(i)!=C.at(i-1)){
        x++;
      }
      m[C.at(i)]=x;
    }
  }

  vector<int> coor(N+1);
  for(int i=0;i<N+1;i++){
    coor.at(i)=m[B.at(i)];
  }

  int n=1;
  while(n<N+1){
    n<<=1;
  }

  vector<int> tree(2*n-1,0);
  ll ans=0;
  plus_tree(tree,n-1+coor.at(0));
  for(int i=0;i<N;i++){
    ans+=(ll)solve(0,coor.at(i+1)+1,0,0,n,tree);
    plus_tree(tree,n-1+coor.at(i+1));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 21888
import numpy as np

# N=>参加者人数　K=>参加時点の全員の所持ポイント　Q=>正解が出た回数
N, K, Q = map(int, input().split())

# 各参加者のポイント
# points = [K] * N
points = np.full(N, K, np.int64) - Q

# 正解者リスト
# ans_list = [input() for i in range(Q)]
#
# for ans in ans_list:
#     points[int(ans)-1] += 1

for i in range(Q):
    points[int(input())-1] += 1

# print(points)

for point in points:
    if point > 0:
        print("Yes")
    else:
        print("No")

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

int main(){

    int d;cin >> d;
    if(d==25)cout << "Christmas" << endl;
    else if(d==24)cout << "Christmas Eve" << endl;
    else if(d==23)cout << "Christmas Eve Eve" << endl;
    else if(d==22)cout << "Christmas Eve Eve Eve" << endl;
    else cout << "Christmas" << endl;

    return 0;

}


Measured memory_bytes: 256
n, m, l = [int(i) for i in input().split()]

A = []
B = []
C = []

for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for li in range(n):
    print(" ".join([str(s) for s in C[li]]))

Measured memory_bytes: 9012
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, t;
    cin >> n >> t;
    int cost = 10000;
    for(int i = 0; i < n; i++)
    {
        int ci, ti;
        cin >> ci >> ti;
        if(ti <= t)
        {
            cost = min(cost, ci);
        }
    }
    if(cost != 10000) cout << cost << endl;
    else cout << "TLE" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main(){

    // what was confusing about this question is that the question is at most k, if it's under then we are fine

    // we need to count occurences of numbers, sort based on 

    map<int, int> cnt;

    int n, k, temp, ans = 0;
    cin >> n >> k;

    for (int i = 0; i < n; i++){
        cin >> temp;
        if (cnt.count(temp)){
            cnt[temp]++;
        } else {
            cnt[temp] = 1;
            ans++;
        }     
    }

    if (ans <= k){
        cout << 0 << endl;
    } else {

        map<int, int>::iterator it;

        int rem = ans - k;

        // 10 3
        // 5 1 3 2 4 1 1 2 3 4
        // 3

        // cout << " ans : " << ans << " k : " << k << endl;

        int retVal = 0;

        vector<int> nums;

        for ( it = cnt.begin(); it != cnt.end(); it++)
        {
            nums.push_back(it->second);
        }

        sort(nums.begin(), nums.end());

        for (int i = 0; i < rem; i++){
            retVal += nums[i];
        }        

        cout << retVal;

    }

    return 0;
}

Measured memory_bytes: 10748
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]

scores = [(A+B, A, B) for A,B in AB]
scores.sort(key=lambda x:x[0], reverse=True)
takahashi = 0
aoki = 0
takahashi_turn = True
for score in scores:
    if takahashi_turn:
        takahashi += score[1]
    else:
        aoki += score[2]
    takahashi_turn = not takahashi_turn
print(takahashi-aoki)

Measured memory_bytes: 76120
import re
s = input()
k = int(input())
scl = sorted(list(set(s)))
ans = scl[:k]
for i in range(k-1):
  dans = []
  for j in ans[i:]:
    dans += re.findall(j+".",s)
    dans = sorted(list(set(dans)))[:k]
    if len(dans) == k:
      break
  ans = sorted(list(set(ans+dans)))[:k]
  #print(ans)

print(ans[-1])

Measured memory_bytes: 9812
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		int white = H * W;
		int black = (H * w) + (W * h);
		black = black - (h*w);
		sc.close();
		System.out.println(white - black);
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, i, j, k;
	cin >> n;
	for (i = n;; i++) {
		string s = to_string(i);
		sort(s.begin(), s.end()); 
		if (s[0] == s[s.length() - 1]) {
			cout << i << "\n";
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
char out[1<<20];outsz;
main(N,M){
	scanf("%d%d",&N,&M);
	for(int i=1;i<1<<N;i++)
	{
		for(int j=1;j<1<<M;j++)
		{
			out[outsz++]=__builtin_ffs(i|j)&1|48;
		}
		out[outsz++]='\n';
	}
	write(1,out,outsz);
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * x % mod;
            x = x * x % mod;
            n >>= 1;
    }
    return res;
}


void solve() {
    const int mod = 1e9 + 7;
    ll N, C;
    cin >> N >> C;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    // acc[k][b] := \sum_{i=0}^{b-1} i^k
    vector<vector<ll>> acc(401, vector<ll>(402, 0));
    for (ll k = 0; k <= 400; k++) {
        for (int i = 0; i <= 400; i++) {
            acc[k][i + 1] = acc[k][i] + mod_pow(i, k, mod);
        }
    }

    vector<vector<ll>> dp(N + 1, vector<ll>(C + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= C; j++) {
            for (int k = 0; k <= C; k++) {
                if (j + k > C) continue;
                ll sum = (acc[k][B[i] + 1] + mod - acc[k][A[i]]) % mod;
                dp[i + 1][j + k] += dp[i][j] * sum;
                dp[i + 1][j + k] %= mod;
            }
        }
    }

    cout << dp[N][C] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

ll fac[1000001],inv[1000001],finv[1000001];

void COMinit() {
  fac[0]=fac[1]=1;
  inv[1]=1;
  finv[0]=finv[1]=1;
  FOR(i,2,1000001){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=(MOD-(MOD/i*inv[MOD%i])%MOD)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
ll choose(ll n,ll k){
  return (fac[n]*finv[k]%MOD)*finv[n-k]%MOD;
}

int main() {
  COMinit();
  ll X,Y;
  cin >> X >> Y;
  if((X+Y)%3!=0){
    cout << 0 << endl;
  }
  else{
    ll K=(X+Y)/3;
    X-=K;
    Y-=K;
    if(min(X,Y)<0){
      cout << 0 << endl;
    }
    else{
      cout << choose(K,X) << endl;
    }
  }
}

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

public class P
{
    public string s { get; set; }
    public int c { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string s;
        for (; (s = Console.ReadLine()) != null;)
        {
            var a = new int[9];
            for (int i = 0; i < 13; i++) a[int.Parse(s[i].ToString()) - 1]++;
            var ret = new List<int>();
            for (int i = 0; i < 9; i++)
            {
                a[i]++;
                if (a[i] >= 5) { a[i]--; continue; }
                for (int j = 0; j < 9; j++)
                {
                    if (a[j] >= 2)
                    {
                        var b = new int[9];
                        Array.Copy(a, b, 9);
                        b[j] -= 2;
                        if (goBfs(putA(b), 12)) { ret.Add(i); goto next; }
                    }
                }
                next:;
                a[i]--;
            }
            print(ret);
        }
    }
    public static void print(List<int> a)
    {
        var ac = a.Count();
        if (ac == 0) Console.WriteLine(0);
        for (int i = 0; i < ac; i++)
            if (i == ac - 1) Console.WriteLine(a[i] + 1);
            else Console.Write("{0} ", a[i] + 1);
    }
    public static bool goBfs(string s, int c)
    {
        var hs = new HashSet<string>();
        var st = new Stack<P>();
        st.Push(new P { s = s, c = c });
        hs.Add(s);
        while (st.Count() > 0)
        {
            var x = st.Pop();
            if (x.c == 0) return true;
            var a = getA(x.s);
            for (int i = 0; i <= 6; i++)
            {
                if (a[i] >= 1 && a[i + 1] >= 1 && a[i + 2] >= 1)
                {
                    a[i]--; a[i + 1]--; a[i + 2]--;

                    st.Push(new P { s = putA(a), c = x.c - 3 });
                    a[i]++; a[i + 1]++; a[i + 2]++;
                }
            }
            for (int i = 0; i <= 8; i++)
                if (a[i] >= 3)
                {
                    a[i] -= 3;
                    st.Push(new P { s = putA(a), c = x.c - 3 });
                    a[i] += 3;
                }
        }
        return false;
    }
    public static int[] getA(string s)
    {
        var ret = new int[9];
        for (int i = 0; i < 9; i++) ret[i] = int.Parse(s[i].ToString());
        return ret;
    }
    public static string putA(int[] a)
    {
        var ret = "";
        for (int i = 0; i < 9; i++) ret += a[i].ToString();
        return ret;
    }
}



Measured memory_bytes: 10768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m){
        ll v[m];
        vll w;
        rep(i, m){
            cin >> v[i];
        }
        sort(v, v + m);
        rep(i, 1, m){
            w.pb(v[i] - v[i - 1]);
        }
        sort(all(w), greater<ll>());
        ans = 0;
        rep(i, n - 1, m){
            ans += w[i];
        }
        print(ans);
    }
}


Measured memory_bytes: 2168
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
void read(int &x){
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=4e5+10,mod=998244353,g=3,gi=332748118;
int n;
int main(){
    read(n);
    printf("%d\n",(n-1)/2);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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 pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;

template<typename T>
struct LazySegmentTree{
private:
    int n;
    vector<T> node,lazy;
    vector<bool> flg;
public:
    T SUP=(1ull<<31)-1; /* 初期値　*/
    T merge(T x,T y){
        return min(x,y);
    }
    LazySegmentTree(vector<T> v){
        int sz=(int)v.size();
        n=1; while(n<sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,SUP);
        flg.resize(2*n-1,false);
        for(int i=0;i<sz;i++) node[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--){
            node[i]=merge(node[2*i+1],node[2*i+2]);
        }
    }
    void eval(int idx,int l,int r){
        if(flg[idx]){
            node[idx]=lazy[idx];
            flg[idx]=false;
            if(r-l>1){
                /* node[idx]からの伝播  */
                lazy[2*idx+1]=lazy[2*idx+2]=lazy[idx];
                flg[2*idx+1]=flg[2*idx+2]=true;
            }
            lazy[idx]=0;
        }
    }
    void update(int a,int b,T x,int idx=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(idx,l,r);
        if(b<=l||r<=a) return;
        if(a<=l&&r<=b){
            lazy[idx]=x;
            flg[idx]=true;
            eval(idx,l,r);
        }else{
            update(a,b,x,2*idx+1,l,(l+r)/2);
            update(a,b,x,2*idx+2,(l+r)/2,r);
            node[idx]=merge(node[2*idx+1],node[2*idx+2]);
        }
    }
    T query(int a,int b,int idx=0,int l=0,int r=-1){
        if(r<0) r=n;
        if(b<=l || r<=a) return SUP;
        eval(idx,l,r);
        if(a<=l && r<=b) return node[idx];
        T vl = query(a,b,2*idx+1,l,(l+r)/2);
        T vr = query(a,b,2*idx+2,(l+r)/2,r);
        return merge(vl,vr);
    };
};



signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n,q; cin >> n >> q;
    vector<ll> v(n,(1ull<<31)-1);
    LazySegmentTree<ll> lsg(v);
    rep(i,q){
        int x; cin >> x;
        if(x==0){
            int s,t,y; cin >> s >> t >> y;
            t++;
            lsg.update(s,t,y);
        }else{
            int s,t; cin >> s >> t;
            t++;
            cout << lsg.query(s,t) << "\n";
        }
    }

    
}



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

#define ll long long 

int main() {
    ios::sync_with_stdio(0); 

    int h, n; 
    cin >> h >> n; 
    vector<int> a(n); 
    for (int i = 0; i < n; i++) cin >> a[i]; 

    long long ss = accumulate(a.begin(), a.end(), 0); 

    cout << (ss >= h ? "Yes" : "No") << "\n"; 


    return 0; 
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <tuple>
#include <time.h>
using namespace std;
typedef long long ll;

int main() {
    float t1, t2;
    int r1, r2;
    cin >> t1 >> t2 >> r1 >> r2;
    if (r1 == -1 || r2 == -1) {
        if (t1 < t2) cout << "Alice" << endl;
        else if (t1 > t2) cout << "Bob" << endl;
        else cout << "Draw" << endl;
    }
    else {
        if (r1 > r2) cout << "Alice" << endl;
        else if (r1 < r2) cout << "Bob" << endl;
        else cout << "Draw" << endl;
    }
}



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

int main(){
    int i,no=0,counter=0;
    string w,t;

    cin >> w;
    while(cin >> t){
        if(t == "END_OF_TEXT") break;
        for(i=0;i<t.size();i++){
            if(t[i] >= 'A' && t[i] <= 'Z') t[i] += ('a' - 'A');
            if(w[i] != t[i]){
                no = 1;
                break;
            }
        }
        if(i == w.size() && no == 0){
            counter++;
        }
        no = 0;
    }
    cout << counter << endl;
    return 0;
}



Measured memory_bytes: 3160
n = int(input())
a, b = map(int, input().split())
p = sorted(list(map(int, input().split())))

num1 = len([x for x in p if x <= a])
num2 = len([x for x in p if a < x <= b])
num3 = len([x for x in p if b < x])

print(min(num1, num2, num3))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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, M;
    cin >> N >> M;
    int kobetsu = (1900 * M) + (100 * (N - M));
    cout << pow(2, M) * kobetsu << endl;
    return 0;
}

Measured memory_bytes: 4152
# -*- coding: utf-8 -*-
"""
D - Flipping Signs
https://atcoder.jp/contests/abc125/tasks/abc125_d

"""
import sys


def solve(N, array):
    nf, f = 0, float('-inf')
    for a in array:
        nf, f = max(nf+a, f-a), max(nf-a, f+a)
    return nf


def main(args):
    N = int(input())
    array = [int(a) for a in input().split()]
    ans = solve(N, array)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 14412
from collections import deque


def BFS(num):
    color=["white" for _ in range(n+1)]
    D=[-1 for _ in range(n+1)]

    color[num]="gray"
    D[num]=0
    queue=deque([num])

    while len(queue)>0:
        u=queue.popleft()
        for i in M[u]:
            if color[i]=="white":
                color[i]="gray"
                D[i]=D[u]+1
                queue.append(i)
        color[u]="black"

    return D


n=int(input())

M=[[] for _ in range(n+1)]
for i in range(n):
    for j in list(map(int,input().split()))[2:]:
        M[i+1].append(j)

D=BFS(1)
for i in range(1,n+1):
    print(i,D[i])


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

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e4+10;
const int64 MO = 1000000007;
const int64 IN = 1000000000;

int d;
string s;
int dp[maxn][105];

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s >> d;
	for (int i = 0; i < maxn; i++)
		for (int t = 0; t < 105; t++)
			dp[i][t] = 0;

	dp[0][0] = 1;
	for (int i = 0; i <= 9; i++)
		dp[1][i % d]++;
	for (int i = 2; i <= sz(s); i++)
		for (int k = 0; k < d; k++)
			for (int t = 0; t <= 9; t++)
				dp[i][(t + k) % d] = (dp[i][(t + k) % d] + dp[i - 1][k]) % MO;
	
	int cur = 0;
	int ans = -1;
	for (int i = 0; i < sz(s); i++) {
		for (int t = 0; t < s[i] - '0'; t++) {
			int f = (cur + t) % d;
			f = (d - f) % d;
			ans = (ans + dp[sz(s) - i - 1][f]) % MO;
		}
		cur = (cur + s[i] - '0') % d;
	}
	if (cur == 0)
		ans++;
	ans = (ans + MO) % MO;
	cout << ans << "\n";
}


Measured memory_bytes: 7764
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        long a[] = new long[n];
        long b[] = new long[n];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
            b[i] = in.nextLong();
        }

        long ans = 0;
        for (int i = n - 1; i >= 0; i--) {
            a[i] += ans;
            long c = ((a[i] + b[i] - 1) / b[i]) * b[i] - a[i];
            ans += c;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 89996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S / 3600;
		int H = S % 3600;
		int m = H / 60;
		int s = H % 60;
		System.out.println(h+":"+m+":"+s);
		sc.close();
	}
}


Measured memory_bytes: 26348
while True:
    h,w = map(int,input().split())
    
    if h == 0 and w == 0:
        break
    for i in range(h):
        for j in range(w):
            if (i + j) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    
    print()


Measured memory_bytes: 7004
#include <iostream>
typedef long long ll;
using namespace std;

int main(void) {
    ll N;
    cin>>N;
    ll max_divider;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) max_divider = i;
    }
    cout << (max_divider - 1) + (N / max_divider - 1) << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 1010;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

int n, pos[MAXN];
vector<int> a[MAXN], tmp;
set<II> s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n)
        FOR(j,1,n-1) {
            int u;
            cin >> u;
            a[i].emplace_back(u);
        }
    FOR(i,1,n) pos[i] = 0;
    FOR(i,1,n) {
        int g = a[i][pos[i]];
        int h = a[g][pos[g]];
        if (h == i) {
            if (i < g) s.insert(II(i, g));
            else s.insert(II(g, i));
        }
    }
    // FORALL(it, s) cout << it->FI << ' ' << it->SE << endl;
    int cnt = 0;
    while (SZ(s)) {
        cnt++;
        FORALL(it, s) {
            int g = it->FI;
            int h = it->SE;
            pos[g]++;
            pos[h]++;
            tmp.emplace_back(g);
            tmp.emplace_back(h);
        }
        // FOR(i,1,n) cout << pos[i] << ' '; cout << endl;
        s.clear();
        FOR(i,0,SZ(tmp)-1) {
            int p = tmp[i];
            if (pos[p] >= n-1) continue;
            int g = a[p][pos[p]];
            if (pos[g] >= n-1) continue;
            int h = a[g][pos[g]];
            if (h == p) {
                if (p < g) s.insert(II(p, g));
                else s.insert(II(g, p));
            }
        }
        tmp.clear();
    }
    FOR(i,1,n)
        if (pos[i] < n-1) {
            cout << -1;
            return 0;
        }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 4352
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if(a==b && b == c){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    
  }
}

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

int main() {
  int a=gi()*100, b=gi()*10, c=gi();
  a=a+b+c;
  if(a%4)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<char, int> ci;
vector<ci> vet;
vector<int> v1;
string str;
bool isPal(){
    
  int n = vet.size();
  for(int i = 0;i<vet.size()/2;i++)
    if(vet[i].first != vet[n-i-1].first)
      return  0;
      
  v1.push_back(0);
  
  for(auto it: vet)
    v1.push_back(it.second+1);
    
  v1.push_back(str.size()+1);
     
	return 1;
}

int main(){
    
  cin >> str;
  
  for(int i =0;i<str.size();i++){
  	if(str[i] != 'x')
      	vet.push_back({str[i],i});
  }
  
  if(!isPal()){
    cout<<-1;
    return 0;
  }
  
  int s = 0;
  
  if(vet.size() == 0){
      cout<<0;
      return 0;
  }
  
 else if(vet.size() & 1){
    int z = v1.size()/2;
    
    int r = z, l = z;
    while(l > 0 and r < v1.size()-1){
        int c = abs( (v1[r+1] - v1[r] -1) - (v1[l] - v1[l-1]-1));
        s+=c;
        
        r++;
        l--;
    }
    
  }else{
      
    int l = v1.size()/2-1, r = v1.size()/2;
    
    while(l > 0 and r < v1.size()-1){
        int c = abs( (v1[r+1] - v1[r] -1) - (v1[l] - v1[l-1]-1));
        s+=c;
        r++;
        l--;
    }
  }
  cout<<s<<endl;
  
}

Measured memory_bytes: 2036
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("out.o", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	if (s == "RSR") {
		cout << 1;
	}
	else if (s == "SSS") {
		cout << 0;
	}
	else {
		int cnt = 0;
		for (int i = 0; i < 3; i++) {
			if (s[i] == 'R') {
				cnt++;
			}
		} cout << cnt;
	}
}

Measured memory_bytes: 3588
<?php

// 標準入力を一行ずつ配列に代入します
fscanf(STDIN, '%d %d %d', $n, $a, $b);


$total = 0;
function findSumOfDigits($n) {
	$sum = 0;

	while($n > 0) {
		$sum += $n % 10;
		$n /= 10;
	}
	return $sum;
}

$total = 0;
for ($i = 1; $i <= $n; $i++) {
	$x = findSumOfDigits($i);
	if ($x >= $a && $x <= $b) {
		$total += $i;
	}
}

echo $total;


Measured memory_bytes: 4728
#include <iostream>
#include <string>

using namespace std;

int main(){
  string S, T, str;
  cin >> S;
  cin >> T;
  str = T.substr(0, T.length()-1);
  if(str == S) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3588
n = int(input())
a = [0]+list(map(int,input().split()))+[0]
cost = sum([abs(a[i]-a[i+1]) for i in range(n+1)])
for i in range(1,n+1):
  print(cost+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i]-a[i+1]))


Measured memory_bytes: 14048
#include<iostream>

using namespace std;

typedef struct{
	int parent,left,right,degree;
}Node;

void print(Node T[],int deep[],int n);
void setDepth(Node T[],int deep[],int u,int p);
void printChild(Node T[],int u);
void type(Node T[],int n);

int main(){
	int n;cin>>n;
	Node *T; T = new Node[n];
	for(int i=0;i<n;i++)
		T[i].parent = T[i].left = T[i].right = -1;

	for(int i=0;i<n;i++){
		int id,deg,*brother; cin>>id>>deg;
		T[id].degree = deg;
		brother = new int[deg];
		for(int j=0;j<deg;j++){
			int child; cin>>child;
			brother[j] = child;
			if(j==0)
				T[id].left = child;
			T[child].parent = id;
		}
		for(int j=0;j<deg;j++){
			if(j!=deg-1)
				T[brother[j]].right = brother[j+1];
		}
		delete [] brother;
	}

	int *deep,root;
	deep = new int[n];
	for(int i=0;i<n;i++){
		*(deep+i) = 0;
		if(T[i].parent==-1) root = i;
	}

	setDepth(T,deep,root,0);

	print(T,deep,n);

	delete [] T;
	delete [] deep;
}

void setDepth(Node T[],int deep[],int u,int p){
	deep[u] = p;
	if(T[u].right!=-1) setDepth(T,deep,T[u].right,p);
	if(T[u].left!=-1) setDepth(T,deep,T[u].left,p+1);
}

void print(Node T[],int deep[],int n){
	for(int i=0;i<n;i++){
		cout<<"node "<<i<<": parent = "<<T[i].parent<<", depth = "<<deep[i]<<", ";type(T,i);cout<<", [";printChild(T,i);cout<<"]"<<endl;
	}
}

void printChild(Node T[],int u){
	int c = T[u].left;
	while(c!=-1){
		if(T[c].right!=-1){
			cout<<c<<", ";
		}else{
			cout<<c;
		}
		c = T[c].right;
	}
}

void type(Node T[],int n){
	if(T[n].parent==-1){
		cout<<"root";
	}else if(T[n].left==-1){
		cout<<"leaf";
	}else{
		cout<<"internal node";
	}
}

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

using namespace std;
using ll = long long;

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    ll a = ll(abs(x)/d);
    if(a > k) cout<<abs(x) - d * k<<endl;
    else if((a-k)%2 == 0) cout<<abs(x) % d<<endl;
    else cout<<d - abs(x)%d <<endl;
    return 0;
}  


Measured memory_bytes: 3628
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define endl "\n"
#define inf 1<<30
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ss stringstream
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x , y , sizeof(x))
#define bit_cnt(mask) __builtin_popcount(mask)
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const ll MOD = 1000000007; /// 1e9+7
const int MAX = 100005;     /// 1e5+5
ll bigmod(ll n, ll r)
{
    if(r==0) return 1;
    if(r==1) return n;
    if(r%2==0)
    {
        ll ret = bigmod(n, r/2);
        return ((ret%MOD) * (ret%MOD)) % MOD;
    }
    else return ((n%MOD) * (bigmod(n,r-1)%MOD)) % MOD;
}
ll modinverse(ll a){return bigmod(a,MOD-2)%MOD;}
ll lcm(ll a, ll b) {a=abs(a); b=abs(b); return (a/__gcd(a,b))*b;}
ll gcd(ll a, ll b) {a=abs(a); b=abs(b); if(!b) return a; return __gcd(b,a%b);}
//int in() {int x; scanf("%d",&x); return x;}
//ll lin() {ll x; scanf("%lld",&x); return x;}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin>>n; int mn = INT_MAX;
    while(n--){
        int x; cin>>x;
        int cnt=0;
        while(x%2==0){
            x/=2;
            cnt++;
        }
        mn = min(mn, cnt);
    }
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 256
open Scanf
open Printf

let rec for_iter a b f = if a >= b then () else (f a; for_iter (a+1) b f)
let rec for_iterr a b f = if a <= b then () else (f a; for_iter (a-1) b f)
let rec for_iters a b s f = if (a-b >= 0) <> (s >= 0) then () else (f a; for_iter (a+s) b f)

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)
let read_ints_arr n = Array.init n (fun _ -> read_int ())
let read_ints_arr_ref n = Array.init n (fun _ -> ref (read_int ()))

let accum xs =
  let rec f ys ac =
    match ys with
    | [] -> []
    | (y::ys') -> (y+ac) :: f ys' (y+ac)
  in f xs 0

let () =
  let n = read_int () in
  let x0 = read_ints n |> accum in
  let x1 = read_ints n |> List.rev |> accum |> List.rev in
  let ans = List.fold_left2 (fun c a b -> max c (a+b)) 0 x0 x1 in
  printf "%d\n" ans


Measured memory_bytes: 2432
#include <iostream>

using namespace std;

int main(void)
{
	int s;
	bool table[1000001];
	cin >> s;
	for(auto e:table){
		e = false;
	}
	for(int a = s, m = 1;;m++){
		if (table[a] == true){
			cout << m << endl;
			break;
		}
		table[a] = true;
		if (a % 2 == 0){
			a = a / 2;
		}else{
			a = 3*a + 1;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
class cum_sum{
  private:
    vector<long long>sum;
    vector<long long>tmp;
    int n;
  public:
    cum_sum(vector<long long>v):tmp(v),n(v.size()){
      sum.resize(n + 1);
      for(int i = 0; i < n; i++){
        sum[i + 1] = sum[i] + tmp[i];
      }
    };
    long long range_sum(int l, int r){
      if(l > r)swap(l,r);
      return sum[r + 1] - sum[l];
    }
}; 
int solve(){
  int n;
  cin >> n;
  vector<ll>v(n);
  rep(i,n)cin >> v[i];
  cum_sum sum(v);
  ll ans = 100000000000;
  REP(i,0,n - 1){
    ll L = sum.range_sum(0,i),R = sum.range_sum(i + 1,n - 1);
    ans = min(ans,abs(L - R));
  }
  cout << ans << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	string S[3];
 
	cin >> S[0] >> S[1] >> S[2];
	int i[] = { 0,0,0 };
	int now = 0;
	while( true ) {
		//cout << now << endl;
		if( S[now].size() > i[now] ) {
			i[now]++;
			now = S[now][i[now] - 1] - 'a';
		} else {
			cout << ( char )(now + 'A') << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

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

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 20100;

int n, p[MAXN];

int a[MAXN], b[MAXN];

int main() {
	scanf("%d",&n);
	REP(i, n) scanf("%d",&p[i]);
	a[0] = 1;
	FOR(i, 1, n) a[i] = a[i - 1] + 50000;

	int tmp = 1000000001;
	vector <pii> v;
	REP(i, n) v.push_back(mp(p[i], i));
	//sort(all(v));
	reverse(all(v));
	REP(i, n) {
		int x = v[i].fi - 1;
		b[x] = tmp - a[x];
		tmp--;
	}

	REP(i, n) printf("%d ",a[i]);
	puts("");
	REP(i, n) printf("%d ",b[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 1148