# Pack the Polyominoes (Reflections Allowed)

## Problem
You are given a set of n polyominoes placed on a unit square grid. Each polyomino consists of between 1 and 10 unit cells, connected edge-to-edge (4-connectivity). Your task is to place all polyominoes—allowing **rotations, reflections, and translations**—into an axis-aligned rectangle of the grid with no overlaps and no cells outside the rectangle, minimizing the rectangle’s area.

A placement specifies, for every polyomino, an integer translation, an optional reflection, and a rotation by a multiple of 90°, such that:

- every cell lands on integer grid coordinates,
- no two placed cells overlap,
- all placed cells lie within a single axis-aligned rectangle of width W and height H.

The objective is to minimize A = W × H. In case of ties on area, prefer smaller H, then smaller W.

---

## Input Format
- Line 1: integer n (100 <= n <= 10^4) — number of polyominoes.
- For each polyomino i = 1 … n:
  - One line: integer kᵢ (1 ≤ kᵢ ≤ 10) — number of cells.
  - Next kᵢ lines: two integers xᵢⱼ, yᵢⱼ — cell coordinates in the polyomino’s local frame.
    These coordinates define a 4-connected polyomino.

Notes:
- Coordinates may be negative.
- Shapes may have internal holes.
- Shapes are defined by structure; initial placement does not matter.

---

## Output Format
- Line 1: two integers W and H — width and height of the chosen rectangle.
- Then n lines — one per polyomino i, each containing:
$$X_i\ Y_i\ R_i\ F_i$$

Where:
- (Xᵢ, Yᵢ): integer translation
- Rᵢ ∈ {0,1,2,3}: number of 90° clockwise rotations
- Fᵢ ∈ {0,1}: reflection flag (**1 = reflect across the y-axis before rotation**, 0 = no reflection)

All transformed cells must satisfy:
0 ≤ xᵢⱼ′ < W, 0 ≤ yᵢⱼ′ < H, W=H

---

## Rules
1. All cells occupy unit squares with integer coordinates.
2. **Allowed transforms: reflection (optional) → rotation (0°, 90°, 180°, 270°) → translation (in that order).**
3. Distinct polyomino cells must not overlap.
4. Every cell must lie inside [0, W) × [0, H).
5. Scoring: Minimize A = W × H.

---

## Constraints
- 100 ≤ n ≤ 10000
- 1 ≤ kᵢ ≤ 10

---

## Validation
A solution is valid if:
- All rules are satisfied.
- The judge verifies non-overlap and bounding-box compliance.

---

## Scoring (for heuristic / leaderboard contests)
- Per test case: score = 1e5*Σkᵢ/A
- Any invalid test case → entire submission rejected

---

## Example

Input
```
3
1
0 0
3
0 0
1 0
0 1
4
0 0
1 0
0 1
1 1
```

Output
```
3 3
0 0 0 0
2 0 1 0
1 1 0 0
```

This places the monomino at (0,0), rotates the triomino by 90° (R=1), and fits all shapes into a 3×3 rectangle. (Reflections are allowed, but not used in this example: F=0.)

---

## Generation

Let $S$ be the set of all pieces from size 1-10. Each piece is chosen uniformly at random with replacement from $S$.

$n$ is chosen as $10^p$, where $p \sim U(2, 4)$.

type: default
checker: chk.cc

# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 256m

# The subtasks section works the same way
subtasks:
- score: 100
  n_cases: 70


Problem F: Treasure Packing

A dragon has terrorized the region for decades, breathing fire and stealing treasures. A hero has decided to steal back the treasures and return them to the community. However, they drastically underestimated the size of the dragon's hoard, bringing only a single 25 liter bag, only strong enough to hold 20 kg, to carry out the treasures. The hero has decided to try to return as much value as possible. The dragon has 12 different types of items of different values, masses, and volumes: crowns, figurines, jeweled goblets, gold helms, etc., where each item of the same type has the same mass and volume. For example, all goblets have the same mass and volume. Write a program helping the hero determine what items they should put in the bag so as to maximize value accounting for the constraints on the bag.

Input
The input is JSON keyed by treasure category name, such as "goblet". Every category has a unique name composed of at most 100 lowercase ASCII characters. There are exactly twelve treasure categories. Each corresponding value is a list with one integer q (1 <= q <= 10000) and three integers v (0 < v <= 10^9), m (0 < m <= 20 * 10^6), and l (0 < l <= 25 * 10^6), where q is the maximum number of treasures of this category that can be looted, v is the value of one item, m is the mass (in mg) of one item, and l the volume (in µliters) of one item. (There are one million mg per kg and µliters per liter.)

Please see the sample input for an example of how the JSON is formatted.

Output
Print a JSON with the same keys as the input, but with single a nonnegative integer values giving the numbers of items of that category added to the bag in your solution.

Scoring
Producing an algorithm that always generates optimal solutions is very difficult, so your solution only needs to be "good enough". We will compare your output to a baseline heuristic provided by the NSA, and to a best effort to compute the true optimum. You must beat the NSA heuristic to receive points; after that, the better your solution, the higher your score. Specifically, your score on this problem is your average of the per-test-case score.

100 * clamp((your value - baseline value) / (best value - baseline value), 0, 1).

Time limit:
1 second

Memoriy limit:
1024 MB

Sample input:
{
    "circlet": [
        19,
        113005,
        146800,
        514247
    ],
    "coppercoin": [
        887,
        6171,
        12593,
        18081
    ],
    "crown": [
        13,
        726439,
        1079353,
        1212213
    ],
    "dagger": [
        21,
        279513,
        558367,
        522344
    ],
    "figurine": [
        18,
        26272,
        1488281,
        2295986
    ],
    "goblet": [
        22,
        300053,
        698590,
        986387
    ],
    "goldcoin": [
        129,
        14426,
        82176,
        27597
    ],
    "helm": [
        3,
        974983,
        2470209,
        882803
    ],
    "jewelry": [
        23,
        272450,
        171396,
        262226
    ],
    "plate": [
        22,
        98881,
        246257,
        363420
    ],
    "silvercoin": [
        288,
        12587,
        53480,
        28654
    ],
    "torc": [
        17,
        244957,
        388222,
        500000
    ]
}

Sample Output:
{
 "circlet": 2,
 "coppercoin": 8,
 "crown": 13,
 "dagger": 0,
 "figurine": 0,
 "goblet": 0,
 "goldcoin": 0,
 "helm": 0,
 "jewelry": 23,
 "plate": 0,
 "silvercoin": 1,
 "torc": 4
}

type: default
# The time limit is now 1 second.
time: 1s
memory: 1024m
# A custom checker is required for the special scoring.
checker: chk.cc
subtasks:
  - score: 100
    n_cases: 3


Problem: Tree distance

Time limit: 2 second

Memory limit: 512 MB

This is an interactive problem.

Little Cyan Fish has a weighted tree of n verticies generated in the following way:
- First, generate a random labeled tree: uniformly randomly select from all nn−2 possible labeled trees.
- Then, independently assign random integer edge weights in the range [1, K] to each edge, where K is a hidden parameter.

You cannot directly observe the structure of the tree or the edge weights, but Little Cyan Fish grants
you a superpower: querying! Each time, you can query the distance between two vertices. Specifically, you
can choose two vertices u, v (1 \leq u, v \leq n, u \neq v), and we will tell you the distance between these two
vertices (i.e., the sum of the edge weights on the simple path connecting these two vertices).

Now, Little Cyan Fish wants you to determine all the edges and their weights within queries as less as you can.

Scoring

The score is calculated based on the linear formula determined by the range [5n, Z]:
- Score = 100 * (Z - Q) / (Z - 5n)

Interaction Protocol

Each test case contains multiple sets of test data. First, you need to read an integer T (1 \leq T \leq 10^4)
indicating the number of data sets.
For each set of test data, you first need to read an integer n (1 \leq n \leq 10^5).
Next, the interaction process begins. To
make a query, you need to output a line “? u v” (1 \leq u, v \leq n, u \neq v), describing a query. Then, you need
to read the result from standard input.
To provide your answer, you need to output “! u_1 v_1 w_1 u_2 v_2 w_2··· u_{n−1} v_{n−1} w_{n−1}”. You can output
these edges in any order. The output of the answer will not count towards the n * n / 3 query limit. After you
output the answer, you need to immediately read the next set of test data or terminate your program.
After outputting a query, do not forget to output a newline character and flush the output stream.
To do this, you can use fflush(stdout) or cout.flush() in C++, System.out.flush() in Java,
flush(output) in Pascal, or stdout.flush() in Python.
It is guaranteed that 1 \leq K \leq 10^4, and the sum of all n in the test data does not exceed 10^5.

In this problem, it is guaranteed that the interaction library is non-adaptive. That is, the shape of the
tree and the edge weights are determined before the interaction process. They will not change with your
queries.

Example input:
2
3

3

4

7

4

3

7

2

4

5

9

Example Output:

? 1 2

? 2 3

? 1 3

! 1 2 3 2 3 4

? 1 2

? 2 3

? 2 4

? 1 3

? 1 4

? 3 4

! 1 2 3 1 3 4 2 4 2

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cc

# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 512m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


Problem Name: Circuit

Description:
You are given a circuit board consisting of N component slots and R external switches.
Each slot contains either an AND gate (&) or an OR gate (|). The actual type of each slot is hidden.
Your task is to determine the true type of every slot by interacting with the judge.

Specifications of the Circuit Board:
- The board consists of 2N+1 switches numbered 0..2N, each with an ON/OFF state, outputting 0 or 1.
- The board also consists of N component slots numbered 0..N-1, each outputting 0 or 1.
- The outputs are determined from the highest index down to 0, according to the following rules:
  * For j = 2N, 2N-1, ..., N:
    - If switch j is OFF, it outputs 0.
    - If switch j is ON, it outputs 1.
  * For j = N-1, N-2, ..., 0:
    - Let the output of slot j be x.
    - If switch j is OFF, it outputs x.
    - If switch j is ON, it outputs 1-x.
  * For i = N-1, N-2, ..., 0:
    - Slot i is connected to two switches Ui, Vi (i < Ui < Vi ≤ 2N).
    - If slot i is AND, it outputs min(output(Ui), output(Vi)).
    - If slot i is OR, it outputs max(output(Ui), output(Vi)).

- For each j = 1..2N, exactly one slot i satisfies Ui=j or Vi=j.
- The output of the circuit is defined as the output of switch 0.

Interaction:
At the beginning of the interaction, the judge prints N and R, followed by N lines each containing Ui Vi.
This describes the wiring of the board. Then your program must interact as follows:

1. Query:
   You may print a line of the form: "? s"
   where s is a binary string of length 2N+1. Each character sets the ON/OFF state of the corresponding switch.
   The judge replies with a single line containing 0 or 1, the output of the circuit (switch 0).

2. Answer:
   When you have determined the types of all slots, you must print a line of the form: "! t"
   where t is a string of length N, each character being & or |, representing your guess of the hidden circuit.
   If your guess is completely correct, the judge accepts. Otherwise, you receive Wrong Answer.

