akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n;
  cin >> n;
  vll a(n);
  map<ll,ll> mp;
  rep(i,n) {
    ll a;
    cin >> a;
    mp[a]++;
  }
  ll ans = 0LL;
  for(auto p : mp) {
    ll k = p.first;
    ll v = p.second;
    ans += k*v;
  }
  vll ret;
  ll q;
  cin >> q;
  rep(i,q) {
    ll b, c;
    cin >> b >> c;
    ans -= b*mp[b];
    ans += c*mp[b];
    ret.push_back(ans);
    mp[c] += mp[b];
    mp.erase(b);
  }
  int m = ret.size();
  rep(i,m) cout << ret[i] << endl;
  return 0;
}

Measured memory_bytes: 8912
#include<stdio.h>
int main(void){
  int a,b,c,d,e,k;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%d",&e);
  scanf("%d",&k);
  if(e-a>k){
    printf(":(");
  }
  else{
    printf("Yay!");
  }
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << 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 if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
typedef pair<int, int> PII;

const int MAX = 1e6;
const int B = 1000;

int nums[MAX];
PII bucket[MAX/B];

int N;

void update(int n, int value)
{
	nums[n] += value;
	
	bucket[n/B] = PII(-INF, -1);
	for (int i=(n/B)*B; i<min(N, (n/B+1)*B); i++) {
		if (bucket[n/B].first < nums[i]) {
			bucket[n/B].first = nums[i];
			bucket[n/B].second = i;
		}
	}
}

int main()
{
	int Q;
	cin>>N>>Q;
	
	memset(nums, 0, sizeof(nums));
	memset(bucket, 0, sizeof(bucket));
	
	for (int q=0; q<Q; q++) {
		int a, v;
		cin>>a>>v;
		
		a--;
		update(a, v);
		
		PII ans(-INF, -1);
		for (int i=0; i<=N/B; i++) {
			if (ans.first < bucket[i].first) {
				ans.first = bucket[i].first;
				ans.second = bucket[i].second;
			}
		}
		
		cout << ans.second+1 << " " << ans.first << endl;
	}
}

Measured memory_bytes: 5080
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

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

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

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


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

	vll a(N + 1);
	for (ll i = N; i >= 0; i--) cin >> a[i];

	vector<bool> pr(N + 1, 1);
	pr[0] = 0;
	if(N>0)pr[1] = 0;
	for (ll i = 2; i <= N; i++) {
		if (pr[i] == 0) { continue; }
		for (ll j = 2 * i; j <= N; j += i) { pr[j] = 0; }
	}

	repn(p, N) {
		if (pr[p] == 0) { continue; }

		bool b = 1;
		repn(i, p - 1) {
			ll s = 0;
			for (ll j = i; j <= N; j += p - 1)s += a[j];
			if (s % p != 0) { b = 0; break; }
		}
		if (a[0] % p != 0) { b = 0; }

		if (b)cout << p << endl;
	}

	ll g = abs(a[0]);
	repn(i, N) g = gcd(g, abs(a[i]));

	for (ll c = 2; c * c <= g; c++) {
		if (g % c == 0) {
			if (c > N) { cout << c << endl; }
			while (g % c == 0) { g /= c; }
		}
	}

	if (g > 1&&g>N) { cout << g << endl; }


}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 20 10:02:53 2020

