Under construction

Still being built. Things may change

Try XORing This Too

Time limit2sMemory limit1024 MB

Summary
Find the weight of each of n coins, where the weights are exactly 1 to k, by querying the XOR of two disjoint subset sums at most n-1 times.
Level

Medium7 of 10

Topics
Bit manipulation, Math, Implementation
Solved
No attempts yet

Statement

Coin collector Seungjae had sorted his coins by weight. Then a cat appeared, mixed the coins up at random, and vanished after saying, "Try XORing this too!" Unable to lose to a mere cat, Seungjae decided to sort the coins again using an XOR scale he built himself.

The XOR scale is a modified balance. It weighs each side separately and returns the XOR of the two weights. However, something went wrong during the modification, and if either side is empty, the scale does not work.

The coins Seungjae collected follow a few rules.

  1. He collected the coins in order from 1 g upward. So if the maximum weight of a coin is kk g, then for every integer pp with 1≤p≤k1 \leq p \leq k, there is a coin weighing pp g.
  2. kk is not of the form 2×2m−22 \times 2^m-2 (m≥2m \geq 2). He does not remember the exact value of kk.
  3. The coins are labeled from 00 to n−1n-1.

Use these conditions to help Seungjae sort all the coins.

Input

The first line contains the number of coins nn. (k≤n≤10 000)(k \leq n \leq 10\,000) The coins are labeled from 00 to n−1n-1.

The maximum weight kk is not given. (3≤k≤1 000(3 \leq k \leq 1\,000, k≠2×2m−2k \neq 2 \times 2^m-2, m≥2)m \geq 2)

Output

Print the following to standard output (stdout), one per line, to learn the XOR of the total coin weights.

  • ?? a0a_0 ⋯\cdots ai−1a_{i-1} −1-1 b0b_0 ⋯\cdots bj−1b_{j-1} −1-1: Uses the XOR scale to output (ca0+⋯+cai−1)⊕(cb0+⋯+cbj−1)(c_{a_0} + \cdots + c_{a_{i-1}}) \oplus (c_{b_0} + \cdots + c_{b_{j-1}}). cqc_q is the weight of coin qq. The indices a0,⋯ ,ai−1,b0,⋯ ,bj−1a_0, \cdots, a_{i-1}, b_0, \cdots, b_{j-1} are distinct coin labels. (i≥1,j≥1,i+j≤n)(i \geq 1, j \geq 1, i+j \leq n)

After each query, you must flush the standard output buffer, then read the answer from standard input (stdin). Otherwise you get Time Limit Exceeded or Runtime Error.

If any index in a query is outside the range of coin labels, you get Wrong Answer.

You may make at most n−1n-1 queries. Making more queries gives Wrong Answer.

Using at most n−1n-1 queries, print the answer exactly once to standard output (stdout):

  • !! c0c_0 ⋯\cdots cn−1c_{n-1}: Prints the weights of all coins in order.

Then flush the standard output buffer and end the program. This output does not count toward the query limit.

Hint

Flush the standard output buffer after printing the output. Flush methods by language:

  • C: fflush(stdout)
  • C++: std::cout << std::flush
  • Java: System.out.flush()
  • Python: sys.stdout.flush()

Examples1

  1. Example 1

    Input
    5
    
    12
    
    11
    
    Expected output
    
    ? 1 2 -1 3 4 -1
    
    ? 0 1 4 -1 2 -1
    
    ! 1 2 3 4 5