akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    lli N, K;
    cin >> N >> K;
    lli ans = 0;
    if (N >= K)
    {
        if (N % K != 0)
        {
            ans = min(abs(N - K * (lli)((N / K) + 1)), abs(N - K * (lli)((N / K))));
            cout << ans << endl;
        }
        else
        {
            ans = 0;
            cout << ans << endl;
        }
    }
    else
    {
        cout << min(N, abs(N - K)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
int a[200005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	FOR(i, n) cin >> a[i];
	vector<int> v;

	if (n & 1) {
		for (int i = n-1; i >= 0; i -= 2) v.push_back(a[i]);
		for (int i = 1; i < n; i += 2) v.push_back(a[i]);
	}
	else {
		for (int i = n-1; i >= 1; i -= 2) v.push_back(a[i]);
		for (int i = 0; i < n; i += 2) v.push_back(a[i]);
	}

	FOR(i, n) {
		if (i < n-1) cout << v[i] << " ";
		else cout << v[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
int main() {
    int a,b;
    while(cin >>a>>b){
        int c=0,d=a+b;
        while(d){
            d=d/10;
            c++;
        }
        cout <<c << endl;
    }
    return 0;
}



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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#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 in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

bool is_prime(int x)
{
    for (int y=2; y*y<=x; y++) if (x%y == 0) return false;
    return true;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, cnt = 0;
    cin >> N;

    for (int i=3; cnt<N ; i++) {
        if (i%10 == 3 && is_prime(i)) {
            if (cnt > 0) cout << " ";
            cout << i;
            cnt++;
        }
    }
    cout << endl;
}

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

bool myless(const string &s1, const string &s2) {
    if (s1.size() != s2.size()) {
        return s1.size() < s2.size();
    }
    return s1 < s2;
}

int main(void) {
    int W, H;
    while (cin >> W >> H, W) {
        VS C(H);
        for (auto &c : C) cin >> c;

        VVS dp(H, VS(W));

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (isalpha(C[i][j])) continue;

                string s1, s2;

                if (i != 0) {
                    s1 = dp[i - 1][j];
                }
                if (j != 0) {
                    s2 = dp[i][j - 1];
                }
                s1 += C[i][j];
                s2 += C[i][j];

                dp[i][j] = max(s1, s2, myless);

                if (dp[i][j] == "0") {
                    dp[i][j] = "";
                }
            }
        }

        string ans;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                ans = max(ans, dp[i][j], myless);
            }
        }

        cout << ans << endl;
    }

	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,b[100],tmp,ans;

signed main() {
    cin >> n;
    rep(i,n-1) cin >> b[i];
    ans += b[0] + b[n-2];
    rep(i,n-1) ans += min(b[i], b[i+1]);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i, n/2) {
        if (s[i] != s[n-1-i]) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int a[5],k;
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            if(a[i] - a[j] > k){
                cout << ":(";
                return 0;
            }
        }
    }
    cout << "Yay!";
}

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

