akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<iomanip>
#include<stdlib.h>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<algorithm>
#include<complex>
using namespace std;
#define loop(i,l,r) for(int (i)=(int)(l);(i)<(int)(r);(i)++)
#define rloop(i,l,r) for(int (i)=(int)(l);(i)>(int)(r);(i)--)
#define rep(i,n) loop(i,0,n)
#define rrep(i,n) rloop(i,n-1,-1)
#define INF 0x3f3f3f3f
#define mod 1000000007LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef complex<double> C;

int main(){
		ll a,b,t;
		cin>>a>>b;
		if(a>0){
				cout<<"Positive"<<endl;
		}else if(a==0){
				cout<<"Zero"<<endl;
		}else{
				if(b>=0){
						cout<<"Zero"<<endl;
				}else{
						if((b-a)%2==1){
								cout<<"Positive"<<endl;
						}else{
								cout<<"Negative"<<endl;
						}
				}
		}
}



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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K;
int S[101010];
signed main(){
    while(cin>>N>>K,N||K){
    rep(i,N){
        cin>>S[i+1];
        S[i+1]+=S[i];
    }

    int ma=-1001001001001001001ll;
    for(int i=0;i+K<=N;i++)chmax(ma,S[i+K]-S[i]);
    cout<<ma<<endl;
    }
    return 0;
}

Measured memory_bytes: 1940
n,m = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
g=0
for i in range(n):
    g=g+a[i] 
for i in range(n):
    if a[i]>=g/(4*m):
        ans+=1
if ans >= m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
string s[1000010];
ll a[1000010],b[1000010];
vector<int> G[3];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> s[i];
    }
    rep(i,n){
        int m=s[i].length();
        ll res=0;
        rep(j,m){
            if(s[i][j]=='(') res+=1;
            else res-=1;
            b[i]=min(b[i],res);
        }
        a[i]=res;
        //cout << a[i] << " " << b[i] << endl;
        if(b[i]>=0){
            G[0].push_back(i);
        }
        else if(a[i]>=0 && b[i]<0){
            G[1].push_back(i);
        }
        else{
            G[2].push_back(i);
        }
    }
    ll M=0;
    rep(i,n){
        M+=a[i];
    }
    if(M!=0) {
        cout << "No" << endl;
        return;
    }
    ll S=0;
    for(int t:G[0]){
        S+=a[t];
    }
    b[n]=-INF;
    G[1].push_back(n);
    sort(G[1].begin(),G[1].end(),[](int p,int q){return b[p]>b[q];});
    G[2].push_back(n);
    sort(G[2].begin(),G[2].end(),[](int p,int q){return -a[p]+b[p]>-a[q]+b[q];});
    // for(int t:G[1]){
    //     cout << b[t] << endl;
    // }
    priority_queue<ll> que={};
    int now=0;
    bool ans=true;
    for(int t:G[1]){
        if(b[t]==-INF) break;
        while(b[G[1][now]]+S>=0){
            //cout << b[G[1][now]] << endl;
            que.push(a[G[1][now]]);
            now+=1;
        }
        if(que.empty()){
            ans=false;
            break;
        }
        S+=que.top();que.pop();
    }
    ll T=0;
    priority_queue<ll,vector<ll>,greater<ll>> que2={};
    now=0;
    for(int t:G[2]){
        //cout << -a[t] << " " << b[t] << endl;
        if(b[t]==-INF) break;
        while(-a[G[2][now]]+b[G[2][now]]>=T){
            //cout << b[G[2][now]] << endl;
            que2.push(a[G[2][now]]);
            now+=1;
        }
        if(que2.empty()){
            ans=false;
            break;
        }
        T+=que2.top();que2.pop();
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

Measured memory_bytes: 58216
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>

using namespace std;

long long N, M, cost[100000], x, y;
long long visited[100000];
long long selected[100000];
vector<long long> adj[100000];
long long min_cost, min_cost_ver;
queue<long long> qu;
long long least_unvisited, num_of_conn_cmp, ans, p, q;

int main() {

	scanf("%lld %lld", &N, &M);

	for (int i = 0; i < N; i++) {
		scanf("%lld", &cost[i]);
	}

	for (int i = 0; i < M; i++) {
		scanf("%lld %lld", &x, &y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	for (int i=0; i < N; i++) {
		visited[i] = 0; selected[i] = 0;
	}

	least_unvisited = 0;
	num_of_conn_cmp = 0;
	ans = 0;
	while (least_unvisited<N) {
		num_of_conn_cmp++;
		qu.push(least_unvisited);
		min_cost = 1000000000;
		visited[least_unvisited] = 1;
		while (qu.empty() == 0) {
			p = qu.front();
			qu.pop();
			if (min_cost>cost[p]) {
				min_cost = cost[p];
				min_cost_ver = p;
			}
			for (int i = 0; i<adj[p].size(); i++) {
				q = adj[p][i];
				if (visited[q] == 0) {
					visited[q] = 1;
					qu.push(q);
				}
			}
		}
		ans = ans + min_cost;
		selected[min_cost_ver] = 1;

		/*least_unvisitedを更新*/
		while (visited[least_unvisited] == 1) { least_unvisited++; if (least_unvisited == N) { break; } }
	}

	if (num_of_conn_cmp == 1) { printf("0\n"); return 0; }/*連結なら0*/

	if (2 * num_of_conn_cmp - 2 > N) { printf("Impossible\n"); return 0; }

	long long cost_unselected[100000];
	int j = 0;
	for (int i = 0; i<N; i++) {
		if (selected[i] == 0) { cost_unselected[j] = cost[i]; j++; }
	}

	sort(cost_unselected, cost_unselected + j);

	for (int i = 0; i<num_of_conn_cmp - 2; i++) {
		ans = ans + cost_unselected[i];
	}

	printf("%lld\n", ans);
}

Measured memory_bytes: 9344
#include <cstdio>

int main()
{
	int H, W, N, a;
	int board[100][100];
	scanf("%d %d", &H, &W);
	scanf("%d", &N);
	int y = 0, x = 0;
	for (int i = 1; i <= N; i++) {
		scanf("%d", &a);
		while (a) {
			board[y][x] = i;
			if (y % 2 == 0) {
				x++;
				if (x == W) {
					x--;
					y++;
				}
			}
			else {
				x--;
				if (x == -1) {
					x++;
					y++;
				}
			}
			a--;
		}
	}
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++)
			printf("%d ", board[y][x]);
		printf("\n");
	}
}

Measured memory_bytes: 256
class Node:
    def __init__(self, idx, key):
        self.idx = idx
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

    def print_self(self):
        s = 'node {}: key = {}, '.format(self.idx + 1, self.key)
        if self.parent is not None:
            s += 'parent key = {}, '.format(self.parent)
        if self.left is not None:
            s += 'left key = {}, '.format(self.left)
        if self.right is not None:
            s += 'right key = {}, '.format(self.right)
        print(s)

n = int(input())
array = list(map(int, input().split()))
heap = []

for i in range(n):
    node = Node(i, array[i])
    heap.append(node)

for i in range(1, n):
    node = heap[i]
#    parent = heap[i // 2]
    parent = heap[(i+1) // 2 - 1]
    node.parent = parent.key
    # print('i//2: ' + str(i//2))
    # print('parent : ' + str(parent))
    if i % 2 == 1:
        parent.left = node.key
    else:
        parent.right = node.key

for i in range(n):
    node = heap[i]
    node.print_self()



Measured memory_bytes: 5628
import java.util.Scanner;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String b = sc.next();
        if (b.equals("A")) {
        	System.out.println("T");
        }
        if (b.equals("T")) {
        	System.out.println("A");
        }
        if (b.equals("C")) {
        	System.out.println("G");
        }
        if (b.equals("G")) {
        	System.out.println("C");
        }
    }

}

