akhauriyash/Code-Regression huggingface dataset:
from math import factorial
n = int(input())

P = list(map(int, input().split()))
Q = list(map(int, input().split()))
P_order = 1
Q_order = 1

numlist = list(range(1,n+1))
for i in range(n):
    P_order += numlist.index(P[i]) * factorial(n-i-1)
    numlist.remove(P[i])

numlist = list(range(1,n+1))
for i in range(n):
    Q_order += numlist.index(Q[i]) * factorial(n-i-1)
    numlist.remove(Q[i])

print(abs(P_order - Q_order))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using i64 = long long;

auto calc(const std::string &s) {
    std::vector<int> a(s.size() + 1);
    a[0] = -1;
    for (int i = 0, j = -1; i < s.size(); i++) {
        while (j >= 0 && s[i] != s[j]) j = a[j];
        j++;
        a[i + 1] = s[i + 1] == s[j] ? a[j] : j;
    }
    return a;
}

auto find(const std::string &s, const std::string &t, const std::vector<int> &a, int ss = 0, int ts = 0) {
    for (int i = ss, j = ts; i < s.size(); i++) {
        while (j >= 0 && s[i] != t[j]) j = a[j];
        if (++j == t.size()) return i - t.size() + 1;
    }
    return s.size();
}

int main() {
    std::string s, t;
    std::cin >> s >> t;
    int n = s.size(), m = t.size();
    std::vector<int> e(s.size());
    auto ss = s;
    while (ss.size() < s.size() + t.size()) ss += s;
    auto a = calc(t);

    for (int i = 0, j = 0; i < ss.size();) {
        auto k = find(ss, t, a, i, j);
        if (k == ss.size()) break;
        e[k % n] = 1;
        i = k + t.size();
        j = a[m];
    }

    int ret = 0;
    std::vector<int> p(n);
    for (int i = 0; i < n; i++) {
        if (e[i] < 0 || p[i]) continue;
        int j = i, tmp = 0;
        while (!p[j] && e[j]) {
            p[j] = 1;
            j = (j + m) % n;
            if (j == i) {
                std::cout << -1 << std::endl;
                return 0;
            }
            tmp++;
        }
        p[i] = tmp + p[j];
        ret = std::max(ret, p[i]);
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 8756
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>

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

using namespace std;

int dp[21][11][160];
int dfs(int n, int k, int s){
	if(k == 0) return s == 0; 

	int &res = dp[n][k][s];
	if(res >= 0) return res;

	res = 0;
	for(int i = n; i >= k; i--){
		res += dfs(i-1, k-1, s-i);
	}

	return res;
}

int main(){
	int n, k, s;
	memset(dp, -1, sizeof(dp));
	while(cin >> n >> k >> s, n|k|s){
		cout << dfs(n, k, s) << endl;
	}


	return 0;
}

Measured memory_bytes: 1312
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from itertools import count

def douteki(limit, data):
    V = [[0 for w in xrange(limit+1)] for i in xrange(len(data)+1)]
    W = [[0 for w in xrange(limit+1)] for i in xrange(len(data)+1)]
    for i in xrange(len(data)+1):
        for w in xrange(limit+1):
            diff = w - data[i-1][1]
            if i - 1 >= 0 and diff >= 0:
                v1 = V[i-1][diff] + data[i-1][0]
                w1 = W[i-1][diff] + data[i-1][1]
            else:
                v1 = 0
                w1 = 0
            v2 = V[i-1][w]
            w2 = W[i-1][w]

            V[i][w], W[i][w] = (v1, w1) if v1 >= v2 else (v2, w2)
    return V[-1][-1], W[-1][-1]

for case in count(1):
    W = int(stdin.readline())
    if not W:
        break

    N = int(stdin.readline())
    data = []
    for _ in xrange(N):
        data.append([int(s) for s in stdin.readline().split(',')])

    value, weight = douteki(W, data)
    print('Case {}:\n{}\n{}'.format(case, value, weight))

Measured memory_bytes: 26792
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
int dp[1234567];
int dp2[1234567];


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

    int A,B,C,X;
    cin >> A >> B >> C >> X;
    dp[0] = 1;

    rep(i,0,100000){
        if(dp[i]){
            rep(j,0,A+1){
                dp2[j * 500 + i] += dp[i];
            }
        }
    }
    rep(i,0,100000){
        dp[i] = dp2[i];
    }
    fill(dp2,dp2+100000,0);

    rep(i,0,100000){
        if(dp[i]){
            rep(j,0,B+1){
                dp2[j* 100 + i] += dp[i];
            }
        }
    }
    rep(i,0,100000){
        dp[i] = dp2[i];
    }
    fill(dp2,dp2+100000,0);

    rep(i,0,100000){
        if(dp[i]){
            rep(j,0,C+1){
                dp2[j* 50 + i] += dp[i];
            }
        }
    }
    rep(i,0,100000){
        dp[i] = dp2[i];
    }
//    fill(dp2,dp2+100000,0);
//    rep(i,0,101){
//        cout << i << " " << dp[i] << endl;
//    }

    cout << dp[X] << endl;

    return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int w,h,n;
	cin >> w >> h >> n;
	vector<vector<bool>> square(h, vector<bool>(w, false));
	FOR(i,0,n){
		int x,y,a;
		cin >> x >> y >> a;
		FOR(j,0,h)FOR(k,0,w){
			if(square[j][k])continue;
			if(a == 1 && k >= x)continue;
			if(a == 2 && k < x)continue;
			if(a == 3 && j >= y)continue;
			if(a == 4 && j < y)continue;
			square[j][k] = true;
		}
	}
	int ans = 0;
	FOR(i,0,h){
		FOR(j,0,w){
			//cout << square[i][j];
			if(!square[i][j])ans++;
		}
		//cout << endl;
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net.Sockets;
using System.Reflection.Metadata.Ecma335;
using System.Xml.Serialization;
//格子天井を動く組み合わせ
//条件
//・(x+y)/3=n
//(x,y)=>(x+1,y+2),(x+2,y+1)のどちらかなので(x+1,y+1)をくくり出す
//(a+b)!/a!b! = (a+b)Ca
//ヒント
//・nCk
//n!/(k!(n-k)!)
//・a/b(mod p)
//逆元をもとめる、フェルマーの小定理
//x^(p-1)=1(mod p)なので(mod p)の逆元はx^(p-2)

namespace D
{
    class Program
    {
        
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            int x = int.Parse(In[0]);
            int y = int.Parse(In[1]);
            if ((x + y) % 3 == 0)
            {
                int n = (x + y) / 3;
                x -= n;
                y -= n;
                if(x<0 || y < 0)
                {
                    Console.WriteLine(0);
                }
                else
                {
                    Fac[0] = 1;
                    iFac[0] = 1;
                    for(long i =0;i< 670000; i++)
                    {
                        Fac[i + 1] = Fac[i] * (i + 1) % M;
                        iFac[i + 1] = iFac[i] * MPow(i+1,M-2) % M;
                    }
                    long ans = Comb(x + y, x);
                    Console.WriteLine(ans);

                }
            }
            else
            {
                Console.WriteLine(0);
            }
        }

        static public readonly int M = 1000000007;
        static public long[] Fac=new long[670001];//n!(mod M)
        static public long[] iFac=new long[670001];//k!^(M-2)(mod M)
        static long MPow(long x, long n)//x^n(mod M) 普通のpowと同じだけどあふれ対策
        {
            long ans = 1;
            while (n!= 0)
            {
                if ((n & 1) == 1) ans = ans * x % M;
                x = x * x % M;
                n = n >> 1;
            }
            return ans;
        }
        static long Comb(long a, long b)//aCbをmodで計算
        {
            if (a == 0 && b == 0) return 1;
            if (a < b || a < 0) return 0;
            long temp = iFac[a - b] * iFac[b] % M;
            return temp * Fac[a] % M;
        }
    }
}


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

using namespace std;

#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

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

//Debug
string to_string(const string& s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A, typename B>
string to_string(pair<A, B> p) {return "("+to_string(p.fi)+", "+to_string(p.se)+")";}
template <typename A>
string to_string(A v) {
	if(v.begin()==v.end()) return "";
	return accumulate(++v.begin(), v.end(), "{"+to_string(*v.begin()),
			[](const string& a, auto b){ return a + ", " + to_string(b);})+"}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) false
#endif


double PI=3.141592653589793;

const int mx=1<<18,mvn=1e5;
map<int,int> proc[mx];
int va[mx],w[mx];


void solve(){
	int n,q;
	cin >> n;
	int bs=10;
	forse(i,1,n+1) cin >> va[i] >> w[i];
 
	forse(i,1,n+1){

		if(i>=(1<<bs)) break;
		map<int,int> cur;

		if(i==1){
			cur[0]=0;
			cur[w[i]]=va[i];
			proc[i]=cur;
			continue;
		}
 
		cur=proc[i/2];
		for(auto v:proc[i/2]){
			int vn=v.fi+w[i],val=v.se+va[i];
			if(vn<=mvn) cur[vn]=max(cur[vn],val);
		}
		int bval=-1;
		for(auto v:cur){
			if(v.se<=bval) continue;
			bval=v.se;
			proc[i][v.fi]=v.se;
		}	
	}
 
//	forse(i,1,n+1){
//		debug(i,proc[i]);
//	}
 
	cin >> q;
	while(q--){
		int v,l;
		cin >> v >> l;
		int pr=v,out=0;

		vector<pii> pro;
		while(pr>=(1<<bs)){
			pro.pb({w[pr],va[pr]});	
			pr/=2;
		}

		forn(ind,(1<<sz(pro))){
			int vsm=0,wsm=0;
			forn(j,sz(pro)){
				if(ind&(1<<j)){
					vsm+=pro[j].se;
					wsm+=pro[j].fi;
				}
			}
			if(l<wsm) continue;
			out=max(out,vsm+(--proc[pr].upper_bound(l-wsm))->se);
		}

		cout << out << '\n';
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
		//	cout << "Case #" << cid << ": ";
		solve();
	}
}


Measured memory_bytes: 49024
#include <stdio.h>
#include <queue>
using namespace std;

int main()
{
	int n,no;
	long long many,yen;
	long long total[4001];
	bool update;
	queue<int> que;

	for(int i = 0; i <= 4000; i++){
		total[i] = 0;
	}

	scanf("%d",&n);

	while(n != 0){
		
		update = false;

		for(int i = 0; i < n; i++){
			scanf("%d%lld%lld",&no,&many,&yen);
			total[no] += many*yen;
			que.push(no);
		}

		while(!que.empty()){
			if(total[que.front()] >= 1000000){
				printf("%d\n",que.front());
				update = true;
			}
			total[que.front()] = 0;
			que.pop();
		}
		if(!update){
			printf("NA\n");
		}

		scanf("%d",&n);
	}

	return 0;
}

Measured memory_bytes: 1100
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1000005,M=1e9+7;
int fac[N],inv[N],n;
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*x%M)
		if (y&1)(ans*=x)%=M;
	return ans;
}
int C(int x,int y){
	if (x<y)return 0;
	return fac[x]*inv[y]%M*inv[x-y]%M;
}
int w(int k){
	int x=n-2-k;
	int y=k-x;
	return C(x+y,x);
}
signed main(){
	scanf("%lld",&n);
	if (n==2){
		puts("1");
		return 0;
	}
	fac[0]=inv[0]=1;
	for (int i=1;i<N;i++)fac[i]=fac[i-1]*i%M,inv[i]=ksm(fac[i],M-2);
	int ans=fac[n-1];
	for (int i=1;i<n;i++)(ans+=(C(n-2,i)+C(n-2,i-1)-w(i-1)+M)*fac[i]%M*fac[n-i-1])%=M;
	printf("%lld\n",ans);
}


Measured memory_bytes: 15872
/*Lucky_Glass*/
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b;
int gcd(int x,int y)
{
	if(x>y) swap(x,y);
	int r=x%y;
	while(r)
	{
		r=x%y;
		x=y;y=r;
	}
	return x;
}
int main()
{
	scanf("%d%d",&a,&b);
	if(a<b) printf("%d\n",a);
	else
		if(a%b==0) printf("%d\n",-1);
		else
		{
			int G=gcd(a,b);
			int A=a/G,B=b/G;
			
			printf("%lld\n",1ll*G*A*(B-1));
		}
	return 0;
}

Measured memory_bytes: 128
def sieve_prime(n): # return prime numbers within [1, n]
  primes = []
  is_prime = [True] * (n+1) # [0, n]
  for i in range(2, n+1):
    if not is_prime[i]:
      continue # need only primes

    primes.append(i)
    for j in range(i*2, n+1, i): # range(i*2, n+1, i) = {i*2, i*3, ...}
      is_prime[j] = False

    """
    Compare the above code with the below one in the view of time complexity
    for j in range(i*2, n+1):
      if j % i == 0:
        is_prime[j] = False
    """
        
  return primes
      
while True:
  try:
    n = int(input())
    print(len(sieve_prime(n))) # because T <= 30, you can simply use sieve_prime every time
  except EOFError:
    break

Measured memory_bytes: 19020
N, M = map(int, input().split())
P = [i for i in range(N)]
D = [0] * N
C = [1] * N

def par(a):
    if a == P[a]:
        return a
    p = par(P[a])
    d = D[P[a]]
    P[a] = p
    D[a] += d
    return p

def dist(a, b):
    pa = par(a)
    pb = par(b)
    if pa == pb:
        return D[b] - D[a]
    return 1 << 30

def unite(a, b, d):
    if par(a) == par(b):
        return
    if C[P[a]] < C[P[b]]:
        a, b, d = b, a, -d
    C[P[a]] += C[P[b]]
    D[P[b]] = D[a] + d - D[b]
    P[P[b]] = P[a]

for _ in range(M):
    l, r, d = map(int, input().split())
    l, r = l-1, r-1
    dd = dist(l, r)
    if dd == 1<<30:
        unite(l, r, d)
    else:
        if d != dd:
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 108704
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

int n;
int constexpr N = 3009;
int a[N];
int dp[N][N][2];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
}

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

    for(int len = 1; len <= n; ++len) {
        for(int i = 1; i <= n - len + 1; ++i) {
            int j = i + len - 1;
            if(len == 1) {
                dp[i][j][0] = a[i];
                dp[i][j][1] = -a[i];
                continue;
            }
            dp[i][j][0] = max(a[i] + dp[i + 1][j][1], a[j] + dp[i][j - 1][1]);
            dp[i][j][1] = min(-a[i] + dp[i + 1][j][0], -a[j] + dp[i][j - 1][0]);
        }
    }

    cout << dp[1][n][0] << endl;

}


