akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n,q;
    cin>>n>>q;
    vector<in> a(n);
        rep(i,n) cin>>a.at(i);
    vector<in> x(q);
        rep(i,q) cin>>x.at(i);
    rep(i,q){
        in ans=0;
        in sum=0;
        in migi=-1;
        rep(hidari,n){
            while(sum<=x[i]){
                migi ++;
                if(migi==n) break; 
                sum +=a[migi];
            }
            if(migi==n){
                ans +=(n-hidari)*(n-hidari+1)/2;
                break;
            }
            ans +=(migi-hidari);
            sum -=a[hidari];
        }
        cout<<ans<<endl;
    }
}/*
./problem.exe
*/


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

int main() {
    string s,t;
    cin >> s >> t;
    cout << t+s << endl;
    return 0;
}

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

typedef vector<int> vi; 
typedef pair<int,int> p;
typedef long long ll;
#define F first 
#define S second 
#define PB push_back 
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pmod 1000000007
#define INF 1000000000000000000
#define pi atan(1)*4
#define modi 1000000

ll l,r,d;

void solve(){
	
	cin >> l >> r >> d;
	
	ll res = 0;
	
	for(ll i = l; i <= r; i++){
		if(i%d == 0) res++;
	}
	
	cout << res << endl;
	
}