Measured memory_bytes: 20564
def digitSum(n):
    digitSum = 0
    while n > 0:
        digitSum += n%10
        n //= 10
    return digitSum

n = int(input())
n_str = str(n)

left = 0
right = 0

if n_str[0] == 1:
    left = int("9" * (len(n_str) - 1))
    right = int("1" + left)
else:
    left = int(str(int(n_str[0])-1) + "9" * (len(n_str) - 1))
    right = int(n_str[0] + "9" * (len(n_str) - 1))

if left <= n < right:
    print(digitSum(left))
elif n == right:
    print(digitSum(right))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <numeric>
using namespace std;
using Int = long long;
#define REP(i, n) for(int i = 0; i < n; i++)
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    int N, K; cin >> N >> K;
    int b1 = 0; REP(i, K) { int x; cin >> x; b1 |= (1 << x); }
    int n = N;
    for (;;) {
        int b2 = 0;
        int k = n;
        while (k) {
            b2 |= (1 << (k % 10));
            k /= 10;
        }
        if ((b1 & b2) == 0) {
            cout << n << endl;
            return 0;
        }
        n++;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			a = new int[10];
			while (n-- > 0) {
				int b = scanner.nextInt();
				a[b]++;
			}
			int sum = 0;
			for (int i = 1; i < 5; i++) {
				int c = Math.min(a[i], a[10 - i]);
				sum += c;
				a[i] -= c;
				a[10 - i] -= c;
			}
			sum += a[5] / 2;
			a[5] %= 2;

			ans = 0;
			dfs(1, 0, 0);
			System.out.println(sum + ans);

		}
	}

	private void dfs(int i, int sum, int now) {
		int rem = sum;
		for (int j = 1; j < 10; j++)
			rem += a[j] * j;
		if (now + rem / 10 <= ans)
			return;
		ans = Math.max(ans, now);
		if (sum == 10) {
			dfs(1, 0, now + 1);
			return;
		}
		if (i == 10)
			return;
		dfs(i + 1, sum, now);
		if (a[i] > 0 && i + sum <= 10) {
			a[i]--;
			dfs(1, sum + i, now);
			a[i]++;
		}
	}

	int ans;
	int[] a;
}

Measured memory_bytes: 33044
import java.util.Scanner;

public class Main {

	private static final long x = (long) Math.pow(10, 18);

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = x / 100;
		int z = x - y * 100;

