atcoder#NOMURA2020C. Folia
Folia
Score : points
Problem Statement
Given is an integer sequence of length : . Is there a binary tree of depth such that, for each , there are exactly leaves at depth ? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print .
Notes
- A binary tree is a rooted tree such that each vertex has at most two direct children.
- A leaf in a binary tree is a vertex with zero children.
- The depth of a vertex in a binary tree is the distance from the tree's root to . (The root has the depth of .)
- The depth of a binary tree is the maximum depth of a vertex in the tree.
Constraints
- ()
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
3
0 1 1 2
7
Below is the tree with the maximum possible number of vertices. It has seven vertices, so we should print .
4
0 0 1 0 2
10
2
0 3 1
-1
1
1 1
-1
10
0 0 1 1 2 3 5 8 13 21 34
264