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

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

int main() {
  int n;
  cin >> n;
  vector<int> leaves(n+1);
  long long sum_leaf = 0;
  for(int i=0; i<=n; i++){
    cin >> leaves[i];
    sum_leaf += leaves[i];
  }
  
  long long sum_node = 1;
  
  int root = 1;
  
  for(int i=1; i<=n; i++){
    int leaf = leaves[i];
    sum_leaf -= leaf;
    
    int max_root = min ( root * 2 - leaf, sum_leaf );
    
    int node = max_root+leaf;
    
    if(max_root < 0 || node>root*2){
      sum_node = -1;
      break;
    }
    
    root = max_root;
    sum_node += node;
  }
  
  cout << sum_node << endl;
  
  

}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:24: error: no matching function for call to 'min(int, long long int&)'
   22 |     int max_root = min ( root * 2 - leaf, sum_leaf );
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:22:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   22 |     int max_root = min ( root * 2 - leaf, sum_leaf );
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:22:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   22 |     int max_root = min ( root * 2 - leaf, sum_leaf );
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;



int main(){
  ll N; cin >> N; N++; ll a[N];
  rep(i, N){
    cin >> a[i];
  }
  ll tmp=0, ans=0;
  ll need[N] = {}; need[0] = 1;
  if(a[0]!=0){
    if(N==1&&a[0]==1)cout << 1 << endl, return 0;
    cout << -1 << endl, return 0;
  }
  rep(i, N-1){
    need[i+1] = (need[i]-a[i])*2;
    if(need[i+1]<=0){
      cout << -1 << endl; return 0;
    }
  }
  ll v[N];
  for(int i=N-1; i>=0; i--){
    tmp+=a[i];
    v[i] = min(need[i], tmp);
    tmp=v[i];
  }
  rep(i, N){
    ans+=v[i];
  }
  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:38:41: error: expected primary-expression before 'return'
   38 |     if(N==1&&a[0]==1)cout << 1 << endl, return 0;
      |                                         ^~~~~~
a.cc:39:25: error: expected primary-expression before 'return'
   39 |     cout << -1 << endl, return 0;
      |                         ^~~~~~
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

typedef long long int ll;
const int N_MAX = 100005;
const ll INF = 1000000000000000005;

int n;
int A[N_MAX];
ll nres[N_MAX];


int main(){
    cin >> n;
    for(int i = 0; i <= n; i++) cin >> A[i];
    ll an;
    ll nodenum = 0;
    ll now = 0;
    ll benode = 1;
    nres[0] = 1;
    ll exi = 0;
    if (A[0] > 0)nodenum = -1;
    for(int i = 1; i <= n; i++){
        if (nodenum == -1)break;
        benode = min(2 * benode, INF);
        nres[i] = benode;
        if (A[i] > 0){
            if (benode < A[i]){
                nodenum = -1;
                break;
            }
            nres[i] -= A[i];
            benode -= A[i];

            ll res = A[i];
            while(res > 0){
                if (res <= nres[now]){
                    nres[now] -= res;
                    nodenum += res * (i - now + 1);
                    exi += res;
                    break;
                }
                res -= nres[now];
                nodenum += nres[now] * (i - now + 1);
                exi += nres[now];
                now++;
                exi -= A[now];
                nres[now] -= exi;

            }
        }
    }
    if (n == 0 && A[0] = 1) nodenum = 1;
    cout << nodenum << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:16: error: lvalue required as left operand of assignment
   55 |     if (n == 0 && A[0] = 1) nodenum = 1;
      |         ~~~~~~~^~~~~~~
Language: C++

/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
int n,a[maxn];
LL L[maxn],R[maxn];
int main(){
	int n; cin >> n; // n == 0
	for(int i = 0;i <= n; ++i) cin >> a[i];
	if(n == 0){
		if(a[0] == 1) return printf("%d",a[0]),0;
		else return puts("-1"),0;
	}
	L[n-1] = (a[n]+1)/2; R[n-1] = a[n];
	for(int i = n-2;i >= 0; --i){
		L[i] = (L[i+1]+a[i+1]+1)/2; R[i] = R[i+1]+a[i+1];
	}
	LL sum = 0,up = min(1-a[0],R[0]);
	if(up < L[0]) sum = -1;
	else sum += up;
	for(int i = 1;i < n && sum!=-1; ++i){
		LL r = min(R[i],up*2-a[i]);
		if(r < L[i]){
			sum = -1; break;
		}
		else{
			sum += r;
			up = r;
		}
	}
	if(sum == -1) puts("-1");
	else{
		for(int i = 0;i <= n; ++i) sum += a[i];
		cout << sum << '\n';
	}	 
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:29:28: error: no matching function for call to 'min(int, LL&)'
   29 |         LL sum = 0,up = min(1-a[0],R[0]);
      |                         ~~~^~~~~~~~~~~~~
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:5:
/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:29:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'LL' {aka 'long long int'})
   29 |         LL sum = 0,up = min(1-a[0],R[0]);
      |                         ~~~^~~~~~~~~~~~~
/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:29:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   29 |         LL sum = 0,up = min(1-a[0],R[0]);
      |                         ~~~^~~~~~~~~~~~~
Language: C++

clude <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
 
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}
 
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int a[maxn]; 
int main() {
	ll f = 1;
	int n;
	cin >> n;
	ll S = 0;
	for (int i = 0; i <= n; i++) scanf("%d", &a[i]), S += a[i];
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ans += f;
	//	cout << i << ' ' << f << endl;
		if (f < a[i]) {
			cout << -1 << endl;
			return 0;
		}
		f -= a[i];
		S -= a[i];	
		f *= 2;
		f = min(f, S);
	
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc:1:1: error: 'clude' does not name a type
    1 | clude <bits/stdc++.h>
      | ^~~~~
a.cc: In function 'int main()':
a.cc:28:9: error: 'cin' was not declared in this scope
   28 |         cin >> n;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | clude <bits/stdc++.h>
a.cc:30:38: error: 'scanf' was not declared in this scope
   30 |         for (int i = 0; i <= n; i++) scanf("%d", &a[i]), S += a[i];
      |                                      ^~~~~
a.cc:36:25: error: 'cout' was not declared in this scope
   36 |                         cout << -1 << endl;
      |                         ^~~~
a.cc:36:25: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:36:39: error: 'endl' was not declared in this scope
   36 |                         cout << -1 << endl;
      |                                       ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | clude <bits/stdc++.h>
a.cc:42:21: error: 'min' was not declared in this scope; did you mean 'main'?
   42 |                 f = min(f, S);
      |                     ^~~
      |                     main
a.cc:45:9: error: 'cout' was not declared in this scope
   45 |         cout << ans << endl;
      |         ^~~~
a.cc:45:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:45:24: error: 'endl' was not declared in this scope
   45 |         cout << ans << endl;
      |                        ^~~~
a.cc:45:24: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)

int main(){
    int n; cin >> n;
    vector<ll> a(n + 1); 
    rep(i, 0, n + 1) cin >> a[i];
    vector<ll> s(n+2, 0);
    s[n] = a[n];
    rrep(i, 0, n) s[i] = a[i] + s[i+1];
    if(a[0] == 1){
        if(n == 0) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }
    ll ans = 0,ro = 1, le = 0, sum = 1;

    rep(i, 0, n + 1){
        le = a[i];
        ro = sum - le;
        if(ro < 0) Exit(-1);
        ans += ro + le;
        sum = ro * 2;
        if(i == n) break;
        if(sum > s[i+1]) sum = s[i+1];
        
    }
    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:20: error: 'Exit' was not declared in this scope; did you mean 'exit'?
   24 |         if(ro < 0) Exit(-1);
      |                    ^~~~
      |                    exit
Language: C++

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[100010], mxx[100010];
int main(){
    ll n;
    while(cin>>n){
        ll ans=0;
        bool l=1;
        ll mn=1, mx=1;
        mxx[0]=1;
        for(ll i=0; i<=n; ++i){
            scanf("%lld",a+i);
            // a[i]=0;
            if(i>0){
	            mxx[i]=mxx[i-1]*2-a[i];
	            if(mx[i]<0){
	            	l=0;
	            }
	            mxx[i]=min(mxx[i], (ll)1e14);
            }
        }
        // a[n]=1;
        // ans=1;
        ll tmp;
        ll sm=0;
        for(ll i=n; i>=1; --i){
        	tmp=mxx[i-1];
        	ans+=a[i];
        	a[i]+=sm;
        	assert(a[i]<=1e13);
        	if(a[i]>tmp*2){
        		l=0;
        		break;
        	}
        	else{
        		ans+=min(tmp, a[i]);
        	}
        	sm=min(tmp, a[i]);
        }
        if(a[0]>0){
        	l=0;
        }
        if(n==0){
        	if(a[0]==1){
        		l=1;
        		ans=1;
        	}
        	else{
        		l=0;
        	}
        }
        if(l==0){
        	printf("-1\n");
        }
        else{
        	printf("%lld\n",ans);
        }
    }
  return 0;
}




Compiler output:
a.cc: In function 'int main()':
a.cc:21:26: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   21 |                     if(mx[i]<0){
      |                          ^
Language: C++

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int MOD = 1000000007;

int main(){
	long long int B[100002],C[100001],M[100001]={1},res=0,N,A[100001];
	long long int S;
	cin>>N>>A[0];
	for(int i=1;i<=N;i++){
		cin>>A[i];
		if(M[i-1]<=10000000000000)M[i]=M[i-1]*2;
	}
	B[N+1]=0;
	if(N==0&&A[0]==0){cout<<1;return 0;}
	if(A[0]!=0){cout<<-1;return 0;}
	for(int i=N;i>=0;i--){
		B[i]=B[i+1]+A[i];
		if(i<=58 && B[i]>M[i])B[i]=POW(2,M[i]);
		C[i]=B[i]-A[i];
		if(i<=N-1&&C[i]<=0||C[i]<0){cout<<-1;return 0;}
	}
	for(int i=1;i<=N-1;i++){
		if(C[i-1]*2<B[i]){
			B[i]=C[i-1]*2;
			C[i]=B[i]-A[i];
			if(C[i]<=0){cout<<-1;return 0;}
		}
		res+=B[i];
	}
	res+=B[N]+B[0];
	cout<<res;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:44: error: 'POW' was not declared in this scope
   20 |                 if(i<=58 && B[i]>M[i])B[i]=POW(2,M[i]);
      |                                            ^~~
Language: C++

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

int main(){
  int limit = pow(10,5)+1;
  int N;
  int a[limit];
  int nDown[limit];
  int nUp[limit];
  int nAns[limit];
  cin >> N;
  for (int i=0; i<=N; i++)
    cin >> a[i];
    
  // handle corner cases
  if ((a[0]==1) and N!=0){
    cout << -1 << endl;
    return 0;
  } 
  // compute n's downwards
  nDown[0] = 1;
  for (int i=0; i<N; i++)
    nDown[i+1] = 2*nDown[i] - a[i+1];
  // compute n's upwards 
  nUp[N] = 0;
  for (int i=N; 0<i; i--)
    nUp[i-1] = nUp[i] + a[i];
  // when tree is not realizable
  if ((nDown[N]<0) or (nUp[0]<0)){
    cout << -1 << endl;
    return 0;
  }
  // 
  int sum = 0;
  for (int i=0; i<=N; i++){
    nAns[i] = min(nUp[i], nDown[i]);
    sum += nAns[i] + a[i];
  }
  cout << sum << endl;
  return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

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

int main(){
    long long n;
    cin >> n;
    long long a[n+1];
    for(long long i=0;i<=n;i++) cin >> a[i];
    bool flag=true;
    if(n==0&&a[0]!=1){
        cout << -1 << endl;
        return 0;
    }
    if(n==0&&a[0]==1){
        cout << 1 << endl;
        return 0;
    }
    long long b[n+1],c[n+1];
    b[n]=a[n];
    for(long long i=n-1;i>=0;i--){
        b[i]=b[i+1]+a[i];
    }
    c[0]=1;
    for(long long i=1;i<=n;i++){
        long long m=(c[i-1]-a[i-1])*2;
        if(m<=0) flag=false;
        c[i]=min(m,1000000000000000LL)
    }
    if(c[n]<a[n]) flag=false;
    long long ans=0;
    for(long long i=0;i<=n;i++){
        ans+=min(b[i],c[i]);
    }
    if(flag) cout << ans << endl;
    else cout << -1 << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:39: error: expected ';' before '}' token
   27 |         c[i]=min(m,1000000000000000LL)
      |                                       ^
      |                                       ;
   28 |     }
      |     ~
Language: C++

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

long long llmin(long long a, long long b)
{
    return a < b ? a : b;
}

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n + 1), maxa(n + 1), suma(n + 1);
    for (int i = 0; i < n + 1; i++)
    {
        cin >> a[i];
    }
    
    suma[n] = a[n];
    for (int i = n - 1; i >= 0; i--)
    {
        suma[i] = a[i] + suma[i + 1];
    }
    maxa[0] = 1;
    for (int i = 0; i < n; i++)
    {
        if(maxa[i] - a[i] <= 9223372036854775807 / 2)maxa[i + 1] = (maxa[i] - a[i]) * 2;
        else maxa[i + 1] = 9223372036854775807;
    }
    
    long long ans = 0;
    for (int i = 0; i < n + 1; i++)
    {
        long long buf = llmin(suma[i], maxa[i]);
        cout << suma[i] << " " << maxa[i] << " " << buf << endl;
        if(maxa[i] <= 0)
        {
            ans = -1;
            break;
        }
        else if(a[0] != 0)
        {
            ans = -1;
            break;
        }
        else if(n == 0 || a[0] = 1){
            ans = 1;
            break;
        }
        else if(suma[n] > maxa[n])
        {
            ans = -1;
            break;
        }
        
        ans += buf;
    }
    
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:46:24: error: lvalue required as left operand of assignment
   46 |         else if(n == 0 || a[0] = 1){
Language: Java

import java.util.*;

public class Main {
    private static final long INF =  1_000_000_000_000_000_000L;
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N+1];
        for (int i = 0; i <= N; i++) {
            A[i] = sc.nextInt();
        }

        long[] pow = new long[Math.max(N+1,32)];
        for (int i = 0; i < N+1; i++) {
            pow[i] = INF;
        }
        pow[0] = 1;
        for (int i = 1; i <= 30; i++) {
            pow[i] = 2*pow[i-1];
        }
        // pow[30] 1_000_000_000;

        long[] PMax = new long[N+1];
        for (int i = 0; i < N+1; i++) {
            PMax[i] = INF;
        }

        PMax[0] = 1;
        for (int i = 1; i <= N-1; i++) {
            PMax[i] = Math.min(2*PMax[i-1]-A[i],INF);
            if (PMax[i] == INF) {
                break;
            }
            if (PMax[i] <= 0) {
                System.out.println(-1);
                return;
            }
        }

        if (A[N] > pow[i]) {
            System.out.println(-1);
            return;
        }
        long ans = A[N];
        long pre = A[N];
        for (int i = N-1; i >= 0; i--) {
            long PMax2 = Math.min(PMax[i],pre);
            long now = PMax2+A[i];
            if (now > pow[i]) {
                System.out.println(-1);
                return;
            }
            ans += now;
            pre = now;
        }

        System.out.println(ans);
    }
}


Compiler output:
Main.java:41: error: cannot find symbol
        if (A[N] > pow[i]) {
                       ^
  symbol:   variable i
  location: class Main
1 error
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll arr[n+1];
    ll sum=0;
    bool state=0;
    for(int i=0;i<=n;i++){
        cin>>arr[i];sum+=arr[i];
    }
    ll cnt=1,node=1;
    for(int i=1;i<=n;i++){
        node=min(an*2,sum);
        cnt+=node;
        node-=arr[i];
        sum-=arr[i];
        if(node<0)state=1;
    }
    if(state||arr[0]>0){cout<<"-1\n";return 0;}
    cout<<cnt<<"\n";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:18: error: 'an' was not declared in this scope; did you mean 'n'?
   29 |         node=min(an*2,sum);
      |                  ^~
      |                  n
Language: Java

import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            a[i] = sc.nextInt();
        }
        long max = a[n];
        long prevNodes = a[n];
        for (int i = n - 1; i >= 0; i++) {
          	long currNodes = Math.min(prevNodes + a[i], Math.pow(2, i));
            max += currNodes;
            prevNodes = currNodes;
        }
        System.out.println(max);
    }
}

Compiler output:
Main.java:14: error: incompatible types: possible lossy conversion from double to long
          	long currNodes = Math.min(prevNodes + a[i], Math.pow(2, i));
          	                         ^
1 error
Language: C++


#include<iostream>
#include<vector>

int main()
{
	std::vector<int64_t> A;
	size_t N;
	std::cin >> N;

	for (size_t n = 0; n <= N; ++n)
	{
		int64_t a;
		std::cin >> a;
		A.emplace_back(a);
	}

	std::vector<int64_t> B;
	int64_t n = 1;
	B.push_back(1);
	for (auto a : A)
	{
		n = (n - a) * 2;
		B.emplace_back(n);
	}

	std::reverse(A.begin(), A.end());
	std::vector<int64_t> C;
	n = 0;
	for (auto a : A)
	{
		n += a;
		C.emplace_back(n);
	}
	std::reverse(C.begin(), C.end());

	bool b = false;
	int64_t s = 0;
	for (size_t i = 0; i < C.size(); ++i)
	{
		if (!b && B.at(i) >= C.at(i)) {
			b = true;
		}

		if (!b) {
			s += B.at(i);
		}
		else {
			s += C.at(i);
		}
	}
	if (!b) {
		std::cout << -1 << std::endl;
	}
	else {
		std::cout << s << std::endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:14: error: 'reverse' is not a member of 'std'
   27 |         std::reverse(A.begin(), A.end());
      |              ^~~~~~~
a.cc:35:14: error: 'reverse' is not a member of 'std'
   35 |         std::reverse(C.begin(), C.end());
      |              ^~~~~~~
Language: Java

import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            a[i] = sc.nextInt();
        }
        int max = a[n];
        int prevNodes = a[n];
        for (int i = n - 1; i >= 0; i++) {
          	int currNodes = Math.min(prevNodes + a[i], Math.pow(2, i));
            max += currNodes;
            prevNodes = currNodes;
        }
        System.out.println(max);
    }
}

