akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;



int main() {
   int a;
   cin >> a;
   cout <<setprecision(10)<<(double)((a+1)/2) / a;
}

Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

typedef long long ll;

const ll M=10000000019LL;

ll modmul(ll a,ll b,ll m){
	return (((a*(b>>20)%m)<<20)+a*(b&((1<<20)-1)))%m;
}

ll xgcd(ll a,ll b,ll &x,ll &y){
	if(b==0){ x=1; y=0; return a; }
	ll g=xgcd(b,a%b,y,x); y-=a/b*x;
	return g;
}

ll modinv(ll a,ll m){
	ll x,y;
	if(xgcd(a,m,x,y)==1) return (x+m)%m;
	return -1;
}

int main(){
	int n; scanf("%d",&n);
	ll x=0;
	rep(_,n){
		int op;
		ll y; scanf("%d%lld",&op,&y);
		if(y<0) y+=M;
		if     (op==1) x=(x+y)%M;
		else if(op==2) x=(x-y+M)%M;
		else if(op==3) x=modmul(x,y,M);
		else           x=modmul(x,modinv(y,M),M);
	}
	printf("%lld\n",x<(1LL<<31)?x:x-M);

	return 0;
}

Measured memory_bytes: 0
S=input()
ans0=0
ans1=0
for i in range(len(S)):
    s=int(S[i])
    if i%2==0:
        if s==1:
            ans0+=1
        else:
            ans1+=1
    else:
        if s==0:
            ans0+=1
        else:
            ans1+=1
print(min(ans0,ans1))

Measured memory_bytes: 3188
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		int R = s.replace("B", "").length();
		int B = N - R;
		if (R > B)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

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

int main(){
    int N, i, tmp;
    vector <int> A;

    cin >> N;
    for(i = 0; i < N; i++){
        cin >> tmp;
        A.push_back(tmp);
    }
    sort(A.begin(), A.end());

    cout << A[N - 1] - A[0] << endl;

    return 0;
}


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

using namespace std;
int main()
{
    //要素数入力
    int H, W;
    cin >> H >> W;

    //データ入力
    vector<vector<char>> grid(H, vector<char>(W, '-'));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> grid.at(i).at(j);
        }
    }

    int a[100];
    for (int i = 0; i < 100; i++)
    {
        a[i] = 0;
    }
    //まず行を調べる
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (grid.at(i).at(j) == '.' || grid.at(i).at(j) == '-')
            {
                a[i]++;
            }
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (a[i] == W)
            {
                grid.at(i).at(j) = '-';
            }
        }
    }

    int b[100];
    for (int i = 0; i < 100; i++)
    {
        b[i] = 0;
    }
    //次に列を調べる
    for (int i = 0; i < W; i++)
    {
        for (int j = 0; j < H; j++)
        {
            if (grid.at(j).at(i) == '.' || grid.at(j).at(i) == '-')
            {
                b[i]++;
            }
        }
    }
    for (int i = 0; i < W; i++)
    {
        for (int j = 0; j < H; j++)
        {
            if (b[i] == H)
            {
                grid.at(j).at(i) = '-';
            }
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (grid.at(i).at(j) != '-')
            {
                cout << grid.at(i).at(j);
            }
        }
        if (a[i] != W && b[W] != H){
            cout << "" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
	string s;
	cin >> s;
	int len = s.length();
	for (int i = 0; i < len; i++) {
		for (int j = i + 1; j < len; j++) {
			if (s[i] != s[j]) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
//#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 = 922337203685477580LL;
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;}



//head



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int d, t, s;
	cin >> d >> t >> s;
	if(t*s < d) cout << "No" << endl;
	else cout <<"Yes" << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int N;
  cin >> N;
  vector<i64> p(N);
  rep(i,0,N - 1) cin >> p[i];
  sort(begin(p),end(p));
  i64 ans = 0;
  for(i64 i : p) ans += i;
  cout << ans- p.back() / 2;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a;
	int b;
	int c;
	scanf("%d%d%d",&a,&b,&c);
	if(a<=b&&b<=c) printf("%d %d %d\n",a,b,c);
	else if(a<=c&&c<=b) printf("%d %d %d\n",a,c,b);
	else if(b<=a&&a<=c) printf("%d %d %d\n",b,a,c);
	else if(b<=c&&c<=a) printf("%d %d %d\n",b,c,a);
	else if(c<=a&&a<=b) printf("%d %d %d\n",c,a,b);
	else if(c<=b&&b<=a) printf("%d %d %d\n",c,b,a);
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

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

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int main(){
    int b[3];
    REP(i, 3){
        std::cin >> b[i];
    }

    if(b[0] && b[1] || b[2]){
        std::cout << "Open" << std::endl;
    }else{
        std::cout << "Close" << std::endl;
    }
}

Measured memory_bytes: 1156
import sys

DBG_FLAG = 0

def p_dbg(str):
    if(DBG_FLAG == 1):
        sys.stdout.flush()
        print str

num = int(raw_input())

p_dbg('num : ' + str(num))

array = []
# set to array by 10
dig = 4
while dig > 0:
    array.append((num % 10))
    num = num / 10
    dig = dig -1

array.reverse()
p_dbg('array : ' + str(array))

def ope_permutation(ope_array):
    ope1 = []
    ope2 = []
    ope3 = []
    ope1[:]=ope_array
    ope2[:]=ope_array
    ope3[:]=ope_array
    perm = []
    for o1 in ope1:
        for o2 in ope2:
            for o3 in ope3:
                perm.append([o1, o2, o3])

    return perm

ope_perm = ope_permutation(['+','-'])
p_dbg('ope_perm'+str(ope_perm))

for perm in ope_perm:
    sig = [1,1,1]
    if perm[0] == '-':
        sig[0] = -1
    else:
        sig[0] = 1
    if perm[1] == '-':
        sig[1] = -1
    else:
        sig[1] = 1
    if perm[2] == '-':
        sig[2] = -1
    else:
        sig[2] = 1
    if array[0] + sig[0]* array[1] + sig[1]* array[2] + sig[2]* array[3] == 7:
        print str(array[0]) + perm[0] + str(array[1]) + perm[1] + str(array[2]) + perm[2] + str(array[3])+'=7'
        break



Measured memory_bytes: 2696
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
long i,j,k,n,m;
string s;

int main() {
  cin >>n;
  vector<long> a(n);
  for(i=0;i<n;++i) cin >> a[i];
  j=n-1;
  while (j>=0) {
    cout << a[j] << " ";
    j-=2;
  }
  j=0;
  if ((n-1)%2==0)j=1;
  while (j<n-1) {
    cout << a[j] << " ";
    j+=2;
  }
  return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string N;
  cin>>N;
  queue<string> que;
  que.push("3");
  que.push("5");
  que.push("7");
  string state;
  bool ok;
  int ans = 0;
  while(true){
    state = que.front();que.pop();
    map<char, int> amap;
    ok = true;
    for(int i=0;i<state.size();++i){
      amap[state[i]]++;
    }
    if(!(amap['3']>0 && amap['5']>0 && amap['7']>0)) ok = false;
    if(state.size()>N.size()) break;
    else if(state.size()==N.size()){
      for(int i=0;i<N.size();++i){
        if(state[i]>N[i]) ok = false;
        if(state[i]<N[i]) break;
      }
    }
    if(ok) ans++;
    que.push(state+'3');
    que.push(state+'5');
    que.push(state+'7');
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5556
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#define ll long long
using namespace std;
int main()
{
	ll n;
	scanf("%lld",&n);
	if(n%2==0)
	{
		printf("%lld",n);
	}
	else
		printf("%lld",2*n);
	return 0;
} 

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static int[] a;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        a = new int[N];
        for (int i=0;i<N;i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        long ans = 0L;
        Arrays.sort(a);
        // System.out.println(Arrays.toString(a));
        for (int i=0;i<N;i++) {
            for (int j=i+1;j<N;j++) {
                ans += binary_search(a[i]+a[j])-j-1;
                // System.out.println("N: " + N + "binary: " + (binary_search(a[i]+a[j])-j-1));
                // ans += N;
            }
        }
        System.out.println(ans);
    }
    public static boolean isOK(int index, int key) {
        if (a[index] >= key) return true;
        else return false;
    }

    public static int binary_search(int key) {
        int left = -1;
        int right = a.length;

        while (right - left > 1) {
            int mid = left + (right - left) / 2;

            if (isOK(mid, key)) right = mid;
            else left = mid;
        }
        return right;
    }
}


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

int A, B, C, D;
int op[3] = {0};                // 0: -, 1: +

int calc() {
    int res = 0;
    res = op[0] ? res + A + B : res + A - B;
    res = op[1] ? res + C : res - C;
    res = op[2] ? res + D : res - D;
    return res;
}

bool dfs(int idx, int opn) {
    op[idx] = opn;
    if (idx == 0) {
        if (dfs(1, 0)) return true;
        else if (dfs(1, 1)) return true;
        else return false;
    } else if (idx == 1) {
        if (dfs(2, 0)) return true;
        else if (dfs(2, 1)) return true;
        else return false;
    } else if (idx == 2) {
        if (calc() == 7) return true;
        else return false;
    }
    return false;
}

int main() {
    string S;
    cin >> S;
    A = int(S[0] - '0');
    B = int(S[1] - '0');
    C = int(S[2] - '0');
    D = int(S[3] - '0');
    if (dfs(0, 0)) {}
    else if (dfs(0, 1)) {}
    char res[10] = {0};
    res[0] = S[0];
    res[1] = op[0] ? '+' : '-';
    res[2] = S[1];
    res[3] = op[1] ? '+' : '-';
    res[4] = S[2];
    res[5] = op[2] ? '+' : '-';
    res[6] = S[3];
    res[7] = '=';
    res[8] = '7';
    cout << res << endl;
    return 0;
}


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

void solveTestCase()
{
	int x, n;
	cin >> x >> n;

	if(n == 0)
	{
		cout << x << endl;
		return ;
	}

	vector<int>v(n);

	unordered_map < int, int > mp;

	for(int i=0; i<n; i++){
		cin >> v[i];
		mp[v[i]] += 1;
	}

	int ma = *max_element(v.begin(), v.end());
	int mi = *min_element(v.begin(), v.end());

	for(int i=0; i<=max(abs(ma-x),abs(mi-x))+1; i++)
	{
		if(mp.find(x-i) == mp.end()){
			cout << (x-i) << endl;
			return ;
		}
		else if (mp.find(x+i) == mp.end()){
			cout << (x+i) << endl;
			return ;
		}

	}

	/*for(int i=0; i<n; i++)
	{
		if(ans > abs(x-v[i]))
		{
			ans = abs(x - v[i]);
			ele = v[i];
		}
		if(ans == abs(x-v[i])){
			if(ele > v[i])
				ele = v[i];
		}
	}

	cout << ele << endl;*/
}

int32_t main()
{

	solveTestCase();

	return 0;

}

Measured memory_bytes: 3632
K, A, B = map(int, input().split())

if B - A <= 2:
    ans = K + 1
else:
    ans = A
    K -= A - 1
    if K % 2 == 1:
        ans += 1
        K -= 1
    ans += (B-A) * (K//2)

print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
    int n;
    cin >> n;
    cout << n << ":";
    int lim = sqrt(n);
    for (int i = 2; i <= lim; i++) {
        while (n % i == 0) {
            cout << " " << i;
            n /= i;
        }
    }
    if (n != 1) cout << " " << n;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3088
# hmm...
from sys import setrecursionlimit
setrecursionlimit(10000000)

n = int(input())
xds = [tuple(map(int, input().split())) for _ in range(n)]
xds.sort()

xds.insert(0, (-1000000001, 2000000004))
n += 1

def make_blocks(i):
    x, d = xds[i]
    right = x + d
    res = []
    nexti = i + 1
    while(nexti < n):
        xn, dn = xds[nexti]
        if xn < right:
            l, lasti = make_blocks(nexti)
            res.append(l)
            nexti = lasti + 1
        else:
            return res, nexti - 1
    return res, n - 1

l, _ = make_blocks(0)

def count(l):
    ans = 1
    for ll in l:
        ans = ans * (1 + count(ll)) % 998244353
    return ans

print(count(l))


Measured memory_bytes: 244600
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int N;
    int[] P, T;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        P = new int[N + 1];
        T = new int[N + 1];
        P[0] = T[0] = 0;
        for (int i = 1; i <= N; i++) {
            scanf("%d %d\n", &P[i], &T[i]);
        }
        return true;
    }
    int dist(int a, int b) {
        return abs(P[a] - P[b]);
    }
    void solve() {
        auto dp = new int[][](4, N + 1);
        foreach (ref L; dp) L[] = int.max / 2;
        dp[0][0] = 0;
        dp[1][1] = T[1] < P[1] ? int.max / 2 : P[1];
        for (int j = 1; j <= N; j++) {
            for (int i = 1; i <= 3; i++) {
                int ntime = T[j - 1] + dist(0, j - 1) * (i + 1) + dist(0, j) * 1;
                if (ntime <= T[j]) {
                    dp[1][j] = min(dp[1][j], dp[i][j - 1] + dist(0, j - 1) + dist(0, j));
                }
            }
            for (int i = 2; i <= 3; i++) {
                int ntime = T[j - 1] + dist(j - 1, j) * i;
                if (ntime <= T[j]) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + dist(j, j - 1));
                }
            }
        }
        //foreach (L; dp) L.map!"a == int.max / 2 ? -1 : a".writeln;
        //writeln;
        for (int j = N; j >= 0; j--) {
            int X = int.max / 2;
            for (int i = 0; i <= 3; i++) {
                X = min(X, dp[i][j]);
            }
            if (X < int.max / 2) {
                if (j == N) {
                    writeln("OK ", X + P[N]);
                } else {
                    writeln("NG ", j + 1);
                }
                break;
            }
        }
    }
    while (input) solve;
}

Measured memory_bytes: 1064
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;

void base_number(int n) {
	if (n == 1) {
		printf("1");
		return;
	}
	if (n % (-2) == 0) {
		base_number(n / (-2));
		printf("%d", n % (-2));
	}
	else {
		if (n % (-2) == 1) {
			base_number(n / (-2));
			printf("%d", n % (-2));
		}
		else {
			base_number(n / (-2) + 1);
			printf("1");
		}
	}
}

int main(void) {
	int n;
	cin >> n;
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}
	base_number(n);
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
S = input()
WE = [[] for _ in range(n)]
w = 0
e = 0

for i in range(n):
    if S[i] == "W":
        w += 1
    else:
        e += 1
    
    WE[i].append(w)
    WE[i].append(e)
    
ans = WE[n-1][1] - WE[0][1]

for i in range(1,n):
    res = WE[i-1][0] + (WE[n-1][1] - WE[i][1])
    ans = min(ans,res)
    
print(ans)

Measured memory_bytes: 48208
#include <stdio.h>

int main( void ) {
	int i, a, b, first = 1, exist;

	while ( scanf( "%d %d", &a, &b ), a ) {
		if ( !first )
			putchar( '\n' );

		exist = 0;
		for ( i = ( a - 1 ) / 4 * 4 + 4; i <= b; i += 4 )
			if ( !( i % 4 ) && i % 25 || !( i % 400 ) ) {
				printf( "%d\n", i );

				exist = 1;
			}
		if ( !exist )
			puts( "NA" );

		first = 0;
	}

	return 0;
}

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int a, b;
	cin >> a >> b;
	rep (i, 1e5) {
	  if (i * 8 / 100 == a && i * 10 / 100 == b) {
		cout << i << endl;
		return 0;
	  }
	}
	cout << -1 << endl;
	
    return 0;
}