Constraints:
- 1 ≤ N ≤ 8000
- 1 ≤ R ≤ min(N, 120)
- i < Ui < Vi ≤ 2N for all 0 ≤ i < N
- For each j=1..2N, exactly one i satisfies Ui=j or Vi=j
- At most 5000 queries may be made. Exceeding this limit results in Wrong Answer.

Special Requirement:
- Your program must be written in C++.

Scoring:
- If the number of queries ≤ 900, you receive full score (100 points).
- If the number of queries ≥ 5000, you receive 0 points.
- Otherwise, the score is computed by linear interpolation:
  Score = (5000 - queries) / (5000 - 900) * 100

Sample Interaction:

Suppose the input file contains:
3 2
3 4
2 4
0 1
&&|

The judge first outputs:
3 2
3 4
2 4
0 1

(Here the hidden true circuit is T = "&&|".)

Then the interaction may proceed as follows (lines beginning with '#' are explanations):

? 01001
# Player asks a query with binary string s.
1
# Judge replies that the circuit output is 1.

? 11111
# Another query.
0
# Judge replies with 0.

! &&|
# Player outputs the final answer.
# The hidden circuit matches the answer, so the judge accepts.

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cpp

# Time and memory limits still apply to the contestant's solution
time: 5s
memory: 1024m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


Time Limit: 2 s
Memory Limit: 256 MB
This is an interactive problem.
There are n students, having roll numbers 1 to n. Mr. 1048576 knows that exactly 1 student is absent today. In order to determine who is absent, he can ask some queries to the class. In each query, he provide two integers l and r (1≤l≤r≤n) and all students whose roll numbers are between l and r (inclusive) are expected to raise their hands.
But the students are dishonest. Some students whose roll numbers lie in the given range may not raise their hands, while some other students whose roll number does not lie in the given range may raise their hands. But only the following 4 cases are possible for a particular query (l,r) —
1. True Positive: r−l+1 students are present and r−l+1 students raised their hands.
2. True Negative: r−l students are present and r−l students raised their hands.
3. False Positive: r−l students are present but r−l+1 students raised their hands.
4. False Negative: r−l+1 students are present but r−l students raised their hands.
In the first two cases, the students are said to be answering honestly, while in the last two cases, the students are said to be answering dishonestly. The students can mutually decide upon their strategy, not known to Mr. 1048576. Also, their strategy always meets the following two conditions —
1. The students will never answer honestly 3 times in a row.
2. The students will never answer dishonestly 3 times in a row.
Mr. 1048576 is willing to mark at most 2 students as absent (though he knows that only one is). The attendance is said to be successful if the student who is actually absent is among those two. Also, he can only ask up to 2* ⌈log_{1.116}n⌉ queries. Help him complete a successful attendance.

Interaction
First read a line containing a single integer t (1≤t≤2048) denoting the number of independent test cases that you must solve.
For each test case, first read a line containing a single integer n (5≤n≤10^5). Then you may ask up to 2* ⌈log_{1.116}n⌉ queries.
Your score is inversely linear related to the max number of queries.
To ask a query, print a single line in the format "? l r" (without quotes) (1≤l≤r≤n). Then read a single line containing a single integer x (r−l≤x≤r−l+1) denoting the number of students who raised their hands corresponding to the query.
To mark a student as absent, print a single line in the format "! a" (without quotes) (1≤a≤n). Then read a single integer y (y∈{0,1}). If the student with roll number a was absent, y=1, else, y=0. Note that this operation does not count as a query but you can do this operation at most 2 times.
To end a test case, print a single line in the format "#" (without quotes). Then you must continue solving the remaining test cases.
The sum of n over all test cases does not exceed 10^5.
To flush the buffer, use fflush(stdout) or cout.flush()
The answer may change depending on your queries but will always remain consistent with the constraints and the answer to the previous queries.
Example
input
2
5
3
2
1
2
0
1
0
2
0
1
6
6
2
2
0
1
1
0
0
0
1
output
? 1 4
? 3 5
? 2 2
? 1 3
? 3 3
? 3 3
! 3
? 2 4
? 4 4
! 2
#
? 1 6
? 1 3
? 4 6
? 1 1
? 3 3
? 5 5
! 3
? 2 2
? 4 4
! 4
#

type: interactive
time: 2s
memory: 256m
# A custom checker is required for the special scoring.
checker: interactor.cc
subtasks:
  - score: 100
    n_cases: 3


Hidden Bipartite Graph

This is an I/O interactive problem. I/O interaction refers to interactive problems, where the program communicates with a special judge during execution instead of producing all output at once. In these problems, the program sends queries (output) to the judge and must immediately read responses (input) before continuing. The solution must strictly follow the input-output protocol defined in the problem statement, because any extra output, missing flush, or incorrect format can cause a wrong answer. Unlike standard problems, interactive problems require careful handling of I/O, synchronization, and flushing to ensure smooth communication between the contestant’s code and the judge.

Bob has a simple undirected connected graph (without self-loops and multiple edges). He wants to learn whether his graph is bipartite (that is, you can paint all vertices of the graph into two colors so that there is no edge connecting two vertices of the same color) or not. As he is not very good at programming, he asked Alice for help. He does not want to disclose his graph to Alice, but he agreed that Alice can ask him some questions about the graph.
The only question that Alice can ask is the following: she sends s — a subset of vertices of the original graph. Bob answers with the number of edges that have both endpoints in s. Since he doesn't want Alice to learn too much about the graph, he allows her to ask no more than 50000 questions.
Furthermore, he suspects that Alice might introduce false messages to their communication channel, so when Alice finally tells him whether the graph is bipartite or not, she also needs to provide a proof — either the partitions themselves or a cycle of odd length.
Your task is to help Alice to construct the queries, find whether the graph is bipartite. Let q be the number of queries you asked, your score will be (5000 - q) / 5000.

Input

The first line contains a single integer n (1 ≤ n ≤ 600) — the number of vertices in Bob's graph.

Interaction

First, read an integer n (1≤ n ≤ 600) — the number of vertices in Bob's graph.
To make a query, print two lines. First of which should be in the format "? k" (1 ≤ k ≤ n), where k is the size of the set to be queried. The second line should contain k space separated distinct integers s1, s2, ..., sk (1 ≤ si ≤ n) — the vertices of the queried set.

After each query read a single integer m (0 ≤ m ≤ n(n-1)/2) — the number of edges between the vertices of the set {si}.
You are not allowed to ask more than 50000 queries.

If m = -1, it means that you asked more queries than allowed, or asked an invalid query. Your program should immediately terminate (for example, by calling exit(0)). You will receive Wrong Answer; it means that you asked more queries than allowed, or asked an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.
After printing a query do not forget to print 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.

When you know the answer, you need to print it.

The format of the answer depends on whether the graph is bipartite or not.
If the graph is bipartite, print two lines. The first should contain the letter "Y" (short for "YES") followed by a space, and then a single integer s (0 ≤ s ≤ n) — the number of vertices in one of the partitions. Second line should contain s integers a1, a2, ..., as — vertices belonging to the first partition. All ai must be distinct, and all edges in the main graph must have exactly one endpoint in the set {ai}.
If the graph is not bipartite, print two lines. The first should contain the letter "N" (short for "NO") followed by a space, and then a single integer l (3 ≤ l ≤ n) — the length of one simple cycle of odd length. Second line should contain l integers c1, c2, ..., cl — the vertices along the cycle. It must hold that for all 1 ≤ i ≤ l, there is an edge {ci, c_{(i mod l)+1}} in the main graph, and all ci are distinct.
If there are multiple possible answers, you may print any of them.

Examples

Input

    4
    4
    0
    1
    1
    1
    0

Output
    ? 4
    1 2 3 4
    ? 2
    1 2
    ? 2
    1 3
    ? 2
    1 4
    ? 2
    2 4
    ? 2
    3 4
    Y 2
    1 2

Input

    4
    4
    3

Output

    ? 4
    1 4 2 3
    ? 3
    1 2 4
    N 3
    2 1 4

Note
In the first case, Alice learns that there are 4 edges in the whole graph. Over the course of the next three queries, she learns that vertex 1 has two neighbors: 3 and 4. She then learns that while vertex 2 is adjacent to 4, the vertex 3 isn't adjacent to 4. There is only one option for the remaining edge, and that is (2, 3). This means that the graph is a cycle on four vertices, with (1, 2) being one partition and (3, 4) being the second.
Here, it would be also valid to output "3 4" on the second line.
In the second case, we also have a graph on four vertices and four edges. In the second query, Alice learns that there are three edges among vertices (1, 2, 4). The only way this could possibly happen is that those form a triangle. As the triangle is not bipartite, Alice can report it as a proof. Notice that she does not learn where the fourth edge is, but she is able to answer Bob correctly anyway.

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cpp

# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


F. Guess Divisors Count

time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

This is an I/O interactive problem. I/O interaction refers to interactive problems, where the program communicates with a special judge during execution instead of producing all output at once. In these problems, the program sends queries (output) to the judge and must immediately read responses (input) before continuing. The solution must strictly follow the input-output protocol defined in the problem statement, because any extra output, missing flush, or incorrect format can cause a wrong answer. Unlike standard problems, interactive problems require careful handling of I/O, synchronization, and flushing to ensure smooth communication between the contestant’s code and the judge.

We have hidden an integer 1 ≤ X ≤ 10^9. You don't have to guess this number. You have to find the number of divisors of this number, and you don't even have to find the exact number: your answer will be considered correct if its absolute error is not greater than 7 or its relative error is not greater than 0.5.
More formally, let your answer be ans and the number of divisors of X be d, then your answer will be considered correct if at least one of the two following conditions is true:
  * | ans - d | ≤ 7;
  * 1/2 ≤ ans / d ≤ 2.

You can make at most 100 queries. One query consists of one integer 1 ≤ Q ≤ 10^18. In response, you will get gcd(X, Q) — the greatest common divisor of X and Q.

The number X is fixed before all queries. In other words, interactor is not adaptive.
Let's call the process of guessing the number of divisors of number X a game. In one test you will have to play T independent games, that is, guess the number of divisors T times for T independent values of X. Let q be the maximum number of queries you asked among all games, your score will be (100 - q) / 100.

Input

The first line of input contains one integer T (1 ≤ T ≤ 100) — the number of games.

Interaction

To make a query print a line "0 Q" (1 ≤ Q ≤ 10^18). After that read one integer gcd(X, Q). You can make no more than 100 such queries during one game.
If you are confident that you have figured out the number of divisors of X with enough precision, you can print your answer in "1 ans" format. ans have to be an integer. If this was the last game, you have to terminate the program, otherwise you have to start the next game immediately. Note that the interactor doesn't print anything in response to you printing answer.

After printing a query do not forget to output end of line and flush the output. 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.

Example
Input (from interactor to you)

    2

    1

    1

    1

    1024

    1048576

    4194304

Output (from you to interactor)

    0 982306799268821872

    0 230856864650023977

    0 134690134760714371

    1 5
    0 1024

    0 1048576

    0 1073741824

    1 42

Note