Compiler output:
Main.java:14: error: incompatible types: possible lossy conversion from double to int
          	int currNodes = Math.min(prevNodes + a[i], Math.pow(2, i));
          	                        ^
1 error
Language: C++

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  long long N,a;
  cin>>N;
  vector <long long> V(N+1);
  for(long long i=0;i<N+1;i++){
    cin>>V.at(i);
  }
  int jud=0;
  a=1;
  if(V.size==1 && V.at(0)==0){cout<<-1<<endl;}
  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:13:8: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = long long int; _Alloc = std::allocator<long long int>; size_type = long unsigned int]' (did you forget the '()' ?)
   13 |   if(V.size==1 && V.at(0)==0){cout<<-1<<endl;}
      |      ~~^~~~
      |            ()
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>

int main(int argc, char* argv[]) {
	int N;
	scanf("%d", &N);
	std::vector<int> v_num_leaf(N+1, 0);

	int sum_of_leaves = 0;
	for (int i = 0; i < N + 1; ++i) {
		scanf("%d", &v_num_leaf[i]);
		sum_of_leaves += v_num_leaf[i];
	}

	int sum_of_nodes = 0;
	int current_sum_of_leaves = 0;
	int previous_num_of_nodes = 1;
	for (size_t d = 0; d < v_num_leaf.size(); ++d) {
		int possible_num_of_nodes;
		if (d == 0)
			possible_num_of_nodes = 1;
		else
			possible_num_of_nodes = std::min((int)std::pow(2.0, d), (previous_num_of_nodes - v_num_leaf[d - 1]) * 2);

		if (possible_num_of_nodes < v_num_leaf[d]) {
			sum_of_nodes= -1;
			break;
		}


		int current_num_of_nodes = possible_num_of_nodes;

		if (current_num_of_nodes > (sum_of_leaves - current_sum_of_leaves)) {
			current_num_of_nodes = sum_of_leaves - current_sum_of_leaves;
		}

		sum_of_nodes += current_num_of_nodes;

		previous_num_of_nodes = current_num_of_nodes;
		current_sum_of_leaves += v_num_leaf[d];
	}

	printf("%d", sum_of_nodes);

	return 0;
}

Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:24:68: error: 'pow' is not a member of 'std'
   24 |                         possible_num_of_nodes = std::min((int)std::pow(2.0, d), (previous_num_of_nodes - v_num_leaf[d - 1]) * 2);
      |                                                                    ^~~
