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

#define ll long long
ll n;
string s;
int main()
{
    scanf("%lld",&n);
    cin >> s;
    if(n%2)
        printf("No");
    else
    {
        for(int i = 0; i < n/2; i++)
        {
            if(s[i] != s[(n/2)+i])
            {
                printf("No");
                return 0;
            }
        }
        printf("Yes");
    }
    return 0;
}


Measured memory_bytes: 3680
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=list(input())
n=len(s)
s_set=set(s)
c=Counter(s)
dic=[]
for i in s_set:
    bef=-1
    delta=0
    if c[i]==1:
        continue
    else:
        for j in range(n):
            if  i==s[j]:
                res=j-bef-1
                bef=j
                delta = max(delta,res)
        res=n-1-bef
        dic.append(max(delta,res))
if not dic:
  print(n//2)
else:
  print(min(n//2,min(dic)))


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

int main() {
    int n, m, a, sum = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a;
        sum += a;
    }
    if (sum <= n) cout << n - sum << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3636
var
	N,i,c,t,z:int64;
begin
	read(N);
	i:=2;
	while i*i<=N do begin
		if N mod i=0 then begin
			c:=0;
			while N mod i=0 do begin
				N:=N div i;
				inc(c);
			end;
			t:=1;
			while c>=t do begin
				dec(c,t);
				inc(t);
				inc(z);
			end;
		end;
		inc(i);
	end;
	if N>1 then inc(z);
	writeln(z);
end.


Measured memory_bytes: 1376
N,M,Q=map(int, input().split())

a_ls=[]
b_ls=[]
c_ls=[]
d_ls=[]

for vnwrjvnwakn in range(Q):
	abcd=list(map(int, input().split()))
	a_ls+=[abcd[0]]
	b_ls+=[abcd[1]]
	c_ls+=[abcd[2]]
	d_ls+=[abcd[3]]



import itertools
As=itertools.combinations_with_replacement(range(1,M+1),N)
ans=0
for A in As:
	score=0
	Als=list(A)
	for i in range(Q):
		if Als[b_ls[i]-1]-Als[a_ls[i]-1]==c_ls[i]:
			score+=d_ls[i]
	
	ans=max(ans,score)


print(ans)


Measured memory_bytes: 9160
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        d: i64,
        t: i64,
        s: i64
    }
    let tt = d as f64 / s as f64;

    if tt <= t as f64 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2180
#include <iostream>
using namespace std;
 
int N, M, Q, L[200009], R[200009], X[509][509], C[509][509];
 
int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; i++) {
		cin >> L[i] >> R[i]; X[L[i]][R[i]]++;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) C[i][j] = C[i][j - 1] + X[i][j];
	}
	for (int i = 1; i <= Q; i++) {
		int p, q; cin >> p >> q;
		int sum = 0;
		for (int j = p; j <= q; j++) sum += C[j][q] - C[j][p - 1];
		cout << sum << endl << endl;
	}
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b;
    cin >> a >> b;
    
    if (a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
        

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <numeric>
#include <cmath>

#define rep(i, n) for(int i = 0;i < (int)(n); i++)
#define pb push_back
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n) cin >>  v[i];

    ll tmp = 0;
    ll count = 0;
    sort(v.begin(),v.end());
    rep(i, n) {
        if (tmp == v[i]) {
            count--;
            tmp = 0;
        } else {
            count++;
            tmp = v[i];
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	if((a - b) % 2 == 0) cout << "Alice" << endl;
	else cout << "Borys" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		long X = Math.abs(stdIn.nextLong());
		long K = stdIn.nextLong();
		long D = stdIn.nextLong();
		
		//X = Math.abs(X);
		
		long step = Math.min(K, X / D);
		K -= step;
		X -= step * D;
		
		if(K % 2 == 0) {
			System.out.println(X);
		}else {
			System.out.println(D - X);
		}
		
		
	}
}

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

#define INF ((1<<31)-1)  //int32_t
#define MOD 1000000007
#define MOD2  

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;



int main(){
    bool flag=true;
    ll ans=0,sum=0;
    int n,k,q;
    cin >>n>>k>>q;

    map<int,int> anser;
    
    int a[n]={};

    for (int i = 0; i < q; i++)
    {
        int ai;
        cin >> ai;
        --ai;
        a[ai]++;
    }
    
    for (int i = 0; i < n; i++)
    {
        int point = k - (q - a[i]);
        if(point > 0){
            cout << "Yes" << '\n';
        }else{
            cout << "No" << '\n';
        }
    }
    



    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define ll long long 
const int MAX=1e9+7;
const int mod=1e9+7;


int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	ll n,a,b,sum=0;
	cin>>n>>a>>b;
	sum=n/(a+b)*a;
	n=n%(a+b);
	if(n>a)n=a;
	sum+=n;
	cout<<sum;
}



Measured memory_bytes: 256
dat = []
n = int(input())
for i in range(n):
    dat.append([0] * n)
for i in range(n):
    s = list(map(int, input().split()))
    for j in range(len(s) - 2):

        dat[i][s[j + 2] - 1] = 1
for i in range(n):
    l = list(map(str, dat[i]))
    print(" ".join(l))