Let's look at the example.
In the first game X = 998244353 is hidden. Would be hard to guess this, right? This number is prime, so the number of its divisors is 2. The solution has made several random queries, and all the responses turned out to be 1 (strange things, not even one of three random numbers is divisible by 998244353). It's fare to assume that the hidden number doesn't have many divisors, so the solution has answered 5. Why not. This answer will be considered correct since | 5 - 2 | = 3 ≤ 7.
In the second game X = 4,194,304 = 2^22 is hidden, it has 23 divisors. The solution has made queries 1024 = 2^10, 1,048,576 =2^20, 1,073,741,824 = 2^30 and got responses 1024 = 2^10, 1,048,576 =2^20, 4,194,304 = 2^22, respectively. Then the solution got completely confused and answered the answer to The Ultimate Question of Life, the Universe, and Everything.
This answer will be considered correct since 1/2 ≤ 42 / 23 ≤ 2.

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cpp

# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 256m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


time limit per test: 1 second
memory limit per test: 256 megabytes
This is an interactive problem.
Zookeeper has set up a special lock for the rabbit enclosure.
The lock consists of n concentric rings numbered from 0 to n−1. The innermost ring is ring 0 and the outermost ring is ring n−1. All rings are split equally into n*m sections each. Each of those rings contains a single metal arc that covers exactly m contiguous sections. At the center of the ring is a core and surrounding the entire lock are n*m receivers aligned to the n*m sections.
The core has n*m lasers that shine outward from the center, one for each section. The lasers can be blocked by any of the arcs. A display on the outside of the lock shows how many lasers hit the outer receivers.
For example, there are n=3 rings, each covering m=4 sections. There are n*m=12 sections. The ring 0 covers sections 0, 1, 2, 3, the ring 1 covers sections 1, 2, 3, 4, and ring 2 covers sections 7, 8, 9, 10. Three of the lasers (sections 5, 6, 11) are not blocked by any arc, thus the display will show 3 in this case.
Wabbit cannot see where any of the arcs are. Given the relative positions of the arcs, Wabbit can open the lock on his own.
To be precise, Wabbit needs n−1 integers p_1,p_2,…,p_{n−1} satisfying 0≤p_i<n*m such that for each i (1≤i<n), Wabbit can rotate ring 0 clockwise exactly p_i times such that the sections that ring 0 covers perfectly aligns with the sections that ring i covers. In the example above, the relative positions are p_1=1 and p_2=7.
To operate the lock, he can pick any of the n rings and rotate them by 1 section either clockwise or anti-clockwise. You will see the number on the display after every rotation.
Wabbit has asked you to help him to find the relative positions of the arcs after all of your rotations are completed. You may perform up to 30000 rotations before Wabbit gets impatient, and your score is inversely linear related to the max number of queries.

Input
The first line consists of 2 integers n and m (2≤n≤100,2≤m≤20), indicating the number of rings and the number of sections each ring covers.

Interaction
To perform a rotation, print on a single line "? x d" where x (0≤x<n) is the ring that you wish to rotate and d (d∈{−1,1}) is the direction that you would like to rotate in. d=1 indicates a clockwise rotation by 1 section while d=−1 indicates an anticlockwise rotation by 1 section.
For each query, you will receive a single integer a: the number of lasers that are not blocked by any of the arcs after the rotation has been performed.
Once you have figured out the relative positions of the arcs, print ! followed by n−1 integers p_1,p_2,…,p_{n−1}.
Do note that the positions of the rings are predetermined for each test case and won't change during the interaction process.
After printing a query do not forget to output the end of line and flush the output. Use fflush(stdout) or cout.flush() to flush.

Example
Input
3 4
4
4
3
Output
? 0 1
? 2 -1
? 1 1
! 1 5

Note
For the first test, the configuration is the same as the example form the statement.
After the first rotation (which is rotating ring 0 clockwise by 1 section), we have the ring 0 covers sections 1, 2, 3, 4, the ring 1 covers sections 1, 2, 3, 4, and ring 2 covers sections 7, 8, 9, 10. The sections 0, 5, 6, 11 are not blocked by any arc.
After the second rotation (which is rotating ring 2 counter-clockwise by 1 section), we have the ring 0 covers sections 1, 2, 3, 4, the ring 1 covers sections 1, 2, 3, 4, and ring 2 covers sections 6, 7, 8, 9. The sections 0, 5, 10, 11 are not blocked by any arc.
After the third rotation (which is rotating ring 1 clockwise by 1 section), we have the ring 0 covers sections 1, 2, 3, 4, the ring 1 covers sections 2, 3, 4, 5, and ring 2 covers sections 7, 8, 9, 10. The sections 0, 6, 11 are not blocked by any arc.
If we rotate ring 0 clockwise once, we can see that the sections ring 0 covers will be the same as the sections that ring 1 covers, hence p_1=1.
If we rotate ring 0 clockwise five times, the sections ring 0 covers will be the same as the sections that ring 2 covers, hence p_2=5.
Note that if we will make a different set of rotations, we can end up with different values of p_1 and p_2 at the end.

type: interactive
time: 1s
memory: 256m
# A custom checker is required for the special scoring.
checker: interactor.cc
subtasks:
  - score: 100
    n_cases: 3


Time Limit: 1 second
Memory Limit: 128 MB

Description
A knight moves on an N×N chessboard and must try to visit every square exactly once (no revisiting). Given the board size and the starting square, output the longest possible path.
Note that this problem doesn't require a full complete path. It only asks you to find the longest path possible, and output that path.

Constraints
- 6 ≤ N ≤ 666

Input
- The first line contains the integer N.
- The second line contains two integers r c — the starting position (row and column), 1-indexed.

Output
- The first line of output should be an integer l: the length of the path you found(remember to include r0, c0)
- Then output l lines. Each line must contain two integers r c (1-indexed), the successive positions visited by the knight, starting with the given starting position.
When outputting the answer, make sure to not have an extra empty line at the end of the output after printing out the final move.
- The first pair of coordinates in your path must be the starting points r0 and c0.

Sample Input
6
1 1

Sample Output
36
1 1
3 2
5 1
6 3
5 5
3 6
2 4
1 6
3 5
5 6
4 4
5 2
3 1
1 2
3 3
2 1
1 3
2 5
4 6
6 5
5 3
6 1
4 2
5 4
6 6
4 5
6 4
4 3
6 2
4 1
2 2
1 4
2 6
3 4
1 5
2 3

type: default
time: 1s
memory: 128m

checker: chk.cc

subtasks:
  - score: 100
    n_cases: 3     # auto-picks 1.in…10.in and (logically) 1.out…10.out,
                    # but your JudgeEngine first tries "X.ans" before "X.out".


# Palindrome Path

**Input file:** standard input
**Output file:** standard output
**Time limit:** 1 second
**Memory limit:** 256 megabytes

## Problem Description

Given an \( n \times m \) grid maze, each cell \((i,j)\) is either blank or blocked. George starts at cell \((sr,sc)\) and needs to visit all blank cells in the maze, finally ending at the exit cell \((er,ec)\). George can perform four types of moves, denoted as "L" (left), "R" (right), "U" (up), and "D" (down). When attempting a move, if the adjacent cell in that direction is blank and within bounds, George moves to it; otherwise, he stays in the current cell.

The move sequence must be a palindrome. That is, if the sequence is \( M_1, M_2, \cdots, M_k \) where each \( M_i \in \{L, R, U, D\} \), then for every \( i \) from 1 to \( k \), \( M_i = M_{k-i+1} \).

Your task is to find such a palindrome move sequence that visits all blank cells and ends at the exit cell. If multiple solutions exist, print any one. If no solution exists, output "-1". You need to minimize the number of moves.

Scoring:
Clamp(1.0 - (your sequence length - bound) / bound, 0, 1) where bound is a defined reachable solution number

## Input Format

The first line contains two integers \( n \) and \( m \) (\( 1 \leq n, m \leq 30 \)), the dimensions of the maze.

The next \( n \) lines each contain a binary string of length \( m \). A "1" indicates a blank cell, and a "0" indicates a blocked cell.

The following line contains four integers \( sr \), \( sc \), \( er \), \( ec \) (\( 1 \leq sr, er \leq n \), \( 1 \leq sc, ec \leq m \)), representing the start and exit cells. It is guaranteed that both cells are blank.

## Output Format

If a solution exists, print a string \( S \) (\( 0 \leq |S| \leq 10^6 \)) of moves on one line. If no moves are needed, output an empty line. If no solution exists, output "-1" on one line.

Do not include any extra spaces at the end of your output.

## Examples

### Example 1
**Input:**
```
2 2
11
11
1 1 2 2
```
**Output:**
```
RDLUULDR
```

**Explanation:**
The move sequence "RDLUULDR" results in the following path:
- Move right from (1,1) to (1,2)
- Move down from (1,2) to (2,2)
- Move left from (2,2) to (2,1)
- Move up from (2,1) to (1,1)
- Attempt up from (1,1) but stay (since i=1)
- Attempt left from (1,1) but stay (since j=1)
- Move down from (1,1) to (2,1)
- Move right from (2,1) to (2,2)

All blank cells are visited, and the path ends at (2,2).

### Example 2
**Input:**
```
2 2
10
01
1 1 2 2
```
**Output:**
```
-1
```

**Explanation:** George cannot reach (2,2) from (1,1) due to blocked cells.

## Constraints
- \( n, m \leq 30 \)
- The number of blank cells is at most \( 30 \times 30 = 900 \).
- The move sequence length must not exceed \( 10^6 \).

## Notes
- The start cell is considered visited at the beginning.
- If no moves are required (e.g., start and exit are the same, and only one blank cell), output an empty string.
- Ensure the output sequence is a palindrome and satisfies the visiting condition.

type: default

time: 2s
memory: 512m

checker: chk.cc
cheker_type: testlib
subtasks:
  - score: 100
    n_cases: 3


TIME LIMIT: 1 minute
MEMORY LIMIT: 814 MB

Description
Create and print an 8 × 14 table (grid) whose cells contain only digits 0–9. We say a number can be “read” from the grid if it can be formed as follows:

- Start at any cell in the grid.
- Move to an adjacent cell each step, where adjacency includes up, down, left, right, and the four diagonals (8 directions in total).
- Append the digit in each visited cell, in order, to form the number.

Additional rules:
- You may revisit cells you have previously visited while forming a number.
- You may not skip over cells (i.e., you cannot move to a non-adjacent cell in one step).
- You may not remain in the same cell to append additional digits without moving (i.e., no “stay” moves).

Example (conceptual, 2 × 3 grid):
Starting at a cell containing 1, moving down, then right, then up-left, then left, you could form 12314, so the number 12,314 is readable on that grid. If you begin at the cell with 4 and traverse the reverse path, you could read 41,321. However, you cannot jump to skip cells (so 46 would be unreadable if it requires a jump), and you cannot repeatedly stay on one cell (so 11 would be unreadable if it requires staying).

Input
There is no input. DO NOT TRY TO READ INPUT. WE WILL GIVE YOU THE WRONG ANSWER VERDICT.

Output
Print an 8 × 14 grid consisting only of digits 0–9.

Scoring
If every integer from 1 up to X (inclusive) can be read from your printed grid, but X+1 cannot, then your score is X.

Sample Output
10203344536473
01020102010201
00000000008390
00000000000400
00000000000000
55600000000089
78900066000089
00000789000077

