akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int Mod=1000000007;
int n,m;
#define Maxn 100010
#define V 4000010
int f[Maxn];
int x[Maxn],y[Maxn];
struct P{
	int x,y;
	bool operator <(const P &z)const{return x!=z.x?x<z.x:y>z.y;;}
	bool operator ==(const P &z)const{return x==z.x&&y==z.y;}
}p[Maxn];int len=0;
struct Node{
	int sumv;
	int ls,rs;
}tree[V];
int root,cnt=0;
void insert(int &k,int l,int r,int pos,int x){
	if(!k)k=++cnt;
	tree[k].sumv+=x;
	if(tree[k].sumv>=Mod)tree[k].sumv-=Mod;
	if(l==r)return;
	int mid=(l+r)>>1;
	if(pos<=mid)insert(tree[k].ls,l,mid,pos,x);
	else insert(tree[k].rs,mid+1,r,pos,x);
}
int Query(int k,int l,int r,int L,int R){
	if(l==L&&r==R)return tree[k].sumv;
	int mid=(l+r)>>1;
	if(R<=mid)return Query(tree[k].ls,l,mid,L,R);
	else if(mid<L)return Query(tree[k].rs,mid+1,r,L,R);
	else{
		int ans=Query(tree[k].ls,l,mid,L,mid)+Query(tree[k].rs,mid+1,r,mid+1,R);
		if(ans>=Mod)ans-=Mod;
		return ans;
	}
}

inline void rd(int &x){
	x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
}

int main(){
	rd(n);rd(m);
	for(register int i=1;i<=n;++i)rd(x[i]);
	for(register int i=1;i<=m;++i)rd(y[i]);
	for(register int i=1;i<=n;++i)
	if(x[i]>y[1]&&x[i]<y[m]){
		int at=lower_bound(y+1,y+m+1,x[i])-y;
		if(y[at]==x[i])continue;
		len++;
		p[len]=(P){x[i]-y[at-1],y[at]-x[i]};
	}
	sort(p+1,p+len+1);
	len=unique(p+1,p+len+1)-p-1;
	int Ans=0;
	for(register int i=1,nex;i<=len;i=nex+1){
		nex=i;
		while(nex<len&&p[nex+1].x==p[i].x)nex++;
		for(register int j=i;j<=nex;++j){
			f[j]=Query(root,0,1e9,0,p[j].y-1)+1;
			if(f[j]>=Mod)f[j]-=Mod;
			Ans=Ans+f[j];
			if(Ans>=Mod)Ans-=Mod;
			insert(root,0,1e9,p[j].y,f[j]);
		}
	}
    printf("%d\n",(Ans+1)%Mod);
    return 0;
}

Measured memory_bytes: 19968
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define hoge cout << hoge << endl;
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,f,g,h,w;
ll x[1000005],y[1000005],z[1000005];
ll dp[8000][6000];
bool flag,dame;

int main(){
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	sort(x,x+n);
	ans = INF;
	for(i=0;i<n;i++){
		if(i+k-1>=n)continue;
		ans = min(ans,x[i+k-1]-x[i]);
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 28928
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {

        /// <summary>
        /// ABC 166
        /// B - Trick or Treat
        /// https://atcoder.jp/contests/abc166/tasks/abc166_b
        /// </summary>
        
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var num_NK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            var A = new int[num_NK[0]];

            for (int inumA = 0; inumA < num_NK[1]; inumA++)
            {
                var J = int.Parse(Console.ReadLine());

                var AI = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

                for(int inumB = 0; inumB < J; inumB++)
                {
                    var N = AI[inumB]-1;

                    A[N]++;

                }

            }

            int result = 0;

            foreach(int C in A)
            {
                if (C == 0) result++;
            }

            Console.WriteLine(result);


            Console.Out.Flush();
        }
    }
}


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

int main(){
 int N;
 //int i;
 long long int ans=1,i;
 cin>>N;
 
 for(i=1;i<=N;i++){
 //	if(ans*i>1000000000){
		ans=(ans*i)%1000000007;
//	}else{
//		ans=ans*i;
//	}
	//cout<<ans<<" ";
	//if(ans==0)break;
 }
 cout<<ans%1000000007<<endl;
}

Measured memory_bytes: 256
// fahadmd16(IIEST Shibpur)
#include<bits/stdc++.h>
using namespace std;

#define ll                                      long long
#define pb                                      push_back
#define pf                                      push_front
#define eb                                      emplace_back
#define mp                                      make_pair
#define ff                                      first
#define ss                                      second
#define db                                      double
#define pll                                     pair<ll, ll>
#define ALL(a)                                  (a).begin(),(a).end()
#define endl                                    "\n"

