#include <stdio.h>
#define N 300000
int main()
{

    int n;
    long long lef[N];
    int flag = 0;
    long long node[N];
    long long hutosa[N];
    long x;

    scanf("%d", &n);

    for (int i = 0; i <=n; i++)
    { //道を読み取る
        scanf("%lld", &lef[i]);
    }
    //ここまでは良い

  
    node[0] = 1;

    if (n == 0)
    {//根がたくさん
        if(lef[0]==1){
            hutosa[0] = 1;
        }
        else flag =1;
    }
    else {   
        for (int i = 0; i <= n; i++)
        {
            node[i + 1] = (node[i] - lef[i])*2;

           // printf("%ld\n", node[i]);

            if (i != n && node[i + 1] <= 0)
            {
                flag = 1; //damejyatta
            }
          //  printf("%d ノードにて太さ%ld\n ",i,hutosa[i]);
        }
    }
    if (flag != 1){
    hutosa[n] = lef[n];
    hutosa[0] = 1;

    hutosa[n] = lef[n];
    for (int i = n - 1; i >= 0; i--)
    { //道を読み取る
        x = hutosa[i + 1];

        if (node[i] < hutosa[i + 1])
        {
            x = node[i];
        }

        if (node[i] < lef[i])
        {
            lef[i] = node[i];
        }


        if (node[i] < lef[i] + x)
        {
            hutosa[i] = node[i];
        }
        else
            hutosa[i] = lef[i] + x;
    }


    node[n] = 0;

    }
    if(flag==1)
        printf("-1");
    else {
        long long ans = 0;
        for (int i = 0; i <= n; i++){
            ans += hutosa[i];
        }
        printf("%lld",ans);
    }

    printf("\n");
}