Language: C++

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

int main(){
    long long int A,B,N,C, ii;
    cin >> N;
    B = 0;
    A = N + 1;
    if(A > 30){
        A = 30;
    }
    vector<int> vec(A);
    for(int i=0;i < A;i++){
        cin >> vec.at(i);
    }
    for (int i = 1; i < A; i++)
    {
        ii = i -1;
        C = pow(2,i);
        if(C-2*vec.at(ii) < vec.at(i) ){
            B = 1;
        }
    }
    if(vec.at(0) != 0){
        B = 1;
    }
    if(B == 1){
        cout << -1 <<endl;
    }else{
        int ans = 0;
        for (int i = N; i > 0; i = i -1)
        {
            ii = i - 1;
            int iii = i -2;
            C = pow(2, ii);
            if (C - 2 * vec.at(ii) > vec.at(i))
            {
                ans += vec.at(i);
                int ia = i;
                for(int ia = i;ia > 0;ia = ia -1){
                int iia = ia -2;
                int ai = ia -1;
                    if (ia > 1 && C - 2 * vec.at(iia) > vec.at(ai)){
                        ans += vec.at(ia);
                }
                    cout << vec.at(i) << endl;
            }else{
                cout << vec.at(i) - (C - 2 * vec.at(ii)) << endl;
                ans += vec.at(i) - (C - 2 * vec.at(ii));
            }
            ans+= vec.at(i);
        }
        ans += 1;
        cout << ans << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:14: error: expected '}' before 'else'
   47 |             }else{
      |              ^~~~
a.cc:37:13: note: to match this '{'
   37 |             {
      |             ^
Language: C++

#include<bits/stdc++.h>
using ll = long long;
using namespace std;
ll test[12345678], res[12345678];
signed main() {
	ll n, x = 0, cnt = 0, ans = 0;
	cin >> n;
	for (int h = 0; h <= n; h++) {
		cin >> test[h];

		if (h == 0) { res[h] = 1; }
		else { res[h] = res[h - 1] * 2 - test[h]; }

		if (h != n && res[h] <= 0) { x++; }
		if (h == n && res[h] < 0) { x++; }
		if (h == 0 && test[h] != 0) { x++; }
	}
	if (n == 0) {
		if (test[0] == 1) { cout << 1 << endl; }
		else { cout << -1 << endl; }
		return 0;
	}
	if (x != 0) { cout << -1 << endl; return 0; }

	cnt = test[n]; ans += cnt;

	for (int h = n - 1; h >= 0; h--) {
		if (cnt > res[h]) { cnt = res[h]; }
		cnt += test[h]; ans += cnt;
	}
	cout << max(0,ans) << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:20: error: no matching function for call to 'max(int, ll&)'
   31 |         cout << max(0,ans) << endl;
      |                 ~~~^~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:31:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   31 |         cout << max(0,ans) << endl;
      |                 ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:31:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |         cout << max(0,ans) << endl;
      |                 ~~~^~~~~~~
Language: C++


#include <iostream>
#include <algorithm>
#include <vector>

int main(int argc, char* argv[]) {
	int N;
	scanf("%d", &N);
	std::vector<int> v_num_leaf(N+1, 0);

	int sum_of_leaves = 0;
	for (int i = 0; i < N + 1; ++i) {
		scanf("%d", &v_num_leaf[i]);
		sum_of_leaves += v_num_leaf[i];
	}

	int sum_of_nodes = 0;
	int current_sum_of_leaves = 0;
	int previous_num_of_nodes = 1;
	for (size_t d = 0; d < v_num_leaf.size(); ++d) {
		int possible_num_of_nodes;
		if (d == 0)
			possible_num_of_nodes = 1;
		else
			possible_num_of_nodes = std::min((int)std::pow(2.0, d), (previous_num_of_nodes - v_num_leaf[d - 1]) * 2);

		if (possible_num_of_nodes < v_num_leaf[d]) {
			sum_of_nodes= -1;
			break;
		}


		int current_num_of_nodes = possible_num_of_nodes;

		if (current_num_of_nodes > (sum_of_leaves - current_sum_of_leaves)) {
			current_num_of_nodes = sum_of_leaves - current_sum_of_leaves;
		}

		sum_of_nodes += current_num_of_nodes;

		previous_num_of_nodes = current_num_of_nodes;
		current_sum_of_leaves += v_num_leaf[d];
	}

	printf("%d", sum_of_nodes);

	return 0;
}

Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:25:68: error: 'pow' is not a member of 'std'
   25 |                         possible_num_of_nodes = std::min((int)std::pow(2.0, d), (previous_num_of_nodes - v_num_leaf[d - 1]) * 2);
      |                                                                    ^~~
Language: C++

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

int main(){
    long long int A,B,N,C, ii;
    cin >> N;
    B = 0;
    A = N + 1;
    if(A > 30){
        A = 30;
    }
    vector<int> vec(A);
    for(int i=0;i < A;i++){
        cin >> vec.at(i);
    }
    for (int i = 1; i < A; i++)
    {
        ii = i -1;
        C = pow(2,i);
        if(C-2*vec.at(ii) < vec.at(i) ){
            B = 1;
        }
    }
    if(vec.at(0) != 0){
        B = 1;
    }
    if(B == 1){
        cout << -1 <<endl;
    }else{
        int ans = 0;
        for (int i = N; i > 0; i = i -1)
        {
            ii = i - 1;
            int iii = i -2;
            C = pow(2, ii);
            if (C - 2 * vec.at(ii) > vec.at(i))
            {
                ans += vec.at(i);
                int ia = i;
                for(int ia = i;ia > 0;ia = ia -1)
                int iia = ia -2;
                int ai = ia -1;
                    if (ia > 1 && C - 2 * vec.at(iia) > vec.at(ai)){
                        ans += vec.at(ia);
                }
                    cout << vec.at(i) << endl;
            }else{
                cout << vec.at(i) - (C - 2 * vec.at(ii)) << endl;
                ans += vec.at(i) - (C - 2 * vec.at(ii));
            }
            ans+= vec.at(i);
        }
        ans += 1;
        cout << ans << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:50: error: 'iia' was not declared in this scope; did you mean 'ia'?
   43 |                     if (ia > 1 && C - 2 * vec.at(iia) > vec.at(ai)){
      |                                                  ^~~
      |                                                  ia
Language: C++

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
ll func[100005];

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

    vector<ll> A(N + 1), S(N + 1);
    for (int i = 0; i < N + 1; ++i)
        cin >> A[i];

    func[0] = 1LL;
    for (int i = 1; i <= N; ++i)
        func[i] = func[i - 1] << 1;

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

    for (int i = 0; i < N; ++i) {
        if (A[i] > func[i] || (i > 0 && A[i] > S[i - 1] * 2)) {
            cout << -1 << endl;
            return 0;
        }
        if (i == 0) S[i] = 1 - A[i];
        else S[i] = S[i - 1] * 2 - A[i];

        if(S[i] < 0)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    S[N] = 0;
    ll ans = A[N];
    for (int i = N - 1; i >= 0; --i) {
        S[i] = min(S[i], S[i + 1] + A[i + 1]);
        ans += S[i] + A[i];
    }

    cout << ans << endl;
}

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

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
      	Long A[] = new Long[N+1];
        for (int i=0; i<=N; i++) {
            A[i] = sc.nextLong();
        }
      	long ans = 0;
      	int d = 1;
      	for(int j=1; j<N; j++){
        if(d <= 0) break;
          if(A[j] == 0){
            if(d * 2 <= A[N]){
              ans = ans + d*2;
              d = d*2;
            }
            else{
              ans = ans + A[N];
              d = A[N];
            }
          }
          else {
            if(d * 2 - A[j] <= A[N]){
              ans = ans + d*2 - A[j];
              d = d*2 - A[j];
            }
            else{
              if(A[j] == A[N-1]){
                ans = ans + A[N];
             	d = A[N];
              }
              else{
              ans = ans + A[N] + A[j+1];
              d = A[N]; }
            }
          }
        System.out.println(ans);  
        System.out.println("d="+d);
        }
      	int sum = 0;;
        for( int i=0; i<A.length; i++ ) {
          sum += A[i];
        }
      	System.out.println(sum);
        ans = ans + sum + 1;
      	if(d>=2){
        System.out.println(ans); }
      	else{
          System.out.println("-1");
   		 }
    }
}

Compiler output:
Main.java:22: error: incompatible types: Long cannot be converted to int
              d = A[N];
                   ^
Main.java:28: error: incompatible types: possible lossy conversion from long to int
              d = d*2 - A[j];
                      ^
Main.java:33: error: incompatible types: Long cannot be converted to int
             	d = A[N];
             	     ^
Main.java:37: error: incompatible types: Long cannot be converted to int
              d = A[N]; }
                   ^
4 errors
Language: Java

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
      	Long A[] = new Long[N+1];
        for (int i=0; i<=N; i++) {
            A[i] = sc.nextLong();
        }
      	int ans = 0;
      	int d = 1;
      	for(int j=1; j<N; j++){
        if(d <= 0) break;
          if(A[j] == 0){
            if(d * 2 <= A[N]){
              ans = ans + d*2;
              d = d*2;
            }
            else{
              ans = ans + A[N];
              d = A[N];
            }
          }
          else {
            if(d * 2 - A[j] <= A[N]){
              ans = ans + d*2 - A[j];
              d = d*2 - A[j];
            }
            else{
              if(A[j] == A[N-1]){
                ans = ans + A[N];
             	d = A[N];
              }
              else{
              ans = ans + A[N] + A[j+1];
              d = A[N]; }
            }
          }
        System.out.println(ans);  
        System.out.println("d="+d);
        }
      	int sum = 0;;
        for( int i=0; i<A.length; i++ ) {
          sum += A[i];
        }
      	System.out.println(sum);
        ans = ans + sum + 1;
      	if(d>=2){
        System.out.println(ans); }
      	else{
          System.out.println("-1");
   		 }
    }
}

Compiler output:
Main.java:21: error: incompatible types: possible lossy conversion from long to int
              ans = ans + A[N];
                        ^
Main.java:22: error: incompatible types: Long cannot be converted to int
              d = A[N];
                   ^
Main.java:27: error: incompatible types: possible lossy conversion from long to int
              ans = ans + d*2 - A[j];
                              ^
Main.java:28: error: incompatible types: possible lossy conversion from long to int
              d = d*2 - A[j];
                      ^
Main.java:32: error: incompatible types: possible lossy conversion from long to int
                ans = ans + A[N];
                          ^
Main.java:33: error: incompatible types: Long cannot be converted to int
             	d = A[N];
             	     ^
Main.java:36: error: incompatible types: possible lossy conversion from long to int
              ans = ans + A[N] + A[j+1];
                               ^
Main.java:37: error: incompatible types: Long cannot be converted to int
              d = A[N]; }
                   ^
8 errors
Language: Java

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextint();
      	Long A[] = new Long[N+1];
        for (int i=0; i<=N; i++) {
            A[i] = sc.nextLong();
        }
      	int ans = 0;
      	int d = 1;
      	for(int j=1; j<N; j++){
        if(d <= 0) break;
          if(A[j] == 0){
            if(d * 2 <= A[N]){
              ans = ans + d*2;
              d = d*2;
            }
            else{
              ans = ans + A[N];
              d = A[N];
            }
          }
          else {
            if(d * 2 - A[j] <= A[N]){
              ans = ans + d*2 - A[j];
              d = d*2 - A[j];
            }
            else{
              if(A[j] == A[N-1]){
                ans = ans + A[N];
             	d = A[N];
              }
              else{
              ans = ans + A[N] + A[j+1];
              d = A[N]; }
            }
          }
        System.out.println(ans);  
        System.out.println("d="+d);
        }
      	int sum = 0;;
        for( int i=0; i<A.length; i++ ) {
          sum += A[i];
        }
      	System.out.println(sum);
        ans = ans + sum + 1;
      	if(d>=2){
        System.out.println(ans); }
      	else{
          System.out.println("-1");
   		 }
    }
}

