criyle/codenet-compile-errors huggingface dataset:
Language: C++

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

constexpr int MN = 100005;
unsigned long long s = 0;
ll n, a[MN];
ll max_p[MN];

int main() {
  cin >> n;
  for (int i = 0; i <= n; ++i) {
    cin >> a[i];
    s += a[i];
  }
  if (a[0] > 0) {
    cout << -1 << endl;
    return 0;
  }

  max_p[0] = 1;
  for (int i = 1; i < n; ++i) {
    max_p[i] = min(s + 1, max_p[i - 1] * 2 - a[i]);
  }
  max_p[n] = 0;

  for (int i = n - 1; i >= 0; --i) {
    if (max_p[i] < 1 || max_p[i] * 2 < max_p[i + 1] + a[i + 1]) {
      cout << -1 << endl;
      return 0;
    }
    max_p[i] = min(max_p[i], max_p[i + 1] + a[i + 1]);
    s += max_p[i];
  }
  cout << s << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:19: error: no matching function for call to 'min(long long unsigned int, ll)'
   23 |     max_p[i] = min(s + 1, max_p[i - 1] * 2 - a[i]);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:23:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'll' {aka 'long long int'})
   23 |     max_p[i] = min(s + 1, max_p[i - 1] * 2 - a[i]);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:23:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   23 |     max_p[i] = min(s + 1, max_p[i - 1] * 2 - a[i]);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

// #include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;

    int A[N+1];
    for(int i(0);i<=N;++i) cin >> A[i];
    if(A[i]!=0){
        printf("-1");
        return 0;
    }

    // for (int i(0);i<=N;++i){
    //     if(A[i]<)
    // }
    

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:10: error: 'i' was not declared in this scope
   12 |     if(A[i]!=0){
      |          ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
long long ruijou(long long x, long long y){
    if(x>1000000000LL)return -1;
    if(x<0)return -1;
    if(y==0) return 1;
    else if(y%2==0) return ruijou(x*x,y/2);
    else return x*ruijou(x,y-1);
}





ll i,j,k;


int main(){
    ll N;
    cin>>N;
    V A(N+1);
    rep(i,N+1)cin>>A[i];
    if(A[N]==0){
        cout<<-1<<endl;
        return 0;
    }
    V nonhappa(N+1);
    V kakutei(N+1);
    kakutei[0]=1;
    V mininon(N+1);
    nonhappa.at(0)=1-A[0];
    mininon.at(N)=0;
    if(N==0){
        if(A[0]!=1)cout<<-1<<endl;
        else cout<<1<<endl;
        return 0;
    }
    if(nonhappa[0]<0){
        cout<<-1<<endl;
        return 0;
    }
    for(ll k=0;k<N;k++){
        if(2*nonhappa.at(k)<A[k+1]){
            cout<<-1<<endl;
            return 0;
        }
        else{
            nonhappa.at(k+1)=nonhappa.at(k)*2-A[k+1];
        }

    }
    for(ll k=N;k>0;k--){
        mininon.at(k-1)=(mininon.at(k)+A[k])/2;

    }
    nonhappa.at(N)=0;
    for(ll k=N;k>0;k--){
        nonhappa.at(k-1)=min(nonhappa.at(k-1),nonhappa.at(k)+A[k]);
    }
    ll ans=0;
    for(ll k=1;k<=N;k++){
        
        else{
            ans+=min(nonhappa.at(k),2*kakutei[k-1])+A[k];
            kakutei[k]=min(nonhappa.at(k),2*kakutei[k-1]);
        }
    }
    cout<<ans+1<<endl;
    
    
    

    

}

Compiler output:
a.cc: In function 'int main()':
a.cc:69:9: error: 'else' without a previous 'if'
   69 |         else{
      |         ^~~~
Language: C++

// #include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;

    int A[N+1];
    for(int i(0);i<=N;;++i) cin >> A[i];
    if(A[i]!=0){
        printf("-1");
        return 0;
    }

    // for (int i(0);i<=N;;++i){
    //     if(A[i]<)
    // }
    

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:23: error: expected primary-expression before ';' token
   11 |     for(int i(0);i<=N;;++i) cin >> A[i];
      |                       ^
a.cc:11:23: error: expected ')' before ';' token
   11 |     for(int i(0);i<=N;;++i) cin >> A[i];
      |        ~              ^
      |                       )
a.cc:11:26: error: 'i' was not declared in this scope
   11 |     for(int i(0);i<=N;;++i) cin >> A[i];
      |                          ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int c = 1;
  int d = 0;
  int e = 0;
  int f = 0;
  cin >> a;

  vector<int> b(a + 1);
 
  // a個の入力を受け取る
  for (int i = 0; i < a + 1; i++) {
    cin >> b.at(i);
  }
  
  for (int i = 0; i < a + 1; i++) {
    for (int j = 0; j < i + 1; j++) {
      c = c * 2;
    }
    if (b.at(i) > c) {
      cout << -1 << endl;
      return 0;
    }
    if (d <= b.at(i)) {
      d = b.at(i);
      e = i;
    }
    c = 1
  }
  
  for (int i = 0; i < e; i++) {
    f = f + 2 * i;
  }
  cout << f + d << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:10: error: expected ';' before '}' token
   31 |     c = 1
      |          ^
      |          ;
   32 |   }
      |   ~
Language: C++

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

int N;
int A[100000+10];

int dfs(int cur,int pre,int have){
    cout<<have<<endl;
    int add = 2*pre;
    if(cur == 0) add = 1;
    have += add;
    add -= A[cur];
    if(add <= 0) return -1;
    if(cur == N) return have;
    return dfs(cur+1,add,have);
}

int main(){
    cin>>N;
    long long ans = 0;

    for(int i=0; i<N+1; i++) cin>>A[i];
    int ans = dfs(0,0,0);

    cout<<ans<<endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:9: error: conflicting declaration 'int ans'
   23 |     int ans = dfs(0,0,0);
      |         ^~~
a.cc:20:15: note: previous declaration as 'long long int ans'
   20 |     long long ans = 0;
      |               ^~~
Language: C++

#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<intrin.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
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++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	V<ll> leaf(n + 1), notleaf(n + 1);
	bool ok = true;
	rep(i, n + 1) {
		int a;
		cin >> a;
		leaf[i] = a;
		if (i == 0)notleaf[i] = 1;
		else {
			notleaf[i] = notleaf[i - 1] * 2 - a;
			notleaf[i] = min(notleaf[i], LINF);
		}
		if (i == 0 && a > 0)ok = false;
		if (i < n && notleaf[i] <= 0)ok = false;
		if (i == n && notleaf[i] < 0)ok = false;
	}
	if (!ok) {
		cout << -1 << endl;
		return 0;
	}

	V<ll> v(n + 1);

	rep(i, n + 1) {
		if (i == 0)v[n - i] = leaf[n - i];
		else v[n - i] = v[n - i + 1] + leaf[n - i];
		v[n - i] = min(v[n - i], notleaf[n - i] + leaf[n - i]);
	}
	
	ll sum = 0;
	for (int x : v)sum += x;
	cout << sum << endl;

}

Compiler output:
a.cc:7:9: fatal error: intrin.h: No such file or directory
    7 | #include<intrin.h>
      |         ^~~~~~~~~~
compilation terminated.
Language: Java

import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt() + 1;
		long[] A = new long[N];
		long ans = 1;
		long[] tyoten = new long[N];
		for(int i = 0;i < N;i++){
			A[i] = sc.nextLong();
		}
		tyoten[0] = 1;
		if(A[0] > 0){
			tyoten[0]--;
		}
		if(N == 1 && A[0] != 1){
			ans = -1;
		}
		for(int i = 1;i < N;i++){
			tyoten[i] = tyoten[i-1]*2;
			ans += tyoten[i];
			tyoten[i] -= A[i];
			if(tyoten[i] < 0){
				ans = -1;
				break;
			}
		}
		if(ans != -1 && /*N > 1*/){
			long[] tyo = new long[N];
			ans -= tyoten[N-1];
			if(A[N-1] < tyoten[N-2]){
				tyo[N-2] = A[N-1];
			}else{
				tyo[N-2] = tyoten[N-2];
			}
			for(int i = N - 2;i > 0;i--){
				ans -= tyoten[i];
				ans += tyo[i];
				if(A[i] + tyo[i] < tyoten[i-1]){
					tyo[i-1] = A[i] + tyo[i];
				}else{
					tyo[i-1] = tyoten[i-1];
				}
			}
		}
		System.out.println(ans);
	}
}