Measured memory_bytes: 141568
import java.util.*;

public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    sc.close();

    String aw = "";
    for(int i=0;i<B;++i){
      aw += String.valueOf(A);
    }
    String bw = "";
    for(int i=0;i<A;++i){
      bw += String.valueOf(B);
    }

    if (aw.compareTo(bw) < 0) {
      System.out.println(aw);
    } else {
      System.out.println(bw);
    }
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var < (end); var++)
#define RFOR(var, begin, end) for (int var = (begin) - 1; var >= (end); var--)
#define REP(var, length) FOR(var, 0, length)
#define RREP(var, length) RFOR(var, length, 0)
#define SORT(vector) sort(vector.begin(), vector.end())

const ll MOD = 1e9 + 7;

vector<int> z_algorithm(const string &s) {
  vector<int> prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

void solve(istream& cin, ostream& cout) {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  REP(i, n) {
    auto ret = z_algorithm(s.substr(i));
    int tmp = 0;
    REP(j, n - i) {
      if (ret[j] <= j) {
        tmp = max(tmp, ret[j]);
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


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

int main() {
  string s;
  cin>>s;
  int gx, gy;
  cin>>gx>>gy;
  vector<int> xs;
  vector<int> ys;
  bool is_x = true;
  int idx = 0;
  int n = s.length();
  while (idx < n) {
    if (s[idx] == 'T') {
      ++idx;
      is_x = !is_x;
    }
    int cnt = 0;
    while (idx < n) {
      if (s[idx] == 'F') {
        ++cnt;
        ++idx;
      } else {
        break;
      }
    }
    if (is_x) {
      xs.push_back(cnt);
    } else {
      ys.push_back(cnt);
    }
  }
  int dp_x[2][16001];
  int dp_y[2][16001];

  for (int i=0; i<2; i++) {
    for (int j=0; j<16001; j++) {
      dp_x[i][j] = 0;
    }
  }
  for (int i=0; i<2; i++) {
    for (int j=0; j<16001; j++) {
      dp_y[i][j] = 0;
    }
  }
  if (s[0] == 'F') {
    dp_x[0][8000+xs[0]] = 1;
    xs[0] = 0;
  } else {
    dp_x[0][8000] = 1;
  }
  dp_y[0][8000] = 1;
  for (int i=0; i<xs.size(); i++) {
    int xi = xs[i];
    for (int j=0; j<16001; j++) {
      dp_x[(i+1)%2][j] = 0;
    }
    for (int j=0; j<16001; j++) {
      if (dp_x[i%2][j] == 1) {
        if (j-xi >= 0) dp_x[(i+1)%2][j-xi] = 1;
        if (j+xi <= 16000) dp_x[(i+1)%2][j+xi] = 1;
      }
    }
  }
  for (int i=0; i<ys.size(); i++) {
    int yi = ys[i];
    for (int j=0; j<16001; j++) {
      dp_y[(i+1)%2][j] = 0;
    }
    for (int j=0; j<16001; j++) {
      if (dp_y[i%2][j] == 1) {
        if (j-yi >= 0) dp_y[(i+1)%2][j-yi] = 1;
        if (j+yi <= 16000) dp_y[(i+1)%2][j+yi] = 1;
      }
    }
  }
  if (dp_x[xs.size()%2][gx+8000] && dp_y[ys.size()%2][gy+8000]) {
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }
}

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


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}
int main(){
    ll A,B,N;
    cin>>A>>B>>N;
    ll X = min(B-1, N);
    cout<<(A*X)/B - A*(X/B); 
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
	double x1,x2,x3,x4,y1,y2,y3,y4;
	while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)){
		bool ok1=true;
		bool ok2=true;
		if((x2-x1)*(y4-y1)-(x4-x1)*(y2-y1)<0)ok1=false;
		else ok2=false;
		if((x3-x2)*(y4-y2)-(x4-x2)*(y3-y2)<0)ok1=false;
		else ok2=false;
		if((x1-x3)*(y4-y3)-(x4-x3)*(y1-y3)<0)ok1=false;
		else ok2=false;
		printf((ok1||ok2)?"YES\n":"NO\n");
	}
}

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

int main()
{
    string s;
    cin>>s;

    int idx = 1, counter = 0;
    string s2 = "", s1 = "";

    s2 += s[0];

    while(idx < s.size())
    {
        s1 = s[idx];
        if(s1 == s2){
            counter ++;
            s2 = s.substr(idx, 2);
            idx += 2;
        }
        else{
            s2 = s1;
            idx ++;
        }
    }

    cout<<s.size() - counter;

    return 0;
}


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

int main(){
    int k, x;
    cin >> k >> x;
    for (int i = x-k+1; i <= x+k-1; i++)
    {
        cout << i << " ";
    }
    cout << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
  int x3,y3,x4,y4;
  int x=x2-x1;
  int y=y2-y1;
  x3=x2-y;
  y3=y2+x;
  x4=x1-y;
  y4=y1+x;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;


  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = str(input())


N = 0
number1 = list(range(10))


for i in range(0,n-2):
    if int(s[i]) in number1:
        number1.remove(int(s[i]))
        number2 = list(range(10))
        for j in range(i + 1,n - 1):
            
            if int(s[j]) in number2:
                number2.remove(int(s[j]))
                number3 = list(range(10))
                for k in range(j + 1,n):
                    if int(s[k]) in number3:
                        number3.remove(int(s[k]))
                        N += 1
                        if N == 1000:
                            break
"""
                        print(s[i]+s[j]+s[k])
                        print("{}{}{}".format(i,j,k))
"""
                        

print(N)

Measured memory_bytes: 41948
#include<cstdio>
int main(){
	long long int n,k,a=0;
	scanf("%lld%lld",&n,&k);
	if(k==0){
		a=n*n;
	}
	else{
		for(int i=k+1;i<=n;i++){
			long long int j=0;
			while(j*i+k<=n){
				if((j+1)*i>n){
					a+=n-i*j-k+1;
				}
				else{
					a+=i-k;
				}
				j++;
			}
		}
	}
	printf("%lld\n",a);
}


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

int main() {
	int n,content;
	cin>>n>>content;
	vector<int> v(n),w(n),dp(content+1);
	for(int i=0;i<n;++i){
		cin>>v[i]>>w[i];
	}
	for(int i=0;i<n;++i){
		for(int j=0;j+w[i]<=content;++j){
			dp[j+w[i]]=max(dp[j]+v[i],dp[j+w[i]]);
		}
	}
	cout<<dp[content]<<endl;
	return 0;
}


Measured memory_bytes: 3152
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;//ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n,k;
 cin>>n;
 k=(ll)sqrt(n)+(ll)1;
 if(k>1000000000)k--;
 ll c=k*k-n;
 printf("0 0 %lld %lld %lld 1\n",c,k,k);
 return 0;}

Measured memory_bytes: 3704
def sum(i):
	sum = 0

	while i  >= 1 :
		# 余りを足す i.e 1の位を足す eg. 153は+3
		sum += i % 10
		# 一の位を消す eg. 153 -> 15   3 -> 0
		i = i //10
	return sum	


N, A, B = (int(i) for i in input().split())

counter = 0

for i in range(1 , N + 1 ):
	
	j = sum(i)
	
	if j >= A and j <= B :
		counter += i
		


print(counter)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
int n;
int max=0;
int maxb;
int a[100005],b[100005];
scanf("%d",&n);
for(int i=0;i<n;i++){
    scanf("%d %d",&a[i],&b[i]);
    if(a[i]>max){max=a[i];maxb=b[i];}
}

printf("%d\n",max+maxb);


}


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

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

    int n,k;
    cin >> n >> k;

    vector<double> p(n);
    rep(i,n) cin >> p[i];

    double sum = 0;
    vector<double> exp(1010);
    for(double i = 1; i <= 1010; i++){
        sum += i;
        exp[i] = sum / i;
    }

    vector<double> cusum(n);
    cusum[0] = exp[p[0]];

    for(int i = 1; i < n; i++){
        cusum[i] = cusum[i-1] + exp[p[i]];
    }

    double ans = 0;
    for(int i = k - 1; i < n; i++){
        double tmp;
        if(i == k - 1) tmp = cusum[i];
        else {
            tmp = cusum[i] - cusum[i - k];
        }
        ans = max(ans,tmp);
    }
    cout << fixed << setprecision(10) << ans << endl;
}



