akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Union Find tree
//-------------------------------------------------
class UnionFind
{
private:
    ::std::vector<int> par;
    ::std::vector<int> rank;
public:
    UnionFind(int n):par(n), rank(n){
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x] = root(par[x]);
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx==ry) return;
        if (rank[rx]>rank[ry]){
            par[ry] = rx;
        }else{
            par[rx] = ry;
            if (rx==ry) rank[ry]++;
        }
    }
};

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<pi> X(n),Y(n);
    rep(i,n){
        int x,y; cin>>x>>y;
        X[i] = mp(x,i);
        Y[i] = mp(y,i);
    }
    sort(all(X));
    sort(all(Y));
    using edge = tuple<int,int,int>;
    vector<edge> es;
    rep(i,n-1) es.emplace_back(X[i+1].fi-X[i].fi, X[i].se, X[i+1].se);
    rep(i,n-1) es.emplace_back(Y[i+1].fi-Y[i].fi, Y[i].se, Y[i+1].se);
    sort(all(es));
    UnionFind uf(n);
    ll ans=0;
    for(auto e:es){
        int cost,from,to;
        tie(cost,from,to) = e;
        if (uf.same(from,to)) continue;
        uf.unite(from,to);
        ans+=cost;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 6516
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
vector<int> G;
int m;

bool check(int v)
{
  int cnt = 0;
  int sum = 0;
  rep(i,G.size())
    {
      if(G[i] > v)return false;
      sum += G[i];
      if(sum > v)
	{
	  sum = G[i];
	  cnt++;
	}
    }
  return cnt < m;
}

int main()
{
  int n;
  while(cin >> m >> n,m|n)
    {
      G.resize(n);
      rep(i,n)cin >> G[i];
      //check(1799);
      //return 0;
      int L = 0;
      int R = 1500000;
      int M;
      rep(j,100)
	{
	  M = (L+R)/2;
	  if(!check(M))
	    L = M;
	  else
	    R = M;	      
	}
      cout << R << endl; 
    }
  return 0;
}

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

int main() {
  string t;
  cin>>t;
  int count_d=0;
  int count_pd=0;
  for(int i=0;i<t.size();i++){
    if(t[i]=='?')t[i]='D';
  }
  for(int i=0;i<t.size();i++){
    if(t[i]=='D')count_d++;
    else if(i!=t.size()-1&&t[i]=='P'){
      if(t[i+1]=='D')count_pd++;
    }
  }
  int kotae=count_d+count_pd;
  cout<<t<<endl;
  return 0;
}
  

Measured memory_bytes: 3720
n=int(input())
l=[0]*(10**5)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            l[(x*x+y*y+z*z+x*y+y*z+z*x)-1]+=1
for i in range(n):
    print(l[i])

Measured memory_bytes: 9780
package main

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

func main() {
	const m = 1000000007

	N := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	result := 0
	for bit := 0; bit < 60; bit++ {
		bitSum := 0
		for i := 0; i < N; i++ {
			bitSum += A[i] & 1 // bitSum <= 3 * 10^5
			A[i] >>= 1
		}

		t := bitSum * (N - bitSum) // t <= 2.25 * 10^10
		t %= m
		t *= (1 << uint(bit)) % m
		t %= m

		result += t
		result %= m
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 9088
a,b,c,d = map(int, input().split())
#sを(0,0)にする
#s = (a + (0 - a), b + (0 - b))
#g = (c + (0 - a), d + (0 - b))
s = (a, b)
g = (c, d)

route = []

#turn1 ->g
route.append('R' * (g[0] - s[0]))
route.append('U' * (g[1] - s[1]))
#turn1 ->s
route.append('L' * (g[0] - s[0]))
route.append('D' * (g[1] - s[1]))
#turn2 ->g
route.append('D')
route.append('R' * (g[0] - s[0] + 1))
route.append('U' * (g[1] - s[1] + 1))
route.append('L')
#turn2 ->s
route.append('U')
route.append('L' * (g[0] - s[0] + 1))
route.append('D' * (g[1] - s[1] + 1))
route.append('R')


route = "".join(route)
print(route)

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

using namespace std;
#define sz(x) (int)(x).size()
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ll long long

const int N=3e5+5;

ll ans;

int m,n;

struct comp{
bool operator()(const pair<int,int> &a,const pair<int,int> &b){
    if (a.second>b.second)
            return true;
        if(b.second>a.second)
           return false;
        return a.first<b.first;
    }
};

pair<int,int> a[N];

int main(){ 
    scanf("%d %d",&n,&m);
    priority_queue<pair<int,int>,vector<pair<int,int> >,comp > curr;
    priority_queue<pair<int,int>,vector<pair<int,int> > > pq;
    for(int i=0;i<n;i++){
        scanf("%d %d",&a[i].first,&a[i].second);
        if (a[i].first<=m)
            pq.push(a[i]);
    }
    int last=m+1;
    while(!pq.empty()){
        pair<int,int> x=pq.top();
        pq.pop();
        if (x.first<last){
            curr.push(x);
            last--;
        }
        else{
            int y=curr.top().second;
            if (x.second>y){
                curr.pop(),curr.push(x);
            }
        }
    }
    while(!curr.empty()){
        ans+=curr.top().second;
        curr.pop();
    }
    printf("%lld\n",ans);
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  if ( n % 2 == 0){
    string former = s.substr(0, n/2);
    string latter = s.substr(n/2,n/2);
    if (former == latter){
      cout << "Yes" << endl;
    } else {
       cout << "No" << endl;
    }

  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=100005;
#define M 1000000007
#define double long double
#define BINF 10000000000000000
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;


#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);


    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < n; i++)
        cout << s[i] << t[i];
    



return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int r=as.nextInt();        //????????°
        int c=as.nextInt();        //????????°
        
        int i,j;
        int smr = 0;
        int src = 0;
        int glf[][];
        int smc[];
        glf = new int[r+1][c+1];   //??????
        smc = new int[c];
        String str;
        
        for(i=0;i<r;i++){          
            for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            }
            
            smr=0;
            
        }
        
        for(i=0;i<c+1;i++){
        	if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	}
        	
        }
        
        for(i=0;i<r+1;i++){
        	for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	}
        }
            

	}

}

