akhauriyash/Code-Regression huggingface dataset:
def resolve():
    import collections
    S = input()
    Q = int(input())

    query_list = [input().split() for _ in range(Q)]

    T_cnt_list = collections.deque([0])
    left = ''
    right = ''

    for i, query in enumerate(query_list):
        if query[0] == '1':
            T_cnt_list.append(1+T_cnt_list[-1])

        else:
            T_cnt_list.append(T_cnt_list[-1])

            if query[1] == '1' and T_cnt_list[i+1]%2 == 0:
                left = query[2] + left

            elif query[1] == '1' and T_cnt_list[i+1]%2 == 1:
                right = right + query[2]

            elif query[1] == '2' and T_cnt_list[i+1]%2 == 0:
                right = right + query[2]

            elif query[1] == '2' and T_cnt_list[i+1]%2 == 1:
                left = query[2] + left

    if T_cnt_list[-1]%2 == 0:
        print(left + S + right)
    else:
        print(right[::-1] + S[::-1] + left[::-1])

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 44368
(format t "~A~%"
(let* ((pick 101)
       (sum (loop repeat (read)
                  for i = (read) then (read)
                  sum i
                  do (when (and (/= 0 (mod i 10))
                                (> pick i))
                       (setf pick i)))))
  (if (zerop (mod sum 10))
      (if (= pick 101)
          0
          (- sum pick))
      sum)))

Measured memory_bytes: 6504
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,x;
unordered_set<int>SET;
unordered_map<int,int>byk;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin>>n;
    for(int i=1;i<=n;i++){
        int x; cin>>x;
        SET.insert(x);
        byk[x]++;
    
    }
    if(SET.size()==1 && SET.count(0)!=0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(n%3==0){
        if(SET.size()==2){
            if(byk[0]==n/3){
                cout<<"Yes"<<endl;
                return 0;
            }

        }
        else if(SET.size()==3){
            int bil=0;
            for(auto isi : SET){
                bil^=isi;
            }
            if(bil!=0){
                cout<<"No"<<endl;
                return 0;
            }
            int banyak=n/3;
            int cnt=0;
            for(auto isi:SET){
                if(byk[isi]==banyak) cnt++;
            }
            if(cnt==3){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;
}

Measured memory_bytes: 7112
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	string s;
	cin>>s;
	int ans1=0,ans2=0;
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			if(s[i]!='0'){
				ans1++;
			}
		}
		else{
			if(s[i]!='1'){
				ans1++;
			}
		}
	}
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			if(s[i]!='1'){
				ans2++;
			}
		}
		else{
			if(s[i]!='0'){
				ans2++;
			}
		}
	}
	cout<<min(ans1,ans2)<<endl;
}

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

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

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

	int min = *min_element(x.cbegin(), x.cend());
	int max = *max_element(x.cbegin(), x.cend());

	int load = max+1 - min;
	vector<int> v(load);

	for (int i = 0; i < load; ++i) {
		v.at(i) = min + i;
	}

	vector<int> consumption(load);
	for (int i = 0; i < load; ++i) {
		int kuso = 0;
		for (auto t : x) {
			kuso += pow(t - v.at(i), 2);
		}
		consumption.at(i) = kuso;
	}

	int result = *min_element(consumption.cbegin(), consumption.cend());

	cout << result;
}

Measured memory_bytes: 256
N,C=map(int, input().split())
inl = [tuple(map(int, input().split())) for i in range(N)]
inl.sort()

res = 0
st = set()
for s,t,c in inl:
    nx = set()
    for t1, c1 in st:
        if not (t1 == s and c == c1) and t1 >= s:
            nx.add((t1,c1))
    nx.add((t,c))
    st = nx
    res = max(len(nx), res)

print(res)


Measured memory_bytes: 17748
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}

int main() {
	string s; cin >> s;
	rep(i, s.size()) {
		if (s.at(i) == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final String title = sc.next(); // 3 <= N <=25
        int count = 0;
        for(int i = 0; i < N; ++i)
        {
            final String old = sc.next();
            if(creatable(title, old))
            {
                ++count;
            }
        }
        System.out.println(count);
    }

    private static boolean creatable(final String title, final String old)
    {
        for(int first = old.indexOf(title.charAt(0)); first < old.length() && first != -1; first = old.indexOf(title.charAt(0), first + 1))
        {
            for(int second = old.indexOf(title.charAt(1), first + 1); second < old.length() && second != -1; second = old.indexOf(title.charAt(1), second + 1))
            {
                final int first_second_dif = second - first;
                int backpoint = second;
                for(int seek = 2, tail = old.indexOf(title.charAt(seek), second + 1); seek < title.length() && tail < old.length() && tail != -1; tail = old.indexOf(title.charAt(seek), tail + 1))
                {
                    if(first_second_dif == tail - backpoint)
                    {
                        if(seek == title.length() - 1)
                        {
                            return true;
                        }
                        backpoint = tail;
                        ++seek;
                    }
                }
            }
        }
        return false;
    }
}

Measured memory_bytes: 20280
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
a = na()

dp = [[-1] * (n + 1) for _ in range(61)]
for i in range(n):
    dp[0][i] = a[i] - 1
for i in range(60):
    for j in range(n):
        dp[i + 1][j] = dp[i][dp[i][j]]

cur = 0
for i in range(60, -1, -1):
    if k & (1 << i):
        cur = dp[i][cur]

print(cur + 1)

Measured memory_bytes: 174792
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    while(true){
        cin >> H >> W;
        if(H==0 && W==0) break;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cout << "#";
            }
            cout << endl; 
        }
        cout << endl;
    }
}



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

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