		for (int i = 0; i < y; i++) {
			if (z / 5 > 0) {
				z -= 5;
			} else if (z / 4 > 0) {
				z -= 4;
			} else if (z / 3 > 0) {
				z -= 3;
			} else if (z / 2 > 0) {
				z -= 2;
			} else {
				z -= 1;
			}
		}

		if (z <= 0) {
			System.out.println("1");
		} else {
			System.out.println("0");
		}

		sc.close();
	}

}


Measured memory_bytes: 35644
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,k;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	if(m-n+1<=2*k)
		for(int i=n;i<=m;i++)
			printf("%d\n",i);
	else if(k>=m-n+1)
		for(int i=n;i<=m;i++)
			printf("%d\n",i);
	else
	{
		for(int i=n;i<=n+k-1;i++)
			printf("%d\n",i);
		for(int i=m-k+1;i<=m;i++)
			printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int S, W; std::cin >> S >> W;
  if ( W >= S ) std::cout << "unsafe" << std::endl;
  else std::cout << "safe" << std::endl;
  return 0;
}



Measured memory_bytes: 3664
def main():
    import sys
    readline = sys.stdin.readline
    # readlines = sys.stdin.readlines
    H, N = map(int, input().split())
    M = [tuple(map(int, readline().split())) for _ in range(N)]
    INF = 10 ** 9
    dp = [INF] * (H + 1)
    dp[0] = 0
    
    for i in range(N):
        a, b = M[i]
        for j in range(H):
            nj = min(H, j + a)
            dp[nj] = min(dp[nj], dp[j] + b)

    print(dp[H])


if __name__ == "__main__":
    main()


Measured memory_bytes: 40560
use std::collections::HashSet;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
	input! {
        abc : [usize ; 3]
    }
	
	let m: HashSet<usize> = abc.into_iter().collect();
	println!("{}", if m.len() == 2 { "Yes" } else { "No" })
}

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