#define forn(i, n) for (ll i = 0; i < n; i++)
#define forn1(i, n) for (ll i = 1; i < n; i++)
#define ford(i, n) for (ll i = n - 1; i >= 0; i--)
#define ford1(i, n) for (ll i = n - 1; i >= 1; i--)
#define forab(i, a, b) for(ll i = a; i < b; i++)
#define forabd(i, a, b) for(ll i = a; i >= b; i--)
#define eps 1e-10

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)


#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define tracen( x , n ){ cout<<(#x)<<":";for(int i=0;i<n;i++)cout<<(#x)<<"["<<i<<"]:"<< x[i] << "    "; cout<<endl;}
#define tracenm( x , n , m ){ cout<<(#x)<<endl;for(int i=0;i<n;i++){ cout<<"Row #"<<i<<":"; for(int j=0;j<m;j++) cout<<x[i][j]<<"     "; cout << endl;}}
#define trace(v){ cout<<#v<<": ";for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;}
using namespace std;



const ll sz = 8000;
const ll mod = 1e9 + 7;
const db PI = acos(-1);



typedef vector<ll> VL;
typedef vector<pll > VLL;
typedef vector<vector<ll> > VVL;



ll power(ll n, ll k, ll m) {
	ll ans = 1;
	while (k) {
		if (k & 1)ans = (ans * n) % m;
		k /= 2;
		n = (n * n) % m;
	}
	return ans;
}

void solver() {
	ll a, b, c, k; cin >> a >> b >> c >> k;
	ll ans = 0;
	if (a >= k) {ans += k; k = 0;}
	else {ans += a; k -= a;}
	// trace1(ans);
	k -= b;
	if (k > 0) {
		ans -= k;
	}
	cout << ans << endl;
}


int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	IOS;
	ll T = 1; //cin >> T;
	forn1(i, T + 1) {
		clock_t z = clock();
		solver();
		debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	}
	return 0;
}


Measured memory_bytes: 3688
package main

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

func main() {

	K := nextInt()
	arr := []int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}

	fmt.Println(arr[K-1])
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 640
/*JOI 君はすごろくを持っている．このすごろくは 2019 個のマスが横一列に並んだ形をしている．これらのマスには，左端のスタートマスから右端のゴールマスへと順に 1 から 2019 までの番号がついている．

   現在このすごろくの上には，N 個の駒が置かれている．これらの駒には，スタートに近い順に 1 から N までの番号がついている．駒 i (1≦i≦N) は，マス Xi に置かれている．すべての駒は異なるマスに置かれている．

   JOI 君はこれから M 回の操作を行う．j 回目 (1≦j≦M) の操作では，駒 Aj を 1 マス先へ進める．ただし，移動元のマスがゴールマスであった場合，もしくは移動先のマスに別の駒が置かれている場合，駒 Aj は進まず，位置は変わらない．

   すべての操作が終了した時点で，各駒が置かれているマスを求めよ．*/
#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {

        int N;
        cin >> N;
        int X[102];
        for(int i=1; i<=N; i++) {
                cin >> X[i];
        }
        X[N+1] = 2020;

        int M;
        cin >> M;

        for(int j=0; j<M; j++) {
                int A;
                cin >> A;

                if(X[A]==2019 || X[A+1]==X[A]+1)
                        continue;

                X[A]++;
        }

        for(int i=1; i<=N; i++) {
                cout << X[i] << endl;
        }

        return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define PI 3.141592653589793
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    while(true){
        int n; cin >> n;
        if(n == 0) break;
        vector<int> s(n);
        forn(i, n) cin >> s[i];

        // 平均点を求める
        ld avg = accumulate(all(s), 0.0) / n;

        // 分散α2を求める
        ld a2 = 0;
        forn(i, n) a2 += pow(s[i] - avg, 2);
        a2 /= n;

        // 標準偏差αを求める
        ld a = sqrtl(a2);

        cout << setprecision(10) << a << endl;
    }
}


Measured memory_bytes: 3288
#include <stdio.h>


int main()
{
	int a, b, c, s;

	scanf("%d %d %d", &a, &b, &c);

	s = a + b + c;

	if (s <= 21)
	{
		printf("win\n");
	}
	else
	{
		printf("bust\n");
	}

	
	return 0l;
}


Measured memory_bytes: 128
s = input()

outp = ['0' for _ in range(len(s))]

cross_point = []
split_point = [-1]

cross_point_dict = {}

for i in range(len(s)-1):
    if(s[i] == 'R' and s[i+1] == 'L'):
        cross_point.append(i)
        cross_point_dict[i] = len(cross_point_dict)
    if(s[i] == 'L' and s[i+1] == 'R'):split_point.append(i)
split_point.append(len(s)-1)