Compiler output:
Main.java:6: error: cannot find symbol
        int N = sc.nextint();
                  ^
  symbol:   method nextint()
  location: variable sc of type Scanner
Main.java:21: error: incompatible types: possible lossy conversion from long to int
              ans = ans + A[N];
                        ^
Main.java:22: error: incompatible types: Long cannot be converted to int
              d = A[N];
                   ^
Main.java:27: error: incompatible types: possible lossy conversion from long to int
              ans = ans + d*2 - A[j];
                              ^
Main.java:28: error: incompatible types: possible lossy conversion from long to int
              d = d*2 - A[j];
                      ^
Main.java:32: error: incompatible types: possible lossy conversion from long to int
                ans = ans + A[N];
                          ^
Main.java:33: error: incompatible types: Long cannot be converted to int
             	d = A[N];
             	     ^
Main.java:36: error: incompatible types: possible lossy conversion from long to int
              ans = ans + A[N] + A[j+1];
                               ^
Main.java:37: error: incompatible types: Long cannot be converted to int
              d = A[N]; }
                   ^
9 errors
Language: Java

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextLong();
      	Long A[] = new Long[N+1];
        for (int i=0; i<=N; i++) {
            A[i] = sc.nextInt();
        }
      	int ans = 0;
      	int d = 1;
      	for(int j=1; j<N; j++){
        if(d <= 0) break;
          if(A[j] == 0){
            if(d * 2 <= A[N]){
              ans = ans + d*2;
              d = d*2;
            }
            else{
              ans = ans + A[N];
              d = A[N];
            }
          }
          else {
            if(d * 2 - A[j] <= A[N]){
              ans = ans + d*2 - A[j];
              d = d*2 - A[j];
            }
            else{
              if(A[j] == A[N-1]){
                ans = ans + A[N];
             	d = A[N];
              }
              else{
              ans = ans + A[N] + A[j+1];
              d = A[N]; }
            }
          }
        System.out.println(ans);  
        System.out.println("d="+d);
        }
      	int sum = 0;;
        for( int i=0; i<A.length; i++ ) {
          sum += A[i];
        }
      	System.out.println(sum);
        ans = ans + sum + 1;
      	if(d>=2){
        System.out.println(ans); }
      	else{
          System.out.println("-1");
   		 }
    }
}

