akhauriyash/Code-Regression huggingface dataset:
import time
import random
d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
# 各日に一番満足度の増加が大きいコンテストを開催する
T = [S[i].index(max(S[i])) for i in range(d)]
score = 0
start = time.time()
while True:
    now = time.time()
    if now - start > 1.5:
        break
    p = random.choice(range(d))
    q = random.choice(range(26))
    memo = T[p]
    T[p] = q
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    new_score = 0
    for i in range(d):
        new_score += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        new_score -= C[j] * (dd - X[j])
    temp = 20000 * (1 - (now - start) / 2)
    prob = 2**(max(min(new_score - score, 0), -10**4) / temp)
    u = random.random()
    if u < prob:
        score = new_score
    else:
        T[p] = memo

for t in T:
    print(t + 1)


Measured memory_bytes: 89192
#include<iostream>
#include<cstdlib>
using namespace std;
 
 
struct tree{
    tree* left;
    tree* right;
    tree* parent;
    int val;
};
 
void printPreorder(tree* root){
    if(root== NULL)return;
    cout << " " << root->val;
    printPreorder(root->left);
    printPreorder(root->right);
    return;
}
void printInorder(tree* root){
    if(root== NULL)return;
    printInorder(root->left);
    cout << " " << root->val;
    printInorder(root->right);
    return;
}
 
void find(int val, tree* root){
    if(root->val == val) cout << "yes" << endl;
    else{
        tree* next;
        if(val < root->val)next = root->left;
        else next = root->right;
 
        if(next)find(val,next);
        else cout << "no" << endl;
    }
}
 
void insert(int val, tree* root){
    tree* next;
    bool flag = val < root->val;
    if(flag)next = root->left;
    else next = root->right;
 
    if(next == NULL){
        tree* newNode = (tree*)malloc(sizeof(tree));
        newNode->val = val;
        newNode->left = NULL;
        newNode->right = NULL;
        newNode->parent = root;
        if(flag)root->left = newNode;
        else root->right = newNode;
    }else{
        insert(val,next);
    }
}
 
int main(){
    ios_base::sync_with_stdio(false);
 
    tree* root = (tree*)malloc(sizeof(tree));
 
    char order[10];
    int val;
    int numOfOrder;
 
    cin >> numOfOrder;
    cin >> order;
    cin >> val;
 
    root->val = val;
    root->left = NULL;
    root->right = NULL;
    root->parent = NULL;
     
 
    for(int i = 0; i <  numOfOrder - 1; i++){
        cin >> order;
        if(order[0] == 'i'){
            cin >> val;
            insert(val, root);
        }else if(order[0] == 'p'){
            printInorder(root);
            cout << endl;
            printPreorder(root);
            cout << endl;
        }else{
            cin >> val;
            find(val,root);
        }
    }
 
 
    return 0;
 
}

Measured memory_bytes: 19956
let w, h, x, y = Scanf.scanf " %d %d %d %d" @@ fun a b c d -> a, b, c, d
let _ =
  Printf.printf "%.12f " @@ float w *. float h /. 2.;
  print_endline @@ if x * 2 = w && y * 2 = h then "1" else "0"

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 5005

long long dep[mx][mx], n, N;

long long dp(int panjang, int sisa){
	if(sisa == 0){
		if(panjang == n)
			return 1;
		return 0;
	}
	long long &ret = dep[panjang][sisa];
	if(ret != -1)
		return ret;
	ret = 0;
	//naruh nol
	if(panjang == 0)
		ret = (ret + dp(panjang, sisa - 1)) % MOD;
	else ret = (ret + dp(panjang - 1, sisa - 1) * 2 % MOD) % MOD;
	//naruh selain nol bebas
	ret = (ret + dp(panjang + 1, sisa - 1)) % MOD;
	return ret;
}

long long POW(long long a, int b){
	long long ret = 1;
	while(b > 0){
		if(b & 1)
			ret = ret * a % MOD;
		b >>= 1;
		a = a * a % MOD;
	}
	return ret;
}

int main(){
	string ss;
	cin >> N >> ss;
	n = sz(ss);
	reset(dep, -1);
	// long long dua = 1;
	// for(int i = 1; i <= n; i++)
		// dua = dua * 2 % MOD;
	// debug(dp(0, N));
	long long jaw = dp(0, N);
	cout << jaw << '\n';
}

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

typedef long long ll;

int N,K ;
vector<int> v;
int sum = 0 ;

