akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <chrono>
#include <random>
#include <cstdio>
#define ll long long int
#define endl '\n'
#define pb push_back
#define mp make_pair
// #define mod 998244353
#define rep(i,n) for(ll i=0;i<n;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define pll pair<ll, ll>
#define pint pair<int, int>
#define S second
#define F first
#define all(c) (c).begin(),(c).end()
using namespace std;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
const int N=500001;
// vector<pair<ll, ll> > adj[N];
// bool vis[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
#define pi 3.14159265358979323846264338
using namespace std; 
ll max(ll a, ll b){ if(a>b)return a;return b;}
ll min(ll a, ll b){ if(a < b) return a;return b;}
ll inf = 100000000000000000;
vector <pint> adj[N];

void solve() 
{
    int n;
    cin>>n;

    ll mon = 1000;

    vi a(n+2);
    a[0] = INT_MAX;
    a[n+1] = INT_MIN;
    rep(i, n) cin>>a[i+1];

    ll s = 0;
    for(int i = 1; i <= n; i++)
    {
        if(i == 1)
        {
            if(a[i] <= a[i+1])
            {
                s = mon/a[i];
                mon -= s*a[i];
            }
        }
        else if(i == n)
        {
            mon += s*a[i];
        }
        else
        {
            if(a[i] >= a[i-1] && a[i] > a[i+1])
            {
                mon += s*a[i];
                s = 0;
            }
            else if(a[i] < a[i-1] && a[i] <= a[i+1])
            {
                s = mon/a[i];
                mon -= s*a[i];
            }
        }

    }
    
    cout<<mon<<endl;


}

int main()
{
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)

    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        // cout<<'\n';
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 15464
import sys
sys.setrecursionlimit(100000)

N, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N - 1)]

MOD = 10 ** 9 + 7

g = [[] for _ in range(N)]
for a, b in AB:
	a, b = a - 1, b - 1
	g[a] += [b]
	g[b] += [a]

cn = [0] * N
def dfs(v, p):
	cn[v] = len(set(g[v]) - {p})
	for n in g[v]:
		if n == p:
			continue
		dfs(n, v)
dfs(0, -1)

r = K
for i in range(cn[0]):
	r *= K - 1 - i
	r %= MOD

for n in cn[1:]:
	for i in range(n):
		r *= K - 2 - i
		r %= MOD

print(r)


