akhauriyash/Code-Regression huggingface dataset:
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=300005;
int n;
int a[M];
int lft[M],rgt[M];
 main()

{
    fast
    cin>>n;
    int sz=n;
    n=3*n;
    f(i,1,n)cin>>a[i];
    priority_queue<int>pq;
    int sum=0;
    f(i,1,n)
    {
        sum+=a[i];
        pq.push(-a[i]);
        while(pq.size()>sz)
        {
            sum+=pq.top();
            pq.pop();
        }
        if(pq.size()==sz)
        {
            lft[i]=sum;
        }
    }
    while(!pq.empty())pq.pop();
    sum=0;
    rf(i,n,1)
    {
        sum+=a[i];
        pq.push(a[i]);
        while(pq.size()>sz)
        {
            sum-=pq.top();
            pq.pop();
        }
        if(pq.size()==sz)
        {
            rgt[i]=sum;
        }
    }
    int ses=-inf;
    f(i,1,n-1)
    {
       if(lft[i]!=0 && rgt[i+1]!=0)
       {
           ses=max(ses,lft[i]-rgt[i+1]);
       }
    }
    cout<<ses<<endl;
    return 0;
}


Measured memory_bytes: 9712
import java.util.Scanner;

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

        int n = sc.nextInt();

        double jpy = 0.0;
        double btc = 0.0;

        for (int i = 0; i < n; i++) {
            double x = sc.nextDouble();
            String s = sc.next();
            if (s.equals("JPY")) {
                jpy += x;
            } else {
                btc += x;
            }
        }

        sc.close();

        double sum = jpy + (380000 * btc);

        System.out.println(sum);
    }
}


Measured memory_bytes: 23252
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<62 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

ll gcd(ll x,ll y){
    if(x<y)swap(x,y);
    if(x%y==0)return y;
    else return gcd(y,x%y);
}

ll lcm(ll x,ll y){
    if(x>=longinf||y>=longinf||x<0||y<0)return -1;
    ll g=gcd(x,y);
    if(x/g<longinf/y) return x*(y/g);
    else return -1;
}
vector<ll> fast_mobius_transform(vector<ll> f) {
    for (int i = 0; (1 << i) < f.size(); i++) {
        for (int j = 0; j < f.size(); j++) {
            if (j & 1 << i) {
                f[j] -= f[j ^ 1 << i];
            }
        }
    }
    return f;
}
ll dp[1<<20];
int main(){
   int n;
   cin>>n;
   ll m;
   cin>>m;
   ll a[n];
   rep(i,n)cin>>a[i];
   int N=1<<n;
   dp[0]=1;
   rep(i,N){
       rep(j,n){
           if(i&(1<<j)){
               dp[i]=lcm(a[j],dp[i^(1<<j)]);
               break;
           }
       }
   }
   vector<ll> v;
   rep(i,N){
       if(dp[i]<0)v.push_back(0);
       else v.push_back(m/dp[i]);
   }
   v[0]=0;
   v=fast_mobius_transform(v);
   double ans=0;
   double p[n];
   rep(i,n){
       cin>>p[i];
       p[i]/=100;
   }
   rep(i,N){
       double ret=1.0*abs(v[i]);
       rep(j,n){
           if(i&(1<<j))ret*=p[j];
           else ret*=(1.0-p[j]);
       }
       ans+=ret;
   }
   cout<<fixed<<setprecision(12)<<ans<<endl;
   return 0;
}