void answer(){
	cin >> N >> K;
	for(int i = 0 ; i < N ; i++){
		int a ;
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
// 	if( N == 1){
// 	    cout << v[0];

// 	}
// 	else{
	for(int i = 0 ; i < K ; i++){
	    sum += v[i];
		    }
	cout << sum ;
}


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


Measured memory_bytes: 3636
/**
 *   Praveen Fulera    
**/

// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define endl '\n'
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define point pair <double, double>

const int mod = 1e9 + 7;
//const int mod = 998244353;

signed main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  
  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt", "w", stdout);
  // #endif
  
  int n, k;
  cin >> n >> k;
  double data[n+5];
  double dp[n+5];
  dp[0] = 0.0;

  for(int i = 1; i <= n; i++){
    int x; cin >> x;
    double y = (double)x;
    x = (x*(x+1))/2;
    double p = double(x*1.0)/(1.0*y);
    data[i] = p;
  }

  for(int i = 1; i <= k; i++){
    dp[k] += data[i];
  }

  double ans = dp[k];
  for(int i = k+1; i <= n; i++){
    double temp = dp[i-1] + data[i] - data[i-k];
    dp[i] = temp;
    ans = max(ans, temp);
  } 
  cout << setprecision(12) << ans << '\n';
}


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

int main() {
   int A,B,C,D,K;
   cin >> K;
   D = K % 10;
   K /= 10;
   C = K % 10;
   K /= 10;
   B = K % 10;
   K /= 10;
   A = K % 10;

   if (A + B + C + D == 7) { cout << A << '+' << B << '+' << C << '+' << D << '=' << 7; }
   else if(A - B + C + D == 7) { cout << A << '-' << B << '+' << C << '+' << D << '=' << 7; }
   else if(A + B - C + D == 7) { cout << A << '+' << B << '-' << C << '+' << D << '=' << 7; }
   else if(A + B + C - D == 7) { cout << A << '+' << B << '+' << C << '-' << D << '=' << 7; }
   else if(A - B - C + D == 7) { cout << A << '-' << B << '-' << C << '+' << D << '=' << 7; }
   else if(A - B + C - D == 7) { cout << A << '-' << B << '+' << C << '-' << D << '=' << 7; }
   else if(A + B - C - D == 7) { cout << A << '+' << B << '-' << C << '-' << D << '=' << 7; }
   else if(A - B - C - D == 7) { cout << A << '-' << B << '-' << C << '-' << D << '=' << 7; }




 return 0;

}

Measured memory_bytes: 256
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う
# なんかしらんけど3問駄目だな...

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 10) // 2

while l < r:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""


Measured memory_bytes: 19260
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=1e6+5;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod

// #define LOCAL 1

/************************************


 
*************************************/

vector<int>par,dep,tin,tout;
vector<vector<int>>v;
vector<int>deg;
vector<pll>req;
bool visited[MAX];


ll power(int a,int b){
    int ans=1;
    while(b>0){
        if(b&1)
            ans = (ans%MOD*a%MOD)%MOD;
        b = b>>1;
        a= (a%MOD*a%MOD)%MOD;
    }
    return ans;
}

void bfs(int s,vector<int>&d){
    d[s]=0;
    queue<int>q;
    q.push(s);
    while(!q.empty()){
        int u = q.front();
        q.pop();
        // visited[u]=true;
        for(auto it:v[u]){
            if(d[it]==-1){
                // cout<<it<<" ";
                d[it]=d[u]+1;
                q.push(it);
            }
        }
    }
}


void solve(){
    int t=1;
    // cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n = s.size();
        int f=0;
        for(int i=0,j=n-1;i<j;i++,j--){
            if(s[i]!=s[j]){
                f=1;
                // cout<<"HE ";
                break;
            }
        }
        int j=(n-1)/2;
        j--;
        int i=0;
        while(i<j){
            if(s[i]!=s[j]){
                f=1;
                // cout<<"HRR ";
                break;
            }
            i++,j--;
        }
        j=(n+3)/2;
        j--;
        i=n-1;
        while(j<i){
            if(s[i]!=s[j]){
                f=1;
                break;
            }
            i--,j++;
        }
        if(f==1)
            cout<<"No\n";
        else cout<<"Yes\n";

    }
}


