using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;

namespace _200530
{
    using static Ex;
    public class Solve
    {
        public static void Main(string[] args)
        {
            new _200525_C();
        }
    }
    public class _200525_A
    {
        int h1, m1, h2, m2, k;
        public _200525_A()
        {
            (h1, m1, h2, m2, k) = ReadValue<int, int, int, int, int>();

            var a = h2 * 60 + m2 - (h1 * 60 + m1) - k;
            a.Cw();
        }

    }
    public class _200525_B
    {
        public _200525_B()
        {
            string.Join("", Read.Select(v => v == '?' ? 'D' : v)).Cw();

        }

    }
    public class _200525_C
    {
        long n;
        long[] arr;
        long[] sum;
        public _200525_C()
        {
            n = ReadLong;
            arr = ReadLongArray();
            sum = new long[n + 1];
            sum[n] = arr[n];
            for (long i = n - 1; i >= 0; i--)
            {
                sum[i] = arr[i] + sum[i + 1];
            }


            if (n == 0)
            {
                (arr[0] == 1 ? 1 : -1).Cw();
                return;
            }
            else if (arr[0] != 0)
            {
                (-1).Cw();
                return;
            }
            long res = 1;
            long parent = 1;
            for (long i = 1; i <= n; i++)
            {
                if (parent <= 0)
                {
                    (-1).Cw();
                    return;
                }

                var j = Math.Min(sum[i], parent * 2);
                res += j;
                parent = j - arr[i];
            }

            if (parent != 0) (-1).Cw();
            else res.Cw();
            return;
        }

    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }



        public static bool Mins<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
        public static bool Maxs<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
        public static void Swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
        public static void Swap<T>(List<T> list, int i, int j) { T tmp = list[j]; list[j] = list[i]; list[i] = tmp; }


        static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); }
        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
        public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
        public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }

        public static T1 ReadValue<T1>()
        {
            return (T1)Convert.ChangeType(Read, typeof(T1));
        }

        public static (T1, T2) ReadValue<T1, T2>()
        {
            var inputs = ReadArray();
            var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
            var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
            return (v1, v2);
        }
        public static (T1, T2, T3) ReadValue<T1, T2, T3>()
        {
            var inputs = ReadArray();
            var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
            var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
            var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
            return (v1, v2, v3);
        }
        public static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
        {
            var inputs = ReadArray();
            var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
            var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
            var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
            var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
            return (v1, v2, v3, v4);
        }
        public static (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>()
        {
            var inputs = ReadArray();
            var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
            var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
            var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
            var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
            var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
            return (v1, v2, v3, v4, v5);
        }
        public static (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>()
        {
            var inputs = ReadArray();
            var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
            var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
            var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
            var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
            var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
            var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
            return (v1, v2, v3, v4, v5, v6);
        }
    }
}


Measured memory_bytes: 38328