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

int main()
{
    int A,B,i,count=0,len,n;
    string temp,temp2;
    cin>>A>>B;
    for(i=A; i<=B; i++)
    {
        temp=to_string(i);
        temp2=temp;
        len=temp2.length();
        n=len-1;
        for(int i=0; i<(len/2); i++)
        {

            swap(temp2[i],temp2[n]);
            n = n-1;

        }
       if(temp==temp2)
       {
           count++;
       }
    }
    cout<<count<<endl;

}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, a[200], min = INT_MAX;
	cin >> n;
	REP(i, n) cin >> a[i];
	REP(i, n){
		int beki = 0;
		while(a[i] % 2 == 0){
			beki++;
			a[i] /= 2;
		}
		if(beki < min) min = beki;
	}
	cout << min << endl;

	rtn 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int* x = new int[n];
	for (int i = 0; i <= n - 1; i++) {
		x[i] = 0;
	}
	int a;
	for (int j = 1; j <= n - 1; j++) {
		cin >> a;
		x[a - 1]++;
	}
	for (int k = 0; k <= n - 1; k++) {
		cout << x[k] << endl;
	}
}

Measured memory_bytes: 4376
N = int(input())
S = input()
a = 0
for i in range(1,len(S)):
    if S[i] == 'E':
        a += 1
ans = a
for i in range(1,len(S)):
    if S[i] == 'E':
        a -= 1
    if S[i-1] == 'W':
        a += 1
    if a < ans:
        ans = a
print(ans)

Measured memory_bytes: 3672
#![allow(unused_imports)]
#![allow(dead_code)]

mod reader {
    use std;

    macro_rules! read_line((  ) => {
                           {
                           let mut input = String :: new (  ) ; std :: io ::
                           stdin (  ) . read_line ( & mut input ) . unwrap (
                           ) ; input } } ;);

    pub fn read_and_parse<T: std::str::FromStr>() -> T {
        read_line!().trim().parse().ok().unwrap()
    }
}

use reader::*;

fn main() {
    let a: i32 = read_and_parse();
    let _: i32 = read_and_parse();
    let _: i32 = read_and_parse();
    let _: i32 = read_and_parse();
    let e: i32 = read_and_parse();
    let k: i32 = read_and_parse();

    println!("{}" , if e - a <= k { "Yay!" } else { ":(" });
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;


int main() {
	int N;
	int tmp;
	int d[100];
	int idx = 0;
	int flag;
	scanf("%d", &N);
	REP(i, N) {
		flag = 1;
		scanf("%d", &tmp);
		REP(j, idx) {
			if (tmp == d[j]) {
				flag = 0;
				break;
			}
		}
		if (flag) {
			d[idx++] = tmp;
		}
	}
	PRINTD(idx);
}

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

int main(){
  long long int n,ans=0;
cin >>n;

for(long long int i=1;i<=pow(n,0.5);i++){
if((n-i)%i==0 && (n-i)>i*i)ans+=(n-i)/i;
}
cout <<ans <<endl;
}


Measured memory_bytes: 384
n=int(input())
a=[int(i) for i in input().split()]

total=sum(a)

count=[0]*(10**5+1)

for i in a:
    count[i]+=1

q=int(input())
for i in range(q):
    b,c=[int(i) for i in input().split()]
    total+=(c-b)*count[b]
    count[c]+=count[b]
    count[b] = 0
    print(total)

Measured memory_bytes: 20452
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

bool isPrime[10000001];

int main(){

	fill((bool*)isPrime,(bool*)isPrime+10000001,true);
	isPrime[0] = isPrime[1] = false;
	
	for(int i=2;i*i<=10000000;i++){
		if(isPrime[i]){
			for(int j=i+i;j<=10000000;j+=i){
				isPrime[j] = false;
			}
		}
	}

	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		int res=-1;
		for(int i=n;i>=13;i--){
			if(isPrime[i] && isPrime[i-2]
			&& isPrime[i-6] && isPrime[i-8]){
				res = i;
				break;
			}
		}

		printf("%d\n",res);

	}
}

Measured memory_bytes: 10000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main(){
  int h,w;cin>>h>>w;
  char picture[h][w];
  REP(i,h){
    REP(j,w){
      cin>>picture[i][j];
      cout<<picture[i][j];
      if (j==w-1)
      {cout<<endl;
        REP(k,w){
      cout<<picture[i][k];
      }
      cout<<endl;

      }
      
    }
  }
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mod 1000000007
#define mod1 998244353
#define N 100003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::floatfield );std::cout.precision(15)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
/*vbool isprime(N,true);
vll spf(N,0);
vll prime;
void sieve()
{
    isprime[0] = isprime[1] = false;
    for(ll i = 2 ; i<N ; i++)
    {
        if(isprime[i])
        {
            for(ll j=2*i ; j<N ; j+=i)
            {
                isprime[j] = false;
                if(spf[j]==0)
                {
                    spf[j] = i;
                }
            }
            prime.pb(i);
        }
    }
}*/
ll nck(ll n , ll k ,ll m=1e18+7)
{
    ll i , j,b=1,c=1 ;
    if(n-k<k)
    {
        k = n-k ;
    }
    while(k)
    {
        b*=n ;
        c*=k ;
        ll g = __gcd(b,c) ;
        b/=g ;
        c/=g ;
        n--;
        k-- ;
    }
    return(b) ;
}
long long power(long long k , long long n , long long m=mod)
{
    long long res = 1;
    while(n)
    {
        if(n%2!=0)
        {
            res = (res*k)%m ;
        }
        k = (k*k)%m ;
        n = n/2 ;
    }
    return(res) ;
}
void READ(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cin>>a ;
        v.pb(a) ;
    }
}
void PRINT(vll &v , ll a = 0)
{
    //ll a ;
    for(ll i=a ; i<v.size() ; i=i+1)
    {
        v[i] = max((ll)0,v[i]);
        cout<<v[i]<<" " ;
    }
    cout<<"\n" ;
}
ll n,m,k;
bool ok = true;
int main()
{
    FastIO ;
    PRECISION ;
    ll a,b,c,d,e,i,j,t,x,y,z,x1,y1,z1,f;
    //double p,q,r,u,w ;
    char ch,chr ;
    //string str,st,str2,str3;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    cin>>n>>k;
    vll v(n+1,0);
    x = 0;
    for(i=k ; i<=n+1 ; i++)
    {
        c = i*(i-1)/2;
        d = i*n - c;
        //y = (d*(d+1))/2 - (c*(c-1))/2;
        y = d-c+1;
        x = (x%mod + y%mod)%mod;
    }
    cout<<x;
}

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

