akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int N = inputVal<int>();
	outputVal(3* N*N);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}


Measured memory_bytes: 256
import os
import sys
from collections import deque
from collections import Counter
from heapq import heappop,heappush

def main():
	k = int(input())
	a,b = map(int, input().split())
	for i in range(b, a-1, -1):
		if i % k == 0:
			print("OK")
			sys.exit()
	print("NG")

if __name__ == "__main__":
	main()



Measured memory_bytes: 9456
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let mut cs = s.clone();
    cs = cs.chars().rev().collect();
    if s != cs {
        println!("No");
        return;
    }

    let mut cs_mae = String::new();
    let mut cs_ushiro = String::new();
    for (i, c) in s.chars().enumerate() {
        if i+1 <= (s.len()-1) / 2 {
            cs_mae = format!("{}{}", cs_mae, c);
        } else if (s.len()+3) / 2 <= i+1 {
            cs_ushiro = format!("{}{}", cs_ushiro, c);
        }
    }
    let cs_mae_rev: String = cs_mae.chars().rev().collect();
    if cs_mae != cs_mae_rev {
        println!("No");
        return;
    }
    let cs_ushiro_rev: String = cs_ushiro.chars().rev().collect();
    if cs_ushiro != cs_ushiro_rev {
        println!("No");
        return;
    }
    println!("Yes");
}


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

string toBinary(unsigned long long int n)
{
    string r;
    while(n!=0) {r=(n%2==0 ?"0":"1")+r; n/=2;}
    return r;
}
string generateOnes(int len){
    string result;
    for(int i=0;i<len;i++){
        result.append("1");
    }
    return result;
}

int main()
{
    unsigned long long int H;
    cin >> H;
    string binary = toBinary(H); //to binary
    string resultStr = generateOnes(binary.length());
    unsigned long long int result = 0 ;
    result = stoul(resultStr,0,2);
    
    cout << result << endl;
    
    return 0;
}

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

int n, m, q;
int ans = 0;
std::vector<int> a, b, c, d;

void dfs(std::vector<int> A){
	if(A.size() == n+1){
		int tmp = 0;
		for(int i=0; i<q; i++){
			if(A[b[i]] - A[a[i]] == c[i]){
				tmp += d[i];
			}
		}
		ans = std::max(ans, tmp);
		return;
	}

	A.push_back(A.back());
	while(A.back() <= m){
		dfs(A);
		A.back()++;
	}
}

