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

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

    scanf("%d", &n);

    for (int i = 0; i <=n; i++)
    { //道を読み取る
        scanf("%ld", &lef[i]);
    }
    hutosa[n] = lef[n];

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

    hutosa[0] = 1;
    node[0] = 1;

    if (n == 0 && lef[0] > 0)
    {
        flag =1;
    }
    else {   
        for (int i = 0; i <= n; i++)
        {
            node[i + 1] = (node[i] - lef[i])*2;

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

    node[n] = 0;

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

    printf("\n");
}