Measured memory_bytes: 3456
import java.util.*;
class Main {
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		Dice dice = new Dice(stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt());
		String a = stdIn.next();
		for(int i = 0; i < a.length(); i++) {
			if(a.charAt(i) == 'N') {
				dice.TurnN();
			}
			else if(a.charAt(i) == 'W') {
				dice.TurnW();
			}
			else if(a.charAt(i) == 'E') {
				dice.TurnE();
			}
			else {
				dice.TurnS();
			}
		}
		System.out.println(dice.Top);
	}
	
	
}

class Dice {
	int Top; 
	int Bottom; 
	int N; 
	int S; 
	int W;
	int E; 
	Dice(int a, int b, int c, int d, int e, int f) {
		Top = a;
		S = b;
		E = c;
		W = d;
		N = e;
		Bottom = f;
	}
	public void TurnN() {
		int tmp = Top;
		Top = S;
		S = Bottom;
		Bottom = N;
		N = tmp;
	}
	public void TurnW() {
		int tmp = Top;
		Top = E;
		E = Bottom;
		Bottom = W;
		W = tmp;
	}
	public void TurnE() {
		int tmp = Top;
		Top = W;
		W = Bottom;
		Bottom = E;
		E = tmp;
	}
	public void TurnS() {
		int tmp = Top;
		Top = N;
		N = Bottom;
		Bottom = S;
		S = tmp;
	}
	
}