Compiler output:
Main.java:6: error: incompatible types: possible lossy conversion from long to int
        int N = sc.nextLong();
                           ^
Main.java:9: error: incompatible types: int cannot be converted to Long
            A[i] = sc.nextInt();
                             ^
Main.java:21: error: incompatible types: possible lossy conversion from long to int
              ans = ans + A[N];
                        ^
Main.java:22: error: incompatible types: Long cannot be converted to int
              d = A[N];
                   ^
Main.java:27: error: incompatible types: possible lossy conversion from long to int
              ans = ans + d*2 - A[j];
                              ^
Main.java:28: error: incompatible types: possible lossy conversion from long to int
              d = d*2 - A[j];
                      ^
Main.java:32: error: incompatible types: possible lossy conversion from long to int
                ans = ans + A[N];
                          ^
Main.java:33: error: incompatible types: Long cannot be converted to int
             	d = A[N];
             	     ^
Main.java:36: error: incompatible types: possible lossy conversion from long to int
              ans = ans + A[N] + A[j+1];
                               ^
Main.java:37: error: incompatible types: Long cannot be converted to int
              d = A[N]; }
                   ^
10 errors
Language: Java

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
      	Long A[] = new Long[N+1];
        for (int i=0; i<=N; i++) {
            A[i] = sc.nextInt();
        }
      	int ans = 0;
      	int d = 1;
      	for(int j=1; j<N; j++){
        if(d <= 0) break;
          if(A[j] == 0){
            if(d * 2 <= A[N]){
              ans = ans + d*2;
              d = d*2;
            }
            else{
              ans = ans + A[N];
              d = A[N];
            }
          }
          else {
            if(d * 2 - A[j] <= A[N]){
              ans = ans + d*2 - A[j];
              d = d*2 - A[j];
            }
            else{
              if(A[j] == A[N-1]){
                ans = ans + A[N];
             	d = A[N];
              }
              else{
              ans = ans + A[N] + A[j+1];
              d = A[N]; }
            }
          }
        System.out.println(ans);  
        System.out.println("d="+d);
        }
      	int sum = 0;;
        for( int i=0; i<A.length; i++ ) {
          sum += A[i];
        }
      	System.out.println(sum);
        ans = ans + sum + 1;
      	if(d>=2){
        System.out.println(ans); }
      	else{
          System.out.println("-1");
   		 }
    }
}

Compiler output:
Main.java:9: error: incompatible types: int cannot be converted to Long
            A[i] = sc.nextInt();
                             ^
Main.java:21: error: incompatible types: possible lossy conversion from long to int
              ans = ans + A[N];
                        ^
Main.java:22: error: incompatible types: Long cannot be converted to int
              d = A[N];
                   ^
Main.java:27: error: incompatible types: possible lossy conversion from long to int
              ans = ans + d*2 - A[j];
                              ^
Main.java:28: error: incompatible types: possible lossy conversion from long to int
              d = d*2 - A[j];
                      ^
Main.java:32: error: incompatible types: possible lossy conversion from long to int
                ans = ans + A[N];
                          ^
Main.java:33: error: incompatible types: Long cannot be converted to int
             	d = A[N];
             	     ^
Main.java:36: error: incompatible types: possible lossy conversion from long to int
              ans = ans + A[N] + A[j+1];
                               ^
Main.java:37: error: incompatible types: Long cannot be converted to int
              d = A[N]; }
                   ^
9 errors