indirect enum BinaryTree {
    case node(BinaryTree, Int, BinaryTree)
    case empty

    init(array: [Int]) {
        guard !array.isEmpty else {
            self = .empty
            return
        }

        self = .node(
            .init(array: array, index: 1, depth: 1),
            array[0],
            .init(array: array, index: 2, depth: 1)
        )
    }

    private init(array: [Int], index: Int, depth: Int) {
        if index >= array.count {
            self = .empty
            return
        }
        self = .node(
            .init(array: array, index: index * 2 + 1, depth: depth+1),
            array[index],
            .init(array: array, index: index * 2 + 2, depth: depth+1)
        )
    }

    func count() -> Int {
        switch self {
        case .node(let left, let value, let right):
            var count = 0
            if case .node = left {
                count += value + left.count()
            }
            if case .node = right {
                count += value + right.count()
            }
            return count
        case .empty:
            return 0
        }
    }
 }

let n = readLine()!
var AN = readLine()!.split(separator: " ").compactMap { Int($0) }.sorted(by: { $0 > $1 })
let first = AN[0]
AN.removeFirst()
let binaryTree = BinaryTree(array: AN)
print(first + binaryTree.count())