Measured memory_bytes: 17176
import math

a, b, x = map(int, input().split())

if x >= a ** 2 * b / 2:
    tan_theta = 2 * (a ** 2 * b - x) / (a ** 3)
    theta = math.atan(tan_theta)
    print(math.degrees(theta))
else:
    tan_theta = 2 * x / (a * b ** 2)
    theta = math.atan(tan_theta)
    print(90 - math.degrees(theta))


Measured memory_bytes: 62512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct UnionFind {
  vector<int> par; // 親を指すvector,-par[親]は木のサイズ
  UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
  int root(int x) { // 親をたどる&データの整理
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  bool unite(int x, int y) { // データの結合
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool same(int x, int y) {return root(x) == root(y);} // 所属判定
  int size(int x) {return -par[root(x)];} // 木のサイズ
};

//head

int n, m;
int ans;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  UnionFind uft(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    if(uft.unite(a, b)) ans++;
  }
  cout << n-1-ans << endl;
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
#define pip pair<int,pair<int,int> >
typedef unsigned long long ull;
const int inf=103974182;
using namespace std;
int n;
pair<int,pii> a[200005];
vector <pair<int,pii> >vec;
set <pair<int,pair<int,int> > > squ;
int f[200005];
priority_queue <pip,vector <pip>,greater<pip> >que;

int find(int x)
{
	return (x==f[x]?x:f[x]=find(f[x]));
}

int add(int x,int y)
{
	x=find(x);
	y=find(y);
	if(rand()&1) f[x]=y;else f[y]=x;
}

bool compare1(pair<int,pii> a,pair<int,pii> b)
{
	return a.second.first<b.second.first;
}

bool compare2(pair<int,pii> a,pair<int,pii> b)
{
	return a.second.second<b.second.second;
}

void init()
{
	for(int i=0;i<200005;i++)
	{
		f[i]=i;
	}
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&a[i].second.first,&a[i].second.second);
		a[i].first=i;
	}
	sort(a,a+n,compare1);
	for(int i=0;i<n-1;i++)
	{
		vec.push_back(mp(min(abs(a[i+1].second.first-a[i].second.first),abs(a[i+1].second.second-a[i].second.second)),mp(a[i].first,a[i+1].first)));
	}
	sort(a,a+n,compare2);
	for(int i=0;i<n-1;i++)
	{
		vec.push_back(mp(min(abs(a[i+1].second.first-a[i].second.first),abs(a[i+1].second.second-a[i].second.second)),mp(a[i].first,a[i+1].first)));
	}
	for(int i=0;i<vec.size();i++)
	{
//		que.push(vec[i]);
		squ.insert(vec[i]);
	}
//	for(set <pair<int,pii> > ::iterator it=squ.begin();it!=squ.end();it++)
//	{
//		cout<<it->first<<' '<<it->second.first<<' '<<it->second.second<<endl;
//	}
//	cout<<que.size()<<endl;
	init();
	int k=0;
	ll ans=0;
	while(1)
	{
//		cout<<que.size()<<endl;
//		system("pause");
		if(k==n-1) break;
		pip t=*squ.begin();
		squ.erase(t);
		if(find(t.second.first)==find(t.second.second)) continue;
		k++;
//		cout<<k<<endl;
		ans+=t.first;
		add(t.second.first,t.second.second);
	}
	cout<<ans<<Endl;
	return 0;
}