Measured memory_bytes: 41392
#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 per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
} 
ll n;
void f(ll &counter, ll a, ll use){
  if(a>n) return;
  if(use==0b111) counter++;
  f(counter ,a*10+3, use | 0b100);
  f(counter ,a*10+5, use | 0b010);
  f(counter ,a*10+7, use | 0b001);
}
int main(){
cin>>n;
ll ans = 0;
f(ans,0,0);
cout << ans << endl;}


Measured memory_bytes: 3616
"use strict";

function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");

  let N = Number(inputs[0]);
  let h = inputs[1].split(" ").map(Number);

  console.log(mizuyari(h))

}

function mizuyari(h) {
  // console.log(h);
  let totalCount = 0;
  let count = Math.min(...h);
  totalCount += count;

  let afterH = h.map(x => x - count);

  let subH = [];
  for(let i=0; i<afterH.length; i++) {
    if (afterH[i] !== 0) {
      subH.push(afterH[i]);
    } else {
      if (subH.length > 0) {
        totalCount += mizuyari(subH);
        subH = [];
      }
    }
  }

  if (subH.length > 0) {
    totalCount += mizuyari(subH);
    subH = [];
  }

  // console.log(totalCount);
  return totalCount; 
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  int n;
  cin >> n;
  int ans = pow((double)n, (double)3);
  cout << ans << '\n';
  
  return 0;
}

Measured memory_bytes: 3952
import string

def run(n):
    '''
    '''
    _base_array = string.ascii_lowercase
    results = []
    while n > 0:
        results.append(_base_array[n%26 - 1])
        if n%26 == 0:
            n = n//26 - 1
            continue
        n = n//26

    print(''.join(results[::-1]))



if __name__ == '__main__':
    n = int(input())
    run(n)

