akhauriyash/Code-Regression huggingface dataset:
def insertion_sort(a, n):
    for i in range(0, n):

        value = a[i]
        j = i - 1
        while j >= 0 and a[j] > value:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = value

        # convert string to int.
        process_list = map(str, a)
        # join as string.
        print(" ".join(process_list))


num_length = int(input())
num_array = [int(x) for x in input().split()]

insertion_sort(num_array, num_length)

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


struct qaq{
	int v;int id;
} a[100005];

bool cmp(qaq x,qaq y){
	return x.v<y.v; 
}

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		a[i].id=i;
		a[i].v=x; 
	}	
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		cout<<a[i].id<<" ";
	}
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++)
    cin>>L.at(i);
  sort(L.begin(),L.end());
  int ans=0;
  for(int i=0;i<N-2;i++){
  for(int j=i+1;j<N-1;j++){
   int c=L.at(i)+L.at(j);
    auto itr=lower_bound(L.begin()+j+1,L.end(),c);
    int k=distance(L.begin()+j+1,itr);
    ans+=k;
  
  }
  
  }cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main(){
    let mut array = Vec::new();
    for _i in 0..3 {
        let a1: u32 = read();
        array.push(a1);
    }
    array.sort();
    let mut ans = 0;
    ans += array[1] - array[0];
    ans += array[2] - array[1];
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  int X, A;
  std::cin >> X >> A;
  if (X < A) {
    std::cout << 0 << '\n';
  } else {
    std::cout << 10 << '\n';
  }
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 256
#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <exception>

#include <fstream>

#include <functional>

#include <iomanip>

#include <ios>

#include <iosfwd>

#include <iostream>

#include <istream>

#include <iterator>

#include <limits>

#include <list>

#include <locale>

#include <map>

#include <memory>

#include <new>

#include <numeric>

#include <ostream>

#include <queue>

#include <set>

#include <sstream>

#include <stack>

#include <stdexcept>

#include <streambuf>

#include <string>

#include <typeinfo>

#include <utility>

#include <valarray>

#include <vector>



#if __cplusplus >= 201103L

#include <array>

#include <atomic>

#include <chrono>

#include <condition_variable>

#include <forward_list>

#include <future>

#include <initializer_list>

#include <mutex>

#include <random>

#include <ratio>

#include <regex>

#include <scoped_allocator>

#include <system_error>

#include <thread>

#include <tuple>

#include <typeindex>

#include <type_traits>

#include <unordered_map>

#include <unordered_set>

#endif
using namespace std;

int main(){
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	bool ans = true;
	for (int i = 0;i < s.size();i++) {
		if (s[i] == s[i + 1])ans = false;
	}
	if (ans)cout << "yes" << endl;
	else cout << "no" << endl;
}


Measured memory_bytes: 256
n = int(input())
A = [0] * (10**5+1)

B = list(map(int, input().split()))

for i in B:
    A[i] += 1

m = int(input())

sum_a = sum(B)

for _ in range(m):
    a, b = map(int, input().split())
    sum_a = sum_a + (b - a) * A[a]
    A[b] += A[a]
    A[a] = 0
    print(sum_a)

Measured memory_bytes: 84872
#####segfunc######
def segfunc(x,y):
    return x + y

def init(init_val,j):
    #set_val
    for i in range(n):
        seg[j][i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[j][i]=segfunc(seg[j][2*i+1],seg[j][2*i+2]) 
    
def update(k,x,j):
    k += num-1
    seg[j][k] = x
    while k:
        k = (k-1)//2
        seg[j][k] = segfunc(seg[j][k*2+1],seg[j][k*2+2])
    
def query(p,q,j):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[j][p])
        if q&1 == 1:
            res = segfunc(res,seg[j][q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[j][p])
    else:
        res = segfunc(segfunc(res,seg[j][p]),seg[j][q])
    return res


n = int(input())
s = list(input())
q = int(input())
al = []
l = [[0 for i in range(n)] for i in range(26)]
for i in range(n):
    l[ord(s[i])-97][i] = 1
seg = [[] for i in range(26)]
for i in range(26):
#####単位元######
    ide_ele = 0
#num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg[i]=[ide_ele]*2*num
    init(l[i],i)
for i in range(q):
    q1 = list(input().split())
    if q1[0] == "1":
        p = int(q1[1])
        r = ord(q1[2]) - 97
        for j in range(26):
            if l[j][p-1] == 1 and j != r:
                update(p-1,0,j)
            elif j == r:
                update(p-1,1,j)
            else:
                update(p-1,0,j)
    else:
        a = int(q1[1])
        b = int(q1[2])
        #print(a,b,seg)
        aa = 0
        for j in range(26):
            if query(a-1,b,j) > 0:
                aa += 1
        al.append(aa)
for i in al:
    print(i)

Measured memory_bytes: 443540
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (a < b) {
    rep(i, b)
      cout << a;
  } else {
    rep(i, a)
      cout << b;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,zero=0,mul=1,i,f=0;
    cin>>n;
    long long int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            zero++;
        }
    }
    if(zero>0)
    {
        cout<<0;
    }
    else
    {
        for(i=0;i<n;i++)
        {
            if(a[i]<=1000000000000000000/mul)
            {
                mul*=a[i];
            }
            else
            {
                f=1;
                break;
            }
        }
        if(f==0)
        {
            cout<<mul;
        }
        else
        {
            cout<<-1;
        }
    }
}

