Problem list
Log in
#coci00703 · COCI 2025/2026 Contest 1

Zagi

Unrated 3.0 s 512 MB

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 $x$ that appears in that sequence. Then they delete all occurrences of $x$ in the chosen sequence, thereby splitting the sequence into several new sequences separated at the positions where $x$ 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 $q$ 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

The first line contains two positive integers $n$ and $q$ ($1 \le n$, $q \le 10^{5}$). The second line contains a sequence of positive integers $a_{1}$, $a_{2}$, . . . , $a_{n}$ ($1 \le a_{i} \le 32$ for each $i = 1$, 2, . . . , n). The following $q$ lines each contain two integers $l_{i}$ and $r_{i}$ ($1 \le l_{i} \le r_{i} \le n$), the boundaries of the contiguous subsequence considered in the $i$-th scenario.

Output

For each query, print on a separate line either Toni or Jakov, the name of the winner in the $i$-th scenario.

Example 1

Input
6 4
1 3 2 3 1 2
1 1
2 3
2 4
1 3
Output
Toni
Jakov
Toni
Toni

Example 2

Input
10 5
3 3 3 1 2 2 1 2 2 1
2 3
9 10
5 6
5 8
3 7
Output
Toni
Jakov
Toni
Toni
Toni

Clarification of the first example: In the third scenario, Toni chooses x = 2, which splits the sequence into two sequences of length 1. Whichever sequence Jakov chooses next, Toni will choose the remaining one, after which Jakov will have no possible moves left.

Source
COCI 2025/2026 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code