akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

void insert_sort(vector<int> arr) {
	int n = arr.size();
	for (int i = 0; i < n; ++i) {
		for (int j = i; j > 0; --j) {
			if (arr[j - 1] > arr[j])
				swap(arr[j - 1], arr[j]);
		}
		for (int i = 0; i < n; ++i) {
			cout << arr[i];
			if (i != n - 1) cout << " ";
		}
		cout << endl;
	}
}


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

	vector<int> arr(n, 0);
	for (int i = 0; i < n; ++i)
		cin >> arr[i];
	insert_sort(arr);

	return 0;
}



Measured memory_bytes: 3168
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int h = scan.nextInt();
		String M[] = new String[366];
		for(int i = 0 ; i<366 ; i++){
			if(i%7 == 0){
				M[i] = "Thursday";
			}else if(i%7 == 1){
				M[i] = "Friday";
			}else if(i%7 == 2){
				M[i] = "Saturday";
			}else if(i%7 == 3){
				M[i] = "Sunday";
			}else if(i%7 == 4){
				M[i] = "Monday";
			}else if(i%7 == 5){
				M[i] = "Tuesday";
			}else{
				M[i] = "Wednesday";
			}
		}
		while(t != 0){
			if(t == 1){
				System.out.println(M[h-1]);
			}else if(t == 2){
				System.out.println(M[30+h]);
			}else if(t == 3){
				System.out.println(M[59+h]);
			}else if(t == 4){
				System.out.println(M[90+h]);
			}else if(t == 5){
				System.out.println(M[120+h]);
			}else if(t == 6){
				System.out.println(M[151+h]);
			}else if(t == 7){
				System.out.println(M[181+h]);
			}else if(t == 8){
				System.out.println(M[212+h]);
			}else if(t == 9){
				System.out.println(M[243+h]);
			}else if(t == 10){
				System.out.println(M[273+h]);
			}else if(t == 11){
				System.out.println(M[304+h]);
			}else{
				System.out.println(M[334+h]);
			}
			t = scan.nextInt();
			h = scan.nextInt();
		}
	}
}

Measured memory_bytes: 15372
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<29

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int usage[] = { 4, 1, 4, 1, 2, 1, 2, 1 };