Measured memory_bytes: 4384
N = int(input())
ans = 0
n = N
counter = []
for i in range(2, int(N**0.5) + 2):
  if n % i == 0:
    counter.append(1)
    n = n // i
    while n % i == 0:
      counter[-1] += 1
      n = n // i
if n != 1:
  counter.append(1)
for c in counter:
  a = 1
  while c >= a:
    c -= a
    a += 1
    ans += 1
print(ans)

Measured memory_bytes: 9440
package main

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

const Mod = int(1e9) + 7

func main() {
	_, S := ReadInt(), ReadString()
	m := make(map[byte]int)
	chars := make([]byte, 0)
	for _, c := range []byte(S) {
		m[c]++
		if m[c] == 1 {
			chars = append(chars, c)
		}
	}
	ans := 1
	for _, char := range chars {
		ans = ans * (m[char] + 1) % Mod
	}
	ans--
	fmt.Println(ans % Mod)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
    ll A,B,C;
    cin >>  A >> B >> C;
    ll sum = 0;
    sum = A + B + C;
    ll submax = 0;
    submax = max(A,B);
    submax = max(submax,C);
    if(sum % 2 == 0){
        if(submax%2 == 0) cout << (submax*3 - sum)/2 <<endl;
        else {
            cout << ((submax+1)*3  - sum)/2 <<endl;
        }
    }
    else {
        if(submax%2 == 0) cout << ((1+submax)*3 - sum)/2 <<endl;
        else {
            cout << (submax*3  - sum)/2 <<endl;
        }
    }
}

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

int main() {
  int N,M;
  cin >>N ;
  vector<string> s(101),t(101);
  vector<int> moneyv(N);
  for(int i=0;i<N;i++){cin>>s.at(i);}
  cin>>M;
  for(int i=0;i<M;i++){cin>>t.at(i);}
  for(int i=0;i<N;i++){
    int money=0;
    for(int j=0;j<N;j++){
      if(s.at(i)==s.at(j)){money++;}
    }
      for(int k=0;k<M;k++){
        if(s.at(i)==t.at(k)){money--;}
      }
      if(money<0){money=0;}
      moneyv.at(i)=money;
    
  }
  int ans=0;
  for(int i=0;i<N;i++){
      bool flag=true;
    for(int j=0;j<N;j++){
      if(moneyv.at(i)<moneyv.at(j)){flag=false;}
    }
    if(flag){ans=moneyv.at(i);}
  }
  cout<<ans<<endl;
//  for (int i = 0; i < moneyv.size(); i++) {
//    cout << moneyv.at(i) << endl;
//  }
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
long long n,a,b,dp[N][2];
vector<int> v[N];
long long dfs(int x,int c,int l)
{
	if(dp[x][c])
		return dp[x][c];
	long long ans=1;
	for(int i=0;i<v[x].size();i++)
		if(v[x][i]!=l)
		{
			if(c)
				ans*=dfs(v[x][i],0,x),ans%=mod; 
			else
				ans*=(dfs(v[x][i],0,x)+dfs(v[x][i],1,x)),ans%=mod;
		}
	dp[x][c]=ans;
	return ans;
}
int main(){
	cin>>n;
	for(int i=1;i<n;i++)
	{
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);  
	}
	cout<<(dfs(1,0,-66666)+dfs(1,1,-66666))%mod;
	return 0;
}

Measured memory_bytes: 15616
#include <iostream>

