akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

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


Measured memory_bytes: 18476
/***
	chauhan176's code

	DO WHATEVER IT TAKES!!!
	Nothing happens , nothing happens and then everything happens.
	But the thing is nothing happens in air:)-
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define maxn 300005
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define stringio cin.ignore(256, '\n')  //to take string input after taking integer inputs
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

typedef pair<int,int>pi;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int mx = 1000007;
int main()
{
    fastio;
    int n;
    cin>>n;
    int f=0;
    for(int i=1;i<10;i++)
    {
        int num=n/i;
        if(n%i==0 && num<=9)
            f=1;
    }
    if(f==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int n;

bool binary_search(vector<int> &a ,int k){
    int x , y , z;
    x = 0;
    z = n - 1;
    while( x <= z ){
        y = (x + z) / 2;
        if(k == a[y]) return true;
        else if(k < a[y]) z = y - 1;
        else x = y + 1;
    }
    return false;
}

int main(){
    cin >> n;
    vector<int> a(n);
    rep(i ,n) cin >> a[i];
    int q; cin >> q;
    rep(i ,q){
        int k; cin >> k;
        cout << (binary_search(a , k) ? 1 : 0) << endl;
    }
}



Measured memory_bytes: 3096
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7

###############################################################################\n=17
def power(a,n):
    res=1
    while(n):
        if n&1:
            res=res*a
        a=a*a
        n//=2
        res%=J
        a%=J
    return res%J
s=int(input())

ans=0
def C(n,r):
    if r==0:
        return 1
    res=1
    for i in range(n,n-r,-1):
        res=(res*i)%J
    for j in range(1,r+1):
        res=(res*power(j,J-2))%J
    return res
#print(C(9,9))
ans=0
for i in range(s//3):
    ans=(ans+C(s-3*(i+1)+i,i))%J
    #print(ans)
print(ans)


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
	int n;
  	cin>>n;	
  	map<long long int,long long int> s;
  	long long int sum{0};
    
  	for(int i{0};i<n;i++)
    {
		
		long long int a;
      	cin>>a;
      	if(s.count(a))
      	{
      	    s[a]++;
      	}
      	else
      	{
      	    s[a]=1;
      	}
    	sum=sum+a;
    }
   
    long long int q;
    cin>>q;
    while(q--)
    {
    	long long int b,c;
      	cin>>b>>c;
      	
      	sum=sum+c*(s[b])-b*(s[b]);
    	
    	s[c]=s[c]+ s[b];
    	
    //	cout<<s[b]<<endl;
        s[b]=0;
     	cout<<sum<<endl;
    }
  	
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod=1337;
ll power(ll a,ll b)
{
    if(b==0) return 1;
     ll temp=power(a,b/2);
     if(b%2==0)
     {
         return temp*temp;
     }
     else
     {
         return temp*temp*a;
     }
}
int main()
{
   map<ll, ll>mp;
   for(int i=0;i<200;i++)
   {
       ll a=power(i,5);
       mp[a]=i;
   }
   ll x;
   cin>>x;
   for(int i=0;i<200;i++)
   {
       ll a=power(i,5);
       if(mp.find(x+a)!=mp.end())
       {
           cout<<mp[x+a]<<" "<<i<<"\n";
           break;
       }
       else if(mp.find(x-a)!=mp.end())
       {
           cout<<i<<" "<<-1*mp[x-a]<<"\n";
           break;
       }
   }
}


Measured memory_bytes: 3648
def main():
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	p = 1000000007
	S = 0
	Asq = 0
	for i in range(len(A)):
		x = A[i]
		S += x % (2 * p)
		Asq += (x * x) % (2 * p)
	t = ((S * S) % (2 * p) - Asq) % (2 * p)
	print(int(t / 2))

main()

Measured memory_bytes: 31620
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);

int t;
cin>>t;

int h = t/3600;
int rem = t%3600;
int m = rem/60;
rem = rem%60;

cout<<h<<":"<<m<<":"<<rem<<endl;

return 0;

}


Measured memory_bytes: 3212
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  string s;
  priority_queue<int, vector<int> > que;
  while (cin >> s) {
    if (s == "end") break;
    if (s == "insert") {
      int n;
      cin >> n;
      que.push(n);
    } else {
      cout << que.top() << endl;
      que.pop();
    }
  }
  return 0;
}


Measured memory_bytes: 7024
#include <algorithm>
#include <iostream>

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

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

const string YES = "YES";
const string NO = "NO";

void solve(ll A, ll B, ll C) {
  bool pred = max({A,B,C}) == 7 && min({A,B,C}) == 5 && A+B+C == 17;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  solve(A, B, C);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
     ll ha,sa,hb,sb;
     cin>>ha>>sa>>hb>>sb;
     ll flag=0;

     while(1)
     {
         hb-=sa;
         if(hb<=0)
         {
             break;
         }
         ha-=sb;
         if(ha<=0)
         {
             flag=1;
             break;
         }
     }
     if(flag)
     {
         cout<<"No"<<endl;
     }
     else
     {
         cout<<"Yes"<<endl;
     }
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
const long long INF = 1001001001001001001ll;
struct SegmentTree{
private:
    int n;
    vector<LL> node;

public:
    SegmentTree(vector<LL> v){
        int sz = v.size();
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1,INF);
        for (int i = 0; i < sz; i++) node[i+n-1] = v[i];
        for (int i = n-2; i >= 0; i--) node[i] = min(node[2*i+1],node[2*i+2]);
    }

    void update(int x,LL val){
        x += n-1;
        node[x] = val;
        while(x > 0){
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1],node[2*x+2]);
        }
    }

    LL getmin(int a, int b, int k=0, int l=0, int r=-1){
        if (r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];
        LL vl = getmin(a, b, 2*k+1, l , (l+r)/2);
        LL vr = getmin(a, b, 2*k+2, (l+r)/2,r);
        return min(vl, vr);
    }
};



int main(){
    int n,m;cin >> n >> m;
    SegmentTree seg(vector<LL> (n+1,LINF));
    vector<pair<P,LL>> v(m);
    for (int i = 0; i < m; i++) {
        int l,r;
        LL c;cin >> l >> r >> c;
        l--,r--;
        v[i] = mp(mp(r,l),c);
    }
    sort(ALL(v));
    seg.update(0,0);
    for (int i = 0; i < m; i++) {
        P p = v[i].fs;
        LL c = v[i].sc;
        LL t = seg.getmin(p.sc,p.fs+1);
        seg.update(p.fs,min(seg.getmin(p.fs,p.fs+1),t+c));
    }
    if(seg.getmin(n-1,n)==INF) puts("-1");
    else cout << seg.getmin(n-1,n) << endl;
    return 0;
}


Measured memory_bytes: 4620
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;



ll keeta(ll a){

  ll tmp=1;
while(1){
a/=10;
if(a==0)
break;
tmp++;


}

return tmp;
}

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

  ll tmp=N;
ll tmp1=1;

ll min = keeta(N);

  for(ll i=1;i<=sqrt(tmp);i++){
    if(tmp%i==0){
      auto j = N/i;
      auto mm = max(j,i);
      auto yy = keeta(mm);

      if(min>yy)
      min = yy;
    }
    else
    {
      continue;
    }
    


  }

cout<<min<<endl;
}
  


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

int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int l[Q],r[Q];
    for(int i=0; i<Q; i++){
        cin >> l[i] >> r[i];
    }
    
    vector<int> pos_ac(N, 0);//nまでにいくつACがあるか
    int pos =(int)S.find("AC");
    int count = 0;
    
    //O(N)
    while(pos != string::npos){
        pos_ac[pos] = ++count;
        pos+=2;
        
        pos = (int)S.find("AC", pos);
    }
    
    //O(N)
    count = 0;
    for(int i=0; i<N; i++){
        if(pos_ac[i] != 0){
            count = pos_ac[i];
        }
        pos_ac[i] = count;
    }
    
    //O(Q)
    for(int i=0; i<Q; i++){
        if(l[i] == 0)cout << pos_ac[r[i]] << endl;
        if(r[i] == 0)cout << 0 << endl;
        cout << pos_ac[r[i]-2] - pos_ac[l[i]-2] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

int main(){
    
    int n;
    std::vector<int> v;

    std::cin >> n;

    for(int i = 0; i < n; i++){
        int tmp;
        std::cin >> tmp;
        v.emplace_back(tmp);
    }

    int ans = *std::max_element(v.begin(), v.end()) / 2;
    *std::max_element(v.begin(), v.end()) = 0;

    ans += std::accumulate(v.begin(), v.end(), 0);

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


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

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppi                      pair <int , pii>               
#define    sp(x)                    setprecision(x)

int32_t main()
{
    speed upp
    int n=-1,a,b;
    cin>>a>>b;
    double  x,y;
    f(i,0,1000000)
    {
        x=(double)8/100.00;
        x=x*i;
        y=(double)10/100.00;
        y=y*i;
        int aa=x,bb=y;
        if(aa==a && bb==b)
        {
            cout<<i;
            exit(0);
        }
    }
cout<<n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long i64;
typedef long double ld;
ld xa,ya,xm;
struct pos{
	ld x,y;
	ld operator*(const pos&w)const{return (x+xa)*(w.y+ya)-(y+ya)*(w.x+xa);}
}ps[500007];
int l=500000,r=500000,n,mx;
int main(){
	scanf("%d%d",&n,&mx);
	xm=mx;
	for(int i=1,x,y;i<=n;++i){
		scanf("%d%d",&y,&x);
		xa+=x,ya+=(ld)x*y;
		ps[l-1]=(pos){-xa,-ya};
		if(i>1){
			while(ps[r].x+xa>xm)--r;
			ld yd=ps[r+1].y-ps[r].y,k=(xm-xa-ps[r].x)/(ps[r+1].x-ps[r].x);
			yd=yd*k+ps[r].y;
			ps[++r]=(pos){xm-xa,yd};
		}
		while(l<r&&ps[l]*ps[l+1]>0)++l;
		ps[--l]=(pos){-xa,-ya};
		printf("%.8Lf\n",(ps[r].y+ya)/(ps[r].x+xa));
	}
	return 0;
}

Measured memory_bytes: 25088
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  vector<int> dp(30);
  dp.at(0) = 1;
  dp.at(1) = 2;
  dp.at(2) = 4;
  for(int i = 3; i < 30; i++) dp.at(i) = dp.at(i-1) + dp.at(i-2) + dp.at(i-3);

  while(true){
    
    int n; cin >> n;
    if(n == 0)  break;
    
    int res = dp.at(n-1);
    res = ( (res + 9 ) / 10  + 364) / 365;
    
    cout << res << endl;
    
  }

  return 0;
}


Measured memory_bytes: 2964
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String[] S = new String[N];
		for( int i=0; i<N; i++ ){
			S[i] = sc.next();
		}
		Arrays.sort(S);
		int count = 0;
		for( int i=1; i<N; i++ ){
			if( S[i].equals(S[i-1]) ){
				count++;
			}
		}
		System.out.println(N-count);
	}
}

Measured memory_bytes: 70236
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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 ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int A, B, C, D; cin >> A >> B >> C >> D;
  int res = 0;
  while (true){
    C -= B;
    if (C <= 0){
      cout << "Yes" << endl;
      break;
    }
    A -= D;
    if (A <= 0){
      cout << "No" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
  string r,a;
  for(;cin>>r>>a,r!="0";)
    {
      int hit=0,brow=0;
      
      for(int i=0;i<4;i++)
	for(int j=0;j<4;j++)
	  {
	    if(r[i]==a[j])
	      {
		if(i==j)
		  hit++;
		else
		  brow++;
	      }
	  }
      cout<<hit<<" "<<brow<<endl;
	
    }
}

Measured memory_bytes: 1184
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    n=int(input())
    a=list(map(int,input().split()))
    a=sorted(a)
    ans="YES"
    for i in range(n-1):
        if a[i]==a[i+1]:
            ans="NO"
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 87432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 998244353
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    while(true){
        ll n;
        cin >> n;
        if (n==0)break;
        ll w[n];
        for (ll i=0;i<n;i++)cin >> w[i];
        ll dp[n+1][n+1];
        memset(dp,0,sizeof(dp));
        for (ll i=2;i<=n;i++){
            for (ll l=0;l<=n;l++){
                ll r=i+l;
                if (i+l>n){
                    continue;
                }
                if (dp[l+1][r-1]==i-2 and abs(w[l]-w[r-1])<=1)dp[l][r]=i;
                for (ll mid=l;mid<=r;mid++){
                    dp[l][r]=max(dp[l][r],dp[l][mid]+dp[mid][r]);
                }
            }
        }
        cout << dp[0][n] << endl;
    }
    return 0;
}


Measured memory_bytes: 3796
import java.util.*;
public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
		// 整数の入力
		int X = sc.nextInt();
    int A = sc.nextInt();

    int ans = 0;

    if(X >= A){
      ans = 10;
    }


		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;

int main() {
	string S, T;
	cin >> S >> T;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != T[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	if (S.size() + 1 != T.size()) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3624
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.text.DecimalFormat;

public class Main {
	static boolean debug = false;

	public static void main(String[] args) throws IOException {

		UserScanner scan = new UserScanner();
		PrintWriter pwriter = new PrintWriter(System.out);
		for (int seq = 1; true; seq++) {
			int q = scan.nextInt();
			if (q == 0)
				break;
			Geometry gm = new Geometry();
			for (int i = 0; i < q; i++) {
				gm.polygon(scan.nextInt(), scan.nextInt());
			}
			double area = gm.polygonEnd();
			DecimalFormat df = new DecimalFormat("#######.0");
			pwriter.println(seq + " " + df.format(area));
		}

		pwriter.flush();
		scan.close();
		System.exit(0);
	}
}

class Geometry {

	boolean polygonDo;
	double firstX, firstY, preX, preY;
	double area;

	public void polygon(double x, double y) {
		if (polygonDo)
			calcCross(preX, preY, x, y);
		else {
			polygonDo = true;
			firstX = x;
			firstY = y;
		}
		preX = x;
		preY = y;
	}

	public double polygonEnd() {
		calcCross(preX, preY, firstX, firstY);
		polygonDo = false;
		double ret = area;
		area = 0;
		return ret;
	}

	private void calcCross(double x1, double y1, double x2, double y2) {
		area += (x2 * y1 - x1 * y2) / 2;
		//System.out.println(area);
	}
}

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

	private boolean read() throws IOException {
		ptr = 0;
		buflen = in.read(buffer);
		if (buflen <= 0)
			return false;
		else
			return true;
	}

	private byte getByte() throws IOException {
		if (ptr >= buflen)
			read();
		if (isCtlSpace(buffer[ptr])) {
			return -1;
		} else
			return buffer[ptr++];
	}

	private void skipCtlSpace() throws IOException {
		if (ptr >= buflen)
			read();
		if (isCtlSpace(buffer[ptr])) {
			ptr++;
			skipCtlSpace();
		}
	}

	private boolean isCtlSpace(byte b) {
		if (b <= ' ' || b > '~')
			return true;
		else
			return false;
	}

	public void close() throws IOException {
		in.close();
	}

	public String next() throws IOException {
		skipCtlSpace();
		StringBuilder sb = new StringBuilder();
		byte b;
		while ((b = getByte()) != -1) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() throws IOException {
		skipCtlSpace();
		int n = 0;
		boolean minus = false;
		byte b;
		while ((b = getByte()) != -1) {
			if (b == '-')
				minus = true;
			else {
				n *= 10;
				n += (b - '0');
			}
		}
		if (minus)
			return n * -1;
		else
			return n;
	}
}

Measured memory_bytes: 26032
#include<bits/stdc++.h>
using namespace std;
int main(){
	int h,w;
	cin>>h>>w;
	int n;
	cin>>n;
	int color[n+1];
	for(int i=1; i<=n; i++) cin>>color[i];
	int arr[h+1][w+1]={0};
	int col = 0;
	int p = 1;
	for(int i=1; i<=h; i++){
		if(col==0){
			for(int j=1; j<=w; j++){
				arr[i][j] = p;
				color[p]--;
				if(color[p]==0) p++; 
			}
			col = w+1;
		}
		else{
			for(int j=w; j>=1; j--){
				arr[i][j] = p;
				color[p]--;
				if(color[p]==0) p++;
			}
			col = 0;
		}
	}
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++) cout<<arr[i][j]<<" ";
		cout<<'\n';
	}
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf LLONG_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define f first
#define s second

ll modpow(ll x,ll y)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		x=(x*x)%mod;
		y>>=1;
	}
	return res;
}

ll modpowinv(ll n)
{
	return modpow(n,mod-2);
}

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

	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	ll fact[n+1];
	fact[0]=1;
	fact[1]=1;
	for(ll i=2;i<=n;i++)
	{
		fact[i]=(fact[i-1]*i)%mod;
	}
	ll ans=0;
	ll K=k-1;
	for(ll i=0;i<n;i++)
	{
		ll N=i;
		if(N>=K)
		{
			ll nck=fact[N]%mod;
			nck=(nck*modpowinv(fact[K]))%mod;
			nck=(nck*modpowinv(fact[N-K]))%mod;
			ll temp=(nck*a[i])%mod;//cout<<nck<<endl;
			ans=(ans+temp+mod)%mod;
		}
		N=n-i-1;
		if(N>=K)
		{
			ll nck=fact[N]%mod;
			nck=(nck*modpowinv(fact[K]))%mod;
			nck=(nck*modpowinv(fact[N-K]))%mod;
			ll temp=(nck*a[i])%mod;//cout<<temp<<endl;
			ans=(ans-temp+mod)%mod;
		}
	}
	cout<<ans%mod<<'\n';
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
string s;
int l,a,b,num,i;
int main()
{
    cin>>s;
    l=s.size();
    for (i=0;i<l;i++){
        if (a==b){
            a++;
            if(s[i]=='p') {
		     num--;
		 }
        }
        else{
            b++;
            if(s[i]=='g'){
			num++;
		}
        }
    }
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define INF 2147483647
#define  ll long long
using namespace std;
const int Max=1e5+20;
const int Maxn=1e7+20;
//const int mod=1e9+7;
inline int read()
{
    int f=1,x=0;
    char ch;
    do{ch=getchar(); if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return x*f;
}
int a[120];
int main()
{
    ll x,k,d;
    cin>>x>>k>>d;
    ll mod,num;
    if(x<0)
    {
        ll X=-x;
        mod=X%d;
        num=X/d;
        if(k>num) {if((k-num)&1) cout<<d-mod<<endl;else cout<<mod<<endl;}
        else if(k==num) cout<<mod<<endl;
        else cout<<abs(x+k*d)<<endl;
    }
    else
    {
        mod=x%d;
        num=x/d;
        if(k>num){if((k-num)&1)cout<<abs(mod-d)<<endl; else cout<<mod<<endl;}
        else if(k==num) cout<<mod<<endl;
        else cout<<abs(x-k*d)<<endl;
    }
}




Measured memory_bytes: 3640
while True :
    x,y,z=input().split()
    x=int(x)
    z=int(z)
    if y== "+" : print(int(x+z))
    elif y == "-" : print(int(x-z))
    elif y == "*" : print(int(x*z))
    elif y == "/" : print(int(x/z))
    else : break


Measured memory_bytes: 5596
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static boolean adj[][];
	static int C = 0;
	static ArrayList<Integer> ans = new ArrayList<>();
	static boolean finish = false;
	static boolean visited[];

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		//Getting 隣接行列
		int N = scan.nextInt();
		int M = scan.nextInt();
		adj = new boolean[N][N];

		for (int i = 0; i < N; i++) {
			Arrays.fill(adj[i], false);
		}
		int[] A = new int[M];
		int[] B = new int[M];
		for (int i = 0; i < M; i++) {
			A[i] = scan.nextInt();
			B[i] = scan.nextInt();
			adj[A[i] - 1][B[i] - 1] = adj[B[i] - 1][A[i] - 1] = true;
		}

		for (int i = 0; i < M; i++) {
			adj[A[i] - 1][B[i] - 1] = adj[B[i] - 1][A[i] - 1] = false;
			C = 0;
			visited = new boolean[N];
			finish = false;
			Arrays.fill(visited, false);
			visited[0] = true;
			dfs(0, N, visited);
			for (int j = 0; j < N; j++) {
				if (visited[j]) {
					C++;
				}
			}
			ans.add(C);
			adj[A[i] - 1][B[i] - 1] = adj[B[i] - 1][A[i] - 1] = true;
		}

		int count = 0;
		for (Integer i : ans) {
			if (i != N) {
				count++;
			}
		}
		System.out.println(count);
	}


	public static void dfs(int x, int N, boolean[] visited) {

		if (finish) {
			return;
		}
		boolean allvisited = true;

		for (int i = 0; i < N; i++) {
			if (visited[i] == true) {
				allvisited = false;
			}
		}

		if (allvisited) {
			finish = true;
			return;
		}
		//以上全てのノードを回ったかの確認

		//以下DFS本体

		for (int i = 0; i < N; i++) {
			if (adj[x][i] == false)
				continue;
			if (visited[i])
				continue;

			visited[i] = true;
			dfs(i, N, visited);
		}

		return;
	}
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    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);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int cnt[1000001],cnt2[1000001];
    fill(cnt,cnt+1000001,0);
    fill(cnt2,cnt2+1000001,0);
    int a[n];
    rep(i,0,n){
        cin>>a[i];
        cnt2[a[i]]++;
    }
    rep(i,1,1000001){
        for(int j=i;j<=1000000;j+=i){
            cnt[j]+=cnt2[i];
        }
    }
    int ans=0;
    rep(i,0,n){
        if(cnt[a[i]]==1)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 12248
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}


#pragma endregion




	int main(void) {

		int a;

		scanf("%d", &a);
		

		printf("%d\n",a*a+a*a*a+a);

		return 0;
	}







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

using ll = long long;

void self_max(int &a,int b){
	a = max(a,b);
}

int main() {
    int n,m; cin >> n >> m;
    vector<pair <int ,int>> h(n);
    priority_queue<int> q;
    
    for(int i=0;i<n; i++){
        int a,b; cin >> a >> b;
        h[i].first = a;
        h[i].second = b;
    }

    int ans =0;
    int day = 0;
    sort(h.begin(),h.end());
    for(int i=1 ; i<=m;i++){
    	while( i== h[day].first){
    		q.push(h[day].second);
    		day++;
    	}

    	if(!q.empty()){
    		ans +=q.top();
    		q.pop();
    	}
    }

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

Measured memory_bytes: 1660
#include <iostream>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
 
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n][n], dp[1 << n] = {};
	
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];
	
	dp[0] = 1;
	for (int j = 1; j < (1 << n); j++)
			for (int k = 0; k < n; k++)
				if ((j & (1 << k)) && a[__builtin_popcount(j) - 1][k])
					dp[j] = (dp[j ^ (1 << k)] + dp[j]) % mod;
					
	cout << dp[(1 << n) - 1];
}

Measured memory_bytes: 8448
import java.util.*;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			if(n==-1)
				return;
			String str = "";
			while(true)
			{
				if(n==0)
					break;
					str=String.valueOf(n%4)+str;
				n/=4;
			}
			if(str.equals(""))
				str="0";
			System.out.println(str);
		}
	}
}

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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define debug(x_) cerr << #x_ << ":" << x_ << endl;
#define debug2(x__) for(auto a__ : x__) cerr << a__ << " "; cerr << endl;
#define debug3(x___ , sx___) rep(i, sx___) cerr << x___[i] << " "; cerr << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    smaller_queue<int> que;
    int n;
    cin >> n;
    int x;
    cin >> x;
    int x_s = x;
    int cnt = 0;
    int sum = 0;

    rep(i, n) {
        int a;
        cin >> a;
        sum += a;
        que.push(a);
    }
    while (x > 0 && !que.empty()) {
        if (x - que.top() < 0) break;
        x -= que.top();
        que.pop();
        cnt++;
    }
    if (cnt == n && sum != x_s) cnt--;
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();
    
    int a, b;
    cin >> a >> b;
    cout << (a + b) / 2 << "\n";
}


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

#define INF_LL (int64)1e18
//#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

class UnionFind{
private:
    ::std::vector<int_fast32_t> par, edge;
    size_t n;

public:
    UnionFind(){}
    UnionFind(size_t n):n(n){
        par.resize(n, -1);
        edge.resize(n, 0);
    }

    uint_fast32_t find(uint_fast32_t x){
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }

    size_t size(uint_fast32_t x){
        return -par[find(x)];
    }

    bool unite(uint_fast32_t x, uint_fast32_t y){
        x = find(x);
        y = find(y);
        edge[x] += 1;
        if(x == y) return false;
        if(size(x) < size(y)) std::swap(x, y);
        par[x] += par[y];
        edge[x] += edge[y];
        par[y] = x;
        return true;
    }

    bool same(uint_fast32_t x, uint_fast32_t y){
        return find(x) == find(y);
    }

    size_t esize(uint_fast32_t x) {
        return edge[find(x)];
    }
};

int main(void) {
    int64 N;
    cin >> N;
    vector<int64> s(N);
    REP(i, N) cin >> s[i];
    int64 res = 0;
    vector<int> visited(N, 0);
    for (int64 i = 1; i <= N-1; i++) {
        int64 sum = 0, pos = 0;
        while (pos < N-i) {
            if (visited[pos] == i || visited[N-1-pos] == i|| pos == N-1-pos) {
                break;
            }
            visited[pos] = visited[N-1-pos] = i;
            sum += s[pos] + s[N-1-pos];
            chmax(res, sum);
            pos += i;
        }

    }
    cout << res << endl;
}


Measured memory_bytes: 1408
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}
func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	maxi := a[0]
	midi := maxi / 2
	ans := a[0]
	mind := int(1e9) + 1
	for i := 1; i < n; i++ {
		d := abs(midi - a[i])
		if mind > d {
			mind = d
			ans = a[i]
		}
	}
	fmt.Println(maxi, ans)
}
func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}


Measured memory_bytes: 3072
#include <stdio.h>

main(){
  int data[102];
  int count1, count2, sum, a, b,i,p,t=0;

  while(1){
    for(i=0;i<102;i++){
      data[i]=0;
    }
    
    while(1){
      if(scanf("%d %d", &a, &b)==EOF){
	t=1;
	break;
      }
      if(a==0 && b==0) break;
      if(data[b]>=0){
	data[b]++;
	data[a]--;
      }
      else{
	data[b]--;
	data[a]++;
      }
      //data[b]++;
      //data[a]--;
    }

    if(t==1) break;
    p=0;
    count1=count2=0;
    for(i=0;i<102;i++){
      if(data[i]==1) count1++;
      else if(data[i]==-1) count2++;
      else if(data[i]!=0) p=1;
    }

    if(count1==1 && count2==1) printf("OK\n");
    else printf("NG\n");
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.IO;

namespace Contest
{
    class Program
    {
        public void Solve()
        {
            var sc = new Scanner();
            long N = sc.NextLong();
            long ans = 0;
            for (int i = 1; i < 2000000; i++)
            {

                if ((N - i) % i == 0)
                {
                    long m = (N - i) / i;
                    if (m <= 0) continue;
                    if (i != N / m) continue;
                    ans += m;
                }

            }

            Console.WriteLine(ans);
        }

        static void Main() => new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private char _separator;
    private StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

Measured memory_bytes: 13140
import collections
n=int(input())
v=list(map(int,input().split()))
s=[]
t=[]
for i in range(n):
    if i%2==0:
        s.append(v[i])
    else:
        t.append(v[i])
p=collections.Counter(s)
q=collections.Counter(t)
a=p.most_common()[0][0]
a1=p.most_common()[0][1]
b=q.most_common()[0][0]
b1=q.most_common()[0][1]
if a!=b:
    print(n-a1-b1)
elif len(set(s))==1 and len(set(t))==1:
            print(int(n/2))
else:
     c=p.most_common()[1][1]
     d=q.most_common()[1][1]
     print(n-max(c+b1,d+a1))

Measured memory_bytes: 20576
#include <iostream>
#include <bits/stdc++.h>
#define lld long long int
using namespace std;
int main() 
{
	lld n;
	cin>>n;
	lld a[n];
	for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector <lld> dp(n);
    fill(dp.begin(),dp.end(),0);
    for(int i=1;i<n;i++)
    {
        if(i-1 == 0)
        {
            dp[i]=(abs(a[i]-a[i-1]))+dp[i-1];
        }
        else
        {
            dp[i]=min((dp[i-1]+(abs(a[i]-a[i-1]))),dp[i-2]+abs(a[i]-a[i-2]));
        }
        
    }
    cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long A,B,N;
  cin>>N>>A>>B;
  long long a,b,c;
  a=N/(A+B);
  b=N%(A+B);
  c=min(b,A);
  cout<<a*A+c<<endl;
}

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

int f(long int a,long int b){
    string s;
    if(a < b)a = b;
    s = to_string(a);
    return s.size();
}

int main(void){
    long int n;
    cin >> n;
    long int ans = n,min = 0;
    for(long int a = 1;a*a <= n;a++){
        if(n % a == 0){
            min = f(a,n/a);
            if(ans > min)ans = min;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace panasonic2020
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_panasonic2020A();
        }

        public static void solve_panasonic2020B()
        {

        }

        public static void solve_panasonic2020A()
        {
            int[] k = new int[] {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
            int pos = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(k[pos - 1]);
        }
    }
}


Measured memory_bytes: 11348
#include<stdio.h>
int main(void)
{
  int N;
  char s[100];
  int i;
  int c=0;
  int d=0;
  
  scanf("%d",&N);
  scanf("%s",s);
  for(i=0;i<100;i++){
    if(s[i]=='R')
      c++; 
    else if(s[i]=='B')
      d++;
  }
 
 if(c>d)
    printf("Yes");
 else
    printf("No");
 return 0;
}

Measured memory_bytes: 128
n,k = map(int,input().split())
s = input()+"x"

cnt = 1
li = []
for i in range(0,n):
    if s[i+1] != s[i]:
        li.append(cnt)
        cnt = 1
    else:
        cnt += 1

cursum = [0]*(len(li)+1)
for i in range(len(li)):
    cursum[i+1] = cursum[i]+ li[i]

if s[0]=="1":
  is_s_1 = True
else:
  is_s_1 = False

ans = 0
for i in range(1,len(cursum)):
    if is_s_1:
        low_limit = max(i-2*k-1,0)
    else:
        low_limit = max(i-2*k,0)
    ans = max(ans,cursum[i] - cursum[low_limit])
    is_s_1 = not is_s_1

if ans == 0:
    print(n)
else:
    print(ans)

Measured memory_bytes: 46192
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,m;

struct seg{
    int l,r,v;
} a[200005];

ll dp[200005],s[200005],sg[800005],lz[800005],f[200005],ans;

bool comp(seg a, seg b){
    return a.r<b.r;
}

void Sift(int nod, int l, int r){
    sg[nod]+=lz[nod];
    if(l!=r){
        lz[2*nod]+=lz[nod];
        lz[2*nod+1]+=lz[nod];
    }
    lz[nod]=0;
}

void Upd(int lt, int rt, ll v, int nod=1, int l=1, int r=n){
    Sift(nod,l,r);
    if(l>rt || r<lt) return;
    if(l>=lt && r<=rt){
        lz[nod]+=v;
        Sift(nod,l,r);
        return;
    }
    int mid=(l+r)/2;
    Upd(lt,rt,v,2*nod,l,mid);
    Upd(lt,rt,v,2*nod+1,mid+1,r);
    sg[nod]=max(sg[2*nod],sg[2*nod+1]);
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        cin >> a[i].l >> a[i].r >> a[i].v;
        f[a[i].l]+=a[i].v;
        f[a[i].r+1]-=a[i].v;
    }
    for(int i=1;i<=n;i++){
        f[i]+=f[i-1];
    }
    sort(a+1,a+m+1,comp);
    int j=1;
    for(int i=1;i<=n;i++){
        Sift(1,1,n);
        dp[i]=f[i]+sg[1];
        Upd(i,i,dp[i]-f[i]);
        while(j<=m && a[j].r==i){
            Upd(a[j].l,a[j].r,a[j].v);
            j++;
        }
        ans=max(ans,dp[i]);
    }
    cout << ans;
}


Measured memory_bytes: 17792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << "=" << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << " "
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

int main(){
    ll n,m,result = 0;
    cin >>n >>m;

    vector<ll> a(n);
    priority_queue<ll> q;
    
    loop(i,n) {
        cin >>a[i];
        q.push(a[i]);
    }

    loop(i,m){
        ll tmp = q.top();
        q.pop();
        tmp /= 2;
        q.push(tmp);
    }

    loop(i,n){
        result += q.top();
        q.pop();
    }

    cout << result << endl;
}

Measured memory_bytes: 2168