Measured memory_bytes: 35772
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
typedef vector<ll> V;
typedef vector<V> VV;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}
int main(){
	int n;
	string s;
	cin >>n;
	cin >>s;
	string ans=s;
	V c(110,0);
	rep(i,n){
		if(s[i]=='('){
			c[i]=(i!=0?c[i-1]+1:1);
		}else{
			c[i]=(i!=0?c[i-1]-1:-1);
			if(c[i]<0){
				c[i]++;
				ans='('+ans;
			}
		}
	//	cout<<c[i]<<endl;
	}
	while (c[n- 1] != 0)
	{
		if (c[n- 1] < 0)
		{
			ans = '(' + ans;
			c[n- 1]++;
		}
		else
		{
			ans = ans + ')';
			c[n- 1]--;
		}
	}
	//cout<<('('<')')<<endl;//----1
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int h, w;
	cin >> h >> w;
	vector<int> a(26);
	rep(i, h) rep(j, w) {
		char c;
		cin >> c;
		a[c - 'a']++;
	}
	queue<int> p, q;
	rep(i, 26) {
		if (a[i] % 2)
			p.push(a[i]);
		else if (a[i] % 4)
			q.push(a[i]);
	}
	if (h % 2 and w % 2) {
		if (p.size() != 1) {
			cout << "No" << endl;
			return 0;
		}
		int g = p.front();
		g--;
		if (g % 4) q.push(g);
		if (h / 2 + w / 2 >= q.size())
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	} else if (h % 2) {
		if (!p.empty()) {
			cout << "No" << endl;
			return 0;
		}
		if (w / 2 >= q.size())
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	} else if (w % 2) {
		if (!p.empty()) {
			cout << "No" << endl;
			return 0;
		}
		if (h / 2 >= q.size())
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	} else {
		if (p.size() + q.size() == 0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int d, t, s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> d >> t >> s;
    if((d + s - 1) / s <= t)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main (void) {
	int n, count, c2, c5, res;
	
	for (;;) {
		cin >> n;
		
		if (n == 0) {
			break;
		}
		
		count = 0;
		c2 = 0;
		c5 = 0;
		
		for (int i = 1; i <= n; i ++) {
			int tmp;
			
			tmp = i;
			while (tmp % 2 == 0) {
				c2 ++;
				tmp /= 2;
			}
			
			tmp = i;
			while (tmp % 5 == 0) {
				c5 ++;
				tmp /= 5;
			}
		}
		
		cout << min(c2, c5) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int k=sc.nextInt();
		int div=Math.min(a, b);
		int sub[]=new int[div+1];
		int count =0;
		for( int i=div;i>=1;--i) {
			if(a%i==0 && b%i==0) {
				++count;
				sub[count]=i;
			}
		
		}
		System.out.println(sub[k]);

	}
	
}


Measured memory_bytes: 23892
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int N = sc.nextInt();

//		int[] nums = new int[N];
		List<Integer> nums = new ArrayList<Integer>();
		for (int i=0; i<N; i++) {
			int c = sc.nextInt();
			nums.add(c);
		}

//		int[] num_range = new int[110];
		List<Integer> range = new ArrayList<Integer>();
		for (int k=-50; k<51; k++) {
			range.add(X+k);
		}

		List<Integer> answer = new ArrayList<Integer>();

		for (int a : range) {
			if (!(nums.contains(a))) {
				answer.add(a);
			}
		}

		int min_abs=0;
		int before_min_abs = 51;
		int ans_num=0;
		for (int i=0; i<answer.size(); i++) {
			min_abs = Math.abs(answer.get(i) - X);
			if (min_abs<before_min_abs) {
				before_min_abs = min_abs;
				ans_num=answer.get(i);
			}
		}
		System.out.println(ans_num);


	}

}

Measured memory_bytes: 27196
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final long MOD = 1_000_000_007;

	public static void main(String[] args) {
		int N = sc.nextInt();
		long[] fact = new long[N + 1];
		long[] inv = new long[N + 2];
		fact[0] = 1;
		for (int i = 0; i < N; i++) {
			fact[i + 1] = fact[i] * (i + 1) % MOD;
			inv[i + 1] = inv(i + 1);
		}
		long all = 0;
		for (int i = 2; i <= N; i++) {
			all += fact[N] * inv[i] % MOD;
		}
		all %= MOD;
		long[] A = new long[N];
		long ans = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			ans += A[i] * fact[N];
			ans += A[i] * all;
			ans %= MOD;
			all += MOD - fact[N] * inv[N - i] % MOD;
			all += fact[N] * inv[i + 2];
			all %= MOD;
		}
		System.out.println(ans);
	}

	static long inv(long v) {
		return pow(v, (int) MOD - 2);
	}

	static long pow(long v, int p) {
		if (p == 0) return 1;
		if (p == 1) return v;
		long ret = pow(v, p / 2);
		ret *= ret;
		ret %= MOD;
		if (p % 2 == 1) {
			ret *= v;
			ret %= MOD;
		}
		return ret;
	}

}


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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

uint64_t randint(){
    static int64_t seed = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
    static mt19937_64 rnd(seed);
    return rnd();
}

template<int64_t mod=int64_t(1e9+7)>
struct RollingHash{
    vector<int64_t> hash;
    vector<int64_t> base_pow;
    int64_t base;

    RollingHash(vector<int> S, int64_t base_=-1):base(base_){
        if(base < 0) base = 1000 + randint() % 10000;
        if(S.size() > 0) initialize(S);
    }

    void initialize(string& S){
        int N = S.size();
        vector<int> s(N);
        for(int i=0; i<N; i++) s[i] = S[i];
        initialize(s);
    }