int main(void)
{
	long long A, B;
	std::cin >> A >> B;

	long long result = 0;
	for(int i=0; i<=0; i++)
	{
    long long a4 = A % 4;
    long long b4 = B % 4;
    if( b4<a4 ) { b4+=4; }
    int lowestBit = 0;
    for(int i=a4; i<=b4; i++)
    {
      lowestBit ^= i & 1;
    }
    result += lowestBit;
	}

	for(int i=1; i<=50; i++)
	{
    long long an = A % (1LL << (i+1));
    long long bn = (B+1) % (1LL << (i+1)) ;
    if( (an&(1LL << i))==0) { an = (1LL << i); }
    if( (bn&(1LL << i))==0) { bn = (1LL << i); }
    if (bn < an) { bn += 1LL << (i + 1); }
    long long value = ((bn - an) % 2) << i;
    result += value;
	}

	std::cout << result;
}



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

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
    int n, t, cost = 10000, tm, a, b;
    cin >> n >> t;
    bool ans = false;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        if(b <= t && a < cost){
            ans = true;
            cost = a;
        } 
    }
    if (ans) cout << cost << endl;
    else cout << "TLE" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> c(n), v(n);
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    int ans = 0;
    rep(i,n){
        if(v[i] - c[i] > 0) ans += v[i] - c[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define V vector
#define SI size()
#define pb push_back
#define mk make_pair
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Test int test;cin>>test;while(test--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
using namespace std;
const int mod = 1e9+7;
int n,m,k;
int cou = 0;
string arr[7];
void check(int num,int num1){
    // cout<<num<<" "<<num1<<endl;
    set<int> r,c;
    while(num > 0){
        int t = num%10;
        r.insert(t-1);
        num /= 10;
    }
    while(num1 > 0){
        int t = num1%10;
        c.insert(t-1);
        num1 /= 10;
    }
    int p = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(!r.count(i) && !c.count(j)){
                if(arr[i][j] == '#'){
                    p++;
                }
            }
        }
    }
    if(p == k){
        cou++;
    }
}
void kuch(int num,int ind,int num1){
    if(ind == m+1){
        check(num1,num);
        return;
    }
    int num2 = num*10 + ind;
    kuch(num,ind+1,num1);
    kuch(num2,ind+1,num1);
}
void find(int num,int ind){
    if(ind == n+1){
        kuch(0,1,num);
        return;
    }
    int num1 = num*10 + ind;
    find(num,ind+1);
    find(num1,ind+1);
}
int main() {
    Fast
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    find(0,1);
    cout<<cou<<endl;
}


Measured memory_bytes: 3652
#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 EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(n), z(n);
    for(int i = 0; i < n; ++i)  cin >> x[i] >> y[i] >> z[i];

    ll ans = 0;
    for(int bit = 0; bit < 8; ++bit){
        vector<int> s(3);
        for(int i = 0; i < 3; ++i)  s[i] = ((bit >> i) & 1) ? 1 : -1;
        vector<pair<ll, int>> table;
        for(int i = 0; i < n; ++i){
            ll S = s[0] * x[i] + s[1] * y[i] + s[2] * z[i];
            table.emplace_back(S, i);
        }
        sort(table.rbegin(), table.rend());
        ll X = 0, Y = 0, Z = 0;
        for(int i = 0; i < m; ++i){
            int j = table[i].second;
            X += x[j], Y += y[j], Z += z[j];
        }
        chmax(ans, abs(s[0] * X) + abs(s[1] * Y) + abs(s[2] * Z));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#空のリストを作成する
t = []
x = []
y = []

flag = 0

N=int(input())#まずはNのターミナル入力
for j in range(N): #Nの分だけfor文回す
    a,b,c=[int(i) for i in input().split()] #int型でa,b,cそれぞれに空欄ごとの数字を代入
    t.append(a) #tのリストにaの要素を追加
    x.append(b)
    y.append(c)

if t[0] % 2 == (x[0] + y[0]) % 2 and t[0] >= (x[0] + y[0]):
    flag = 1

for j in range(N-1):
    if (t[j+1]-t[j])%2 == (abs(x[j+1] - x[j]) + abs(y[j+1] - y[j])) % 2 and t[j+1] - t[j] >= (abs(x[j+1] - x[j]) + abs(y[j+1] - y[j])):
        flag = 1
    else:
        flag = 0

if flag==1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 11792
card = [list(map(int, input().split())) for _ in range(3)]
# is_open = [[False, False, False]] * 3
n = int(input())
B = [int(input()) for _ in range(n)]

is_open = []
for b in B:
    for j in range(3):
        for i in range(3):
            if card[j][i] == b:
                is_open.append((i, j))

is_open_list = [True if (i, j) in is_open else False for i in range(3) for j in range(3)]

for i in range(3):
    if is_open_list[i] and is_open_list[i + 3] and is_open_list[i + 6]:
        print('Yes')
        exit()
    elif is_open_list[3 * i] and is_open_list[3 * i + 1] and is_open_list[3 * i + 2]:
        print('Yes')
        exit()

if is_open_list[0] and is_open_list[4] and is_open_list[8]:
    print('Yes')
    exit()
elif is_open_list[2] and is_open_list[4] and is_open_list[6]:
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int mod = 1e9+7;
int n,h[110],cnt,b[110];
ll f[110][110];
ll fp(ll a,ll k){
	ll ans=1;
	for(;k;k>>=1,a=a*a%mod)
		if(k&1) ans=a*ans%mod;
	return ans;
}
int main(){
	read(n);
	for(int i=1;i<=n;i++)
		read(h[i]),b[++cnt]=h[i];
	sort(b+1,b+cnt+1);
	cnt=unique(b+1,b+cnt+1)-b-1;
	for(int i=1;i<=n;i++)
		h[i]=lower_bound(b+1,b+cnt+1,h[i])-b;
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		f[i][0]=f[i-1][0]*2%mod;
		for(int j=h[i]+1;j<=h[i-1];j++) f[i][0]=(f[i][0]+f[i-1][j]*2)%mod;
		for(int j=1;j<=h[i];j++)
			if(h[i]>=h[i-1]) f[i][j]=f[i-1][j]*fp(2,b[h[i]]-b[h[i-1]])%mod;
			else f[i][j]=f[i-1][j];
		for(int j=h[i-1]+1;j<=h[i];j++)
			if(j>1) f[i][j]=f[i-1][0]*(fp(2,b[j]-b[j-1]+1)-2)%mod*fp(2,b[h[i]]-b[j])%mod;
			else f[i][j]=f[i-1][0]*(fp(2,b[j])-2)%mod*fp(2,b[h[i]]-b[j])%mod;
	}
	ll ans=0;
	for(int i=0;i<=h[n];i++)
		ans=(ans+f[n][i])%mod;
	cout<<(ans+mod)%mod<<'\n';
	return 0;
}


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

int n;
vector<int> spots;
vector<int> dist;

void input() {
	cin >> n;
	int x;
	cin >> x;
	spots.push_back(x);
	for (int i = 0; i < n; i++) {
		cin >> x;
		spots.push_back(x);
	}
	sort(spots.begin(), spots.end());
}

void makeDistance() {
	int d;
	for (int i = 0; i < n; i++) {
		d = spots.at(i + 1) - spots.at(i);
		dist.push_back(d);
	}
	sort(dist.begin(), dist.end());
}

bool dividableCheck(int div) {
	for (int i = 1; i < n; i++) {
		if (dist.at(i) % div != 0) return false;
	}
	return true;
}

int solver() {
	int min = dist.at(0);
	for (int div = 1; div < min; div++) {
		if (min % div != 0) continue;
		int minDiv = min / div;
		if(dividableCheck(minDiv)) return minDiv;
	}
	return 1;
}

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

	input();
	makeDistance();

	cout << solver() << "\n";
	return 0;
}

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

