COCI '25 Contest 1 #5 Zagi
View as PDF
Jakov and Toni, the two best players in the world, will face each other in the finals of the world championship in krastoboj.
Krastoboj is a game played by two players on a sequence of positive integers. The players take turns making moves, and the player who cannot make a move loses the game. At the very beginning, there is only one sequence of positive integers on the board - the initial sequence.
In one move, a player chooses one of the existing sequences and one number that appears in that sequence. Then they delete all occurrences of
in the chosen sequence, thereby splitting the sequence into several new sequences separated at the positions where
appeared.
A sequence of numbers - the template for the final match - has been found. It is known that the initial sequence in the final will be some contiguous subsequence of this template sequence. You are given scenarios. For each scenario, can you determine who the winner will be, assuming that both Toni and Jakov play optimally and that Toni makes the first move?
Input Specification
The first line contains two positive integers and
.
The second line contains a sequence of positive integers
for each
.
The following lines each contain two integers
and
, the boundaries of the contiguous subsequence considered in the
-th scenario.
Output Specification
For each query, print on a separate line either Toni or Jakov, the name of the winner in the -th scenario.
Constraints
| Subtask | Points | Constraints |
|---|---|---|
| No additional constraints. |
Sample Input 1
6 4
1 3 2 3 1 2
1 1
2 3
2 4
1 3
Sample Output 1
Toni
Jakov
Toni
Toni
Explanation for Sample Output 1
In the third scenario, Toni chooses , which splits the sequence into two sequences of length
. Whichever sequence Jakov chooses next, Toni will choose the remaining one, after which Jakov will have no possible moves left.
Sample Input 2
10 5
3 3 3 1 2 2 1 2 2 1
2 3
9 10
5 6
5 8
3 7
Sample Output 2
Toni
Jakov
Toni
Toni
Toni
Comments