Measured memory_bytes: 3648
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int[] cards;
    int n, m;

    void run(){
	//while(sc.hasNext()){
	    n = sc.nextInt();
	    cards = new int[2*n];
	    for(int i=0; i<cards.length; i++)
		cards[i] = i+1;
	    m = sc.nextInt();

	    for(int i=0; i<m; i++){
		//show();
		int k = sc.nextInt();
		if(k==0) rif();
		else cut(k);
	    }

	    for(int i=0; i<cards.length; i++)
		System.out.println(cards[i]);
	    //}
    }

    void rif(){
	int[] s = new int[2*n];
	for(int i=0; i<2*n; i++)
	    s[i] = cards[i];

	int a = 0;
	for(int i=0; i<2*n; i+=2){
	    cards[i] = s[a];
	    a++;
	}
	for(int i=1; i<2*n; i+=2){
	    cards[i] = s[a];
	    a++;
	}
    }

    void cut(int k){
	int[] s = new int[2*n];
	for(int i=0; i<2*n; i++)
	    s[i] = cards[i];

	int a = k;
	for(int i=0; i<2*n; i++){
	    cards[i] = s[a];
	    a++;
	    if(a==2*n) a = 0;
	}
    }

    void show(){
	for(int i=0; i<cards.length; i++)
	    System.out.println(cards[i]);
	System.out.println("------------");
    }
}

