F. The Carthaginian Cipher
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem

In ancient Carthage, scholars created a secret numerical cipher to protect their most valuable trade secrets. This cipher, believed to be a function $$$f$$$, that maps each natural number to a secret value, was known only to the High Council of Merchants. The cipher was lost when Rome destroyed Carthage in 146 BC.

For centuries, archaeologists have searched for the legendary "Stone of Accounts", the key to unlocking this ancient secret.

Recently, in the ruins of ancient Carthage near modern-day Tunis, you've discovered the fabled Stone of Accounts! It's a mysterious device with two input slots and one output display. Ancient Punic inscriptions explain how it works: "Place two numbered stones in the slots. If their numbers sum to a power of two, the stone reveals the sum of their hidden values. Otherwise, it reveals nothing."

Formally, The Stone accepts two positive integers $$$n$$$ and $$$m$$$:

  • If $$$n+m$$$ is a power of two, it outputs $$$f(n)+f(m)$$$
  • Otherwise, it outputs $$$0$$$
Here, $$$f$$$ is the lost Carthaginian cipher

Centuries ago, archaeologists discovered ancient Carthaginian scrolls containing encrypted trade secrets: $$$S=[S_1,\dots,S_n].$$$ For generations, scholars have tried to decipher them, but without the Stone of Accounts, all attempts failed.

Now, with the Stone finally discovered, you have a chance to succeed where others could not.

Your mission: Recover the true message $$$M=[f(S_1),\dots,f(S_n)].$$$ But be careful! The Stone is ancient and fragile. You can use it at most 10,000 times before it breaks forever.

Input
  1. The first line contains one integer $$$1 \le n \le 100$$$, denoting the length of the encrypted message.
  2. The second line contains $$$n$$$ integers $$$1 \le S_1,\dots,S_n \le 10^{18}$$$, denoting the encrypted message.
Interaction

Your program will interact via standard input/output with the black box.

Starting from $$$i=1$$$, two modes of operations are supported:

  1. Query the Stone, ? n m: You give two positive integers $$$1 \le n,m \lt 2^{64}$$$ to the Stone. The Stone responds with R s where:
    • $$$s=f(n)+f(m)$$$ if $$$n+m$$$ is power of two
    • $$$s=0$$$ otherwise
  2. Declare a Decrypted Value, ! d: This means you've determined that $$$d=f(S_i)$$$. After this command:
    • You receive N.
    • You move to the next encrypted number: $$$i\leftarrow i+1$$$
    • When all numbers are decrypted, your program can exit.
Example
Input
3
1 3 4
R 0
R 2
N
R 4
N
R 8
N


Output
? 1 2
? 1 1
! 1
? 3 1
! 3
? 4 4
! 4
Note
  • It is guaranteed that $$$f$$$ exists and is unique.
  • It is guaranteed that: $$$$$$ \forall n \in \mathbb{N}, \quad f(n) \le 10^{18} $$$$$$