int main(){
    string s, t; cin >> s >> t;
    int len_s = s.size(), len_t = t.size();
    vector<vector<int>> dp(len_s + 10, vector<int>(len_t + 10, 0));
    vector<vector<pair<int, int>>> revert(len_s + 10, vector<pair<int, int>>(len_t + 10, pair<int, int>(0, 0)));
    rep(i, len_s + 1)rep(j, len_t + 1){
        //deliver to right
        if (dp[i][j] >= dp[i + 1][j]){
            dp[i + 1][j] = dp[i][j];
            revert[i + 1][j] = pair<int, int>{i, j};
        }
        //deliver to down
        if (dp[i][j] >= dp[i][j + 1]){
            dp[i][j + 1] = dp[i][j];
            revert[i][j + 1] = pair<int, int>{i, j};
        }
        //deliver to oblique
        if (s[i] == t[j]){
            if (dp[i][j] + 1 >= dp[i + 1][j + 1]){
                dp[i + 1][j + 1] = dp[i][j] + 1;
                revert[i + 1][j + 1] = pair<int, int>{i, j};
            }
        }
    }
    string ans = "";
    int si = len_s, ti = len_t;
    while(!(si == 0 and ti == 0)){
        pair<int, int> rev = revert[si][ti];
        if (rev.first == si - 1 and rev.second == ti - 1){
            ans = s[rev.first] + ans;
        }
        si = rev.first;
        ti = rev.second;
    }
    cout << ans << endl;
}


Measured memory_bytes: 106624
def max(a, b)
  a > b ? a : b
end
N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i)

rui = Array.new(N, 0)
N.times do |i|
  rui[i] += rui[i-1] + (1.0 + P[i]) / 2
end
rui.unshift(0)

ans = 0
K.upto(N) do |i|
  ans = max(ans, rui[i] - rui[i-K])
end
puts ans

Measured memory_bytes: 17284
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
b=[]
for i in range(m-1):
  b.append(a[i+1]-a[i])
b.sort(reverse=True)
if n>=m:
  print(0)
else:
  print(sum(b[n-1:]))


Measured memory_bytes: 13960
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#define F first
#define S second
using namespace std;

int n, m, i;
pair < int, int > p[222];
int memo[222];

int solve(int k){
  
  if(memo[k]) return memo[k];
  
  int ret = 1;
  for(int i=0;i<n+m;i++){
    if(p[k].F > p[i].F && p[k].S > p[i].S) ret = max(ret, solve(i)+1);
  }

  return memo[k] = ret;
}

int main(){
  
  while(cin >> n, n){
    
    for(i=0;i<n;i++) cin >> p[i].F >> p[i].S;
    cin >> m;  
    for(;i<m+n;i++) cin >> p[i].F >> p[i].S;
    
    memset(memo, 0, sizeof(memo));
    
    int ans = 0;
    for(int j=0;j<n+m;j++) ans = max(solve(j), ans);

    cout << ans << endl;
  }
  
}

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

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

int main(){
	int a,b,c;
	vector<int> s(10000);
	cin >> a >> b >> c;
	int n;
	n=gcd(a,b);
    int factor;
    factor = 1;
    int i = 0;
    while(factor <= n)
    {
        if( n%factor == 0 )
        {
        	i=i+1;
        	s[i] = factor;
        }
        factor = factor+1;
    }
    cout << s[i-c+1];
	return 0;
}

Measured memory_bytes: 384
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  int n; cin>>n;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  ll an = 0, mx = 0;
  for(int i=0;i<n;i++) {
    mx = max(a[i], mx);
    an+=mx-a[i];
  }
  cout<<an<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 5192
#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <math.h>
#include <vector>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB")
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Railway Connection
public class Main{

	int N, M, C, S, G, INF = 1<<29;
	int[][][] wf;
	int[][] cost;
	int[] p, dist;
	int[][] q, r, e;
	
