akhauriyash/Code-Regression huggingface dataset:
#ALDS1_2-C Sort 1 - Stable Sort
def selectionSort(A,N):
    c=0
    for i in range(N):
        minj = i
        j=i
        while j<N:
            if(int(A[j][1])<int(A[minj][1])):
                minj = j
            j+=1
        if(i!=minj):
            A[i],A[minj]=A[minj],A[i]
            c+=1
    return c

def bubbleSort(A,N):
    c=0
    flag=1
    while flag:
        flag=0
        j=N-1
        while j>0:
            if(int(A[j][1])<int(A[j-1][1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1
    return c

N=int(input())
A=input().split()
checkA=[""]*9
for i in range(N):
    checkA[int(A[i][1])-1]+=A[i][0]

B=[]+A
C=[]+A

bubbleSort(B,N)
checkB=[""]*9
for i in range(N):
    checkB[int(B[i][1])-1]+=B[i][0]
S=""
for i in range(N-1):
    S+=B[i]+" "
S+=str(B[-1])
print(S)
if(checkB==checkA):
    print("Stable")
else:
    print("Not stable")
    
selectionSort(C,N)
checkC=[""]*9
for i in range(N):
    checkC[int(C[i][1])-1]+=C[i][0]
S=""
for i in range(N-1):
    S+=C[i]+" "
S+=str(C[-1])
print(S)
if(checkC==checkA):
    print("Stable")
else:
    print("Not stable")

Measured memory_bytes: 7848
#include <cstdio>
#include <cmath>

int main()
{
	for(int n,m;~scanf("%d%d",&n,&m);){
		double l[20],a[20],b[20];
		for(int i=0;i<n;i++)
			scanf("%lf%lf%lf",l+i,a+i,b+i);
		
		if(m==0){
			puts("0");
			continue;
		}
		
		double res=0;
		for(int s=(1<<m)-1;!(s&1<<n);){
			double sum=0;
			for(int i=0;i<n;i++) if(s>>i&1)
				for(int j=i+1;j<n;j++) if(s>>j&1)
					sum+=pow(l[i]-l[j],2)+pow(a[i]-a[j],2)+pow(b[i]-b[j],2);
			if(res<sum)
				res=sum;
			int lo=s&-s,lz=(s+lo)&~s;
			s=(s|lz)&~(lz-1);
			s|=(lz/lo/2-1);
		}
		
		printf("%f\n",res);
	}
	
	return 0;
}

Measured memory_bytes: 1092
#include <iostream>
#include <string>
#include <queue>
#include <utility>
using namespace std;

int main()
{
    int n,q;
    cin >> n >> q;
    queue<pair<string, int> > que;
    for(int i = 0; i < n; ++i){
        string s; int t;
        cin >> s >> t;
        que.push(pair<string,int>(s,t));
    }
    int time = 0;
    while(!que.empty()){
        pair<string, int> p = que.front(); que.pop();
        if(p.second <= q){
            time += p.second;
            cout << p.first << ' ' << time << endl; 
        } else {
            time += q;
            p.second -= q;
            que.push(p);
        }
    }
}

Measured memory_bytes: 4404
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w, ' '));
    for (int y = 0; y < h; ++y)
    {
        for (int x = 0; x < w; ++x)
        {
            cin >> a[y][x];
        }
    }
    
    vector<bool> vecIsAllWhite(w, true);
    for (int x = 0; x < w; ++x)
    {
        for (int y = 0; y < h; ++y)
        {
            if (a[y][x] == '#')
            {
                vecIsAllWhite[x] = false;
                break;
            }
        }
    }
    
    for (int y = 0; y < h; ++y)
    {
        bool isAllWhite  = true;
        for (int x = 0; x < w; ++x)
        {
            if (a[y][x] == '#') isAllWhite = false;
        }
        if (isAllWhite) continue;
        
        for (int x = 0; x < w; ++x)
        {
            if (vecIsAllWhite[x])
            {
                continue;
            }
            else
            {
                printf("%c", a[y][x]);
            }
        }
        printf("%c", '\n');
    }
    
    return 0;
}

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

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

    ll ans = x / 11 * 2;
    if (x % 11 == 0)
        ;
    else if (x % 11 <= 6)
        ans += 1;
    else
        ans += 2;

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


Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		out.println(rec(conv(ir.next().charAt(0)) ^ conv(ir.next().charAt(0))));
	}

	static int conv(char c) {
		return c == 'H' ? 1 : 0;
	}

	static String rec(int a) {
		return a == 1 ? "D" : "H";
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

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

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}

