akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long M = scan.nextLong();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong()/2;
        }
        long lcm = lcm(A);
        long count_odd = 0;
        long count_even = 0;
        for (int i = 0; i < N; i++) {
            long x = lcm / A[i];
            if (x % 2 == 0) {
                count_even += 1;
            } else {
                count_odd += 1;
            }
        }
        if (0 < count_even && 0 < count_odd) {
            System.out.println(0);
            return;
        }
        long answer = M / lcm;
        if (answer % 2 == 1) {
            answer += 1;
        }
        System.out.println(answer/2);
    }
    public long lcm(long[] T) {
        long current_lcm = T[0];
        for (int i = 0; i < T.length; i++) {
            current_lcm = lcm(T[i], current_lcm);
        }
        return current_lcm;
    }
    public long lcm(long x, long y) {
        long gcd = gcd(x, y);
        return x/gcd*y;
    }
    private long gcd(long x, long y) {
        if (y == 0) {
            return x;
        }
        return gcd(y, x % y);

    }
}


Measured memory_bytes: 62680
#include <bits/stdc++.h>
#define MAX_V 2500
#define MAX_A 5000
#define INF LLONG_MAX

using namespace std;

int grau[MAX_V];	
long long int d[MAX_V];		
int p[MAX_V];	
int visitado[MAX_V];	

typedef struct{
	int v;	
	long long int w;	
} TAdj;
TAdj adj[MAX_V][MAX_A];

void aresta(int a, int b, long long int w){
	adj[a][ grau[a] ].v = b;
	adj[a][ grau[a] ].w = w;
	grau[a]++;
}

void initGrafo(int vertices){
	memset(grau, 0, sizeof(int)*vertices);
	memset(p,-1, sizeof(int)*vertices);
}

void dfs(int v){
    visitado[v] = 1;
    for(int i = 0; i < grau[v]; i++){
        if (!visitado[adj[v][i].v])
            dfs(adj[v][i].v);
    }
}

bool interfere(int v, int n){
    memset(visitado, 0, sizeof(int)*n);
    dfs(v);
    if (visitado[0] || visitado[n-1])
        return true;
    return false;
}

bool bellmanFord(int inicial, int n){
    memset(p, -1, sizeof(p));
    for(int i=0; i<n; i++)
        d[i] = INF;
    d[inicial] = 0;
    for(int i=0; i<n; i++){ // todos vertices
        for(int j=0; j<n; j++){ /* todas */
            if (d[j] == INF)
                continue;
            for(int k=0; k<grau[j]; k++){/* arestas */
                if(d[j] + adj[j][k].w < d[adj[j][k].v])
                {
                    d[adj[j][k].v] = d[j] + adj[j][k].w;
                    p[adj[j][k].v] = j;
                }
            }
        }
    }

    for(int i=0; i<n; i++){
        if (d[i] == INF)
            continue;
        for(int j=0; j<grau[i]; j++){
            if(d[adj[i][j].v] > d[i] + adj[i][j].w && interfere(adj[i][j].v, n)) 
                return false;
        }
    }
    return true;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n, m, a, b, i;
    long long int c, pv, resp = 0;
	cin >> n >> m >> pv;
    initGrafo(n);
    for(i = 0; i < m; i++){
        cin >> a >> b >> c;
        aresta(a-1,b-1,pv-c);
    }
    if (bellmanFord(0, n))
    {
        cout << max(resp, -d[n-1]) << endl;
    } 
    else
    {
        cout << "-1" << endl;
    }
}


Measured memory_bytes: 13776
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fr(i,n) for(ll i = 0 ; i < n ; ++i)
#define vi vector<ll>
#define pb push_back
#define mp make_pair
ll a[1000],n;
ll solve(ll p){
	ll sum = 0;
	fr(i,n)sum += (a[i] - p)*(a[i] - p);
	return sum;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	fr(i,n)cin>>a[i];
	ll ans = 1000000;
	fr(i,101){
		if(solve(i) < ans)ans = solve(i);
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int mx = Math.min(a, b);
            int mn = 0;
            if (a + b > n) mn = a + b - n;

            // 出力
            out.printf("%d %d\n", mx, mn);

        }

    }
}



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

int main() {
  long long N, M, L, A;
  cin >> N >> M >> L;

  int l = __builtin_ffsll(L);
  while (cin >> A) {
    if (__builtin_ffsll(A) != l) goto NG;
    L = L * A / __gcd(L, A);
    if (L / 2 > M) goto NG;
  }

  cout << (M - L / 2) / L + 1 << "\n";
  return 0;
  NG:
  cout << 0 << "\n";
}

Measured memory_bytes: 256
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------