signed main() 
{ 
    boost;

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // while (cin.peek() != EOF) {
    //     solve();
    //     cout << endl << endl;
    //     string s;
    //     do getline(cin, s);
    //     while (!cin.eof() && !s.empty());
    //     while (isspace(cin.peek())) cin.get();
    // }
    // #else
    //     solve();
    // #endif

    solve();


    

    
	return 0; 
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 15
#define A 14	

int main() {
int kind[N];
int kindnum,num,i,j,k;
int shougen_num[N];
int shougen[N][A][2];
int kumiawase=1;
int mask=1;
int max=0;
int shoujiki=0;
int breakflag=0;

	scanf("%d",&num);
	for(i=0;i<num;i++) {
		scanf("%d",&shougen_num[i]);
		for(int j=0;j<shougen_num[i];j++) {
			scanf("%d %d",&shougen[i][j][0],&shougen[i][j][1]);
		}
		kind[i]=1;
		kumiawase*=2;
	}
	for(int i=1;i<kumiawase; i++) {
		shoujiki=0;
		mask=1;
		for(int j=0;j<num;j++) {
			if((i&mask)==0) {
				kind[j]=0;
			} else {
              	shoujiki++;
				kind[j]=1;
			}
			mask*=2;
		}
		for(int j=0;j<num;j++) {
			for(int k=0; k<shougen_num[j]; k++) {
				if(kind[j] == 1) {
					if(kind[shougen[j][k][0]-1]!=shougen[j][k][1]) {
						breakflag=1;
					}
				} 
			}
			if(breakflag==1) {
				break;
			}
		}
		if(breakflag==0) {
          	if(max<shoujiki) {
				max=shoujiki;
            }
		}
		breakflag=0;
	}
	printf("%d",max);
	return 0;

}


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

int main() {
	int n;
	cin >>n;
	long long r1 = 1;
	long long r2 = 1;
	long long x[n];
	long long y[n];
	for (int i=0; i
         <n; i++){
		cin >> x[i] >> y[i];
	}
	long long a=x[0], b=y[0];
	for (int i=1; i<n; i++){
		r1 = (a-1)/x[i]+1;
		r2 = (b-1)/y[i]+1;
		long long r = max(r1, r2);
		a = r*x[i];
		b = r*y[i];
		//cout << a << ' ' <<b << endl;
	}
	cout << a+b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  vll a(n);
  rep(i,0,n) cin>>a[i];
  ll q;
  cin>>q;
  ll cnt[110000];
  rep(i,0,110000) cnt[i]=0;
  ll s=0;
  rep(i,0,n){
    cnt[a[i]]++; 
    s+=a[i];
  }
  rep(i,0,q){
    ll b,c;
    cin>>b>>c;
    s-=cnt[b]*b;
    s+=c*cnt[b];
    
    cnt[c]+=cnt[b];
      cnt[b]=0;
    cout<<s<<endl;
  }
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int n = s.size();
	int k = (n+1)/2;
	int count =0;
	for (int i = 0; i < k ; ++i)
	{
		if(s.at(i)==s.at(n-1-i)){
			count = count;
		}
		else{
			count++;
		}
	}
	for (int i = 0; i < (n+3)/4; ++i)
	{
		if(s.at(i)==s.at((n-3)/2-i)){
			count = count;
		}
		else{
			count++;
		}
	}
	for (int i = 0; i < (n+3)/4; ++i)
	{
		if(s.at(n-1-i)==s.at((n+1)/2+i)){
			count = count;
		}
		else{
			count++;
		}
	}
	if(count!=0){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,ans,k;
signed main(){
	string s;
	cin>>s;
	n=s.size();
	int f[26]={0},alluse=1;
	rep(i,n){
		f[s[i]-'a']=1;
		//cout<<s[i]-'a'<<endl;
	}
	rep(i,26){
		if(!f[i])alluse=0;
	}
	//rep(i,26)cout<<'a'+i<<f[i]<<endl;
	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		cout<<-1<<endl;
		return 0;
	}
	if(alluse){
		int place;
		for(int i=n-1;i>=1;i--){
			if(s[i-1]<s[i]){
				place=i;
				break;
			}
		}
		//cout<<place<<endl;
		int mins=INF;;
		for(int i=n-1;i>=place;i--){
			if(s[i]>s[place-1])mins=std::min(mins,(int)s[i]);
		}
		s[place-1]=(char)mins;
		rep(i,place){
			cout<<s[i];
		}
		cout<<endl;
	}
	else{
		char c;
		rep(i,26){
			if(!f[i]){c='a'+i;break;}
		}
		cout<<s<<c<<endl;
	}
}


Measured memory_bytes: 384
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
int32_t main() 
{
    fio
	ll j,i,n,a,t,l,r,c,h,k,m,maxi,d,x;
	long double b;
	cin>>a>>b;
	h=a*b;
	cout<<h<<endl;
}






	

		

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[102] = {}, z = mod;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < 128; i++) {
        int b = 0;
        for (int j = 0; j < n; j++) b += (a[j] - i) * (a[j] - i);
        z = min(z, b);
    }
    cout << z;
}


