akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
#define Forr(i,j,k) for(int i=j;i>=k;--i)
#define Rep(i,u) for(int i=Begin[u],v=to[i];i;i=Next[i],v=to[i])
#define ll long long 
using namespace std;
const int N=210,INF=0x3f3f3f3f;
template<class T>void read(T &x){
	x=0;char c=getchar();
	while(!isdigit(c))c=getchar();
	while( isdigit(c))x=x*10+c-48,c=getchar();
}
int n,Link[N],Begin[N],Next[N*N],to[N*N],e;
inline void add(int x,int y){
	to[++e]=y,Next[e]=Begin[x],Begin[x]=e;
}
inline void file(){
#ifndef ONLINE_JUDGE
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
#endif 
}
int X[N],x[N],y[N],totx,toty;

namespace divide{
	const int N=70,S=13,pri[S]={2,3,5,7,11,13,17,19,23,29,31,37,41};
	ll pr[N],p[N];int c[N],cnt;
	ll qpow(ll a,ll b,ll P){
		ll ret=1;
		for(;b;b>>=1,a=a*a%P)if(b&1)ret=ret*a%P;
		return ret;
	}
	inline bool Miller_Rabin(ll x){
		int C=0,Times=S;
		ll val,t=x-1,lst;
		For(i,0,S-1)if(x==pri[i])return 1;
		if(x==1)return 0;
		while(!(t&1))C++,t>>=1;
		while(Times--){
			ll a=pri[Times]%x;
			lst=qpow(a,t,x);
			For(i,1,C){
				val=lst*lst%x;
				if(val==1&&lst!=x-1&&lst!=1)return 0;
				lst=val;
			}
			if(val!=1)return 0;
		}
		return 1;
	}
}namespace D=divide;
bool check(int p){
	if(p==2)return 0;
	return D::Miller_Rabin(p);
}
void init(){
	read(n);
	For(i,1,n)read(X[i]);
	X[0]=-1;
	For(i,1,n){
		if(X[i-1]!=X[i]-1){
			if(X[i]&1)x[++totx]=X[i];
			else y[++toty]=X[i];
		}
		if(X[i+1]!=X[i]+1){
			if((X[i]+1)&1)x[++totx]=X[i]+1;
			else y[++toty]=X[i]+1;
		}
	}
	//For(i,1,totx)printf("%d ",x[i]);puts("");
	//For(i,1,toty)printf("%d ",y[i]);puts("");
	For(i,1,totx)
		For(j,1,toty)
			if(check(abs(y[j]-x[i])))add(i,j);
}
int vis[N];
bool Hungary(int u){
	Rep(i,u)if(!vis[v]){
		vis[v]=1;
		if(!Link[v]||Hungary(Link[v]))return Link[v]=u,1;
	}
	return 0;
}
void solve(){
	int ret=0,ans=0;
	For(i,1,totx){
		For(j,1,toty)vis[j]=0;
		ret+=Hungary(i);
	}
	ans=ret;
	ans+=(totx-ret)/2*2;
	ans+=(toty-ret)/2*2;
	if(ret%2!=totx%2)ans+=3;
	printf("%d\n",ans);
}
int main(){
	init();
	solve();
	return 0;
}



Measured memory_bytes: 384
package main

import "fmt"

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n int
	fmt.Scan(&n)
	ws := make([]int, n)
	rsum := 0
	for i := range ws {
		fmt.Scan(&ws[i])
		rsum += ws[i]
	}

	lsum := 0
	ans := 100000
	for _, v := range ws {
		lsum += v
		rsum -= v
		if d := abs(rsum - lsum); d < ans {
			ans = d
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc157_b solver = new abc157_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc157_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a[][] = new int[3][3];
            boolean is[][] = new boolean[3][3];
            for (int y = 0; y < 3; y++) {
                for (int x = 0; x < 3; x++) {
                    a[x][y] = in.nextInt();
                }
            }
            int N = in.nextInt();
            for (int i = 0; i < N; i++) {
                int inp = in.nextInt();
                for (int y = 0; y < 3; y++) {
                    for (int x = 0; x < 3; x++) {
                        if (a[x][y] == inp) {
                            is[x][y] = true;
                        }
                    }
                }
            }
            for (int y = 0; y < 3; y++) {
                if (is[0][y] && is[1][y] && is[2][y]) {
                    out.println("Yes");
                    return;
                }
            }
            for (int x = 0; x < 3; x++) {
                if (is[x][0] && is[x][1] && is[x][2]) {
                    out.println("Yes");
                    return;
                }
            }
            if (is[0][0] && is[1][1] && is[2][2]) {
                out.println("Yes");
                return;
            }
            if (is[2][0] && is[1][1] && is[0][2]) {
                out.println("Yes");
                return;
            }
            out.println("No");
        }

    }
}



Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define ll long long int
#define INF 0x3f3f3f3f
#define pb push_back
#define se second
#define fi first
using namespace std;
const int N=1e5+5;
int par[N],sub[N];
vector<int> g[N];