Measured memory_bytes: 9988
h,w,a,b = map(int,input().split())
n = h+w
mod = 10**9+7
fun = [1]*(n+1)
for i in range(1,n+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n+1)
rev[n] = pow(fun[n],mod-2,mod)
for i in range(n-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def nCr(n,r):
    if r > n:
        return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod
ans = 0
i = h-a
j = b+1
while i > 0 and j <= w:
  ans = (ans+nCr(i+j-2,i-1)*nCr(h+w-i-j,h-i)%mod)%mod
  i -= 1
  j += 1
print(ans)


Measured memory_bytes: 18804
#include<iostream>
#include<queue>
#define f first
#define s second
#define inf 100000001
using namespace std;
 
int main()
{
  string a[11],b[11],x,y;
  int n;
 
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    cin>>x>>y;
 
    queue<pair<string,int> > Q;
    Q.push(make_pair(x,0));
    int ans=inf;
    
    while(!Q.empty()){
      pair<string,int> u=Q.front();
      string s=u.f;
      Q.pop();
      for(int i=0;i<n;i++){
    string ss="";
    for(int j=0;j<s.length();j++){
      //cout<<s.substr(j,a[i].length())<<" "<<a[i]<<endl;
      if(s.substr(j,a[i].length())==a[i]){
        ss+=b[i];
        j+=a[i].length()-1;
      }
      else ss+=s[j];
    }
    //cout<<s<<" "<<ss<<" "<<i<<endl;
        if(ss==y){
      ans=min(u.s+1,ans);
      break;
    }
        if(ss.length()>y.length()){
      continue;
    }
        if(s!=ss)Q.push(make_pair(ss,u.s+1));
      }
    }
    if(ans==inf)cout<<-1<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3472
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
const int N=1e6+5;
int n,s,ans,now=1,v[N],w[N],cr[N],vi[N],dis[N],nex[N],head[N];
void addedges(int x,int y,int z){
	nex[++now]=head[x],w[now]=z;
	head[x]=now,v[now]=y;
}
void add(int x,int y,int z){
	addedges(x,y,z);
	addedges(y,x,0);
}
queue<int>que;
bool bfs(){
	for(int i=0;i<=s;i++)	cr[i]=head[i];
	for(int i=0;i<s;i++)	dis[i]=0;
	dis[s]=1,que.push(s);
	while(!que.empty()){
		int x=que.front();	que.pop();
		for(int i=head[x];i;i=nex[i]){
			if(w[i]&&!dis[v[i]]){
				dis[v[i]]=dis[x]+1;
				que.push(v[i]);
			}
		}
	}
	return dis[0];
}
int dfs(int x,int f){
	int ans=0;
	if(!x||!f)	return f;
	for(int &i=cr[x];i;i=nex[i])
		if(w[i]&&dis[v[i]]==dis[x]+1){
			int d=dfs(v[i],min(w[i],f));
			if(!d)	continue;
			ans+=d,w[i]-=d;
			w[i^1]+=d,f-=d;
			if(!f)	break;
		}
	if(!ans)	dis[x]=-1;
	return ans;
}
int bl[N],fa[N];
vector<int>b[N];
int main(){
	scanf("%d",&n),s=n*2;
	for(int i=1,si,x;i<n;i++){
		scanf("%d",&si),add(s,i+n,1);
		while(si--){
			scanf("%d",&x);
			b[x].push_back(i+n);
			if(x!=1)	add(i+n,x,1);
		}
	}
	for(int i=2;i<=n;i++)	add(i,0,1);

	while(bfs())
	while(int d=dfs(s,inf))	ans+=d;

	if(ans!=n-1)	puts("-1"),exit(0);
	for(int i=n+1;i<s;i++)
		for(int j=head[i];j;j=nex[j])
			if(!w[j])	bl[i]=v[j];
	que.push(1);
	while(!que.empty()){
		int x=que.front();	que.pop();
		int si=b[x].size();
		for(int i=0;i<si;i++)
			if(!vi[b[x][i]]){
				fa[b[x][i]]=x,vi[b[x][i]]=1;
				que.push(bl[b[x][i]]);
			}
	}
	for(int i=n+1;i<s;i++)
		printf("%d %d\n",fa[i],bl[i]);
	return 0;
}


Measured memory_bytes: 55040
n = int(input())
a = list(map(int, input().split()))

neven = 0
nodd = 0

for a_ in a:
    if a_ % 2 == 0:
        neven += 1
    else:
        nodd += 1

if nodd % 2 == 1:
    if n == 1:
        print("YES")
    else:
        print("NO")
else:
    print("YES")

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

int main(){
	string s;
	map<char,int> m;
	m['I'] = 1;
	m['V'] = 5;
	m['X'] = 10;
	m['L'] = 50;
	m['C'] = 100;
	m['D'] = 500;
	m['M'] = 1000;
	while( cin >> s ){
		int sum = 0;
		
		while( !s.empty() ){
			for(unsigned int i=0 ; i<s.size() ; i++){
				if( i!=s.size()-1 && m[ s[i] ] < m[ s[i+1] ] ){
					sum += m[ s[i+1] ] - m[ s[i] ];
					s.erase(i,2);
					break;
				}else{
					sum += m[ s[i] ];
					s.erase(i,1);
					break;
				}
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<tuple>
#include<algorithm>

int main(){
    
    size_t n, ans = 0;

    std::cin >> n;

    std::vector<size_t> a(n);
    std::vector<size_t> b(n);
    std::vector<size_t> c(n - 1);

    for(auto&& e : a){
        std::cin >> e;
    }

    for(auto&& e : b){
        std::cin >> e;
    }

    for(auto&& e : c){
        std::cin >> e;
    }

    for(size_t i = 0; i < n; i++){
        ans += b.at(a.at(i) - 1);

        if(i > 0 && a.at(i) - a.at(i - 1) == 1) ans += c.at(a.at(i) - 2);
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int o=0;
string i2s(int k){
  stringstream ss;
  ss << k;
  return ss.str();
}
int s2i(string s){
  istringstream iss(s);
  int x;
  iss >> x;
  return x;
}
void rec(string str){
  //cout << str << endl;
  int i=0,op=0,f=0;
  string buf,next,num;
  vector <int> v;
  while(i<str.size()){
    if(str[i]=='['){
      op++;
      if(str[i+1]=='[') next+="[";
    }else if(str[i]==']'){
      if(f==1){
	//cout << (s2i(num)+1)/2 <<endl;
	v.push_back((s2i(num)+1)/2);
	//cout << v.size() << endl;
	num="";
	f=0;
      }else{
	int k=0;
	sort(v.begin(),v.end());
	//cout << v.size() << endl;
	for(int i=0;i<(v.size()+1)/2;i++){
	  k+=v[i];
	  //cout << k << ":";
	}
	k*=2;
	//cout << i2s(k) << endl;
	if(k!=0)
	  next+=i2s(k);
	next+="]";
	v.clear();
      }
    }else{
      num+=str[i];
      f=1;
    }
    i++;
  }
  //cout << next << endl;
  if(op==1) o=s2i(str.substr(1,str.size()-2))/2;
  else rec(next);
}

int main(){
  int n,i;
  cin >> n;
  for(i=0;i<n;i++){
    string str;
    cin >> str;
    rec(str);
    cout << o << endl;
  }
}

Measured memory_bytes: 1312
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<queue>
#include<bits/stdc++.h>

using namespace std;

int I=1;
typedef long long ll;

void negabinary(int n)
{
    if(n==0)
    {
        cout<<0<<endl;
        return;
    }
    if(n==1)
    {
        cout<<1<<endl;
        return;
    }
    vector<int> a;
    while(n)
    {
        if(n==1)
        {
            a.push_back(1);
            break;
        }
        if(n>0)
        {
            int x=n/(2);
            a.push_back(n%2);
            x=(-1)*x;
            n=x;
        }
        else
        {
            int N=abs(n);
            int x=(N/2);
            if(N%2!=0){
                    a.push_back(1);
                x++;
            }
            else
            {
                a.push_back(0);
            }
            n=x;
        }
    }
    for(int i=a.size()-1;i>=0;i--)
    {
        cout<<a[i];
    }
    cout<<endl;
    return;
}

int main()
{
    //freopen("c.txt","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    int t;
        cin>>n;
        negabinary(n);
    return 0;
}

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

int main() {
  int n;
  char s[101];
  int r=0,b=0;
  cin >> n >> s;
  for(int i=0;i<n;i++){
    if(s[i]=='R') r++;
    if(s[i]=='B') b++;
  }
  if(r>b) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC161
{
    class C
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var n = a[0]; var k = a[1];

            if (n % k == 0) { Console.WriteLine(0); return; }

            long res = 0;
            res = Math.Min(n % k, Math.Abs(n % k - k));
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char c[310][310];
ll dp[101];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	string s;
	cin >> s;
	ll n = s.length();
	vector<ll>a(3);
	rep(i, n) {
		ll res = s[i] - 'a';
		a[res]++;
	}
	rep(i, 3) {
		if (a[i] < n / 3) {
			puts("NO");
			return 0;
		}
		a[i] -= n / 3;
		if (a[i] > 1) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 3724
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for _ in range(n)]

max_i = 0
max_num = 0
sec_num = 0
for i in range(n):
    if a[i] > max_num:
        max_num = a[i]
        max_i = i

a.sort(reverse=True)

for i in range(n):
    if i != max_i:
        print(max_num)
    else:
        print(a[1])


Measured memory_bytes: 12532
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A = [e-1 for e in A]
A = [10000000] + A
ans = 0
for i in range(1,N+1):
    ans += B[A[i]]
    if A[i]-1 == A[i-1]:
        ans += C[A[i-1]]
print(ans)

Measured memory_bytes: 3064
N = input()
tmp = len(N)
ans = 0

for i in range(1, int(N) + 1):
    if i < 10:
        ans += 1
    elif 100 <= i and i <= 999:
        ans += 1
    elif 10000 <= i and i <= 99999:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
int main() {
	int x,y,tmp,i;
	for (i = 0; i < 3000; ++i) {
		scanf("%d%d", &x, &y);
		if (x + y == 0)break;
		if (x > y) {
			tmp = x; x = y; y = tmp;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main(void)
{
	int h,r;
	scanf("%d %d",&h,&r);
	if	(h+r>0){
	printf("1\n");
	}
	else if(h+r<0){
	printf("-1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}


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

#define MAX 1000000

int main( void )
{
	// ツ素ツ青板表ツづーツ催ャツ青ャツつキツづゥ
	vector <bool> is_prime( MAX + 1, false );
	is_prime[2] = 0;
	for ( int i = 3; i < MAX + 1; i += 2 )
		is_prime[i] = true;
	for ( int i = 3; i < MAX + 1; i += 2 )
	{
		if ( is_prime[i] )
		{
			for ( int j = i + i; j < MAX + 1; j += i )
				is_prime[j] = false;
		}
	}

	int n;
	while ( cin >> n && n > 0 )
	{
		int cnt = 0;
		if ( is_prime[n-2] )
			cnt++;
		for ( int i = 3; i <= n / 2; i += 2 )
		{
			if ( is_prime[i] && is_prime[n-i] )
				cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) v.begin(), v.end()

using namespace std;

ll mod = 1e9+7;
inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

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

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return (dividend / divisor);
}

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

inline bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

//階乗
inline ll factorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

inline ll vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
        
        
    }
    else { // 発見できなかったとき
        return 0;
    }
}

inline void recursive_comb(ll *indexes, ll s, ll rest, std::function<void(ll *)> f) {
    if (rest == 0) {
        f(indexes);
    } else {
        if (s < 0) return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes[rest - 1] = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}

inline void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

inline void coutPrecision(ld ans){
    cout << fixed << setprecision(20) << ans << endl;
}

inline bool isKaibun(string s){
    rep(i, s.size() / 2){
        if(s[i] != s[s.size()-1 -i]){
            return false;
        }
    }
    
    return true;
}

int main(){
    ll a, b;
    cin >> a >> b;
    
    cout << a * b << endl;
    
    
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int n;
	cin >> n;
	vecll a(n), sorted_a(n);
	rep(i, n) cin >> a[i];
	copy(all(a), sorted_a.begin());
	sort(all(sorted_a));
	int medians = round((double)(sorted_a[n / 2 - 1] + sorted_a[n / 2]) / 2.);
	for (size_t i = 0; i < n; i++)
	{
		if (a[i] < medians)
		{
			cout << sorted_a[n / 2] << endl;
		}
		else
		{
			cout << sorted_a[n / 2 - 1] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 6456
/*
AizuOnline A0229
Title Big Hit !
@kankichi573
*/
#include <stdio.h>
int b, r, g, c, s, t;
int coins;
int hazure;
//
main()
{
        while(scanf("%d %d %d %d %d %d",&b,&r,&g,&c,&s,&t) 
              && (b||r||g||c||s||t))
        {
                coins=100;
                hazure=t-b*6-r*4-g-c-s;
                coins -= 3*hazure;  //hazure samai -3
                coins += 77*b;      //big samai     12+13*5=77
                coins += 51*r;      //regular samai 12+13*3=51
                coins += 4*g;       //grape samai +4
                coins -= c;         //cherry samai -1
                printf("%d\n",coins);
        }
return(0);
}

Measured memory_bytes: 600
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.ST                 as ST
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n $ BS.unpack <$> BS.getLine
toPair [x, y] = (x, y)

main = do
  [a, b] <- readInt
  print $ solve a b

solve a b = head l
 where
  l :: [Int]
  l =
    [ n
      | n <- [1 .. 1500]
      , floor (fromIntegral n * 0.08) == a
      , floor (fromIntegral n * 0.10) == b
      ]
      ++ [-1]






Measured memory_bytes: 380
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int N;
	cin >> N;
	int res = 0;
	FOR(i, 1, N + 1) {
		if (i % 2 == 0) continue;
		int cnt = 0;
		FOR(j, 1, i + 1) {
			if (i % j == 0) ++cnt;
		}
		if (cnt == 8) ++res;
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
main(){
  int n, i;
  int A[MAX+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2>=1)printf("parent key = %d, ",A[i/2]);
    if(i*2<=n)printf("left key = %d, ",A[i*2]);
    if (i*2+1<=n)printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }
   return 0;
}



Measured memory_bytes: 2112
import math

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)
 

def f(b,n):
	if n < b:
		return n
	return f(b, n//b) + n%b
 

N, K = map(int,input().split())
v = list(map(int,input().split()))
bubunwa = [0]

for i in range(len(v)):
	bubunwa.append(v[i]+bubunwa[-1])

sums = []
for i in range(len(bubunwa)-1):
	for j in range(i+1, len(bubunwa)):
		sums.append(bubunwa[j]-bubunwa[i])

ans = 0
good = []
for i in range(40,-1,-1):

	bit = 1 << i

	for elem in sums:
		if elem & bit == bit:
			good.append(elem)

	if len(good) >= K:
		ans += bit
		sums = good
		good = []
	else:
		good = []

print(ans)

Measured memory_bytes: 23980
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
lli ver(vector<lli> a)
{
    lli n = a.size();
    lli cnt = 0;
    while (true) {
        bool flag = false;
        rep(i, n)
        {
            lli temp = 0;
            if (a[i] >= n) {
                temp += a[i] / n;
                a[i] = a[i] % n;
                flag = true;
                cnt += temp;
            }
            rep(j, n) if (i != j) a[j] += temp;
        }
        if (!flag)
            return cnt;
    }
}
bool check(lli k, vector<lli> a)
{
    lli n = a.size();

    double sum = 0;
    rep(i, n)
    {
        //sum += max(0LL, ((a[i] + k - n + 1) % (1 + n) == 0 ? (double)((a[i] + k - n + 1)) / (1 + n) : (double)(a[i] + k - n + 1) / (1 + n) + 1));
        sum += max(0.0, (((double)a[i] + k - n + 1) / (1 + n)));
    }
    cout << "#" << sum << endl;
    return sum <= k;
}
lli ver2(vector<lli> a)
{
    lli n = a.size();
    lli up = 1e18;
    lli low = 0;
    //cout << check(3, a) << endl;
    while (up - low > 1) {
        lli mid = (up + low) / 2;
        if (check(mid, a)) {
            up = mid;
        } else {
            low = mid;
        }
    }
    return up;
}
int main()
{
    int n;
    cin >> n;
    vector<lli> h(n);
    bool flag = false;
    rep(i, n)
    {
        cin >> h[i];
        if (h[i] >= n)
            flag = true;
    }
    if (flag)
        cout << ver(h) << endl;
    else
        cout << 0 << endl;
}
void solve()
{
    lli k;
    cin >> k;
    lli h = 1e16;
    lli n = (k / h) + 2;
    if (n > 50) {
        n = 50;
    }

    vector<lli> a(n, n + k / n);
    rep(i, k % n) a[i] -= i;
    rep(i, n - k % n) a[k % n + i] -= k % n + 1;

    cout << n << endl;
    rep(i, n)
    {
        cout << a[i] << " ";
    }
    cout << endl;
    //cout << ver(a) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, T;
    cin >> N >> T;
    vector<pii> v(N);
    int a, b;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        v[i] = pii(a, b);
    }
    sort(v.begin(), v.end());

    vector<vector<int> > dp(N + 1, vector<int>(T+1));
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < T; j++) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            int k = j + v[i].first;
            if (k <= T - 1)
                dp[i+1][k] = max(dp[i][k], dp[i][j] + v[i].second);
        }
        // dp[i+1][T] = max(dp[i+1][T], dp[i][T - 1] + v[i].second);
        ans = max(ans, dp[i][T - 1] + v[i].second);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 35584
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

regex re(R"([A]?KIH[A]?B[A]?R[A]?)");

int main(){
    string S;
    cin >> S;
    cout << (regex_match(S, re) ? "YES" : "NO") << endl;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

class union_find {
private:
  unordered_map<lli,lli> par;
  unordered_map<lli,lli> rnk;
public:
  // union_find (lli n){
  //   par = new vll(n);
  //   iota(par->begin(),par->end(),0);
  //   rnk = new vll(n,0);
  // }
  lli parent(lli x){
    if(par[x]) return par[x];
    else return par[x] = x;
  }
  lli find(lli x){
    if(parent(x) == x) return x;
    else return par[x] = find(parent(x));
  }
  void unite(lli x,lli y){
    x = find(x);y = find(y);
    if(x == y)return;
    if(rnk[x] < rnk[y]) par[x] = y;
    else {
      par[y] = x;
      if(rnk[x] == rnk[y]) rnk[x]++;
    }
  }
  bool same(lli x,lli y){
    return find(x) == find(y);
  }
};

lli n,m;
graph g;
graph t;
lli q;
union_find uf;
mat edge;
mat ans;
lli mst = 0;

void dfs(lli x, lli c, lli p, lli from){
  ans[from][x] = c;
  for(auto y : t[x]){
    if(y.first == p) continue;
    dfs(y.first, max(y.second, c), x, from);
  }
}


int main(){
  cin >> n >> m;
  edge = mat(m, vll(3));
  for(lli i=0;i < m;i++){
    cin >> edge[i][1] >> edge[i][2] >> edge[i][0];
  }
  sort(edge.begin(), edge.end());
  for(lli i = 0;i < m;i++){
    if(uf.same(edge[i][1], edge[i][2])) continue;
    uf.unite(edge[i][1], edge[i][2]);
    t[edge[i][1]][edge[i][2]] = t[edge[i][2]][edge[i][1]] = edge[i][0];
    mst += edge[i][0];
  }
  ans = mat(n+1,vll(n+1));
  for(lli i = 1;i <= n;i++){
    dfs(i, 0, 0, i);
  }
  cin >> q;
  for(lli i = 0;i <  q;i++){
    lli s,t;
    cin >> s >> t;
    cout << mst-ans[s][t] << endl;
  }
  return 0;
}


Measured memory_bytes: 149632
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
ll llabs(ll x) {
  return x >= 0 ? x : -x;
}
int main(){
  int N;
  cin>>N;
  ll a[N];
  FOR(i,0,N) cin>>a[i];
  ll sunuke = 0, arai = 0;
  FOR(i,0,N) arai += a[i];
  ll ans = 1e15;
  FOR(i,0,N-1) {
    sunuke += a[i];
    arai -= a[i];
    ans = min(ans, llabs(arai - sunuke));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(1) {
    ll n, i, j; cin >> n >> j >> i;
    i--; j--;
    if(n == 0) break;
    vector<ll> v(n);
    ll tmp = 1;
    for(int i=0;i<n;++i) {
      v[i] = tmp;
      tmp *= 2;
    }
    reverse(v.begin(), v.end());
    string ans = "";
    for(ll k=0;k<n;++k) {
      if(i%2 == j%2) {
        ans.push_back('L');
      } else {
        ans.push_back('R');
      }
      i = i / 2;
      if(j - v[k] >= 0) {
        j = j - v[k];
      } else {
        j = v[k] - j - 1;
      }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
  }
}



Measured memory_bytes: 3124
import java.util.Scanner;

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

        long[] Lucas = new long[N + 1];

        for (int i = 0; i < Lucas.length; i++) {
            if (i == 0) {
                Lucas[i] = 2;
            }else if (i == 1) {
                Lucas[i] = 1;
            }else{
                Lucas[i] = Lucas[i-2] + Lucas[i - 1];
            }
        }
        System.out.println(Lucas[N]);
    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 11111111111;
const int c_mINF = -11111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };

int main() {
	int n, P[30];
	scanf("%d", &n);
	for (int i = 0; i < n; i++)scanf("%d", &P[i]);

	int count = 0;
	
	for (int i = 0; i < n - 2; i++) 
		if ((P[i]<P[i + 1]&& P[i + 1]<P[i + 2]) ||( P[i] > P[i + 1]&& P[i + 1] > P[i + 2])) {
			count++;
			//printf("%d,%d,%d\n", P[i] , P[i + 1] , P[i + 2]);

		
		}
	
	printf("%d", count);



}


/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<ll>>;

int main(){
  int x,a;cin>>x>>a;
  if (x < a)
  {
    cout << 0 << endl;
  }
  else if (x >= a)
  {
    cout << 10 << endl;
  }
  
  
}

Measured memory_bytes: 3592
#include<stdio.h>
int main(){
	int a,b,c;
	int i,j,k,v;
	int num[3];
	scanf("%d %d %d",&a,&b,&c);
	num[0]=a;
	num[1]=b;
	num[2]=c;
	for(i=0;i<2;i++){
		for(k=i,v=num[i],j=i+1;j<3;j++){
			if(num[j]<v){
				k=j;
				v=num[j];
			}
		}
		num[k]=num[i];
		num[i]=v;
	}
	printf("%d %d %d\n",num[0],num[1],num[2]);	
}


Measured memory_bytes: 1988
#include<bits/stdc++.h>
using namespace std;
int main(){
    char str[10010];
    while(scanf("%s",str)!=EOF){
        int J=0,I=0;
        for(int i=0;i<strlen(str)-2;i++){
            if(!strncmp(str+i,"JOI",3))J++;
            if(!strncmp(str+i,"IOI",3))I++;
        }
        printf("%d\n%d\n",J,I);
    }
    return 0;
}

Measured memory_bytes: 1148
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Together
	var N int
	fmt.Scanf("%d", &N)

	sc.Split(bufio.ScanWords)
	a := make([]int, N)
	flag := make(map[int]int, N)
	for i := 0; i < N; i++ {
		a[i] = nextInt()
		flag[a[i]]++
	}

	var max int
	var temp int
	for i := 0; i < 100000; i++ {
		temp = flag[i] + flag[i+1] + flag[i+2]
		if max < temp {
			max = temp
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 5656
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
    public static void main (String[] args) throws java.lang.Exception {
        Scanner io = new Scanner(System.in);
        int n = io.nextInt();
        int arr[] = new int[n];
        for(int i = 0; i < n; i++)
            arr[i] = io.nextInt();
        int f = 1;
        for(int i = 0; i < n; i++)
            if(arr[i] == f && f++ > 0);
        System.out.println(f == 1 ? -1 : n-f+1);
    }
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n;
    cin >> n;
    cout << 2*n*M_PI << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) cin >> p.at(i);
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (p.at(i) != i+1) {
      count++;
    }
  }
  if (count <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

// verified: AOJ DSL_2 A

struct Data {
  int mx, mn;
  Data() : mx(0), mn(0x7FFFFFFF) {}
  Data(int n) : mx(n), mn(n) {}
  Data(int mx, int mn) : mx(mx), mn(mn) {}
};

inline Data Merge(Data left, Data right) {
  return Data(max(left.mx, right.mx), min(left.mn, right.mn));
}

struct SegmentTree {
  int n; vector<Data> data;
  SegmentTree(int N) : n(1 << N), data(n * 2) {}
  void update (int pos, Data value) {
    data[pos] = value;
    while (pos < 2*n-1) {
      int l = pos, r = pos^1;
      if (l > r) swap(l, r);
      pos = pos / 2 + n;
      data[pos] = Merge(data[l], data[r]);
    }
  }
  Data sub(int fr, int to, int node, int la, int ra) {
    if (ra<=fr || to<=la) return Data();
    if (fr<=la && ra<=to) return data[node];
    Data vl = sub(fr, to, (node-n)*2+0, la, (la+ra)/2);
    Data vr = sub(fr, to, (node-n)*2+1, (la+ra)/2, ra);
    return Merge(vl, vr);
  }
  Data query(int fr, int to) { return sub(fr, to, 2*n-2, 0, n); }
};

int main()
{
  int n, k;
  cin>>n>>k;
  vecint p(n);
  for(auto& v : p) cin>>v;
  SegmentTree st(18);
  vecint inc(n, 0);
  for(auto t : index(p)) {
    int i = t.index();
    st.update(i, t.value());
    if (i && p[i] > p[i-1]) {
      inc[i] = 1;
    }
  }
  vecint pinc(n);
  boost::partial_sum(inc, begin(pinc));
  int sum = 0;
  vector<bool> skip(n, false);
  bool has_sorted = false;
  for (int i :irange(0,n-k+1)) {
    if (skip[i]) continue;
    if (pinc.at(i+k-1) - pinc[i] == k-1) {
      has_sorted = true;
      continue;
    }
    sum++;
    if (i+k >= n) continue;
    int mx = st.query(i, i+k).mx;
    if (p.at(i+k) <= mx) {
      continue;
    }
    int mn = st.query(i+1, i+1+k).mn;
    if (p[i] >= mn) {
      continue;
    }
    skip[i+1] = true;
    for (int j :irange(i+1, n-k)) {
      if (inc[j] == 0) break;
      if (inc.at(j+k) == 0) break;
      int mn = st.query(j+1,j+k+1).mn;
      if (p[j] >= mn) break;
      skip[j+1] = true;
    }
  }
  if (has_sorted) ++sum;
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 6784