	void run(){
		Scanner sc = new Scanner(System.in);
		wf = new int[21][101][101];
		cost = new int[21][20001];
		for(;;){
			N = sc.nextInt(); M = sc.nextInt(); C = sc.nextInt(); S = sc.nextInt(); G = sc.nextInt();
			if((N|M|C|S|G)==0)break;
			for(int c=1;c<=C;c++)for(int i=1;i<=N;i++)for(int j=1;j<=N;j++)wf[c][i][j]=INF;
			for(int c=1;c<=C;c++)for(int i=1;i<=N;i++)wf[c][i][i]=0;
			for(int c=1;c<=C;c++)for(int i=0;i<=20000;i++)cost[c][i]=0;
			while(M--!=0){
				int s = sc.nextInt(), t = sc.nextInt(), d = sc.nextInt(), c = sc.nextInt();
				wf[c][s][t] = wf[c][t][s] = Math.min(wf[c][s][t], d);
			}
			for(int c=1;c<=C;c++){
				for(int k=1;k<=N;k++)for(int i=1;i<=N;i++)for(int j=1;j<=N;j++)wf[c][i][j]=Math.min(wf[c][i][j], wf[c][i][k]+wf[c][k][j]);
			}
			p = new int[C+1];
			q = new int[C+1][55];
			r = new int[C+1][55];
			for(int c=1;c<=C;c++){
				p[c] = sc.nextInt();
			}
			for(int c=1;c<=C;c++){
				for(int i=1;i<p[c];i++)q[c][i]=sc.nextInt();
				for(int i=1;i<=p[c];i++)r[c][i]=sc.nextInt();
				int dif = r[c][1], i=1;
				for(int j=1;j<=20000;j++){
					cost[c][j] = cost[c][j-1]+dif;
					if(j==q[c][i]){
						i++;
						dif = r[c][i];
					}
				}
			}
			e = new int[N+1][N+1];
			for(int i=1;i<=N;i++)for(int j=1;j<=N;j++)e[i][j]=INF;
			for(int i=1;i<=N;i++)for(int j=1;j<=N;j++)for(int c=1;c<=C;c++)if(wf[c][i][j]!=INF)e[i][j]=Math.min(e[i][j], cost[c][wf[c][i][j]]);
			dist = new int[N+1];
			Arrays.fill(dist, INF);
			dist[S] = 0;
			PriorityQueue<Integer> que = new PriorityQueue<Integer>(N, new Comparator<Integer>() {
				public int compare(Integer i1, Integer i2) {
					return dist[i1]-dist[i2];
				}
			});
			que.add(S);
			while(!que.isEmpty()){
				int v = que.poll();
				for(int nx=1;nx<=N;nx++){
					int w = dist[v]+e[v][nx];
					if(w < dist[nx]){
						dist[nx] = w; que.add(nx);
					}
				}
			}
			System.out.println(dist[G]==INF?-1:dist[G]);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 15000
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int n;
vector<lint> sum;

template<typename T>
bool check(T mid){
    rep(i, n){
        auto it1 = lower_bound(sum.begin() + i, sum.begin() + i + n, sum[i] + mid);
        auto it2 = lower_bound(it1, sum.begin() + i + n, *it1 + mid);
        if(sum[i + n] - *it2 >= mid){
            return true;
        }
    }
    return false;
}

template<typename T>
T meguru_search(T ok, T ng){
    while(max(ok, ng) - min(ok, ng) > (T)1){
        T mid = (ok + ng) / T(2);
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

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

    cin >> n;

    sum.resize(n * 2 + 1);
    reps(i, n){
        cin >> sum[i];
        sum[i + n] = sum[i];
    }

    reps(i, n * 2){
        sum[i] += sum[i - 1];
    }

    lint ans = meguru_search(1LL, sum[n * 2]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4344
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = input[0];
            var M = input[1];

            var s = new int[M][];
            for (int i = 0; i < M; i++)
            {
                s[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            }

            for (int i = 0; i < M; i++)
            {
                if (N > 1 && s[i][0] == 1 && s[i][1] == 0)
                {
                    Console.WriteLine("-1");
                    return;
                }
                for (int j = 0; j < M; j++)
                {
                    if (s[i][0] == s[j][0] && s[i][1] != s[j][1])
                    {
                        Console.WriteLine("-1");
                        return;
                    }
                }
            }

            var c = new char[N];
            for (int i = 0; i < N; i++)
            {
                c[i] = '0';
            }
            for (int i = 0; i < M; i++)
            {
                c[s[i][0] - 1] = char.Parse(s[i][1].ToString());
            }
            if (N > 1 && c[0] == '0')
            {
                c[0] = '1';
            }
            Console.WriteLine(int.Parse(string.Join(string.Empty, c)));
        }
    }
}


Measured memory_bytes: 13524
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
A_tmp = sorted(A[1:] + A[1:],reverse=True)
ans = 0
index = 0

for i,a in enumerate(A):
    if i == 0:
        continue
    if i == 1:
        ans += A[0]
    else:
        ans += A_tmp[index]
        index += 1
print(ans)

Measured memory_bytes: 104500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;
int n;
int siz[maxn];
ll ans;
ll invbin[maxn];
vector<int> E[maxn];
ll powMod(ll a, ll k)
{
	ll ret = 1;
	while(k)
	{
		if(k & 1) ret = ret * a % mod;
		a = a * a % mod; k >>= 1;
	}
	return ret;
}
ll inv(ll x) { return powMod(x, mod - 2);}
ll norm(ll x) { return (x % mod + mod) % mod;}
void dfs(int x, int fa)
{
	vector<int> a;
	siz[x] = 1;
	for(auto v : E[x])
		if(v != fa)
		{
			dfs(v, x);
			siz[x] += siz[v];
			a.push_back(siz[v]);
		}
	a.push_back(n - siz[x]);
	ll tmp = norm(1 - invbin[n - 1]);
	for(auto v : a)
		tmp = norm(tmp - norm(1 - invbin[v]) * invbin[n - 1 - v] % mod);
	tmp = tmp * invbin[1] % mod;
	ans = norm(ans + tmp);
}
void pre()
{
	invbin[0] = 1;
	ll inv2 = inv(2);
	for(int i = 1; i < maxn; ++i) invbin[i] = invbin[i - 1] * inv2 % mod;
}
int main()
{
	pre();
	scanf("%d", &n);
	for(int i = 1; i < n; ++i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1, 0);
	printf("%lld\n", ans);
	return 0;
}
	

Measured memory_bytes: 29312
#include <iostream>
using namespace std;
int main(void){
    int m;
    cin >> m;
    long long a = -1, b = 0;
    for(int i=0;i<m;i++){
        long long d, c;
        cin >> d >> c;
        a += c;
        b += d*c;
    }
    cout << a + (b-1)/9 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define X first
#define Y second
#define mod 1e9+7
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>21)cout<<"bust"<<endl;
	else cout<<"win"<<endl; 
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer
import scala.math._

object Main {

  case class Point(grids: Vector[Int])

  def solve(sc: Scanner): String = {
    val (n, d) = (sc.nextInt(), sc.nextInt())
    val points = Vector.fill(n)(Vector.fill(d)(sc.nextInt())).map(v => Point(v))

    points.indices.foldLeft(ArrayBuffer.empty[Int]) { case (acc, i) =>
      acc += getGoodDistanceCount(points, i)
      acc
    }.sum.toString
  }

  def getGoodDistanceCount(points: Vector[Point], from: Int): Int = {
    val base = points(from)
    var count = 0
    points.slice(from + 1, points.size).foreach { p =>
      val d = getDistance(base, p)
      if (d.toInt == d) count += 1
    }
    count
  }

  def getDistance(p1: Point, p2: Point) = {
    sqrt(p1.grids.zipWithIndex.foldLeft(ArrayBuffer.empty[Double]) { case (acc, (grid, i)) =>
      acc += pow(grid - p2.grids(i), 2)
      acc
    }.sum)
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}


Measured memory_bytes: 25936
# https://atcoder.jp/contests/abc112/tasks/abc112_c


# ピラミッドの中心は必ず0-100の中にある
# Hは1以上
# 与えられる情報だけで一意に定まる

# 中心座標をa,bと置いたとき、ある点x,yにおける高さは
# h(x,y; a,b)=max(H-|x-a|-|y-b|,0)である。
# ここで、真の高さとの誤差としてe(x,y;a,b)=|h(x,y;a,b) - h(x,y;Cx,Cy)|とすると。
# 任意のx,yでe=0となるa,bが答え。しかしHはわからないので0とする。
# そうすると任意のx,yでe(x,y;a,b)=constとなるa,bが答え。(ただしmaxの扱いが面倒なのでh==0は無視して処理を行う)
# またその定数constはHである

# 座標は10**4点。Nはたかだか100なので 最悪10**6回計算。間に合う。
# あー結局全探索してるんだから問題の定義を借りて素直に実装すればバグらせずに済んだな

import numpy as np
from itertools import product

N = int(input())
X, Y, H = [], [], []
for n in range(N):
    x, y, h = list(map(int, input().split()))
    if h == 0:
        continue
    X.append(x)
    Y.append(y)
    H.append(h)

if len(H) == 1:
    print(X[-1], Y[-1], H[-1])
    exit()

X = np.array(X)
Y = np.array(Y)
H = np.array(H)


def is_ok(X, Y, H, a, b):
    height = H + np.abs(X - a) + np.abs(Y - b)
    if (height == height[-1]).all():
        return True, height[-1]
    else:
        return False, False


for a, b in product(range(101), range(101)):
    flg, ansH = is_ok(X, Y, H, a, b)
    if flg:
        ans = (a, b, ansH)

print(*ans)


Measured memory_bytes: 20628
#include <iostream>
#include<string> //文字列を使う場合
using namespace std;
int main()
{
	string s;
	int ans=0;
	cin >> s;
	if (s[0]=='1')
	{
		ans++;
	}
	if (s[1]=='1')
	{
		ans++;
	}
	if (s[2] == '1')
	{
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)

const int mod = 1e9 + 7;
int N;
bitset<60> A[300000 + 1];

int main() {
  cin >> N;
  REP(i, N) {
    int64_t x;
    cin >> x;
    A[i] = bitset<60>(x);
  }

  int64_t ans = 0;
  REP(i, 60) {
    int64_t count = 0;
    REP(j, N) {
      if (A[j].test(i)) count++;
    }
    ans += ((1LL << i) % mod) * ((count * (N - count)) % mod);
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main(){
	int a,b,c;
	scanf(" %d%d%d",&a,&b,&c);
	if(a < b && b < c){ //a<b<c
		printf("%d %d %d\n",a,b,c);
	}
	if(a < b && b > c && c > a){ //a<c<b
		printf("%d %d %d\n",a,c,b);
	}
	if(a > b && b > c){ //c<b<a
		printf("%d %d %d\n",c,b,a);
	}
	if(a < b && b > c && c < a){ //c<a<b 
		printf("%d %d %d\n",c,a,b);
	}
	if(a > b && b < c && c > a){ //b<a<c
		printf("%d %d %d\n",b,a,c);
	}
	if(a > b && b < c && c < a){ //b<c<a
		printf("%d %d %d\n",b,c,a);
	}
	if(a == b && b < c && c > a){ //a=b<c
		printf("%d %d %d\n",a,b,c);
	}
	if(a < b && b > c && c == a){ //a=c<b
		printf("%d %d %d\n",a,c,b);
	}
	if(a > b && b == c && c < a){ //b=c<a
		printf("%d %d %d\n",b,c,a);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;

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

  int N;
  cin >> N;
  vector<int> d;
  for (int i = 0; i < N; i++) {
    int buf;
    cin >> buf;
    d.push_back(buf);
  }

  if (N % 2 == 1) {
    cout << 0 << endl; // impossible
    return 0;
  }
  sort(d.begin(), d.end());
  int ans = d[N/2] - d[N/2-1];

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	char S[110];
	long long K, count = 0;
	scanf("%s%lld", S, &K);
	for (int i = 0; i < 100; i++) {
		count++;
		if (S[i] > '1' || count == K) {
			printf("%c", S[i]);
			return 0;
		}
	}
	return 0;
}

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

using namespace std;
using ll = long long int;

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

   vector<int> a(n);
   vector<int> c(n);
   for(int i=0;i<n;i++){
       int b;
       cin>>b;
       a[i] = b;
       c[i] = b;
   }

   sort(a.begin(), a.end());

   int max = a[n-1];
   int second = a[n-2];

   for(int i=0;i<n;i++){
       if(c[i] == max) cout<<second<<endl;
       else cout<<max<<endl;
   }
    return 0;

}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
int N,A,B;
int main(){
	cin>>N>>A>>B;
	cout<<min(A,B)<<" "<<max(A+B-N,0)<<endl;
}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int k;
int res;
string s;
string t;
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    cin >> s >> k;
    n = (int)s.size();
    t = string(n, '0');
    if(k == 1){
        for(int i = 0; i < n; i ++){
            for(int ni = 1; ni <= 9; ni ++){
                t[i] = (ni + '0');
                res += (t <= s);
                t[i] = '0';
            }
        }
    }
    else if(k == 2){
        for(int i = 0; i < n; i ++){
            for(int j = i + 1; j < n; j ++){
                for(int ni = 1; ni <= 9; ni ++){
                    for(int nj = 1; nj <= 9; nj ++){
                        t[i] = (ni + '0');
                        t[j] = (nj + '0');
                        res += (t <= s);
                        t[i] = t[j] = '0';
                    }
                }
            }
        }
    }
    else if(k == 3){
        for(int i = 0; i < n; i ++){
            for(int j = i + 1; j < n; j ++){
                for(int k = j + 1; k < n; k ++){
                    for(int ni = 1; ni <= 9; ni ++){
                        for(int nj = 1; nj <= 9; nj ++){
                            for(int nk = 1; nk <= 9; nk ++){
                                t[i] = (ni + '0');
                                t[j] = (nj + '0');
                                t[k] = (nk + '0');
                                res += (t <= s);
                                t[i] = t[j] = t[k] = '0';
                            }
                        }
                    }
                }
            }
        }
    }
    cout << res << "\n";
}


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

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

int main()
{
	ll n, k, s;
	cin >> n >> k >> s;
	for (ll i = 0; i < n; i++) {
		if (k > 0) {
			cout << s << " ";
			k--;
		}
		else cout << s / 10 + 10 << " ";
	}
}

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

string tmp;
int a[11][1111], cnt[11], k, h;

bool check(int col, int num)
{
	int i, gr = 0;

	for (i = 0; i < h; i++)
	{
		if (a[i][col])
			cnt[gr]++;

		if (cnt[gr] > k)
			return false;

		if (num >> i & 1)
			gr++;
	}

	return true;
}

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

	int w, i, j, p, ans = 1e9;

	cin >> h >> w >> k;
	for (i = 0; i < h; i++)
	{
		cin >> tmp;
		for (j = 0; j < w; j++)
			a[i][j] = tmp[j] - '0';
	}

	for (i = 0; i < (1 << (h - 1)); i++)
	{
		int hrz = 0, vrt = 0;

		for (j = 0; j < h; j++)
			cnt[j] = 0;

		hrz = __builtin_popcount(i);

		bool ret = true;
		for (j = 0; j < w; j++)
			if (!check(j, i))
			{
				vrt++;
				for (p = 0; p < h; p++)
					cnt[p] = 0;

				ret = check(j, i);
//				if(!ret) break;
			}

		if (ret)
			ans = min(ans, hrz + vrt);

//		cout << hrz << vrt << "\n";
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int n,m;
    int a[101][101];
    int b[101];
    int i,l,k,j,o;
    int c[101];

    scanf("%d %d", &n, &m);
    for( i = 1; i <= n ; i++){
        for( l = 1; l <= m; l++){
            scanf("%d", &a[i][l]);
        }
    }
    for( k = 1; k <= m; k++){
        scanf("%d", &b[k]);
    }
    for( o = 1; o <= n; o++){
        for( j = 1; j <= m; j++){
            c[o] = c[o] + (b[j] * a[o][j]);
        }
    }
    for( int p = 1; p <= n; p++){
        printf("%d\n", c[p]);
    }
    return 0;
}
        
    




Measured memory_bytes: 2116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define MOD 1000000007;

using namespace std;
using namespace __gnu_pbds;
//typedef tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//typedef tree<TYPE, null_type, less_equal<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

int n, inc[16], add[16];
vector<pair<int, int>> tst[16];

int most(int k, int cnt){
	if(k <= n){
		int ret = 0;
		ret = most(k + 1, cnt);
		inc[k] = 1;
		ret = max(ret, most(k + 1, cnt + 1));
		inc[k] = 0;
		return ret;
	}else{
		for(int i = 1; i <= n; i++) add[i] = inc[i];
		for(int k = 0; k <= n; k++)
			for(int i = 1; i <= n; i++)
				if(add[i]){
					for(auto j : tst[i])
						if(add[j.first] && !j.second) return 0;
						else if(j.second) add[j.first] = 1;
				}
		return cnt;
	}
}

int main(){
	//IO("input.txt", "output.txt");
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 1; i <= n; i++){
		int a, x, y;
		cin >> a;
		for(int j = 0; j < a; j++){
			cin >> x >> y;
			tst[i].push_back({x, y});
		}
	}
	cout << most(1, 0) << "\n";
	return 0;
}

Measured memory_bytes: 256
n, w=gets.split.map(&:to_i)
wei, val=[], []
n.times do
  a, b=gets.split.map(&:to_i)
  wei<< a
  val<< b
end

item=Array.new(4){[]}
r=wei[0]
n.times{|i| item[wei[i]-r]<< val[i]}
item.each{|v| v.sort!{|a, b| b<=>a}}

ans=0
(item[0].size+1).times do |i|
  (item[1].size+1).times do |j|
    (item[2].size+1).times do |k|
      (item[3].size+1).times do |l|
        _w, _v=0, 0
        _w=r*i+(r+1)*j+(r+2)*k+(r+3)*l
        if _w>w
          break
        end
        if i.nonzero?
          i.times{|_i| _v+=item[0][_i]}
        end
        if j.nonzero?
          j.times{|_j| _v+=item[1][_j]}
        end
        if k.nonzero?
          k.times{|_k| _v+=item[2][_k]}
        end
        if l.nonzero?
          l.times{|_l| _v+=item[3][_l]}
        end
        if _w<=w
          ans=[ans, _v].max
        end
      end
    end
  end
end

puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    double R;
    cin >> R;
    cout << setprecision(12) << 2 * R * M_PI;

    return 0;
}


Measured memory_bytes: 3756
int D(const void *a, const void *b){return *(int*)b-*(int*)a;}c[100];main(A,a,C,n,i,x,r,s){scanf("%d%d%d%d",&n,&A,&a,&C);for(i=0;i<n;i++)scanf("%d",c+i);qsort(c,n,4,D);for(r=C/A,x=i=0;i<n;i++){x+=c[i];s=(C+x)/(A+a*(i+1));if(s<r)break;r=s;}printf("%d\n",r);exit(0);}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, INF = 1000000000;
	vector<string> S;
	vector<vector<long long> > Dist;
	cin >> N;
	S.resize(N);
	Dist.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		Dist[i].assign(N, INF);
		for (int j = 0; j < N; j++) {
			if (S[i][j] == '1') Dist[i][j] = 1;
		}
		Dist[i][i] = 0;
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
 				Dist[i][j] = min(Dist[i][j], Dist[i][k] + Dist[k][j]);
			}
		}
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (Dist[i][j] % 2 != (Dist[i][k] + Dist[k][j]) % 2) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	long long ANS = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ANS = max(ANS, Dist[i][j]);
		}
	}
	cout << ANS + 1 << endl;
}

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

