Final round of the 11th Regional Olympiad for the Governor’s Prize 2026, grades 9-10, Vologda Region
1. Forced Stop
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Train driver Ivan Ivanovich's locomotive broke down while the train was traveling along an inclined section of the track. As a result, the train came to a halt and is currently being held in place by its pneumatic brakes. However, air is gradually leaking from the braking system through the seals...

To prevent the train from rolling away, Ivan Ivanovich decides to place wheel chocks under the train cars. Using a specific formula (which accounts for the incline angle and the mass of the train) he calculates that he needs to place one chock under each car. There are $$$n$$$ cars in the train.

The wheel chocks are stored in the locomotive. Ivan Ivanovich can carry no more than two chocks at a time. Traveling from the locomotive to car $$$i$$$ (or vice versa) takes $$$t \cdot i$$$ seconds.

Determine the minimum amount of time required for him to place all the chocks and return to the locomotive.

For example, if $$$n=4$$$ and $$$t=10$$$, it will take him 120 seconds. One possible sequence of actions for Ivan Ivanovich is as follows: he takes two chocks, walks to the second car (placing one chock under the first car along the way), returns to the locomotive, picks up two more chocks, walks to the fourth car (placing one chock under the third car along the way), and then returns.

An alternative approach, which also results in a total time of 120 seconds, is to first walk to the fourth car (placing a chock under the third car along the way), return, then walk to the second car (placing a chock under the first car along the way), and return once more.

Input

Two integers, $$$n$$$ and $$$t$$$, are provided, each on a separate line ($$$1 \le n \le 10^9$$$, $$$1 \le t \le 10$$$).

Output

Output a single integer — the minimum number of seconds.

Scoring

Subtask 1 (up to 40 points): $$$n \le 1000$$$

Subtask 2 (up to 60 points): no additional constraints.

Example
Input
4
10
Output
120
Note

The answer for the second subtask may exceed the capacity of a 32-bit data type. It is recommended to use a 64-bit data type—for example, 'long long' in C++, 'int64' in Pascal, or 'long' in Java and C#. In Python, no additional steps are required.

2. Point on a Line
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Four points $$$A$$$, $$$B$$$, $$$C$$$ and $$$D$$$ are marked on a plane. No three of them lie on the same line.

A straight line is drawn through points $$$A$$$ and $$$B$$$. Find the coordinates of a point $$$M$$$ on this line such that the length of the polyline $$$CMD$$$ is minimized.

Input

Each of the four input lines contains a pair of integers $$$x_i$$$, $$$y_i$$$, representing the coordinates of points $$$A$$$, $$$B$$$, $$$C$$$, and $$$D$$$, respectively ($$$-1000 \le x_i, y_i \le 1000$$$).

Output

Output two real numbers $$$x_m$$$ and $$$y_m$$$ — the coordinates of point $$$M$$$. The relative or absolute error for each coordinate in your answer must not exceed $$$10^{-3}$$$.

Scoring

Each test case is worth an equal number of points. The maximum score for the problem is 100.

Example
Input
2 1
-3 -1
1 2
-3 3
Output
0.678160951 0.471264380
Note

In Python, you can read two space-separated integers as follows: x, y = map(int, input().split())

3. Gas Station
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A gas station has N fuel pumps, all of which are initially free.

Cars arrive at the gas station from time to time and join a single common queue. As soon as a pump becomes available, the first car in the queue moves to it to refuel. Refueling takes T seconds.

After refueling, the car moves aside to free up the pump, and the driver joins a queue for the checkout counter (since the online payment system is down again). There is only one checkout counter. Processing a payment at the counter takes V seconds.

For each car, determine the time at which it leaves the gas station. You may assume that all movements of cars and drivers occur instantaneously.

Input

The first line contains four space-separated integers:

  • F (1 ≤ F ≤ 105) — the number of cars.
  • N (1 ≤ N ≤ 10) — the number of fuel pumps.
  • T (1 ≤ T ≤ 100) — the time required to refuel one car.
  • V (1 ≤ V ≤ 100) — the time required to process a payment at the checkout counter.

Each of the following F lines contains a single integer X (1 ≤ X ≤ 109) — the arrival time of a car. All arrival times are distinct and are given in ascending order.

