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


#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define sci(a)	scanf("%d",&a)
#define scll(a)	scanf("%lld",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prll(a)	printf("%lld\n",a)
	

const int maxn = 300500;

typedef long long ll;

typedef pair<int, int> pii;

ll dp[maxn];


int main() {
	//freopen("in.in", "r", stdin);	
	int n; sci(n);
	int W; sci(W);
	lp(i, n){
		int a, b; scii(a, b);
		for (int j = W - a; j >= 0; j--)
			dp[j + a] = max(dp[j + a], dp[j] + b);
	}
	prll(*max_element(dp, dp + maxn));
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void)


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

	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
int dp[100001];

int main(){
  int x;
  cin >> x;
  dp[100]=1;
  dp[101]=1;
  dp[102]=1;
  dp[103]=1;
  dp[104]=1;
  dp[105]=1;
  for(int i=106;i<=x;i++){
    if(dp[i-100]==1||dp[i-101]==1||dp[i-102]==1||dp[i-103]==1||dp[i-104]==1||dp[i-105]==1){
      dp[i]=1;
    }
  }
  
  if(dp[x]==1)cout << 1;
  else cout << 0;
  
  return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


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

    int D, N;
    cin >> D >> N;
    
    if (N == 100) N = 101;
    int ans = pow(100, D) * N;

    print(ans);

}


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

int main() {
	int n;
	cin>>n;
	int arr[n];
	int maxi=0;
	vector<pair<int,int>>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		if(i!=0)
		{
			v[i]={maxi,0};
			
		}
		maxi=max(maxi,arr[i]);
		
	}
	maxi=0;
	for(int i=0;i<n;i++)
	{
		//cin>>arr[i];
		if(i!=0)
		{
			maxi=max(maxi,arr[i]);
			
		}
		
		
	}
	v[0]={0,maxi};
	maxi=0;
	for(int i=n-1;i>=0;i--)
	{
		//cin>>arr[i];
		if(i!=n-1)
		{
			maxi=max(maxi,arr[i]);
			
		}
		
		
	}
	v[n-1].second=maxi;
	
    maxi=0;
	for(int i=n-1;i>0;i--)
	{
		if(i!=n-1)
		{
		   v[i].second=maxi;	
		}
		maxi=max(maxi,arr[i]);
		
	}
	for(int i=0;i<n;i++)
	{
		cout<<max(v[i].first,v[i].second)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
long long a[55],n,i,x,ans;//
main(){
for(std::cin>>n;i<n;std::cin>>a[++i]);
for(;std::sort(a+1,a+n+1),a[n]>=n;a[n]%=n)for(ans+=x=a[n]/n,i=1;i<n;a[i++]+=x); 
std::cout<<ans<<'\n';
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int h,w,a,b; cin>>h>>w>>a>>b;

	char ans[1000][1001]={};
	rep(i,h+1) rep(j,w+1) if(i*a+(h-i)*(w-a)==j*b+(w-j)*(h-b)) {
		bool ok=true;
		int vcnt[1000]={};
		rep(y,h){
			int hcnt=0;
			rep(x,w){
				if(hcnt==(y<i?a:w-a) || vcnt[x]==(x<j?b:h-b)){
					ans[y][x]='0';
				}
				else{
					ans[y][x]='1';
					hcnt++;
					vcnt[x]++;
				}
			}
			if(hcnt!=(y<i?a:w-a)) ok=false;
			if(!ok) break;
		}
		rep(x,w) if(vcnt[x]!=(x<j?b:h-b)) ok=false;
		if(!ok) continue;

		rep(y,h) puts(ans[y]);
		return 0;
	}
	puts("No");

	return 0;
}


Measured memory_bytes: 2176
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program{
  static void Main(){
	var input = ReadLine().Split(' ').Select(int.Parse).ToArray();
    var n = input[0];
    var m = input[1];
    var x = new int[m,2];
    
    for(var i = 0;i < m;i++){
    	var k = ReadLine().Split(' ');
      	x[i,0] = int.Parse(k[0]);
        x[i,1] = int.Parse(k[1]);
    }
    
    var z = new int[n];
    

    for(var i = 0;i < n;i++){
		z[i] = -1;
    }

    for(var i = 0;i < m;i++){
      	var t = x[i,0]-1;

        if(z[t] != x[i,1] && z[t] != -1){
          Write("-1");
          return;
        }
      	z[t] = x[i,1];
    }


    if(z[0] == 0 && n > 1){
		Write("-1");
        return;
    }else if(z[0] <= 0 && n == 1){
    	Write("0");
      	return;
    }else if(z[0] == -1){
    	z[0] = 1;
    }
    
    for(var i = 0;i < n;i++){
    	if(z[i] == -1){
			z[i] = 0;
    	}
    }
    
	for(var i = 0;i < n;i++){
    	Write(z[i]);
    }

  }
}

Measured memory_bytes: 18924
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;


int main() {
	string s, t;
	cin >> s >> t;
	map<char, vector<ll>> mapa;
	ll n = s.size();
	for(ll i=0; i<n; i++) {
		mapa[s[i]].push_back(i); 
	}

	ll ans = 0;
	int pos = 0;
	int block = 0;
	for(ll i=0; i<t.size(); i++) {
		auto it = lower_bound(mapa[t[i]].begin(), mapa[t[i]].end(), pos); 
		if (it != mapa[t[i]].end()) pos = mapa[t[i]][it - mapa[t[i]].begin()] + 1;
		else {
			if (mapa[t[i]].size() == 0) ans = -1;
			else {
				pos = mapa[t[i]][0] + 1;
				block++;
			}
		}
	}

	if (ans != -1) {
		ans = block * s.size() + pos;
	}

	cout << ans << endl;

}


Measured memory_bytes: 1664
S = str(input())

if (S[0:2] == S[2:4] and S[1] != S[2]) or (S[0:2] == ''.join(list(reversed(S[2:4]))) and S[0] != S[2]):
    print('Yes')
elif S[0] == S[1] and S[2] == S[3] and S[0] != S[2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    int check = 0, ans;
    for(int i = 1; i <= 1000000; ++i){
        ans = i * 1.08;
        if(ans == n){
            ans = i;
            check = 1;
            break;
        }
    }
    if(check) cout << ans ;
    else cout << ":(" ;
}


Measured memory_bytes: 3608
#include<stdio.h>

int main(void){

	int a,b,c,i,j,k=0;
	
		scanf("%d %d %d",&a,&b,&c);
			for(i=a;i<=b;i++){
				if(c%i==0)k++;
			}
		printf("%d\n",k);
	
	return 0;
}

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    int n, p;
    cin >> n >> p;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i] >> b[i];