Measured memory_bytes: 3620
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
    int n,d;
    cin>>n>>d;
    if(n>=10){
        cout<<d<<"\n";
    }  else{
        int ans  = d+ 100*(10-n);
        cout<<ans<<"\n";
    }
return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
br = [list(map(int, input().split())) for _ in range(m)]

ro= [i for i in range(n+1)]
uni=[[i] for i in range(n+1)]

ans = n * (n - 1) // 2
result = [0] * m
result[m-1] = ans
for i in range(m - 1, -1, -1):
    a=br[i][0]
    b=br[i][1]
    if i!=0:
        if ro[a]!=ro[b]:
            ans-=len(uni[ro[a]])*len(uni[ro[b]])
            result[i-1]=ans
        else:
            result[i-1]=ans
    if ro[a]!=ro[b]:
        if len(uni[ro[a]])>len(uni[ro[b]]):
            uni[ro[a]]+=uni[ro[b]]  
            for j in uni[ro[b]]:
                ro[j]=ro[a]
            

        else:
            uni[ro[b]]+=uni[ro[a]]
            for j in uni[ro[a]]:
                ro[j]=ro[b]
            
   
for k in result:
    print(k)

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

int main(){
    int n[6];
    int a[4]={};
    for(int i=0;i<6;i++){
        cin>>n[i];
        a[n[i]-1]++;
    }
    sort(&a[0],&a[4]);
    if(a[3]>=3)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;


ll f(ll n) {
    ll ret = 0;
    while (n > 0) ret += (n % 10), n /= 10;
    return ret;
}


int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n;
        cin >> n;
        ll ans = ll_inf;
        for (int i = 1; i < n; ++i) {
            ll a = i, b = n - i;
            ans = min(ans, f(a) + f(b));
        }
        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stack>

using namespace std;

int n,a[300000],s[300000];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	int cnt=0,sn=0;
	for(int i=0;i<n;i++){
		if(sn==0 || s[sn-1]<a[i]){
			s[sn++]=a[i];
			cnt++;
		}else if(s[sn-1]==a[i])continue;
		else{
			while(sn>0 && s[sn-1]>a[i])sn--;
			if(sn==0 || s[sn-1]<a[i]){
				s[sn++]=a[i];
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}


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

using i64 = long long;
using P = pair<i64, i64>;


void solve(long long N, std::vector<long long> a){
    i64 cnt = 1;
    i64 ans = 0;
    for(int i = 0; i < N; ++i){
        if(a[i] == cnt) ++cnt;
        else{
            ++ans;
        }
    }
    if(cnt == 1) cout << -1 << endl;
    else cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) {
		int i=0,j=0,k=0;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int a;
		HashSet<Integer> r = new HashSet<>();
		int cnt32=0;
		for(i=0;i<n;i++) {
			a = parseInt(sc.next());
			if(a<3200) {
				r.add(a/400);
			} else {
				cnt32++;
			}
		}
		sc.close();
		int mx = r.size()+cnt32;
//		if(mx>8)mx=8;
		int mn = r.size();
		if(mn<1)mn=1;
		out.print(mn);
		out.print(" ");
		out.println(mx);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A=700,B=100 ;
  char a[3];
  scanf("%c%c%c",&a[0],&a[1],&a[2]);
  if(a[0]=='o'){
    A+=B;
  }
  if(a[1]=='o'){
    A+=B;
  }
  if(a[2]=='o'){
    A+=B;
  }
  cout <<A<<endl ;
  return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

int main(){
    int n;
    cin >> n;
    vector<int> a_vec(n, 0);
    vector<int> lmax_vec(n, 0);
    vector<int> rmax_vec(n, 0);
    for(size_t i = 0; i < a_vec.size(); ++i){
        cin >> a_vec[i];
    }

    for(size_t i = 0; i < a_vec.size(); ++i){
        /* iよりも左側の範囲の最大値を取得 */
        lmax_vec[i] = (i == 0)? 0 : max(lmax_vec[i - 1], a_vec[i - 1]);

        /* iよりも右側の範囲の最大値を取得 */
        size_t r_index = a_vec.size() - 1 - i;
        rmax_vec[r_index] = (i == 0)? 0 : max(rmax_vec[r_index + 1], a_vec[r_index + 1]);
    }

    for(size_t i = 0; i < a_vec.size(); ++i){
        int ans = max(lmax_vec[i], rmax_vec[i]);
        cout << ans << endl;
    }
    return 0;
}

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

		public static void main(String[] args) {
			Scanner scan = new Scanner(System.in);
			int d,n;
			d=scan.nextInt();
			n=scan.nextInt();

			int result = 0;
			result = (int)Math.pow(100, d) * n;
			if(n == 100) result += (int)Math.pow(100, d);
			System.out.println(result);
			scan.close();
		}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	int res = 0;
	ll ans = 1;
	for (int i = 1;i < n;++i) {
		if (a[i - 1] == a[i]) {
			ans *= a[i];
			i++;
			res++;
			if (res == 2)break;
		}
	}
	if (res == 2)cout << ans << endl;
	else cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 1024
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    s = input()
    t = input()
    cnt = 0
    for i in range(len(s)):
        if s[i]!=t[i]:
            cnt+=1
    print(cnt)




main()




Measured memory_bytes: 10328
# a = int(input())
# n, *a = map(int, open(0))
M, D = map(int, input().split())
# A = list(map(int, input().split()))
# S = input()
cnt = 0
for i in range(M+1):
    for j in range(D+1):
        m = i
        d_10 = j//10
        d_1 = j - d_10 * 10
        if d_10 > 1 and d_1 > 1 and m == d_10 * d_1:
            cnt += 1
print(cnt)

Measured memory_bytes: 3060
//0039 Roman Figure

#include<iostream>
#include<string>
#include<map>
using namespace std;

int main(void)
{
	string str;
	while(cin >> str)
	{
		int s = 0;
		for(int i = 0; i < str.size(); i++)
		{
			char c = str[i];
			char next = (i==str.size()-1 ? 0 : str[i+1]);
			switch(c)
			{
			case 'I': 
				if(next == 'V') s += 4, i++;
				else if(next == 'X') s += 9, i++;
				else s+=1;
				break;
			case 'V':
				s += 5;
				break;
			case 'X':
				if(next == 'L') s += 40, i++;
				else if(next== 'C') s += 90, i++;
				else s+=10;
				break;
			case 'L':
				s += 50;
				break;
			case 'C':
				if(next == 'D') s += 400, i++;
				else if(next =='M') s += 900, i++;
				else s += 100;
				break;
			case 'D':
				s += 500;
				break;
			case 'M':
				s += 1000;
				break;
			}
		}
		cout << s << endl;
	}
	return 0;
}

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

int f(int x) {
    if (x % 2 == 0) return x/2;
    else return 3*x + 1;
}

int main() {
    int s;
    cin >> s;
    vector<int> vec(10000000, 0);
    vec[s] += 1;
    for (int i = 2; ; ++i) {
        s = f(s);
        if (vec[s] == 1) {
            cout << i << endl;
            break;
        } else {
            vec[s] += 1;
        }
    }
    return 0;
}

Measured memory_bytes: 39296
#include<iostream>
#include<string>
#include<vector>
#include<map>

using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<string> S(n);
    for(int i = 0; i < n; i++){
        cin >> S[i];
    }
    map<char, int> m;
    for(char c = 'a'; c <= 'z'; c++) m[c] = 2500;
    for(int i = 0; i < S.size(); i++){
        map<char, int> mtmp;
        for(int j = 0; j < S[i].length(); j++) mtmp[S[i][j]]++;
        for(char c = 'a'; c <= 'z'; c++) m[c] = min(m[c], mtmp[c]);
    }
    for(char c = 'a'; c <= 'z'; c++){
        for(int i = 0; i < m[c]; i++) cout << c;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define zeros(x) ((x) & (-x))
#define inf 1e18

using namespace std;

typedef long long ll;
typedef long double ld;

ll n, V[200005], dp[200005], maxim=-inf;

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>V[i];
    }

    for (int i=1; i<=n; i++)
    {
        if (V[i] == 1)
        {
            dp[1] = max(dp[1], 1LL);
        }
        else
        {
            if (dp[V[i]-1] > 0)
                dp[V[i]] = max(dp[V[i]], dp[V[i]-1] + 1);
        }
    }
    for (int i=1; i<=n; i++)
        maxim=max(maxim, dp[i]);

    if (maxim == 0)
        cout<<-1;
    else
        cout<<n-maxim;
    return 0;
}

Measured memory_bytes: 3328
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_a
import operator

# input
n = int(input())
V = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
# get ans
D = [v-c for v, c in zip(V, C)]
D = filter(lambda x: x>0, D)
ans = sum(D)
# output
print(ans)


Measured memory_bytes: 3060
from sys import exit, setrecursionlimit
setrecursionlimit(10**6)

def array2D(row, col ,val=0):
    return [[val]*col for i in range(row)]

n,m = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
for i in range(n):
    A[i] *= (4*m)
cnt = 0

for a in A:
    if a >= s:
        cnt += 1
print('Yes' if cnt>=m else 'No')


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int givenNum = scanner.nextInt();
        int currentTarget = 0;
        for(int i=1; i<givenNum; i++) {
            int target1 = 0;
            int target2 = 0;
            int num1 = i;
            int num2 = givenNum - i;
            while(num1 > 0) {
                target1 += num1 % 10;
                num1 /= 10;
            }
            while(num2 > 0) {
                target2 += num2 % 10;
                num2 /= 10;
            }
            if(i == 1) {
                currentTarget = target1 + target2;
            }
            if(currentTarget > target1 + target2) {
                currentTarget = target1 + target2;
            }
        }
        System.out.println(currentTarget);
    }
}


Measured memory_bytes: 23252
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();int M = nextInt();
		int[] S = new int [2020];
		int[] T = new int [2020];
		S = nextIntArray(N);
		T = nextIntArray(M);

		long[][] num = new long[2020][2020];
		long[][] sum = new long[2020][2020];

		for(int i=0;i < 2020;i++) {
			sum[i][0]=1;
			sum[0][i]=1;
		}

		long res = 1;
		for(int i=0;i<N;i++) {
			for(int j=0;j<M;j++) {
				if(S[i]==T[j]) {
					num[i+1][j+1]=(sum[i][j])%Mod;
					res+=num[i+1][j+1];
				}
				sum[i+1][j+1]=(sum[i][j+1]+sum[i+1][j]+Mod-sum[i][j]+num[i+1][j+1])%Mod;
			}
		}
		out.println(res%Mod);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

Measured memory_bytes: 131540
n=int(input())
s=[""]*n
t=[""]*n
for i in range(n):
  s[i],t[i]=input().split()
x=input()
for i in range(n):
  if s[i]==x:
    ans=0
    for j in range(i+1,n):
      ans+=int(t[j])
    break
print(ans)

Measured memory_bytes: 3060
n = int(input())
a = sorted(map(int,input().split()))
b = sorted(map(int,input().split()))
c = sorted(map(int,input().split()))

lis = [0] * n
j = 0
for i in range(n):
    while j < n and a[j] < b[i]:
        j += 1
    lis[i] = j

li = [0] * n
m = 0
j = 0
for i in range(n):
    while j < n and b[j] < c[i]:
        m += lis[j]
        j += 1
    li[i] = m
print(sum(li))

Measured memory_bytes: 23476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

const int N = 10000005;
vector<int> table(N);

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

  rep3(i, 1, n + 1) {
    for (int j = i; j <= n; j += i) {
      table[j]++;
    }
  }
  ll ans = 0;
  rep3(i, 1, n + 1) ans += 1LL * i * table[i];
  cout << ans << endl;
}


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