Measured memory_bytes: 17776
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 330030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;

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

ll arr[n];
rep(i,0,n)
cin>>arr[i];
if(n==1)
{
	cout<<arr[0]/2;
	return 0;
}
ll ans=0;
ll x=0;
while(x<n)
{
	ll y=0;
	if(arr[x]!=0)
	{
		while(x<n&&arr[x]!=0)
		{
			y+=arr[x];
			x++;
		}
		ans+=y/2;
	}
	else
	x++;
}
//ans+=arr[n-1]/2;
cout<<ans;
}


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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

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

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

int H,W;
int sx,sy,gx,gy;
vector<vector<char>> maze;
vector<vector<int>> dis;
queue<pint> que;
bool flg;

int dfs( int x, int y) {
    //int n = maze[x][y] - '0';
    int n = dis[x][y];
    if ( x == gx and y == gy ){
        flg = true;
        return n;
    }
    que.push(pint(x,y));
     
    //cout << "dfs " << x << " " << y << " " << maze[x][y] << endl;;
    
    REP(i,4){
        int nx = x + dx[i], ny = y + dy[i];
        if ( maze[nx][ny] == '.' ){
            //maze[nx][ny] = n + '0';
            maze[nx][ny] = '#';
            dis[nx][ny] = n;
            dfs(nx,ny);
        }
    }
    return 0;
}


