Kostya is going through a series of training sessions, each of which involves solving one problem.
Let be the number of problems he has solved. Each problem has a result:
— correct solution,
— incorrect solution.
The sequence of results is represented by an array a = (a_1, a_2, \dots, a_n), where a_i \in \{0, 1\}.
It is guaranteed that a_n = 1.
For each solution, Kostya receives a certain number of points.
Initially, Kostya has points on his account, and the initial amount of addition or penalty for a solution is s_1 = 1. For each (1 \le i \le n), the update of the account and s_i occurs according to the following rules:
If a_i = 1, then s_i is added to the total account, and for the next task s_{i+1} is set to .
If a_i = 0, then s_i is subtracted from the total account, and for the next task s_{i+1} is set to 2 \cdot s_i.
You need to calculate the final number of points after completing all training sessions.
The first line contains an integer (1 \le n \le 10^5) — the number of problems. The second line contains numbers a_1, a_2, \dots, a_n (a_i \in \{0, 1\}), separated by spaces.
Print one integer — the final number of points after completing all training sessions.
Example 1
Let's see how Kostya's account changes at each step. Initially, his account has points, and the initial value of addition or penalty is s_1 = 1. Next, he sequentially solves the problems:
First problem (a_1 = 1) — correct answer:
Add s_1 = 1 point, the account becomes 0 + 1 = 1.
Since the problem is solved correctly, set s_2 = 1.
Second problem (a_2 = 0) — incorrect answer:
Subtract s_2 = 1 point, the account becomes 1 - 1 = 0.
Since the answer is incorrect, the next penalty value doubles: s_3 = 2 \cdot s_2 = 2.
Third problem (a_3 = 0) — incorrect answer:
Subtract s_3 = 2 points, the account becomes 0 - 2 = -2.
Since the answer is incorrect, the next penalty value doubles: s_4 = 2 \cdot s_3 = 4.
Fourth problem (a_4 = 1) — correct answer:
Add s_4 = 4 points, the account becomes -2 + 4 = 2.
Since the problem is solved correctly, set s_5 = 1.
Fifth problem (a_5 = 1) — correct answer:
Add s_5 = 1 point, the account becomes 2 + 1 = 3.
Tasks are finished, so the final account is 3 points.