Steven, the monkey, is baking banana bread today!
The recipe for banana bread calls for ingredients numbered from to . The recipe can be modelled as an array of length , where describes the amount for ingredient . Moreover, Steven's special banana bread recipe is a permutation of the first positive integers!
Unfortunately, Steven lost the recipe and doesn't remember the ordering!
Fortunately, Steven had sent his recipe to his friend Tony for safekeeping. However, being a monkey, Tony obfuscated the recipe and tells Steven that he can only ask for the number of inversions present in some subarray of array from to inclusive satisfying . Due to how impatient Tony is, he informs Steven that he can only ask up to questions. Help Steven recover the recipe so he can have dessert tonight!
A pair of indices and in the array is considered an inversion if and .
Array is a permutation of the first positive integers.
This is an interactive problem.
You will start by reading in a single integer , the number of ingredients in the bread.
Note: The grader is NOT adaptive.
After reading , you can start interacting with the interactor.
To ask a query, you must output in the form
? l r to standard output. You will then read a single integer from standard input, which is the number of inversions in the contiguous subarray from to .
To validate your final answer, you must output
! followed by a space, then space-separated numbers, which are the elements of the array . Your program should then terminate immediately.
The output must be flushed after every line is printed, including the last line. In C/C++, you can use
cout << endl, in Java you can use
System.out.flush(), and in Python you can use
At any time, if you ask an invalid query or exceed queries, the interactor will print
-1. Once you read
-1, terminate your program immediately and you will receive a Wrong Answer verdict. Failure to terminate your program may result in an undefined result.
Sample Interaction 1
Note: Do not actually print out
>>> means that the interactor printed out the line, and
<<< means that you printed out the line.
>>> 5 <<< ? 3 4 >>> 0 <<< ? 1 5 >>> 5 <<< ? 2 4 >>> 0 <<< ! 3 2 4 5 1
Explanation for Sample Interaction 1
Our array is and there are inversions. The pairs of indices that form inversions are .
Sample Interaction 2
>>> 3 <<< ? 1 2 >>> 0 <<< ! 1 2 3