So Mean
Contest: Codeforces Round 618 (Div. 1)
Difficulty rating: 3400
Tags: interactive, math

This problem is interactive.

We have hidden a permutation $$$p_1, p_2, \dots, p_n$$$ of numbers from $$$1$$$ to $$$n$$$ from you, where $$$n$$$ is even. You can try to guess it using the following queries:

$$$?$$$ $$$k$$$ $$$a_1$$$ $$$a_2$$$ $$$\dots$$$ $$$a_k$$$.

In response, you will learn if the average of elements with indexes $$$a_1, a_2, \dots, a_k$$$ is an integer. In other words, you will receive $$$1$$$ if $$$\frac{p_{a_1} + p_{a_2} + \dots + p_{a_k}}{k}$$$ is integer, and $$$0$$$ otherwise.

You have to guess the permutation. You can ask not more than $$$18n$$$ queries.

Note that permutations $$$[p_1, p_2, \dots, p_k]$$$ and $$$[n + 1 - p_1, n + 1 - p_2, \dots, n + 1 - p_k]$$$ are indistinguishable. Therefore, you are guaranteed that $$$p_1 \le \frac{n}{2}$$$.

Note that the permutation $$$p$$$ is fixed before the start of the interaction and doesn't depend on your queries. In other words, interactor is not adaptive.

Note that you don't have to minimize the number of queries.

Input format:
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 800$$$, $$$n$$$ is even).

Interaction format:
You begin the interaction by reading $$$n$$$.

To ask a question about elements on positions $$$a_1, a_2, \dots, a_k$$$, in a separate line output

$$$?$$$ $$$k$$$ $$$a_1$$$ $$$a_2$$$ ... $$$a_k$$$

Numbers in the query have to satisfy $$$1 \le a_i \le n$$$, and all $$$a_i$$$ have to be different. Don't forget to 'flush', to get the answer.

In response, you will receive $$$1$$$ if $$$\frac{p_{a_1} + p_{a_2} + \dots + p_{a_k}}{k}$$$ is integer, and $$$0$$$ otherwise.

In case your query is invalid or you asked more than $$$18n$$$ queries, the program will print $$$-1$$$ and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

When you determine permutation, output

$$$!$$$ $$$p_1$$$ $$$p_2$$$ ... $$$p_n$$$

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.

Hack format

For the hacks use the following format:

The first line has to contain a single integer $$$n$$$ ($$$2 \le n \le 800$$$, $$$n$$$ is even).

In the next line output $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ — the valid permutation of numbers from $$$1$$$ to $$$n$$$. $$$p_1 \le \frac{n}{2}$$$ must hold.

Constraints:
Time limit: 4.0 s
Memory limit: 256.0 MB

Example input:
2
1 2

Example output:
? 1 2
? 1 1
! 1 2

