akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	int a, b;
	cin >> a >> b;
	if(a < 10 && b < 10){
		dump(a * b);
	}else {
		dump(-1);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int n,l,ans=0,min=101,pos=-1;
	cin>>n>>l;
	for(int i=1;i<=n;i++)if(abs(l+i-1)<min){
		min=abs(l+i-1);
		pos=i;
	}
	for(int i=1;i<=n;i++){
		if(i==pos)continue;
		ans+=(l+i-1);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){

string s;
  cin >> s;
int now = 0;
char c[s.size()];  
  
  for(int i = 0;i < s.size();i++){
  if((s.at(i) == '0') || (s.at(i) == '1')){
  c[now] = s.at(i);
  now++;
  }
  else if((s.at(i) == 'B') && (now > 0)) now--; 
  }
  
  for(int i = 0;i < now;i++) cout << c[i];
  return 0;
  
}

Measured memory_bytes: 256
import math
def prime(a):
    if a <= 1:
        return False + 0
    elif a <= 3:
        return True + 0
    for i in range(2, int(math.sqrt(a))+1):
        if a % i == 0:
            return False + 0
    return True + 0

n = int(input())
c = 0
for i in range(n):
    c += prime(int(input()))

print(c)


Measured memory_bytes: 5676
package main

import (
	"fmt"
)

func main() {


	var N,X int

	fmt.Scan(&N,&X)

	L:=make([]int,N)

	for i:=0;i<N;i++{

		fmt.Scan(&L[i])

	}

	last :=0
	count :=1

	for i :=0; i<N; i++{

		last = last + L[i]

		if last <= X{

			count++
		}

	}

	fmt.Println(count)

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  ll num, ans = 1;
  rep(i, n) {
    cin >> num;
    ans = lcm(ans, num);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;


map<ll, ll> pf(ll x){
    ll y = x;
    ll a = 2;
    map<ll, ll> m;
    while (a * a <= x) {
        if (y % a == 0) {
            y /= a;
            ++m[a];
        } else {
            ++a;
        }
    }
    if (y != 1) ++m[y];

    return m;
}

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

ll lcm (ll a, ll b){
    return a * b / gcd(a, b);
}

int main(void){
    cin.tie(0); ios::sync_with_stdio(false);
    ll a, b;

    cin >> a >> b;

    ll g = gcd(a, b);

    auto m = pf(g);

    cout << m.size() + 1;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int M = N%10;
  if(M==3){
    cout << "bon";
  }else if(M==0 || M==1 || M== 6 || M==8){
    cout << "pon";
  }else{
    cout << "hon";
  }
  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >>n;
vector<int> x(n);
for(int i=0;i<n;i++){
cin >> x.at(i);
}
int output =0;
sort(x.begin(),x.end());
reverse(x.begin(),x.end());
int bob=0;
int alice=0;
for(int i=0;i<n;i++){
if(i%2==0){
bob += x.at(i);
}else{
alice += x.at(i);
}
output = bob - alice;
}
cout << output <<endl;
  
  
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int a, b, c, x, cnt = 0;
    cin >> a >> b >> c >> x;
    fore(i,0,a+1) fore(j,0,b+1) fore(k,0,c+1) {
        int sum = i*500 + j*100 + k*50;
        if (sum == x) cnt++;
    }
    cout << cnt << endl;
}


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



int main(void) {
	long long N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	long long diff = B - A;
	long long cnt = N - 1;

	for (int i = 0; i <= cnt; i++) {
		long long up = D*i - C*(cnt-i);
		long long dn = C*i - D*(cnt-i);
		if ((dn <= diff) && (diff <= up)) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)


int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int cnt=1;
    int first=a[0];
    for(int i=1; i<n;i++){
        if(first > a[i]){
            cnt++;
            first=a[i];
        }else{
            continue;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
  
  int n;
  cin>>n;
  
  vector<int> a(n);
  for(int i=0 ; i<n ; ++i)
    cin>>a[i];
  
  sort(a.begin(),a.end());
  double ans = a[0];
  
  for(int i=1 ; i<n ; ++i)
    ans = (ans+a[i])/2;
  
  cout<<ans;
}
  

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int K;
	int all[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	scanf("%d", &K);
	printf("%d\n",all[K-1]);
	
	return 0;
}

Measured memory_bytes: 128
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,f[100005],ans;
multiset<int> s[100005];
map<ll,int> m;
queue<pair<int,int> >q;
ll g(int x,int y){
    if(x<y) swap(x,y);
    return x*1000000ll+y;
}
int get(int x){return x==f[x]?x:f[x]=get(f[x]);}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n*2-2;++i){
        int x,y;
        scanf("%d%d",&x,&y);
        s[x].insert(y);
        s[y].insert(x);
        if((++m[g(x,y)])==2)q.push(mp(x,y));
    }
    for(int i=1;i<=n;++i)f[i]=i;
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        x=get(x),y=get(y);
        if(m[g(x,y)]==0) continue;
        ++ans;
        m[g(x,y)]=0;
        if(s[x].size()<s[y].size())swap(x,y);
        f[y]=x;
        for(multiset<int>::iterator it=s[y].begin();it!=s[y].end();++it){
            if(*it==x) continue;
            s[x].insert(*it);
            s[*it].erase(y);
            s[*it].insert(x);
            --m[g(y,*it)];
            if((++m[g(x,*it)])==2)q.push(mp(x,*it));
        }
        s[y].clear();
    }
    if(ans==n-1)puts("YES");
    else puts("NO");
   // system("pause");
    return 0;
}


Measured memory_bytes: 55936
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 k, a, b;
  cin >> k >> a >> b;
  if (a >= k) cout << 1 << endl;
  else if (b >= a) cout << -1 << endl;
  else cout << (k - a + (a - b - 1)) / (a - b) * 2 + 1 << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long x = stdIn.nextLong();
		long price = 100;
		long cnt = 0;
		while(price < x) {
			cnt++;
			price*=1.01;
			
		}
		System.out.println(cnt);
		
	}

}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
  ll N; cin >> N;
  ll cnt = 0;
  REP(i, N){
    ll a; cin >> a;
    cnt += (a % 2);
  }
  (cnt % 2) ? printf("NO\n") : printf("YES\n");
  
}


Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
S,K = S(),I()
count_1 = 0
for x in S:
    if x=='1':
        count_1 += 1
    else:
        if K>count_1:
            print(x)
            break