/*
  REMEMBER:
  1.Think TWICE, code ONCE!
  Are there any counterexamples to your algo?
	
  2.Be careful about the BOUNDARIES in your algo!
  N=1? P=1? Is P a prime? Something about 0?
	
  3.Never make STUPID MISTAKES!
  Integer overflow? Array size? Time complexity? Memory usage? Precition error?
*/

int N , A , B , C , D; char str[200003];

void work(int p , int q){
	while(p != q)
		if(str[p + 1] == '.') ++p;
		else if(str[p + 2] == '.') p += 2;
		else{puts("No"); exit(0);}
}

int main(){
	scanf("%d %d %d %d %d %s" , &N , &A , &B , &C , &D , str + 1);
	if(C > D){
		while(B <= D && (str[B + 1] != '.' || str[B - 1] != '.'))
			if(str[B + 1] == '.') ++B;
			else if(str[B + 2] == '.') B += 2;
			else{puts("No"); return 0;}
		if(B > D){puts("No"); return 0;}
		str[B] = '#'; work(A , C); work(B , D);
	}
	work(B , D); work(A , C);
	puts("Yes"); return 0;
}


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

using namespace std;

void rwFile() {
    freopen("INP.inp", "r", stdin);
    freopen("OUT.out", "w", stdout);
}

