import Foundation
let N = Int(readLine()!)!

var leafs: [Int] = readLine()!.split(separator: " ").map { Int($0)! }

resolve(N, leafs)

func powc(_ v: Int, _ k: Int) -> Int {
  if k == 0 {
    return 1
  }
  var res = 1
  for _ in 0..<k {
    res *= v
  } 
  return res
}

func resolve(_ N: Int, _ leafs: [Int]) {
  if N == 0 {
    print(leafs[0] == 1 ? "1" : "-1")
    return
  }

  var childs = leafs[N]
  var res = childs

  for i in (0..<N).reversed() {
    let parents = powc(2, i) - leafs[i]
    if parents * 2 < childs {
      res = -1
      break
    }
    res += childs
    if childs > parents {
      childs = Int(floor(Float(childs) / 2))
    }
    print(parents, childs)
  }
  print(res)
}