Measured memory_bytes: 5672
#include<stdio.h>

#define MAX_INPUT 100

void inputArray(int array[], int *arraySize);
int bubbleSort(int array[], int arraySize);
void outputArray(int array[], int arraySize);

int main(void)
{
  int size;
  int bubbleArray[MAX_INPUT];
  int sortNum = 0;
  
  //  printf("bubble sort.\n");
  inputArray(bubbleArray, &size);
  sortNum = bubbleSort(bubbleArray, size);

  outputArray(bubbleArray, size);
  printf("%d\n", sortNum);
  
  return 0;
}

void inputArray(int array[], int *arraySize)
{
  //  printf("input array size =\n");
  scanf("%d", arraySize);

  //  printf("input array = \n");
  for ( int i = 0; i < *arraySize; i++ ) {
    scanf("%d", &array[i]);
  }
}

// return value is number of change.
int bubbleSort(int array[], int arraySize)
{
  int sortNum = 0;
  int flag = 1;
  int temp;

  while ( flag ) {
    flag = 0;
    for ( int i = arraySize-1; i > 0; i-- ) {
      if ( array[i] < array[i-1] ) {
	temp = array[i];
	array[i] = array[i-1];
	array[i-1] = temp;
	flag = 1;
	sortNum++;
      }
    }
  }
  return sortNum;
}