void solveA() {
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes";
    else cout << "No";
}

void solveB() {
    int n; cin >> n;
    string s; cin >> s;
    int res = 0;
    for (int i = 0; i + 2 < n; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') res++;
    }
    cout << res;
}

void solveC() {
    int n; cin >> n;
    int p[n], q[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n;i ++) cin >> q[i];
    int arr[n];
    int lim = 1;
    for (int i = 1; i <= n; i++) lim *= i;
    for (int i = 0; i < n; i++) arr[i] = i + 1;
    int a = 0, b = 0;
    for (int i = 0; i < lim; i++) {
        int isA = 1, isB = 1;
        for (int j = 0; j < n; j++) {
            if (arr[j] != q[j]) isB = 0;
            if (arr[j] != p[j]) isA = 0;
        }
        if (isA) a = i;
        if (isB) b = i;
        next_permutation(arr, arr + n);
    }
    cout << abs(a - b);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    //rwFile();
    ///solveA();
    ///solveB();
    solveC();
}


Measured memory_bytes: 256
#include <stdio.h>
void spin1(int a[]);
void spin2(int a[]);
void spin3(int a[]);
 
int main(void){
    int d[6],q,u,f,i;
    for(i=0;i<6;i++){
        scanf("%d",&d[i]);
    }
    scanf("%d",&q);
    while(q--){
        scanf("%d %d",&u,&f);
        if(d[0]==u||d[1]==u||d[5]==u||d[4]==u){
            while(d[0]!=u)
                spin1(d);
            while(d[1]!=f)
                spin2(d);
        }
        else{
            while(d[0]!=u)
                spin3(d);
            while(d[1]!=f)
                spin2(d);
        }
        printf("%d\n",d[2]);
    }
     
    return 0;
}
 