Compiler output:
Main.java:28: error: illegal start of expression
		if(ans != -1 && /*N > 1*/){
		                         ^
1 error
Language: C++

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

int main() {
  long long a=1,b=0,c=0,d=0,m=0,n=0,p=0,q=0;
  
  cin >> n;
  vector<long long> v(n+1,0),ok(n+1,0);
  for(long long i=0;i<n+1;i++)
  {
	  cin >> v.at(i);
	  ok.at(i)=a;
	  a -= v.at(i);
	  a *= 2;
    if(a<0)
    {
      cout << -1;
      return;
    }
  }
  a=0;
  for(long long i=n;i>=0;i--)
  {
	 a+=v.at(i);
     while(ok.at(i)<a)
	 {
		 if(a-v.at(i)<=0)
		 {
			 cout << -1;
			 return 0;
		 }
		 a--;
	 }		 
    b+=a;
  }
  cout << b;
	  
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:7: error: return-statement with no value, in function returning 'int' [-fpermissive]
   18 |       return;
      |       ^~~~~~
Language: C++

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  long long N;
  vector <long long> V(N);
  for(long long i=0;i<N+1;i++){
    cin>>V.at(i);
  }
  int jud=0;
  long long cnt=0;
  long long a=1;
  for(long long i=0; i<N;i++){
    a-=V.at(i);
    a*=2;
    if(a<V.at(i+1)){
      jud++;break;
    }
    else if(a=v.at(i+1)){
      if(i==N-1){
        jud++;break;
      }
    }
    
  }
  if(jud==1){cout<<"-1"<<endl;}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:15: error: 'v' was not declared in this scope
   19 |     else if(a=v.at(i+1)){
      |               ^
Language: C++

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  long long N;
  vector <long long> V(N);
  for(long long i=0;i<N+1;i++){
    cin>>V.at(i);
  }
  int jud=0
  long long cnt=0;
  long long a=1;
  for(long long i=0; i<N;i++){
    a-=V.at(i);
    a*=2;
    if(a<V.at(i+1)){
      jud++;break;
    }
    else if(a=v.at(i+1)){
      if(i==N-1){
        jud++;break;
      }
    }
    
  }
  if(jud==1){cout<<"-1"<<endl;}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:3: error: expected ',' or ';' before 'long'
   11 |   long long cnt=0;
      |   ^~~~
a.cc:19:15: error: 'v' was not declared in this scope
   19 |     else if(a=v.at(i+1)){
      |               ^
Language: C++

#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

  int n;
  cin >> n;
  vector<ll> as(n + 1);
  for (auto & a : as ) cin >> a;
  vector<ll> b(n + 1, 0);
  b[n] = as[n];
  for (int i = n - 1; i >= 0; --i ) {
    b[i] = min<ll>(pow(2, i), b[i + 1] + as[i]);
    // cout << i << "," << counter << "," << total << endl;
  }

  vector<ll> c(n + 1, 0);
  c[0] = 1;
  for (int d = 0; d < n; ++d) {
    c[d + 1] = min<ll>(pow(2, i), 2 * (c[d] - as[d]));
  }

  ll total = 0;
  for (int i = 0; i < n + 1 ; ++i) {    
    if (min(c[i], b[i]) <= 0 ) {
      cout << -1 << endl;
      return 0;
    }
    // cout << min(c[i], b[i]) << endl;
    total += min(c[i], b[i]);
  }
  cout << total << endl;
  return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:31: error: 'i' was not declared in this scope
   33 |     c[d + 1] = min<ll>(pow(2, i), 2 * (c[d] - as[d]));
      |                               ^
Language: Java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;

public class E {

	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] input;
		int n = Integer.parseInt(reader.readLine());
		long[] arr = new long[n + 1];
		input = reader.readLine().split(" ");
		for(int i = 0; i <= n; i++) {
			arr[i] = Integer.parseInt(input[i]);
		}
		if(n > 0 && (arr[0] != 0 || arr[n] == 0)) {
			System.out.println(-1);
			return;
		}
		long[][] up = new long[n + 1][2];
		up[0][0] = 1;
		for(int i = 1; i <= n; i++) {
			up[i][0] = ((up[i - 1][0]) * 2) - arr[i];
			if(up[i - 1][0] > Math.pow(10, 17)) {
				up[i][0] = (long)Math.pow(10, 16);
			}
			if(up[i][0] < 0) {
				System.out.println(-1);
				return;
			}
//			System.out.println(up[i][0] + " ");
		}
		up[n][1] = 0;
		for(int i = n - 1; i >= 0; i--) {
			up[i][1] = arr[i + 1] + up[i + 1][1];
		}
		long ans = 0;
		long[] temp = new long[n + 1];
		for(int i = 0; i <= n; i++) {
			ans += Math.min(up[i][0], up[i][1]) + arr[i];
			temp[i] = Math.min(up[i][0], up[i][1]);
			if(temp[i] < 0) {
				System.out.println(-1);
				return;
			}
		}
		out.print(ans);
		out.flush();
	}

}


Compiler output:
Main.java:7: error: class E is public, should be declared in a file named E.java
public class E {
       ^
1 error
Language: C++

> a(n + 1);
    rep(i, n + 1) cin >> a[i];
    vector<ll> node(n + 1);
    ll ans = 1;
    vector<ll> lef(n + 1);
    lef[n] = a[n];
    if(a[0] == 1 && n != 0) cout << -1 << endl;
    else if(n == 0 && a[0] == 1) cout << 1 << endl;
    else {
        node[0] = 1;
        for(int i = 1; i <= n; i++) {
            node[i] = 2 * node[i - 1] - a[i];
        }
        for(int i = n; i >= 1; i--) {
            if(lef[i] > node[i - 1] * 2) ans = -1;
            else {
                lef[i - 1] = min(lef[i] + a[i - 1], min(node[i - 2] * 2,node[i - 1] + a[i]));
                ans += lef[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Compiler output:
a.cc:1:1: error: expected unqualified-id before '>' token
    1 | > a(n + 1);
      | ^
a.cc:2:8: error: expected constructor, destructor, or type conversion before '(' token
    2 |     rep(i, n + 1) cin >> a[i];
      |        ^
a.cc:3:5: error: 'vector' does not name a type
    3 |     vector<ll> node(n + 1);
      |     ^~~~~~
a.cc:4:5: error: 'll' does not name a type
    4 |     ll ans = 1;
      |     ^~
a.cc:5:5: error: 'vector' does not name a type
    5 |     vector<ll> lef(n + 1);
      |     ^~~~~~
a.cc:6:5: error: 'lef' does not name a type
    6 |     lef[n] = a[n];
      |     ^~~
a.cc:7:5: error: expected unqualified-id before 'if'
    7 |     if(a[0] == 1 && n != 0) cout << -1 << endl;
      |     ^~
a.cc:8:5: error: expected unqualified-id before 'else'
    8 |     else if(n == 0 && a[0] == 1) cout << 1 << endl;
      |     ^~~~
a.cc:9:5: error: expected unqualified-id before 'else'
    9 |     else {
      |     ^~~~
a.cc:23:5: error: expected unqualified-id before 'return'
   23 |     return 0;
      |     ^~~~~~
a.cc:24:1: error: expected declaration before '}' token
   24 | }
      | ^
Language: C++

#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列
#define CO(a, b, c) ((a) ? (b) : (c))
#define rep(i, n) for (long long int i = 0; i < (n); ++i)

using namespace std;
// typedef(long long long long int) long long int;

long long int main(void)
{

    long long int n;
    cin >> n;
    vector<long long int> a(n + 1);
    for (auto &&i : a)
    {
        cin >> i;
    }

    vector<long long int> work(n + 1), res(n + 1);
    for (long long int i = 0; i < n + 1; i++)
    {
        work[i] = (long long int)pow(2, i);
    }

    long long int count = 0;
    res.back() = a.back();
    for (long long int i = n - 1; i >= 0; --i)
    {
        long long int temp = res[i + 1] + a[i];
        if (temp <= work[i])
        {
            res[i] = temp;
        }
        else if (work[i] >= (ceil((double)(res[i + 1]) / 2.0) + a[i]))
        {
            res[i] = work[i];
        }
        else
        {
            cout << i << ":" << (ceil((double)(res[i + 1]) / 2.0) + a[i]);
            cout << "-1" << endl;
        }
    }
    cout << accumulate(res.begin(), res.end(), 0) << endl;

    return 0;
}

Compiler output:
a.cc:26:11: error: '::main' must return 'int'
   26 | long long int main(void)
      |           ^~~
Language: C++

#include <bits/stdc++.h> 
using namespace std;
int main() {
  int N, z;
  cin >> N;
  vector<int> A(N+1);
  for(int i=0;i<N+1;i++) {
    cin >> A.at(i);
  }
  int x=1;
  for(int i=0;i<N;i++) {
    x*=2;
  }
  for(int i=N;i>=0;i++) {
    if(A.at(i)>x||((A.at(i+1)+1/2+A.at(i)>x&&i!=N)) {
      cout << -1 << endl;
      break;
    }
    if(i==N) {
      z = A.at(i);
    }
    if(i!=0||i!=N) {
      z+=(A.at(i+1)+1)/2;
    }
    if(i==0) {
      z++;
      cout << z << endl;
    }
    x/=2;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:52: error: expected ';' before '{' token
   15 |     if(A.at(i)>x||((A.at(i+1)+1/2+A.at(i)>x&&i!=N)) {
      |                                                    ^~
      |                                                    ;
a.cc:19:5: error: expected primary-expression before 'if'
   19 |     if(i==N) {
      |     ^~
a.cc:18:6: error: expected ')' before 'if'
   18 |     }
      |      ^
      |      )
   19 |     if(i==N) {
      |     ~~
a.cc:15:7: note: to match this '('
   15 |     if(A.at(i)>x||((A.at(i+1)+1/2+A.at(i)>x&&i!=N)) {
      |       ^
Language: C++

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll nax = 1e18;
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, cur = 1, ans = 1, temp;
    cin>>n;
    ll a[n + 1];
    for(int i = 0; i <= n; i++) {
    	cin>>a[i];
    }
    for(int i = 0; i < n; i++) {
    	if(cur <= a[i]) {
    		cout<<"-1\n";
    		return 0;
    	}
    	cur = cur - a[i];
    	temp = cur;
    	// cur = min(cur * 2, (ll)nax);
    	cur = cur * 2
    	ans = ans + cur;

    }
    ans = ans - cur + a[n];
    if(a[n] < temp) {
    	ll extra = temp - a[n];
    	for(int i = n - 1; i >= 0; i--) {
    		ans = ans - extra;
    		extra = extra - a[i] - a[i + 1];
    		if(extra < 0) {
    			break;
    		}
    		extra = extra / 2;
    	}
    }
    cout<<ans<<"\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:22: error: expected ';' before 'ans'
   38 |         cur = cur * 2
      |                      ^
      |                      ;
   39 |         ans = ans + cur;
      |         ~~~
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

void solve(){
  int n; cin >> n;
  vector<ll> a(n + 1), d(n + 1);
  for(int i = 0; i <= n; i++){
    cin >> a[i];
  }
  d[n] = a[n];
  for(int i = n - 1; i >= 0; i--){
    d[i] = d[i + 1] + a[i];
  }
  /*for(int i = 0; i <= n; i++){
    cout << d[i] << endl;
  }*/
  unsigned long long ans = 0
  ll x = 1;
  bool ok = true;
  for(int i = 0; i <= n; i++){
    if(a[i] > x || x <= 0){
      ok = false;
      break;
    }
    if(a[i] == x && i != n){
      ok = false;
      break;
    }
    //cout << x << " : " << y << endl;
    ans += min(x, d[i]);
    x = (x - a[i]) * 2;
  }
  if(!ok) cout << -1 << endl;
  else cout << ans << endl;
  return;
}

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


Compiler output:
a.cc: In function 'void solve()':
a.cc:25:3: error: expected ',' or ';' before 'll'
   25 |   ll x = 1;
      |   ^~
a.cc:28:15: error: 'x' was not declared in this scope
   28 |     if(a[i] > x || x <= 0){
      |               ^
a.cc:32:16: error: 'x' was not declared in this scope
   32 |     if(a[i] == x && i != n){
      |                ^
a.cc:37:16: error: 'x' was not declared in this scope
   37 |     ans += min(x, d[i]);
      |                ^
Language: C++

#include <bits/stdc++.h> 
using namespace std;
int main() {
  int N, z;
  cin >> N;
  vector<int> A(N+1);
  for(int i=0;i<N+1;i++) {
    cin >> A.at(i);
  }
  int x=1;
  for(int i=0;i<N;i++) {
    x*=2;
  }
  for(int i=N;i>=0;i++) {
    if(A.at(i)>x) {
      cout << -1 << endl;
      break;
    }
    if(i==N) {
      z=A.at(i);
    }
    if(i!=0||i!=N) {
      z+=(A.at(i+1)+1)/2;
    }
    if(i==0) {
      z++;
      cout << z << endl;
    }
    x/=2
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:9: error: expected ';' before '}' token
   29 |     x/=2
      |         ^
      |         ;
   30 |   }
      |   ~
Language: C++

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
   　cout << -1 << endl;
}

Compiler output:
a.cc:18:4: error: extended character 　 is not valid in an identifier
   18 |    　cout << -1 << endl;
      |    ^
a.cc: In function 'int main()':
a.cc:18:4: error: '\U00003000cout' was not declared in this scope
   18 |    　cout << -1 << endl;
      |    ^~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100005;
int n,a[N],v[N];
signed main(){
	scanf("%lld",&n);
	for (int i=0;i<=n;i++)scanf("%lld",&a[i]);
	if (n==0){
		if (a[0]==1){
			puts("1");
			return 0;
		}
		else {
			puts("-1");
			return 0;
		}
	}
	if (a[0]){
		puts("-1");
		return 0;
	}
	int Max=1,s=0;
	for (int i=1;i<=n;i++)
		if (a[i]>Max*2){
			puts("-1");
			return 0;
		}
		else v[i-1]=Max,Max=min(1000000000000000ll,Max*2-a[i]);
	int ans=0;
	for (int i=0;i<=n;i++)ans+=a[i];
	for (int i=n-1;i>=0;i--)v[i]=min(v[i],v[i+1]+a[i+1]),ans+=v[i];
	printf("%lld\n",ans+s);
}
·

Compiler output:
a.cc:35:1: error: '\U000000b7' does not name a type
   35 | ·
      | ^
Language: C++

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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> as(n + 1);
	for (auto &&a : as)
	{
		cin >> a;
	}

	if (as[0] != 0)
	{
		cout << -1 << endl;

		return 0;
	}

	for (int64_t i = 1; i <= min<int64_t>(30, n); i++)
	{
		if ((1LL << i) < as[i])
		{
			cout << -1 << endl;

			return 0;
		}
	}

	vector<int64_t> cnt(n + 1);
	cnt[n] = as[n];
	for (int64_t i = n; 0 < i; i--)
	{
		cnt[i - 1] = cnt[i] + as[i - 1];
	}
	cnt[0] = 1;
	for (int64_t i = 1; i <= n; i++)
	{
		cnt[i] = min(cnt[i], 2 * (cnt[i - 1] - as[i - 1]));

		if (0 <= cnt[i - 1] - as[i - 1] && cnt[i - 1] - as[i - 1] <= 60)
		{
			cnt[i] = min(cnt[i], (1LL << (cnt[i - 1] - as[i - 1])));
		}
	}

	cout << accumulate(cnt.begin(), cnt.end(), int64_t(0)) << endl;

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:37: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&, long long int)'
   44 |                         cnt[i] = min(cnt[i], (1LL << (cnt[i - 1] - as[i - 1])));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:44:37: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   44 |                         cnt[i] = min(cnt[i], (1LL << (cnt[i - 1] - as[i - 1])));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:44:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   44 |                         cnt[i] = min(cnt[i], (1LL << (cnt[i - 1] - as[i - 1])));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h> 
using namespace std;
int main() {
  int N, z;
  cin >> N;
  vector<int> A(N+1);
  for(int i=0;i<N+1;i++) {
    cin >> A.at(i);
  }
  int x=1;
  for(int i=0;i<N;i++) {
    x*=2;
  }
  for(int i=N;i>=0;i++) {
    if(A.at(i)>x) {
      cout << -1 << endl;
      break;
    }
    if(i==N) {
      z+=A.at(i);
    }
    if(i!=0||i!=N) {
      z+=(A.at(i+1)+1)/2);
    }
    if(i==0) {
      z++;
    }
  }
  cout << z << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:25: error: expected ';' before ')' token
   23 |       z+=(A.at(i+1)+1)/2);
      |                         ^
      |                         ;
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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(){
    ll n; cin>>n;
    vector<ll> a(n+1);
    rep(i,n+1) cin>>a[i]; // a: num of leaf
    if(n==0){
        if(a[0]==1) cout<1<<endl;
        else cout << -1 << endl;
        return 0;
    }
    vector<ll> branch(n+1, 1); // branch: remain
    branch[0] -= a[0];
    branch[1] = branch[0];
    ll res=n+1;
    ll j=0;
    rep(i, n+1){
        if(a[i]==0) continue;
        ll cnt = a[i];
        if(i == n) cnt--;
        while(j<i){
            
            if(cnt >= branch[j]){
                cnt -= branch[j];
                branch[j+1] += branch[j];
                //branch[i] += branch[j];
                res += branch[j] * (i - j);
                branch[j] = 0;
                j++;
                branch[j] -= a[j];
                branch[j+1] = branch[j];
                if(cnt == 0) break;
            }else{
                branch[j+1] += cnt;
                //branch[i] += cnt;
                branch[j] -= cnt;
                res += cnt * (i - j);
                cnt = 0;
                break;
            }
        }
        //branch[i] -= a[i];
        if(cnt > 0){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << res << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:27: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'
   14 |         if(a[0]==1) cout<1<<endl;
      |                          ~^~~~~~
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll,ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int n; cin >> n;
    vector<ll> a(n+1);
    vector<ll> wa(n+1);
    rep(i,n+1) {
        cin >> a[i];
    }
    wa[n]=a[n];
    rep(i,n){
        wa[n-i-1]=wa[n-i]+a[n-i-1];
    }
    ll ans=1;
    ll pa=1;
    if(a[0]!=0){
        cout << -1 << endl;
        return 0;
    }
    rep(i,a.size()-1){
        pa=min(wa[i+1],pa*2);
        if(pa-a[i+1]<=0 && i!=a.size()-2){
            cout << -1 << endl;
            return 0;
        }
        ans+=pa;
        pa-=a[i+1];
    }
    //rep(i,n+1) cout << wa[i] << endl;
    /*if(pa<0){

    }*/
    //if(n==0 && a[0]==0) cout << 1 << endl;
    else cout << ans << endl;
return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:5: error: 'else' without a previous 'if'
   43 |     else cout << ans << endl;
      |     ^~~~
Language: Java


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class C {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt() + 1;
        in.nextLine();
        final int[] leaves = new int[n];
        for (int i = 0; i < n; i++) {
            leaves[i] = in.nextInt();
        }
        final long[] dp = new long[n];
        for (int i = 0; i < n; i++) {
            dp[i] = i == 0 ? 1 : (2 * (dp[i - 1] - leaves[i - 1]));
            if (dp[i] <= 0) {
                System.out.println(-1);
                return;
            }
        }
        for (int i = n - 1; i >= 0; i--) {
            dp[i] = i == n - 1 ? Math.min(dp[i], leaves[i]) : Math.min(dp[i], dp[i + 1] + leaves[i]);
            double pow = Math.pow(2, i);
            if (Double.compare(pow, Long.MAX_VALUE) < 0) {
                dp[i] = Math.min(dp[i], (long) pow);
            }
        }
        long res = 0;
        for (long num : dp) {
            res += num;
        }
        System.out.println(res);
    }
}


Compiler output:
Main.java:6: error: class C is public, should be declared in a file named C.java
public final class C {
             ^
1 error
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  int c = 1;
  int d = 0;
  int e = 0;
  int f = 0;
  cin >> a;

  vector<int> b(a);
 
  // a個の入力を受け取る
  for (int i = 0; i < a; i++) {
    cin >> b.at(i);
  }
  
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < i; j++) {
      c = c * 2;
    }
    if (b.at(i) > c) {
      cout << -1 << endl;
      return 0;
    }
    if (d <= b.at(i)) {
      d = b.at(i);
      e = i;
    }
  }
  
  for (int i = 0; i < e; i++) {
    f = f + 2 * i;
  }
  cout << f + d << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:15: error: conflicting declaration 'std::vector<int> b'
   12 |   vector<int> b(a);
      |               ^
a.cc:5:9: note: previous declaration as 'int b'
    5 |   int a,b;
      |         ^
a.cc:16:14: error: request for member 'at' in 'b', which is of non-class type 'int'
   16 |     cin >> b.at(i);
      |              ^~
a.cc:23:11: error: request for member 'at' in 'b', which is of non-class type 'int'
   23 |     if (b.at(i) > c) {
      |           ^~
a.cc:27:16: error: request for member 'at' in 'b', which is of non-class type 'int'
   27 |     if (d <= b.at(i)) {
      |                ^~
a.cc:28:13: error: request for member 'at' in 'b', which is of non-class type 'int'
   28 |       d = b.at(i);
      |             ^~
Language: C++

//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
  
using namespace std;
//using namespace boost;
//using namespace multiprecision;  

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

template <class A, class B> inline int Max(const A &a, const B &b){ return (a < b ? b : a); }
template <class A, class B> inline int Min(const A &a, const B &b){ return (a > b ? b : a); }

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


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
 
    int n;
    cin >> n;

    vector<int> a(n+1);

    int res = 1, nd = 1, sum = 0;

    rep(i,n+1){
        cin >> a[i];
        sum += a[i];
    }

    if((a[0] > 0 && n != 0) || (n == 0 && a[i] == 1)){
        return cout << -1 << '\n', 0;
    }
  
    reps(i, n){
        nd = min(nd * 2, sum);
        res += nd;
        nd -= a[i];
        sum -= a[i];
    }

  	if(nd < 0){
        cout << -1 << '\n';
    }else{
    	cout << res << '\n';
    }
 
    return (0);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:45: error: 'i' was not declared in this scope
   57 |     if((a[0] > 0 && n != 0) || (n == 0 && a[i] == 1)){
      |                                             ^
Language: C++

n = int(input())
a = [int(x) for x in input().split()]
least = [0] * (n+2)
good = 1
for i in reversed(range(n+1)):
	least[i] = (least[i+1] + 1) // 2 + a[i]
	if i <= 52 and least[i] > 2**i:
		good = 0
		break
if good == 0:
	print(-1)
	exit(0)

ans = [0] * (n+2)
for i in reversed(range(n+1)):
	if i >= 500:
		ans[i] = ans[i+1] + a[i]
		continue

	lo, hi = 0, ans[i+1]//2
	while lo < hi:
		mid = (lo + hi) // 2
		v = ans[i+1] + a[i] - lo
		good = 1
		if i <= 52 and v > 2**i:
			good = 0
		for j in reversed(range(i)):
			v = (v + 1) // 2 + a[j]
			if j <= 52 and v > 2**j:
				good = 0
				break
		if good == 1:
			hi = mid
		else:
			lo = mid + 1
	ans[i] = ans[i+1] + a[i] - lo
print(sum(ans))


Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n = int(input())
      | ^
Language: C++

#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll t;
	cin>>t;
	vector<ll> pap(t+1);
	for(auto &a:pap){
		cin>>a;
	}
	ll ver=1;
	ll kayn=1;
	if(t!=0&&pap[0]!=0){
		cout<<"-1"<<endl;
		return 0;
	}
	for(ll i=0;i<t;i++){
		if(pap[i]>(kayn-1)){
			cout<<"-1"<<endl;
			return 0;
		}
		else{
			kayn=(kayn-pap[i])*2;
			ver+=kayn;
		}

	}
	ll zayd=kayn-pap[t];
	if(zayd<0){
		cout<<"-1"<<endl;
	}
	ver-=zayd;
	ll o=1;
	while(zayd>0){
		zayd=-kayn/2+zayd;
		kayn=kayn/2;
		ver-=zayd;
		o++;
	}
	if(o>(t+1){
		cout<<"-1"<<endl;
		return 0;
	}
	cout<<ver<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:46:19: error: expected ';' before '{' token
   46 |         if(o>(t+1){
      |                   ^
      |                   ;
a.cc:50:24: error: expected ')' before ';' token
   50 |         cout<<ver<<endl;
      |                        ^
a.cc:46:11: note: to match this '('
   46 |         if(o>(t+1){
      |           ^
Language: C++

#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(n);
    VIN(ll, a, n+1);
    if (a[0] > 0) {
        cout << -1 << endl;
        return;
    }
    ll k = 2;
    reps(i, 1, n+1) {
        if (a[i] > k) {
            cout << -1 << endl;
            return;
        }
        k *= 2;
        if (k > 100000000LL) break;
    }
    vector<pair<ll,ll>> b(n+1);
    b[0] = make_pair(1, 1);
    reps(i, 1, n+1) {
        ll mi, mx;
        mi = min(b[i-1].first - a[i], 0LL);
        mx = 2*b[i-1].second-a[i];
        if (mx < 0) {
            cout << -1 << endl;
            return;
        }
        b[i] = make_pair(mi, mx);
        if (mi > mx) {
            cout << -1 << endl;
            return;
        }
    }
    if (b[n].first > 0 || b[n].second < 0) {
        cout << -1 << endl;
        return;
    }
    vector<pair<ll,ll>> c(n+1);
    c[n] = make_pair(0, 0);
    for (ll i = n; i > 0; --i) {
        ll mi, mx;
        mi = (c[i].first+a[i]+1)/2;
        mx = c[i].second+a[i];
        c[i-1] = make_pair(max(mi, b[i-1].first), min(mx, b[i-1].second));
        if (c[i-1].first > c[i-1].second) {
            cout << -1 << endl;
            return;
        }
    }
    if (c[0].first > 1 || c[0].second < 1) {
        cout << -1 << endl;
        return;
    }
    ll s = 1;
    ll k = 1;
    reps(i, 1, n+1) {
        k = min(c[i].second, k*2-a[i]);
        s += k + a[i];
    }
    cout << s << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:87:8: error: redeclaration of 'll k'
   87 |     ll k = 1;
      |        ^
a.cc:41:8: note: 'll k' previously declared here
   41 |     ll k = 2;
      |        ^
Language: C++

#include <stdio.h>
#include <string.h>
#include <algorithm>

using ll = long long;

int main()
{
	int N;
	scanf("%d", &N);

	static ll A[100001];
	for (int i = 0; i < N + 1; i++) {
		scanf("%lld", &A[i]);
	}
	if (N == 0) {
		if (A[i] == 1) {
			puts("1");
		}
		else {
			puts("-1");
		}
		return 0;
	}

	static ll hist_max[100001];
	ll cmax = A[N];
	ll cmin = A[N];
	for (int i = N - 1; i >= 0; i--) {
		bool ng = false;
		cmax = cmax;
		cmin = (cmin + 1) / 2;
		cmax += A[i];
		cmin += A[i];
		if (i < 60) {
			ll newmax = (1LL << i);
			if (newmax < cmin) {
				ng = true;
			}
			if (cmax > newmax) {
				cmax = newmax;
			}
		}
		if (ng) {
			puts("-1");
			return 0;
		}
		hist_max[i] = cmax;
		//printf("%d..%d\n", cmin, cmax);
	}

	ll ans = A[N] + 1;
	ll cur = 1;
	for (int i = 1; i < N; i++) {
		ll tmp = std::min(cur * 2, hist_max[i]);
		cur = tmp - A[i];
		ans += tmp;
	}
	printf("%lld\n", ans);

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:23: error: 'i' was not declared in this scope
   17 |                 if (A[i] == 1) {
      |                       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> B(N+10),A(N+10, 1e18),C(N+10),D(N+10);
    rep(i,N+1){
        cin >> B[i];
    }
    /*
    A[0] = 1;
    C[0] = A[0] - B[0];
    if(C[0] < 0){
        cout << -1 << endl;
        return 0;
    }
    A[1] = C[0]*2;
    */
   if(N == 0){
       if(B[0] != 1){
           cout << -1 << endl
           return 0;
       }else{
           cout << 1 << endl;
           return 0;
       }
   }
   
    A[0] = 1;
    rep(i,N+1){
        C[i] = A[i] - B[i];
        if(C[i] < 0){
            cout << -1 << endl;
            return 0;
        }
        A[i+1] = C[i]*2;
        if(A[i+1] >= 1e9){
            break;
        }
    }
    /*ll ans = 0;
    rep(i,N+1){
        ans += A[i];
    }*/
    C[N] = 0;
    D[N] = B[N];
    for(ll i=N-1;i>=0;i--){
        D[i] = B[i] + D[i+1];
        if(D[i+1] > D[i]*2){
            cout << -1 << endl;
            return 0;
        }
        if(D[i+1] > A[i]*2){
            cout << -1 << endl;
            return 0;
        }
        if(D[i] > A[i]){
            D[i] = A[i];
        }
        //C[i] = D[i] - B[i];
    }
    ll ans = 0;
    rep(i,N+1){
        ans += D[i];
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:33:30: error: expected ';' before 'return'
   33 |            cout << -1 << endl
      |                              ^
      |                              ;
   34 |            return 0;
      |            ~~~~~~
Language: C++

#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int n;
  int a[n+1];
  cin >> n;
  for(int i; i < n+1; ++i){
    cin >> a[i];
  }
  if(a[0] != 0){
    cout << -1 << endl;
    break;
  }

  for(int i; i < n; ++i){
    if(a[i] != 0 && a[i+1] > a[i]){
      cout << -1 << endl;
      break;
    }
  }

  int count = 0;
  long long ans = pow(2,n);
  for(int i; i < n+1; ++i){
    count += a[i];
    ans -= pow(2,count);
  }
  cout << ans << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:5: error: break statement not within loop or switch
   15 |     break;
      |     ^~~~~
Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;
const ll INF = 1e9+10;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	int n; cin >> n;
	vector<ll> v(n+1); FOR(i, n+1) cin >> v[i];

	vector<ll> tam(n+7, 1);
	FOR(i, n+1){
		if(v[i] > tam[i]){
			cout << "-1\n";
			return 0;
		}
		tam[i+1] = min((tam[i]-v[i])*2LL, 10000000000);
	}

	ll ans = 0;
	ll now = 0;
	for(int i = n; i >= 0; i--){
		if(now + v[i] <= tam[i]){
			ans += now + v[i];
			now += v[i];
		}else{
			now = tam[i];
			ans += now;
		}
	}

	cout << ans << '\n';

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:31: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, long int)'
   31 |                 tam[i+1] = min((tam[i]-v[i])*2LL, 10000000000);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:31:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   31 |                 tam[i+1] = min((tam[i]-v[i])*2LL, 10000000000);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:31:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   31 |                 tam[i+1] = min((tam[i]-v[i])*2LL, 10000000000);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~