n = int(input())
st = set()
for i in range(n):
    st.add(input().strip())
print(len(st))


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,d;
const ll big = 1000000007;

vl A;
map<ll,ll> M;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;

    cin >> n;
    for(int c1 = 0; c1 < n; c1++){
        cin >> a;
        if(M.find(a) == M.end())M[a] = 0;
        M[a]++;
        A.push_back(a);
    }
    sort(all(A));
    ll ans = 0;
    for(int c1 = n-1; c1 >= 0; c1--){
        a = A[c1];
        if(M[a] == 0)continue;
        ll t = 1;
        while(t <= a){
            t *= 2;
        }
        b = t-a;
        if(M.find(b) != M.end() && M[b] != 0){
            if(a == b && M[b] == 1)continue;
            M[b]--;
            ans++;
        }
        M[a]--;
    }

    cout << ans << "\n";

    return 0;
}


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

using namespace std;

const int N = 100010;
int act[N];

int main() {
	ios::sync_with_stdio(false);
	cout.tie(0);
	
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		act[i] = act[i-1] + 1;
		for (int j = 6; j <= i; j *= 6) {
			act[i] = min(act[i], act[i-j] + 1);
		}
		for (int j = 9; j <= i; j *= 9) {
			act[i] = min(act[i], act[i-j] + 1);
		}
	}
	cout << act[n] << endl;
	return 0;
}

Measured memory_bytes: 640
N = int(input())
if N == 2:
    print(4,7)
    print(23,10)
    exit()

MAXN = 8000
sieve = [0,0] + [1]*MAXN
primes = []
p = 2
while p*p <= MAXN:
    if sieve[p]:
        primes.append(p)
        for q in range(2*p,MAXN+1,p):
            sieve[q] = 0
    p += 1
for q in range(p,MAXN):
    if sieve[q]:
        primes.append(q)

mem = [[[] for j in range(N)] for i in range(N)]
pi = 0
for i in range(0,2*N-1,4):
    for x in range(N):
        y = i-x
        if y >= N: continue
        if y < 0: break
        mem[y][x].append(primes[pi])
    pi += 1
for i in reversed(range(2,2*N-1,4)):
    for x in range(N):
        y = i-x
        if y >= N: continue
        if y < 0: break
        mem[y][x].append(primes[pi])
    pi += 1

