#abc296e. [abc296_e]Transition Game
[abc296_e]Transition Game
Problem Statement
You are given a sequence of numbers: . Here, each satisfies .
Takahashi and Aoki will play rounds of a game. For each , the -th game will be played as follows.
-
Aoki specifies a positive integer .
-
After knowing Aoki has specified, Takahashi chooses an integer between and , inclusive, and writes it on a blackboard.
-
Repeat the following times.
- Replace the integer written on the blackboard with .
If is written on the blackboard after the iterations, Takahashi wins the -th round; otherwise, Aoki wins.
Here, and can be chosen independently for each .
Find the number of rounds Takahashi wins if both players play optimally to win.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Find the number of rounds Takahashi wins if both players play optimally to win.
Sample Input 1
3
2 2 3
Sample Output 1
2
In the first round, if Aoki specifies , Takahashi cannot win whichever option he chooses for : , , or .
For example, if Takahashi writes on the initial blackboard, the two operations will change this number as follows: , . The final number on the blackboard will be , so Aoki wins.
On the other hand, in the second and third rounds, Takahashi can win by writing and , respectively, on the initial blackboard, whatever value Aoki specifies as .
Therefore, if both players play optimally to win, Takashi wins two rounds: the second and the third. Thus, you should print .
Sample Input 2
2
2 1
Sample Output 2
2
In the first round, Takahashi can win by writing on the initial blackboard if specified by Aoki is odd, and if it is even.
Similarly, there is a way for Takahashi to win the second round. Thus, Takahashi can win both rounds: the answer is .