void spin1(int a[]){
    int t=a[0];
    a[0]=a[4];
    a[4]=a[5];
    a[5]=a[1];
    a[1]=t;
}
void spin2(int a[]){
    int t=a[1];
    a[1]=a[2];
    a[2]=a[4];
    a[4]=a[3];
    a[3]=t;
}
void spin3(int a[]){
    int t=a[0];
    a[0]=a[2];
    a[2]=a[5];
    a[5]=a[3];
    a[3]=t;
}


Measured memory_bytes: 2032
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

int main()
{
    string S;
    cin >> S;
    cout << S.substr(0, 3) << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(vector<T> a){
    for (const auto& ai : a) cout << ai << " ";
    cout << endl;
}
vector<string> Yes = {"No", "Yes"};
int main(){
    INT(a, b, c, k);
    vlint x;
    int ret = 0;
    if (k > 0){
        ret += min(k, a);
        k -= min(k, a);
    }
    if (k > 0){
        k -= min(k, b);
    }
    if (k > 0){
        ret -= min(k, c);
        k -= min(k, c);
    }
    cout << ret << endl;
}


Measured memory_bytes: 3616
S = list(input())
K = int(input())
# 5000000000000000 = 5 * 10**15
S = [int(e) for e in S]
days = 5 * 10**15
for e in S:
    result = 1
    if e == 1:
        K -= 1
        if K <= 0:
            print(e)
            exit()
        continue
    for f in range(days):
        result *= e
        if K - result <= 0:
            print(e)
            exit()
        if f == days - 1:
            K -= result

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long www(long long a,long long b){
    long long x,tmp,r,w;
    w=b;
    x=a;
    if(a<b){
        tmp=a;
        a=b;
        b=tmp;
    }
    r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return x/b*w;
}
int main(){
    int N;
    long long t[101];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> t[i];
    }
    for(int i=0;i<N-1;i++){
        t[i+1]=www(t[i],t[i+1]);

    }
    cout << t[N-1];
    return 0;
    }

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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