ini = -((N-1)//2*2)
for i in range(ini,N,4):
    for x in range(N):
        y = x-i
        if y < 0: continue
        if y >= N: break
        mem[y][x].append(primes[pi])
    pi += 1
for i in range(ini+2,N,4):
    for x in range(N):
        y = x-i
        if y < 0: continue
        if y >= N: break
        mem[y][x].append(primes[pi])
    pi += 1

ans = [[None]*N for i in range(N)]
dxy = [(1,0),(0,1),(-1,0),(0,-1)]
for y in range(N):
    for x in range(N):
        if (x+y)%2:
            pset = set()
            for dx,dy in dxy:
                nx,ny = x+dx,y+dy
                if not 0 <= nx < N: continue
                if not 0 <= ny < N: continue
                pset.add(mem[ny][nx][0])
                pset.add(mem[ny][nx][1])
            a = 1
            for p in pset:
                a *= p
            ans[y][x] = a+1
        else:
            ans[y][x] = mem[y][x][0] * mem[y][x][1]

for row in ans:
    print(*row)

Measured memory_bytes: 40880
# -*- coding:utf-8 -*-
import sys

sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
mod = 1000000007
inf = float("INF")


def I(): return int(input().rstrip())


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


def F(): return float(input().rstrip())


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


def S(): return input().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


# def LI_(): return list(map(lambda x: int(x) - 1, input().rstrip().split()))
# def IR(n): return [I() for _ in range(n)]
# def LIR(n): return [LI() for _ in range(n)]
# def FR(n): return [F() for _ in range(n)]
# def LFR(n): return [LI() for _ in range(n)]
# def LIR_(n): return [LI_() for _ in range(n)]
# def SR(n): return [S() for _ in range(n)]
# def LSR(n): return [LS() for _ in range(n)]


a, b = LI()

if a * b % 2 == 1:
    print('Odd')
else:
    print('Even')


Measured memory_bytes: 9108
import java.util.Scanner;
import java.lang.Math;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
            int cnt = input.nextInt();
            if(cnt == 0)
                break;
            double[] grade = new double[cnt];
            double sum = 0;
            double ave = 0;
            double a = 0;
            for(int i = 0; i < cnt; i ++ ){
                grade[i] = input.nextDouble();
                sum += grade[i];
            }
            ave = sum / cnt;
            for(int j = 0; j < cnt; j ++ ){
                a += ((grade[j] - ave) * (grade[j] - ave));
            }
            a = Math.sqrt(a / cnt);
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 40024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int N,M;
    cin >> N >> M;
    vector<int> H(N);
    for(int i=0; i<N; i++){
        cin >> H.at(i);
    }

    vector<vector<int>> vec(N);

    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        vec.at(a-1).push_back(b-1);
        vec.at(b-1).push_back(a-1);
    }
    int count=0;
    for(int i=0; i<N; i++){
        bool flag = true;
        for(int j=0; j<vec.at(i).size(); j++){
            if(H[vec.at(i).at(j)]>=H[i]){
                flag = false;
            }
        }
        if(flag){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 8808
import re

def solve(s):
    if s == 'keyence':
        return True
    if re.match(r'^([a-z]+)keyence$', s):
        return True
    if re.match(r'^k([a-z]+)eyence$', s):
        return True
    if re.match(r'^ke([a-z]+)yence$', s):
        return True
    if re.match(r'^key([a-z]+)ence$', s):
        return True
    if re.match(r'^keye([a-z]+)nce$', s):
        return True
    if re.match(r'^keyen([a-z]+)ce$', s):
        return True
    if re.match(r'^keyenc([a-z]+)e$', s):
        return True
    if re.match(r'^keyence([a-z]+)$', s):
        return True
    return False

s = raw_input().rstrip()

if solve(s):
    print 'YES'
else:
    print 'NO'


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

int main(){
    int n, m;
    cin >> n >> m;
    bool ans = true;
    rep(i,m){
        int a;
        cin >> a;
        n -= a;
        if(n < 0){
            ans = false;
            break;
        }
    }
    if(ans) cout << n << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;
typedef pair<long long, long long> pll;
// scanf("%d %d %d %d", &w, &b, &d, &s); %lld
// printf("%d\n", points);
// const double PI = acos(-1);

int main()
{
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    #else
        fastIO;
    #endif
        ll n, aux, temp;
        ll ans = 0, rta = 0;
        map <int, pll> m;
        cin >> n;
        int num[n];
        for(int i = 0; i<n; i++){
            cin >> aux;
            num[i] = aux;
            m[aux].sd+=(m[aux].ft);
            m[aux].ft++;
        }

        for(auto &x: m)
            rta += x.sd.sd;

        for(int i = 0; i<n; i++){
            aux = num[i];
            temp = m[aux].ft-2;
            temp = ((temp*temp+temp)/2);
            ans = rta-m[aux].sd + temp;
            cout << ans << endl;
        }
        return 0;
}

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

int main(){
  string n;cin>>n;
  for(int i=0;i<3;i++){
    if(n[i]=='1')n[i]='9';
    else if(n[i]=='9')n[i]='1';
  }
  cout<<n;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n[3];
	int i, max, imax;
	int ans;
	
	scanf("%d %d %d", &n[0], &n[1], &n[2]);
	
	max = n[0];
	imax = 0;
	for (i = 1; i < 3; i++) {
		if (n[i] > max) {
			max = n[i];
			imax = i;
		}
	}
	
	ans = max * 10;
	for (i = 0; i < 3; i++) {
		if (i != imax)
			ans += n[i];
	}
	
	printf("%d", ans);
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h> 
using namespace std;

typedef long long ll;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) 
#define rep(pp,nn) for (int ii = pp; ii < nn; ++ii)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

string int_to_string(int x) {
    stringstream ss;
	ss << x;
	string ni = ss.str();
	return ni;
}
int string_to_int(string x) {
	int n;
	stringstream s(x);
	s >> n;
	return n;
}

int64_t power_mod(ll a, ll b, ll mo) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}
int64_t POW(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = ans * a;
		}
		a = a * a;
		b /= 2;
	}
	return ans;
}

vector<int64_t> INVERSE(int64_t nn, int64_t mo) {
	vector<int64_t> inv(nn + 1);
	vector<int64_t> mul(nn + 1);
	inv[0] = 1;
    inv[1] = 1;
	for (ll i = 2; i <= nn; ++i) {
		inv[i] = (mo - (mo / i) * inv[mo % i] % mo) % mo; 
	}
	mul[0] = 1;
	for (int i = 1; i <= nn; ++i) {
		mul[i] = (mul[i - 1] * inv[i]) % mo;
	}
	return mul;
}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main() {
	IOS;
	int n, k;
	cin >> n >> k;
	vector<int64_t> v(n);
	set<pair<int64_t,int>> s;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		s.insert({-v[i],i});
	}
	while (k && !s.empty()) {
		auto it = s.begin();
		k--;
		if ((-it->first) / 2 != 0) {
			s.insert({-(-it->first / 2) , it->second});
		}
		s.erase(it);
	}
	int64_t ans = 0;
	for (auto x : s) {
		ans += -1 * x.first;
	}
	cout << ans;
}














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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll MAX_M = 1000000000;
const ll MAX_N = 100000;