int main(int argc, char const *argv[])
{
	int q;
	cin>>q;
	multiset<long long> l,r;
	long long a=0LL,b=0LL,ai,bi;
	int p;
	cin>>p>>ai>>bi;
	b+=bi;
	l.insert(ai);
	for (int i = 1; i < q; ++i)
	{
		cin>>p;
		if (p==1)
		{
			cin>>ai>>bi;
			b+=bi;
			if (l.size()==r.size())
			{
				auto itr=l.end();
				--itr;
				if (*itr<ai)
				{
					if ((*r.begin())>=ai)
					{
						l.insert(ai);
					}
					else
					{
						long long move=*r.begin();
						r.erase(r.begin());
						l.insert(move);
						a+=abs(move-ai);
						r.insert(ai);
					}
				}
				else
				{
					a+=abs((*itr)-ai);
					l.insert(ai);
				}
			}
			else
			{
				auto itr=l.end();
				--itr;
				if (*itr<=ai)
				{
					a+=abs((*itr)-ai);
					r.insert(ai);
				}
				else
				{
					a+=abs((*itr)-ai);
					long long move=*itr;
					l.erase(itr);
					r.insert(move);
					l.insert(ai);
				}
			}
		}
		else if(p==2)
		{
			auto itr=l.end();
			--itr;
			cout<<*itr<<" "<<a+b<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 9600
n = int(input())
X, Y, H = [], [], []
for _ in range(n):
    x, y, h = map(int, input().split())
    X.append(x); Y.append(y); H.append(h)

for cx in range(101):
    for cy in range(101):
        for i in range(n):
            if H[i] > 0:
                ch = H[i] + abs(cx-X[i]) + abs(cy-Y[i])
                break
        flg = True
        for i in range(n):
            if H[i] != max(ch-abs(cx-X[i])-abs(cy-Y[i]), 0):
                flg = False
                break
        if flg:
            print(cx, cy, ch)
            exit()

Measured memory_bytes: 42860
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <utility>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int N; cin >> N;
  int cmin = 20;
  for (long long int A = 1; A <= sqrt(N); A++) {
    if (N%A == 0) {
      int a, b;
      a = to_string(A).length(); b = to_string(N/A).length();
      int Ar[2] = {a,b};
      int F = *max_element(Ar, Ar+2);
      int Ar2[2] = {cmin, F};
      cmin = *min_element(Ar2, Ar2+2);
    }
  }
  cout << cmin << endl;
}


Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
    static short st[30];short tp=0;
    if(x<0) putchar('-'),x=-x;
    do st[++tp]=x%10,x/=10; while(x);
    while(tp) putchar('0'|st[tp--]);
    putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 4005;
int h[N], ne[N<<1], to[N<<1], tot;
inline void add(int x, int y) {
    ne[++tot] = h[x], to[h[x] = tot] = y;
}

char s[N];
int siz[N], dis[N], f[N], ans = 1e9, n;
void dfs(int x, int fa) {
    siz[x] = s[x] == '1'; int mx = dis[x] = f[x] = 0;
    for (int i = h[x]; i; i = ne[i]) {
        int y = to[i]; if (y == fa) continue;
        dfs(y, x), dis[y] += siz[y];
        dis[x] += dis[y], siz[x] += siz[y]; 
        if (dis[y] > dis[mx]) mx = y;
    }
    if (dis[mx] * 2 <= dis[x]) { f[x] = dis[x] / 2; return; }
    f[x] = dis[x] - dis[mx] + min(f[mx], (2 * dis[mx] - dis[x]) / 2);
}

int main() {
    read(n), scanf ("%s", s + 1);
    for (int i = 1, x, y;i < n; i++)
        read(x), read(y), add(x, y), add(y, x);
    for (int i = 1;i <= n; i++) 
        dfs(i, 0), f[i] * 2 == dis[i] && (Mn(ans, f[i]), 0);
    write(ans < 1e8 ? ans : -1);
    return 0;
}


Measured memory_bytes: 3328
# ABC064C - Colorful Leaderboard
from collections import Counter


def main():
    n = int(input())
    cnt = Counter(i // 400 for i in tuple(map(int, input().rstrip().split())))
    colored = sum(i < 8 for i in cnt.keys())  # rate: <3200
    free = sum(j if i >= 8 else 0 for i, j in cnt.items())  # >=3200
    x = max(1, colored)  # min
    y = colored + free  # max
    print(x, y)


if __name__ == "__main__":
    main()

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

using namespace std;
const int mod = 1000000007;

int main(void){
    int N;
    cin >> N;
    vector<int> B(N-1);
    for(int i = 0; i < N-1; i++){
        cin >> B.at(i);
    }

    vector<int> A(N);
    int ans = 0;
    A.at(0) = B.at(0);
    A.at(1) = B.at(0);
    for (int i = 1; i < N-1; i++){
        if (A.at(i) > B.at(i)){
            A.at(i) = B.at(i);
            A.at(i+1) = B.at(i);
        }else{
            A.at(i+1) = B.at(i);
        }
    }
    ans = accumulate(A.begin(), A.end(), 0);
    cout << ans  << endl;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c, k; cin >> a >> b >> c >> k;
    int ans = 0;
    while (k && a) {
        int d = min(k, a);
        k -= d, a -= d, ans += d;
    }
    while (k && b) {
        int d = min(k, b);
        k -= d, b -= d;
    }
    ans -= k;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans;
    if(s == "SUN") ans = 7;
    else if(s == "MON") ans = 6;
    else if(s == "TUE") ans = 5;
    else if(s == "WED") ans = 4;
    else if(s == "THU") ans = 3;
    else if(s == "FRI") ans = 2;
    else ans = 1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		int n = in.nextInt(), a = in.nextInt(), b = in.nextInt();
		out.println((a - b) % 2 == 0 ? "Alice" : "Borys");
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(void)
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> sc(n+1);
    fill(sc.begin(), sc.end(), k);
    vector<int> app(n+1);
    fill(app.begin(), app.end(), 0);

    int i;
    for(i=0;i<q;i++)
    {
        int a;
        cin >> a;
        app[a] +=1;
    }

    for(i=1;i<n+1;i++)
    {
        if(sc[i] - (q-app[i]) > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }

    return 0;

}

Measured memory_bytes: 1408
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

    l = [A[0]]
    for i in range(N-2):
        l.append(l[-1] + A[i+1])

    ans = 0
    for i in range(N-1):
        ans += l[i] * A[i+1] % mod

    print(ans % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32668
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long 
using namespace std;
const ll INF = 1e18+10;
const ll N = 100010;
ll n, a[N], lim, d[N], c[N], res;

void chkMax(ll &x, ll y){if (x < y) x = y;}
void chkMin(ll &x, ll y){if (x > y) x = y;}

void Msort(ll l, ll r)
{
    if (l == r) return;
    ll mid = (l+r)>>1;
    Msort(l, mid);
    Msort(mid+1, r);
    ll i = l, j = mid+1, k = l;
    while (i <= mid && j <= r){
        if (d[i] <= d[j]){
            c[k++] = d[i++];
            res += r-j+1;
        }
        else
            c[k++] = d[j++];
    }
    while (i <= mid) c[k++] = d[i++];
    while (j <= r) c[k++] = d[j++];
    for (ll o = l; o <= r; o++)
        d[o] = c[o];
}

bool Check(ll mid)
{
    d[0] = 0;
    for (ll i = 1; i <= n; i++){
        d[i] = d[i-1];
        if (a[i] >= mid)
            d[i]++;
        else
            d[i]--;
    }
    res = 0;
    Msort(0, n);
    if (res >= lim) return true;
    return false;
}

int main()
{
    cin >> n;
    lim = (n*(n+1)/2+1)/2;
    ll l = INF, r = -INF, mid, ans;
    for (ll i = 1; i <= n; i++){
        cin >> a[i];
        chkMax(r, a[i]);
        chkMin(l, a[i]);
    }
    while (l <= r){
        mid = (l+r)>>1;
        if (Check(mid))
            ans = mid, l = mid+1;
        else
            r = mid-1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 2560
import math
import itertools
import statistics
#import numpy as np
import collections

#n = int(input())
#n, m = list(map(int, input().split()))
a = int(input())
b = int(input())
if a>b:
    print("GREATER")
elif a<b:
    print("LESS")
else:
    print("EQUAL")

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 1e5 + 9, M = 2e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


int main()
{
    init();

    int n, m;
    cin >> n >> m;
    char a[n][n], b[m][m];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> a[i][j];

    for(int i = 0; i < m; i++)
        for(int j = 0; j < m; j++)
            cin >> b[i][j];

    for(int i = 0; i + m - 1< n; i++)
    {
        for(int j = 0; j + m - 1 < n; j++)
        {
            int ok = 1;
            for(int u = 0; u < m; u++)
            {

                for(int v = 0; v < m; v++)
                {
                    if(a[i + u][j + v] != b[u][v]) ok = 0;
                }
            }
            if(ok)  return cout << "Yes", 0;

        }

    }

    cout << "No";

}

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

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	// ll sum = 1000;
	// REP(i,40) {
	// 	sum *= 2;
	// 	debug(sum);
	// }
	int N; cin >> N;
	vl A(N);
	REP(i,N) cin >> A[i];
	ll sum = 1000;
	using p = pair<int, int>;
	vector<p> ps;
	int cur = -1;
	int cand = -1;
	REP(i,N) {
		if (cur == -1) {
			cur = A[i];
			continue;
		} else if (A[i] >= cur && A[i] >= cand) {
			cand = A[i];
		} else {
			if (cur != -1 && cand != -1) {
				ps.emplace_back(cur, cand);
			}
			cur = A[i];
			cand = -1;
		}
	}
	if (cur != -1 && cand != -1) {
		ps.emplace_back(cur, cand);
	}
	int pn = ps.size();
	auto dfs = [&](auto dfs, int v, ll res) -> ll {
		if (v > pn) return res;
		ll max_res = res;
        FOR(i, v, pn) {
			if (i > v) break;
			ll n = res / ps[v].first;
			res -= n * ps[v].first;
			res += n * ps[i].second;
			ll response = dfs(dfs, i + 1, res);
			chmax(max_res, response);
        }
		return max_res;
    };
    ll ans = dfs(dfs, 0, sum);
	cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int                 long long
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
//#define ordered_set         tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
/*

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).

*/
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 3e18;

/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
int Power(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1)res*=a;
        a*=a;
        b>>=1;
    }
    return res;
}
signed main()
{
    FastIO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        int x,n;
        cin>>x>>n;
        vi a(n);
        cin>>a;
        MAP mp;
        for(auto it:a)mp[it]++;
        int ans=inf;
        int k=0;
        while(ans==inf)
        {
            if(mp[x-k]==0||mp[x+k]==0)
            {
                if(mp[x-k]==0)ans=x-k;
                else ans=x+k;
            }
            else k++;
        }
        cout<<ans<<"\n";
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||

|| A year from now you may wish you had started today ||
*/



Measured memory_bytes: 3636
import java.io.*;
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    if(s.charAt(0)=='A')
       System.out.println("T");
    if(s.charAt(0)=='T')
       System.out.println("A");
    if(s.charAt(0)=='C')
       System.out.println("G");
    if(s.charAt(0)=='G')
       System.out.println("C");
   }
 }
    
    

Measured memory_bytes: 21460
#include <stdio.h>
#include <math.h>

int main(void){
  double xp1,xp2,yp1,yp2,xp,yp;
  int q;
  scanf("%lf %lf %lf %lf",&xp1,&yp1,&xp2,&yp2);
  scanf("%d",&q);
  double v1x,v1y;
  v1x=(xp2-xp1)/sqrt((yp2-yp1)*(yp2-yp1)+(xp2-xp1)*(xp2-xp1));
  v1y=(yp2-yp1)/sqrt((yp2-yp1)*(yp2-yp1)+(xp2-xp1)*(xp2-xp1));
  double dot;
  for(int i=0;i<q;i++){
    scanf("%lf %lf",&xp,&yp);
    dot=(xp-xp1)*v1x+(yp-yp1)*v1y;
    printf("%.16f %.16f\n",xp1+dot*v1x,yp1+dot*v1y);
  }
  return 0;
}



Measured memory_bytes: 2760
def main():
  import sys
  a=int(input())
  b=tuple(map(int,sys.stdin.readline().split()))
  c=[None]*a
  d=1
  for e in b:
    c[e-1]=d
    d+=1
  print(" ".join(map(str,c)))
if __name__=="__main__":
  main()

Measured memory_bytes: 18316
//10のi乗pow(10, i);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n,d;
  cin >>n>>d;
  vector<vector<int>> data(n, vector<int>(d));
  rep(i,n){
    rep(j,d){
      cin>>data.at(i).at(j);
    	}
  }

  int count=0;

  rep(i,n-1){
    for(int k=1+i;k<n;k++){//kkaishi
    int sum=0;
   	 rep(j,d){
	   sum += pow(	(data.at(i).at(j) -data.at(k).at(j)), 2);
  	}
    rep(k,1000){
      if(sum == k*k ) count++;
    } 
   }//kshuuryou
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                          
using namespace std;                              
                                                  
bool check(long int n){                           
  int c3 = 0,c5 = 0,c7 = 0;                       
  int a = 0;                                      
  while(n != 0){                                  
    a = n % 10;                                   
    if(a == 3) c3++;                              
    else if(a == 5) c5++;                         
    else if(a == 7) c7++;                         
    n /=10;                                       
  }                                               
  if(c3 > 0 && c5 > 0 && c7) return true;         
  else return false;                              
}                                                 
                                                  
int count(long int s,int n){                      
  if(s > n) return 0;                             
  int c = 0,i;                                    
  int seti[3] = {7,5,3};                          
  if(check(s)) c = 1;                             
  for(i = 0;i < 3;++i){                           
    c += count(s*10+seti[i],n);                   
  }                                               
  return c;                                       
}                                                 
int main(void){                                   
  int n;                                          
  cin >> n;                                       
  cout << count(0,n) << endl;                     
  return 0;                                       
}                                                 
                                                  
                                                  

Measured memory_bytes: 256
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

N = int(input())
ans = "No"
for i in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if a[y][x] == b:
                a[y][x] = 0

    for j in range(3):
        if sum(a[j]) == 0:
            ans = "Yes"
            break
    for j in range(3):
        s = 0
        for k in range(3):
            s += a[k][j]
        if s == 0:
            ans = "Yes"
            break
    if (a[0][0]+a[1][1]+a[2][2]) == 0 or (a[0][2]+a[1][1]+a[2][0]) == 0:
        ans = "Yes"
        break
    if ans == "Yes":
        break
print(ans)


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


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    int ans = 0;
    rep(i,k){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

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

int A[100005];
vector< pair<int, int> > X, Y;

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N, M;
    cin >> N >> M;

    for(int i=1; i<=N; i++)
        cin >> A[i];
    
    sort(A+1, A+1+N);

    for(int i=1; i<=M; i++)
    {
        int b, c;
        cin >> b >> c;

        X.push_back({c, b});
    }

    int ptr = 1;
    sort(X.begin(), X.end());
    reverse(X.begin(), X.end());

    for(int i=0; i<X.size(); i++)
    {
        int b = X[i].second;
        int c = X[i].first;

        while(ptr <= N && b && A[ptr] < c)
            A[ptr++] = c, b--;
    }

    long long ans = 0;

    for(int i=1; i<=N; i++)
        ans += A[i];

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1784
#include <cstdio>
#include <iostream>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::getline;
using std::printf;
using std::set;
using std::stack;
using std::stod;
using std::string;
using std::stringstream;
using std::vector;

double calculate(vector<string> rpev) {
	set<string> op {"+","-","*","/"}; // operator set
	stack<double> num_s; // number stack
	for (auto i = rpev.begin();i != rpev.end();++i) {
		if (op.find(*i) == op.end()) { // if *i is a number
			num_s.push(stod(*i));
		} else { // if *i is an operator
			double second = num_s.top();
			num_s.pop();
			double first = num_s.top();
			num_s.pop();
			if (*i == "+") {
				num_s.push(first+second);
			} else if (*i == "-") {
				num_s.push(first-second);
			} else if (*i == "*") {
				num_s.push(first*second);
			} else {
				num_s.push(first/second);
			}
		}
	}
	return num_s.top();
}

int main() {
	string rpe; // reverse Polish expression
	while (getline(cin,rpe)) {
		vector<string> rpev; // reverse Polish expression vector
		stringstream str_in(rpe);
		while (!str_in.eof()) {
			string unit;
			str_in >> unit;
			rpev.push_back(unit);
		}
		printf("%lf\n",calculate(rpev));
	}
}

Measured memory_bytes: 3156
s = gets.chomp
q = gets.to_i

queries = []
q.times do
  query = gets.split
  if (size = query.size) == 1
    queries << query.map(&:to_i)
  else
    queries << query.map.with_index(1) { |string, i| i == size ? string : string.to_i }
  end
end

answer = s.split('')

reverse = false

queries.each do |query|
  if query.first == 1
    reverse = !reverse
  else
    if (query[1] == 1 && !reverse) || (query[1] == 2 && reverse)
      answer.unshift(query.last)
    else
      answer.push(query.last)
    end
  end
end

answer = answer.reverse if reverse

puts answer.join


Measured memory_bytes: 47248
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,0,n)

int main()
{
	int N, K;
	cin >> N >> K;

	int a, b;
	REP(i, K) {
		cin >> a >> b;
		a = min(a, N-a+1);
		b = min(b, N-b+1);
		cout << (min(a, b)-1)%3+1 << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf();

int main() {
    int N;
    cin >> N;
    cout << (N < 1000 ? "ABC" : "ABD") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		String T = scanner.next();
		String judge = "No";

		int l = S.length();

		for (int i = 0; i < l; i++) {
			//文字列Sの末尾を取得
			String end = S.substring(l-1,l);

			//文字列Sの末尾は削除
			S = S.substring(0,l-1);

			//文字列Sの先頭に追加
			S = end + S;

			if (T.equals(S)) {
				judge = "Yes";
				break;
			}
		}
		System.out.println(judge);
	}
}

Measured memory_bytes: 21972
from collections import *
import sys
sys.setrecursionlimit(10**6)

H, W = map(int, input().split())
mas = []
for i in range(H):
    line = input()
    temp = []
    for j in range(W):
        temp.append(line[j])
    mas.append(temp)

color = []
for i in range(H):
    color.append([-1] * W)

def DFS(node, c_color):
    x = node[0]
    y = node[1]
    nb = [[x, y-1], [x, y+1], [x+1, y], [x-1, y]]
    deq = deque()
    for i in range(4):
        if(nb[i][0] >= 0 and nb[i][0] < H and nb[i][1] >= 0 and nb[i][1] < W):
            if(color[nb[i][0]][nb[i][1]] == -1):
                deq.append(nb[i])

    deq_ = deque()
    while(deq):
        next_node = deq.popleft()
        if(mas[next_node[0]][next_node[1]] != mas[node[0]][node[1]]):
            color[next_node[0]][next_node[1]] = c_color
            deq_.append(next_node)
            
    while(deq_):
        next_node = deq_.popleft()
        DFS(next_node, c_color)
    return
        
current_color = 0
for i in range(H):
    for j in range(W):
        if(color[i][j] >= 0):
            continue
        else:
            color[i][j] = current_color
            DFS([i, j], current_color)
            current_color += 1

color_num = []
for i in range(current_color):
    color_num.append([0, 0])


for i in range(H):
    for j in range(W):
        if(mas[i][j] == '#'):
            color_num[color[i][j]][0] += 1
        else:
            color_num[color[i][j]][1] += 1

ans = 0
for i in range(len(color_num)):
    ans += color_num[i][0] * color_num[i][1]

print(ans)


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


int main() {
  int X;
  bool j = false;
  cin >> X;
  for (int a= 0; a< 26; ++a){
    for (int b= 0; b< 15; ++b){
      int total = 4*a + 7*b;
      if (total == X) {
        j = true;
      }
   }
  }
  if (j == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"

/*##################################################################################*/


int prime[1000000] ;
vector < int > pr;
void calculateprime()
{
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; i <= 1000000 ; i++)
    {
        if(prime[i] == 0)
        {
            pr.pb(i);
            for(ll j = i*2 ; j <= 1000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}

void customrun(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n)
{
    ll a = 0, b = 1, c, i;
    if( n == 0)
        return a;
    for (i = 2; i <= n; i++)
    {
        c = (a + b);
        a = b;
        b = c;
    }
    return b;
}


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

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}


ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


bool comp(const pair<long long,ll> &a , const pair<ll ,ll > &b){
    if(a.first == b.first)  return a.second < b.second;
    return a.first > b.first;

    return false;
}

void solve();

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

    return 0;
}


void solve(){
    int n;
    in(n);
    int arr[n];
    f(i,n) in(arr[i]);
    int cnt = 0;
    f(i,n){
        if( (i+1) & 1 and arr[i] & 1) ++cnt;
    }
    out(cnt);
}


Measured memory_bytes: 3608
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
INF=float('inf')
ans=[INF,INF]

for i in range(N):
    if ans[1]> abs(A-(T-H[i]*0.006)):
        ans[0]=i+1
        ans[1]=abs(A-(T-H[i]*0.006))
        
print(ans[0])

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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


int n, a[200001];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i] -= i+1;
	}
	sort(a, a+n);
	
	ll ans = 0;
	for(int i = 0; i < n; i++){
		ans += abs(a[i] - a[n/2]);
	}
	cout << ans << endl;
	
	return 0;
}

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

int field[55][55];

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

int w,h;

void dfs(int i, int j){
	field[i][j] = 0;
	for (int k = -1; k <= 1; ++k) {
		for (int l = -1; l <= 1 ; ++l) {
			if(k == 0 && l == 0) continue;
			int x = j + k;
			int y = i + l;
			if(x<0 || x>= w || y<0 || y>=h) continue;
			if(field[y][x] == 1){
				dfs(y,x);
			}
		}
	}
	return ;
}

int main(){
	cin >> w >> h;
	
	while(w != 0 || h != 0) {
		rep(i, h) {
			rep(j, w) {
				cin >> field[i][j];
			}
		}
		
		int ans = 0;
		
		rep(i, h) {
			rep(j, w) {
				if (field[i][j] == 1) {
					dfs(i, j);
					ans++;
				}
			}
		}
		
		cout << ans << endl;
		cin >> w >> h;
	}
    return 0;
}




Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 200001
const int inf = 1e18;

int mn[2][1010], mx[2][1010];
int a[MAX], dp[2][1010];
signed main(){
	int n, m, k;
	fill((int*)dp, (int*)(dp+2), inf);
	fill((int*)mn, (int*)(mn+2), inf);
	scanf("%lld%lld%lld", &n, &m, &k);
	for(int i = 0;i < n;i++)scanf("%lld", &a[i]);
	
	dp[0][0] = k;
	mn[0][0] = mx[0][0] = a[0];
	for(int i = 1;i < n;i++){
		for(int j = 1;j < m;j++){
			if(dp[0][j-1] == inf)continue;
			mn[1][j] = min(mn[0][j-1], a[i]);
			mx[1][j] = max(mx[0][j-1], a[i]);
			dp[1][j] = dp[0][j-1];
		}
		for(int j = 0;j < m;j++){
			if(dp[0][j] == inf)continue;
			int sum = dp[0][j]+(j+1)*(mx[0][j]-mn[0][j])+k;
			dp[1][0] = min(dp[1][0], sum);
			mx[1][0] = mn[1][0] = a[i];
		}
		for(int j = 0;j < m;j++){
			mn[0][j] = mn[1][j];mn[1][j] = inf;
			mx[0][j] = mx[1][j];mx[1][j] = 0;
			dp[0][j] = dp[1][j];dp[1][j] = inf;
		}
	}
	
	int ans = dp[0][0];
	for(int i = 1;i < m;i++){
		int sum = dp[0][i]+(i+1)*(mx[0][i]-mn[0][i]);
		ans = min(ans, sum);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3432
#include <stdio.h>
#include <math.h>

int main(){

  int i, n, input, max, min;

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

  max = -1000000000;
  min = input;
  for(i = 1; i <= n-1; i++){
    scanf("%d", &input);
    max = fmax(max, input-min);
    min = fmin(min, input);
  }
  printf("%d\n", max);

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}
 
using i64=int64_t;
 
struct edge{
    int from,to;
    i64 weight;
    edge(int from_,int to_,i64 weight_){
        from=from_;
        to=to_;
        weight=weight_;
    }
};
 
void solve(){
    int N,M;
    cin >> N >> M;
    vector<edge> edges;
    rep(i,0,M){
        int a,b;
        i64 c;
        cin >> a >> b >> c;
        --a;
        --b;
        edges.push_back(edge(a,b,-c));
    }

    vector<i64> dist(N,inf64);
    dist[0]=0;
    for(int i=0; i<N-1; ++i){
        for(edge& e:edges){
            int u=e.from,v=e.to;
            if(dist[u]!=inf64 and dist[v]>dist[u]+e.weight) dist[v]=dist[u]+e.weight;
        }
    }

    vector<bool> negative(N,false);
    for(int i=0; i<N; ++i){
        for(edge& e:edges){
            int u=e.from,v=e.to;
            if(dist[u]!=inf64 and dist[v]>dist[u]+e.weight){
                dist[v]=dist[u]+e.weight;
                negative[u]=negative[v]=true;
            }
        }
    }
    if(negative[N-1]) cout << "inf" << endl;
    else cout << -dist[N-1] << endl;
}
 
int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

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

const int MAX_N=200000;

class UnionFind{
public:
  UnionFind(){}
  
  UnionFind(int n){
    for(int i=0;i<n;i++){
      this->par[i]=i;
      this->d[i]=0;
    }
  }

  int find(int x){
    if(this->par[x]==x) return x;
    else return this->par[x]=find(this->par[x]);
  }

  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;

    if(this->d[x]<this->d[y]) this->par[y]=x;
    else{
      this->par[y]=x;
      if(this->d[x]==this->d[y]) this->d[x]++;
    }
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }

private:
  int par[MAX_N];
  int d[MAX_N];
};
  
int main(){
  int N,K,L;
  scanf("%d%d%d",&N,&K,&L);

  UnionFind u1(N);
  UnionFind u2(N);
  for(int i=0;i<K;i++){
    int p,q;
    scanf("%d%d",&p,&q);
    p--;
    q--;
    u1.unite(p,q);
  }

  for(int i=0;i<L;i++){
    int r,s;
    scanf("%d%d",&r,&s);
    r--;
    s--;
    u2.unite(r,s);
  }

  map<pair<int,int>,int> cnt;
  for(int i=0;i<N;i++) cnt[make_pair(u1.find(i),u2.find(i))]++;

  for(int i=0;i<N;i++){
    if(i!=0) printf(" ");
    printf("%d",cnt[make_pair(u1.find(i),u2.find(i))]);
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 15104
s=input()
if(len(s)<=1):
    print('No')
    exit()

for i in range(len(s)-1):
    if(s[i]=='h'):
        if(s[i+1]=='i'):
            continue
        else:
            print('No')
            exit()
    elif(0<i and s[i]=='i'):
        if(s[i+1]=='h'):
            if(i+2<len(s) and s[i+2]=='i'):
                continue
            else:
                print('No')
                exit()
        else:
            print('No')
            exit()
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

signed main(){
    int N,T,A;
    cin>>N>>T>>A;
    vector<double> H(N);
    REP(i,N) cin>>H[i];
    vector<double> AVE(N);
    REP(i,N) AVE[i]=T-0.006*H[i];
    int ans = 1;
    double X = INF;
    REP(i,N){
        if(abs((double)A-AVE[i]) < X){
            X = abs(A-AVE[i]);
            ans = i;
        }
    }
    cout<<ans+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int k,a,b;
  cin >> k >> a >> b;
  if(b-a<=2 || k<a+1){
    cout << 1+k << endl;
    return 0;
  }
  cout << a+(b-a)*((k-a+1)/2)+(k-a+1)%2 << endl;
}

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

string s,akb = "AKIHABARA";
int asize = akb.size();

bool solve();

int main(){
    cin >> s;
    if(solve())cout << "YES" << endl;
    else cout << "NO" << endl;
}

bool solve(){
    string nows;
    int now = 0,ssize = s.size();
    for(int i = 0;i < asize;++i){
        if(now < ssize && s[now] == akb[i])nows += s[now++];
        else if(akb[i] == 'A')nows += 'A';
    }
    if(now < ssize)return 0;
    return nows == akb;
}

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

int main(){
  int s,s1;
    float sf,s2;
    cin >> s;
    sf = s;
    s1 = (sf/100 - s/100)*10;
    s2 = (sf/100 - s/100)*10;
    cout << s/100 + s1 + (s2-s1)*10 << endl;
}





Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <random>
using namespace std;


int main() {
	int x;
	int a, b;

	cin >> x >> a >> b;

	int aa = x - a;
	aa = aa < 0 ? aa*-1 : aa;

	int bb = x - b;
	bb = bb < 0 ? bb*-1 : bb;

	if (aa < bb)
		cout << "A" << endl;
	else
		cout << "B" << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

count=Counter(a)
outrange=0
flow=0

for i in range(n):
    if (a[i]>n):
        outrange+=1

for i in range(1,n+1):
    if (count[i]>i):
        flow+=count[i]-i
    elif (count[i]<i):
        flow+=count[i]

print(flow+outrange)


Measured memory_bytes: 18672