Sphere Packing in a Cube (Optimization)

You are given an integer n. Place n pairwise-disjoint congruent solid spheres inside the unit cube [0, 1]^3 so that the common radius is as large as possible. You do not need to output the radius explicitly; the checker infers the largest valid common radius from your centers.

Input
The input consists of a single line with one integer:
n  (2 ≤ n ≤ 10^6 in principle; in the official tests n ≤ 4096.)

Output
Output exactly n lines. Each line must contain three real numbers x y z (in any standard real-number format parseable by C/C++, e.g., 0.0, 1, 1e-3), giving the coordinates of a sphere center. All coordinates must satisfy 0 ≤ x, y, z ≤ 1. Whitespace is free; no additional text is allowed. Trailing whitespace is ignored.

Feasibility & how the checker interprets your output
Given your centers C = {c_i}, the checker computes the largest common radius that makes the spheres non-overlapping and contained in the cube, completely ignoring any radius you might have assumed. Formally, your geometric radius is
    r(C) = min( ½ * min_{i≠j} ||c_i - c_j||_2 ,  min_i dist(c_i, ∂[0,1]^3) ),
where dist(c_i, ∂[0,1]^3) is the minimum distance from c_i to any cube face. If any coordinate lies outside [0,1] (up to an absolute tolerance of 1e−12), the output is rejected.

Scoring
This is an optimization problem. For each test case we normalize your geometric radius r(C) between a baseline lower bound and a general upper bound:
    score = clamp( (r(C) − baseline) / (best − baseline), 0, 1 ).
Here:
• baseline is the radius achieved by a balanced m×k×ℓ cubic grid with m·k·ℓ ≥ n (equally spaced centers with margin r = 1/(2·max(m,k,ℓ))). This is a constructive packing every team can implement quickly.
• best is an a priori upper bound that no packing can exceed: best = min( ½ , ((δ·3)/(4πn))^{1/3} ), where δ = π/√18 is the Kepler density upper bound for sphere packings in 3D.
Your total score is the average of per-test-case scores.

Validation & precision
• The checker reads doubles and computes in IEEE-754 double precision. It accepts coordinates on the faces of the cube.
• The checker rejects outputs that do not contain exactly n triples, that contain non-finite numbers, or that place any center outside [0,1].
• Distances are computed exactly as written above; there is no relative/absolute tolerance applied to r(C) beyond floating-point rounding.
• The checker runs in O(n^2) on your centers (only 8.4 million pairs at n=4096), so keep n modest if you test locally.

Example
Input
5

Valid Output (one of many)
0.1 0.1 0.1
0.9 0.1 0.1
0.1 0.9 0.1
0.1 0.1 0.9
0.9 0.9 0.9

(Your solution is free to produce any arrangement.)

Notes
• You only need to output centers. The checker automatically determines the maximum common radius supported by your centers.
• Greedy / local-improvement heuristics, lattice-based constructions, simulated annealing, or nonlinear optimization often yield good packings.
• Touching spheres and touching the cube faces are allowed; overlaps are not.


Problem: Hamiltonian Path Challenge

You are given a directed graph with n vertices and m edges.
Your task is to find a path that visits each vertex exactly once.

If it is not possible to find a Hamiltonian path, you should instead output a path that is as long as possible and does not repeat vertices.

----------------------------------------
Input
The first line contains two integers n, m.
The second line contains 10 integers, where the i-th number is a_i, the scoring parameter.
Each of the next m lines contains two integers u, v, representing a directed edge from u to v.

----------------------------------------
Output
Output two lines:

- The first line contains an integer k, the number of vertices in your path.
- The second line contains k integers, the sequence of vertices in the path.

----------------------------------------
Sample 1
Input:
3 3
3 3 3 3 3 3 3 3 3 3
1 2
1 3
2 3

Output:
3
1 2 3

Explanation:
Edges are directed.
In this case, the contestant’s submission scores 10 points.

----------------------------------------
Sample 2
Input:
4 4
1 1 2 2 3 3 4 4 4 4
1 2
2 1
1 3
4 2

Output:
2
2 1

Explanation:
In this case, the submission scores 4 points.
Note: you do not need to output the optimal solution.

----------------------------------------
Scoring
- If your output is invalid, your score is 0.
- Otherwise, let k be the number of vertices in your path.
  Your score is equal to:

  sum_{i=1}^{10} [k ≥ a_i]

That is, the number of a_i values that are less than or equal to your k.

----------------------------------------
Constraints
- 1 ≤ n, m ≤ 500000
- No multiple edges, no self-loops
- At least one Hamiltonian path exists in the graph

----------------------------------------
Time Limit: 4 second
Memory Limit: 512 MB

type: default

time: 4s
memory: 512m

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


Time Limit: 10s
Memory Limit: 1024M

Firstly, you are given two integers n (1 <= n <= 400) and m (1 <= m <= 4000), which means that you have n elements and m sets.

After that, there are m integers, the i-th integer is the cost of choosing the i-th set.

After that, for the i-th element, firstly input an integer k_i, which means the number of sets that contain the element. After that, there

are k_i integers, the j-th integer a_j means that the set with id a_j contains the element i.

Find some sets so that each element belongs to at least one of these sets. You need to minimize the total cost of these sets. This value will determine your final score.

Output:

Firstly output an integer |S|, which means the number of sets you choose. After that, output |S| ids of the sets you choose in another line.

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


Geemu

This is an interactive problem.

Little A has an interesting game.
Initially, there is a permutation p of length n. You don't know the permutation p, and you need to determine the final p through the following operations:
1. Query the number of value-contiguous segments in a given interval.
2. Swap two elements at given positions.

Smart little B discovered that no matter what you do, there are always two permutations p that cannot be distinguished. For convenience, you only need to find one of the possible permutations p.
Let s_1 be the number of times you use operation 1, and s_2 be the number of times you use operation 2.

Input
There is only one test case in each test file.
The first line of the input contains three integers n, l_1, and l_2 (1 ≤ n ≤ 10^3, 1 ≤ l_1, l_2 ≤ 10^5) indicating the length of the hidden permutation, the maximum allowed number of ask operations, and the maximum allowed number of swap operations.

Interaction
To query the number of value-contiguous segments in an interval [l, r], output one line:
    1 l r
where 1 ≤ l ≤ r ≤ n.
After flushing your output, read one integer x indicating the number of value-contiguous segments in the interval [l, r].
To swap two elements at positions i and j, output one line:
    2 i j
where 1 ≤ i, j ≤ n.
After flushing your output, read the integer 1 to confirm the swap was performed.
To submit your final answer, output one line:
    3 p_1 p_2 ... p_n
where p_1, p_2, ..., p_n is your determined permutation.
After submitting your report, your program should exit 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.

Scoring
Your solution will be scored based on the efficiency of your queries and swaps, with limits l_1 for operation 1 and l_2 for operation 2.
Let s_1 be the number of queries (operation 1) you use, and s_2 be the number of swaps (operation 2) you use.
Let r_1 be the number of queries (operation 1) the reference solution uses, and r_2 be the number of swaps (operation 2) the reference solution uses.
Your score for each test case is calculated as follows:
1. If s_1 > l_1 or s_2 > l_2, you receive 0 points for that test case.
2. Otherwise, your score for this test case is calculated as:
   score = 100 * min((r_1 + r_2 + 1) / (s_1 + s_2 + 1), 1)
Your final score is the average of your scores across all test cases.

Time limit: 2 seconds
Memoriy limit: 512 MB

Example input:

1 1 2

1 1 3

1 2 3

1 1 3

1 2 4

1 1 4

1 2 5

1 3 5

1 4 5

1 2 5

1 1 5

3 3 5 4 1 2

Example output:
5 100 50

2

1

1

1

2

2

2

2

1

2

1

type: interactive

interactor: interactor.cc

time: 2s
memory: 512m

subtasks:
  - score: 100
    n_cases: 3


Problem: G2. Inter Active (Hard Version)

Time limit: 2 seconds

Memory limit: 512 MB

This is the hard version of the problem. The difference between the versions is that in this version, you can make at most 10 * n queries. You can hack only if you solved all versions of this problem.

Ali loved Bahamin's gift (from problem E) so much that he illegally traveled from Qazvin to Liverpool to have the gift signed by football players. Now Interpol is searching for him, but they've offered a deal: solve a problem, and he can stay in Liverpool. But since he's currently at the stadium, he can't solve it so he asked you to do it.

This is an interactive problem.

There is a hidden permutation p of length n >= 4 where p_i != i for each 1 <= i <= n.

Initially, you should give the jury a positive integer k <= n, which will be constant through future queries.

Then you need to find permutation p using some queries.

In each query, you give a permutation q_1, q_2, ..., q_n to the jury. In response, you will receive the number of pairs (i, j) such that all of the following conditions hold:
- i < j
- p_{q_i} = q_j
- i != k (k is the constant you have given to the jury)

You are given n, and you need to find the permutation p in at most 10 * n queries.

A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 <= t <= 500). The description of the test cases follows.

The only line of each test case contains a single integer n (4 <= n <= 100) — the length of p.

It is guaranteed that the sum of n^2 over all test cases does not exceed 10^4.

Interaction Protocol

The interaction for each test case begins with reading the integer n.

Then you should output the integer k (1 <= k <= n). This is not considered as a query.

Then you can ask up to 10 * n queries. To make a query, output a line in the following format:
? q_1 q_2 ... q_n

The jury will return the answer to the query.

When you find the permutation p, output a single line in the following format:
! p_1 p_2 ... p_n

This is also not considered as a query.

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

The interactor is not adaptive, which means that the permutation is determined before the participant outputs k.

If your program makes more than 10 * n queries, your program should immediately terminate to receive the verdict Wrong answer. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

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.

Note:
In the first test case, p=[3,1,4,2]. The solution selected k=1 then it asked permutation q=[1,2,3,4]. Only pair (3,4) satisfies the conditions.
In the second test case, p=[3,1,2,5,4]. The solution selected k=3. For permutation q=[1,2,5,4,3], only pair (1,5) satisfies the conditions. For permutation q=[2,1,4,3,5], pairs (1,2) and (2, 4) satisfy the conditions.

Example Input:
2
4
1

5
1
2

Example Output:
1
? 1 2 3 4
! 3 1 4 2
3
? 1 2 5 4 3
? 2 1 4 3 5
! 3 1 2 5 4