int main( void )
{
	int N;
	cin >> N;
	
	ll A[200];
	
	rep(i,N)
		cin >> A[i];
	
	bool x = true;
	int sum = 0,ans = 0;
	
	while ( x )
	{
		rep(i,N)
		{
			sum += A[i] % 2;
			A[i] /= 2;
		}
		
		if ( sum == 0 )
		{
			ans++;
		}
		
		else
			x = false;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
N, Y = list(map(int, input().split()))

for i in range(N + 1):
  for j in range(N - i + 1):
    k = N - i - j
    if i * 10000 + j * 5000 + k * 1000 == Y:
      print(i, j, k)
      exit()

print(-1, -1, -1)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int H, W, D, Q;
std::vector<std::vector<int>>A(312, std::vector<int>(312));
std::vector<int>L(112345), R(112345), imos(91234);
std::vector<std::pair<int, int>>pos(91234);

int main()
{
	in >> H >> W >> D;
	rep(i, H) rep(j, W) in >> A[i][j];
	in >> Q;
	rep(i, Q) in >> L[i] >> R[i];
	rep(i, H)
	{
		rep(j, W)
		{
			pos[A[i][j]].first = i;
			pos[A[i][j]].second = j;
		}
	}
	for (int i = 1; i <= H * W; ++i)
	{
		if (i - D < 1) continue;
		imos[i] = imos[i - D] + abs(pos[i].first - pos[i - D].first) + abs(pos[i].second - pos[i - D].second);
	}
	rep(i, Q) out << imos[R[i]] - imos[L[i]] << std::endl;
	return 0;
}

Measured memory_bytes: 3456
#include<stdio.h>
int main()
{
  int x,y,gcd;
  
  scanf("%d%d",&x,&y);
  
  if(x == y) gcd = x;
  else
  while((x % y) != 0){
    gcd = x % y;
    x = y;
    y = gcd;
  }
  printf("%d\n",gcd);
  return 0;
}

Measured memory_bytes: 592
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    N,M,X=pin()
    A=lispin()
    ans=0
    x=X
    for i in range(N):
        
        if x==N:break
        if x in A:ans+=1
        x+=1
    bns=0
    x=X
    for i in range(N):
        
        if x==0:break
        if x in A:bns+=1
        x-=1
    print(min(bns,ans))    
            

#%%submit!    
resolve()

Measured memory_bytes: 38256
s = int(input())

a = []
i = 0
a.append(s)
cnt = 1
while True:
    t = 0
    if a[i] % 2 == 0:
        t = a[i]//2
    else:
        t = 3*a[i]+1
    for j in range(len(a)):
        if a[j] == t:
            print(i+2)
            exit()
    a.append(t)
    i += 1



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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		for(int i = 0; i < n; i++) b[i] = sc.nextInt();
		for(int i = 0; i < n; i++) c[i] = sc.nextInt();
		Arrays.sort(a);
		Arrays.sort(c);
		long ans = 0;
		for(int i = 0; i < n; i++) {
			ans += lowerBound(a, b[i]) * (n - upperBound(c, b[i]));
		}
		System.out.println(ans);
	}

	static long lowerBound(int[] a, int x) {
		int l = -1, r = a.length;
		while(r - l > 1) {
			int mid = (l + r) / 2;
			if(a[mid] >= x) r = mid;
			else l = mid;
		}
		return r;
	}

	static long upperBound(int[] a, int x) {
		int l = -1, r = a.length;
		while(r - l > 1) {
			int mid = (l + r) / 2;
			if(a[mid] <= x) l = mid;
			else r = mid;
		}
		return r;
	}

}