else:
    print(1)


Measured memory_bytes: 3060
from itertools import accumulate

def main():
    class BIT:
        def __init__(self, N):
            self.size = N
            self.tree = [0] * (N + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

    N, K, *A = map(int, open(0).read().split())

    B = [0] + list(accumulate(a - K for a in A))

    memo = {n: i for i, n in enumerate(sorted(set(B)), 1)}
    bit = BIT(N + 1)

    ans = 0
    for b in map(memo.get, B):
        ans += bit.sum(b)
        bit.add(b, 1)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 54684
#include<stdio.h>
#include<string.h>
#define LEN 100005
typedef struct pp{
	char name[100];
	int t;
}P;
P Q[LEN];
int head,tail,n;
void enqueue(P x){
	Q[tail]=x;
	tail=(tail+1)%LEN;
}
P dequeue(){
	P x=Q[head];
	head=(head+1)%LEN;
	return x;
}
int min(int a,int b){return a<b?a:b;}
int main(void){
	int elaps=0,c;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=1;
	tail=n+1;
	while(head!=tail){
		u=dequeue();
		c=min(q,u.t);
		u.t-=c;
		elaps+=c;
		if(u.t>0){
			enqueue(u);
		}else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	return 0;
}


Measured memory_bytes: 11928
#include<bits/stdc++.h>
using namespace std;
long long a[605];
vector<int> vv;
signed main(){
	long long n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		for(int j=1;j<n;j++){
			vv.push_back(1);
			for(int k=1;k<n;k++){
				swap(a[k-1],a[k]);
			}
			if(a[0]<a[n-1]){
				vv.push_back(n-1);
				swap(a[0],a[n-1]);
			}
		}
		vv.push_back(1);
		for(int j=1;j<n;j++){
			swap(a[j],a[j-1]);
		}
	}
	cout << vv.size()<<endl;
	for(auto x: vv){
		cout << x<<endl;
	}
}

Measured memory_bytes: 764
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(X):
    for i in range(1, 1000000+1):
        if 100 * i <= X <= 105* i:
            return 1
    return 0


def main():
    X = read_int()
    print(slv(X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6720
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
#define NIL -1

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

struct Node T[MAX];
int n;


void preParse(int u){
  if( u == NIL ) return;
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if( u == NIL) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}

void postParse(int u){
  if( u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

int main(){
  int i, d, v, l, r;
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++) T[i].p = NIL;

  for( i = 0 ; i < n ; i++){
    scanf("%d", &v);
    scanf("%d", &l);
    scanf("%d", &r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL ) T[l].p = v;
    if(r != NIL ) T[r].p = v;
  }
for( i = 0 ; i < n ; i++){
    if( T[i].p == NIL ) d = i;
  }

  printf("Preorder\n");
  preParse(d);
  printf("\n");
  printf("Inorder\n");
  inParse(d);
  printf("\n");
  printf("Postorder\n");
  postParse(d);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2036
import re
while True:
    try:
        s = input()
    except EOFError:
        break

    for x in '0123456789':
        t = s.replace('X', x)
        a, b, c = re.split(r'[+=]', t)

        if len(a) > 1 and a[0] == '0': continue
        if len(b) > 1 and b[0] == '0': continue
        if len(c) > 1 and c[0] == '0': continue
        a, b, c = map(int, (a, b, c))
        if a + b != c: continue

        print(x)
        break
    else:
        print('NA')



Measured memory_bytes: 6540
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;

using namespace std;

int main()
{
    fast_cin;
    int n;
    cin >> n;
    vi v(n);
    for(int i=0;i<n;i++) cin >> v[i];

    ll min_stamina=inf;
    for(int pos=0;pos<=100;pos++){
        ll current_res=0;
        for(int j=0;j<n;j++){
            current_res+=1LL*(v[j]-pos)*(v[j]-pos);
        }
        min_stamina=min(min_stamina,current_res);
    }
    cout << min_stamina <<'\n';
}


Measured memory_bytes: 256
class BinarySearchTree:
    def __init__(self):
        self.root = None
    def show_keys(self):
        in_order_from(self.root)
        print('')
        pre_order_from(self.root)
        print('')
    def insert(self, key):
        node = Node(key)
        insert(self, node)
    def find(self, key):
        if find_from(self.root, key):
            print('yes')
        else:
            print('no')
    def delete_key(self, key):
        node = find_from(self.root, key)
        delete_node(self, node)

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

def insert(T, z):
    y = None
    x = T.root
    while x != None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y == None:
        T.root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

def delete_node(T, node):
    if node.left and node.right:
        x = node.right
        while x.left:
            x = x.left
        node.key = x.key
        delete_node(T, x)
    elif node.left or node.right:
        child = node.left or node.right
        if node is T.root:
            T.root = child
            child.parent = None
        else:
            if node.parent.left is node:
                node.parent.left = child
                child.parent = node.parent
            else:
                node.parent.right = child
                child.parent = node.parent
    else:
        if node.parent.left is node:
            node.parent.left = None
        else:
            node.parent.right = None

def in_order_from(node):
    if node:
        in_order_from(node.left)
        print(' {0}'.format(node.key), end = '')
        in_order_from(node.right)

def pre_order_from(node):
    if node:
        print(' {0}'.format(node.key), end = '')
        pre_order_from(node.left)
        pre_order_from(node.right)

def find_from(node, k):
    while node:
        if node.key == k:
            return node
        if k < node.key:
            node = node.left
        else:
            node = node.right


import sys

t = BinarySearchTree()

m = sys.stdin.readline()

for i in sys.stdin.readlines():
    if i[0] == 'i':
        t.insert(int(i[7:]))
    elif i[0] == 'f':
        t.find(int(i[5:]))
    elif i[0] == 'd':
        t.delete_key(int(i[7:]))
    else:
        t.show_keys()



Measured memory_bytes: 122924
#include<stdio.h>
int main(void)
{
	int a[3];
	int i,j;
	int temp;
	for(i=0;i<3;i++)
		scanf("%d",&a[i]);
	for(i=0;i<3;i++){
		for(j=0;j<3-1;j++){
			if(a[j]>a[j+1]){
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}
		}
	}
	printf("%d\n",a[1]-a[0]+a[2]-a[1]);
	return 0;
}

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

using namespace std;
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<ll> cum(N);
    for(int i=0; i<N; i++){
        int a; cin >> a;
        if(i==0) cum[i] = a;
        else cum[i] = cum[i-1] + a;
    }
    
    ll ans = 1LL<<60;
    for(int i=0; i<N-1; i++){
        ll value = abs(cum[i] - (cum[N-1]-cum[i]));
        ans = min(ans, value);
    }
    
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

string S;
bool dir[4];
signed main() {
    cin>>S;
    for(int i=0;i<S.length();i++){
        if(S[i]=='N')dir[0]=1;
        if(S[i]=='W')dir[1]=1;
        if(S[i]=='S')dir[2]=1;
        if(S[i]=='E')dir[3]=1;
    }
    if((dir[0]^dir[2])||(dir[1]^dir[3]))cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define i(a) insert(a)
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7 ;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1;
  //cin>>t;
  while(t--)
  {
    ll n ; cin>>n ;
    vector<pair<ll,ll>> a(n) ;
    for( ll i = 0 ; i<n ; i++ ) {
    cin>>a[i].first>>a[i].second;
    }
    bool ok = false;
    for( ll i = 0 ; i<n-2 ; i++ ){
        if( a[i].first == a[i].second ){
            if( (a[i+1].first==a[i+1].second) && (a[i+2].first==a[i+2].second) ) ok = true ;
        }
    }
    if(ok) cout<<"Yes";
    else cout<<"No";
  }
 return 0;
}




Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, k; cin >> n >> k;
    vi a(n);
    bool possible = false;
    ll gcdNum = -1;
    rep(i, n){
        cin >> a[i];
        if(a[i] == k) possible = true;
        if(i == 0) gcdNum = a[i];
        else gcdNum = __gcd(gcdNum, a[i]);
    }
    sort(all(a));
    if(a[n-1] >= k && !possible){
        ll sub = k-a[n-1];
        if(sub%gcdNum == 0) possible = true;     
    }
    cout << (possible ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 3972
init_pos, move_max, move_dist = [int(x) for x in input().split(' ')]
if init_pos < 0:
    init_pos *= -1

move_cnt = min(init_pos // move_dist, move_max)

moved_pos = init_pos - move_cnt * move_dist
min_abs = moved_pos

if move_max - move_cnt > 0:
    dests = [moved_pos, move_dist - moved_pos]
    min_abs = dests[(move_max - move_cnt) % 2]

print(min_abs)

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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> x(N);
  for(int i=0;i<N;++i) cin>>x[i];

  int sum=0;
  for(int i=0;i<N;++i){
    sum += 2*min(x[i],K-x[i]);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;

constexpr ll INF = 1e+14;

void solve(istream &cin) {
    string s, t;
    if (!(cin >> s)) { return; }
    cin >> t;
    vector<vector<ll>> dp(s.size()+1, vector<ll>(t.size()+1, 0));
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else{
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }
    string ans;
    int i, j;
    i = s.size();j = t.size();
    while(j > 0 && i > 0){
        if(dp[i][j] == dp[i-1][j-1]+1 && s[i-1] == t[j-1]){
            ans = t[j-1] + ans;
            i--; j--;
        }
        else if(dp[i][j] == dp[i-1][j]){
            i--;
        }
        else {
            j--;
        }

    }
    cout << ans << endl;

}

int main(int argc, char *argv[]) {
    string FileName("EDPC"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    // /home/USER/.../MEPH_X -> MEPH_X
    if (sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size() - ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        while (cin) { solve(cin); }
    } else {
        cerr << sub << " test" << endl;
        string inFile = FileName + ".txt";
        auto fs = fstream(inFile, fstream::in);
        while (fs) { solve(fs); }
    }
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int>>> G;
map<pair<int,int>,int> E;
vector<bool> visited;
vector<pair<int,long long>> val;
void f(int p, int a, long long b) {
	val[p] = {a,b};
	for (auto pp : G[p]) {
		auto vv = pp.first;
		auto ss = pp.second;
		if (!visited[vv]) {
			visited[vv] = true;
			E.erase({p,vv});
			E.erase({vv,p});
			f(vv, -a, ss-b);
		}
	}
}
int main() {
	int N, M;
	cin >> N >> M;
	G.resize(N);
	for (int i = 0; i < M; ++ i) {
		int u, v;
		long long s;
		cin >> u >> v >> s;
		-- u; -- v;
		G[u].push_back({v,s});
		G[v].push_back({u,s});
		E[{u,v}] = s;
	}
	visited.resize(N);
	val.resize(N);
	visited[0] = true;
	f(0, 1, 0);
	long long Xmin = 1, Xmax = 1LL<<60;
	for (auto x : val) {
		if (x.first == 1) {
			Xmin = max(Xmin, 1 - x.second);
		} else if (x.first == -1) {
			Xmax = min(Xmax, x.second - 1);
		} else {
			throw 1;
		}
		// cerr << x.first << "x+" << x.second << endl;
	}
	if (Xmin > Xmax) {
		cout << 0 << endl;
		return 0;
	}
	for (auto ee : E) {
		auto e = ee.first;
		auto a1 = val[e.first].first;
		auto b1 = val[e.first].second;
		auto a2 = val[e.second].first;
		auto b2 = val[e.second].second;
		auto a = a1 + a2;
		auto b = ee.second - (b1 + b2);
		//cerr << a << "x = " << b << endl;
		if (a == 0) {
			if (b != 0) {
				cout << 0 << endl;
				return 0;
			}
		} else {
			if (b % a != 0) {
				cout << 0 << endl;
				return 0;
			}
			auto c = b / a;
			if (Xmin <= c && c <= Xmax) {
				Xmin = Xmax = c;
			} else {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	cout << (Xmax-Xmin+1) << endl;
}


Measured memory_bytes: 22912
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
    ($line:expr,$name:ident,$t:tt) => {
        let $name=value!($line,$t);
    };
    }

    macro_rules! values_def {
    ($lines:expr,$n:expr,$name:ident,$t:tt) => {
        let $name={
        let mut vec=Vec::new();
        for i in 0..$n{
            let mut next=$lines.next().unwrap().split_whitespace();
            vec.push(value!(next,$t));
        }
        vec
        };
    };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize));
    prime_sieve(55555)
        .0
        .into_iter()
        .filter(|&x| x % 5 == 1)
        .take(n)
        .map(|x| x.to_string())
        .collect::<Vec<_>>()
        .join(" ")
        .to_string()
}

pub fn prime_sieve(n: usize) -> (Vec<usize>, Vec<bool>) {
    let mut prime = Vec::new();
    let mut is_prime = Vec::with_capacity(n + 1);
    is_prime.resize(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for i in 2..n + 1 {
        if is_prime[i] {
            prime.push(i);
            {
                let mut j = 2 * i;
                while j <= n {
                    is_prime[j] = false;
                    j += i;
                }
            }
        }
    }

    (prime, is_prime)
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}


Measured memory_bytes: 4352
#include <cstdio>
using namespace std;
const int N=100010;
const int INF=1e9;
int n,m;
int a[N];
inline int min(int x,int y){
	return x<y?x:y;
}
void readData(){
	scanf("%d%d",&n,&m);
	a[0]=-INF;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	a[n+1]=INF;
}
void solve(){
	int p;
	for(p=1;p<=n&&a[p]<0;p++); // p is the first one which a[p]>=0
	int ans=INF;
	for(int i=p,j=1;j<=m&&i<=n;i++,j++)
		if(m-j<=p-1)
			ans=min(ans,a[i]+((m-j)?a[i]-a[p-(m-j)]:0));
	for(int i=p-1,j=1;j<=m&&i;i--,j++)
		if(m-j<=n-p+1)
			ans=min(ans,(-a[i])+((m-j)?(-a[i])+a[p+(m-j)-1]:0));
	printf("%d\n",ans);
}
int main(){
	readData();
	solve();
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int c[3][3];

int main(void)
{
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> c[i][j];
		}
	}
	set<int>a[2], b[2];
	for (int i = 1; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			a[i - 1].insert(c[i][j] - c[i - 1][j]);
		}
	}
	for (int i = 0; i < 3; ++i) {
		for (int j = 1; j < 3; ++j) {
			b[j - 1].insert(c[i][j] - c[i][j - 1]);
		}
	}
	if (a[0].size() == 1 && a[1].size() == 1 && b[0].size() == 1 && b[1].size() == 1) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 256
x, n = gets.split(" ").map(&:to_i)
array = gets.split(" ").map(&:to_i)

if !array.include?(x)
  puts x
  exit
end

nums = []
for i in (x + 1)..101
#   puts "#{i}  #{(x - i).abs}"
#   p !array.include?(i)
  if !array.include?(i)
    nums << [i, (x - i).abs]
    break
  end
end

i = 0
while i < x
#   puts "#{x - 1 - i}  #{(x - 1 - i - x).abs}"
#   p !array.include?(x - 1 - i)
  if !array.include?(x - 1 - i)
    nums << [(x - 1 - i), (x - 1 - i - x).abs]
    break
  end
  i += 1
end

puts nums.sort_by{|item| [item[1], item[0]]}[0][0]

Measured memory_bytes: 14328
from itertools import accumulate
N, W = map(int, input().split())
Items = [[] for i in range(4)]

w, v = map(int, input().split())
base_w = w
Items[0].append(v)

for i in range(N - 1):
    w, v = map(int, input().split())
    Items[w - base_w].append(v)

for i in range(4):
    Items[i] = [0] + sorted(Items[i], reverse=True)
    Items[i] = list(accumulate((Items[i])))


ans = 0
for w0 in range(len(Items[0])):
    for w1 in range(len(Items[1])):
        for w2 in range(len(Items[2])):
            for w3 in range(len(Items[3])):
                if base_w * w0 + (base_w + 1) * w1 + (base_w + 2) * w2 + (base_w + 3) * w3 > W:
                    continue
                tmp_ans = Items[0][w0] + Items[1][w1] + Items[2][w2] + Items[3][w3]
                ans = max(ans, tmp_ans)

print(ans)


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

const int maxN=105;
const int maxW=10005;
int d[maxN][maxW];

int main()
{
    int N,W;
    cin>>N>>W;
    int v[maxN],w[maxW];
    for(int i=1;i<=N;i++)
        cin>>v[i]>>w[i];
    for(int i=1;i<=N;i++)
        d[i][0]=0;

    for(int i=1;i<=N;i++)
    {
        for(int j=0;j<=W;j++)
        {
            if(w[i]>j)
                d[i][j]=d[i-1][j];
            else
                d[i][j]=max(d[i-1][j],d[i-1][j-w[i]]+v[i]);
        }
    }
    cout<<d[N][W]<<endl;
    return 0;
}

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

int isPrime(int);

int main(){
  int n,i,count=0,k;

  
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&k);
    if(isPrime(k)==1) count++;
  } 

  printf("%d\n",count);

  return 0;

}

int isPrime(int x){
  int i;

  if(x==2) return 1;
  if(x<2 || x%2==0) return -1;

  i=3;

  while(i<=sqrt(x)){
    if(x%i==0) return -1;
    i=i+2;
  }
  return 1;
}



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

using namespace std;

int main(void)
{
  int N, M;
  cin >> N >> M;
  int ans[30] = {0};
  for(int i = 0; i < N; i++){
    int K;
    cin >> K;
    for(int j = 0; j < K; j++){
      int index;
      cin >> index;
      index--;
      ans[index]++;
    }
  }
  int cnt = 0;
  for(int i = 0; i < M; i++){
    if(ans[i] == N){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a[200001],c[200002],n,k;
int main( ) {
    cin >> n >> k;
    register int i, j, t, s, f;
    for (i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (j = 1; j <= k; ++j) {
        memset(c, 0, sizeof(c));
        for (i = 1; i <= n; ++i) {
            ++c[max(1, i - a[i])];
            --c[min(n + 1, i + a[i] + 1)];
        }
        s = 0, f = 1;
        for (i = 1; i <= n; ++i) {
            a[i] = s += c[i];
            if (a[i] < n)f = 0;

        }
        if (f)break;
    }
    for (i = 1; i <= n; ++i) {
        cout << a[i] << " ";
    }
}


Measured memory_bytes: 5096
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

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

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
def parent_children(start, g):
    parent, children, depth, q = [-1]*len(g), make_list(len(g), 0), [-1]*len(g), deque([start]); depth[start] = 0
    while q:
        i = q.popleft()
        for j in g[i]:
            if depth[j] != -1: parent[i] = j
            else: depth[j] = depth[i] + 1; children[i].append(j), q.append(j)
    return parent, children, depth
def adjacency_list(N, edges):
    g = make_list(N, 0)
    for a, b in edges: g[a].append(b), g[b].append(a)
    return g

sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")

def main():
    N, u, v = LI()
    AB = LIR1(N-1)
    max_dist = [None] * N
    g = adjacency_list(N, AB)
    parent, children, depth = parent_children(v-1, g)

    def dfs(i):
        dist = max([0] + [dfs(j) for j in children[i]])
        max_dist[i] = dist
        return dist + 1
    mid = u-1
    for _ in range((depth[u-1] - 1)//2):
        mid = parent[mid]
    dfs(mid)
    print(depth[mid] + max_dist[mid] - 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 270932
#include <cstdlib>
#include <iostream>
#include <stdio.h>

using namespace std;

/*
 * 
 */

#define MAX 251

void print(int *binaryHeap, int num) {
    
    for(int i = 1; i < num + 1; i++) {
        printf("node %d: key = %d, ",i, binaryHeap[i]);
        
        if(i / 2 > 0) {
            printf("parent key = %d, ", binaryHeap[i / 2]);
        }
        if(2 * i <= num) {
            printf("left key = %d, ", binaryHeap[2 * i]);
        }
        if(2 * i + 1 <= num) {
            printf("right key = %d, ", binaryHeap[2 * i + 1]);
        }
        cout << endl;
    }
}

int main(void) {
    //ifstream ifs;
    //ifs.open("./input.txt", ifstream::in);
    int num;
    //ifs >> num;
    cin >> num;
    int binaryHeap[MAX];
    for(int i = 1; i < num + 1; i++) {
        cin >> binaryHeap[i];
        
    }
    
    print(binaryHeap, num);
    
    
    return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long int n,m,l;
    long long int A[100][100],B[100][100],C[100][100]={};
    cin>>n>>m>>l;
    for(long long int i=0;i<n;i++){
        for(long long int j=0;j<m;j++){
            cin>>A[i][j];
        }
    }
    for(long long int i=0;i<m;i++){
        for(long long int j=0;j<l;j++){
            cin>>B[i][j];
        }
    }
    for(long long int i=0;i<n;i++){
        for(long long int j=0;j<l;j++){
            for(long long int k=0;k<m;k++){
                C[i][j]+=A[i][k]*B[k][j];
            }
        }
    }
    for(long long int i=0;i<n;i++){
        for(long long int j=0;j<l;j++){
            cout <<C[i][j];
            if(j==l-1){
                cout <<endl;
            }else cout <<" ";
        }
    }   
    return 0;
}

Measured memory_bytes: 3316
N, K =map(int, input().split())
win = 1
cnt = 0
 
def DFS(i, win):
    if(i < K):  # Kを超える得点にならない限り、コインで表になり続ける必要がある
        win *= 0.5 # 1枚追加で表
        i *= 2 # 特典は2倍
        return DFS(i, win) # それが繰り返される
    else:
        return win
    
for i in range(1, N+1): # 1からNまでのケースで繰り返す
    cnt += DFS(i, 1/N)
print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int n,i,s1=0,s2=0,min,sum=0,x,y;
    scanf("%d",&n);
    int a[n];

    for(i=0;i<n;i++)
    {

        scanf("%d",&a[i]);
        s1+=a[i];

    }
    for(i=0;i<n;i++)
    {
        s1-=a[i];
        s2+=a[i];
        if(i!=0 && abs(s1-s2)>min) break;


        min=abs(s1-s2);

    }



    printf("%d",min);

}


Measured memory_bytes: 128
n = input()
st1 = raw_input()
st2 = raw_input()
m = 1
mod = 1000000007
pat = 0 # or 1,2
bl = False
for i in range(n):
  #print m
  if pat == 2 and bl:
    bl = False
    continue
  if st1[i] == st2[i] and pat == 0:
    m = m*3%mod
    pat = 1
  elif st1[i] == st2[i] and pat == 1:
    m = m*2%mod
    pat = 1
  elif st1[i] == st2[i] and pat == 2:
    pat = 1
  elif st1[i] != st2[i] and pat == 0:
    m = m*6%mod
    pat = 2
    bl = True
  elif st1[i] != st2[i] and pat == 1:
    m = m*2%mod
    pat = 2
    bl = True
  elif st1[i] != st2[i] and pat == 2:
    m = m*3%mod
    pat = 2
    bl = True
print m


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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

ll mpow(ll a,ll b){
    ll res=1;
    a%=mod;
    while(b){
    	if(b%2) res=res*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return res;
}

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

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

void solve(){
	//code
	string s;
	cin>>s;
	
	cout<<s.substr(0,4)<<" "<<s.substr(4)<<endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll k;cin>>k;
    ll n;cin>>n;
    vector<ll> a(n+1);
    For(i,0,n) cin>>a[i];
    a[n]=a[0]+k;
    ans=k;
    For(i,0,n){
        ans=min(ans,k-(a[i+1]-a[i]));
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var L = sc.nextInt();
        var arr = new int[N];
        var min = int.MaxValue;
        var idx = -1;
        for (int i = 0; i < N; i++) {
            arr[i] = L + (i + 1) - 1;
            if (Math.Abs(arr[i]) < min) {
                min = Math.Abs(arr[i]);
                idx = i;
            }
        }

        var ans = 0;
        for (int i = 0; i < N; i++) {
            if (idx == i) continue;
            ans += arr[i];
        }
        WriteLine(ans);
    }
}

class Combination {
    static int mod = 1000000007;

    public static long Calc(int a, int b) {
        if (b > a - b) return Calc(a, a - b);

        long ansMul = 1;
        long ansDiv = 1;
        for (int i = 0; i < b; i++) {
            ansMul *= (a - i);
            ansDiv *= (i + 1);
            ansMul %= mod;
            ansDiv %= mod;
        }
        return ansMul * ModPow(ansDiv, mod - 2) % mod;
    }

    private static long ModPow(long a, int p) {
        if (p == 0) return 1;
        if (p % 2 == 0) {
            long half = ModPow(a, p / 2);
            return half * half % mod;
        } else {
            return a * ModPow(a, p - 1) % mod;
        }
    }
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 11220
#include<iostream>

using namespace std;

int main()
{
        int h[10];
	int i,j;
	int temp=0;
	
	for(i=0; i<10; i++)
	{
		cin>>h[i];
	}
	
	for(i=0; i<9; i++)
	{
	   for(j=i+1; j<10; j++)
	   {
	   	  if(h[j]>h[i])
	   	  {
	   	  	 temp=h[j];
	   	  	 h[j]=h[i];
	   	  	 h[i]=temp;	
	          }
	   } 
        }
    
        for(i=0; i<3; i++)
	{
		cout<<h[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 1160