akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define Test ll t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define loopS(i,a,b,step) for(ll i=a;i<b;i+=step)
#define loopRS(i,a,b,step) for(ll i=a;i>=b;i-=step)
#define ull unsigned long long int
#define pll pair<ll,ll>
#define puu pair<ull, ull>
#define V vector
#define M map
#define UM unordered_map
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf INT_MAX
#define S3(a,b,c) cin >> a >> b >> c
#define S2(a,b) cin >> a >> b
#define debug(x) cerr << #x << " = " << x << endl;
#define debug2(x,y) cerr << #x << " = " << x << " " << #y << " = " << y << endl;
#define debug3(x,y,z) cerr << #x << " = " << x << " " << #y << " = " << y <<  " " << #z << " = " << z << endl;
using namespace std;

void input(ll n, ll arr[]) {
	rep(i, 0, n)cin >> arr[i];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout.tie(NULL);
	string s; cin >> s;
	ll ans = 0;
	char c = s[0];
	ll cntone = 0, cntzero = 0, cnt = 1;
	if (s[0] == '0')cntzero++;
	else cntone++;
	rep(i, 1, s.size()) {
		if (s[i] == c)cnt++;
		else {
			if (cnt == 0) {
				c = ((c == '0') ? '1' : '0');
				cnt = 1;
			} else {
				ans += 2;
				cnt--;
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n,k;cin>>n>>k; unordered_map<ll,ll>m;
    while(k--)
    {
         ll d;cin>>d;
         while(d--)
         {
              ll tp;cin>>tp;
              m[tp]++;
         }
    }
    cout<<n-m.size();
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<queue>

using namespace std;
static const int N=100;
static const int INFTY=(1<<21);

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

int n,M[N][N];
int d[N];

void bfs(int s)
{
    queue<int> q;
    q.push(s);
    rep(i,n)d[i]=INFTY;
    d[s]=0;
    int u;
    while (!q.empty())
    {
        u=q.front();
        q.pop();
        rep(v,n)
        {
            if(M[u][v]==0)continue;
            if (d[v]!=INFTY)continue;
            d[v]=d[u]+1;
            q.push(v);
        }
    }
    rep(i,n)
    {
        cout<<i+1<<" "<<((d[i]==INFTY)?(-1):d[i])<<endl;
    }
}

int main()
{
    int u,k,v;

    cin>>n;
    rep(i,n)
    {
        rep(j,n)M[i][j]=0;
    }
    
    rep(i,n)
    {
        cin>>u>>k;
        u--;
        rep(j,k)
        {
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    bfs(0);

    return 0;
}



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


int main()
{
    ifstream fIn("input.txt");
    if (fIn.is_open())
        cin.rdbuf(fIn.rdbuf());

    ll n;
    cin >> n;
    ll ans = 1e18;
    for(ll i = 1; i * i <= n; ++i){
        if(n % i != 0)continue;
        ll j = n / i;
        ans = min(ans, i + j - 2);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,l=map(int,input().split())
dic={0:0}
for _ in range(n):
  w,v=map(int,input().split())
  tmp=sorted(list(dic.keys()),reverse=True)
  for key in tmp:
    if key+w not in dic:
      dic[key+w]=dic[key]+v
    else:
      dic[key+w]=max(dic[key]+v,dic[key+w])
tmp=sorted(list(dic.keys()))
ans=0
for key in tmp:
  if key>l:
    break
  ans=max(ans,dic[key])
print(ans)

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

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(int argc, const char * argv[]) {
    
    ll A, B ; cin >> A >> B;
    ll x = max(1,2);
    cout << max(0LL,A-2*B) << endl;
    
    return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

const int maxn = 100005;

struct Edge
{
	int to, nxt;
} e[maxn << 1];

int first[maxn];

inline void add_edge(int from, int to)
{
	static int cnt = 0;
	e[++cnt].nxt = first[from];
	first[from] = cnt;
	e[cnt].to = to;
	e[++cnt].nxt = first[to];
	first[to] = cnt;
	e[cnt].to = from;
}

bool shan[maxn];
int n;

inline void dfs(int now, int fa)
{
	for(int i = first[now]; i; i = e[i].nxt)
	{
		register int to = e[i].to;
		if(to != fa)
			dfs(to, now);
	}
	if(!shan[now])
	{
		if(shan[fa])
		{
			puts("First");
			exit(0);
		}
		shan[now] = shan[fa] = true;
	}
}

int main()
{
	shan[0] = true;
	scanf("%d", &n);
	for(int i = 1, f, t; i < n; ++i)
	{
		scanf("%d%d", &f, &t);
		add_edge(f, t);
	}
	dfs(1, 0);
	puts("Second");
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-9;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,k;cin>>n>>k;
    ll ans=k;
    rep(i,1,n)ans*=k-1;
    cout<<ans<<endl;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define ar array

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
 
    int x, y;
    cin >> x >> y;
    for (int a = 0; a <= x; a++) {
        int b = x - a;
        if (2 * a + 4 * b == y) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> memo(100005,-INF);

ll f(ll x){
    if(x==0 || x==1) return 1;
    else if(memo[x]!=-INF) return memo[x];
    else{
        return memo[x]=(f(x-1)+f(x-2))%MOD;
    }
}

int main(){
    ll N,M; cin>>N>>M;
    ll ans=1;
    vector<ll> A(M);
    
    rep(i,M){
        cin>>A[i];
        if(i>=1 && A[i]==A[i-1]+1){
            cout<<0<<endl;
            return 0;
        }
    }
    A.pb(N+1);
    // 0~A[0]-1,A[0]+1~A[1]-1,....,A[M-1]+1~N(=A[M]-1)
    rep(i,M+1){
        if(i==0){
            ans*=f(A[0]-1);
            ans%=MOD;
        }
        else{
            ans*=f(A[i]-A[i-1]-2);
            ans%=MOD;
        }
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 7124
#include<bits/stdc++.h>
using namespace std;
 
 
int main()
{
	int n,m;
	cin>>n>>m;
	vector<int> votes(n);
	double total=0;
	for(int i=0;i<n;i++){
		cin>>votes[i];
		total += votes[i];
	}
	double qualify = (total/4)/m;
	sort(votes.rbegin(),votes.rend());
	
	
	if(votes[m-1]<qualify) cout<<"No";
	else cout<<"Yes";
	
	
}

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

using namespace std;

#define M 1000000007

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<long long int> x(n);
	vector<long long int> y(m);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	long long int ysum = 0;
	for (int i = 0; i < m; i++) {
		cin >> y[i];
	}
	long long int l, r;
	l = 0; r = m - 1;


	while (r - l > 0) {
		ysum += (y[r] - y[l])*(r-l);
		ysum %= M;
		r--;
		l++;
	}
	/*
	for (int i = 0; i < m - 1; i++) {
		for (int j = i + 1; j < m; j++) {
			ysum += (y[j] - y[i]);
			ysum %= M;
		}
	}*/

	long long int ans = 0;
	long long int xsum = 0;
	l = 0; r = n - 1;
	while (r - l > 0) {
		xsum += (x[r] - x[l])*(r - l);
		xsum %= M;
		r--;
		l++;
	}
	/*
	for (int i = 0; i < n-1; i++) {
		for (int j = i + 1; j < n; j++) {
			xsum += (x[j] - x[i]);
			xsum %= M;
		}
	}*/

	ans = xsum * ysum;
	ans %= M;

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)


int check(int k)
{
    int x = 7;
    if( k % 2 == 0 ) return -1;
    if( k % 5 == 0 ) return -1;
    int count = 1;
    while(true)
    {
        if( x % k == 0 ) return count;
        count++;
        x = (x * 10 + 7) % k;
    }

}

int main()
{
    int k;
    cin >> k;
    cout << check(k);
    return 0;    
}

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

char str[1010];
int len;

int main(){
    cin>>str; len=strlen(str);
    for(int i=0;i<len;i++){
        if(str[i]==',') cout<<" ";
        else cout<<str[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	char a[10],b[10],c[10];
	scanf("%s%s%s",a,b,c);
	int la=strlen(a);
	int lb=strlen(b);
	if(a[la-1]==b[0]&&b[lb-1]==c[0])
		printf("YES\n");
	else
	    printf("NO\n");
}

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


// kugiri[i]=1 は i番目直後の区切りがある 0<=i<=H-2

int solve(vector<int> hsplit, vector< vector<int> >& choco, int K){

    vector<int> vsplit(choco[0].size()-1,0);
    int num_hsplit=0; for(int i=0;i<hsplit.size();i++){ num_hsplit+=hsplit[i]; }
    vector<int> tmp(num_hsplit,0);

    int count = 0;
    for(size_t w=0;w<choco[0].size();w++){
        
        for(size_t h=0,i=0;h<choco.size();h++){
            count += choco[h][w];

            // 最後のとき or 区切りがあるとき
            if(hsplit[h]==1){
                // 上限超えたら
                if(count+tmp[i]>K){
                    // 前の部分で区切らないといけない
                    // ただし先頭なら不可能なやつ
                    if(w==0){
                        return 10*1000;
                    }
                    vsplit[w-1] = 1;
                    count = 0;
                    for(size_t j=0;j<tmp.size();j++){ tmp[j] = 0; }
                    w--;
                    break;
                // 超えてないなら次
                }else{
                    tmp[i] += count;
                    i++;
                    count = 0;
                }
            }
        }
    }

    int num_vsplit=0; for(size_t i=0;i<vsplit.size();i++){ num_vsplit+=vsplit[i]; }
    

    //cout << "===================================" << endl;
    //for(size_t h=0;h<choco.size();h++){
    //    for(size_t w=0;w<choco[h].size();w++){
    //        cout << choco[h][w];
    //        if(vsplit[w]==1){ cout << '|';}
    //    }
    //    cout << endl;
    //    if(h!=hsplit.size()-1 && hsplit[h]==1){
    //        for(size_t w=0;w<num_vsplit+choco[h].size();w++){
    //            cout << '-';
    //        }
    //        cout << endl;
    //    }
    //}

    int result = num_vsplit+num_hsplit-1;

    //cout << "(" << result << ")" << endl;

    return result;
}


int recursive_comb_and_solve(vector<int> kugiri, int tmp_pos, vector< vector<int> >& choco, int K){
    int result;
    if(tmp_pos<kugiri.size()-1){
        kugiri[tmp_pos]=0;
        int a = recursive_comb_and_solve(kugiri, tmp_pos+1, choco,K);
        kugiri[tmp_pos]=1;
        int b = recursive_comb_and_solve(kugiri, tmp_pos+1, choco,K);
        result = min(a,b);
    }else{
        kugiri[kugiri.size()-1] = 1;
        result = solve(kugiri, choco, K);
    }
    return result;
}


int main(){

    int H,W,K;
    cin >> H >> W >> K;

    vector< vector<int> > choco(H, vector<int>(W, 0));

    char c;
    for(int h=0;h<H;h++)for(int w=0;w<W;w++){
        cin >> c;
        choco[h][w] = c-48;
    }

    vector<int> kugiri(H,0);
    int minv = recursive_comb_and_solve(kugiri, 0, choco, K);
    cout << minv << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
// #define ll long long
typedef long long ll;
typedef pair<int, int> P;

const int V = 100005;
vector<int> to[V*2];
bool visited[V*2];
vector<int> cnt;

void dfs(int v){
  if (visited[v]) return;
  visited[v] = true;
  cnt[v/V]++;
  for (int u : to[v]) dfs(u);
}

int main(int argc, const char * argv[]) {

    string s;
    cin >> s;
    
    char first = s[0];
    char second = '\0';

    rep(i,4){
      if(first != s[i]){
        second = s[i];
        break;
      }
    }
    // cout << second << endl;
    int sum1 = 0, sum2 = 0;
    rep(i,4){
      if (first == s[i]){
        sum1 += 1;
      }else if(second == s[i]){
        sum2 += 1;
      }
    }
    bool flag = false;

    if(sum1 == 2 && sum2 ==2) flag = true;

    if (flag){
      puts("Yes");
    }else{
      puts("No");
    }



    return 0;
}


Measured memory_bytes: 4992
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<int> cnt(128, 0);
    for(int i=0; i<h*w; ++i){
        char c;
        cin >> c;
        ++ cnt[c];
    }

    int n = (h / 2) * (w / 2);
    for(int i=0; i<128; ++i){
        while(n > 0 && cnt[i] >= 4){
            -- n;
            cnt[i] -= 4;
        }
    }
    if(n > 0){
        cout << "No" << endl;
        return 0;
    }

    n = (h % 2) * (w / 2) + (h / 2) * (w % 2);
    for(int i=0; i<128; ++i){
        while(n > 0 && cnt[i] >= 2){
            -- n;
            cnt[i] -= 2;
        }
    }
    if(n > 0){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
color = [-1] * n
neighbor = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = tuple(map(int, input().split()))
    neighbor[u - 1].append((v-1, w))
    neighbor[v - 1].append((u-1, w))
def col(u, c):
    color[u] = c
    for v, w in neighbor[u]:
        if color[v] < 0:
            col(v, (c + w) % 2)
col(0, 0)
for i in range(n):
    print(color[i])

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++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=1.01e9;
const i64 inf64=4.01e18;
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;
}

void solve(){
    i64 N,X;
    cin >> N >> X;

    vector<i64> x(53),p(53);
    x[0]=1;
    p[0]=1;
    rep(i,1,53){
        x[i]=2*x[i-1]+3;
        p[i]=2*p[i-1]+1;
    }

    function<i64(i64,i64)> rec=[&](i64 l,i64 i){
        if(l==0) return (i64)1;
        if(i==1) return (i64)0;
        if(i==(x[l]+1)/2) return p[l-1]+1;
        if(i==x[l]) return p[l];
        if(i<(x[l]+1)/2) return rec(l-1,i-1);
        return p[l-1]+1+rec(l-1,i-(x[l]+1)/2);
    };

    cout << rec(N,X) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
constexpr ll mod = 1000000007;
constexpr ll base = 32984971;

long long dpow[10001];

long long mpow(int n) {
    if (n == 0)return 1;
    if (dpow[n] == 0) {
        dpow[n] = (mpow(n - 1) * base) % mod;
    }
    return dpow[n];
}

ll rh_b(ll c, char s) {
    return (c * base + s) % mod;
}

ll rh_f(ll c, char s, int len) {
    return ((c - (s * mpow(len - 1))) % mod + mod) % mod;
}

long long mhash(string s) {
    ll ret = 0;
    for (auto &e:s) {
        ret = rh_b(ret, e);
    }
    return ret;
}


int main() {
    string t, p;
    cin >> t >> p;
    ll v = mhash(p);
    int n = p.length(), m = t.length();
    ll u = mhash(t.substr(0, n));
    if (v == u) cout << 0 << '\n';
    for (int i = 0; i < m - n; i++) {
        u = rh_f(u, t[i], n);
        u = rh_b(u, t[i + n]);
        if (u == v)cout << i + 1 << '\n';
    }
}



Measured memory_bytes: 4168
#include "bits/stdc++.h"

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);
int gcd(int a, int b);

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i=0; i<n; i++) {
        cin >> s[i];
    }
    int num_s_b = 0;
    int num_g_a = 0;
    int num_s_b_g_a = 0;
    int num_ab = 0;
    for(int i=0; i<n; i++) {
        string cs = s[i];

        if(cs[0] == 'B' && cs[cs.size()-1] == 'A') num_s_b_g_a++;
        else if(cs[0] == 'B') num_s_b++;
        else if(cs[cs.size()-1] == 'A') num_g_a++;

        bool a_flg = false;
        for(int j=0; j<cs.size()-1; j++) {
            if(cs[j] == 'A' && cs[j+1] == 'B') {
                num_ab++;
            }
        }
    }
    

    int linked_num = 0;
    if(num_s_b_g_a == 0) {
        linked_num = min(num_s_b, num_g_a);
    } else {
        if(num_s_b + num_g_a > 0) {
            linked_num = num_s_b_g_a + min(num_s_b, num_g_a);
        } else{
            linked_num = num_s_b_g_a - 1;
        }
    }
    cout << linked_num + num_ab << endl;

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}

// ユークリウッドの互除法
int gcd(int a, int b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}
 


Measured memory_bytes: 768
S = input()
N = len(S)
S_1 = S[:((N-1)//2)]
S_2 = S[((N+3)//2-1):]
if (S == S[::-1]) and (S_1 == S_1[::-1]) and (S_2 == S_2[::-1]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define INF 987654321
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

#define MAX_N 110
int A[MAX_N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(16); // show 16 digits

    int N;
    cin >> N;
    double res = 0.0;
    for(int i=0; i<N;i++){
        cin >> A[i];
        res += (1.0 / (double)A[i]);
    }
    cout << 1.0 / res << '\n';
    return 0;
}

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

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

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

  vector<vector<int>> kumi(9, vector<int>(9,0));

  for(int i=1; i<=N; i++){
    if(i%10!=0){
    string now = to_string(i);
    int start = now.at(0) - '0';
    int size = now.size();
    int last = now.at(size-1) - '0';
    int x = kumi.at(start-1).at(last-1);
    kumi.at(start-1).at(last-1) = x + 1;
  }
  }

  int ans = 0;

  for(int i=0; i<9; i++){
    for(int j=0; j<9; j++){
      ans += kumi.at(i).at(j) * kumi.at(j).at(i);
    }
  }
  
  cout << ans;

  
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main(){
  const int N = 9;
  const int S = 1001;
  const int M = 101;
  ll dp[N + 1][M + 1][S + 1] = {}; // num, last, sum
  dp[0][0][0] = 1;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      for(int k = 0; k < S; k++){
        for(int l = j; l < M && k + l < S; l++){
          dp[i + 1][l + 1][k + l] += dp[i][j][k];
        }
      }
    }
  }
  int n, s;
  while(cin >> n >> s && n){
    ll res = 0;
    for(int i = 0; i < M + 1; i++){
      res += dp[n][i][s];
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 11048
#include <stdio.h>
#include <string.h>

typedef enum
{
	true = 1,
	false = 0
} bool;

typedef long long ll;

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

void sort(int arr[], int n)
{
   int i, j;
   for (i = 0; i < n-1; i++)  
       for (j = 0; j < n-i-1; j++) 
           if (arr[j] > arr[j+1])
              swap(&arr[j], &arr[j+1]);
}


ll sum(ll a)
{
	ll s = 0; 
	ll b = a;
	while(b)
	{
		s += b%10;
		b /= 10;
	}
	return s;
}


int main()
{
	ll a;
	scanf("%lld", &a);
	if (a % sum(a) == 0) puts("Yes");
	else puts("No");
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	int A,B,C,D,L;
	cin>>L>>A>>B>>C>>D;
	int s;
	int t1,t2;
	if(A%C==0){
		t1=A/C;
	}
	else t1=(A/C)+1;
	if(B%D==0){
		t2=B/D;
	}
	else t2=(B/D)+1;
	cout<<L-max(t1,t2)<<endl;
}

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

int main() {
	int N; cin >> N;
	int t = 0, x = 0, y = 0;
	for (int i = 0; i < N; i++) {
		int tt, xx, yy;
		cin >> tt >> xx >> yy;
		int dt = abs(t - tt);
		int dx = abs(x - xx);
		int dy = abs(y - yy);
		int dist = dx + dy;
		if (dist > dt || dist % 2 != dt % 2) {
			cout << "No" << endl;
			return 0;
		}
		t = tt, x = xx, y = yy;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

N = int(input())

edges = [{} for i in range(N)]
colors = [0 for i in range(N)]

def dfs(s, dist):

    for key, val in edges[s].items():
        d = dist + val
        if d % 2 == 0:
            colors[key] = 0 
        else :
            colors[key] = 1
        
        if s in edges[key]:
            del edges[key][s]

        dfs(key, d)

    return

for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    edges[u][v] = w
    edges[v][u] = w

dfs(0, 0)

for color in colors:
    print(color)


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

int main() {
  string L;
  cin >> L;
  int N;
  long long n1 = 0;
  N = L.size();
  for (int i=0; i<N; i++) {
  }
  long long ans = 1;
  long long n3 = 1;
  for (int i=N-1; i>=0; i--) {
    if (L[i] == '1') {
      ans *= 2;
      ans %= 1000000007;
      ans += n3;
      ans %= 1000000007;
      n3 *= 3;
      n3 %= 1000000007;
    }
    else {
      n3 *= 3;
      n3 %= 1000000007;
    }
  }
  ans = ans % 1000000007;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz=4e5+5;

ll a[sz], d[sz];

ll fnc(ll n)
{
    return n * (n-1) / 2;
}

int main()
{
    ll n, tot=0;
    cin >> n;
    for(ll i=0; i<n; i++) scanf("%lld", &a[i]), d[a[i]]++;
    for(ll i=0; i<=n; i++) tot+=fnc(d[i]);

    for(ll i=0; i<n; i++) printf("%lld\n", tot-fnc(d[a[i]])+fnc(d[a[i]]-1));
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    string s;
    cin>>s;
    int q;
    cin>>q;
    int sum=0;
    string m={},u={};
    rep(i,q){
        int y;
        cin>>y;
        if(y==1)++sum;
        else{
            int f;
            char c;
            cin>>f>>c;
            if((f+sum)&1){
                m+=c;
            }
            else u+=c;
        }
    }
    if(sum&1){
        reverse(u.begin(),u.end());
        reverse(s.begin(),s.end());
        cout<<u<<s<<m<<endl;
    }
    else{
        reverse(m.begin(),m.end());
        cout<<m<<s<<u<<endl;
    }
}


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

int n,a[100010];
bool has[100010];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	int cnt=0;
	for(int i=0;i<n;i++){
		if(!has[a[i]]){
			cnt++;
			has[a[i]]=1;
		}
	}
	if(cnt%2==1) printf("%d\n",cnt);
	else printf("%d\n",cnt-1);
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
#define mod 1000000007

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

	vector<vector<char> > vec(m,vector<char> (n));
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
			cin>>vec[i][j];
	}

	vector<vector<ll> > dp(m,vector<ll> (n,0));
	
	dp[0][0]=1;
	for(int i=1;i<n;i++)
	{
		if(vec[0][i]=='#')
			dp[0][i]=0;
	
		else
			dp[0][i]=dp[0][i-1];
	}

	for(int i=1;i<m;i++)
	{
		if(vec[i][0]=='#')
			dp[i][0]=0;
	
		else
			dp[i][0]=dp[i-1][0];
	}

	for(int i=1;i<m;i++)
	{
		for(int j=1;j<n;j++)
		{
			if(vec[i][j]=='.')
			{
				dp[i][j]=dp[i-1][j]+dp[i][j-1];
				dp[i][j]%=mod;
			}
		}
	}

	cout<<dp[m-1][n-1];

	return 0;
}

Measured memory_bytes: 12148
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(v) v.begin(),v.end()
#define ll long long
#define pb(a) push_back(a)
#define pf(a) push_flont(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
        int n;
        cin >> n;
        vector<int> p;
        int x;
        REP(i,n){
                cin >> x;
                p.push_back(x);
        }
        sort(all(p));
        int sum = 0;
        REP(i,n-1){
                sum+=p[i];
        }
        sum+=p[n-1]/2;
        cout << int(sum) << endl;
        
        return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n, s;
	scanf("%lld%lld", &n, &s);
	for (ll i = 2; i*i <= n; i++)
	{
		ll t = 0;
		ll now = n;
		for (;;)
		{
			if (now == 0)break;
			t += now%i;
			now /= i;
		}
		if (t == s)
		{
			printf("%lld\n", i);
			return 0;
		}
	}
	for (ll i = 1000000; i >= 1; i--)
	{
		ll t = n - (s - i);
		if (t%i == 0)
		{
			ll b = t / i;
			if (b <= 1)continue;
			ll now = n;
			ll tt = 0;
			for (;;)
			{
				if (now == 0)break;
				tt += now%b;
				now /= b;
			}
			if (tt == s)
			{
				printf("%lld\n", b);
				return 0;
			}
		}
	}
	if (n == s)
	{
		printf("%lld\n", n + 1);
		return 0;
	}
	printf("-1\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n;
  while(cin >> n,n) {
    if (n==1)      {
      cout << "deficient number" << endl;
      continue;
    }
    int hoge = 1;
    for (int i=2; i*i<=n; ++i) {
      if (n%i==0) {
        if (i*i!=n)
          hoge += i+n/i;
        else
          hoge += i;
      }
    }
    if (hoge<n) {
      cout << "deficient number" << endl;
    }else if (hoge==n)
      cout << "perfect number" << endl;
    else
      cout << "abundant number" << endl;
  }
}

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

typedef struct{
    long long a;
    long long b;
} mise;

bool cmp(const mise &x, const mise &y){
    return x.a < y.a;
}

int main(void){
    long long n, m, ans = 0;
    mise da[100010];
    cin >> n >> m;
    for(int i=0;i<n;++i) cin >> da[i].a >> da[i].b;
    sort(da, da+n, cmp);
    for(int i=0;i<n;++i){
        if(da[i].b < m){
            ans += da[i].a*da[i].b;
            m -= da[i].b;
        }else{
            ans += da[i].a*m;
            break;
        }
    }
    cout << ans << endl;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end())
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
const ll inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
	int n;
	cin >> n;
	vi cnts;
	int cnt = 0;
	int pre = -1;
	rep(i, n) {
		int c;
		cin >> c;
		if (c == pre) {
			cnt++;
		}
		else {
			pre = c;
			cnts.push_back(cnt);
			cnt = 1;
		}
	}
	cnts.push_back(cnt);

	int ans = 0;
	rep(i, cnts.size()) {
		ans += (cnts[i]) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
que = []
for i in range(n):
  if s[i] == ")" and que and que[-1] == "(":
    que.pop()
  else:
    que.append(s[i])
ket = que.count(")")
bra = len(que) - ket
print("("*ket + s + ")"*bra)

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> c(h, vector<char>(w));
    for (auto& e : c) for (auto& f : e) cin >> f;

    for (auto& e : c) {
        for (auto& f : e) cout << f;
        cout << endl;
        for (auto& f : e) cout << f;
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
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;
}

int dp[101][101];
int main(){
    int n,m;
    cin >> n >> m;
    vector<string> s(n);
    rep(i,n)cin >> s[i];
    Fill(dp,inf);
    if(s[0][0]=='.'){
        dp[0][0] = 0;
    }else{
        dp[0][0] = 1;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(j!=0){
                if(s[i][j]==s[i][j-1]){
                    chmin(dp[i][j],dp[i][j-1]);
                }else{
                    chmin(dp[i][j],dp[i][j-1]+1);
                }
            }
            if(i!=0){
                if(s[i][j]==s[i-1][j]){
                    chmin(dp[i][j],dp[i-1][j]);
                }else{
                    chmin(dp[i][j],dp[i-1][j]+1);
                }
            }
        }
    }
    int res = 0;
    if(s[n-1][m-1]=='.'){
        res = dp[n-1][m-1];
    }else{
        res = dp[n-1][m-1]+1;
    }
    cout << res/2 << endl;
    return 0;
}

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

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

    long long int ans = 0;

    vector<long long int> five(25);

    for (int i = 0; i < 25; i++) {
        five.at(i) = pow(5,i+1);
    }
    


    if (N % 2 != 0) {
        cout << ans << endl;
        return 0;
    }

    ans += N/10;

    for (int i = 0; i < 25; i++) {
        ans += (N/10)/five.at(i);
    }
    

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

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



struct comp{
	bool operator()(const pair<int,int>& a,const pair<int,int>& b){
		return a.second > b.second;
	}
};



int main() {

	int x,n;
	cin>>x>>n;
	int a[n];
	set<int> s;
	for(int i=0;i<n;i++){
	cin>>a[i];s.insert(a[i]);}
	if(s.find(x)==s.end())cout<<x;
	else
	{
		int l=x-1,h=x+1;
		while(1)
		{
			if(s.find(l)==s.end()){cout<<l;break;
			}
			if(s.find(h)==s.end()){cout<<h;break;
			}
			l--;
			h++;
		}
	}
	return 0;
}

Measured memory_bytes: 3628
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll k;cin>>k;
  vl a(k);
  rep(i,k)cin>>a[i];
  reverse(a.begin(),a.end());
  if(a[0]!=2){
    cout<<-1<<endl;
    return 0;
  }
  ll n=2;
  ll MAX=2;
  ll MIN=2;
  rep(i,k){
    MIN=(MIN+a[i]-1)/a[i]*a[i];
    MAX=(MAX+a[i]-1)/a[i]*a[i]+a[i]-1;
    if(i!=k-1){
      MIN=(MIN+a[i+1]-1)/a[i+1]*a[i+1];
      MAX=MAX/a[i+1]*a[i+1];
    }
    if(MIN>MAX){
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<MIN<<" "<<MAX<<endl;
}
  
  
  

Measured memory_bytes: 1152
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    let res = if a >= 13 {
        b
    } else if a >= 6 {
        b/2
    }else {
        0
    };
    println!("{}", res);
}


Measured memory_bytes: 4352
n = int(input())
a = list(map(int, input().split()))
cnt = 2
for i in range(n):
    if a[i] < 0:
        cnt += 1
sum = 0
for i in range(n):
    sum += abs(a[i])
if cnt%2 == 0:
    print(sum)
else:
    mi = abs(a[0])
    for i in range(n):
        if mi > abs(a[i]):
            mi = abs(a[i])
    print(sum - mi - mi)

Measured memory_bytes: 64752
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int tr[200010];
int lb(int pos){return pos & (-pos);}
void mdf(int pos,int wh){
	while(pos<=200000){
		tr[pos]+=wh;
		pos+=lb(pos);
	}
}
long long fnd(int pos){
	long long ret=0;
	while(pos){
		ret+=tr[pos];
		pos-=lb(pos);
	}
	return ret;
}
int N,A[100010];
int L,R,M;
int qzh[100010];
bool check(int md){
	for(int i=1;i<=N;i++)
		qzh[i]=qzh[i-1]+((A[i]<=md)?-1:1);
	long long tj=0;
	for(int i=0;i<=N;i++){
		tj+=fnd(qzh[i]);
		mdf(qzh[i],1);
	}
	for(int i=N;i+1;i--)	mdf(qzh[i],-1);
	if(tj*2>=(1ll*(N+1)*N)/2)	return true;
	return false;
}
int main(){
	scanf("%d",&N);
	qzh[0]=N+1;
	for(int i=1;i<=N;i++)	scanf("%d",&A[i]);
	L=0;R=1e9+10;
	while(L+1<R){
		M=(L+R)>>1;
		if(check(M))	L=M;
		else	R=M;
	}
	printf("%d\n",check(L)?R:L);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

long long m = 1e9+7, mod = 1e9+7;
//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

//約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


int main() {
  int a1,a2,a3;
  scanf("%d %d %d",&a1,&a2,&a3);
  if (a1+a2+a3>=22) printf("bust");
  else printf("win");
}

Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    field = []
    for _ in range(H):
        line = list(map(int, input().split()))
        field.append(line)
    
    ans = []
    # zig-zag
    for i in range(H):
        if i%2 == 0:
            for j in range(W):
                if field[i][j] % 2 == 1:
                    field[i][j] -= 1
                    if j != W-1:
                        field[i][j+1] += 1
                        ans.append((i+1, j+1, i+1, j+2))
                    elif i != H - 1:
                        field[i+1][j] += 1
                        ans.append((i+1, j+1, i+2, j+1))
                    
                    else:
                        field[i][j] += 1
        else:
            for j in range(W-1, -1, -1):
                if field[i][j] % 2 == 1:
                    field[i][j] -= 1
                    if j != 0:
                        field[i][j-1] += 1
                        ans.append((i+1, j+1, i+1, j))
                    elif i != H - 1:
                        field[i+1][j] += 1
                        ans.append((i+1, j+1, i+2, j+1))

                    else:
                        field[i][j] += 1
    print(len(ans))
    for line in ans:
        print(*line, sep=" ")
    


if __name__ == "__main__":
    main()

Measured memory_bytes: 30424
def main():
    A, B, C = map(int, input().split())
    # print(A, B, C)

    L = [A, B, C]
    L.sort()
    c = 0

    while L[0] != L[1] or L[0] != L[2]:
        if L[1] < L[2]:
            L[0] += 1
            L[1] += 1
        elif L[0] < L[2]:
            L[0] += 2
        elif L[0] > L[1]:
            L[1] += 1
            L[2] += 1
        c += 1

    return c


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main() {
    int A,B; cin>>A>>B;
    int plag=1;
    int ans=0;
    for(;plag<B;plag+=A){
        plag-=1;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256