akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}

using Graph = vector<vector<int>>;
Graph G;
int dfs(int u, int p=-1) {
  int g = 0;
  for (auto v : G[u]) {
    if (v == p) continue;
    g ^= dfs(v, u);
  }
  return g + 1;
}

int main() {
  ll N; cin >> N;

  G = Graph(N);
  for (int i = 0; i < N-1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  cout << ((dfs(0) != 1) ? "Alice" : "Bob") << endl;
  return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define int long long
#define fill(x, v) memset(x, v, sizeof(x))
#define ios std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
int n;
int mx = -1, mod = 1e9 + 7;
int arr[21][21];
int dp[1 << 21];
//dp[mask] = number of ways to marry rmaining unmarried men to women which are 0(unmarried) in mask;
int count(int idx, int mask)
{
    if (idx >= n)
        return 1;
    if (dp[mask] != -1)
        return dp[mask];
    int ret = 0;
    for (int i = 0; i < n; i++)
    {
        if ((!(mask & (1 << i))) && (arr[idx][i]))
        {
            ret = (ret + count(idx + 1, mask | (1 << i))) % mod;
        }
    }
    return dp[mask] = ret;
}
int32_t main()
{
    ios;
    cin >> n;
    fill(dp, -1);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> arr[i][j];
    count(0, 0);
    cout << dp[0] << endl;
}


Measured memory_bytes: 16640
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int g=0,x,y,i,a[4];
	for(i=0;i<4;i++)
	{
		cin>>a[i];
		g=g+a[i];
	}
	x=g/60;
	y=g%60;
	cout<<x<<endl<<y<<endl;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int n,x,t;
    cin>>n>>x>>t;

    cout<<((n+x-1)/x)*t<<"\n";

    return 0;

}

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

typedef long long ll;
ll n, k, a[100010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(int i=0; i<n; ++i) cin >> a[i];
	vector<int> v;
	for(int i=0; (k>>i)>0; ++i)
		v.push_back((k>>i)&1);
	reverse(v.begin(), v.end());
	vector<int> w(v.size(), 0);
	for(int i=0; i<w.size(); ++i){
		int cnt = 0;
		for(int j=0; j<n; ++j)
			cnt += (a[j] >> (w.size()-i-1)) & 1;
		if(cnt <= n/2) w[i] = 1;
	}
	ll x = 0;
	bool f = true;
	for(int i=0; i<v.size(); ++i){
		if(f){
			if(v[i] == 1){
				if(w[i] == 1) x += (ll)1 << (v.size()-i-1);
				else f = false;
			}
		}else{
			if(w[i] == 1) x += (ll)1 << (v.size()-i-1);
		}
	}
	ll ans = 0;
	for(int i=0; i<n; ++i)
		ans += x ^ a[i];
	cout << ans << "\n";
}

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

constexpr int MOD = 1e9 + 7;

int mod_inv(int a, int m) {
  int b = m, u = 1, v = 0;
  while (b) {
    int t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int sum = 0;
  int d_sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A[i];
    d_sum += A[i] * A[i] % MOD;
    sum %= MOD;
    d_sum %= MOD;
  }

  int ans = ((sum * sum) % MOD - d_sum + MOD) % MOD;
  ans = ans * mod_inv(2, MOD) % MOD;

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

Measured memory_bytes: 4852
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define inp(a) for(auto& i : a) cin >> i;
#define out(a) for(auto i : a){cout << i << ' ';}cout << endl;
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
string s ;
//#define int long long

int32_t main(){_
	int n,k ;
	cin >> n ;
	n++ ;
	vi a(n) , pre(n) , suf(n);
	for(int i=  1 ; i < n ; i++)
		cin >> a[i] ;
	for(int i = 0 ; i < n ; i++){
		if(!i) pre[i] = a[i] ;
		else pre[i] = pre[i-1] + a[i] ;
	}
	reverse(all(a)) ;
	for(int i = 0 ; i < n ; i++){
		if(!i) suf[i] = a[i] ;
		else suf[i] = suf[i-1] + a[i] ;
	}
	reverse(all(suf)) ;
	int mn = INF ;
	for(int i = 0 ; i < n ; i++){
		mn = min(mn, abs(suf[i]-pre[i-1])) ;
	}

	cout << mn << endl ;
}





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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
using namespace std;

using ll = long long;
using ii = pair<ll, ll>;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int a[n];
    rep(i, n) { cin >> a[i]; }
    sort(a, a + n);

    cout << a[n - 1] - a[0] << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main(){
    int s,w;
    cin >> s >> w;
    if(w>=s) cout << "unsafe" <<endl;
    else cout << "safe" <<endl;
    return 0;
}


Measured memory_bytes: 3636
fn calc_cost(cost: u32, year: u32) -> u32 {
    match year {
        6 ... 12 => cost / 2,
        0 ... 5 => 0,
        _ => cost,
    }
}


fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();

    let mut iter = input.split_whitespace();
    let year = iter.next().unwrap().parse().unwrap();
    let cost = iter.next().unwrap().parse().unwrap();

    println!("{}", calc_cost(cost, year));
}

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

using namespace std;

int main() {
	int n, m, x, taroPoint, hanakoPoint, difference;
	vector<int> taro;
	vector<int> hanako;
	while (cin >> n >> m, n || m) {
		taroPoint = 0;
		hanakoPoint = 0;

		for (int i = 0; i < n; i++) {
			cin >> x;
			taro.push_back(x);
			taroPoint += x;
		}
		sort(taro.begin(), taro.end());

		for (int i = 0; i < m; i++) {
			cin >> x;
			hanako.push_back(x);
			hanakoPoint += x;
		}
		sort(hanako.begin(), hanako.end());
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (taroPoint - hanakoPoint == (taro[i] - hanako[j]) * 2) {
					cout << taro[i] << " " << hanako[j] << endl;
					goto LABEL;
				}
			}
		}
		cout << "-1" << endl;
		LABEL:
		taro.clear();
		hanako.clear();
	}
	return 0;
}