int main() {
    cin >> H >> W;
    cin >> sx >> sy >> gx >> gy; ++gx; ++gy;
    maze.assign(H+4,vector<char>(W+4,'#'));
    dis.assign(H+4,vector<int>(W+4,-1));
    REP(i,H) REP(j,W){
        cin >> maze[i+2][j+2];
    }
    
    
    flg = false;
    int ans = -1;
    //maze[sx+1][sy+1] = '0';
    maze[sx+1][sy+1] = '#';
    dis[sx+1][sy+1] = 0;
    
    queue<pint> quex;
    quex.push(pint(sx+1,sy+1));
    
    while( flg == false ){
        //ans = dfs(sx+1,sy+1);
        while ( quex.size() ){
            pint p2 = quex.front(); quex.pop();
            sx = p2.first - 1; sy = p2.second - 1;
            ans = dfs(sx+1,sy+1);
        }
        if ( flg == true ) break;
        while( que.size() ){
            pint p = que.front(); que.pop();
            int x = p.first, y = p.second;
            //int d = maze[x][y] - '0';
            int d = dis[x][y];
            //cout << x << " " << y << " " << d << endl;
            for ( int nx = x-2; nx <= x + 2; ++nx){
                for ( int ny = y-2; ny <= y + 2; ++ny){
                    //cout << nx << " " << ny << endl;
                    if ( maze[nx][ny] == '.' ){
                        //maze[nx][ny] = ( d + 1 ) + '0';
                        maze[nx][ny] = '#';
                        dis[nx][ny] = d+1;
                        quex.push(pint(nx,ny));
                    }
                }
            }
        }
        if ( quex.empty() ) break;
        //pint p2 = quex.front(); quex.pop();
        //sx = p2.first - 1; sy = p2.second - 1;
    }
    
    
    /*REP(i,H+4){
        REP(j,W+4){
            cout << dis[i][j];
        }
        cout << endl;
    }*/
    
    cout << dis[gx][gy] << endl;
    
    return 0;
}


Measured memory_bytes: 8620
#include <iostream>
#include <algorithm>

constexpr int max_r()
{
    return static_cast<int>(1e+9);
}

constexpr int max_size()
{
    return static_cast<int>(2e+5);
}

