akhauriyash/Code-Regression huggingface dataset:
//raja1999

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define int ll

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;


//std::ios::sync_with_stdio(false);
int pres[105];
main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int x,y,n,i,id,ans=inf,p;
	cin>>x>>n;
	rep(i,n){
		cin>>p;
		pres[p]=1;
	}
	f(i,0,102){
		if(pres[i]==0){
			if(abs(x-i) < ans){
				ans=abs(x-i);
				id=i;
			}
		}
	}
	cout<<id<<endl;
	return 0;
} 


Measured memory_bytes: 3652
#include <stdio.h>
int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if((x + r <= W && x - r >= 0) && (y + r <= H && y - r >= 0)) 
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");	
	}
	return 0;
	
}


Measured memory_bytes: 2144
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

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

    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    int sum = 0;
    for(int i = n - k; i < n; i++){
        sum += a[i];
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 760
# coding=utf-8
 
class Node:
    def __init__(self, ID, left, right):
        ### information for output ###
        self.id = ID
        self.parent = -1 #??????
        self.sibling = -1 #??????
        self.degree = -1 #??????
        self.depth = 0 #??????
        self.height = 0 #??????
        self.type = None #??????
 
        ### other information ###
        self.left_child = left
        self.right_child = right
 
def calc_depth(i):
    global node_list
 
    if node_list[i].depth != 0:
        return node_list[i].depth
 
    depth = 0
    if node_list[i].parent != -1:
        depth = calc_depth(node_list[i].parent) + 1
 
    node_list[i].depth = depth
    return depth
 
 
def calc_height(i):
    global node_list
 
    if node_list[i].height != 0:
        return node_list[i].height
 
    h1 = h2 = 0
    if node_list[i].right_child != -1:
        h1 = calc_height(node_list[i].right_child) + 1
    if node_list[i].left_child != -1:
        h2 = calc_height(node_list[i].left_child) + 1
 
    height = max(h1, h2)
    node_list[i].height = height
    return height
 
n = int(input())
data = [tuple(map(int, input().split())) for x in range(n)]
node_list = []
 
for data_row in data:
    ID, left, right = data_row
    node = Node(ID, left, right)
    node_list.append(node)
 
node_list.sort(key = lambda node: node.id)
 
for i, node in enumerate(node_list):
    left = node.left_child
    right = node.right_child
    degree = 0
 
    ### child information ###
    if left != -1:
        degree += 1
        node_list[left].parent = i
        node_list[left].sibling = right
 
    if right != -1:
        degree += 1
        node_list[right].parent = i
        node_list[right].sibling = left
 
    ### self information ###
    node.degree = degree
 
for i in range(n):
    calc_depth(i)
    calc_height(i)
 
    node = node_list[i]
 
    if node.depth == 0:
        node.type = 'root'
    elif node.height == 0:
        node.type = 'leaf'
    else:
        node.type = 'internal node'
 
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(node.id, node.parent, node.sibling, node.degree, node.depth, node.height, node.type))

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

int main() {
  int a, b, c; cin >>a >>b >>c;
  vector<int> d = {a, b, c};
  sort(d.begin(), d.end());
  
  bool ans = false;
  if (d.at(0) == 5 && d.at(1) == 5 && d.at(2) == 7){
    ans = true;
  }
  
  if (ans) cout <<"YES";
  else cout <<"NO";
  
  cout <<endl;
}


Measured memory_bytes: 256
isEven x = (mod x 2) == 0

nDivide :: Int -> Int -> [Int] -> Int
nDivide n n_number nums = if (length . filter isEven $ nums) == n_number then
                         nDivide (n+1) n_number (map (\x -> x `div` 2) nums)
                       else
                         n

main = do
  n_num <- read <$> getLine
  nums  <- fmap (read :: String -> Int) . words <$> getLine
  putStrLn $ show $ nDivide 0 n_num nums