int main(){
	std::cin >> n >> m >> q;
	a = b = c = d = std::vector<int>(q);
	for(int i=0; i<q; i++){
		std::cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	
	dfs(std::vector<int>(1,1));
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3588
N, M = map(int, input().split())
sc_list = []
for i in range(M):
    s, c = map(int, input().split())
    sc_list.append([s,c])
ans = ""
flag = 0
num_slot = ["X" for i in range(N)]
for lists in sc_list:
    if num_slot[lists[0]-1] != "X" and num_slot[lists[0]-1] != lists[1]:
        print(-1)
        flag = 1
        break
    else:
        num_slot[lists[0]-1] = lists[1]
if flag == 0:
    for i in range(N):
        if num_slot[i] != "X":
            ans += str(num_slot[i])
        else:
            if i == 0:
                ans += "1"
            else:
                ans += "0"
    if ans[0] == "0" and ans != "0":
        print(-1)
    elif N == 1 and M == 0:
        print(0)
    else:
        print(int(ans))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
using namespace std;


int main(){
    long long l, r;
    cin >> l >> r;
    int result = 2018;
    if (r - l >= 2019 - 1){
        result = 0;
    }
    else {
        l %= 2019;
        r %= 2019;
        if (r <= l){
            result = 0;
        }
        else {
            for (int t = l; t <= r; t++){
                for (int s = t + 1; s <= r; s++){
                    int tmp = (t * s) % 2019;
                    result = min(result, tmp);
                }
            }
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
--{-# LANGUAGE StandaloneDeriving #-}
--{-# LANGUAGE BangPatterns #-}

module Main where

import Debug.Trace
--import Data.List
--import Data.Char
--import qualified Data.Set.Strict as Set
--import qualified Data.Map.Strict as Map

main :: IO ()
main = do
  getLine
  a <- map read . words <$> getLine
  --a `traceShow`
  print $ solve a

solve :: [Int] -> Int
solve a = length . filter (\(i, ai) -> i `mod` 2 == 1 && ai `mod` 2 == 1) . zip [1..] $ a


Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mx = 1000+5,mod = 1e9+7;
int dp[mx][mx];
char a[mx][mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        cin>>a[i][j];
    dp[1][1]=1;
    for(int i=2;i<=n;i++)
    if(a[i][1]=='.')
        dp[i][1] = dp[i-1][1];
    for(int i=2;i<=n;i++)
    if(a[1][i]=='.')
        dp[1][i] = dp[1][i-1];

    for(int i=2;i<=n;i++)
        for(int j=2;j<=m;j++)
    {

         if(a[i][j]=='#')
            dp[i][j] = 0;
        else
            dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod;
    }
    cout<<dp[n][m]%mod<<endl;
    return 0;
}



Measured memory_bytes: 5120
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    static Scanner in;

    void solve() {
        String s = in.nextLine();
        Deque<Character> q = new ArrayDeque<>();
        for(char c:s.toCharArray()) {
            q.addLast(c);
        }
        int ans = 0;
        while(q.size() > 1) {
            char a = q.getFirst();
            char b = q.getLast();
            if(a == b) {
                q.removeFirst();
                q.removeLast();
            }else if(a == 'x') {
                q.addLast('x');
                ans++;
            }else if(b == 'x') {
                q.addFirst('x');
                ans++;
            }else{
                System.out.println("-1");
                return;
            }
        }
        System.out.println(ans);
    }

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


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

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

int main(){
    int h ,w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    int ans = 0;
    rep(is, 1<<h) rep(js, 1<<w){
        int cnt = 0;
        rep(i, h) rep(j ,w){
            if(is>>i & 1) continue;
            if(js>>j & 1) continue;
            if('#' == s[i][j]) ++cnt;
        }
        if(k == cnt) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<stack>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<string>
#include<cstring>
#include<sstream>
using namespace std;
 
const int LOOP_TIMES = 1e3;
const double EPS = 1e-6;
int L, N;
 
double Evaluate(int *r){
    double val = r[0] + r[N-1];
    for(int i = 0; i < N - 1; i++){
        int a = abs( r[i] - r[i+1] ), c = r[i] + r[i+1];
        val += sqrt(c*c - a*a);
    }
    return val;
}
 
bool IsChange(int cnt){
    return cnt < rand()%LOOP_TIMES + 1;
}
 
double Solve(int *r){
    double score = Evaluate(r), mi = score;
    for(int cnt = 0; cnt < LOOP_TIMES; cnt++){
        int *a = r + rand()%N, *b = r + rand()%N;
        swap(*a, *b);
 
        double next_score = Evaluate(r);
        if( score >= next_score && !IsChange(cnt) ) swap(*a, *b);
        else score = next_score;
         
        mi = min(mi, score);
    }
    return mi;
}
 
int main(){
    while(cin >> L){
        N = 0;
        int r[12];
        string S;
        getline(cin, S);
        stringstream SS(S);
        while( !SS.eof() ){
            SS >> r[N++];
        }
 
        double ans;
        if(N == 1) ans = r[0]*2;
        else ans = Solve(r);
 
        if(L - ans + EPS > 0) puts("OK");
        else puts("NA");
    }
    return 0;
}

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

const int MAX_N = 100005;

struct Sieve{
    ll n;
    vector<ll> f;
    Sieve(int n=1): n(n), f(n+1){
        f[0] = f[1] = -1;
        for(ll i=2;i<=n;i++){
            if(f[i]) continue;
            f[i] = i;
            for(ll j=i*i;j<=n;j+=i){
                if(!f[j]) f[j] = i;
            }
        }
    }

    bool isPrime(ll x){return f[x]==x;}

    //素因数分解
    vector<int> factorlist(int x){
        vector<int> primelist;
        int nx=x;
        while(nx!=1){
            primelist.push_back(f[nx]);  //xの素因数が小さい順に並ぶ
            nx /= f[nx];
        }
        
        return primelist;
    }

    vector<pair<int,int>> factornum(int x){
        vector<int> fl = factorlist(x);
        if(fl.size()==0) return {};
        vector<pair<int,int>> vec(1,make_pair(fl[0],0));
        for(int p : fl){
            if(vec.back().first==p){
                vec.back().second++;
            }else{
                vec.emplace_back(p,1);
            }
        }

        return vec;
    }


};

int main(void){
    Sieve S(MAX_N);
    vector<bool> islike(MAX_N,false);
    for(int i=0;i<MAX_N;i++){
        if(i%2==0) continue;
        if(S.isPrime(i) && S.isPrime((i+1)/2)) islike[i] = true;
    }
    vector<int> d(MAX_N,0);   //i<=xまでの似た数の個数
    for(int i=1;i<MAX_N;i++){
        d[i] = d[i-1];
        if(islike[i]) d[i]++;
    }

    int q;
    cin >> q;
    vector<int> ans(q);
    for(int i=0;i<q;i++){
        int l,r;
        cin >> l >> r;
        ans[i] = d[r] - d[l-1];
    }

    for(int i=0;i<q;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> l(n, 0);
    rep2(i,1,n+1){
        ll res = 0;
        while(i*pow(2, res) < k){
            res++;
        }
        l[i-1] = res;
    }
    ll sum = 0, num = n*pow(2, l[0]);
    rep1(i, n) sum += pow(2, l[0]-l[i]);
    double ans = (double)sum / (double)num;
    cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 4180
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<string> s(N);
    for(int i=0;i<N;i++){
        cin >> s[i];
    }
    int M; cin >> M;
    vector<string> t(M);
    for(int i=0;i<M;i++){
        cin >> t[i];
    }
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    int out=-INF;
    for(int i=0;i<N;i++){
        int tmp=1;
        for(int j=i+1;j<N;j++){
            if(s[i]==s[j]) tmp++;
        }
        for(int j=0;j<M;j++){
            if(s[i]==t[j]) tmp--;
        }
        if(tmp>out) out = tmp;
    }
    cout << max(0,out) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner (System.in);
        
        int n = sc.nextInt();
        
        int moneyCount = 1;
        int money = 1000;
        
        while (money * moneyCount < n) {
            moneyCount++;
        }
        
        int result = money * moneyCount - n;
        
        System.out.println(result);
        
    }
}

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

int main(){
    ll a,v,b,w,t; 
    cin >> a >> v >> b >> w >> t;
    
    if(abs(a-b) <= (v-w)*t) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 3620
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

n = int(input())
x = [int(item) for item in input().split()]
inv = [0] * (n + 10)

n_minus_1_fac = 1
for i in range(1, n):
    n_minus_1_fac *= i
    n_minus_1_fac %= MOD 

for i in range(n + 10):
    inv[i] = pow(i, MOD-2, MOD)
inv_cumsum = [0] * (n + 10)
for i in range(1, n + 10):
    inv_cumsum[i] = (inv_cumsum[i-1] + inv[i]) % MOD

ans = 0
for i, (x1, x2) in enumerate(zip(x, x[1:])):
    ans += (x2 - x1) * inv_cumsum[i+1] * n_minus_1_fac % MOD
    ans %= MOD
print(ans)

Measured memory_bytes: 15732
package main

import(
	"fmt"
)

// func main() {
// 	var a, b, c int
// 	fmt.Scan(&a, &b, &c)
// 	if 4*a*b < (c*c + a*a + b*b - 2*c*a - 2*c*b + 2*a*b) {
// 		fmt.Print("Yes")
// 	} else {
// 		fmt.Print("No")
// 	}
// }

func main() {
	var h, f int
	fmt.Scan(&h, &f)
	var r int = 0
	if h == 1 || f == 1 {
		r = 1
	} else {
		if h % 2 == 0 {
			for i := 0; i < f; i++ {
				r += h / 2
			}
		} else {
			if f % 2 == 0{
				for i := 0; i < f / 2; i++ {
					r += h
				}
			} else {
				for i := 0; i < f / 2; i++ {
					r += h
				}
				r += (h / 2) + 1
			}
		}
	}

	fmt.Print(r)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=1;i<=N;i++)


signed main(){
  int N,ans;
  cin>>N;
  if(N%2==1)ans=2*N;
  else ans=N;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll        long long
#define endl      "\n"
#define loop(n)   for(int i=0;i<n;i++)

using namespace std;
int main(){
    string s,s1;
    cin>>s;
    s1=s[s.length()-1];
    if(s1=="3"){cout<<"bon"<<endl;} 
    else if(s1=="0" || s1=="1" || s1=="6" || s1=="8"){cout<<"pon"<<endl;}
    else{cout<<"hon"<<endl;}
 
}

Measured memory_bytes: 3596
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    a, b, c, k = map(int, input().split())

    if a >= k:
        print(k)
    elif (a+b) >= k:
        print(a)
    else:
        num_of_C = k - a - b
        print(a-num_of_C)



if __name__ == "__main__":
    resolve()



Measured memory_bytes: 61896
#include <iostream>
 
using namespace std;
 
int main()
{
  string s; cin >> s;
  
  int ans = 700;
  for(int i  = 0;i < 3; i++)
  {
    if(s[i] == 'o') ans += 100;
  }
  
  cout << ans << endl; 
  
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int x[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(void)
{
    int n;

    cin >> n;
    cout << x[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
typedef long long ll;

using namespace std;


int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	cout << a[0] + a[1];
	}







Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,r,i,f;
	for(i=0;i<5;i++){
		r=0;
		scanf("%d",&f);
		if(f==0){
			break;
		}
		n=1000-f;
		if(n>=500){
			r++;
			n-=500;
		}
		while(n>=100){
			r++;
			n-=100;
		}
		if(n>=50){
			r++;
			n-=50;
		}
		while(n>=10){
			r++;
			n-=10;
		}
		if(n>=5){
			r++;
			n-=5;
		}
		while(n>0){
			r++;
			n-=1;
		}
		printf("%d\n",r);
	}

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	vl vec(n);
	vl s(0);
	vl t(0);
	bool v=true;
	rep(i,0,n){
		ll a; cin>>a;
		if(v) s.push_back(a);
		else t.push_back(a);
		if(v) v=false;
		else v=true;
	}
	if(n%2==0){
		reverse(all(t));
		rep(i,0,t.size()){
			cout<<t[i]<<" ";
			//cout<<"t ";
		}
		rep(i,0,s.size()){
			cout<<s[i]<<" ";
			//cout<<"s ";
		}
	}
	else{
		reverse(all(s));
		rep(i,0,s.size()){
			cout<<s[i]<<" ";
			//cout<<"s ";
		}
		rep(i,0,t.size()){
			cout<<t[i]<<" ";
			//cout<<"t ";
		}
	}
	return 0;
}

Measured memory_bytes: 5484
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

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

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}



int main()
{
ll n,k;
cin>>n>>k;
vector<ll>v(n);
rep(i,n){
    ll a;
    cin>>a;
    v[i]=a-1;
}
ll now=0;

vector<ll>c(n,-1);


for(ll l=0;l<k;l++){
    if(c[now]==-1){
        c[now]=l;
    }else{
            ll m=l-c[now];
            ll b=k-l;
            ll d=b%m;
            for(ll j=0;j<d;j++){
                now=v[now];
                if(j==d-1){
                    cout<<now+1<<endl;
                    return 0;
                }
            }
        }
    
    now=v[now];
}
cout<<now+1<<endl;

}



Measured memory_bytes: 6416
# solution

from bisect import bisect_left
from operator import itemgetter

nim, mike = map(int, input().split())
array = list(map(int, input().split()))
array1 = []
array2 = []
for _ in range(mike):
    b, c = map(int, input().split())
    array2.append((b, c))

array2 = sorted(array2, key=itemgetter(1), reverse=True)

for b, c in array2:
    array1.extend([c] * b)
    if len(array1) >= nim:
        break

Y = array + array1
Y.sort(reverse=True)
answer = sum(Y[:nim])
print(answer)

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

int main(){
    string S;
    cin >> S;
    string hi;
    if(S.size()%2!=0){
        cout << "No" << endl;
        return 0;
    }
    rep(i, S.size()/2){
        hi += "hi";
    }
    if(S==hi) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, node):
        self.parent = [-1 for _ in range(node)]

    def find(self, target):
        if self.parent[target] < 0:
            return target
        else:
            self.parent[target] = self.find(self.parent[target])
            return self.parent[target]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x == root_y:
            return
        if self.parent[root_x] > self.parent[root_y]:
            root_x, root_y = root_y, root_x
        self.parent[root_x] += self.parent[root_y]
        self.parent[root_y] = root_x

    def get_size(self, x):
        return -self.parent[self.find(x)]


def main():
    users, friend_pairs, block_pairs = map(int, input().split())
    answer = [0] * users
    user_relationship = UnionFind(users)
    friend = [[] for _ in range(users)]
    for _ in range(friend_pairs):
        a, b = map(lambda x: int(x) - 1, input().split())
        user_relationship.union(a, b)
        friend[a].append(b)
        friend[b].append(a)
    for _ in range(block_pairs):
        c, d = map(lambda x: int(x) - 1, input().split())
        if user_relationship.is_same(c, d):
            answer[c] -= 1
            answer[d] -= 1
    for i in range(users):
        answer[i] += user_relationship.get_size(i) - 1 - len(friend[i])
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()



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

typedef long long ll;
#define INF INT_MAX
#define MAXN 105
#define MAXW 100005

int N,W;
ll memo[MAXN][MAXW];
bool computed[MAXN][MAXW];
int w[MAXN];
int v[MAXN];

ll maxself(ll a,ll b){
    if(a > b)
        return a;
    return b;
}

ll dp(ll i,ll c)
{
    if(i == 0)
        return 0;
    if(computed[i][c])
        return memo[i][c];

    ll best = dp(i-1,c);
    if(c >= w[i]){
        best = maxself(best,dp(i-1,c-w[i]) + v[i]); 
    }
    computed[i][c] = true;
    memo[i][c] = best;
    return best;
}

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

    cin >> N >> W;
    for(int i = 1 ; i <= N ; i++){
        cin >> w[i] >> v[i];
    }
    cout << dp(N,W) << '\n';

    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      cin >> table.at(i).at(j);
    }
  }
  
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (table.at(i).at(j) == '#'){
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }
  
  for (int i=0; i<H; i++){
    if (row.at(i)) {
      for (int j=0; j<W; j++){
        if (col.at(j)) {
        cout << table.at(i).at(j);
      }
      }
      cout << endl;
    }
  } 
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<"IMPOSSIBLE"<<endl;return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;//19234567892927;
const llint mmd=1e9+7;
const int big=1e12+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int i,j,ans=0,n,m,mae=0;cin>>n>>m;
	vector<int>in(n);
	vector<int>ama(m);
	vector<int>pa(m);
	for(i=0;i<n;i++){cin>>in[i];}
	sort(in.begin(),in.end());
	for(i=0;i<n;i++){
		if(i!=n-1&&in[i]==in[i+1]&&mae==0){
			pa[in[i]%m]++;mae=1;
		}else{mae=0;}
		ama[in[i]%m]++;
	}
	for(i=1;i<(m+1)/2;i++){
		ans+=min(ama[i],ama[m-i]);
		if(ama[i]>ama[m-i]){ans+=min(pa[i],(ama[i]-ama[m-i])/2);}
		else{ans+=min(pa[m-i],(ama[m-i]-ama[i])/2);}
	}
	ans+=ama[0]/2;
	if(m%2==0){ans+=ama[m/2]/2;}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    int a,b; scanf("%d %d", &a, &b);
    int res = (a&1) & (b&1);
    puts(res ? "Yes" : "No");
    return 0;
}

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

int main(){
  int N,M;cin>>N>>M;
  dsu X(N);
  for(int i=0;i<M;i++){
    int A,B;cin>>A>>B;
    X.merge(A-1,B-1);
  }
  cout<<X.groups().size()-1<<endl;
}


Measured memory_bytes: 9072
#include <bits/stdc++.h>
#define ll long long
#define mp(a, b) make_pair(a, b)
#define newline cout << endl;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(),v.end()
using namespace std;

template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p)
{
	out << '(' << p.ff << ", " << p.ss << ')';
	return out;
}

template <typename T> ostream& operator<<(ostream& out, vector<T> const& v)
{
	int l = v.size();
	for (int i = 0; i < l - 1; i++)
		out << v[i] << ' ';
	if (l > 0)
		out << v[l - 1];
	return out;
}

template <typename T> void trace(const char* name, T&& arg1) { cout << name << " : " << arg1 << endl; }

template <typename T, typename... Args> void trace(const char* names, T&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cout.write(names, comma - names) << " : " << arg1 << " | ";
	trace(comma + 1, args...);
}

/*Input*/
const ll size = 1e6+10;
ll n,k,q;
vector<ll> v(size);
/*Input*/

void reset(){
    for(int i = 0; i < size; i++){
        v[i] = k;
    }
}

int main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
	clock_t tStart = clock();
	int test;
	test = 1;
	// cin >> test;
	while (test--) {
	    cin >> n >> k >> q;
        reset();
        for(int i = 0;i < q; i++){
            ll x;
            cin >> x;
            v[--x]+=1;   
        }
        for(int i = 0;i < n; i++){
            v[i] -= q;
        }
        for(int i = 0;i < n; i++){
            /* cout << v[i] <<  ' '; */
            if(v[i] > 0) cout << "Yes\n";
            else cout << "No\n";
        } cout << endl;
        
    }
#ifdef LOCAL_DEFINE
	printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
#endif
	return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<set<pair<int, int>>> v(n + 1);
    int p, y;
    REP(i, m) {
	cin >> p >> y;
	v[p].emplace(y, i);
    }
    vector<pair<int, int>> ans(m);
    REP1(i, n) {
	int idx = 1;
	for (auto st : v[i]) {
	    ans[st.second] = {i, idx++};
	}
    }
    REP(i, m) cout << setw(6) << setfill('0') << ans[i].first << setw(6) << setfill('0') << ans[i].second << endl;
}


Measured memory_bytes: 13492
void main() {
	auto ip = readAs!(int[]), H = ip[0], W = ip[1];
	auto C = readMatrix!char(H, W);
	foreach(i; C) {
		i.writeln;
		i.writeln;
	}
}

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

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

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

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

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

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 380
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    static int modP = 1000000007;
    static long inf  = Long.MAX_VALUE;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        List<P> points = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            P p = new P(in.nextLong(), in.nextLong());
            points.add(p);
        }

        List<Long> xList = points.stream().map(p -> p.x).collect(Collectors.toList());
        List<Long> yList = points.stream().map(p -> p.y).collect(Collectors.toList());

        long area = inf;
        for(int x1 = 0; x1 < n; x1++) {
            for(int x2 = x1+1; x2 < n; x2++) {
                for(int y1 = 0; y1 < n; y1++) {
                    for(int y2 = y1+1; y2 < n; y2++) {
                        if(xList.get(x1) == xList.get(x2) || yList.get(y1) == yList.get(y2)) continue;

                        P p1 = new P(xList.get(x1), yList.get(y1));
                        P p2 = new P(xList.get(x2), yList.get(y2));

                        int cnt = 0;
                        for(P p : points) {
                            if(check(p1, p2, p)){
                                cnt++;
                            }
                        }

                        if(cnt >= k){
                            area = Math.min(area, calcArea(p1, p2));
                        }
                    }
                }
            }
        }

        print(area);
    }

    static long calcArea(P a, P b) {
        return Math.abs(a.x-b.x) * Math.abs(a.y-b.y);
    }

    static boolean check(P a, P b, P c) {
        long leftMost  = Math.max(a.x, b.x);
        long rightMost = Math.min(a.x, b.x);
        long upMost    = Math.max(a.y, b.y);
        long downMost  = Math.min(a.y, b.y);
        if(c.x < rightMost || leftMost < c.x) return false;
        if(c.y < downMost  || upMost   < c.y) return false;
        return true;
    }

    static void print(String s) {
        System.out.println(s);
    }

    static void print(int i) {
        System.out.println(i);
    }

    static void print(long i) {
        System.out.println(i);
    }
}

class P {
    long x, y;
    P(long x, long y) {
        this.x = x;
        this.y = y;
    }
}

class E {
    int from, to;
    long w;
    E(int from, int to, long w) {
        this.from = from;
        this.to = to;
        this.w = w;
    }
}


Measured memory_bytes: 65100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int cnt;
int n;
int l;
int A[1000000];
vector<int> G;

void insertionSort(int A[],int n, int g){
    for (int i = g; i < n ; ++i) {
        int v = A[i];
        int j = i-g;
        while (j >= 0 && A[j] > v ){
            A[j+g] = A[j];
            j = j-g;
            cnt ++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[],int n){
    for (int h = 1 ; ; ){
    if(h > n)break;
    G.push_back(h);
        h = 3 * h + 1;
    }
    for (int i = G.size() -1 ; i >= 0 ; i--) {
        insertionSort(A, n, G[i]);
    }
}

int main(){
    cin >> n;
	for (long i = 0; i < n; i++) cin >> A[i];
    cnt = 0;

    shellSort(A,n);

    cout << G.size() << endl;
    for (int i = G.size() -1 ; i >= 0 ; i--) {
        printf("%d", G[i]);
        if (i) printf(" ");
    }
    cout << endl;
    cout << cnt << endl;
    for (int i = 0; i < n ; ++i) {
        cout << A[i] << endl;
    }
    return 0;
}

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

int main(){
  int a,b,cou,c;
  while(cin>>a>>b){
    c=a+b;
    cou=1;
    for(int i=1;i<=c;i*=10)cou++;
    cout<<cou-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
using System;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    int[] arrX = new int[N];
    int[] arrY = new int[N];
    for (int i = 0; i < N; i++) {
      string[] s = Console.ReadLine().Split(' ');
      arrX[i] = int.Parse(s[0]);
      arrY[i] = int.Parse(s[1]);
    }
    int n = 1;
    for (int i = 1; i <= N; i++) {
      n *= i;
    }
    double sum = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (i == j) { continue; }
        sum += Math.Sqrt(Math.Pow(arrX[j] - arrX[i], 2) + Math.Pow(arrY[j] - arrY[i], 2));
      }
    }
    Console.WriteLine(sum * (n / N) / n);
  }
}

Measured memory_bytes: 11092
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<u32> = sc.vec(n);
    let b: Vec<u32> = sc.vec(n);

    let mut ab = b.into_iter().zip(a.into_iter()).collect::<Vec<_>>();
    ab.sort();
    let b: Vec<_> = ab.iter().map(|&(b, _)| b).collect();
    let mut a: Vec<_> = ab.iter().enumerate().map(|(i, &(_, a))| (a, i)).collect();
    a.sort();

    for i in 0..n {
        if a[i].0 > b[i] {
            println!("No");
            return;
        }
    }

    let mut cur = a[0].1;
    let mut vis = vec![false; n];
    while !vis[cur] {
        vis[cur] = true;
        cur = a[cur].1;
    }
    let vis_count = vis.into_iter().filter(|&c| c).count();
    if vis_count != n {
        println!("Yes");
        return;
    }

    for i in 1..n {
        let a1 = a[i].0;
        let b0 = b[i - 1];
        if b0 >= a1 {
            println!("Yes");
            return;
        }
    }

    println!("No");
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int a,b;
    cin >> a >> b;
    int mx=0;
    int A=0,B=0;
    A+=a;
    B+=b;
    mx=max(mx,max(A,B));
    mx=max(mx,A+B);

    A=0,B=0;
    A+=a;
    A+=(a-1);
    B+=b;
    B+=(b-1);

    mx=max(mx,max(A,B));

    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    X, N = list(map(int, input().split(' ')))
    if N == 0:
        P = input()
        print(X)
        return
    P = list(map(int, input().split(' ')))
    min_dist, ans = abs(X), 0
    for n in range(102):
        if n in P:
            continue
        if abs(X - n) < min_dist:
            min_dist = abs(X - n)
            ans = n
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9136
#include<bits/stdc++.h>
using namespace std;
typedef pair<double,string> pd;
#define MK make_pair

int make(string s){
  int a=0;
  for(int i=0;i<s.size();i++){
    a+=(int)(s[s.size()-1-i]-'0')*pow(10,i);
  }
  return a;
}

string makes(int a,int l){
  string s;
  for(int i=l-1;i>=0;i--){
    s.push_back('0'+(int)a/pow(10,i));
    a%=(int)pow(10,i);
  }
  return s;
}

int main(){
  while(1){


  
  vector<string> k;
  set<string> f;
  int a;
  int l;
  cin>>a>>l;
  if(a==0 && l==0){break;}
  string x=makes(a,l);
  k.push_back(x);
  f.insert(x);
  int ans=-1;
  string sans;
  for(int i=0;i<=20;i++){
    string g=k[i];
    sort(g.begin(),g.end());
    int mi=make(g);
    reverse(g.begin(),g.end());
    int mx=make(g);
    mi=mx-mi;
    string d=makes(mi,l);
    if(f.find(d)!=f.end()){ans=i+1; sans=d; break;}
    f.insert(d);
    k.push_back(d);
  }
  int q=0;
  for(int i=0;i<k.size();i++){
    if(sans==k[i]){ans-=i; q=i; break;}
  }
  int w=make(sans);
  cout<<q<<" "<<w<<" "<<ans<<endl;
  



  }
  
  return 0;
}
  
  



Measured memory_bytes: 3344
#include <iostream>
using namespace std;
int main(){
	int a , b , c;
	int max , med , min;
	cin >> a >> b >> c;
	if(a<b){
		if(a<c) {
			min=a;
			if (b<c){
				med=b;
				max=c;
			} else {
				med=c;
				max=b;
			}
		} else {
			min=c;
			if (a<b){
				med=a;
				max=b;
			} else {
				med=b;
				max=a;
			}
		}
	} else {
		if(b<c){
			min=b;
			if(a<c){
				med=a;
				max=c;
			} else {
				med=c;
				max=a;
			}
		} else { 
			min=c;
			med=b;
			max=a;
		}
	}
	cout << min << " " << med << " "<< max << endl;
	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int a = 0, z = 0;
		for (int i = 0; i < s.length(); i++) {
			if(s.charAt(i)=='A') {
				a = i;
				break;
			}
		}
		for (int i = s.length()-1; i >= 0; i--) {
			if(s.charAt(i)=='Z') {
				z = i;
				break;
			}
		}
		System.out.println(z-a+1);
		sc.close();
	}
}

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

int main(){
  string S;
  cin >> S;
  reverse(S.begin(),S.end());
  string T="";
  string x="";
  vector <string> s={"dream","dreamer","erase","eraser"};
  for(int i=0;i<s.size();i++){
    reverse(s.at(i).begin(),s.at(i).end());
  }
  for(int i=0;i<S.size();i++){
    x+=S.at(i);
    if(x.size()>=5){
      for(int j=0;j<s.size();j++){
        if(x==s.at(j)){
          T+=x;
          x="";
          break;
        }
      }
    }
  }
  if(T==S){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int n, a[3][3];
    for(int i=0;i<3;i++) for(int j=0;j<3;j++) cin >> a[i][j];
    cin >> n;
    for(;n--;){
        int b;
        cin >> b;
        for(int i=0;i<3;i++) for(int j=0;j<3;j++) if(b == a[i][j]) a[i][j] = 0;
    }
    
    bool flg = false;
    for(int i=0;i<3;i++){
        int c = 0, d = 0;
        for(int j=0;j<3;j++){
            if(a[i][j] == 0) c++;
            if(a[j][i] == 0) d++;
        }
        if(c == 3 || d == 3) flg = true;
    }
    for(int i=0;i<3;i++){
        if(a[i][i] != 0) break;
        if(i == 2) flg = true;
    }
    for(int i=0;i<3;i++){
        if(a[i][2-i] != 0) break;
        if(i == 2) flg = true;
    }
    if(flg) puts("Yes");
    else puts("No");
}


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

namespace ABC096B
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABC = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var K = int.Parse(Console.ReadLine());

            ABC = ABC.OrderByDescending(x => x).ToArray();

            for(int i = 0; i < K; i++)
            {
                ABC[0] = ABC[0] * 2;
            }

            long ans = ABC.Sum();
            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13396
#python3.4以前はfractionsにgcdがある
#lcm（最小公倍数）はa*b/gcd(a,b)
import fractions
n=int(input()) 
t=[int(input()) for _ in range(n)]
ans=t[0]

for i in range(1,n):
  ans = (ans*t[i])//(fractions.gcd(ans,t[i]))
    
print(ans)

Measured memory_bytes: 5304
num = list(map(int,input().split()))

a = num[0]
b = num[1]

if a+b<=num[2]:
  a=0
  b=0
elif a+b>num[2] and a>num[2]:
  a = a - num[2]
elif a+b>num[2] and a<=num[2]:
  b = b - (num[2] - a)
  a = 0


print(a,b)

Measured memory_bytes: 3064
//minamoto
#include<bits/stdc++.h>
#define R register
#define pb push_back
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2005+5,M=5e6+5;
struct eg{int v,nx;}e[M];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
vector<int>to[N];int deg[N],vis[N],a[N],n;
priority_queue<int>q;
void dfs(int u){
	vis[u]=1;
	for(auto v:to[u])if(!vis[v])add(u,v),++deg[v],dfs(v);
}
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	fp(i,1,n)fp(j,i+1,n)if(__gcd(a[i],a[j])>1)to[i].pb(j),to[j].pb(i);
	fp(i,1,n)if(!vis[i])dfs(i);
	fp(i,1,n)if(!deg[i])q.push(i);
	for(R int u;!q.empty();){
		u=q.top(),q.pop();
		printf("%d ",a[u]);
		go(u)if(!--deg[v])q.push(v);
	}
	return 0;
}

Measured memory_bytes: 17664