--p; // add this line
    vector<vector<int>> dp(n + 1, vector<int>(p + 1, -MOD));
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= p; ++j){
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if(j + a[i] > p)
                continue;
            dp[i + 1][j + a[i]] = max(dp[i + 1][j + a[i]], dp[i][j] + b[i]);
        }
    }
    vector<vector<int>> dp2(n + 1, vector<int>(p + 1, -MOD));
    dp2[n][0] = 0;
    for(int i = n - 1; i >= 0; --i){
        for(int j = 0; j <= p; ++j){
            dp2[i][j] = max(dp2[i][j], dp2[i + 1][j]);
            if(j + a[i] > p)
                continue;
            dp2[i][j + a[i]] = max(dp2[i][j + a[i]], dp2[i + 1][j] + b[i]);
        }
    }

    for(int i = 0; i <= n; ++i)
        for(int j = 0; j < p; ++j){
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
            dp2[i][j + 1] = max(dp2[i][j + 1], dp2[i][j]);
        }

    int ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= p; ++j){
            ans = max(ans, dp[i][j] + dp2[i + 1][p - j] + b[i]);
        }
    }
    cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	// cin.tie(0); // tie
	// ios::sync_with_stdio(false); // sync
	int N;
	while (cin >> N, N) {
		vector<int> x(N), y(N);
		REP(i, 1, N) {
			int n, d;
			cin >> n >> d;
			x[i] = x[n] + dx[d];
			y[i] = y[n] + dy[d];
		}

		int min_x = INT_MAX, max_x = INT_MIN;
		int min_y = INT_MAX, max_y = INT_MIN;
		rep(i, N) {
			min_x = min(min_x, x[i]);
			max_x = max(max_x, x[i]);
			min_y = min(min_y, y[i]);
			max_y = max(max_y, y[i]);
		}
		cout << (max_x - min_x + 1) << ' ' << (max_y - min_y + 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define ll                    long long int
#define ull                   unsigned long long int
#define vll                   vector<long long int>
#define loop(i,a,b) 		  for(ll i=(ll)a;i<(ll)b;++i)
#define pb                    push_back
#define ii					  pair<int, int> 
#define vii					  vector<ii>
#define vvi					  vector<vector<int>> 
#define pi                    acos(-1.0)
#define MOD                   1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void f_io(){
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int main()
{
	f_io();
	ll t,n,k,a,b,c,d,x,y;
  
    string s1,s2;
    cin>>s1>>s2;
    if(s2.substr(0,s2.size()-1)==s1)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    
 
 
}

Measured memory_bytes: 3644
N = int(input())
c = -1
s = 0
for i in range(N):
    ai,bi = map(int,input().split())
    s += ai
    if ai > bi:
        if c == -1:
            c = bi
        if bi < c:
            c = bi
if c == -1:
    print(0)
else:
    print(s-c)


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>

int main() {
	
	unsigned long A, B, C, K, ans;
	
	scanf("%lu %lu %lu", &A, &B, &K);

	if (A <= K) {
		C = K - A;
		A = 0;
		if (B <= C) {
			B = 0;
		}
		else {
			B = B - C;
		}
	}
	else {
		A = A - K;
	}

	printf("%lu %lu", A, B);

	return 0;
}



Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()

	var k, n int
	fmt.Fscan(read, &k, &n)

	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(read, &a[i])
	}
	a[n] = k + a[0]

	v := 0
	for i := 0; i < n; i++ {
		if v < a[i+1]-a[i] {
			v = a[i+1] - a[i]
		}
	}
	fmt.Fprintln(write, k-v)
}