Measured memory_bytes: 3148
def main():
    N = int( input())
    Q = 10**9+7
    C = list( map( int, input().split()))
    C.sort()
    ans = 1
    if N == 1:
        print(C[0]*2%Q)
        return
    for i in range(N-1):
        ans += pow(2,i,Q)*(((N-1)-i)*pow(2,N-2-i,Q) + pow(2, N-1-i, Q))*C[i]%Q
        ans %= Q
    ans += pow(2, N-1, Q)*C[N-1]%Q
    ans -= 1
    print(ans*pow(2,N,Q)%Q)
if __name__ == '__main__':
    main()


Measured memory_bytes: 25768
#include<bits/stdc++.h>
using namespace std;
struct date{
	int c0,c1,id;
	bool operator <(date rhs) const{
		return (long long)c0*rhs.c1<(long long)c1*rhs.c0;
	}
};
priority_queue<date> q;
int p[300000],c0[300000],c1[300000],fa[300000];
int find(int x){
	if (fa[x]==x) return x;
	else return fa[x]=find(fa[x]);
}
int main(){
	int n;
	scanf("%d",&n);
	for (int i=2;i<=n;i++)
		scanf("%d",p+i);
	for (int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if (!x) c0[i]++;
		else c1[i]++;
	}
	for (int i=2;i<=n;i++)
		q.push((date){c0[i],c1[i],i});
	for (int i=1;i<=n;i++) fa[i]=i;
	long long ans=0;
	while (!q.empty()){
		date d=q.top();
		int u=d.id;
		q.pop();
		if (d.c0!=c0[u]||d.c1!=c1[u]) continue;
		int v=find(p[u]);
		ans+=(long long)c1[v]*c0[u];
		c0[v]+=c0[u];
		c1[v]+=c1[u];
		fa[u]=v;
		if (v!=1) q.push((date){c0[v],c1[v],v});
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8052
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
// cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
// gcd function
// __gcd(a, b)
// for max of n elements
// cout<<max({a,b,c,d})<<endl;

lli input(lli n, vector<lli> &ve);
lli input(lli n, vector<lli> &ve) {
    lli val;
    for (lli i = 0; i < n; i++) {
        cin >> val;
        ve.pb(val);
    }
    return 0;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    lli n, a, wt, b;
    vector<lli> v, w;
    cin >> n >> wt;
    vector<vector<lli>> dp(n + 1, vector<lli>(100002, 1e13));
    fr(i, 0, n) {
        cin >> a >> b;
        w.pb(a);
        v.pb(b);
    }

    fr(i, 0, n) {
        dp[i][0] = 0;
    }

    dp[0][v[0]] = w[0];
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= 100000; j++) {
            if (j >= v[i]) {
                dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i - 1][j]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    for (lli i = 100000; i >= 0; i--) {
        if (dp[n - 1][i] <= wt) {
            cout << i << endl;
            rt;
        }
    }

    rt;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int n,ans,s[1000],b[1000];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];b[s[i]]=1;
	}
	for(int i=1;i<=100;i++)
	  ans+=b[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
// Last Change: 04/23/2019 23:13:16.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int A, B, C, ans;
  cin >> A >> B >> C;

  if (A < B) {
    swap(A, B);
  }
  if (B < C) {
    swap(B, C);
  }
  if (A < B) {
    swap(A, B);
  }

  ans = A * 10 + B + C;

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 504
from bisect import bisect_right as binarysearch
A, B, Q = map(int,input().split())

ss = [-10**10]+[int(input()) for _ in range(A)]+[2*10**10]
ts = [-10**10]+[int(input()) for _ in range(B)]+[2*10**10]
xs = [int(input()) for _ in range(Q)]
for x in xs:
    sind = binarysearch(ss,x)-1
    tind = binarysearch(ts,x)-1
    
    s0,s1,t0,t1 = ss[sind],ss[sind+1],ts[tind],ts[tind+1]
    d1,d2,d3,d4 = 10**10,10**10,10**10,10**10

    d1 = max(x-s0,x-t0)
    d2 = min((t1-x)*2+(x-s0),(x-s0)*2+(t1-x))
    d3 = min((s1-x)*2+(x-t0),(x-t0)*2+(s1-x))
    d4 = max(s1-x, t1-x)
    print(min(d1,d2,d3,d4))

Measured memory_bytes: 17296
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
ll a[10000009];
inline ll nod(ll n)
{
  if(n==1)
    return 1;
  ll ans=1,d,ct;
  while(n!=1)
  {
    d=a[n];
    ct=0;
    while(n%d==0)
    {
      ct++;
      n/=d;
    }
    ans*=(ct+1);
  }
  return ans;
}
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll i=2,j;
  a[1]=1;
  while(i<=10000000)
  {
    if(a[i]==0)
    {
      j=i;
      while(j<=10000000)
      {
        a[j]=i;
        j+=i;
      }
    }
    i++;
  }
  ll n;
  cin>>n;
  i=1;
  ll ans=0;
  while(i<=n)
  {
    ans+=i*nod(i);
    //deb(ans)
    i++;
  }
  deb(ans)
}

Measured memory_bytes: 81732
function main()
    N = pread(Int)
    X = reverse(pread(String))
    pc = count(x -> x == '1', X)
    cp = parse(BigInt, reverse(X), base=2) % (pc + 1)

    ap = zeros(Int, N)
    am = zeros(Int, N)
    ap[1] = 1
    am[1] = 1

    for i in 2:N
        ap[i] = ap[i-1]<<1 % (pc+1)
    end
    cm = 0
    if (pc-1) != 0
        cm = parse(BigInt, reverse(X), base=2) % (pc - 1)
        for i in 2:N
            am[i] = am[i-1] << 1 % (pc-1)
        end
    end
    ans = zeros(Int,N)
    for i in 1:N
        c = (X[i]=='1' ? cm : cp)
        ppm = (pc + (X[i]=='1' ? -1 : 1))
        ppm == 0 && continue
        tmp = (ppm + c + (X[i]=='1' ? -am[i] : ap[i])) % ppm
        cc = 1
        while tmp != 0
            tmp = tmp % count_ones(tmp)
            cc += 1
        end
        ans[i] = cc
    end
    for i in N:-1:1
        println(ans[i])
    end
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


Measured memory_bytes: 326164
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
int main()
{
    fast;
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    ll dp1[n],dp2[n],dp3[n];
    f(i,n)
       cin>>a[i]>>b[i]>>c[i];
    dp1[0]=a[0];
    dp2[0]=b[0];
    dp3[0]=c[0];
    for(ll i=1;i<n;i++)
    {
        dp1[i]=max(dp2[i-1],dp3[i-1])+a[i];
        dp2[i]=max(dp1[i-1],dp3[i-1])+b[i];
        dp3[i]=max(dp2[i-1],dp1[i-1])+c[i];
    }
    ll ans;
    ans=max(dp1[n-1],max(dp2[n-1],dp3[n-1]));
    cout<<ans; 
    return 0;
}

Measured memory_bytes: 4992
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define SCIN(x) string x;cin>>x;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end());

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    CIN(n);
    ll k;cin>>k;
    map<int,ll> m;
    V a(n);V b(n);

    REP(i,n)cin>>a[i]>>b[i];
    REP(i,n)m[a[i]]+=b[i];

    FOREACH(x,m){
        k-=x.second;
        if(k<=0){COUT(x.first);return 0;}
    }

    return 0;
}


