#define ICC ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI acos(-1)
#include<time.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<iostream>
#include<algorithm>
//#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
clock_t start,finish;
const ll MOD=(1?100000000000000007:233333333333333333);
const int mod=(1?1000000007:998244353);
void time_in(){start=clock();}
void time_out(){finish=clock();double tim=(double)(finish-start)/CLOCKS_PER_SEC;printf("Running time is %lf\n",tim);}
inline ll mul(ll a,ll b){ll s=0;while(b){if(b&1)s=(s+a)%mod;a=(a<<1)%mod;b>>=1;}return s%mod;}
inline ll pow_mul(ll a,ll b){ll s=1;while(b){if(b&1)s=mul(s,a);a=mul(a,a);b>>=1;}return s;}
inline ll poww(ll a,ll b){ll s=1;while(b){if(b&1)s=(s*a)%mod;a=(a*a)%mod;b>>=1;}return s%mod;}
inline int read(){char c=getchar();int sgn=1,ret=0;while(c!='-'&&(c<'0'||c>'9'))c=getchar();
   if(c=='-')sgn=-1,c=getchar();while(c>='0'&&c<='9')ret=ret*10+c-48,c=getchar();return ret*sgn;}
void write(int x){if(x>9)write(x/10);putchar(x%10+'0');}
inline ll phi(ll x){ll ans=x;for(ll i=2;i*i<=x;i++)if(x%i==0){ans-=ans/i;while(x%i==0)x/=i;}if(x>1)ans-=ans/x;return ans;}
//ll inv(ll down){return down==1?1:((mod-mod/down)*inv(mod%down))%mod;}
int st[4][2]={1,0,0,1,-1,0,0,-1};

/*线性素数
int p[N],vis[N];
int getpre(){
    memset(vis,1,sizeof(vis));vis[0]=vis[1]=0;
    int sum=0;
    for(int i=2;i<=1e5;i++){
        if(vis[i])p[sum++]=i;
        for(int j=0;j<sum&&i*p[j]<=1e5;j++){
            vis[i*p[j]]=0;
            if(i%p[j]==0)break;
        }
    }
    return sum;
}
*/

/*前向星
int head[N],tot;
void init(int n){tot=1;for(int i=0;i<=n;i++)head[i]=0;}
struct edge{int to,next,w;}e[N<<1];
void add(int u,int v,int w){e[tot].to=v,e[tot].w=w,e[tot].next=head[u],head[u]=tot++;}
*/

/*优先队列优先级
struct node{
    int x,y;
    bool operator < (const node & a) const{
        return x<a.x;  //大的优先级高
    }
};
*/

/*树状数组
int tree[N];
void add(int i){for(;i<=n;i+=i&-i)tree[i]++;}
int getsum(int i){int s=0;for(;i>0;i-=i&-i)s+=tree[i];return s;}
*/

/*线性递推组合数板子
struct CC
{
    static const int M=200010;
    ll fac[M],inv[M]; //fac[i]等于i!，inv[i]等于1/i!
    CC(){
        fac[0]=1;
        for(int i=1;i<M;i++)fac[i]=fac[i-1]*i%mod;
        inv[M-1]=poww(fac[M-1],mod-2);
        for(int i=M-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
    ll operator()(ll a,ll b){ //a>=b
        if(a<b||a<0)return 0;
        return fac[a]*inv[a-b]%mod*inv[b]%mod;
    }
}C;   //int c=C(a,b);
*/

/*点P0到线P1,P2的距离
double dist(double x1,double y1,double x2,double y2,double x0,double y0){
    return fabs((y2-y1)*x0+(x1-x2)*y0+(x2*y1)-(x1*y2))/hypot(y2-y1,x1-x2);
}
*/

//freopen("a.in","r",stdin);freopen("a.out","w",stdout);
//priority_queue<ll,vector<ll>,greater<ll> >q;  //(greater) | (less)
//unordered_map<int,int>q;
//map<int,int>::iterator it;
//getline(cin,s);
//reverse(s.begin(),s.end());   //翻转字符串
//floor(); 向下取整 // ceil(); 向上取整
//cnt=__builtin_popcount(x); 计算x的二进制中1的个数
//fflush(stdout); 清空输出缓存区
//s.insert(x); s.erase(it);  //set的插入删除
//lower_bound(begin,end,num); 第一个大于或等于num的数字
//upper_bound(begin,end,num); 第一个大于num的数字,返回地址
//fflush(stdout);能强制把缓存内容输出(加在交互题输出后)
//log(10);        以e为底的对数函数
//log10(100);     以10为底的对数函数
//log(8)/log(2);  计算log2^8,运用换底公式
//exp(1);         计算自然常数e
//数轴上的n个点移动到同一位置，移动到该组数字的中位数的总距离最短
//hypot(double, double); 该函数返回两个参数的平方总和的平方根

//-----------------------------------------------------------------------------------------------------------------------------//

const ll INF=0x7fffffffffffffff;
const int inf=0x7fffffff;
const double eps=1e-9;
const int N=2e5+5;

int T,cas;
int n,m;
ll a[N];
int main()
{
    while(~scanf("%d",&n))
    {
        ll ma=0;
        for(int i=0;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            ma+=a[i];
        }
        ll sum=1,ans=0;
        int vis=1;
        for(int i=0;i<=n;i++)
        {
            ans+=sum;
            ma-=a[i];
            if(sum>=a[i])
            {
                sum-=a[i];
                sum=min(sum<<1,ma);
            }
            else
            {
                vis=0;
                break;
            }
        }
        if(vis==0)
        {
            printf("-1\n");
        }
        else
        {
            printf("%lld\n",ans);
        }
    }
}










Measured memory_bytes: 4544