Photo by Epauwels. License: CC BY-SA 4.0.
Beer Pong is a popular drinking game between two teams. Each
team starts with $10$ cups and takes turns
throwing a ping pong ball into the opposing team’s cups. In the
very first round, the first team is chosen at random and throws
the ball once. In each of the following rounds, teams alternate
and throw the ball twice. When a cup is hit, it is removed from
the game. As soon as one team is reduced to $0$ cups, the current round ends
and the game stops immediately.
The score is a pair $a$, $b$ of integers, the number of cups of
team A and B, respectively. You have implemented an automatic
beer pong score sensor system that records the score after each
round. Check whether the output history is valid, i.e., whether
the given sequence of scores could possibly have been the
result of recording a beer pong score after each round. The
game need not have finished.
Input
-
One line with the number $n\in \{ 1, \ldots , 100\} $ of
recorded rounds,
-
$n$ lines, the
$i$th of which
contains a pair $a_i, b_i\in
\{ 0,\ldots , 10\} $ of integers, the score after
round $i$.
Output
Output “finished” if the record describes a valid and
finished game. Output “ongoing” if the record describes a valid
game that is not yet finished. Output “invalid” if the record
does not describe a valid game.
Sample Input 1 |
Sample Output 1 |
11
9 10
9 10
7 10
7 9
5 9
5 8
3 8
3 8
1 8
1 7
0 7
|
finished
|
Sample Input 2 |
Sample Output 2 |
2
10 10
10 8
|
ongoing
|
Sample Input 3 |
Sample Output 3 |
1
8 10
|
invalid
|
Sample Input 4 |
Sample Output 4 |
2
9 10
8 10
|
invalid
|
Sample Input 5 |
Sample Output 5 |
3
9 10
9 9
10 9
|
invalid
|
Sample Input 6 |
Sample Output 6 |
11
9 10
9 8
7 8
7 6
5 6
5 4
3 4
3 2
1 2
1 0
0 0
|
invalid
|