#include<bits/stdc++.h>
using namespace std;
int main(){
unsigned long long n,sum=0;
cin>>n;
for(unsigned long long i=1;i<=n+1;i++){
cin>>a[i];
}
int b[n+5]={0},c[n+5]={0};
for(unsigned long long i=2;i<=n+1;i++){
b[i]=(b[i-1]-a[i-1])*2;
}
for(unsigned long long i=n;i>=1;i--){
c[i]=c[i+1]+a[i];
}
for(unsigned long long i=1;i<=n+1;i++){
sum+=min(b[i],c[i]);
}
for(unsigned long long i=1;i<=n;i++){
if(a[i]>b[i]){
cout<<"-1"<<endl;
return 0;
}
}
cout<<sum<<endl;
return 0;
}