Explanation of Sample
For the grid above, all integers from 1 through 112 can be read, but 113 cannot, so the score is 112.

NOTE: THE CODE IS REQUIRED, NOT THE ACTUAL OUTPUT, AND YOU CODE HAS 1 MINUTE TO GENERATE AN 8X14 GRID. AND DO NOT JUST HAVE THE CODE PRINT OUT A GRID YOU PREDETERMINED.


Problem: Distinct Pairwise XOR Set

Time Limit: 1 second
Memory Limit: 512 MB

Description
Given an integer n, find a subset S ⊆ {1, 2, ..., n} such that:
1) For all pairs (a, b) with a, b ∈ S and a < b, the values (a XOR b) are all distinct (i.e., no two different unordered pairs produce the same XOR).
2) |S| ≥ floor(sqrt(n / 2)).

Input
A single integer n (1 ≤ n ≤ 10^7).

Output
- First line: an integer m — the size of the set S.
- Second line: m distinct integers in the range [1, n] — the elements of S, in any order.

Notes
- Any valid S is accepted. You do NOT need to maximize m; you only need m ≥ floor(sqrt(n/2)).
- The pairwise XOR distinctness means the set {a_i XOR a_j | 1 ≤ i < j ≤ m} has size m*(m-1)/2.
- Multiple correct outputs may exist for the same n.
- Print out the sequence with the longest length.

Sample
Input
49
Output
4
1 2 3 4


SphereSpread

You are given an integer n. You need to place n points in 3D space such that all points lie within or on
a unit sphere centered at the origin (i.e., the distance from each point to the origin is at most 1).

Your goal is to maximize the minimum pairwise distance between any two points. In other words, you want
to spread the points out as much as possible, maximizing the distance between the closest pair.

Input
The first line contains a single integer n — the number of points to place.

Output
On the first line, print a single real number min_dist — the minimum pairwise distance achieved by your
point placement.
The next n lines should each contain three real numbers xi, yi, zi — the coordinates of the i-th point.

All coordinates must satisfy xi² + yi² + zi² ≤ 1 (the point lies within or on the unit sphere).

Constraints
2 <= n <= 1000

Your answer will be accepted if:
- All points are within or on the unit sphere (with absolute or relative error at most 10^-9)
- The actual minimum pairwise distance matches your claimed min_dist (with absolute or relative error at most 10^-6)

Scoring
You will be graded based on the minimum pairwise distances you achieve.
To be more specific, your answer will be compared to a reference solution ref_answer.
Your final score will be calculated as the average of 100 * min(your_answer / ref_answer, 1) across all test cases.

Time limit: 2 seconds

Memory limit: 512 MB

Sample Input:
2

Sample Output:
2
0 0 1
0 0 -1

type: default
time: 2s
memory: 512m
checker: chk.cc
subtasks:
  - score: 100
    n_cases: 3


Problem
There are $N$ balls numbered from $1$ to $N$, and three baskets numbered from $1$ to $3$. Initially, all $N$ balls are in basket $1$.

Balls can be moved from one basket to another according to the following rules:

When the balls in a basket are arranged in numerical order, the ball in the middle is called the center ball.
If the number of balls is even, the center ball is the one with the larger number between the two middle balls.
When moving a ball from basket $a$ to basket $b$, the center ball of basket $a$ must be moved to basket $b$, and the moved ball must become the center ball of basket $b$.
Using this rule, output the process of moving all $N$ balls from basket $1$ to basket $3$.

Input
The first line contains the number of balls $N$. ($1 \le N \le 30$)

Output
The first line should output the number of moves $M$.
The next $M$ lines should each contain two integers $a$ and $b$, separated by a space. ($1 \le a, b \le 3; a \ne b$) This indicates that the $i$-th operation moves a ball from basket $a$ to basket $b$ according to the problem's rules.

After the output, all balls originally in basket $1$ must be moved to basket $3$.

type: default
time: 1s
memory: 512m
subtasks:
  - score: 100
    n_cases: 3
checker: chk.cc
checker_type: testlib
filename: std.cc


Line

The territory of country P is a square with side length 2 * 10^12.
The origin is placed at the center of the square, and a Cartesian coordinate system is established so that the sides of the square are parallel to the axes.
Thus, the territory of country P is the region [-10^12, 10^12] × [-10^12, 10^12].

There are N lines on this territory, each of the form y = a_i * x + b_i.
Both a_i and b_i are unknown integers between -10^4 and 10^4.
You do not know their values.

Your task is to recover all these N lines.
To do this, you may ask the king up to Q_max queries of the following type:

- You give a point (x, y), and the king tells you the sum of the distances from (x, y) to all N lines.

You need to recover all the lines by making no more than Q_max queries.

Input

The only line of input contains one integer n.

Implementation details

You may issue queries by writing to standard output lines of the form

    ? x y

This query sends the interactor a query point (x, y).
You must ensure that (x, y) is inside the region [-10^12, 10^12] × [-10^12, 10^12], x and y do not have to be integers.
The interactor returns the sum of distances from (x, y) to all N lines.
You may call this function at most Q_max times.

You must also make a guess exactly once of the form

    ! a_1 a_2 ... a_n b_1 b_2 ... b_n

You may output the lines in any order.

Subtasks and scoring

If your program fails the time limit (1.0 s), memory limit (256 MiB),
or produces wrong output, the score for that test point is 0.

Otherwise, let Q be the number of queries you made and S be the full score of that test point:

- If Q > Q_max, score = 0.
- If Q_min < Q <= Q_max, score = S * (1 - 0.7 * (Q - Q_min) / (Q_max - Q_min)).
- If Q <= Q_min, score = S.

Constraints:
1 <= N <= 100
-10^4 <= a_i, b_i <= 10^4
Q_max = 10^4, Q_min = 402
No two lines are parallel.

Time limit: 1 second
Memory limit: 256 MB

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cpp

# Time and memory limits still apply to the contestant's solution
time: 1s
memory: 256m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


Operators

-   You are given n operators op₁, op₂, …, opₙ. For an input sequence of
    n+1 integers a₀, a₁, …, aₙ, you need to compute the following value:
    (((…(a₀ op₁ a₁) op₂ a₂) op₃ a₃)… opₙ aₙ) mod (10⁹ + 7).
-   For any 0 ≤ i ≤ n, we have 0 ≤ aᵢ < 10⁹ + 7.
-   For any 1 ≤ i ≤ n, opᵢ ∈ {+, ×}; that is, each operator is either
    addition “+” or multiplication “×”.

You quickly wrote a program to solve this problem. Unfortunately,
because you were over‑excited after solving it, you accidentally deleted
the original problem statement and your code. As a result, you lost the
information about the n operators op₁, …, opₙ. Fortunately, you still
have the program you just compiled, so you can recover these operators
by querying your program.

Since the contest is about to end, and the program you wrote is not
efficient enough, you cannot ask more than Qₘₐₓ = 600 queries.

Implementation details

This is an interactive problem. As usual, you should submit a source code file that can compile.

Initially, you should read an integer n, the number of operators.

You may issue queries by writing to standard output lines of the form

? a₀ a₁ … aₙ

1 <= a_i < 10^9+7

Then you must flush output, and read from standard input one integer in [0, 10⁹ + 6], representing the interactor’s response.

When you have determined the operators, output a line of the form

! o₁ o₂ … oₙ

o_i is 0 if op_i is "+", is 1 if op_i is "×".

Remember to flush after your output.

Subtasks

-   For all data, 1 ≤ n ≤ 600.
-   Let your program make Q queries:
    -   If your program exceeds time limit, memory limit, or returns
        incorrect answer → score=0.
    -   Otherwise, your score depends on Q:
        -   score(Q) = 41 / (Q + 1)
        -   In other words, a solution with Q ≤ 40 is awarded the full score.

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cpp

# Time and memory limits still apply to the contestant's solution
time: 1s
memory: 512m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


“Da Bai” (Interactive)

There is an undirected simple graph with 100 vertices.

In each query, you can ask the interactor by choosing three distinct vertices a, b, c.
The interactor will tell you how many edges exist among the three vertices {a, b, c}, i.e., the number of edges in the induced sub-graph on {a, b, c}. The answer will be an integer in {0, 1, 2, 3}.
You must ensure that a, b, c are pairwise distinct.

Your goal: reconstruct the entire graph.

Implementation details

This is an interactive problem. As usual, you should submit a source code file that can compile.
Initially, you should read no input.

You may issue queries by writing to standard output lines of the form

? a b c

Then you must flush output, and read from standard input one integer in [0, 3], representing the interactor’s response.

When you have determined the graph, output a line

!

Then output 100 lines, each with a length-100 binary string s_i (i from 1 to 100), describing the graph. Here s_{i,j} = ‘1’ if and only if there is an edge between vertex i and j in the graph.
Remember to flush after your output.

Sample
For convenience, in this sample we assume the graph has only **4** vertices. (In actual tests the graph has 100 vertices.)

Contestant prints     | Interactor replies
---------------------|--------------------
`? 1 2 3`             | 0
`? 1 2 4`             | 2
`? 1 3 4`             | 2
`!`                  |
0001
0001
0001
1110

Constraints
- All test instances have exactly 100 vertices.
- Let Q = the number of queries you make.
  - If your program exceeds time limit, memory limit, or returns incorrect answer → score=0.
  - Otherwise, your score depends on Q:
    - score(Q) = 3400 / (Q + 1)
    - In other words, a solution with Q < 3400 is awarded the full score.


DNA Matching

Time Limit: 2 s
Memory Limit: 512 MB

A string s is called a “DNA sequence” if and only if s consists only of the characters A, C, G, T.

You are given m strings s1, s2, ..., sm, each of length n, and each of them consists only of the characters A, C, G, T, ?.

For a DNA sequence t of length n, we call t valid if and only if there exists an index i (1 ≤ i ≤ m) and a way to replace each ? in si by one of A,C,G,T, so that after replacement the resulting string s_i' is exactly equal to t.

You need to compute the probability that a randomly chosen DNA sequence t (of length n, where each of the 4^n possible DNA sequences is equally likely) is valid.

Input Format
The first line contains two positive integers n, m.
Then follow m lines, each line contains a string si of length n. It is guaranteed that each si only uses characters from A, C, G, T, ?.

Output Format
Output one real number — the probability. Make sure the number is precise enough.

Sample 1
input
3 1
AC?
output
0.0625

Sample 2
input
6 2
AC??A?
A??A?T
output
0.0302734375

# Set the problem type to interactive
type: default

# Specify the interactor source file
interactor: chk.cc

# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 512m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


This is an interactive problem.

The RiOI Team has recently developed a text editor named RiOI Editor. The editor works with exactly one integer parameter W
 — the width of each line. It is known that 1≤W≤10^5
.

As you cannot understand the RiOI Language, from your point of view, words differ from each other only by their length. Hence, an article of length n
 is defined as a sequence a
 consisting of n
 positive integers, where ai
 is the length of the i
-th word in the article. The RiOI Editor displays the article [a1,a2,…,an]
 on screen as follows:

