#ARC139A. [ARC139A] Trailing Zeros

[ARC139A] Trailing Zeros

Score : 300300 points

Problem Statement

For a positive integer xx, let ctz(x)\mathrm{ctz}(x) be the number of trailing zeros in the binary representation of xx. For example, we have ctz(8)=3\mathrm{ctz}(8)=3 because the binary representation of 88 is 1000, and ctz(5)=0\mathrm{ctz}(5)=0 because the binary representation of 55 is 101.

You are given a sequence of non-negative integers T=(T1,T2,,TN)T = (T_1,T_2,\dots,T_N). Consider making a sequence of positive integers A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N) of your choice so that it satisfies the following conditions.

  • A1<A2<<AN1<ANA_1 \lt A_2 \lt \cdots \lt A_{N-1} \lt A_N holds. In other words, AA is strictly increasing.
  • ctz(Ai)=Ti\mathrm{ctz}(A_i) = T_i holds for every integer ii such that 1iN1 \leq i \leq N.

What is the minimum possible value of ANA_N here?

Constraints

  • 1N1051 \leq N \leq 10^5
  • 0Ti400 \leq T_i \leq 40
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

T1T_1 T2T_2 \dots TNT_N

Output

Print the answer.

4
0 1 3 2
12

For example, A1=3,A2=6,A3=8,A4=12A_1=3,A_2=6,A_3=8,A_4=12 satisfy the conditions. A4A_4 cannot be 1111 or less, so the answer is 1212.

5
4 3 2 1 0
31
1
40
1099511627776

Note that the answer may not fit into a 3232-bit integer.

8
2 0 2 2 0 4 2 4
80