Measured memory_bytes: 3840
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    int x, y;
    cin >> x >> y;

    int a = 4*x - y;
    int b = y - 2*x;

    if((a % 2 == 0 && a >= 0) && (b % 2 == 0 && b >= 0)) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
const int N = 15;
char s[N];
int main(){
	while(scanf("%s",s)!=EOF){
		int len;
		len=strlen(s);
		int time=0;
		int mark=0;
		if(s[0]=='A'){
			for(int i=1;i<len;i++)
			    if(isupper(s[i]))
			        time++;
			for(int i=2;i<len-1;i++)
			    if(s[i]=='C')
			        mark++;
			if(time==1&&mark==1)
			    printf("AC\n");
			else
			    printf("WA\n");
		}
		else
		    printf("WA\n");
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
col = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199]
a = list(map(int,input().split()))
col_set = set()
cnt = 0
for i in range(n):
    if a[i] >= 3200:
        cnt += 1
    for j in range(len(col)):
        if a[i] <= col[j]:
            col_set.add(j)
            break
print(max(len(col_set), 1), len(col_set)+cnt)



Measured memory_bytes: 3060
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem2153 : Mirror Cave **/
 
typedef struct P{
	int x, y;
	P (){}
	P(int x_, int y_){x = x_; y=y_;}
} P;
struct State {
	P l, r;
	State(){}
	State (P L_, P R_) {l = L_; r = R_;}
};


int main()
{
	int W, H;
	while (cin>>W>>H, W||H) {
		State start;
		bool vis[52][52][52][52] = {false};
		char boardL[W+2][H+2], boardR[W+2][H+2];
		
		rep(i, W+2) {
			boardL[i][0] = '#';
			boardL[i][H+1] = '#';
			boardR[i][0] = '#';
			boardR[i][H+1] = '#';
		}
		rep(i, H) {
			boardL[0][i+1] = '#'; boardL[W+1][i+1] = '#';
			rep(j, W) {
				char c; cin>>c;
				boardL[j+1][i+1] = c;
				if (c=='L')
					start.l = P(j+1, i+1);
			}
			
			boardR[0][i+1] = '#'; boardR[W+1][i+1] = '#';
			rep(j, W) {
				char c; cin>>c;
				boardR[j+1][i+1] = c;
				if (c=='R')
					start.r = P(j+1, i+1);
			}
		}
		
		queue<State> Q;
		Q.push(start);
		vis[start.l.x][start.l.y][start.r.x][start.r.y]=true;
		bool flg=false;
		
		while (Q.size()) {
			State s = Q.front(); Q.pop();
			
			if (boardL[s.l.x][s.l.y]=='%' && boardR[s.r.x][s.r.y]=='%') {
				flg = true;
				break;
			} else if ((boardL[s.l.x][s.l.y]=='%') != (boardR[s.r.x][s.r.y]=='%')) {
				continue;
			}
			
			rep(i, 4) {
				State ns = State(P(s.l.x+dx[i], s.l.y+dy[i]), P(s.r.x-dx[i], s.r.y+dy[i]));
				if (boardL[ns.l.x][ns.l.y] == '#')
					ns.l = s.l;
				if (boardR[ns.r.x][ns.r.y] == '#')
					ns.r = s.r;
				
				if (!vis[ns.l.x][ns.l.y][ns.r.x][ns.r.y]) {
					Q.push(ns);
					vis[ns.l.x][ns.l.y][ns.r.x][ns.r.y] = true;
				}
			}
		}
		cout << (flg?"Yes":"No") << endl;
	}
}

Measured memory_bytes: 9272
using System;
using System.Linq;

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

            int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int divisionTimes = 0;

            bool finished = false;
            while (!finished)
            {
                for (int i = 0; i < N; i++)
                {
                    if (A[i] % 2 == 0)
                    {
                        A[i] /= 2;
                    }
                    else
                    {
                        finished = true;
                        break;
                    }
                }

                if (finished)
                {
                    break;
                }
                divisionTimes++;
            }

            Console.WriteLine(divisionTimes);
        }
    }