    void initialize(vector<int>& S){
        int sz = S.size();
        hash.resize(sz+1);
        base_pow.resize(sz+1);
        hash[0] = 0;
        base_pow[0] = 1;
        for(int i=1; i<=sz; i++){
            hash[i] = (hash[i-1] * base + S[i-1]) % mod;
            base_pow[i] = base_pow[i-1] * base % mod;
        }
    }

    // 0-indexed, [a, b)
    int64_t between(int a, int b){
        return (mod + hash[b] - hash[a] * base_pow[b-a] % mod) % mod;
    }
};

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

    vector<int> num(N), A(N), B(N);
    int64_t b1 = 1000 + randint() % 10000;
    RollingHash<> hash1A({}, b1), hash1B({}, b1);
    auto eq = [&](int la, int ra, int lb, int rb){
        int64_t v1A = hash1A.between(la, ra);
        int64_t v1B = hash1B.between(lb, rb);
        return (v1A == v1B);
    };

    bitset<200000> ok;
    for(int k=0; k<30; k++){
        ok.reset();
        for(int i=0; i<N; i++){
            A[i] = nth_bit(AA[i], k);
            B[i] = nth_bit(BB[i], k);
        }
        hash1A.initialize(A);
        for(int t=0; t<2; t++){
            hash1B.initialize(B);
            for(int i=0; i<N; i++) if(eq(0, i, N-i, N) && eq(i, N, 0, N-i)) ok[i] = 1;
            for(int i=0; i<N; i++) B[i] = 1-B[i];
        }
        for(int i=0; i<N; i++) if(ok[i]) num[i]++;
    }
    for(int i=0; i<N; i++) if(num[i] == 30){
        cout << i << " " << (AA[i]^BB[0]) << endl;
    }
    return 0;
}


Measured memory_bytes: 15104
k = int(input())
li = [str(i) for i in range(1, 10)]
n = 0
while n < 9:
  rep = li[:]
  for r in rep:
    if r[-1] == "0":
      li.append(r+"0")
      li.append(r+"1")
    elif r[-1] == "9":
      li.append(r+"8")
      li.append(r+"9")
    else:
      x = int(r[-1])
      li.append(r+str(x-1))
      li.append(r+str(x))
      li.append(r+str(x+1))
  n += 1

setli = set(li)
li = list(setli)
#print(li)
intli = [int(i) for i in li]
intli.sort()
#print(intli)
#intli.sort
#print(len(intli))
#print(intli)
print(intli[k-1])