Measured memory_bytes: 23648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long LL;

constexpr long long INFLL = 1e18;

using namespace std;

int main()
{
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p.at(i);
    }
    for (int i = 0; i <= n; i++)
    {
        if (find(p.begin(), p.end(), x - i) == p.end())
        {
            cout << x - i << endl;
            return 0;
        }

        if (find(p.begin(), p.end(), x + i) == p.end())
        {
            cout << x + i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3168
#include<cstdio>
#include<algorithm>
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define per(i,x,y) for(int i=(x);i>=(y);--i)
const int N=1e5+10,M=2e5+10;
int n,m,cnt,path[N];
struct Graph{
	int tot,head[N],to[M],next[M],vis[N];
	void ins(int a,int b){to[++tot]=b;next[tot]=head[a];head[a]=tot;}
	void addedge(int a,int b){ins(a,b);ins(b,a);}
	void dfs(int k){
		path[++cnt]=k;
		vis[k]=1;
		for(int p=head[k];p;p=next[p])if(!vis[to[p]]){dfs(to[p]);break;}
	}
}G;
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,m){int a,b;scanf("%d%d",&a,&b);G.addedge(a,b);}
	G.vis[G.to[1]]=G.vis[G.to[2]]=1;
	G.dfs(G.to[1]);
	std::reverse(path+1,path+1+cnt);
	G.dfs(G.to[2]);
	printf("%d\n",cnt);
	rep(i,1,cnt)printf("%d ",path[i]);
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n , x) for (int i = (int)(x); i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 1; --i)
#define repBX(i, n , x) for (int i = (int)(n); i >= int(X); --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    char C;
    cin >> C;
    cout << (char)(C + 1) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<char> a(3);
  vector<char> b(3);
  int ans=0;
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
    for(int i=0;i<3;i++){
    cin>>b[i];
  }
    for(int i=0;i<3;i++){
    if(a[i]==b[i]){
      ans++;
    }
    }
      cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <functional>
