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

#define int long long int

int32_t main() {
    
    int n, k;
    cin >> n >> k;
    int arr[n + 2];
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    
    int tel = 1;
    map<int,int> m;
    int count = 0;
    while(k > 0 && m[tel] == 0){
        m[tel] = ++count;
        tel = arr[tel - 1];
        k--;
    }
    if(k == 0){
        cout << tel << endl;
    
        return 0;
    }
    k = k % (count + 1 - m[tel]);
    
    for(int i = 0; i < k; i++)
        tel = arr[tel - 1];
    
    cout << tel << endl;
    return 0;
}

Measured memory_bytes: 15192
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    long long int s;
    cin >> s;
    long long int v = 1000000000;
    long long int x = (v - s % v) % v;
    long long int y = (s + x) / v;
    cout << "0 0 1000000000 1 " << x << " " << y << "\n";

    return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
S_ = []
P = 2019
num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1

print(ans)

Measured memory_bytes: 73968
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.*;

public class Main {
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }


    }

    public static void main(String[] args) {
        FastReader s = new FastReader();
        Main obj = new Main();

       int h=s.nextInt();
       int a=s.nextInt();
       int count=0;
       int temp=h;
       for(int i=0;i<temp;i++)
       {
           h=h-a;
           if(h<=0)
               break;
           else
               count++;
       }
       System.out.println(count+    1);


    }






}

Measured memory_bytes: 23124
package main

import (
	"fmt"
)

func main(){
	var s string
	fmt.Scan(&s)
	var result string

	for _, b := range s {

		switch b {
		case '0':
			result += "0"
		case '1':
			result += "1"
		case 'B':
			if len(result) > 0 {
				result = result[0:len(result)-1]
			}
		}
	}
	fmt.Println(result)

}


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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	i64 x, y, z;
	cin >> x >> y >> z;
	print((x - z) / (y + z));
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

int main(){
  int a,b;
  double x,y,k;

  cin >> a >> b;
  x = a * 2.0;
  y = b;
  k = a+1 + b+ 1 -2;
  for(int i=1;i<a;i++){
    for(double j=1.0;j<y;j++){
      //cout << i+2.0*(y/x) << endl;
      if(i*2.0*(y/x) == j){
        k--;
        break;
      }
    }
  }
  cout << k << endl;
}




Measured memory_bytes: 3292
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