vector<ll> primes;
bool is_prime[MAX_N + 1];

// eratosthenesの篩 O(nloglogn)
// n以下の素数を列挙して、n以下の素数の数を返す
void sieve(){
  for(ll i=0;i*i<=MAX_M;i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for(ll i=2;i*i<=MAX_M;i++){
    if(is_prime[i]){
      primes.push_back(i);
      for(ll j=2*i;j*j<=MAX_M;j+=i) is_prime[j] = false;
    }
  }
}

map<ll, ll> prime_factors(ll x){
    // set primes
    sieve();
    map<ll, ll> res;
    for(ll p: primes){
        while(x % p == 0){
            res[p]++;
            x = x / p;
        }
    }
    if(x != 1) res[x]++;
    return res;
}

// 二分累乗法により、x^n %mod を求める
ll mod_pow(ll x, ll n){
  if (n == 0) return 1;
  ll res = mod_pow(x * x %MOD, n / 2);
  // nが奇数の場合, x^n = ((x^2)^(n/2)) * x
  if(n & 1) return res = res * x %MOD;
  // nが偶数の場合、x^n = (x^2)^(n/2)
  return res %MOD;
}

// nCk = n!/(n - k)!k!を、逆元a/b = a*b^(1e7 - 2)(mod 1e7)を用いて求める
ll comb(ll n, ll k){
  ll res = 1;
  k = min(n - k, k);
  for(ll i=n-k+1;i<=n;i++) res = (res * i) %MOD;
  for(ll i=1;i<=k;i++) res = (res * mod_pow(i, MOD-2)) %MOD;
  return res;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    map<ll, ll> pf = prime_factors(m);
    ll ans = 1;
    for(auto it = pf.begin();it != pf.end();it++){
        ll is = it -> second;
        ans = (ans * comb(is + n - 1, is)) %MOD;
    }
    cout << ans << endl;
}

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

int main() {
    int ans=-1;
    for(int i=1;i<=5;i++)
    {
        int k;
        cin>>k;
        if(k==0)
        {
            ans=i;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int X = scanner.nextInt();

        int[] C = new int[N];
        int[][] A = new int[N][M];

        for (int i = 0; i < N; i++) {
            C[i] = scanner.nextInt();
            for (int j = 0; j < M; j++) {
                A[i][j] = scanner.nextInt();
            }
        }

        int minCost = -1;
        for (int i = 0 ; i < (1 << N) ; i++) {
            int cost = 0;
            int[] skills = new int[M];
            for (int j = 0 ; j < N ; j++) {
                if (((i >> j) & 1) == 1) {
                    cost += C[j];
                    for (int k = 0 ; k < M ; k++) {
                        skills[k] += A[j][k];
                    }
                }
            }

            boolean flag = true;
            for (int k = 0 ; k < M ; k++) {
                if (skills[k] < X) flag = false;
            }

            if (flag) {
                if (minCost == -1) {
                    minCost = cost;
                } else  {
                    minCost = Math.min(minCost, cost);
                }
            }
        }
        System.out.println(minCost);
    }
}


Measured memory_bytes: 37332
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define  DESC std::greater<int>() //sort 3rd arg

int main()
{
	int x;
	REP(i, 5) {
		cin >> x;
		if (x == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}

	return 0;
}



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

int main() {
    int n, q;
    cin >> n >> q;
    stack<int> st[n];
    while (q--) {
        int t;
        cin >> t;
        if (t == 0) {
            int a, b;
            cin >> a >> b;
            st[a].push(b);
        } else if (t == 1) {
            int a;
            cin >> a;
            if (st[a].size()) {
                cout << st[a].top() << endl;
            }
        } else {
            int a;
            cin >> a;
            if (st[a].size()) {
                st[a].pop();
            }
        }
    }
}


Measured memory_bytes: 4188
// Example program
#include <iostream>
#include <string>
using namespace std;

int main()
{
    // 整数の入力
    int N;
    cin >> N;
    // 出力
    if(N % 2 == 0) cout << N << endl;
    if(N % 2 == 1) cout << N * 2 << endl;
    return 0;
}

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

using ll = long long;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (ll i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

template<typename T> using pop_max = std::priority_queue<T>;
template<typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T> void LOG(const T& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T> void LOG(const vector<vector<T>>& a) { for (const auto& x : a) LOG(x); }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }
ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll gcd(const vector<ll>& v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll(*)(ll, ll)>(gcd)); }
ll lcm(const vector<ll>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll(*)(ll, ll)>(lcm)); }
ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
ll inv(ll x, ll m) { return pow(x, m - 2, m); }

template<typename T> bool chmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<typename T> bool chmin(T& x, const T& y) { return x > y ? x = y, true : false; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp;

const ll INF = inf<ll>;
using P = pair<ll, ll>;
const ll M = 1000000007;
signed main() {
  ll r,c,R,C;
  cin>>r>>c>>R>>C;
  vector<ll> fact(R+C+3);
  fact[0]=1;
  REP(i,R+C+2)fact[i+1]=(i+1)*fact[i]%M;
  auto f=[&](ll a,ll b)->ll{
    return fact[a+b]*inv(fact[a],M)%M*inv(fact[b],M)%M;
  };
  cout<<((f(R+1,C+1)-f(R+1,c)-f(r,C+1)+f(r,c))%M+M)%M<<endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,C,D;
    bool win;
    cin >> A >> B >> C >> D;
    while(1){
        C-=B;
        if(C<=0){
            win=true;
            break;
        }
        A-=D;
        if(A<=0){
            win=false;
            break;
        }
    }
    if(win){
        cout << "Yes";
    } else {
        cout << "No";
    }
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int ans = n * (n + 1) / 2 + n * (l - 1)
                - (l + (l > 0 ? 1 : (n > -l ? -l + 1 : n)) - 1);
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    long long n;
    cin >> n;
    cout << (long long)n * (n - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a*100+b*10+c)%4==0)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

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

long long dig(long long n) {
	return (long long)floor(log10(n)) + 1;
}

int main() {
	long long n;
	scanf("%lld", &n);
	bool found = 0;
	long long ans = dig(n);
	for (long long i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			long long foo = max(dig(i), dig(n / i));
			ans = min(ans, foo);
			found = 1;
		}		
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	long i=0,n,x,a[114];
	for(cin>>n>>x;i<n;cin>>a[i++]);
	sort(a,a+n);
	for(i=0;x>0&&i<n;i++)x-=a[i];
	cout<<i-1+(x==0)<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int k = Integer.parseInt(tokenizer.nextToken());
        int s = Integer.parseInt(tokenizer.nextToken());
        int count = 0;
        for (int i = 0; i <= k; i++) {
            for (int j = 0; j <= k; j++) {
                if (s >= i+j && s-(i+j) <= k){
                    count++;
                }
                if (s < i+j)
                    break;
            }
            if (s < i)
                break;
        }
        System.out.println(count);

    }
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL)
#define PI acos(-1.0)
#define TEST(n) cout<<"dhukse"<<n<<'\n'
#define endl '\n'
#define FILEREAD freopen("input.txt","r",stdin)
#define FIXED(n) cout << fixed << setprecision(n);
#define CASE(n) cout<<"Case " << n << ": ";
long long Set(long long N,long long pos){ return N=N | (1<<pos);}
long long reset(long long N,long long pos){return N= N & ~(1<<pos);}
bool check(long long N,long long pos){return (bool)(N & (1<<pos));}
long long min(long long a, long long b){if(a<b)return a;else return b;}
long long max(long long a, long long b){if(a>b)return a;else return b;}

/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////In the name of almighty ALLAH/////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Coded By: pranonrahman////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    FAST;
    long long t=1;
   // cin >> t;
    long long T = t;
    while(t--)
    {
        long long n,k;
        cin >> n >> k;
        if(n%k==0)  cout << n/k << endl;
        else        cout << (n/k)+1 << endl;
    }
    return 0;
}



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

long long f(long long a, long long b) {
  string s1,s2;
  s1 = to_string(a);
  s2 = to_string(b);
  return max(s1.size(), s2.size());
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, ans = 1000000000000000000LL;
  cin >> n;
  long long a=1, b=n;
  for (a = 1; a <= sqrt(n); a++) {
    if (n%a != 0) continue;
    b = n/a;
    ans = min((long long)ans, (long long)f(a, b));
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
bool C(int j,int k,int l){
  if(j==0&&k==1&&l==2) return true;
  if(j==0&&k==2&&l==1) return true;
  if(j==1&&k==0&&l==2) return true;
  return false;
}
  
int main(){
  int n;cin>>n;
  ll dp[110][4][4][4];
  fill(dp,0);
  rep(j,4){
    rep(k,4){
      rep(l,4){
	if(C(j,k,l)) dp[3][j][k][l]=0;
	else dp[3][j][k][l]=1;
      }
    }
  }
  for(int i=4;i<=n;i++){
    rep(j,4){
      rep(k,4){
	rep(l,4){
	  if(C(j,k,l)) dp[i][j][k][l]=0;
	  else if((j==1&&l==2)||(k==1&&l==2)){
	    rep1(s,3) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][s][j][k])%MOD;
	  }
	  else{
	    rep(s,4) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][s][j][k])%MOD;
	  }
	}
      }
    }
  }
  ll res=0;
  if(n!=3){
    rep(j,4){
      rep(k,4){
	rep(l,4){
	  res=(res+dp[n][j][k][l])%MOD;
	}
      }
    }
  }
  else res=61;
  prin(res);


  
  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#define N 100005