#include <random>
using namespace std;
#define Would
#define you

const int MOD = 1e9 + 7;
const int INF = 999999999;

int a, b, c;
map<int, int>ma;
int main() {
	Would you cin >> a;
	for (int i = 0; i < a; ++i) {
		Would you cin >> c;
		++ma[c];
	}
	Would you cin >> b;
	for (int i = 0; i < b; ++i) {
		Would you cin >> c;
		--ma[c];
		if (ma[c] < 0) {
			Would you cout << "NO" << endl;
			return 0;
		}
	}
	Would you cout << "YES" << endl;
}

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

int main() {
	for (int i = 0; i < 9; ++i) {
		for (int j = 0; j < 9; ++j) {
			cout << i + 1 << 'x' << j + 1 << '=' << (i + 1)*(j + 1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3084
using System;
using System.Collections.Generic;
using System.Linq;

public class Program {
	public static void Main() {
		new Calc().calc();
	}
	public class Calc {
		public Calc() { }
		public void calc() {
			long N = long.Parse(Console.ReadLine());
			int ans = N.ToString().Length;
			for (long i = (long)Math.Sqrt(N); i > 1; i--) {
				long am;
				long dv = Math.DivRem(N, i, out am);
				if (am == 0){
					ans = dv.ToString().Length; break;
				}
			}
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 13140
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
int a[100010], b[100010];
int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<int> ind(N);

    FOR(i,0,N) ind[i] = i;
    FOR(i,0,N){
        cin >> a[i] >> b[i];
    }
    //小さい順
    sort(ind.begin(), ind.end(), [](int i, int j){
        return a[i] < a[j];
    });
    ll k = 0;
    int i = 0;
    while(1){
        if(k<K && K<=k+b[ind[i]]){
            cout << a[ind[i]] << endl;
            return 0;
        }
        k += b[ind[i]];
        i++;
    }
}


Measured memory_bytes: 1408
#include <iostream>

int func(int a, int b, int c){
    int ans= 0;
    int sum = c;
    while(c > 0){
        ans += c % 10;
        c /= 10;
    }
    if (a <= ans && ans <= b) return sum;
    return 0;
}

int main () {
    int n, a, b, c, ans = 0;
    std::cin >> n >> a >> b;
    
    for(int i = 0; i <= n; ++i) {
        ans += func(a, b, i);
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 3620
import math
n,d=map(int,input().split())
v=[list(map(int,input().split())) for i in range(n)]
e=0
for i in range(n-1):
    for j in range(i+1,n):
        c=0
        for g in range(d):
            c+=abs(v[i][g]-v[j][g])**2
        if math.sqrt(c)%1==0:
            e+=1
print(e)

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <queue>
#define ll long long
using namespace std;
const ll MAx = 1e5+5;

ll n, m, num, temp, x, y;
ll head[MAx], col[MAx], cnt[3];
struct node{
	ll ne, to;
}e[MAx<<1];
queue <ll> q;

void add(ll fr, ll to){
	e[++num].ne = head[fr]; e[num].to = to;
	head[fr] = num;
}

int bfs(){
	for(ll i = 1;i <= n;i++){
		if(!col[i]){
			col[i] = 1; temp++; q.push(i);
			cnt[col[i]]++;
			while(!q.empty()){
				ll u = q.front(); q.pop();
				for(ll j = head[u];j;j = e[j].ne){
					ll v = e[j].to;
					if(!col[v])
						col[v] = 3-col[u] , temp++,
						q.push(v), cnt[col[v]]++;
					else if(col[v] == col[u]) return 0;
				}
			}
		}
		if(temp == n) break;
	}
	return 1;
}

int main(){
	scanf("%lld%lld", &n, &m);
	for(int i = 1;i <= m;i++){
		scanf("%lld%lld", &x, &y);
		add(x, y); add(y, x);
	}
	if(bfs()) printf("%lld", cnt[1]*cnt[2]-m);
	else printf("%lld", n*(n-1)/2-m);
	return 0;
}

Measured memory_bytes: 5376
#include <vector>
#include <algorithm>
#include <limits.h>
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#define MOD 1000000007
typedef  long long int  lli;
using namespace std;
int main() {
    int a; cin>>a;
    cout<<a+(a*a)+(a*a*a)<<"\n";
    return 0;
}

Measured memory_bytes: 3576
N, K = map(int, input().split())
teleporters = list(map(int, input().split()))
n = 0
present = 0
praces = [-1 for i in range(N)]
praces[0] = 0
for i in range(K):
  present = teleporters[present] - 1
  n += 1
  if praces[present] == -1:
    praces[present] = n
  else:
    before = praces[present]
    loop = n - before
    remainder = (K - before) % loop
    present = praces.index(before + remainder)
    break
print(present + 1)

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

const int N = 500005;
string w;
int n;
int pre[N], gpre[N];
int suf[N], gsuf[N];

void check() {
	for (int i = 1; i < n; ++i) if (w[i] != w[0]) return;
	printf("%d\n1\n", n);
	exit(0);
}

void calc(int Z[], int G[]) {
	int L = -1, R = -1;
	for (int i = 1; i < n; ++i) {
		if (R < i) {
			L = R = i; while(R < n && w[R] == w[R - L]) ++R;
			Z[i] = R - L; --R;
		} else {
			int k = i - L;
			if (Z[k] < R - i + 1) Z[i] = Z[k];
			else {
				L = i; while(R < n && w[R] == w[R - L]) ++R;
				Z[i] = R - L; --R;
			}
		}
	}

	for (int i = 0; i < n; ++i) G[i] = true;
	for (int i = 1; i < n; ++i) {
		for (int j = i + i; j <= Z[i] + i; j += i) G[j - 1] = false;
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> w;
	n = w.size();
	check();

	calc(pre, gpre);
	reverse(w.begin(), w.end());
	calc(suf, gsuf);

	// check whether w is a good string or not
	if (gpre[n - 1]) return printf("1\n1\n"), 0;

	int ans = 0;
	for (int i = 0; i < n - 1; ++i) if (gpre[i] && gsuf[n - i - 2]) ++ans;
	printf("2\n%d\n", ans);
}

Measured memory_bytes: 8732
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
typedef pair<int,int> pii;
map<pii,int> mp;
int h=read(),w=read(),n=read(),cnt[10];

int main(){
int i,j;
for (;n--;){
  int x=read(),y=read();
  for (i=max(1,x-2);i<=min(h-2,x);++i){
    for (j=max(1,y-2);j<=min(w-2,y);++j){
      mp[pii(i,j)]++; 
	  }
	}
  }
for (auto p:mp) cnt[p.second]++,n++;
ll ans=1ll*(h-2)*(w-2);
write(ans-n-1),pl;
for (i=1;i<=9;++i) write(cnt[i]),pl;
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  int ans = 0;
  int prev = -1;
  int cur = 0;
  for (int i = 0; i < N; i++) {
    int h; cin >> h;
    if (i > 0) {
      if (prev >= h) {
	cur += 1;
      }else {
	ans = max(ans, cur);
	cur = 0;
      }
      prev = h;
    }else {
      prev = h;
    }
  }
  ans = max(ans, cur);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> N >> K;
	vector<long long int>num(K + 1);
	long long int ans = 0;
	for (int i = K; i > 0; i--) {
		long long int add = power(K/i, N, MOD);
		for (int j = i * 2; j <= K; j += i) {
			add += MOD - num[j];
			add %= MOD;
		}
		num[i] = add;
		ans += add * i;
		ans %= MOD;
	}
	cout << ans << endl;
}


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

typedef long long ll;

const long double PI = (acos(-1));

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

  string s;
  cin >> s;

  if (s == "Sunny"){
    cout << "Cloudy" << endl;
  }else if (s == "Cloudy"){
    cout << "Rainy" << endl;
  }else {
    cout << "Sunny" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define vi vector<int>
#define vl vector<ll>
#define inarr(a,n) for(ll i=0;i<n;i++)cin>>a[i]
int main(){
    int a,b,c,d,e;
    string s;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    
}


Measured memory_bytes: 764
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

map<tuple<ll,ll,ll>,ll> memo;

ll solve(ll a,ll b, ll tar){
  if(a<=0 && b<=0 && tar<=0)return 0;
  if(memo.count(mt(a,b,tar)))return memo[mt(a,b,tar)];

  ll res=LINF;
  if(tar%2 != (a%2 ^ b%2)){
    res=LINF;
  }else{
    chmin(res,solve(a/2,b/2,tar/2)*2);
    chmin(res,solve((a-1)/2,(b+1)/2,tar/2)*2 +1);
  }

  memo[mt(a,b,tar)]=res;
  return res;
}

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  ll a,b,tar=0;
  cin>>a>>b;
  rep(i,2,n){
    ll x;cin>>x;
    tar^=x;
  }

  ll tmp=solve(a,b,tar);
  if(tmp<LINF && tmp!=a)cout<<tmp<<ENDL;
  else cout<<-1<<ENDL;
  
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e3 + 17;

int n, m, q;
int a[maxn][maxn], e1[maxn][maxn], e2[maxn][maxn];
int sum_a[maxn][maxn], sum_e1[maxn][maxn], sum_e2[maxn][maxn];

bool read()
{
	if (scanf("%d %d %d", &n, &m, &q) != 3)
		return false;

	forn (i, n)
	{
		scanf("%s", buff);

		forn (j, m)
			a[i + 1][j + 1] = buff[j] - '0';
	}

	return true;
}

void calc(int c[][maxn], int sum[][maxn])
{
	for (int i = 1; i <= n; ++i)
	{
		int cur = 0;

		for (int j = 1; j <= m; ++j)
		{
			cur += c[i][j];
			sum[i][j] = sum[i - 1][j] + cur;
		}
	}
}

void solve()
{
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (a[i][j])
			{
				if (a[i - 1][j])
					e1[i][j] = 1;

				if (a[i][j - 1])
					e2[i][j] = 1;
			}

	calc(a, sum_a);
	calc(e1, sum_e1);
	calc(e2, sum_e2);

	forn (j, q)
	{
		int x, y, X, Y;
		scanf("%d %d %d %d", &x, &y, &X, &Y);
		int v = sum_a[X][Y] + sum_a[x - 1][y - 1] - sum_a[X][y - 1] - sum_a[x - 1][Y], e = 0;
		e += sum_e1[X][Y] + sum_e1[x][y - 1] - sum_e1[X][y - 1] - sum_e1[x][Y];
		e += sum_e2[X][Y] + sum_e2[x - 1][y] - sum_e2[X][y] - sum_e2[x - 1][Y];
		printf("%d\n", v - e);
	}
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 97792
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main{
    //WRWWRWRR     wwwrrrrwwwwrrr
    ///112 112
    ///1223 12

    int mod = (int) 1e9+7;
    public void solve(int testNumber, InputReader in, PrintWriter out) {

    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(new InputStreamReader(System.in));
        //long n = Long.parseLong(scanner.nextLine());
        int n = scanner.nextInt();
        int mod = (int) 1e9+7;
        long[] dp = new long[n+1];
        //dp[3] = 1;
        for(int i=3;i<=n;i++) dp[i] = 1;
        for(int i=3;i<=n;i++){
            for(int j=3;j<=i;j++){
                if(i-j<3) continue;
                dp[i] += dp[j];
                dp[i]%=mod;
            }
        }
        System.out.println(dp[n]);

    }
    //	public static void main(String[] args){
//        InputStream inputStream = System.in;
//        OutputStream outputStream = System.out;
//        InputReader in = new InputReader(inputStream);
//        PrintWriter out = new PrintWriter(outputStream);
//        Main solver = new Main();
////        int num = in.nextInt();
////        while(num-->0){
////            solver.solve(1, in, out);
////        }
//        solver.solve(1, in, out);
//        out.close();
//    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 36076
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,k,q;
    cin >> n >> k >> q;
    vi a(n);
    cin >> a;
    auto g = [&](vi v)->vi {
        int sz = v.size();
        if(sz < k) return {};
        sort(all(v));
        vi res;
        rep(i,sz-k+1) res.pb(v[i]);
        return res;
    };
    auto f = [&](int y) {
        vi can;
        vi now;
        rep(i,n) {
            if(a[i] >= y) now.pb(a[i]);
            else {
                auto temp = g(now);
                can.insert(can.end(),all(temp));
                now.clear();
            }
        }
        auto temp = g(now);
        can.insert(can.end(),all(temp));
        if(can.size() < q) return -1;
        sort(all(can));
        return can[q-1];
    };
    vi b = a;
    sort(all(b));
    int ans = inf;
    for(int i : b) {
        int x = f(i);
        if(x == -1) continue;
        chmin(ans,x-i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3696
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

	int array[5];
	scanf("%d %d %d %d %d",&array[0],&array[1],&array[2],&array[3],&array[4]);

	for(int i=1;i<=4;i++){
		for(int k=4;k>=i;k--){
			if(array[k]>array[k-1])swap(array[k],array[k-1]);
		}
	}

	for(int i=0;i<4;i++)printf("%d ",array[i]);
	printf("%d\n",array[4]);

    return 0;
}



Measured memory_bytes: 3220
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)



int main(void)
{
    string A, B;
    cin >> A >> B;
    if(A.length() > B.length())
        cout << "GREATER" << endl;
    else if(A.length() < B.length())
        cout << "LESS" << endl;
    else if(A.length() == B.length()){
        if(A > B)
            cout << "GREATER" << endl;
        else if(A < B)
            cout << "LESS" << endl;
        else if(A == B)
            cout << "EQUAL" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 

int main(){
	int N;
  	cin >> N;
  	map<string, int> mp;
  	for(int i=0; i<N; i++){
      string s;
      cin >> s;
      mp[s]++;
    }
  
  	for(string x : {"AC", "WA", "TLE", "RE"}){
      cout << x << " x " << mp[x] << endl;
    }

}


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


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


    vector<vector<int>> a(n,vector<int>(3));


    for(int x=0;x<n;x++)
    {
        cin>>a[x][0]>>a[x][1]>>a[x][2];
    }

    vector<vector<long long>> dp(n,vector<long long>(3));
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    // cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl;
    for(int x=1;x<n;x++)
    {
        dp[x][0]=a[x][0]+max(dp[x-1][1],dp[x-1][2]);
        dp[x][1]=a[x][1]+max(dp[x-1][0],dp[x-1][2]);
        dp[x][2]=a[x][2]+max(dp[x-1][0],dp[x-1][1]);

        // cout<<dp[x][0]<<" "<<dp[x][1]<<" "<<dp[x][2]<<endl;
    }




    int ans=max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);

    cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VL vector<LL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e18;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    /*
    int t,n;
    cin>>t;
    loop(t1,1,t+1)
    {
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    int n;
    cin>>n;
    LL a[n], b[n];
    loop(i,0,n) cin>>a[i]>>b[i];
    sort(a,a+n);
    sort(b,b+n);

    LL mn, mx;
    if(n & 1)
    {
        mn = a[n/2];
        mx = b[n/2];
    }
    else
    {
        mn = a[(n/2)-1] + a[n/2];
        mx = b[(n/2)-1] + b[n/2];
    }

    LL ans = mx - mn + 1;
    cout<<ans<<'\n';

    /*
    if(f) cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
    */

    return 0;
}


Measured memory_bytes: 6732
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    string s;
    cin >> s;
    string ans;
    rep(i,s.size()) {
        char c = s[i];
        if(c == '0') ans += "0";
        else if(c == '1') ans += "1";
        else {
            if(ans.size() != 0) ans = ans.substr(0,ans.size()-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256