# 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: 10 # Looks for 1.in, 2.in, ... 5.in


time limit per test: 5 seconds
memory limit per test: 1024 megabytes
**Submissions are only allowed in C++ language.**

This problem is interactive.

Baudelaire is very rich, so he bought a tree of size n, rooted at some arbitrary node. Additionally,
every node has a value of 1 or -1.

Cow the Nerd saw the tree and fell in love with it. However, computer science doesn't pay him
enough, so he can't afford to buy it. Baudelaire decided to play a game with Cow the Nerd, and if
he won, he would gift him the tree.

Cow the Nerd does not know which node is the root, and he doesn't know the values of the nodes
either. However, he can ask Baudelaire queries of two types:

Type 1 query: Let f(u) be the sum of the values of all nodes in the path from the root of
the tree to node u. Cow the Nerd may choose an integer k and k nodes u1,u2,...,uk,
and he will receive the value f(u1)+f(u2)+...+f(uk).

To ask this query, print:
? 1 k u1 u2 ... uk
and read an integer from the interactor.

Type 2 query: Baudelaire will toggle the value of node u. Specifically, if the value of u is 1, it will
become -1, and vice versa.

To ask this query, print:
? 2 u
and read the response (no output, just toggle).

Cow the Nerd wins if he guesses the value of every node correctly (the values of the final tree,
after performing the queries) within Q total queries. Can you help him win?

Scoring
If your solution makes at most n queries, you will receive 100 points.
If it makes more than n+1000 queries, you will receive 0 points.
If it makes x queries where n < x ≤ n+1000, your score will be linearly interpolated
from 100 down to 0.

Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100), the number of test cases.

The first line of each test case contains a single integer n (2 ≤ n ≤ 1000), the size of the tree.

Each of the next n-1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v),
denoting an edge between nodes u and v in the tree.

It is guaranteed that the sum of n over all test cases does not exceed 1000 and that each graph
provided is a valid tree.

Interaction
After printing a query do not forget to output the end of line and flush the output. Otherwise, you
may get the Idleness Limit Exceeded verdict.

When you have found the answer, output:
! v1 v2 ... vn
where vi is the value of node i after performing the queries.

Printing the answer does not count as a query.

Example

input
3
4
1 4
4 2
2 3
1
-1
-5
-5
2
1 2
2
7
1 2
2 7
7 3
7 4
7 5
7 6
-1

output
? 1 3 1 2 4
? 1 2 3 1
? 2 4
? 1 3 1 2 4
? 1 2 3 1
! -1 -1 -1 -1
? 1 1 1
! -1 1 1 1 1 1 -1

# 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


Inverse Counting Path

Walk Alone is an expert in dynamic programming, but he gets bored with traditional dynamic programming problem like counting paths on a 2-dimension grid, so he wants to do it in reverse. The problem he raised is as follows:

On a 2-dimension grid of size n*n, originally you are on grid (1,1). The grid consists of 0 and 1, and you can only walk on the grid with number 1 in it. You can only go down or right, i.e. you can only increase your x or y by one. Also you cannot walk outside the grid.

Given the number x of ways to walk from (1,1) to (n,n), you need to construct a grid of n*n so that the ways to walk is exactly x. However, since Walk Alone's brain is too small to memorize such a big grid, you need to guarantee that the size of the grid n is equal to or smaller than 300. Specifically, your score will be (300 - n) / 300.

Input

The only line of the input contains one integer x (1<=x<=10^18), denoting the ways to walk.

Output

The first line of the output contains the size of the grid n. Remind that you need to guarantee 1<=n<=300.

The following n lines each contains n integers a_{i,j}∈{0,1} denoting the grid, where 0 denotes you cannot walk on the grid while 1 is on the contrast.

Example Input 1:

3

Example Output 1:

3
1 1 0
1 1 0
1 1 1

Example Input 2:

10

Example Output 2:

4
1 1 1 0
1 1 1 1
1 0 1 1
1 1 1 1

# 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: 1s
memory: 512m

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


# Limited Shuffle Restoring

**Input file:** standard input
**Output file:** standard output
**Time limit:** 3 seconds
**Memory limit:** 512 meblbytes

**This is an interactive problem.**

Bobo had an array \\( a \\), initially equal to \\((1,2,\ldots,n)\\). He did the following operations with the array.

- For each \\( i \\) from 1 to \\( n \\) in this order, Bobo picked some index \\( j \\) such that \\( i \leq j \leq \min(n,i+2) \\), and swapped \\( a_i \\) and \\( a_j \\). Of course, if \\( i = j \\), then nothing happened after the operation.

Your goal is to determine the final array. You may ask questions of the following type.

- ? i j meaning the question "How do \\( a_i \\) and \\( a_j \\) compare to each other?". Bobo will respond to this with one symbol < or >, meaning that \\( a_i < a_j \\) or \\( a_i > a_j \\), respectively.

You may ask no more than \\(\lfloor 5n/3 \rfloor + 5\\) questions. After this, you must guess the array.

## Interaction Protocol

First, the interactor prints the number \\( n \\) in a separate line (\\( 1 \leq n \leq 30,000 \\)). Then the solution makes queries, where each query consists of printing ? i j on a separate line, where \\( 1 \leq i,j \leq n \\), and \\( i \neq j \\). After each query the interactor prints one character < or > on a separate line.

After the solution has finished asking questions, it must make a guess. If you think that the array is \\((a_1,\ldots,a_n)\\), print ! \\( a_1 \ a_2 \ldots \ a_n \\) on a separate line and terminate.

If your solution makes more than \\(\lfloor 5n/3 \rfloor + 5\\) queries, the interactor will finish with the WA verdict. If you do not flush the output after printing a query, you may receive the IL verdict.

Note that the interactor in this task is **adaptive**, i.e. the array may be generated at the runtime consistently with your questions.

## Example

| standard input | standard output |
|----------------|-----------------|
| 5              | ? 5 4           |
| <              | ? 5 1           |
| >              | ? 5 3           |
| >              | ? 3 1           |
| <              | ? 2 1           |
| >              | ? 5 2           |
| >              | ! 2 3 1 5 4     |

type: interactive

time: 3s
memory: 512m

interactor: interactor.cpp
interactor_type: testlib

subtasks:
  - score: 100
    n_cases: 3


worldmap
Day 1 Tasks
English (ISC)
World Map
Mr. Pacha, a Bolivian archeologist, discovered an ancient document near Tiwanaku that describes
the world during the Tiwanaku Period (300-1000 CE). At that time, there were N countries,
numbered from 1 to N.
In the document, there is a list of M diﬀerent pairs of adjacent countries:
(A[0],B[0]),(A[1],B[1]),…,(A[M−1],B[M−1]).
For each i (0≤i<M), the document states that country A[i] was adjacent to country B[i] and
vice versa. Pairs of countries not listed were not adjacent.
Mr. Pacha wants to create a map of the world such that all adjacencies between countries are
exactly as they were during the Tiwanaku Period. For this purpose, he ﬁrst chooses a positive
integer K. Then, he draws the map as a grid of K×K square cells, with rows numbered from 0
to K−1 (top to bottom) and columns numbered from 0 to K−1 (left to right).
He wants to color each cell of the map using one of N colors. The colors are numbered from 1 to
N, and country j (1≤j≤N) is represented by color j. The coloring must satisfy all of the
following conditions:
For each j (1≤j≤N), there is at least one cell with color j.
For each pair of adjacent countries (A[i],B[i]), there is at least one pair of adjacent cells
such that one of them is colored A[i] and the other is colored B[i]. Two cells are adjacent if
they share a side.
For each pair of adjacent cells with diﬀerent colors, the countries represented by these two
colors were adjacent during the Tiwanaku Period.
For example, if N=3, M=2 and the pairs of adjacent countries are (1,2) and (2,3), then the
pair (1,3) was not adjacent, and the following map of dimension K=3 satisﬁes all the conditions.
worldmap (1 of 5)In particular, a country does not need to form a connected region on the map. In the map above,
country 3 forms a connected region, while countries 1 and 2 form disconnected regions.
Your task is to help Mr. Pacha choose a value of K and create a map. The document guarantees
that such a map exists. Since Mr. Pacha prefers smaller maps, in the last subtask your score
depends on the value of K, and lower values of K may result in a better score. However, ﬁnding
the minimum possible value of K is not required.
Implementation Details
You should implement the following procedure as well as a main function:
std::vector<std::vector<int>> create_map(int N, int M,
    std::vector<int> A, std::vector<int> B)
N: the number of countries.
M: the number of pairs of adjacent countries.
A and B: arrays of length M describing adjacent countries.
The procedure should return an array C that represents the map. Let K be the length of C.
Each element of C must be an array of length K, containing integers between 1 and N
inclusive.
C[i][j] is the color of the cell at row i and column j (for each i and j such that 0≤i,j<K).
K must be less than or equal to 240.
Constraints
1≤N≤40
0≤M≤
1≤A[i]<B[i]≤N for each i such that 0≤i<M.
2
N⋅(N−1)
worldmap (2 of 5)The pairs (A[0],B[0]),…,(A[M−1],B[M−1]) are distinct.
There exists at least one map which satisﬁes all the conditions.
Scoring
You need to make R = K/N as small as possible and a smaller R will result in a better score.
Example
In CMS, both of the following scenarios are included as part of a single test case.
Example 1
Consider the following call:
2
N⋅(N−1)
worldmap (3 of 5)create_map(3, 2, [1, 2], [2, 3])
This is the example from the task description, so the procedure can return the following map.
[
[2, 3, 3],
[2, 3, 2],
[1, 2, 1]
]
Example 2
Consider the following call:
create_map(4, 4, [1, 1, 2, 3], [2, 3, 4, 4])
In this example, N=4, M=4 and the country pairs (1,2), (1,3), (2,4), and (3,4) are adjacent.
Consequently, the pairs (1,4) and (2,3) are not adjacent.
The procedure can return the following map of dimension K=7, which satisﬁes all the
conditions.
[
[2, 1, 3, 3, 4, 3, 4],
[2, 1, 3, 3, 3, 3, 3],
[2, 1, 1, 1, 3, 4, 4],
[2, 2, 2, 1, 3, 4, 3],
[1, 1, 1, 2, 4, 4, 4],
[2, 2, 1, 2, 2, 4, 3],
[2, 2, 1, 2, 2, 4, 4]
]
The map could be smaller; for example, the procedure can return the following map of dimension
K=2.
[
[3, 1],
[4, 2]
]
Note that both maps satisfy K/N≤2.
worldmap (4 of 5)Sample Grader
The ﬁrst line of the input should contain a single integer T, the number of scenarios. A description
of T scenarios should follow, each in the format speciﬁed below.
Input Format:
N M
A[0] B[0]
:
A[M-1] B[M-1]
Output Format:
P
Q[0] Q[1] ... Q[P-1]
C[0][0] ... C[0][Q[0]-1]
:
C[P-1][0] ... C[P-1][Q[P-1]-1]
Here, P is the length of the array C returned by create_map , and Q[i] (0≤i<P) is the length of
C[i]. Note that line 3 in the output format is intentionally left blank.
worldmap (5 of 5)

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