void outputArray(int array[], int arraySize)
{
  for (int i=0; i < arraySize-1; i++) {
    printf("%d ", array[i]);
  }
  printf("%d\n", array[arraySize-1]);
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,m,i,sum=0;
	cin>>n>>m;
	long int a[m];
	for(i=0;i<m;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<m;i++)
	{
		sum=sum+a[i];
	}
	if((n-sum)<0)
	{
		cout<<"-1"<<endl;
	}
	else
	{
		cout<<n-sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 3680
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		int C = int.Parse(str[2]);
		string ans = "Yes";
		if((C>A && C>B)||(C<A && C<B)){
			ans = "No";
		}
		Console.WriteLine(ans);
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;


int main(){
int a, b;

cin>>a>>b;

if(a<13 && a>=6){
	b=b/2;
} else if(a<6){
	b=0;
}

cout << b;
return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a;
    cin>>a;
    
    for(int i=1;i<=9;i++)
    {
        if(a%i==0&&1<=a/i&&a/i<=9)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
//累積和したほうが簡単。最後に配列を上から下に舐める。
//(配列を舐めるときに累積和の挙動をして、元のデータが復元される)
#include<stdio.h>
#include<iostream>
using namespace std;

int data[10][10];
char str[6];
int ink[3][5] = { {-1,0,1,0,-1},{-1,1,1,1,-1},{0,1,2,1,0} };
int abs(int x){return (x>0?x:-x);}

void drop( int y,int x,int size )
{
	size--;
	
	int i;
	for( i = 0;i < 5;i++ ){
		if( ink[size][i] == -1 || x+i-2 < 0 || x+i-2 > 9 )
			continue;
			
		data[max(0,y-ink[size][i])][x+i-2]++;
		if( y+ink[size][i]+1 > 9 )
			continue;
		
		data[y+ink[size][i]+1][x+i-2]--;
	}
}

int main()
{
	int x,y,size;
	int i,j;
	while( scanf("%s",str) != -1 )
	{
		if( str[0] == '\n' || str[0] == '\r' )
			continue;
		x = 	str[0]-'0';
		y = 	str[2]-'0';
		size = 	str[4]-'0';
		
		drop( y,x,size );
	}
	
	//iが横,jが縦
	for( i = 0;i < 10;i++ ){
		int rui = 0;
		for( j = 0;j < 10;j++ ){
			rui += data[j][i];
			data[j][i] = rui;
		}
	}
	
	int ans1 = 0,ans2 = 0;
	
	for( i = 0;i < 10;i++ ){
		for( j = 0;j < 10;j++ ){
			if( data[i][j] == 0 )
				ans1++;
			else
				ans2 = max(ans2, data[i][j]);
		}
	}
	printf("%d\n%d\n",ans1,ans2);
	return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  int n,c;
  cin>>n>>c;
  vector<vector<int>> d(c+1,vector<int>(c+1));
  vector<int> z(c+1,0),o(c+1,0),t(c+1,0);

  for(int i=0;i < c;i++)
  {
    for(int j=0;j < c;j++)
    {
      cin>>d[i+1][j+1];
    }
  }

  for(int i=1;i <= n;i++)
  {
    for(int j=1;j <= n;j++)
    {
      int x;
      cin>>x;
      if((i+j)%3==0)z.at(x)++;
      else if((i+j)%3==1)o.at(x)++;
      else t.at(x)++;
    }
  }

  ll ans=INF,sum=0;
  for(int i=1;i <= c;i++)//変え先の色の種類
  {
    for(int j=1;j <= c;j++)
    {
      if(j==i)continue;
      for(int k=1;k <= c;k++)
      {
        if(k==i || j==k)continue;
        sum=0;
        for (int l = 1; l < c+1; l++)
        {
          sum+=z.at(l)*d.at(l).at(i);
          sum+=o.at(l)*d.at(l).at(j);
          sum+=t.at(l)*d.at(l).at(k);
        }
        ans=min(ans,sum);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : AMAN SAXENA *
* "There's some good in this world, and it's worth fighting for." *
* INSTITUTION : KIET Group of Institutions *
******************************************/
#include <bits/stdc++.h>

const long long MODULO=1000000007;
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FOR1(i,a,n) for(int i=a;i<=n;i++)
#define FOR2(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

template <typename TYPE> void in(TYPE &x){cin>>x;}

void solve()
{
    string c[10]={"pon","pon","hon","bon","hon","hon","pon","hon","pon","hon"};
    int n;
    cin>>n; 
    cout << c[n%10] << '\n';
}

void test()
{
    int t;
    cin>>t;
    while(t--) //for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
    {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    // test();
    solve();
    
    return 0;
}

Measured memory_bytes: 3676
n, m = map(int, input().split())
li_input = list()
counter = dict()
cities = dict()

for i in range(m):
    li_input.append(list(map(int, input().split())))

sorted_city = sorted(li_input, key=lambda x: x[1])

for c in sorted_city:
    idx = counter.get(c[0], 0)
    cities[c[1]] = idx

    # count up
    counter[c[0]] = idx + 1


for c in li_input:
    print('{0:06}{1:06}'.format(c[0], cities[c[1]] + 1))


Measured memory_bytes: 45960
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    long x;
    cin >> x;
    long ans=0;
    ans = (x/11)*2;
    long r = x%11;
    if(r>6){
        ans+=2;
    }else if(r==0){
        ans;
    }else{
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
if N == 3:
    if A[0]^A[1] == A[2]:
        print('Yes')
    else:
        print('No')
    exit()
a = A[0]
for i in range(1,N):
    a = a ^ A[i]
if a == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 60784
n, m = map(int, input().split())
s = input()

if "1" * m in s:
    print(-1)
    exit()

pos = n
ans = []
while pos > 0:
    prev = max(pos - m, 0)
    while s[prev] == "1":
        prev += 1

    ans.append(pos - prev)

    pos = prev

ans = ans[::-1]
print(*ans)


Measured memory_bytes: 6372
import math
n, m = map(int, input().split())
mod = 10**9+7
if abs(n-m) > 1:
    print(0)
    exit()

dog = math.factorial(n)
monkey = math.factorial(m)
if abs(n-m) == 1:
    ans = dog*monkey % mod
elif n == m:
    ans = dog*monkey*2 % mod
print(ans%mod)

Measured memory_bytes: 11052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define iFOR(idx, from, upto) for (int  idx = from; idx < upto; ++idx)
#define lFOR(idx, from, upto) for (long idx = from; idx < upto; ++idx)

#define ll long long

using namespace std;

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

    double _l = (double) l / 3;

    double v =  _l * _l * _l;

    printf("%.12f\n", v);

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define inf 2e9
#define f first
#define s second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

int dy[] = {0,0,1,-1};
int dx[] = {1,-1,0,0};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}


int main (){
    int a,b;
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    }else if(a >= 6 && a <= 12){
        cout << b/2 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mi min(a,b)
#define ma max(a,b)
int main(){
  int w,a,b;
  cin>>w>>a>>b;
  if(mi>=ma&&mi<=ma+w||
  mi+w>=ma&&mi+w<=ma+w){
    cout<<0;
  }else{
    cout<<ma-mi-w;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int a[300001],n,L,i,j,k,l,sum,Sum;
ll ans,X[300001],T[300001];

int main()
{
	#ifdef file
	freopen("agc022d.in","r",stdin);
	#endif
	
	scanf("%d%d",&n,&L);
	fo(i,1,n) scanf("%lld",&X[i]);
	fo(i,1,n)
	{
		scanf("%lld",&T[i]);
		if (!(T[i]%(L*2)))
		ans+=(T[i]/(L*2)-1)*2,T[i]=L*2;
		else
		ans+=(T[i]/(L*2))*2,T[i]%=L*2;
	}
	fo(i,1,n) a[i]=((X[i]*2)>=T[i])+2*(((L-X[i])*2)>=T[i]),ans+=(!a[i])*2;
	
	++ans,sum=0;
	if (a[n]==2)
	{
		fo(i,1,n)
		if (a[i]==3) ++sum,++Sum;
		else
		if (a[i]==2)
		{
			if (i==n) ++ans;
			else ans+=2;
			if (i<n && sum) --sum,--Sum;
		}
	}
	else
	{
		fo(i,1,n)
		if (a[i]==3) ++sum,++Sum;
		else
		if (a[i]==2)
		{
			ans+=2;
			if (sum) --sum,--Sum;
		}
		
		++ans;
		if (!a[n])
		{
			sum=0;
			fd(i,n,1)
			if (a[i]==3) ++sum;
			else
			if (a[i]==1)
			{
				ans+=2;
				if (sum) --sum,--Sum;
			}
		}
		else
		{
			sum=0;
			fd(i,n,1)
			if (a[i]==3)
			{
				if (i==n) --Sum;
				else ++sum;
			}
			else
			if (a[i]==1)
			{
				ans+=2;
				if (sum) --sum,--Sum;
			}
		}
	}
	ans+=Sum;
	
	ans+=ans&1;
	printf("%lld\n",ans*L);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

Measured memory_bytes: 9592
x = int(input())
n = list(map(int, input().split()))
lenn = len(n)
sn = sorted(n)
l = sn[int(lenn / 2) - 1]
r = sn[int(lenn / 2)]
for i in n:
  if i <= l:
    print(r)
  else:
    print(l)

Measured memory_bytes: 25556
class segtree:

    def __init__(self, n, operator, identity):
        """
        n:データ配列のサイズ
        operator:演算子(モノイド)。関数オブジェクト 最小=min, 最大=max
        identity:演算子に対応する単位元
        """
        nb = bin(n)[2:] #２進数に変換して先頭の0bを取り除く
        bc = sum([int(digit) for digit in nb]) #bitで1が立ってる数。これが1のときはちょうど2^nb.そうじゃないときは、2^nb<n<2^(nb+1)
        if bc == 1: #2^nbなら
            self.num_end_leaves = 2**(len(nb)-1) #最下段の葉っぱは2^nb個
        else:#そうじゃないなら2^(nb+1)確保
            self.num_end_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_end_leaves * 2)] #単位元で初期化

        self.identity = identity 
        self.operator = operator
        #後で使うので単位元と演算子を持っておく

    def update(self,x,val):
        """
        x:代入場所
        val:代入する値
        """
        actual_x = x+self.num_end_leaves #1-indexの末端の葉のindexがどこから始まるか分を足す(例えばデータ配列サイズ4のとき木配列サイズは8で、後半部はindex4から始まる。
        self.array[actual_x] = val #値を更新する
        while actual_x > 0 :
            actual_x = actual_x//2#親を見る
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])#あたらしい子をつかって親を更新

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        """
        q_left：クエリ区間の左
        q_right:クエリ区間の右
        arr_ind:木配列のインデックス。最初は親なので1
        leaf_left:木配列インデックスに対して、それが表す葉がカバーする範囲の左
        depth:木配列での深さ。カバー範囲の広さの計算に使用
        """
        width_of_floor = self.num_end_leaves//(2**depth) #今の葉のカバー幅
        leaf_right = leaf_left+width_of_floor-1 #左端とカバー幅から今の葉のカバー範囲の右を求める。

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity #クエリ領域と葉が関係ないなら単位元を返す

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind] #クエリ領域に葉がすっぽり入ってるなら、葉の値を返す

        else: #そうじゃないならば、子を見る
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)#子の左
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)#子の右
            return self.operator(val_l,val_r)#子をマージする演算をする。

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

s_tree = segtree(N,min,2**31-1) #10**5までの配列なので適当に単位元は10**9
arr = [2**31-1] * N

#print(arr)

for i,a in enumerate(arr):
    s_tree.update(i,a)

for i in range(Q):
    a, x, y = map(int,input().split())
    if a == 0:
        s_tree.update(x,y)
    else:
        print(s_tree.get(x,y))


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

const int mod = 998244353;
typedef __int128 LL;

std::map<std::string, int> dp;

int dfs(const std::string &s) {
	if (s == "") return 1;
	if (dp.count(s)) return dp[s];
	int ret = dfs(std::string(s.begin() + 1, s.end())) * (s[0] - '0' + 1) % mod, n = s.size();
	for (int A = 1; A * 2 <= n; ++A) {
		std::string str = s.substr(0, A);
		for (int k = 2; A * k <= n; ++k) {
			for (int t = 0; t < A; ++t)
				str[t] &= s[A * (k - 1) + t];
			ret = (ret + (LL) dfs(str) * dfs(std::string(s.begin() + A * k, s.end()))) % mod;
		}
	}
	return dp[s] = ret;
}
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::string s; std::cin >> s, std::cout << dfs(s) << '\n';
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int ctoi(char c) {
  return c - '0';
}

template <class C>
void printContainer(C &container, const char *delim=",") {
  for(const auto &e : container) {
    std::cout << e << delim;
  }
  std::cout << "\n";
}

// Greatest common divisor
template<class T>
T gcd(T x, T y) {
  if(x < y) {
    std::swap(x, y);
  }
  T r = x % y;
  while(r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

// Least common multiple
template<class T>
T lcm(T x, T y) {
  return (x*y)/gcd(x,y);
}

int main() {
  char a, b;
  cin >> a >> b;
  if(a == 'H') {
    cout << b << endl;
  }
  else {
    if(b == 'H') {
      cout << 'D' << endl;
    }
    else {
      cout << 'H' << endl;
    }
  }
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  char ch = sc.next().charAt(0);
  int asciival = ch -'A';
  if(0 <= asciival && asciival <= 26)
    System.out.println("A");
  else
    System.out.println("a");
  }
}


Measured memory_bytes: 35792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Solution
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var vals = Console.ReadLine().Split(' ').ToArray();
        var s = vals[0];
        var t = vals[1];

        var buff = new StringBuilder();
        for (int i = 0; i < n; i++)
        {
            buff.Append(s[i]);
            buff.Append(t[i]);
        }

        Console.WriteLine(buff.ToString());
    }
}

Measured memory_bytes: 11220
import java.util.*;

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

      int x = Integer.parseInt(sc.next());

      int n = 100010;

      int[] food = {100,101,102,103,104,105};

      int[] dp = new int[n];

      for(int i=0;i<n;i++){
        for(int j=0;j<6;j++){
          int now = dp[i] + food[j];
          if(now<100005){
            dp[now] = Math.max(dp[now],now);
          }
        }
      }

      if(dp[x]==x){
        System.out.println("1");
      }
      else{
        System.out.println("0");
      }


/*
      for(int i=0;i<6;i++){
        System.out.println(food[i]);
      }
*/


    }
}


Measured memory_bytes: 22228
_, *names = readlines.map(&:chomp)
marchs = names.select {|n| 'MARCH'.each_char.any?{|c| n.start_with?(c)}}
marchs.length < 3 && p(0) && exit
x = marchs.reduce(Hash.new {|h, k| h[k]=0}) {|r, n| r[n[0]]+=1; r}
x.length < 3 && p(0) && exit
p x.keys.combination(3).map {|c| c.reduce(1) {|r, k| r *= x[k]}}.reduce(:+)

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

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ll n,t;
	cin>>n;
	t=sqrt(1+8*n);
	if (t*t==1+8*n){
		cout<<(t-1)/2;
	}
	else {
		cout<<(t-1)/2+1;
	}
	return 0;
}

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

int main() {
  ll n,k;
  cin >> n >> k;

  //aとk-aの小さい方が答えになる
  ll a = n%k;
  ll ans = min(a,k-a);

  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void)
{
  int k, s;
  cin >> k >> s;

  ll ans = 0;
  REP(i, k+1) {
    REP(j, k+1) {
      int z = s-i-j;
      if(0 <= z && z <= k) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(int argc,char* argv[])
{
    int n,m,i,a,b;
    cin >> n >> m;
    vector<int> city(n,0);

    for(i=0;i<m;i++){
        cin >> a >> b;
        city.at(a-1)++;
        city.at(b-1)++;
    }

    for(i=0;i<n;i++){
        cout << city.at(i) << "\n";
    }

    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a_vec(n);
    for(int i=0; i<n; i++)
    {
        cin >> a_vec.at(i);
    }

    int ans = 0;
    int count = 1;
    for(auto& a : a_vec)
    {
        if(a == count)
        {
            count++;
        }
        else
        {
            ans++;
        }
    }

    if(count == 1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    


    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}

const ll MOD = 1e9+7;
long long Comb(int n, int i){long long ans = 1; if(i>n || i < 0) return 0; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){ans *=(n+1-j); ans /= j; ans %= MOD;} }return ans;}
template<typename T> T gcd(T a, T b){if(b == 0) return a;else return gcd(b, a%b);}
template<typename T> T lcm(T a, T b){if(b > a) swap(a, b); T g = gcd(a, b);return a / g * b;}

void solve(){
  int n; cin >> n;
  int num = 0;
  int record = 0;
  for(int i = 0; i < n; ++i){
    int a, b; cin >> a >> b;
    if(a == b) {
      num++;
      record = max(num, record);
      }
    else {
      num = 0;
    }
  }
  if (record >= 3){
    cout << "Yes" << endl;
  } else {
    cout << "No";
  }
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 3592
a = []
for i in range(5):
    a.append(int(input()))
count = 0
min_i = 9
min_aa = 0
#しも一桁が最小のものを調べる
for i in a:
    ama = i % 10
    if (ama <= min_i) & (ama != 0):
        min_i = ama
        min_aa = i
#print('min',min_i)
aaa = 0
for i in a:
    #print(i)
    #print(i,min_aa)
    if ((i == min_aa)&(aaa == 0)):
        #print('tasuuu',i)
        count += i
        aaa += 1
    elif (i % 10 == 0):
        #print('tasui',i)
        count += i
    else:
        count += (i + (10 - i % 10))
        #print('tasu',(i + (10 - i % 10)))
print(count)

Measured memory_bytes: 3064
fun c82(args: Array<String>) {
    val numList = args[1].split(" ").map { it.toInt() }
    var numMap = mutableMapOf<Int, Int>()
    numList.forEach {
        if (!numMap.containsKey(it)) {
            numMap.put(it, 0)
        }
        numMap.put(it, numMap[it]!! + 1)
    }

    println(numMap.map{ if (it.value >= it.key) it.value - it.key else it.value}.sum())
}

fun main(args: Array<String>) {
    c82(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 56340
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
ll MOD = 1000000007;
const int mod = 1000000007;
ll INF = 1LL << 60;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
   for (auto &v : vec)
      is >> v;
   return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
   os << "[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec)
{
   os << "deq[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{
   os << "(" << pa.first << "," << pa.second << ")";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
}
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
   fill((T *)array, (T *)(array + N), val);
}

int a[2020],dp[2020][2];
int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);

   int n , z , w;
   cin >> n >> z >> w;
   for(int i=0; i < n; i++)
      cin >> a[i];

   int ans = 0;
   ans = abs(a[n-1] - w);
   if(n > 1){
      ans = max(ans, abs(a[n - 2] - a[n - 1]));
   }
   cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i,N) cin >> d.at(i);
  int sum = 0;
  for(int i = 0;i < N - 1; i++){
    for(int j = i + 1; j < N; j++){
      sum += (d.at(i) * d.at(j));
    }
  }
  cout << sum << endl;

}


Measured memory_bytes: 256
# coding:utf-8
n, k = map(int,raw_input().split())
ws = []
for _ in xrange(n):
  ws.append(int(raw_input()))

def possible_put_p(p):
  # P??\?????????????????????????????????
  current = 1
  weight = 0
  for w in ws:
    if weight + w <= p:
      weight += w
    else:
      current += 1
      if current > k:
        return False
      weight = w

  if current <= k:
    return True
  else:
    return False

low = max(ws)
high = sum(ws)
while(high - low > 0):
  mid = (low + high) / 2
  if(possible_put_p(mid)):
    high = mid
  else:
    low = mid + 1

print high

Measured memory_bytes: 9388
n,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
x=[[] for _ in range(4)]
w0=wv[0][0]
for w,v in wv:
    x[w-w0].append(v)
for i in range(4):
    x[i].sort()
    x[i]=x[i][::-1]
y=[[0] for i in range(4)]
for i in range(4):
    if len(x[i])>0:
        y[i].append(x[i][0])
for i in range(4):
    for j in range(1,len(x[i])):
        y[i].append(y[i][-1]+x[i][j])
res=[]
for a in range(len(x[0])+1):
    for b in range(len(x[1])+1):
        for c in range(len(x[2])+1):
            for d in range(len(x[3])+1):
                if w0*a+(w0+1)*b+(w0+2)*c+(w0+3)*d<=W:
                    res.append(y[0][a]+y[1][b]+\
                              y[2][c]+y[3][d])
print(max(res))

Measured memory_bytes: 48180
program abc110d
  implicit none
  integer(8), parameter :: modulo = 10**9 + 7
  integer(8) :: ans = 1
  integer(8) n, m, i, count

  read *, n, m
  i = 2
  do
     if (m < i * i) exit
     if (mod(m, i) == 0) then
        count = 0
        do
           m = m / i;
           count = count + 1
           if (mod(m, i) /= 0) exit
        end do
        ans = mod(comb(n + count - 1, count, modulo), modulo)
     end if
     i = i + 1
  end do
  if (m /= 1) then
     ans = mod(ans * n, modulo)
  end if
  print '(i0)', ans

contains

  recursive integer(8) function comb(n, k, m) result(r)
    integer(8), intent(in) :: n, k, m
    integer(8) :: nume = 1, deno = 1
    integer(8) i

    if (n - k < k) then
       r = comb(n, n - k, m)
    else
       do i = 0, k - 1
          nume = mod(nume * (n - i), m)
          deno = mod(deno * (i + 1), m)
       end do
       r = mod(nume * modpow(deno, m - 2, m), m)
    end if
  end function comb

  recursive integer(8) function modpow(a, p, m) result(r)
    integer(8), intent(in) :: a, p, m
    integer(8) h
    
    if (p == 0) then
       r = 1
    else if (mod(p, 2) == 0) then
       h = modpow(a, p / 2, m)
       r = mod(h * h, m)
    else
       r = mod(a * modpow(a, p - 1, m), m)
    end if
  end function modpow
end program abc110d


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

int main()
{
    int N,D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < D; j++)
        {
            cin >> X.at(i).at(j);
        }
    }

    int ans=0;
    for (int i = 0; i < N-1; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            double distance=0;
            for (int d = 0; d < D; d++)
            {
                distance+=pow((X[i][d]-X[j][d]),2.0);
            }
            if(ceil(sqrt(distance)) == floor(sqrt(distance)))ans++;
        }
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
int n;
int max,min;
char in[9];
cin>>n;
while(n--){
cin >>in;
max=min=0;
for(int i=0;i<8;i++){
in[i]=in[i]-'0';
}
sort(in,in+8);
for(int i=0;i<8;i++){
max=max+in[i]*pow(10,i);
min=min+in[i]*pow(10,7-i);
}
cout<<max-min<<endl;
}
return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	ios::sync_with_stdio(false);

	int H,W,N;
	vector<int> a_arr;
	cin>>W>>H>>N;
	
	int x_right,x_left,y_up,y_down;

	x_right = W;
	x_left = 0;
	y_up = 0;
	y_down = H;
	
	for(int i = 0; i < N;i++){
		int x,y,a;
		cin>>x>>y>>a;
		
		switch(a){
			case 1:
				if(x_left < x){
					x_left = x;
				}
				break;

			case 2:
				if(x_right > x){
					x_right = x;
				}
				break;

			case 3:
				if(y_up < y){
					y_up = y;
				}
				break;
			case 4:
				if(y_down > y){
					y_down = y;
				}
				break;

		}
	}

	if((x_left >= x_right) || (y_up >= y_down)){
		cout<<0<<endl;
	}
	else{

		cout<<(x_right - x_left) * (y_down - y_up)<<endl;
	}

	return 0;
}


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

int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }

int area_type(char c)
{
	switch(c)
	{
		case '\\':
			return -1;
		
		case '/':
			return +1;
	}
	return 0;
}

int main()
{
	int  n, m, tmp, ans;
	int  a[10000];
	int  w[20001];
	int  g[20001];
	char s[20001];
	
	scanf("%s", s);
	n = strlen(s);
	
	g[0] = 0;
	for(int i = 0; i < n; ++i)
	{
		g[i+1] = g[i] + area_type(s[i]);
	}
	
	tmp = w[0] = g[0];
	for(int i = 1; i <= n; ++i)
	{
		tmp = max(tmp, g[i]);
		w[i] = tmp;
	}
	
	tmp = w[n] = g[n];
	for(int i = n-1; i >= 0; --i)
	{
		tmp = max(tmp, g[i]);
		w[i] = min(w[i], tmp);
	}
	
	tmp = ans = m = 0;
	for(int i = 1; i <= n; ++i)
	{
		tmp += (w[i-1]-g[i-1])+(w[i]-g[i]);
		if((w[i] == g[i]) && tmp)
		{
			tmp /= 2;
			ans += tmp;
			a[m++] = tmp;
			tmp = 0;
		}
	}

	printf("%d\n%d", ans, m);
	for(int i = 0; i < m; ++i)
	{
		printf(" %d", a[i]);
	}
	printf("\n");
}