int main(){
    string S;
    int x,y;
    cin >> S >> x >> y;
    int s=S.size();
    int j=0;
    while (j<s&&S[j]=='F'){
        j++;
    }
    bool dir=true;
    int cx=0,cy=0;
    vector<int> vx,vy;
    for (int i=j;i<s;i++){
        if (S[i]=='T'){
            dir^=1;
            vx.push_back(cx);
            vy.push_back(cy);
            cx=cy=0;
        }
        else if (dir){
            cx++;
        }
        else {
            cy++;
        }
        if (S[i]=='F'&&i==s-1){
            vx.push_back(cx);
            vy.push_back(cy);
        }
    }
    int sx=vx.size(),sy=vy.size();
    int sumx=0,sumy=0;
    rep (i,sx){
        sumx+=vx[i];
    }
    rep (i,sy){
        sumy+=vy[i];
    }
    int rx=sumx-abs(j-x),ry=sumy-abs(y);
    if (rx%2==0&&rx>=0&&ry%2==0&&ry>=0){
        rx/=2,ry/=2;
        vector<vector<bool>> dpx(sx+1,vector<bool>(8001,false));
        dpx[0][0]=true;
        rep (i,sx){
            rep(k,8001){
                if (dpx[i][k]){
                    dpx[i+1][k]=true;
                    dpx[i+1][k+vx[i]]=true;
                }
            }
        }
        vector<vector<bool>> dpy(sy+1,vector<bool>(8001,false));
        dpy[0][0]=true;
        rep (i,sy){
            rep(k,8001){
                if (dpy[i][k]){
                    dpy[i+1][k]=true;
                    dpy[i+1][k+vy[i]]=true;
                }
            }
        }
        if (dpx[sx][rx]&&dpy[sy][ry]){
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 16512
N, M = map(int, input().split())
heights = list(map(int, input().split()))
roads = [list(map(int, input().split())) for i in range(M)]

good = [1 for i in range(N)]

for road in roads:
  if heights[road[0]-1] > heights[road[1]-1]:
    good[road[1]-1] = 0
  elif heights[road[0]-1] < heights[road[1]-1]:
    good[road[0]-1] = 0
  else:
    good[road[0]-1] = 0
    good[road[1]-1] = 0

print(sum(good))

Measured memory_bytes: 31916
N = int(input())
numbers = list(map(int,input().split()))
min_abs = sum(numbers)
for i in range(N-1):
  	# 全てのパターンを試して、一番小さいabsをmin_absとして出力。T以下とTより大きいのグループ比較にはスライスを活用して。
    min_abs = min(min_abs,abs(sum(numbers[:i+1])-sum(numbers[i+1:])))
print(min_abs)

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

int x;

int gcd(int x, int y) { return x? gcd(y % x, x): y; }

int main()
{
    cin >> x;
    int lcm = x / gcd(x, 360) * 360;
    cout << lcm / x << endl;
    return 0;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI d(n);
  ll ans = 100;
  rep(i,n){
    cin >> d[i];
    ans = min<ll>(d[i],ans);
  }
  sort(all(d));

  VI r, l;
  rep(i,n){
    if(d[i] == 12){
      l.push_back(d[i]);
      r.push_back(d[i]);
      continue;
    }

    if(i % 2 == 0){
      r.push_back(d[i]);
    }else{
      l.push_back(d[i]);
    }
  }

  rep(i,(int)r.size() - 1) ans = min<ll>(r[i+1] - r[i], ans);
  rep(i,(int)l.size() - 1) ans = min<ll>(l[i+1] - l[i], ans);
  if(r.back() != 12){
    if(r.size() >= 1 && l.size() >= 1)ans = min<ll>(ans,24-r.back()-l.back());
  }

  cout << ans << endl;
  return  0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	string s;
	cin >> s;
	string y = s.substr(0, 4);
	string m = s.substr(5, 2);
	string d = s.substr(8, 2);
	if (y <= "2019"&&m <= "04"&&d <= "30") {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
vector<vector<ll> > g(100001);
map<pair<ll,ll> ,ll> mp;
ll ma=0;
bool niko[100001];
void dfs(ll n,ll m){
    ll maki=g[n].size();
    niko[n]=true;
    ll index=1;
    for(int i=0;i<maki;i++){
        if(!niko[g[n][i]]){
            if(index==m)index++;
            mp[make_pair(n,g[n][i])]=mp[make_pair(g[n][i],n)]=index;
            ma=max(ma,index);
            dfs(g[n][i],index);
            //cout << index<<endl;
            index++;
        }
    }
    return;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll x[n],y[n];
    memset(niko,0,sizeof(niko));
    
    
    for(int i=0;i<n-1;i++){
        cin>>x[i]>>y[i];
        x[i]--;y[i]--;
        g[x[i]].pb(y[i]);
        g[y[i]].pb(x[i]);
    }
    dfs(0,0);
    cout << ma<<endl;
    for(int i=0;i<n-1;i++){
        cout <<mp[make_pair(x[i],y[i])]<<endl;
    }
    return 0;
}


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

const int MAXN = 110;
typedef long long LL;
const LL INF = std::numeric_limits<LL>::max() - 10;
int n, xs[MAXN], ys[MAXN];
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], tot;
void addedge(int b, int e) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e;
	nxt[++tot] = head[e]; to[head[e] = tot] = b;
}
typedef std::pair<int, int> pi;
int dfs(int u, int fa = 0) {
	int res = 0;
	for (int i = head[u]; i; i = nxt[i])
		if (to[i] != fa)
			res = std::max(res, dfs(to[i], u));
	return res + 1;
}
int maxd, degs[MAXN], deg[MAXN];
void dfs2(int u, int dep, int fa) {
	maxd = std::max(maxd, dep);
	degs[dep] = std::max(degs[dep], deg[u]);
	for (int i = head[u]; i; i = nxt[i])
		if (to[i] != fa)
			dfs2(to[i], dep + 1, u);
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	int rtv = n; LL Ans = INF;
	for (int i = 1; i < n; ++i) {
		std::cin >> xs[i] >> ys[i];
		addedge(xs[i], ys[i]);
		++deg[xs[i]], ++deg[ys[i]];
	}
	for (int i = 1; i <= n; ++i)
		rtv = std::min(rtv, dfs(i));
	for (int i = 1; i < n; ++i)
		rtv = std::min(rtv, std::max(dfs(xs[i], ys[i]), dfs(ys[i], xs[i])));
	for (int i = 1; i <= n; ++i)
		if (dfs(i) == rtv) {
			memset(degs, 0, maxd + 1 << 2);
			maxd = 1;
			dfs2(i, 1, 0);
			++degs[1];
			long long ans = 1;
			long double fa = 1;
			for (int i = 1; i < maxd; ++i) {
				ans *= degs[i] - 1;
				fa *= degs[i] - 1;
			}
			if (fa < Ans + 10) Ans = std::min(Ans, ans);
		}
	for (int i = 1; i < n; ++i)
		if (std::max(dfs(xs[i], ys[i]), dfs(ys[i], xs[i])) == rtv) {
			memset(degs, 0, maxd + 1 << 2);
			maxd = 1;
			degs[1] = 3;
			dfs2(xs[i], 2, ys[i]);
			dfs2(ys[i], 2, xs[i]);
			long long ans = 1;
			long double fa = 1;
			for (int i = 1; i < maxd; ++i) {
				ans *= degs[i] - 1;
				fa *= degs[i] - 1;
			}
			if (fa < Ans + 10) Ans = std::min(Ans, ans);
		}
	std::cout << rtv << ' ' << Ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int a,b,x;
  scanf("%d%d%d",&a,&b,&x);
  if(x<=a+b && x>=a){
    printf("YES\n");
  } else {
    printf("NO\n");
  }
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define f(a,j,k) for(int i = a ; i < j ; i += k)
#define f1(a,j,k) for(int i = a ; i > j ; i -= k)
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
typedef pair<int,int> pri;
typedef pair<long long,long long> prl;
ll cnt[200001];
int a[200001];
int main() {
	std::ios::sync_with_stdio(false);
	int n , x , y;
	cin >> n >> x >> y;
	int ans[n+5] = {0};
	f(1,n,1){
		  int j = i + 1;
			while(j <= n){
				 ans[min(j-i,abs(i-x)+abs(j-y)+1)]++;
				 ++j;
			}
	}
	f(1,n,1) cout << ans[i] << endl;
	return 0;
}


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

int main(){
    int A,B;
    int ans;
    ans=0;
    cin >> A >> B;
    for(int i=0;i<2;i++){
        if(A>B){
            ans += A;
            A -= 1;
        }else{
            ans += B;
            B -= 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

res = []

if n%2 is not 0:
  print('No')
if n%2 == 0:
  tl = s[0:(n//2)]
  t_list = list(tl)
  if s.count(tl) == 2:
    print('Yes')
  else:
    print('No')
    
  

Measured memory_bytes: 2940
# フェルマーの小定理
def mcomb(n, k):
    a = 1
    b = 1
    for i in range(k):
        a *= n - i
        a %= m
        b *= i + 1
        b %= m
    return a * pow(b, m - 2, m) % m


n, a, b = map(int, input().split())

m = 1000000007

result = pow(2, n, m) - 1
result += m - mcomb(n, a)
result %= m
result += m - mcomb(n, b)
result %= m
print(result)


Measured memory_bytes: 9104
#include<cstdio>
#include<iostream>
using namespace std;
const int Maxn=100000+20;
int f[Maxn][3];
int r,s,p,n,k,ans;
char a[Maxn];
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
inline int val(int pos,int x)
{
	if(a[pos]=='r' && x==2)return p;
	else if(a[pos]=='p' && x==1)return s;
	else if(a[pos]=='s' && x==0)return r;
	return 0;
}
int main()
{
//	freopen("in.txt","r",stdin);
	n=read(),k=read();
	r=read(),s=read(),p=read();
	scanf("%s",a+1);
	for(int i=1;i<=n;++i)
	{
		for(int j=0;j<3;++j)
		{
			char tmp=a[i];
			f[i][j]=val(i,j);
			if(i-k<=0)continue;
			int u,v;
			if(j==0)u=1,v=2;
			if(j==1)u=2,v=0;
			if(j==2)u=1,v=0;
			f[i][j]=max(f[i-k][u],f[i-k][v])+val(i,j);
		}
	}
	for(int i=n;i>=n-k+1;--i)
	ans+=max(f[i][0],max(f[i][1],f[i][2]));
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
  string n; cin >> n;
  int a = n[n.size() - 1] - '0';
  if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9)
    cout << "hon" << endl;
  else if (a==0||a==1||a==6||a==8)
    cout << "pon" << endl;
  else
    cout << "bon" << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else
      x = x->right;
  }
  z->parent = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else
    y->right = z;
}

void inorder(Node u){

  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){

  if(u != NIL){
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25120
def solve():
    S = input()
    idx = len(S)
    while idx-5 >= 0:
        if S[idx-5:idx] in ["dream","erase"]:
            idx -= 5
        elif idx-6 >= 0 and S[idx-6:idx] == "eraser":
            idx -= 6
        elif idx-7 >=0 and S[idx-7:idx] == "dreamer":
            idx -= 7
        else:
            print('NO')
            return
    else:
        if idx == 0:
            print('YES')
        else:
            print('NO')

if __name__ == '__main__':
    solve()

Measured memory_bytes: 68536
n,k = map(int,input().split())
freq = [0] * n
for _ in range(k):
	d = int(input())
	l = list(map(int,input().split()))
	for i in l:
		freq[i-1] += 1
count = 0
for i in freq:
	if i==0:
		count += 1
print(count)

Measured memory_bytes: 67440
#include <iostream>
#include "bits/stdc++.h"

using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i, a, b) for(ll i=a;i<b;i++)
#define REP(i, a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i, a) for(ll i=a-1;i>=0;i--)
#define rrep(i, a, b) for(ll i=a-1;i>=b;i--)
#define printall(n, array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
typedef vector<vector<ll>> VVE;
const ll mod = 1e9 + 7; //10^9+7


int main() {
    ll n;
    cin >> n;
    VE a(n);
    ll neg = 0;
    ll min_ = mod;
    ll sum = 0;
    REP(i, n){
        cin >> a[i];
        if(a[i] < 0)neg++;
        sum += abs(a[i]);
        min_ = min(min_, abs(a[i]));
    }
    if(neg % 2) {
        sum -= min_ * 2;
    }
    print(sum);
}

Measured memory_bytes: 1024
s=input()
n=int(s)

d={}

for i in range(1,n+1):
	ts=str(i)
	hs=ts[0]+" "+ts[len(ts)-1]

	if(hs in d):
		d[hs]+=1
	else:
		d[hs]=1



ans=0

for i in range(1,10):
	for j in range(1,10):
		if(((str(i)+" "+str(j)) in d) and ((str(j)+" "+str(i)) in d)):
			ans+=d[(str(i)+" "+str(j))]*d[(str(j)+" "+str(i))]

print(ans)




Measured memory_bytes: 41580
/**
*    author:  souzai32
*    created: 02.08.2020 13:17:06
**/

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

int main() {

    long int n,k,s;
    cin >> n >> k >> s;

    vector<int> num(n,s);

    for(int i=k; i<n; i++){
        num.at(i)++;
        if(s==1000000000) num.at(i)=1;
    }

    rep(i,n) cout << num.at(i) << ' ';
    cout << endl;

    return 0;
}

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

int main() {
	int N;
	cin >> N;
	int out = 111;
	while (out < N)out += 111;
	cout << out;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

ループ回して等しくなったらやるという方法もあるが、もうちょっと簡単な方法がある
答えは111, 222, ...と111の倍数になることは自明
なので、単にこれを回してN以上になったら出力すれば良い
*/

Measured memory_bytes: 256
require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########


# 約数
def divisors(num)
  return [1] if num == 1

  pows = []
  # 0乗、1乗・・・した値を入れる
  num.prime_division.each do |b, r|
    pow = []
    0.upto(r).each do |n|
      pow << b ** n
    end

    pows << pow
  end

  first_array = pows.shift
  return first_array if pows.size == 0

  result = first_array.product(*pows)
  result.map do |item|
    item.inject { |sum, i| sum * i }
  end.sort
end

def can?(n,k)
  return true if k==1||n==1
  
  if n%k==0
    can?(n/k,k)
  else
    n%k==1
  end
end

n=gi
divs=(divisors n) - [1]
#pu divs:divs.to_s
cnt=0
# 約数は全部試す
divs.each do |d|
  cnt+=1 if can?(n,d)
end
#pu cnt:cnt
# あまりが1となる数 約数を除く
divs2=(divisors n-1) - [1]
#pu divs2:divs2.to_s
puts cnt+(divs2-divs).size

Measured memory_bytes: 3320
#include<iostream>
using namespace std;
int main() {
    int a;
    cin >> a;
    int b = a / 60;
    int m = b % 60;
    int h = b / 60;
    int s = a % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}
   


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll N,T;
    cin>>N>>T;
    vector<ll>t(N);
    rep(i,N){
        cin>>t[i];
    }
    ll ans=T;
    for(ll i=0; i<N-1; ++i){
        if((t[i+1]-t[i])<T){
            ans+=(t[i+1]-t[i]);
        }
        else{
            ans+=T;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
    int N, K;
    string str;
 
    cin >> N >> K;
    cin >> str;
 
    int num_of_happiness = 0;
    char last_char;
 
    for (int i = 0; i<N; i++) {
        if (i == 0) {
            last_char = str[i];
        } else {
            if (last_char == str[i]) {
                num_of_happiness += 1;
            } 
            last_char = str[i];
        }
    }
 
    int res = num_of_happiness + 2 * K;
    if ((N-1) < res) {
        res = N-1;
    } 
 
    cout << res;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
#define pb push_back
#define SZ(x) ((int)x.size())
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vint;
typedef long long LL;
typedef pair<int,int> PII;
const int N=500010;
int read(){
	char c=getchar();int d=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';d=d*10+c-48,c=getchar());
	return d*f;
}
int n,q,m,cnt,s[N],res[N];
int a[N];
multiset<PII> S;
vector<PII> p,px,py,pz,rd;int Rd[N];
bool cmpse(PII a,PII b){return a.se<b.se;}
void upd(int x,int s){	
	for(;x<=m;x+=x&-x)a[x]+=s;
}
int ask(int x){int s=0;
	for(;x;x-=x&-x)s+=a[x];return s;
}
int main(){
	n=read();
	ref(i,1,n*3+1)rd.pb(mp(read(),i));
	q=read();
	ref(i,1,q*2)rd.pb(mp(read(),n*3+1+i));
	sort(rd.begin(),rd.end());
	for(int i=0,la=-1;i<SZ(rd);++i){
		m+=rd[i].fi!=la;la=rd[i].fi;
		Rd[rd[i].se]=m;
	}
	ref(i,1,n){
		int a=Rd[++cnt],b=Rd[++cnt];
		s[a]++;if(b<a)p.pb(mp(b,a-1));
	}
	ref(i,1,n+1)s[Rd[++cnt]]--;
	ref(i,1,m)if(s[i])upd(i,s[i]);
	px=py=p;
	ref(i,0,SZ(px)-1)swap(px[i].fi,px[i].se);
	sort(px.begin(),px.end(),cmpse);
	sort(py.begin(),py.end(),cmpse);
	S.clear();S.insert(mp(1e9,1e9));
	bool flag=1;
	int rs=n;
	for(int i=m,cntb=SZ(py)-1;i>=1;--i){
		int s=ask(i);if(s>=-1)continue;s=-1-s;
		while(cntb>=0&&py[cntb].se>=i)S.insert(py[cntb--]);
		while(s){
			multiset<PII>::iterator it=S.lower_bound(mp(0,0));
			PII w=*it;
			if(w.fi>i){flag=0;break;}
			upd(w.se+1,-1);
			upd(w.fi,1);
			S.erase(it);
			pz.pb(mp(w.se,w.fi));
			rs--;s--;
		}
		if(!flag)break;
	}
	sort(pz.begin(),pz.end(),cmpse);
	if(!flag){
		ref(i,1,q)puts("-1");
		return 0;
	}
	S.clear();S.insert(mp(1e9,1e9));S.insert(mp(0,0));
	ref(i,1,m)res[i]=-1e9;
	for(int i=1,cnta=0,cntb=0;i<=m;++i){
		res[i]=rs;
		int s=ask(i);if(s>=0)continue;s=-s;
		while(cnta<SZ(px)&&px[cnta].se<=i)S.insert(px[cnta++]);
		while(cntb<SZ(pz)&&pz[cntb].se<=i)S.erase(S.lower_bound(pz[cntb++]));
		while(s){
			multiset<PII>::iterator it=--S.lower_bound(mp(1e9,1e9));
			PII w=*it;
			if(w.fi<i){flag=0;break;}
			upd(w.fi+1,-1);
			upd(w.se,1);
			S.erase(it);
			rs--;s--;
		}
		if(!flag)break;
	}
	ref(i,1,q){
		int a=Rd[++cnt],b=Rd[++cnt];
		int ans=max(res[a]+1,res[b]);
		if(ans<0)ans=-1;
		printf("%d\n",ans);
	}
}

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

class Union_Find{
  vector<int> par; vector<int> rank; vector<int> num;
public:
  Union_Find(int n) {
    par = vector<int>(n); rank = vector<int>(n,0); num = vector<int>(n,1);
    rep(i,n) par[i] = i;
  }
  int find(int x) {
    if(par[x] == x) return x;
    else  return par[x] = find(par[x]);
  }
  int number(int x) {
    return num[find(x)];
  }
  void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x;
    num[x] += num[y];
  } 
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  int a[m], b[m], c[k], d[k];
  vector<int> ans(n,0);
  Union_Find uf(n);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    uf.unite(a[i],b[i]);
  }
  rep(i,k) {
    cin >> c[i] >> d[i];
    c[i]--; d[i]--;
  }
  rep(i,n) ans[i] = uf.number(i) - 1;
  rep(i,m) {
    ans[a[i]]--;
    ans[b[i]]--;
  }
  rep(i,k) {
    if(uf.same(c[i],d[i])) {
      ans[c[i]]--;
      ans[d[i]]--;
    }
  }
  rep(i,n) cout << ans[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <stack>
using namespace std;
int main()
{
    stack<int>  stk;
    int         car;
    while (cin >> car) {
        if (car) {
            stk.push(car);
        } 
        else {
            cout << stk.top() << endl;
            stk.pop();
        }
    }
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define Maxn 110
using namespace std;
int pos = 0;
vector<int> Pre, In, Post;
void rec(int l, int r){
	if(l >= r) return;
	int root = Pre[pos++];
	int m = distance(In.begin(), find(In.begin(), In.end(), root));
	rec(l, m);
	rec(m + 1, r);
	Post.push_back(root);
}
int main()
{	
	int n, k;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &k);
		Pre.push_back(k);
	} 
	for(int i = 1; i <= n; i++){
		scanf("%d", &k);
		In.push_back(k);
	}
	
	rec(0, Pre.size());
	for(int i = 0; i < n; i++){
		if(i) printf(" ");
		printf("%d", Post[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 3272
using System;

public class Hello
{
    public static void Main()
    {
        var a = new double[] { 165, 170, 175, 180, 185 };
        var b = new int[6];
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var h = double.Parse(Console.ReadLine().Trim());
            for (int j = 0; j < 5; j++)
                if (h < a[j]) { b[j]++; goto next; }
            b[5]++;
            next:;
        }
        for (int i = 0; i < 6; i++)
            Console.WriteLine("{0}:{1}", i + 1, new string('*', b[i]));
    }
}



Measured memory_bytes: 9076
K, N = list(map(int, input().split()))
A = list(sorted(list(map(int, input().split()))))
A.append(A[0]+K)
d_max = 0
for i in range(len(A)-1):
  d_max = max([A[i+1]-A[i], d_max])
print(K - d_max)

Measured memory_bytes: 26004
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int main(void)
{
  int N, K;
  cin >> N >> K;
  cout << (N % K == 0 ? 0 : 1) << endl;
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll k,x,y;
	cin>>k>>x>>y;
	if(k%2==0&&(abs(x)+abs(y))%2==1) {
		cout<<-1<<endl;
		return 0;
	}
	ll ans=(abs(x)+abs(y)+k-1)/k;
	if(ans==1&&abs(x)+abs(y)!=k) ans++;
	while((ans*k-abs(x)-abs(y))%2==1) ans++;
	cout<<ans<<endl;
	ll b=(ans*k-abs(x)-abs(y))/2,curx=0,cury=0;
	while(b>0) {
		bool cmp=abs(x-curx)<abs(y-cury);
		ll move=min(b,k);
		if(cmp)
			if(x>=0) curx-=move;
			else curx+=move;
		else
			if(y>=0) cury-=move;
			else cury+=move;
		ll left=k-move;
		if(cmp)
			if(cury<y) cury+=left;
			else cury-=left;
		else
			if(curx<x) curx+=left;
			else curx-=left;
		b-=move;
		cout<<curx<<' '<<cury<<endl;
	}
	while(curx!=x||cury!=y) {
		ll left=k;
		if(curx!=x) {
			ll move=min(k,abs(x-curx));
			if(curx>x) curx-=move;
			else curx+=move;
			left-=move;
		}
		if(cury!=y) {
			ll move=min(left,abs(y-cury));
			if(cury>y) cury-=move;
			else cury+=move;
		}
		cout<<curx<<' '<<cury<<endl;
	}
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#define MAX 100010
#define VMAX 1000000000

using namespace std;

int n,k,uc,ms,ans,ansa,ss,sd;
int a[MAX];

int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++){
      cin>>a[i];
      if(a[i]<0)uc=i;
    }
    ans=VMAX;
    for(int ms=0;ms<=uc&&ms<=k;ms++){
      if(ms+(n-uc)<k)continue;
      if(ms==0)ss=0;
      else ss=-a[uc-ms+1];
      if(ms==k)sd=0;
      else sd=a[uc+k-ms];
      ansa=min(ss*2+sd,sd*2+ss);
      ans=min(ans,ansa);
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 640
const main = (input) => {
  input = input.split(' ');
  const str1 = input[0];
  const str2 = input[1];
  const str3 = input[2];
  
  console.log(str1.charAt()+str2.charAt()+str3.charAt());
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main (){
	int N ;
	int line[N] = {} ;
	cin >> N ;
	for( int i = 0 ; i < N ; i++ ) {
		int a ;
		cin >> a ;
		line[i] = a - 1 ;
	}
	int ans = 0 ;
	for(int i = 0 ; i < N ; i++ ){
		if(line[line[i]]==i) ans++ ;
	}
	ans /= 2 ;
	cout << ans << endl ;
}

Measured memory_bytes: 16640
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 4e3+5;
int n, x, a[N], q[N], l, r;
int64 ans;
int main()
{
    n = read(), x = read(); 
    for(int i = 1; i <= n; ++i) a[i] = read(), a[i+n] = a[i];
    for(int k = 0; k < n; ++k)
    {
        int64 s = 1ll*k*x; l = 1, r = 0;
        for(int i = 1; i <= k; ++i)
        {
            while(l <= r&&a[q[r]] >= a[i]) --r;
            q[++r] = i;
        } 
        for(int i = k+1; i <= n+k; ++i) 
        {
            while(l <= r&&i-k > q[l]) ++l;
            while(l <= r&&a[q[r]] >= a[i]) --r; 
            q[++r] = i; s += a[q[l]];
        }
        ans = k?min(s, ans):s;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int a,b,c,x,y,z;
	scanf("%d %d %d",&a,&b,&c);
	x=a+b;
	y=b+c;
	z=a+c;
	if(x==c || y==a || z==b){
			printf("Yes\n");
	}
	else{
			printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

ll dp[10100][105][2];

int main(){
	int D;
	string s;
	cin >> s >> D;
	int N = s.size();
	rep(i,10100)rep(j,105)rep(k,2)dp[i][j][k] = 0;
	dp[0][0][0] = 1;
	rep(i,N)rep(j,D)rep(k,2){
		int nd = s[i]-'0';
		rep(d,10){
			int ni = i+1, nj = j, nk = k;
			nj = (j+d) % D;
			if(k == 0){
				if(nd < d)continue;
				if(nd > d)nk = 1;
			}
			dp[ni][nj][nk] += dp[i][j][k];
			dp[ni][nj][nk] %= MOD;
		}
	}
	ll ans = (dp[N][0][0] + dp[N][0][1])%MOD - 1;
	if(ans < 0)ans += MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 20212
import sys

N = int(input())
a = list(map(int, input().split()))

for val in a:
    if val == 0:
        print("0")
        exit(0)

ans = 1
for val in a:
    ans *= val
    if ans > 1000000000000000000:
        print("-1")
        exit(0)

print(ans)


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

using namespace std;

int main(){
	string s;
	int k;

	cin >> k >> s;

	for(int i = 0; i < min(k, (int)s.length()) ; i++){
		cout << s[i];
	}

	if(s.length() > k){
		cout << "...";
	}

	cout << "\n";

	return 0;
}

Measured memory_bytes: 3624
n = int(input())
w = list(map(int, input().split()))

a = [0]*(n+1)
j = 0

for i in range(n):
  a[0] += w[i]

for i in range(n+1):
  if a[i] > 0:
    a[i+1] = a[i]- 2*w[i]
  else:
    j = i
    break
    
p = -a[j]
q = a[j-1]
if p < q:
  print(p)
else:
  print(q)






Measured memory_bytes: 9176
#include <stdio.h>
#include <math.h>

#define PI 3.14159265358979323846264338327950L
int main(void) {
    int a, b, h, m;
    scanf("%d%d%d%d", &a, &b, &h, &m);

    long double rad = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
    long double rsq = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(rad);
    printf("%20.20Lf\n", sqrtl(rsq));

  return 0;
}


Measured memory_bytes: 2576
<?php
$input = STDIN;

$W = trim(fgets($input));

$T = [];
while (true) {
    $line = trim(fgets($input));
    if ($line == 'END_OF_TEXT')
        break;
    $line = strtolower($line);
    $T = array_merge($T, explode(' ', $line));
}

$w = strtolower($W);
$cnt = 0;
foreach ($T as $T_i) {
    if ($T_i == $w)
        $cnt++;
}

print $cnt . "\n";


Measured memory_bytes: 9296
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> w(n);
    rep(i,0,n) cin>>w[i];
    int ans = 10000000;
    rep(i,0,n){
        int a = 0, b= 0;
        rep(j,0,i) a+=w[j];
        rep(j,i,n) b+=w[j];
        ans = min(ans,abs(a-b));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628