Measured memory_bytes: 146728
/*input
5
10
8
5
3
2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

vector<int> v;
int a[maxn];

int main()
{
	//IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n) v.pb(a[i]);
	SORT_UNIQUE(v);
	REP(i,n) a[i]=GET_POS(v,a[i]);

	int ans=0;
	for(int i=0;i<n;i+=2){
		if(a[i]%2) ans++;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1276
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str,str2;
    cin>>str;
    rep(i,str.length()){
        if(str[i]=='+') sum++;
        else sum--;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <assert.h>
#include <string>
#include <algorithm>
#include <sstream>
#include <iostream>
using namespace std;

typedef long long ll;
const int maxl = 100010;
const int mod = 1e9 + 7;

int n;

int main() {
    while (scanf("%d", &n) != EOF) {
        bool flag = false;
        while (n > 0) {
            if (n % 10 == 9)
                flag = true;
            n /= 10;
        }
        puts(flag ? "Yes" : "No");
    }

    return 0;
}

Measured memory_bytes: 256
def main():
    N = int( input())
    A = list( map( int, input().split()))
    # if N == 1 or N == 2:
    #     print(1)
    #     return
    sing = 0
    now = A[0]
    ans = 1
    for a in A[1:]:
        if sing == 0:
            if now < a:
                sing = 1
            elif now > a:
                sing = -1
        elif sing > 0:
            if not ( now <= a):
                ans += 1
                sing = 0
        else:
            if not ( now >= a ):
                ans += 1
                sing = 0
        now = a
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
    class Program
    {
        //メイン関数
        static void Main(string[] args)
        {
            string[] input = Read().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            int d = int.Parse(input[3]);

            if (Abs(a - c) <= d || (Abs(a - b) <= d && Abs(b - c) <= d)) WriteLine("Yes");
            else WriteLine("No");
        }

        //メインじゃない関数
        private static string Read() { return ReadLine(); }
        private static int ReadI() { return int.Parse(ReadLine()); }
    }
}


Measured memory_bytes: 11092
from itertools import chain

def main():
    inputs = []
    r, _ = map(int, input().split())
    for i in range(r):
        inputs.append(tuple(map(int, input().split())))

    row_sums = map(lambda row: sum(row), inputs)
    column_sums = map(lambda column: sum(column), map(lambda *x: x, *inputs))
    all_sum = sum(chain.from_iterable(inputs))

    for i, s in zip(inputs, row_sums):
        print(" ".join(map(lambda n: str(n), i)) + " {}".format(s))
    else:
        print(" ".join(map(lambda n: str(n), column_sums)) + " {}".format(all_sum))

if __name__ == "__main__":
    main()

Measured memory_bytes: 7900
#include <stdio.h>

int main(){
  int flag = 1,ct=0,l,i,j,cp,A[100];
  scanf("%d",&l);
  for(i=0; i<l; i++){
    scanf("%d",&A[i]);
  }
  while(flag==1){
    flag = 0;
    for(j=l-1; j>=1; j--){
      if(A[j] < A[j-1]){
        cp = A[j];
        A[j] = A[j-1];
        A[j-1] = cp;
        flag = 1;
        ct++;
      }
    }
  }
  for(i=0; i<l-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d",A[i]);
  printf("\n%d\n",ct);
}



Measured memory_bytes: 2736
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n)  for(int i=0;i<n;i++)
#define per(i,n)  for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int A,a,B,b,M,price,best;
    cin >> A >> B >> M;
    vector <int> As,Bs,Prices,sums;
    vector < pair<int,int> > discounts;
    pair <int,int> p;
    int sum = 0;
    rep(i,A){
        cin >> a;
        As.push_back(a);
        
    }
    rep(i,B){
        cin >> b;
        Bs.push_back(b);
    }
    
    rep(i,M){
        cin >> p.first >> p.second >> price;
        discounts.push_back(p);
        Prices.push_back(price);
    }
    
    
    rep(i,M){
       sum = ( ( As[ discounts[i].first - 1 ] + Bs[ discounts[i].second - 1]) - Prices[i] );
        sums.push_back(sum);
    }
    sort(sums.begin(),sums.end());
    int sum1 = sums[0];
    sort(As.begin(),As.end());
    sort(Bs.begin(),Bs.end());
    int sum2 = As[0] + Bs[0];
    if (sum1 < sum2) best = sum1;
    else best = sum2;
    cout << best;
    return 0;
}


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

int main(){
    string card, sub;
    int m, h;
    
    while(1){
        cin >> card;
        if(card == "-") break;
        cin >> m;
        for(int i = 0; i < m; i++){
            cin >> h;
            sub = card.substr(0, h);
            card = card.erase(0, h);
            card = card.insert(card.size(), sub);
        }
        cout << card << endl;
    }
    return 0;
    
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,input,x,q,xx,xxx;
    cin>>n;
    deque<long long>v;
    //memset(v,0,sizeof v);
    while(n--)
    {

        cin>>input;
        if(input == 0)
        {
            cin>>x;
            if(x==0)
            {
                cin>>xx;
                v.push_front(xx);
            }
            else if(x==1)
            {
                cin>>xx;
                v.push_back(xx);
            }
        }
        else if(input == 1)
        {
            cin>>q;
            cout<<v[q]<<endl;
        }
        else if(input == 2)
        {
            cin>>xxx;
            if(xxx == 0)
            {
                v.pop_front();
            }
            else if(xxx == 1)
            {
                v.pop_back();
            }
        }
    }
    return 0;
}



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

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

    if(1199 >= R){
        cout << "ABC" << endl;
    }
    else if(2799 >= R){
        cout << "ARC" <<endl;
    }
    else if(2800<= R){
        cout << "AGC" << endl;
    }
}


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

const int Maxn = 105;

int n;
int w[Maxn];
int res = 1000000000;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &w[i]);
    for (int i = 1; i < n; i++) {
        int sum = 0;
        for (int j = 0; j < n; j++)
            if (j < i) sum += w[j];
            else sum -= w[j];
        res = min(res, abs(sum));
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

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; }

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

ll n, k;
ll h[100010];
ll dp[100010];

void solve() {
    cin >> n >> k;
    Vl h(n);
    rep(i, 0, n) cin >> h[i];

    rep(i, 0, 100010) dp[i] = INF;
    dp[0] = 0;
    //高々O(nk)
    rep(i, 0, n){
        Rep(j, 1, k){
            if(i+j > n) break;
            chmin(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 1792
s = gets.chomp

gets.to_i.times do
  o, b, e, r = gets.split
  b, e = [b, e].map(&:to_i)
  case o
  when 'print' then puts s[b..e]  
  when 'reverse' then s[b..e] = s[b..e].reverse
  when 'replace' then s[b..e] = r
  end
end

Measured memory_bytes: 8756
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define invrep(i,n) for(int i = (int)(n); i > 0; i++)
using ll = long long;

ll m = 100;

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

    ll ans = 0;
    while(m< x) {
        m += (m / 100);
        ans++; 
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int g[20][20];
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      g[i][j]=-1;
    }
  }
  for(int i=0; i<n; i++){
    int m;
    cin >> m;
    for(int j=0; j<m; j++){
      int a, x;
      cin >> a >> x;
      a--;
      g[i][a]=x;
    }
  }
  int ans=0;
  for(int bit=0; bit<(1<<n); bit++){
    vector<int> d(n);
    for(int j=0; j<n; j++){
      if(bit>>j&1){
        d[j]=1;
      }
    }
    bool ok=true;
    for(int j=0; j<n; j++){
      if(d[j]){
        for(int k=0; k<n; k++){
          if(g[j][k]==-1) continue;
          if(g[j][k]!=d[k]) ok=false;
        }
      }
    }
    if(ok) ans = max(ans, __builtin_popcount(bit));
  }
  cout << ans << endl;
}

Measured memory_bytes: 764
# coding:utf-8

INF = float('inf')


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


N = int(input())

F = [inpl() for _ in range(N)]
P = [inpl() for _ in range(N)]

ans = -INF
for i in range(1, 1 << 10):

    score = 0
    for shop in range(N):

        both_open = 0
        for period in range(10):
            if i >> period & F[shop][period] == 1:
                both_open += 1

        score += P[shop][both_open]

    ans = max(ans, score)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 110
#define Pair pair<int,int>

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
ll INF = 1e18;
int main(){
    ll dp[110][100100] = {0};
    ll N,W; cin >> N >> W;
    ll w[105], v[105];
    for(ll i = 1; i <= N; i++) cin >> w[i] >> v[i];
    for(ll i = 1; i <= 1e5; i++) dp[0][i] = INF;

    for(ll i = 1; i <= N; i++){
        for(ll j = 0; j <= 100000; j++){
            dp[i][j] = dp[i-1][j];
            if(j - v[i] >= 0){
                dp[i][j] = min(dp[i][j], w[i]+dp[i-1][j-v[i]]);
            }
        }
    }
    ll ans = 0;
    for(ll i = 1e5; i >= 0; i--){
        if(dp[N][i] <= W){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
int n,a,b;
int main()
{
	scanf("%d",&n);
	if(n==1)
	{
		printf("Hello World");
		return 0;
	}
	if(n==2)
	{
		scanf("%d %d",&a,&b);
		printf("%d",a+b);
		return 0;
	}
}



Measured memory_bytes: 256
ans_list = []
n = int(input())

def mcxl2digit(s):
    ans = 0
    dig = 1
    for i in range(len(s)):
        if "2" <= s[i] <= "9":
            dig = int(s[i])
        else:
            if s[i] == "m":
                key = 1000
            elif s[i] == "c":
                key = 100
            elif s[i] == "x":
                key = 10
            else:
                key = 1
            ans += key * dig
            dig = 1
    return ans

def digit2mcxl(i):
    return_list = []
    m = i // 1000
    if m != 0 and m != 1:
        return_list.append(str(m))
    if m != 0:
        return_list.append("m")
    i = i % 1000

    c = i // 100
    if c != 0 and c != 1:
        return_list.append(str(c))
    if c != 0:
        return_list.append("c")
    i = i % 100

    x = i // 10
    if x != 0 and x != 1:
        return_list.append(str(x))
    if x != 0:
        return_list.append("x")
    i = i % 10

    l = i
    if l != 0 and l != 1:
        return_list.append(str(l))
    if l != 0:
        return_list.append("i")

    return return_list

for i in range(n):
    a, b = input().split()
    ans = (mcxl2digit(a) + mcxl2digit(b))
    #print(a, b, mcxl2digit(a), mcxl2digit(b))
    #print(ans)
    ans = digit2mcxl(ans)
    ans_list.append(ans)
for i in ans_list:
    print("".join(i))


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

vector<pair<int, unsigned> > evt;
vector<pair<int, int> > ran;
stack<unsigned> S;
int n, r, c;

bool bnd(int x, int y) { return (x == 0 || x == r || y == 0 || y == c); }

int ev(int x, int y)
{
	if (x == 0) return y;
	if (y == c) return c+x;
	if (x == r) return c+r+c-y;
	return c+r+c+r-x;
}

int main()
{
	scanf("%d%d%d", &r, &c, &n);
	for (int i = 0;i < n;i++)
	{
		int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if (bnd(x1, y1) && bnd(x2, y2))
		{
			ran.emplace_back(ev(x1, y1), ev(x2, y2));
			if (ran.back().first > ran.back().second) swap(ran.back().first, ran.back().second);
		}
	}
	for (unsigned i = 0;i < ran.size();i++) evt.emplace_back(ran[i].first, i), evt.emplace_back(ran[i].second, i);
	sort(evt.begin(), evt.end());
	for (auto u: evt)
		if (S.empty() || S.top() != u.second) S.push(u.second);
		else S.pop();
	if (S.size() == 0) printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int h, w;
int dp[26];
int main()
{
    cin >> h >> w;
    rep(i, h)
    {
        string s;
        cin >> s;
        rep(j, w)
        {
            dp[s[j] - 'a']++;
        }
    }
    int cnt = 0;
    int odd = 0;
    rep(i, 26)
    {
        cnt += dp[i] % 4;
        odd += dp[i] % 2;
    }
    if (h % 2 && w % 2)
    {
        cnt -= (h + w - 1);
        odd--;
    }
    else if (h % 2)
    {
        cnt -= w;
    }
    else if (w % 2)
    {
        cnt -= h;
    }
    if (odd == 0 && cnt < 0 && (-cnt) % 4 == 0)
    {
        cout << "Yes" << endl;
    }
    else if (cnt + odd)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function lower_bound(d,a,b,e){for(var c;1<b-a;)d[c=0|(a+b)/2]<e?a=c:b=c;return d[a]<e?b:a};

main();
function main(){
  var n = o.a();
  var k = o.a();
  var a = o.l();
  var map = {};
  for(var i = 0; i < n; i++){
    if(map[a[i]])map[a[i]].push(i);
    else map[a[i]] = [i];
  }
  var ans;
  var u = solve2(0);
  if(k === 1 || u === -1){
    printf(solve(0));
    return;
  }
  var first = [,u];
  for(var i = 1; i < k; i++){
    var t = first[i];
    var l = lower_bound(map[t],0,map[t].length,0);
    var u = solve2(map[t][l]+1);
    if(u === -1)break;
    first.push(u);
  }
  if(u === -1)i++;
  var q = k%i;
  if(q===0){
    if(u === -1)return;
    var t = first[i-1];
    var l = lower_bound(map[t],0,map[t].length,0);
    printf(solve(map[t][l]+1));
    return;
  }
  if(q === 1)var l = 0;else{
    var t = first[q-1];
    var l = lower_bound(map[t],0,map[t].length,0);
    l = map[t][l]+1;
  }
  printf(solve(l));

  function solve(i){
    ans = [];
    for(var j = i; j < n; j++){
      var t = a[j];
      var l = lower_bound(map[t],0,map[t].length,j+1);
      if(l !== map[t].length){
        j = map[t][l];
      }else{
        ans.push(t);
      }
    }
    return ans;
  }
  function solve2(i){
    for(var j = i; j < n; j++){
      var t = a[j];
      var l = lower_bound(map[t],0,map[t].length,j+1);
      if(l !== map[t].length){
        j = map[t][l];
      }else{
        return t;
      }
    }
    return -1;
  }
}
function printf(ar){
  if(ar.length)console.log(ar.join(" "));
}

Measured memory_bytes: 80740
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline T pow2_L(T a){
  return a*a;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int X[100];
int main(){
  int i;
  int tmp;
  int res = 1073709056;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(X[Lj4PdHRW]);
    }
  }
  for(i=(1);i<(101);i++){
    tmp = 0;
    {
      int RZTsC2BF;
      for(RZTsC2BF=(0);RZTsC2BF<((N-1) + 1);RZTsC2BF++){
        tmp +=pow2_L((X[RZTsC2BF] - i));
      }
    }
    chmin(res, tmp);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200217-1

// --- original code ---
// int N, X[100];
// {
//   int tmp, res = int_inf;
//   rd(N,X(N));
// 
//   rep(i,1,101){
//     tmp = 0;
//     tmp += (X[0..N-1] - i) ** 2;
//     res <?= tmp;
//   }
//   wt(res);
// }


Measured memory_bytes: 256
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    int ans = 0;
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    if (A + B > 2 * C) {
        int N = min(X, Y);
        ans += 2 * N * C;
        X -= N;
        Y -= N;
    }
    if (A > 2 * C) {
        ans += 2 * X * C;
        X = 0;
    }
    if (B > 2 * C) {
        ans += 2 * Y * C;
        Y = 0;
    }
    ans += X * A + Y * B;
    print(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);





signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	vector<vector<int>>g(N);
	rep(i, M) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	int one = 0, bip = 0, nbg = 0;

	vector<int>searched(N, 0);
	rep(i, N)if (searched[i] == 0) {
		if (g[i].size() == 0) {
			one++;
			continue;
		}
		bool bipartile_flag = true;
		stack<array<int,2>>dfs;
		dfs.push({ i,1 });
		while (!dfs.empty()) {
			auto x = dfs.top(); dfs.pop();
			int pos = x[0], color = x[1];
			if (searched[pos]) {
				if (searched[pos] != color) {
					bipartile_flag = false;
				}
				continue;
			}
			searched[pos] = color;
			for (int y : g[pos]) {
				dfs.push({ y,color == 1 ? 2 : 1 });
			}
		}
		if (bipartile_flag)bip++;
		else nbg++;
	}
	
	int ans = 0;
	ans += one * one;
	ans += 2 * one * (N - one);
	ans += nbg * nbg + 2 * bip * nbg + 2 * bip * bip;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12544
///------------------  CODE FOR FUN -------------------
#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i = j; i <= k; i ++)
#define FORD(i,j,k) for(int i = j; i >= k; i --)
#define mp make_pair
//#define f first
//#define s second
//#define int long long
using namespace std;

const int MOD=1e9+7;
const int N = 200005;
int x, n;
int d[150];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    #define task""
//    freopen(task".inp","r",stdin);
//    freopen(task".out","w",stdout);
    cin >> x >> n;
    FOR(i, 1, n)
    {
        int a;
        cin >> a;
        d[a] = 1;
    }
    int t = x, res = 0;
    while(1)
    {
        if(d[t] == 1) t--;
        else
        {
            res = t;
            break;
        }
    }
    t = x;
    while(1)
    {
        if(d[t] == 1) t ++;
        else
        {
            if(t - x < x - res) res = t;
            break;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3600
import bisect

def main():
    N,M,K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

    # cumsum
    A_cum = [0] * (N+1)
    B_cum = [0] * (M)
    ap = 0
    for i, a in enumerate(A_list):
        A_cum[i+1] = ap + a
        ap += a
    bp = 0
    for i, b in enumerate(B_list):
        B_cum[i] = bp + b
        bp += b

    max_cnt = 0
    for i in range(N+1):
        a = A_cum[i]
        if a > K:
            break
        bi = bisect.bisect_right(B_cum, K-a)
        max_cnt = max(max_cnt, i+bi)

    print(max_cnt)

if __name__ == "__main__":
    main()

Measured memory_bytes: 118752
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<double,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], dp[5000];
str S[200010]; bool check = true;	vector<ll> v;



int main() {
	//Code Line
   cin.tie(0); ios::sync_with_stdio(false); 
	cin >> n;
	map<str, ll> m;
	for (int i = 0; i < n; i++) {
		cin >> S[i];

		m[S[i]]++;

	}

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

		Max = max(Max, m[S[i]]);

	}

	sort(S, S + n);

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

		if (Max == m[S[i]])cout << S[i] << endl;

		m[S[i]] = 0;
	}



	return 0;
}


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

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		int arr[n];
		for (int i = 0; i < n; i++)
			cin >> arr[i];
		sort(arr, arr + n);
		int sum = 0;
		for (int i = 0; i < k; i++)
			sum += arr[i];
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		long ans = 0;
		for(int i = 0 ; i < n - 1 ; i++) {
			if(a[i] + a[i + 1] > x) {
				ans += a[i] + a[i + 1] - x;
				if(a[i] <= x) a[i + 1] = x - a[i];
				else {
					a[i + 1] = 0;
					a[i] = x;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 50704
#include <iostream>
#include <vector>
#include <cmath>

typedef long long ll;

using namespace std;

ll n;
int maxs,maxn = 50;

ll solve(int x)
{
    int cnt = 0;
    while(x)
    {
        x /= 10;
        cnt++;
    }
    return cnt;
}

int main()
{
    cin >> n;
    for (int i = sqrt(n); i >= 1; i -- )
    {
        int cnt1 = 0;
        int cnt2 = 0;

        if(n % i == 0)
        {
            cnt1 = solve(i);
            cnt2 = solve(n / i);
            maxs = max(cnt1,cnt2);
            maxn = min(maxs,maxn);
        }
    }
    cout << maxn << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  
  int a[4],i,sum;
  a[3]=0;
  sum=0;
  
  for(i=0;i<4;i++){
    scanf("%d",&a[i]);
  }
  sum=a[0]+a[1]+a[2]+a[3];
  
  printf("%d\n%d\n",sum/60,sum%60);
  
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
typedef long long ll;
using namespace std;

ll mod=1000000007, dp[2010][2010];

int main(void){
    int N, K;
    cin >> N >> K;
    for(int i=1; i<=N; ++i) dp[0][i]=0;
    dp[0][N+1]=1;
    for(int i=0; i<K; ++i){
        ll sum=0;
        for(int j=1; j<=N+1-i; ++j){
            (sum += dp[i][j]) %= mod;
        }
        for(int j=1; j<=N-i; ++j){
            dp[i+1][j]=sum;
            (sum += mod-dp[i][j]) %= mod;
        }
    }
    ll ans=(dp[K][1]+mod-dp[K-1][1])%mod;
    for(int i=1; i<N-K; ++i){
        (ans *= 2) %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31104
MOD = 10 ** 9 + 7

# def mymodBinomial(n, k, p):
# 	if k < 0 or k > n:
# 		return 0
# 	else:
# 		numerator = 1
# 		for i in range(k):
# 			numerator = (numerator * (n - i)) % p
# 		denominator = 1
# 		for i in range(1, k + 1):
# 			denominator = (denominator * i) % p
# 		return (numerator * pow(denominator, p - 2, p)) % p

def modBinomiallist(n, k, p):
	l = [0 for i in range(n)]
	for i in range(n):
		if i < k:
			l[i] = 0
		elif i == k:
			l[i] = 1
		else:
			l[i] = l[i - 1] * i * pow(i-k, p-2, p) % p
	return l


if __name__ == "__main__":
	N, K = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	# print(A)
	# l = [0]*(N + 1)
	# for i in range(1, N+1):
	# 	l[i] = mymodBinomial(i-1, K-1, MOD)
	# print(l)
	l = modBinomiallist(N, K-1, MOD)
	# print(l)
	ans = 0
	# print(l)
	for i in range(N):
		ans += (A[i] - A[N-1-i])* l[i] % MOD
	print(ans % MOD)

Measured memory_bytes: 65448
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll modinv(ll n)    { ll ans=powm(n,mod-2); return ans; }
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

int main()
{
	fast
	ll m,d;
	cin>>m>>d;
	ll ans=0;
	forn(i,1,m+1)
	{
		for(ll j=1;j*j<=i;j++)
		{
			if(i%j==0)
			{
				if(j==(i/j))
				{
					if(j>=2 && j<=9 && (j*10+j)<=d)
						ans++;
				}
				else
				{
					if(j>=2 && j<=9 && (i/j)<=9 && (i/j)>=2 && (10*j+(i/j))<=d)
						ans++;
					if(j>=2 && j<=9 && (i/j)<=9 && (i/j)>=2 && (10*(i/j)+j)<=d)
						ans++;
				}
			}
		}
	}	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	sum := 0
	for i := 1; i <= n; i++ {
		dsum := 0
		j := i
		for j > 0 {
			dsum += j % 10
			j /= 10
		}
		if a <= dsum && dsum <= b {
			sum += i
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define M 1000000007

using namespace std;
typedef long long int ll;


int main()
{
int k;
cin>>k;
int a,b;
cin>>a>>b;
bool ans =false;
for(int i=a;i<=b;i++)
{
    if(i%k==0)
    {
        ans=true;
        break;
    }
}
if(ans)
    cout<<"OK";
else
    cout<<"NG";
}


Measured memory_bytes: 3592
S=input()
Q=int(input())

states=1
front=[]
back=[]
for n in range(Q):
    query=input()
    if query=="1":
        states*=-1
    else:
        N,F,C=query.strip().split()
        if int(F)==1:
            if states==1:
                front.append(C)
            else:
                back.append(C)
        else:
            if states==1:
                back.append(C)
            else:
                front.append(C)

if states==1:
    print("".join(front)[::-1]+S+"".join(back))
else:
    print("".join(back)[::-1]+S[::-1]+"".join(front))

Measured memory_bytes: 5700
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    REP(i, 2, 50) {
        ll t = 1LL << i;
        ll cnt = 0;
        if ((A % t) >= t / 2) {
            cnt += t - (A % t);
        }
        if ((B % t) >= t / 2) {
            cnt += (B % t) - t / 2 + 1;
        }
        if (cnt % 2) {
            ans += 1LL << (i - 1);
        }
        //dump(ans);
    }
    // 1bit
    if (B - A <= 16) {
        for (ll i = A; i <= B; i++) {
            ans ^= (i % 2);
        }
    } else {
        for (int i = A % 4; i < 4; i++) {
            ans ^= (i % 2);
        }
        for (int i = 0; i <= B % 4; i++) {
            ans ^= (i % 2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int N,L,sum;
    scanf("%d %d",&N,&L);
    sum=N*(1+N)/2-N+L*N;
    if(L>=0){
        sum-=L;
        printf("%d",sum);
    }else if(-L<=N-1){
        printf("%d",sum);
    }else{
        sum-=L+N-1;
        printf("%d",sum);
    }
return 0;
}


Measured memory_bytes: 128