#define K 200005
#define MOD 998244353
#define ll long long int
using namespace std;
 ll max(ll a,ll b)
 {
     if(a>=b)
     {
         return a;
     }
     else
     {
         return b;
     }
     
 }
 const int size=1e5+5;
vector<int> edges[size];
int indegree[size];
vector<bool> visited(size,0);
vector<int> dist(size,0);
void dfs(int a)
{
    visited[a]=1;
    for(int b:edges[a])
    {
        dist[b]=max(dist[b],dist[a]+1);
       // cout<<dist[b]<<endl;
        indegree[b]--;
        if(indegree[b]==0)
        {
            dfs(b);
        }
    }
}
int main() {
int n,m;
cin>>n>>m;
while(m--)
{
    int a,b;
    cin>>a>>b;
    edges[a].push_back(b);
    indegree[b]++;
  
}
for(int i=1;i<=n;i++)
{
    
    if(visited[i]==0&& indegree[i]==0)
    {
        //cout<<indegree[i]<<endl;
        dfs(i);
        
    }
}
int ans=0;
for(int i=1;i<=n;i++)
{
   // cout<<dist[i]<<endl;
    ans=max(ans,dist[i]);
}
cout<<ans<<endl;

}

Measured memory_bytes: 9600
def dfs(i, f, Sum):
    if i == n-1:
        if Sum == 7:
            print(f+"=7")
            exit()
    else:
        dfs(i+1, f+"+"+a[i+1], Sum + int(a[i+1]))
        dfs(i+1, f+"-"+a[i+1], Sum - int(a[i+1]))
        