static uint64_t gcd(uint64_t a, uint64_t b)
{
	uint64_t temp;

	if (a < b) {
		temp = a;
		a = b;
		b = temp;
	}

	uint64_t r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

static uint64_t lcd(uint64_t a, uint64_t b)
{
	uint64_t temp, _gcd;

	if (a < b) {
		temp = a;
		a = b;
		b = temp;
	}

	_gcd = gcd(a, b);

	uint64_t sho_a = a / _gcd;
	uint64_t sho_b = b / _gcd;
	return sho_a * sho_b * _gcd;
}

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

	int64_t res = 1;
	for (int32_t i = 0; i < N; i++) {
		int64_t T;
		cin >> T;
		res = lcd(res, T);
	}

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

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>
#include <cstdint>
#include <cmath>

using namespace std;

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

    int n,m;
    cin >> n >> m;
    
    vector<int> wa(n);
    vector<bool> ac(n);
    int cp = 0;
    int ca = 0;
    
    for(int i = 0; i < m; ++i){
        int id;
        string result;
        cin >> id >> result;
        bool a = (result[0] == 'A');

        if(!ac[id-1] && a){
            ++ca;
            cp += wa[id-1];
            ac[id-1] = true;
        }
        if(!a){
            ++wa[id-1];
        }
    }

    cout << ca << ' ' << cp << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
int main()
{
	int cs[5], i, j, t, r, fl, fl2;
	char c, *s[8] = {"null", "one pair", "two pair", "three card", "straight", "full house", "four card"};
	while (std::cin >> cs[0] >> c >> cs[1] >> c >> cs[2] >> c >> cs[3] >> c >> cs[4])
	{
		r = 1;
		std::sort(cs, cs+5);
		int n[13] = {0};
		for (i = 0; i < 5; i++)
			n[cs[i]-1]++;
		for (i = t = 0; i < 13; i++)
			if (n[i] == 2)	t++;
		if (t == 1)	r = 2;
		if (t == 2)	r = 3;
		for (i = fl = 0; i < 13 && !fl; i++)
			if (n[i] == 3)		r = 4, fl = 1;
			else if (n[i] == 4)	r = 7, fl = 1;
		for (i = fl = 0; i < 9 && !fl; i++)
		{
			for (j = 0, fl2 = 1; j < 5 && fl2; j++)
				if (n[i+j] != 1)	fl2 = 0;
			if (fl2)	r = 5;
		}
		if (!fl)
		{
			for (i = 9, fl = 0; i < 13 && !fl; i++)
				if (n[i] != 1)	fl = 1;
			if (!fl && n[0])	r = 5;
		}
		for (i = fl = fl2 = 0; i < 13; i++)
		{
			if (n[i] == 2)	fl = 1;
			if (n[i] == 3)	fl2 = 1;
		}
		if (fl && fl2)	r = 6;
		std::cout << s[r-1] << std::endl;
	}
}

Measured memory_bytes: 0
// Probably getting a WA/Tle
// Still trying
// Apna time ayega

#include<bits/stdc++.h>
#define ll long long int
#define FastRead ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    double n,l,a,b,m,k,i,j;
    cin>>n;
    n=n/3;
    cout<<fixed<<setprecision(12)<<n*n*n<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int N = 15;
const int MAXS = (1 << N) + 5;

template <typename T> inline void read(T &AKNOI) {
    T x = 0, flag = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') flag = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    AKNOI = flag * x;
}

template <typename T> inline void cmax(T &x, T y) {
	if (x < y) x = y;
}

int n, m, S, g[N][N], bin[N], id[MAXS];
int sum[MAXS], dp[MAXS][N];

void init() {
	read(n); read(m);
	S = (1 << n);
	for (int i = 0; i < n; ++i) {
		bin[i] = (1 << i);
		id[bin[i]] = i;
	}
	for (int i = 1; i <= m; ++i) {
		int a, b, c;
		read(a); read(b); read(c);
		g[a - 1][b - 1] = g[b - 1][a - 1] = c;
	}
	for (int s = 1; s < S; ++s) {
		int u = id[s & (-s)];
		sum[s] = sum[s ^ bin[u]];
		for (int i = u + 1; i < n; ++i) {
			if ((s >> i) & 1) {
				sum[s] += g[u][i];
			}
		}
	}
}

void solve() {
	mset(dp, 0x80);
	int ans = dp[0][0];
	dp[1][0] = 0;
	for (int s = 1; s < S; ++s) {
		for (int i = 0; i < n; ++i) {
			for (int t = s; t; t = (t - 1) & s) {
				if (t & bin[i]) {
					cmax(dp[s][i], dp[s ^ t ^ bin[i]][i] + sum[t]);
				}
			}
			for (int j = 0; j < n; ++j) {
				if ((s >> j) & 1) continue;
				if (!g[i][j]) continue;
				cmax(dp[s | bin[j]][j], dp[s][i] + g[i][j]);
			}
		}
		if (s & bin[n - 1]) {
			cmax(ans, dp[s][n - 1]);
		}
	}
	printf("%d\n", sum[S - 1] - ans);
}

int main() {
	init();
	solve();
	return 0;
}


Measured memory_bytes: 2304
/*package whatever //do not write package name here */

import java.util.*;

public class Main {
	public static void main (String[] args) {
	    
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        long c = sc.nextLong();
        long x[] = new long[n];
        long v[] = new long[n];
        long l[] = new long[n];
        long r[] = new long[n];
        for(int i=0;i<n;i++){
            x[i] = sc.nextLong();
            v[i] = sc.nextLong();
        }
        long ans = 0l;
        for(int i=0;i<n;i++){
            if(i==0) {
                l[i] = v[i];
                continue;
            }
            l[i] = l[i-1]+v[i];
        }
        
        for(int i=0;i<n;i++){
            l[i]-=x[i];
            ans = Math.max(ans, l[i]);
        }
        
        
        //also do this for going right
        r[0] = v[n-1];
        for(int i=1;i<n;i++){
            r[i] = r[i-1]+v[n-i-1];
        }
        
        for(int i=0;i<n;i++){
            r[i] -= c-x[n-i-1];
            ans = Math.max(ans, r[i]);
        }
        
        long ll[]  =new long[n];
        long rr[]  =new long[n];
        
        for(int i=0;i<n;i++){
            ll[i] = l[i]; 
            rr[i]=r[i];
        }
        for(int i=1;i<n;i++){
            rr[i] = Math.max(rr[i], rr[i-1]);
            ll[i] = Math.max(ll[i], ll[i-1]);
        }
        
        //System.out.println(Arrays.toString(ll)+" " + Arrays.toString(rr));
        //System.out.println(Arrays.toString(l)+" " + Arrays.toString(r));
        
        //go to left and then come back to right. for all these cases
        for(int i=0;i<n-1;i++){
            //System.out.print(r[i] - c- x[n-1-i]+" ");
            ans = Math.max(ans, l[i] - x[i] + rr[n-i-2]);
            ans = Math.max(ans, r[i] - (c- x[n-1-i]) + ll[n-i-2]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 91116
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 100000000
using namespace std;

int main(void){
  int N;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++){
      cin>>A[i];
  }
  int way=0;
  for(int i=0;i<N;i++){
     if(i!=0) way+=abs(A[i]-A[i-1]);
     else way+=abs(A[i]);
  }
  way+=abs(A[N-1]);
  for(int i=0;i<N;i++){
      if(i==0) cout<<way-abs(A[1]-A[0])-abs(A[0])+abs(A[1])<<endl;
      else if(i==N-1) cout<<way-abs(A[N-1]-A[N-2])-abs(A[N-1])+abs(A[N-2])<<endl;
      else cout<<way-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1])<<endl;
  }
  return 0;
}


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

int linearSearch(int S[],int n,int key){
    int i=0;
    S[n] = key;
    while (S[i] != key){
        i++;
    }   
    return i != n;
}

int main(){
    int n,q,S[10001],key,sum=0;
    scanf("%d",&n);
    for (int i=0;i<n;i++)scanf("%d",&S[i]);
    scanf("%d",&q);

    for (int i=0;i<q;i++){
        scanf("%d",&key);
        if(linearSearch(S,n,key))sum++;
    }   
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[MAXn];
int main(){
    IOS();
    ll n;
    cin >> n;
    for (int i=0;i<n;++i) cin >> d[i];
    ll ans = 0;
    ll mx = 0;
    for (int i=0;i<n;++i) {
        if (d[i] < mx) {
            ans += (mx - d[i]);
        }
        else {
            mx = d[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5212
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


A, B = map(lambda x: int(x), input().split())
cake = range(1, 17)

pattern_A = [pattern for pattern in itertools.combinations(cake, A)]
# pattern_B = [pattern for pattern in itertools.combinations(range(len(cake)-A), B)]
iter_cakeB = []
for pat in pattern_A:
    cake1 = list(range(1, 17))
    for i in pat:
        cake1.remove(i)
    iter_cakeB.append(cake1)


pattern_B = [[[] for _ in range(combinations_count(len(cake)-A, B))]
             for i in range(len(iter_cakeB))]

for i, cake_put_by_A in enumerate(iter_cakeB):
    for j, pattern in enumerate(itertools.combinations(cake_put_by_A, B)):
        pattern_B[i][j] = pattern
# print(len(pattern_B))


flag = False
for cnt, patA in enumerate(pattern_A):
    a = [patA[i + 1] - patA[i] for i in range(len(patA)) if i < len(patA)-1]
    if 1 in a:
        continue
    else:
        for patB in pattern_B[cnt]:
            b = [patB[i + 1] - patB[i] for i in range(len(patB)) if i < len(patB)-1]
            if 1 in b:
                continue
            else:
                print('Yay!')
                flag = True
                break
    if flag:
        break

if cnt == len(pattern_A)-1:
    print(':(')


Measured memory_bytes: 149748
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        int num = i;
        int d = 0;
        while (num > 0) {
            d++;
            num /= 10;
        }
        if (d % 2) cnt++;
    }
    
    cout << cnt;

    return 0;
}


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

#define Need_For_Speed ios_base::sync_with_stdio;cin.tie(NULL);cout.tie(NULL);

#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define sz size()
#define fi first
#define se second

#define batr ONLINE_JUDGE
#define all(x) (x).begin(),(x).end()
#define skip continue

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e6 + 17, maxN = 4 * N, darr = 1e3 + 17, mod = 1e9 + 7;

int n;
int a[N];

map <ll, ll> m;

ll p[N];

int main () {
	Need_For_Speed;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		p[i] = p[i-1] + a[i];
	}
	ll res = 0;
	for (int i = 0; i <= n; i++) {
		res += m[p[i]];
		m[p[i]]++;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 18432
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>

using namespace std;

long long num[100005];
long long mn[100005];

int main() {
  long long n, i, a;
  scanf(" %lld", &n);
  for(i=0; i<n; i++)mn[i] = 1000000000;
  mn[0] = 0;
  for(i=0; i<n; i++){
    scanf(" %lld", &num[i]);
    if(i >=1) mn[i] = min(mn[i], abs(num[i]-num[i-1])+mn[i-1]);
    if(i>=2) mn[i] = min(mn[i], abs(num[i]-num[i-2])+mn[i-2]);
    //cout<<mn[i]<<" ";
  }
  printf("%lld\n", mn[n-1]);

}

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

int main() {
int N;
  cin >> N;
  long long result = 0;
  vector<long long>A(N);
  for(int a = 0;a < N;a++)cin >> A[a];
  vector<int>B(200000);
  for(int a = 0;a < 200000;a++)B[a] = 0;
  for(int a = 0;a < N;a++){
    if(200000 > A[a] + a + 1&&A[a] + a + 1 >= 0){
    B[A[a] + a + 1]++;
    }
    if(200000 > a + 1 - A[a]&&a + 1 - A[a] >= 0){
    result += B[a + 1 - A[a]];
    }
  }
  cout << result << endl;
}

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

typedef vector<int> vi;
typedef vector<bool> vb;

int N, M;
vector<vi> G;
vi V;
vb used;
vi dp;

void input_init(void) {
	cin >> N >> M;
	G.resize(N + 1);
	for (int i = 0; i < M; ++i) {
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
	}
	used.resize(N + 1, false);
	dp.resize(N + 1, 0);
}

void dfs(int i) {
	if (used[i])
		return;
	used[i] = true;
	for (int j = 0; j < (int)G[i].size(); ++j) {
		int nxt = G[i][j];
		dfs(nxt);
	}
	V.push_back(i);
}

void rev_tsort(void) {
	for (int i = 1; i <= N; ++i)
		dfs(i);
}

int solve(void) {
	int d = 0;
	for (int i = 0; i < (int)V.size(); ++i) {
		int u = V[i];
		for (int j = 0; j < (int)G[u].size(); ++j) {
			int v = G[u][j];
			dp[u] = max(dp[v] + 1, dp[u]);
		}
		d = max(dp[u], d);
	}
	return d;
}

int main(void) {
	input_init();
	rev_tsort();
	int ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 8828
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>

using namespace std;



int main(int argc, char *argv[])
{
	int count_zero = 0;
	int count_one = 0;
	string s;
	int ans = 0;

	//input
	cin >> s;
	


	//calc
	for (int i = 0; i < s.length(); i++){
		if (s[i] == '0'){
			count_zero++;
		}
		else if (s[i] == '1'){
			count_one++;
		}
	}

	if (count_zero < count_one){
		ans = count_zero * 2;
	}
	else{
		ans = count_one * 2;
	}


	//ans
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
      
		int X = sc.nextInt();
		int A = sc.nextInt();
		
		if(X>=A) {
			System.out.println(10);
		}else {
			System.out.println(0);
		}
	}

}

Measured memory_bytes: 23892
#include<iostream>
#include<cstdio>
#define int long long
#define maxx 400010
using namespace std;
int k,mod;
int M(int x){
    return x%mod;
}
int root;
int head[maxx],depth[maxx],a[maxx];
int tot,num,n,m,f[maxx],l[maxx];
int ch[maxx],top[maxx],size[maxx],son[maxx];
int cnt;
struct node{
    int to;
    int next;
}e[maxx];

void add(int u,int v){
    e[++cnt].next=head[u];
    e[cnt].to=v;
    head[u]=cnt;
}

struct TREE{
    int l,r;
    int pre,add;
}t[maxx*4];

void pushup(int p){
	t[p].pre=t[p*2].pre+t[p*2+1].pre;
	M(t[p].pre);
}

void pushdown(int p){
	if(t[p].add){
		t[p*2].add+=t[p].add;
		t[p*2+1].add+=t[p].add;
		M(t[p*2].add);
		M(t[p*2+1].add);
		t[p*2].pre+=M(t[p*2].r-t[p*2].l+1)*t[p].add;
		M(t[p*2].pre);
		t[p*2+1].pre+=M(t[p*2+1].r-t[p*2+1].l+1)*t[p].add;
		M(t[p*2+1].pre);
		t[p].add=0;		
	}
}

void update(int p,int x,int y,int z){
	if(t[p].l>=x && t[p].r<=y){
		t[p].pre+=M(t[p].r-t[p].l+1)*z;
		M(t[p].pre);
		t[p].add+=z;
		M(t[p].add);	
		return;
	}
	int mid=(t[p].l+t[p].r)>>1;
	pushdown(p);
	if(x<=mid) update(p*2,x,y,z);
	if(y>mid)  update(p*2+1,x,y,z);
	pushup(p);
}

int query(int p,int x,int y){
	int ans=0;
	if(t[p].l>=x && t[p].r<=y){	
		return t[p].pre;
	}
	int mid=(t[p].l+t[p].r)>>1;
	pushdown(p);
	if(x<=mid) ans+=query(p*2,x,y);
	if(y>mid)  ans+=query(p*2+1,x,y);
	return ans;
}

void dfs1(int u){
	size[u]=1;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(!depth[v]){
			depth[v]=depth[u]+1;
			f[v]=u;
			dfs1(v);
			size[u]+=size[v];
			if(size[son[u]]<size[v]) son[u]=v;
		}
	}
} 

void dfs2(int u,int fa){
	l[u]=++tot;a[tot]=ch[u];top[u]=fa;
	if(son[u]) dfs2(son[u],fa);
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(v!=f[u] && v!=son[u]){
			dfs2(v,v);
		}
	}
}

void update_tree(int x,int y,int z){
	int fx=top[x];int fy=top[y];
	while(fx!=fy){
		if(depth[fx]<depth[fy]){
			swap(x,y);
			swap(fx,fy);
		}
		update(1,l[fx],l[x],z);
		x=f[fx];fx=top[x];
	}
	if(l[x]>l[y]) swap(x,y);
	update(1,l[x],l[y],z);
}

int query_tree(int x,int y){
	int fx=top[x];int fy=top[y];
	int ans=0;
	while(fx!=fy){
		if(depth[fx]<depth[fy]){
			swap(x,y);
			swap(fx,fy);
		}
		ans+=query(1,l[fx],l[x]);
		x=f[fx];fx=top[x];
	}
	if(l[x]>l[y]) swap(x,y);
	ans+=query(1,l[x],l[y]);
	return ans;
}
void build(int p,int l,int r){
	t[p].l=l;t[p].r=r;
	if(l==r){
		t[p].pre=a[l];
		return;
	}
	int mid=(l+r)>>1;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	pushup(p);
}
signed main(){
	scanf("%lld%lld",&n,&m);
	root=1;
	mod=1e9;
	for(int i=1;i<=n-1;i++){
		int x,y,z;
		scanf("%lld%lld",&x,&y);
		add(x,y);
		add(y,x);
	}
	depth[root]=f[root]=1;
	dfs1(root);
	dfs2(root,root);
	build(1,1,n);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%lld%lld",&x,&y);
		update(1,l[x],l[x]+size[x]-1,y);		
	}
	for(int i=1;i<=n;i++){
		printf("%lld\n",query_tree(i,i));
	}
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  rep(i, N) { cin >> A[i]; }
  sort(all(A));
  int ans = 0;
  vector<int> list(1000001, 0);
  rep(i, N) {
    if (list[A[i]] == 0) {
      if (i > 0 && (A[i] == A[i - 1]) || (i < N - 1 && A[i] == A[i + 1])) {
        ans = ans;
      }
      else{
        ans ++;
      }
      int j = 1;
      while (A[i] * j <= 1000000) {
        list[A[i] * j]++;
        j++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 12672
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
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 ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int r , d , x;
	
	cin >> r >> d >> x;
	
	for(int i = 1; i <= 10 ; ++i) {
		cout << r*x - d << endl;
		
		x = r*x - d;
	}
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL<<60;
int main() {
  int H,N; cin>>H>>N;
  vector<int> A(N);
  vector<int> B(N);
  rep(i,N) cin>>A.at(i)>>B.at(i);
  vector<long long> DP(H+1, INF);
  DP[0]=0;
  for(int i=0;i<=H;i++){
    rep(j,N){
      DP[min(i+A.at(j),H)]=min(DP[min(i+A.at(j),H)],DP[i]+B.at(j));
    }
  }
  cout<<DP[H];
}


Measured memory_bytes: 3716
import java.util.ArrayDeque;
import java.util.Iterator;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		ArrayDeque<Integer> de = new ArrayDeque<>();
		Iterator<Integer> itr;
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
			for (int i = 0; i < n; i++) {
				int a = scan.nextInt();
				if ((i & 1) == 0) {
					de.addLast(Integer.valueOf(a));
				} else {
					de.addFirst(Integer.valueOf(a));
				}
			}
			if((n&1)==0){
				itr = de.iterator();
			}else{
				itr = de.descendingIterator();
			}
			System.out.print(itr.next());
			while(itr.hasNext()){
				System.out.print(" ");
				System.out.print(itr.next());
			}
			System.out.println("");

		scan.close();

	}

}

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

int main(){
    ll n;
    cin>>n;
    vector<ll> sum(64);
    vector<ll> dat(n);
    rep(i,n){
        cin>>dat[i];
        rep(j,60){
            if((dat[i]>>j)&1) sum[j]++;
        }
    }
    ll now=n,num=1;
    ll ans=0;
    rep(i,60){
        n=now;
        if(i!=0) num*=2;
        num%=MOD;
        rep(j,now-1){
            if((dat[j]>>i)&1){
                sum[i]--;
                n--;
                ans+=num*(n-sum[i])%MOD;
            }
            else{
                n--;
                ans+=num*(sum[i])%MOD;
            }
            ans%=MOD;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5556
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#define pq priority_queue
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;


int main(){
  int n;
  cin>>n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin>>a[i];
  }
  ll big=a[0],mid=a[1];
  for (int i = 0; i < n; i++) {
    big=max(big,a[i]);
  }
  for (int i = 0; i < n; i++) {
    if(abs(big-mid*2)>=abs(big-a[i]*2)) mid=a[i];
  }
  cout<<big<<' '<<mid<<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		final String S = sc.next();

		sc.close();

		String ans = "Yes";

		for (int i = 0; i < S.length(); i++) {
			final char c = S.charAt(i);
			if (i % 2 == 0) {
				if (!(c == 'R' || c == 'U' || c == 'D')) {
					ans = "No";
					break;
				}
			} else {
				if (!(c == 'L' || c == 'U' || c == 'D')) {
					ans = "No";
					break;
				}

			}
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 23636
n = int(input())
p = list(map(int, input().split()))

count = 0
for i in range(1,len(p)-1,1):
    if p[i+1] > p[i] and p[i] > p[i-1]:
        count = count +1
    elif p[i+1] < p[i] and p[i] < p[i-1]:
        count = count +1
    else:
        pass

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t,n,a,b;
    cin>>a>>b;
    if(a<10&&b<10)
    {
        cout<<a*b<<endl;
    }
    else
        cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int 	     	  long long   // [9,223,372,036,854,775,807 to -9.....808] 19 digits
#define pb                push_back 
#define all(x)            (x).begin(),(x).end()
#define mp                make_pair
#define vi                vector<int> 
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define x                 first
#define y                 second 
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define sz(x)             (int)((x).size())

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order()  // order_of_key

//const int32_t hellhsh = 444440583533; const double pi=2*acos(0.0); 
const int32_t mod = 1e9+7;
const int32_t maxn=2e5+5;
int inf=1e18;

void solve(){
    string a,b;cin>>a>>b;
    int n=sz(a),m=sz(b);
    int d[n][m];mem(d,0);

    rep(i,0,n){
        rep(j,0,m){
            if(!i or !j){
                d[i][j]=(a[i]==b[j]);
            }
            else {
                d[i][j]=max({d[i-1][j],d[i][j-1],d[i-1][j-1]+(a[i]==b[j])});
            }
        }
    }
    string s;
    int i=n-1,j=m-1;
    set<int> aa,bb;

    while(1){
        
        if(a[i]==b[j] and !aa.count(i) and !bb.count(j)){
            s.pb(a[i]);
            aa.insert(i);
            bb.insert(j);
        }
        if(!i and !j) break;

        if(!i) j--;
        else if(!j) i--;
        else {
            if(d[i][j]==d[i-1][j]) i--;
            else if(d[i][j]==d[i][j-1]) j--;
            else{
                i--;j--;
            }
        }
    }
    reverse(all(s));
    cout<<s;
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1,k=1;                                                                                                                  
    //cin>>tc;
    while(tc--){
        //cout<<"Case #"<<k++<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 74208
Input = input().split()
f = int(Input[0])
s = int(Input[1])
t = int(Input[2])

if f <= s <= t :print(f,s,t)
elif f <= t <= s :print(f,t,s)
elif s <= f <= t :print(s,f,t)
elif s <= t <= f :print(s,t,f)
elif t <= f <= s :print(t,f,s)
else:print(t,s,f)


Measured memory_bytes: 5596
use std::io;
//use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
use std::cmp; // cmp::max,cmp::min


#[allow(dead_code)]
fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char>{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_int() -> i64{
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String{
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n:i64) -> Vec<String>{
    let mut xs = Vec::new();

    for _i in 0..n{
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n:i64) -> Vec<i64>{
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

////////////////////////////////////////////////

fn count(b:i64,n:i64,k:i64) -> i64{
    // bが引数のbであとき，a%b>=kなるaの個数を返す関数

    if b <= k {
        return 0;
    }

    let chunk_size = cmp::max(0,b-k);// 1塊の中のtrueの数
    let n_chunk = n / b;    // ちゃんとあれしてるchunkの数
    let n_rest = n % b;     // 残った部分
    let candy = cmp::max(0,n_rest - k + 1);

    candy + chunk_size * n_chunk
}

fn main(){
    let inputs = read_ints();
    let (n,k) = (inputs[0],inputs[1]);

    if k==0{
        println!("{}",n*n);
        return;
    }

    let ans = (1..n+1).into_iter()
            .map(|b| count(b,n,k))
            .fold(0,|s,i|s+i);
    
    println!("{}",ans);
}

Measured memory_bytes: 4352
mod = 10**9+7
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
frac = [1]*(n+1)
finv = [1]*(n+1)
for i in range(n):
    frac[i+1] = (i+1)*frac[i]%mod
finv[-1] = pow(frac[-1],mod-2,mod)
for i in range(1,n+1):
    finv[n-i] = finv[n-i+1]*(n-i+1)%mod
def nCr(n,r):
    if n<0 or r<0 or n<r: return 0
    r = min(r,n-r)
    return frac[n]*finv[n-r]*finv[r]%mod
maxv = 0
for i,a in enumerate(A):
    maxv += nCr(i,k-1)*a
    maxv %=mod
minv = 0
for i,a in enumerate(A):
    minv += nCr(n-i-1,k-1)*a
    minv %= mod
print((maxv-minv)%mod)

Measured memory_bytes: 87656
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define all(x) x.begin(), x.end()

using namespace std;

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

const int N = 5e5+5;

void solve(){
	int x;
	cin>>x;
	int a=((x/10)%10)*10+x%10;
	if(5*(x/100)>=a)cout<<1;
	else cout<<0;
}

int main(){
	ios_base :: sync_with_stdio(false);
	int test = 1; 
	//cin >> test;	
	while (test--){
		solve();
	}
	return 0;
}

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

using namespace std;

int main()
{
	long long n, t, a;
	cin >> n >> t >> a;
	for (int i = 1; i < n; i++)
	{
		long long ti, ai;
		cin >> ti >> ai;
		auto m = max(t/ti + (t%ti > 0 ? 1 : 0), a/ai + (a%ai > 0 ? 1 : 0));
		t = max(ti, ti * m);
		a = max(ai, ai * m);
	}
	cout << t + a << endl;
	return 0;
}


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

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

    string s, t;
    cin >> s >> t;

    int res = 0;
    rep(i, s.size()){
        if(s[i] != t[i]) ++res;
    }

    cout << res << endl;

    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

vector<pair<int, LL>> G[100001];
int color[100001];

void solve(int now_idx, int now_color){
    REP(i, G[now_idx].size()) {
        if(color[G[now_idx][i].first] != -1) continue;
        int next_color = now_color;
        if(G[now_idx][i].second % 2 == 1) {
            if(next_color == 0) next_color = 1;
            else next_color = 0;
        }

        //cout << G[now_idx][i].first << " " << next_color << endl;

        color[G[now_idx][i].first] = next_color;
        solve(G[now_idx][i].first, next_color);
    }
}

void solve(long long N, std::vector<long long> u, std::vector<long long> v, std::vector<long long> w){
    REP(i, N) color[i] = -1;
    REP(i, N-1) {
        G[u[i]-1].PB(MP(v[i]-1, w[i]));
        G[v[i]-1].PB(MP(u[i]-1, w[i]));
    }

    int idx = -1;
    REP(i, N){
        if(G[i].size() == 1) {
            idx = i;
            break;
        }
    }

    color[idx] = 0;
    solve(idx, 0);

    REP(i, N) cout << color[i] << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> u(N-1);
    std::vector<long long> v(N-1);
    std::vector<long long> w(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&u[i]);
        scanf("%lld",&v[i]);
        scanf("%lld",&w[i]);
    }
    solve(N, std::move(u), std::move(v), std::move(w));
    return 0;
}


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

int main() {
    int N = 19;
    char S[19];
    cin >> S;

    if (strlen(S) != N) {
        return 0;
    }
    for (int i = 0; i < strlen(S); i++) {
        if (S[i] == ',') {
            S[i] = ' ';
        }
    }

    cout << S;
}

Measured memory_bytes: 256
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define DEBUG
#undef DEBUG

using ll  = long long;
using ull = unsigned long long;

int N, K;
ll A[5000];
ll S[5000]; // 累積和

void solve()
{
    sort(A, A+N);

    S[0] = A[0];
    FOR(i, 1, N) {
        S[i] = S[i-1] + A[i];
    }

    bool need[5000] = {};
    for(int i = N-1; i >= 0; --i) {
        if(A[i] >= K) {
            need[i] = true;
            continue;
        }

        for(int j = i-1; j >= 0; --j) {
            ll s = A[i] + S[j];
            if(s >= K) {
                need[i] = true;
                for(int k = j; k >= 0; --k) {
                    if(s - A[k] < K) {
                        need[k] = true;
                    }
                    else {
                        break;
                    }
                }
            }
            else {
                break;
            }
        }
    }

    int cnt = count(need, need+N, false);

    cout << cnt << "\n";
}

int main()
{
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 384
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, ipti().split()))
    node_next = [set() for _ in range(n)]

    for i in range(m):
        u, v = list(map(int, ipti().split()))
        node_next[u - 1].add(v - 1)

    s, t = list(map(int, ipti().split()))
    s, t = s - 1, t - 1

    dist = [[INF] * n for _ in range(3)]
    dist[0][s] = 0

    que = deque()
    que.append((0, s))

    while que:
        cstate, cnode = que.popleft()
        d = dist[cstate][cnode]
        nstate = (cstate + 1) % 3
        for nnode in node_next[cnode]:
            if dist[nstate][nnode] == INF:
                dist[nstate][nnode] = d + 1
                que.append((nstate, nnode))

    if dist[0][t] != INF:
        print(dist[0][t] // 3)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76536
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, m, s[5010][5010];
vi x, y;
vi vy, vx;

int main(){
	scanf("%d%d", &n, &m);
	rep(i, n){
		int a, b;
		scanf("%d%d", &a, &b);
		x.pb(a); y.pb(b);
		vx.pb(a); vy.pb(b);
	}
	vx.pb(-inf - 1); vy.pb(-inf - 1);
	vx.pb(inf + 1); vy.pb(inf + 1);
	sort(all(vx)); sort(all(vy));
	
	rep(i, n){
		int a = lower_bound(all(vx), x[i]) - vx.begin();
		int b = lower_bound(all(vy), y[i]) - vy.begin();
		s[a][b]++;
	}
	rep(i, vx.size()) rep(j, vy.size()){
		s[i + 1][j + 1] += s[i + 1][j] + s[i][j + 1] - s[i][j];
	}
	
	rep(i, m){
		int x, X, y, Y;
		scanf("%d%d%d%d", &x, &y, &X, &Y);
		x = lower_bound(all(vx), x) - vx.begin() - 1;
		y = lower_bound(all(vy), y) - vy.begin() - 1;
		X = lower_bound(all(vx), X + 1) - vx.begin() - 1;
		Y = lower_bound(all(vy), Y + 1) - vy.begin() - 1;
		
		printf("%d\n", s[X][Y] - s[x][Y] - s[X][y] + s[x][y]);
	}
	
	return 0;
}

Measured memory_bytes: 99256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int counter=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='o') counter=counter+1;
    }
    printf("%d",700+100*counter);
    return 0;
    
}

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

int main(){
  deque<int> dq;
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    int k; cin >> k;
    dq.push_front(k);
  }
  int prev = 0;
  long long count = 0;
  while(!dq.empty()) {
    int u = dq.front(); dq.pop_front();
    if (u != prev-1) {
      if (u < prev) {
        cout << -1 << endl;
        return 0;
      }
      count += (long long) u;
    }
    prev = u;
  }
  if (prev != 0) cout << -1 << endl;
  else cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;

const ll NMAX = 200005;
const ll INF = (ULLONG_MAX - 5);

ll n, x;
ll a[NMAX], S[NMAX];
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);

   cin >> n >> x;
   for (int i = 1; i <= n; i++)
      cin >> a[i], S[i] = S[i - 1] + a[i];

   ll minim = INF;
   for (int k = 1; k <= n; k++)
   {
      ll aici = 0;
      ll coef = 5;
      for (ll st = n - k + 1; st >= 1; st -= k)
      {
         // [st, st + k - 1]
         int dr = st + k - 1;
         aici += (S[dr] - S[st - 1]) * coef;

         if (coef == 5)
         {
            if (st != n - k + 1)
               coef = 7;
         }
         else
            coef += 2;

         if (st <= k) // ca sa nu scada sub 0
            break;
      }

      // ce a ramas
      if (n % k)
      {
         int st = 1, dr = n % k;
         aici += (S[dr] - S[st - 1]) * coef;
      }

      minim = min(minim, aici + k * x);
   }
   cout << minim + n * x;

   return 0;
}


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

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	string ans;
	if (c <= a + b) {
		ans = "No";
	}
	else if ((c - a - b) * (c - a - b) > 4 * a * b) {
		ans = "Yes";
	}
	else {
		ans = "No";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256