#C5776. Reconstruct the Super Binary Tree

    ID: 49462 Type: Default 1000ms 256MiB

Reconstruct the Super Binary Tree

Reconstruct the Super Binary Tree

You are given a complete binary tree in which only the leaf nodes are provided. The number of leaf nodes, n, is guaranteed to be a power of 2. Starting from the leaf nodes, each parent node is computed as the sum of its two children. In other words, if at some level the two adjacent nodes are a and b, then their parent’s value is given by the formula \(P = a + b\). This process is repeated until only one node (the root) remains.

Your task is to compute and output the value of the root node of the tree.

Example:

Input:
4
2 3 5 8

Output: 18

</p>

inputFormat

The first line of input contains a single integer n, which is the number of leaf nodes (a power of 2). The second line contains n space-separated integers representing the values of the leaf nodes.

For example:

4
2 3 5 8

outputFormat

Output a single integer that is the value of the root node after reconstructing the Super Binary Tree.

For example:

18
## sample
4
2 3 5 8
18