Qualifying round of the IX regional Olympiad for the Governors Prize 2024, grades 9-10, Vologda region
A. Rectangle and Squares
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya cut out a rectangle of size $$$m \times n$$$ cells from paper. Petya, at each step, cuts out the largest possible square from the rectangle and keeps it. Write a program to determine how many squares will Petya eventually have?

Consider the example. Suppose the initial rectangle has a size of 3 x 5. In the first step, Petya will cut out a 3 x 3 square, leaving a rectangle of 3 x 2. In the second step, Petya will cut out a 2 x 2 square, leaving a rectangle of 1 x 2. In the third step, Petya will cut out a 1 x 1 square, and in the fourth step, he will take the remaining 1 x 1 square. In total, he will have 4 squares.

Input

Two integers $$$m$$$ and $$$n$$$ are given, each on a separate line ($$$1 \le m, n \le 2 \cdot 10^9$$$).

Output

Output a single integer — the number of squares.

Example
Input
3
5
Output
4
Note

Solutions that work correctly for $$$m, n \le 1000$$$ can earn 50 points.

B. Number of Words
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Write a program to find the number of N-letter «words» composed of the letters A, B, C (by «word» we mean any sequence of consecutive letters) such that there are no more than three letters B in them.

Input

The integer $$$N$$$ ($$$1 \le N \le 20$$$).

Output

Output a single integer — the number of «words» that satisfy the condition.

Example
Input
4
Output
80

C. Guess the Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A certain natural number is hidden. Three statements have been made about it:

  1. This number is greater than $$$A$$$ and less than $$$B$$$;
  2. This number is not greater than $$$C$$$ or not less than $$$D$$$;
  3. This is an even number, and it is greater than $$$E$$$.
All three statements are false.

You need to determine what is the smallest natural number that could have been hidden (or if such a number does not exist). You need to find the answer for several test cases.

Input

The first line of the input contains an integer $$$T$$$ — the number of test cases ($$$1 \le T \le 1000$$$).

In each of the following $$$T$$$ lines, five integers $$$A$$$, $$$B$$$, $$$C$$$, $$$D$$$, $$$E$$$ are given, separated by spaces ($$$0 \le A, B, C, D, E \le 10^9$$$).

Output

For each test case, output the smallest natural number that could have been hidden. If such numbers do not exist, output -1.

Scoring

Solutions that work for $$$T=1$$$ and $$$A, B, C, D, E \le 100$$$ will be scored 40 points.

Example
Input
2
5 8 4 10 3
7 8 7 3 9
Output
5
-1
Note

Note for participants writing in Python. You can read 5 numbers entered with spaces like this:

a, b, c, d, e = map(int, input().split())

D. Snake
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Andrey fills a table in a «snake» pattern: in the first row, he writes numbers in increasing order from left to right, starting with 1, then he continues in the second row from right to left, then in the third row — again from left to right, and so on. In this table, a 2 x 2 fragment was found with the numbers

a+1a
bb+1

Determine the maximum number of columns that could have been in Andrey's table.

Input

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

Output

Output a single integer — the answer. If there is no solution, output -1.

Scoring

Solutions that work correctly for $$$a, b \le 1000$$$ will score at least 30 points.

Solutions that work correctly for $$$a, b \le 10^6$$$ will score at least 60 points.

Example
Input
4
8
Output
3
Note

The table in the example looks like this:

123
654
789

E. Good Pairs
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

An unordered pair of natural numbers is called good if one of the numbers divides the other. Output $$$n$$$ such natural numbers not exceeding one million, such that there are exactly $$$k$$$ good pairs among them, or determine that this is impossible.

More formally: for the numbers output by your program $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$, there must be exactly $$$k$$$ pairs of indices $$$i$$$, $$$j$$$, where $$$i \lt j$$$, such that $$$a_i$$$ divides $$$a_j$$$ or $$$a_j$$$ divides $$$a_i$$$.

Input

Two integers $$$n$$$ and $$$k$$$ are given, each on a separate line ($$$1 \le n \le 10^5$$$, $$$0 \le k \le 10^5$$$).

Output

Output $$$n$$$ such natural numbers in the range from 1 to $$$10^{6}$$$, such that there are exactly $$$k$$$ good pairs among them. If there are multiple correct answers, output any. If there are no solutions, output -1.

Scoring

Subtask 1 (up to 30 points): $$$n \le 5$$$.

Subtask 2 (up to 30 points): $$$n \le 100$$$.

Subtask 3 (up to 40 points): no additional constraints.

Examples
Input
4
3
Output
2 2 4 7
Input
2
100
Output
-1