If max(a1,a2,…,an)>W
, the editor is unable to display the article;
Otherwise, the editor is able to display the article by the following process:
Initially, l=1
, and s=0
. During the whole process, l
 always denotes the current number of lines in the editor, and s
 always denotes the sum of lengths of words in the last line;
Then, for each 1≤i≤n
:
If s+ai≤W
, the word is inserted at the end of the current line. Thus, l
 remains unchanged, and s
 gets increased by ai
.
Otherwise, the word is inserted into a new line. Thus, l
 becomes l+1
, and s
 becomes ai
.
The number of lines needed to display the article is the final value of l
.
You are very interested in the editor, so you decide to find out the value of W
 by inputting some articles into the editor and observing the number of lines needed to display each article.

Formally, you can query the jury at most 2
 times. In each query, you input an article [a1,a2,…,an]
 (1≤n≤10^5
) to the editor, and the jury will respond to you with:

The number of lines needed to display the article, if the editor is able to display it;
0
, if the editor is unable to display the article.
Input
Each test contains multiple test cases. The first line contains the number of test cases t
 (1≤t≤10
). The description of the test cases follows.

Interaction
For each test case, you can make up to 2
 queries to find out the value of W
. It is guaranteed that 1≤W≤10^5
.

To make a query, you should print a new line in the following format:

? n a1 a2 … an
 (1≤n,ai≤10^5
) — the article you input to the editor.
At the end of each query, the jury will print an integer, as described in the statements.

You need to minimize the sum of length of the articles in your queries. That is, the sum of n in your queries. A smaller sum will result in a better score.

To report that you have found the value of W
, print a new line in the following format:

! W
 — the parameter of the editor.
Printing the answer does not count as one of the 2
 queries.

After that, proceed to process the next test case or terminate the program if it was the last test case.

After printing each query do not forget to output the end of line and flush∗
 the output. Otherwise, you will get Idleness limit exceeded verdict.

If, at any interaction step, you read −1
 instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

type: interactive
time: 3s
memory: 512m
subtasks:
  - score: 100
    n_cases: 3
interactor: interactor.cc
checker_type: testlib


Time limit per test: 1 second
Memory limit per test: 256 megabytes

Goal
-----
There is a hidden integer x with 1 ≤ x ≤ n that you must determine.

What you can do
----------------
1) Ask membership questions (up to 53 total):
   - Choose any non-empty set S ⊆ {1, 2, …, n}.
   - Ask whether x ∈ S.
   - The judge replies “YES” if x ∈ S, otherwise “NO”.

2) Make guesses (up to 2 total):
   - Output a single number as your guess for x.
   - The reply is always truthful:
     • “:)” if your guess equals x (you must terminate immediately).
     • “:(” if your guess is wrong.

Noisy answers & guarantee
--------------------------
- Not all “YES”/“NO” answers are guaranteed to be truthful.
- However, for every pair of consecutive questions, at least one answer is correct.
- This remains true across guesses: if you ask a question, then make a guess, then ask another question, the “consecutive questions” rule applies to those two questions surrounding the guess.
- Guesses themselves are always judged correctly.

Adaptive x
----------
- The judge does not fix x in advance; it may change over time.
- Changes are constrained so that all previous responses remain valid and consistent with:
  • the rule “for each two consecutive questions, at least one answer is correct,” and
  • the correctness of guess judgments.

Input
-----
- A single integer n (1 ≤ n ≤ 100000), the maximum possible value of x.

Interactive protocol (I/O format)
----------------------------------
To ask a question about a set S:
- Print a line: “? k s1 s2 … sk”
  • k = |S| (k ≥ 1)
  • s1, s2, …, sk are distinct integers in [1, n]
- Flush output immediately.
- Read a single word reply: “YES” or “NO”.

To make a guess for x:
- Print a line: “! g” where g is your guess (1 ≤ g ≤ n).
- Flush output immediately.
- Read the judge’s reply:
  • “:)” if correct — your program must terminate immediately.
  • “:(” if incorrect — you may continue if you still have remaining queries/guesses.

Flushing
--------
After every printed line, flush the output to avoid idleness/timeout:
- C++: fflush(stdout) or cout.flush()
- Java: System.out.flush()
- Pascal: flush(output)
- Python: sys.stdout.flush()
- See language docs for others.

Limits
------
- Maximum questions: 53
- Maximum guesses: 2
- n up to 100000

Important notes
----------------
- Because at least one of every two consecutive question answers is correct, you can design strategies that compare adjacent answers to filter lies.
- Guesses are always reliable; use them sparingly (you only have 2).
- Note that this problem has a scoring system. You are graded based on the # of queries you use. The lower the # of queries you use, the higher the score you get.

Example
--------
Input
  6

(Sequence of interactions as seen by the contestant)
  ? 5 1 2 5 4 3
  NO
  ! 6
  :(
  ? 4 1 2 3 4
  NO
  ! 5
  :)

Explanation
- If the first question’s “NO” had been truthful, x would have to be 6.
- The guess “! 6” receives “:(“, so 6 is not the answer. Therefore, the first answer must have been a lie.
- By the guarantee, the next question’s answer must then be truthful.
- From “? 4 1 2 3 4” with reply “NO”, we conclude x ∉ {1,2,3,4}; combined with “6 is wrong”, x must be 5.
- The final guess “! 5” is confirmed with “:)”.

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cc

# Time and memory limits still apply to the contestant's solution
time: 4s
memory: 1024m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


AveragePermutation

This is an interactive problem.

There is a hidden permutation p of n, where n is even. You want to discover this permutation using queries.
Each query consists of asking about k specific positions a1, a2, ..., ak. The query is answered with 1 if the average of the elements at these positions is an integer, and 0 otherwise.
Note that permutations [p1, p2, ..., pn] and [n+1-p1, n+1-p2, ..., n+1-pn] are indistinguishable using these queries. Therefore, you are guaranteed that p1 ≤ n/2.
This problem is graded based on the number of queries you use. Specifically, your answer will be compared to a reference solution ref_queries.
Your final score will be calculated as the average of 100 * min((ref_queries + 1) / (your_queries + 1), 1) across all test cases.

Input
The first line of the input contains an even integer n (2 ≤ n ≤ 800) indicating the length of the hidden permutation.

Interaction
To ask a query, output one line. First output ? followed by a space, then print an integer k (1 ≤ k ≤ n), then print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) separated by spaces. After flushing your output, your program should read a single integer (0 or 1) indicating whether the average is an integer.
If you want to guess the permutation, output one line. First output ! followed by a space, then print a permutation of n separated by spaces, satisfying the constraint that p1 ≤ n/2. After flushing your output, your program should exit immediately.

Note that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.

To flush your output, you can use:
    fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.
    System.out.flush() in Java.
    stdout.flush() in Python.

Time limit: 4 seconds
Memory Limit: 256 MB

Example input:

? 2 1 2

! 1 3 2

Example output:
3

1

type: interactive

interactor: interactor.cc

time: 4s
memory: 256m

subtasks:
  - score: 100
    n_cases: 3


Time Limit: 1 second
Memory Limit: 256 MB

Overview
This is an INTERACTIVE PROBLEM. There are N kinds of minerals. For each kind there are exactly 2 slices, for a total of 2N slices numbered 1..2N. The judge fixes a hidden pairing: for each kind, the two slices of that kind form one pair. Your task is to determine all N pairs.

You have access to a device. You may insert or extract slices from the device one at a time. After each operation, you learn how many DISTINCT kinds of minerals are currently present among the slices inside the device.

Goal
Determine all N pairs while MINIMIZING the number of queries you use. You may use at most 1,000,000 queries. Any correct solution using ≤ 1,000,000 queries is accepted; fewer queries are considered better.

Interaction Protocol (standard input/output)
1) At the start, the judge outputs a single integer:
   N
   • 1 ≤ N ≤ 43,000.

2) You may then repeatedly perform queries. To toggle the presence of slice x in the device:
   • Output a line:  ? x
     where 1 ≤ x ≤ 2N
   • Flush stdout.
   • Read a single integer r from stdin.
     r is the number of DISTINCT kinds currently present among all slices inside the device after this toggle:
       – If x was not in the device, it is now inserted.
       – If x was already in the device, it is extracted.
       – r counts how many mineral kinds appear at least once among the slices currently in the device.

3) When you have determined a pair (a, b), output exactly one line:
   • Output:  ! a b
     where 1 ≤ a ≤ 2N and 1 ≤ b ≤ 2N.
   Over the entire run you must output exactly N such lines, and together they must use each index 1..2N exactly once.

4) Order is flexible:
   • You may interleave “? x” queries and “! a b” answers in any order.
   • The judge terminates the interaction immediately after reading the N-th valid “! a b” line. Do not send any further output after that point.

Important Rules and Constraints
• Only print lines of the form “? x” and “! a b”.
• Indices in queries and answers must satisfy their ranges.
• Exactly N answer lines must be printed and together cover each index 1..2N exactly once.
• A “query” is defined as one printed line “? x”. You may perform at most 1,000,000 queries.
• Flush stdout after every line you print (interactive).
• If you violate the protocol (bad format, invalid index, wrong pairings, too many queries, wrong number of answers), the judge will return a Wrong Answer verdict with a message.

Device Behavior (for clarity)
• The device maintains a set S of slices currently inside.
• Query “? x” toggles membership of x in S:
  – If x ∉ S, insert x.
  – Else (x ∈ S), remove x.
• The judge replies with r = number of DISTINCT mineral kinds represented by S. If S is empty, r = 0.

Scoring / Ratio (informative)
• Let Q be your total number of “? x” queries.
• The judge also knows an optimal_queries value for the instance.
• Your ratio is (1,000,000 − Q) / (1,000,000 − optimal_queries).
• The judge reports this ratio and scores only on Accepted submissions.

Sample Communication
Judge → program:
4

Program → judge:
? 1
Judge → program:
1

Program → judge:
? 2
Judge → program:
2

Program → judge:
? 5
Judge → program:
2

Program → judge:
? 2
Judge → program:
1

Program → judge:
! 3 4
Program → judge:
! 5 1
Program → judge:
! 8 7
Program → judge:
! 2 6

(Here, the program used 4 queries total.)

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cc

# Time and memory limits still apply to the contestant's solution
time: 20s
memory: 256m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


Time Limit: 1 second
Memory Limit: 256 mb

Interactive Problem

YOU MUST USE INTERACTIVE FORMAT FOR THIS PROBLEM.

You are standing in front of a row of n boxes, labeled 0 through n−1 from left to right.
Each box contains a prize that cannot be seen until the box is opened. There are v ≥ 2
different prize types, numbered from 1 to v in decreasing order of value:
type 1 is the most expensive (the diamond), and type v is the cheapest (a lollipop).
There is exactly one diamond in the boxes.

The number of cheaper prizes is much larger than the number of more expensive ones.
More precisely, for all 2 ≤ t ≤ v: if there are k prizes of type t−1, then there are
strictly more than k^2 prizes of type t.

Your task is to find the index i of the box containing the diamond using as few
queries as possible.

-------------------------------------------------------------------------------
Input
-------------------------------------------------------------------------------
Standard input (stdin) initially contains a single integer:
  n  — the number of boxes.

Box indices are 0-based: 0, 1, …, n−1.