```markdown
# Problem K: Probing the Disk

**Time Limit: 2 seconds**

*This is an interactive problem.*

A thin black disk is laid flat on the square bottom of a white box. The sides of the box bottom are 10^5 units long.

Somehow, you are not allowed to look into the box, but you want to know how large the disk is and where in the box bottom the disk is laid. You know that the shape of the disk is a true circle with an integer units of radius, not less than 100 units, and its center is integer units distant from the sides of the box bottom. The radius of the disk is, of course, not greater than the distances of the center of the disk from any of the sides of the box bottom.

You can probe the disk by projecting a thin line segment of light to the box bottom. As the reflection coefficients of the disk and the box bottom are quite different, from the overall reflection intensity, you can tell the length of the part of the segment that lit the disk.

Your task is to decide the exact position and size of the disk through repetitive probes.

## Interaction

You can repeat probes, each of which is a pair of sending a query and receiving the response to it. You can probe at most 1024 times.

A query should be sent to the standard output in the following format, followed by a newline.

```
query x1 y1 x2 y2
```

Here, (x1, y1) and (x2, y2) are the positions of the two ends of the line segment of the light. They have to indicate distinct points. The coordinate system is such that one of the corners of the box bottom is the origin (0, 0) and the diagonal corner has the coordinates (10^5, 10^5). All of x1, y1, x2, and y2 should be integers between 0 and 10^5, inclusive.

In response to this query, a real number is sent back to the standard input, followed by a newline. The number indicates the length of the part of the segment that lit the disk. It is in decimal notation without exponent part, with 7 digits after the decimal point. The number may contain an absolute error up to 10^−6.

When you become sure about the position and the size of the disk through the probes, you can send your answer. The answer should have the center position and the radius of the disk. It should be sent to the standard output in the following format, followed by a newline.

```
answer x y r
```

Here, (x, y) should be the position of the center of the disk, and r the radius of the disk. All of x, y, and r should be integers.

After sending the answer, your program should terminate without any extra output. Thus, you can send the answer only once.

### Notes on interactive judging

When your output violates any of the conditions above (incorrect answer, invalid format, x1, y1, x2, or y2 being out of the range, too many queries, any extra output after sending your answer, and so on), your submission will be judged as a wrong answer. As some environments require flushing the output buffers, make sure that your outputs are actually sent. Otherwise, your outputs will never reach the judge.

You are provided with a command-line tool for local testing. For more details, refer to the clarification in the contest system.

**Figure K.1. Sample Interaction**

Read

```
60000.0000000
0.0000000
12315.3774869
```

Write
```
query 40000 0 40000 100000
query 0 10000 100000 10000
query 60000 60000 80000 80000
answer 40000 60000 30000
```


# Let's Go! New Adventure

**Input file:** standard input
**Output file:** standard output
**Time limit:** 3 seconds
**Memory limit:** 1024 megabytes

In Pigeland, Pishin is a popular open-world action RPG where users can play multiple characters. Each character has an independent adventure rank, which increases as they earn experience points (EXP) while being played. Initially, every character starts with an adventure rank of level 0 and can progress up to a maximum level of \( m \). To advance from level \((i-1)\) to level \( i \) (\( 1 \leq i \leq m \)), the character is required to earn \( b_i \) EXP.

Grammy plans to play Pishin for the next \( n \) days. As a rich girl, her Pishin account has an infinite number of characters. However, being a lazy girl, all characters in her account start with an adventure rank of level 0 at the beginning of the \( n \) days. Each day, Grammy will select exactly one character to play, but once she stops playing a character, she cannot resume playing that character on any future day. In other words, she can only continue playing the same character on consecutive days.

On the \( i \)-th day, Grammy will earn \( a_i \) EXP for the character she plays. This means that if she plays a character continuously from the \( l \)-th day to the \( r \)-th day (both inclusive), the character's adventure rank will increase to level \( k \), where \( k \) is the largest integer between 0 and \( m \) such that the total EXP earned (which is \(\sum_{i=l}^{r} a_i\)) is greater than or equal to the requirement of leveling up to \( k \) (which is \(\sum_{i=1}^{k} b_i\)).

Being a greedy girl, Grammy wants to maximize the total sum of adventure ranks across all her characters after the \( n \) days. However, as a single-minded girl, she doesn't want to play too many different characters. To balance this, she introduces a penalty factor of \( c \). Her goal is to maximize the total sum of adventure ranks across all characters after the \( n \) days, minus \( c \times d \), where \( d \) is the number of different characters she plays. As Grammy's best friend, your task is to compute the maximum value she can achieve under the optimal strategy for selecting characters.

## Input

There are multiple test cases. The first line of the input contains an integer \( T \) (\( 1 \leq T \leq 5 \times 10^4 \)) indicating the number of test cases. For each test case:

- The first line contains three integers \( n \), \( m \) and \( c \) (\( 1 \leq n, m \leq 5 \times 10^5, 0 \leq c \leq 5 \times 10^5 \)).
- The second line contains \( n \) integers \( a_1, a_2, \cdots, a_n \) (\( 0 \leq a_i \leq 10^{12}, 0 \leq \sum_{i=1}^{n} a_i \leq 10^{12} \)).
- The third line contains \( m \) integers \( b_1, b_2, \cdots, b_m \) (\( 0 \leq b_i \leq 10^{12}, 0 \leq \sum_{i=1}^{m} b_i \leq 10^{12} \)).

It is guaranteed that neither the sum of \( n \) nor the sum of \( m \) of all test cases will exceed \( 5 \times 10^5 \).

## Output

For each test case, output one line containing one integer, indicating the maximum value.

## Example

**standard input**
```
2
5 4 2
1 0 3 1 2
0 1 1 2
4 5 1
7 16 23 4
1 3 6 20 20
```

**standard output**
```
3
6
```

## Note

For the first sample test case, one solution is to use the first three days to get a character with adventure rank 4 and the next two days to get another character with adventure rank 3. This gives us a value of \((4-2)+(3-2)=3\).

For the second sample test case, we can play a different character each day; this gives us adventure ranks 2, 3, 3, and 2, respectively. So the value is \((2-1)+(3-1)+(3-1)+(2-1)=6\).

type: default

time: 3s
memory: 1024m

checker: check.cpp
cheker_type: testlib
subtasks:
  - score: 100
    n_cases: 3


Ball Moving Game

Xiao C is playing a ball-moving game. In front of him, there are n + 1 pillars, numbered from 1 to n + 1. On each of the first n pillars, there are m balls placed from bottom to top, while pillar (n + 1) initially has no balls. Altogether there are n × m balls in n different colors, with exactly m balls of each color.

At the beginning, the balls on a pillar may be of different colors. Xiao C’s task is to move all balls of the same color onto the same pillar. This is the only objective, and there is no restriction on which pillar each color ends up on.

Xiao C can achieve this by performing a sequence of operations. In each operation, he can move the top ball from one pillar to another. More specifically, moving a ball from pillar x to pillar y must satisfy:

Pillar x has at least one ball.

Pillar y has at most (m - 1) balls.

Only the top ball of pillar x can be moved, and it must be placed on top of pillar y.

The task itself is not too difficult, so Xiao C adds a restriction for himself: the total number of operations must not exceed 10^7. In other words, Xiao C needs to complete the goal using at most 10^7 operations. Specifically, your score will be (10^7 - k) / 10^7, where k is the number of operations.

Although Xiao C feels stuck, he believes you can solve it. Please output a valid sequence of operations to achieve the goal. Multiple correct solutions may exist; you only need to output one. It is guaranteed that at least one valid solution exists.

Input

The first line contains two integers n and m: the number of colors, and the number of balls of each color.

The following n lines each contain m integers, separated by spaces.

For the i-th line, the integers (from bottom to top) give the colors of the balls on pillar i.

Output

The first line of your output should contain a single integer k, the number of operations in your solution, where 0 ≤ k ≤ 10^7.

Each of the following k lines should contain two integers x and y, meaning you move the top ball of pillar x onto the top of pillar y.

You must guarantee that 1 ≤ x, y ≤ n + 1 and x ≠ y.

Sample Input 1

3 2
1 2
3 2
1 2

Sample Output 1

6
2 1
3 2
3 2
3 1
3 2
3 2

Explanation of Sample 1

Pillars are shown as stacks from bottom to top.
After performing the operations step by step, all balls of the same color are gathered on the same pillar.


Space Thief

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.

You are active as a thief in the JOI galaxy.

There are N stars, numbered from 0 to N − 1, in the JOI galaxy.
There are M warp devices, numbered from 0 to M − 1.
Each warp device i (0 ≤ i ≤ M − 1) connects two stars U_i and V_i bidirectionally.
It is possible to travel between any two stars using warp devices.

A key is hidden in one star, and a treasure box is hidden in another.
Your mission is to determine the numbers of the stars where the key and the treasure box are hidden.

To do this, you may ask up to 600 questions of the following form:

For each warp device i (0 ≤ i ≤ M − 1), choose one of two directions:

Allow travel only from U_i to V_i.

Allow travel only from V_i to U_i.

Then ask whether it is possible to travel from the star containing the key to the star containing the treasure box under these directed conditions.

Your goal is to identify the star A containing the key and the star B containing the treasure box while minimizing the number of questions. Let q be the number of queries you asked, your score will be (600 - q) / 600.

Constraints

2 ≤ N ≤ 10,000

1 ≤ M ≤ 15,000

0 ≤ A, B ≤ N − 1 and A ≠ B

0 ≤ Ui < Vi ≤ N − 1

All pairs (Ui, Vi) are unique

The graph is connected (travel possible between any two stars)

Input

The first line contains two integers: N and M.

For the next M lines, the i-th line contains 2 integers: U_{i-1} and V_{i-1}.

Interaction

To ask a query, output one line. First output 0 followed by a space, then output a sequence of m integers of 0 or 1 separated by a space. After flushing your output, your program should read a single integer x, x = 0 means that it is not possible to travel from the star A to the star B by using warp devices, x = 1 means that it is possible to travel from the star A to the star B by using warp devices.

If you want to guess the star A and the star B, output one line. First output 1 followed by a space. Then output A followed by a space, then output B. 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: 2 seconds

Memory Limit: 1024 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: 2s
memory: 1024m

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


Given (1 <= n <= 1e2) and (B = 1e15), n integers a_1 … a_n (0 <= a_i <= B) drawn from either (normal, uniform, pareto, exponential) distributions, find a subset of a_1..a_n that sums as close as possible to T=x_i*a_i, x_i drawn from Bernoulli (1/2).

Score = 100 * (15 - log(error + 1)) / 15

25% of the test cases will be from U(0, B)
25% of the test cases will be from N(B/2, B/6)
25% of the test cases will be from Exp(B/2)
25% of the test cases will be from TruncatedPareto(m=B/3, alpha=2, max=B)

Input:
n T
A_1 a_2 a_3 a_4 .. a_n

Output:
Print a binary string of length n, denoting the subset selection.

Sample input:
3 4
1 2 3

Sample output:
101

type: default
# The time limit is now 1 second.
time: 10s # Let asymtotics beat constant factor and heuristic BS
memory: 1024m # 1GB should be enough for checkpointing backtrack
# A custom checker is required for the special scoring.
checker: chk.cc
subtasks:
  - score: 100
    n_cases: 3


Pen

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.

There are n pens, numbered from 0 to n − 1.
Each pen contains a certain amount of ink — let the i-th pen have p_i units of ink.
You only know that (p_0, p_1, …, p_{n-1}) is a permutation of 0 … n − 1, but you do not know the exact values of p_i.

Your task is to choose two pens such that together they have at least n units of ink remaining.

You cannot directly query the amount of ink in any pen.
Instead, you can only “try to write” with a pen — then you will learn whether it can still write or not.
If it can write, it will consume 1 unit of ink.

Note that the requirement refers to the remaining ink in the two chosen pens:
when you finally select them, their total remaining ink must be at least n.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1001). The description of the test cases follows.

Each test case contains one integer n (10 ≤ n ≤ 25), the number of pens.

Interaction

To use a pen, output one line. First output 0 followed by a space, then output the number of the pen you want to use. After flushing your output, your program should read a single integer x, x = 0 means that the pen was already empty, x = 1 means the pen still had ink before consuming 1 unit of ink (can be empty now).

If you want to select two pens, output one line. First output 1 followed by a space. Then output the number of those two pens, separated by a space. Note that they cannot be the same pen. After flushing your output, you should start processing the next test case (or end the code if there is no next test case).

# 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: 512m

# 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: 10 seconds
Memory limit per test: 256 megabytes
Note: The only difference between versions of this problem is the maximum value of n.

Overview
Professor Vector is preparing to teach her Arithmancy class. She needs to prepare n distinct magic words for the class. Each magic word is a string over the alphabet {X, O}. A spell is created by concatenating two magic words. The power of a spell is defined as the number of distinct non-empty substrings of the resulting string.

Example: The power of the spell "XOXO" is 7, because it has 7 distinct non-empty substrings:
X, O, XO, OX, XOX, OXO, XOXO.

Task Summary
Your program must:
1) Read n and output n distinct magic words (w1, w2, ..., wn).
2) Then read q (the number of students/queries).
3) For each student j = 1..q:
   - Read pj, the power of the student’s spell.
   - Output the exact pair of indices (uj, vj) such that concatenating w_uj followed by w_vj produces a string whose power is pj.
   - The order matters: you must output the indices in the correct order (first word, then second word).

Interaction Protocol (Interactive Problem)
1) Input: A single integer n (1 ≤ n ≤ 1000), the number of magic words to prepare.
2) Output: Print n distinct magic words, one per line.
   - Each magic word must:
     • Consist only of characters 'X' and 'O'.
     • Have length between 1 and 30·n (inclusive).
   - Denote the i-th printed word as w_i (1 ≤ i ≤ n).
   - After printing all n words, flush the output.

3) Input: A single integer q (1 ≤ q ≤ 1000), the number of students.
4) For each of the q students:
   - Input: A single integer pj, the power of their spell.
     • It is guaranteed that pj was produced as follows:
       ◦ Two indices uj and vj were chosen independently and uniformly at random from {1, 2, ..., n}.
       ◦ The spell S was formed by concatenating w_uj and w_vj (in this order).
       ◦ pj equals the number of distinct non-empty substrings of S.
   - Output: Print the two integers uj and vj (1 ≤ uj, vj ≤ n) in this order.
   - Flush after printing each pair (uj, vj).

Important Requirements and Notes
• Distinctness: All n magic words you output must be distinct.
• Alphabet: Only 'X' and 'O' are allowed in each magic word.
• Length bounds: For each word, 1 ≤ |w_i| ≤ 30·n.
• Exact identification: For each query, it is not enough to find any pair that yields pj. You must identify the exact two words used by the student and the correct order (w_uj then w_vj).
• Flushing: Remember to flush after:
  – Printing all n words.
  – Printing each answer pair (uj, vj).

Definitions
• Magic word: A string over {X, O}.
• Spell: Concatenation of two magic words (w_a followed by w_b).
• Power of a string: The number of different non-empty substrings of that string.

Constraints
• 1 ≤ n ≤ 1000
• 1 ≤ q ≤ 1000
• For each i: 1 ≤ |w_i| ≤ 30·n
• Alphabet: {X, O} only

Example
Input (conceptual, since the problem is interactive):
2
2
15
11

Output (one possible valid interaction transcript):
XOXO
X
1 1
2 1

Explanation of the example:
• After reading n = 2, the program outputs two distinct magic words, e.g., w1 = "XOXO" and w2 = "X" (flush).
• Then q = 2 is read.
• For the first student, the power p1 = 15 is read; the program answers with the indices "1 1".
• For the second student, the power p2 = 11 is read; the program answers with the indices "2 1".
(Exact details of powers and indices depend on the judge’s random choices and the specific words you output.)

Scoring:
Your score for this problem is not just an AC or WA verdict. The scoring is based on the following formula:
(30n^2 - Total length of your magic words)/(30n^2 - Optimal total length of magic words)
Your goal is to maximize your score.

# 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: 10s
memory: 256m

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


Build a Computer
Input ﬁle: standard input
Output ﬁle: standard output
Time limit: 1 second
Memory limit: 1024 megabytes
You want to build a computer to achieve a speciﬁc functionality: Given an integerx, determine whether
x lies within the interval[L, R]. To accomplish this, you designed a directed acyclic graph (DAG) with
edge weights of0 and 1, which contains a starting node with an indegree of0 and an ending node with an
outdegree of0. By starting from the starting node and following a path to the ending node, the sequence
of the traversed edge weights forms a binary representation of an integer within the range[L, R] without
leading zeros. Every integer within the range[L, R] must correspond to exactly one unique path in this
graph. In this way, you can determine whether an integer lies within the range[L, R] by checking if its
binary representation can be constructed by traversing this DAG.
Clearly, you could separate the corresponding path for each integer into individual chains. However, you
realized that for a large range, such a DAG would require too many nodes, and the computer you built with
only 256 MiB of memory cannot store it. Therefore, you need to compress this DAG, allowing diﬀerent
paths to share nodes, in order to reduce the number of nodes and edges. Formally, you need to construct
a DAG with no more than100 nodes, where each node has an outdegree of at most200. The DAG must
have edge weights of0 and 1, with exactly one starting node with an in-degree of0 and one ending node
with an out-degree of0. Every integer in the range[L, R] must correspond toexactly one unique path
from the start to the end in this DAG, and no path should represent any integer outside the range[L, R].
Note that none of the binary sequences formed by any path in the graph should have leading zeros. There
may be two edges with diﬀerent weights between two nodes.
Input
A single line containing two positive integersL, R(1 ≤L ≤R ≤106).
Output
The ﬁrst line should output the number of nodesn (1 ≤n ≤100). You need to make n as small as possible and your score will be determined by the value of n.
For the nextn lines, thei-th line should start with an integerk (0 ≤k ≤200), representing the number
of outgoing edges from nodei. Then output2 ·k integers ai,k, vi,k (1 ≤ai,k ≤n, ai,k ̸= i, vi,k ∈{0, 1}),
which means that nodei has a directed edge with weightvi,k to node ai,k. You must ensure that the
output represents a directed acyclic graph that satisﬁes the requirements.
Example
standard input standard output
5 7 8
3 2 1 3 1 4 1
1 5 0
1 6 1
1 7 1
1 8 1
1 8 0
1 8 1
0
Page 1 of 1

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


Problem: Treasure Hunt

Time limit: 5 seconds

Memory limit: 256 MB

This is an interactive problem.

Imagine you are a treasure hunter exploring an ancient map represented as an undirected graph with n vertices (junctions) and m edges (roads). You start at a known fixed vertex. Your goal is to visit every vertex in the graph at least once to collect treasures.

However, a wicked wizard is working against you. While the structure of the graph remains constant, the wizard shuffles the order of the roads at every junction each time you arrive. You cannot see the labels of the adjacent vertices. Instead, when standing at a junction, you can only see:
- The degree of the current vertex.
- For each adjacent vertex: its degree and whether you have visited it before (indicated by a flag).

You must navigate the graph and collect all treasures as fast as possible. You are provided with a base_move_count, and your score depends on how close your move count is to this baseline.

Scoring:
Let moves be the number of moves you take.
If moves <= base_move_count, you get:
   100 - c * (sol_fraction - 1)
   where c = 90 / sqrt(base_fraction - 1)
   base_fraction = (base_move_count + 1) / n
   sol_fraction = (moves + 1) / n

If base_move_count < moves <= 2 * base_move_count, you get:
   20 * (1.0 - (moves + 1) / (base_move_count + 1)) points.

If moves > 2 * base_move_count, you get 0 points.

Interaction Protocol

First, the interactor prints an integer t (1 <= t <= 5), the number of maps to solve.
Then for each map, the interactor prints the graph description:
- Four integers: n, m, start, base_move_count.
  (2 <= n <= 300, 1 <= m <= min(n(n-1)/2, 25n), 1 <= start <= n).
- m lines describing the edges u, v (1 <= u, v <= n).

After the graph description, the interaction begins. The interactor prints vertex descriptions in the format:
   d deg_1 flag_1 deg_2 flag_2 ... deg_d flag_d
   where d is the degree of the current vertex, deg_i is the degree of the i-th neighbor, and flag_i (0 or 1) indicates if that neighbor has been visited.

To make a move, you must output a single integer i (1 <= i <= d), choosing the i-th neighbor described in the current line.
Remember to use the flush operation after each output.

The interaction ends for a map when:
- You have visited all vertices: The interactor prints "AC".
- You have exceeded the move limit: The interactor prints "F".
You must then proceed to the next map or terminate if it was the last one.

Example Input:
1
3 3 1 1000
1 2
2 3
3 1
2 2 0 2 0

2 2 0 2 1

2 2 0 2 1

AC

Example Output:

1

2

1

# 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: 5s
memory: 256m

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


Puzzle

There is a puzzle game. The board is a 6 × 6 grid with grooves in the tiles to allow vehicles to slide. Cars and trucks are both one square wide, but cars are two squares long and trucks are three squares long. Vehicles can only be moved forward or backward along a straight line on the grid. The goal of the game is to get the only red car totally out through the exit of the board by moving the other vehicles out of its way.
We give each vehicle of a puzzle a unique id, numbered from 1 to the number of vehicles, in which the red car's id is 1. The board information of a puzzle is represented by a 6 × 6 matrix, named board matrix. Each entry of a board matrix is the id of the vehicle placed on that groove, and the entries are filled with 0 if there exists no vehicle on those grooves. The exit of the board is located at the right end side of the 3rd row.
Moving a piece by one unit is called a step.
Given an initial puzzle, you can conduct a sequence of moves to form a new puzzle.
Your task is to maximum the minimum number of steps required to solve the new puzzle and output the sequence of moves to form the new puzzle.

Input
The input contains 6 lines, each line indicates the content (6 integers separated by a blank) of each row of a board matrix.

Output
First, output two integers in one line, representing the minimum number of steps required to solve the new puzzle and the number of steps to form the new puzzle.
Then, output the sequence of moves to form the new puzzle. Each move should be on a separate line in the format:
    vehicle_id direction
where:
- vehicle_id is the id of the vehicle to move (1 to n)
- direction is one of: U (up), D (down), L (left), R (right)

Scoring
This problem uses a scoring system based on your solution's efficiency.
Let your_steps be the minimum number of steps required to solve the new puzzle in your solution, and ref_steps be the minimum number of steps required to solve the new puzzle in the reference solution.
Your score for each test case is calculated as follows:
   score = 100 * min((your_steps + 1) / (ref_steps + 1), 1)
Your final score is the average of your scores across all test cases.

Technical Specification
- There are at most 10 vehicles in the puzzle.
- The red car is always horizontal and positioned on the 3rd row.
- All vehicles can only move forward or backward along their orientation (horizontal vehicles move left/right, vertical vehicles move up/down).
- It is guaranteed there is a solution for each initial puzzle.

Example

Sample input:
0 0 0 0 0 0
0 0 0 0 0 0
0 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

Sample output:
6 1
1 L

Time limit: 2 seconds
Memory limit: 1024 MB

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


Inversion

Description

This is an interactive problem.

There is a hidden permutation p1, p2, ..., pn of {1, 2, ..., n}.
You want to find it by asking for the parity (even or odd) of the number of inversions in a subarray pl, ..., pr.

You can query in the format:
0 l r
and the interactor will respond with
(sum over all l ≤ i < j ≤ r of [pi > pj]) mod 2

Here, [pi > pj] equals 1 if pi > pj, and 0 otherwise.

Interaction Protocol

1. First, read an integer n (1 ≤ n ≤ 2000).
2. You can make no more than 1999000 queries.

To make a query, output
0 l r
(where 1 ≤ l ≤ r ≤ n)
on a separate line, then read the response from standard input.

To give your final answer, print
1 p1 p2 ... pn
on a separate line.
The output of your final answer does not count toward the limit of 1999000 queries. Your score will be (exp(-q/249875) - exp(-8)) / (1 - exp(-8)), where q is the number of queries.

After printing a query, remember to flush the output, using for example:
- fflush(stdout) or cout.flush() in C++
- System.out.flush() in Java
- flush(output) in Pascal
- stdout.flush() in Python

It is guaranteed that the permutation is fixed in advance.

Example
Standard input:
3
0
0
1

Standard output:
? 1 2
? 1 3
? 2 3
! 2 3 1

# 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: 1024m

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


Black and White

Time limit: 2 seconds
Memory limit: 256 megabytes

------------------------------------------------------------
The jury has a great artistic idea — to create a rectangular
panel out of a huge pile of black and white squares of the
same size. The panel should have exactly b 4-connected areas
made of black tiles, and w 4-connected areas made of white tiles.

A 4-connected area of some color is a maximal set of the
panel tiles such that:
• any two tiles of the area share the same color;
• for any two tiles of the area there is a tile sequence
  connecting them, such that any two consecutive tiles of
  the sequence share a common side.

You will also be given two integers x, y. Try to minimize x * (the number of black tiles in your grid) + y * (the number of white tiles in your grid).

------------------------------------------------------------
Input
------------------------------------------------------------
The only line of the input file contains four integers b, w —
number of black and white areas (1 ≤ b, w ≤ 1000) and x, y - grading coefficients (1 ≤ x, y ≤ 1000).

------------------------------------------------------------
Output
------------------------------------------------------------
The first line of the output file should contain the picture sizes
r and c — the number of rows and columns (1 ≤ r, c ≤ 100 000).
This line should be followed by r lines of c symbols each.
Each symbol should be either '@' (for black tile) or '.' (for
white one). There should be no more than 100 000 tiles in
the panel.

------------------------------------------------------------
Example
------------------------------------------------------------
Input:
2 3 5 6

Output:
6 7
@@@@@@@
@.@@@@@
@@...@@
@@@@@@@
.......
@@@@@@@

# 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: 256m

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


Problem:
Time limit: 3 seconds
Memory limit: 512 megabytes
The popular improv website Interpretation Impetus hosts regular improv contests and maintains a rating
of the best performers. However, since improv can often go horribly wrong, the website is notorious for
declaring improv contests unrated. It now holds a wager before each improv contest where the participants
try to predict whether it will be rated or unrated, and they are now more popular than the improv itself.
Izzy andnother participants take part in each wager. First, they each make their prediction, expressed as
1 (“rated”) or0 (“unrated”). Izzy always goes last, so she knows the predictions of the other participants
when making her own. Then, the actual competition takes place and it is declared either rated or unrated.
You need to write a program that will interactively play as Izzy. There will be m wagers held in 2021,
and Izzy’s goal is to minimize the number of wrong predictions after all those wagers. Izzy knows nothing about the other participants /emdash.cyr they might
somehow always guess correctly, or their predictions might be correlated. Izzy’s predictions, though, do
not aﬀect the predictions of the other participants and the decision on the contest being rated or not /emdash.cyr in
other words, in each test case, your program always receives the same inputs, no matter what it outputs.
Interaction Protocol
First, a solution must read two integers n (1 ≤n ≤1000) and m (1 ≤m ≤10 000). Then, the solution
must process m wagers. For each of them, the solution must ﬁrst read a string consisting of n 0s and 1s,
in which the i-th character denotes the guess of the i-th participant. Then, the solution must print Izzy’s
guess as 0 or 1. Don’t forget to ﬂush the output after printing it! Then, the solution must read the actual
outcome, also as 0 or 1, and then proceed to the next wager, if this wasn’t the last one.
Suppose your solution has c wrong predictions, your score will be min((2*b-c)/b, 1)*100, where b is the smallest
number of mistakes made by any other participant. If you . Note that if a solution outputs anything except 0 or
1 for a wager, it will be considered incorrect even if it made no other mistakes.
There are 200 test cases in this problem.
Example
standard input standard output
3 4
000
1
100
1
001
0
111
1
0
0
1
1
Note
In the example, the participants made 1, 2, and 3 mistakes respectively, thereforeb= 1(the smallest of
these numbers). Izzy made 3 mistakes, which were not more than 1.3 ·b + 100 = 101.3, so these outputs
are good enough to pass this test case (as are any other valid outputs).
Page 12 of 14

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


Problem H. Hack
Time limit: 10 seconds

Heidi is analyzing a peculiar device. This device takes an `a` as input and computes `a^d (mod n)` using the following pseudocode and some integers `d` and `n` stored in this device:

```
1 modPow(a, d, n) {
2   r=1;
3   for (i=0;i<60;++i) {
4     if ((d&(1<<i))!=0) {
5       r=r*a%n
6     }
7     a=a*a%n;
8   }
9 }
```

Note that the pseudocode assumes arbitrary sized integers, `<<` denotes bitwise shift left, `&` denotes bitwise and, and `%` denotes modulo.

The device does not tell Heidi the result of the computation. However, Heidi can measure how long does the computation take. She knows that only multiplication modulo n (lines 5 and 7 in the above pseudocode) takes any measurable amount of time, all other lines can be assumed to take 0 nanoseconds.

Moreover, she knows that it takes `(bits(x)+1) * (bits(y)+1)` nanoseconds to multiply `x` by `y` modulo n, where `bits(x)` is the number of bits in the binary representation of `x` without leading zeros, or more formally `bits(x) = ceil(log2(x+1))`.

Heidi knows the integer `n` but does not know the integer `d`. She wants to find `d` by feeding the device different integers `a` as input and measuring the time the computation takes for each `a`.

She knows that `n` and `d` were chosen in the following way: first, two prime numbers `p` and `q` with 30 bits in binary representation (in other words, between `2^29` and `2^30 - 1`) were picked independently and uniformly at random. Then the number `n` was computed as `n = p * q`. Then the number `m = phi(n) = (p - 1) * (q - 1)` was computed. Then `d` was picked uniformly at random between 1 and `m - 1` inclusive, such that it is coprime with `m`.

Interaction Protocol

First, the testing system writes the integer `n` - the modulo used by the device. Note that `n` and the hidden number `d` are guaranteed to have been generated according to the procedure described above.

Your solution shall print requests of two types:

  * "? `a`" tells to feed `a` as input to the device. `a` must be an integer between 0 and `n - 1` inclusive. The testing system responds with the time it took the device to compute modPow `(a, d, n)` in nanoseconds.
  * "\! `d`" tells the value of `d` that your program has determined.

Don't forget to flush the output after each request\!

Your solution must issue exactly one request of the second type, which must be the last request, and the solution must terminate gracefully after issuing it.

Your solution is allowed to issue at most 30000 requests of the first type.

Your solution will be run on 30 testcases, working with one `(n, d)` pair per run. For each testcase the numbers `n` and `d` are fixed and were generated using the procedure described above. The example below was not generated in that manner and thus will not be used for testing your solution; it only serves to illustrate the input/output format and provide a sanity check for your calculation of the computation time.

Examples

(System output) 15
(Your output) ? 3
(System output) 980
(Your output) ? 8
(System output) 293
(Your output) \! 5

Notes

In the first request in the example case, the following multiplications are done by the device when computing modPow(3, 5, 15):

1.  `1 * 3 (mod 15) = 3`, taking 6 nanoseconds
2.  `3 * 3 (mod 15) = 9`, taking 9 nanoseconds
3.  `9 * 9 (mod 15) = 6`, taking 25 nanoseconds
4.  `3 * 6 (mod 15) = 3`, taking 12 nanoseconds
5.  `6 * 6 (mod 15) = 6`, taking 16 nanoseconds
6.  `6 * 6 (mod 15) = 6`, taking 16 nanoseconds
7.  `6 * 6 (mod 15) = 6`, taking 16 nanoseconds
    (55 more repetitions of the last multiplication)

The computation takes `6 + 9 + 25 + 12 + 58 * 16 = 980` nanoseconds.

A positive integer is prime if it has exactly two divisors: 1 and itself.
Two positive integers are coprime if their greatest common divisor is 1.

Here are a few first values of the function `bits()`:

  * `bits(0) = 0`
  * `bits(1) = 1`
  * `bits(2) = 2`
  * `bits(3) = 2`
  * `bits(4) = 3`

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


The Empress

Capoo invented an interesting language named Push-Pop. This language is an interpreted language. The interpreter starts with an empty stack with infinite capacity and reads the first instruction of the custom program. There are only two kinds of instructions in this language:

POP a GOTO x PUSH b GOTO y

If the top element of the stack is a, then pop the stack once and transfer the control flow to the x-th instruction (which means the next instruction will be the x-th).

Otherwise, push an element b into the stack and transfer the control flow to the y-th instruction.

HALT PUSH b GOTO y

If the stack is empty, halt the whole program after executing this instruction. Otherwise, push an element b into the stack and transfer the control flow to the y-th instruction. Capoo wants to construct a Push-Pop program that halts after executing exactly k instructions. A program can contain at most 512 instructions. Then, let n be the number of instructions, your score will be (512 - n) / 512.

Input

The only line contains a single integer k (1 <= k <= 2^31 − 1, k is odd).

Output

The first line contains an integer n (1 <= n <= 512) denoting the number of instructions, and then follows n lines denoting the Push-Pop program. For each instruction, 1 <= a, b ≤ 1024, 1 <= x, y <= n should hold. It is guaranteed that a solution exists for given input.

Example Input 1:

1

Example Output 1:

1
HALT PUSH 1 GOTO 1

Example Input 2:

5

Example Output 2:

5
POP 1 GOTO 2 PUSH 1 GOTO 2
HALT PUSH 1 GOTO 3
POP 1 GOTO 4 PUSH 2 GOTO 4
POP 1 GOTO 2 PUSH 2 GOTO 4
HALT PUSH 99 GOTO 4

# Set the problem type to interactive
type: default

# Specify the interactor source file
checker: chk.cc

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

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


Indiana Jones and the Uniform Cave

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.

Indiana Jones has stuck in the Uniform Cave.
There are many round chambers in the cave, and all of them are indistinguishable from each other.
Each chamber has the same number of one-way passages evenly distributed along the chamber’s wall.
Passages are indistinguishable from each other, too.

The Cave is magical. All passages lead to other chambers or to the same one.
However, the last passage, after all passages are visited, leads to the treasure.
Even the exact number of chambers is a mystery.
It is known that each chamber is reachable from each other chamber using the passages.

Dr. Jones noticed that each chamber has a stone in the center.
He decided to use these stones to mark chambers and passages.
A stone can be placed to the left or to the right of one of the passages.
When Indiana Jones enters the chamber all that he can observe is the location of the stone in the chamber.
He can move the stone to the desired location and take any passage leading out of the chamber.

Your task is to help Indiana Jones to visit every passage in the Uniform Cave and find the treasure.

Interaction Protocol

First, the testing system writes the integer m — the number of passages in each chamber (2 ≤ m ≤ 20).

Dr. Jones enters the chamber and sees, in the next line, where the stone is placed:
either in the “center” of the chamber or to the “left”, or to the “right” of some passage.
On the first visit to the chamber, the stone is in the center.

Your solution shall output his actions:
the number and the side of the passage to place the stone to,
and the number of the passage to take.
Both numbers are relative to the passage marked by the stone, counting clockwise from 0 to m−1.
If the stone is in the center of the chamber, the origin is random.

For example,
3 left 1
tells that Dr. Jones moves the stone three passages clockwise and places it to the left of the passage,
then he takes the passage to the right of the initial stone position.

After each move, the testing system tells either the location of the stone in the next chamber
or “treasure”, if Indiana Jones had found it.
The testing system writes “treasure” when all the passages are visited.

If Dr. Jones does not find the treasure room after 50 000 passages are taken, he starves to death,
and your solution receives the “Wrong Answer” outcome.
You also receive this outcome if your solution terminates before all passages are taken. Let q be the number of passages you have taken, your score will be (50000 - q) / 50000.

The total number of chambers in the cave is unknown,
but you may assume that it does not exceed 20,
and that each chamber is reachable from every other chamber.

Example

Standard Input
2
center
left
center
left
right
treasure

Standart Output
0 left 0
1 left 1
1 right 0
0 left 0
1 right 0

Dr. Jones enters the example cave and sees that the stone in the first chamber is in the center.
He marks the chamber by placing the stone to the left of some passage and takes it.
He sees the chamber where the stone is to the left of the passage, so he is in the first chamber again.
He moves the stone clockwise and takes the passage marked by it.
This passage leads to the second chamber.
He marks it by placing the stone to the right of some passage and takes another one.
He is in the first chamber again, so he returns to the second chamber and takes the remaining passage.
This passage leads to the treasure.

# 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: 512m

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


Time Limit: 2 s
Memory Limit: 1024 MB
This is an interactive problem.
Bitaro found out that a string S of length N was written on the stone slate. Each character of the string is either ‘0’ or ‘1’. However, he does not yet know each character of the string S.
Bibako found out how to use the machine. To use it, we put the stone slate on the machine, input an integer m and two sequences of integers a, b, and make a query. Here the integer m and the sequences of integers a, b should satisfy:
- 1 <= m <= 1002
- Both of the lengths of the sequences a, b are equal to m.
- Every element of the sequences a, b is an integer between 0 and m - 1, inclusive.
If we put the stone slate on the machine, input an integer m and two sequences of integers a, b, and make a query, the machine will operate as follows and will show an integer.
 1. The machine sets 0 in the memory area of the machine.
 2. The machine performs the following N operations. The (i + 1)-th (0 <= i <= N - 1) operation proceeds as follows.
Let x be the current integer set in the memory area of the machine. The machine reads the character S_i (0<=i<N).
 - If S_i is ‘0’, the machine sets a_x in the memory area of the machine. Here, a_x is the x-th element of the sequence a, if we count the elements of the sequence a so that the first element is the 0-th element.
 - If S_i is ‘1’, the machine sets b_x in the memory area of the machine. Here, b_x is the x-th element of the sequence b, if we count the elements of the sequence b so that the first element is the 0-th element.
 3. The machine shows the integer which is finally set in the memory area.
Bitaro wants to specify the string written on the stone slate. However, the number of queries cannot exceed 1000. Moreover, the maximum of the integer m input to the machine for a query should be as small as possible.
Write a program which, using the machine, specifies the string written on the stone slate.

Implementation Details
First output one line. '1' indecate a query, '0' indecate a guess.
To ask a query, first an integer m, then print two sequences separated by a space, represent sequence a and sequence b.
After flushing your output, your program should read an integer x, indicating the finally set in the memory area. You can use fflush(stdout) (if you use printf) or cout.flush() (if you use cout).
If you want to guess, output the string s. Your code should exit immediately after guessing.
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.

Input
An integer N (N = 1000), represent the length of string S.

Grading
If your program is judged as correct for all the test cases, set M as the maximum of the parameter m of the function Query for all the test cases. However, if your program is judged as correct without calling the function Query, your score is calculated by M = 0.
 - If 103 <= M <= 1002,your score is 10 + ⌊(1002 - M)^2 / 9000⌋ points.
 - If 0 <= M <= 102, your score is 100 points.

Sample Communication
Assume s = "110". If we put the stone slate on the machine, input (m, a, b) = (4, [3, 3, 2, 2], [2, 2, 1, 0]),and make a query, the machine will operate as follows.
 1. The machine sets 0 in the memory area of the machine.
 2. For the first operation, since S_0 is ‘1’, the machine sets b_0, i.e. 2, in the memory area of the machine.
 3. For the second operation, since S_1 is ‘1’, the machine sets b_2, i.e. 1, in the memory area of the machine.
 4. For the third operation, since S_2 is ‘0’, the machine sets a_1, i.e. 3, in the memory area of the machine.
 5. Since the integer which is finally set in the memory area is 3, the machine shows 3.

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


Problem
Joe chose a hidden permutation p of length n consisting of all integers from 0 to n−1 (each used exactly once).
Your goal is to recover the entire permutation.

Interactive Protocol
• You may query two distinct indices i and j (1 ≤ i, j ≤ n, i ≠ j).
• To ask a question, print:    ? i j
• The interactor replies with a single integer: (p_i | p_j), where | is the bitwise OR.
• You can make at most 4269 queries(however the less queries you use, the better, as explained in the scoring section). The permutation is fixed in advance (it does not change based on your queries).

Input (Interactive Version)
• The judge first provides one line containing the integer n (3 ≤ n ≤ 2048).
• Then you interact by printing queries as described and reading the corresponding replies.
• If the interactor responds with −1 at any time, you either exceeded the query limit or issued an invalid query.
  You must terminate immediately after reading −1.

Output (Interactive Version)
• Once you have determined the permutation, print exactly one line:
  ! p1 p2 … pn
• Printing the final answer does NOT count toward the 4269 query limit.

I/O & Flushing Requirements
• After every query and after printing the final answer, print a newline and flush stdout.
  (e.g., fflush(stdout) / cout.flush() in C++; System.out.flush() in Java; stdout.flush() in Python.)

Example (Interactive Transcript)
Input
3
1
3
2

Output
? 1 2
? 1 3
? 2 3
! 1 0 2

Explanation of the Example
• The hidden permutation is [1, 0, 2].
• Queries and replies:
  – ? 1 2  → reply 1  (p1 | p2 = 1)
  – ? 1 3  → reply 3  (p1 | p3 = 3)
  – ? 2 3  → reply 2  (p2 | p3 = 2)
• From these, you can deduce p = [1, 0, 2], then print the final answer.

Notes & Constraints
• n ranges from 3 to 2048.
• The permutation p is over {0, 1, …, n−1}.
• Query limit: 4269.
• If you receive −1 at any time, terminate to avoid a wrong-answer due to reading from a closed stream.

Scoring:
• Your score for this problem is (4269-queries)/10
• Note that printing out the final answer is not counted as a query.

# 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


# Function

## Problem Description

Construct a **completely multiplicative function** \( f \) (that is, \( f(xy) = f(x)f(y) \)) such that \(|f(i)| = 1\) for all \(i\), and **minimize**

\[
\max_{1 \le k \le n} \left| \sum_{i=1}^k f(i) \right|.
\]

## Input

A single integer \( n \).

## Output

Output \( n \) integers on one line, representing \( f(1), f(2), \ldots, f(n) \).

## Constraints

There is only **one test case**, with \( n = 10^6 \).

## Scoring

Let your output be `out`, and the standard answer be `ans`.
Your score is computed based on the difference between `out` and `ans` (exact formula not specified in the statement).

type: default

time: 3s
memory: 1024m

checker: check.cpp
cheker_type: testlib
subtasks:
  - score: 100
    n_cases: 1


Maze
Time limit: 2s
Memory limit: 512MB

3.1 Background
The subject of this work is SCP-167. It is recommended to review information about SCP-167 before proceeding with the work.

3.2 Description
SCP-167 can be roughly described as a point connected to an infinitely deep binary tree, as shown in the figure below.

Level 0 o
|
Level 1 o
/
Level 2 o ...
/
Level 3 o ...
o
o
o

We define the point at Level 0 as the exit of SCP-167. To prevent researchers from getting lost inside SCP-167, you need to write a pathfinding system to help SCP-167 researchers find the exit.
For a researcher lost in SCP-167, because the three edges connected to their current node are highly similar, they cannot tell which edge leads towards the exit.
In SCP-167, one becomes lost as soon as they cannot determine the absolute position of their current node. At this point, all you know is the relative path between points.
To easily describe relative paths, we can assume each edge is one of three colors: red, yellow, or blue, and the three edges connected to any single node are all different colors.
Thus, each move can be represented by a color, indicating the edge of that color.
Simultaneously, you have a ranging device that can measure the distance between your current node and the exit.

Assume you are lost in SCP-167. You only know the initial distance initialDeep between your current node and the exit, but not the absolute position of this node. Please write a pathfinding system to locate the exit.

3.3 Task Description
To simulate being lost, we have prepared an interaction library. You will read initialDeep from the standard input, which represents the distance between your initial position and the exit. Here, initialDeep ≤ 10^4. You can perform the following two operations by outputing to the interactor by standard output. After each operation, you need to flush the output and read the returned value of the interactor from the standard input.

"move c"

where c is an integer 0, 1, or 2, which represent red, yellow and blue respectively. You can perform such operation for at most
10^5
  times. Once you have reached the exit, you must not move again. The interactor will return 1 if you reach the exit after the move. Otherwise, it will return 0.

"query"

The interactor will return the distance between your current node and the exit. The number of times you make a query will determine your score. Details are shown below.

3.6 Grading Method

The the number of queries exceed 10^5, you will get a score of zero. Otherwise, the less queries, the higher score you will get.

The time and memory limits given in the problem statement are the total resources available for your code and the interaction library combined.
We guarantee that for any legal data and calls within the limits, any version of the interaction library (including those distributed to contestants and those used for final evaluation) will not use more than 0.1 seconds of CPU time or more than 10MB of memory. This means contestants have at least 1.9 seconds of CPU time and at least 502MB of memory available for their code.

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


Hidden Tree

This is an interactive problem.

There is a hidden tree with n nodes. The nodes are numbered from 1 to n. Your task is to discover the structure of this tree by asking queries.

Each query consists of three distinct node numbers. The interactor will return the node that minimizes the sum of distances to these three nodes.

Your goal is to determine the structure of the tree. You are allowed to make at most 20,000 queries.

This problem is graded based on the number of queries you use. In order to receive any points, you must use no more than 20,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 (3 ≤ n ≤ 1000) indicating the number of nodes in the hidden tree.

Interaction

To ask a query, output one line. First output 0 followed by a space, then print three distinct integers from 1 to n separated by spaces. After flushing your output, your program should read a single integer representing the node that minimizes the sum of distances to the three queried nodes.

When you have determined the tree structure, output one line. First output 1 followed by a space, then print n-1 pairs of integers representing the edges. The format should be: u1 v1 u2 v2 ... u(n-1) v(n-1), where each pair (ui, vi) represents an edge in the tree. All values should be separated by spaces. After flushing your output, your program should exit immediately.

Note that the tree structure for each test case is pre-determined. That is, the interactor is not adaptive.

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:
3

2

Output:

0 1 2 3

1 1 2 2 3

Time Limit: 2 seconds
Memory Limit: 512 MB

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


Graph Coloring

You are given an undirected graph G with n nodes. Each node is colored either black (0) or white (1). You are given the initial coloring state and the target coloring state. Your task is to transform the graph from the initial state to the final state using a sequence of valid transformations.

In one transformation, each node simultaneously changes its color to either:
- Its current color (stays the same), or
- The color of one of its neighbors

Your goal is to minimize the number of transformations needed. You can use at most 20,000 transformations.

Input
The first line contains two integers n (1 ≤ n ≤ 100) and m — the number of nodes and edges in the graph.
The second line contains n integers representing the initial state.
The third line contains n integers representing the target state.
The next m lines each contain two integers u and v, indicating an undirected edge between nodes u and v. The graph has no self-loops or multiple edges.
It is guaranteed that a solution exists

Output
On the first line, print a single integer k — the number of transformation steps in your solution.
The next k+1 lines should each contain n integers representing the coloring state at each step.

Scoring
You will be graded based on the number of transformations you use.
Your answer will be compared to a reference solution ref_steps. Your final score will be calculated as the average of 100 * min((ref_steps + 1) / (your_steps + 1), 1) across all test cases.

Time limit: 2 seconds
Memory limit: 512 MB

Sample Input:
6 6
1 1 0 1 0 1
1 0 0 0 1 0
1 2
2 3
3 5
5 4
4 6
6 5

Sample Output:
2
1 1 0 1 0 1
1 1 0 0 1 0
1 0 0 0 1 0

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


Problem: Tree Reconstruction via Steiner-Membership Queries

Time limit: 3 seconds
Memory limit: 512 MB

This is an interactive problem.

You are given an unknown unweighted tree T with n labeled vertices V = {1, 2, ..., n}. Your task is to determine all edges of T by interacting with a judge.

Definition
For any subset S ⊆ V, define Steiner(S) as the smallest connected subgraph of T that contains all vertices in S. Equivalently, Steiner(S) is the union of all simple paths between all pairs of vertices in S. For a vertex v ∈ V, we say “v is on Steiner(S)” if v belongs to this subgraph.

Interaction
- At the start, read a single integer n (n <= 1000 in all official tests).
- You may then issue queries of the following form to the judge:

  Print a line:
  ? k v s1 s2 ... sk

  where:
  - k is an integer with 1 ≤ k ≤ n,
  - v is a vertex label with 1 ≤ v ≤ n,
  - s1, s2, ..., sk are k distinct integers in [1, n] forming the set S,
  - v may or may not belong to S; both are allowed.

  After each query, read a single integer from standard input:
  - 1 if v ∈ Steiner(S),
  - 0 otherwise.

- When you have determined the entire tree, output your answer:

  First print a line containing just:
  !

  Then print exactly n − 1 lines, each containing two integers u v (1 ≤ u, v ≤ n), describing the edges of the tree. You may output the edges in any order. After printing all edges, flush and terminate your program.

Important notes
- Flushing: After every query and after the final answer, flush your output. For example:
  - C++: fflush(stdout) or cout << endl << flush;
- Validity: If you print an invalid query (wrong format, out-of-range labels, duplicate elements in S, k = 0, etc.), the judge may terminate your program with a Wrong Answer verdict.
- Non-adaptiveness: The hidden tree is fixed before interaction begins and does not depend on your queries.

Global limit on total set sizes
To ensure the judge runs efficiently, the total size of all sets you submit across all queries must not exceed 3,000,000. Formally, if your queries are (k1, ...), (k2, ...), ..., then sum(ki) over all queries must be ≤ 3,000,000. If you exceed this limit, the judge may terminate the interaction immediately (e.g., by returning -1 or by issuing Wrong Answer). If you ever read -1, you must exit immediately.

Input/Output summary
- Read:
  - n (once at the beginning)
  - After each query: one integer (0/1), or possibly -1 if you violated the protocol (exit immediately if so)
- Write:
  - Queries: ? k v s1 s2 ... sk
  - Final answer:
    !
    u1 v1
    u2 v2
    ...
    u_{n−1} v_{n−1}

Scoring
Your solution is judged by both correctness and the number of queries.

- Let Q be the total number of queries you make.
- Full score (100 points) if Q ≤ 3,000.
- Zero score if Q > 1,200,000.
- Otherwise, your score is interpolated linearly:
  score = 100 × (1,200,000 − Q) / (1,200,000 − 3,000), rounded to the nearest integer.

Only solutions that correctly reconstruct the tree are scored. Violations of the interaction protocol, printing an invalid final tree, or exceeding the total-set-size limit result in 0 points for that test.

Example interaction
This example is illustrative only. The actual judge will use a hidden tree with n = 1000.

Judge: 5
You: ? 2 2 1 3
Judge: 1
You: ? 2 5 1 3
Judge: 0
You: ? 3 4 1 3 5
Judge: 1
You: !
You: 1 2
You: 2 3
You: 2 4
You: 4 5

Additional clarifications
- S must be non-empty (k ≥ 1).
- If |S| = 1 with S = {x}, then Steiner(S) is the single vertex x. A query “? 1 v x” returns 1 if and only if v = x.
- The final answer must describe a simple tree on vertices {1, 2, ..., n}. Edges can be in any order, but duplicates and self-loops are not allowed.

# 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: 3s
memory: 512m

# 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:1024 megabytes

Bobo is given a tree T = (V, E) of n vertices, where there is a number pi on vertex i initially, and p1, p2,..., pn is a permutation of 1 to n, meaning that all integers from 1 to n appear exactly once in p1, p2, ..., pn.
In each operation, Bobo can select a matching M (M belongs to E) (M is a matching means that no two edges in M share a common vertex), and for each (u,v) belongs to M, swap the number on vertex u and vertex v (i.e. swap pu and pv).
Bobo wants to make pi = i for each 1<=i<=n with as few operations as possible, can you please help him?

Input
There are multiple test cases. The first line of the input contains an integer T (T>=1), indicating the number of test cases. For each test case:
- The first line contains a single integer n (10<n<=1000) the number of vertices of the tree.
- The second line contains n integers p1, p2, ..., pn (1<=pi<=n, and p is a permutation of 1 to n), meaning the initial number on vertex i is pi.
Then follow n-1 lines, each with integers u, v (1<= u,v <=n, and u not equals to v) meaning that there is an edge between u and v.
It is guaranteed that the sum of n^2 of all test cases will not exceed 10^6.

Output
For each test case: The first line contains a single integer m (m>=0) meaning the number of operations you used.
Then m lines follow, where each line starts with an integer 0<=ki<n, denoting the number of edges in the matching you select in the i-th operation. Then ki integers t_{i,1}, t_{i,2}, ..., t_{i,ki} follow, denoting the indexes of edges you select.

Scoring
For each test case i (1<=i<=T), your score s_i = max(0, (base_value-m)/(base_value-best_value))
your score on each subtask is 0 if any subtask failed to get the correct result, or the average of all s_i

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

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


Greedy

Time limit: 7 seconds
Memory limit: 512 MB
This is an interactive problem. All communication is via standard input/output (no input/output files).

Story
Little U tackles an optimization on trees but only has a greedy “black box.” You must reconstruct the hidden tree using queries to this black box.

Core Problem
You are given a hidden rooted tree with n nodes labeled 1..n. Every node has either 0 children or at least 2 children.
Let A be any set of nodes with no ancestor–descendant pairs (an antichain). The size of the maximum such set depends on the tree.

Greedy Black Box (what your queries measure)
For any sequence (order) of distinct node labels vec (length sz ≥ 1):
• Start with an empty chosen set S.
• Scan vec from left to right. For the current node x:
  – If x is neither an ancestor nor a descendant of any node already in S, insert x into S.
  – Otherwise skip x.
• The black box outputs |S|, the number of chosen nodes.

Your Task
Reconstruct the entire parent array par[1..n] of the tree (par[root] = 0) by interactively querying the black box.

Standard I/O Protocol

Initial input (from the judge)
The first line contains two integers:
  n ty
where:
• n — number of nodes (1 ≤ n ≤ 3000)
• ty — a test identifier chosen by the judge (for your program, it has no algorithmic effect and can be ignored)

Making a query
To ask the black box for the greedy result on a sequence vec of length sz:
  1) Print a line in the following format exactly:
       ? sz v1 v2 ... vsz
     where each vi is a distinct integer in [1, n] and all vi are pairwise distinct.
  2) Immediately flush stdout after printing the line.
  3) Read a single integer R from stdin — this is the black box answer |S| for your sequence.

Submitting the final answer
When you have reconstructed the tree, print a single line:
  ! p1 p2 ... pn
with:
• pi = parent of node i (for all i = 1..n)
• The root’s parent must be 0 (i.e., p_root = 0).
After printing the answer, flush stdout and terminate without issuing further queries.

Protocol Requirements (binding)
• You must flush stdout after every output line you produce (both “?” and “!” lines).
• You must not output any extra text beyond the specified formats; no prompts, logging, or debug prints.
• For each query, you must print exactly one “?” line, flush, then read exactly one integer reply.
• After the “!” line is printed and flushed, your program must exit immediately.
• The judge evaluates only the first “!” line. Any subsequent output will be ignored and may cause a Wrong Answer verdict.
• Each query (“?” line) will be processed in O(n) time on the judge side.
• The sequence in a “?” query can be any subset order (no duplicates required to cover all nodes).

Scoring (0–100 scale based on number of queries)
Let T be the number of queries you print (the number of lines beginning with “?”).
• If T ≤ 45,000 → score = 100
• If T > 200,000 → score = 0
• Otherwise (45,000 < T ≤ 200,000) → use a smooth linear scale strictly inside (0, 100):
    score = clamp(0.01, 99.99, 100 * (200000 - T) / 155000)
  where clamp(a, b, x) = min(b, max(a, x)).
  (This yields 99.99 when T is just above 45,000, and 0.01 when T is 200,000.)

Constraints (single overall setting; no subtasks beyond the original hardest setting)
• n ≤ 3000
• Node labels are 1..n
• Each node has either 0 children or at least 2 children

Sample interaction (illustrative)
Judge → Program:
  3 0
Program → Judge:
  ? 2 2 3
(Program flushes)
Judge → Program:
  2
Program → Judge:
  ! 0 1 1
(Program flushes and exits)

Explanation of the sample
The query “? 2 2 3” returns 2, implying that nodes 2 and 3 can both be taken simultaneously by the greedy, so neither is an ancestor of the other; since every non-leaf has ≥ 2 children and n = 3, this suggests both 2 and 3 are children of 1. The final answer line “! 0 1 1” declares 1 as root (parent 0) and parents of 2 and 3 as 1, which the judge accepts.

# 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: 7s
memory: 512m

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


Cant-Be-Late Scheduling Problem
================================

Problem Setting
--------

You are given a long-running compute job that must complete before a fixed **hard deadline**.
At each time step, you must choose which type of cloud compute resource to use:

- **Spot instances**
  - Very cheap
  - May become unavailable at certain timesteps
  - Can be preempted at any time, the job will incur a **restart overhead**

- **On-demand instances**
  - Guaranteed available
  - Expensive
  - Never interrupted

Your strategy must decide at every timestep whether to use Spot, use On-Demand, or pause (NONE).

Restart overheads do not stack: launching a new instance while an old overhead is still pending will replace the previous remaining restart overhead with the new one.

Your goal is to **finish before the deadline** while **minimizing cost**.

The evaluation uses many real spot-availability traces.

---

API Specification
-----------------

Implement a `Solution` class that inherits from `Strategy`:

```python
from sky_spot.strategies.strategy import Strategy
from sky_spot.utils import ClusterType