Measured memory_bytes: 93336
N = int(input())

import math

n = math.sqrt(N)

if n.is_integer() == True:
  print(int(2*n - 2))
  exit()
else:
  c = math.floor(n)
  for i in range(0, c):
    d = c - int(i) 
    e = N / d
    if e.is_integer() == True:
      print(int(d + N/d - 2))
      exit()
      

Measured memory_bytes: 9184
H, W = map(int, input().split())

def solve2(h, w):
  l = h // 2
  s1 = l * w
  s2 = (h - l) * w
  return s1, s2

def solve(h, w):
  mn = 1e10
  for i in range(1, h):
    s1 = i * w
    s2, s3 = solve2(h - i, w)
    dif1 = (max(s1, s2, s3) - min(s1, s2, s3))
    s4, s5 = solve2(w, h - i)
    dif2 = (max(s1, s4, s5) - min(s1, s4, s5))
    mn = min(mn, dif1, dif2)
  return mn

print(min(solve(H, W), solve(W, H)))


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


void lcs(string a, string b, int n, int m){
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i==0||j==0)
				dp[i][j] = 0;
			else if(a[i-1]==b[j-1])
				dp[i][j] = dp[i-1][j-1] + 1;
			else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}
	// return dp[n][m];
	int size = dp[n][m];
	char lcs[size+1];
	lcs[size] = '\0';
	int i=n,j=m;
	while(i>0 && j>0){
		if(a[i-1]==b[j-1]){
			lcs[size-1] = a[i-1];
			i--,j--,size--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else
			j--;
	} 
	cout << lcs << endl;
}
int main(){
	string s,t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	lcs(s,t,n,m);
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

void no(){
    p_no();
    exit(0);
}

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

    // input
    ll N; 
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    A[0]--;
    FOR(i, 1, N-1){
        // 下げれるなら下げる
        if(A[i]==A[i-1]){
            // 下げれない
        }
        else if(A[i]<A[i-1]){
            no();
        }
        else{
            A[i]--;
        }
        if(A[i+1]<A[i]){
            no();
            // return 0;
        }
    }
    p_yes();
    
    return 0;
}

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