constexpr int min_value()
{
    return 1 - max_r();
}

/**
@brief simple solution.
@detail O(n^2)
*/
int solve0(const int n, int const* r)
{
    int ret = min_value();
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            ret = std::max(ret, r[i] - r[j]);
        }
    }
    return ret;
}

/**
@brief hold min value.
@detail O(n)
*/
int solve1(const int n, int const* r)
{
    int ret = min_value();
    int temp_min = r[0];
    for (int i = 1; i < n; ++i) {
        ret = std::max(ret, r[i] - temp_min);
        temp_min = std::min(r[i], temp_min);
    }
    return ret;
}

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

    int n;
    std::cin >> n;

    constexpr int N = max_size();
    int r[N];
    for (int i = 0; i < n; ++i) {
        std::cin >> r[i];
    }

    const int ret = solve1(n, r);
    std::cout << ret << std::endl;
    
    return 0;
}

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

int main(){
  int N, K;
  int s = 1;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
    if(s*2 < s+K){
      s = s*2;
    } else {
      s = s+K;
    }
  }
  
  cout << s << endl;
}
  

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll a,b,h,m; cin>>a>>b>>h>>m;
  double bx=b*sin(double(M_PI*m/30));
  double by=b*cos(double(M_PI*m/30));
  double ax=a*sin(double(M_PI*h/6+M_PI*m/360));
  double ay=a*cos(double(M_PI*h/6+M_PI*m/360));
  cout <<fixed<<setprecision(12)<<sqrt((bx-ax)*(bx-ax)+(by-ay)*(by-ay))<<endl;
}

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

using namespace std;

string s, t, v;

int main () {
	cin >> s >> t;
	for(int i = 0; i < max(s.size(), t.size()); i++) {
		if(s[i] >= 'a' && s[i] <= 'z') {
			v.push_back(s[i]);
		}
		if(t[i] >= 'a' && t[i] <= 'z') {
			v.push_back(t[i]);
		}
	}
	cout << v;
	return 0;
}

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

int main() {
  ll k,a,b; cin >> k >> a >> b;
  ll h;
  for(ll i = a; i<b+1; i++){
    if(i%k==0) h++;
  }
  if(h>0) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
int read()
{
	int res=0,ch,flag=0;
	if((ch=getchar())=='-')             //判断正负
		flag=1;
	else if(ch>='0'&&ch<='9')           //得到完整的数
		res=ch-'0';
	while((ch=getchar())>='0'&&ch<='9')
		res=res*10+ch-'0';
	return flag?-res:res;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
bool st[110];
void solve()
{
	memset(st,0,sizeof st);
	int x,n;
	cin>>x>>n;
	for(int i=1; i<=n; i++)
	{
		int x1;
		cin>>x1;
		st[x1]=1;
	}
	int ans=x;
	int cha=110;
	for(int i=0; i<=110; i++)
		if(st[i]==0)
		{
			if(abs(i-x)<cha)
			{
				cha=abs(i-x);
				ans=i;
			}
		}
	cout<<ans<<endl;
}
int main()
{
	int t=1;
	while(t--)
		solve();
}


Measured memory_bytes: 3620
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))