Measured memory_bytes: 4992
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-05-02 20:45:04
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  int64 x; cin >> x;

  int64 cur = 100;

  for (int i = 1; i <= 4000; ++i) {
    cur = (int64)((long double)(cur) * 1.01);
    if (cur >= x) {
      cout << i << endl; return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3648
import math 

def isPrime(n):
    if n<=1:
        return False
    for i in range(2,int(math.sqrt(n)+1)):
        if (n%i == 0):
            return False
    return True

def countPrime(x):
    count = 0
    for e in x:
        if isPrime(e) is True:
            count += 1
    return count
    
n = int(input())
x = []
for i in range(n):
    x.append(int(input()))
print(countPrime(x))


Measured memory_bytes: 6004
#include <stdio.h>

int main(){
    int i, j, k, n, m, l, a[100][100], b[100][100];
    long int s;
    
    scanf("%d %d %d", &n, &m, &l);
    
    for (i=0; i<n; i++) {
        for (j=0; j<m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    
    for (i=0; i<m; i++) {
        for (j=0; j<l; j++) {
            scanf("%d", &b[i][j]);
        }
    }
    
    for (i=0; i<n; i++) {
        for (j=0; j<l; j++) {
            s = 0;
            for (k=0; k<m; k++) {
                s += a[i][k] * b[k][j] ;
            }
            printf("%ld", s);
            
            if (j+1 == l) {
                printf("\n");
            }else {
                printf(" ");
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 2100
//
// Created by yamunaku on 2019/09/07.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    vi b(n-1);
    rep(i,n-1) cin >> b[i];
    int ans=b[0]+b[n-2];
    rep(i,n-2){
        ans+=min(b[i],b[i+1]);
    }
    cout << ans << endl;
    return 0;
}


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

#define LEN 100005

typedef struct pp{
	string name;
	int t;
}P;

P Q[LEN+1];
int head,tail,n;

void enque(P x)
{
	Q[tail] = x;

	if (tail + 1 == LEN)
		tail = 0;
	else
		tail++;
}

P deque()
{
	P x = Q[head];

	if (head + 1 == LEN)
		head = 0;
	else	
		head++;

	return x;
}

int min(int a,int b) {return a < b ? a : b;}

int main()
{
	int q;
	int elaps = 0,c;
	cin >> n >> q;
	P u;


	for (int i = 0; i < n; i++) {
		cin >> Q[i].name >> Q[i].t;
		enque(Q[i]);
	}

	while (head != tail) {
		u = deque();
		c = min(q,u.t);
		u.t -= c;
		elaps += c;

		if (u.t > 0)
			enque(u);
		else 
			cout << u.name << ' ' << elaps << '\n';

	}
	
	return 0;
}


Measured memory_bytes: 7076
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;
typedef pair<string, string> pss;

int main()
{
	int a[3];
	rep(i, 3)cin >> a[i];
	sort(a, a + 3);
	if (a[0] == a[1])
		cout << a[2] << endl;
	else if (a[1] == a[2])
		cout << a[0] << endl;

 	return 0;
}

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

int main() {
    int N;
    cin >> N;

    for (int i = 0; i <= N;i++) {
        if(int(i*1.08)==N){
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val s = br.readLine()!!
    val t = br.readLine()!!
    for (i in s.indices) {
        val prefix = s.substring(i until s.length)
        if (t.startsWith(prefix)) {
            out.println(n + i)
            return
        }
    }

    out.println(s.length + t.length)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 35984
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define __ ios_base::sync_with_stdio(false); cin.tie(NULL);


int main() {
//    __

    ll n , i , ans = 0 ;
    string s , t ;
    cin>> s >> t ;
    n = s.size() ;
    for (i = 0;i< n; i++) ans+= (s[i]!=t[i]) ;
    cout << ans << endl ;


    return 0 ;
}





Measured memory_bytes: 3916
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        long[] x = new long[N];
        long[] y = new long[N];
        long[] z = new long[N];
        for (int i=0;i<N;i++) {
            x[i] = Long.parseLong(sc.next());
            y[i] = Long.parseLong(sc.next());
            z[i] = Long.parseLong(sc.next());
        }
        ArrayList<int[]> flag = new ArrayList<int[]>();
        for (int i=0;i<1<<3;i++) {
            int x_flag = (int)Math.pow(-1, (i>>2)&1);
            int y_flag = (int)Math.pow(-1, (i>>1)&1);
            int z_flag = (int)Math.pow(-1, (i>>0)&1);
            int[] add = {x_flag, y_flag, z_flag};
            flag.add(add);
        }

        Comparator<Long> comparator = new Comparator<Long>() {
            @Override
            public int compare(Long o1, Long o2) {
                return Long.compare(o2, o1);
            }
        };

        long ans = 0L;
        for (int j=0;j<1<<3;j++) {
            Long[] value = new Long[N];
            for (int i=0;i<N;i++) {
                value[i] = x[i]*flag.get(j)[0]+y[i]*flag.get(j)[1]+z[i]*flag.get(j)[2];
            }
            Arrays.sort(value, comparator);
            long tmp_ans = 0L;
            for (int i=0;i<M;i++) {
                tmp_ans += value[i];
            }
            ans = Math.max(ans, tmp_ans);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 26452
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  String po=sc.next();
  String s=sc.next();
  boolean b=false;
  for(char c='a';c<='z';c++){
  if((po+c).equals(s)){
  b=true;
  }
  }
  System.out.println(b?"Yes":"No");
}
}

Measured memory_bytes: 38864
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000099;
const int OO = 0x3f3f3f3f;

int n, h[MAX];
int dp[MAX];

int solve(int x)
{
	if(x == n - 1) return 0;
	if(x > n) return OO;
	if(dp[x] != -1) return dp[x];
	return dp[x] = min(solve(x + 1) + abs(h[x] - h[x + 1]), solve(x + 2) + abs(h[x] - h[x + 2]));
}

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> h[i];
	memset(dp, -1, sizeof(dp));	
	cout << solve(0) << '\n';

	return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define LL long long int
using namespace std;

const int N = 3e3 + 5;
const int oo = 1e9 + 5;
const int MOD = 998244353;

int dp[N][N];

LL powermod(LL a, LL b) {
    if (b == 0) return 1;
    LL res = powermod(a, b/2);
    res = (res * res)%MOD;
    if (b & 1) res = (res * a)%MOD;
    return res;
}

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i=0;i<=c;++i) for (int j=0;j<=d;++j) dp[i][j] = 0;

    for (int i=a;i<=c;++i) dp[i][b] = powermod(b, i - a);
    for (int j=b;j<=d;++j) {
        dp[a][j] = powermod(a, j - b);
    }
    dp[a][b] = 1;

    for (int i=a+1;i<=c;++i) for (int j=b+1;j<=d;++j) {
        // dp[i][j] = (dp[i-1][j] * 1LL * j)%MOD;
        // for (int k=2;k <= j;++k) {
        //     dp[i][j] += ((dp[i-1][k-1] * 1LL * (k-1))%MOD * 1LL * powermod(i, j-k))%MOD;
        //     if (dp[i][j] >= MOD) dp[i][j] -= MOD;
        // }
        dp[i][j] = 0;
        dp[i][j] += (i * 1LL * dp[i][j-1])%MOD; dp[i][j] %= MOD;
        dp[i][j] += (dp[i-1][j] * 1LL * j)%MOD; dp[i][j] %= MOD;
        dp[i][j] -= (i * 1LL * (dp[i-1][j-1] * 1LL * (j - 1))%MOD)%MOD; dp[i][j] %= MOD;
        dp[i][j] += (dp[i-1][j-1] * 1LL * (j - 1))%MOD;
        dp[i][j] %= MOD;
        if (dp[i][j] < 0) dp[i][j] += MOD;
    }
    cout << dp[c][d] << '\n';
} 

int main() {
    FASTIO;
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 38836
n=int(input())
primelist=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
ll=[0,0,0,0,0]
for i in range(len(primelist)):
  a=primelist[i]
  t=n
  po=0
  while(t>0):
    t=int(t/a)
    po+=t
  if(po>=74):
    ll[4]+=1
  if(po>=24):
    ll[3]+=1
  if(po>=14):
    ll[2]+=1
  if(po>=4):
    ll[1]+=1
  if(po>=2):
    ll[0]+=1
ans=ll[4]+(ll[3])*(ll[0]-1)+(ll[2])*(ll[1]-1)+(ll[1])*(ll[1]-1)*(ll[0]-2)/2
print(int(ans))
    

Measured memory_bytes: 3064
#include<stdio.h>
int bubble_sort(int array[],int size){
  int count=0,tmp,i,j;
  for(i=0;i<size;i++){
    for(j=size-1;j>i;j--){
      if(array[j]<array[j-1]){
        tmp=array[j];
        array[j]=array[j-1];
        array[j-1]=tmp;
        count++;
      }
    }
  }
  return count;
}

int main(void){
  int i,size,array[100000],count;
  scanf("%d",&size);
  for(i=0;i<size;i++){
    scanf("%d",&array[i]);
  }
  count = bubble_sort(array,size);
  for(i=0;i<size;i++){
    if(i>0) printf(" ");
    printf("%d",array[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);

    int a,p;
    cin >> a >> p;

    cout << (a*3+p)/2 << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

bool sosu(int n)
{
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)return false;
	}
	return true;
}

int main(void)
{
	while(1)
	{
		int n;
		cin>>n;
		if(n==0)break;
		int ans;
		ans=0;
		int i,j;
		for(i=0,j=2;i<n;j++)
		{
			if(sosu(j))
			{
				ans+=j;
				i++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,top;
char s[200010],st[200010];
int main() {
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;i++) {
		if(!top) st[++top]=s[i];
		else {
			if(st[top]=='S'&&s[i]=='T') top--;
			else st[++top]=s[i];
		}
	}
	printf("%d\n",top);
}

Measured memory_bytes: 640
#include <stdio.h> 
int main(void)
{
	int a[11],b[11];
	int i;
		while(~scanf("%d",&a[i])){
		if(a[i]!=0){
			i++;
		}else if(a[i]==0){
			printf("%d\n",a[i-1]);
			i--;
	}
}
return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<(n); i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
signed main(void){
    int n;cin>>n;
    int A[n];rep(i,n)cin>>A[i];
    int ans=0;
    rep(i,n-1){
        int a=A[i];
        ans+=a/2;a%=2;
        if(a==1&&A[i+1]>0){ans++;A[i+1]--;}
    }
    ans+=A[n-1]/2;
    cout<<ans<<endl;
}

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

const int N = 123456 * 2 + 2;
int prime[N];
bool is_prime[N];

void eratos(int n) {
    int p = 0;
    for (int i=0; i<=n; ++i) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i=2; i<=n; ++i) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j=2*i; j<=n; j+=i) is_prime[j] = false;
        }
    }
}

int main() {
    eratos(N-1);

    int n;
    while (cin >> n and n) {
        int ans=0;
        for (int i=n+1; i<=2*n; ++i) {
            if (is_prime[i]) {
                ans++;
            }
        }
        cout << ans << endl;
    }

}

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

int main(){
    int a, b;
    string op;
    cin >> a >> op >> b;
    while(op!="?"){
        if(op=="+") cout << a+b<<endl;
        if(op=="-") cout << a-b<< endl;
        if(op=="*") cout << a*b<< endl;
        if(op=="/") cout << a/b<< endl;
        cin >> a >> op >> b;
    }
    return 0;
}


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

int main(int argc, char *argv[]){
     int n; float x, y, r;

     while(scanf("%d",&n), n!=-1){
	  n--;
	  x=1.0, y=0.0, r=atan2(-y,-x);
	  
	  while(n--){
	       r-=M_PI/2.0;
	       x+=cos(r), y+=sin(r);
	       
	       r=atan2(-y,-x);
	  }

	  printf("%.2f\n%.2f\n",x,y);
     }

     return 0;
}

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

typedef long long ll;
using namespace std;
int main()
{

  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max(max(a*c,a*d),max(b*c,b*d))<<endl;
  return 0;
}


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

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

Node root;

Node treeMinimum(Node x) {
  while(x -> left != NIL) {
    x = x -> left;
  }
  return x;
}

Node treeSearch(Node u, int k) {
  if(u == NIL || k == u -> key) {
    return u;
  }
  if(k < u -> key) {
    return treeSearch(u -> left, k);
  }
  else {
    return treeSearch(u -> right, k);
  }
}

Node treeSuccessor(Node x) {
  Node y;
  if(x -> right != NIL) {
    return treeMinimum(x -> right);
  }
  y = x -> parent;
  while(y != NIL && x == y -> right) {
    x = y;
    y = y -> parent;
  }
  return y;
}

void treeDelete(Node z) {
  Node y;
  Node x;
  
  if(z -> left == NIL || z -> right == NIL) {
    y = z;
  }
  else {
    y = treeSuccessor(z);
  }
  
  if(y -> left != NIL) {
    x = y -> left;
  }
  else {
    x = y -> right;
  }
  
  if(x != NIL) {
    x -> parent = y -> parent;
  }
  
  if(y -> parent == NIL) {
    root = x;
  }
  else if(y == y -> parent -> left) {
    y -> parent -> left = x;
  }
  else {
    y -> parent -> right = x;
  }
  
  if(y != z) {
    z -> key = y -> key;
  }
} 

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

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

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

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

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll INF = (1ll << 40);

int main() {
  ll N, M;
  cin >> N >> M;
  vi a(M), b(M), c(M);
  for (ll i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i] -= 1;
    b[i] -= 1;
  }
  vi dist(N, -INF);
  dist[0] = 0;
  vi v;
  for (ll i = 0; i <= 2 * N; i++) {
    for (ll j = 0; j < M; j++) {
      if (dist[a[j]] != -INF) {
        dist[b[j]] = max(dist[b[j]], dist[a[j]] + c[j]);
      }
    }
    v.push_back(dist[N - 1]);
  }

  if (v[v.size() - 1] == v[v.size() - 2]) {
    cout << v[v.size() - 1] << endl;
  } else {
    cout << "inf" << endl;
  }
}

Measured memory_bytes: 384
#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.at(i);
    }
    sort(A.begin(), A.end());
    
    int y = N % 2;
    bool can = true;
    if (y == 0){
        for (int i = 0; i < N; i += 2){
            if (A.at(i) != i + 1){
                can = false;
                break;
            }
            if (A.at(i + 1) != i + 1){
                can = false;
                break;
            }
        }
    }
    else{
        if (A.at(0) != 0) can = false;
        for (int i = 1; i < N; i += 2){
            if (A.at(i) != i + 1){
                can = false;
                break;
            }
            if (A.at(i + 1) != i + 1){
                can = false;
                break;
            }
        }
    }
    int64_t x = 1;
    
    for (int i = 0; i < N / 2; i++){
        x *= 2;
        x %= 1000000007;
    }
    if (can) cout << x << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int a[512][512];

int main() {
  for(int N; scanf("%d", &N), N; ) {
    memset( a, -1, sizeof(a) );
    
    a[256][256] = 0;

    const int dr[] = {0, 1, 0, -1};
    const int dc[] = {-1, 0, 1, 0};

    for(int i = 1; i < N; i++) {
      int v, dir; scanf("%d%d", &v, &dir);
      
      for(int r = 0; r < 512; r++)
        for(int c = 0; c < 512; c++) {
          if( a[r][c] == v ) {            
            a[r + dr[dir]][c + dc[dir]] = i;            
            goto BK;
          }
        }
    BK:;
    }
    
    
    int left = 512;
    int right = -1;
    int upper = 512;    
    int bottom = -1;

    for(int r = 0; r < 512; r++) {
      for(int c = 0; c < 512; c++) {
        if( a[r][c] != -1 ) {
          left = min(left, c);
          right = max(right, c);

          upper = min(upper, r);
          bottom = max(bottom, r);
        }
      }
    }
    
    cout << (right - left + 1) << " " << (bottom - upper + 1) << endl;
    
  }
  return 0;
}

Measured memory_bytes: 1916
from collections import Counter
N = int(input())
S = []
for i in range(N):
    s = input()
    if s[0] in ["M","A","R","C","H"]:
        S.append(s[0])
C = Counter(S).most_common()
lenC = len(C)
Ans = 0
for i in range(lenC):
    for j in range(i+1,lenC):
        for k in range(j+1,lenC):
            Ans += C[i][1]*C[j][1]*C[k][1]
print(Ans)


Measured memory_bytes: 4224
use std::cmp::max as max;
use std::cmp::min as min;

use itertools::Itertools;

fn build(buildings: &Vec<u64>, build_ups: &Vec<u64>) -> u64 {
    let mut highest = buildings[0] - 1;
    let mut costs = 0;

    for i in 0..buildings.len() {
        let cost = if build_ups.contains(&(i as u64)) {
            if highest + 1 < buildings[i] { 0 } else { highest + 1 - buildings[i] }
        } else {
            0
        };
        costs += cost;
        highest = max(highest, buildings[i] + cost);
    }
    costs
}

fn solve(buildings: Vec<u64>, n: usize, k: usize) -> u64 {
    let mut result = 9223372036854775807;

    for build_ups in (0..n as u64).combinations(k) {
        result = min(build(&buildings, &build_ups), result)
    }

    result
}

fn main() {
    let (n, k) = read_tup2();
    let buildings = read_vec();

    println!("{}", solve(buildings, n, k));
}

// utils

fn read_tup2<T: std::str::FromStr + Copy>() -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v = s.trim().split_whitespace()
        .map(|c| c.parse().ok().unwrap())
        .collect::<Vec<T>>();
    (v[0], v[1])
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|c| c.parse().ok().unwrap())
        .collect()
}


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

int main() {

	int a, b, c;

	int min, mid, max;

	cin >> a >> b >> c;

	if (a > b && a > c)
		max = a;
	else if (b > a && b > c)
		max = b;
	else if (c > a && c > b)
		max = c;

	if (a < b && a < c)
		min = a;
	else if (b < a && b < c)
		min = b;
	else if (c < a && c < b)
		min = c;

	if (min == a && max == b || min == b && max == a)
		mid = c;
	else if (min == b && max == c || min == c && max == b)
		mid = a;
	else if (min == a && max == c || min == c && max == a)
		mid = b;

	cout << min << " " << mid << " " << max << endl;

	return 0;
}


Measured memory_bytes: 3088
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
A, B = map(int, input().split())
count = 0
for i in range(B - A + 1):
    L = list(str(A + i))
    if L[0] == L[4] and L[1] == L[3]:
        count += 1
print(str(count))


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {

			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();

			int tmpA = a;
			a = b;
			b = tmpA;

			tmpA = a;
			a = c;
			c = tmpA;

			System.out.println(a + " " + b + " " + c);
		}
	}
}

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

#include <bits/stdc++.h>

using namespace std;

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

void d_err() {
    cerr << endl;
}

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

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

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

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

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

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

    string S;
    cin >> S;

    REP(i, S.size()) {
        if (S[i] - 'A' + N > 25) S[i] = 'A' + (S[i] - 'A' + (N - 26));
        else S[i] += N;
    }

    print(S);
}


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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x) cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x) cout << ((x) ? "YES" : "NO") << endl