void solve()
{
	string s;
	cin>>s;
	map<int,int> m;
	m[0]++;
	int mod = 2019;
	int k = 1;
	int l = 0;
	int n = s.length();
	for (int i = 0; i < s.length(); ++i)
	{
		l = ((s[n-i-1]-'0')*k + l)%mod;
		m[l]++;
		k = (k*10)%mod;
	}
	ll ans = 0;
	for(auto i:m)
	{
		ans += i.second*(i.second-1)/2;
	}
	cout<<ans<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

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

int main(){
    map<int, string> msg;
    msg[25] = "Christmas";
    msg[24] = "Christmas Eve";
    msg[23] = "Christmas Eve Eve";
    msg[22] = "Christmas Eve Eve Eve";

    int D;
    cin >> D;
    cout << (msg[D]) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define lowbit(i) (i&(-i))
using namespace std;
const int maxn = 1e5+5;
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
vector<int> g[maxn];
int h[maxn];
signed main (){
	int x=readint();
	for(int i=0;;i++)
		for(int j=-1e3;j<=1e3;j++)
			if(pow(i,5)-pow(j,5)==x){
				cout<<i<<" "<<j;
				return 0;
			}		
	return 0;
}


Measured memory_bytes: 6444
def main():
    n, k = map(int, input().split(' '))
    result = [n//i*max(0,i-k) + max(0, n%i-k+1) for i in range(1, n+1)]
    if k == 0:
        print(sum(result)-n)
    else:
        print(sum(result))
main()

Measured memory_bytes: 7012
#include <stdio.h>
int main(void){
  int i,j,N;
  long long p;
  p=1;
  scanf("%d",&N);
  for(i=1; i<=N; i++){
    p*=i;\
    p%=1000000007;
  }
  printf("%d",(int)p);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,n=0,w=0;
  std::cin >> x;
  std::vector<int> v(x);
  std::vector<int> dp(x,INF);
  rep(i,x)std::cin >> v[i];
  dp[0]=0;
  repone(i,x){
    dp[i]=min(dp[i],dp[i-1]+abs(v[i]-v[i-1]));
    if(i>1)dp[i]=min(dp[i],dp[i-2]+abs(v[i]-v[i-2]));
  }
  std::cout << dp[x-1] << '\n';
}


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

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 0;
    for(int i = 0; i <= N-3; i++){
        if(S.substr(i, 3) == "ABC"){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256