A. Artistic Choice
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It's year $$$5202$$$ and the world famous artist Nonnel is going through her technostrawberry phase. Her canvas is a gigantic white field and her brush is a robotic arm. Nonnel spent a long time crafting it and perfecting the design. She recrafted, tested, recrafted again and after much recrafting the design is complete.

This arm consists of $$$k$$$ ($$$k \in \{2, 3\}$$$) sections, each with specified lengths $$$l_i$$$. The first section is anchored at the origin of the plane, which is the point $$$(0, 0)$$$, and it can rotate around this point. Its angle of position is defined relative to the positive $$$OX$$$-axis. Each subsequent section begins at the end of the previous section and can rotate around that joint. The angle of position for each following section is defined relative to the direction of the preceding section. Sections can coincide or pass through each other.

The position angles of the arm's sections determine its configuration. A position angle is defined as a real number within the range $$$[0, 2\pi)$$$. When the arm is deployed on a field, all initial position angles are set to zero, meaning that the joints are positioned at the coordinates $$$(0, 0)$$$, $$$(l_1, 0)$$$, $$$(l_1 + l_2, 0)$$$, and so forth. The end point of the final section is located at $$$(l_1+l_2+\dots+l_k, 0)$$$.

The arm can transition from one configuration to another. The cost of a transition is determined by the maximum difference between the current and next position angles across all segments. The difference between two angles $$$x$$$ and $$$y$$$ is defined as the minimum of the clockwise and counter-clockwise rotations: $$$\mathtt{dist}(x, y) = \min(|x - y|, 2\pi - |x - y|)$$$.

Consider an example. Suppose the arm has two segments, and their current position angles are $$$\frac{\pi}{3}$$$ and $$$\frac{\pi}{4}$$$, respectively. If the next position angles are $$$\frac{\pi}{4}$$$ and $$$2 \pi - \frac{\pi}{4}$$$, the total cost would be $$$\max(\frac{\pi}{12}, \frac{\pi}{2}) = \frac{\pi}{2}$$$.

The arm paints, and it only paints strawberries. It's an artistic choice, don't question it.

Nonnel wants to produce a series of gigantic strawberry fields. Each strawberry is identified by a pair of coordinates. Your task is to specify the order in which to paint the strawberries and to provide the corresponding arm configurations. The end of the arm's last segment should be almost aligned with the coordinates of the target strawberry: the absolute difference for each coordinate must not exceed $$$10^{-6}$$$. The arm will receive these configurations and will transition between them in the specified order, starting from the initial position.

In her work Nonnel wants to explore the concept of efficiency, so each field should be painted with minimal total transition cost.

Input

You are given a zip-archive "problem-a-inputs.zip" with $$$12$$$ tests: 01, 02, $$$\ldots$$$, 12.

The first line of each test contains the number of sections $$$k$$$ of the robotic arm ($$$k \in \{2, 3\}$$$). The second line contains $$$k$$$ real numbers $$$l_1, l_2, \ldots, l_k$$$ — the lengths of the sections. The third line contains $$$n$$$ — the number of strawberries to paint. Each of the next $$$n$$$ lines contain two real numbers — the coordinates of the strawberries.

It is guaranteed that for each strawberry there exists a configuration that paints it.

Here is a short description of tests' parameters:

Testkn
0128
022100
032100
04215
052100
062100
072100
0821000
093300
10316
113660
123150
Output

As an answer, you should submit a zip-archive with files 01.out, 02.out, $$$\ldots$$$, 12.out. Some of the files may be missing.

Each of these files should contain $$$n$$$ lines. Each line should have the label of the painted strawberry (they are labeled from $$$1$$$ to $$$n$$$ in the order of input) and the configuration represented with $$$k$$$ real numbers: the position angles of the arm sections in the respective order. The angles should be in the range $$$[0, 2\pi)$$$.

Scoring

Let the configuration $$$i$$$ in the output be represented as an array of angles $$$c_i[\cdot]$$$. And let the initial position be $$$c_0 = [0, \ldots, 0]$$$.

The checker iterates through the configurations one by one. Suppose the next configuration is $$$c_i$$$. At first, the checker verifies that the configuration indeed paints the strawberry in the target position. For that, it calculates the coordinates of joints one by one and compares the coordinates of the end of the last segment with the coordinates of the strawberry. Then, it calculates the cost of that move: $$$\max_{j = 1}^k \mathtt{dist}(c_i[j], c_{i - 1}[j])$$$. And adds it to the total number of points.

Your final score for the test is calculated as follows:

  • If the output score is not properly formatted or does not solve the problem correctly — your output gets $$$0$$$.
  • Otherwise, it will be the lowest amount of points among all participants for this test divided by the number of points for your output: $$$100 \cdot \frac{\mathtt{best\_points}}{\mathtt{your\_points}}$$$.

Note that the scoreboard will consider at the end your best score for each test among all your submissions.

Note

Below is a visualization of the first test file 01.

The initial position of the mechanical arm.Strawberry #3 is painted.
Problem by Recraft