-------------------------------------------------------------------------------
Interaction protocol (stdin/stdout)
-------------------------------------------------------------------------------
Your program communicates using standard input and standard output only.
There is no provided procedure to call; write a normal main program.

To ask about a box i (0 ≤ i < n):
  • Print a line:   ? i
  • Flush the output stream immediately.

Then read from stdin two integers a0 and a1 (on the same line):
  • a0  — among the boxes strictly to the left of i, the number of boxes that
           contain a more expensive prize than the one in box i.
  • a1  — among the boxes strictly to the right of i, the number of boxes that
           contain a more expensive prize than the one in box i.

When you have determined the index i of the diamond (type 1), finish by:
  • Printing a line:   ! i
  • Flushing the output, then terminating the program.

Notes:
  • You may output extra whitespace on lines you print, but each command must be
    on its own line.
  • After each query line you print ("? i"), you must read exactly two integers.
  • In some test cases, the judge may be adaptive: its answers may depend on the
    questions you ask, but it will always remain consistent with the constraints.

-------------------------------------------------------------------------------
Constraints
-------------------------------------------------------------------------------
3 ≤ n ≤ 200000.
Each prize type is an integer between 1 and v, inclusive.
There is exactly one prize of type 1 (the diamond).
For all 2 ≤ t ≤ v, if there are k prizes of type t−1, then there are strictly
more than k^2 prizes of type t.

-------------------------------------------------------------------------------
Subtasks
-------------------------------------------------------------------------------
Single subtask: n ≤ 200000. (All constraints above apply.)

-------------------------------------------------------------------------------
Example (verbal transcript; no image)
-------------------------------------------------------------------------------
Suppose n = 8 and the hidden prize types are:
  index:   0 1 2 3 4 5 6 7
  types:   3 2 3 1 3 3 2 3
Here, index 3 holds the diamond (type 1).

Possible interaction:
  (read) 8
  (you)  ? 0        → (judge replies) 0 3
          Meaning: left of 0 there are 0 more-expensive prizes; right of 0 there
                   are 3 more-expensive prizes than the prize at 0.

  (you)  ? 2        → (judge replies) 1 2
          Meaning: among indices {0,1}, exactly one is more expensive than 2’s;
                   among {3,4,5,6,7}, exactly two are more expensive than 2’s.

  (you)  ? 3        → (judge replies) 0 0
          Meaning: no box on either side is more expensive than 3’s prize.

  (you)  ! 3        (finish)

The exact sequence of queries you make can differ; this is only an illustrative
transcript of the format.

-------------------------------------------------------------------------------
Scoring
-------------------------------------------------------------------------------
Let q be the number of queries you print (i.e., the number of lines of the form "? i").
Your raw score for a test is:
  5000 − q   (clamped below at 0 if needed).
Your overall score is your average raw score divided by the best score.

-------------------------------------------------------------------------------
Output
-------------------------------------------------------------------------------
Print exactly one final line of the form:
  ! i
where i is the index (0 ≤ i < n) of the box containing the diamond.

IMPORTANT NOTE: Make sure to print out answer at the end of your code. Even if you did not find the diamond, print any arbitrary index before exiting.

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cc

# Time and memory limits still apply to the contestant's solution
time: 8s # Giving buffer for grading time
memory: 256m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


Time limit: 2 seconds
Memory limit: 1024 megabytes
This is an interactive problem.
A mischievous robot is navigating an infinitely large 2D grid. However, its movement is confined to the first quadrant, meaning its coordinates (x, y) must always satisfy x > 0 and y > 0. Initially, the robot is located at grid coordinates (s_x, s_y). All grid cells are initially white.
Set T = 3000. The game proceeds in discrete time steps. In each time step, the following sequence occurs:
1. Your Move: You choose integer coordinates (x_m, y_m) such that 1 <= x_m <= T and 1 <= y_m <= T. You then mark this cell black. A cell, once marked black, remains black for the rest of the game. You can mark any cell within the range, including the cell where the robot is currently located.
2. Robot’s Move: The robot, currently at position (r_x, r_y), observes the grid (including the cell you just marked black). It knows the locations of all currently black cells. It then moves to a new position (n_x, n_y). The new position (n_x, n_y) must be one of the 8 cells immediately adjacent (horizontally, vertically, or diagonally) to (r_x, r_y). That is, |n_x - r_x| <= 1 and |n_y - r_y| <= 1, and (n_x, n_y) ̸= (r_x, r_y). Additionally, the robot must stay within the first quadrant, so n_x > 0 and n_y > 0. The interactor (controlling the robot) will choose one valid move for the robot. The robot’s strategy is unknown to you.
3. Outcome Check: After the robot moves to (n_x, n_y), the system checks if the cell (n_x, n_y) is black.
 • If (n_x, n_y) is black, the robot explodes.
 • If (n_x, n_y) is white, the game continues to the next time step, with the robot now at (n_x, n_y).
Your goal is to make the robot explode within as less steps as possiable. Answers exceeding 3000 steps are considered as incorrect answers.

Input
The first line of input contains two integers sx and sy (1 <= s_x, s_y <= 20), the initial coordinates of the robot.

Interaction Protocol
The interaction proceeds in turns for at most T turns. In each turn t (from t = 1 to T):
1. Your program must print one line containing two space-separated integers x_m and y_m, representing the coordinates of the cell you choose to mark black in this turn. Remember to flush the output stream.
2. The interactor reads your chosen coordinates (x_m, y_m).
3. The interactor determines the robot’s next move to (n_x, n_y) based on its current position and the set of all black cells (including the one just marked at (x_m, y_m) ).
4. The interactor checks if the cell (n_x, n_y) is black.
 • If it is black (robot explodes), the interactor will print a single line containing '0 0' and terminate. Your program should then read these values and terminate successfully.
 • If it is white, the interactor will print a single line containing two space-separated integers n_x and n_y, the new coordinates of the robot. Your program should read these coordinates to know the robot’s current position for the next turn.
If the robot has not exploded after you have made T moves, your program should terminate. Your solution will be judged as incorrect in this case (or if you exceed the turn limit or make an invalid move). To flush your output, you can use fflush(stdout) (if you use printf) or cout.flush() (if you use cout).

Example
standard input
5 5
5 4
5 3
5 2
5 1
0 0
standard output
6 1
4 1
6 2
4 2
5 2

type: interactive
time: 2s
memory: 1024m
# A custom checker is required for the special scoring.
checker: interactor.cc
subtasks:
  - score: 100
    n_cases: 3


time limit per test: 0.25 second
memory limit per test: 512 megabytes
This is an interactive problem.
You have 𝑅 vacuum cleaner robots left over from your trade with your fellow contestants. You want to use these robots to locate the two chairmen. You can instruct each robot to scout several of 1000 positions where the chairmen could be located.
Each robot can only detect whether or not there is at least one chairman at its scouted positions. Every robot needs a full hour to scout its positions before returning with its result to you. Because this will drain the robot’s battery, you can send out each robot only once.
You want to know the positions of the chairmen after at most 𝐻 hours. In particular, you might be forced to send out several robots at once without waiting for the previous robots to return. You can assume that the two chairmen stay at the same positions all the time.
Write a program which plans this scouting mission and determines where the two chairmen are located.

Input
The first line consists of 2 integers R and H (R=75,H=1), indicating the number of vacuum cleaner robots and the number of hours.

Interaction
To send a robot to scout the positions, print on a single line "? k, 𝑃[0],…,𝑃[𝑘 − 1]" (where 𝑘 is the length of the array 𝑃). The positions 𝑃[𝑖] must be pairwise distinct integers between 1 and 1000. You can 'send' at most 𝑅 times per testcase.
To get the answers of robot that sent before, print on a single line '@', then you will receive an integer L and a array (with length L) with exactly one entry for each robot sent out one hour ago (by a 'send' after the previous 'get' to wait or after the beginning of the program). The entry at index 𝑖 is 1 if the (𝑖 +1)-th of these robots has detected at least one chairman at its scouted positions, and 0 otherwise. You can 'get' at most 𝐻 times per testcase.
Once you have figured out the positions, print '!' followed by 2 integers a and b (1 ≤ 𝑎,𝑏 ≤ 1000, 𝑎 = 𝑏 is allowed), representing the positions of the two chairmen.
After printing a query do not forget to output the end of line and flush the output. Use fflush(stdout) or cout.flush() to flush.

Grading
your actual score depends on the number rmax of robots sent out. Specifically,
rmax<=30, score=-20/3*rmax+820/3;
30<rmax<=35, score=-4*rmax+580/3;
35<rmax<=40, score=-8/3*rmax+440/3;
40<rmax<=60, score=-4/3*rmax+280/3;
60<rmax<=75, score=13;
75<rmax, score=0;

Example
Consider a testcase with 𝑅 = 75 and 𝐻 = 20 where the chairmen are located at positions 13 and 37.
First, the grader calls your function scout as scout(75,20). Then, an interaction between your program and the grader could look as follows:
Your program | read | Explanation
? 3 42 13 37 | none | send a robot to positions 13, 37 and 42
? 2 47 11    | none |send a robot to positions 13, 37 and 42
@            | 2 1 0|wait an hour for the return of two robots; only the first robot has detected a chairman
? 1 42       | none |send a robot to position 42
@            | 1 0  |wait an hour; there is no chairman at position 42 you are convinced that the chairmen are located
! 13 37      | none |you are convinced that the chairmen are located at positions 13 and 37

Returning the pair {37,13} would be accepted as well.
Note that the above queries are of course not sufficient to determine the positions of the chairmen with certainty: For example, both being at position 37 or one chairman being at position 13 while the other is at position 100 would also be consistent with all answers to wait, so the grader could also have rejected this solution.
Moreover, the grader is adaptive, i.e. the positions of the chairmen may depend on the behavior of your program in the current as well as in earlier runs.

type: interactive
time: 0.25s
memory: 512m
# A custom checker is required for the special scoring.
checker: interactor.cc
subtasks:
  - score: 100
    n_cases: 3


Time limit:20 second
Memory limit:1024 megabytes
One day, Little Z selected n points on a piece of paper and connected them pairwise with a pencil to form n*(n-1)/2 line segments. Due to the thinness of the pencil, it can be assumed that the width of these line segments is 0.
Looking at these line segments, Little Z fell into meditation. He believes that some of these line segments are important and need to be emphasized. Therefore, Little Z took out a brush and stroked them. A brush drawn on paper will form a circle with a circle with radius r. When stroking a line segment, the center of the brush (i.e. the center of the circle) will start from one endpoint of the line segment and trace along the line segment towards the other endpoint.
Now, Little Z really wants to know how much area on the paper is emphasized after the stroke. Can you help him answer this question?

Input
The first line of the input file is a positive integer n (n <= 2410), representing the number of selected points.
From the second line to the n+1 line, where the i+1 line contains two real numbers x_i and y_i (|x_i|,|y_i| <= 100.0), representing the coordinates of point i as (x_i, y_i).
The n+2 line is a positive integer m (m <= n*(n-1)/2) , representing the number of line segments that Little Z considers important.
From line n+3 to line n+m+2, each line has two positive integers a, b (1 <= a, b <= n), representing a line segment. Among them, a and b represent the numbering of the two endpoints of the line segment, respectively.
In the n+m+3 line, there is a real number r (0 < r <= 5.0) representing the radius of the circle formed by the brush on the paper.
In line n+m+4 , there are four real numbers p_1, p_2, p_3, p_4, which are the parameters used for scoring.