typedef long long ll;

int main(){
    
    set<ll>S;
    for(ll i = 0; i < 3; i++){
        ll x;
        cin >> x;
        S.insert(x);
    }
    cout << S.size() << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int func(char c) {
	switch(c) {
		case 'M':
			return 1000;
		case 'D':
			return 500;
		case 'C':
			return 100;
		case 'L':
			return 50;
		case 'X':
			return 10;
		case 'V':
			return 5;
		case 'I':
			return 1;
	}

	return 0;
}

int main() {
	char input[128];
	int ans;
	int i;

	while(scanf("%s", input) != EOF) {
		ans = 0;

		for(i = 0; input[i + 1]; i++) {
			if(func(input[i]) < func(input[i + 1])) {
				ans -= func(input[i]);
			}
			else
				ans += func(input[i]);
		}
		ans += func(input[i]);

		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

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

    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<ll>() );

    ll left = -1, right = 1e18;
    while(right - left > 1){
        ll mid = left + (right - left) / 2;
        ll k = 0;
        for(int i=0; i<N; i++){
            k += max(A[i] - mid / F[i], (ll)0);
        }
        if(k<=K) right = mid;
        else left = mid;
    }

    cout << right << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, K,InA;
  string stA;
  cin >> N;
  K = sqrt(N);
  bool gudge = true;
  
  while(gudge){
    if(N % K == 0){
      InA = N / K;
      gudge = false;
      }
  K--;
  }
  stA = to_string(InA);
  cout << stA.size() << endl;
}

Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int i,j;
  int n;
  while(cin>>n,n){
    int a[16][17];
    for(i=0;i<n;i++)
      for(j=0;j<n+1;j++)
	cin>>a[i][j];
    int b[1<<16];
    memset(b,-1,sizeof(b));
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > c;
    for(i=0;i<n;i++)
      c.push(make_pair(a[i][0],1<<i));
    for(;;){
      int p,q;
      p=c.top().first;
      q=c.top().second;
      if(q==(~((~0)<<n)))
	break;
      c.pop();
      if(b[q]){
	b[q]=0;
	for(i=0;i<n;i++){
	  if((q&(1<<i))==0&&b[q|(1<<i)]){
	    int mn=0;
	    for(j=0;j<n;j++){
	      if((q&(1<<j))&&a[i][mn]>a[i][j+1])
		mn=j+1;
	    }
	    c.push(make_pair(p+a[i][mn],q|(1<<i)));
	  }
	}
      }
    }
    cout<<c.top().first<<endl;    
  }
  return 0;
}