int main(int argc, const char* argv[]) {
	string s;
	cin >> s;

	cout << (s[0] == '1' ? 1 : 0) + (s[1] == '1' ? 1 : 0) + (s[2] == '1' ? 1 : 0) << endl;

	return 0;
}


Measured memory_bytes: 256
from collections import Counter
from operator import mul
from functools import reduce
def main():
    def combinations_count(n, r):
        r = min(r, n - r)
        numer = reduce(mul, range(n, n - r, -1), 1)
        denom = reduce(mul, range(1, r + 1), 1)
        return numer // denom
    n = int(input())
    A = list(map(int, input().split()))
    B = [0, ]
    s = 0
    for i in range(n):
        s += A[i]
        B.append(s)
    C = Counter(B).most_common()
    ans = 0
    for c in C:
        if c[1] >= 2:
            ans += combinations_count(c[1], 2)
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 53560
#include<stdio.h>
int main(void){
  int p[3],i=0,max=0,cnt=0,sum=0;
  while(i<3){
    scanf("%d",&p[i]);
    if(max<p[i]){
      max=p[i];
      cnt=i;
    }
    i++;
  }
  while(i>=0){
    if(i!=cnt) sum+=p[i];
    i--;
  }
  if(sum==p[cnt]){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

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

int main() {
  long long a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a){
    cout<<k<<endl;
  }
  else if(k<=a+b){
    cout<<a<<endl;
  }
  else{
    cout<<a-(k-a-b)<<endl;
  }
  
}


Measured memory_bytes: 3620