@author: NEC-PCuser
"""

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
   t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

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

int main(){
	int n, acnt, bcnt, ccnt;
	long long a, b, c, in;
	cin >> n;
	a = -1;
	b = -1;
	c = -1;
	acnt = 0;
	bcnt = 0;
	ccnt = 0;
	for(int i=0; i<n; i++){
		cin >> in;
		if(in == a){
			acnt++;
			continue;
		}else if(in == b){
			bcnt++;
			continue;
		}else if(in == c){
			ccnt++;
			continue;
		}else{
			if(a == -1){
				a = in;
				acnt++;
				continue;
			}
			else if(b == -1){
				b = in;
				bcnt++;
				continue;
			}
			else if(c == -1){
				c = in;
				ccnt++;
				continue;
			}

			cout << "No" << endl;
			return 0;
		}
	}
	if(b==(-1) && c==(-1)){
		if(a == 0){
			cout << "Yes" << endl;
			return 0;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	if(c == (-1)){
		if((a^b) == a){
			if(acnt == 2*bcnt){
				cout << "Yes" << endl;
				return 0;
			}else{
				cout << "No" << endl;
				return 0;
			}
		}
		if((a^b) == b){
			if(bcnt == 2*acnt){
				cout << "Yes" << endl;
				return 0;
			}else{
				cout << "No" << endl;
				return 0;
			}
		}
	}

	if((a^b) != c){
		cout << "No" << endl;
		return 0;
	}
	if((acnt == bcnt)&&(bcnt==ccnt)){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    if(a < b){
      System.out.println("a < b");
    }
    else if(a == b){
      System.out.println("a == b");
    }
    else if(a > b){
      System.out.println("a > b");
    }
  }
}


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


int main(){
  int N;
  cin >> N;
  vector<list<pair<int, int>>> A(N);
  for(auto& a : A){
    int m;
    cin >> m;
    for(int ii=0; ii<m; ii++){
      int x, y;
      cin >> x >> y;
      x--;
      a.push_back({x, y});
    }
  }
  
  int ans = 0;
  for(int ii=0; ii<(1<<N); ii++){
    bool check = true;
    for(int jj=0; jj<N; jj++){
      for(auto& b : A[jj]){
        if((ii>>jj)&1){
          if(((ii>>b.first)&1)!=b.second){
            check = false;
            break;
          }
        }
      }
      if(check==false) break;
    }
    if(check==false) continue;
    int num_honest = 0;
    for(int jj=0; jj<N; jj++){
      if((ii>>jj)&1) num_honest++;
    }
    ans = max(ans, num_honest);
  }
  cout << ans << endl;
  return 0;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int r,g,b,n;
  cin>>r>>g>>b>>n;
  int res=0;
  for(int i=0;i<3005;i++){
    if(i*r>n)break;
    for(int j=0;j<3005;j++){
      int t=i*r+j*g;
      // cout<<t<<':'<<i<<' '<<j<<endl;
      if(t>n)break;
      if(t==n){
        res++;
        // cout<<t<<':'<<i<<' '<<j<<' '<<0<<endl;
        break;
      }
      if((n-t)%b==0){
        res++;
        // cout<<t<<':'<<i<<' '<<j<<' '<<(n-t)/b<<endl;
      }
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <limits>
#include <cmath>
#include <typeinfo>
 
 
using namespace std; 


int main() {
	string s;
	cin >> s;
	if(s == "SUN") {
		cout << 7 << endl;
		return 0;
	}
	if(s == "SAT") {
		cout << 1 << endl;
		return 0;
	}
	if(s == "FRI") {
		cout << 2 << endl;
		return 0;
	}
	if(s == "THU") {
		cout << 3 << endl;
		return 0;
	}
	if(s == "WED") {
		cout << 4 << endl;
		return 0;
	}
	if(s == "TUE") {
		cout << 5 << endl;
		return 0;
	}
	if(s == "MON") {
		cout << 6 << endl;
		return 0;
	}	

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

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

int main(){
    int n;
    while(cin>>n, n){
        double ave=0;
        vector<double> a(n);
        for(int i=0; i<n; i++){
            cin>>a[i];
            ave+=a[i];
        }
        ave/=n;

        int ans=0;
        for(int i=0; i<n; i++){
            if(a[i]<=ave) ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3268
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;


long long Sum(const string& str, int i, vector<int>& plus)
{
	int n = str.size();
	if (i == n - 1)
	{
		long long sum = 0;
		string str1;
		for (int i = 0; i < n; ++i)
		{
			str1 += str[i];
			if (plus[i] != 0)
			{
				sum += stoll(str1);
				str1.clear();
			}
		}
		return sum;
	}

	long long ret = 0;
	plus[i] = 1;
	ret += Sum(str, i + 1, plus);
	plus[i] = 0;
	ret += Sum(str, i + 1, plus);
	return ret;
}
void ARC061C()
{
	string str;
	cin >> str;
	int n = str.size();

	vector<int> flag(n);
	flag.back() = 1;
	auto x = Sum(str, 0, flag);
	cout << x << endl;
}
int main()
{
	ARC061C();
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define forn(i, s, f) for (int i = s; i < f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int a, p;
    cin >> a >> p;
    p += 3 * a;
    cout << p / 2;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define sum(x) accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

struct LCS {
private:
  vector<vector<int>> dp;
  string one, two;
  int n1, n2;

public:
  LCS(string &temp1, string &temp2): n1(temp1.size()), n2(temp2.size()) {
    one = temp1;
    two = temp2;
    dp.assign(n1 + 1, vector<int>(n2 + 1, 0));
  }
  int lcs() {
    for (int i = 0; i < n1; i++) {
      for (int j = 0; j < n2; j++) {
        if (one[i] == two[j]) {
          dp[i + 1][j + 1] = max({dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1]});
        } else {
          dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        }
      }
    }
    return dp[n1][n2];
  }
  string restoration() { // do after lcs
    string ret{};
    int i = n1, j = n2;
    while (i != 0 and j != 0) {
      if (dp[i][j] == dp[i - 1][j]) {
        i--;
      } else if (dp[i][j] == dp[i][j - 1]) {
        j--;
      } else {
        i--;
        j--;
        ret += one[i];
      }
    }
    reverse(ALL(ret));
    return ret;
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  LCS lcs(s, t);
  lcs.lcs();
  cout << lcs.restoration() << endl;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

//http://www.prefield.com/algorithm/misc/interval_scheduling.html
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<pair<ll, ll>> xl(n);
    rep(i, n) {
        ll x, l; cin >> x >> l;
        xl[i] = make_pair(x+l, x-l);
    }
    sort(xl.begin(), xl.end());

    int ans = 0;
    rep(i, n) {
        ll right = xl[i].first;
        ++ans;
        while(i+1<n && xl[i+1].second<right) ++i;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
G = [[] for i in range(N)]
deg = [0] * N
E = []
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)
    E.append((a, b))
    deg[a] += 1
    deg[b] += 1

C = list(map(int, input().split()))
C = sorted(C)
que = deque()
for i in range(N):
    if deg[i] == 1:
        que.append(i)

D = [-1] * N
used = [0] * N
i = 0
while i < N:
    k = que.popleft()
    D[k] = C[i]
    i += 1
    for w in G[k]:
        deg[w] -= 1
        if deg[w] == 1:
            que.append(w)

ans = 0
for i in range(len(E)):
    ans += min(D[E[i][0]], D[E[i][1]])

print(ans)
print(*D)

Measured memory_bytes: 47984
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int n, k;
    cin >> n >> k;
    vector pre(n+1, 0);
    for (int i=0; i<n; i++) cin >> pre[i];

    vector ans(n+1, 0);
    for (int _=0; _<k; _++) {
        ans = vector(n+1, 0);
        for (int i=0; i<n; i++) {
            ans[max(0, i-pre[i])]++;
            ans[min(n, i+pre[i]+1)]--;
        }

        for (int i=0; i<n; i++)
            ans[i+1] += ans[i];

        if (all_of(ans.begin(), ans.end()-1, [&](const int& x){return x==n;})) {
            break;
        }

        pre = ans;
    }
    for (int i=0; i<n; i++) {
        if (i != 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 5216
#include<stdio.h>
int main()
{
	int K,X,a,b,c;
	scanf("%d %d",&K,&X);
	if(1<=K && K <=100 && 0<=K && K <=100)
	{
		a = X;
		b = a - K + 1;
		c = a + K - 1;

		for(;b <= c;b++)
		{
			printf("%d ",b);
		}

	}
return 0;
}

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

long long fac(int k){long long sum = 1;for(int i=1;i<=k;++i)sum *= i;return sum;}
long long per(int n,int r){long long nn,rr;nn=fac(n);rr=fac(r)*fac(n-r);return nn/rr;}

int main(){
    int H,W;
    cin >> H >> W;
    char s[50][50];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> s[i][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(s[i][j]=='#'){
                bool f = false;
                if(i-1>=0){
                    if(s[i-1][j]=='#')f=true;
                }
                if(j-1>=0){
                    if(s[i][j-1]=='#')f=true;
                }
                if(i+1<H){
                    if(s[i+1][j]=='#')f=true;
                }
                if(j+1<W){
                    if(s[i][j+1]=='#')f=true;
                }
                if(f==false){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}

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

signed main(){
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N)cin>>A[i];
  int S=0,ans=0;
  rep(i,N+1){
    S=A[S]-1;
    ans++;
    if(S==1){
      cout<<ans;
      return 0;
    }
  }
  cout<<-1;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n;
	cin >> n;
	vector<int> a(3 * n);
	for (int i = 0; i < 3 * n;i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());
	ll sum = 0;
	for (int i = n; i < 3 * n;i += 2) {
		sum += a[i];
	}
	cout << sum << endl;


}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  ll A, B;
  cin >> A >> B;
  if(A > 0) {
    cout << "Positive" << endl;
  }
  else if(B < 0) {
    if((B - A + 1) % 2 == 0) {
      cout << "Positive" << endl;
    }
    else {
      cout << "Negative" << endl;
    }
  }
  else {
    cout << "Zero" << endl;
  }
}

Measured memory_bytes: 3616
import math
n=int(input())
while n != 0 :
	sums = 0.0
	s = list(map(float,input().split()))
	m = sum(s)/n
	for i in range(n):
		sums += ((s[i]-m)**2)/n
	print(math.sqrt(sums))
	n = int(input())


Measured memory_bytes: 5780
N = int(input())
tr = [int(input()) for i in range(5)]
# s = -(-N // tr[0])
# cnt = 5 + s - 1
# for i in range(1, 5):
#    # print(cnt, s, (-(-N // tr[i]) - s))
#    if (-(-N // tr[i]) - (-(-N // tr[i-1]))) > 0:
#        cnt += -(-N // tr[i]) - (-(-N // tr[i-1]))
print(-(-N // min(tr)) + 4)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
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_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

vector<int> N(4);

int main()
{
    cin >> N;
    sort(N.begin(), N.end());
    if (N == vector<int>{1, 4, 7, 9}) puts("YES");
    else puts("NO");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#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(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int main(){
    int N;
    cin >>N;
    set<string> S;
    rep(i,N){
        string gacha;
        cin >> gacha;
        S.insert(gacha);
    }
    cout << S.size()<<endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> f(H);
  cin >> f;
  int ans = INF;
  for (int S = 0; S < (1 << (H - 1)); S++) {
    vector<int> belong(H, 0);
    for (int i = 1; i < H; i++) {
      if ((S >> (i - 1)) & 1)
        belong[i] = belong[i - 1] + 1;
      else
        belong[i] = belong[i - 1];
    }
    int base = 0;
    for (int i = 0; i < H - 1; i++)
      if ((S >> i) & 1) base++;
    int res = 0;
    int m = belong.back() + 1;
    vector<int> cnt(m, 0);
    int cur = 0;
    while (cur < W) {
      auto tmp = cnt;
      for (int i = 0; i < H; i++) {
        if (f[i][cur] == '1') tmp[belong[i]]++;
      }
      bool judge = true;
      for (int i = 0; i < m; i++) {
        if (tmp[i] > K) judge = false;
      }
      if (!judge) {
        cnt = vector<int>(m, 0);
        for (int i = 0; i < H; i++) {
          if (f[i][cur] == '1') cnt[belong[i]]++;
        }
        for (int i = 0; i < m; i++) {
          if (cnt[i] > K) res = INF;
        }
        res++;
      } else {
        cnt = tmp;
      }
      cur++;
    }
    chmin(ans, res + base);
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
pair<int, int> dp[32][32][32][32];
int table[32][32], sum_table[32][32];
int h, w, s;
int calc(int sy, int sx, int gy, int gx)
{
    int res = sum_table[gy][gx];
    if(sy > 0) res -= sum_table[sy - 1][gx];
    if(sx > 0) res -= sum_table[gy][sx - 1];
    if(sy > 0 and sx > 0) res += sum_table[sy - 1][sx - 1];
    return res;
}
pair<int, int> dfs(int sy, int sx, int gy, int gx)
{
    if(dp[sy][sx][gy][gx].first) return dp[sy][sx][gy][gx];
    int cost = sum_table[h - 1][w - 1] - calc(sy, sx, gy, gx);
    if(cost > s) return dp[sy][sx][gy][gx] = make_pair(-1, -1);
    pair<int, int> res = {1, -cost};
    for(int i = sy; i < gy; i++)
    {
        pair<int, int> s = dfs(sy, sx, i, gx), t = dfs(i + 1, sx, gy, gx);
        if (s.first == 0 or t.first == 0) continue;
        pair<int, int> u = make_pair(s.first + t.first, min(s.second, t.second));
        if(res < u) res = u;
    }

    for(int j = sx; j < gx; j++)
    {
        pair<int, int> s = dfs(sy, j + 1, gy, gx), t = dfs(sy, sx, gy, j);
        if(s.first == 0 or t.first == 0) continue;
        pair<int, int> u = make_pair(s.first + t.first, min(s.second, t.second));
        if(res < u) res = u;
    }
    return dp[sy][sx][gy][gx] = res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> h >> w >> s, h or w or s)
    {
        for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> table[i][j];
        memset(dp, 0, sizeof(dp));
        memset(sum_table, 0, sizeof(sum_table));
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                sum_table[i][j] = table[i][j];
                if(i > 0) sum_table[i][j] += sum_table[i - 1][j];
                if(j > 0) sum_table[i][j] += sum_table[i][j - 1];
                if(i > 0 and j > 0) sum_table[i][j] -= sum_table[i - 1][j - 1];
                //cout << setw(5) << sum_table[i][j] << " ";
            }
            //cout << endl;
        }
        pair<int, int> ans = dfs(0, 0, h - 1, w - 1);
        cout << ans.first << " " << s + ans.second << endl;
    }
    return 0;
}





Measured memory_bytes: 11292
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

ll dp[N+5]={1000000000}; 
int main(){
    REP(i,N+5){
        dp[i]=1000000000000000000;
    }
	int n;
    cin>>n;
    vector<int> h(n);
    REP(i,n) {
        cin>>h.at(i);
    }
    dp[0]=0;
    REP(i,n-1){
        dp[i+1]=min(dp[i+1],(dp[i]+abs(h[i+1]-h[i])));
        if(i>=n-2) continue;
        dp[i+2]=min(dp[i+2],(dp[i]+abs(h[i+2]-h[i])));
       // OUT(dp[i+1]);
        //OUT(dp[i+2]);
    }
    OUT(dp[n-1]);
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    String s = "";
    if(r<1200){
      s="ABC";
    }else if(r<2800){
      s="ARC";
    }else{
      s="AGC";
    }
    System.out.println(s);
  }
  

  
}

Measured memory_bytes: 22356
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
using namespace std;

int main() {
    string S;
    cin >> S;
    int size = S.size();
    if (S[size - 1] == 's') {
        S.push_back('e');
        S.push_back('s');
    }
    else {
        S.push_back('s');
    }
    cout << S << endl;
    
}

Measured memory_bytes: 3132
n,m = map(int, input().split())
amat = [[0 for i in range(m)] for j in range(n)]
bmat = [[0 for k in range(1)] for l in range(m)]
cmat = [[0 for x in range(1)] for y in range(n)]
for i in range(n):
 amat[i] = list(map(int, input().split()))
for j in range(m):
 bmat[j][0] += int(input())
for k in range(n):
 for l in range(m):
  cmat[k][0] += amat[k][l]*bmat[l][0]
 print(cmat[k][0])


Measured memory_bytes: 5964
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main() {
	int n; cin >> n;
	int a, b, c, d;
	string ans = "No";
	a = n/1000;
	b = (n-a*1000)/100;
	c =  (n-a*1000-b*100)/10;
	d = n-a*1000-b*100-c*10;
	if (a==b && b==c){
		ans = "Yes";
	}
	if(b==c && c==d){
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

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

public class Main {

  int[] dp;
  void solve(InputReader in, PrintWriter out) {
    int h = in.nextInt();
    int n = in.nextInt();
    int[][] arr = new int[n][2];

    for (int i = 0; i < n; ++i) {
      arr[i][0] = in.nextInt();
      arr[i][1] = in.nextInt();
    }

    dp = new int[h + 1];
    Arrays.fill(dp, Integer.MAX_VALUE);

    out.println(solve(h, arr));
  }

  public int solve(int h, int[][] arr) {
    if (h <= 0) return 0;
    if (dp[h] != Integer.MAX_VALUE) return dp[h];

    for (int i = 0; i < arr.length; ++i) {
      dp[h] = Math.min(dp[h], solve(h - arr[i][0], arr) + arr[i][1]);  
    }

    return dp[h];
  }
  public static void main(String[] args) throws Exception {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Main solver = new Main();
    solver.solve(in, out);
    out.close();
  }

  static class InputReader {
    BufferedReader in;
    StringTokenizer st;

    public InputReader(InputStream is) {
      in = new BufferedReader(new InputStreamReader(is));
    }

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

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

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


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

bool solve();

int main()
{
	if (solve()) puts("First");
	else puts("Second");

	return 0;
}

bool solve()
{
	int N;
	scanf("%d", &N);
	std::vector<int> a(N);
	for (auto& e: a) scanf("%d", &e);
	std::sort(a.rbegin(), a.rend());
	a.push_back(0);
	for (auto& e: a) e--;
	int center{};
	while (center + 1 <= a[center + 1]) center++;
	// 後手が相手と逆のを選んだ場合の挙動
	if ((a[center] + center) % 2 == 0)	// centerが負けの場合
	{
		if (a[center + 1] < center) return false;	// 先手がcenter+1に行けない場合
		int count{};
		for (int i{center + 1}; i < N; i++)
			if (a[i] == a[center + 1])
				count++;
		if (count % 2 == 1) return true;
		return false;
	}
	else
	{
		if (center < a[center]) return true;
		if (center > 0 && (a[center - 1] + center) % 2 == 0) return true;
		return false;
	}
}

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 1e5 + 2;

int P[N], W[N], V[N], U[N], Q[N];

int GetPar(int v) { return P[v] == v ? v : P[v] = GetPar(P[v]); }
bool Merge(int v, int u) {
	v = GetPar(v), u = GetPar(u);
	if (v == u) return false;
	P[v] = u;
	return true;
}
int Power(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
	return res;
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);	
	
	int n, m; cin >> n >> m;
	ll x; cin >> x;
	for (int i = 0; i < m; i++) cin >> V[i] >> U[i] >> W[i], Q[i] = i;
	sort(Q, Q + m, [&](int i, int j) { return W[i] < W[j]; });
	int les = 0, eq = 0, gre = 0;
	for (int i = 0; i < m; i++) {
		ll s = 0;
		for (int j = 0; j < n; j++) P[j + 1] = j + 1;
		if (Merge(V[Q[i]], U[Q[i]])) s += W[Q[i]];
		for (int j = 0; j < m; j++) if (Merge(V[Q[j]], U[Q[j]])) s += W[Q[j]];
		if (s < x) les++;
		if (s == x) eq++;
		if (s > x) gre++;
	}
	if (les) cout << 2LL * (Power(2, eq) - 1) * Power(2, gre) % MOD << endl;
	else if (eq) cout << 1LL * (Power(2, eq) - 2) * Power(2, gre) % MOD << endl;
	else cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int n,d;
cin>>n>>d;
int ans=1;
n-=(2*d+1);
while(n>0)
{
	n-=(2*d+1);
	ans++;
}
cout<<ans;


}







Measured memory_bytes: 256
from fractions import gcd


def main():
    N = int(input())
    *A, = map(int, input().split())

    L = [0] * (N+1)
    R = [0] * (N+1)
    G = [0] * N
    L[0] = A[0]
    R[N-1] = A[N-1]
    for i in range(1, N):
        L[i] = gcd(L[i-1], A[i])
    for i in range(N-1)[::-1]:
        R[i] = gcd(R[i+1], A[i])
    G[0] = R[1]
    G[N-1] = L[N-2]
    for i in range(1, N-1):
        G[i] = gcd(L[i-1], R[i+1])
    print(max(G))


main()


Measured memory_bytes: 91104
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int maxn=2e5+5;
int a[maxn];
string s;
int main()
{
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    int a1,a2,a3;cin>>a1>>a2>>a3;
    swap(a1,a2);
    swap(a1,a3);
    cout<<a1<<" "<<a2<<" "<<a3<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool is_palin(string s)
{
     string t(s.rbegin(), s.rend());
     return s==t;
}
int main() {
    
    string s;
    cin>>s;
    int n = s.size();
    if (is_palin(s) && is_palin(s.substr(0,(n-1)/2)) && is_palin(s.substr((n+1)/2)))  
         cout<<"Yes";
    else
         cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mo=1e9+7;
int n,m,k,f[20][1<<19],S[1<<19][20],B[2][22][22];
void inc(int &x,int y){ x=x+y>=mo ? x+y-mo : x+y;}
int main()
{
	int i,j,l,x,y,z;
	cin>>n>>m>>k; n--;
	for(i=1;i<=k;i++){
		scanf("%d %d %d",&x,&y,&z),y--;
		B[z][x][y]=1;
	  }
	f[0][0]=1;
	for(i=0;i<(1<<n);i++){
		S[i][n]=(1<<n);
		for(j=n-1;j>=0;j--){
			S[i][j]=S[i][j+1];
			if((i>>j)&1)
				S[i][j]=(1<<j);
		  }
	  }
	f[0][0]=1;
	for(l=1;l<=m;l++){
		for(j=0;j<n;j++)
			for(i=0;i<(1<<n);i++){
				y=((i>>j)&1);
				for(x=y;x<2;x++){
					if(B[x^1][l][j]) continue;
					if(x==y) inc(f[j+1][i],f[j][i]);
					else{
						z=i^(1<<j);
						if(S[i][j]<(1<<n)) z^=S[i][j];
						inc(f[j+1][z],f[j][i]);
					  }
				  }
			  }
		for(i=0;i<(1<<n);i++){
			f[0][i]=f[n][i];
			for(j=1;j<=n;j++) f[j][i]=0;
		  }
	  }
	int ans=0;
	for(i=0;i<(1<<n);i++)
		inc(ans,f[0][i]);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 82176
import sys
x,n = map(int, sys.stdin.readline().rstrip("\n").split())
p = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
num = [i for i in range(-200,200)]
for i in range(n):
    num.remove(p[i])
if not num:
    pass
elif x in num:
    print(x)
else:
    d = 1
    while True:
        if x-d in num:
            print(x-d)
            break
        elif x+d in num:
            print(x+d)
            break
        else:
            d += 1

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vector<double> dp(1, 1);
	rep(i, n){
		double p; cin >> p;
		vector<double> next(i + 2);
		rep(j, dp.size()){
			next[j + 1] += dp[j] * p;
			next[j] += dp[j] * (1 - p);
		}
		dp = next;
	}
	double ans = 0;
	for(int i = 0; i <= n; i++) if(i > n - i) ans += dp[i];
	printf("%.20f\n", ans);
	return 0;
}

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

typedef long long ll;

int main(){
    int n;
    cin >> n;
    queue<string> q;
    stack<string> s;

    // nが偶数 -> 奇数番目が前 -> 奇数番目をstack
    // nが奇数 -> 偶数番目が前 -> 偶数番目をstack
    for(int i = 0; i < n; i++){
        string tmp;
        cin >> tmp;
        if(n % 2 == 0){
            if(i % 2 == 0){
                q.push(tmp);
            } else { 
                s.push(tmp);
            }
        } else { 
            if(i % 2 != 0){
                q.push(tmp);
            } else { 
                s.push(tmp);
            }
        }
    }
    // stackから追加していく
    vector<string> ans;
    while(!s.empty()){
        ans.push_back(s.top());
        s.pop();
    }
    while(!q.empty()){
        ans.push_back(q.front());
        q.pop();
    }
    for(int i = 0; i < ans.size(); i++){
        if(i == ans.size() -1){
            cout << ans[i] << endl;
        } else {
            cout << ans[i] << " ";
        }
    }
}


Measured memory_bytes: 17648
#include <stdio.h>

int main (void) {
    int N;
    scanf ("%d", &N);
    int l[N], r[N], sum=0;
    for (int i=0; i<N; i++){
        scanf (" %d %d", &l[i], &r[i]);
        sum += r[i]-l[i]+1;
    }
    //FR
    printf ("%d\n", sum);
    return 0;
}

Measured memory_bytes: 128
import sys

n,m = map(int,input().split())

if n >= m :
  print("0")
  sys.exit()
xlist = [int(_) for _ in input().split()]
xlist.sort()
nlist = []
for i in range(m-1):
  nlist.append(xlist[i+1] - xlist[i])
nlist.sort()

print(sum(nlist[0:m-n]))

Measured memory_bytes: 13832
#include <iostream>

using namespace std;

int pat(int n,int s,int d){
  if(n==0){
    if(s==0) return 1;
    else return 0;
  }
  if(d<0) return 0;

  return pat(n-1,s-d,d-1) + pat(n,s,d-1);
}

int main(){
  int n,s;
  while(cin>>n>>s&&(n>0||s>0)){
    cout << pat(n,s,9) << endl;
  }
}

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

int n, a[200], ans = INT32_MAX;

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

	for (int i = 0; i < n; i++) {
		int count = 0;
		while (a[i]%2 == 0 && a[i] > 1) {
			count++;
			a[i] /= 2;
		}
		ans = min(ans, count);
	}

	cout << ans << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdlib>
#include <cstdio>
#define N 5011
#define int long long
using namespace std;
int val[N][211],Sum[N][N],Stack[N],L[N],R[N],top,dis[N],n,m,ans;
void solve(int k){
	for(int i=1;i<=n;i++){
		while(top && val[Stack[top]][k]<val[i][k]){
			R[Stack[top]]=i-1;
			top--;
		}
		L[i]=Stack[top]+1;
		Stack[++top]=i;
	}
	while(top){
		R[Stack[top]]=n;
		top--;
	}
	for(int i=1;i<=n;i++){
		Sum[L[i]][i]+=val[i][k];
		Sum[L[i]][R[i]+1]-=val[i][k];
		Sum[i+1][i]-=val[i][k];
		Sum[i+1][R[i]+1]+=val[i][k];
	}
}
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=2;i<=n;i++) scanf("%lld",&dis[i]);
	for(int i=2;i<=n;i++) dis[i]+=dis[i-1];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%lld",&val[i][j]);
		}
	}
	for(int i=1;i<=m;i++) solve(i);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			Sum[i][j]=Sum[i][j]+Sum[i-1][j]+Sum[i][j-1]-Sum[i-1][j-1];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			ans=max(ans,Sum[i][j]-(dis[j]-dis[i]));
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 204800
#include<iostream>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

map< ll, ll > prime_factor(ll n) {
	  map< ll, ll > ret;
		  for(ll i = 2; i * i <= n; i++) {
		    while(n % i == 0) {
		      ret[i]++;
		      n /= i;
		    }
		  }
	  if(n != 1) ret[n] = 1;
	  return ret;
}


int main(){
	ll A, B; cin >> A >> B;

	map<ll, ll> tmp = prime_factor(GCD(A, B));
	/*
	auto itr = tmp.begin();
	for(; itr != tmp.end(); itr++){
		cout << itr->first << " " << itr->second << endl;
	}
	// cout << tmp.size() << endl;
	*/

	// cout << GCD(A, B) << endl;
	cout << tmp.size()+1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <limits>
#include <time.h>
#define inf 998244353

using namespace std;

struct w
{
    int l, r, o, len;
}w[100005];

bool cmp(struct w a,struct w b)
{
    if(a.r!=b.r)
    {
        return a.r<b.r;
    }
    return a.l<b.l;
}

int main(void){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&w[i].o,&w[i].len);
        w[i].l=w[i].o-w[i].len;
        w[i].r=w[i].o+w[i].len;
    }
    sort(w,w+n,cmp);
    int p=w[0].r, z=1;
    for(int i=0;i<n;i++)
    {
        if(w[i].l>=p)
        {
            p=w[i].r;
            z++;
        }
    }
    printf("%d\n",z);
	return 0;
}


Measured memory_bytes: 1792
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define en '\n'
#define rep(i,n)    for(ll i=0; i<n; i++)
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(1);
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;



int main()
{
    godspeed
    ll  t,n,i,j,k,x,l,ans=0,cnt;
    string s;
    cin>>s;
        cnt=0;
    for(i=0;s[i];i++)
    {
        if(s[i]=='R') cnt++;
        else{
            ans=max(ans,cnt);
            cnt=0;
        }
    }
        cout<<max(ans,cnt)<<en;

    return 0;
}





Measured memory_bytes: 3632