Measured memory_bytes: 13268
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
int ps4[4][2]={0,1,0,-1,1,0,-1,0};
int ps8[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,-1,-1,1};
inline int min(int a,int b,int c) {return min(a,min(b,c));}
inline int max(int a,int b,int c) {return max(a,max(b,c));}
inline int min(int a,int b,int c,int d){return min(min(a,b,c),d);}
inline int max(int a,int b,int c,int d){return max(max(a,b,c),d);}
//struct Edge{int p, next, w;}edge[maxn];
//inline add_edge(int u, int v, int w){edge[cnt]=Edge{v,head[u],w}; head[u]=cnt++;}
const int N=100005;
///Code begin..................................................................

VI E[N];
struct Node{int l, r, mark;}node[N];
int a[N], ans[N];
bool vis[N], flag;

Node operator ^(Node a, Node b){return Node{max(a.l,b.l),min(a.r,b.r),a.mark|b.mark};}
void dfs(int x, int fa){
    int l, r;
    Node tmp;
    if (vis[x]) node[x]=Node{a[x],a[x],true};
    else node[x]=Node{-INF,INF,false};
    AU(i,E[x]) {
        if (*i==fa) continue;
        dfs(*i,x);
        tmp=Node{node[*i].l-1,node[*i].r+1,node[*i].mark};
        if (node[x].mark&&tmp.mark&&(abs(node[x].l-tmp.l)&1)) flag=true;
        node[x]=node[x]^tmp;
    }
    if (node[x].l>node[x].r) flag=true;
}
void Sol(int x, int fa){
    if (fa==0) ans[x]=node[x].l;
    else {
        if (ans[fa]+1>=node[x].l&&ans[fa]+1<=node[x].r) ans[x]=ans[fa]+1;
        else ans[x]=ans[fa]-1;
    }
    AU(i,E[x]) if (*i!=fa) Sol(*i,x);
}
int main ()
{
    int n, u, v, K;
    scanf("%d",&n);
    FOR(i,1,n-1) scanf("%d%d",&u,&v), E[u].pb(v), E[v].pb(u);
    scanf("%d",&K);
    FOR(i,1,K) scanf("%d%d",&u,&v), vis[u]=true, a[u]=v;
    dfs(1,0);
    if (flag) puts("No");
    else {
        Sol(1,0);
        puts("Yes");
        FOR(i,1,n) printf("%d\n",ans[i]);
    }
    return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

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

  string s;
  cin >> s;

  string t = "AKIHABARA";

  bool ok = true;
  int ind = 0;
  rep(i, s.length()){

    if(s[i] != t[ind] && t[ind] == 'A'){
      ind++;
    }

    if(s[i] != t[ind]){
      ok = false;
      break;
    }
    ind++;
    

  }

  if(ind < 8){
    ok = false;
  }

  if(ok){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }



  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
ar = []
n.times do
  ar << gets.chomp
end

hash = Hash.new(0)
ar.each do |elem|
  hash[elem] += 1
end

h_max = hash.values.max

hash.select{|k,v| v == h_max}.keys.sort.each do |v|
  puts v
end


Measured memory_bytes: 55144
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val X = listOfLong().map { ModInt(it) }.toTypedArray()
    val Y = listOfLong().map { ModInt(it) }.toTypedArray()
    var x = ModInt(0)
    for (n in 1 until N) {
        x += X[n] * n - X[n - 1]
        X[n] += X[n - 1]
    }
    var y = ModInt(0)
    for (m in 1 until M) {
        y += Y[m] * m - Y[m - 1]
        Y[m] += Y[m - 1]
    }
    println(x * y)
}   

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)