Measured memory_bytes: 107964
/*#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define mod 1000000007
int max3(int a, int b, int c){if(a>b){if(a>c) return a; else return c;}else{if(b>c)return b;else return c;}}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int32_t main()
{
	IOS;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		int f1=0;
		int l1=0;
		rep(i,0,s.size())
		{

			if(s[i]=='1')
			{
				f1=i;
				break;
			}
		}
		for(int i=s.size()-1;i>=f1;i--)
		{
			if(s[i]=='1')
			{
				l1=i;
				break;
			}
		}
		int cnt=0;
		rep(i,f1,l1)
		if(s[i]=='0')
			cnt++;
		cout<<cnt<<endl;
	}
	return 0;
}*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c, d;
	cin>>a>>b>>c>>d;
	if(abs(a-b)<=d&&abs(b-c)<=d)
	{
		cout<<"Yes";
		return 0;
	}
	if(abs(a-c)<=d)
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

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

int main(void){
  int a;
  int b;
  cin >> a >> b;
  std::string if_ans = std::to_string(a) + std::to_string(b);
  int ans = std::stoi(if_ans);
  int last_ans = std::sqrt(ans);
  int last_ans2 = ans % last_ans;
  if (ans % last_ans == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
h,w=map(int,input().split())
s=[]
s.append(['.']*(w+2))
for i in range(h):
    s.append( list(map(str,input())))
    

s.append(['.']*(w+2))
for i in range(1,h+1):
    s[i].insert(0,'.')
    s[i].append('.')


for i in range(1,h):
    for j in range(1,w):
        if s[i][j]=='#':
            if s[i+1][j]!='#' and s[i-1][j]!='#' and s[i][j+1]!='#' and s[i][j-1]!='#' :
                print("No")
                exit()

print("Yes")

Measured memory_bytes: 3064
if __name__ == '__main__':
    N = input()

    m = [[0] * N for i in range(N)]

    for i in range(N):
        v = map(int, raw_input().split())
        for j in v[2:]:
            m[i][j-1] = 1

    for row in m:
        for i in row:
            print i,
        print

Measured memory_bytes: 6420
import re

S_ = input().replace('?', '.')
T = input()
flag = True
for i in range(len(S_)-len(T), -1, -1):
    angou = re.compile(S_[i:i+len(T)])
    mo = angou.search(T)
    if mo != None:
        S_ = S_[:i] + mo.group() + S_[i+len(T):]
        flag = False
        break
S = S_.replace('.', 'a')

if flag:
    print('UNRESTORABLE')
else:
    print(S)


Measured memory_bytes: 38384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        if (n.indexOf("7") == -1) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 35464
#include<stdio.h>
int main(void)
{
	int a,b,c,x;
	x='x';
	for(a=1;a<=9;a++){
		for(b=1;b<=9;b++){
			c=a*b;
	printf("%dx%d=%d\n",a,b,c);
			}
		}
	return 0;
}


Measured memory_bytes: 2704
#include <bits/stdc++.h>
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;register bool _=0;register T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){register bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ld = long double;

int main(){
    
     ld a, b, x;
     cin >> a >> b >> x;
     x /= a;
     cout << fixed;
     cout << setprecision(10);
     
     ld half = a*b/2;
     
     if(x == a*b){
         puts("0");
         return 0;
     }
     
     if(x > half){
         ld rem = a*b - x;
         ld side = 2*rem/a;
         ld hyp = sqrtl(a*a+side*side);
         ld h = 2*rem/hyp;
         ld th = asin(h/side);
         //cout << rem << ' ' << side << ' ' << hyp << ' ' << h << ' ' << th << '\n';
         cout << 90-th*180/M_PI << '\n';
     }
     else if(x == half){
        ld hyp = sqrtl(b*b+a*a);
        ld h = 2*x/hyp;
        ld th = asin(h/b);
         cout << 90-th*180/M_PI << '\n';
     }
     else{
         ld side = 2*x/b;
         ld hyp = sqrtl(b*b+side*side);
         ld h = 2*x/hyp;
         ld th = asin(h/b);
         cout << 90-th*180/M_PI << '\n';
     }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
const int mod = 1000000007;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c) cout << "Yes" << endl;
  else cout << "No"<< endl;
  return 0;
}


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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {//x^n
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    int n;
    cin >> n;
    vector<long long>a(n);
    bool flag = false;//0あり=true
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) flag = true;
    }
    if (flag) {
        cout << 0 << endl;
    }else {
        long long ans = 1;
        long long max = 1;
        rep(i, 18) max *= 10;
        rep(i, n) {
            if (ans < LLONG_MAX / a[i] && ans * a[i] <= max) {
                ans *= a[i];
            }else {
                ans = -1;
                break;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
const ll mod = 1000000007;

ll dp[51][51][6000];

int main() {
    int n, k;
    cin >> n >> k;
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int s = 0; s <= n*n; s++) {
                dp[i+1][j][s+j*2] += dp[i][j][s];
                dp[i+1][j][s+j*2] %= mod;

                dp[i+1][j+1][s+(j+1)*2] += dp[i][j][s];
                dp[i+1][j+1][s+(j+1)*2] %= mod;

                dp[i+1][j][s+j*2] += dp[i][j][s] * j*2;
                dp[i+1][j][s+j*2] %= mod;

                if (j-1 >= 0) {
                    dp[i+1][j-1][s+(j-1)*2] += dp[i][j][s] * j*j;
                    dp[i+1][j-1][s+(j-1)*2] %= mod;
                }
            }
        }
    }

    cout << dp[n][0][k] << endl;

    return 0;
}

Measured memory_bytes: 119552
import sys
def main():
    S = list(input())
    T = list(input())

    substrings = []
    for i in range(0, len(S) - len(T) + 1):
        substrings.append(S[i:i+(len(T))])

    ans = sys.maxsize
    for string in substrings:
        count = 0
        for i in range(len(T)):

            if string[i] == T[i]:
                count += 1

        # print(string, T, count)

        ans = min(len(T)-count, ans)

    print(ans)



main()


Measured memory_bytes: 10552
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int main(void)
{
	int n, m, x;
	cin >> n >> m >> x;
	int a[m];
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	int l=0, r=0;
	for (int i = 0; i < m; i++) {
		if (a[i] < x) {
			l++;
		} else if (a[i] > x) {
			r++;
		}
	}

	cout << min(l, r) << endl;
	return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll x,y,xx,yy; cin>>x>>y>>xx>>yy;
  rep(i,xx-x) cout<<"R";
  rep(i,yy-y+1) cout<<"U";
  rep(i,xx-x+1) cout<<"L";
  rep(i,yy-y+1) cout<<"D";
  cout<<"R";
  cout<<"D";
  rep(i,xx-x+1) cout<<"R";
  rep(i,yy-y+1) cout<<"U";
  rep(i,xx-x+1) cout<<"L";
  rep(i,yy-y) cout<<"D";
  cout<<endl;
}

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

#define int long long

string w;

signed main() {
    cin >> w;
    for (int i = 0; i < 26; i++) {
        int cnt = 0;
        for (int j = 0; j < w.length(); j++) {
            if (w[j] - 'a' == i) {
                cnt++;
            }
        }
        if (cnt % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define ALL(v) v.begin(), v.end()


using namespace std;
int main() {

	int n;
	cin >> n;

	int total = 0;

	int n4 = 0, n2 = 0, n1 = 0;


	for (int i = 0; i < n; i++)
	{
		long long temp;
		cin >> temp;
		if (temp % 4 == 0) {
			n4++;
		}
		else if (temp % 2 == 0) {
			n2++;
		}
		else {
			n1++;
		}

	}


	if (n2 == 0) {
		if (n1 <= n4 + 1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else
	{
		if (n1 <= n4)cout << "Yes" << endl;
		else cout << "No" << endl;
	}




}

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

struct Node {
    int p, l, r;
};
Node *nd;


void preorder(int k) {
    cout << " " << k;
    if (nd[k].l != -1) {
        preorder(nd[k].l) ;
    }
    if (nd[k].r != -1) {
        preorder(nd[k].r);
    }
}

void inorder(int k) {
    if (nd[k].l != -1) {
        inorder(nd[k].l) ;
    }
    cout << " " << k;
    if (nd[k].r != -1) {
        inorder(nd[k].r);
    }
}

void postorder(int k) {
    if (nd[k].l != -1) {
        postorder(nd[k].l) ;
    }
    if (nd[k].r != -1) {
        postorder(nd[k].r);
    }
    cout << " " << k;
}
int main() {
    cin >> N;
    int id, l, r;
    nd = new Node[N];
    for (int j = 0; j < N; ++j) {
        nd[j].l = nd[j].r = nd[j].p = -1;
    }
    for (int i = 0; i < N; ++i) {
        cin >> id >> l >> r ;
        nd[id].l = l; nd[id].r = r;
        nd[l].p = id; nd[r].p = id;
    }

    int root ;
    while (nd[root].p != -1) {
        root = nd[root].p;
    }

    cout << "Preorder" << endl;
    preorder(root );
    cout << endl;
    cout << "Inorder" << endl;
    inorder(root);
    cout << endl;
    cout << "Postorder" << endl;
    postorder(root);
    cout << endl;



    return 0;
}



Measured memory_bytes: 3100
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
n=int(input())
d=defaultdict(int)
A=list(map(int,input().split()))

for i in A:
    d[i]+=1
for i in range(1,n+1):
    print(d[i])


Measured memory_bytes: 37964
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

struct Event{
    ll time;
    ll sign;
    ll position;
};

bool comp(const Event& e1, const Event& e2){
    if(e1.time == e2.time){
        if(e1.position == e2.position) return e1.sign < e2.sign;
        return e1.position < e2.position;
    }
  	return e1.time < e2.time;
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, q;
    cin >> n >> q;

    vector<Event> v;
    vll tim;
    REP(i, n){
        ll s, t, x;
        cin >> s >> t >> x;
        v.push_back(Event{s - x, 1, x});
        v.push_back(Event{t - x, -1, x});
        tim.push_back(s - x);
        tim.push_back(t - x);
    }
    sort(v.begin(), v.end(), comp);
    //各 Event 発生時において通行止めされている座標のうち最小のもの
    vll ngpoint(2 * n, -1);
    //通行止めリスト
    set<ll> stops;
    REP(i, 2 * n){
        if(v[i].sign > 0){
            stops.insert(v[i].position);
            ngpoint[i] = *stops.begin();
        }
        else{
            stops.erase(v[i].position);
            if(stops.empty()) ngpoint[i] = -1;
            else ngpoint[i] = *stops.begin();
        }
    }
    ll d;
    REP(i, q){
        cin >> d;
        if(d < v[0].time || d >= v[2 * n - 1].time){
            cout << -1 << endl;
        }
        else{
            Event limit = Event{d, 10, (ll)1e10};
            ll k = upper_bound(v.begin(), v.end(), limit, comp) - v.begin();
            cout << ngpoint[k - 1] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 26536
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    string s;cin>>s;
    ll n=s.size();
    ll ans=0;
    rep(i,n/2)ans+=s[i]!=s[n-1-i];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        public class Node
        {
            public int key;
            public Node parent;
            public Node left;
            public Node right;
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Node rootNode = null;
            for(int i=0;i<n;++i)
            {
                string[] szarr = Console.ReadLine().Split(' ');
                if (szarr[0] == "print")
                {
                    InOrder(rootNode);
                    Console.WriteLine();
                    PreOrder(rootNode);
                    Console.WriteLine();
                }
                else
                {
                    int key = int.Parse(szarr[1]);
                    var z = new Node();
                    z.key = key;
                    Insert(ref rootNode, z);
                }
            }

        }
        static void Insert(ref Node rootNode, Node z)
        {
            Node y = null;

            Node x = rootNode;
            while(x != null)
            {
                y = x;
                if( z.key < x.key)
                {
                    x = x.left;
                }else
                {
                    x = x.right;
                }
            }
            z.parent = y;
            if(y == null)
            {
                rootNode = z;
            }else if( z.key < y.key)
            {
                y.left = z;
            }else
            {
                y.right = z;
            }
        }

        static void PreOrder(Node p)
        {
            if( p == null) { return; }
            Console.Write(" " + p.key);
            PreOrder(p.left);
            PreOrder(p.right);
        }
        static void InOrder(Node p)
        {
            if( p == null) { return; }
            InOrder(p.left);
            Console.Write(" " + p.key);
            InOrder(p.right);
        }
    }

}



Measured memory_bytes: 46672
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  sort(A.begin(),A.end());
  cout<<A.at(N-1)-A.at(0)<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double maxvolume(double s)
{
    double length = s / 3;

    s -= length;

    double breadth = s / 2;
    double height = s - breadth;

    return length * breadth * height;
}


int main()
{
    double s ;
    cin>>s;
    double a=maxvolume(s);
   printf("%.12lf\n",a);
    return 0;
}


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

using namespace std;

int main() {
  int n;
  long long k;
  while (scanf("%d%lld\n", &n, &k) != EOF) {
    vector<int> a(n + 1);
    vector<int> t(n + 1);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    int i = 1, j = 1;
    while (t[i] == 0 && k > 0) {
      t[i] = j++;
      i = a[i];
      k--;
    }
    if (k != 0) {
      k %= (j - t[i]);
      while (k > 0) {
        i = a[i];
        k--;
      }
    }
    printf("%d\n", i);
  }
}


Measured memory_bytes: 4816
#include<bits/stdc++.h>
using namespace std;
long long a[200010];
long long b[200010];
map<int,int> v;
int main()
{
	long long n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
		v[b[i]]+=a[i];
	}
	sort(b,b+n);
	for(int i=0;i<n;i++)
	{
		if(b[i]==b[i-1] && i)
		  continue;
		//cout<<v[b[i]]<<" "<<ans<<" "<<b[i]<<endl;
		if((ans+v[b[i]])>b[i])
		{
		  cout<<"No";
		  return 0;
	    }
	    else
	      ans=ans+v[b[i]];
	}
	cout<<"Yes";
	return 0;
}


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

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

bool check(int n) {
	return 1 <= n && n <= 12;
}

void solve() {
	string s;
	cin >> s;
	int one = (s[0] - '0') * 10 + s[1] - '0';
	int two = (s[2] - '0') * 10 + s[3] - '0';
	
	if (check(one) && check(two)) cout << "AMBIGUOUS";
	else if (check(one)) cout << "MMYY";
	else if (check(two)) cout << "YYMM";
	else cout << "NA";
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
//#include <bits/stdc++.h>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// print(x, y, z);
// print(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 20 == 19) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}

template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}

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

  std::string s;
  std::cin >> s;

  char fst = s[0];
  bool judge0 = true;
  for (std::string::iterator it = s.begin(); it != s.end(); ++it) {
    if (*it != s[0]) {
      judge0 = false;
    }
  }
  if (judge0) {
    print(0);
    return 0;
  }

  ll ans = INF;
  for (char c = 'a'; c <='z'; c++) {
    //print("[char]", c);
    std::string t1, t2;
    ll cnt = 0;
    t1 = s;
    while (t1.size() > 1) {
      t2 = "";
      bool judge = true;
      for (ll i = 0; i < (ll)t1.size() - 1; ++i) {
	if (t1[i] == c || t1[i+1] == c) {
	  t2 += c;
	} else {
	  t2 += t1[i];
	  judge = false;
	}
      }
      cnt++;
      //print(t2);

      if (judge == true) {
	break;
      }
      t1 = t2;
    }
    ans = std::min(ans, cnt);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let print_int n = Printf.printf "%d\n" n

let rec gcd a b = if a mod b = 0 then b else gcd b (a mod b)

let rec div h d = if h mod d = 0 then div (h/d) d else h

let rec solve i h ret =
  if i * i > h then
    if h = 1 then ret + 1
    else ret + 2
  else
    if h mod i = 0 then solve (i+1) (div h i) (ret+1)
    else solve (i+1) h ret


let () =
  let a = scan_int() and b = scan_int() in
  print_int (solve 2 (gcd a b) 0)


Measured memory_bytes: 384
#include <iostream>
#include <string>
#define llint long long

using namespace std;

llint N, Q;
string s;

llint sumD[1000005];
llint sumC[1000005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> N >> s >> Q;
	
	if(s[0] == 'D') sumD[0] = 1;
	if(s[0] == 'C') sumC[0] = 1;
	for(int i = 1; i < s.size(); i++){
		sumD[i] = sumD[i-1];
		if(s[i] == 'D') sumD[i]++;
		sumC[i] = sumC[i-1];
		if(s[i] == 'C') sumC[i]++;
	}
	
	llint k;
	for(int q = 0; q < Q; q++){
		cin >> k;
		llint ans = 0;
		llint D = 0, M = 0, C = 0, DM = 0, MC = 0;
		for(int i = 0; i < k; i++){
			if(s[i] == 'D') D++;
			if(s[i] == 'C') C++;
			if(s[i] == 'M'){
				ans += sumD[i-1]*(sumC[k-1]-sumC[i]);
				DM += sumD[i-1];
				MC += sumC[k-1] - sumC[i];
				M++;
			}
		}
		//cout << D << " " << M << " " << C << " " << DM << " " << MC << endl;
		//cout << ans << endl;
		
		for(int r = k; r < s.size(); r++){
			llint l = r-k;
			
			if(s[l] == 'D'){
				DM -= M;
				D--;
			}
			if(s[l] == 'M'){
				MC -= C;
				M--;
			}
			if(s[l] == 'C') C--;
			
			if(s[r] == 'D') D++;
			if(s[r] == 'M'){
				DM += D;
				M++;
			}
			if(s[r] == 'C'){
				MC += M;
				C++;
				ans += DM;
			}
			//cout << D << " " << M << " " << C << " " << DM << " " << MC << endl;
			//cout << ans << endl;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 17644
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> x(N), y(N);
    for(int i=0; i<N; i++) cin >> x[i] >> y[i];
    
    vector<int> perm(N);
    iota(perm.begin(), perm.end(), 0);
    double ans = 0;
    int mul = 1;
    for(int i=1; i<=N; i++) mul *= i;
    do {
        for(int i=0; i+1<N; i++) {
            int u = perm[i], v = perm[i+1];
            int dfx = x[u] - x[v];
            int dfy = y[u] - y[v];
            ans += sqrt(dfx*dfx + dfy*dfy);
        }
    }while(next_permutation(perm.begin(), perm.end()));
    ans /= mul;
    printf("%.12f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int N, A;
	cin >> N >> A;
	if (N % 500 <= A) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long 
using namespace std;

int main(){
  int a[3],ans;
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  int A=a[0],B=a[1],C=a[2];
  if( (C-B)%2==0 && (C-A)%2==0 ){
    ans=(2*C-A-B)/2;
  }else if( (C-B)%2==1 && (C-A)%2==1 ){
    ans=(2*C-B-A)/2;
  }else{
    ans=(2*C-A-B+3)/2;
  }
  cout<<ans<<endl;
}

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 3e5 + 9;

int n, N;
int s[maxN];
int cur[maxN];

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

	N = (1LL << n);
	multiset<ll> se;
	for(int i = 1; i <= N; i++){
		cin >> s[i];
		se.insert(s[i]);
	}
	
	int curSz = 1;
	int pos = 0;
	cur[pos++] = *se.rbegin();
	se.erase(se.lower_bound(cur[0]));
	
	while(curSz < N){
		for(int i = 0; i < curSz; i++){
			multiset<ll>::iterator it = se.lower_bound(cur[i]);
			if(it == se.begin()){
				cout << "No\n";
				return 0;
			}
			it--;
			cur[pos++] = *it;
			se.erase(it);
		}

		curSz = curSz + curSz;
	}
	
	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
string a;
bool x = 0;
int main(){
	cin>>a;
	for(int i = 0;i<a.length();i++){
		if(a[i] == 'C') x = 1;
		if(a[i] == 'F'&&x){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();

		int N = Integer.parseInt(sc.next());
		int num = N % 10;
		String mes = "";

		switch(num) {
		case 0:
			mes = "pon";
			break;
		case 1:
			mes = "pon";
			break;
		case 2:
			mes = "hon";
			break;
		case 3:
			mes = "bon";
			break;
		case 4:
			mes = "hon";
			break;
		case 5:
			mes = "hon";
			break;
		case 6:
			mes = "pon";
			break;
		case 7:
			mes = "hon";
			break;
		case 8:
			mes = "pon";
			break;
		case 9:
			mes = "hon";
			break;
		}

		System.out.print(mes);
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
}

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

#define reg register
typedef long long ll;
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)

char IO;
int rd(){
	int s=0,f=0;
	while(!isdigit(IO=getchar())) if(IO=='-') f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}

const int N=4e5;
const int z[5][4]={{0,1},{0,-1},{1,0},{-1,0}};

int n,m;
struct Edge{
	int to,nxt;
}e[N<<1];
int head[N],ecnt;
void AddEdge(int u,int v){
	e[++ecnt]=(Edge){v,head[u]};
	head[u]=ecnt;
}
#define erep(u,i) for(int i=head[u];i;i=e[i].nxt)

int ans[N],a[N];

void dfs(int u,int f,int d){
	d+=a[u];
	ans[u]=d;
	erep(u,i) {
		int v=e[i].to;
		if(v==f) continue;
		dfs(v,u,d);
	}
	d-=a[u];
}



int main(){
	n=rd(),m=rd();
	rep(i,2,n) {
		int u=rd(),v=rd();
		AddEdge(u,v);
		AddEdge(v,u);
	}
	rep(i,1,m) {
		int p=rd(),x=rd();
		a[p]+=x;
	}
	dfs(1,0,0);
	rep(i,1,n) printf("%d%c",ans[i],i==n?'\n':' ');
}









Measured memory_bytes: 18944
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;
struct edge{
    int to, w;
    edge(){to=-1; w=-1;}
    edge(int to, int w){
        this->to = to;
        this->w = w;
    }
};
int n, u0, s0, ans;
vector< vector<edge> > G(100001);
stack<int> sta;
bool visited[100001];

int dfs(int u, int dis, int max_dis){
    int v, w, tmp_max_dis=max_dis;
    bool is_leave = true;
    for(int i=0; i<G[u].size(); i++){
        v = G[u][i].to;
        w = G[u][i].w;
        if(visited[v])
            continue;
        else{
            is_leave = false;
            visited[v] = true;
            tmp_max_dis = max(tmp_max_dis, dfs(v, dis+w, tmp_max_dis));
        }
    }
    if(is_leave){
        if(dis > max_dis){
            u0 = u;
            return dis;
        }else{
            return max_dis;
        }
    }
    else 
        return tmp_max_dis;
}

int main(){
    scanf("%d", &n);
    int u, v, w;
    for(int i=0; i<n-1; i++){
        scanf("%d %d %d", &u, &v, &w);
        G[u].push_back(edge(v, w));
        G[v].push_back(edge(u, w));
    }
    //set point 0 to be the root. find the farest point
    memset(visited, 0, sizeof(visited));
    visited[0] = true;
    u0 = 0;
    dfs(0, 0, 0);

    //set point u0 to be the root , find the farset point
    memset(visited, 0, sizeof(visited));
    visited[u0] = true;
    s0 = u0;
    ans = dfs(s0, 0, 0);
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 H, W, cy, cx, gy, gx, i;
  cin >> H >> W >> cy >> cx >> gy >> gx;
  cy--; cx--;
  gy--; gx--;

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

  vector<string> S(H);
  REP(0, H, i) {
    cin >> S[i];
  }

  vvi A(H, vi(W, -1));

  i64 ans = 0;
  set<pi> P;
  P.insert({cy, cx});
  while(!P.empty()) {
    // dfs
    set<pi> Q;
    stack<pi> st;
    for(auto s: P) {
      if(A[s.first][s.second] == -1) {
	st.push(s);
	A[s.first][s.second] = ans;
	while(!st.empty()) {
	  pi cur = st.top();
	  st.pop();
	  Q.insert(cur);
	  //cerr << "visit " << cur.first << " " << cur.second << endl;
	  i64 d;
	  REP(0, 4, d) {
	    i64 ny = cur.first + dy[d];
	    i64 nx = cur.second + dx[d];
	    if(0 <= ny && ny < H && 0 <= nx && nx < W
	       && S[ny][nx] == '.' && A[ny][nx] == -1) {
	      st.push({ny, nx});
	      A[ny][nx] = ans;
	    }
	  }
	}

      }
    }
    // dfs
    P.clear();
    for(auto &q: Q) {
      i64 dx, dy;
      REP(-2, 3, dy) {
	REP(-2, 3, dx) {
	  i64 ny = q.first + dy;
	  i64 nx = q.second + dx;
	  if(0 <= ny && ny < H && 0 <= nx && nx < W
	     && S[ny][nx] == '.' && A[ny][nx] == -1) {
	    P.insert({ny, nx});
	  }
	}
      }
    }
    
    ans++;
  }  

  cout << A[gy][gx] << endl;
  return 0;
}


Measured memory_bytes: 14192
n,k = map(int,input().split())
p = list(map(int,input().split()))
used = [0]*n
c = list(map(int,input().split()))
ans = -float("INF")
def calc(x):
    l = []
    now = x
    score = 0
    while used[now] == 0:
        used[now] = 1
        l.append(c[now])
        now = p[now]-1
    S = sum(l)
    le = len(l)
    if S > 0 and k > le:
        score += (k//le-1)*S
        mod = k%le
        now = 0
        for i in range(le):
            cal = 0
            for j in range(le):
                if j <= mod:
                    now = max(now,cal+S)
                cal += l[(i+j)%le]
                now = max(now,cal)
        return score+now
    else:
        mod = min(le,k)
        now = -float("INF")
        for i in range(le):
            cal = 0
            for j in range(mod):
                cal += l[(i+j)%le]
                now = max(now,cal)
        return score+now
    
for i in range(n):
    if used[i] == 0:
        ans = max(ans,calc(i))
print(ans)

Measured memory_bytes: 68928
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	int num = 1, ans = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 2; j <= N; j++) {
			num = pow(i, j);
			if (N >= num) ans = max(num, ans);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    LL n;
    LL m;
    LL tmp;
    LL ans;
    cin >> n >> m;
    if(m>n){
        tmp=n;
        n=m;
        m=tmp;
    }
    if(m==1){
        if(n==1){
            ans=1;
        }else if(n==2){
            ans=0;
        }else{
            ans=n-2;
        }
    }else if(m==2){
        ans=0;
    }else{
        ans=(n-2)*(m-2);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define pii pair<int, int>
#define fst first
#define snd second
#define pub push_back
#define vi vector<int>
#define ll long long

using namespace std;

int s[200001], e[200001] = {};

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i] >> e[i];
	}
	sort(s, s + n);
	sort(e, e + n);
	int l = s[n / 2] + ((n % 2 == 0) ? s[n / 2 - 1] : 0);
	int r = e[n / 2] + ((n % 2 == 0) ? e[n / 2 - 1] : 0);
	if (l > r) {cout << "0\n";}
	else {cout << r - l + 1 << "\n";}
	return 0;
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    for(int i = 0; i < n; i++){
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    int ans = 0;
    bool f = false;
    for(int i = 0; i < n; i++){
        if (f) ans += t[i];
        if (s[i] == x) f = true;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    public class Prog
    {
        public static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Prog().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var k = cin.ReadInt;

            var ans = 0d;

            for (int i = 1; i <= n; i++)
            {
                ans += 1d /(n * Math.Pow(2, CoinCount(k, i)));
            }

            Console.WriteLine(ans);
        }
        private int CoinCount(int k, int firstPoint)
        {
            var count = 0;
            var point = firstPoint;
            while (k > point)
            {
                point *= 2;
                count++;
            }
            return count;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int a, b;
  cin >> a >> b;

  string ans = "x";
  if (a + b == 15) {
    ans = "+";
  }
  if (a * b == 15) {
    ans = "*";
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def makeAccount():
    fee=0
    a,b,c,x,y=map(int,input().split())

    #まずはA,Bどちらかが0になるまで購入
    fee+=min(x,y)*min(a+b,2*c)
    x, y=x-min(x,y), y-min(x,y)

    #残りのAを購入
    fee+=x*min(a, 2*c)

    #残りのBを購入
    fee+=y*min(b, 2*c)

    return fee
    
print(makeAccount())


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

int main(){
 ll a,b,c,d,A,B,C,D,E,F,G;
 cin >> a >> b >> c >> d;
  
 A=a*c;
 B=a*d;
 C=b*c;
 D=b*d;
 E=max(A,B);
 F=max(C,E);
 G=max(D,F);
  
  cout << G << endl;
}

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

#define ll long long
#define inf 0x3f3f3f3f 
#define il inline 

#define in1(a) a=read()
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
#define out(a) printf( "%d" , a ) 
#define outn(a) out(a),putchar('\n')

#define I_int int 
inline I_int read() {
	
    I_int x = 0 , f = 1 ; char c = getchar() ;
    while( c < '0' || c > '9' ) {
        if( c == '-' ) f = -1 ;
        c = getchar() ;
    }
    while( c >= '0' && c <= '9' ) {
        x = (x << 1) + (x << 3) + c - 48 ;
        c = getchar() ;
    }
    return x * f ;
}
#undef I_int

using namespace std ;

#define N 100010
int a[ 3 ] , k ;

int main() {
	in2( a[ 1 ] , a[ 0 ] ) ; in1( k ) ;
	for( int i = 1 ; i <= k ; i ++ ) {
		if( a[ i % 2 ] % 2 ) a[ i % 2 ] -- ;
		a[ ( i % 2 ) ^ 1 ] += a[ i % 2 ] / 2 ;
		a[ i % 2 ] -= a[ i % 2 ] / 2 ;
	}
	out( a[ 1 ] ) , putchar(' ') , outn( a[ 0 ] ) ; 
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))
count = 0

for i in range(1, N):
    if i == p[i-1]:
        p[i-1], p[i] = p[i], p[i-1]
        count += 1
    if i > 1:
        if p[-1] == N:
            p[-1], p[-2] = p[-2], p[-1]
            count += 1

print(count)

Measured memory_bytes: 14008
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const steps = arg[1].split(" ").map(n=>parseInt(n));
    
    const dp = [...Array(N)].fill(Infinity);
    
    dp[0] = 0;
    dp[1] = Math.abs(steps[1] - steps[0]);
    
    for(let i=2; i<N; i++) {
        let oneStep = dp[i-1] + Math.abs(steps[i] - steps[i-1]);  
        let twoStep = dp[i-2] + Math.abs(steps[i] - steps[i-2]);
        
        dp[i] = Math.min(oneStep, twoStep);
    }
    
    console.log(dp[N-1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 27804
#include<stdio.h>
int main(){
	int a;
	scanf("%d",&a);
	if(a<1200&&a>=0){
		printf("ABC\n");
	}
	else if(a>=1200&&a<2800){
		printf("ARC\n");
	}
	else if (a>=2800&&a<=4208)
	{
		printf("AGC\n");
	}
	return 0;
}


Measured memory_bytes: 128
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
vc = []
m = 0
for i in range(n):
    vc.append(v[i]-c[i])
for j in range(n):
    if vc[j] > 0:
        m += vc[j]
print(m)

Measured memory_bytes: 3060