Output

For each car, output the time at which it leaves the gas station.

Scoring

Subtask 1 (up to 25 points): F ≤ 100, X ≤ 105

Subtask 2 (up to 36 points): F ≤ 1000, X ≤ 109

Subtask 3 (up to 39 points): F ≤ 105, X ≤ 109

The number of points for a single test may vary between subtasks.

Examples
Input
4 2 10 100
1
2
500
510
Output
111
211
610
710
Input
7 2 5 1
1
2
3
4
500
510
520
Output
7
8
12
13
506
516
526
Note

In Python, you can read 4 integers separated by spaces as follows: f, n, t, v = map(int, input().split())

4. Triangle Spiral
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are two points on the plane: $$$A$$$ and $$$B_0$$$. The length of segment $$$AB_0$$$ is 1.

From point $$$B_0$$$, a segment $$$B_0B_1$$$ of length $$$c_1$$$ is drawn perpendicular to segment $$$AB_0$$$ counter-clockwise. Similarly, from each point $$$B_i$$$, a segment $$$B_{i-1}B_i$$$ of length $$$c_i$$$ is drawn perpendicular to segment $$$AB_{i-1}$$$ counter-clockwise, $$$i = 1..N$$$. There are $$$N$$$ segments in total.

It is required to find at what distance $$$X$$$ from point $$$A$$$ the last point $$$B_N$$$ is located, that is, the length of segment $$$AB_N$$$. It is guaranteed that $$$X$$$ is an integer.

Input

The first line contains one integer $$$N$$$. The second line contains $$$N$$$ integers separated by spaces — the lengths of the segments $$$c_i$$$.

Output

Print one number $$$X$$$ — the length of segment $$$AB_N$$$.

Scoring

Subtask 1 (up to 20 points): $$$1 \leq N \leq 10, 1 \leq c_i \leq 100$$$

Subtask 2 (up to 20 points): $$$1 \leq N \leq 10, 1 \leq c_i \leq 10^8$$$

Subtask 3 (up to 20 points): $$$1 \leq N \leq 10^4, 1 \leq c_i \leq 10^8$$$

Subtask 4 (up to 20 points): $$$1 \leq N \leq 10, 1 \leq c_i \leq 10^{15}$$$

Subtask 5 (up to 20 points): $$$1 \leq N \leq 10^4, 1 \leq c_i \leq 10^{15}$$$

Examples
Input
2
2 2
Output
3
Input
3
1 1 1
Output
2
Note

An example of a spiral with 2 segments ($$$N = 2$$$) is shown below.

A reminder for Python programmers: you can input a set of space-separated integers like this:

c = [int(x) for x in input().split()]

5. Colored Balls 2D
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an $$$n \times m$$$ rectangular grid of colored balls, where each ball can be one of three colors. In a single step, you may swap any two balls. Determine the minimum number of steps required to arrange the balls such that the grid is partitioned into single-colored rectangles — one rectangle for each color present.

Input

The first line of the input contains two integers $$$n$$$ and $$$m$$$. The following $$$n$$$ lines each contain $$$m$$$ integers (1, 2, or 3), representing the colors of the balls.

Output

Output a single integer: the minimum number of steps required. If no solution exists, output -1.

Scoring

Subtask 1 (up to 20 points): $$$1 \le n, m \le 10$$$; the balls can only be of color 1 or 2.

Subtask 2 (up to 20 points): $$$1 \le n, m \le 1000$$$; the balls can only be of color 1 or 2.

Subtask 3 (up to 24 points): $$$1 \le n, m \le 10$$$; the balls can be of color 1, 2, or 3.

Subtask 4 (up to 36 points): $$$1 \le n, m \le 1000$$$; the balls can be of color 1, 2, or 3.

Examples
Input
3 4
1 2 1 1
2 1 1 3
3 3 3 1
Output
2
Input
2 2
1 1
1 1
Output
0
Input
2 3
1 1 1
1 1 2
Output
-1
Note

In the first example, it is sufficient to swap the first two balls in the first row and the last two balls in the last column.

A note for those using Python: You can read a sequence of space-separated integers as follows:

c = [int(x) for x in input().split()]