Editorial:
Let's solve this problem in several steps.
1. First, let's ask a query about each group of $$$n-1$$$ numbers. Note that $$$1 + 2 + \dots + (i-1) + (i+1) + \dots + n = \frac{n(n+1)}{2} - i \equiv \frac{1\cdot 2}{2} - i \bmod (n-1)$$$. Therefore, answer will be YES only for numbers $$$1$$$ and $$$n$$$. Find the positions where $$$1$$$ and $$$n$$$ lie, assign one of them to be $$$1$$$ and the other one to be $$$n$$$ (it doesn't matter how to assign $$$1$$$ and $$$n$$$ to these $$$2$$$ spots, as permutations $$$[p_1, p_2, \dots, p_k]$$$ and $$$[n + 1 - p_1, n + 1 - p_2, \dots, n + 1 - p_k]$$$ are indistinguishable). $$$n$$$ queries.
2. Note that knowing $$$1$$$, we can find parity of every other number. Indeed, just ask about $$$1$$$ and $$$p_i$$$, if answer is YES, $$$p_i$$$ is odd, else it is even.$$$n$$$ queries.
3. Suppose that we have found numbers $$$1, 2, \dots, k, n-k+1, n-k+2, \dots, n$$$ at some point. Let's find numbers $$$k+1$$$ and $$$n-k$$$.Consider all numbers except $$$1, 2, \dots, k, n-k+1, n-k+2, \dots, n$$$ now. Ask a query about each subset of $$$n - 2k - 1$$$ numbers among them. Again, we can see that we will get answer YES only when we omit $$$k+1$$$ and $$$n-k$$$. Indeed, $$$k+1 + \dots (i-1) + (i+1) + \dots + (n-k) = k\cdot (n - 2k - 1) + \frac{(n-2k)(n-2k+1)}{2} - (i-k) \equiv 1 - (i-k) \bmod (n-2k-1)$$$, which is $$$0$$$ only for $$$i = k+1$$$ and $$$n-k$$$.Now that we know parities of all numbers, we can distinguish between $$$k+1$$$ and $$$n-k$$$. So, we determined $$$k+1$$$ and $$$n-k$$$ in $$$n - 2k$$$ queries.
4. Note that this already means that we can solve our problem in $$$n + n + (n - 2) + (n - 4) + (n - 6) \dots + (n - (n-2))$$$ queries, which is $$$\frac{n^2 + 6n}{4}$$$ queries. Unfortunately, this is much larger than we are allowed. However, we will use this method for $$$n\le 8$$$.
5. Let's use the procedure above to find numbers $$$1, 2, 3, 4, n-3, n-2, n-1, n$$$. We have used $$$5n - 12$$$ queries by now, but let's round this up to $$$5n$$$. Now, we are going to find the remainders of each element of permutation modulo $$$3$$$, $$$5$$$, $$$7$$$, $$$8$$$. As $$$3\cdot 5 \cdot 7 \cdot 8 = 840 \ge 800 \ge n$$$, we will be able to restore each number uniquely.
6. To find remainders modulo $$$3$$$, we will first ask each number with already found $$$1$$$ and $$$2$$$. We will get YES only for numbers, divisible by $$$3$$$. Next, we will ask each number whose remainder under division by $$$3$$$ we haven't yet found with $$$1$$$, $$$3$$$. This way we find all the numbers which give the remainder $$$2$$$. All others give the remainder $$$1$$$.We spend $$$n + \frac{2n}{3}$$$ queries.
7. Similarly, we find remainders mod $$$5$$$ and mod $$$7$$$. For mod $$$5$$$, at step $$$i$$$ ask each number whose remainder we don't know yet with $$$n, n-2, n-3, i$$$ (for $$$i$$$ from $$$1$$$ to $$$4$$$). We spend $$$n + \frac{4n}{5} + \frac{3n}{5} + \frac{2n}{5}$$$ queries.For mod $$$7$$$, first ask all numbers whose remainders we don't know yet with $$$\{1, 2, 3, n-3, n-2, n-1\}$$$, then with $$$\{1, 2, 3, n-3, n-2, n\}$$$, $$$\{1, 2, 3, n-3, n-1, n\}$$$, $$$\{1, 2, 3, n-2, n-1, n\}$$$, $$$\{1, 2, 4, n-2, n-1, n\}$$$, $$$\{1, 3, 4, n-2, n-1, n\}$$$ (sums of all these sets are different mod $$$7$$$).We spend $$$n + \frac{6n}{7} + \dots + \frac{2n}{7}$$$ queries.
8. Now time to find remainders mod $$$4$$$. We already know all remainders mod $$$2$$$. To distinguish $$$4k$$$ from $$$4k+2$$$, ask with $$$1, 2, 3$$$. To distinguish $$$4k+1$$$ from $$$4k+3$$$, ask with $$$1, 2, 4$$$.We spend $$$n$$$ queries.Now time to find remainders mod $$$8$$$. We already know all remainders mod $$$4$$$. Similarly, to distinguish $$$8k$$$ from $$$8k+4$$$, ask with $$$n, n-1, n-2, n-3, 1, 2, 3$$$, $$$\dots$$$, to distinguish $$$8k+3$$$ from $$$8k+7$$$, ask with $$$n, n-1, n-2, n-3, 1, 2, 4$$$.We spend $$$n$$$ queries.
Overall, we spend $$$5n + (n + \frac{2n}{3}) + (n + \frac{4n}{5} + \frac{3n}{5} + \frac{2n}{5}) + (n + \frac{6n}{7} + \dots + \frac{2n}{7}) + n + n \sim 15.324 n$$$.
Note that this bound is easy to optimize (for example, determine all remainders mod $$$3$$$ and $$$4$$$ from $$$1, 2, n, n-1$$$, and after that check only candidates which work mod $$$12$$$ in phase $$$5$$$. This will reduce the number of operations to $$$13.66 n$$$ operations. Of course, a lot of other optimizations are possible.