Measured memory_bytes: 21204
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define ll long long 
const int N = 1e6+7;

char s[N];
int len;
int sum[N],maxn[N],n;

int get(int p){
	int ans = 0,tot = 0;
	for(int i = 1; i <= n; i++){
		if(s[i] == '?' && tot + 2 + maxn[i] <= p) tot += 2;
		ans = min(sum[i] + tot,ans);
	}
	return ans;
}

int main(){
	cin >> (s+1);
	n = strlen(s+1);
	for(int i = 1; i <= n; i++)
		if(s[i] == '1') sum[i] = sum[i-1] + 1;
		else sum[i] = sum[i-1] - 1;
	maxn[n] = sum[n];
	for(int i = n-1; i > 0; i--) maxn[i] = max(maxn[i+1],sum[i]);
	int m = max(0,maxn[1]);
	cout << min(m-get(m),m+1-get(m+1));
} 

Measured memory_bytes: 11976
#include<iostream>
#include<stack>
#define _w_ true
using namespace std;

const int Ebit[8] = {0,1,2,3,5,7,8,9};

int main(){
  int n;
  stack<int> st;
  while(_w_){
    cin >> n;
    if(n == 0)break;
    while(_w_){
      if(n<8){
	st.push(Ebit[n]);
	break;
      }
      int amari = n%8;
      n = n/8;
      st.push(Ebit[amari]);
    }
    while(st.size()){
      cout << st.top();
      st.pop();
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n,C = LI()
    T = [[0 for i in range(200002)] for j in range(C)]
    for i in range(n):
        s,t,c = LI()
        c -= 1
        T[c][2*s] += 1
        T[c][2*t+1] -= 1
    for c in range(C):
        for i in range(200000):
            T[c][i+1] += T[c][i]
    ans = 0
    for i in range(200000):
        k = 0
        for c in range(C):
            if T[c][i]:k += 1
        ans = max(ans, k)
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


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

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

	int ans = 0;
	int x = 0;

	if (h > w) {
		for (int i = 1; x < n; i++) {
			x += h;
			ans++;
		}

	}
	else {
		for (int i = 1; x < n; i++) {
			x += w;
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = int64_t;

//1点更新,区間和
class SegmentTree {
public:
    SegmentTree(ll n) {
        n_ = (ll)pow(2, ceil(log2(n)));
        nodes_.resize(2 * n_ - 1, 0);
    }
    void addOne(ll x) {
        nodes_[x + n_ - 1]++;
        for (ll i = (x + n_ - 2) / 2; ; i = (i - 1) / 2) {
            nodes_[i] = nodes_[2 * i + 1] + nodes_[2 * i + 2];
            if (i == 0) {
                break;
            }
        }
    }

    ll getSum(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
        if (r < 0) {
            r = n_;
        }
        if (r <= a || b <= l) {
            return 0;
        }
        if (a <= l && r <= b) {
            return nodes_[k];
        }
        ll lv = getSum(a, b, 2 * k + 1, l, (l + r) / 2);
        ll rv = getSum(a, b, 2 * k + 2, (l + r) / 2, r);
        return lv + rv;
    }

private:
    //2のべき乗
    ll n_;
    vector<ll> nodes_;
};

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N);
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
        a[i] -= K;
    }

    vector<ll> b(N + 1, 0);
    for (ll i = 0; i < N; i++) {
        b[i + 1] = b[i] + a[i];
    }

    //座標圧縮
    map<ll, ll> mp;
    for (ll i = 0; i <= N; i++) {
        mp[b[i]] = 0;
    }
    ll count = 0;
    for (auto& itr : mp) {
        itr.second = count++;
    }

    vector<ll> c(N + 1);
    for (ll i = 0; i <= N; i++) {
        c[i] = mp[b[i]];
    }

    ll ans = 0;
    SegmentTree st(count + 1);
    for (ll i = 0; i <= N; i++) {
        //自分より左にある自分以下の値の個数
        ans += st.getSum(0, c[i] + 1);

        //自分を追加
        st.addOne(c[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 21504
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cctype>
using namespace std;

class P{
public:
	int val,l,r;
	P(int _val,int _l,int _r){
		val = _val;
		l = _l;
		r = _r;
	}

	void show(void){
		cout<<"["<<val<<","<<l<<","<<r<<"]"<<endl;
	}
};

int n,idx,leaf[10];
string s;
vector<P> tree;

void mkTree(int node){
	if(isdigit(s[idx])){
		tree[node].val = s[idx++] - '0';
		return;
	}

	tree.push_back(P(0,-1,-1));
	tree.push_back(P(0,-1,-1));
	tree[node].r = tree.size()-1;
	tree[node].l = tree.size()-2;

	idx++; // '('
	mkTree(tree[node].l);
	idx++; // ' '
	mkTree(tree[node].r);
	idx++; // ')'
}

map<int,int> solve(int node){
	map<int,int> res;
	if(tree[node].val > 0){
		res[leaf[tree[node].val-1]]++;
		return res;
	}

	map<int,int> left = solve(tree[node].l);
	map<int,int> right = solve(tree[node].r);

	for(map<int,int>::iterator i=left.begin();i!=left.end();i++){
		for(map<int,int>::iterator j=right.begin();j!=right.end();j++){
			int lbit = i->first;
			int rbit = j->first;
			res[lbit & rbit] += i->second * j->second;
			res[lbit | rbit] += i->second * j->second;
			res[lbit ^ rbit] += i->second * j->second;
		}
	}

	return res;
}

int main(void){
	while(getline(cin,s),s!="END"){
		idx = 0;
		tree.clear();
		tree.push_back(P(0,-1,-1));
		mkTree(0);

		cin>>n;
		for(int i=0;i<n;i++){
			leaf[i] = 0;
			for(int j=0;j<4;j++){
				int x;
				cin>>x;
				if(x) leaf[i] |= 1<<j;
			}
		}

		map<int,int> rst = solve(0);
		cout<<rst[15]<<endl;

		getchar(); //ツ嘉シツ行ツづづ篠つオ
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;
typedef pair<int,int> Pair;

int BinaryFind(int *A,int n, int key){
    int left = 0;
    int right = n;
    while(left<right){
        int mid=(left+right)/2;
        if(A[mid]==key){
            return 1;
        }else if(key <A[mid]){
            right=mid;
        }else left =mid+1;
    }
    return 0;
}

int main(){
    int A[100010];
    int n,q;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> A[i];
    }   
    cin >> q;
    int tmp;
    int cnt=0;
    for(int i=0;i<q;i++){
        cin >> tmp;
        cnt+=BinaryFind(A,n,tmp);
    }
    cout << cnt << endl;
    return 0;
}



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

int buttle(int *A,int N)
{
	int temp,num=0;
	bool flag=true;
	for (int i=0;flag;i++)
	{
		flag=false;
		for (int j=N-1;j>=i+1;j--)
		{
			if (A[j-1]>A[j])
			{
				temp=A[j];A[j]=A[j-1];A[j-1]=temp;
				flag=true;
				num++;
			}
		}
	}
	return num;
}

int main (void)
{
	int N;
	cin>>N;
	int *A=new int [N];
	for (int i=0;i<N;i++)
	    cin>>A[i];
	int j=buttle(A,N);
	for (int i=0;i<N;i++)
	{
	    if (i) cout<<" ";
	cout<<A[i];}
	cout<<endl;
	cout<<j<<endl;
	delete[]A;
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, a[mxn], dp[mxn], p1, p2, cnt = 1;

int main(){
    cin >> n;
    for (int i = 1; i <= n; i ++){
        cin >> a[i];
    }if(a[2] > a[1]) p1 = 1;
    if(a[2] < a[1]) p2 = 1;
    for (int i = 2; i <= n; i ++){
        if(a[i - 1] < a[i]){
            p1 = 1;
        }if(a[i - 1] > a[i]){
            p2 = 1;
        }if(p1 == 1 && p2 == 1){
            cnt ++;
            p1 = p2 = 0;
        }
    }cout << cnt;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <map>
#include<string>
#include <cmath>
using namespace std;
typedef long long ll;

int f(int n){
  if(n > 1){
    return n*f(n - 1);
  }
  else return 1;
}

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

  int p=1,q=1;

  for(int i=1; i<N; i++){
    int c=0;
    for(int j=i+1; j<N+1; j++){
      if(P[i]>P[j]) ++c;
    }
    p += c*f(N-i);
  }
  for(int i=1; i<N; i++){
    int c=0;
    for(int j=i+1; j<N+1; j++){
      if(Q[i]>Q[j]) ++c;
    }
    q += c*f(N-i);
  }
  int ans = abs(p-q);

  cout << ans << endl;

 return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  string s,t;
  cin >> s >> t;
  sort(all(s));
  sort(all(t));
  char bs = s[0];
  char bt = t[0];
  ll sf = 0;
  ll tf = 0;
  ll co = 0;
  priority_queue<ll> ques;
  rep(i,s.length()){
    if(bs!=s[i]){
      bs=s[i];
      sf |= (1<<(bs-'a'));
      ques.push(co);
      co=0;
    }
    co++;
  }
  ques.push(co);
  sf |= (1<<(bs-'a'));


  co=0;
  priority_queue<ll> quet;
  rep(i,t.length()){
    if(bt!=t[i]){
      bt=t[i];
      tf |= (1<<(bt-'a'));
      quet.push(co);
      co=0;
    }
    co++;
  }
  tf |= (1<<(bt-'a'));
  quet.push(co);
  
  if(s.length()!=t.length()){
    pri("No");
    return 0;
  }
  while(!quet.empty()){
    if(quet.top() != ques.top()){
      pri("No");
      return 0;
    }
    quet.pop();
    ques.pop();
  }
  pri("Yes");
    
  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;

/* [💭] [💡] [🎈] */

string b[100];
int dist[100][100];

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

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

    int n, m;
    cin >> n >> m;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dist[i][j] = 10001;
        }
    }

    priority_queue<pair<int, pii>> pq;
    dist[0][0] = 0;
    pq.emplace(-dist[0][0], pii(0, 0));

    while (pq.size()) {
        int d = -pq.top().first;
        pii c = pq.top().second;
        int x = c.first, y = c.second;
        pq.pop();
        if (dist[x][y] < d) continue;

        for (int d = 0; d < 2; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (0 > nx || nx >= n) continue;
            if (0 > ny || ny >= m) continue;
            if (dist[nx][ny] <= dist[x][y] + (b[nx][ny] != b[x][y])) continue;
            dist[nx][ny] = dist[x][y] + (b[nx][ny] != b[x][y]);
            pq.emplace(-dist[nx][ny], pii(nx, ny));
        }
    }

    cout << (dist[n - 1][m - 1] + (b[0][0] == '#') + (b[n - 1][m - 1] == '#')) / 2;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#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 itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    int n;
    cin >> n;
    int ma=0;
    int sum = 0;
    int tmp;
    REP(i,n){
        cin >> tmp ;
        sum+= tmp;
        ma = max( ma, tmp);
    }
    cout << int(sum - ma/2) << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll N, T;
    cin >> N >> T;
    vector<ll> t(N);
    rep(i,0,N) cin >> t[i];

    ll accm(0);
    rep(i, 0, N-1)
    {
        ll trial = t[i+1]-t[i];
        if (trial > T)
            trial = T;

        accm += trial;     
    }
    accm += T;

    cout << accm << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
using namespace std;

const int MAX_LEN = 100000;
// const int MAX_K = 1000000000;

int main() {
	string s;
	int K, c;
	cin >> s >> K;
	for(int i=0;i<s.length()-1;i++) {
		if(s[i]-'a'>0 && 'z'-s[i]+1 <= K) {
			K -= 'z'-s[i]+1;
			s[i] = 'a';
		}
	}
	c = s[s.length()-1] - 'a';
	c += K; c %= 26;
	s[s.length()-1] = 'a' + c;
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 512
n, m = gets.split.map(&:to_i)

oks = Array.new(n+1, true)
m.times { oks[gets.to_i] = false }

dp = Array.new(n+1,0)
dp[0] = 1
n.times do |i|
  (i+1..[i+2,n].min).each do |j|
    if oks[j]
      dp[j] += dp[i]
      dp[j] %= 1_000_000_007
    end
  end
end
puts dp[n]


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

int main(){
  int a[5];
  int loss[5];
  int maxloss = 0;
  int sum = 0;
  for(int i=0; i < 5; i++){
    cin >> a[i];
    loss[i] = (10 - (a[i] % 10)) % 10;
    if(maxloss < loss[i]){
      maxloss = loss[i];
    }
    sum += (a[i] + loss[i]);
  }
  sum -= maxloss;
  cout << sum;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int vis[100005];
vector<int> v;
vector<vector<int> > adj(100005,v);
int sign[100005];
void bfs(int s){
    queue<int> q;
    q.push(s);
    vis[s]=1;
    while (!q.empty()){
        int id=q.front();
        q.pop();
        for (int i=0;i<adj[id].size();i++){
            if (!vis[adj[id][i]]){
                q.push(adj[id][i]);
                vis[adj[id][i]]=1;
                sign[adj[id][i]]=id;
            }
        }
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    int a,b;
    for (int i=0;i<m;i++){
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    bfs(1);
    for (int i=1;i<=n;i++)
        if (vis[i]==0){
            cout<<"No"<<endl;
            return 0;
        }
    cout<<"Yes"<<endl;
    for (int i=2;i<=n;i++)
        cout<<sign[i]<<endl;
}


Measured memory_bytes: 10576
#include <bits/extc++.h>

#ifndef DUMP
#define DUMP(...) (void)0
#endif

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, x, t;
  cin >> n >> x >> t;
  cout << (n + x - 1) / x * t << '\n';
}


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

using namespace std;

int main(){

    int n, a, b;
    cin >> n >> a >> b;

    int res = 0;

    for (int i = 1; i <= n; i++){
        int temp = i;
        bool done = false;

        int tempResult = 0;

        while (temp){
            int t = temp % 10;
            temp /= 10;
            tempResult += t;
        }

        if (tempResult >= a && tempResult <= b){
            res += i;
        } 
    }


    cout << res << endl;




    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int D[100001], G[100001];
vector<int> E[100001];
int dfs(int A) {
	if (!D[A]) {
		int g = 0;
		D[A] = 1;
		for (auto i : E[A]) {
			g ^= dfs(i);
		}
		G[A] = g + 1;
	}
	return G[A];
}

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


	int N;
	cin >> N;
	rep(i, N - 1) {
		int x, y;
		cin >> x >> y;
		E[x].pb(y);
		E[y].pb(x);
	}

	dfs(1);

	if (G[1] - 1) co("Alice");
	else co("Bob");

	Would you please return 0;
}

Measured memory_bytes: 11264
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
#include <iomanip>
using namespace std;

//??°?????????????????°

void function()
{
	//??¢??°
}

int main()
{
	int n, m, l;
	int a[101][101];
	int b[101][101];
	cin >> n >> m >> l;

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

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

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			long long int sum = 0;
			for (int k = 0; k < m; k++)
			{
				sum += a[i][k] * b[k][j];
			}
			cout << sum;

			if (j != l - 1)
			{
				cout << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
    if(a+b >= 10){
      System.out.println("error");
    }else{
      System.out.println(a+b);
    }
  }
}


Measured memory_bytes: 21844
ys = gets.strip.to_i

yh = (ys / 100).to_i
yl = ys % 100

def isMonth(m)
    return 0 < m && m <= 12
end

fyh = isMonth(yh)
fyl = isMonth(yl)

if fyh && fyl then
    puts "AMBIGUOUS"
elsif !fyh && ! fyl then
    puts "NA"
elsif fyh && ! fyl then
    puts "MMYY"
else
    puts "YYMM"
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int inf = numeric_limits<int>::max();

int main(void){
  int n;
  vector< int > a;
  cin >> n;
  a.resize(n);
  for(int i = 0;i < n;++i)cin >> a[i];
  for(int i = n-1;i >= 0;i -= 2){
    cout << a[i] << " ";
  }
  if(n % 2 == 0){
    for(int i = 0;i < n;i += 2){
      cout << a[i] << " ";
    }
  }else{
    for(int i = 1;i < n;i += 2){
      cout <<  a[i] << " ";
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2944
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val X = readLine()!!.split(" ").map(String::toLong)
    val p = (X.sum() + (X.size / 2)) / X.size
    println(X.map { (it - p) * (it - p) }.sum())
}

Measured memory_bytes: 36208
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	input := scanString()
	if len(input)%2 != 0 {
		fmt.Println("No")
		return
	}
	for i := 0; i < len(input); i++ {
		if i%2 == 0 {
			if input[i] != 'h' {
				fmt.Println("No")
				return
			}
		} else {
			if input[i] != 'i' {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

func scanString() (s string) {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


int M, N, K; 
int J[1001][1001], O[1001][1001], I[1001][1001];
string s[1000];

int main() {
	cin >> M >> N >> K;
	for (int i = 0; i < M; i++) {
		cin >> s[i];
	}

	for (int i = 0; i <= M; i++) {
		J[i][0] = 0;
		O[i][0] = 0;
		I[i][0] = 0;
	}
	for (int i = 0; i <= N; i++) {
		J[0][i] = 0;
		O[0][i] = 0;
		I[0][i] = 0;
	}

	for (int i = 1; i <= M; i++) {
		for (int j = 1; j <= N; j++) {
			J[i][j] = J[i][j - 1] + J[i - 1][j] - J[i - 1][j - 1];
			O[i][j] = O[i][j - 1] + O[i - 1][j] - O[i - 1][j - 1];
			I[i][j] = I[i][j - 1] + I[i - 1][j] - I[i - 1][j - 1];

			if (s[i-1][j-1] == 'J') {
				J[i][j]++;
			}
			if (s[i-1][j-1] == 'O') {
				O[i][j]++;
			}
			if (s[i-1][j-1] == 'I') {
				I[i][j]++;
			}
		}
	}


	for (int i = 0; i < K; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		int Jn = J[c][d] - J[a - 1][d] - J[c][b - 1] + J[a - 1][b - 1];
		int On = O[c][d] - O[a - 1][d] - O[c][b - 1] + O[a - 1][b - 1];
		int In = I[c][d] - I[a - 1][d] - I[c][b - 1] + I[a - 1][b - 1];

		cout << Jn << " " << On << " " << In << endl;
	}


	return 0;
}




Measured memory_bytes: 15644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }
            for (int i = 0; i < H; i++) {
                for (int k = 0; k < W; k++) {
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
        sc.close();
    }
}


Measured memory_bytes: 62956
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int INF=1e20;

signed main(){
   int N;cin>>N;
   int A[N];
   map<int,int>memo;
   REP(i,N){
       cin>>A[i];
       if(i+1==A[i])memo[i]++;
   }
   int ans=0;
   int before=-2;
   for(auto it=memo.begin();it!=memo.end();it++){
       int va=it->first;
       if(va-before==1){
           before=-2;
       }
       else{
           ans++;
           before=va;
       }
   }
   cout<<ans<<endl;
}

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

int main()
{
    string s;
    cin>>s;
    int n= s.length();
    if(s[n-1]=='s')
    {
        s+="es";
    }
    else
    {
        s+="s";
    }
    cout<<s<<endl;
}


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

vector <int> v;
int n;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		v.push_back(t);
	}
	sort (v.begin(), v.end());
	if (v.back() - v[0] > 1) {
		cout << "No";
		return 0;
	}
	if (v.back() == v[0]) {
		if (n == v[0] + 1 || n >= v[0] * 2) {
			cout << "Yes";
		}
		else
			cout << "No";
		return 0;
	}
	int k = 0;
	for (int i = 0; i < v.size(); i++) {
		if (v[i] == v[0])
			k = i;
	}
	k++;
	int t = v[0] - k + 1;
	if (t <= 0) {
		cout << "No";
		return 0;
	}
	if (n - k >= 2 * t) {
		cout << "Yes";
	}
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 892
o = input()
e = input()

ans = []

if len(o) == len(e):
    for i in range(len(o)):
        ans.append(o[i])
        ans.append(e[i])

else:
    for i in range(len(e)):
        ans.append(o[i])
        ans.append(e[i])

    ans.append(o[len(o) - 1])

print(''.join(ans))


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        a: i64,
        b: i64,
    }

    let ans = if b % a == 0 { a + b } else { b - a };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#3つの数字をリストにする
data = input().split( )
#場合わけ
if (data[0] == data[1] or data[1] == data[2] or
   data[2] ==data[0]) and not data[1]== data[2]==data[0] :
    print("Yes")

else:
    print("No")

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

public class Main{
  public static void main(String[] args){
    try {
      Scanner sc = new Scanner(System.in);
      int n;
      n=Integer.parseInt(sc.next());

      if(n==111){
        System.out.println(999);
      }else if(n==119){
        System.out.println(991);
      }else if(n==191){
        System.out.println(919);
      }else if(n==199){
        System.out.println(911);
      }else if(n==911){
        System.out.println(199);
      }else if(n==919){
        System.out.println(191);
      }else if(n==991){
        System.out.println(119);
      }else if(n==999){
        System.out.println(111);
      }
      
      }catch (Exception e) {
      System.out.println("out");
    }
  }
}


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

std::vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}

int main(){
    sieve(1000000);
    int x;
    cin >> x;
    for(int i = x;i<1000000;i++){
        if(IsPrime[i]){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi acos(-1)
#define mod 1000000007
#define inf INT_MAX
#define scl(x) scanf("%lld",&x)
#define sc(x) scanf("%d",&x)
int main()
{

    //ios_base::sync_with_stdio(false);cin.tie(NULL);

    int i,j,k,n,t,ans=0,x,ct=0,ln,ok=0,m,y,sum=0,l,r,d;
    cin>>l>>r>>d;
    ans=(r/d)-((l-1)/d);
    cout<<ans<<endl;



}



Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<limits.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int IINF=INT32_MAX;
static const ll LINF=INT64_MAX;
static const ll mod=1e9+7;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};

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

int N,K;
string S;

int seq1[100005];
vector<int> v1;
int ans;

int main(){
    cin>>N>>K;
    cin>>S;
    int t=0;
    v1.push_back(0);
    for(int i=1;i<N;++i){
        if(S[i]=='1')if(S[i+1]=='0')v1.push_back(i);
    }
    for(int i=0;i<N;++i){
        if(S[i]=='1'){
            if(i==0)seq1[i]=1;
            else seq1[i]=seq1[i-1]+1;
        }
    }
    v1.push_back(N-1);
    for(int i=0;i<v1.size();++i){
        int a;
        if(S[v1[i]]=='0')a=1;
        else a=0;
        if(i+K>=v1.size())chmax(ans,v1[v1.size()-1]-v1[i]+seq1[v1[i]]+a);
        else chmax(ans,v1[i+K]-v1[i]+seq1[v1[i]]+a);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1148
// Problem : C - Folia
// Contest : AtCoder - NOMURA Programming Competition 2020
// URL : https://atcoder.jp/contests/nomura2020/tasks/nomura2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) { *s = __c; } *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) { x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; } return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) { qu[++ qr] = x % 10 + '0',  x /= 10; } while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

ll S[100005];
ll maxpos[100005];
const ll infty = 2000000000000000000;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; gi(n);
    rep(i, n+1) {
    	gi(S[i]);
    }
    if(S[0] > 1) { print(-1); return 0; }
    maxpos[0] = 1-S[0];
    // maxpos[i] = how many non-leaf nodes can there be on level i?
    rep1(i, n) {
    	if(maxpos[i-1] == infty) maxpos[i] = infty;
    	else maxpos[i] = (maxpos[i-1] << 1) - S[i];
    	maxpos[i] = min(maxpos[i], infty);
    	if(maxpos[i] < 0) { print(-1); return 0; }
    }
    ll cnc = 0, curlayerc = 0;
    for(int i=n; i>=0; i--) {
    	curlayerc += S[i];
    	cnc += curlayerc;
    	if(!i) break;
    	if(maxpos[i-1] < (curlayerc+1) / 2) { print(-1); return 0; }
    	curlayerc = min(curlayerc, maxpos[i-1]);
    }
    print(cnc);
}



Measured memory_bytes: 6096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A=0,B=0;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
  cin >> a.at(i);
  }
 for(int i=0;i<N;i++){
   int max = 0;
   int j   =0;
   for(int k=0;k<N;k++){
     if(max<a.at(k)){
       max=a.at(k);
       j = k;
     }
   }
   a.at(j) = 0;
   if(i%2 == 0){
   A += max;
   }
   else{
   B += max;
   }
  }  
  cout << A-B << endl;
  return 0; 
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N;cin>>N;
    int ans=0;
      if(N<2) ans = 1;
      else if(N<4) ans = 2;
      else if(N<8) ans = 4;
      else if(N<16) ans = 8;
      else if(N<32) ans = 16;
      else if(N<64) ans = 32;
      else ans = 64;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<int,int> P;
const ll MAX_N=131072;
const ll INF=1000000;
vector<int> G[1000010];
int main(){
  string S;cin>>S;
  int N=S.size();
  int n=N/2;
  int res=N;
  rep(i,n){
    if (S[i]!=S[i+1]){
      res=min(res,N-i-1);
    }
    if(S[N-1-i]!=S[N-2-i]){
      res=min(res,N-i-1);
    }
  }
  cout<<res<<endl;
}


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

int main(){
  int n,a[100001],l[100000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  l[0]=a[0];
  int length=1;
  for(int i=1;i<n;i++){
    if(l[length-1]<a[i]){
      l[length++]=a[i];
    }else {
      *lower_bound(l,l+length,a[i])=a[i];
    }
  }
  cout<<length<<endl;
  return 0;
}

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

int main() {
	string s;
	int k;
	cin >> s >> k;
	int n = s.size();
	set<string> sub;
	for (int i = 0; i < n; i++)
		for (int j = 1; j <= k && i + j - 1 < n; j++)
			sub.insert(s.substr(i, j));

	auto it = sub.begin();
	while (--k)
		it++;
	cout << *it << endl;
}


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

using namespace std;

string s;
int sum = 0,vic;
int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'p' && sum > 0){
            sum--;
            continue;
        }
        else if(s[i] == 'p'){
            vic--;
            sum++;
            continue;
        }
        if(s[i] == 'g' && sum > 0){
            sum--;
            vic++;
        }
        else if(s[i] == 'g')
            sum++;
        //cout << sum << " " << vic << "\n";
    }
    cout << vic << "\n";
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a>b && a>c){
        cout << a*10 +b +c << endl;
    }
    else if(b>a && b>c){
         cout << b*10 +a +c << endl;
    }
    else if(c>a && c>b){
         cout << c*10 +b +a << endl;
    }else{
         cout << a*10 +b +c << endl;
    }
    return 0;
}

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

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

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

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

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

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

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

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

use std::cmp::max;

fn main() {
    input!{
        n: usize,
        v: [[usize; 3]; n]
    }
    let mut tab: Vec<Vec<usize>> = vec![vec![0; 3]; n];
    tab[0][0] = v[0][0];
    tab[0][1] = v[0][1];
    tab[0][2] = v[0][2];
    for i in 1..n {
        tab[i][0] = max(tab[i - 1][1], tab[i - 1][2]) + v[i][0];
        tab[i][1] = max(tab[i - 1][0], tab[i - 1][2]) + v[i][1];
        tab[i][2] = max(tab[i - 1][0], tab[i - 1][1]) + v[i][2];
    }
    println!("{}", tab[n - 1].iter().max().unwrap());
}


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

int main() {
    long long a, b, k;
    cin >> a >> b >> k;
    long long ansa, ansb;
    if (a <= k) {
        ansa = 0;
        ansb = max(0ll, b - (k-a));
    } else {
        ansa = ansa = a - k;
        ansb = b;
    }
    cout << ansa << " " << ansb << endl;
    return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    string s;
    cin >> s;

    int year, month, day;
    year = stoi(s.substr(0, 4));
    month = stoi(s.substr(5, 2));
    day = stoi(s.substr(8, 2));
    if(year < 2019) cout << "Heisei" << endl;
    else if(year == 2019){
        if(month <= 4){
            cout << "Heisei" << endl;
        }
        else{
            cout << "TBD" << endl;
        }
    }
    else{
        cout << "TBD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
    int d;
    cin >> d;
    if(d==25){
        cout << "Christmas" << endl;
    }else if(d==24){
        cout << "Christmas Eve" << endl;
    }else if(d==23){
        cout << "Christmas Eve Eve" << endl;
    }else if(d==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
    return 0;
}

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

int main(){
  int n;
  cin >> n;
  string ans = "No";
  string N = to_string(n);
  rep(i,N.size())if(N[i] == '7')ans = "Yes";
  cout << ans << endl;
}


Measured memory_bytes: 3720