Measured memory_bytes: 2260
#include<iostream>
using namespace std;
int main(){
	int n,sum = 0;
	cin >> n;
	int d[n];
	for(int i=0;i<n;i++)
		cin >> d[i];
	
	for(int i=0;i<n;i++){
		for(int j=i;j<n-1;j++){
			sum += d[i]*d[j+1];
		}
	}
	cout << sum;
	return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = int(s.size());
    long long res = 0;

    for (int i = 0; i < (1 << (n - 1)); i++) {
        long long now = 0;

        for (int j = 0; j < n; j++) {
            now = now * 10 + (s[j] - '0');

            if (j < n - 1 && ((i >> j) & 1)) {
                res += now;
                now = 0;
            }
        }
        res += now;
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    int L[N];

    REP(i, N) cin >> L[i];

    sort(L, L+N, greater<>());

    int s = L[0];
    bool f = false;
    FOR(i, 1, N) {
        s -= L[i];
        if (s < 0) f = true;
    }

    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;

  vector<int> vec(N);

  double ans = 0;
 
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
    ans += (double)(1.0) / (double)vec.at(i);
  }
  
  cout << 1/ans << endl;
 
}


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

class Unionfind{
public:
  vector<int> par;
  vector<int> rak;

  Unionfind(int n): par(n), rak(n, 0){
    for(int i=0; i<n; ++i) par[i] = i;
  }

  int root(int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  bool same(int x, int y){
    return root(x) == root(y);
  }

  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(rak[x] < rak[y]) par[x] = y;
    else{
      par[y] = x;
      if(rak[x] == rak[y]) rak[x]++;
    }
  }
};

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  for(int i=0; i<n; ++i){
    cin >> p[i];
    p[i]--;
  }
  Unionfind pairs(n);
  int x, y;
  for(int i=0; i<m; ++i){
    cin >> x >> y;
    pairs.unite(x-1, y-1);
  }

  int ans=0;
  for(int i=0; i<n; ++i){
    if(pairs.same(p[i], i)) ans++;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll d = 0;
  cin >> d;
  vector<ll> c(26);
  //ll min = 0;
  //min = pow(10,18);
  //ll mini = 0;
  for(int i = 0;i < 26;i++){
    cin >> c[i];
    //if(min > c[i])min = c[i],mini = i;
  }
  vector<vector<ll>> s(d,vector<ll>(26));
  vector<ll> last(26);
  for(int i = 0;i < 26;i++)last[i] = -1;
  for(int i = 0;i < d;i++){
    ll now = 0;
    ll nowi = 0;
    for(int j = 0;j < 26;j++){
      cin >> s[i][j];
      s[i][j] += c[j] * (i - last[j]) * (d - i);
      if(now < s[i][j]){
        now = s[i][j];
        nowi = j;
      }
    }
    last[nowi] = i;
    cout << nowi + 1 << endl;
  }
  //for(int i = 0;i < 365;i++)cout << mini + 1 << endl;
}



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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        // Read input
        int n = Integer.parseInt(br.readLine());
        String[] split = br.readLine().split(" ");
        int[] stones = new int[n+1];
        for (int i = 0; i < n; i++) {
            stones[i+1] = Integer.parseInt(split[i]);
        }
        
        // Compute answer
        int[] dp = new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[1] = 0;
        
        for (int i = 1; i < dp.length-1; i++) {

            dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(stones[i] - stones[i+1]));
            
            if ((i+2) < dp.length)
                dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(stones[i] - stones[i+2]));

        }

        // Print answer
        System.out.println(dp[n]);
    }
}