int main(){
	
	ifstream fin ("text.in");
    ofstream fout ("text.out");   
	
	ll t = 1;
		
	while(t--) solve();
	
	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

vector<bool> seen;
vector<int> a;
int ans = 0;

bool dfs(int n)
{
    ans++;
	if(a[n-1] == 2) return true;
	if(seen[n-1]) return false;
	seen[n-1] = true;
	return dfs(a[n-1]);
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	seen.resize(n,false);
	a.resize(n);
	rep(i, n) cin >> a[i];

	cout << (dfs(1) ? ans : NIL) << endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
	int n,m;
	int i,j,k;
	int cups[3][16];
	int cup[3][16];
	int temp;
	int move[2];
	int moves[2];
	int min;
	int ccups[3];
	scanf("%d %d",&n,&m);
	while(n && m){
		for(i=0;i<3;i++){
			scanf("%d",&cups[i][0]);
			cup[i][0] = cups[i][0];
			for(j=1;j<cups[i][0]+1;j++){
				scanf("%d",&cups[i][j]);
				cup[i][j] = cups[i][j];
			}
		}
		if(cups[0][0] == n || cups[2][0] == n){
			printf("0\n");
		}else{
			move[0] = -1;
			move[1] = -1;
			moves[0] = -1;
			moves[1] = -1;
			min = -1;
			for(i=1;i<m+1;i++){
				ccups[0] = cups[0][cups[0][0]];
				ccups[1] = cups[1][cups[1][0]];
				ccups[2] = cups[2][cups[2][0]];
				if(ccups[0] > ccups[1] && (move[0] != 1 || move[1] != 0)){
					cups[1][cups[1][0]+1] = ccups[0];
					cups[0][0]--;
					cups[1][0]++;
					move[0] = 0;
					move[1] = 1;
				}else if(ccups[1] > ccups[2] && (move[0] != 2 || move[1] != 1)){
					cups[2][cups[2][0]+1] = ccups[1];
					cups[1][0]--;
					cups[2][0]++;
					move[0] = 1;
					move[1] = 2;
				}else if(ccups[2] > ccups[1] && (move[0] != 1 || move[1] != 2)){
					cups[1][cups[1][0]+1] = ccups[2];
					cups[2][0]--;
					cups[1][0]++;
					move[0] = 2;
					move[1] = 1;
				}else if(ccups[1] > ccups[0] && (move[0] != 0 || move[1] != 1)){
					cups[0][cups[0][0]+1] = ccups[1];
					cups[1][0]--;
					cups[0][0]++;
					move[0] = 1;
					move[1] = 0;
				}
				if(cups[0][0] == n || cups[2][0] == n){
					min = i;
					break;
				}
				ccups[0] = cup[0][cup[0][0]];
				ccups[1] = cup[1][cup[1][0]];
				ccups[2] = cup[2][cup[2][0]];
				if(ccups[1] > ccups[0] && (moves[0] != 0 || moves[1] != 1)){
					cup[0][cup[0][0]+1] = ccups[1];
					cup[1][0]--;
					cup[0][0]++;
					moves[0] = 1;
					moves[1] = 0;
				}else if(ccups[2] > ccups[1] && (moves[0] != 1 || moves[1] != 2)){
					cup[1][cup[1][0]+1] = ccups[2];
					cup[2][0]--;
					cup[1][0]++;
					moves[0] = 2;
					moves[1] = 1;
				}else if(ccups[1] > ccups[2] && (moves[0] != 2 || moves[1] != 1)){
					cup[2][cup[2][0]+1] = ccups[1];
					cup[1][0]--;
					cup[2][0]++;
					moves[0] = 1;
					moves[1] = 2;
				}else if(ccups[0] > ccups[1] && (moves[0] != 1 || moves[1] != 0)){
					cup[1][cup[1][0]+1] = ccups[0];
					cup[0][0]--;
					cup[1][0]++;
					moves[0] = 0;
					moves[1] = 1;
				}
				if(cup[0][0] == n || cup[2][0] == n){
					min = i;
					break;
				}
			}
			printf("%d\n",min);
		}
		scanf("%d %d",&n,&m);
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int dy[][4] = {{0, 0, 1, 1}, {0, 0, 2, 2}};
const int dx[][4] = {{0, 2, 0, 2}, {0, 1, 0, 1}};

int h, w;
vector<vector<bool> > used;
vector<vector<int> > corner;

int solve(int y, int x)
{
    if(x > w){
        ++ y;
        x = 1;
        if(y > h)
            return 1;
    }

    if(used[y][x])
        return solve(y, x+1);

    int ret = 0;
    for(int j=0; j<2; ++j){
        if(!used[y+j][x+(j^1)]){
            bool ok = true;
            used[y][x] = used[y+j][x+(j^1)] = true;
            for(int i=0; i<4; ++i){
                if(++ corner[y+dy[j][i]][x+dx[j][i]] == 4)
                    ok = false;
            }
        
            if(ok)
                ret += solve(y, x+1);

            for(int i=0; i<4; ++i)
                -- corner[y+dy[j][i]][x+dx[j][i]];
            used[y][x] = used[y+j][x+(j^1)] = false;
        }
    }

    return ret;
}

int main()
{
    for(;;){
        cin >> h >> w;
        if(h == 0)
            return 0;

        used.assign(h+2, vector<bool>(w+2, true));
        for(int y=1; y<=h; ++y){
            for(int x=1; x<=w; ++x){
                used[y][x] = false;
            }
        }
        corner.assign(h+2, vector<int>(w+2, 0));

        cout << solve(1, 1) << endl;
    }
}

Measured memory_bytes: 1240
#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int b,r,g,c,s,t;
	while(cin >> b >> r >> g >> c >> s >> t, (b||r||g||c||s||t)) {
		int lost=0, gain=0;
		lost += (t-s-5*b-3*r)*3;
		gain += 15*(b+r)+(5*b+3*r)*13+g*7+c*2;
		cout << 100-lost+gain << endl;
	}
}

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

int main(void)
{
	int K;

	cin >> K;

	int i[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	
	cout << i[K - 1] << endl;
}

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

int main(){

int n;
scanf("%d",&n);

long debt=100000;

for(int i=0;i<n;i++)
	debt=(long)(ceil(debt*1.05/1000.0))*1000;

printf("%ld\n",debt);

return 0;		
}

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

int main() {
    int a[3];
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    for (int i = 2; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if (a[j] > a[j+1]) {
                int tmp = a[j];
                a[j] = a[j+1];
                a[j+1] = tmp;
            }
        }
    }
    printf("%d %d %d\n", a[0], a[1], a[2]);
    return 0;
}


Measured memory_bytes: 3156
#include <stdio.h>
int f(int x){
  return x*x;
}
int main(){
  int sum=0;
  int d;
  int i;
  while(scanf("%d",&d)!=EOF){
    sum=0;
    for(i=d;i<600;i+=d){
      sum+=d*f(i);
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 596
#E
import sys
input=sys.stdin.readline

def main():
    n,m=map(int,input().split())
    Cost=[0]*m
    Key=[0]*m
    for i in range(m):
        a,b=map(int,input().split())
        C=tuple(map(int,input().split()))
        Cost[i]=a
        for c in C:
            Key[i]+=1<<(c-1)
    #print(Cost,Key)
    DP=[[float('inf')]*(1<<n) for _ in range(m+1)]
    for i,(c,k) in enumerate(zip(Cost,Key)):
        DP[i+1][k]=min(DP[i][k],c)
        for j in range(1,1<<n):
            DP[i+1][j]=min(DP[i][j],DP[i+1][j])
            DP[i+1][j|k]=min(DP[i+1][j|k],DP[i][j|k],DP[i][j]+c)
        #print(DP)
    print(-1 if DP[-1][-1]==float('inf') else DP[-1][-1])

if __name__=='__main__':
    main()

Measured memory_bytes: 145756
using System;

namespace d
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            char[][] map = new char[100][];

            for (int i = 0; i < 100; i++)
            {
                map[i] = new char[100];
                for (int j = 0; j < 100; j++)
                {
                    map[i][j] = i < 50 ? '.' : '#';
                }
            }

            for (int i = 0; i < b - 1; i++)
            {
                map[2 * (i / 50)][2 * (i % 50)] = '#';
            }

            for (int i = 0; i < a - 1; i++)
            {
                map[51 + 2 * (i / 50)][2 * (i % 50)] = '.';
            }

            Console.WriteLine("100 100");
            Array.ForEach(map, c =>
            {
                Array.ForEach(c, c1 => { Console.Write(c1); });
                Console.WriteLine();
            });
        }
    }
}

Measured memory_bytes: 13268
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
;; Scheme-style named let
(defmacro nlet (name args &body body)
  (labels ((ensure-list (x) (if (listp x) x (list x))))
    (let ((args (mapcar #'ensure-list args)))
      `(labels ((,name ,(mapcar #'car args) ,@body))
         (,name ,@(mapcar #'cadr args))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(define-condition vacance () ())

(defun main ()
  (let* ((n (read))
         (table (make-array n :element-type 'bit :initial-element 0)))
    (labels ((query (pos)
               (println pos)
               (let ((answer (read-line)))
                 (cond ((string= answer "Male")
                        (setf (aref table pos) 1))
                       ((string= answer "Female")
                        (setf (aref table pos) 0))
                       ((string= answer "Vacant")
                        (signal 'vacance))
                       (t (error "Huh?"))))))
      (handler-bind ((vacance (lambda (c) (return-from main))))
        (query 0)
        (nlet bisect ((l 0) (r n))
          (let ((mid (ash (+ l r) -1)))
            (query mid)
            (if (evenp (- mid l))
                (if (= (aref table l) (aref table mid))
                    (bisect mid r)
                    (bisect l mid))
                (if (= (aref table l) (aref table mid))
                    (bisect l mid)
                    (bisect mid r)))))))))

#-swank(main)


Measured memory_bytes: 23220
n,c=map(int,input().split())


kyori=[0]*(n+2)
kyori[n+1]=c
calo=[0]*(n+2)
ans=[0]
tmp=0

for i in range(1,n+1):
    x,v=map(int,input().split())
    kyori[i]=x
    calo[i]=v
    tmp+=v-(x-kyori[i-1])
    ans.append(tmp)


tmp=0
for i in range(n):
    tmp+=calo[-2-i] - (kyori[-1-i]-kyori[-2-i])
    ans.append(tmp)


i=1
rmax=0
tmpmax=0
tmp=0
while(2*kyori[i]< c and i<=n):
    tmp+=calo[i]-2*(kyori[i] -kyori[i-1])
    if(tmpmax<tmp):
        tmpmax=tmp
        rmax=i
    i+=1


tmp=0
tmpmax_max=0
i=0
while(rmax < -i+n):
    tmp+=calo[-2-i] - (kyori[-1-i] - kyori[-2-i])
    if(tmpmax_max<tmp):
        tmpmax_max=tmp
    i+=1
ans.append(tmpmax+ tmpmax_max)


now=tmpmax+ tmp
for i in range(rmax):
    tmpmax+= -calo[rmax-i]+2*(kyori[rmax-i] - kyori[rmax-i-1])
    tmp+=calo[rmax-i] -(kyori[rmax+1-i]-kyori[rmax-i])
    if(tmpmax_max<tmp):
        tmpmax_max=tmp
    ans.append(tmpmax+tmpmax_max)




i=0
lmax=0
tmpmax=0
tmp=0
while(2*kyori[-2-i] > c and i<n):
    tmp+=calo[-2-i]-2*(kyori[-1-i] -kyori[-2-i])
    if(tmpmax<tmp):
        tmpmax=tmp
        lmax=-i+n
    i+=1
if(lmax==0):
    lmax=n+1
tmp=0
tmpmax_max=0
i=1
while(i < lmax):
    tmp+=calo[i] - (kyori[i] - kyori[i-1])
    if(tmpmax_max <tmp):
        tmpmax_max=tmp
    i+=1

ans.append(tmpmax+ tmpmax_max)



now=tmpmax+ tmp
for i in range(n-lmax):
    tmpmax+= -calo[lmax+i]+2*(kyori[lmax+i+1] - kyori[lmax+i])
    tmp+=calo[lmax+i] -(kyori[lmax+i]-kyori[lmax+i-1])
    if(tmpmax_max<tmp):
        tmpmax_max=tmp
    ans.append(tmpmax+tmpmax_max)





print(max(ans))

Measured memory_bytes: 25140
#include <stdio.h>

int main(void)
{
    int sx, sy, tx, ty;
    scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
    int i;
    int w = tx - sx;
    int h = ty - sy;
    // first turn
    for (i = 1; i <= w; i++)    putchar('R');
    for (i = 1; i <= h; i++)    putchar('U');
    // second turn
    for (i = 1; i <= w; i++)    putchar('L');
    for (i = 1; i <= h; i++)    putchar('D');
    // third turn
    putchar('D');
    for (i = 1; i <= w + 1; i++)    putchar('R');
    for (i = 1; i <= h + 1; i++)    putchar('U');
    putchar('L');
    // fourth turn
    putchar('U');
    for (i = 1; i <= w + 1; i++)    putchar('L');
    for (i = 1; i <= h + 1; i++)    putchar('D');
    putchar('R');
    putchar('\n');
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {    
    
   public static void main(String[] args){
       
    Scanner sc = new Scanner(System.in);
    
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();

    int first  = A*B;
    int second = C*D;
    
    if(first == second){
        System.out.println(first);
    }else if(first > second){
        System.out.println(first);
    }else if(second > first){
        System.out.println(second);
    }  
    
  }
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for(int i=0; i<M; i++){
    cin >> s[i] >> c[i];
  }
  string str(N, '0');
  str[0]='1';
  int start=stoi(str);
  str+='0';
  int end=stoi(str);
  if(N==1) start=0;
  for(int i=start; i<end; i++){
    bool x=true;
    string check=to_string(i);
    for(int j=0; j<M; j++){
      if (check[s[j]-1]!=c[j]+'0'){
        x=false;
        break;
      }
    }
    if (x==true){
      cout << i <<endl;
      return 0;
    }
  }
  cout << -1 <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <set>
#include <string>

using namespace std;

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

	cin >> n;

	set<string> s;

	for (uint32_t i = 0; i < n; i++) {
		string tmp;
		cin >> tmp;
		s.insert(tmp);
	}

	cout << s.size() << endl;

	return 0;
}


Measured memory_bytes: 19224
#include <stdio.h>

int main() {
	int A, B, M, a[100000], b[100000], c[100000], x[100000], y[100000];
	int mina = 100000, minb = 100000, wa[100000], ans;
	scanf("%d%d%d",&A,&B,&M);
	for (int i = 0; i < A;i++) {
		scanf("%d",&a[i]);
		if (mina > a[i]) {
			mina = a[i];
		}
	}
	for (int i = 0; i < B; i++) {
		scanf("%d", &b[i]);
		if (minb > b[i]) {
			minb = b[i];
		}
	}
	ans = mina + minb;
	for (int i = 0; i < M; i++) {
		scanf("%d%d%d", &x[i], &y[i], &c[i]);
		wa[i] = a[x[i]-1] + b[y[i]-1] - c[i];
		if (wa[i] < ans) {
			ans = wa[i];
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2176
// Gaurav Aggarwal
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif  

    ll n;
    cin>>n;

    ll ans = 1e17;

    for(int i=1;i<=sqrt(n);++i) {

        if(n%i == 0) {

            ll o = n/i;

            ans = min(ans, o + i - 2);

        }

    }

    cout<<ans<<"\n";

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int len = s.size();
  int ct = 0;
  for(int i=0; i<len / 2; i++) {
    if(s[i] != s[len - i - 1]) { ct ++; }
  }

  cout << ct << endl;
  return 0;
}


Measured memory_bytes: 256
def LI(): return list(map(int,input().split()))
N,K = LI()
a = LI()
ans = float('INF')
for i in range(2**(N-1)):
    bit = [i>>j&1 for j in range(N-1)]
    if K-1!=sum(bit):
        continue
    temp,kijun = 0,a[0]
    for k in range(N-1):
        if bit[k]==0:
            kijun = max(kijun,a[k+1])
        else:
            if a[k+1]>=kijun+1:
                kijun = a[k+1]
                continue
            temp += (kijun+1)-a[k+1]
            kijun += 1
    ans = min(ans,temp)
print(ans)


Measured memory_bytes: 3064
S = list(input())
T = list(input())
s_appeared = [0] * 26
t_appeared = [0] * 26
for i in range(len(S)):
    if S[i] != T[i]:
        s_temp = s_appeared[ord(S[i])-97]
        if s_temp == 0:
            s_appeared[ord(S[i])-97] = T[i]
        else:
            if T[i] != s_temp:
                print('No')
                break

        t_temp = t_appeared[ord(T[i])-97]
        if t_temp == 0:
            t_appeared[ord(T[i])-97] = S[i]
        else:
            if S[i] != t_temp:
                print('No')
                break
    else:
        s_appeared[ord(S[i])-97] = T[i]
        t_appeared[ord(T[i])-97] = S[i]
else:
    print('Yes')

Measured memory_bytes: 6704
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read()
{
    ll 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-'0';ch=getchar();}
    return x*f;
}
const int MN=1e5+5;
ll N,C,X[MN],W[MN];
ll p1,p2,s1,s2,p1m[MN],p2m[MN],s1m[MN],s2m[MN];
int main()
{
	N=read(),C=read();
	int i;
	for(i=1;i<=N;++i) X[i]=read(),W[i]=read();
	X[N+1]=C;
	for(i=1;i<=N;++i){
		p1+=W[i]+X[i-1]-X[i];
		p2=p1-X[i];
		p1m[i]=max(p1m[i-1],p1);
		p2m[i]=max(p2m[i-1],p2);
	}
	for(i=N;i;--i){
		s1+=W[i]-X[i+1]+X[i];
		s2=s1-C+X[i];
		s1m[i]=max(s1,s1m[i+1]);
		s2m[i]=max(s2,s2m[i+1]);
	}
	ll ans=0;
	for(i=1;i<=N;++i)
		ans=max(p2m[i]+s1m[i+1],ans),ans=max(p1m[i],ans);
	for(i=1;i<=N;++i)
 		ans=max(s2m[i]+p1m[i-1],ans),ans=max(s1m[i],ans);
	printf("%lld\n",ans);
 	return 0;
}

Measured memory_bytes: 8420
N = int(input())

X = list(map(int, input().split()))
sum_X = sum(X)

ans = 0
tmp1 = 0
tmp2  = 0

if sum_X % N == 0:
    mean = sum_X // N
    for i in range(N):
       ans += (mean-X[i]) ** 2

else:
    mean1 = sum_X // N
    mean2 = -(-sum_X//N)
    for i in range(N):
      tmp1 += (mean1-X[i]) ** 2
      tmp2 += (mean2-X[i]) ** 2
    if tmp1 <= tmp2:
        ans = tmp1
    else:
        ans = tmp2  
print(ans) 

Measured memory_bytes: 3316
n = int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
ans=0
for i in range(n):
    if A[i]<B[i]:
        ans+=A[i]
        tmp = min(B[i]-A[i], A[i+1])

        A[i+1]-=tmp
        ans+=tmp
    else:
        ans+=B[i]

print(ans)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 200010;

int father[N];

bool isRoot[N];

int findFather(int x) {

	if (x == father[x]) return x;

	int fa = findFather(father[x]);

	father[x] = fa;

	return fa;

}
//并查集的合并操作 
void Union(int x, int y) {

	int fax = findFather(x);

	int fay = findFather(y);

	if (fax != fay)

		//两者的根节点不一样才进行合并操作

		father[fax] = fay;

}
void init(int n) {

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

		father[i] = i;

		isRoot[i] = false;

	}

}



int main(void) {

	int n, m, a, b;

	scanf("%d%d", &n, &m);

	init(n);
	map<int, map<int, int> > ma;
	for (int i = 0; i < m; ++i) {

		scanf("%d%d", &a, &b);
		if (a>b)swap(a, b);
		if (ma.count(a) && ma[a].count(b))continue;
		ma[a][b]++;
		Union(a, b);
	}
	map<int, int> cnt;
	for (int i = 0; i < n; ++i) {

		//isRoot[findFather(i + 1)] = true;
		cnt[findFather(i + 1)]++;
	}

	int ans = 0;
	for (auto v : cnt) {
		ans = max(ans, v.second);
	}

	printf("%d\n", ans);

}



Measured memory_bytes: 38992
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

using namespace std;

typedef long long ll;

typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const ll inf=100000000000000;
struct edge{
	int to,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 100002
int dp[60][MAX_N]={};
int rdp[60][MAX_N]={};
int d[MAX_N]={};
//bool d[MAX_N]={};
int pa[MAX_N];

vector<int> G[MAX_N];

vector<int> child[MAX_N];
vector<int> ra[MAX_N];
priority_queue<P2,vector<P2>,greater<P2>> que2;
queue<pos> que;
vector<int> vec;
int main() {

	int n,q,l;
	cin>>n;
	rep(i,n){
		int x1;
		cin>>x1;
		vec.push_back(x1);
	}
	int a2[32]={};
	a2[0]=1;
	rep(i,31)a2[i+1]=2*a2[i];

	memset(dp,-1,sizeof(dp));
	memset(rdp,-1,sizeof(rdp));
	cin>>l>>q;
	rep(i,n){
		auto it=upper_bound(vec.begin(),vec.end(),vec[i]+l);
		dp[0][i]=it-vec.begin()-1;
//		cout<<dp[0][i]<<endl;
	}
	rrep(i,n){
		auto it=lower_bound(vec.begin(),vec.end(),vec[i]-l);
		rdp[0][i]=it-vec.begin();
//		cout<<rdp[0][i]<<endl;
	}
	rep(j,31){
		rep(i,n){
			dp[j+1][i]=dp[j][dp[j][i]];
			rdp[j+1][i]=rdp[j][rdp[j][i]];
//			cout<<j+1<<" "<<i+1<<" "<<rdp[j+1][i]+1<<endl;
		}
	}

	rep(i,q){
		int a1,b1;
		cin>>a1>>b1;
		a1--;
		b1--;
		int t=0;
		if(a1<b1){
			rrep(j, 31){
				if(dp[j][a1]<b1){
					t+=a2[j];
					a1=dp[j][a1];
				}
//			cout<<t<<endl;
			}
			if(a1<b1)t++;
		}else{
			rrep(j, 31){
				if(rdp[j][a1]>b1){
					t+=a2[j];
					a1=rdp[j][a1];
				}
//			cout<<t<<endl;
			}
			if(a1>b1)t++;
		}

		cout<<t<<endl;
	}
	return 0;

}





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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	vector <int> a(n),b(n),c(n);
	for (int i = 0; i < n; ++i){
		cin >> a[i] >> b[i] >> c[i];
	}
	vector <vector<int>> dp(n,vector<int>(3));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; ++i){
		dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c[i];	
	}	
	cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]) << "\n";	
	return 0;
}


Measured memory_bytes: 9784
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

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

int main() {

	int R;
	cin >> R;

	double ans = 3.14 * R * 2.0f;

	cout << ans << endl;

}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  swap(a,b);
  swap(a,c);
  cout<<a<<" "<<b<<" "<<c<<endl;
}

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


Measured memory_bytes: 3076
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

set<ll> filter(set<ll> a, set<ll> b){
    set<ll> s = {};
    for (auto itr = a.begin(); itr != a.end(); ++itr) {
        ll t = *itr;
        if(b.find(t) != b.end()){
            s.insert(t);
        }
    }
    return s;
}

ll reduce(set<ll> a){

    if(a.size() == 0){
        return 0;
    }
    auto r = * a.begin();
    for (auto itr = a.begin(); itr != a.end(); ++itr) {
        r = r & *itr;
    }
    return r;

}

ll ppow(ll a, ll b){
    if(b == 0){
        return 1;
    }
    return a * ppow(a, b-1);
}

int main() {
    ll N, K;
    vector<ll> A;
    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        A.push_back(a);
    }

    map<ll, ll> S;

    for (int i = 0; i < N; ++i) {
        for (int j = i; j < N; ++j) {
            ll x = 0;
            for (int k = i; k <= j; ++k) {
                x += A[k];
            }
            if(S.find(x) == S.end()){
                S[x] = 1;
            }else{
                S[x] += 1;
            }
        }
    }

    ll r = 0;
    for (int i = 40; i >= 0; --i) {
        ll count = 0;
        for (auto itr = S.begin(); itr != S.end(); ++itr) {
            ll n = itr->first;
            ll n2 = itr->second;
            ll r2 = r + ppow(2, i);
            ll rx = r2 & n;
            //cout << "r2: " << r2 << " n : " << n << " r2&n: " << rx << endl;
            if(rx == r2){
                //cout << "r2: " << r2 << " n : " << n << " r2&n: " << rx << endl;
                count += n2;
            }
        }
        if(count >= K){
            r += ppow(2, i);
        }
    }

    cout << r << endl;

    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

int A[2][101];
int cumA0[101];
int cumA1[101];

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

    REP0(i, N)
    {
        cin >> A[0][i];
        cumA0[i] = (i == 0) ? A[0][i] : cumA0[i - 1] + A[0][i];
    }

    REP0(i, N)
    {
        cin >> A[1][i];
    }

    cumA1[N - 1] = A[1][N - 1];
    for (int i = N - 2; i >= 0; i--)
    {
        cumA1[i] = cumA1[i + 1] + A[1][i];
    }

    int ans = 0;

    REP0(i, N)
    {
        ans = max(ans, cumA0[i] + cumA1[i]);
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-30;
const double INF = 1e12;

long double to_deg(long double r) {
    return r * 180.0 / (atan(1.0) * 4.0);
}
int main(){
	int a,b;
	while(cin>>a>>b){
		cout<<SZ(toString(a+b))<<endl;
	}
	return 0;
}

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

int main() {
	
	int a[5];
	int k;
	rep(i, 5) cin >> a[i];
	cin >> k;
	
	for(int i=0; i<5; i++){
		if(a[i] - a[0] > k){
			puts(":(");
			return 0;
		}
	}
	puts("Yay!");
	return 0;
}

Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())

ax = a * math.cos(math.radians(h*30 + m/2))
ay = a * math.sin(math.radians(h*30 + m/2))
bx = b * math.cos(math.radians(6*m))
by = b * math.sin(math.radians(6*m))
print(math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by)))


Measured memory_bytes: 9568
a= int(input())
b_list = input().split()
for i in range(a):
    b = int(b_list[i])
    if b%2 == 0:
        if b % 3 == 0 or b%5 == 0:
            d =0
        else:
            print('DENIED')
            break
    if (a-1) == i:
        print('APPROVED')

Measured memory_bytes: 3060
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n,k;
  cin >> n >> k;

  int ans = 0;

  ans = k * pow(k - 1,n - 1);

  cout << ans << endl;
  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, M;
  cin >> N >> M;
  int ret = (100 * (N - M) + 1900 * M) << M;
  cout << ret << endl;
  return 0;
}



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

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		String s = sc.next();

		int min = 114514;

		for (int i = 0; i < s.length(); i++) {
			int count = 0;
			char c = s.charAt(i);
			char[] cs = s.toCharArray();
			while (!isSingle(cs)) {
				cs = convert(cs, c);
				count++;
			}
			min = Math.min(min, count);
		}

		out.println(min);
		out.flush();
	}

	static char[] convert(char[] s, char c) {
		char[] cs = new char[s.length - 1];
		for (int i = 0; i < s.length - 1; i++) {
			if (s[i + 1] == c) {
				cs[i] = c;
			} else {
				cs[i] = s[i];
			}
		}
		return cs;
	}

	static boolean isSingle(char[] s) {
		for (int i = 1; i < s.length; i++) {
			if (s[i - 1] != s[i]) return false;
		}
		return true;
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) { return false; }
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) { throw new NumberFormatException(); }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public long nextLong() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		long n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) { throw new NumberFormatException(); }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 22612
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
 
int main() {
    int n;
    long long a[200200];
    long long sum=0;
    cin>>n;
    REP(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    long long s=0;
    REP(i,n){
        s+=a[i];
        if(s>=sum/2){
            cout<<min(sum-(s-a[i])*2,2*s-sum)<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
int N,a,k,x;
scanf("%d",&N);
  a=0;
  for(int i=1;i<=N;i++){
    x=i;
    k=0;
    while(x>=1){
      k++;
      x=x/10;
    }
    if(k%2==1)
      a++;
  }
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 128
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_4-D: Allocation
 
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <vector>
using namespace std;
 
using uint = unsigned int;
 
static bool is_loaded(uint max_load, uint num, const vector<uint>& ws)
{
  const auto last = ws.end();
  auto it = ws.begin();
  for (auto i = 0u; i < num; ++i) {
    auto capacity = max_load;
    while (it < last && *it <= capacity) {
      capacity -= *it++;
    }
    if (it == last) return true;
  }
  return false;
}
 
static uint min_load_capacity(uint num, const vector<uint>& ws)
{
  const auto ws_sum = accumulate(ws.begin(), ws.end(), 0u);
  const auto max_w = *max_element(ws.begin(), ws.end());
 
  auto left = max(max_w, (ws_sum-1)/num+1);
  auto right = ws_sum;
  while (left < right) {
    const auto middle = (left+right)/2;
    if (is_loaded(middle, num, ws)) {
      right = middle;
    } else {
      left = middle+1;
    }
  }
  return right; // right == left;
}
 
int main()
{
  uint n, k;
  scanf("%u %u", &n, &k);
 
  vector<uint> ws(n);
  for (auto i = 0u; i < n; ++i) {
    scanf("%u", &ws[i]);
  }
 
  auto c = min_load_capacity(k, ws);
  printf("%u\n", c);
}
 
// eof

Measured memory_bytes: 2760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define mp make_pair
#define ins insert
#define sz size
#define whoami(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); whi(_it, args); }

void whi(istream_iterator<string> it) { cerr<<"\n"; }

template<typename T, typename... Args>
void whi(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<" "<<a<<" "; whi(++it, args...); }

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed); cerr.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;
const ll INF = 4e18;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	string s;
	cin>>s;
	for(auto &&u : s)
	{
		if(u == '?')
		u = 'D';	
	}
	cout<<s<<"\n";
	return;
}

int main(void)
{
	FLASH();
	//freopen("cowjog.in", "r", stdin);
	//freopen("cowjog.out", "w", stdout);
	int T;
	T = 1;

#ifndef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	//cin>>T;
	while(T--)
	solve(T);

#ifndef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cerr<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}

Measured memory_bytes: 3776
def solve(N, A, B):
    d1 = A - 1
    d2 = B - A - 1
    d3 = N - B

    if d2 % 2 == 1:
        return "Alice"
    else:
        return "Borys"
        # if d1 == 0 and d2 == 0:
        # if d1 % 2 == 0 and d3 % 2 == 0:
        #     return "Borys"
        # else:
        #     return "Draw"


if __name__ == "__main__":
    N, A, B = tuple(map(int, input().split(" ")))
    print(solve(N, A, B))


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(ll i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cerr.tie(0);
	ll a,b;
	cin>>a>>b;
	cout<<b*2-a<<Endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,k;
  	ci(n>>k)
  vll A(n);
  FOR(i,0,n){
    ci(A[i])
  }
  SORT(A);
  ll ans=0;
  FOR(i,0,n-1){
    if(k>=A[i]){
      k-=A[i];
      ans++;
    }
    else{
      break;
    }
}
  if(k!=A[n-1]){
    co(ans)
  }
  else{
    co(ans+1)
  }
}

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

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> L(n);
    vector<int> R(n);
    for(int i=0; i<q; i++){
        cin >> L[i] >> R[i];
    }

    vector<int> at(n+1);
    at[0] = 0;
    at[1] = 0;
    for(int i=2; i<n+1; i++){
        string ss = s.substr(i-2, 2);
        if(ss == "AC"){
            at[i] = at[i-1] + 1;
        }else{
            at[i] = at[i-1];
        }
    }
    for(int i=0; i<q; i++){
        int ans;
        ans = at[R[i]] - at[L[i]];
        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 2176