data class ModInt(private var v: Long) {
    companion object { private const val MOD = 1000000007L }
    init { this.v %= MOD }
    constructor(n: Int): this(n.toLong())
    operator fun plus(other: Int) = ModInt((this.v + other) % MOD)
    operator fun plus(other: ModInt) = ModInt((this.v + other.v) % MOD)
    operator fun minus(other: Int) = ModInt((this.v + MOD - other) % MOD)
    operator fun minus(other: ModInt) = ModInt((this.v + MOD - other.v) % MOD)
    operator fun times(other: Int) = ModInt(this.v * other % MOD)
    operator fun times(other: ModInt) = ModInt(this.v * other.v % MOD)
    operator fun div(other: ModInt) = ModInt(this.v * pow(other.v, MOD - 2) % MOD)
    private fun pow(a: Long, b: Long): Long {
        if (b == 0L) return 1L
        if (b % 2 == 0L) {
            val d = pow(a, b / 2)
            return (d * d) % MOD
        }
        return a * pow(a, b - 1) % MOD
    }
    override fun toString() = this.v.toString()
}

Measured memory_bytes: 90932
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string str;

int main() {
    while (cin >> str) {
        int n = str.size();
        
        int res = 0;
        if (n & 1) {
            if (str[n/2] == '(' || str[n/2] == ')') ++res;
        }
        for (int i = 0; i < n/2; ++i) {
            int j = n-i-1;
            if (str[i] == '(' && str[j] == ')') continue;
            if (str[i] == ')' && str[j] == '(') continue;
            if (str[i] == 'w' && str[j] == 'w') continue;
            if (str[i] == 'i' && str[j] == 'i') continue;
            ++res;
        }
         
        cout << res << endl;
    }
    
    return 0;
}


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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);


  char c;cin>>c;
  if(c=='A')puts("T");
  else if(c=='T')puts("A");
  else if(c=='G')puts("C");
  else if(c=='C')puts("G");

  
  return 0;
}


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

int main() {
  int n, l;
  cin >> n >> l;
  int res = 0;
  if (l > 0) {
    for (int i = 2; i <= n; i++) {
      res += l + i - 1;
    }
    cout << res << endl;
  }
  if (l <= 0 && l + n - 1 >= 0) {
    for (int i = 1; i <= n; i++) {
      res += l + i - 1;
    }
    cout << res << endl;
  }
  if (l + n - 1 < 0) {
    for (int i = 1; i <= n - 1; i++) {
      res += l + i - 1;
    }
    cout << res << endl;
  }
}


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

using namespace std;

const int INF = 1e9;

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	
	int n = 5;	
	vector<int> dishes(5), perm(5);
	for (int i = 0; i < n; i++) {
		cin >> dishes[i];
		perm[i] = i;
	}
	
	int ans = INF;

	do {
		int start = 0;
		for (int i = 0; i < n; i++) {
			start += dishes[perm[i]];
			int m = start % 10;
			if (m != 0 && i != n - 1)
				start += (10 - m);
		}
		ans = min(ans, start); 
	} while(next_permutation(perm.begin(), perm.end()));
    cout << ans << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    PR(MAX((B-A)*(N-2)+1,0));

    return 0;
}

/*



*/

Measured memory_bytes: 3624
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		while(sc.hasNext()){
			int N = sc.nextInt();
			int[] arr = new int[N];
			for(int i=0;i<arr.length;i++){
				arr[i] = sc.nextInt();
			}
			int q = sc.nextInt();
			int[] target = new int[q];
			for(int i=0;i<q;i++){
				target[i] = sc.nextInt();
			}
			for(int i=0;i<q;i++){
				boolean res =  solve(0,target[i],arr);
				if(res){
					System.out.println("yes");
				}else{
					System.out.println("no");
				}
			}
		}
	}
	public static  boolean solve(int i,int m,int[] A){
		if(m==0) return true; 
		if(i>=A.length) return false;
		boolean res = solve(i+1,m,A) || solve(i+1,m-A[i],A);
		return res; 
	}
}

Measured memory_bytes: 26860
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0.0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1.0
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])


Measured memory_bytes: 268384
import sys


def reverse_search(n, parents):
    q = [n - 1]
    visited = set()
    while q:
        v = q.pop()
        if v in visited:
            continue
        visited.add(v)
        q.extend(u for u in parents[v] if u not in visited)
    return visited


n, m, p = list(map(int, input().split()))
INF = 10 ** 12
links = [set() for _ in range(n)]
parents = [set() for _ in range(n)]
for line in sys.stdin:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add((b, p - c))
    parents[b].add(a)
reachable = reverse_search(n, parents)

dist = [INF] * n
dist[0] = 0
for _ in range(len(reachable)):
    updated = False
    for v in reachable:
        d = dist[v]
        if d == INF:
            continue
        for u, c in links[v]:
            if dist[u] > d + c:
                dist[u] = d + c
                updated = True
    if not updated:
        break
