akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ze(ll a) {
  if (a < 0) return -a;
  return a;
}
int main () {
  int N;
  cin >> N;
  vector<ll>X(N);
  vector<ll>Y(N);
  vector<ll>P(N);
  for (int i = 0; i < N; i ++) cin >> X[i] >> Y[i] >> P[i];
  ll tate[321600][20];
  ll yoko[321600][20];
  ll lx[20];
  ll ly[20];
  int si;
  for (int i = 0; i < 1 << N; i ++) {
    int i_ = i;
    lx[0] = 0;
    si = 1;
    ly[0] = 0;
    for (int j = 0; j < N; j ++) {
      if (i_ % 2) {
        lx[si] = X[j];
        ly[si] = Y[j];
        si ++;
      }
      i_ /= 2;
    }
    for (int j = 0; j < N; j ++) {
      ll tkj = ze(Y[j]);
      ll ykj = ze(X[j]);
      for (int k = 0; k < si; k ++) {
        tkj = min(tkj, ze(X[j] - lx[k]));
        ykj = min(ykj, ze(Y[j] - ly[k]));
      }
      tate[i][j] = tkj;
      yoko[i][j] = ykj;
    }
  }
  ll cnt = 1;
  for (int i = 0; i < N; i ++) cnt *= 3;
  ll ans[20];
  for (int i = 0; i <= N; i ++) ans[i] = 1e17;
  int bi[20];
  bi[0] = 1;
  for (int i = 1; i < N; i ++) bi[i] = bi[i - 1] * 2;
  for (int i = 0; i < cnt; i ++) {
    int i_ = i;
    int num = N;
    int tt = 0;
    int yk = 0;
    ll kj = 0;
    for (int j = 0; j < N; j ++) {
      if (i_ % 3 == 0) {
        num --;
      }
      if (i_ % 3 == 1) {
        tt += bi[j];
      }
      if (i_ % 3 == 2) {
        yk += bi[j];
      }
      i_ /= 3;
    }
    for (int j = 0; j < N; j ++) {
      kj += P[j] * min(tate[tt][j], yoko[yk][j]);
    }
    ans[num] = min(ans[num], kj);
  }
  for (int i = 0; i <= N; i ++) cout << ans[i] << endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<int>results(n+1);
  rep1(x, 100)rep1(y,100)rep1(z,100){
    int s = x*x+y*y+z*z + x*y+y*z+x*z;
    if(s>n)continue;
    results[s-1]++;
  }

  rep(i, n)cout<<results[i]<<endl;

  return 0;
}

Measured memory_bytes: 3576
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())

def get_sum(n):
    n_str = str(n)
    ret = 0
    for ch in n_str:
        ret += int(ch)
    return ret

A = 1
B = N - A
ans = 1e10
while B >= 1:
    ans = min(ans, get_sum(A) + get_sum(B))
    A += 1
    B -= 1
print(ans)



Measured memory_bytes: 8080
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    double n;
    cin>>n;
    cout<<2*n*3.1415926<<endl;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;