a = input()
n = len(a)

dfs(0, a[0], int(a[0]))

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<map>
using namespace std;

int main() {
    int n;
	cin>>n;
    map<string,int> m;
    m["AC"]=0;
    m["WA"]=0;
    m["TLE"]=0;
    m["RE"]=0;
    while(n--) {
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
    return 0;
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
//RNG based on mersenne_twister 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }


int _runtimeTerror_()
{
	int n,i,j;
	cin>>n;
	string s;
	cin>>s;
	int count[n+1][3];
	mem0(count);
	for(i=n-1;i>=0;--i)
	{
		count[i][0]=count[i+1][0];
		count[i][1]=count[i+1][1];
		count[i][2]=count[i+1][2];
		if(s[i]=='R')
			++count[i][0];
		if(s[i]=='G')
			++count[i][1];
		if(s[i]=='B')
			++count[i][2];
	}
	ll ans=0;
	for(i=0;i<n;++i)
	{
		for(j=i+1;j<n;++j)
		{
			if(s[j]!=s[i])
			{
				char x='R'+'G'+'B'-s[i]-s[j];
				if(x=='R')
					ans+=count[j][0];
				if(x=='G')
					ans+=count[j][1];
				if(x=='B')
					ans+=count[j][2];
				//cout<<x<<endl;
				if(j+j-i<n && s[j+j-i]==x)
					--ans;
				//cout<<"ASN"<<ans<<endl;
			}
		}
	}
	cout<<ans;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	cerr<<"\n"<<_time_;
	return 0;
}


Measured memory_bytes: 3900
#include<bits/stdc++.h>
using namespace std;
int main(){
  string o,e;
  cin>>o>>e;
  for(int i=0;i<o.size()+e.size();i++){
    if(i%2==0)
      cout<<o.at(i/2);
    else
      cout<<e.at(i/2);
  }
  cout<<endl;
}

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

using namespace std;

int main(){
  int n,z=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    if(a!=i)
    z++;
  }
  if(z==0 || z==2)  puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	string S;
	
	cin>>N>>S;
	
	if(N%2) cout<<"No"<<endl;
	else {
		string x = S.substr(0, N/2);
		x += x;
		if(x == S) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
	
	return 0;
}

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

class Calc {
  private:
    string str;
    vector<char> p;
    string::iterator it;

  public:
    Calc (string str, vector<char> p) {
        this->str = str;
        this->p   = p;
        it = this->str.begin();
    }

    ll get_val(ll a, char op, ll b)
    {
        switch (op) {
            case '*':
                return a * b;
            case '+':
                return a + b;
            case '-':
                return a - b;                
        }
    }

    ll f0(int pt)
    {
        ll res = 0;
        if (*it == '(') {
            ++it;
            if (pt == 0) {
                res = f3(0);
            } else if (pt <= 2) {
                res = f2(pt);   
            } else {
                res = f1(3);
            }
            ++it;
        } else {
            while (isdigit(*it)) {
                res *= 10LL;
                res += (ll)(*it - '0');
                ++it;
            }
        }
        return res;
    }

    ll f1(int pt)
    {
        ll res = f0(pt);
        while (*it == p[0] ||
               (pt >= 2 && *it == p[1]) ||
               (pt >= 3 && *it == p[2])) {
            
            if (*it == p[0]) {
                ++it;            
                res = get_val(res, p[0], f0(pt));
            } else if (pt >= 2 && *it == p[1]) {
                ++it;
                res = get_val(res, p[1], f0(pt));
            } else if (pt >= 3 && *it == p[2]) {
                ++it;
                res = get_val(res, p[2], f0(pt));
            }            
        }
        return res;
    }

    ll f2(int pt)
    {
        ll res = f1(pt);
        while ((pt <= 1 && *it == p[1]) ||
               (pt >= 1 && *it == p[2])) {
            
            if (pt <= 1 && *it == p[1]) {
                ++it;
                res = get_val(res, p[1], f1(pt));                                
            } else if (pt >= 1 && *it == p[2]) {
                ++it;
                res = get_val(res, p[2], f1(pt));                
            }
                   
        }
        return res;
    }

    ll f3(int pt)
    {
        ll res = f2(0);
        while (*it == p[2]) {
            ++it;
            res = get_val(res, p[2], f2(0));
        }
        return res;
    }
};

int main()
{
    string str;
    cin >> str;      
    vector<char> p = {'*', '+', '-'};
    ll res = LLONG_MIN;    
    do {
        for (int i = 0; i < 4; i++) {
            Calc  c(str, p);
            ll r = -1;
            if (i == 0) {
                r = c.f3(0);
            } else if (i <= 2) {
                r = c.f2(i);
            } else {
                r = c.f1(3);
            }
            res = max(res, r);
        }
    } while (next_permutation(p.begin(), p.end()));
    cout << res << endl;    
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int size = s.size();
    int diff = 1000;
    for (int i=0; i < size - 2; i++){
        string k;
        for (int j=i; j < i+3; j++){
            k += s.at(j);
        }
        int intk = stoi(k);
        diff = min(abs(intk - 753), diff);
    }
    cout << diff << endl;
}

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

int main()
{
    double a,b,c;
    cin>>a>>b>>c;
    cout<<fixed<<setprecision(6)<<a*b*sin(c/180*M_PI)/2<<endl<<a+b+sqrt(a*a+b*b-2*a*b*cos(c/180*M_PI))<<endl<<b*sin(c/180*M_PI)<<endl;
}




Measured memory_bytes: 3520
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline

H, W = map(int, readline().split())
S = [list(input()) for i in range(H)]


def bfs(grid, start):
    distance = [[0] * W for _ in range(H)]
    queue = deque([start])
    visited = [[False] * W for _ in range(H)]
    visited[start[0]][start[1]] = True
    while queue:
        x, y = queue.popleft()

        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_y, new_x = y + j, x + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if grid[new_x][new_y] == '.' and not visited[new_x][new_y]:
                    distance[new_x][new_y] = distance[x][y] + 1
                    visited[new_x][new_y] = True
                    queue.append((new_x, new_y))
    return distance


answer = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue

        tmp = max(map(max, bfs(S, (i, j))))
        if tmp > answer:
            answer = tmp

print(answer)


Measured memory_bytes: 3316
class BinaryTreeNode():
    def __init__(self, val, parent=None, left=None, right=None):
        self.parent = parent
        self.left = None
        self.right = None
        self.val = val

    def get_child_num(self):
        num = 0
        if self.left != None: num += 1
        if self.right != None: num += 1
        return num

    def get_successor(self):
        x = self
        if x.right != None:
            return x.right.get_minimum()

        y = x.parent
        while y != None and x == y.right:
            x = y
            y = y.parent
        return y

    def get_minimum(self):
        x = self
        while x.left != None:
            x = x.left
        return x

class BinarySearchTree():
    def __init__(self):
        self.root = None

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val, parent=y)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def find(self, val):
        x = self.root
        while x != None:
            if x.val == val:
                return x
            elif x.val < val:
                x = x.right
            else:
                x = x.left
        return None

    def delete(self, val):
        z = self.find(val)
        if z == None: return

        y = None
        if z.get_child_num() < 2:
            y = z
        else:
            y = z.get_successor()

        x = None
        if y.left != None:
            x = y.left
        else:
            x = y.right

        if x != None:
            x.parent = y.parent

        if y.parent == None:
            self.root = x
        elif y == y.parent.left:
            y.parent.left = x
        else:
            y.parent.right = x

        if y != z:
            z.val = y.val

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op.startswith('insert'):
        num = int(op[7:])
        bst.insert(num)
    elif op.startswith('delete'):
        num = int(op[7:])
        bst.delete(num)
    elif op.startswith('find'):
        num = int(op[5:])
        if bst.find(num):
            print('yes')
        else:
            print('no')
    else:
        print_elements(bst.inorder())
        print_elements(bst.preorder())



Measured memory_bytes: 121516
def nibutan(arr,max,min,key)
  if max < min
    return min
  else
    mid = min+(max-min)/2
    if arr[mid] > key
      nibutan(arr,mid-1,min,key)
    elsif arr[mid] < key
      nibutan(arr,max,mid+1,key)
    else
      return mid
    end
  end
end
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
for i in 1..n-1
  a[i] += a[i-1]
end
ans = 10**10
for i in 1..n-3
  c1 = nibutan(a,i,0,a[i]/2)
  c2 = nibutan(a,n-1,i+1,(a[-1]+a[i])/2)
  p,q = 0,10**10
  for j in c1..c1+1
    if j != 0
      tp = a[j-1]
      tq = a[i]-tp
      if (p-q).abs > (tp-tq).abs
        p,q = tp,tq
      end
    end
  end
  r,s = 0,10**10
  for j in c2..c2+1
    if j != i
      tr = a[j-1]-a[i]
      ts = a[-1]-a[j-1]
      if (r-s).abs > (tr-ts).abs
        r,s = tr,ts
      end
    end
  end
  pqrs = [p,q,r,s]
  pqrs.sort!
  temp = pqrs[3]-pqrs[0]
  ans = [ans,temp].min
end
p ans

Measured memory_bytes: 23844
A, B, m = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(m)]