int main()
{
//	cut here before submit 
//	freopen ("testcase.flying_jenny", "r", stdin );

	vector<vector<int> > c (8, vector<int> (8, 0 ) );
	rep (i, 8 ) c[0][i] = usage[i];
	for (int i = 1; i < 8; i++ ){
		rep (j, 8 ){
			c[i][j] = c[i-1][(i+j)%8];
		} // end rep
	} // end for
	sort (ALL (c ) );
/*
	rep (i, 8 ){
		rep (j, 8 ){
			cerr << setw(2) << c[i][j];
		} // end rep
		cerr << endl;
	} // end rep			
*/
	string str = "";
	while (getline (cin, str ) ){
		stringstream ss (str );
		vector<int> p (8, 0 );
		rep (i, 8 ){
			ss >> p[i];
		} // end rep

		int res = INF;
		int ans = -1;
		rep (i, 8 ){
			int curr = 0;
			rep (j, 8 ){
				curr += max (p[j] - c[i][j], 0 );
			} // end rep
			if (res > curr ){
				res = curr;
				ans = i;
			} // end if
		} // end rep
		rep (i, 8 ){
			cout << c[ans][i] << (i != 7 ? ' ' : '\n' );
		} // end rep
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1252
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, A;
vi X;

int main() {
    cin >> N >> A;
    X.resize(N);
    rep(i, N) cin >> X[i];

    vv<vll> dp = vvec<vll>(N + 1, 51, vector<ll>(2551, 0));
    dp[0][0][0] = 1;
    rep(i, 0, N) {
        rep(j, 0, i + 1) {
            rep(k, 0, 50 * j + 1) {
                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j + 1][k + X[i]] += dp[i][j][k];
            }
            int a = 0;
        }
        int b = 0;
    }

    ll ans = 0;
    rep(i, N) {
        ans += dp[N][i + 1][A * (i + 1)];
    }
    write(ans);
}

Measured memory_bytes: 53248
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    # 2019 = 3* 673
    L, R = LI()

    if (R//673 - (L-1)//673 > 0) and (R//3 - (L-1)//3 > 0):  # 範囲内に 673の倍数も3の倍数もある。
        print(0)
        return
    else: # 範囲は 673 よりも狭いので全探索してもいける。
        minimum = INF
        import itertools
        for x, y in itertools.combinations(range(L, R+1), 2):
            minimum = min((x*y)%2019, minimum)
        print(minimum)
        return


main()

Measured memory_bytes: 3064
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,M) = (int(i) for i in input().split(" "))
print("".join([str(min(N,M)) for i in range(max(N,M))]))

Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using itn = int;

int main(void){
    int n,m;
    cin >> n >> m;
    int a[m],b[m];
    for(int i = 0;i < m;i++)cin >> a[i] >> b[i];
    
    vector<vector<int>> G(n+1);
    for(int i = 0;i < m;i++){
        a[i]--;b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    
    vector<bool> v(n+1,false);
    vector<int> ans(n+1);
    queue<int> que;
    que.push(0);
    
    while(!que.empty()){
        int p = que.front();
        que.pop();
        
        for(auto u : G[p]){
            if(v[u] == true)continue;
            que.push(u);
            ans[u] = p;
            v[u] = true;
        }
    }
    
    cout << "Yes" << endl;
    for(int i = 1;i < n;i++){
        cout << ans[i] + 1<< endl;
    }
}


Measured memory_bytes: 11484
import sys
input=sys.stdin.readline

N,M=map(int,input().split())

R=[1 for i in range(N+1)]
A,B=map(int,input().split())
R[A]=0
R[B]=0

L=[[]for i in range(N+1)]
L[A].append(B)
L[B].append(A)

for i in range(M-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)

l=[A]
P=A
#print(L)

for i in range(10**6):
    flag=0
    #print("P",L[P])
    for j in L[P]:
        #print("j",L,L[P],j,P)
        if R[j]==1:
            P=j
            R[j]=0
            l.append(j)
            flag+=1
            break
    if flag==0:
        break
#print(l)
r=[B]
P=B
for i in range(10**6):
    flag=0
    #print("P",L[P])
    for j in L[P]:
        #print("j",L,L[P],j,P)
        if R[j]==1:
            P=j
            R[j]=0
            r.append(j)
            flag+=1
            break
    if flag==0:
        break
#print(r)
l=l[::-1]
ans=l+r

ANS=str(ans[0])
for i in range(1,len(ans)):
    ANS+=" "+str(ans[i])
print(len(ans))
print(ANS)


Measured memory_bytes: 25724
<?php
$N = intval(trim(fgets(STDIN)));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$B = array_map("intval", explode(" ", trim(fgets(STDIN))));
$dp = array_fill(0, 1<<$N, array_fill(0,51,PHP_INT_MAX));
$dp[0][0] = 0;
for($bit = 0, $NN = (1<<$N); $bit < $NN; ++$bit){
    $con = 0;
    for ($i = 0; $i < $N; ++$i) if ($bit & (1<<$i)) ++$con;
    $ords = [];
    $iter = $con - 1;
    for($i = 0; $i < $N; ++$i)
        if(!($bit & (1<<$i)))
            $ords[$i] = ++$iter;
    for($s = 0; $s <= 50; ++$s){
        if($dp[$bit][$s] == PHP_INT_MAX)continue;
        foreach($ords as $p0 => $p1){
            $ns = ($p0-$con) & 1 ? $B[$p0] : $A[$p0];
            if($ns >= $s){
                $dp[$bit | (1<<$p0)][$ns] = min($dp[$bit|(1<<$p0)][$ns], $dp[$bit][$s] + abs($p1 - $con));
            }
        }
    }
}
$min = min($dp[(1<<$N)-1]);
if($min == PHP_INT_MAX){
    echo -1;
}else{
    echo $min;
}


Measured memory_bytes: 682488
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

bool pari(string S){
    string R = S;
    reverse(R.begin(),R.end());
    if(R==S)return true;
    return false;
}

signed main(void){
    string S;
    cin >> S;
    
    int N = S.size();
    string T = S.substr(0,(N-1)/2);
    string U = S;
    reverse(U.begin(),U.end());
    U = U.substr(0,(N-1)/2);
    
    //cout << S MM T MM U << endl;
    if(pari(S) && pari(T) && pari(U)){
        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 < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

using namespace std;
using ll = long long;
using P = pair<int,int>;

double PI = 3.141592653589 ;

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

    cout << (double)(2.0)*PI*R<<endl;
    return 0;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int factors[1100000]; // 10^6は百万
void prime_fact(ll x) {
	vector<P<ll>> factor;
	for (ll i = 2; i * i <= x; i++) {
		if (x % i != 0) continue;
		int res = 0;
		while (x % i == 0) {
			res++;
			x /= i;
		}
		chmax(factors[i], res);
	}
	if (x != 1) chmax(factors[x], 1);
}
ll modpow(ll a, ll b, ll M) {
	ll res = 1;
	for (; b > 0; b >>= 1) {
		if (b & 1) res = (res * a) % M;
		a = a * a % M;
	}
	return res;
}
int main() {
	int n;
	cin >> n;
	V a(n);
	rep(i, n) {
		cin >> a[i];
		prime_fact(a[i]);
	}
	ll lcms = 1;
	rep(i, 1001001) {
		if (factors[i] == 0) continue;
		lcms *= modpow(i, factors[i], MOD);
		lcms %= MOD;
	}
	ll ans = 0;
	rep(i, n) {
		ans += lcms * modpow(a[i], MOD - 2, MOD);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4096
N = gets.strip.to_i
ABS = readlines.map {|line| line.strip}
ABS.each_with_index do |str, index|
  ABS[index] = str.split('').sort.join('')
end

class Integer
  def combination(k)
    return 1 if k.zero?
    (self - k + 1..self).inject(:*) / k.factorial
  end
  
  def factorial
    return 1 if self.zero?

    (1..self).inject(:*)
  end
end
count = 0
ABS.group_by{ |e| e }.each do |k,v|
  count += v.size.combination(2)
end

puts count

Measured memory_bytes: 47196
n, m = map(int, input().split())
key = [0] * (n+1)
for _ in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    key[l] += 1
    key[r+1] -= 1
ims = [0] * (n)
ims[0] = key[0]
for i in range(n-1):
    ims[i+1] = ims[i] + key[i+1]
ans = ims.count(m)
print(ans)

Measured memory_bytes: 7996
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct edge{
	int to,cost,num;
};

vector<edge> G[200];
bool used[100000];
int sz;

bool ok;

void dfs(int s,int d){
	if(d==sz){
		ok=true;
		return;
	}
	else if(ok)
		return;
	for(int i = 0; i < G[s].size(); i++){
		edge e = G[s][i];
		if(!used[G[s][i].num]){
			used[G[s][i].num]=true;
			dfs(G[s][i].to,d+1);
			used[G[s][i].num]=false;
		}
	}
}

int main(){
	while(1){
		ok=false;
		fill(used,used+100000,false);
		int from,to;
		sz=0;
		while(cin>>from>>to&&!(from==0&&to==0)){
			edge e;
			e.to=to;
			e.num=sz;
			G[from].push_back(e);
			e.to=from;
			G[to].push_back(e);
			sz++;
		}
		if(cin.eof())
			break;

		if(G[1].size()%2==1&&G[2].size()%2==1){
			bool f=false;
			for(int i = 3; i < 101; i++){
				if(G[i].size()==0)
					continue;
				else{
					if(G[i].size()%2){
						cout<<"NG"<<endl;
						f=true;
						break;
					}
				}
			}
			if(!f){
				cout<<"OK"<<endl;
			}
		}
		else
			cout<<"NG"<<endl;


//		dfs(1,0);
		//if(ok)
		//	cout<<"OK"<<endl;
		//else
		//	cout<<"NG"<<endl;

		for(int i = 0; i < 200; i++)
			G[i].clear();
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (ll)(1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll a[1 << 17];
int main() {
	int n; cin >> n;
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	ll out = 0;
	if (n % 2 == 0) {
		rep(i, n / 2) {
			sum -= 2 * a[i];
		}
		Rep(i, n / 2,n) {
			sum += 2 * a[i];
		}
		sum += a[n/2-1]; sum -= a[n/2];
		out = sum;
	}
	else {
		rep(i, n / 2) {
			sum -= 2 * a[i];
		}
		Rep(i, n / 2, n) {
			sum += 2 * a[i];
		}
		sum -= a[n / 2]; sum -= a[n / 2 + 1];
		out = max(out, sum);
		sum = 0;
		rep(i, n / 2 + 1) {
			sum -= 2 * a[i];
		}
		Rep(i,n/2+1,n){
			sum += 2 * a[i];
		}
		sum += a[n / 2];
		sum += a[n / 2 - 1];
		out = max(out, sum);
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
int main()
{
    int n, i, j, m, m2, s, t, k, T, w;
    char a[1001], b[100], c[1001], d[1001];

    scanf("%s", a);
    m = strlen(a);

    scanf("%d", &n);

    for (j = 0; j < n; j++)
    {

        scanf("%s", b);
        m2 = strlen(b);

        scanf("%d %d", &s, &t);

        if (b[0] == 'r' && b[1] == 'e' && b[2] == 'p')
        {
            scanf("%s", c);

            for (i = s; i <= t; i++)
            {
                a[i] = c[i - s];
            }
        }

        else if (b[0] == 'r' && b[1] == 'e' && b[2] == 'v')
        {

            for (i = s; i <= t; i++)
            {
                d[i] = a[i];
            }

            for (k = s; k <= t; k++)
            {
                a[k] = d[t - k + s];
            }
        }

        else
        {
            for (i = s; i <= t; i++)
            {
                printf("%c", a[i]);
            }
            printf("\n");
        }
    }

    return 0;
}



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

int N, A[101];

void trace(int A[], int len)
{
	for(int i = 0; i < len; i++)
	{
		printf("%d", A[i]);
		if(i < len-1)
		{
			printf(" ");
		}
	}
	printf("\n");
}


void BubbleSort(int A[], int n)
{
	int cnt = 0;
	for(int i = 0; i < n; i++)
	{
		for (int j = n-1; j >= i+1; j--) {
			if(A[j] < A[j-1])
			{
				swap(A[j], A[j-1]);
				cnt++;
			}
		}
	}
	trace(A, n);
	printf("%d\n", cnt);
	return;
}

int main(int argc, char *argv[]) {
	cin >> N;
	for(int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	BubbleSort(A, N);
	return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    double n, t, a; cin >> n >> t >> a;

    double jud = t + 10000.0;
    int ans;

    rep(i,n){
        double h; cin >> h;
        if(jud != min(jud,abs((t - h * 0.006)-a))){
        jud = abs((t - h * 0.006)-a);
        ans = i+1;
        }
    }

    dunk(ans);

}
    

Measured memory_bytes: 256
N = int(input())
alphabet_lst = list('abcdefghijklmnopqrstuvwxyz')
#print(alphabet_lst)

keta = 0
keta_lst = []
sum_lst = []
while N>=sum(keta_lst):
    keta_lst.append(26**keta)
    sum_keta = sum(keta_lst)
    sum_lst.append(sum_keta)
    keta += 1
    
keta -= 1
keta_lst = keta_lst[:keta]
#print(keta_lst)
#print(keta)

ans_lst = []
for i in range(keta):
    ans_n = (N - sum(keta_lst[:-(i+1)])) // keta_lst[-(i+1)]
    #print(ans_n)
    #print(keta_lst[-(i+1)])
    N -= ans_n*keta_lst[-(i+1)]
    ans_lst.append(alphabet_lst[ans_n-1])

for i in range(keta):
    print(ans_lst[i],end="")

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define pb  push_back
#define mp  make_pair
#define v1  first
#define v2  second
using namespace std;

typedef pair <int,int>  PII;
const int N=605;
int n,d1,d2,vis[N][N];
vector <PII> V;

void dfs(int x,int y)
{
	for (auto d:V)
		if ((0<=x+d.v1)&&(x+d.v1<2*n)&&(0<=y+d.v2)&&(y+d.v2<2*n))
			if (!vis[x+d.v1][y+d.v2])
				{
					vis[x+d.v1][y+d.v2]=vis[x][y]^1;
					dfs(x+d.v1,y+d.v2);
				}
}

void solve(int d)
{
	V.clear();
	for (int i=-2*n+1; i<2*n; i++)
		for (int j=-2*n+1; j<2*n; j++)
			if (i*i+j*j==d)
				V.pb(mp(i,j));
	for (int i=0; i<2*n; i++)
		for (int j=0; j<2*n; j++)
			if (!vis[i][j])
				vis[i][j]=2,dfs(i,j);
	int cnt2=0,cnt3=0;
	for (int i=0; i<2*n; i++)
		for (int j=0; j<2*n; j++)
			{
				cnt2+=(vis[i][j]==2);
				cnt3+=(vis[i][j]==3);
			}
	if (cnt2<cnt3)
		{
			for (int i=0; i<2*n; i++)
				for (int j=0; j<2*n; j++)
					if (vis[i][j]>1)
						vis[i][j]^=1;
		}
	for (int i=0; i<2*n; i++)
		for (int j=0; j<2*n; j++)
			if (vis[i][j]>1)
				vis[i][j]-=2;
}

void work()
{
	scanf("%d %d %d",&n,&d1,&d2);
	solve(d1),solve(d2);
	for (int i=0,k=n*n; i<2*n; i++)
		for (int j=0; j<2*n; j++)
			if ((!vis[i][j])&&(k>0))
				printf("%d %d\n",i,j),k--;
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 19200
x,y=map(int,input().split())
mod=10**9+7

def comb(n,k):
    if n<k:
        return 0
    if n-k<k:
        k=n-k
    comb=1
    for x in range(n-k+1,n+1):
        comb=(comb*x)%mod
    d=1
    for x in range(1,k+1):
        d =(d*x)%mod
    comb*=pow(d,mod-2,mod)
    return comb%mod

ans=0
if (x+y)%3==0:
    n=int((x+y)/3)
    r=int((2*x-y)/3)
    if n-r>=0 and r>=0:
        ans=comb(n,r)%mod
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define vector basic_string
#define fi first
#define se second
#ifndef qwq
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
#endif
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=200010; const double err=1e-11; typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;} typedef double lf; typedef long double llf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;} typedef pair<int,int> pii; template<typename A,typename B> ostream &operator<<(ostream &o,const pair<A,B> &x){return o<<'('<<x.fi<<','<<x.se<<')';}
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
//#define int ll
ll n,k;
signed main(){
	cin>>n>>k;
	n%=k;
	cout<<min(n,k-n)<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int H, W;
vector<string>S;
int dp[123][123][246];

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		string s;
		cin >> s;
		S.push_back(s);
	}
	memset(dp, 0x7f, sizeof(dp));
	dp[0][0][0] = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			for (int k = 0; k <= H + W + 2; ++k) {
				if (i > 0)
					if (k - (S[i][j] == S[i - 1][j] ? 0 : 1) >= 0)
						dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k - (S[i][j] == S[i - 1][j] ? 0 : 1)]);
				if (j > 0)
					if (k - (S[i][j] == S[i][j - 1] ? 0 : 1) >= 0)
						dp[i][j][k] = min(dp[i][j][k], dp[i][j - 1][k - (S[i][j] == S[i][j - 1] ? 0 : 1)]);
			}
		}
	}
	int ans = 0;
	while (dp[H - 1][W - 1][ans] > 0)ans++;
	ans /= 2;
	ans++;
	if (S[0][0] == '.') {
		if (S[H - 1][W - 1] == '.') {
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14848
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] e = new int[m];
		int[] num =  new int[n+1];
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i=0;i<m;i++){
			int x = sc.nextInt();
			num[x] = 1;
			list.add(x);
		}
		for(int i=list.size()-1;i>=0;i--){
			if(num[list.get(i)]==1){
				System.out.println(list.get(i));
				num[list.get(i)] = 2;
			}
		}
		for(int i=1;i<=n;i++){
			if(num[i]==0){
				System.out.println(i);
			}
		}	
	}
}

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

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<long long> red(a), gre(b), whi(c);
    for (auto &e : red) cin >> e;
    for (auto &e : gre) cin >> e;
    for (auto &e : whi) cin >> e;
    
    sort(red.begin(), red.end(), greater<long long>());
    sort(gre.begin(), gre.end(), greater<long long>());
    
    for (int i = 0; i < x; i++) whi.emplace_back(red[i]);
    for (int i = 0; i < y; i++) whi.emplace_back(gre[i]);
    
    sort(whi.begin(), whi.end(), greater<long long>());
    
    cout << accumulate(whi.begin(), whi.begin() + x + y, 0LL) << endl;
    return 0;
}

Measured memory_bytes: 6000
#include<iostream>
using namespace std;
int main()
{
    int num,temp;
    while(cin>>num)
    {
        temp=num%10;
        if(temp==2 || temp==4 || temp==5 ||temp==7 || temp==9 )
        {
            cout<<"hon"<<endl;
        }
        else if(temp==0 || temp==1 || temp==6 || temp==8 )
        {
            cout<<"pon"<<endl;
        }
        else if(temp==3)
        {
            cout<<"bon"<<endl;
        }
        break;
    }
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt(), k = s.nextInt();
		long sum = 0;
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		Arrays.sort(a);
		for(int i=0;i<n-k;i++) {
			sum += a[i];
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 89308
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

int partition(int,int);

int A[MAX];

int main(){
int i,n,k;

scanf("%d",&n);
if(n > 100000) exit(2);
for(i = 0; i < n ; i++){
  scanf("%d",&A[i]);
}

k = partition(0,n - 1);

for(i = 0; i < n-1 ; i++){
  if(i == k)printf("[%d] ",A[i]);
  else printf("%d ",A[i]);
}
  printf("%d\n",A[i]);

  return 0;
}

int partition(int p,int r){
  int i,j,x,z;
  x = A[r];
  i = p - 1;
  for(j = p; j < r ; j++){
    if(A[j] <= x){
      i++;
      z = A[i];
      A[i] = A[j];
      A[j] = z;
    }
  }
  z = A[i + 1];
  A[i + 1] = A[r];
  A[r] = z;

  return i + 1;
}



Measured memory_bytes: 2140
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main(){
  int n;
  cin >> n;
  ll c = 0;
  vector<ll>a(n),b(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }
  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());
  rep(i,n){
  	a[i] += c;
    ll t = (a[i]/b[i])*b[i];
    if(a[i]!=t){
    	t += b[i];
      	c += t-a[i];
    }
  }
  cout << c << endl;
  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int ac=0,wa=0,tle=0,re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="AC")ac++;
        else if(s=="WA")wa++;
        else if(s=="TLE")tle++;
        else re++;
    }
    cout<<"AC x "<<ac<<endl;
     cout<<"WA x "<<wa<<endl;
      cout<<"TLE x "<<tle<<endl;
       cout<<"RE x "<<re<<endl;

    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;

int main(){

  string n,m;

  while(true){
    cin >> n >> m;
    if(n == "0" && m == "0") break;

    int hit = 0,blow = 0;

    for(int i=0;i<4;i++){
      if(n[i] == m[i]){
	hit++;
	m[i] = 'A';
      }
    }

    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
	if(n[i] == m[j]){
	  blow++;
	  m[j] = 'A';
	}
      }
    }

    cout << hit << " " << blow << endl;

  }

}

Measured memory_bytes: 1184
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int P[1010], X[1010];
vector <int> E[1010];
int N;
pii R[1010];
int ok = 1;

void dfs(int x) {
	if(sz(E[x]) == 0) {
		R[x] = pii(0, X[x]);
		return;
	}
	int sum = 0; vector <int> v;
	int sum2 = 0;
	for(int e : E[x]) {
		dfs(e);
		sum += R[e].Fi;
		sum2 += R[e].Se;
		v.pb(R[e].Se - R[e].Fi);
	}
	if(sum > X[x]) { ok = 0; return; }
	int d[5050] = {};
	d[0] = 1;
	int rr = X[x] - sum;
	for(int e : v) {
		for(int j=rr-e;j>=0;j--) d[j+e] |= d[j];
	}
	int f = -1;
	for(int j=rr;j>=0;j--) if(d[j]) { f = j; break; }
	R[x].Fi = X[x], R[x].Se = sum2 - f;
	if(R[x].Fi > R[x].Se) swap(R[x].Fi, R[x].Se);
}

void solve(){
	scanf("%d", &N);
	for(int i=2;i<=N;i++) scanf("%d", P+i);
	for(int i=1;i<=N;i++) scanf("%d", X+i);
	for(int i=2;i<=N;i++) E[P[i]].pb(i);
	dfs(1);
	puts(ok ? "POSSIBLE" : "IMPOSSIBLE");
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		// printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}

Measured memory_bytes: 8832
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
const int INF = 1100100;
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  int x = k + A[0] - A[n - 1];
  rep(i, n - 1) x = (max(x, A[i + 1] - A[i]));
  cout << k - x << endl;
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
ll n,a[100009],dp[100009];
	
int main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> a[i];
	}
	for (int i=n; i>=1; i--){
		ll x,y;
		if (i<=n-2){
			dp[i]=min(abs(a[i]-a[i+1])+dp[i+1],abs(a[i]-a[i+2])+dp[i+2]);
		}
		else if (i==n-1) dp[i]=abs(a[i]-a[i+1])+dp[i+1];
	}
	cout << dp[1] << endl;	
}

Measured memory_bytes: 1792
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun main(args: Array<String>) {
    val N = readLong()
    val A = readLongList().toMutableList()
    val B = readLongList().toMutableList()

    var res = 0L
    for (i in B.indices) {
        var win = A[i].coerceAtMost(B[i])
        A[i] -= win
        B[i] -= win
        res += win

        win = A[i + 1].coerceAtMost(B[i])
        A[i + 1] -= win
        B[i] -= win
        res += win
    }
    println(res)
}

Measured memory_bytes: 80480
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = np.array(rl())
answer = 0
MOD = 10 ** 9 + 7

for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x

print(answer%MOD)


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

int main() {
    int i, j, n, a[52] = {}, x;
    char ch, mark[4] = {'S', 'H', 'C', 'D'};

    cin >> n;
    for(i=0; i<n; ++i) {
        cin >> ch >> x;
        switch(ch) {
            case 'S':
                ++a[x-1];
                break;
            case 'H':
                ++a[13+x-1];
                break;
            case 'C':
                ++a[26+x-1];
                break;
            case 'D':
                ++a[39+x-1];
                break;
            default:
                break;
        }
    }

    for(i=0; i<52; ++i) {
        if(a[i] < 1) {
            cout << mark[i/13] << ' ' << i%13+1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rand365(1,365);
uniform_int_distribution<> rand26(1,26),rand100(0,100);
ll D,c[30];
vec s[400];
vec ans(400);
double start_temp=10,end_temp=0;
double start_time,TIME_LIMIT=1.95;
ll score(vec A){
    ll ans=0,last[30]={0};
    rep1(i,D){
        ans+=s[i][A[i]];
        last[A[i]]=i;
        rep1(j,26) ans-=c[j]*(i-last[j]);
    }
    return ans;
}

double getTime(){
    return (double)clock()/CLOCKS_PER_SEC;
}

void input(){
    cin>>D;
    rep1(i,26) cin>>c[i];
    int S;
    rep1(i,D){
        s[i].push_back(0);
        rep(j,26) cin>>S,s[i].push_back(S);
    }
}


void solve(){
    rep1(i,D){
        ans[i]=max_element(all(s[i]))-s[i].begin();
        if(110<i&&i<137) ans[i]=i%26;
        if(210<i&&i<237) ans[i]=i%26;
    }
    start_time=getTime();
    ll now=score(ans);
    while(true){
        double now_time=getTime();
        if (now_time - start_time > TIME_LIMIT) break;
        double temp = start_temp + (end_temp - start_temp) * (now_time-start_time) / TIME_LIMIT;
        int d=rand365(mt),q=rand26(mt),preq;
        preq=ans[d];
        ans[d]=q;
        ll a=score(ans);
        if(a>now) now=a;
        else{
            if(temp>rand100(mt)) now=a;
            ans[d]=preq;
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    input();
    solve();
    rep1(i,D) cout<<ans[i]<<"\n";
}


Measured memory_bytes: 3780
// Created by: WeirdBugsButOkay

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define endl '\n'

using namespace std;

void solve()
{
	int x[5];
	for(int i = 0; i < 5; i++)
	{
		cin >> x[i];
	}
	for(int i = 0; i < 5; i++)
		if(x[i] == 0)
			cout << i + 1;
}

int main()
{
	int q = 1;
	//scanf("%d", &q);
	for(int i = 1; i <= q; i++)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <map>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;

int g[205][205];
const int INF = 1000000000;

int vs[10];
int perm[10];

int main(void) {
  int nNode, nEdge, n;
  scanf("%d%d%d", &nNode, &nEdge, &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
    --vs[i];
  }
  REP(i, nNode) REP(j, nNode) {
    g[i][j] = i == j ? 0 : INF;
  }
  REP(i, nEdge) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a;
    --b;
    g[a][b] = c;
    g[b][a] = c;
  }
  // REP(i, nNode) {
  //   REP(j, nNode) {
  //     cerr << g[i][j] << " ";
  //   }
  //   cerr << endl;
  // }
  REP(k, nNode) REP(i, nNode) REP(j, nNode) {
    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  }
  REP(i, n) {
    perm[i] = i;
  }
  // REP(i, nNode) {
  //   REP(j, nNode) {
  //     cerr << g[i][j] << " ";
  //   }
  //   cerr << endl;
  // }

  int res = INF;
  do {
    int cur = 0;
    REP(i, n-1) {
      cur += g[vs[perm[i]]][vs[perm[i+1]]];
    }
    res = min(res, cur);
  } while(next_permutation(perm, perm + n));
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;int x;cin>>x;
    cout << (int)(x/500)*1000+(int)((x%500)/5)*5 << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

int main(){
	int n;
	while(cin>>n,n){
		vector<int>s(n),p(n);
		for(int i = 0; i < n; i++) cin>>p[i];
		int cnt = 0;
		do{
			s.swap(p);
			map<int,int> st;
			for(int i = 0; i < n; i++) st[s[i]]++;
			for(int i = 0; i < n; i++) p[i] = st[s[i]];
			cnt++;
		}while(s != p);
		cout << cnt - 1 << endl;
		for(int i = 0; i < n; i++) printf("%d%c",p[i],i==n-1?'\n':' ');
	}

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 1
 
int main()
{	
	ios_base::sync_with_stdio(0);
    int n,m,a,b;
    cin>>n>>m;
    std::vector<int> arr(n,-1);
    while(m--){
    	cin>>a>>b;
    	a--;
    	if(arr[a]>=0 && arr[a]!=b){
    		cout<<-1<<endl;
    		return 0;
    	}
    	arr[a] = b;
    }
    if(arr[0]==0 && n>1){
    	cout<<-1<<endl;
    	return 0;
    }
    if(arr[0]==-1){
    	if(n==1) arr[0] = 0;
    	else arr[0] = 1;
    }

    for(int i=1; i<n; i++){
    	if(arr[i]==-1) arr[i] = 0;
    }
    int ans = 0;
    for(int i=0; i<n; i++){
    	ans = ans*10 + arr[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//ContestwithDrinksEasy.cpp (B)
#include <iostream>
#include <string>
using namespace std;

int main(){
  int N,M,total;
  int T[110],P[110],X[110];
  cin >> N;
  total = 0;
  for(int i = 0; i < N; i++) cin >> T[i], total += T[i];
  cin >> M;
  for(int i = 0; i < M; i++) cin >> P[i] >> X[i];
  int Ans;
  for(int i = 0; i < M; i++){
    Ans = 0;
    Ans = total - T[P[i]-1] + X[i];
    printf("%d\n",Ans);
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{
    public void AtCoder()
    {
        string[] input;
        input = Console.ReadLine().Split(' ');

        string s = input[0];
        int x = int.Parse(s.Substring(0, 2));
        int y = int.Parse(s.Substring(2, 2));
        string ans = "";
        if(1 <= x && x <= 12)
        {
            if (1 <= y && y <= 12)
            {
                ans = "AMBIGUOUS";
            }
            else ans = "MMYY";
        } else
        {
            if (1 <= y && y <= 12)
            {
                ans = "YYMM";
            }
            else ans = "NA";
        }

        

        Console.WriteLine(ans);
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

typedef long long lli;
typedef pair<lli, lli> P;

const lli N = 2005;
const lli M = 100005;
const lli INF = 1e12;

lli n, m, l, K[N], S[M+1], dp[N][N], cum[M+1];
P vec[N];

lli calc(lli a, lli b){
	//if(vec[a].first > vec[b].first) swap(a, b);
	//return (cum[vec[b].second] - cum[vec[a].second-1]) / l;
	return (cum[K[a]] - cum[K[b]-1]) / l;
}

int main(){
	cin >> n >> m >> l;
	for(lli i=0;i<n;i++) cin >> K[i];
	for(lli i=1;i<=m;i++) cin >> S[i];
	cum[0] = 0;
	for(lli i=1;i<=m;i++) cum[i] = cum[i-1] + S[i];
	for(lli i=0;i<n;i++) vec[i] = make_pair(S[K[i]], K[i]);
	//sort(vec, vec+n);
	//reverse(vec, vec+n);
	sort(K, K+n);
	reverse(K, K+n);
	fill(dp[0], dp[N], INF);
	dp[0][0] = 0;
	for(lli i=0;i<n;i++){
		for(lli j=0;j<=i;j++){
			if(dp[i][j] >= INF) continue;
			int h = i+1;
			//dp[i+1][j] = min(dp[j][i+1], dp[i][j] + calc(i, i+1));
			//dp[i+1][i] = min(dp[i+1][i], dp[i][j] + calc(j, i+1));
			dp[h][j] = min(dp[j][h], dp[i][j] + (cum[K[i]] - cum[K[h]-1]) / l);
			dp[h][i] = min(dp[h][i], dp[i][j] + (cum[K[j]] - cum[K[h]-1]) / l);
		}
	}
	lli ans = INF;
	for(lli i=0;i<n;i++){
		ans = min(ans, dp[n-1][i] + (cum[K[i]] - cum[K[n-1]-1]) / l);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 34192
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a,b,c,k;
int jyz(int x,int y)
{
	int tmp=x;
	for (int i=1;i<=y;i++) tmp*=2;
	return tmp;
}
signed main()
{
	cin>>a>>b>>c>>k;
	bool flag=0;
	for (int i=0;i<=k;i++)
	{
		int j=k-i;
		if (a<jyz(b,i)&&jyz(b,i)<jyz(c,j)) flag=1;
	}
	if (flag) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 3620
N, W= map(int, input().split())
inf1 = 10**9+10
inf = 10**5+10
dp = [inf1]*inf

for j in range(N):
    w, v = map(int, input().split())
    for i in reversed(range(inf)):
        
        if i>v:
            dp[i] = min(dp[i], dp[i-v]+w)
        else:
            dp[i] = min(dp[i], w)
j = 0
while dp[j+1]<=W:
    j+=1

print(j)

Measured memory_bytes: 42860
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next()) - 1;
		char[] s = sc.next().toCharArray();
		s[k] += 32;
		for(int i = 0 ; i < n ; i++) ou.print(s[i]);
		ou.println();
		ou.flush();
	}
}

Measured memory_bytes: 35648
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    int mini=1000;
    cin>>s;
    int n=s.size();
    rep(i,n-2){
        int num=(s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0';
        mini=min(abs(753-num),mini);
    }
    cout<<mini;
}

Measured memory_bytes: 3488
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    char a[10];
    cin>>a;
    if(a[2]==a[3]&&a[4]==a[5])
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  long k, a, b;
  readf("%s %s %s\n", &k, &a, &b);
  auto res = k + 1;
  
  long cnt = 1;
  if (cnt < a) {
    k -= a - cnt;
    cnt += a - cnt;
  }
  if (k >= 0) {
    auto d = b - a;
    cnt += d * (k / 2);
    cnt += k % 2;
    res = max(res, cnt);
  }
  res.writeln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long ans=114514,n,tmp;
  string s,t;
  cin >> n;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0){
      s=to_string(n/i);
      t=to_string(i);
      if(s.size()>t.size()){
      	tmp=s.size();  
      }else{
        tmp=t.size();
      }
      ans=min(ans,tmp);
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

    vector<int64_t> hero(n);
    vector<int64_t> monstor(n + 1);

    for (int i = 0; i < n + 1; i++){
        cin >> monstor.at(i);
    }
    for (int i = 0; i < n; i++){
        cin >> hero.at(i);
    }

    int64_t count = 0;
    for (int i = 0; i < n; i++){
        // 他の町も倒す余力ある
        if (hero.at(i) >= monstor.at(i)){
            count += monstor.at(i);
            hero.at(i) -= monstor.at(i);
            // 他の町
            if (hero.at(i) > 0){
                if (hero.at(i) >= monstor.at(i + 1)){
                    count += monstor.at(i + 1);
                    monstor.at(i + 1) -= hero.at(i);
                    if (monstor.at(i + 1) < 0){
                      monstor.at(i + 1) = 0;
                    }
                }
                else{
                    count += hero.at(i);
                    monstor.at(i + 1) -= hero.at(i);
                }
            }
        }
        else{
            count += hero.at(i);
        }
    }

    cout << count << endl;
}

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

int main(){
	int x,y,w,h,r;
	cin >> w >> h >> x >> y >> r;
	
	if((x<=w-r)&&(x>=r)&&(y<=h-r)&&(y>=r )) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#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++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
const int inf=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};


int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(a-x)<abs(b-x))cout<<"A"<<endl;
  else cout<<"B"<<endl;
  return 0;
  }

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

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 10;
ll par[maxn], mn, mx, ans;
int n, a[maxn];

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		par[i + 1] = par[i] + a[i];
	}
	ans = 1e18;
	for (int i = 2; i + 1 < n; ++i) {
		int b = 1, e = i, mid;
		mx = 0, mn = 1e18;
		while (e - b > 1) {
			mid = (b + e) >> 1;
			if (par[mid] * 2 > par[i])
				e = mid;
			else
				b = mid;
		}
		if (b + 1 != i && par[b + 1] < par[i] - par[b])
			b++;
		mx = max(mx, par[b]);
		mn = min(mn, par[b]);
		mx = max(mx, par[i] - par[b]);
		mn = min(mn, par[i] - par[b]);
		b = i + 1, e = n;
		while (e - b > 1) {
			mid = (b + e) >> 1;
			if ((par[mid] - par[i]) * 2 > par[n] - par[i])
				e = mid;
			else
				b = mid;
		}
		if (b + 1 != n && par[b + 1] - par[i] < par[n] - par[b])
			b++;
		mx = max(mx, par[b] - par[i]);
		mn = min(mn, par[b] - par[i]);
		mx = max(mx, par[n] - par[b]);
		mn = min(mn, par[n] - par[b]);
		ans = min(ans, mx - mn);
	}
	cout << ans << '\n';
	return 0;
}


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

int main(void) {
    int N;
    cin>>N;
    int B[N];
    B[0] = 0;
    // B1 >= max(A1, A2) >= A1, A2
    // B2 >= max(A2, A3) >= A2, A3
    // BN-1 >= max(AN-1, AN)
    // A1 + A2 + .... + AN <= ????
    for (int i = 1; i <= N - 1; i++) cin >> B[i];
    int result = 0;
    for (int i = 1; i <= N; i++) {
        if (i == 1) result += B[1];
        else if (i == N) result += B[N - 1];
        else result += min(B[i], B[i - 1]);
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  vector<int> w(10), k(10);
  for(int i = 0; i < 10; ++i) {
	cin >> w[i];
  }
  for(int i = 0; i < 10; ++i) {
	cin >> k[i];
  }
  sort(w.begin(), w.end());
  sort(k.begin(), k.end());

  cout << w[7] + w[8] + w[9] << " " << k[7] + k[8] + k[9] << endl;
  return 0;
}

Measured memory_bytes: 3060