Measured memory_bytes: 1020
#include<iostream>
#include<algorithm>
using namespace std;
int a[12];
int main(){
	for(int i=0;i<12;i++)cin>>a[i];
	sort(a,a+12);
	bool ok=true;
	for(int i=0;i<12;i++){
		if(i%4!=3)if(a[i]!=a[i+1])ok=false;
	}
	if(ok)cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	return 0;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
int main(){
  int n,k;
  cin>>n>>k;
  ll ans=0;
  for(int b=k+1;b<=n;b++){
      ans+=b-k;
       ans+=(b-k)*((n-n%b)/b-1);
       if(n%b>=k)ans+=(n%b-k+1);
     // cout<<ans<<endl;
  }
  if(k==0)ans-=n;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a[N];
  for(int i=0;i<N;i++)cin>>a[i];
  int c[N];
  for(int i=0;i<N;i++)c[i]=0;
  for(int i=0;i<N;i++){
    while(a[i]%2==0){
      c[i]+=1;
      a[i]/=2;
    }
  }
  int res=c[0];
  for(int i=0;i<N;i++){
    if(res>c[i])res=c[i];
  }
  cout<<res;
  return 0;
}
    

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> H = new ArrayList<Integer>();
        ArrayList<Integer> W = new ArrayList<Integer>();
        int tempH, tempW;

        while (true) {
            tempH = sc.nextInt();
            tempW = sc.nextInt();

            if (tempH == 0 && tempW == 0)
                break;

            H.add(tempH);
            W.add(tempW);
        }

        for (int k = 0; k < H.size(); k++) {
            for (int i = 0; i < H.get(k); i++) {
                for (int j = 0; j < W.get(k); j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }

        sc.close();
    }
}


Measured memory_bytes: 37508
h,w,c,max;
int D(x,y,c,n,M)int *M;{
	int r=1;
	M[x+(w+2)*y]=n;
	if(M[x-1+(w+2)*y]==c)r+=D(x-1,y,c,n,M);
	if(M[x+1+(w+2)*y]==c)r+=D(x+1,y,c,n,M);
	if(M[x+(w+2)*(y-1)]==c)r+=D(x,y-1,c,n,M);
	if(M[x+(w+2)*(y+1)]==c)r+=D(x,y+1,c,n,M);
	return r;
}
E(d,M)int *M;{
	if(d==4&&M[1+w+2]==c)return;

	int *m=malloc(400);
	if(d==4){
		memcpy(m,M,400);
		D(1,1,m[1+w+2],c,m);
		int k=D(1,1,m[1+w+2],-1,m);
		if(max<k)max=k;
	}else{
		int i=1,I,J;
		for(;i<7;i++){
			if(M[1+w+2]==i)continue;
			memcpy(m,M,400);
			D(1,1,m[1+w+2],i,m);
			E(d+1,m);
		}
	}
	free(m);
}
a[100];
main(i,j){
	for(;scanf("%d%d%d",&h,&w,&c),c;printf("%d\n",max)){
		memset(a,0,400);
		for(j=1;j<h+1;j++)for(i=1;i<w+1;i++)scanf("%d",a+i+(w+2)*j);
		E(max=0,a);
	}
}

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

int main(){
  ll n;
  cin >> n;
  map<char,ll> mp;
  for(ll i=0;i<n;++i){
    string s;
    cin >> s;
    mp[s[0]]++;
  }
  vector<ll> num(5,0);
  for(auto p : mp){
    if(p.first=='M'){
      num[0]=p.second;
    }else if(p.first=='A'){
      num[1]=p.second;
    }else if(p.first=='R'){
      num[2]=p.second;
    }else if(p.first=='C'){
      num[3]=p.second;
    }else if(p.first=='H'){
      num[4]=p.second;
    }
  }

  ll ans=0;
  for(ll i=0;i<3;++i){
    for(ll j=i+1;j<4;++j){
      for(ll k=j+1;k<5;++k){
        ans+=num[i]*num[j]*num[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def shift(l, n):
    return l[n:] + l[:n]

def main():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    v_ = v[::-1]

    time = min(n, k)
    maxv = 0
    for a in range(time + 1):
        for b in range(time + 1 - a):
            sumlist = v[:a] + v_[:b]
            sumlist.sort()
            index = -1
            for i in range(min(len(sumlist), k - (a + b))):
                if sumlist[i] < 0:
                    index = i
            sumv = sum(sumlist[index+1:])
            if maxv < sumv:
                maxv = sumv
    print(maxv)

if __name__ == '__main__':
    main()


Measured memory_bytes: 41196
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
long long int mod = 998244353;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
//↓,→,↑,←
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 

ll i,j,k,ii,jj;
ll n,m,num,sumxor,sum,ans;
ll a,b,c,d,e,f,g,h,w,v;
ll x[800005],y[800005],z[900005];

bool solve(ll a){
	//a回でできますか？
	num = 0;
	for(i=0;i<n;i++){
		b = x[i] + a;
		num += (b+1)/(n+1);
	}
	//pe("a = ");pe(a);
	//pe("num = ");p(num);
	if(num == a){
		return true;
	}
	return false;
}


int main(){	
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x[i];
		sum += x[i];
	}
	a = n * (n-1);
	//sum - a回　~ sum - a + n * n回の中にある
	//O(n^3)
	for(ll i=max(0ll,sum-a-n*n);i<=sum-a+n*n;i++){
		if(solve(i)){
			p(i);
			return 0;
		}
	}


	

	
	return 0;
}

Measured memory_bytes: 8064
#include <cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1009;
int n;
int a[maxn];
int getAns(int a,int b)
{
	return (a-b)*(a-b);
}
int main(int argc, char *argv[])
{

	while(scanf("%d",&n)!=EOF)
	{
       for(int i=0;i<n;i++)
		  scanf("%d",&a[i]);
      sort(a,a+n);

      int min=19999999;
	  for(int i=-100;i<=100;i++)
		{
		  int ans=0;
		  for(int j=0;j<n;j++)
			{
			  ans+=getAns(a[j],i);
			}
			if(ans<min)
				min=ans;
		}
		printf("%d\n",min);
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S, T;
	cin >> S >> T;
	bool ans = false;
	for (int i = 0; i < S.size(); ++i) {
		if (S == T) {
			ans = true;
			break;
		}
		S = S.back() + S.substr(0, S.size() - 1);
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;

#define NUM (120000)
#define DAY (4000000)
int N, Q, t[NUM], x[NUM], y[NUM];
Int w[NUM];
int s[NUM];
Int val[NUM];
vector<int> ev[DAY];
Int a, b, c;

void enq(int ix, int d) {
    if (t[ix] == 0) c++;
    else if (t[ix] == 1) b++, c -= d;
    else a++, b -= 2*d, c += (Int)d*d;
    s[ix] = d;
    ev[d+x[ix]].push_back(ix);
}

void deq(int ix) {
    if (t[ix] == 0) c--;
    else if (t[ix] == 1) b--, c += s[ix];
    else a--, b += 2*s[ix], c -= (Int)s[ix]*s[ix];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> Q;
    rep (i, N) cin >> w[i] >> t[i] >> x[i];
    rep (i, Q) cin >> y[i];
    rep (i, N) s[i] = DAY;
    int p = 0, q = 0;
    Int cur = 0;
    for (int d = 0; d < DAY; d++) {
        cur += a*d*d + b*d + c;
        if (d == 0) c++;
        while (p < N && w[p] <= cur) enq(p++, d);
        rep (i, ev[d].size()) deq(ev[d][i]);
        while (q < Q && y[q] == d) val[q++] = cur;
    }
    rep (i, N) {
        if (s[i] > 3652425) cout << "Many years later" << endl;
        else cout << s[i] << endl;
    }
    rep (i, Q) cout << val[i] << endl;
    return 0;
}

Measured memory_bytes: 98984
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
const int N=1e5+1;
const int INF=1e9+7;

int32_t main()
{
 ios_base::sync_with_stdio(0);
 cin.tie(0); cout.tie(0);
 string s; cin>>s;
 int sum=0;
 for(int i=0;i<s.size();i++)
 {
     sum+=(s[i]-'0');
 }
 if(sum%9==0){cout<<"Yes";}
 else{cout<<"No";}
}


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

int main(){
  string CIN;
  cin >> CIN;
  int COUT = 0;
  for(int i = 0; i < 3; i++){
   if( static_cast<int>(CIN[i]) == 49 ){ COUT++; }
  }
  cout << COUT << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while(true) {
            String line = sc.nextLine();
            if(line.equals("-")) {
                break;
            }
            String line1 = sc.nextLine();
            int m = Integer.parseInt(line1);
            String ans = line;
            for(int i = 0; i < m; i++) {
                String line2 = sc.nextLine();
                int h = Integer.parseInt(line2);
                String add = ans.substring(0, h);
                ans = ans.substring(h, ans.length());
                ans += add;
            }
            System.out.println(ans);
        }
    }
 }


Measured memory_bytes: 26448
import itertools
while True:
    n, x = [int(i) for i in input().split()]
    if n == 0 and x == 0:
        break
    
    count = 0
    for i, j, k in itertools.combinations(range(1, n + 1), 3):
        if i + j + k == x:
            count = count +1
    print(count)


Measured memory_bytes: 5640
import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;

/**
 * Created on 2017/09/30 21:17.
 */
public class Main {
    private static long[] reduce(long p, long q) {
        BigInteger P = new BigInteger(Long.toString(p));
        BigInteger Q = new BigInteger(Long.toString(q));
        BigInteger gcd = P.gcd(Q);
        P = P.divide(gcd);
        Q = Q.divide(gcd);
        return new long[]{P.longValue(), Q.longValue()};
    }

    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextLong()) {
            long N = sc.nextLong();
            long hAns = -1;
            long nAns = -1;
            long wAns = -1;

            for (long h = 1; hAns == -1 && h <= 3500; h++) {
                for (long n = h; n <= 3500; n++) {
                    long p = 4 * h * n - N * n - N * h;
                    if (p <= 0) {
                        continue;
                    }

                    long q = N * h * n;
                    long[] r = reduce(p, q);
                    if (r[0] == 1) {
                        hAns = h;
                        nAns = n;
                        wAns = r[1];
                        break;
                    }
                }
            }

            System.out.println(hAns + " " + nAns + " " + wAns);
        }
    }
}

Measured memory_bytes: 26452
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (b % a == 0 ? a + b : b - a) << endl;
}

Measured memory_bytes: 3604
from sys import exit

n = int(input())
a = [int(input()) for i in range(n)]

i = 0
cnt = 0
while 1:
    if i == 1:
        print(cnt)
        exit()

    if cnt>=n:
        print(-1)
        exit()

    i = a[i] - 1
    cnt += 1

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

signed main() {
    int ans, sum;
    string s, t;
    
    cin >> s >> t;
    
    ans = 1000;
    for (int i=0 ;i<=s.size()-t.size(); i++ ) {
        sum = 0;
        for (int j=0; j<t.size(); j++ ) {
            if (s[i+j] != t[j]) {
                sum ++;
            }
        }
        
        ans = min(sum, ans);
    }
    
    cout << ans << endl;
    
    return (0);
}

Measured memory_bytes: 3632
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]

A.sort()
B.sort()
C.sort()

A.append(10**10)
B.append(10**10)
C.append(10**10)

btab=[0 for i in range(n)]

idx=0
for i in range(n):
    while A[idx] < B[i]:
        idx+=1
    btab[i]=idx

idx=0
sow=0
ans=0
for i in range(n):
    while B[idx] < C[i]:
        sow+=btab[idx]
        idx+=1
    ans+=sow

print(ans)

Measured memory_bytes: 29248
chomp($line = <>);

($s, $t) = (0, 0);
for $i (split(//, $line)){
	if($i eq 'S'){
		$s++;
	}elsif(($i eq 'T') and ($s >= 1)){
		$s--;
		$t++;
	}
}

printf length($line) - ($t * 2) . "\n";


Measured memory_bytes: 17996
N = int(input())
works = [tuple(map(int, input().split())) for i in range(N)]
works.sort(key=lambda x:x[1])

now = 0
ans = "Yes"
for i in range(N):
    now += works[i][0]
    if(works[i][1]<now):
        ans = "No"
        break

print(ans)

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

int main() {
    int a;
    int b;
    int c;
    int d;
    int e;
    int k;
    cin >>a;
    cin >>b;
    cin >>c;
    cin >>d;
    cin >>e;
    cin >>k;
    if(e - a <= k)cout << "Yay!" <<endl;
    else cout << ":(" <<endl;
}

Measured memory_bytes: 3604
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int n;
    cin >> n;
    const int MAX_K = 1e6;
    vector<int> d(n);
    REP(i, n) cin >> d[i];
    set<int> s;
    REP(i, MAX_K) s.insert(i);
    for(int i = 0; i < n; i++) {
        if(d[i] == 0) {
            s.erase(d[i]);
        } else {
            int num = 0;
            for(int k = i; k < n; k++) {
                num = num * 10 + d[k];
                if(num > MAX_K) break;
                s.erase(num);
            }
        }
    }
    cout << *s.begin() << endl;
    return 0;
}

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

namespace ConsoleApp_ITP1_7_A
{
    class Program
    {
        static void Main(string[] args)
        {

            for (int i = 1; i <= 50; i++)
            {
                int[] inputScore = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                int m = inputScore[0];
                int f = inputScore[1];
                int r = inputScore[2];

                if (m == -1 && f == -1 && r == -1)
                    break;

                else if (m == -1 || f == -1 || m + f < 30)
                    Console.WriteLine("F");

                else if (m + f >= 80)
                    Console.WriteLine("A");

                else if (m + f >= 65 && m + f < 80)
                    Console.WriteLine("B");

                else if (m + f >= 50 && m + f < 65)
                    Console.WriteLine("C");

                else if (m + f >= 30 && m + f < 50)
                {
                    if (r >= 50)
                        Console.WriteLine("C");
                    else
                        Console.WriteLine("D");
                }
            }
        }
    }
}



Measured memory_bytes: 9268
#include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std; 
     
    int n,k,a[100005],f[100005];
     
    int main(void){
    	scanf("%d %d",&n,&k);
    	for(int i=1;i<=n;i++)
    	scanf("%d",&a[i]);
    	memset(f,0x3f,sizeof(f));
    	f[1]=0;
    	for(int i=2;i<=n;i++){
    		for(int j=1;j<=k;j++)
    		if(i-j<=0)continue;
    		else
    		f[i]=min(f[i],abs(a[i]-a[i-j])+f[i-j]);
    	}
    	printf("%d",f[n]);
    }

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

vector<int> v1[10010],v2[10010];
bool used[10010];
int cmp[10010]={};

stack<int> st;

void dfs(int num){
  used[num] = true;
  for(int i=0;i<v1[num].size();i++){
    if(!used[ v1[num][i] ]) dfs(v1[num][i]);
  }
  st.push(num);
}

void rdfs(int num,int k){
  used[num] = true;
  cmp[num] = k;
  for(int i=0;i<v2[num].size();i++){
    if(!used[ v2[num][i] ]) rdfs(v2[num][i],k);
  }
}

int main(){
  
  int n,m,s,t;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> s >> t;
    v1[s].push_back(t);
    v2[t].push_back(s);
  }
  
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++){
    if(!used[i]) dfs(i);
  }

  int k=0,top;
  memset(used,0,sizeof(used));
  while(!st.empty()){
    top = st.top();
    st.pop();
    if(!used[top]){
      rdfs(top,k);
      k++;
    }
  }
  
  int q,a,b;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> a >> b;
    cout << (cmp[a]==cmp[b]?1:0) << endl;
  }
  
  return(0);
}