mx = min(aa) + min(bb) # 割引なしの最安
for i in range(m):
    x, y, c = xyc[i]
    x -= 1
    y -= 1
    mx = min(mx, aa[x]+bb[y]-c)
print(mx)

Measured memory_bytes: 38560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int k, s;
    cin >> k >> s;
    ll ans = 0;
    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            int z = s - x - y;
            if (0 <= z && z <= k){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin
import sys, math

n,m,x = [int(x) for x in stdin.readline().rstrip().split()]

c = []
for i in range(n):
    c.append([int(x) for x in stdin.readline().rstrip().split()])

money = []
for i in range(2**n):
    b = bin(i)
    d = [0 for i in range(m + 1)]
    for j in range(n):
        if b[-1] == "1": d = [p+q for (p,q) in zip(d,c[j])]
        b = str(bin(int(b, 2) // 2))

    if min(d[1:]) >= x: money.append(d[0])

if len(money) == 0:
    print(-1)
else:
    print(min(money))
   

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,sum;
	scanf("%d",&n);
	int a=n;
	while(n){
		sum+=n%10;
		n/=10;
	}
	if(a%sum==0)printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		BigDecimal a = new BigDecimal(sc.nextInt());

		BigDecimal x = a.subtract(BigDecimal.ONE).multiply(new BigDecimal("0.5"));
		BigDecimal result = x.multiply(a);

		result = result.setScale(0,BigDecimal.ROUND_DOWN);
		System.out.println(result.toPlainString());
	}
}

Measured memory_bytes: 22988
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long int n,a,b,x;
    cin>>n>>a>>b;
    
    //if(b-a==1){
    //    x=a;
        // cout<<"x is : "<<x<<endl;
//}
    
    if((b-a)%2==0){
       x=(b-a)/2;
    //   cout<<"x is : "<<x<<endl;
    }
    
    else {
       x= min(a - 1, n - b) + 1 + (b-a-1)/2;
        }
    
    cout<<x<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int N;
    scanf("%d", &N);
    
    int i,j;
    int P[200000+1] = {0};
    // sum[i] : 0~i 番目の中での最小値
    int sum[200000+1] = {0};
    sum[0]=200000+1;
    for( i = 1; i <= N; i++ ){
        scanf("%d", &P[i]);

        if( P[i] < sum[i-1] ) sum[i]=P[i];
        else sum[i]=sum[i-1];
    }

    int flag=0;
    for( i = 1; i <= N; i++ ){
        if( P[i] > sum[i-1] ) flag++;
    }

    printf("%d\n", N-flag);

    return 0;
}
       


Measured memory_bytes: 1664