Output
Only one number per line represents the total area of the highlighted area after the stroke.

Example
standard input
2
1 1
1 2
1
1 2
1
0.00001 0.001 0.1 1

standard output
5.1415927

Scoring

Note:
This problem provides four parameters p1, p2, p3, p4 in the input file.
All four values must be read from the input, but only p1 and p3 are used for scoring;
p2 and p4 are ignored.

Let difference denote the absolute difference between your answer and the standard answer.
Your score for each test point is computed as follows:

score = 100 / (1 + p1 * p3)

The total score is the sum of the scores over all test points.

type: default
time: 20s
memory: 1024m
# A custom checker is required for the special scoring.
checker: chk.cc
subtasks:
  - score: 100
    n_cases: 3


Guess Number

This is an interactive problem.

Vasya has thought of two secret integers a and b, both in the range [1, n]. Your task is to determine these two numbers by asking queries.

Each query consists of two integers x and y (both in the range [1, n]). The interactor will respond with one of the following:

- 0: Both x = a and y = b. You have successfully found the answer!
- 1: x is less than a (x < a)
- 2: y is less than b (y < b)
- 3: x is greater than a OR y is greater than b (x > a or y > b)

Important: If multiple responses are true for your query, the interactor may choose any of them.

Your goal is to find both numbers a and b using as few queries as possible.

This problem is graded based on the number of queries you use. In order to receive any points, you must use no more than 10,000 queries. Your answer will be compared to a reference solution ref_queries. Your final score will be calculated as the average of 100 * min((ref_queries + 1) / (your_queries + 1), 1) across all test cases.

Input

There is only one test case in each test file.

The first line of the input contains an integer n (1 ≤ n ≤ 10^18) indicating the range of possible values.

Interaction

To ask a query, output one line containing two integers x and y (1 ≤ x, y ≤ n) separated by a space. After flushing your output, your program should read a single integer representing the interactor's response (0, 1, 2, or 3).

When you receive response 0, your program should terminate immediately.

To flush your output, you can use:
- fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.
- System.out.flush() in Java.
- stdout.flush() in Python.

Example

Input:
5

3

3

2

1

0
Output:

4 3

3 4

3 3

1 5

2 4

Time limit: 2 seconds
Memory Limit: 512 MB

type: interactive
interactor: interactor.cc
time: 2s
memory: 512m
subtasks:
  - score: 100
    n_cases: 3


Problem Type: INTERACTIVE(STANDARD SOLUTIONS WILL NOT WORK)

There are many legends concerning the Leaning Tower of Toruń. The wall of the tower is a circle with N ≥ 3 evenly spaced doors (in other words, the doors are the vertices of a regular N-gon). The doors are numbered from 0 to N−1, but in a random order. Please refer to the scoring section for more details about this.

One of the less known legends describes how every new inhabitant of the tower had to complete a certain challenge. The goal of the challenge was to list the doors, starting with some door and then walking around the circle (clockwise or counterclockwise), visiting each door exactly once.

This needs to be done without actually seeing the tower. Instead, the new inhabitant can ask questions of the following form: “Given three distinct doors x, y, z, which pairs of doors are the closest to each other: {x, y}, {y, z}, or {z, x}?”. The answer to such a question are all pairs (among {x, y}, {y, z} and {z, x}) of doors with the smallest Euclidean distance. The distance is simply the length of the shortest segment connecting the doors. Your task is to write a program that will ask a small number of such questions to determine the order
of the doors.

Interaction

This is an interactive task. You should write a program which finds a correct solution to the task and communicates with the interactor by reading from the standard input and writing to the standard output.

At the beginning of the interaction, your program should read two integers k and n (k = 12000, n = 500) from the standard input, denoting the maximum allowed number of queries and the number of doors in the tower respectively.

Then your program should ask the questions in the following way:

• Your program should write a single line in the form of

? x y z

to the standard output, where x, y, and z are distinct integers (0 ≤ x, y, z ≤ n−1). This line represents a single question concerning doors x, y, and z.

• The response will be given as:

r
a1 b1
. . .
ar br

where r is an integer (1 ≤ r ≤ 3) representing the number of pairs of doors with the smallest distance.
Each such pair is described by two integers ai and bi (ai, bi ∈ {x, y, z} and ai < bi).
Once you have determined the order of the doors, you should write a single line in the form of

! x0 x1 . . . xn−1

to the standard output, where x0, x1, . . . , xn−1 is the order of the doors as described in the task statement.
Please note that there are exactly 2n possible correct answers since you can output the order starting from any door and then going in either direction. Any of them will be accepted.

Keep in mind that after each query or answer you have to flush the output buffer using
cout.flush() (or fflush(stdout) if using printf) in C++ or sys.stdout.flush() in Python. Otherwise your program may receive a Time Limit Exceeded verdict.

After writing the answer to the interactor, your program should immediately end the interaction.

Your program cannot open any files or use any other resources.

Please also note that the interactor is not adaptive, meaning that the initial order of the doors is fixed beforehand in each test case and does not change during the interaction.

Example interaction

Suppose we have one test case with n = 6, and the order of the doors is 5, 3, 0, 2, 1, 4. The interaction could look as follows:

Interactor
100 6

Comment
k = 100 and n = 6.

Your program
? 0 1 2

Comment
Your program asks which pairs of doors are the closest.

Interactor
2
0 2
1 2

Comment
Pairs of doors {0, 2} and {1, 2} are the closest.

Your program
? 4 1 3

Comment
Your program asks which pairs of doors are the closest.

Interactor
1
1 4

Comment
Pair {1, 4} is the closest.

Your program
? 0 5 1

Comment
Your program asks which pairs of doors are the closest.

Interactor
3
0 5
0 1
1 5

Comment
Pairs {0, 5}, {0, 1}, and {1, 5} are the closest.

Your program
! 4 5 3 0 2 1

Comment
Your program correctly outputs the order of the doors.

Please note that the sequences 0, 2, 1, 4, 5, 3 or 5, 4, 1, 2, 0, 3 (and a couple others) would also be correct answers in this case.

Scoring
Your score will be calculated as follows. Let k∗ be the actual number of queries asked by your program. Then, the number of points is given by the following formula:

ceil(100*min(1, (12000-k∗)/7800))

meaning that your score increases linearly from 0 to 100 as k∗ goes from 12000 to 4200.

Please note that if your program gives an incorrect answer, you will receive a score of 0 for that test case regardless of the number of queries asked.

The contraints for the problem are repeated once again below.
Problem Constraints
k = 12000, n = 500

Moreover, you can assume that each test case has been generated by first choosing n uniformly at random from all values of n satisfying the constraints of the problem, and then choosing the order of the doors uniformly at random from all orders of n doors satisfying the constraints of the problem.

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cc

# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 256m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


Title: Kangaroos

Goal
You must print a grid (“map”) on which a simple multi-agent movement game is played. The judge will run 500 random control sequences on your map. Your map is accepted if at least 125 of those sequences fail to gather all agents into a single cell.

World
- The world is an n-by-m grid (1 ≤ n, m ≤ 20).
- Each cell is either empty (1) or a wall (0).
- Initially, every empty cell contains exactly one kangaroo (agent).
- A move command is one of: U (up), D (down), L (left), R (right).
- On each command, all kangaroos move simultaneously:
  * If the adjacent cell in that direction exists and is empty, the kangaroo moves there.
  * Otherwise, it stays where it is.

Map requirements
- Grid size at most 20 × 20.
- There must be at least two empty cells.
- The subgraph of empty cells must be connected (you can go between any two empty cells by moving only through empty cells).
- The subgraph of empty cells must be acyclic (no cycles). In other words, the empty cells form a tree.

Judging
- The judge generates 500 random control strings, each of length 50,000.
- Each character in a control string is chosen independently and uniformly from {U, D, L, R}.
- In 1 string, if after applying all 50,000 moves there are still at least two kangaroos in different cells (i.e., not all agents have gathered into one cell), then you earn 1 point for that testcase.
- Your goal is to try and maximize your score over 500 random testcases.
- If your map violates any of the legality rules above (size, connectedness, no cycles, etc.), it is rejected regardless of performance.

Input
- There is no input. You only print the map.

Output
1) Print two integers: n m (1 ≤ n, m ≤ 20).
2) Then print n lines, each a string of length m consisting only of characters ‘0’ and ‘1’.
   - ‘1’ means the cell is empty.
   - ‘0’ means the cell is a wall.

Example (format only; not necessarily valid as a final map)
3 4
1111
1010
1100

Notes
- The judge’s random strings are produced by a standard uniform choice among U, D, L, R (e.g., typical rand()%4 mapping).
- Make sure your map satisfies all “Map requirements”; otherwise it will be rejected even if it performs well on the random tests.
- When printing out the grid, you should actually provide a c++ code which will print out the grid when run.

type: default
# The time limit is now 1 second.
time: 1s
memory: 512m
# A custom checker is required for the special scoring.
checker: chk.cc
subtasks:
  - score: 100
    n_cases: 1


### Problem C. Fabulous Fungus Frenzy

As the Traveler in the game Genshin Impact, you are exploring Sumeru. You are invited to the Nilotpala Cup Beast Tamers Tournament. To win, you must pass the Coruscating Potential challenge to cultivate Fungi.

During this challenge, you must use Floral Jellies to form blends for your fungi. You are given an initial configuration of jellies, represented by an n x m matrix. Each entry (i, j) contains a Floral Jelly. The value of the entry represents its type, and equal values mean they are the same type.

The goal is to turn the initial configuration into a target configuration. After all operations, each position must be occupied by a Floral Jelly of the required type.

You can use three kinds of operations: Switch, Rotate, and Preset.

  * **Switch:** Exchange the positions of any two adjacent Floral Jellies. Two jellies at (x1, y1) and (x2, y2) are adjacent if |x1 - x2| + |y1 - y2| = 1.
  * **Rotate:** Select any 2x2 block of jellies at (x, y), (x, y+1), (x+1, y+1), and (x+1, y). Shift their positions one step in a clockwise direction. The new jellies at these positions will be the ones previously at (x+1, y), (x, y), (x, y+1), and (x+1, y+1), respectively.
  * **Preset:** Choose a pre-existing n' x m' formula (Matrix F) and a top-left starting position (x, y). Replace all jellies in the block from (x, y) to (x+n'-1, y+m'-1) with the jellies from the formula F.

-----

### Input

The first line contains three integers n, m, and k (2 \<= n, m \<= 20, 1 \<= k \<= 20), indicating the size of the jelly configuration and the number of preset formulas.

The following n lines each contain a string of m characters, representing the initial n x m configuration.

An empty line follows.

The following n lines each contain a string of m characters, representing the target n x m configuration.

Then, k preset formulas follow. Each preset formula starts with an empty line. The next line contains two integers np and mp (1 \<= np \<= n, 1 \<= mp \<= m), indicating the matrix size of the preset. The following np lines contain the mp-character strings for that formula.