set_cp = set(cross_point)
set_sp = set(split_point)
for i in range(len(s)):
    if(i not in set_cp):continue
    else:
        if(i in set_cp):
            idx = cross_point_dict[i]
            n1 = cross_point[idx] - split_point[idx]
            n2 = split_point[idx + 1] - cross_point[idx]
            outp[i] = str(n1 // 2 + n1 % 2 + n2 // 2)
            outp[i+1] = str(n1 // 2 + n2 // 2 + n2 % 2)
print(' '.join(outp))

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

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

    // 引数の受け取り
    //
    cin >> a >> b ;

    // 出力
    cout << (a=='H'?b=='H'?'H':'D':b=='H'?'D':'H') << endl;
    return 0;
}



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

using ll = long long; 
using P = pair<int,int>;

int main() {

  int N, M;
  cin >> N >> M;

  vector <int> A(N);
  rep(i, N) cin >> A.at(i);

  int total = 0;
  rep(i, N) total += A.at(i);
  
  int count = 0;
  rep(i, N){
    if (A.at(i)*4*M >= total){
      count++;
    }
  }

  if (count < M) {
   cout << "No" << endl;
  }
  else {
   cout << "Yes" << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll m=1e9+7;
int main()
{
	ll n;
	cin>>n;
	ll a[n],res=0;
	for(int i=0;i<n;i++) cin>>a[i];
	ll r[n];
	r[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--) r[i]=(a[i]+r[i+1])%m;
	for(int i=0;i<n-1;i++) res=(res+(a[i]*r[i+1])%m)%m;
	cout<<res;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0'; 
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
    bitset<3> bi(tmp);
    int sum = a;
    char op1, op2, op3;
    if(bi.test(0)) {
      op1 = '+';
      sum+= b;
    }else {
      op1 = '-';
      sum-= b;
    }
    if(bi.test(1)) {
      op2 = '+';
      sum+= c;
    }else {
      op2 = '-';
      sum-= c;
    }
    if(bi.test(2)) {
      op3 = '+';
      sum+= d;
    }else {
      op3 = '-';
      sum-= d;
    }
    if(sum == 7) {
      printf("%d%c%d%c%d%c%d=7", a, op1, b, op2, c, op3, d);
      break;
    }
  }
}

Measured memory_bytes: 3688
n, k = map(int, input().split())

mod = 10 ** 9 + 7
'''
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, n+1):
    fac.append(fac[-1] * i % mod)
    inv.append(-inv[mod%i] * (mod // i) % mod)
    finv.append(finv[-1] * inv[-1] % mod)
'''
fac = [1]
finv = [0]*(n+4)
for i in range(n+3):
    fac.append(fac[-1]*(i+1)%mod)

finv[-1] = pow(fac[-1],mod-2,mod)
for i in range(n+2,-1,-1):
    finv[i] = finv[i+1]*(i+1)%mod

ans = 0
for i in range(min(n-1, k) + 1):
    com1 = fac[n] * finv[i] * finv[n-i] % mod
    com2 = fac[n-1] * finv[i] * finv[n-i-1] % mod
    mul = com1 * com2 % mod
    ans = (ans + mul) % mod

print(ans)

Measured memory_bytes: 54128
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const ll INF=2e18;
const double PI=acos(-1);


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

    int n;
    cin >> n;
    vector<int> a(n);
    bool flag=1;
    rep(i,n) {
        cin >> a[i];
        if (a[i]>i+1) flag=0;
    }
    vector<int> ans(n);
    rep(i,n) {
        invrep(j,n-i) {
            if (a[j]==j+1) {
                ans[n-1-i]=a[j];
                a.erase(a.begin()+j);
                break;
            }
        }
    }
    if (flag) {
        rep(i,n) cout << ans[i] << endl;
    } else {
        cout << -1 << endl;
    }
    
    return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 200;
int x[N], y[N], n; ll h[N];
ll ok(int cx, int cy) {
	ll zh=1e15, ph=1e15;
	for (int i=0; i<n; ++i)
		if (h[i] == 0) {
			zh = min(zh, h[i] + abs(x[i] - cx) + abs(y[i] - cy));
		}
		else {
			ll hh = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
			if (ph != 1e15 && hh != ph) return -1;
			ph = hh;
		}
	if (ph > zh) return -1;
	if (zh < 1) return -1;
	return min(ph, zh);
}
int main() {
	cin >> n; for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> h[i];
	for (int cx = 0; cx <= 100; ++cx)
		for (int cy = 0; cy <= 100; ++cy)
			if (ok(cx, cy)!=-1) {
				cout << cx << " " << cy << " " << ok(cx, cy) << endl;
				exit(0);
			}
}

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

int main(){
  int N;
  cin >> N;
  int ans=1000000;
  int six[7]={1,6,36,216,1296,7776,46656};
  int nine[6]={1,9,81,729,6561,59049};
  for(int i=0;i<=N;i++){
    int n=i;
    int m=N-i;
    int count=0;
    int a=6;
    while(n){
      if(n>=six[a]&&a>=0){
        count++;
        n-=six[a];
      }else{
        a--;
      }
    }
    a=5;
    while(m){
      if(m>=nine[a]&&a>=0){
        count++;
        m-=nine[a];
      }else{
        a--;
      }
    }
    ans=min(count,ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
par=[-1]*n

def find(n):
    if par[n]<0:
        return n
    par[n]=find(par[n])
    return par[n]

def union(x,y):
    x,y=find(x),find(y)
    if x!=y:
        if x>y:
            x,y=y,x
        par[x]+=par[y]
        par[y]=x

for i in range(m):
    a,b=map(int,input().split())
    union(a-1,b-1)

print(-min(par))

Measured memory_bytes: 80192
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int batu=0;
    int l = s.length();
    REP(i,l){
        if(s[i]=='x'){
            batu++;
        }
    }
    if(batu>=8){
        cout << "NO\n";
    }else{
        cout << "YES\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	double m;
	double sd,sd2;
	int point[1000];
	int n,sum;
	while(1){
		sum = 0;
		sd2 = 0;
		cin >>n;
		if(n==0){break;}
		for(int i=0 ; i<n ;i++){
			cin >> point[i];
			sum +=point[i];
		}
		m = (double)sum/(double)n;
		for(int i=0; i<n ;i++){
			sd2 +=pow((point[i]-m),2); 
		}
		sd = sqrt((sd2)/(double)n);
	
	 printf("%.9f\n",sd);
	}
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
const int N=2*(1e5)+10;
struct Pr{
	ll in,out;
	Pr(){}
	Pr(ll x,ll y){in=x; out=y;}
};
int h[N],ch[N][2],dis[N][2];
ll rec[N];
vector<Pr> f[N];
int n,tot;
ll sum,Mx;
bool cmp1(Pr x,Pr y){return x.in<y.in;}
bool cmp2(Pr x,Pr y){return x.out<y.out;}
void merge(int x){
	int lch=ch[x][0],rch=ch[x][1];
	if (f[lch].size()>f[rch].size()) swap(lch,rch);
	int lsz=f[lch].size(),rsz=f[rch].size();

	sort(f[lch].begin(),f[lch].end(),cmp2);
	sort(f[rch].begin(),f[rch].end(),cmp1);
	rec[0]=f[rch][0].out;
	for (int i=1;i<rsz;++i) rec[i]=min(rec[i-1],f[rch][i].out);
	for (int i=0,j=rsz-1;i<lsz;++i){
		while (j>=0&&f[lch][i].out+f[rch][j].in>Mx) --j;
		if (j>=0) f[x].push_back(Pr(f[lch][i].in,rec[j]));
	}

	sort(f[lch].begin(),f[lch].end(),cmp1);
	sort(f[rch].begin(),f[rch].end(),cmp2);
	rec[0]=f[rch][0].in;
	for (int i=1;i<rsz;++i) rec[i]=min(rec[i-1],f[rch][i].in);
	for (int i=0,j=rsz-1;i<lsz;++i){
		while (j>=0&&f[rch][j].out+f[lch][i].in>Mx) --j;
		if (j>=0) f[x].push_back(Pr(rec[j],f[lch][i].out));
	}
}
void dfs(int x){
	int u,sz;
	f[x].clear();
	if (ch[x][0]==0&&ch[x][1]==0){
		f[x].push_back(Pr(0,0));
		return;
	}
	dfs(ch[x][0]);
	dfs(ch[x][1]);
	sz=f[ch[x][0]].size();
	for (int i=0;i<sz;++i) 
		f[ch[x][0]][i].in+=dis[x][0],f[ch[x][0]][i].out+=dis[x][0];
	sz=f[ch[x][1]].size();
	for (int i=0;i<sz;++i) 
		f[ch[x][1]][i].in+=dis[x][1],f[ch[x][1]][i].out+=dis[x][1];
	merge(x);
}
bool check(ll x){
	Mx=x;
	dfs(1);
	return f[1].size()>0;
}
void solve(){
	ll l=0,r=sum,mid,ans=0;
	while (l<=r){
		mid=l+r>>1;
		if (check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",ans);
}
int read(){
	int ret=0; char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while ('0'<=ch&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	//freopen("a.in","r",stdin);
#endif
	int x,y;
	n=read();
	memset(h,-1,sizeof(h));
	tot=0; sum=0;
	for (int i=1;i<n;++i){
		x=read(); y=read();
		if (ch[x][0]) ch[x][1]=i+1,dis[x][1]=y;
		else ch[x][0]=i+1,dis[x][0]=y;
		sum+=y;
	}
	solve();
}

Measured memory_bytes: 29944
A = input()
B = input()
C = input()
D = input()
E = input()
L = [A,B,C,D,E]
#L_s = str(L)
m=9
for i in L:
    if(i[-1]!="0"):
        m=min(m,int(i[-1]))

ans=0
flag=1
for i in L:
    if(i[-1]==str(m) and flag):
        ans+=int(i)
        flag=0
        #print(i)
    else:
        ans+=int(i)
        if(i[-1]!="0"):
            ans+=10-int(i[-1])
print(ans)

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

const long long mod =998244353 ;
const int N = 3e3+5;


#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define fr(i,l,m) for(int i=l;i<m;i++)
# define vii vector<int>
#define vpr vector<pair<ll,ll> >
double arr[N],dp[N][N];

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

int n;
cin>>n;
double ans=0.0;
fr(i,1,n+1)
{
    cin>>arr[i];
}
dp[0][0]=1;
fr(i,1,n)
{
    dp[0][i]=(dp[0][i-1]*(double)(1-arr[i]));
}
fr(i,1,n+1)
{
    fr(j,i,n+1)
    {
         //cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
        dp[i][j]+=((double)dp[i-1][j-1]*arr[j]);
       // cout<<dp[i][j]<<endl;
        dp[i][j]+=((double)dp[i][j-1]*double(1-arr[j]));
       // cout<<dp[i][j]<<endl;
       if(j==n){if(i>=(j/2+1)){ans+=(double)dp[i][j];}}
    }
}

cout<<setprecision(15)<<fixed<<ans<<endl;


return 0;
}
ll pwr(ll x,ll y)
{
    ll ans=1;
    x=x%mod;
    while(y>0){
    if(y&1)ans=(x*(ans%mod))%mod;
    x=(x*x)%mod;
    y=y/2;
    }
    return ans%mod;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */


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

	int N; cin >> N;
	vector<LL> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	LL ans = 0LL;
	FOR(_, 0, 128) {
		bool ok = 1;
		FOR(i, 0, N) {
			if (a[i] && a[i] % 2 == 0) {
				a[i] /= 2;
			}
			else {
				ok = 0;
			}

		}
		ans += ok;
	}
	
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007LL
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N;
int A[4];
ld dp[305][305][305];

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N;
    rep(i, N) {
        int t; cin >> t; A[t]++;
    }

    rep(k, N+1) rep(j, N+1) rep(i, N+1) {
        if (i+j+k == 0) continue;
        if (i+j+k > N) continue;
        ld &a = dp[i][j][k];
        a = 1;
        if (i > 0) a += dp[i-1][j][k]  *i/N;
        if (j > 0) a += dp[i+1][j-1][k]*j/N;
        if (k > 0) a += dp[i][j+1][k-1]*k/N;
        
        a /= (ld)(i+j+k)/N;
        debug(i, j, k, dp[i][j][k]);
    }

    cout << fixed << setprecision(15) << dp[A[1]][A[2]][A[3]] << endl;
}

Measured memory_bytes: 436480
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
    int n; cin >> n;
    vector<char> s(n);
    rep(i,n) cin >> s[i];
    int p=0,w=0,g=0,y=0;
    rep(i,n){
        if(s[i] == 'P') p++;
        if(s[i] == 'W') w++;
        if(s[i] == 'G') g++;
        if(s[i] == 'Y') y++;
        }
        if(p==0||w==0||g==0||y==0){
            cout << "Three" << endl;
        }else{
            cout << "Four" << endl;
        }
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n, count = 0, output;
  string s;
  cin >> n >> s;
  for (int i = 1; i < n; i++) {
    if (s[i] == 'E') {
      count++;
    }
  }
  output = count;
  for (int i = 1; i < n; i++) {
    count = count + (s[i - 1] == 'W' ? 1 : 0) + (s[i] == 'E' ? -1 : 0);
    output = min(output, count);
  }
  cout << output << endl;
  return 0;
}


Measured memory_bytes: 832
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    int x,y;
    cin>>x>>y;
    for(int a=0;a<=100;a++){
        for(int b=0;b<=100;b++){
            if(x==a+b&y==2*a+4*b){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3584
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
*/
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)
 
#define pb              push_back
#define mp              make_pair
 
#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))

#define ff              first
#define ss              second
 
#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)
 
#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())
 
#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )
#define RFOR(i,e,s)     for( LL i = e ; i>=s ; i-- )
         
 
#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("out.txt","w",stdout)
 
#define DEBUG(x)        cerr<<#x<<" = "<<x<<endl
#define PRINTALL(v)     {cerr<<endl<<"Printing: "<<#v<<endl;for(LL i = 0 ; i<v.size(); i++) DEBUG(v[i]); cerr<<endl;}
 
using namespace std;

LL f[100];

int main(){
   
   FOR(i,1,99){
       LL j = 1;
       while( ((j+2)*(j+1))/2 <= i ) j++;
       f[i] = j;
   }

   LL N;
   SL(N);
   //DEBUG(N);
   LL ans = 0;
   for( LL i = 2 ; i*i<=N ; i++ ){
       if(N%i) continue;
       LL r = 0;
       while( N % i == 0){
           r++;
           N = N / i;
           //DEBUG(N);
       }
      /* DEBUG(i);
       DEBUG(r);
       DEBUG(f[r]);*/
       ans += f[r];
   }    
   if(N>1) ans++;
   cout<<ans<<endl;

return 0;}

Measured memory_bytes: 3768
#include<stdio.h>
n,a,b,c,d,m;int main(){
	for(;scanf("%d",&n)!=EOF;m=0){
		for(a=0;a<=9 && a<=n;a++){
			for(b=0;b<=9 && b<=n;b++){
				for(c=0;c<=9 && c<=n;c++){
					for(d=0;d<=9 && d<=n;d++)if(a+b+c+d==n)m++;
				}
			}
		}
		printf("%d\n",m);
	}
	return 0;
}

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define v(d_type) vector<d_type>
#define loop(i, s, n) for(int i = s; i < n; i++)
#define print_vec(X) loop(i, 0, X.size()) cout << X[i] << "\n"
#define nl "\n"
#define fat 1000000007

int main()
{
    boost;
    int a, b;
    cin >> a >> b;

    if(b == 1) cout << "0" << nl;

    else if(a >= b)
        cout << "1" << nl;
    else
    {
        b = b - a;
        int sockets = b / (a - 1);
        if(b%(a - 1) != 0) sockets++;
        sockets++;
        cout << sockets << nl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main
{
	public static void main (String[] args) throws Exception
	{
		BufferedReader stdReader =
		new BufferedReader(new InputStreamReader(System.in));
		String natural[] = stdReader.readLine().split(" ",0);
		int x = Integer.parseInt(natural[0]);
		int y = Integer.parseInt(natural[1]);
		if (x < y) {
			x = x^y;
			y = x^y;
			x = x^y;
		}
		System.out.println(gcd(x, y));
	}
	private static int gcd(int x, int y) {
		return y == 0? x: gcd(y, x % y);
	}
}

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

const int MAX_N = 200005;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
} comb(MAX_N);

vector<int> to[MAX_N];

struct DP {
    mint dp;
    int t;
    DP(mint dp=1, int t=0):dp(dp),t(t) {}
    DP& operator+=(const DP& a) {
        dp *= a.dp;
        dp *= comb(t+a.t, t);
        t += a.t;
        return *this;
    }
    DP operator-(const DP& a) const {
        DP res(*this);
        res.t -= a.t;
        res.dp /= comb(res.t+a.t, res.t);
        res.dp /= a.dp;
        return res;
    }
    DP addRoot() const {
        DP res(*this);
        res.t++;
        return res;
    }
};

DP dp[MAX_N];

void dfs(int v, int p=-1) {
    for (int u : to[v]) {
        if (u == p) continue;
        dfs(u,v);
        dp[v] += dp[u].addRoot();
    }
}
void bfs(int v, int p=-1) {
    for (int u : to[v]) {
        if (u == p) continue;
        DP d = dp[v] - dp[u].addRoot();
        dp[u] += d.addRoot();
        bfs(u,v);
    }
}

int main() {
    int n;
    cin >> n;
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    dfs(0);
    bfs(0);
    rep(i,n) {
        cout << dp[i].dp << endl;
    }
    return 0;
}


Measured memory_bytes: 20224
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


#define VACANT 0
#define MALE   1
#define FEMALE 2


int N;


int get(int x)
{
  std::cout << x << std::endl; std::cout.flush();

  std::string s;

  std::cin >> s;

  return s == "Male" ? MALE : s == "Female" ? FEMALE : VACANT;
}

void update(std::vector<int>& a, int x, int y)
{
  if (y == MALE) {
    a[x] = 0;

    a[(x + 1)     % N] &= ~1;
    a[(x - 1 + N) % N] &= ~1;
  }
  else {
    a[x] = 0;

    a[(x + 1)     % N] &= ~2;
    a[(x - 1 + N) % N] &= ~2;
  }
}


class node_t {
public:
  node_t(int vv, int aa, int bb) : v(vv), a(aa), b(bb) {};

public:
  bool operator<(const node_t& x) const {
    if (v != x.v)
      return v < x.v;

    if (b - a != x.b - x.a)
      return b - a > x.b - x.a;

    if (a != x.a)
      return a > x.a;

    return b > x.b;
  };
    
public:
  int v;
  int l;
  int a;
  int b;
};

void push(const std::vector<int>& a, std::priority_queue<node_t>& pq, int l, int r, bool init = true)
{
  bool has_vacant = false;

  int d = r - l;

  if (d < 0)
    return;
    
  if (d % 2 == 0) {
    has_vacant = a[l] != a[r];
  }
  else {
    has_vacant = a[l] == a[r];
  }
    
  has_vacant = init ? has_vacant : true;

  pq.emplace(has_vacant, l, r);
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  std::cin >> N;

  std::vector<int> a(N, 3);

  std::set<int> set;

  for (int i = 0; i < N; i ++)
    set.insert(i);

  int x, y = get(x = 0);

  if (y == VACANT)
    return 0;

  update(a, x, y);

  y = get(x = N / 2);
    
  if (y == VACANT)
    return 0;
  
  update(a, x, y);

  std::priority_queue<node_t> pq;
    
  push(a, pq, 1, x - 1,        true);
  push(a, pq,    x + 1, N - 1, true);

  for (int i = 2; i < 22; i ++) {
    node_t node = pq.top(); pq.pop();

    y = get(x = (node.a + node.b) / 2);

    if (y == VACANT)
      break;

    update(a, x, y);

    push(a, pq, node.a, x - 1);
    push(a, pq,         x + 1, node.b);
  }

  return 0;
}


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

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

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

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

int main()
{
    ll N, X;
    cin >> N >> X;
    vec A(N);
    REP(i,0,N) cin >> A[i];

    ASC(A);
    ll sum = 0;
    REP(i,0,N) sum += A[i];
    
    if(X == sum) PR(N);
    else if(X > sum) PR(N-1);
    else {
        ASC(A);
        ll cnt = 0;
        REP(i,0,N) {
            X -= A[i];
            if(X < 0) break;
            ++cnt;
        }
        PR(cnt);
    }

    return 0;
}

/*

X = S -> N
X > S -> N-1
X < S -> 

*/

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll h, w, a;
  in2(h, w);
  vector<vector<char>> c(h + 2, vector<char> (w + 2, '?'));
  rep(i, h){
    rep(j, w)
      in(c[i + 1][j + 1]);
  }
  vector<vector<ll>> d(h + 2, vector<ll> (w + 2, 99999));
  d[1][1] = 0;
  rep(l, 500){
    rep2(i, 1, h + 1){
      rep2(j, 1, w + 1){
        if(c[i][j] == c[i - 1][j])
          d[i][j] = min(d[i][j], d[i - 1][j]);
        else
          d[i][j] = min(d[i][j], d[i - 1][j] + 1);
        if(c[i][j] == c[i][j - 1])
          d[i][j] = min(d[i][j], d[i][j - 1]);
        else
          d[i][j] = min(d[i][j], d[i][j - 1] + 1);
      }
    }
  }
  a = 0;
  if(c[1][1] == '#')
    a++;
  if(c[h][w] == '#')
    a++;
  a = a + d[h][w];
  out(a / 2);
  memi;
}

Measured memory_bytes: 384
import sys
# from collections import Counter, deque
# from collections import defaultdict
# from itertools import combinations, permutations, accumulate, groupby, product
# from bisect import bisect_left,bisect_right
# from heapq import heapify, heappop, heappush
# from math import floor, ceil,pi,factorial
# from operator import itemgetter
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9 + 7

a = int(input())
print(a+a*a+a*a*a)


Measured memory_bytes: 9132
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]

total = 0
for i in range(n):
    if b[i] <= a[i]:
        total += b[i]
        a[i] -= b[i]
    elif a[i] < b[i] <= a[i] + a[i+1]:
        total += b[i]
        a[i+1] -= b[i] - a[i]
        a[i] = 0
    else:
        total += a[i] + a[i+1]
        a[i] = 0
        a[i+1] = 0

print(total)

Measured memory_bytes: 19004
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

    vector<ll> dp(n);

    // init
    dp[0] = 0;

    for (int i = 1; i < n; ++i) {
        ll temp_min = 1 << 30;
        for (int ki = 1; ki <= k; ki++) {
            if (i-ki < 0) {
                break;
            }
            ll temp_score = dp[i-ki] + abs(h[i]-h[i-ki]);
            if (temp_score < temp_min) {
                temp_min = temp_score;
            }
        }    
        dp[i] = temp_min;
        // cout << "i:min, " << i << ":" << temp_min << endl;
    }

    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n,k;
  cin >> n>>k;
  ll num = 1;
rep(i,n){
  if(num*2>=num+k){
    num += k;
  }
  else{
    num *= 2;
  }
}
print(num);
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int m,n;
    cin>>m>>n;
    for(int i=n/m+1;i>0;i--){
        if(n%i==0){
            int cnt=n/i;
            if(cnt>=m){
                cout<<i<<endl;
                return 0;
            }

        }
    }
    cout<<"-1"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] arr = new int[3];
		for (int i = 0; i < 3; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int count = arr[2] - arr[1];
		arr[0] += count;
		count += (arr[2] - arr[0]) / 2;
		if ((arr[2] - arr[0]) % 2 == 1) {
		    count += 2;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
const int mu=1000000007,N=200005;
int n,A,B,c[N],w[N],a[N],p[N],inv[N],Min,cnt,c2[N],ans,Min2;
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*1ll*x%mu)
		if (y&1) ans=ans*1ll*x%mu;
	return ans;
}
int C(int x,int y){
	return p[x]*1ll*inv[x-y]%mu*inv[y]%mu;
}
int main(){
	scanf("%d%d%d",&n,&A,&B);
	memset(a,0x3f,sizeof(a));
	for (int i=1;i<=n;i++){
		scanf("%d%d",&c[i],&w[i]);
		a[c[i]]=std::min(a[c[i]],w[i]);
	}
	Min=Min2=0;
	for (int i=1;i<=n;i++){
		if (w[i]+a[c[i]]<=A) w[i]=a[c[i]];
		if (a[i]<a[Min]){
			Min2=Min;
			Min=i;
		}else{
			if (a[i]<a[Min2]) Min2=i;
		}
	}
	p[0]=1;
	for (int i=1;i<=n;i++) p[i]=p[i-1]*1ll*i%mu;
	inv[n]=ksm(p[n],mu-2);
	for (int i=n;i>=1;i--) inv[i-1]=inv[i]*1ll*i%mu;
	for (int i=1;i<=n;i++)
		if ((w[i]+a[Min2]<=B)||(c[i]!=Min && a[Min]+w[i]<=B)){
			cnt++;
			c2[c[i]]++;
		}
	ans=1;
	ans=p[cnt];
	for (int i=1;i<=n;i++)
		ans=ans*1ll*inv[c2[i]]%mu;	
	printf("%d\n",ans); 
}

Measured memory_bytes: 4992
#coding: utf-8

while True:
    n, x = map(int, input().split())
    pattern = list()
    if n + x == 0:
        break
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i == j:
                continue
            k = x - i - j
            if k == i or k == j:
                continue
            if k < 1 or n < k:
                continue
            temp = sorted([i, j, k])
            if temp not in pattern:
                pattern.append(temp)
    #print(pattern)
    print(len(pattern))


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

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <stdlib.h>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <float.h>
using namespace std;

int n;
int k;


int main()
{
	long long ans = 0;
 
	cin >> n >> k;

	if( k == 0 ) {
		ans = (long long)n * n;
	}
	else {
		for( int b = k + 1; b <= n; b++ ) {
			ans += (long long)(n + 1) / b * (b - k);
			ans += max( 0, ((n + 1) % b) - k );
		}
	}

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


Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let a = arr(n, |_| scan.read::<usize>()-1);
    let mut b = inverse(&a, n);
    for i in 0..b.len() {
        b[i] += 1;
    }
    println!("{}", join(&b, " "));
}

#[allow(dead_code)]
fn inverse(a: &[usize], n: usize) -> Vec<usize> {
    let mut inv = vec![0;n];
    for i in 0..a.len() {
        inv[a[i]] = i;
    }
    inv
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 10492
#include<iostream>
#include<utility>
#include<cstring>
#include<set>
using namespace std;

int cnt;
set<string> ans;
int tmp;

int rec(string s,int pos,bool u[26]){
  if(pos==s.length()){
    ans.insert(s);
    if(ans.size()>10){
      set<string>::iterator ite=ans.begin();
      for(int i=0;i<5;i++)ite++;
      ans.erase(ite);
    }
    tmp++;
    return 0;
  }
  bool *used;
  used = new bool[26];
  for(int i=0;i<26;i++) used[i]=u[i];
  if(s[pos]=='a'){
    used[0]=true;
    rec(s,pos+1,used);
    used[0]=false;
    if(used[1]!=true){
      used[1]=true;
      s[pos]++;
      rec(s,pos+1,used);
    }
  }else if(s[pos]=='z'){
    if(used[25]==false){
      return 0;
    }else{
      rec(s,pos+1,used);
    }
  }else if(used[s[pos]-'a']==true){
    rec(s,pos+1,used);
    if(used[s[pos]-'a'+1]!=true){
      used[s[pos]-'a'+1]=true;
      s[pos]++;
      rec(s,pos+1,used);
    }
  }else{
    if(used[s[pos]-'a'+1]!=true){
      used[s[pos]-'a'+1]=true;
      s[pos]++;
      rec(s,pos+1,used);
    }
  }
  delete[] used;
  return 0;
}

int main(){
  string s;
  while(cin>>s){
    ans.clear();
    cnt = 0;
    tmp = 0;
    if(s=="#")break;
    bool used[26];
    memset(used,0,sizeof(used));
    rec(s,0,used);
    cout << tmp << endl;
    for(string i : ans){
      if(cnt<5){
	cout << i << endl;
      }else if(cnt>ans.size()-6){
	cout << i << endl;
      }
      cnt++;
    }
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

int main(){
    ll n,m,i,j,ans;
    cin>>ans>>m;
    vector<ll> a(m);
    for(i=0;i<m;i++) cin>>a[i];
    for(i=0;i<m;i++){
        ans-=a[i];
    }
    if(ans<0) ans=-1;
    cout<<ans;

    return 0;
}



Measured memory_bytes: 3668