void dfs(int u,int p){
    par[u]=p;
    sub[u]=1;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(v!=p){
            dfs(v,u);
            sub[u]+=sub[v];
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n; cin>>n;
    for(int i=1;i<n;i++){
        int u,v; cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1,0);
    int cnt=-1;
    int y=n;
    while(y!=1){
        cnt++;
        y=par[y];
    }
    int node=n; cnt/=2;
    for(int i=0;i<cnt;i++){
        node=par[node];
    }
    int cntw=sub[node];
    int cntb=n-cntw;
    if(cntw>=cntb) cout<<"Snuke\n";
    else cout<<"Fennec\n";
    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define x first
#define y second
#define sz(a) ((int)(a.size()))
#define OTIMIZA 2
#define INSERE 1
#define REMOVE 0
#define move aslzxc
int pref[200005];
int nxt[200005];
int l[2][200005];
int sum(int l , int r)
{
	return pref[r] - (l ? pref[l - 1] : 0);
};
int main()
{
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	for(int i = 0; i < sz(s); i++)
		pref[i] = (s[i] == 'o') + (i ? pref[i - 1] : 0);
		
	for(int it = 0; it < 2; it++)
	{
		int N = n;
		for(int i = n - 1; i >= 0; i--)
		{
			if(s[i] == 'o')
				N = i;
			nxt[i] = N;
		}
		l[it][0] = nxt[0];
		for(int i = 1; i < k; i++)
			l[it][i] = nxt[l[it][i - 1] + c + 1];
			
		reverse(s.begin() , s.end());
	}
	int N = n;
	for(int i = n - 1; i >= 0; i--)
	{
		if(s[i] == 'o')
			N = i;
		nxt[i] = N;
	}
	reverse(l[1] , l[1] + k);
	for(int i = 0; i < k; i++)
		l[1][i] = n - 1 - l[1][i];
	for(int i = 0; i < k; i++)
	{
		if(sum(l[0][i] , l[1][i]) == 1)
		{
			cout << nxt[l[0][i]] + 1 << endl;
		}
	}
	
}


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

typedef long long int LL;
#define REP(n) for(LL i = 0; i < (n); i++)
#define COUT(val) cout << (val) << endl
#define CIN(val) cin >> (val)
#define SORT(vec) sort(vec.begin(), vec.end())
#define SORT_GRE(vec) sort(vec.begin(), vec.end(), greater<LL>())

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a*c <= b){
        cout << c << endl;   
    } else {
        cout << b/a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int n, m, q;
int a[55], b[55], c[55], d[55];
int ans = 0;

void dfs(vector<int> v = vector<int>(0)){
    if((int)v.size() == n){
        int sum = 0;
        for(int i = 0; i < q; ++i){
            if(v[b[i]] - v[a[i]] == c[i])   sum += d[i];
        }
        chmax(ans, sum);
        return;
    }

    int st = 1;
    if(v.size() != 0)   st = v.back();
    for(int i = st; i <= m; ++i){
        vector<int> next = v;
        next.push_back(i);
        dfs(next);
    }
}

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

    cin >> n >> m >> q;
    for(int i = 0; i < q; ++i){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i], --b[i];
    }

    dfs();
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n){
    int s=0,a[10],k=0;
    for(int i=512;i>0;i/=2)if(n>=i){
        a[k++]=i;
	n-=i;
      }
    for(int i=k-1;i>=0;i--,s++){
      if(!s)cout<<a[i];
      else cout<<' '<<a[i];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 2980
s = list(input())
n = len(s)


ans = 0

for i in range(2 ** (n-1)):
    s_temp = s.copy()
    numbers = [s_temp.pop(0)]
    for j in range(n-1):
        if (i >> j) & 1:
            numbers.append(s_temp.pop(0))
        else:
            numbers[len(numbers)-1] = numbers[len(numbers)-1] + s_temp.pop(0)

    numbers = list(map(int, numbers))

    ans += sum(numbers)

print(ans)


Measured memory_bytes: 9132
/* 
 *     author-->@harshrajani460
 *     codeforces round-567
 *
 */
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define mp make_pair
#define pe(x) cout<< x << endl ;
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define el endl
#define M 998244353 
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROR(i,a,b) for(int i=a;i>=b;i--)
const int N = 1e5 + 5;
int dp[N];
void dfs(vector<vector<int> > &v,vector<bool> &vis,int x)
{
    vis[x]=true;
    for(int i=0;i<v[x].size();i++)
    {
        if(!vis[v[x][i]])
        dfs(v,vis,v[x][i]);
        
        dp[x]=max(dp[x],1+dp[v[x][i]]);
    }
}
int32_t main() 
{ 
   int n,m;
   cin>>n>>m;
   vector<vector<int> > v(n+1);
   vector<bool> vis(n+1,false);
   //memset(vis,false,sizeof(false));
   memset(dp,0,sizeof(dp));
   FOR(i,0,m)
   {
       int x,y;
       cin>>x>>y;
       v[x].pb(y);
   }
   FOR(i,1,n+1)
   {
       if(!vis[i])
       dfs(v,vis,i);
   }
   int ans=0;
   FOR(i,1,n+1)
   ans=max(ans,dp[i]);
   cout<<ans;
   
} 

Measured memory_bytes: 9984
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main(){
	
	int N;
	
	int a[10000];
	
	cin >> N;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	sort(a, a + N);
	
	cout << a[N - 1] - a[0] << endl;
	
	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <chrono>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <cassert>
# include <array>
# include <tuple>
# include <cctype>
# include <unistd.h>
# include <unordered_map>
# include <unordered_set>
using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define fast_work {ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

const ll INF = 1e18 + 5, NMAX = 2e5 + 5, MOD = 998244353, N = 1e9 + 5, LOG = 25;
const ld EPS = 1e-8, pi = 3.14159265358979323846;

#define int long long

int hor[4 * NMAX], ver[4 * NMAX], n, q;

void push(int * t, int v) {
    t[v * 2] = min(t[v * 2], t[v]);
    t[v * 2 + 1] = min(t[v * 2 + 1], t[v]);
    t[v] = n;
}

void update(int * t, int v, int tl, int tr, int l, int r, int val) {
    if(l > r) return;

    if(tl == l &&  tr == r) {
        t[v] = min(t[v], val);
    } else {
        int tm = (tl + tr) / 2;

        push(t, v);

        update(t, v * 2, tl, tm, l, min(r, tm), val);
        update(t, v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int get(int * t, int v, int tl, int tr, int pos) {
    if(tl == tr) return t[v];

    int tm = (tl + tr) / 2;
    if(pos <= tm)
        return min(t[v], get(t, v * 2, tl, tm, pos));
    else
        return min(t[v], get(t, v * 2 + 1, tm + 1, tr, pos));
}

signed main() {
    fast_work

    cin >> n >> q;

    ll answer = (n - 2LL) * (n - 2LL);

    for(int i = 1; i <= 4 * n; ++i) hor[i] = ver[i] = n;

    while(q --> 0) {
        int type, x;
        cin >> type >> x;
        if(type == 1) {
            int border = get(hor, 1, 1, n, x);
            answer -= border - 2;
            update(ver, 1, 1, n, 1, border - 1, x);
        } else {
            int border = get(ver, 1, 1, n, x);
            answer -= border - 2;
            update(hor, 1, 1, n, 1, border - 1, x);
        }
    }

    cout << answer;
}


Measured memory_bytes: 16148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>

using namespace std;

long long n, m;
long long p;
vector<pair<int, int> > graph[50000];

struct edge{
    int from, to, w;
};

vector<edge> edges;
vector<int> rgraph[50000];

int correct[50000];
int evencorrect[50000];
long long dist[50000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> p;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        c -= p;
        graph[a].push_back({b, -c});
        rgraph[b].push_back(a);
        edges.push_back({a, b, -c});
    }
    correct[n] = 1;
    vector<int> q = {n};
    for (int i = 0; i < q.size(); i++)
    {
        int u = q[i];
        for (int j = 0; j < rgraph[u].size(); j++)
        {
            int v = rgraph[u][j];
            if (correct[v] == 0)
            {
                correct[v] = 1;
                q.push_back(v);
            }
        }
    }
    q = {1};
    evencorrect[1] = 1;
    for (int i = 0; i < q.size(); i++)
    {
        int v = q[i];
        for (int j = 0; j < graph[v].size(); j++)
        {
            int u = graph[v][j].first;
            if (evencorrect[u] == 0)
            {
                evencorrect[u] = 1;
                q.push_back(u);
            }
        }
    }
    fill(dist, dist + n + 1, 10000 * 100000);
    dist[1] = 0;
    for (int j = 0; j < n; j++)
    {
        for (int i = 0; i < m; i++)
        {
            long long f = edges[i].from;
            long long t = edges[i].to;
            if (dist[f] + edges[i].w < dist[t])
            {
                dist[t] = dist[f] + edges[i].w;
            }
        }
    }
    for (int i = 0; i < m; i++)
    {
        long long f = edges[i].from;
        long long t = edges[i].to;
        if (dist[f] + edges[i].w < dist[t])
        {
            dist[t] = dist[f] + edges[i].w;
            if (correct[t] && evencorrect[t])
            {
                cout << -1;
                return 0;
            }
        }
    }
    cout << max(0LL, -dist[n]) << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N), num(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    P[i]--;
  }
  for (int i = 0; i < N; i++) {
    cin >> Q[i];
    Q[i]--;
    
  }
  for (int i = 0; i < N; i++) num[i] = i;
  map<vector<int>, int> permutation;
  int cnt = 0;
  while (next_permutation(num.begin(), num.end())) {
    cnt++;
    permutation[num] = cnt;
  }
  cout << abs(permutation[P] - permutation[Q]) << endl;
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
char s[109];
int main()
{
	cin>>s+1;
	int x=0;
	for (int i=1; i<=4; ++i)
		x=x*10+s[i]-'0';
	if (x<2019) {puts("Heisei"); return 0;}
	if (x>2019) {puts("TBD"); return 0;}
	x=0;
	for (int i=6; i<=7; ++i)
		x=x*10+s[i]-'0';
	if (x<4) {puts("Heisei"); return 0;}
	if (x>4) {puts("TBD"); return 0;}
	x=0;
	for (int i=9; i<=10; ++i)
		x=x*10+s[i]-'0';
	if (x<=30) {puts("Heisei"); return 0;}
	if (x>30) {puts("TBD"); return 0;}
}

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

#define pb push_back
#define F first
#define S second
#define fo(i,a,b)  for(int i = a; i < b; i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
    return(m == 0)?1:n*nCr(n-1,m-1)/m;
}
/*****************************************************/

const int N = (int) 2e3 + 4;

int n , a[N];

int bs(int i , int j){
    int l = j + 1 , r = n - 1 , ans = j;
    while(l <= r){
        int mid = l + (r - l) / 2;
        if(a[i] + a[j] > a[mid])
            ans = mid , l = mid + 1;
        else
            r = mid - 1;
    }
    return ans - j;
}

int main()
{
    cin >> n;

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

    sort(a , a + n);
    ll res = 0;

    for(int i = 0; i < n; ++i)
        for(int j = i + 1; j < n; ++j)
            res += bs(i , j);

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 384
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 M = 0;

	SINT32 ans = 0;

	cin >> N;
	cin >> M;

	ans = M*1900+(N-M)*100;
	ans = ans * pow(2,M);
	
	cout << ans << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 256
module ABC086C
	sub Main(ByVal args() as String)
		dim i,n,t,x,y as integer
		dim arr(3) as string
		n=Console.ReadLine()
		t=x=y=0
		for i=1 to n
			arr=Split(Console.ReadLine())
			dim t0,x0,y0 as integer
			t0=arr(0):x0=arr(1):y0=arr(2)
			dim dt,dx,dy as integer
			dt=t0-t:dx=x0-x:dy=y0-y
			if dx+dy>dt orelse (dt-dx-dy) mod 2>0
				Console.WriteLine("No")
				return
			end if
			t=t0:x=x0:y=y0
		next
		Console.WriteLine("Yes")
	end sub
end module


Measured memory_bytes: 15576
//g++でビルド

#include "bits/stdc++.h"

using namespace std;

string getminstring(string s, string t, int i){
    int len = t.length();
    string sub = s.substr(i, len);
    for(int i = 0; i<len; i++){
        if(sub[i] == t[i]){
            //ok
        }else if(sub[i] == '?'){
            sub[i] = t[i];
        }else{
            return "?";
        }
    }

    string result = s.substr(0, i) + sub + s.substr(i+len);
    for(int i = 0; i < result.length(); i++){
        if(result[i] == '?') result[i] = 'a';
    }

    return result;
}

int main(){
    string s, t;
    cin >> s >> t;
    int slen = s.length();
    int tlen = t.length();
    string result = "UNRESTORABLE";
    if(slen < tlen){
        cout << result << endl;
        return 0;
    }
    vector<string> results;
    for(int i = 0; i < slen - tlen + 1; i++){
        string ans = getminstring(s, t, i);
        results.push_back(ans);
    }

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

    for(int i = 0; i < results.size(); i++){
        if(results[i] != "?"){
            result = results[i];
            break;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
N=gets.to_i
A=gets.split.map(&:to_i).sort
B=gets.split.map(&:to_i).sort
C=gets.split.map(&:to_i).sort
j=0
r=Array.new(N){0}
N.times{|i|
    while j < N && A[j] < B[i]
        j+=1
    end
    r[i] = j
}
warn r.inspect
j=0
N.times{|i|
    while j < N && B[i] >= C[j]
        j+=1
    end
    r[i] *= N-j
}
warn r.inspect
puts r.inject(0){|r,i|r+i}


Measured memory_bytes: 32112
#include <stdio.h>

int main(){
	int A;
	int B;
	int C;
	scanf ("%d %d %d",&A,&B,&C);
	if (A==B && A==C && C==B){
		printf ("No");
	}
	else if (A==B && A!=C){
		printf ("Yes");
	}
	else if (A==C && A!=B){
		printf ("Yes");
	}
	else if (B==C && B!=A){
		printf ("Yes");
	}
	else if (A!=B && A!=C && B!=C){
		printf ("No");
	}
	
	return 0;
}

Measured memory_bytes: 2128
n=int(input())
h=list(map(int,input().split()))
h=h[::-1]
for i in range(n-1):
    if h[i+1]-h[i]>1: 
        print('No')
        exit()
    elif h[i+1]-h[i]==1:
        h[i+1] -= 1
    else:
        pass
print('Yes')

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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 main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<int32> a(n);
  REP(i,n)cin >> a[i];
  sort(all(a));
  vector<bool> flg(1e6+10,true);
  int32 ans = 0;
  REP(i,n){
    if(flg[a[i]]){
      if(i == n-1 || a[i] != a[i+1])++ans;
      FOR(j,1,1e6+10){
        if(a[i] * j >= 1e6+5)break;
        flg[a[i] * j] = false;
      }
    }
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 5116
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 1000005


ll fact[SIZE],inv_fact[SIZE];
ll A[100005],table[100005];


ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll nCk(ll n,ll k){

	if(k > n)return 0;

	ll ret = fact[n]*inv_fact[k];
	ret %= MOD;
	ret *= inv_fact[n-k];

	return ret%MOD;
}



int main(){

	fact[0] = 1;
	for(ll i = 1; i < SIZE; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}
	inv_fact[SIZE-1] = mod_inverse(fact[SIZE-1],MOD);
	for(ll i = SIZE-1; i >= 1; i--){

		inv_fact[i-1] = inv_fact[i]*i;
		inv_fact[i-1] %= MOD;
	}

	ll N;
	scanf("%lld",&N);

	for(ll i = 1; i <= N; i++){

		table[i] = 0;
	}

	int base = -1;

	for(ll i = 0; i < N+1; i++){

		scanf("%lld",&A[i]);
		table[A[i]]++;
		if(table[A[i]] == 2){

			base = A[i];
		}
	}

	ll L = -1, R = -1;

	for(ll i = 0; i < N+1; i++){
		if(A[i] != base)continue;

		if(L == -1){

			L = i;
		}else{

			R = i;
		}
	}

	ll pre = L;
	ll mid = R-(L+1); //LとRの間にある数
	ll tail = N-(R+1)+1;

	//printf("pre:%lld mid:%lld tail:%lld\n",pre,mid,tail);


	printf("%lld\n",N); //1
	for(ll num = 2; num <= N; num++){

		//printf("\n\nnum:%lld\n",num);

		//baseを含まない
		ll tmp = nCk(N-1,num);
		//printf("tmp:%lld\n",tmp);

		//baseを1つ含む
		//区間midにデータなし(L,Rが区別されない)
		ll no_mid = nCk(pre+tail,num-1);
		//printf("no_mid:%lld\n",no_mid);

		//区間midにデータあり(L,Rが区別される)
		//printf("nCk(N-1,num-1):%lld -nCk(pre+tail,num-1):%lld\n",nCk(N-1,num-1),nCk(pre+tail,num-1));

	 	ll yes_mid = 2*(nCk(N-1,num-1)-nCk(pre+tail,num-1)+MOD)%MOD; //★★ここが－になる場合あり★★
		//printf("yes_mid:%lld\n",yes_mid);

		tmp += (no_mid+yes_mid)%MOD;
		tmp %= MOD;

		//baseを2つ含む
		ll num_two = nCk(N-1,num-2);
		//printf("num_two:%lld\n",num_two);

		tmp += num_two;
		tmp %= MOD;

		printf("%lld\n",tmp);
	}
	printf("1\n");

	return 0;
}


Measured memory_bytes: 20892
#include<stdio.h>
#include<stdlib.h>

int pop();
void push(int);
int stack[2000];
int kazu=0;
void push(int j){
  stack[kazu++]=j;
}
int pop(){
  if(kazu<=0) return 0;
  return stack[--kazu];
}

int main(){
  int i,j,k=0,l,n,Ans;
  char s[100];
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      l=pop();
      n=pop();
      Ans=l+n;
      push(Ans);
    }
    else if(s[0]=='-'){
      l=pop();
      n=pop();
      Ans=n-l;
      push(Ans);
    }
    else if(s[0]=='*'){
      l=pop();
      n=pop();
      Ans=l*n;
      push(Ans);
    }
    else{
      j=atoi(s);
      push(j);
    }
  }
  Ans=pop();
  printf("%d\n",Ans);
  return 0;
}



Measured memory_bytes: 2116
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (k, n) = (v[0] as i64, v[1]);
    let a = read_vec::<i64>();
    let mut ans = k - a[0] - (k - a[n - 1]);
    for i in 0..n - 1 {
        ans = min(ans, k - (a[i + 1] - a[i]));
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 10492
// Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
typedef long long LL;
const int MAXN = 100000;
using namespace std;

inline void enableFileIO() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

struct Ufs {
  int fa[MAXN + 5];
  int find(int x) {
    return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);
  }
  void unionSet(int x, int y) {
    int p = find(x), q = find(y);
    if (p == q) return;
    fa[p] = q;
  }
}S;

int p[MAXN + 5], n, m;

void init() {
  //enableFileIO();

  n = read();
  m = read();
  for (int i = 1; i <= n; ++i) {
    p[i] = read();
    S.fa[i] = i;
  }
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    S.unionSet(u, v);
  }
}

int main() {
  init();

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (S.find(i) == S.find(p[i])) ++ans;
  }
  printf("%d\n", ans);
  return 0;
}

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

const int MAX_N = 1e5+10;
int n, m;
int x[MAX_N],y[MAX_N];

bool red[MAX_N];
int cnt[MAX_N];

void solve()
{
    for(int i=1;i<=n;++i) cnt[i]=1;
	red[1]=true;
	for(int i=0;i<m;++i){
	    cnt[x[i]]--, cnt[y[i]]++;
		if(red[x[i]]){
			red[y[i]]=true;
		}
		if(!cnt[x[i]]) red[x[i]]=false;
	}
	int ans = 0;
	for(int i=1;i<=n;++i)if(red[i])ans++;
	cout<<ans<<'\n';
}

int main()
{
	cin >> n >> m;
	for(int i=0;i<m;++i){
		cin >> x[i] >> y[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 4780
// ------------------------------------
// Date:2018/ 2/24
// Problem:AGC 021 DigitSum2 a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

int main()
{
  string s;
  int tmp;
  bool flag = true;
  ll ans = 0ll;
  cin >> s;
  REP(i,s.size()) {
    if (s.size() == 1) {
      cout << s << endl;
      return 0;
    }
    ll tmp = s[i] - '0';
    if (i == 0) {
      ans = tmp-1;
    } else {
      ans += 9ll;
    }
    if (i != 0 && tmp != 9) flag = false;
    if (flag && i == s.size()-1) ++ans;
    //cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <ostream>
#include <iomanip>
#include <set>

using namespace std;


int main() {

    unsigned int N;
    unsigned int M;
    unordered_map<int, map<int, int>> city;
    vector<pair<int, int>> result;

    cin>>N>>M;
    result.resize(M);

    int a, b;
    for(int i=0; i<M; ++i)
    {
        cin>>a>>b;
        city[a][b] = i;
    }

    for (auto &iter : city)
    {
        int i=1;
        for(auto iter2 = iter.second.begin(); iter2!=iter.second.end(); ++iter2)
        {
            result[iter2->second].first = iter.first;
            result[iter2->second].second= i;
            ++i;
        }
    }

    for(int i=0; i<M; ++i)
    {
        cout<<setfill('0')<<setw(6)<<result[i].first;
        cout<<setfill('0')<<setw(6)<<result[i].second<<endl;
    }


    return 0;
}



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

using namespace std;

#define pb            push_back
#define mp            make_pair
#define po            pop_back
#define fi            first
#define se            second
#define mxn           100005
#define ll            long long int
#define ldb           long double
#define fr(i,a,b,k)   for(int i=a ; i<b ; i+=k)
#define frr(i,a,b,k)  for(int i=a ; i>b ; i-=k)
#define all(v)        v.begin(),v.end()
#define endl          "\n"
#define deg(x)        cout<<endl<<#x<<" = "<<(x)<<endl;
#define casep(x)      cout<<"Case #"<<(x)<<": ";
#define fast          ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

typedef pair<ll,ll> pp;
typedef vector<ll> vi;
typedef vector<pp> vpp;
typedef vector<vi> vvi;

const int inf = INT_MAX;

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b){ return __gcd(a,b);}
ll lcm(ll a,ll b){return a*b/__gcd(a,b);}
vector<vector<ll>> adj;
vector<bool> vis;


void solve(ll test){

    long long int N, K, res = -1000000009;
vector<long long int> P, C, score;
cin >> N >> K ;

P.resize(N+1);
C.resize(N+1);
score.resize(N+1);

for(int i = 1; i<N+1; i++){
    cin >> P[i];
}
for(int i = 1; i<N+1; i++){
    cin >> C[i];
}

for(int i = 1; i<N+1; i++){
    int tmpIdx = i, loopL = 0;
    long long int loopS = 0, score = 0;

    do{
        loopL++;
        tmpIdx = P[tmpIdx];
        loopS += C[tmpIdx];
        score += C[tmpIdx];

        if(loopL <= K){
            res = max(res, score);
        }
    }while(tmpIdx != i);
    // loop部分を使わない場合はこのループで網羅

    // tmpIdx は i
    score = 0;
    if(K >= loopL && loopS > 0){
        for(int j=1; j<loopL+1; j++){
            tmpIdx = P[tmpIdx];
            score += C[tmpIdx];
            res = max(res, score + loopS*((K-j)/loopL));
        }
    }

}


cout << res;

}

int main(){

    fast;
    int t=1;
    // cin >> t;
    for(int i=1 ; i<=t ; i++){
        solve(i);
        cout << endl;
    }
    return 0;
}


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

int main(void)
{
    int array[] = {1,
                 1,
                 1,
                 2,
                 1,
                 2,
                 1,
                 5,
                 2,
                 2,
                 1,
                 5,
                 1,
                 2,
                 1,
                 14,
                 1,
                 5,
                 1,
                 5,
                 2,
                 2,
                 1,
                 15,
                 2,
                 2,
                 5,
                 4,
                 1,
                 4,
                 1,
                 51};

    int n;
    cin >> n;
    cout << array[n-1] << endl;
    return 0;
}

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

int main()
{

	int sum;
	int value[9];

	while(cin >> sum, sum) {
		for (int i = 0; i < 9; i++) {
			cin >> value[i];
			sum -= value[i];
		}
		cout << sum <<  endl;
	}

	return 0;

}

Measured memory_bytes: 3008
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
if k in a:
    print("POSSIBLE")
    exit()
tmp = a[0]
for i in range(1,n):
    tmp = math.gcd(tmp,a[i])
for i in a:
    if i > k and (i-k) % tmp == 0:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Measured memory_bytes: 84696
#include<bits/stdc++.h>
using namespace std;
map<string,int> mp;
int main(){
  int n;cin>>n;
  string x;bool f=true;
  for(int i=0;i<n;i++){
    string s;cin>>s;
    if(mp[s])f=false;
    mp[s]=1;
    if(i>0){
      if(s[0]!=x[x.length()-1])f=false;
    }
    x=s;
  }
  if(f)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    const tokens = input[0].split(' ').map(function(value) { return parseInt(value, 10); });
    const h = tokens[0];
    const w = tokens[1];

    let a = new Array(h);
    for (let i = 0; i < h; i++) {
        a[i] = input[i + 1].split('');
    }

    let distanceMap = new Array(h);
    let blackCells = [];
    for (let i = 0; i < h; i++) {
        distanceMap[i] = new Array(w);
        for (let j = 0; j < w; j++) {
            distanceMap[i][j] = Number.MAX_SAFE_INTEGER;
        }
    }

    for (let i = 0; i < h; i++) {
        for (let j = 0; j < w; j++) {
            if (a[i][j] === "#") {
                distanceMap[i][j] = 0;
            } else {
                if (i - 1 >= 0 && distanceMap[i - 1][j] < distanceMap[i][j]) {
                    distanceMap[i][j] = distanceMap[i - 1][j] + 1;
                }
                if (j - 1 >= 0 && distanceMap[i][j - 1] < distanceMap[i][j]) {
                    distanceMap[i][j] = distanceMap[i][j - 1] + 1;
                }
            }
        }
    }
    for (let i = h - 1; i >= 0; i--) {
        for (let j = w - 1; j >= 0; j--) {
            if (a[i][j] === "#") {
                distanceMap[i][j] = 0;
            } else {
                if (i + 1 < h && distanceMap[i + 1][j] < distanceMap[i][j]) {
                    distanceMap[i][j] = distanceMap[i + 1][j] + 1;
                }
                if (j + 1 < w && distanceMap[i][j + 1] < distanceMap[i][j]) {
                    distanceMap[i][j] = distanceMap[i][j + 1] + 1;
                }
            }
        }
    }

    let ans = 0;
    for (let i = 0; i < h; i++) {
        for (let j = 0; j < w; j++) {
            if (ans < distanceMap[i][j]) {
                ans = distanceMap[i][j];
            }
        }
    }

    console.log(ans);

    return 0;
}


Measured memory_bytes: 56892
// AGC039 B

#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int a[205], G[205][205];
queue <int> q;

int main() {
    
  int n; read(n);
  for (RI i = 1; i <= n; ++i)
    for (RI j = 1; j <= n; ++j) {
      char ch = gc();
      while (ch != '0' && ch != '1') ch = gc();
      if (ch == '1') G[i][j] = 1;
    }
  int ans = 0;
  for (RI i = 1; i <= n; ++i) {
    memset(a, 0, sizeof(a));
    a[i] = 1;
    q.push(i);
    while (!q.empty()) {
      int t = q.front(); q.pop();
      for (RI i = 1; i <= n; ++i)
        if (G[t][i]) {
          if (!a[i]) a[i] = a[t] + 1, q.push(i);
          else if (abs(a[i] - a[t]) != 1) return puts("-1"), 0;
        }
    }
    for (RI j = 1; j <= n; ++j)
      ans = max(ans, a[j]);
  }
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 512
// C.

#include <iostream>
#include <sstream>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>

using namespace std;

typedef long long LL;

LL solve(int n, vector<int>& a) {
	if (n == 0) {
		return a[0] == 1 ? 1 : -1;
	}
	if (n < 60 && a[n] > (1LL << n)) {
		return -1;
	}
	vector<LL> vmn(n + 1);
	vector<LL> vmx(n + 1);
	vmn[n] = a[n];
	vmx[n] = a[n];
	for (int i = n - 1; i >= 0; --i) {
		LL curr = a[i];
		LL upper = 1LL << min(60, i);
		if (curr > upper) {
			return -1;
		}
		LL nmn = (vmn[i + 1] + 1) / 2 + curr;
		if (nmn > upper) {
			return -1;
		}
		LL nmx = min(vmx[i + 1] + curr, upper);
		vmn[i] = nmn;
		vmx[i] = nmx;
	}
	LL ans = 1 + a[n];
	LL mx = 1;
	for (int i = 1; i < n; ++i) {
		LL next = min(vmx[i], (mx - a[i - 1]) * 2);
		ans += next;
		mx = next;
	}
	return ans;
}

int main(int argc, char* argv[]) {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 0; i <= n; ++i) {
		cin >> a[i];
	}
	LL ans = solve(n, a);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5116
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int INF=100000;

int main(void){
  int time[101][101];
  int cost[101][101];
  int a,b,c,d;
  int n,m;
  int p,q,r;
  int k;
  int i,j,l;
  while(true){
    cin>>n>>m;
    if(n==0&&m==0)return(0);
    for(i=0;i<101;i++){
      for(j=0;j<101;j++){
	time[i][j]=INF;
	cost[i][j]=INF;
      }
    }

    for(i=0;i<n;i++){
      cin>>a>>b>>c>>d;
      cost[a][b]=cost[b][a]=c;
      time[a][b]=time[b][a]=d;
    }
    for(i=1;i<m+1;i++){
      for(j=1;j<m+1;j++){
	for(l=1;l<m+1;l++){
	  cost[j][l]=min(cost[j][l],cost[j][i]+cost[i][l]);
	  time[j][l]=min(time[j][l],time[j][i]+time[i][l]);
	}
      }
    }

    cin>>k;
    for(i=0;i<k;i++){
      cin>>p>>q>>r;
      if(r==0){
	cout<<cost[p][q]<<endl;
      }
      else if(r==1){
	cout<<time[p][q]<<endl;;
      }
    }
  }
}

Measured memory_bytes: 1240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemB
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var A = read[0];
            var B = read[1];
            var ret = 0;
            if (B != 1)
                ret = B <= A ? 1 : (B - A) % (A - 1) == 0 ? 1 + (B - A) / (A - 1) : 2 + (B - A) / (A - 1);
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 13268
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ta = tb = 0
m = 0
while m<M and tb+B[m]<=K:
    tb += B[m]
    m += 1
ans = m

for n in range(1,N+1):
    ta += A[n-1]
    while ta+tb>K and m>0:
        m -= 1
        tb -= B[m]
    if ta+tb>K:
        break
    ans = max(ans, n+m)

print(ans)

Measured memory_bytes: 40616
#include <iostream>
#include <map>

using namespace std;

int N;
const int MAX_N = 200001;
long A[MAX_N];
map<int, long> m;

int main(){
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> A[i];
        if(m.count(A[i]) == 0) m[A[i]] = 1;
        else m[A[i]]++;
    }

    long ans = 0;
    map<int, long> t;
    for(auto it=m.begin(); it != m.end(); it++){
        long num = it->second;
        int p = it->first;
        if(num >= 2)t[p] = num*(num-1)/2;
        else t[p] = 0;
        ans += t[p];
    }

    for(int i=0; i<N; i++){
        if(m[A[i]]<=2) cout << ans - t[A[i]];
        else cout << ans - m[A[i]]+1;
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 18944
#include <iostream>
#define INF (1 << 28)

using namespace std;

int c[3][3];

bool check_info() {
	for (int j = 0; j < 2; ++j) {
		int base = c[0][j] - c[0][j+1];
		for (int i = 1; i < 3; ++i) {
			if (base != c[i][j] - c[i][j+1]) {
				return false;
			}
		}
	}
	
	for (int i = 0; i < 2; ++i) {
		int base = c[i][0] - c[i+1][0];
		for (int j = 1; j < 3; ++j) {
			if (base != c[i][j] - c[i+1][j]) {
				return false;
			}
		}
	}

	return true;
}

int main(void) {
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> c[i][j];
		}
	}

	if (check_info()) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


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

int main(){
  int n; cin >> n;
  vector<int> b(n-1); vector<int> a(n);
  for(int i=0;i<n-1;i++){
    cin >> b[i];
  }
  a[0]=b[0];
  for(int i=0;i<n-2;i++){
    if(b[i]<=b[i+1]){
      a[i+1]=b[i];
    }
    else{
      a[i+1]=b[i+1];
    }
  }
  a[n-1]=b[n-2];
  int sum; sum=0;
  for(int i=0;i<n;i++){
    sum=sum+a[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD

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

bool g(string s) {
  for(int i = 0; i < sz(s); i++) if(s[i] != s[sz(s)-1-i]) return false;
  return true;
}

void solve() {
  string s;
  cin >> s;
  int n = sz(s);
  if(g(s) && g(s.substr(0, n/2)) && g(s.substr(n/2+1))) cout << "Yes\n";
  else cout << "No\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
using namespace std;
//int main(int argc, char* argv[]){
int main(){
	int K;//文字数
  	int length;
 	string str1;
  	string str2;
  	cin>>str1;//数字
  	cin>>str2;
  	K = atoi(str1.c_str());
  	length = str2.length();
  	if(length > K){
      str2.erase(K);//K文字目以降の文字列を削除
      cout << str2;
      cout << "..." << endl;
    }else {
		cout << str2;
    }
  return 0;
}

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

using namespace std;

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

    vector<string> status = {"AC", "WA", "TLE", "RE"};
    vector<int> cnt(status.size(), 0);
    for (int i = 0; i < n; i++) {
        string buf;
        cin >> buf;
        for (int j = 0; j < status.size(); j++) {
            if (buf == status[j]) {
                cnt[j]++;
                break;
            }
        }
    }
    for (int i = 0; i < status.size(); i++) {
        string output = status[i] + string(" x ") + std::to_string(cnt[i]);
        cout << output << endl;
    }
    return 0;
}


Measured memory_bytes: 3688
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int h,w,k;
    cin>>h>>w>>k;
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    vvi a(h,vi(w));
    int t=1;
    rep(i,h)rep(j,w){
        if(s[i][j]=='#')a[i][j]=t++;
    }
    rep(i,h){
        Rep(j,1,w)if(a[i][j]==0)a[i][j]=a[i][j-1];
        rev(j,w-1)if(a[i][j]==0)a[i][j]=a[i][j+1];
    }
    rep(j,w){
        Rep(i,1,h)if(a[i][j]==0)a[i][j]=a[i-1][j];
        rev(i,h-1)if(a[i][j]==0)a[i][j]=a[i+1][j];
    }
    rep(i,h){
        rep(j,w)cout<<a[i][j]<<sp;
        cout<<endl;
    }
}

Measured memory_bytes: 1664
import math

while(1):
    a_2 = 0
    n = int(raw_input())
    if n == 0:
        break
    s = map(float, raw_input().split())

    Sum = sum(s)
    m = Sum/n
    
    for i in range(n):
        a_2 += (s[i] - m)**2 
    a_2 = a_2/n
    
    a = math.sqrt(a_2)
    
    print a

Measured memory_bytes: 6512
#include<bits/stdc++.h>
#define rep(x,a,b) for(x=a;x<b;x++)
#define SIZE
typedef long long int ll;
using namespace std;
ll i,j;

int main(){
	ll n,k;
	cin>>n>>k;
	ll t,ans=0;
	for(i=0;i<n;i++){
		cin>>t;
		ans+=min(t,abs(k-t));
	}
	cout<<ans*2<<endl;
	return 0;
}


Measured memory_bytes: 256