else:
    print(-1)
    exit()

print(max(0, -dist[n - 1]))


Measured memory_bytes: 48348
#include<bits/stdc++.h>
using namespace std;
int n;
double a[3005];
double dp[3005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	dp[0]=1.0;
	for(int i=1;i<=n;i++){
		for(int j=i;j>=1;j--) dp[j]=dp[j]*a[i]+dp[j-1]*(1.0-a[i]);
		dp[0]*=a[i]; 
	}
	double ans=0.0;
	for(int i=0;i<=n/2;i++) ans+=dp[i];
	printf("%.10lf\n",ans);
	return 0;
}

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

int main() {
	int a,b,c,d,e,i;
	cin >> a >> b >> c;
	


	for (i = 1; i < 1000 ; i++) {
		d = a*i;
		e = d%b;
		if (c == e) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

const int INF = 1e18;
int n,cnt;
int a[500010];
int L[300010],R[300010];

void merge(int l,int m,int r){
  int n1 = m-l;
  int n2 = r-m;
  for(int i = 0; i < n1; i++) L[i] = a[l+i];
  for(int i = 0; i < n2; i++) R[i] = a[m+i];
  L[n1] = R[n2] = INF;
  int i = 0,j = 0;
  for(int k = l; k < r; k++){
    if(L[i] <= R[j]) a[k] = L[i++];
    else {
      a[k] = R[j++];
    }
    cnt++;
  }
}

void mergesort(int l,int r){
  if(l+1 == r) return;
  int m = (l+r)/2;
  mergesort(l,m);
  mergesort(m,r);
  merge(l,m,r);
}

signed main(){

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

  mergesort(0,n);

  for(int i = 0; i < n; i++){
    if(i == n-1) cout << a[i] << endl;
    else cout << a[i] << " ";
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 10904
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;
int n,r;

map<int, double> keep_y;  
bool check2(double x,double y, double xl, double xr, double hei){
  return xl <= x && x <= xr && y <= hei;
}
void addPoint(vector<double> &xl,vector<double> &xr,vector<double> &hei){
  keep_y = map<int, double>();
  for(int i = 0;i < n;i++){
	for(int j = xl[i];j < xr[i];j++){
	  keep_y[j] = max(keep_y[j], hei[i]);
	}
  }
}
double dist(double x1,double y1,double x2,double y2){
  return ((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
bool check(double h){//円内に, 候補点があり=> アウト日が出る
  for(int i = -r;i <= r;i++){
	if(dist(i, keep_y[i], 0, h) < r*r || dist(i, keep_y[i-1], 0, h) < r*r){
	  return true;
	}
  }
  return false;
}

double bs(double h,vector<double> &xl,vector<double> &xr,vector<double> &hei){
  double f = -r;
  double e = h;  
  while(e - f >= 0.0001){
	double mid = (f + e) / 2.0;
	if(check(mid)){
	  e = mid;
	}else{
	  f = mid;
	}
  }
  return f;
}
int main(){
  
  while(cin >> r >> n){
	if(n == 0 && r == 0)break;
	vector<double> xl(n);
	vector<double> xr(n);
	vector<double> hei(n);
	for(int i = 0;i < n;i++){
	  cin >> xl[i] >> xr[i] >> hei[i];
	}
	addPoint(xl,xr,hei);
	cout << fixed << setprecision(5) << bs(min(keep_y[0]-r, keep_y[-1]-r),xl,xr,hei) + r<< endl;
	 
  }
   
  return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    int s;
    cin >> s;
    ll ans = 0;
    COMinit();
    for(int k = 1; k <= s/3; k++){ // kグループに分けるとき
        int t = s - 3 * k;
        ans += COM(t+k-1, t);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15548
import sys

n = int(input())
As = list(map(int, input().split()))

Sc = list()

dp = [10**9] * (n-1)
ep = [10**9] * (n-1)
s = sum(As)

if n-2 == 0:
    print(abs(As[0] - As[1]))
    sys.exit()

for i in range(n-2):
    if i == 0:
        dp[i] = As[i]
    else:
        dp[i] = dp[i-1] + As[i]
    ep[i] = abs(dp[i] - s + dp[i])


print(min(ep))

Measured memory_bytes: 78288
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  bool ret = false;
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= m; j++) {
      ret |= k == i*m+j*n-2*i*j;
    }
  }
  if(ret) cout << "Yes\n";
  else cout << "No\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256
N, D=map(int,input().split())

if N-(2*D+1)<=0:
  print(1)
else:
  ans=0
  while N-(2*D+1)>0:
    ans =ans+1
    N=N-(2*D+1)
    if N-(2*D+1)<=0:
      print(ans+1)
      break

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

int main(){
    int n; cin >> n;
    vector<int> a(n), b(n);
    for (auto i = 0; i < n; i++) cin >> a[i];
    for (auto i = 0; i <= n / 2; i++) b[i] = a[n - 2 * i - 1];
    for (auto i = 0; i < n / 2; i++) b[n - i - 1] = a[n - 2 * i - 2];
    for (auto i = 0; i < n; i++) cout << b[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repl(i,n) for(int64_t i=0;i<(int64_t)(n);i++)
#define MAX_N 10000000
#define ll int64_t
#define all(v) (v).begin(),(v).end()
using namespace std;

int main() {
    //入力
    int n; cin>>n;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    int pre=-999;
    rep(i,n) {
        if(pre<=h[i]-1) {
            pre=h[i]-1;
        }
        else if(pre<=h[i]) {
            pre=h[i];
        }
        else{
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
} 

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
#include <set>
using namespace std;

int main() {
  int64_t N;
  cin >> N;
  
  int mx = 0;
  vector<int> nums(N);
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
    mx = max(mx, nums[n]);
  }
  vector<int> mods(mx+1);
  mods[1] = 1;
  for (int i = 2; i <= mx; ++i) {
    if (mods[i] != 0) {
      continue;
    }
    mods[i] = i;
    int tmp = i;
    while (tmp + i <= mx) {
      tmp += i;
      if (mods[tmp] != 0) continue;
      mods[tmp] = i;
    }
  }
  bitset<1000001> already;
  vector<int> cnts(mx+1);
  bool pairwise = true;
  for (int n : nums) {
    while (n > 1) {
      int tmp = mods[n];
      while (n % tmp == 0) {
        n /= tmp;
      }
      if (already.test(tmp)) {
        pairwise = false;
      }
      if (++cnts[tmp] == N) {
        cout << "not coprime" << endl;
        return 0;
      }
      already.set(tmp);
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }

  return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<int(n);i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int,int>;
const ll mod = 1e9+7;

vector<int> to[100005];

vector<int> dist;
void dfs(int v, int d=0, int p=-1){
  dist[v] = d;
  for(int u: to[v]){
    if(u==p) continue;
    dfs(u, d+1, v);
  }
}

vector<int> calcDist(int v){
  dist = vector<int>(100005,0);
  dfs(v);
  return dist;
}

int main(){
  int n,u,v;
  cin>>n>>u>>v;
  u--; v--;
  rep(i,n-1){
    int a, b;
    cin>>a>>b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  vector<int> distU = calcDist(u);
  vector<int> distV = calcDist(v);

  int mx = 0;
  rep(i,n) if(distU[i]<distV[i]) mx = max(mx,distV[i]);
  int ans = mx - 1;
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 13816
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    string s;
    cin >> s;
    cout << s.substr(0, 4) << " " << s.substr(4) << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,p=1,q=1;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0;
    ll strr[200005];
    cin>>n;
    vector<ll> a(n);
    rep(i,n)   cin >> a[i];
    rep(i,n) sum+=a[i];
    ll half=sum/2;
    ll halfadd;
    ll summ=0;
    rep(i,n){
        summ+=a[i];
        if(summ>=half){
            halfadd=i;
            break;
        }
    }
    ll half2=sum-summ;
    if(summ*2==sum){
        cout<<0<<endl;
        return 0;
    }
    ll sums=0;
    ll halfads;
    rep(i,halfadd){
        sums+=a[i];
    }
    ll half3=sum-sums;
    if(abs(half3-sums)<abs(half2-summ)){
        cout<<abs(half3-sums)<<endl;
    }else{
    cout<<abs(half2-summ)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<vector>
#include<unordered_map>

using namespace std;
typedef pair<long long int, long long int> P;

long long int A[110000], B[110000], C[110000];

int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  for(int i = 0; i < N; i++){
    cin >> B[i];
  }
  for(int i = 0; i < N; i++){
    cin >> C[i];
  }
  sort(A, A + N);
  sort(B, B + N);
  sort(C, C + N);
  long long int ans = 0;
  for(int i = 0; i < N; i++){
    long long int pos1 = distance(A, lower_bound(A, A + N, B[i]));
    long long int pos2 = N - distance(C, upper_bound(C, C + N, B[i]));
    ans += pos1 * pos2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
import math
n = int(input())
a = list(map(int, input().split()))
res = [-1]*n
last = n-1
middle = math.ceil(n/2)
for i in range(middle):
    res[i] = str(a[last - 2*i])

for i in range(n//2):
    res[middle+i] = str(a[last - 2*(n//2)+i*2 + 1])
print(" ".join(res))

Measured memory_bytes: 117560
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
#define rep_re(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

ll cnt[200001];
ll visit[200001];
vector<ll> v[200001];
void dfs(ll id, ll c) {
	cnt[id] += c;
	if (visit[id])return;
	visit[id] = true;

	if (id == 3) {
		cout << endl;
	}
	rep(i, 0, v[id].size()) {
		if (visit[v[id][i]])continue;

		ll nextid = v[id][i];
		dfs(v[id][i], cnt[id]);
	}
}
int main() {
	ll n, q; cin >> n >> q;

	repe(i, 1, n - 1) {
		ll a, b; cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	repe(i, 1, q) {
		ll p, q; cin >> p >> q;
		cnt[p] += q;
	}

	dfs(1, 0);

	repe(i, 1, n) {
		cout << cnt[i];
		if (i != n) {
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 25856
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl
#define COUT(x) cerr<<#x<<" = "; cout<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   char b; cin >> b;
   char ans;
   if (b == 'A') {
      ans = 'T';
   } else if (b == 'T') {
      ans = 'A';
   } else if (b == 'C') {
      ans = 'G';
   } else {
      ans = 'C';
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[200010][26];

int main(){
  string  s,t;
  cin >> s >> t;
  int n=s.size();
  int m=t.size();
  s+=s;
  rep(i,2*n){
    rep(j,26)dp[i][j]=-1;
  }
  for(int i=n-1;i>=1;i--){
    dp[i-1][s[i]-'a']=i;
    dp[i-1+n][s[i]-'a']=i;
  }
  dp[n-1][s[0]-'a']=0;
  dp[n-1+n][s[0]-'a']=0;
  for(int i=2*n-2;i>=0;i--){
    for(char c='a';c<='z';c++){
      if(dp[i][c-'a']==-1)dp[i][c-'a']=dp[i+1][c-'a'];
    }
  }
  ll temp=0;
  ll ans=1;
  rep(i,m){
    ll dist=0;
    if(i==0 && s[0]==t[0])dist=0;
    else if(temp<dp[temp][t[i]-'a'])dist=dp[temp][t[i]-'a']-temp;
    else dist=dp[temp][t[i]-'a']+n-temp;
    if(dp[temp][t[i]-'a']==-1){
      cout << -1 << endl;
      return 0;
    }
    ans+=dist;
    temp=dp[temp][t[i]-'a'];
    if(i==0 && s[0]==t[0])temp=0;
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 41344
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }

    vector<ll> s(N + 1, 0);
    map<ll, ll> ma;
    rep(i, N) { s[i + 1] = s[i] + A[i]; }
    rep(i, N + 1) { ma[s[i]]++; }

    ll res = 0;
    for (auto p : ma) {
        ll num = p.second;
        res += num * (num - 1) / 2;
    }

    cout << res << endl;
}

Measured memory_bytes: 15104
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(dead_code)]
fn read<T: FromStr>(s: &mut StdinLock) -> T {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

#[allow(unused_macros)]
macro_rules! p {
    ($x:expr) 
    => (println!("{}", $x));
    ($x:expr, $y:expr)
    => (println!("{} {}", $x, $y));
    ($x:expr, $y:expr, $z:expr) 
    => (println!("{} {} {}", $x, $y, $z));
}

#[allow(unused_macros)]
macro_rules! pl {
    ($x:expr) 
    => (println!("{}", $x));
    ($x:expr, $y:expr)
    => (println!("{}\n{}", $x, $y));
    ($x:expr, $y:expr, $z:expr) 
    => (println!("{}\n{}\n{}", $x, $y, $z));
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

    let a: usize = read(s);
    let b: usize = read(s);
    let s: String = read(s);
    let s: Vec<char> = s.chars().collect();
    let mut ok = true;
    for i in 0..(a+b+1) {
        if (i != a) {
            ok &= s[i].is_digit(10);
        } else {
            ok &= s[i] == '-';
        }
    }
    p!(if ok { "Yes" } else { "No"});
}

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

int main(int argc, char const *argv[]) {
  int a, b;
  cin >> a >> b;
  int u;
  string s;
  if (a != b) {
    u = min(a, b);
    rep(i, max(a, b)) s.push_back(u + 48);
  } else {
    rep(i, min(a, b)) s.push_back(a + 48);
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256