Measured memory_bytes: 4824
#include<stdio.h>
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
int main(){
  long long a,b,n,d[110],s=1,i;
  scanf("%lld",&n);
  for(i=0;i<n;i++)scanf("%lld",&d[i]);
  a=d[0];
  for(i=1;i<n;i++)a=gcd(a,d[i]);
  for(i=0;i<n;i++)s*=d[i]/gcd(s,d[i]);
  printf("%lld\n",s);
  return 0;
}
  


Measured memory_bytes: 256
from fractions import gcd
def lcm(p,q):
    return p*q//gcd(p,q)

n,m = map(int, input().split())
a = list(map(int, input().split()))
x = 1
for i in range(n):
    a[i] = a[i]//2
    x = lcm(x,a[i])
    if x>m:
        print(0)
        exit()
for i in range(n):
    if (x//a[i])%2==0:
        print(0)
        exit()
p = m//x
if p%2==0:
    ans = p//2
else:
    ans = p//2 +1
print(ans)

Measured memory_bytes: 16320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, k;
    cin >> a >> b >> k;
    ll s = a - min(k, a);
    k -= a - s;
    ll t = b - min(b, k);
    cout << s << " " << t << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
int main()
{
	int hw[100][100]={0};
	int h,w;
	int n;
	scanf("%d%d",&h,&w);
	scanf("%d",&n);
	vector<int> cs(n+1);
	int t,t1;
	for(t=1;t<=n;t++)
		scanf("%d",&cs[t]);
	int j = 1,cw=1;
	t = t1 = 0;
	while(cw <= n)
	{
		hw[t][t1] = cw;
		cs[cw]--;
		if(cs[cw] == 0)
			cw++;
		t1 += j;
		if(t1==w || t1==-1)
		{
			j = -j;
			t ++;
			t1 += j;
		}
	}
	for(t=0;t<h;t++)
	{
		printf("%d",hw[t][0]);
		for(t1=1;t1<w;t1++)
			printf(" %d",hw[t][t1]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
#define int long long
using namespace std;

int a[3003][3003],pre[3003][3003];

main(){

    string s,ss;
    cin>>s>>ss;
    r(i,0,ss.size()+2)r(j,0,s.size()+2)a[i][j]=0;
    ss=' '+ss;
    s=' '+s;
    r(i,1,ss.size()+1){
      r(j,1,s.size()+1){
        if(ss[i]==s[j]){
          a[i][j]=a[i-1][j-1]+1;
          pre[i][j]=(i-1)*100000+j-1;
        }
        else{
          a[i][j]=max(a[i-1][j],a[i][j-1]);
          if(a[i-1][j]<a[i][j-1]){
            pre[i][j]=i*100000+j-1;
          }
          else{
            pre[i][j]=(i-1)*100000+j;
          }
        }
      }
    }

    string ans;
    int y=ss.size()-1;
    int x=s.size()-1;

    while(y!=0||x!=0){
      //cout<<ss<<' '<<s<<endl;
      //cout<<y<<' '<<x<<endl;
      //cout<<ss.size()<<endl;
      int X=pre[y][x];
      int i=X/100000;
      int j=X%100000;
      //cout<<x<<endl;
      //cout<<s[x]<<endl;
      //cout<<x<<endl;
      if(y!=i&&x!=j)ans+=s[x];
      y=i;
      x=j;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;

}

Measured memory_bytes: 141184
import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			k = scanner.nextInt();
			if ((n | k) == 0)
				break;
			num = new int[n];
			for (int i = 0; i < n; i++)
				num[i] = scanner.nextInt();
			set = new HashSet<String>();
			dfs(0, "", 0);
			System.out.println(set.size());
		}
	}

	private void dfs(int x, String s, int bit) {
		if (x == k) {
			set.add(s);
			return;
		}
		for (int i = 0; i < n; i++) {
			if (((bit >> i) & 1) == 1)
				continue;
			dfs(x + 1, s + num[i], bit | 1 << i);
		}
	}

	int n, k;
	int[] num;
	Set<String> set;
}

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

void reader(int *x) {
	int k = getchar(); *x = k - '0';
	while (true) {
		k = getchar();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
vector<int>E[100000], V[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
bool b[200000], ok[100000];

void bfs(int u) {
	queue<int>que;
	que.push(u);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		for (int v : V[p]) {
			if (d[v] == d[p] + 1 && !ok[v]) {
				ok[v] = true; cnt++; que.push(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(&n); reader(&m); reader(&q);
	rep(i, m) {
		reader(&u[i]); reader(&v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	queue<int>que;
	memset(d, -1, sizeof(d));
	d[0] = 0; que.push(0);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		for (int i : E[p]) {
			if (d[i] == -1) {
				d[i] = d[p] + 1; que.push(i);
			}
		}
	}
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, q) {
		reader(&r[i]); r[i]--;
		b[r[i]] = true;
	}
	ok[0] = true;
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] - d[u[i]] == 1) {
				V[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] - d[u[r[i]]] == 1 && !ok[v[r[i]]]) {
			V[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = true;
				bfs(v[r[i]]);
			}
		}
	}
	rep(i, q)printf("%d\n", ans[i]);
}

Measured memory_bytes: 17876
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define All(A) A.begin(),A.end()
#define RAll(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<double,double> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;


int main(){
    int N;
    cin >> N;
    LL ans=0;
    for(int i=0;i<N;i++){
        LL a;
        cin >> a;
        while(1){
            if(a%2) break;
            a/=2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>

using namespace std;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool isSame(int x, int y) {
        return root(x) == root(y);
    }

    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

using P = pair<int, int>;

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<set<int>> F(N);
    vector<set<int>> B(N);
    UnionFind uf(N);

    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--, b--;
        F[a].insert(b);
        F[b].insert(a);
        uf.unite(a, b);
    }
    for (int i = 0; i < K; i++) {
        int c, d; cin >> c >> d; c--, d--;
        if (!uf.isSame(c, d)) continue;
        B[c].insert(d);
        B[d].insert(c);
    }

    for (int i = 0; i < N; i++) {
        int mem = uf.size(i) - 1;
        mem -= F[i].size();
        mem -= B[i].size();
        cout << mem << " ";
    }
    cout << endl;

    return 0;

}


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

int main(){
  int N;
  cin >> N;
  
  int P = 0;
  
  vector<int> position(N);
  for (int i = 0; i < N; i++){
    cin >> position.at(i);
    P += position.at(i);
  }
  
  P /= N;
  
  int Q = P + 1;
  
  int answer1 = 0;
  int answer2 = 0;
  
  for (int i = 0; i < N; i++){
    answer1 += (position.at(i) - P) * (position.at(i) - P);
    answer2 += (position.at(i) - Q) * (position.at(i) - Q);
  }
  
  cout << min(answer1, answer2) << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int a,b,c;

	cin >> a >> b >> c;

	cout << a+b+c-max(a,max(b,c)) << endl;

	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) REPI(i, 0, n)
#define REPI(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)

#define SZ(x) ((int)(x).size())


using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;

int main()
{
    string S;
    cin >> S;
    cout << S.substr(0, 3) << endl;
    return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define M 100005
int a[M];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)if(a[i]>a[i-1])a[i]--;
	for(int i=1;i<n;++i)if(a[i]>a[i+1]){
		puts("No");
		return 0;
	}
	puts("Yes");
}

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

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	string s;
	cin>>s;
	int n = s.size();

	ll ans = 0;
	ll cnt_a = 0;
	int pos = 0;
	while(pos<n){
		if(s[pos] == 'A'){
			cnt_a++;
			pos++;
		}
		else{
			if(s[pos]=='B' && pos+1<n && s[pos+1] == 'C'){
				ans += cnt_a;
				if (pos+2<n)
					pos += 2;
				else
					break;
			}else{
				cnt_a = 0;
				pos++;
			}
		}
	}

	cout << ans<<endl;

	return 0;
}

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

using namespace std;

int main(){
    int n, l;
    cin >> n >> l;
    vector<string> ss(n);
    
    for(size_t i = 0; i < n; ++i)
        cin>> ss.at(i);
    sort(ss.begin(), ss.end());

    for(size_t i = 0; i < n; ++i)
    {
        cout << ss.at(i);
    } cout << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    
    int w,a,b;
    
    scanf("%d %d %d",&w,&a,&b);
    
    int sa = a;
    int ea = a+w;
    int sa2 = b;
    int ea2 = b+w;
    
    if(sa <= sa2 && sa2 <= ea)printf("0\n");
    else if(sa <=ea2 && ea2<=ea) printf("0\n");
    else if(sa2 <=sa && sa<=ea2) printf("0\n");
    else if(sa2 <= ea && ea<=ea2) printf("0\n");
    else printf("%d\n",min(abs(sa2-ea),abs(sa-ea2)));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define REP(i,n,m) for(int i=(m);i<(n);i++)
using namespace std;
 
  int main(){
      int ans=0;
      int n;
      cin >> n;
    vector<int> a(n),b(n);
    rep(i,n-1){
        cin >> b[i];
    }
    
    for(int i=0;i<n;i++){
        ans+=b[i];
        
        if(b[i-1]<b[i] && i!=0){
        ans=ans-b[i]+b[i-1];
        }
        if(i+2==n){
            ans+=b[i];
        }
    }
      cout << ans << endl;
  }

Measured memory_bytes: 3608
void main() {
	auto N = ri;
	auto A = readAs!(int[]).sort!"a > b"().array;
	auto B = A.uniq.array;
	long last = A[0];
	int[] arr = [1];
	foreach(i; A[1..$]) {
		if(last == i) arr.back++;
		else {
			last = i;
			arr ~= 1;
		}
	}
	ulong len1, len2;
	foreach(i, v; arr) {
		if(v >= 4) {
			if(len1 == 0) {
				len1 = len2 = B[i];
				break;
			} else {
				len2 = B[i];
				break;
			}
		} else if(v >= 2) {
			if(len1 == 0) len1 = B[i];
			else {
				len2 = B[i];
				break;
			}
		}
	}
	writeln(len1 * len2);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n); rep(i,n) cin >> a[i];
    rep(i,n-k) cout << (a[i+k] > a[i] ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int A,B,C;
    cin>> A >> B >> C;
    if(A==B){
        if(A==C){
            cout << "No";
        }else{
            cout << "Yes";
        }
    }else{
        if(A==C){
            cout << "Yes";
        }else if(B==C){
            cout << "Yes";
        }else{
            cout << "No";
        }
    }
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 2007;

int n, m, q;
char s[MAXN][MAXN];
int a[MAXN][MAXN];
int er[MAXN][MAXN], ec[MAXN][MAXN];
int cv[MAXN][MAXN], ce[MAXN][MAXN], cr[MAXN][MAXN], cc[MAXN][MAXN];
int xl, xr, yl, yr;

void init ();
void input ();
void inputq ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d%d%d", &n, &m, &q );
	lpi ( i, 1, n ) scanf ( "%s", s[i]+1 ); 
}

void inputq ()
{
	// input query
	
	scanf ( "%d%d%d%d", &xl, &yl, &xr, &yr );
}

void work ()
{
	// main work
	
	INIT ( a, -1 );
	lpi ( i, 1, n ){
		lpi ( j, 1, m ){
			a[i][j] = s[i][j] - '0';
			er[i][j] = a[i][j] == 1 && a[i][j-1] == 1;
			ec[i][j] = a[i][j] == 1 && a[i-1][j] == 1;
		}
	}
	
	lpi ( i, 1, n ){
		lpi ( j, 1, m ){
			cv[i][j] = cv[i-1][j] + cv[i][j-1] - cv[i-1][j-1] + a[i][j];
			ce[i][j] = ce[i-1][j] + ce[i][j-1] - ce[i-1][j-1] + er[i][j] + ec[i][j];
			cr[i][j] = cr[i][j-1] + ec[i][j];
			cc[i][j] = cc[i-1][j] + er[i][j];
		}
	}
	
	lp ( _q, 0, q ){
		inputq ();
		
		printf ( "%d\n", ( cv[xr][yr] - cv[xl-1][yr] - cv[xr][yl-1] + cv[xl-1][yl-1] ) - ( ( ce[xr][yr] - ce[xl-1][yr] - ce[xr][yl-1] + ce[xl-1][yl-1] ) - ( cr[xl][yr] - cr[xl][yl-1] ) - ( cc[xr][yl] - cc[xl-1][yl] ) ) );
	}
}

Measured memory_bytes: 115840
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
//#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cassert>
#include <unordered_map>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const int MAX = 2e3 + 50;
#else
const int MAX = 1e6 + 50;
#endif
const int mod = 1e9 + 7;
void file_read() {
#ifdef DEBUG
	freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
#endif
}

P inter[MAX];
int main() {
	file_read();
	int n, m;
	scanf("%d%d", &n, &m);
	multiset<int> ans;
	map<int, int> mp;
	for(int i = 1; i <= m; i++) {
		mp[i] = i;
		ans.insert(0);
	}
	for(int i = 1; i <= n; i++) {
		int l, r;
		scanf("%d%d", &l, &r);
		r++;
		auto it = mp.lower_bound(l);
		int tmp  = -1;
		while(it != mp.end() and it->first <= r) {
			tmp = max(tmp, it->second);
			ans.erase(ans.find(it->first - it->second));
			mp.erase(it++);
		}
		if(tmp != -1 and r <= m) {
			mp[r] = tmp;
			ans.insert(r-tmp);
		}
		if(ans.size()) {
			printf("%d\n", i+*ans.begin());
		}
		else 
		{
			puts("-1");
		}
	}
	return 0;
}

Measured memory_bytes: 22388
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MOD2 1494318097
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 105;

int R,C,dis[maxn][maxn],m[4][2] = {{0,1},{1,0},{-1,0},{0,-1}};
bool vis[maxn][maxn],in[maxn][maxn];
char arr[maxn][maxn];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> R >> C;
    for(int i=1; i<=R; i++)
        for(int k=1; k<=C; k++)
            cin >> arr[i][k];
    memset(dis,0x3f,sizeof dis);
    queue<pii> q;
    dis[0][1] = 0;
    vis[0][1] = true;
    arr[0][1] = '.';
    q.push(mp(0,1));
    while(q.size()){
        int x = q.front().first, y = q.front().second; q.pop();
        for(int i=0; i<4; i++){
            int nx = x+m[i][0], ny = y+m[i][1], cc = dis[x][y]+(arr[x][y]!=arr[nx][ny]);
            if(nx >= 1 && ny >= 1 && nx <= R && ny <= C && dis[nx][ny] > cc){
                dis[nx][ny] = cc;
                if(!in[nx][ny])
                    in[nx][ny] = true, q.push(mp(nx,ny));
            }
        }
    }
    cout << (dis[R][C]+1)/2 << nl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	long long int n, m;
	cin >> n >> m;
	vector<vector<int> > graph(100001);
	for(int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		graph[u].push_back(v);
	}
	int s, t;
	cin >> s >> t;
	s--;
	t--;

	int cnt[100001][3];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 3; j++){
			cnt[i][j] = -3;
		}
	}
	queue<pair<int, int> > qu;
	qu.push(make_pair(s, 0));
	cnt[s][0] = 0;
	while(!qu.empty()){
		int now = (qu.front()).first;
		int step = (qu.front()).second;
		qu.pop();
		for(int i = 0; i < graph[now].size(); i++){
			int next = graph[now][i];
			if(cnt[next][(step + 1) % 3] >= 0) continue;
			cnt[next][(step + 1) % 3] = cnt[now][step] + 1;
			qu.push(make_pair(next, (step + 1) % 3));
		}
	}
	cout << cnt[t][0] / 3 << endl;
}

Measured memory_bytes: 6912
k,n = map(int,input().split())
s = list(map(int,input().split()))
a=[]
for num in range(n-1):

    p= s[num+1]-s[num]
    a.append(p)
b = s[0]+(k-s[-1])
a.append(b)
x = k-max(a)
print(x)

Measured memory_bytes: 26420
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int main() {
    int N;
    long x;
    cin >> N;
    cin >> x;
    vector<long> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    sort(data.begin(), data.end());
    long sum = data.at(0);
    int ans = 0;
    for (int i = 1; i < N + 1; i++) {
        if (x < sum) {
            break;
        }
        if (sum == x) {
            ans++;
            break;
        }
        ans++;
        if (i == N) {
            break;
        }
        sum += data.at(i);
    }
    if (ans == N && sum < x) {
        ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	string t="keyence";
	int n=s.size();
	if(n<t.size())
	{
		cout<<"NO";
		return 0;
	}
	if(n==t.size())
	{
		if(s==t)
			cout<<"YES";
		else
			cout<<"NO";
		return 0;
	}
	if(s.substr(0,t.size())==t or s.substr(n-t.size())==t)
	{
		cout<<"YES";
		return 0;
	}
	for(int i=1;i<(int)t.size();i++)
	{
		string sleft=s.substr(0,i);
		string tleft=t.substr(0,i);
		string sright=s.substr(n-(t.size()-i));
		string tright=t.substr(i);
		//cout<<sleft<<" "<<tleft<<" "<<sright<<" "<<tright<<endl;
		if(sright==tright and sleft==tleft)
		{
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
}


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

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

  set<string> w;

  string s0, s1;
  cin >> s1;
  w.insert(s1);

  for (int i = 1; i < n; i++){
    s0 = s1;
    cin >> s1;

    set<string>::iterator iti = w.find(s1);
    if (iti != w.end()) {
      cout << "No" << endl;
      return 0;
    }
    w.insert(s1);

    if (s0[s0.size()-1] != s1[0]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
# print(f'{A=}, {A[1::2]=}')

M = [0] * N
M[0] = A.sum() - 2 * A[1::2].sum()

for i in range(N - 1):
    M[i + 1] = 2 * A[i] - M[i]

print(*M, sep=' ')
# A1 + A2 + ... + AN = X1 + X2 + ... + XN = S
# XN+1 = N1とすると
# (Xi + Xi+1) / 2 = Ai
# Xi + Xi+1 = 2 * Ai
# X1 = S - (X2 + ... + XN) = S - 2(A2 + A4 + ... + AN-1)
# Xi+1 = 2Ai - Xi


Measured memory_bytes: 36632
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

#include <stdio.h>

int main(void)
{
  int x;
  scanf("%d",&x);
	int i,j,yakusuu;

	for(i=x;i>=x;i++)
	{
		yakusuu=0;
		for(j=1;j<=i;j++)
		{
			if(i%j==0) yakusuu++;
        }
		if(yakusuu==2){ printf("%d",i);
        return 0;
                      }
    }

	return 0;
}

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


int main(){
    int N, M;
    int A[100];
    cin >> N >> M;
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    int sum = 0;
    for(int j=0; j<N; j++){
        sum += A[j];
    }

    int count = 0;

    for(int k=0; k<N; k++){
        if(A[k]*4*M >= sum){
            count++;
        }
    }

    if(count >= M){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
x,k,d=map(int,input().split())
x=abs(x)
ans=0
if x//d>=k:
    ans=x-d*k
else:
    if ((x//d)%2==0 and k%2==0) or ((x//d)%2==1 and k%2==1):
        ans=x%d
    else:
        ans=abs(x%d-d)
print(ans)

Measured memory_bytes: 9184
def resolve():
    X, N = [int(i) for i in input().split()]
    if N == 0:
        print(X)
        return
    P = sorted([int(i) for i in input().split()])
    if X not in P:
        print(X)
        return
    for i in range(100):
        if (X - i) not in P:
            print(X - i)
            return
        if (X + i) not in P:
            print(X + i)
            return


resolve()


Measured memory_bytes: 9188