int main(){
    int n;
    cin >> n;
    string s[n];
    int p[n];
    for(int i = 0; i < n; i++){
        cin >> s[i] >> p[i];
    }
    vector<pair<int, int>> ans(n);
    for(int i = 0; i < n; i++){
        int cnt = 0;
        int rank = 5;
        for(int j = 0; j < n; j++){
            if(i != j && s[i] < s[j]){
                cnt++;
            }else if(i != j && s[i] == s[j] && p[i] > p[j]){
                cnt++;
            }
        }
        // cout << cnt << endl;
        ans[i] = make_pair(cnt,i+1);
    }
    sort(ans.begin(), ans.end(), greater<>());
    for(int i = 0; i < n; i++) cout << ans[i].second << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back

using namespace std;

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

const int MAXN = 2e5 + 10;

int n, a, b, c, d;
string s;

int main(){
	cin >> n >> a >> b >> c >> d;
	cin >> s;
	s = "!" + s;
	
	if(c < d){
		while(b < d){
			if(s[b+1] == '.') b++;
			else if(s[b+2] == '.') b+=2;
			else break;
		}

		while(a < c){
			if(s[a+1] == '.') a++;
			else if(s[a+2] == '.') a+=2;
			else break;
		}
	} else {
		int cu = 0;
		bool can = 0;
		for(int i=b-1; i<=d+1; i++){
			if(s[i] == '#') cu = 0;	
			else {
				cu++;
				if(cu == 3) can = true;
			}
		}

		if(can){
			while(b < d){
				if(s[b+1] == '.') b++;
				else if(s[b+2] == '.') b+=2;
				else break;
			}

			while(a < c){
				if(s[a+1] == '.') a++;
				else if(s[a+2] == '.') a+=2;
				else break;
			}
		}
	}

	if(a == c && b == d){
		cout << "Yes" << endl;
	} else
		cout << "No" << endl;
}


Measured memory_bytes: 772
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int N, M;
    long long total = 0, border = 0;
    bool ans = true;
    cin >> N >> M;
    vector<long long> A(N);
    for(int i = 0; i < N; ++i)
    {
        cin >> A.at(i);
        total += A.at(i);
    }
    if(total % (4 * M) == 0) border = total / (4 * M);
    else border = total / (4 * M) + 1;
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    for(int i = 0; i < M; ++i)
    {
        if(A.at(i) >= border) ans = true;
        else ans = false;
    }
    if(ans == true) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var str = Console.ReadLine().ToArray();
            var rCnt = str.Count(c => c == 'R');

            var tmp = 0;
            var result = 0;
            for (var i = 0; i < n; i++)
            {
                if (str[i] == 'R')
                {
                    if (tmp + 1 <= rCnt)
                    {
                        result += tmp;
                        rCnt -= tmp + 1;
                        tmp = 0;
                    }
                    else
                    {
                        result += rCnt;
                        break;
                    }
                }
                else
                {
                    tmp++;
                }
            }
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 29508
from heapq import *

def find(x):
    parent = data[x]
    if parent < 0: return x
    root = find(parent)
    data[x] = root
    return root

def union(x, y):
    root, second = find(x), find(y)
    if root == second: return False
    if height[root] < data[second]:
        second, root = root, second
    data[root] += data[second]
    height[root] = max(height[root], height[second]+1)
    data[second] = root
    return True

N = int(input())
X = [(0,0)] * N
Y = [(0,0)] * N
E = [(0,0)] * N

for i in range(N):
    x, y = map(int, input().split())
    X[i] = (x, i)
    Y[i] = (y, i)

X.sort()
Y.sort()
H = []

for i in range(N - 1):
    x1, j1 = X[i]
    x2, j2 = X[i + 1]
    y1, k1 = Y[i]
    y2, k2 = Y[i + 1]
    # ヒープ構造を用いて常にHの最初に最小値を持ってくる
    # X座標とY座標でそれぞれHに追加
    heappush(H, (x2 - x1, j1, j2))
    heappush(H, (y2 - y1, k1, k2))

answer = 0
data = [-1] * (N+1)  # 1-indexed rootには-sizeが入る
height = [0] * (N+1)

while H:
    w, s, t = heappop(H)
    # sとtの集合が異なっていた時、道を作る
    if union(s, t):
        answer += w

print(answer)


Measured memory_bytes: 51880
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int D;
    cin >> D;
    cout << "Christmas";
    REP(i, 25 - D) cout << " Eve";
    cout << endl;
    return 0;
}

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