Measured memory_bytes: 34904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, w;
	cin >> n >> w;
	vector<pair<ll,ll>> v;
	vector<vector<ll>> ans(2, vector<ll>(w + 1, 0));
	for(int i = 0;i < n; ++i){
		int wi, vi;
		cin >> wi >> vi;
		v.push_back(make_pair(wi, vi));
	}
	int prev = 1;
	for(auto&x: v){
		for(int j = 1;j < x.first; ++j)
			ans[!prev][j] = ans[prev][j];
		for(int j = x.first; j <= w; ++j)
			ans[!prev][j] = max(ans[prev][j], ans[prev][j - x.first] + x.second);
		prev ^= 1;
	}
	cout << ans[prev][w] << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N, A[100001] = {}, sum[100001] = {};
    cin >> N;
    REP(i, N + 1) cin >> A[i];
    sum[N] = A[N];
    RREP(i, N) sum[i] = A[i] + sum[i + 1];

    if (N == 0) {
        if (A[0] == 1) {
            cout << 1 << endl;
            return 0;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    if (A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 1, cur = 1;
    FOR(i, 1, N + 1) {
        cur = min(cur * 2, sum[i]);
        ans += cur;
        if (i != N && cur <= A[i]) {
            cout << -1 << endl;
            return 0;
        }
        if (i == N && cur != A[N]) {
            cout << -1 << endl;
            return 0;
        }
        cur -= A[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N, 0);

    int l=0, r=0, now=0;
    ll res = 0;

    //条件を満たす範囲は、そのビットごとの1の個数の総和が必ず1以下であるという
    //性質があるため、これを基に尺取り法を用いて答えをもとめる。
    while(r < N) {
        cin >> A[r];

        //現在までの値と次の入力値の論理積が0でないとき、次の範囲(右端を右にずらした範囲)は  
        //条件を満たせないため、左端の値を引いていく(排他的論理和なので和と差は同値))。
        while(now & A[r]) now ^= A[l++];

        //次の範囲が条件を満たせるようになったら、右端を右にずらす。
        now ^= A[r++];

        //lからr(+1)までの範囲が条件を満たすならば、l+1からr(+1)までの範囲も条件を満たす。
        res += r - l;
    }

    cout << res <<endl;
    return 0;
}

Measured memory_bytes: 1024
X, N = map(int, input().split())
P = list(map(int, input().split()))


diff = 10000
best = -1
for i in range(-100, 201):
    if i not in P:
        d = abs(X-i)
        if diff > d:
            best = i
            diff = d
            # print(i)
print(best)


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

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for(int i=0;i<n;i++){
		cin >> p.at(i);
	}
	int ans=1;
	int a=p.at(0);
	for(int i=1;i<n;i++){
		if(a>p.at(i)){
			a=p.at(i);
			ans =ans+1;
		}
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

int vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
    }
    else { // 発見できなかったとき
        return 0;
    }
}

int main() {
    int n; int k; cin >> n >> k;
    vector<int> d(k);
    rep(i, k) cin >> d[i];
//    sort(d.begin(), d.end());
//    vector<int> dd{0,1,2,3,4,5,6,7,9};
//
//    vector<int> allowed_num;
//    set_difference(dd.begin(), dd.end(), d.begin(), d.end(), back_inserter(allowed_num));

    while(true) {
        string tmp = to_string(n);
        bool flag = true;
        rep(i, tmp.size()) {
            if(vector_finder(d, tmp[i]-'0')) {
                flag = false;
                break;
            }
        }
        if(flag) {
            cout << n << endl;
            return 0;
        } else {
            n++;
        }
    }


}



Measured memory_bytes: 256
N = int(input())
A = []
A_ap = A.append
for i in range(N):
    A_ap(int(input()))
    
max_A = sorted(A)[-1]
max_2A = sorted(A)[-2]
for i in range(N):
    if A[i] != max_A:
        print(max_A)
    else:
        print(max_2A)

Measured memory_bytes: 68512
#include <iostream>

using namespace std;

int n;
int lowest = 200001;
int curr;
int ans = 0;

int main()
{
  	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);

  	cin >> n;
  
  	for (int i = 0; i < n; i++)
    {
      	cin >> curr;
      	if (curr <= lowest)
        {
          	lowest = curr;
          	ans++;
        }
    }
  
  	cout << ans;
  	
  	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

struct Segtree{
	int data[1<<19], base=1<<18;
	void add(int p, int v){
		for(p+=base-1; p; p/=2)
			data[p]+=v;
	}
	int getKth(int k){
		int now=1;
		while(now < base){
			if(data[now*2]>=k) now*=2;
			else{
				k -= data[now*2];
				now = now*2+1;
			}
		}
		return now-(base-1);
	}
} seg;

int a[200010];
vector<int> comp;
int O2N(int Org){ return lower_bound(comp.begin(), comp.end(), Org)-comp.begin()+1;}
int N2O(int New){ return comp[New-1]; }

int main(){
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%d", &a[i]), comp.push_back(a[i]);;
	sort(comp.begin(), comp.end());
	comp.resize(distance(comp.begin(), unique(comp.begin(), comp.end())));
	for(int i=1; i<=n; i++){
		a[i] = O2N(a[i]);
		seg.add(a[i], 1);
	}
	for(int i=1; i<=n; i++){
		seg.add(a[i], -1);
		int val = seg.getKth(n/2);
		printf("%d\n", N2O(val));
		seg.add(a[i], 1);
	}
	return 0;
}


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

int main() {
  int a, b;
  cin >> a >>b;
  if (b % a == 0){
    cout << a + b << endl;
  }
  else{
    cout << b - a << endl;
  }

}

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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> data(n-1);
    for(int i = 0; i < data.size(); ++i){
        cin >> data[i];
    }
    vector<int> ans(n, 0);
    for(int i = 0; i < ans.size(); ++i){
        ans[data[i]]++;
    }
    for(int i = 1; i < ans.size(); ++i){
        cout << ans[i] << endl;
    }
    cout << 0 << endl;

    return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
template<class num> inline void rd(num &x) {
	char c;
	while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar()))
		x = (x << 3) + (x << 1) + c - '0';
	if(neg) x = -x;
}
const int N = 212345;
const int mod = 1000*1000*1000+7;
ll fpow (ll b, ll e) {
	if (!e) return 1;
	ll r = fpow(b, e/2);
	r = (r*r) % mod;
	return e % 2 ? (r * b) % mod : r;
}
ll fat[N], inv[N], calc[N];
int v[N];
int main (void) {
	fat[0] = inv[0] = 1;
	for (int i = 1; i < N; i++) {
		fat[i] = fat[i-1] * i % mod;
		inv[i] = fpow(fat[i], mod-2);
	}
	int n;
	rd(n); 
	for (int i = 0; i < n; i++) rd(v[i]);
	for (int i = 2; i <= n; i++) 
		calc[i] = fat[n] * inv[i] % mod * fat[i-1] % mod;
	
	ll left = 0;
	ll right = 0;
	int sz = 1;
	for (int i = 1; i < n; i++) 
		right = (right + calc[++sz]) % mod;
	ll ans = 0;
	int sz2 = 1;
	ans = (ans + v[0] * (fat[n] + right)) % mod;
	for (int i = 1; i < n; i++) {
		right = (right - calc[sz--] + mod) % mod;
		left = (left + calc[++sz2]) % mod;
		ans = (ans + v[i] * (fat[n] + right + left)) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5248
/*

#      #      #####   ##   ##  #####      ##     #  #      #   #  #####
#      #      #   #  #  ###  # #          # ##   #  #      #   #  #   #
#      #      #   #  #   #   # #          #  ##  #  #      #   #  #   #
#      #      #   #   #     #  #####      #   #  #  #       ###   #####
#      #      #   #    #   #   #          #  ##  #  #        #    #   #
#      #      #   #     ###    #          # ##   #  #        #    #   #
#      #####  #####      #     #####      ##     #  #####    #    #   #

*/

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <llong> vl;
typedef vector <string> vs;
typedef vector <vector <llong>> matrix;

typedef pair <llong, llong> pll;

typedef map <llong, llong> mll;

typedef set <llong> sl;

const llong MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;};

llong n;
llong a[MXN];

mll cnt, used;

int main () {
    android;
    random_device rand;
    #ifdef I_LOVE_DILYA
        freopen ("input.txt", "r", stdin);
    #endif
    cin >> n;
    for (llong i = 1; i <= n; ++ i) {
        cin >> a[i];
        ++ cnt[a[i]];
    }
    llong sum = 0;
    for (llong i = 1; i <= n; ++ i) {
        if (!used[a[i]]) {
            sum += (cnt[a[i]] < a[i] ? cnt[a[i]] : cnt[a[i]] - a[i]);
            used[a[i]] = 1;
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 13056
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll two=0;
    int n;
    cin>>n;
    while(n--){
        int a;
        cin>>a;
        while(a%2==0)
            two++,a/=2;
    }
    cout<<two<<endl;
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin>>n;
  vector <ll> a(n);
  ll H=0,h=0;
  for (ll i=0;i<n;i++)
  {
    cin>>a[i];
    if (H>a[i])
    {
      h+=H-a[i];
    }
    H=max(H,a[i]);
  }
  cout<<h;
  return 0;
}

Measured memory_bytes: 4716
N,L = input().split()
N = int(N)
L = int(L)
tastes = []
abs_tastes = []
for i in range(N):
  tastes.append(L + i)
  abs_tastes.append(abs(L+i))
abs_min = min(abs_tastes)
if L>0:
  abs_min = abs_min
else:
  abs_min = - abs_min
print(sum(tastes)-abs_min)


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint a(n+1); rep(i,n+1) cin>>a[i];
    vint b(n+1,0);
    b.back() = a.back();
    repr(i,n){
        b[i] = a[i] + b[i+1];
    }

    if(n==0){
        if(a[0] == 1) cout<<1<<endl;
        else cout<<-1<<endl;
    }else{
        ll ans = 1;
        ll now = 1;
        repf(i,1,n+1){
            now = min(b[i], 2*(now-a[i-1]));
            if(now < a[i]){
                cout<<-1<<endl;
                return 0;
            }
            ans += now;
        }
        cout<<ans<<endl;
    }

    return 0;

}

Measured memory_bytes: 4748
from heapq import heappush, heappushpop

T = int(input())
ans = []
for _ in range(T):
    N = int(input())
    first = []
    last = []
    base = 0
    base_max = 0
    for _ in range(N):
        k, l, r = map(int, input().split())
        if k == N:
            r = l
        if l > r:
            first.append([k, l - r])
        elif r > l:
            last.append([N - k, r - l])
        base += min(l, r)
        base_max += max(l, r)
    first.sort()
    last.sort()

    pool = []
    for k, p in first:
        if len(pool) < k:
            heappush(pool, p)
        else:
            if pool and pool[0] < p:
                heappushpop(pool, p)
    base += sum(pool)
    pool = []
    for k, p in last:
        if len(pool) < k:
            heappush(pool, p)
        else:
            if pool and pool[0] < p:
                heappushpop(pool, p)
    base += sum(pool)
    ans.append(base)
    pass
print(*ans, sep="\n")



Measured memory_bytes: 106728
#include <bits/stdc++.h>
#include<iostream>
#include <math.h>//pow(x,y)=x^y
#include <algorithm>//sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define rep(i,n) for (int i=0; i <(n);i++)
#define ll long long
#define rev(s) reverse(s.begin(),s.end())
#define sor(v) sort(v.begin(),v.end())

using namespace std;


int main() {
int N;
cin >>N;
rep(i,11){
    if(N < i*1000){
        cout << i*1000-N <<endl;break;
    }else if(N == i*1000){
        cout << 0 << endl;break;
    }
}
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define N 100005
#define LL long long
using namespace std;
const int mo=1e9+7;
int n,m,x[N];
LL z[4][4],G[4][4],H[4][4],A[4][4],X[4][4],B[4][4],f[N];
void mult(LL u[4][4],LL v[4][4])
{
	int i,j,k;
	for(i=0;i<4;i++)
		for(j=0;j<4;j++){
			z[i][j]=0;
			for(k=0;k<4;k++)
				z[i][j]+=u[i][k]*v[k][j];
		  }
	for(i=0;i<4;i++)
		for(j=0;j<4;j++)
			u[i][j]=z[i][j]%mo;
}
void calc(int n)
{
	int i,j;
	for(i=0;i<4;i++)
		for(j=0;j<4;j++)
			H[i][j]=G[i][j],B[i][j]=(i==j);
	while(n){
		if(n&1) mult(B,H);
		n>>=1,mult(H,H);
	  }
}
int main()
{
	int i,j;
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++)
		scanf("%d",&x[i]);
	G[0][0]=G[0][1]=G[0][2]=G[0][3]=1;
	G[1][1]=G[1][3]=1;
	G[2][2]=G[2][3]=1;
	G[3][0]=G[3][1]=G[3][2]=1,G[3][3]=2;
	x[++m]=n;
	for(i=1;i<=m;i++){
		calc(x[i]);
		f[i]=B[0][3];
		calc(x[i]-x[i-1]);
		mult(A,B);
		f[i]=(f[i]-A[0][3]+mo)%mo;
		for(j=0;j<4;j++)
			A[j][j]=(A[j][j]+f[i])%mo;
	  }
	cout<<f[m];
	return 0;
}


Measured memory_bytes: 1408
N = int(input())
given_list = [int(i) for i in input().split()]

limit = 10**18
ans = 1

if 0 in given_list:
    print(0)
else:
    for i in given_list:
        ans *= i
        if ans > limit:
            print('-1')
            break
    if ans <= limit:
        print(ans)

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

int main()
{
    char s[101];
    cin >> s;
    int l=strlen(s);
    int count=0;
    for(int i=0; i<l/2; i++)
    {
        if(s[i]!=s[l-i-1])
            count++;
    }
    cout << count;
    return 0;
}

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

int main(){
  int N,sum2=0;
  cin >> N;
  vector<string> S(N);
  vector<int> T(N,0);
  for(int i=0;i<N;i++){
    cin >> S[i] >> T[i];
    sum2 += T[i];
  }
  int sum1=0;
  string X;
  cin >> X;
  for(int i=0;i<N;i++){
    sum1 += T[i];
    if(S[i]==X){
      cout << sum2 - sum1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            WriteLine(180 * (n - 2));
        }
        

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        //文字数を数える
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
}


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


int main(){
	string s;
	cin>>s;
	int ar[s.length()]={0};
	int ap[s.length()]={0};
	for(int i=0;i<s.length();i++){
		if(s[i]=='g') ar[i]=0;
		else ar[i]=-1;
		if(s[i]=='g') ap[i]=1;
		else ap[i]=0;
	}
	
	int rok=0,ppr=0,ans=0;
	for(int i=0;i<s.length();i++){
		if(rok==ppr) {
			ans+=ar[i];
			rok++;
		}
		else if(ar[i]==0&&ap[i]==0){
			rok++;
		}
		else{
			ans+=ap[i];
			ppr++;
		}
		
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1280
import scala.io.StdIn.readInt

object Main {

  def main(args: Array[String]) = {
      var n = 0
      var i = 1
      n = readInt
      while( n!= 0 ) {
        println("Case " + i + ": " + n)
        n = readInt
        i += 1
      }
  }
}

Measured memory_bytes: 50692
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef long long ll;

ll n;

int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	if (n < 2 || n & 1ll)
		cout << "0\n";
	else {
		ll mult = 2;
		ll num2 = 0;
		while (n / mult) {
			num2 += n / mult;
			mult *= 2ll;
		}
		ll num5 = 0;
		mult = 10;
		while (n / mult) {
			num5 += n / mult;
			mult *= 5;
		}
		cout << min(num5, num2) << "\n";
	}
	//system("pause");
	return 0;
}

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

#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<ll>
#define all(x) x.begin() , x.end()

using namespace std;
void OJ();

int x, y , z;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);// OJ();

    cin >> x >> y >> z;
    int mx = max( x , y );

    cout << z / mx + ( z%mx ? 1 : 0 );
    return  0;
}

void OJ(){
#ifndef ONLINE_JUDGE
       freopen( "inp.c"         , "r" , stdin  );
       //freopen( "OutPut.txt"   , "w" , stdout );
#endif // ONLINE_JUDGE
}
ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }


Measured memory_bytes: 256