akhauriyash/Code-Regression huggingface dataset:
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;
#define int LL

const int inf = 1e9,maxn=2e5+5;

int n,a[maxn],nxt[maxn][22],lst[maxn],b[maxn];

signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]); 
	for(int i=0;i<=20;i++){
		for(int j=1;j<=n;j++)b[j] = 0;
		for(int j=1;j<=n;j++)
			if(a[j]&(1<<i))b[j] = 1;
		nxt[n+1][i] = n+1;
		int cnt = 0, most = n+1;
		for(int j=n;j>=1;j--){
			if(!b[j]){
				nxt[j][i] = most;
				continue;
			}
			++ cnt;
			nxt[j][i] = most;
			most = j;
		}
//		for(int j=n;j>=1;j--)lst[j] = max(lst[j], nxt[j]);
	}
	LL ans=0;
	for(int i=1;i<=n;i++){
		int mx = inf;
		for(int j=0;j<=20;j++){
			if(a[i]&(1<<j)){
				mx = min(mx,nxt[i][j] - 1);
			}else{
				mx = min(mx,nxt[nxt[i][j]][j] - 1);
			}
		}
		ans += mx-i+1;
	}
	printf("%lld\n",ans);

	return 0;
}


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

int N;

int main() {
    cin >> N;

    if (N % 2 == 0) {
        vector<pair<int, int> > vp;
        for (int i = 1; i <= N; i++) {
            for (int j = i; j <= N; j++) {
                if (j != i && j != N+1-i) {
                    vp.push_back(make_pair(i, j));
                }
            }
        }
        cout << vp.size() << endl;
        for (int i = 0; i < vp.size(); i++) {
            cout << vp[i].first << " " << vp[i].second << endl;
        }
    }
    else {
        vector<pair<int, int> > vp;
        for (int i = 1; i < N; i++) {
            for (int j = i; j < N; j++) {
                if (j != i && j != N-i) {
                    vp.push_back(make_pair(i, j));
                }
            }
        }
        for (int i = 1; i < N; i++) {
            vp.push_back(make_pair(N, i));
        }
        cout << vp.size() << endl;
        for (int i = 0; i < vp.size(); i++) {
            cout << vp[i].first << " " << vp[i].second << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>

using namespace std;
typedef long long int ll;



int n;
int abc[100010][3];
ll dp[100010][3];
bool dpf[100010][3];

int main(){
    scanf("%d",&n);
    //for(int i=0;i<n;i++)scanf("%lld",&h[i]);
    for(int i=0;i<n;i++){
        scanf("%d %d %d",&abc[i][0],&abc[i][1],&abc[i][2]);
        
    }
    for(int i=0;i<3;i++)dp[0][i]=0;
    
    for(int i=1;i<=n;i++){
        for(int j=0;j<3;j++){
            for(int m=0;m<3;m++){
                if(m==j)continue;
                if(dpf[i][m]){
                    dp[i][m]=max(dp[i-1][j]+abc[i-1][m],dp[i][m]);
                }
                else{
                    dpf[i][m]=true;
                    dp[i][m]=dp[i-1][j]+abc[i-1][m];
                }
            }
        }
    }
    
    printf("%lld\n",max(max(dp[n][0],dp[n][1]),dp[n][2]));
    
}

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

int main(){
  int A ,B ,C;
  scanf("%d %d %d", &A, &B, &C);
  
  bool can=false;
  for(int i=0; i<B; i++){
    int mod=(A*i)%B;
    if(mod==C){
      can=true;
      break;
    }
  }
  
  printf((can? "YES" : "NO"));
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
#define MAX 100
#define nan -1
struct node{int p,l,r;};
node tree[MAX];
int num;
void print_qian(int root){
cout<<" "<<root;	
if(tree[root].l!=nan)	print_qian(tree[root].l);
if(tree[root].r!=nan)	print_qian(tree[root].r);
return ;
}
void print_zhong(int root){
if(tree[root].l!=nan)	print_zhong(tree[root].l);
cout<<" "<<root;
if(tree[root].r!=nan)	print_zhong(tree[root].r);
return ;
}
void print_hou(int root){
if(tree[root].l!=nan)	print_hou(tree[root].l);
if(tree[root].r!=nan)	print_hou(tree[root].r);
cout<<" "<<root;	
return ;
}
int main(){
	 scanf("%d",&num);
	 for(int i=0;i<num;i++){tree[i].p=tree[i].l=tree[i].r=nan;}
	 for(int i=0;i<num;i++){
	 	int v,l,r;
	 	scanf("%d %d %d",&v,&l,&r);
	 	if(l!=-1){tree[v].l=l;tree[l].p=v;}
	 	if(r!=-1){tree[v].r=r;tree[r].p=v;}
	 }
	 int root;
	 for(int i=0;i<num;i++){
	 	if (tree[i].p==nan) root=i;
	 }
	 cout<<"Preorder"<<endl;
	 print_qian(root);cout<<endl;
	 cout<<"Inorder"<<endl;
	 print_zhong(root);cout<<endl;
	 cout<<"Postorder"<<endl;
	 print_hou(root);cout<<endl;
}



Measured memory_bytes: 3152
def get_postorder(preorder, inorder):
    if not preorder:
        return []

    root = preorder[0]
    root_index = inorder.index(root)
    result = []

    result.extend(get_postorder(preorder[1:root_index+1], inorder[:root_index]))
    result.extend(get_postorder(preorder[root_index+1:], inorder[root_index+1:]))
    result.append(root)

    return result


if __name__ == '__main__':
    n = int(input())
    preorder = list(map(int, input().split()))
    inorder = list(map(int, input().split()))

    print(*get_postorder(preorder, inorder))

Measured memory_bytes: 7728
#include<bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5;
int N;
ll K,A[MAX_N],B[MAX_N];
int main(){
	scanf("%d %lld",&N,&K);
	REP(i,N){
		scanf("%lld %lld",A+i,B+i);
	}
	K++;
	int dig=0;
	{
		ll k=K;
		while(k){
			dig++;
			k>>=1;
		}
	}
	ll ans=0;
	REP(i,dig){
		if((K>>i)&1){
			ll k=(1ll<<i)-1+((K>>(i+1))<<(i+1));
			ll sm=0;
			REP(j,N){
				if((k|A[j])==k){
					sm+=B[j];
				}
			}
			ans=max(ans,sm);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1920
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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 ll mod=1e9+7;

int main(){
    ll a,b;
    cin >> a >> b;
    ll ans=0;
    for(ll i=a;i<=b;i++){
        string s=to_string(i);
        bool ok=true;
        rep(j,5){
            if(s[j]!=s[4-j]){
                ok=false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
} 

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

int main(){
    string s;
    cin >> s;
    rep(i,s.size()){
        cout << "x";
    }
    cout << endl;

    return 0;
}

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


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

    // all the code goes here
    int n;cin>>n;
    int dp[n][3];
    int m[n][3];
    for(int i = 0; i< n; i++){
        for(int j = 0; j< 3; j++)
        {
            cin>>m[i][j];
            dp[i][j] = 0;
        }
    }


    
    // dp[0] = *max_element(m[0],m[0]+3);
    for(int i = 0; i < 3; i++)
    {
        dp[0][i] = m[0][i];
    }

    for(int i = 1; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            for(int k = 0; k < 3; k++)
            {
                if(j != k)
                {
                    dp[i][j] = max(dp[i][j],dp[i-1][k]+m[i][j]);
                }
            }
        }
    }

    cout<<*max_element(dp[n-1],dp[n-1]+3)<<"\n";
    return 0;
}

Measured memory_bytes: 2560
using System;

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

            Console.WriteLine(GCD(a, b));

        }

        public static int GCD (int x, int y)
        {
            if (x == 0) return y;
            if (x < y)
            {
                int tmp = x;
                x = y;
                y = tmp;
            }
            return GCD(x % y, y);
            
        }
    }
}

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

const int MAX = 100005;
ll fac[MAX], finv[MAX], inv[MAX];

struct mint {
    ll x;
    mint(ll x=0):x(x%MOD){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
};

mint factorial(int n) {
    mint res = 1;
    rep(i, n) {
        res *= i+1;
    }
    return res;
}

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

    if (abs(n-m) > 1) {
        puts("0");
        return 0;
    }

    mint ans = 1;
    if (n == m) {
        ans = factorial(n);
        ans *= ans;
        ans *= 2;
    }
    else {
        ans = factorial(n);
        ans *= factorial(m);
    }

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define N 10000

int H=0,A[2000000001];

void maxHeapify(int k){
  int v,l,r,z;
  l=k*2;
  r=k*2+1;
  z=k;
  if(l<=H&&A[l]>A[k]) z=l;
  else z=k;
  if(r<=H&&A[r]>A[z]) z=r;

  if(z!=k){
    v=A[k];
    A[k]=A[z];
    A[z]=v;
    maxHeapify(z);
  }
}

int extract(){
  int m;
  if(H<1)return -N;
  m=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return m;
}

void t(int a,int b,int i){
  A[i/2]=a;
  A[i]=b;
  return;
}

void upheap(int i, int k) { 
    int v;
    if(k<A[i]) return;
    A[i]=k;
    while(i > 1 && A[i/2]<A[i]) {
      t(A[i],A[i / 2],i);
        i = i / 2;
    }
}


void insert(int k) {
  H++;
    A[H] = -N;
    upheap(H,k);
}

int main() {

  int i,a;
  char c[10];


    while(1){
      scanf("%s",c);
      if(c[0]=='e'&&c[1]=='n')break;
      if(c[0]=='i'){
	scanf("%d",&a);
	insert(a);
      }
      else printf("%d\n",extract());
    }
   
    return 0;
}



Measured memory_bytes: 5752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
  ll n,m;
  cin >> n >> m;
  
  ll p[m];
  string s[m];
  rep(i,m) cin >> p[i] >> s[i];
  
  ll acnum[n+1];
  for(ll i = 0; i < m; i++){
    if(s[i] == "AC"){
      acnum[p[i]] = 1;
    }
  }
  
  ll ac = 0, wa = 0;
  ll ok[n+1];
  for(ll i = 1; i <= n; i++) ok[i] = 0;
  for(ll i = 0; i < m; i++){
    if(s[i] == "WA" && ok[p[i]] == 0 && acnum[p[i]] == 1){
      wa++;
    }
    if(s[i] == "AC" && ok[p[i]] == 0){
      ok[p[i]] = 1;
      ac++;
    }
  }
  
  cout << ac << " " << wa << endl;
}

Measured memory_bytes: 8960
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

string s;

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> s)
    {
		ans = 0;

		ll cnt = 0;

		s += 'S';
		for(auto it: s)
		{
			if(it == 'R') cnt++;
			else
			{
				ans = max(ans, cnt);
				cnt = 0;
			}
		}

		cout << ans << "\n";
    }


}





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

using namespace std; 

int main() 
{ 
    long long int n1,n2,e=1000000007;
	
	cin>>n1>>n2;
	
	long long int a[n1],b[n2];
	
	for(long long int i = 0 ; i < n1 ; i++) cin>>a[i];
	for(long long int i = 0 ; i < n2 ; i++) cin>>b[i];
	
	long long int cnt[n1+1][n2+1];
	memset(cnt,0,sizeof(cnt));

    for(long long int i = 0 ; i <= n1 ; i++){
        for(long long int j = 0 ; j <= n2 ; j++){
            if(i==0||j==0) {cnt[i][j] = 1;}
            else{
                cnt[i][j] = (cnt[i-1][j]%e+cnt[i][j-1]%e-cnt[i-1][j-1]%e)%e;
                if(a[i-1]==b[j-1]){
                    cnt[i][j] += (cnt[i-1][j-1])%e;
                }
            }
        }
    }
    
    //printf("%llu\n",(cnt[n1][n2])%e);
	cout <<(cnt[n1][n2]+e)%e<<endl;
	return 0; 
} 


Measured memory_bytes: 34884
s = input()
ans1 = 0
ans2 = 0
for i in range(len(s)):
    if(i % 2 == 0):
        if(s[i] == '0'):
            ans1 += 1
        else:
            ans2 += 1
    else:
        if (s[i] == '1'):
            ans1 += 1
        else:
            ans2 += 1
print(min(ans2, ans1))

Measured memory_bytes: 3188
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

""" input template
S = input()
N = int(input())
L = list(map(int, input().split()))
a, b = list(map(int, input().split()))
SL = list(input())
"""

# --------------------------------------------

dp = None

def main():
    print(input().count("1"))

main()


Measured memory_bytes: 4932
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;

void calc(vector<int> num,char c){
}


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

    string tmpIn;
    vector<int> numArray;
    int a,b;
    while(true){
        cin >> tmpIn;
        if(cin.eof()) break;
        if(tmpIn[0] == '+'){
            b = numArray[numArray.size()-1];
            numArray.pop_back();
            a = numArray[numArray.size()-1];
            numArray.pop_back();
            numArray.push_back(a+b);
        }else if(tmpIn[0] == '-'){
            b = numArray[numArray.size()-1];
            numArray.pop_back();
            a = numArray[numArray.size()-1];
            numArray.pop_back();
            numArray.push_back(a-b);

        }else if(tmpIn[0] == '*'){
            b = numArray[numArray.size()-1];
            numArray.pop_back();
            a = numArray[numArray.size()-1];
            numArray.pop_back();
            numArray.push_back(a*b);
        }else{
            numArray.push_back(atoi(tmpIn.c_str()));
        }
       
    }

    cout << numArray[0] << endl;

    

    return 0;
}


Measured memory_bytes: 3228
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/


#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

const int INF = 2147483647;
//const ll LINF = ll();今度書く

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	char tmp[100], tmp2[100];
	bool ispossible;
	scanf("%s%s", tmp, tmp2);
	string s = tmp, t = tmp2;
	sort(all(s));
	sort(all(t), greater<int>());
	rep(i, min(s.length(), t.length())) {
		if (s[i] < t[i]) {
			ispossible = true;
			break;
		}
		else if (s[i] > t[i]) {
			ispossible = false;
			break;
		}
		else {
			if (i == min(s.length(), t.length()) - 1) {
				if (s.length() < t.length()) {
					ispossible = true;
				}
				else {
					ispossible = false;
				}
			}
			continue;
		}
	}
	printyn(ispossible);

	return 0;
}


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

int main(){
	int ninzuu;
	while(cin >> ninzuu && ninzuu != 0){
		int max_value=-1;
		int min_value=1001;
		int sum=0;
		int average;
		for(int i=0;i<ninzuu;i++){
			int tmpNum;
			cin >> tmpNum;
			max_value = max(tmpNum,max_value);
			min_value = min(tmpNum,min_value);
			sum += tmpNum;
		}
		sum -= (max_value + min_value);
		average = sum / (ninzuu - 2);
		cout << average << endl; // 出力
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ff first 
#define ss second
#define mod 1000000007
#define lim 200005
#define nfs_mw ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	nfs_mw;
	ll n, out = 0;
	cin>>n;
	if(!(n&1)){
		n/=2; 
		while(n) out += (n/=5);
	}
	cout<<out;
}

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

vector<ll>A(100010,0),B(100010,0),C(100010,0);
/*
なるべくはやく最大数まで伸ばす
*/

int main(){
  ll N; cin>>N;
  for(ll i=0; i<=N; i++)cin>>A[i];
  if(N==0){
    if(A[0]==1) cout<<1<<endl;
    else cout<<-1<<endl;
    return 0;
  }
  else if(N>0 && A[0]>0){
    cout<<-1<<endl;
    return 0;
  }
  B=A;
  for(ll i=N-1; i>=0; i--)B[i]+=B[i+1];//許容数
  ll ans=1;
  C[0]=1;
  for(ll i=1; i<=N; i++){
    C[i]=min(C[i-1]*2,B[i]);
//cout<<"i:"<<i<<" C:"<<C[i]<<" B:"<<B[i]<<" A:"<<A[i];    
    ans+=C[i];
//cout<<" ans:"<<ans<<endl;
    C[i]-=A[i];
    if(i<N && C[i]<=0 || i==N && C[i]<0){
      ans=-1;
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5492
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	char a, b;
	cin >> a >> b;
	if(b < a) swap(a, b); //a is smaller
	rep(i, (b - '0')) cout << a;
	cout << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  int n;
  cin>>n;
  int cnt=0;
  for(int i=1;i<=n;i++){
    if(to_string(i).size()%2==1)cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int DN=1e5+5,M=1e9+7;
int n,dp[2][(1<<21)+5],a[55][55],p,pr,ur=1;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];
    p=(1<<n);
    dp[0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<p;j++)
            dp[ur][j]=0;
        for(int j=0;j<p;j++)
            if(dp[pr][j])
                for(int h=0;h<n;h++)
                    if(a[i][h]&&!(j&(1<<h)))
                        dp[ur][(j|(1<<h))]=(dp[ur][(j|(1<<h))]+dp[pr][j])%M;
        pr^=1;
        ur^=1;
    }
    cout<<dp[pr][p-1];
}


Measured memory_bytes: 16640
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, C, K = LI()

    ans = (-1) ** (K % 2) * (A - B)
    if abs(ans) > 10 ** 18:
        print('Unfair')
    else:
        print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10108
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define N 100010
const int mod=998244353;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
const int NUM=qpow(10,18);
int n,cnt[3][633],pw[N*3],ans,sg[N];
vector<int> G[N];
int get_mex(vector<int> &vec){
	static int vis[N],myh=0;
	++myh;
	for(auto x:vec){
		vis[x]=myh;
	}
	for(int k=0;;++k){
		if(vis[k]^myh)return k;
	}
}
void dfs(int u){
	vector<int> tmp;
	for(auto v:G[u]){
		if(!~sg[v])dfs(v);
		tmp.push_back(sg[v]);
	}
	sg[u]=get_mex(tmp);
}
void Solve(int T){
	int m=read();
	for(int i=1;i<=n;++i){
		G[i].clear();
		sg[i]=-1;
	}
	for(int i=1;i<=m;++i){
		int u=read(),v=read();
		if(u>v)swap(u,v);
		G[u].push_back(v);
	}
	for(int i=1;i<=n;++i){
		if(~sg[i])continue;
		dfs(i);
	}
	for(int i=1;i<=n;++i){
		cnt[T][sg[i]]=(cnt[T][sg[i]]+pw[i])%mod;
	}
}
int main(){
	n=read();
	pw[0]=1;
	for(int i=1;i<=3*n;++i){
		pw[i]=1LL*pw[i-1]*NUM%mod;
	}
	for(int T=0;T<3;++T){
		Solve(T);
	}
	for(int i=0;i<512;++i){
		for(int j=0;j<512;++j){
			int k=i^j;
			ans=(ans+1LL*cnt[0][i]*cnt[1][j]%mod*cnt[2][k])%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 10248
#include <stdio.h>
#include <string.h>

int main( void ){
	char s[8];
	int i;
	scanf("%s",s);
	if( strlen(s)>=3 ){
		for( i=2;i>=0;i-- )
			printf("%c",s[i]);
		printf("\n");
	}else{
		printf("%s\n",s);
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<functional>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<pair<int, int > > task(N);
  REP(i, N) cin >> task[i].second >> task[i].first;
  sort(task.begin(), task.end());
  //  REP(i, N) cout << task[i].first <<"," <<  task[i].second << endl;
  int res;
  bool flag = true;
  res = task[0].first - task[0].second;
  if(res < 0) {flag = false;}
  ///  cout << res << endl;
  REP(i,N - 1){
    res += task[i + 1].first - task[i].first - task[i+1].second; 
    if(res < 0) {flag = false; break;}
    //    cout << res << endl;
  }
  if(flag) {cout << "Yes" << endl;}
  else{cout << "No" << endl;}
}


Measured memory_bytes: 1792
# -*- coding utf-8 -*-
import math


def calc_C(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r))) % (10**9 + 7)


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

ans = 0

# row
for i in range(N):
    ans += i * (N - i) * M * M % (10**9 + 7)

# col
for i in range(M):
    ans += i * (M - i) * N * N % (10**9 + 7)

ans = ans % (10**9 + 7)
ans = ans * calc_C(N * M - 2, K - 2) % (10**9 + 7)
print(ans)


Measured memory_bytes: 74588
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0

for i in range(n-1) :
    if a[i] + 1 == a[i+1] :
        ans += c[a[i]-1]

print(ans + sum(b))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=0;cin>>n;
    vector<int> s(n);
    for(int i=0;i<n;i++)cin>>s.at(i);
    for(int i=0;i<n-1;i++){
        int cnt=0;
        for(int j=i;j+1<n;j++){
            if(s.at(j)>=s.at(j+1))cnt++;
            else break;
        }
        i+=cnt;
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}

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

int main()

{
   int a,b,w;
   cin>>w>>a>>b;
   if(a<=b && b<=w+a)
   {

       cout<<"0"<<endl;
   }
   else if(a<=w+b && w+b<=w+a)
   {

       cout<<"0"<<endl;
   }
   else{
    cout<<min(abs((w+a)-b),abs((w+b)-a))<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
import collections
N = int(input())
G = [set() for i in range(N)]
ab = [tuple(map(int, input().split())) for i in range(N-1)]

d = dict()
i = 0
for a, b in ab:
    a -= 1
    b -= 1
    d[(a, b)] = i
    d[(b, a)] = i
    i += 1
    G[a].add(b)
    G[b].add(a)


q = collections.deque()
r = set()
r.add(0)
q.append((0, 0))
ans = [0]*(N-1)

while(q):
    x, s = q.popleft()
    i = 1
    for y in G[x]:
        if y in r:
            continue
        else:
            r.add(y)
            if i == s:
                i += 1
            ans[d[(x, y)]] = i
            q.append((y, i))
            i += 1
print(max(ans))
print(*ans, sep='\n')


Measured memory_bytes: 84440
while True:
    H, W = map(int,input().split())
    if H == 0 and W == 0:break
    for j in range(H):
        for i in range(W):
            if i == 0 or j == 0 or i == W-1 or j == H-1:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()


Measured memory_bytes: 7004
import sys
input=sys.stdin.readline
N = int(input())
ans=0
XY=[]
for i in range(N):
    X,Y = list(map(int,input().split()))
    for xy in XY:
        ans += ((xy[0]-X)**2+(xy[1]-Y)**2)**0.5
    XY.append((X,Y))
print(ans*2/N)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		ll sx,sy,tx,ty;
		cin>>sx>>sy>>tx>>ty;

		cout<<string(ty-sy,'U')<<string(tx-sx,'R');
		cout<<string(ty-sy,'D')<<string(tx-sx,'L');
		cout<<"L"<<string(ty-sy+1,'U')<<string(tx-sx+1,'R')<<"D";
		cout<<"R"<<string(ty-sy+1,'D')<<string(tx-sx+1,'L')<<"U";
		cout<<endl;
		return 0;
	}


Measured memory_bytes: 256
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm(a, b):
  return a*b//gcd(a, b)

def main():
  n = int(readline())
  a = list(map(int, readline().split()))
  k = reduce(lcm, a) - 1
  ans = 0
  for i in range(n):
    ans += k % a[i]
  print(ans)
  
  
  
  
  
if __name__ == '__main__':
  main()

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

vector<int>v[31];
ll dp[31][50];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, 31)v[i].clear();
		rep(i, n) {
			int f; scanf("%d", &f);
			rep(j, f) {
				int k; scanf("%d", &k);
				v[k].push_back(i);
			}
		}
		rep(i, n)dp[0][i] = 1LL << i;
		for (int i = 1; i <= 30; i++) {
			rep(j, n)dp[i][j] = dp[i - 1][j];
			for (int j : v[i])for (int k : v[i]) {
				dp[i][j] |= dp[i][k];
				dp[i][k] |= dp[i][j];
			}
		}
		rep(i, 31)rep(j, n) {
			if (dp[i][j] == (1LL << n) - 1) {
				printf("%d\n", i); goto g;
			}
		}
		puts("-1");
	g:;
	}
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N=0;
  cin >> N;
  vector<int> vec(N);
  for (int i=0;i<vec.size();i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  vector<int> alice;
  vector<int> bob;
  for(int i=0;i<vec.size();i++){
    if(i%2==0){
      alice.push_back(vec.at(i));
    }else{
      bob.push_back(vec.at(i));
    }
  }
  
  int alice_sum=0,bob_sum=0;
  for (int i=0;i<alice.size();i++){
    alice_sum+=alice.at(i);
  }
  for(int i=0;i<bob.size();i++){
    bob_sum+=bob.at(i);
  }
  
  cout << alice_sum - bob_sum << endl;
  
}

Measured memory_bytes: 256
(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))

(defun f(a b)
  (let ((a0 (format nil "~{~A~}" (loop for i from 1 to b collect (format nil "~A" a))))
        (b0 (format nil "~{~A~}" (loop for i from 1 to a collect (format nil "~A" b)))))
    (format t "~A~%" (if (null (string< a0 b0)) b0 a0))))
(let ((line (mapcar #'parse-integer (splitat #\space (read-line nil nil)))))
  (f (car line) (cadr line)))


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
int X1[100005], Y1[100005], X2[100005], Y2[100005];
int a[100005], b[100005];
pii p[100005];
int r, c, n;
int st[800005];
void update(int n, int s, int e, int idx, int v){
    if(s == e) st[n] = min(st[n], v);
    else{
        int mid = (s+e)/2;
        if(idx <= mid) update(n+n, s, mid, idx, v);
        else update(n+n+1, mid+1, e, idx, v);
        st[n] = min(st[n+n], st[n+n+1]);
    }
}
int query(int n, int s, int e, int l, int r){
    if(s > r || l > e) return 1e9;
    if(l <= s && e <= r) return st[n];
    int mid = (s+e)/2;
    return min(query(n+n, s, mid, l, r), query(n+n+1, mid+1, e, l, r));
}
int check(pii a){
    if(a.first == 0) return 1;
    else if(a.second == c) return 2;
    else if(a.first == r) return 3;
    return 4;
}
vector<pii> h[5];
int getIDX(pii a){
    int ans = 0;
    for(int i=1;i<=4;i++){
        if(binary_search(all(h[i]), a)){
            int res = lower_bound(all(h[i]), a) - h[i].begin();
            if(i >= 3) res = sz(h[i])-res-1;
            ans += res;
            break;
        }
        else ans += sz(h[i]);
    }
    return ans;
}
int main(){
    scanf("%d%d%d", &r, &c, &n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d%d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
        if( ((X1[i] == 0 || X1[i] == r) || (Y1[i] == 0 || Y1[i] == c)) && ((X2[i] == 0 || X2[i] == r) || (Y2[i] == 0 || Y2[i] == c)) ){
            h[check(mp(X1[i], Y1[i]))].eb(mp(X1[i], Y1[i]));
            h[check(mp(X2[i], Y2[i]))].eb(mp(X2[i], Y2[i]));
        }
    }
    for(int i=1;i<=4;i++) sort(all(h[i]));

    int m = sz(h[1]) + sz(h[2]) + sz(h[3]) + sz(h[4]);
    for(int i=1;i<=4*m;i++) st[i] = 1e9;

    int x = 0;
    for(int i=1;i<=n;i++){
        if( ((X1[i] == 0 || X1[i] == r) || (Y1[i] == 0 || Y1[i] == c)) && ((X2[i] == 0 || X2[i] == r) || (Y2[i] == 0 || Y2[i] == c)) ){
            a[i] = getIDX(mp(X1[i], Y1[i])) + 1;
            b[i] = getIDX(mp(X2[i], Y2[i])) + 1;
            if(a[i] > b[i]) swap(a[i], b[i]);
            p[++x] = pii(b[i], a[i]);
        }
    }
    sort(p+1, p+1+x);
    bool ok = 1;
    for(int i=1;i<=x;i++){
        int r = p[i].fi, l = p[i].se;
        int q = query(1, 1, m, l, r);
        if(q < l) ok = 0;
        update(1, 1, m, r, l);
    }
    if(ok) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 8472
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<int> y = {1,0,-1,0};
  vector<int> x = {0,1,0,-1};
  vector<string> s(H);
  bool ans = true;
  for (int i = 0; i < H; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '.') {
        continue;
      }
      bool check = false;
      for (int k = 0; k < 4; k++) {
        int ny = i + y[k];
        int nx = j + x[k];
        if (ny < 0 || ny >= H || nx < 0 || nx >= W) {
          continue;
        }
        if (s[ny][nx] == '#') {
          check = true;
          break;
        }
      }
      if (!check) {
        ans = false;
        break;
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

const int INF = 1001001001;


int main() {

    int n, k, q;

    cin >> n >> k >> q;


    vector<int> points = vector<int>(n);

    rep(i, q) {
        int a;
        cin >> a;
        a --;
        points[a] ++;
    }

    int dead_line = q - k;

    for(int point : points ) {
        if(point <= dead_line) {
            cout << "No" << endl;
        }else {
            cout << "Yes" << endl;
        }
    }


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int dsu[1000001];
int prt(int n){
	if (dsu[n]==n) return n;
	return dsu[n]=prt(dsu[n]);
}
void unn(int x,int y){
	if (prt(x)==prt(y)) return;
	dsu[prt(x)]=dsu[prt(y)];
}
void solve(){
	int n,m;
	cin>>n>>m;
	for (int i=1; i<=n; i++) dsu[i]=i;
	int x,y;
	for (int i=0; i<m; i++){
		cin>>x>>y;
		unn(prt(x),prt(y));
	}
	map <int,bool> p;
	int ans=0;
	for (int i=1; i<=n; i++){
		if (!p[prt(i)]){
			p[prt(i)]=1;
			ans++;
		}
	}
	cout<<ans-1;
}
signed main(){
    solve();
}

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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		int K=nextInt();
		int X=nextInt();

		int min=Math.max(-1000000, X-(K-1));
		int max=Math.min(1000000, X+(K-1));

		for(int i=min;i<=max;i++){
			System.out.print(i+" ");
		}
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

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

void solve(long long N, long long M){
    if(N%2==1){
        for(int i=0;i<M;i++){
            int t = i+1;
            cout << t << " "<<N+1-t << endl;
        }
        return;
    }
    int k=0;
    // set<int> s;
    int half = N/2;
    for(int i=0;i<M;i++){
        int t= i+1;
        int a = N+1-t;
        if((a-t) < (half+1)){
            break;
        }
        // if(s.find(a-t) != s.end() || s.find(t+N-a) != s.end()){
        //     cerr << "false" << endl;
        //     return;
        // }else{
        //     s.insert(a-t);
        //     s.insert(t+N-a);
        // }
        cout << t <<" "<< a << endl;
        k++;
    }
    
    for(int i=k;i<M;i++){
        int t= half +(i-k)+1;
        int a = half-1-(i-k);
        // if(s.find(a-t) != s.end() || s.find(t+N-a) != s.end()){
        //     cerr << "false" << endl;
        //     return;
        // }else{
        //     s.insert(a-t);
        //     s.insert(t+N-a);
        // }
        cout << t <<" " <<a << endl;
    }

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 9223372036854775807;
const int MOD = 1000000007;

std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

int main(){
	int n,s;
	std::cin >> n>>s;
	std::vector<int> x(n),d(n-1);
	rep(i,n)std::cin >> x[i];
	if(n==1){
		std::cout << abs(s-x[0]) << std::endl;
		exit(0);
	}
	sort(all(x));
	rep(i,n-1)d[i]=x[i+1]-x[i];
	sort(all(d));
	std::vector<int> an;
	an=enum_div(d[0]);
	an.push_back(d[0]);
	sort(all(an));
	if(n==1){
		std::cout << abs(s-x[0]) << std::endl;
		exit(0);
	}
	for (int i = an.size()-1; i >=0; i--) {
		/* code */
		bool han=1;
		an[i]=-an[i];
		rep(j,n)if(x[j]%an[i]!=s%an[i])han=0;
		if(han){
			std::cout << -an[i] << std::endl;
			exit(0);
		}
	}
}

Measured memory_bytes: 1024
mycode = r'''
# distutils: language=c++
# cython: language_level=3
# cython: boundscheck=False
# cython: wraparound=False
# cython: infer_types=True
# cython: cdivision=True
# False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。

ctypedef long long LL

import numpy as np

# 読み込みはpython側で行う
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.readline #文字列読み込む時はこっち

def exit(*argv,**kwarg):
    print(*argv,**kwarg)
    sys.exit()


def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)

cdef LL i,j,k,_

cdef LL N,Y
N,Y=ints()
Y//=1000

cdef LL a,b,c #a+b+c=Nかつ10a+5b+c=Yを満たすa,b,cを見つけたい
for a in range(N+1):
    for b in range(N+1):
        c = N-a-b
        if c<0 : break
        if 10*a+5*b+c==Y:
            exit(a,b,c)
print(-1,-1,-1)
        


'''

import sys
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    import os
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode


Measured memory_bytes: 27252
#include <bits/stdc++.h>
#define ll long long
#define re register
#define IL inline
using namespace std;
const int maxn=1<<21+5;
const int mod=1e9+7;
template<typename T> void read(T &x){
	T f=1;x=0;
	char s=getchar();
	while(s<'0' || s>'9'){if(s=='-') f=-1;s=getchar();}
	while(s>='0' && s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();}
	x*=f;
}
int n;
int f[maxn];
int a[22][22];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	read(n);
	for(re int i=1;i<=n;i++){
		for(re int j=1;j<=n;j++){
			read(a[i][j]);
		}
	}
	f[0]=1;
	for(re int i=1;i<=n;i++){
		for(re int j=0;j<(1<<n);j++){
			int tmp=j,cnt=0;
			while(tmp){
				cnt+=tmp&1;
				tmp>>=1;
			}
			if(cnt==i){
				for(re int k=1;k<=n;k++){
					if(a[k][i] && (j>>(k-1))&1){
						f[j]=(f[j]+f[j-(1<<(k-1))])%mod;
					}
				}
			}
		}
	}
	cout<<f[(1<<n)-1]<<endl;
	return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;
int inf=1000000000;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w,d;cin >> h >> w >> d;
	vector<vector<int>> a(h,vector<int>(w));
	map<int,pii> m;
	rep(i,h) rep(j,w){
		cin >> a[i][j];
		m[a[i][j]]=mp(i,j);
	}
	int q;cin >> q;
	vector<int> l(q),r(q);
	rep(i,q) cin >> l.at(i) >> r.at(i);
	vector<int> b(h*w+1);
	for(int i=h*w;i>0;--i){
		if(b.at(i)!=0) continue;
		for(int j=i-d;j>0;j-=d){
			pii x=m[j],y=m[j+d];
			b.at(j)=b.at(j+d)+abs(x.first-y.first)+abs(x.second-y.second);
		}
	}
	rep(i,q){
		cout << b.at(l.at(i))-b.at(r.at(i)) << endl;
	}
}


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

int main()
{
  int n;
  cin>>n;
  int last=n%10;
  if(last==2 or last==4 or last==5 or last==7 or last==9)
    cout<<"hon"<<endl;
  else if(last==3)
    cout<<"bon"<<endl;
  else
    cout<<"pon"<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> X(N);
    REP(i, N) cin >> X[i];

    vector<ll> sorted_X = X;
    sort(sorted_X.begin(), sorted_X.end());

    ll base_value = sorted_X[N/2 -1];
    debug(sorted_X, base_value);
    REP(i, N){
        if(X[i]<=base_value){
            cout << sorted_X[N/2] << endl;
        }else{ //X>=base_value
            cout << base_value << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 5376
module Memoizable
    def memoize(name)
        original = "__original_#{name}__"
        ([Class, Module].include?(self.class) ? self : self.class).class_eval {
            alias_method(original, name)
            private(original)
            cache = {}
            define_method(name){|*args|
                cache[args] ||= send(original, *args)
            }
        }
    end
end

include Memoizable

def f(n)
    return [n, 1].max if n <= 2
    f(n-3) + f(n-2) + f(n-1)
end

memoize :f

loop do
    n = gets.to_i
    break if n == 0
    p (f(n) / 3650.0).ceil
end

Measured memory_bytes: 8624
N,M=map(int,input().split())
data=[]
for _ in range(N):
    a,b=map(int,input().split())
    data.append((a,b))
data.sort()
count=0
index=0
sum=0
while count<M:
    sum+=data[index][0]*data[index][1]
    count+=data[index][1]
    index+=1

index+=-1

sum=sum-data[index][0]*(count-M)

print(sum)


Measured memory_bytes: 16908
#include<iostream>
using namespace std;
main()
{
	string s;
	cin>>s;
	int i;
	if(s.size()==6)
	{
		if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes\n";
		else
		cout<<"No\n";
	}
	else
	cout<<"No\n";
}


Measured memory_bytes: 256