int main(){
  long long N;
  cin >> N;
  vector<long long> A(N,0),B(N,0);
  for(int i=0;i<N;i++){
    string a;
    cin >> a;
    
    long long dot = a.size()-1;
    for(int j=0;j<a.size();j++){
      if(a[j]=='.') dot = j;
    }
    B[i] = pow(10,a.size() - dot - 1);
    for(int j=a.size()-1;j>=0;j--){
      if(j>dot || dot==a.size()-1) A[i] += (a[j] - '0') * pow(10,a.size()-j-1);
      else if(j<dot) A[i] += (a[j] - '0') * pow(10,a.size()-j-2);
    }
    
    long long g = gcd(A[i],B[i]);
    A[i] /= g;
    B[i] /= g;
  }
  
  vector<pair<long long,long long>> A2(N);
  vector<long long> V(10000,0);
  for(int i=0;i<N;i++){
    long long an2=0,bn2=0,an5=0,bn5=0;
    while(A[i]%2==0 && an2<9){
      A[i] /= 2;
      an2++;
    }
    while(A[i]%5==0 && an5<9){
      A[i] /= 5;
      an5++;
    }
    while(B[i]%2==0 && bn2<9){
      B[i] /= 2;
      bn2++;
    }
    while(B[i]%5==0 && bn5<9){
      B[i] /= 5;
      bn5++;
    }
    
    long long k = an2*1000 + an5*100 + bn2*10 + bn5;
    V[k]++;
  }
  
  long long ans=0;
  for(int i=0;i<10000;i++){
    long long an2_i = i/1000,
              an5_i = (i%1000)/100,
              bn2_i = (i%100)/10,
              bn5_i = i%10;
    for(int j=i;j<10000;j++){
      long long an2_j = j/1000,
                an5_j = (j%1000)/100,
                bn2_j = (j%100)/10,
                bn5_j = j%10;
      
      if(an2_i>=bn2_j && an5_i>=bn5_j){
        if(an2_j>=bn2_i && an5_j>=bn5_i){
          if(i==j) ans += (V[i] * (V[i]-1))/2;
          else ans += V[i] * V[j];
        }
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10064
#include <bits/stdc++.h>
using namespace std;
int INF = 1000;
int main(){
  int tests = 0;
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    if (tests > 0){
      cout << endl;
    }
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int A, B, C, D;
    int M = INF;
    for (int i = 0; i <= a; i++){
      for (int j = 0; j <= b; j++){
        for (int k = 0; k <= c; k++){
          for (int l = 0; l <= d; l++){
            int sum = i * 10 + j * 50 + k * 100 + l * 500;
            if (sum >= N){
              int a2 = a - i;
              int b2 = b - j;
              int c2 = c - k;
              int d2 = d - l;
              int r = sum - N;
              d2 += r / 500;
              r %= 500;
              c2 += r / 100;
              r %= 100;
              b2 += r / 50;
              r %= 50;
              a2 += r / 10;
              if (M > a2 + b2 + c2 + d2){
                M = a2 + b2 + c2 + d2;
                A = i;
                B = j;
                C = k;
                D = l;
              }
            }
          }
        }
      }
    }
    if (A > 0){
      cout << 10 << ' ' << A << endl;
    }
    if (B > 0){
      cout << 50 << ' ' << B << endl;
    }
    if (C > 0){
      cout << 100 << ' ' << C << endl;
    }
    if (D > 0){
      cout << 500 << ' ' << D << endl;
    }
    tests++;
  }
}


Measured memory_bytes: 3004
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
	int a = 1;
	for (int b = 1; b <= 9&&a<=9; b++)
	{
		cout << a << "x" << b << "=" << a*b << endl;
		if (b == 9)
		{
			b = 0;
			a++;
		}
	}
	

	return 0;
}

Measured memory_bytes: 1116
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int k[100];
	char s[101];
	while (n != 0) {
		for (int i = 0; i < n; i++) cin >> k[i];
		cin >> s;
		int j = 0;
		for (int i = 0; s[i] != '\0'; i++) {
			if (s[i] >= 'a') s[i] -= 6;
			s[i] -= k[j];
			if (s[i] < 'A') s[i] += 52;
			j++;
			if (j == n) j = 0;
		}
		for (int i = 0; s[i] != '\0'; i++) {
			if (s[i] > 'Z') s[i] += 6;
		}
		
		cout << s << endl;
	cin >> n;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
int rec(int,int);
#define MAX 200
int A[MAX],B[MAX],n,count=0;

int main(void){
  int i,j,k,l;

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

  scanf("%d",&j);
  for(k=0;k<j;k++){
    scanf("%d",&B[k]);

  }

  for(l=0;l<j;l++){
    rec(0,B[l]);
      if(count == 1){
	printf("yes\n");

      }

      else{
      printf("no\n");
    }
      count = 0;

  }



  return 0;




}


int rec(int a,int b){
 

  if (b == 0){
    count=1;
    return 1;

  } 

  else if(a < n){
  
    rec(a+1,b-A[a]);
    rec(a+1,b);
  }
  return 0;

 
}

Measured memory_bytes: 580
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a||b){
    vector<string>in(a);
    vector<int>in1(a);
    vector<int>in2(a);
    rep(i,a)cin>>in[i]>>in1[i]>>in2[i];
    rep(q,b){
      int n;
      cin>>n;
      bool h=false;
      rep(i,a){
	if(in2[i]-in1[i]<n&&n<=in2[i]){
	  h=true;
	  cout<<in[i]<<" "<<n-in2[i]+in1[i]<<endl;
	  break;
	}
      }
      if(!h)cout<<"Unknown"<<endl;
    }
  }
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

int main(){
    int n, m, total = 0;
    int Left = 0, Right = 0;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int L, R;
        cin >> L >> R;
        if(i == 0){
            Left = L; Right = R;
        }
        if(Left > R || Right < L){//区间无交集
            total = 0;
            Right = -1;//一次不符合，就没有通过的
        }
        else{
            Left = max(L, Left);
            Right = min(Right, R);
        }
        //cout << Left << ' ' << Right << endl;
    }
    if(Right == -1){
        cout << 0;
    }
    else{
        cout << Right - Left + 1;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	ios::sync_with_stdio(false);
	int k, a, b;
	cin >> k >> a >> b;
	rep2(i, a, b + 1) {
		if (i%k == 0) {
			cout << "OK"; return 0;
		}
	}
	cout << "NG";
}

Measured memory_bytes: 3616
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

const ll inf = 1e18;

int A, B, Q;
ll s[100000];
ll t[100000];

ll g(ll si, ll ti, ll x){
  ll res = inf;
  rep(ds, -1, 1){
    rep(dt, -1, 1){
      int sii = si + ds;
      int tii = ti + dt;
      if(sii >= A) continue;
      if(tii >= B) continue;
      if(sii < 0) continue;
      if(tii < 0) continue;
      ll sx = s[sii];
      ll tx = t[tii];
      res = min(res, abs(sx - tx) + min(abs(x - sx), abs(x - tx)));
    }
  }
  return res;
}

ll f(ll x){
  ll si, ti;
  {
    ll ng = 0;
    ll ok = A - 1;
    while(abs(ok - ng) > 1){
      ll md = (ok + ng) / 2;
      (s[md] >= x ? ok : ng) = md;
    }
    si = ok;
  }
  {
    ll ng = 0;
    ll ok = B - 1;
    while(abs(ok - ng) > 1){
      ll md = (ok + ng) / 2;
      (t[md] >= x ? ok : ng) = md;
    }
    ti = ok;
  }
  return g(si, ti, x);
}

int main(){
  cin >> A >> B >> Q;
  rep(i, A) cin >> s[i];
  rep(i, B) cin >> t[i];
  rep(i, Q){
    ll x;
    scanf("%lld", &x);
    printf("%lld\n", f(x));
  }
  return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=2e5+10;
vector<int>g[MAX];
ll sub[MAX],ans[MAX];
void dfs(int u,int par)
{
    ans[u]+=sub[u];
    for(int v:g[u])
    {
        if(v==par)continue;
        ans[v]+=ans[u];
        dfs(v,u);
    }
}
int main ()
{
    int N,u,v,Q;cin >> N >> Q;
    for(int i=1;i<=N-1;i++){
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    while(Q--)
    {
        int u,p;cin >> u >> p;
        sub[u]+=p;
    }
    dfs(1,0);
    for(int i=1;i<=N;i++)cout<<ans[i]<<" ";
    return 0;
}

Measured memory_bytes: 25600
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int a,b,c;
    bool ans = false;
    cin >> a >> b >> c;

    for (int i=1; i<=b; i++) {
        if (a*i % b == c) ans = true;
    }

    cout << (ans? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
 int main(){
	 int num=1;
	 while(1){
		 int tmp=0;
		 scanf("%d",&tmp);
		 if(tmp==0){
			 break;
		 }
		 printf("Case %d: %d\n",num,tmp);
		 num++;
	 }
	 return 0;
 }



Measured memory_bytes: 2712
# -*- coding: utf-8 -*-
import sys

N,Q=map(int, sys.stdin.readline().split())
s=raw_input()
q=[ sys.stdin.readline().split()  for i in range(Q) ]

def leftout(cur):
	for x,y in q:
		if s[cur]==x:
			if y=="L":
				cur-=1
			elif y=="R":
				cur+=1
		if cur<0:
			return True
			break
		elif cur>N-1:
			return False
			break			

	else:
		return False


def rightout(cur):
	for x,y in q:
		if s[cur]==x:
			if y=="L":
				cur-=1
			elif y=="R":
				cur+=1
		if cur>N-1:
			return True
			break
		if cur<0:
			return False
			break
	else:
		return False


l=-1
r=N
while r-l!=1:
	m=(l+r)/2
	if leftout(m):
		l=m
	else:
		r=m
sl=l

l=-1
r=N
while r-l!=1:
	m=(l+r)/2
	if rightout(m):
		r=m
	else:
		l=m

sr=r


ans=N
if sl>=0:
	ans-=(sl+1)
if sr<N:
	ans-=(N-sr)

print ans


Measured memory_bytes: 66588
n = int(input())
s = [input() for i in range(n)]
ruiseki = [[None] * (len(s[i]) + 1) for i in range(n)]

for i in range(n):
    ruiseki[i][0] = 0
    for j, char in enumerate(s[i]):
        if char == "(":
            ruiseki[i][j + 1] = ruiseki[i][j] + 1
        else:
            ruiseki[i][j + 1] = ruiseki[i][j] - 1


first = []
second = []
now_m = 0
now_s = 0
for i in range(n):
    min_, sum_ = min(ruiseki[i]), ruiseki[i][-1]
    if sum_ > 0:
        first.append((min_, sum_))
    else:
        second.append((min_, sum_))

now_m = 0
now_s = 0

first = sorted(first, reverse=True)
for mi, su in first:
    if now_s + mi < 0:
        print("No")
        exit()
    now_s += su

second = sorted(second, key=lambda x: x[0] - x[1])
for mi, su in second:
    if now_s + mi < 0:
        print("No")
        exit()
    now_s += su

if now_s == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 312808
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    string S;
    cin >> S;
    int N = S.length();
    ll mod = 2019;
    vector<int> res(N, 0);
    res[N - 1] = S[N - 1] - '0';
    ll power = 10;
    for (int i = N - 2; i >= 0; i--) {
        res[i] = (S[i] - '0') * power + res[i + 1];
        res[i] %= mod;
        power = (power * 10) % mod;
    }

    ll ans = 0;
    map<int, int> cnt;
    cnt[0]++;
    for (int i = N - 1; i >= 0; i--) {
        ans += cnt[res[i]];
        cnt[res[i]]++;
    }
    cout << ans << endl;
}


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

int main(){
	queue<long long int> numbers;
	for(int i = 1;i<10;i++){
		numbers.push(i);
	}
	long long int k,x = 1;
	cin >> k;
	while(k--){
		x = numbers.front();
		numbers.pop();
		if(x%10 != 0) numbers.push(10*x + x%10 -1);
		numbers.push(10*x + x%10);
		if(x%10 != 9) numbers.push(10*x + x%10 +1);
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int p[100010],q[100010],r[100010];
long long ans=0;
priority_queue <int,vector<int>,greater<int> > m;
bool cmp(int h,int g){
	return h>g;
}
int main(){
	int x,y,a,b,c;
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	for(int i=1;i<=a;i++){
		scanf("%d",&p[i]);
	}
	for(int i=1;i<=b;i++){
		scanf("%d",&q[i]);
	}
	for(int i=1;i<=c;i++){
		scanf("%d",&r[i]);
	}
	sort(p+1,p+1+a,cmp);
	sort(q+1,q+1+b,cmp);
	sort(r+1,r+1+c,cmp);
	for(int i=1;i<=x;i++){
		m.push(p[i]);
	}
	for(int j=1;j<=y;j++){
		m.push(q[j]);
	}
	for(int i=1;i<=c;i++){
		if(r[i]>m.top()){
			m.pop();
			m.push(r[i]);
		}
		else{
			break;
		}
	}
	while(!m.empty()){
		ans+=m.top();
		m.pop();
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2552
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <map>
using namespace std;

int main() {
    int a;
    int b;
    int c;

    map<int, int> mp;

    if (scanf("%d %d %d", &a, &b, &c) < 3) return 0;

    mp[a]++;
    mp[b]++;
    mp[c]++;

    printf("%d\n", mp.size());
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int a, b;
	int s;
	scanf("%d %d", &a, &b);
	s = a * b;

	if (s % 2 == 0) {
		printf("Even\n");
	}
	else
		printf("Odd\n");

	return 0;
}


Measured memory_bytes: 1648
n = gets.to_i
a = gets.split.map{|x| x.to_i}
h = n/2
es = Array.new(100001)
os = Array.new(100001)
for i in 0..100000
  es[i] = [0, i]
  os[i] = [0, i]
end
for i in 0...h
  es[a[2*i]][0] += 1
  os[a[2*i+1]][0] += 1
end

es.sort_by!{|x| -x[0]}
os.sort_by!{|x| -x[0]}

esuf1 = es[0][1]
emax1 = es[0][0]
osuf1 = os[0][1]
omax1 = os[0][0]
esuf2 = es[1][1]
emax2 = es[1][0]
osuf2 = os[1][1]
omax2 = os[1][0]

if esuf1 != osuf1
  print (n - emax1 - omax1)
else
  print (n - [omax1+emax2, omax2+emax1].max)
end


Measured memory_bytes: 20872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

const int DAT_SIZE=(1<<20)-1;

int datA[26][DAT_SIZE], datB[26][DAT_SIZE];

// [a,b)にxを加算する
// add(a,b,x,0,0,N+1);
void add(int a, int b, int x, int k, int l, int r,int c){
  if(a<=l && r<=b) datA[c][k]+=x;
  else if(l<b && a<r){
    datB[c][k]+=(min(b,r)-max(a,l))*x;
    add(a,b,x,k*2+1,l,(l+r)/2,c);
    add(a,b,x,k*2+2,(l+r)/2,r,c);
  }
}

// [a,b)の和を計算する
// sum(a,b,0,0,N+1)
ll sum(int a, int b, int k, int l, int r,int c){
  if(b<=l || r<=a) return 0;
  else if(a<=l && r<=b) return (datA[c][k]*(r-l)+datB[c][k]);
  else{
    ll res=(min(b,r)-max(a,l))*datA[c][k];
    res+=sum(a,b,k*2+1,l,(l+r)/2,c);
    res+=sum(a,b,k*2+2,(l+r)/2,r,c);
    return res;
  }
}


int main(){
  int N; cin>>N;
  string S; cin>>S;
  rep(i,N){
    int n=S[i]-'a';
    add(i,i+1,1,0,0,N+100,n);
  }
  int Q; cin>>Q;
  while(Q--){
    int x; cin>>x;
    if(x==1){
      int i;
      char c;
      cin>>i>>c; i--;
      if(S[i]==c) continue;
      int n1=S[i]-'a',n2=c-'a';
      add(i,i+1,-1,0,0,N+100,n1);
      add(i,i+1,1,0,0,N+100,n2);
      S[i]=c;
    }else{
      int l,r; cin>>l>>r; l--,r--;
      int ans=0;
      rep(i,26){
        ans+=(sum(l,r+1,0,0,N+100,i)!=0);
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 213892
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, K;
    cin >> n >> K;

    // n = 5000;
    // K = 5000;

    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    sort(all(a));

    // dp[i][j]: i個目まで使ったときの総和がjである場合
    vector<vector<char> > dp(n+1, vector<char>(K+1));
    dp[0][0] = 1;
    repi(i, n+1) {
        rep(j, K+1) {
            if (j-a[i-1] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i-1][j-a[i-1]]); //use
            }
            dp[i][j] = max(dp[i][j], dp[i-1][j]); //unuse
        }
    }

    vector<vector<char> > dpi(n+2, vector<char>(K+1));
    dpi[n+1][0] = 1;
    for (int i = n; i >= 0; i--) {
        rep(j, K+1) {
            if (j-a[i-1] >= 0) {
                dpi[i][j] = max(dpi[i][j], dpi[i+1][j-a[i-1]]); //use
            }
            dpi[i][j] = max(dpi[i][j], dpi[i+1][j]); //unuse
        }
    }


    ll res = 0;
    vector<ll> S(K+2);
    rep(i, n) {
        repi(j, K+2) {
            S[j] = S[j-1] + dpi[i+2][j-1];
        }
        bool necessary = false;
        rep(j, K+1) {
            if (0 == dp[i][j]) {
                continue;
            }
            ll sum = i - 1 >= 0 ? j + a[i] : a[i];
            if (sum > K) {
                necessary = true;
                break;
            }
            ll v1 = K - sum;
            ll v2 = K + a[i] - 1 - sum;
            ll cnt = S[v2+1] - S[v1];
            if (cnt > 0) {
                necessary = true;
                break;
            }
        }
        if (!necessary) {
            res++;
        }
    }
    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 52636
memo={}
def fib(n) :
    if n == 0 :
        return 1
    elif n == 1 :
        return 1
    else :
        if n-1 not in memo:
            memo[n-1] = fib(n-1)
        if n-2 not in memo:
            memo[n-2] = fib(n-2)
        return memo[n-1] + memo[n-2]
n = int(input())
print(fib(n))


Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define INF 999999999
using namespace std;

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

    if(n % 500 <= a) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

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

int main(){
	ll n, m;
	cin >> n >> m;
	vector<pair<ll, ll>> person(n);
	vector<pair<ll, ll>> point(m);
	vector<ll> ans(n);
	rep(i, n){
		ll temp_x, temp_y;
		cin >> temp_x >> temp_y;
		pair<ll, ll>temp;
		temp.first = temp_x;
		temp.second = temp_y;
		person[i] = temp;
	}
	rep(i, m){
		ll temp_x, temp_y;
		cin >> temp_x >> temp_y;
		pair<ll, ll>temp;
		temp.first = temp_x;
		temp.second = temp_y;
		point[i] = temp;
	}

	rep(i, n){
		ll distance = 1e10;
		rep(j, m){
			ll temp_distance = abs(person[i].first - point[j].first) + abs(person[i].second - point[j].second); 
			if(temp_distance < distance){
				distance = temp_distance;
				ans[i] = j+1;
			}
		}
	}
	rep(i, n){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n){
    int r = n%10;
    if(r == 7){
      cout<<"Yes"<<'\n';
      return 0;
    }
    n = n/10;
  }
  cout<<"No"<<'\n';
}

Measured memory_bytes: 3624
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int n,x,ans=0;
  cin>>n>>x;
  int time[300000];
  for(int i=0;i<n;i++){
    cin>>time[i];
  }
  for(int j=1;j<n;j++){
    int y;
    y=time[j]-time[j-1];
    if(y>=x)
      ans+=x;
    else
      ans+=y;
  }
  cout<<ans+x<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(){
	string ans,forecast;
	while(1){
		cin>>ans>>forecast;
		if(ans=="0" && forecast=="0")break;
		int hit,blow;
		hit=blow=0;
		for(int i=0 ; i<4 ; i++ ){
			for(int j=0 ; j<4 ; j++ ){
				if(ans[i]==forecast[j]){
					if(i==j)
						hit++;
					else
						blow++;
				}
			}
		}
		cout<<hit<<" "<<blow<<endl;
	}
}

Measured memory_bytes: 2968
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
while(cin>>n, n!=0){
int k=0;
vector<vector<int> >v(n, vector<int>(n));
for(int i=-n/2; i<=n/2; i++)
for(int j=0; j<n; j++)
v[(j-i+n)%n][(j+i+n)%n]=++k;
for(int i=0; i<n-1; i++){
for(int j=i+1; j<n; j++){
swap(v[i][j], v[j][i]);
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++)printf("%4d", v[i][j]);
cout<<"\n";			
}
}
return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100000];
long long int s[100000];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	sort(a,a+n);
	s[0]=a[0];
	for(int i=1;i<n;i++)s[i]=s[i-1]+a[i];
	int lim=-1;
	for(int i=0;i<n-1;i++){
		if(2*s[i]<a[i+1])lim=i;
	}
	printf("%d",n-lim-1);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define M 1000000007
#define INF 999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define MAX 1000005
#define fs first
#define sc second 
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;


int main()
{
// freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
 cin.tie(0);
 ll a,b;
 cin>>a>>b;
 cout<<(a-1)*(b-1)<<endl;
 


return 0;

}

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

using namespace std;

void paint(int, int, vector<vector<char>>&, queue<pair<int, int>>*);

int darken(vector<vector<char>> a){
  int turn = 0;
  
  int h = (int)a.size();
  int w = (int)a[0].size();
  
  queue<pair<int, int>> q;
  
  q.push(make_pair(-1, -1));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(a[i][j] == '#'){
        q.push(make_pair(i, j));
      }
    }
  }
  
  while(q.size() > 1){
    pair<int, int> p = q.front();
    q.pop();
    
    int i = p.first;
    int j = p.second;
    
    if(i == -1 && j == -1){
      turn++;
      q.push(p);
      continue;
    }
    
    paint(i + 1, j, a, &q);
    paint(i, j + 1, a, &q);
    paint(i - 1, j, a, &q);
    paint(i, j - 1, a, &q);
  }
  
  return max(turn - 1, 0);
}

void paint(int i, int j, vector<vector<char>> &a, queue<pair<int, int>> *q){
  int h = (int)a.size();
  int w = (int)a[0].size();
  
  if(i >= 0 && i < h && j >= 0 && j < w && a[i][j] == '.'){
    a[i][j] = '#';
    q->push(make_pair(i, j));
  }
}

int main(){
  int h, w;
  cin >> h >> w;
  
  vector<vector<char>> a(h, vector<char>(w));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> a[i][j];
    }
  }
  
  cout << darken(a) << endl;
  
  return 0;
}

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

using namespace std; 
  int main()
  {
  int n,k,m;
  cin>>n>>k;
  int a[n];
  int i,j;
  long long int M=1e9+7;
  for(i=0;i<n;i++)
  {
      cin>>a[i];
  }
  long long int dp[k+1][n],dp2[k+1][n];
  for(i=0;i<k+1;i++)
  {
      for(j=0;j<n;j++)
      {
          dp[i][j]=0;
      }
  }
  for(i=0;i<k+1;i++)
  {
      for(j=0;j<n;j++)
      {
          
              if(i==0)
              {
              dp[i][j]=1;
              dp2[i][j]=1;
              }
              else if(j==0&&i<=a[0])
              {
              dp[i][j]=1;
              dp2[i][j]=dp2[i-1][j]+1;
              }
              else if(j==0&&i>a[0])
              {
              dp[i][j]=0;
              dp2[i][j]=dp2[i-1][j];
              }
              else
              {
             
             
             
                  if(i-a[j]>0)
                  {
              dp[i][j]=dp2[i][j-1]-dp2[i-a[j]-1][j-1];
              if(dp[i][j]<0)
              dp[i][j]+=M;
              
                  }
              else
              dp[i][j]=dp2[i][j-1];
              dp2[i][j]=(dp2[i-1][j]+dp[i][j])%M;
              
          }
      }
  }
  //
  cout<<dp[k][n-1]<<endl;
  /*for(i=0;i<k+1;i++)
  {
      for(j=0;j<n;j++)
      {
          cout<<dp[i][j]<<" ";
      }
      cout<<endl;
  }*/
  
      return 0;
  }

Measured memory_bytes: 156544
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in); 
		int X = input.nextInt();
		int N = input.nextInt();
		int ans = Integer.MAX_VALUE;
		boolean[] vis = new boolean[1001];
		for (int i = 0; i < N; i++) {
			int num = input.nextInt();
			vis[num]=true;
		}
		for (int i = -1000; i <= 1000; i++) {
			if (i>=0&&!vis[i]) {
				if (Math.abs(i-X)<Math.abs(ans-X)) {
					ans=i;
				}else if (Math.abs(i-X)==Math.abs(ans-X)) ans=Math.min(i, ans);
			}else if (i<0) {
				if (Math.abs(i-X)<Math.abs(ans-X)) {
					ans=i;
				}else if (Math.abs(i-X)==Math.abs(ans-X)) ans=Math.min(i, ans);
			}
		}
		System.out.println(ans);
	}	
}


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

int main() {
	int N,M;
  	cin >> N >> M;
  
  	vector<int> num(N , 0);
  

  
  	for(int i = 0; i < M; i++) {
    	int a,b;
     	cin >> a >> b;
      	num.at(a - 1)++;
      	num.at(b - 1)++;
    }
  
  	for(int i = 0; i < N; i++) {
    	cout << num.at(i) << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;

int main(void){
  int i,n,s=0;
  int a[100000];

  scanf("%d",&n);

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

  sort(a,a+n);

  for(i=0;i<n;i++){
    if(a[i]==a[i+1]){
      i++;
    }
    else
      s++;
  }

  printf("%d\n",s);

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,len=0;
int a[1000005],b[1000005],c[1000005];

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i]>>b[i];
	for (int i=1;i<=n;i++)
	{
		if (a[i]==b[i])
		{
			len++;
			if (len>=3)  return cout<<"Yes"<<endl,0;
		}
		else len=0;
	}
	cout<<"No"<<endl; 
	return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    int n;
    while (cin >> n && n) {
        unordered_map<int, int> pos;
        vector<pair<int, ll>> res(4001);
        for (int i=1; i<=n; ++i) {
            int no;
            ll price, quantity;
            cin >> no >> price >> quantity;
            if ( ! pos[no]) {
                pos[no] = i;
                res[pos[no]].first = no;
            }
            res[pos[no]].second += price * quantity;
        }

        bool NA = true;
        for (int i=0; i<(int)res.size(); ++i) {
            if (res[i].second >= 1000000) {
                cout << res[i].first << endl;
                NA = false;
            }
        }
        if (NA)
            cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 1320
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

void solve() {
  string s;
  cin >> s >> s;
  while(true) {
    bool cont = false;
    int curr = 0;
    for(int i = 0; i < s.size(); i++) {
      if(s[i] == '(') curr++;
      else {
        if(--curr < 0) {
          s = "(" + s;
          cont = true;
          break;
        }
      }
    }
    if(cont) continue;
    if(curr > 0) {
      s += ")";
      continue;
    }
    break;
  }
  cout << s << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int W, N; cin >> W >> N;
  int a[31], b[31];
  for(int i=0;i<N;++i)
    scanf("%d,%d", &a[i], &b[i]);
  
  int x[31];
  for(int i=1;i<=W;++i){
    int n = i;
    for(int j=0;j<N;++j){
      if(n == a[j])
	n = b[j];
      else if(n == b[j])
	n = a[j];
    }
    x[n] = i;
  }
  for(int i=1;i<=W;++i)
    cout << x[i] << endl;

  return 0;
}

Measured memory_bytes: 1236
N = int(input())
s = [int(input()) for _ in range(N)]

t = sorted(s)
ans = sum(t)

if ans % 10 == 0:
    for i in range(N):
        if t[i] % 10 != 0:
            ans -= t[i]
            break
    else:
        ans = 0

print(ans)


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

using namespace std;

int main(){
    int64_t a;
    long double b;
    int64_t c;

    cin >> a >> b;
  
    if(a==0||b==0){
        cout << 0 << endl;
        return 0;
    }
  
    c = (int64_t)a*b;

  	cout << c << endl;

    return 0;
}

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

public class Main 
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int arr[] = new int[3];
		arr[0]=sc.nextInt();
		arr[1]=sc.nextInt();
		arr[2]=sc.nextInt();
		Arrays.sort(arr);
		int res;
		res=(arr[2]*10)+arr[0]+arr[1];
		System.out.println(res);
	}
}


Measured memory_bytes: 22868
#include<stdio.h>
int main(){
int a[4],b[4],c=0,d=0,i;
while(scanf("%d %d %d %d\n",&a[0],&a[1],&a[2],&a[3])!=EOF){
scanf("%d %d %d %d\n",&b[0],&b[1],&b[2],&b[3]);
for(i=0;i<4;i++){
if(a[i]==b[i]){
c++;
}
}
for(i=0;i<4;i++){
if(a[i]==b[1] || a[i]==b[2] || a[i]==b[3] || a[i]==b[0]){
d++;
}
}
printf("%d %d\n",c,d-c);
c=0;
d=0;
}
return 0;
}


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

using namespace std;
int main(){
    int n;
    cin >> n;
    int p[n];
    int sum=0,ans=0;
    for(int i=0; i<n; i++){
       cin >> p[i];
       sum = max(sum,p[i]);
       ans+=p[i];
    }
    ans=ans-sum/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3536
n, a, b = gets.split(" ").map(&:to_i)
sums = 0
for num in 0..n do
  remainder = num
  digit_sum = 0
  while(true) do
    digit_sum+= remainder % 10
    break if remainder < 10
    remainder = remainder / 10
  end
  sums+= num if digit_sum >= a && digit_sum <= b
end
puts sums

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, T;
  cin >> N >> T;
  int ans = 0;
  vint t(N);
  int prev = 0;
  rep(i, N) {
    cin >> t[i];
    ans += min(T, t[i]-prev);
    prev = t[i];
  }
  ans += T;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int d,e;
  while(cin>>d>>e,d){
    double ans=INF*1.0;
    for(int i=0;i<=d;i++){
      double tmp=pow(i*i+(d-i)*(d-i),0.5);
      ans=min(ans,abs(tmp-e));
    }
    printf("%f\n",ans);
  }
  return 0;
}



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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using ld = long double;

template <typename T>
int sz(T &x) {
  return (int)(x.size());
}


const int mod = 998244353;
const int inf = 1'000'000'007;

int power(int x, int y) {
  if (y == 0) {
    return 1;
  }
  int z = power(x, y >> 1);
  z = z * 1ll * z % mod;
  if (y & 1) {
    z = z * 1ll * x % mod;
  }
  return z;
}

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

  auto can = [&](int pos) {
    if (a[pos] + m < a[p - 1]) {
      return false;
    }
    if (pos < p) {
      return true;
    }
    ll f = (p - 1) * 1ll * m + (n - pos) * 1ll * m;
    for (int i = p - 1; i < pos; ++i) {
      f += a[pos] + m - a[i];
    }
    return f >= m * 1ll * v;
  };

  int ans = 0;
  for (int i = 30; i >= 0; --i) {
    if (ans + (1 << i) < n && can(ans + (1 << i))) {
      ans += (1 << i);
    }
  }
  cout << ans + 1 << "\n";
}

int main() {
  #ifndef LOCAL58
    // don't forget to remove if interactive
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
  #endif

  int t;
  t = 1;
  while(t--) {
    solve();
  }

  return 0;
}


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

int main() {

  int A, B;
  cin >> A >> B;


  int cnt = 0;
  for (int i=A; i<=B; i++) {
    string canditate = to_string(i);

    if ( (canditate.at(0) == canditate.at(4)) && (canditate.at(1) == canditate.at(3)) ) {
      cnt++;
    }
  }

  cout << cnt << endl;
}


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

typedef long long ll;

int main() {
	ll N, M;
	scanf("%lld%lld", &N, &M);
	if (N*2>M) {
		printf("%lld",M/2);
		return 0;
	}
	ll lol=M-N;
	lol*=2;
	lol-=M;
	lol/=4;
	N+=lol;
	printf("%lld",N);
}



Measured memory_bytes: 256