class Solution(Strategy):
    NAME = "my_solution"  # REQUIRED: unique identifier

    def solve(self, spec_path: str) -> "Solution":
        """
        Optional initialization. Called once before evaluation.
        Read spec_path for configuration if needed.
        Must return self.
        """
        return self

    def _step(self, last_cluster_type: ClusterType, has_spot: bool) -> ClusterType:
        """
        Called at each time step. Return which cluster type to use next.

        Args:
            last_cluster_type: The cluster type used in the previous step
            has_spot: Whether spot instances are available this step

        Returns:
            ClusterType.SPOT, ClusterType.ON_DEMAND, or ClusterType.NONE
        """
        # Your decision logic here
        if has_spot:
            return ClusterType.SPOT
        return ClusterType.ON_DEMAND

    @classmethod
    def _from_args(cls, parser):  # REQUIRED: For evaluator instantiation
        args, _ = parser.parse_known_args()
        return cls(args)
```

Available Attributes in `_step`:
- `self.env.elapsed_seconds`: Current time elapsed (seconds)
- `self.env.gap_seconds`: Time step size (seconds)
- `self.env.cluster_type`: Current cluster type
- `self.task_duration`: Total task duration needed (seconds)
- `self.task_done_time`: List of completed work segments
- `self.deadline`: Deadline time (seconds)
- `self.restart_overhead`: Time overhead when restarting (seconds)

ClusterType Values:
- `ClusterType.SPOT`: Use spot instance
- `ClusterType.ON_DEMAND`: Use on-demand instance
- `ClusterType.NONE`: Do nothing this step (no cost)

Scoring (0-100)
---------------
```
OD_anchor = Cost of running fully on-demand (baseline upper bound)
SPOT_anchor = Cost of running fully on spot (baseline lower bound)
AvgCost = Your strategy's average cost

normalized_score = (OD_anchor - AvgCost) / (OD_anchor - SPOT_anchor)
score = clip(normalized_score, 0, 1) × 100
```

If you fail to finish before the deadline, you receive a penalty score of -100000.

Evaluation Details
------------------
- Tested on real Spot instance traces
- Task duration: 48 hours
- Deadline: 70 hours (22-hour slack)
- Restart overhead: 0.20 hours (12 minutes)
- Price of on-demand: ~3.06$/hr
- Price of Spot: ~0.97$/hr
- Regions: High availability (43-78%)

Your program has a total time limit of 300 seconds.

Implementation Notes
---------------------
**Required Elements:**
- `NAME` attribute must be defined on your Solution class
- `_from_args` classmethod must be implemented
- `solve()` must return `self`
- `_step()` must not return `ClusterType.SPOT` when `has_spot=False`

dependencies:
  uv_project: ../common/cant-be-late-simulator
datasets:
  - type: local_tar
    path: ../common/real_traces.tar.gz
    target: ../common/cant-be-late-simulator/data
    expected_glob: "real/ddl=search+task=48+overhead=*/real/*/traces/random_start/*.json"
tag: os