akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>

using namespace std;

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

#define inf 0x3f3f3f3f
#define INF INT_MAX/3
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

int main() {
	int N; cin >> N;
	vector<int> A(N); for (auto &a : A) cin >> a;

	ull cnt = 0;
	REP(i, N-1) {
		cnt += A[i] / 2;
		if ((A[i] % 2) == 1 and A[i + 1] > 0) {
			A[i + 1]--;
			cnt++;
		}
	}
	cnt += A.back() / 2;

	cout << cnt << endl;
	return 0;
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> a(N);
    rep(i, N) {
        cin >> a[i];
        a[i]--;
    }

    vector<bool> b(N);
    b[0] = true;
    int j = 0;
    rep(i, N) {
        if (b[1]) {
            cout << i << endl;
            return 0;
        }
        if (b[a[j]]) {
            cout << -1 << endl;
            return 0;
        }
        b[a[j]] = true;
        j = a[j];
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
queue < ll > a;
int ans;
int k2;
int main()
{
	int k;
	cin>>k;
	for(ll i=1;i<10;i++)
		a.push(i);
	long long r=0;
	long long p=0;
	long long u=0;
	while(1)
	{
		k2++;
		r=a.front();a.pop();
		if(k2==k)
		{
			cout<<r;
			return 0;
		}
		p=r*10;
		u=r%10;
		for(int i=u-1;i<=u+1;i++)
		{
			if(i>=10)
				break;
			if(i<0)
				continue;
			a.push(p+i);
		}	
	}
	return 0;
}

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

using namespace std;

using int64 = long long;

int main() {
  int N;
  cin >> N;
  deque< int > deq(N);
  for(int i = 0; i < N; i++) cin >> deq[i];
  sort(begin(deq), end(deq));


  int64 ans = 0;
  for(int _ = 0; _ < 2; _++) {
    deque< int > sa;
    auto q = deq;
    int f = _ ? 0 : 2;
    int64 ret = 0;

    {
      int v;
      if(f) v = deq[0], deq.pop_front();
      else v = deq.back(), deq.pop_back();
      sa.push_back(v);
    }

    int mod = f;
    while(deq.size()) {
      int v;
      if(mod % 4 <= 1) v = deq[0], deq.pop_front();
      else v = deq.back(), deq.pop_back();
      ++mod;
      if(mod % 2 == 0) {
        ret += abs(sa.back() - v);
        sa.push_back(v);
      } else {
        ret += abs(sa[0] - v);
        sa.push_front(v);
      }
    }
    ans = max(ans, ret);
    deq = q;
  }
  cout << ans << endl;
}



Measured memory_bytes: 1536
// clang-format off
#include <bits/stdc++.h>
#include <queue>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const ll INF = TEN(15);
int h, w, k;
vec<string> grid;
vl dist;
using Triple = tuple<int, int, int>;
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };

bool ok(int i, int j) {
    return 0 <= i and i < h and 0 <= j and j < w and grid[i][j] == '.';
}

int to_idx(int i, int j, int d) {
    if (!ok(i, j))
        return -1;
    else
        return (i * w + j) * 4 + d;
}

Triple from_idx(int x) {
    return make_tuple(x / 4 / w, x / 4 % w, x % 4);
}

int main() {
    fastio();

    cin >> h >> w >> k;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;

    dist = vl(h * w * 4, INF);

    forn(i, h) {
        string s;
        cin >> s;
        grid.push_back(s);
    }

    priority_queue<pli, vec<pli>, greater<pli>> q;

    forn(i, 4) {
        int idx = to_idx(x1, y1, i);
        q.emplace(0, idx);
        dist[idx] = 0;
    }

    while (!q.empty()) {
        auto [d, idx] = q.top();
        q.pop();

        auto [x, y, dir] = from_idx(idx);

        if (d != dist[idx]) continue;

        //printf("%d %d: %lld\n", x, y, d);

        forn(i, 4) {
            int j = to_idx(x + dx[i], y + dy[i], i);

            ll newd = (i == dir) ? (d + 1) : ((d + k - 1) / k * k + 1);

            if (j < 0 or dist[j] <= newd) continue;

            dist[j] = newd;
            q.emplace(newd, j);
        }
    }

    ll d = INF;
    forn(i, 4) {
        chmin(d, dist[to_idx(x2, y2, i)]);
    }

    if (d == INF) {
        cout << -1 << endl;
    } else {
        cout << (d + k - 1) / k << endl;
    }

    return 0;
}

Measured memory_bytes: 39616
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	long long int K;
	cin >> S;
	cin >> K;

	if (S[0] != '1') {
		cout << S[0] << endl;
	}
	else {
		int cnt_one = 0;
		char number;
		REP(i, S.size()) {
			if (S[i] != '1') {
				number = S[i];
				break;
			}
			else {
				cnt_one++;
			}
		}
		if (K <= cnt_one) {
			cout << 1 << endl;
		}
		else {
			cout << number << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
vector<vector<bool>> used(500,vector<bool>(500,false));
P bfs(int N,int M,vector<string> field,int sx,int sy){
    int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
    queue<P> que;
    que.push(P(sx,sy));
	used[sx][sy] = true;
	P ans = mp(0,0);
	if (field[sx][sy] == '.'){
		ans.fs++;
	}
	else{
		ans.sc++;
	}
    //キューが空になるまでループ
    while(que.size()){
        P p = que.front();
        que.pop();//先頭を取り出す
        for (int i = 0;i < 4;i++){
            int nx = p.fs + dx[i], ny = p.sc + dy[i];
            //nx,nyが進めるマスか、行ったことのないマスかどうかを判定
			if (field[p.fs][p.sc] == '.'){
 				if (0 <= nx && nx < N && 0 <= ny && ny < M && field[nx][ny] != '.' && !used[nx][ny]){
                	que.push(P(nx,ny));//追加
                	used[nx][ny] = true;
					ans.sc++;
           		}
			}
			else{
				if (0 <= nx && nx < N && 0 <= ny && ny < M && field[nx][ny] != '#' && !used[nx][ny]){
                	que.push(P(nx,ny));//追加
                	used[nx][ny] = true;
					ans.fs++;
            	}
			}
        }
    }
	return ans;
}
int main(){
	int h,w;cin>>h>>w;
	vector<string> s(h);
	for(int i = 0; i < h; i++) {
		cin>>s[i];
	}
	ll ans = 0;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if (!used[i][j]){
				P res = bfs(h,w,s,i,j);
				ans += (res.fs * res.sc);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5],B[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
sc(n);
f1(i,n+1){
	sc(A[i]);	
}
f1(i,n){
	sc(B[i]);	
}	
f1(i,n){
	if(A[i]<=B[i]){
		c=B[i]-A[i];
		ans+=A[i];
		c=min(c,A[i+1]);
		A[i+1]-=c;
		ans+=c;
	}
	else ans+=B[i]
;}
pr(ans);
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

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

using namespace std;

int N, K;
long long maxA = -1;
vector<long long> A;

bool search(long long X) {
  long long sum = 0;
  
  for (int i = 0; i < N; i++) {
    sum += A[i] / X;
    
    if (A[i] % X == 0) {
      sum--;
    }
  }
  
  return sum <= K;
}

int main() {
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    long long inA;
    
    cin >> inA;
    
    A.push_back(inA);
    maxA = max(maxA, inA);
  }
  
  long long left = 0, right = maxA;
  
  while (abs(right - left) > 1) {
    long long mid = (left + right) / 2;
    
    if (search(mid)) {
      right = mid;
    } else {
      left = mid;
    }
  }
  
  cout << right << endl;
  
  return 0;
}

Measured memory_bytes: 5356
S = input()

length = len(S)
ans = 0

for x in range(2 ** (length - 1)):
    res = ""
    b = str(format(x, '010b'))
    for i in range(length):
        res += str(S[i])
        if b[-(i + 1)] == "1":
            res += "+"
    res = res.split("+")
    ans += sum(list(map(int,res)))
        
print(ans)

Measured memory_bytes: 41948
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int n, h, w;
    cin >> n >> h >> w;

    int count = 0;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (a >= h && b >= w) {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<string>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<unistd.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")

struct Bipartite_Matching
    {
    vector< vector< int > > graph;
    vector< int > match, alive, used;
    int timestamp;
    
    Bipartite_Matching(int n)
    {
        timestamp = 0;
        graph.resize(n);
        alive.assign(n, 1);
        used.assign(n, 0);
        match.assign(n, -1);
    }
    
    void add_edge(int u, int v)
    {
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    
    bool dfs(int v)
    {
        used[v] = timestamp;
        for(int i = 0; i < graph[v].size(); i++) {
        int u = graph[v][i], w = match[u];
        if(alive[u] == 0) continue;
        if(w == -1 || (used[w] != timestamp && dfs(w))) {
            match[v] = u;
            match[u] = v;
            return (true);
        }
        }
        return (false);
    }
    
    int bipartite_matching()
    {
        int ret = 0;
        for(int i = 0; i < graph.size(); i++) {
        if(alive[i] == 0) continue;
        if(match[i] == -1) {
            ++timestamp;
            ret += dfs(i);
        }
        }
        return (ret);
    } 
};


signed main(){
    int n;
    cin >> n;
    Bipartite_Matching graph(n*2);
    int a[114],b[114],c[114],d[114];
    REP(i,n) scanf("%d%d",&a[i],&b[i]);
    REP(i,n) scanf("%d%d",&c[i],&d[i]);

    REP(i,n){
        REP(j,n){
            if(a[i]<c[j]&&b[i]<d[j]) graph.add_edge(i,j+n);
        }
    }

    cout << graph.bipartite_matching() << endl;

    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
ret = -1
for i in range(10**n+1):
    x = str(i)
    if len(x)!=n:
        continue
    flg = True
    for s,c in sc:
        if x[s-1]!=str(c):
            flg = False
    if flg:
        ret = x
        break
print(ret)

Measured memory_bytes: 40432
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a;
	a=n/1.08;
	if(a*1.08<n)
	{
		if((a+1)*1.08-n>=1)
		cout<<":(";
		else
		cout<<a+1;
	}
	else
	cout<<a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_X=1e3,MAX_Y=1e3,MAX_Z=1e3;
ll X,Y,Z,K,A[MAX_X],B[MAX_Y],C[MAX_Z],cmb[MAX_X*MAX_Y],inx[MAX_Z];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>X>>Y>>Z>>K;
	REP(i,X)cin>>A[i];
	REP(i,Y)cin>>B[i];
	REP(i,Z)cin>>C[i];
	REP(i,X)REP(j,Y){
		cmb[i*Y+j]=A[i]+B[j];
	}
	sort(cmb,cmb+X*Y);
	fill(inx,inx+Z,X*Y-1);
	while(K--){
		ll ans=-1;
		REP(i,Z){
			if(inx[i]>=0 && (ans==-1 || cmb[inx[ans]]+C[ans]<cmb[inx[i]]+C[i])){
				ans=i;
			}
		}
		cout<<cmb[inx[ans]]+C[ans]<<endl;
		inx[ans]--;
	}
				
}

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

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

int main() {
  int n,m;
  cin >> n >> m;
  int l,r;
  int ansl = 1;
  int ansr = n;
  rep(i,m) {
    cin >> l >> r;
    if (ansl < l) ansl = l;
    if (ansr > r) ansr = r;
  }
  if (ansr-ansl+1>0) cout << ansr-ansl+1 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3532
using System;
using System.Linq;
using System.Collections.Generic;
using static program.Input;
using static program.MyMath;
using static System.Console;

namespace program {
  class Program {
    static void Main()
    {
      string al = "abcdefghijklmnopqrstuvwxyz";
      
      var s = ScanStr();
      for(int i=0; i<al.Length; i++){
        if(s[0] == al[i]) WriteLine(al[i+1]);
      }
    }
  }
  
  static class Input {
    static public int ScanInt() { return int.Parse(Console.ReadLine()); }
    static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
    static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
    static public long ScanLong() { return long.Parse(Console.ReadLine()); }
    static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
    static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
    static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
    static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
    static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
    static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

    static public string ScanStr() { return Console.ReadLine(); }
    static public string[] ScanStrArray() { return ScanStr().Split(); }
  }
  
  static class MyMath {
    public static int GCD(int a, int b) {
        Func<int, int, int> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static long GCD(long a, long b) {
        Func<long, long, long> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
      if(b==0) {
        x=1; 
        y=0;
        return a;
      }
      var d = extGCD(b, a%b, ref y, ref x);
      y -= a/b *x;
      return d;
    }
    public static int LCM(int a, int b) { return a * b / GCD(a, b); }
    public static long LCM(long a, long b) { return a * b / GCD(a, b); }
  }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    set<int> s;
    REP(i, n){
        cin >> p[i];
        s.insert(p[i]);
    }
    int a, b;
    b = 100000;
    rep(i, -1, 102){
        if (s.find(i) != s.end()) continue;
        if(abs(i - x) < b){
            a = i;
            b = abs(i - x);
        }
    }
    cout << a << endl;

    return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#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 llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007

#define ARRAY_MAX 15


//半分全列挙
void build(int first,int last,vector<int>& a,vector<int>& b,vector<int>& c,map<P,int>& mp){

    int times = last - first;
    for(int i = 0;i < (1<<times);i++){

        int suma = 0,sumb = 0,cost = 0;
        for(int j = 0;j < times;j++){
            
            if((i>>j)&1){
                //選ぶ
                suma += a[first + j];
                sumb += b[first + j];
                cost += c[first + j];
            }
        }
        if(!mp.count({suma, sumb}) || mp[{suma, sumb}] > cost) {
            mp[{suma, sumb}] = cost;
        }
    }
}




int main(){

    int n,ma,mb;
    cin >> n >> ma >> mb;
    vector<int> a(n),b(n),c(n);
    REP(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }

    map<P,int> s1,s2;

    build(0,n/2,a,b,c,s1);//前半部分
    build(n/2,n,a,b,c,s2);//後半部分
    int ans = INF;

    for(auto itr1:s1){
        for(auto itr2:s2){
            int a1 = itr1.first.first + itr2.first.first;//aの重さ
            int b1 = itr1.first.second + itr2.first.second;//bの重さ
            if(a1 * b1 > 0 && a1*mb == b1*ma){
                ans = min(ans,itr1.second + itr2.second);
            }
        }
    }
    if(ans == INF){
        cout << "-1" << endl;
    }else{
        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 896
n = input()
p, q = [-1, -1]
for i in xrange(n):
    t, a = map(int, raw_input().split())
    if p == -1 or q == -1:
        p = t
        q = a
        continue
    if t >= p and a >= q:
        p = t
        q = a
    else:
        z = max(p / t + (p % t != 0), q / a + (q % a != 0))
        p = t * z
        q = a * z
print p + q



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

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vec;

int main()
{
    int n,l;

    ios::sync_with_stdio(false);
    cin.tie(0);

    while(cin>>n>>l)
    {
        vec arr;
        for(int i=0;i<n;i++)
        {
            int tmp;
            cin>>tmp;
            arr.push_back(tmp);
        }
        vector<pii> dl;

        for(int i=0;i<l;i++)
        {
            while(dl.size()&&dl[dl.size()-1].first>=arr[i])
            {
                dl.erase(dl.begin()+dl.size()-1);
            }
            dl.push_back(make_pair(arr[i],i));
        }

        cout<<dl[0].first;
        for(int i=l;i<n;i++)
        {
            while(dl.size()&&i-dl[0].second>=l)
            {
                dl.erase(dl.begin());
            }
            while(dl.size()&&dl[dl.size()-1].first>=arr[i])
            {
                dl.erase(dl.begin()+dl.size()-1);
            }
            dl.push_back(make_pair(arr[i],i));
            cout<<" "<<dl[0].first;
        }
        cout<<endl;
    }

    return 0;
}



Measured memory_bytes: 7080
#include <iostream>
#include <map>
#include <algorithm>
#define F(i,a,n) for(int i = (a); i < (n); ++i)
#define Fl(i,a,n) for(long long i = (a); i < (n); ++i)
using namespace std;
int N;
map<long long, bool>mp;
int main(){
  cin >> N;
  F(i,0,N){
    int x;
    cin >> x;
    if(mp[x]){
      mp[x] = !mp[x];
    }else{
      mp[x] = true;
    }
  }
  long long ans = 0;
  for(auto itr = mp.begin();itr != mp.end();++itr){
    if(itr->second) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#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++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  int a, b;
  cin >> a >>b;
  if(a<b)
    cout << 0 << endl;
  else
    cout << 10 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin>>N;
    int A[N];
    rep(i,N) cin>>A[i];

    int ans=0;
    int c=0;
    if(A[0]!=0){
        cout << -1 << endl;
        return 0;
    }
    reverse(A,A+N);
    ans+=A[0];
    for(int i=1;i<N;i++){
        int x=A[i-1]-A[i];
        if(x>1){
            cout << -1 << endl;
            return 0;
        }
        if(A[i]==0)continue;
        if(x==1){
            ans+=0;
        }else{
            ans+=A[i];
        }
    }
    cout << ans << endl;
    



}


Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define MAX_N 1000000

using namespace std;

bool IsPrime[MAX_N];
int NofP[MAX_N];
void q9() {
	memset(IsPrime, 1, sizeof(IsPrime));
	IsPrime[0] = false;
	IsPrime[1] = false;
	for (int i = 0; i < sqrt(MAX_N); i++) {
		if (!IsPrime[i]) continue;
		for (int j = i * 2; j < MAX_N; j += i) {
			IsPrime[j] = false;
		}
	}

	
	NofP[0] = 0;
	for (int i = 1; i < MAX_N; i++) {
		NofP[i] = NofP[i - 1] + IsPrime[i];
	}

	int n;
	for (; cin >> n;) {
		cout << NofP[n] << endl;
	}
}

int main() {
	q9();
	return 0;
}

Measured memory_bytes: 7856
#include<iostream>
#include<string>

using namespace std;

int main(void) {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	if (n > k) {
		cout << k*x + (n - k)*y << endl;
	}
	else {
		cout << n*x << endl;
	}
	return 0;
}


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

long long gcd(long long a,long long b){
    if(a < b)swap(a,b);
    if(b == 0)return a;
    if(a%b==0)return b;
    else return gcd(b, a % b);
}

int pf(long long n) {
  map<long long,int>p;
  for (long long i = 2; i*i <= n; i++) {
    if (n%i !=0) continue;
    p[i]++;
    while (n%i == 0) {
      n = n / i;
      p[i]++;
    }
  }
  if (n != 1) p[n]++;
  return p.size();
}

int main(){
  long long A,B,temp,ans;
  cin>>A>>B;
  ans=0;
  temp=gcd(A,B); 
   auto f=pf(temp);
  ans=f+1;
  cout<<ans<<endl;      
  return 0;
}

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

X = [list(map(int,input().split())) for _ in range(N)]
X = sorted(X,key=lambda X:-X[0])
a = X[0][0]
X = sorted(X,key=lambda X:-X[1])

i = 0
count = 0
while M > 0:
	if i < N and X[i][1] > a:
		M -= X[i][1]
		i += 1
	else:
		count += -(-M//a)
		break
	count += 1

print(count)

Measured memory_bytes: 32880
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
int n;
ll w[400][400],ww[400][400];
ll ans=0;

int main()
{
    cin>>n;
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=n; ++j)
        {
            cin>>w[i][j];
            ww[i][j]=w[i][j];
        }
    for (int k=1; k<=n; ++k)
        for (int i=1; i<=n; ++i)
            for (int j=1; j<=n; ++j)
                if (ww[i][k]+ww[k][j]<ww[i][j])
                    ww[i][j]=ww[i][k]+ww[k][j];
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=n; ++j)
        {
            if (ww[i][j]!=w[i][j])
            {
                cout<<-1<<endl;
                return 0;
            }
            bool flag=0;
            for (int k=1; k<=n; ++k)
                if (i!=j && j!=k && i!=k)
                {
                    if (w[i][k]+w[k][j]==w[i][j])
                        flag=1;
                }
            if (flag==0) ans+=w[i][j];
        }
    cout<<ans/2<<endl;

    return 0;
}



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

int power(int a, int n) {
  if (n == 1) return a;
  
  return power(a, n-1) * a;
}

void chmax(int& a, int b) {
  if (a < b) a = b;
}

int main() {
  int X;
  cin >> X;
  
  int ans = 1;
  
  for (int i = 2; i < 10; i++) {
    for (int j = 2; j < 33; j++) {
      int x = power(j, i);
      if (x <= X) {
        chmax(ans, x);
      } else {
        break;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int s;
  std::cin >> s;
  int res{0};
  while (res++, s != 1) {
    if (s == 4 || s == 2 || s == 1) break;
    int n{(s % 2 == 0) ? s / 2 : 3 * s + 1};
    // std::cout << n << ' ';
    s = n;
  }
  printf("%d\n", res + 3);
}

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

set <int> s;

int main()
{
	int n;
	scanf ("%d", &n);
	for (int i=1; i<=n; i++){
		int a;
		scanf ("%d", &a);
		s.insert (a);
	}
	
	int l=s.size();
	if (l % 2)
		printf ("%d\n", l);
	else
		printf ("%d\n", l-1);

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <queue>
using namespace std;

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

int main(){    
    int l,r,d ;
    cin >> l >> r >> d ;
    cout << r/d - (l-1)/d << endl ;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>

int main(int argc, char *argv[]) {  
	std::string aa;
	std::cin >> aa;
	char a = aa[0];
	char b = aa[1];
	char c = aa[2];
	char d = aa[3];
	//1std::cout << a << b << c << d;
	if((a==b&&b==c)||(b==c&&c==d)) {
		std::cout << "Yes\n";
	} else {
		std::cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<deque>
using namespace std;

int main() {

    string name;
    char t;

    while(true) {
        cin >> name >> t;
        if (t == 'X') break;

        switch(t) {
            case 'U':
                if (name.find("_") == string::npos) {
                    if (name[0] >= 'a' && name[0] <= 'z') {
                        name[0] += 'A' - 'a';
                    }
                    cout << name << endl;
                } else {
                    while(name.find("_") != string::npos) {
                        name[0] += 'A' - 'a';
                        cout << name.substr(0, name.find("_"));
                        name = name.substr(name.find("_") + 1);
                    }
                    name[0] += 'A' - 'a';
                    cout << name << endl;
                }
                break;
            case 'L':
                if (name.find("_") == string::npos) {
                    if (name[0] >= 'A' && name[0] <= 'Z') {
                        name[0] -= 'A' - 'a';
                    }
                    cout << name << endl;
                } else {
                    cout << name.substr(0, name.find("_"));
                    while(name.find("_") != string::npos) {
                        name = name.substr(name.find("_") + 1);
                        name[0] += 'A' - 'a';
                        cout << name.substr(0, name.find("_"));
                    }
                    cout << endl;
                }
                break;  
            case 'D':
                if (name.find("_") != string::npos) {
                    cout << name << endl;
                } else {
                    for(int i = 0; i < name.length(); i++) {
                        if(name[i] >= 'A' && name[i] <= 'Z') {
                            name[i] -= 'A' - 'a';
                            if(i != 0) cout << "_";
                        }
                        cout << name[i];
                    }
                    cout << endl;
                }
        }
    }
     
    return 0;
}

Measured memory_bytes: 0
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

L = input()

def digit_dp_2(n):
    l = len(n)

    dp = [[[0] * 2 for _ in range(2)] for i in range(l + 1)]
    dp[0][0][0] = 1

    for i in range(l):
        d = int(n[i])

        # Lになる可能性があるかないか
        for j in range(2):
            # 次の桁が0か1か
            for d_j in range(2 if j else d + 1):
                if d_j == 0:
                    dp[i + 1][j | (d_j < d)][d_j] += (dp[i][j][0] + dp[i][j][1])
                    dp[i + 1][j | (d_j < d)][d_j] %= mod
                else:
                    dp[i + 1][j | (d_j < d)][d_j] += 2 * (dp[i][j][0] + dp[i][j][1])
                    dp[i + 1][j | (d_j < d)][d_j] %= mod

    return sum(dp[-1][0]) + sum(dp[-1][1])

print(digit_dp_2(L) % mod)

Measured memory_bytes: 113452
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#define nmax 100001

using namespace std;
ifstream fin("p.in");
ofstream fout("p.out");

int n,k;
vector<int>vec;

int main()
{
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        {
            int x;
            cin>>x;
            vec.push_back(x);
        }
    vector<long long>mem(2*n,1e9);
    mem[n-1]=0;
    for(int i=n-2; i>=0; i--)
        if(i+k<n)
            {
                int ck=k;
                int val=i+1;
                while(ck!=0)
                    {
                        if(mem[val]+abs(vec[i]-vec[val])<mem[i])
                            mem[i]=mem[val]+abs(vec[i]-vec[val]);
                        ck--;
                        val++;
                    }
            }
        else
            {
                for(int j=i+1; j<n; j++)
                    if(mem[j]+abs(vec[i]-vec[j])<mem[i])
                        mem[i]=mem[j]+abs(vec[i]-vec[j]);
            }

    cout<<mem[0];
    return 0;
}


Measured memory_bytes: 2300
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

enum suit
{
    SPADE = 0,
    HEART,
    CLUB,
    DIA,
    SUIT_NUM
};


int main() {
    // 0初期化
    int tramp[13][SUIT_NUM] = {};
    ll n;
    string s;
    string head = "SHCD";
    ll num;
    ll sn;
    
    cin >> n;
    for(int i = 1;n >= i; i++){
        cin >> s >> num;
        // cout << s << num << endl;
        if(s == "S") sn=SPADE;
        if(s == "H") sn=HEART;
        if(s == "C") sn=CLUB;
        if(s == "D") sn=DIA;
        tramp[num - 1][sn] = 1;
    }

    for(int j = 0; SUIT_NUM > j; j++){
        for (int i = 0; 13 > i; i++){
            if(tramp[i][j] == 0){
                cout << head[j] << " " << i+1 << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3184
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, a: "List[int]"):
    left_sum = list(itertools.accumulate(a))
    right_sum = list(itertools.accumulate(a[::-1]))

    answer = 2*10**9
    for i in range(N-1):
        answer = min(answer,abs(left_sum[i]-right_sum[N-2-i]))
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 44020
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n;
int ans[510][510];
signed main(){
    cin>>n;
    rep(i,n){
        rep(j,n){
            if(i<j){
                rep(k,30){
                    if(((i>>k)&1)+((j>>k)&1)==1)ans[i][j]=k+1;
                }
            }
        }
    }
    rep(i,n){
        rep(j,n){
            if(i<j)cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int H[N];
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    H[0] --;
    for (int i = 0; i < N - 1; i++) {
        if (H[i + 1] > H[i]) H[i + 1] --;
        else if (H[i] == H[i + 1]) continue;
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
import itertools
import math
import fractions
import functools
import copy

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if b-a > k or c-a > k or d-a > k or e-a > k or c-b > k or d-b > k or e-b > k or d-c > k or e-c > k or e-d > k:
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 64364
#include <bits/stdc++.h>
using LL = long long;
using namespace std;

const int M = 2e5 + 100;
const int mod = 1e9 + 7;

vector<int> e[M];
int n, sz[M], ans[M];
int fac[M], inv[M];

LL mul(LL a, LL b) {
    return a * b % mod;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i <= n; i++) fac[i] =1LL* fac[i - 1]*i%mod;
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = mul((mod - mod / i), inv[mod % i]);
}

void dfs(int u, int fa) {
    sz[u] = 1;
    for (int v : e[u]) {
        if (v != fa) {
            dfs(v, u);
            sz[u] += sz[v];
        }
    }
}

void reroot(int u, int fa) {
    ans[u] = mul(mul(ans[fa], sz[u]), inv[n - sz[u]]);
    for (int v : e[u]) {
        if (v != fa) {
            reroot(v, u);
        }
    }
}

int main() {
    cin >> n;
    init();
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(1, 0);
    ans[1] = fac[n];
    for (int i = 1; i <= n; i++) ans[1] = mul(ans[1], inv[sz[i]]);
    for (int v : e[1]) reroot(v, 1);
    for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
}


Measured memory_bytes: 17012
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int> Z(N+1,0);
  for(int i=2;i<=N;i++){
    int a;cin>>a;
    Z[a]++;
  }
  for(int i=1;i<=N;i++){
    cout<<Z[i]<<endl;
  }
}

Measured memory_bytes: 4052
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0) 
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n,m,a,b,c,d,x=INF,y,z;
  string s,t;
  //

  // ここから
  IN2(a,b);
  Vi TASTE(a);
  REP(i,a){
    TASTE[i] = i+b;
  }
  int SUM = VSUM(TASTE);
  REP(i,a){
    if(abs(x) > abs(TASTE[i])){
      c = TASTE[i];
      x = abs(TASTE[i]);
    }
  }
  OUT(SUM-c);
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;


public class Main {
    public static void main(String[] args) {

        Scanner scanner=new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();

        int ans=100;
        if(a==0){
        	if(b==100)
        		System.out.println(101);
        	else
        		System.out.println(b);
        }
        else{
        	if(a==2)
        		ans*=ans;
        	if(b==100)
        		System.out.println(ans*101);
        	else
        		System.out.println(ans*b);
        }



    }

}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll A[100010];
ll F[2100010];

ll Mul(ll a, ll b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
ll square(ll x) {
	return (x * x) % mod;
}

ll power(ll x, ll y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

ll Div(ll a, ll b) {
	return Mul(a, power(b, mod - 2));
}
ll P(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

ll C(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	ll ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}

int main()
{
	fact();
	ll N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	ll ans = 0;
	ll m = 0;
	ll p = 0;
	for (ll i = 0; i < N; i++) {
		m += Mul(A[i], C(N - i - 1, K - 1));
	}
	for (ll i = N - 1; i >= 0; i--) {
		p += Mul(A[i], C(i, K - 1));
	}
	cout << (p - m) % mod << endl;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 



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

i64 N, A, B; cin >> N >> A >> B;


cout << N / (A+B) * A + min(A, N%(A+B))<< "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
n = gets.to_i
xys = []
n.times do
  xys << gets.split.map(&:to_f)
end

distances = 0.0
xy_perms = xys.permutation
xy_perms.each do |xy|
  dis = 0
  (1..n-1).each do |i|
    dis += ((xy[i][0] - xy[i-1][0]) ** 2 + (xy[i][1] - xy[i-1][1]) ** 2) ** (1.0/2)
  end
  distances += dis
end
puts distances / xy_perms.size


Measured memory_bytes: 1916
#include <iostream>
#include <string>

int main(){
   std::string S;
   std::cin >> S;
   std::size_t N = S.size();
   std::string new_S = S; 
   int ans = 0;
   for (std::size_t i=2; i<N; i+=2){
      std::string new_S = S.substr(0, N-i);
      std::cerr << new_S << std::endl;
      if (new_S.substr(0, (N-i)/2) == new_S.substr((N-i)/2, (N-i)/2)){
         ans = N-i;
         break;
      }
   }
   std::cout << ans << std::endl;
}



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

/*
月になりうる
*/

bool month(char a, char b){
    return ((a=='0' && b!='0') || (a=='1' && ((0 <= (b -'0')) && ((b-'0') <= 2))));
}


void solve(){
    string s;
    cin >> s;
    char s1 = s[0];
    char s2 = s[1];
    char s3 = s[2];
    char s4 = s[3];
    string st;
    if(month(s1,s2)&&month(s3,s4)){
        st = "AMBIGUOUS";
    }
    else if(month(s1,s2)){
        st = "MMYY";
    }
    else if(month(s3,s4)){
        st = "YYMM";
    }
    else{
        st = "NA";
    }
    cout << st << endl;
}

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

Measured memory_bytes: 256