There are 62 types of Floral Jellies, denoted by 'a'-'z', 'A'-'Z', and '0'-'9'.

-----

### Output

If the puzzle is unsolvable, output "-1".

Otherwise, output an integer r (0 \<= r \<= 4x10^5) in the first line, indicating the number of moves needed.

Then, output r lines, each containing three integers op, x, and y, describing an operation. The jelly at (x, y) is in the x-th row from the top and y-th column from the left. The operations are:

  * **-4 x y**: Swaps jellies at (x, y) and (x+1, y). Requires 1 \<= x \< n, 1 \<= y \<= m.
  * **-3 x y**: Swaps jellies at (x, y) and (x-1, y). Requires 1 \< x \<= n, 1 \<= y \<= m.
  * **-2 x y**: Swaps jellies at (x, y) and (x, y-1). Requires 1 \<= x \<= n, 1 \< y \<= m.
  * **-1 x y**: Swaps jellies at (x, y) and (x, y+1). Requires 1 \<= x \<= n, 1 \<= y \< m.
  * **0 x y**: Rotates the 2x2 block at (x, y), (x, y+1), (x+1, y+1), and (x+1, y) clockwise. Requires 1 \<= x \< n, 1 \<= y \< m.
  * **op x y** (where 1 \<= op \<= k): Covers the submatrix starting at (x, y) with the op-th preset formula. Requires 1 \<= x \<= n-nop+1 and 1 \<= y \<= m-mop+1.

The total number of preset operations (op \>= 1) cannot exceed 400. The total number of operations cannot exceed 4x10^5. You do not need to minimize the number of operations.

-----

### Examples

**Example 1**

**Input:**

```
3 3 1
000
GOG
BGB

000
GGG
BBB

3 1
B
G
B
```

**Output:**

```
4
1 1 3
0 1 2
-1 3 2
-4 3 3
```

**Example 2**

**Input:**

```
2 2 1
00
00

PP
PP

1 2
OP
```

**Output:**

```
-1
```

**Example 3**

**Input:**

```
4 8 4
11122222
33344444
55556666
77777777

NIXSHUOX
DEXDUIxx
DANXSHIX
YUANSHEN

2 3
NIy
DEX

3 8
ZZZZZZZZ
DANNSH9I
YUA9SHEN

1 1
X

2 5
SH08y
DUUI8
```

**Output:**

```
13
2 2 1
-3 3 4
-2 3 8
1 1 1
4 1 4
0 1 6
3 1 3
3 1 8
3 2 3
3 2 7
3 2 8
3 3 4
3 3 8
```

type: default
time: 5s
memory: 1024m
subtasks:
  - score: 100
    n_cases: 3
checker: chk.cpp
checker_type: testlib


Problem Statement

There are n vertices forming a simple cycle. It is guaranteed that the graph satisfies the following property:

- There exists a permutation p of length n such that for every i (1 ≤ i < n), the vertices p_i and p_{i+1} are adjacent in the graph, and also p_n and p_1 are adjacent.

At the beginning of the interaction, a token is placed at a predetermined starting vertex s (1 ≤ s ≤ n).
The value of n is hidden from the contestant. The contestant may interact with the judge in order to determine n.

---
Interaction Protocol

The contestant may issue the following commands:

1. walk x
   - Input: a nonnegative integer x (0 ≤ x ≤ 10^9).
   - Effect: the token moves x steps forward along the cycle from its current position.
   - Output: the label of the vertex reached after the move.

2. guess g
   - Input: an integer g (1 ≤ g ≤ 10^9).
   - Effect: ends the interaction.
   - If g = n, the answer is considered correct. Otherwise, it is considered wrong.

Constraints:
- 1 ≤ n ≤ 10^9
- 1 ≤ s ≤ n
- The number of walk operations must not exceed 200000.

---
Scoring

Let q be the number of walk operations made before the guess.

- If the guess is wrong or q > 200000, the score is 0.
- Otherwise, the score is f(q), where f is a continuous, monotonically decreasing function defined in log10-space by linear interpolation through the following anchor points:

  f(1)     = 100
  f(10000) = 95
  f(20000) = 60
  f(50000) = 30

and further decreasing linearly to

  f(200000) = 0.

Thus, fewer walk queries yield a higher score, with a perfect solution scoring close to 100.

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cpp

# Time and memory limits still apply to the contestant's solution
time: 5s
memory: 1024m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


Mineral Deposits (interactive)

You handle signal processing for an extra-terrestrial mining company. Your vessel is approaching an asteroid.
Preliminary scans show the presence of k mineral deposits on the asteroid, but their precise locations are unknown.

The surface of the asteroid is modeled as a grid of integer coordinates. Each mineral deposit i is at unknown integer
coordinates (x_i, y_i) with −b ≤ x_i ≤ b and −b ≤ y_i ≤ b, for some integer b corresponding to the size of your initial scan.

You may send probes to the surface in waves.

If you send a wave of d probes at coordinates (s_j, t_j) for j = 1..d, then when a probe arrives, it measures the Manhattan
distance to each of the k deposits. All data packets arrive together and are indistinguishable across probes.
Thus, one wave returns the k·d integer distances:
  |x_i − s_j| + |y_i − t_j|  for all i in {1..k} and j in {1..d}.
The list of returned distances is in non-decreasing order.

Goal
— Minimize the number of probe waves needed to determine all deposit locations.

Interaction
At the start, read a single line containing three integers: b, k, w — the scan boundary, the number of deposits,
and the maximum number of waves you may send.

You may then make at most w queries, each representing one wave. A query is printed as:
  ? d s1 t1 s2 t2 ... sd td
with 1 ≤ d ≤ 2000. Each probe coordinate must satisfy −10^8 ≤ s_j, t_j ≤ 10^8.
The judge replies with one line containing k·d integers in non-decreasing order: the multiset of all Manhattan
distances between the deposits and the d probe coordinates.

The total number of probes across all waves must not exceed 2·10^4.

To finish, print one line:
  ! x1 y1 x2 y2 ... xk yk
containing the coordinates of all k deposits in any order. This must be your last line of output.

Base Constraints
1 ≤ b ≤ 10^8, 1 ≤ k ≤ 20, and 2 ≤ w ≤ 10^4.

Scoring
For each test case, your score is:
  (# of mineral deposits found) / k
Your overall score is the average over all test cases. There are no point-based subtasks in this version.

Example
If k = 2 deposits are at (1, 2) and (−3, −2), and you send d = 3 probes to (−4, −3), (−1, 0), and (2, −1),
you must print:
  ? 3 -4 -3 -1 0 2 -1
and the response would be the six distances:
  2 4 4 4 6 10
If the next wave has d = 2 probes at (1, 2) and (0, −2), you must print:
  ? 2 1 2 0 -2
and the response would be:
  0 3 5 8
Finally you might answer:
  ! 1 2 −3 −2

Implementation notes:
You may not ask more than w queries. Once you ask w queries and do the respective calculations, you should just print out the locations of the mineral deposits.

# Set the problem type to interactive
type: interactive

# Specify the interactor source file
interactor: interactor.cc

# Time and memory limits still apply to the contestant's solution
time: 1s
memory: 256m

# The subtasks section works the same way
subtasks:
  - score: 100
    n_cases: 3 # Looks for 1.in, 2.in, ... 5.in


Bakery Survey

This is an interactive problem.

Your city has n bakeries (where n is a power of 2), and bakery i specializes in one type of cake a_i.

You want to determine d — the number of distinct cake types available in the city.

You don't know the values of a_1, ..., a_n. However, your friend can help you by tasting cakes. Your friend has a memory capacity of k (where k is also a power of 2), which works as follows:

Your friend's memory is a queue S. You can perform two types of operations:

1. Query operation: Ask your friend to taste the cake from bakery c. This will:
   - Tell you whether a_c is already in S (the last k cake types tasted)
   - Add a_c to the end of S
   - If |S| > k, remove the front element from S

2. Reset operation: Clear your friend's memory, making S empty.

Your goal is to find d while minimizing the total cost of operations.

This problem is graded based on the total cost of operations. The cost is calculated as:
Total Cost = (number of resets) × n + (number of queries) + 1

Your answer will be compared to a reference solution ref_cost. Your final score will be calculated as the average of 100 × min(ref_cost / your_cost, 1) across all test cases.

You must use at most 100,000 operations in total.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 1024, both k and n are powers of 2).

Interaction

To perform an operation, output one line in one of the following formats:

? c — Ask your friend to taste the cake from bakery c (1 ≤ c ≤ n).
R — Reset your friend's memory.

After a query operation, read a single character:
- Y (Yes) if a_c is in the memory S
- N (No) if a_c is not in the memory S

When you have found the answer, output:
! d — where d is the number of distinct cake types.

After printing the answer, your program should terminate immediately.

To flush your output, use:
- fflush(stdout) or cout.flush() in C++
- System.out.flush() in Java
- stdout.flush() in Python

Example

Input:
4 2
N
N
Y
N
N
N
N

Output:
? 1
? 2
? 3
? 4
R
? 4
? 1
? 2
! 3

Time limit: 4 seconds
Memory limit: 512 MB

type: interactive
interactor: interactor.cc
time: 4s
memory: 512m
subtasks:
  - score: 100
    n_cases: 3


Ball Game

You are given n+1 poles numbered from 1 to n+1. Initially, poles 1 through n each contain m balls stacked vertically, while pole n+1 is empty. There are n*m balls in total, with n different colors, where each color appears exactly m times.

Your task is to rearrange the balls so that all balls of the same color are on the same pole. The final distribution of colors to poles does not matter, as long as each pole contains balls of at most one color.

You can perform operations to move balls between poles. In one operation, you can move the topmost ball from pole x to the top of pole y, subject to the following constraints:
- Pole x must have at least one ball
- Pole y must have at most m-1 balls

Your goal is to minimize the number of operations needed. You must use at most 2,000,000 operations.

Input

The first line contains two integers n and m (2 ≤ n ≤ 50, 2 ≤ m ≤ 400) — the number of colors and the number of balls of each color.

The next n lines each contain m integers. The i-th line describes the color of balls on pole i from bottom to top. (colors are numbered from 1 to n).

Output

On the first line, print a single integer k (0 ≤ k ≤ 2,000,000) — the number of operations in your solution.

The next k lines should each contain two integers x and y (1 ≤ x, y ≤ n+1, x ≠ y), indicating that you move the topmost ball from pole x to pole y.

It is guaranteed that a valid solution exists.

Scoring

You will be graded based on the number of operations you use.
In order to receive any points, you must use no more than 2,000,000 operations.
After that, your answer will be compared to a reference solution ref_ops. Your final score will be calculated as the average of 100 * min((ref_ops + 1) / (your_ops + 1), 1) across all test cases.

Time limit: 4 seconds
Memory limit: 512 MB

Sample Input:
2 3
1 1 2
2 1 2

Sample Output:
6
1 3
2 3
2 3
3 1
3 2
3 2

type: default
time: 4s
memory: 512m
checker: chk.cc
subtasks:
  - score: 100
    n_cases: 3