int main() {
    i64 a[3];
    rep(i, 3) cin >> a[i];
    rep(i, 3) {
        if(a[i] % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    i64 mi = 1.0e18 + 1LL;
    rep(i, 3) rep(j, 3) {
        if(i == j) continue;
        mi = min(mi, a[i] * a[j]);
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;
 
public class Main {
	
	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		int t = 1;
		while(t-->0) solver.solve(1, scan, out);
		out.close();
	}
	
	static class Task {
		static char[] a;
		public void solve(int testNumber, FastReader scan, PrintWriter out) {
			int n = scan.nextInt(), k = scan.nextInt();
			a = scan.next().toCharArray();
			int t = 0;
			char curr = a[0];
			ArrayList<Character> b = new ArrayList<>();
			b.add(curr);
			for(int i = 0; i < a.length; i++) {
				if(a[i] == 'L' && i > 0 && a[i-1] == 'L') t++;
				if(a[i] == 'R' && i < a.length-1 && a[i+1] == 'R') t++;
				if(a[i] != curr) {
					b.add(a[i]);
					curr = a[i];
				}
			}
			int count = Math.min(k, b.size()/2);
			t += count*2;
			if(b.size()%2 == 0 && count == b.size()/2) t--;
			out.println(t);
		}
		
	}
	
	static void shuffle(int[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
	static void shuffle(long[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
 
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}
 
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
 
}

Measured memory_bytes: 25172
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string x, y;
	cin >> x >> y;
	if (x > y) {
		cout << ">\n";
	}
	else if (x < y) {
		cout << "<\n";
	}
	else {
		cout << "=\n";
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x7fffffffffffffffll 
#define MN 100005
using namespace std;
inline ll in(){
    ll x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
ll a[MN],b[MN],c[MN],sum[MN],sum2[MN],sum3[MN];
ll n,k,mx,mn,xl,xr,nl,nr,res,ans;
int main()
{
	n=in();k=in();mx=-inf;mn=inf;
	for (int i=1;i<=n;++i){
		a[i]=in();sum[i]=sum[i-1]+a[i];
		b[i]=min(a[i],0ll);sum2[i]=sum2[i-1]+b[i];
		c[i]=max(a[i],0ll),sum3[i]=sum3[i-1]+c[i];
	}
	for (int i=k;i<=n;++i){
		if (sum2[i]-sum2[i-k]>mx){
			mx=sum2[i]-sum2[i-k];
			xl=i-k+1ll;xr=i;
		}
		if (sum3[i]-sum3[i-k]<mn){
			mn=sum3[i]-sum3[i-k];
			nl=i-k+1ll;nr=i;
		}
	}
	for (int i=1;i<xl;++i) res+=max(a[i],0ll);
	for (int i=xr+1;i<=n;++i) res+=max(a[i],0ll);
	res+=max(0ll,sum[xr]-sum[xl-1]);
	for (int i=1;i<nl;++i) ans+=max(a[i],0ll);
	for (int i=nr+1;i<=n;++i) ans+=max(a[i],0ll);
	printf("%lld",max(0ll,max(res,ans)));return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int x,mul,i;
  cin>>x;
  for(i=1; ;i++){
    mul=x*i;
    if(mul%360==0){
      break;
    }
  }
  cout<<i<<endl;
  return 0;
}

Measured memory_bytes: 3596
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,4);
  var A = input[0];
  var B = input[1];
  var K = input[2];
  var alist = [];
  var blist = [];
  for(var i = A; i < A+K; i++){
    if(i > B){break;}
    alist.push(i);
  }
  for(var i = B; i > B-K; i--){
    if(i < A){break;}
    blist.push(i);
  }
  blist.sort(function(a,b){return a-b;});
  alist = alist.concat(blist);
  alist = Array.from(new Set(alist));
  myout(alist.join("\n"));
}

Main(myin());


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

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

  vector<int> card(N);
  for(int i = 0; i < N; i++){
    cin >> card.at(i);
  }

  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());

  int A = 0, B = 0;
  int i = 0;
  while(i < N){
    A += card.at(i++);
    if(i >= N)break;
    B += card.at(i++);
  }

  cout << A - B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S seconnd
#define int ll
#define PB push_back


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

  while(!(n/100==n%10&&(n/10)%10==n%10)) n++;

  cout<<n<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N, K; {int[] a = in.ii(2); N = a[0]; K = a[1];}
        int[] p = in.ii(N);
        int[] sum = new int[N + 1];
        for(int i = 0; i < N; i++){
            sum[i + 1] = sum[i] + p[i];
        }

        int ans = 0;
        for(int i = 0, M = N - K + 1; i < M; i++){
            ans = Math.max(sum[i + K] - sum[i] + K, ans);
        }
        out.println(ans / 2.0);
    }


    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        int[] ii(final int N) {
            int[] a = new int[N];
            int i = 0;
            String s = s();
            for (int j = 0; j < a.length; j++) {
                while (s.charAt(i) == ' ') {
                    i++;
                }

                boolean minus = s.charAt(i) == '-';
                i = minus ? i + 1 : i;

                int k = 0;
                while (true) {
                    try {
                        int h = s.charAt(i++) - '0';
                        if (h < 0 || 9 < h) {
                            break;
                        }
                        k = 10 * k + h;
                    } catch (Exception e) {
                        break;
                    }
                }
                a[j] = minus ? -k : k;
            }
            return a;
        }
    }
}


Measured memory_bytes: 40748
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int A, B, C, n;
vector<int> l;

int dfs(int current, int a, int b, int c) {
  if (current == n) {
    return (a > 0 && b > 0 && c > 0) ? abs(a - A) + abs(b - B) + abs(c - C) - 30
                                     : 1111111111;
  }

  int ret1 = dfs(current + 1, a, b, c);
  int ret2 = dfs(current + 1, a + l[current], b, c) + 10;
  int ret3 = dfs(current + 1, a, b + l[current], c) + 10;
  int ret4 = dfs(current + 1, a, b, c + l[current]) + 10;

  return min({ret1, ret2, ret3, ret4});
}

int main() {
  cin >> n >> A >> B >> C;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    l.push_back(tmp);
  }
  cout << dfs(0, 0, 0, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int K;
  cin >> K;

  vector <int> a(K + 1);
  a[1] = 7 % K;
  for (int i = 2; i <= K; i++){
    a[i] = (a[i - 1] * 10 + 7) % K;
  }
  for (int i = 1; i <= K; i++){
    if (a[i] == 0){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 7108
N=int(input())
L=2**N
#print(bin(10),bin(10)[1])
#print(N)

data=[]
for i in range(N):
  A=int(input())
  kari=[]
  for j in range(A):
    kari.append(list(map(int,input().split())))
#  print(kari)
  data.append(kari)
                
#print(data)   
answer=0
for i in range(L):
  cond=0
  ansatz=bin(i)
  m=len(ansatz)
  for j in range(m-2):
    if cond==1:
      break
    if int(ansatz[m-j-1])==1:
      for k in range(len(data[j])):
        x=data[j][k][0]
        y=data[j][k][1]
        if x>m-2:
         if y==1:
           cond=1
           break
        else:
          if y != int(ansatz[m-x]):
           cond=1 
           break
  if cond==0:
    sum=0
    for j in range(m-2):
      sum += int(ansatz[m-j-1])
    if sum > answer:
      answer=sum
      
print(answer)




Measured memory_bytes: 3064
import heapq
N,M = map(int,input().split())
list_A = list(map(lambda x: int(x)*(-1),input().split()))	

#print(list_A)
heapq.heapify(list_A)
for i in range(M):
  
  target = heapq.heappop(list_A)
  #print("after heappop",list_A)
  
  '''負の要素の切り捨て除算は切り捨てがマイナスの方に
  行くため少しだけややこしい。'''
  heapq.heappush(list_A, (-1)*((-target) // 2))  # 要素の挿入
  #print("No.",i,"change finished",list_A)

print(-sum(list_A))




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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

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

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

    int N, A, B;
    cin >> N >> A >> B;
    string S;
    cin >> S;
    int cnta = 0, cntb = 0;
    for (int i = 0; i < N; i++) {
        bool ok = false;
        if (S[i] == 'a') {
            if (cnta + cntb < A + B) {
                ok = true;
                ++cnta;
            }
            else {
                ok = false;
            }
        }
        else if (S[i] == 'b') {
            if (cnta + cntb < A + B && cntb < B) {
                ok = true;
                ++cntb;
            }
            else {
                ok = false;
            }
        }
        else {
            ok = false;
        }

        cout << (ok ? "Yes" : "No") << "\n";
    }

    return 0;
}

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

class DisjointSets {
 public:
  DisjointSets(int size) : data_(size, -1) {}

  void Union(int a, int b) {
    if ((a = Find(a)) != (b = Find(b))) {
      if (data_[a] > data_[b]) std::swap(a, b);
      data_[a] += data_[b];
      data_[b] = a;
    }
  }

  int Find(int a) {
    if (data_[a] < 0) return a;
    return data_[a] = Find(data_[a]);
  }

  int GetSize(int a) {
    return -data_[Find(a)];
  }

 private:
  std::vector<int> data_;
};


int main() {
  int N, M;
  std::cin >> N >> M;
  DisjointSets disjoint_sets(N);
  for (int i = 0; i < M; ++i) {
    int A, B;
    std::cin >> A >> B;
    disjoint_sets.Union(A - 1, B - 1);
  }
  int max_size = 0;
  for (int i = 0; i < N; ++i) {
    max_size = std::max(max_size, disjoint_sets.GetSize(i));
  }
  std::cout << max_size << std::endl;
  return 0;
}


Measured memory_bytes: 4044
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }


fn main() {
    input! {
        H: u64, W: u64,
        h: u64, w: u64
    }

    println!("{}", (W - w) * (H - h));
}

Measured memory_bytes: 4352
import time
import random
import sys
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math

inf = 10**9


def isPrime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    for i in range(3, math.floor(math.sqrt(x))+1, 2):
        if x % i == 0:
            return False

    return True


def main():
    count = 0
    n = int(input())

    for i in range(n):
        x = int(input())
        if isPrime(x):
            count = count + 1
            # print(x, "is prime number")

    print(count)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9092
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		while(sc.hasNext()){
			long a = sc.nextLong();
			long a1 = a;
			long b = sc.nextLong();
			long b1 = b;
			long i;
			if(a > b){
				for(;;){
					if(a1 % b == 0){
						break;
					}
					a1 += a;
				}
				if(a % b == 0){
					System.out.println(b + " " + a1 );
				}
				else{
					for(i = b / 2; i > 0; i--){
						if(a % i == 0 && b % i == 0){
							break;
						}
					}
					System.out.println(i + " " + a1 );
				}
			}
			else if(a < b){
				for(;;){
					if(b1 % a == 0){
						break;
					}
					b1 += b;
				}
				if(b % a == 0){
					System.out.println(a + " " + b1 );
				}
				else{
					for(i = a / 2; i > 0; i--){
						if(a % i == 0 && b % i == 0){
							break;
						}
					}
					System.out.println(i + " " + b1 );
				}	
			}
			else{
				System.out.println(b + " " + b1 );
			}
		}
	}

}

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

using namespace std;

int main () {

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

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		


int main() {

	int n;
	cin >> n;
	VLL a(n);
	REP(i, n)cin >> a[i];
	sort(ALL(a));
	ll ans = 0;

	vector<bool> b(n, true);

	for (int i = n - 1; i >= 0; i--) {
		if (!b[i])continue;
		b[i] = false;
		ll j = 1;
		while (j <= a[i])j *= 2;
		j -= a[i];

		ll l = upper_bound(ALL(a), j) - a.begin();
		for (int k = min(l - 1,(ll)i);; k--) {
			if (a[k] != j)break;
			if (b[k]) {
				b[k] = false;
				ans++;
				break;
			}
		}
	}

	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 1920
#include <cmath>
#include<iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
using namespace std;
 
int main(){    
  int A,B;
  cin >> A >> B;

  if(A <= 2*B){
    cout << "0" << endl;
  }
  else{
    cout << A-2*B << endl;
  }
}


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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int height, width;
	cin >> height >> width;
	
	string dummy(width + 2, '.');
	vector<string> field(height + 2, dummy);
	for (int i = 0; i < height; i++) {
		string input;
		cin >> input;
		field[i + 1] = "." + input + ".";
	}
	
	// ---
	string init(width, '#');
	vector<string> answer(height, init);
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++){
			int x = i + 1;
			int y = j + 1;
			if (field[x][y] == '#') continue;
			// ---
			int count = 0;
			if (field[x-1][y] == '#') count++;
			if (field[x+1][y] == '#') count++;
			if (field[x][y+1] == '#') count++;
			if (field[x][y-1] == '#') count++;
			if (field[x-1][y-1] == '#') count++;
			if (field[x+1][y-1] == '#') count++;
			if (field[x-1][y+1] == '#') count++;
			if (field[x+1][y+1] == '#') count++;
			// ---
			ostringstream oss;
			oss << count;
			answer[i][j] = oss.str()[0];
		}
	}
	// ---
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++){
			cout << answer[i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;
    int maxH; cin >> maxH;
    rep(i, 1, N) {
      int H; cin >> H;
      if (maxH - H > 1) {
        cout << "No" << endl;
        return 0;
      }
      maxH = max(maxH, H);
    }
  
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
S = input()
T = input()
count = 0
for i in range(len(S)):
    if S == T:
        print("Yes")
        count += 1
        break
    else:
        s1 = S[-1] 
        s2 = S[:-1]
        S = s1 + s2
if count == 0:
    print("No")

Measured memory_bytes: 3060
#!/usr/bin/perl
my ($n,$k) = map { $_ - 0 } split(/[\s]+/,<STDIN>);
my @h = ();
foreach(1..$n){
  my $hh = scalar(<STDIN>) - 0;
  push(@h,$hh);
}
my @sh = sort { $a <=> $b} @h;
my $mn = 10 ** 9;
for(my $i=0;$i<=($n-1)-($k-1);$i++){
  my $dif = $sh[$i+$k-1]-$sh[$i];
  $mn = $dif if $dif < $mn;
}
print "$mn\n";


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,K;
ll A[202020];

ll i, j, k;

int main(){
    scanf("%lld%lld", &N, &K);
    rep(i,0,N){
        scanf("%lld", &A[i]);
    }
    rep(i,K,N){
        if(A[i-K]<A[i]){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }

    return 0;
}

Measured memory_bytes: 5248
module ABC049C
	sub Main(ByVal args() as String)
		dim T() as string = {"dream","dreamer","erase","eraser"}
		dim s as string
		dim i,c,l,k as integer
		for i=0 to 3
			T(i)=StrReverse(T(i))
		next
		s=StrReverse(Console.ReadLine())
		c=0
		l=s.Length
		while c<l
			k=-1
			for i=0 to 3
				if l-c>=T(i).Length andalso s.Substring(c,T(i).Length)=T(i)
					k=T(i).Length
					exit for
				end if
			next
			if k<0
				Console.WriteLine("NO")
				return
			end if
			c+=k
		end while
		Console.WriteLine("YES")
	end sub
end module


Measured memory_bytes: 22736
#include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int l=0,d=0,m=0;
		int L=0,D=0,M=0;

		rep(i,n){
			int a,b,c;
			char ch;
			cin>>a>>ch>>b>>c;
			if(c<b)c+=60;

			if(11<=a && a<=14){
				L++;
				if(c-b<=8)l++;
			}if(18<=a && a<=20){
				D++;
				if(c-b<=8)d++;

			}if(21<=a && a<=24){
				M++;
				if(c-b<=8)m++;

			}if(0<=a && a<=1){
				M++;
				if(c-b<=8)m++;
			}
		}
		cout<<"lunch ";
		if(L==0)cout<<"no guest"<<endl;
		else cout<<(int)100*l/L<<endl;
		cout<<"dinner ";
		if(D==0)cout<<"no guest"<<endl;
		else cout<<(int)100*d/D<<endl;
		cout<<"midnight ";
		if(M==0)cout<<"no guest"<<endl;
		else cout<<(int)100*m/M<<endl;
	}
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP((i),0,(n))
#define ALL(v) (v).begin(),(v).end()

int main() {
	int n, k;
	cin >> n >> k;
	int sum = 1;
	while(n--) sum = min(sum * 2, sum + k);

	cout << sum << endl;
}

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

typedef unsigned long long ull;

#define MAX_P5 8883

signed main()
{
    ull p5[MAX_P5 + 10];
    for (ull i = 0; i <= MAX_P5; ++i)
        p5[i] = i * i * i * i * i;

    ull x; cin >> x;
    int d = 0;
    int a, b;

    for (a = 0; a <= MAX_P5; ++a){
        for (b = 0; b <= MAX_P5; ++b){
            if (p5[a] - p5[b] == x){
                d = 1; break;
            }
            if (p5[a] + p5[b] == x){
                d = -1; break;
            }
        }
        if (d != 0) break;
    }

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

    return 0;
}


Measured memory_bytes: 3840
import math
n,k=map(int,input().split())
#まずサイコロでN通り
#表が何回あればいいか考える((k-1)//2+1)
#裏が出たら負け
p=0
for i in range(1,n+1):
    if k//i==0:
        p+=1/n
    elif k%i!=0:
        p+=((1/2)**(int(math.log2(k//i)+1)))/n
    elif 2**int(math.log2(k//i))!=k//i:
        p+=((1/2)**(int(math.log2(k//i)+1)))/n
    else:
        p+=((1/2)**(int(math.log2(k//i))))/n

print(p)


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int n;
    cin >> n;
    vector<pair<int,int>> v;
    vector<vector<int>> count(64, vector<int>(32));

    rep(i, n){
        string s;
        cin >> s;

        int index = 0;
        ll a = 0;
        ll b = 0;

        while(index < s.size() && s[index] != '.'){
            a = a * 10 + (s[index] - '0');
            index++;
        }

        index++;
        int bdigit = 0;

        while(index < s.size()){
            b = b * 10 + (s[index] - '0');
            index++;
            bdigit++;
        }
        
        rep(i, 9){
            a = a * 10;
        }

        rep(i, 9 - bdigit){
            b = b * 10;
        }

        ll sum = a + b;

        int num2 = 0;
        int num5 = 0;

        while(sum % 2 == 0){
            sum = sum / 2;
            num2++;
        }

        while(sum % 5 == 0){
            sum = sum / 5;
            num5++;
        }

        v.push_back(make_pair(num2, num5));
        //cerr << num2 << " " << num5 << endl;
        count[num2][num5]++;
    }

    ll ans = 0;

    vector<vector<int>> imos(65, vector<int>(33));

    rep(i, 64){
        rep(j, 32){
            imos[0][0] += count[i][j];
            imos[0][j + 1] -= count[i][j];
            imos[i + 1][0] -= count[i][j];
            imos[i + 1][j + 1] += count[i][j];
        }
    }

    rep(i, 64){
        rep(j, 32){
            imos[i][j + 1] = imos[i][j + 1] + imos[i][j];
        }
    }

    rep(j, 32){
        rep(i, 64){
            imos[i + 1][j] = imos[i + 1][j] + imos[i][j];
        }
    }

    /*
    rep(i, 65){
        rep(j, 33){
            cerr << imos[i][j] << " ";
        }
        cerr << endl;
    }*/

    rep(i, n){
        int need2 = max(0, 18 - v[i].first);
        int need5 = max(0, 18 - v[i].second);

        ans += imos[need2][need5] - (v[i].first >= 9 && v[i].second >= 9 ? 1 : 0);
    }
    cout << ans / 2 << endl;
    return 0;
}


Measured memory_bytes: 5296
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}

int h,w,n;
vector<vector<char>> bord;
vector<vector<pair<int,ll>>> graph; // id,weight
ll dist[1000005],pre[1000005];
void dijkstra(int start){
	for(int i{0};i < n;i++){
		dist[i] = 1e18;
		pre[i] = -1;
	}
	dist[start] = 0;
	set<pair<int,int>> pq; // distance,id
	pq.insert({0,start});
	while(!pq.empty()){
		int top = pq.begin()->second;
		pq.erase(pq.begin());
		for(auto node : graph[top]){
			//debug(node.second);
			if(dist[node.first] > dist[top] + node.second){
				dist[node.first] = dist[top] + node.second;
				pre[node.first] = top;
				pq.insert({dist[node.first],node.first});
			}
		}
	}
}
void solve(int i,int j){
	if(bord[i][j] != '.')return;
	for(int r = i - 2;r <= i+2;r++){
		for(int c = j-2;c <= j+2;c++){
			if(r >= 0 && r < h && c >= 0 && c < w && !(i == r && j == c) && bord[r][c] == '.'){
				ll cost = 1e6;
				if(abs(i-r) + abs(j-c) <= 1){cost = 1;}
				graph[i*w + j].pb({r*w + c,cost});
				graph[r*w + c].pb({i*w + j,cost});
			}
		}
	}
}
void testcase(){
	int ch,dh,cw,dw;
	cin >> h >> w;
	cin >> ch >> cw >> dh >> dw;
	ch--;cw--;dh--;dw--;
	int start = ch * w + cw,end = dh * w + dw;
	bord.resize(h,vector<char>(w));
	graph.resize(h*w);
	n = h*w;
	for(int i{0};i < h;i++)for(int j{0};j < w;j++)cin >> bord[i][j];
	for(int i{0};i < h;i++){
		for(int j{0};j < w;j++){
			solve(i,j);
		}
	}
	//for(int i{0};i < n;i++){
		//debug(i);
		//for(auto x : graph[i])cout <<(x.first) << endl;
	//}
	dijkstra(start);
	ll ans;
	if(dist[end] == 1e18)ans = -1;
	else ans = dist[end] / 1000000;
	cout << ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 299380
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){

    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;
    if (U == S) cout << A-1 << ' ' << B << endl;
    else cout << A << ' ' << B-1 << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <map>
#define pb push_back
using namespace std;
int n,k,a[200005];
int64_t ans;
int main(){
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;++i) scanf("%d",&a[i]),a[i]=(a[i-1]+a[i])%k;
    map<int,int> d;
    ++d[0];
    for (int i=1,j=0;i<=n;++i){
        if (i-j>=k) --d[a[j++]];
        a[i]=(a[i]-i)%k;
        if (a[i]<0) a[i]+=k;
        ans+=d[a[i]];
        ++d[a[i]];
    }
    printf("%lld",ans);
}


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

int main()
{
string s , t ;
cin >> s >> t ;
ll q ;
cin >> q ;
vector<ll> sa(1),sb(1),ta(1),tb(1);
rep(i,s.size()){
  if(s[i]=='A')sa.push_back(sa.back()+1);
  else sa.push_back(sa.back());
  if(s[i]=='B')sb.push_back(sb.back()+1);
  else sb.push_back(sb.back());
  if(t[i]=='A')ta.push_back(ta.back()+1);
  else ta.push_back(ta.back());
  if(t[i]=='B')tb.push_back(tb.back()+1);
  else tb.push_back(tb.back());
}
vector<bool> ans;
rep(i,q){
  ll a , b , c , d ;
  cin >> a >> b >> c >> d ;
  ll numa=sa[b]-sa[a-1];
  ll numb=sb[b]-sb[a-1];
  ll numaa=ta[d]-ta[c-1];
  ll numbb=tb[d]-tb[c-1];
  if((numa+numb*2)%3==(numaa+numbb*2)%3) ans.push_back(true);
  else ans.push_back(false);
}
for(auto an:ans){
  if(an) cout << "YES" << endl;
  else cout << "NO" << endl;
}

return 0;
}

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

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;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  int N,A,B,C;
  cin>>N>>A>>B>>C;
  vector<int> ban(N);
  rep(i,N) cin>>ban[i];
  int ans = INF;
  for(int i = 0; i < (1<<(2*N));i++){
    bitset<20> bi(i);
    vector<int> v(N);
    int cnt=0;
    for(int j = 0; j < N; j++){
      if(bi.test(2*j)&&bi.test(2*j+1)) v[j]=0;
      if(!bi.test(2*j)&&bi.test(2*j+1)) v[j]=1;
      if(bi.test(2*j)&&!bi.test(2*j+1)) v[j]=2;
      if(!bi.test(2*j)&&!bi.test(2*j+1)) v[j]=3;
    }
    vector<vector<int>> vv(4);
    rep(j,N) {
      vv[v[j]].push_back(ban[j]);
    }
    if((int)vv[0].size()==0||(int)vv[1].size()==0||(int)vv[2].size()==0)continue;
    rep(j,3){
      cnt+=((int)vv[j].size()-1)*10;
      int s=0;
      for(auto x:vv[j]) s+=x;
      if(j==0)cnt+=abs(s-A);
      if(j==1)cnt+=abs(s-B);
      if(j==2)cnt+=abs(s-C);
    }
    chmin(ans,cnt);
  }
  cout<<ans<<endl;
}

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

int main(){
	int N;
	cin >> N;
	string ans="";
	char s;
	while(N){
		s='0'+abs(N)%2;
	
		ans=s+ans;
		N=(N-abs(N)%2)/(-2);
	}
	cout << (ans.empty()?"0":ans) <<endl;
    return 0;

}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,K = MI()
	A = LI();A.sort();
	F = LI();F.sort(reverse=True);
	upper_X = -1
	for i in range(N):
		upper_X = max(A[i]*F[i], upper_X)


	def BinarySearch(upper_X, lower_X):
		X = upper_X//2 
		candidate = upper_X
		while upper_X > lower_X:
			deduct = 0
			for i in range(N):
				n = A[i]-X//F[i]
				deduct += n if n>=1 else 0
			if(K < deduct):
				lower_X = X
				if(upper_X - lower_X) <= 1: break
			else:
				candidate = X
				upper_X = X
			X = (lower_X+upper_X)//2
		return candidate

	print(BinarySearch(upper_X,0))


main()

Measured memory_bytes: 107212
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int N, P, a[50];

int main(void) {
  while(cin >> N >> P, N && P) {
    REP(i, 0, N) a[i] = 0;

    for(int i = 0; true; i = (i + 1) % N) {
      if(P == 0) {
        P = a[i];
        a[i] = 0;
      } else {
        P--;
        a[i]++;
        if(P == 0) {
          bool fin = true;
          REP(j, 0, N) if(j != i && a[j] != 0) fin = false;
          if(fin) {
            cout << i << endl;
            break;
          }
        }
      }
    }
  }

  return 0;
}

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

using namespace std;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << min(a, b) + min(c, d);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
//typedef pair<int, int> P;

#define INF 1e+14
#define MAX_V 100000

struct edge {
	int to;
	ll cost;
	//edge e ={to,cost}
};

// <最短距離, 頂点の番号>
using P = pair<ll, ll>;

int V;// 頂点の数
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s) {
	//sからiへの最短距離をd[i]に保存 i=e.to
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + V, INF);
	d[s] = 0;//初期位置へのコストは0

	que.push(P(0, s));
	//queはmake_pair(cost,to)?

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;//v=e.to	from s to v
		//すでにこの経路よりいい経路が見つかっているなら無視
		if (d[v] < p.first) continue;
		

		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			// i 番目の v と v'を結ぶ辺　G=<e.to, e.cost>
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				//from s to v'> from s to v + from v to v'
				//vを経由したほうがコストが低いなら経由する
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
int main() {
	cin >> V;
	int E;//辺の数
    E=V-1;
	for (int i = 0; i < E; ++i) {
		int a, b, c;
		cin >> a >> b>>c ;
		a--; b--;
		//the route a to b costs c
		edge e = { b, c };
        edge e1={a,c};
        G[b].push_back(e1);
		G[a].push_back(e);
		//a
	}
	//dijkstra(int n); nからの最短距離を計算
	//d[i]はnからiまでの最短距離が保存される the path from n to i costs d[i]
    int q,k;
    cin>>q>>k;
    dijkstra(k-1);
    rep(i,q){
        int x,y;
        cin>>x>>y;
        x--;y--;
        ll ans=d[x]+d[y];
        cout<<ans<<endl;
    }

}



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


int main()
{
  int x, n;
  cin >> x >> n;
  set<int> s;
  rep(i, n)
  {
    int p;
    cin >> p;
    s.insert(p);
  }
  int i = 0;
  while (true)
  {
    if (!s.count(x-i))
    {
      cout << x - i << endl;
      return 0;
    }
    if (!s.count(x+i))
    {
      cout << x + i << endl;
      return 0;
    }
    i++;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main()
{
	unsigned int n;
	scanf("%d",&n);

	unsigned int a[n+2];
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	int cnt=0;

	int i,j;
	int ans[n+1];

	for(int i=0;i<=n;i++){
		ans[i] = i+1;
	}

	j = 0;
	for(i=0;i<n;i++){
		if(a[i] == ans[j]){
			j++;
		}		
	}

	if(j){
		j = n - j;
		printf("%d",j);
	}
	else{
		printf("-1");
	}

	return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <tuple>
#include <queue>
#include <deque>
using namespace std;
using ll=long long;
#define INF 2100000000

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }
  set<int> s;
  for(int i=0;i<K;i++){
    s.insert(P.at(i));
  }

  int ans=1;
  for(int i=0;i<N-K;i++){
    int m=*begin(s);
    s.erase(P.at(i));
    s.insert(P.at(i+K));
    int M=*rbegin(s);
    if(m==P.at(i)&&M==P.at(i+K)){
      continue;
    }
    ans++;
  }

  int num=1;
  int count=0;
  for(int i=1;i<N;i++){
    if(P.at(i)>P.at(i-1)){
      num++;
    }else{
      if(num>=K){
        count++;
      }
      num=1;
    }
  }
  if(num>=K){
    count++;
  }
  ans-=max(0,count-1);

  cout<<ans<<endl;
}


Measured memory_bytes: 10368
#include <stdio.h>

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

void bubbleSort(int arr[], int n)
{
   int i, j;
   for (i = 0; i < n-1; i++)      
       for (j = 0; j < n-i-1; j++) 
           if (arr[j] > arr[j+1])
              swap(&arr[j], &arr[j+1]);
}

int main(void)
{
    int n;
    scanf("%d", &n);

    int d[n];
    int i;
    for (i = 0; i < n; i++)
        scanf("%d", &d[i]);
    
    bubbleSort(d, n);

    int c = 1;
    for (i = 0; i < n - 1; i++) {
        if (d[i] < d[i + 1])
            c++;
    }

    printf("%d\n", c);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <utility>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	ll ans = n - k + 1;
	vector<bool> cx(n), cy(n);
	priority_queue<P> pq;
	for (int i = 0; i < k; i++) pq.push(P(a[i], i));
	for (int i = k; i < n; i++) {
		P p = pq.top();
		while (p.second < i - k) {
			pq.pop();
			p = pq.top();
		}
		if (p.first < a[i]) cx[i] = true;
		pq.push(P(a[i], i));
	}
	priority_queue<P> pq2;
	for (int i = n - 1; i >= n - k; i--) pq2.push(P(-a[i], i));
	for (int i = n - k - 1; i >= 0; i--) {
		P p = pq2.top();
		while (p.second > i + k) {
			pq2.pop();
			p = pq2.top();
		}
		if (a[i] < -p.first) cy[i] = true;
		pq2.push(P(-a[i], i));
	}
	for (int i = 0; i < n-k; i++) {
		if (cx[i + k] && cy[i]) ans--;
	}
	ll same = 0;
	ll cnt = 1;
	vector<int> check;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] < a[i + 1]) cnt++;
		else {
			check.push_back(cnt);
			cnt = 1;
		}
	}
	check.push_back(cnt);
	for (auto s:check) {
		if (s >= k) {
			same++;
		}
	}
	if (same >= 1) ans -= (same - 1);
	cout << ans << endl;
}

Measured memory_bytes: 13164
// A.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int x, a, b;
	cin >> x >> a >> b;
	int ans = (x - a) % b;
	cout << ans << endl;
cout << endl;
	return 0;
}


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

int main() {
	while (cin >> n) {
		if(!n)break;
		int data[n + 1][n + 1];
		for (int i = 0; i < n; ++i) {
			int tmp=0, sum=0;
			for (int j = 0; j < n; ++j) {
				cin >> tmp;
				data[i][j] = tmp;
				sum += tmp;
			}
			data[i][n] = sum;
		}int sump=0;
		for (int i = 0; i < n; ++i) {
			int summ = 0;
			for (int j = 0; j < n; ++j) {
				summ += data[j][i];
			}
			data[n][i] = summ;
			sump+=summ;
		}data[n][n]=sump;
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				//cout << " " << data[i][j];
				printf("%5d",data[i][j]);
			}
			cout<<endl;
			//printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int n, a, min, ans;

	n = in()-2;
	min = in(), a = in();
	ans = a-min;
	if (a < min) min = a;
	while (n--) {
		a = in();
		if (a < min) min = a;
		else if (a-min > ans) ans = a-min;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 2112
#include<stdio.h>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
int a[1001][1001];
int main(){
    int i,j,n,x1,x2,y1,y2,x1_min=1000,y1_min=1000,x2_max=0,y2_max=0,count=0;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d%d%d",&x1, &y1, &x2, &y2);
        a[x1][y1]++,a[x1][y2]--;a[x2][y1]--,a[x2][y2]++;
        x1_min=min(x1,x1_min),x2_max=max(x2,x2_max),y1_min=min(y1,y1_min),y2_max=max(y2,y2_max);
    }
    for(i=x1_min;i<=x2_max;i++)for(j=y1_min;j<=y2_max;j++){
        if(i)a[i][j]+=a[i-1][j];
        if(j)a[i][j]+=a[i][j-1];
        if(i&&j)a[i][j]-=a[i-1][j-1];
        count=max(count,a[i][j]);
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 4512
#include <iostream>

using namespace std;

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

	int i, min=1000, num=0;
	int m[n];

	for(i=0; i<n; i++)
	{
		cin >> m[i];
		x = x - m[i];
		num++;
		if(min > m[i]) min = m[i];
	}

	for(i=0; x>-1; i++)
	{
		x = x - min;
		num++;
	}

	num--;
	cout << num << endl;

	return 0;
}

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

signed main(){
    string s; cin>>s;
    int a=stoi(s.substr(0,4)),b=stoi(s.substr(5,2)),c=stoi(s.substr(8,2));
    if(a<=2018) cout<<"Heisei"<<endl;
    else if(b<=4) cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;
}

Measured memory_bytes: 256