Measured memory_bytes: 2116
#include <iostream>


int main(void){
	long N, n;
	int res = 0;
	std::cin >> N;

	if(N == 1) std::cout << 0 << std::endl;
	else {
		n = N;
		int cnt, exp;
		for(long i = 2; i * i <= N; i++){
			cnt = 0;
			exp = 1;
			while(n % i == 0){
				n /= i;
				cnt++;
			}
			while(cnt - exp >= 0){
				cnt -= exp;
				res++;
				exp++;
			}
		}
		if(n != 1) res++;
		std::cout << res << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
using namespace std;
template <class T> inline void chmax(T & a, T const & b) { a = max(a, b); }
template <typename T> T gcd(T a, T b) { while (a) { b %= a; swap(a, b); } return b; }

int main() {
    // input
    int m; scanf("%d", &m);
    assert (m % 2 == 0);
    vector<int> x(m), y(m);
    REP (i, m) scanf("%d%d", &x[i], &y[i]);
    // solve
    map<pair<int, int>, vector<int> > from_angle;
    REP (j, m) REP (i, j) {
        int dy = y[j] - y[i];
        int dx = x[j] - x[i];
        int d = gcd(abs(dy), abs(dx));
        dy /= d;
        dx /= d;
        if (dy < 0) { dy *= -1; dx *= -1; }
        if (dy == 0) dx = 1;
        if (dx == 0) dy = 1;
        from_angle[make_pair(dy, dx)].push_back((1 << i) | (1 << j));
    }
    vector<int> dp(1 << m, -1);
    dp[0] = 0;
    REP (s, 1 << m) if (dp[s] != -1) {
        for (auto pairs : from_angle) {
            vector<int> ts;
            ts.push_back(0);
            for (int dt : pairs.second) {
                if (s & dt) continue;
                for (int i = ts.size(); i --; ) {
                    int t = ts[i] | dt;
                    int k = __builtin_popcount(t) / 2;
                    chmax(dp[s | t], dp[s] + k * (k - 1) / 2);
                    ts.push_back(t);
                }
            }
        }
    }
    // output
    printf("%d\n", dp.back());
    return 0;
}

Measured memory_bytes: 3324
n = int(input())
a = list(map(int, input().split()))
sa = sum(a)
stone = n*(n+1)//2
if sa % stone:
    print("NO")
    exit()
a.append(a[0])
k = sa//stone
d = [a[i+1]-a[i] - k for i in range(n)]
for i in d:
    if i%n or i>0:
        print("NO")
        exit()
print("YES")


Measured memory_bytes: 14108
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, m, l[100000], r[100000];
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
		scanf("%d %d", l + i, r + i);
	for (int i = 1; i < m; i++) {
		l[i] = max(l[i - 1], l[i]);
		r[i] = min(r[i - 1], r[i]);
	}
	printf("%d\n", max(0, r[m - 1] - l[m - 1] + 1));
}

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

int gcd(int a,int b)
{
    int l,s,r;
    if (a<b)
    {
	l=b;
	s=a;
    } else {
	l=a;
	s=b;
    }
    while(true)
    {
	r=l%s;
	if (r == 0) break;
	l=s;
	s=r;
    }
    return s;
}

int main()
{
    int a,b;
    vector<int> r1,r2;
    while (scanf("%d %d",&a,&b) != EOF)
    {
	r1.push_back(gcd(a,b));
	r2.push_back(a/r1[r1.size()-1]*b);
    }
    for (int i=0; i<r1.size(); i++)
    {
	cout << r1[i] << " " << r2[i] << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using Edge = pair<ll,ll>;
using Graph =vector<vector<Edge>>;
vector<int> color;
Graph G;
vector<int> ans;
ll N;
void dfs(ll i, ll j=-1){
    for(auto u : G[i]){
        if(u.first == j) continue;
        if(u.second % 2 == 0){
            color[u.first] = color[i];
        }else{
            color[u.first] = -color[i];
        }
        dfs(u.first, i);
    }
}
int main() {
cin>>N;
G.resize(N);
rep(i,N-1){
  ll a,d,c;
  cin>>a>>d>>c;
  --a;
  --d;
  G[a].push_back(Edge(d,c));
  G[d].push_back(Edge(a,c));
}
   ans.resize(N);
    ans[0] = 1;
color.resize(N,-1);
color[0]=1;
dfs(0);
    rep(i,N){
        if(color[i]==-1) cout << '0' << endl;
        else if(color[i]==1) cout << '1' << endl;
    }
return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
    int N;
    cin >> N;
    int P[N],Q[N];
    vector<int> perm(N);
    for(int i = 0; i  < N; i++)
    {
        cin >> P[i];
    }
    for(int i = 0; i  < N; i++)
    {
        cin >> Q[i];
        perm[i] = i+1;
    }
    int count = 0;
    int a,b;
    do
    {
        bool flagp = true;
        bool flagq = true;
        count++;
        for(int i = 0; i < N; i++)
        {
            if(perm[i] != P[i]) flagp = false;
            if(perm[i] != Q[i]) flagq = false;
        }
        if(flagp) a = count;
        if(flagq) b = count;
    } while (next_permutation(perm.begin(),perm.end()));
    cout << abs(a -b) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var a = ReadLineIntSpilit();
            var result = Math.Ceiling(((float)a[0] + a[1]) / 2);
            Console.WriteLine(result);
            ReadLine();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

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

int main() {
    string A, B;
    cin >> A >> B;

    if (A.size() > B.size()) {
        cout << "GREATER" << endl;
    }
    else if (A.size() < B.size()) {
        cout << "LESS" << endl;
    }
    else {
        if (A == B) {
            cout << "EQUAL" << endl;
        }
        else {
            for (int i = 0; i < A.size(); i++) {
                if (A[i] > B[i]) {
                    cout << "GREATER" << endl;
                    break;
                }
                else if (A[i] < B[i]) {
                    cout << "LESS" << endl;
                    break;
                }
            }
        }
    }
}

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

// ----------- define --------------
#define int long long
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void MAIN() {
  int x, n;
  cin >> x >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    s.insert(t);
  }
  for (int i = 0; ; i++) {
    if (!s.count(x - i)) {
      cout << x - i << '\n';
      return;
    }
    if (!s.count(x + i)) {
      cout << x + i << '\n';
      return;
    }
  }
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef priority_queue<int> pqb;
typedef priority_queue<int, vi, greater<int> > pqs;

#define iamtheflash         ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod                 1000000007
#define debug1(x)           cout<<"#x: "<<x<<"\n"
#define debug2(x,y)         cout<<"#x: "<<x<<" #y: "<<y<<"\n"
#define debug3(x,y,z)       cout<<"#x: "<<x<<" #y: "<<y<<" #z: "<<z<<"\n"
#define debug4(x,y,z,w)     cout<<"#x: "<<x<<" #y: "<<y<<" #z: "<<z<<" #w: "<<w<<"\n"
#define rep(i,n)            for(int i=0;i<(n);i++)
#define repl(i,n)           for(ll i=0;i<(n);i++)
#define fori(i,a,b)         for(int i=(a);i<=(b);i++)
#define forl(i,a,b)         for(ll i=(a);i<=(b);i++)
#define ford(i,a,b)         for(int i=(a);i>=(b);i--)
#define fordl(i,a,b)        for(ll i=(a);i>=(b);i--)
#define pb                  push_back
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define mid(s,e)            (s+(e-s)/2)
#define setbits(x)          __builtin_popcountll(x)
#define zrobits(x)          __builtin_ctzll(x)
#define ps(x,y)             fixed<<setprecision(y)<<x
#define w(x)                int x; cin>>x; while(x--)
#define in(x)               int x; cin>>x;
#define ins(x)              string x; cin>>x;
#define endl                '\n'
#define infi                INT_MAX
#define infll               LLONG_MAX
#define infim               INT_MIN
#define infllm              LLONG_MIN
#define mk(arr,n,type)      type *arr = new type[n];
#define umap(x,type1,type2) unordered_map<type1, type2 > x;


struct activity {
	int a, b, c;
};

int solve(activity* arr, int n) {
	int dp[n + 1][3];
	dp[1][0] = arr[1].a;
	dp[1][1] = arr[1].b;
	dp[1][2] = arr[1].c;

	fori(i, 2, n) {
		dp[i][0] = arr[i].a + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = arr[i].b + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = arr[i].c + max(dp[i - 1][0], dp[i - 1][1]);
	}

	return max({dp[n][0], dp[n][1], dp[n][2]});
}

int32_t main() {
	iamtheflash

	in(n);

	mk(arr, n + 1, activity);
	fori(i, 1, n) {
		cin >> arr[i].a;
		cin >> arr[i].b;
		cin >> arr[i].c;
	}

	cout << solve(arr, n);

	return 0;
}


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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=998244353;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	int n;
	cin>>n;
	cout<<(n+999)/1000*1000-n;
	return 0;
}

Measured memory_bytes: 3656