int main() {
	reg n = read(), m = read(), k = read();
	fo(i, 0, n) {
		fo(j, 0, m) {
			if(n * m - i * j - (n - i) * (m - j) == k) {
				puts("Yes");
				return 0;
			}
		}
	} puts("No");
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define _F(i,a,b,s) for(int i=(a);((s)>0?i<(b):i>(b));i+=(s))
#define _1(e) _F(i,0,e,1)
#define _2(i,e) _F(i,0,e,1)
#define _3(i,b,e) _F(i,b,e,(b)<(e)?1:-1)
#define _G(a,b,c,d,e,...) e
#define FOR(...) _G(__VA_ARGS__,_F,_3,_2,_1)(__VA_ARGS__)

int n;
int col[200];
vector<int> adj[200];
bool isBip = 1;

void dfs(int node = 0, int c = 1) {
	if (col[node]) {
		if (col[node] != c)
			isBip = 0;
		return;
	}
	col[node] = c;
	for (int nbr : adj[node]) {
		dfs(nbr, c % 2 + 1);
	}
}

int main() {
	ios::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	FOR (i, n) {
		string s; cin >> s;
		FOR (j, n) {
			if (s[j] == '1') {
				adj[i].pb(j);
			}
		}
	}
	dfs();
	if (!isBip) {
		cout << "-1\n";
		return 0;
	}
	int mxDist = 0;
	vector<vector<int>> minDist(n, vector<int>(n, 1e9));
	FOR (i, n) {
		minDist[i][i] = 0;
		for (int nbr : adj[i]) {
			minDist[i][nbr] = minDist[nbr][i] = 1;
		}
	}
	FOR (i, n) {
		FOR (j, n) {
			FOR (k, n) {
				minDist[j][k] = min(minDist[j][k], minDist[i][k] + minDist[i][j]);
			}
		}
	}
	FOR (i, n) {
		FOR (j, n) {
			mxDist = max(mxDist, minDist[i][j]);
		}
	}
	cout << mxDist + 1 << '\n';
}

Measured memory_bytes: 3860
#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;
  cin >> N;
  vector<int> A(N);
  vector<int> M(N);
  int sum = 0;
  rep(i, N) {
    cin >> A.at(i);
    sum += A.at(i);
  }


  for(int i = 1; i < N; i += 2){
    sum -= A.at(i) * 2;
  }

  M.at(0) = sum;

  for(int j = 0; j < N-1; j++){
    M.at(j+1) = A.at(j) * 2 - M.at(j);
  }

  rep(k, N-1) cout << M.at(k) << " ";
  cout << M.at(N-1) << endl;


}


Measured memory_bytes: 2048
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt64()
	K := readInt64()

	if K == 0 {
		println(N * N)
		return
	}

	var ans int64
	for b := int64(1); b <= N; b++ {
		ans += N / b * max(0, b-K)
		ans += max(0, N%b+1-K)
	}
	println(ans)
}

func max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <utility>
#include <climits>
#include <cstring>
#include <cstdio>

using namespace std;
typedef long long int llg;

const int INF = 1000001000;
#define REP(var, count) for(int var=0; var<count; var++)


int vert[100010];
int edge[500010][3];

int main(void) {
	int V, E, r;
	scanf("%d", &V);
	scanf("%d", &E);
	scanf("%d", &r);
	
	REP(v, V) { vert[v] = INF; }
	vert[r] = 0;
	
	REP(i, E) {
		scanf("%d", &edge[i][0]);
		scanf("%d", &edge[i][1]);
		scanf("%d", &edge[i][2]);
	}
	
	REP(v, V) {
		bool update = false;
		REP(i, E) {
			int s = edge[i][0];
			int t = edge[i][1];
			if ( vert[s] != INF && vert[t] > (vert[s]+edge[i][2]) ) {
				vert[t] = vert[s] + edge[i][2];
				update = true;
			}
		}
		if ( !update ) { break; }
	}
	
	REP(v, V) {
		if ( vert[v] == INF ) {
			cout << "INF" << endl;
		} else {
			cout << vert[v] << endl;
		}
	}

}

Measured memory_bytes: 9240
#include<iostream>
#include<cstring>
using namespace std;
string s;
int x1,x2;
int main()
{
	cin>>s;
	int len=s.length();
	for(int i=0;i<len;i++)
		if(s[i]=='A')
		{
			x1=i;
			break;
		}
	for(int i=len-1;i>=0;i--)
		if(s[i]=='Z')
		{
			x2=i;
			break;
		}
	cout<<x2-x1+1<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n;
char s[1000001],s2[1000001];

int main(){
	while(cin>>n){
		if(n==0)return 0;
		for(int i=0;i<10001;i++){s[i]=0;s2[i]=0;}
		cin>>s;
		int l=0;
		while(isdigit(s[l]))l++;
		for(int i=0;i<n;i++){
			int m,t=0,cur=0;
			for(int j=0;j<=l;j++){
				if(t==0){m=s[j]-'0';t=1;}
				else {
					if(s[j]-'0'==m)t++;
					else {
						int f=0;
						if(t>99){s2[cur++]=t/100+'0';t%=100;f=1;}
						if(t>9||f){s2[cur++]=t/10+'0';t%=10;}
						s2[cur++]=t+'0';
						s2[cur++]=m+'0';
						m=s[j]-'0';t=1;
					}
				}
			}
			for(int i=0;i<cur;i++)s[i]=s2[i];
			s[cur]=0;
			l=cur;
		}
		for(int i=0;i<l;i++)cout<<s[i];
		cout<<endl;
	}
}

Measured memory_bytes: 0