CF BUDDY
← Problems·

1556D · Take a Guess

1800 · bitmasks, constructive algorithms, interactive

Problem: This is an interactive task

William has a certain sequence of integers a1,a2,,ana_1, a_2, \dots, a_n in his mind, but due to security concerns, he does not want to reveal it to you completely. William is ready to respond to no more than 2n2 \cdot n of the following questions:

  • What is the result of a bitwise AND of two items with indices ii and jj (iji \neq j)
  • What is the result of a bitwise OR of two items with indices ii and jj (iji \neq j)

You can ask William these questions and you need to find the kk-th smallest number of the sequence.

Formally the kk-th smallest number is equal to the number at the kk-th place in a 1-indexed array sorted in non-decreasing order. For example in array [5,3,3,10,1][5, 3, 3, 10, 1] 44th smallest number is equal to 55, and 22nd and 33rd are 33.

Input Format: It is guaranteed that for each element in a sequence the condition 0ai1090 \le a_i \le 10^9 is satisfied.

Note: In the example, the hidden sequence is [1,6,4,2,3,5,4][1, 6, 4, 2, 3, 5, 4].

Below is the interaction in the example.

Query (contestant's program)Response (interactor)Notesand 2 52a2=6a_2=6, a5=3a_5=3. Interactor returns bitwise AND of the given numbers.or 5 67a5=3a_5=3, a6=5a_6=5. Interactor returns bitwise OR of the given numbers.finish 555 is the correct answer. Note that you must find the value and not the index of the kth smallest number.

Sample Cases

Case 1

Input

7 6

2

7

Output

and 2 5

or 5 6

finish 5

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback