atcoder#MSOLUTIONS2019F. Random Tournament
Random Tournament
Score : points
Problem Statement
We will host a rock-paper-scissors tournament with people. The participants are called Person , Person , , Person . For any two participants, the result of the match between them is determined in advance. This information is represented by positive integers ( ) as follows:
- If , Person defeats Person .
- If , Person defeats Person .
The tournament proceeds as follows:
- We will arrange the participants in a row, in the order Person , Person , , Person from left to right.
- We will randomly choose two consecutive persons in the row. They will play a match against each other, and we will remove the loser from the row. We will repeat this process times, and the last person remaining will be declared the champion.
Find the number of persons with the possibility of becoming the champion.
Constraints
- is or .
Input
Input is given from Standard Input in the following format:
Output
Print the number of persons with the possibility of becoming the champion.
3
0
10
2
Person defeats Person , Person defeats Person and Person defeats Person . If Person and Person play the first match, Person will become the champion. If Person and Person play the first match, Person will become the champion.
6
0
11
111
1111
11001
3