mod=10**9+7
fac=[1]*n
finv=[1]*n
inv=[0]*n
inv[1]=1
for i in range(2,n):
  fac[i]=fac[i-1]*i%mod
  inv[i]=mod-inv[mod%i]*(mod//i)%mod
  finv[i]=finv[i-1]*inv[i]%mod
def comb(n,k):
  if n<k:
    return 0
  if n<0 or k<0:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod

ans=0
for i in range(n-k+1):
  ans-=a[i]*comb(n-i-1,k-1)%mod
  ans%=mod
a=a[::-1]
for i in range(n-k+1):
  ans+=a[i]*comb(n-i-1,k-1)%mod
  ans%=mod
print(ans%mod)

Measured memory_bytes: 25520
#include<bits/stdc++.h>
using namespace std;
long long a[200005];
int main(){
    string s;
    cin>>s;
    if(s=="SAT") cout<<1<<endl;
    if(s=="SUN") cout<<7<<endl;
    if(s=="MON") cout<<6<<endl;
    if(s=="TUE") cout<<5<<endl;
    if(s=="WED") cout<<4<<endl;
    if(s=="THU") cout<<3<<endl;
    if(s=="FRI") cout<<2<<endl;
}

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

int main(){

	string s;
	cin >> s;

	int ans;

	if(s=="SUN") ans = 7;
	else if(s=="MON") ans =6; 	
	else if(s=="TUE") ans = 5;
	else if(s=="WED") ans = 4;
	else if(s=="THU") ans = 3;
	else if(s=="FRI") ans = 2;
	else if(s=="SAT") ans = 1;

	cout << ans << endl;
	

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(c)  c.begin(), c.end()
#define vb vector<bool>
#define vll vector<ll>
#define vp vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define lb "\n"
#define rep(i,a,b) for(int i = a;i<b;i++)
#define INF 998244353
#define MAX LLONG_MAX
#define PI 3.14159265358
ll max(ll x,ll y){if(x>y)return x;else return y;}
ll min(ll x,ll y){if(x>y)return y;else return x;}
ll dp[100001][3];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
      #ifdef LOCAL
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll i,j,k,n,ans;
    cin>>n;
    vll a(3);
    rep(i,0,n)
    {
        cin>>a[0]>>a[1]>>a[2];
        dp[i+1][0]=max(dp[i][1]+a[0],dp[i][2]+a[0]);
        dp[i+1][1]=max(dp[i][0]+a[1],dp[i][2]+a[1]);
        dp[i+1][2]=max(dp[i][1]+a[2],dp[i][0]+a[2]);
    }
    ans=max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<ans;
}


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

using namespace std;

int main()
{
  int p,q;
  for(;cin>>p>>q;)
    {
      bool loop =false;
      vector<int> mod;
      vector<pair<int,int> > pa;
      int count=0;
      int size=0;
      for(;!(p==0||loop);)
	{	
	  p*=10;
	  int t=p/q;
	  p=p%q;
	  //	  cout<<"  "<<p;
	
	  if(find(mod.begin(),mod.end(),p)==mod.end())
	    {
	      cout<<t;
	      size++;
	      //	      cout<<":insert"<<endl;
	      mod.push_back(p);
	      pa.push_back(pair<int,int>(t,p));
	    }
	  else
	    {
	      count+= find(mod.begin(),mod.end(),p)-mod.begin();
	      if(find(pa.begin(),pa.end(),pair<int,int>(t,p))==pa.end())
		{
		  cout<<t;
		  size++;
		}
	      else
		count--;
	      loop=true;
	    }
	}
      cout<<endl;
      if(loop)
	{
	  for(int i=0;i<count+1;i++)
	    cout<<" ";
	  for(int i=count+1;i<size;i++)
	    cout<<"^";
	  cout<<endl;
	}
    }
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    int N, M;
    
    cin >> N;
    cin >> M;
    
    int a[100001] = {0};
    
    for ( int i = 0; i < M; i++ ) {
        int x,y;
        cin >> x;
        cin >> y;
        
        a[x]++;
        a[y]++;
    }
    
    for ( int i = 1; i <= N; i++ ) {
        if ( a[i] % 2 != 0 ) {
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    string s;
    cin>>s;
    int a1 = 0, a2 = 0;
    REPALL(i,s) {
        if (s[i] == (char)((i%2) + '0')) {
            a1++;
        } else {
            a2++;
        }
    }

    cout<<min(a1,a2)<<endl;

    return 0;
}


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

int n;
int main()
{
	cin >> n;
	if (n % 2 == 0) puts("0.500000000");
	else printf("%.9f", 1.0 * (n / 2 + 1) / n);
    return 0;
}

Measured memory_bytes: 384
#include <iostream> //10000 5000 1000
using namespace std;
int main(){
	int n,y;
	cin>>n>>y;
	int a,b,c;
	for(a=0; a<=y/10000; a++){
		for(b=0; b<=(y-10000*a)/5000; b++){
			c=n-a-b;
			if(c*1000 + b*5000 + a*10000 == y){
				cout<<a<<" "<<b<<" "<<c;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1";
}

Measured memory_bytes: 256
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
class UnionFind():
   # 作りたい要素数nで初期化
   # 使用するインスタンス変数の初期化
   def __init__(self, n):
       self.n = n
       # root[x]<0ならそのノードが根かつその値が木の要素数
       # rootノードでその木の要素数を記録する
       self.root = [-1]*(n+1)
       # 木をくっつける時にアンバランスにならないように調整する
       self.rnk = [0]*(n+1)
   # ノードxのrootノードを見つける
   def Find_Root(self, x):
       if(self.root[x] < 0):
           return x
       else:
           # ここで代入しておくことで、後の繰り返しを避ける
           self.root[x] = self.Find_Root(self.root[x])
           return self.root[x]
   # 木の併合、入力は併合したい各ノード
   def Unite(self, x, y):
       # 入力ノードのrootノードを見つける
       x = self.Find_Root(x)
       y = self.Find_Root(y)
       # すでに同じ木に属していた場合
       if(x == y):
           return
       # 違う木に属していた場合rnkを見てくっつける方を決める
       elif(self.rnk[x] > self.rnk[y]):
           self.root[x] += self.root[y]
           self.root[y] = x
       else:
           self.root[y] += self.root[x]
           self.root[x] = y
           # rnkが同じ（深さに差がない場合）は1増やす
           if(self.rnk[x] == self.rnk[y]):
               self.rnk[y] += 1
   # xとyが同じグループに属するか判断
   def isSameGroup(self, x, y):
       return self.Find_Root(x) == self.Find_Root(y)
   # ノードxが属する木のサイズを返す
   def Count(self, x):
       return -self.root[self.Find_Root(x)]
n=int(input())
p=[list(map(int,input().split()))+[i] for i in range(n)]
p.sort()
d=[0]*(2*n-2)
for i in range(n-1):
    d[i]=[p[i][2],p[i+1][2],p[i+1][0]-p[i][0]]
p.sort(key=lambda x:x[1])
for i in range(n-1):
    d[i-1+n]=[p[i][2],p[i+1][2],p[i+1][1]-p[i][1]]
d.sort(key=lambda x:x[2])
h = UnionFind(n) 
cost = 0
for i in d:
    if not h.isSameGroup(i[0],i[1]):
        h.Unite(i[0],i[1])
        cost += i[2]
print(cost)

Measured memory_bytes: 53796