

def resolve():

  N = int(eval(input()))

  A = [int(x) for x in input().split(" ")]

  if N == 0 and A[0] != 1:

    print((-1))

    return True

  min_maxs = {}

  min_maxs[len(A)-1] = [A[-1], A[-1]]



  for index in reversed(list(range(len(A)-1))):

    min_maxs[index] = [min_maxs[index+1][0] // 2 + A[index], min_maxs[index+1][1] + A[index]]

  # print(min_maxs)

    # min_maxs.insert(0, [min_maxs[0][0] // 2 + a, min_maxs[0][1] + a])

  # print(min_maxs)

  # max_node_in_depth = [sum(A[i:]) for i in range(len(A))]



  # # 各 depth における最小値

  # min_node_in_depth = [0] * (len(A))

  # min_node_in_depth[-1] = max_node_in_depth[-1]

  # index = -1

  # for i in range(1, len(A)):

  #   min_node_in_depth[index] = -(-min_node_in_depth[index + 1] // 2) + A[index]

  #   index = index - 1



  # for min_max in min_maxs:

  #   print(min_max)



  result = 1

  recent = 1

  for index in range(1, len(A)):

    num_of_node = (recent - A[index-1]) * 2

    # print(min_max, num_of_node)

    if num_of_node < min_maxs[index][0]:

      print((-1))

      return True

    

    result += min(num_of_node, min_maxs[index][1])

    recent = min(num_of_node, min_maxs[index][1])



  print(result)



if __name__ == "__main__":

    resolve()
def resolve():

  N = int(eval(input()))

  A = [int(x) for x in input().split(" ")]

  if N == 0 and A[0] != 1:

    print((-1))

    return True

  min_maxs = [0] * len(A)

  min_maxs[len(A)-1] = [A[-1], A[-1]]



  for index in reversed(list(range(len(A)-1))):

    min_maxs[index] = [min_maxs[index+1][0] // 2 + A[index], min_maxs[index+1][1] + A[index]]



  result = 1

  recent = 1

  for index in range(1, len(A)):

    num_of_node = (recent - A[index-1]) * 2

    if num_of_node < min_maxs[index][0]:

      print((-1))

      return True

    

    result += min(num_of_node, min_maxs[index][1])

    recent = min(num_of_node, min_maxs[index][1])



  print(result)



if __name__ == "__main__":

    resolve()
def resolve():
    N = int(eval(input()))
    A = [int(x) for x in input().split(" ")]
    if N == 0 and A[0] != 1:
        print((-1))
        return True
    min_maxs = {}
    min_maxs[len(A) - 1] = [A[-1], A[-1]]
    for index in reversed(list(range(len(A) - 1))):
        min_maxs[index] = [
            min_maxs[index + 1][0] // 2 + A[index],
            min_maxs[index + 1][1] + A[index],
        ]
    # print(min_maxs)
    # min_maxs.insert(0, [min_maxs[0][0] // 2 + a, min_maxs[0][1] + a])
    # print(min_maxs)
    # max_node_in_depth = [sum(A[i:]) for i in range(len(A))]
    # # 各 depth における最小値
    # min_node_in_depth = [0] * (len(A))
    # min_node_in_depth[-1] = max_node_in_depth[-1]
    # index = -1
    # for i in range(1, len(A)):
    #   min_node_in_depth[index] = -(-min_node_in_depth[index + 1] // 2) + A[index]
    #   index = index - 1
    # for min_max in min_maxs:
    #   print(min_max)
    result = 1
    recent = 1
    for index in range(1, len(A)):
        num_of_node = (recent - A[index - 1]) * 2
        # print(min_max, num_of_node)
        if num_of_node < min_maxs[index][0]:
            print((-1))
            return True
        result += min(num_of_node, min_maxs[index][1])
        recent = min(num_of_node, min_maxs[index][1])
    print(result)


if __name__ == "__main__":
    resolve()

def resolve():
    N = int(eval(input()))
    A = [int(x) for x in input().split(" ")]
    if N == 0 and A[0] != 1:
        print((-1))
        return True
    min_maxs = [0] * len(A)
    min_maxs[len(A) - 1] = [A[-1], A[-1]]
    for index in reversed(list(range(len(A) - 1))):
        min_maxs[index] = [
            min_maxs[index + 1][0] // 2 + A[index],
            min_maxs[index + 1][1] + A[index],
        ]
    result = 1
    recent = 1
    for index in range(1, len(A)):
        num_of_node = (recent - A[index - 1]) * 2
        if num_of_node < min_maxs[index][0]:
            print((-1))
            return True
        result += min(num_of_node, min_maxs[index][1])
        recent = min(num_of_node, min_maxs[index][1])
    print(result)


if __name__ == "__main__":
    resolve()

-    min_maxs = {} +    min_maxs = [0] * len(A) -    # print(min_maxs) -    # min_maxs.insert(0, [min_maxs[0][0] // 2 + a, min_maxs[0][1] + a]) -    # print(min_maxs) -    # max_node_in_depth = [sum(A[i:]) for i in range(len(A))] -    # # 各 depth における最小値 -    # min_node_in_depth = [0] * (len(A)) -    # min_node_in_depth[-1] = max_node_in_depth[-1] -    # index = -1 -    # for i in range(1, len(A)): -    #   min_node_in_depth[index] = -(-min_node_in_depth[index + 1] // 2) + A[index] -    #   index = index - 1 -    # for min_max in min_maxs: -    #   print(min_max) -        # print(min_max, num_of_node)