akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>

#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
double start_moment = 0;
double get_runtime() { return 1.0*clock()/CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime(){cout<<fixed<<setprecision(5)<<get_runtime()<<'\n';}
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

int n;
vector<int> a;

int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
//    freopen("OUTPUT.txt", "w", stdout);
    
    cin>>n;
    read(a,n);
    int res=0;
    
    for(int i=0;i<a.size();i++)
        for(int j=i+1;j<a.size();j++)
            for(int k=j+1;k<a.size();k++)
            {
                vector<int> v={a[i],a[j],a[k]};
                sort(all(v));
                if(v[0]==v[1] || v[1]==v[2] || v[0]==v[2]) continue;
                if(v[0]+v[1]>v[2])
                    res++;
            }
    cout<<res;
    
    
    
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    lint s, t; int d;
    scanf("%lld%lld%d", &s, &t, &d);
    lint w[d+1];
    w[0] = 0;
    rep(i, d) scanf("%lld", &w[i+1]);
    partial_sum(w, w+d+1, w);
    rep(i, d+1)if(s+w[i] <= t){
        printf("%d\n", i);
        return 0;
    }
    if(w[d] >= 0){
        puts("-1");
        return 0;
    }

    lint ans = INF;
    rep(i, d){
        lint k = div_ceil(t-s-w[i], w[d]);
        chmin(ans, k*d + i);
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 3976
#include<bits/stdc++.h>
#define rint register int 
#define ll long long 
#define mk make_pair
using namespace std;
ll ans,N,X;
inline void Solve(ll a,ll b){
	if(b%a==0) {
		ans+=(2ll*b/a-1)*a;
		return ;
	}
	ll t=b/a;
	ans+=2ll*t*a;
	Solve(b%a,a);
}
int main(){
	cin>>N>>X;
	ans=N;
	Solve(min(X,N-X),max(X,N-X));
	cout<<ans;
	return 0;
} 

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

const int N = 1e5 + 5, mod = 1e9 + 7;
int n, k, u, v;
long long fact[N];
vector<int> adj[N];
long long solve(int v = 1, int p = 0, int val = k) {
  long long c = val;
  long long z = k - (p == 0 ? 1 : 2);
  for (int u : adj[v]) {
    if (u == p) continue;
    c *= solve(u, v, z);
    c %= mod;
    --z;
  }
  return c;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
//  freopen("in.txt", "r", stdin);
#endif  // ONLINE_JUDGE
  fact[0] = 1;
  for (int i = 1; i < N; ++i) fact[i] = (i * fact[i - 1]) % mod;
  cin >> n >> k;
  if (k == 1) {
    if (n == 1)
      cout << 1 << '\n';
    else
      cout << 0 << '\n';
    return 0;
  }
  for (int i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  cout << solve() % mod << '\n';
  return 0;
}


Measured memory_bytes: 12416
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

map<ll,ll> M;

int main(){
  ll N,C=0,X;
  cin >> N ;
  rep(i,N){
    cin >> X;
    M[X]++;
  }
  for(auto P : M){
    C++;
  }
  cout << C << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> D(N);
  for (int i = 0; i < N; i++) {
    cin >> D[i].first >> D[i].second;
  }

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

  long long ans = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    long long minv = min(M - cnt, D[i].second);
    cnt += minv;
    ans += minv * D[i].first;
    if (cnt == M) break;
  }

  cout << ans << endl;
}

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

len_o = len(o)
len_e = len(e)
ans = ''

if len_o == len_e:
  for i in range(len_o):
    ans += o[i]
    ans += e[i]
elif len_o > len_e:
  for i in range(len_e):
    ans += o[i]
    ans += e[i]
  for i in range(len_e, len_o):
    ans += o[i]
else:
  for i in range(len_o):
    ans += o[i]
    ans += e[i]
  for i in range(len_o, len_e):
    ans += e[i]
print(ans)
    

Measured memory_bytes: 9024
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <iostream>
#include <cstring>
#include <cstdio>


#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define f(n) for (ll i = 0; i < n; i++)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	int abc[26]{0};
	string s;
	cin >> s;
	f((ll)s.size()) abc[s[i] - 'A']++;
	ll x = 0;
	f(26) if (abc[i] == 2) x++;
	if (x == 2) cout << "Yes\n";
	else cout << "No\n";
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

int N[2005][2005];
int S[2005][2005];
int L[2005][2005];
int R[2005][2005];

class DLamp {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int H, W;
        cin >> H >> W;

        vector<string> s(H);
        REP(i, H) {
            cin >> s[i];
        }

        REP(j, W) N[0][j] = -1;
        REP(i, H) {
            REP(j, W) {
                N[i + 1][j] = N[i][j];
                if (s[i][j] == '#') {
                    N[i + 1][j] = i;
                }
            }
        }

        REP(j, W) S[H - 1][j] = H;
        REV(i, H - 1, 1) {
            REV(j, W - 1, 0) {
                S[i - 1][j] = S[i][j];
                if (s[i][j] == '#') {
                    S[i - 1][j] = i;
                }
            }
        }

        REP(i, H) L[i][0] = -1;
        REP(j, W) {
            REP(i, H) {
                L[i][j + 1] = L[i][j];
                if (s[i][j] == '#') {
                    L[i][j + 1] = j;
                }
            }
        }

        REP(i, H) R[i][W - 1] = W;
        REV(j, W - 1, 1) {
            REV(i, H - 1, 0) {
                R[i][j - 1] = R[i][j];
                if (s[i][j] == '#') {
                    R[i][j - 1] = j;
                }
            }
        }

        int res = -INF;
        REP(i, H) {
            REP(j, W) {
                if (s[i][j] == '#') continue;
                int tmp = (j - L[i][j]) + (R[i][j] - j) + (i - N[i][j]) + (S[i][j] - i);
                tmp -= 3;
                res = max(tmp, res);
            }
        }
        cout << res << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DLamp solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 130048
n=int(input())
H=list(map(int,input().split()))
cnt=0
cnts=[]
for i in range(len(H)-1):
    if H[i]>=H[i+1]:
        cnt+=1
    else:
        cnts.append(cnt)
        cnt=0
cnts.append(cnt)
#print(cnts)
print(max(cnts))


Measured memory_bytes: 20328
#include <iostream>
using namespace std;
int n, r, sma, res;
int main(void){
    // Your code here!
    cin >> n >> sma;
    for (int i = 1; i < n; i++) {
        cin >> r;
        if (i == 1) res = r - sma;
        else res = max(res, r - sma);
        sma = min(sma, r);
        }
    cout << res << endl;
}



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

using namespace std;
typedef long long int ll;
#define debug(val) "[ " << #val " : " << (val) << " ]\n"
#define space " "
#define space " "
#define vi vector<int>
#define PI atan(1)*4
#define pb push_back
#define ff first
#define ss second
#define PI atan(1)*4
const int INF = (int)2e9 ;

void solve() {
	int n , k ; 
	cin >> n >> k ;
	vi h(n), dp(n , INF) ; 
	for(int i=0;i<n;i++){
		cin >> h[i] ; 
	}

	dp[0] = 0 ; 
	for(int i=0;i<n;i++){
		for(int j=i+1 ; j<n && j <= i+k ; j++){
			dp[j] = min(dp[j] , dp[i] + abs(h[i] - h[j])) ; 
		}
	}
	cout <<  dp[n-1] << endl; 
   
}
int main() {
#ifdef _DEBUG // place in cmake-build-debug folder
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
        // cout << "Case #" << i << ": ";
        solve();
    }
}


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

inline void ioThings() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#define debug(x) cerr << #x << ": <" << (x) << ">\n"
#else
#define debug(x)
#endif
}

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp(x, y)  make_pair(x, y);
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second
#define mod       1000000007

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int main() {
  ioThings();

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

  vi c(n);
  vvi a(n, vi(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int mn = 1 << 30;
  queue<vi> q;
  q.push({});
  while (!q.empty()) {
    auto i = q.front();
    q.pop();

    if (sz(i) == n) {
      int cost = 0;
      vi skills(m);
      rep(r, n) {
        if (i[r]) {
          cost += c[r];
          rep(z, m) {
            skills[z] += a[r][z];
          }
        }
      }

      rep(z, m) {
        if (skills[z] < x) cost = 1 << 30;
      }

      mn = min(mn, cost);
    } else {
      i.pb(0);
      q.push(i);
      i.pop_back();
      i.pb(1);
      q.push(i);
    }
  }

  cout << (mn == 1 << 30 ? -1 : mn);

  return 0;
}


Measured memory_bytes: 3884
#import sys
#import math
#import numpy as np
'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
#n,l= map(int, input().split())
#x = [list(map(int, input().split())) for _ in range(n)] 
a,b,c=map(int,input().split())
li=[list(map(int,input().split())) for _ in range(a+1)]
ans=ju=0
for i in range(1,a+1):
  ans=0
  for j in range(b):
    ans+=li[0][j]*li[i][j]
  ans+=c
  if ans>0:
    ju+=1
print(ju)



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

long long x, k, d;

int main() {
	scanf("%lld%lld%lld", &x, &k, &d);
	x = abs(x);
	if (x / d >= k)
		printf("%lld\n", x - k * d);
	else
		printf("%lld\n", x / d & 1 ^ k & 1 ? (x / d + 1) * d - x : x % d);
	return 0;
}



Measured memory_bytes: 3824
#include <algorithm>
#include <iostream>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <fstream>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <stack>
#include <map>
#include <set>
#if __cplusplus > 199711L
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//	tree<key, mapped = null_type, cmp = less<key>, rb_tree_tag, tree_order_statistics_node_update> name;
//	order_of_key
//	find_by_order
#endif

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fs first
#define sc second
#define abs(a) ((a) < 0 ? -(a) : (a))
#define sqr(a) ((a) * (a))

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

const double eps = 1e-9;
const int mod = (int) 1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;

int a[maxn];

int main() {

	#ifdef SOL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	#else
	srand(time(0));
	const string file = "";
	if (!file.empty()) {
		freopen((file + ".in").c_str(), "r", stdin);
		freopen((file + ".out").c_str(), "w", stdout);
	}
	#endif

	int n, cnt = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if(a[i] < i) {
			if(a[a[i]] == i) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;

	#ifdef SOL
	fflush(stdout);
	fprintf(stderr, "%.3lf ms\n", 1000. * clock() / CLOCKS_PER_SEC);
	fflush(stderr);
	#endif
	return (0);
}

// by Andrey Kim


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

int d[100][100];

int main(){
  int n,m,s,g1,g2;
  int b1,b2,c;
  for(;;){
    cin >> n >> m >> s >> g1 >> g2;
    if(!n && !m && !s && !g1 && !g2)break;

    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	if(i==j)d[i][j] = 0;
	else d[i][j] = (1<<25);

    for(int i=0;i<m;i++){
      cin >> b1 >> b2 >> c;
      d[b1-1][b2-1] = c;
    }

    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
    /*
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)cout << d[i][j] << " ";
      cout << endl;
    }
    */
    int ans = (1<<25);
    for(int i=0;i<n;i++)ans = min(ans,d[s-1][i]+d[i][g1-1]+d[i][g2-1]);
    cout << ans << endl;
  }
}

Measured memory_bytes: 904
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main(void){

  int K;
  cin >> K;
  string S = "ACL";
  string St = "";
  for(int i=0; i<K; i++)
  {
    St += S;
  }
  cout << St << endl;
  return 0;
}


Measured memory_bytes: 3628
S = input()
K = int(input())

import re

def nchars(s, n):
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

if len(S)==1:
  print(K//2)
  
elif S[0]!=S[-1]:
  S_l = list(nchars(S,2))
  answer = 0
  for s in S_l:
    answer += len(s)//2
  print(answer*K)

else:
  if (S[0]!=S[1])&(S[-1]!=S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2

    answer = S_lr + (1+S_lr)*(K-1)
    print(answer)
  
  elif (S[0]!=S[1])&(S[-1]==S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[-1])
    answer = S_lr + ((a+1)//2 + (S_lr-a//2))*(K-1)
    print(answer)
  
  elif (S[0]==S[1])&(S[-1]!=S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[0])
    answer = S_lr + ((a+1)//2 + (S_lr-a//2))*(K-1)
    print(answer)
    
  else:
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    if len(S_l)==1:
      print(len(S)*K//2)
    else:
      for s in S_l:
        S_lr += len(s)//2

      a=len(S_l[0])
      b=len(S_l[-1])
      answer = S_lr + ((a+b)//2 + (S_lr-a//2-b//2))*(K-1)
      print(answer)

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll x;
  cin >> x;
  ll n = x/11;
  ll m = x%11;
  ll ans = 2*n+(m+5)/6;
  cout << ans << endl;
  return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  int ans = 0;
  for (int base = 1; base <= x; base++) {
    for (int p = 2; p <= x; p++) {
      int tmp = pow(base, p);
      // printf("b=%d, p=%d, tmp=%d\n", base, p, tmp);
      if (tmp <= x) {
        ans = max(ans, tmp);
      }
    }
  }
  if (x == 1) {
    cout << 1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
    unsigned long long n, a, b;
    cin >> n >> a >> b;
    if (a == 0) {
        cout << 0 << endl;
    }
    else if (b == 0) {
        cout << n << endl;
    }
    else if (n < a + b) {
        cout << (n <= a ? n : a) << endl;
    }
    else {
        unsigned long long divide = n / (a + b);
        unsigned long long mod = n % (a + b);
        cout << divide * a + (mod <= a ? mod : a) << endl;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class Z> V<Z> divisor(Z n) {
  V<Z> res;
  Z i;
  for (i = 1; i * i < n; ++i) if (n % i == 0) res.push_back(i), res.push_back(n / i);
  if (i * i == n) res.push_back(i);
  sort(rbegin(res), rend(res));
  return res;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b, k; cin >> a >> b >> k, --k;
  cout << divisor(__gcd(a, b))[k] << '\n';
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 62) - 1;

ll gcd(ll a, ll b)
{
    ll tmp;
    ll c;
    if (a < b)
    {
        tmp = a;
        a = b;
        b = tmp;
    }

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

    return a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

vector<P> factorization(ll n)
{
    vector<P> p;
    ll i;

    for (i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            if (p.empty())
            {
                p.push_back(P(i, 1));
            }

            if (p.empty() || p.back().first != i)
            {
                p.push_back(P(i, 1));
            }
            else
            {
                p.back().second++;
            }

            n /= i;
        }
    }

    if (n != 1)
    {
        p.push_back(P(n, 1));
    }

    return p;
}

int main(void)
{
    ll a, b;
    ll g;
    vector<P> p;

    cin >> a >> b;

    g = gcd(a, b);

    p = factorization(g);

    cout << p.size() + 1 << endl;
}

Measured memory_bytes: 256
// デバッグ実行：Ctrl+F5

using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        int N = int.Parse(line);
        var dict = new Dictionary<int, int>();
        int count = 0;
        for(int i = 2; i <= N; i++)
        {
            var list = Soinsu(i);
            foreach(int yakusu in list)
            {
                if (dict.ContainsKey(yakusu))
                {
                    dict[yakusu]++;
                }
                else
                {
                    dict[yakusu] = 1;
                }
            }
        }
        List<int> keys = new List<int>(dict.Keys);
        // 探索
        // 75 → 3 * 5 * 5より、
        // 約数2個以上と4個以上と4個以上の組み合わせ
        for(int i = 0; i < keys.Count; i++)
        {
            if (dict[keys[i]] >= 2)
            {
                for (int j = 0; j < keys.Count; j++)
                {
                    if (i != j && dict[keys[j]] >= 4)
                    {
                        for (int k = j + 1; k < keys.Count; k++)
                        {
                            if (i != k && dict[keys[k]] >= 4)
                            {
                                count++;
                            }
                        }
                    }
                }
            }
        }

        // 75 → 15 * 5より、
        // 約数14個以上と4個以上の組み合わせ
        for (int i = 0; i < keys.Count; i++)
        {
            if (dict[keys[i]] >= 4)
            {
                for(int j = 0; j < keys.Count; j++)
                {
                    if (i != j && dict[keys[j]] >= 14)
                    {
                        count++;
                    }
                }
            }
        }

        // 75 → 25 * 3より、
        // 約数24個以上と2個以上の組み合わせ
        for (int i = 0; i < keys.Count; i++)
        {
            if (dict[keys[i]] >= 2)
            {
                for (int j = 0; j < keys.Count; j++)
                {
                    if (i != j && dict[keys[j]] >= 24)
                    {
                        count++;
                    }
                }
            }
        }

        // 75より、
        // 約数74個以上の組み合わせ
        foreach (KeyValuePair<int,int> value in dict)
        {
            if (value.Value >= 74)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
    
    static IEnumerable<int> Soinsu(int N)
    {
        int i = 2;
        int now = N;
        while(i <= N)
        {
            if(now % i == 0)
            {
                now /= i;
                yield return i;
            }
            else
            {
                i++;
            }
        }
    }
}

Measured memory_bytes: 13276
#include<stdio.h>

int main(void){
  int n,i;
  int ans=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    ans=ans+b-a+1;
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N, M;
typedef pair<long, long> P;
vector<P> v[100001];
vector<long> pos(100001);

bool bfs(long u) {
  queue<P> que;
  que.push(P(0, u));
  pos.at(u) = 0;
  long mi = 0;
  long ma = 0;
  while(!que.empty()) {
    P pa = que.front(); que.pop();
    u = pa.second;
    for (auto e : v[pa.second]) {
      long v = e.first;
      long dis = e.second;
      if (pos.at(v) == LONG_MIN) {
        pos.at(v) = pos.at(u) + dis;
        mi = min(mi, pos.at(v));
        ma = max(ma, pos.at(v));
        que.push(P(pos.at(v), v));
      } else {
        if (pos.at(v) != pos.at(u) + dis) {
          return false;
        }
      }
    }
  }
  return (ma - mi <= 1000000000);
}

int main() {
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    v[l].emplace_back(r, d);
    v[r].emplace_back(l, d*(-1));
  }

  for (int i=1; i<=N; i++) {
    pos.at(i) = LONG_MIN;
  }

  for (int i=1; i<=N; i++) {
    if (pos.at(i) == LONG_MIN) {
      if (!bfs(i)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 14448
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <cstring>
using namespace std;
#define INF 1000000000
int main(){
	int w[10],k[10];
	for(int i = 0; i < 10; i++){
		scanf("%d",&w[i]);
	}
	for(int i = 0; i < 10; i++){
		scanf("%d",&k[i]);
	}
	sort(w,w+10);
	sort(k,k+10);
	printf("%d %d\n",w[7]+w[8]+w[9],k[7]+k[8]+k[9]);
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (((ll)1<<31)-1)
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0;
using namespace std;
int n;
double b[8];
int a[8];
int gcd(int x,int y){
	if(y==0)return x;
	return gcd(y,x%y);
}
signed main(){
	cin>>n;
	rep(i,n){
		rep(j,8){
			cin>>b[j];
			a[j]=b[j]*1000000;
		}
		int A=a[2]-a[0],B=a[3]-a[1],C=a[6]-a[4],D=a[7]-a[5];
		if(A*D==B*C)puts("YES");
		else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <algorithm>
#include <iomanip>
#include <cstring>

using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
int v[26];
int main()
{
    string s;
    cin >> s;
    int length = s.length();
    rep(i, length)
    {
        v[s[i] - 'A']++;
    }
    int counter = 0;
    int ok = 1;
    rep(i, 26)
    {
        if (v[i] != 2 && v[i] > 0)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<tr1/unordered_set>
#include<tr1/unordered_map>
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007
#define Pi 3.14159
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define IN(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printPI(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define PI pair<int,int>
#define PL pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<VI>
#define vvl vector<VL>
#define vvvi vector<VVI>
#define vvvl vector<VVL>
#define vpi vector<PI>
#define vpl vector<PL>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define dbg(x, y) cout << x << " = " << y << endl
using namespace std;


const int Ntest = 1e5 + 5;


ll gcd(ll a, ll b) {ll temp; while (b > 0) {temp = a % b; a = b; b = temp;} return a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll fpow(ll  b, ll exp, ll mod) {if (exp == 0) return 1; ll t = fpow(b, exp / 2, mod); if (exp & 1) return t * t % mod * b % mod; return t * t % mod;}
ll divmod(ll i, ll j, ll mod) {i %= mod, j %= mod; return i * fpow(j, mod - 2, mod) % mod;}

clock_t time_p = clock();
void TimeTaken()
{
	time_p = clock() - time_p;
	cerr << "Completion time : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}


void sol() {
	ll n, a, b, cnt;
	cin >> n;
	string str;
	cnt = 0;
	while (n > 0) {
		b = n % 26;
		a = n / 26;

		if (b == 0) {
			str += 'z';
			a--;
		} else {
			str += 'a' + b - 1;
		}
		cnt++;
		n = a;
	}
	reverse(all(str));
	cout << str << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	while (t--)
		sol();

	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  FORe(i, a, b){
    string s = to_string(i); 
    bool ok = true;
    REP(i, 3) if(s[i] != s[4-i]) ok = false;
    if(ok) ans++; 
  }
  cout << ans << endl;
  return 0;
}

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

int main ()
{
    int n;
    cin>>n;
    // vector<pair<string,pair<int,int>> rest(n);
    vector<tuple<string,int,int>> rest(n);
    vector<int> order(n);
    for (int i=0;i<n;i++)
    {
        cin>>get<0> (rest.at(i));
        cin>>get<1> (rest.at(i));
        get<1> (rest.at(i)) = -get<1> (rest.at(i));
        get<2> (rest.at(i)) = i;
    }

    sort(rest.begin(),rest.end());
    
    for (int i=0;i<n;i++)
    {
        cout<<get<2> (rest.at(i))+1<<endl;
    }

}

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

int main(){
    double n,m;
    cin >> n >> m;
    printf("%.8f\n",1/(1/n + 1/m));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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 main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    string s;cin>>s;
    ll cur = n;
    ll cnt = m;
    vector<ll> res;
    if (m==1) {
        rep(i,n) {
            if (s[i]=='1') {
                cout << -1 << endl;
                return 0;
            }
        }
        rep(i,n) {
            cout << 1 << ((i==n-1) ? "\n" : " ");
        }
        return 0;
    }
    while(cur>0) {
        if (cur<cnt) {
            cnt--;
            continue;
        }
        if (s[cur-cnt]=='0') {
            res.push_back(cnt);
            cur -= cnt;
            cnt = m;
        } 
        else {
            cnt--;
        }
        if (cnt==1) {
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(all(res));
    rep(i,res.size()) {
        cout << res[i] << ((i==res.size()-1) ? "\n" : " ");
    }
    return 0;
}


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

using namespace std;

const int N = 1e5 + 5;

long long n, w, a[N], b[N], dp[N], ans;

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

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

      for(int i = 1; i < N; i ++)
            dp[i] = 2e9;

      for(int i = 1; i <= n; i ++){
            for(int j = N - 1; j >= b[i]; j --){
                  dp[j] = min(dp[j], dp[j - b[i]] + a[i]);
            }
      }

      for(int i = 1; i < N; i ++){
            if(dp[i] <= w)
                  ans = i;
      }

      cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
 

int main() {
    string s;
    cin >> s;
    int n;
    n = s.length();
    string res = "Yes";
    for (int i = 0; i < int((n-1)/2); i++){
        if (s[i]!=s[(n-1)/2-1-i] || s[i]!=s[(n-1)/2-1+2+i] || s[i]!=s[n-1-i]){
            res = "No";
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int H[10000], W[10000], h, i, j,c=0;
	for (i = 0; i < 10000; i++){
		scanf("%d %d", &H[i], &W[i]);
		if (H[i] == 0){
			break;
		}
		c++;
	}
	for (h = 0; h < c; h++){
		for (i = 1; i <= H[h]; i++){
			for (j = 1; j <= W[h]; j++){
				if (i == 1 || i == H[h] || j == 1 || j == W[h]){
					printf("#");
				}
				else{
					printf(".");
				}
			}
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1756
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int m,int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(m,n / 2);
	x *= x;
	if (n % 2 == 1)x *= m;
	return x;
}
ll max(ll a, ll b) {
	if (a < b)return b;
	else return a;
}
struct edge { int to, cost; };

ll x(ll a) {
	if (a % 2 == 0) {
		ll s = a / 2;
		if (s % 2 == 0)return a;
		return a + 1;
	}
	else {
		ll s = (a+1)/ 2;
		return s % 2;
	}
}

int main() {
	int n;
	cin >> n;
	hei(int) a(n-1), b(n-1), c(n-1);
	rep(i, 0, n-1) {
		cin >> a[i] >> b[i] >> c[i];
		b[i] /= c[i];
	}
	rep(i, 0, n) {
		int ans = 0;
		rep(j, i, n - 1) {
			if (ans <= b[j] * c[j])ans = b[j] * c[j]+a[j];
			else {
				ans = ((ans + c[j] - 1) / c[j]) * c[j] + a[j];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

const int N = 1e5 + 10;
pair<int, int> a[N];

bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first + a.second < b.first + b.second;
}

int main() {
	int n;
  	cin >> n;
  	for (int i = 0; i < n; i++)
    	cin >> a[i].first >> a[i].second;
  	sort(a, a + n, cmp);
  	long long ans1 = 0, ans2 = 0;
  	for (int i = n - 1; i >= 0; i--) {
      	if (i % 2 == (n - 1) % 2)
          	ans1 += a[i].first;
     	else
          ans2 += a[i].second;
    }
  	cout << ans1 - ans2 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P  = pair<int, int>;
struct dat {
    int x, y;
    char c;
    dat() {}
    dat(int a, int b, char c) : x(a), y(b), c(c) {}
};
int main() {
    const int inf = 2e8;
    int n;
    int coll = inf;
    cin >> n;
    vector<dat> a(n);
    for (dat& i : a) cin >> i.x >> i.y >> i.c;
    for (int rot = 0; rot < 4; ++rot) {
        vector<vector<int>> udlist(2e5 + 1, vector<int>(0));
        vector<vector<int>> urlist(4e5 + 1, vector<int>(0));
        for (int i = 0; i < n; ++i) {
            if (rot < 2 && (a[i].c == 'U' || a[i].c == 'D'))
                udlist[a[i].x].push_back(i);
            if (a[i].c == 'U' || a[i].c == 'R')
                urlist[a[i].x + a[i].y].push_back(i);
        }
        if (rot < 2) {
            for (auto& v : udlist) {
                if (v.size() > 1) {
                    sort(v.begin(), v.end(), [&](int l, int r) {
                        return a[l].y < a[r].y;
                    });
                    for (int i = 0; i < v.size() - 1; ++i) {
                        if (a[v[i]].c == 'U' && a[v[i + 1]].c == 'D')
                            coll = min(coll, (a[v[i + 1]].y - a[v[i]].y) * 5);
                    }
                }
            }
        }

        for (auto& v : urlist) {
            if (v.size() > 1) {
                sort(v.begin(), v.end(), [&](int l, int r) {
                    return a[l].y < a[r].y;
                });
                for (int i = 0; i < v.size() - 1; ++i) {
                    if (a[v[i]].c == 'U' && a[v[i + 1]].c == 'R')
                        coll = min(coll, (a[v[i + 1]].y - a[v[i]].y) * 10);
                }
            }
        }
        if (rot < 3){
            for (dat& i : a) {
                int x = i.x, y = i.y;
                i.x = y;
                i.y = -x + 2e5;
                if (i.c == 'U')
                    i.c = 'R';
                else if (i.c == 'R')
                    i.c = 'D';
                else if (i.c == 'D')
                    i.c = 'L';
                else
                    i.c = 'U';
            }
        }
    }
    if (coll >= inf) cout << "SAFE" << endl;
    else
        cout << coll << endl;
}

Measured memory_bytes: 27580
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    def min2(x, y): return x if x <= y else y

    N = int(input())
    As = list(map(int, input().split()))

    if N == 0:
        if As[0] == 1:
            return 1
        else:
            return -1

    pow2 = 1
    pow2s = [pow2]
    for d in range(61):
        pow2 *= 2
        pow2s.append(pow2)
    pow2s += [pow2] * N
#    print('pow2s:', pow2s)

    maxV = min2(1, 1-As[0])
    maxVs = [maxV]
    for d in range(1, N+1):
        maxV = min2(maxV*2, pow2s[d]) - As[d]
        maxVs.append(maxV)
#    print('maxVs:', maxVs)

    numVs = [0] * (N+1)
    numVs[N] = As[N]
    for d in reversed(range(N)):
#        print('\n##### d:', d)
        numC2 = -(-numVs[d+1] // 2)
#        print('numC2:', numC2)
        if maxVs[d] < numC2:
            return -1
        num = min2(maxVs[d], numVs[d+1])
        numVs[d] = As[d] + num
#        print('As[d]:', As[d], '/ num:', num, '/ numVs[d]:', numVs[d])
        if numVs[d] > pow2s[d]:
            return -1

#    print('numVs:', numVs)
    return sum(numVs)


ans = solve()
print(ans)


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

using namespace std;

int k,n,a[200005],b[200005];

int main()
{
	cin>>k>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		b[i]=a[i]-a[i-1];
	}
	int ans=b[1]+k-a[n];
	for(int i=2;i<=n;++i)
		ans=max(ans,b[i]);
	cout<<k-ans;
	return 0;
}

Measured memory_bytes: 1792
// Last Change: 05/13/2019 19:23:24.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll X, Y, Z;
  cin >> X >> Y >> Z;

  cout << (X - Z) / (Y + Z) << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 384
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [0] * 45
for i in c:
    e = bin(i)
    e = e[2:]
    for j in range(len(e)):
        if e[-j-1] == "1":
            d[j] += 1
f = 0
for i in range(45-1, -1, -1):
    if d[i] * 2 < a:
        f += 2 ** i
        if f > b:
            f -= 2 ** i
g = 0
for i in c:
    g += f ^ i
print(g)


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

constexpr int MAX_N = 100;

struct Dice {
  int faces[6 + 1];
  Dice() : faces{0, 1, 2, 3, 4, 5, 6} {}
  void order(char cmd) {
    switch (cmd) {
      case 'E':swap(faces[1], faces[4]);
        swap(faces[4], faces[6]);
        swap(faces[6], faces[3]);
        break;
      case 'N':swap(faces[1], faces[2]);
        swap(faces[2], faces[6]);
        swap(faces[6], faces[5]);
        break;
      case 'S':swap(faces[1], faces[5]);
        swap(faces[5], faces[6]);
        swap(faces[6], faces[2]);
        break;
      case 'W':swap(faces[1], faces[3]);
        swap(faces[3], faces[6]);
        swap(faces[6], faces[4]);
        break;
      case 'L':swap(faces[2], faces[4]);
        swap(faces[4], faces[5]);
        swap(faces[5], faces[3]);
        break;
      case 'R':swap(faces[2], faces[3]);
        swap(faces[3], faces[5]);
        swap(faces[5], faces[4]);
        break;
    }
  }
};

enum Faces { Top = 1, Front = 2, Right = 3, Left = 4, Back = 5, Bottom = 6 };

int L[MAX_N][6 + 1];
Dice b;
int N, A, B;

bool dfs(Dice a, int cnt) {
  if (L[A][a.faces[Top]] == L[B][b.faces[Top]] &&
      L[A][a.faces[Front]] == L[B][b.faces[Front]] &&
      L[A][a.faces[Right]] == L[B][b.faces[Right]] &&
      L[A][a.faces[Left]] == L[B][b.faces[Left]] &&
      L[A][a.faces[Back]] == L[B][b.faces[Back]] &&
      L[A][a.faces[Bottom]] == L[B][b.faces[Bottom]]) {
    return true;
  }
  // 4回ころがせば正解があるはず
  if (cnt == 4)
    return false;

  ++cnt;
  a.order('E');
  if (dfs(a, cnt)) return true;
  a.order('W');

  a.order('W');
  if (dfs(a, cnt)) return true;
  a.order('E');

  a.order('S');
  if (dfs(a, cnt)) return true;
  a.order('N');

  a.order('N');
  if (dfs(a, cnt)) return true;
  a.order('S');

  return false;
}

int main() {
  cin >> N;
  for (int n{}; n < N; ++n) {
    for (int i{1}; i <= 6; ++i)
      cin >> L[n][i];
  }

  for (A = 0; A < N - 1; ++A) {
    for (B = A+1; B < N; ++B) {
      Dice a;
      if (dfs(a, 0)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define rept(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.bigin(),v.end()
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
int main(){
    ll x[5],a;
    rep(i,5){
        cin>>x[i];
        if(x[i]==0){
            a=i+1;
        }
    }
    cout<<a;

}



Measured memory_bytes: 3608
inData1 = input().split(' ')
inData2 = input().split(' ')
sMasu = int(inData1[0]) * int(inData1[1])

sMasu -= int(inData1[1]) * int(inData2[0])
sMasu -= (int(inData1[0]) - int(inData2[0])) * int(inData2[1])

print(sMasu)

Measured memory_bytes: 3060