Voronezh State University - Sitronics contest II
A. A+B?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Once, Maxim bet that he could come up with a problem with the shortest statement that could touch anyone's heart. He won the bet:

"For given numbers $$$n$$$ and $$$p$$$, calculate the number of possible pairs ($$$a, b$$$) such that $$$a + b = n$$$ and $$$-10^{p} \le a, b \le 10^{p}$$$."

Input

A single line contains two integers $$$n$$$ ($$$-2 \cdot 10^{9} \le n \le 2 \cdot 10^{9}$$$) and $$$p$$$ ($$$1 \le p \le 9$$$).

Output

Print a single integer – the answer to the problem.

Examples
Input
7 1
Output
14
Input
-4 1
Output
17
Input
25 1
Output
0

B. Before contest
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Nikita and Maxim are evaluating the complexity of problems. Each problem is characterized by the length of the statement $$$x$$$ and the length of the solution code $$$y$$$. Nikita assumes that the complexity of a problem is determined as $$$x^{y}$$$, while Maxim believes that the complexity of a problem is $$$y^{x}$$$.

Help the boys understand the relationship between the complexity estimates $$$x^{y}$$$ and $$$y^{x}$$$.

Input

The only line contains two positive integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^{9}$$$).

Output

Output one of the following:

  • '<', if $$$x^{y} \lt y^{x}$$$
  • '=', if $$$x^{y} = y^{x}$$$
  • '>', if $$$x^{y} \gt y^{x}$$$
Examples
Input
3 5
Output
>
Input
7 7
Output
=

C. Creative archery
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Maxim is a big fan of all kinds of games. This time he is playing a game called "Minecraft".

This time he came up with a great idea to build a huge target and practice archery. According to Maxim's plan, the target will look like a square with an even side length $$$x$$$, and each inner layer is painted either white or red, with the colors alternating (for better understanding, see the picture):

Example of an $$$8 \times 8$$$ target.
Example of a $$$4 \times 4$$$ target.

Maxim also wants to make this target out of wool, but he doesn't have a lot of red wool, specifically $$$n$$$ blocks. Help Maxim figure out the maximum side length $$$x$$$ his target can have!

Input

The only line contains a single integer $$$n$$$ ($$$4 \le n \le 1000$$$).

Output

Output a single integer $$$x$$$ - the answer to the problem.

Examples
Input
5
Output
4
Input
12
Output
6

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

Masha and Petya love eating pies. Their grandmother decided to delight them today by baking $$$n$$$ pies with cabbage and mushrooms. She prepared the dough, put the pies in the oven, and went to sleep. However, when it started smelling delicious, the grandchildren couldn't resist and decided to eat some of the pies. The pies are laid out in the oven in a single row from left to right. Masha wants to take every third pie, and Petya every seventh.

For example, Masha wants to take pies $$$3, 6, 9, 12, 15, 18, 21, 24$$$ and so on, while Petya wants $$$7, 14, 21, 28...$$$ The grandchildren take the pies in turns, starting from the left side of the oven. Masha starts first. If one of the grandchildren has already taken a pie with number $$$x$$$, then the other takes the next one. For instance, Petya will take the third pie with number $$$21$$$. Consequently, when Masha takes her seventh pie, she will take the pie with number $$$24$$$.

Since mushroom pies are tastier than cabbage pies, tell us how many mushroom pies each of the grandchildren will eat.

Input

The first line contains the number of pies $$$n$$$ ($$$1 \le n \le 10^{5}$$$).

The next line specifies $$$n$$$ values $$$a_{i}$$$ ($$$0 \le a_{i} \le 1$$$) – if $$$0$$$, then the pie is with cabbage, otherwise with mushrooms.

Output

Print two numbers separated by a space - the number of mushroom pies that Masha will eat, and then Petya.

Examples
Input
7
1 1 0 1 0 1 1
Output
1 1
Input
24
1 0 1 1 1 0 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 1
Output
5 2
Input
1
1
Output
0 0

E. Efficient synchronization
time limit per test
10 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have at your disposal $$$k$$$ servers, which store information that can be represented as an array of $$$n$$$ elements. At the initial moment in time, all the information on all $$$k$$$ servers is identical, and it will be given to you in the form of an array $$$a$$$. Also, at certain times, requests are sent to the servers, and there are two types of requests:

  • "Set sid pos val" – change the information on the sid-th server at position pos to the value val.
  • "Get sid pos" – get the value on the sid-th server at position pos.

You would like to create a system that will allow you to quickly process all these requests. But that's not all; you would also like to set up synchronization between all servers every $$$s$$$ seconds, meaning that every $$$s$$$ seconds, the servers exchange information and update so that there are no differences between the data of two different servers. Conflicts that arise during synchronization should be resolved automatically as follows: suppose there are different values at position $$$i$$$ on the servers, then during synchronization, the value that was updated later will be chosen for updating, i.e., if on server $$$x$$$ at position $$$i$$$ the value was changed at time $$$t_{1}$$$, and on server $$$y$$$ at position $$$i$$$ at time $$$t_{2}$$$, and $$$t_{1} \gt t_{2}$$$, then the value on server $$$x$$$ will be chosen.

Can you handle such a task?

Input

The first line contains three integers $$$k, n$$$ ($$$1 \le k, n \le 10^{5}$$$) and $$$s$$$ ($$$1 \le s \le 10^{9}$$$) – the number of servers, the size of the data array on each server, and the synchronization period, respectively.

The second line contains $$$n$$$ integers $$$a_{i}$$$ ($$$-10^{9} \le a_{i} \le 10^{9}$$$) – the information stored on each server at the initial moment in time.

The third line contains one integer $$$q$$$ ($$$1 \le q \le 10^{6}$$$) – the number of requests.

The following $$$q$$$ lines contain requests, one per line. The requests are given in the following format:

  • "time Set sid pos val"
  • "time Get sid pos"

For each request, in addition to the parameters described in the problem statement, the moment in time at which it arrives is also given. The parameters have restrictions ($$$1 \le time \le 10^{9}$$$), ($$$1 \le sid \le k$$$), ($$$1 \le pos \le n$$$), ($$$-10^{9} \le val \le 10^{9}$$$).

Note that if any request arrives at time $$$t$$$ and synchronization is supposed to occur at that moment ($$$t \bmod s = 0$$$), then synchronization of the servers occurs first, and only then is the request processed by the system.

Requests are given in increasing order of $$$time$$$.

Additional restriction: no two requests have the same $$$time$$$.

Output

For each "Get" request, output the response that your system will provide.

Examples
Input
2 5 10
3 2 2 4 4
5
4 Get 2 3
7 Set 2 3 1
8 Get 1 3
9 Get 2 3
100 Get 1 3
Output
2
2
1
1
Input
5 5 60
0 0 0 0 0
8
1 Get 1 5
2 Set 2 2 7
7 Set 5 2 1
59 Get 2 2
60 Get 2 2
61 Get 3 2
69 Set 4 1 9
120 Get 1 1
Output
0
7
1
1
9

F. Fine arts museum
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Students of Voronezh State University not only participate in various programming competitions. This time, in another city, Nikita suggested visiting the fine arts museum. Out of all the paintings, he was most impressed by the works of Ivan Shishkin. Inspired by the great Russian painter, Nikita decided to create his own masterpiece in the form of an ASCII drawing. For the ASCII drawing to be a masterpiece, it must have the following:

  1. The drawing is framed by a rectangular border, which consists of the characters '+' at the corners, '-' on the horizontal borders, and '|' on the vertical borders.
  2. The drawing depicts $$$n$$$ trees. Each tree consists of a trunk and a crown, which are defined by the parameters $$$s_{i}$$$ and $$$t_{i}$$$. The trunk of the tree is made up of $$$s_{i}$$$ characters '|', with the very bottom of the trunk necessarily drawn from the bottom border of the frame. Trees come in three types depending on the character that makes up the crown of the tree. The crown of the tree is an isosceles triangle with a height of $$$t_{i} + 1$$$ and a base of $$$2 \cdot t_{i} + 1$$$, which borders the top part of the trunk and consists of identical characters $$$c$$$. The trunk of the tree is exactly in the middle of the base of the crown's triangle. Depending on the type of tree, the character $$$c$$$ is equal to '*', '+' or '#'. For a better understanding of how a tree is drawn, please refer to the figure.
  3. Each tree fits completely within the drawing, meaning the drawings of the trees and the frame borders do not intersect but may touch.
  4. If any two trees touch with their crowns, they are of different types. Trees $$$x$$$ and $$$y$$$ touch with their crowns if there is a crown character belonging to tree $$$x$$$, which has an adjacent side character of the crown belonging to tree $$$y$$$.
  5. The rectangular frame of the drawing has the smallest possible perimeter.
  6. Characters inside the frame that do not belong to any of the trees are spaces (i.e., the character with ASCII code $$$32$$$).
Correct tree drawings.
Incorrect tree drawings.
Correct (left) and incorrect (right) ASCII drawings.

Given $$$n$$$ trees, tell us what Nikita's masterpiece will look like!

If there are several possible answers that fit all of the above conditions, any of them may be output.

Input

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 8$$$) – the number of trees.

The following $$$n$$$ lines contain two integers $$$s_{i}$$$ and $$$t_{i}$$$ ($$$1 \le s_{i}, t_{i} \le 10$$$) – the parameters of the $$$i$$$-th tree.

Output

Output the ASCII drawing.

The output data should not contain any extra characters that do not belong to the drawing!

Examples
Input
3
1 1
2 2
3 3
Output
+-----------+
|   +       |
|  +++      |
| +++++  *  |
|+++++++*** |
| # |  *****|
|###|    |  |
| | |    |  |
+-----------+
Input
4
1 1
1 1
1 1
1 1
Output
+------------+
| +  *  +  * |
|+++***+++***|
| |  |  |  | |
+------------+

G. Grandma's Cubes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Masha and her grandmother are playing dice. The girl throws the dice and announces the number that appears on it. The grandmother is very old and has poor eyesight, but she can hear everything. Masha can distort the result of any dice throw. For example, if the dice show $$$2$$$, and Masha says $$$5$$$, then the result will be $$$5$$$. However, if the grandmother hears three sixes in a row, she takes a magnifying glass and checks only the last throw, after which the number of consecutive sixes is reset.

Masha loves her grandmother very much and does not want to upset her, but at the same time she dreams of scoring the maximum number of points. Help Masha to score the maximum number of points without getting caught by her grandmother.

Input

The first line contains the number of throws $$$n$$$ ($$$1 \le n \le 10^{5}$$$).

The next line contains $$$n$$$ values $$$a_{i}$$$ ($$$1 \le a_{i} \le 6$$$) - the actual number of points on the dice after the $$$i$$$-th throw.

Output

Output a single number - the maximum sum of points that Masha can score.

Examples
Input
3
1 1 6
Output
18
Input
3
2 3 5
Output
17

H. Have fun taking tests
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

You like taking tests, don't you?

The test consists of a list of $$$n$$$ questions, each with two possible answers, and exactly one of them is correct. After completing the test, you receive a mark, with the following grading system:

  • Less than $$$50\%$$$ correct answers – mark $$$2$$$.
  • From $$$50\%$$$ to $$$69\%$$$ correct answers – mark $$$3$$$.
  • From $$$70\%$$$ to $$$89\%$$$ correct answers – mark $$$4$$$.
  • From $$$90\%$$$ correct answers – mark $$$5$$$.

Marks $$$3, 4, 5$$$ are considered satisfactory.

You can take the test a maximum of $$$3$$$ times.

Pass the test with a satisfactory mark!

Input

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) – the number of questions in the test.

Interaction

After you have read $$$n$$$, you can start an attempt. To do this, print: "Start test" on a new line.

Once the attempt has started, questions will be presented to you. Each question consists of three lines. The first line contains the description of the question, the second – the first answer option, and the third – the second answer option. For each question, you must print on a new line "A", if you choose the first answer option, or "B", if the second.

Please note that you will only receive the next question after you have selected an option for the current one. After you answer the $$$n$$$-th question, you need to read a line – the result for the current attempt, the line has the format "Your result: mark". If this mark is satisfactory, then you need to do nothing more, and your program should terminate. Otherwise, you can start the next attempt if you have not exceeded the limit.

Please note that you can start an attempt a maximum of $$$3$$$ times. If you exceed the limit of attempts, then the next line you read will be "Attempts exceeded". In such a case, your program must immediately terminate. Also, if you make an incorrect choice or output something that the system does not expect, you will receive "Incorrect output", and your program must terminate.

It is guaranteed that all tests consist only of ASCII characters with codes from $$$32$$$ to $$$126$$$, and that the length of any line does not exceed $$$256$$$ characters.

After any output, do not forget to print a newline and flush the output buffer. Otherwise, you will receive the verdict Idleness limit exceeded. To flush the buffer, use:

  • fflush(stdout) or cout.flush() or std::endl in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see the documentation for other languages.
Examples
Input
5

1) Cats have nine lives?
A) YES
B) NO

2) Are moles blind?
A) YES
B) NO

3) Does a fly agaric kill flies?
A) YES
B) NO

4) Does an octopus have one heart?
A) YES
B) NO

5) Can turtles cry?
A) YES
B) NO

Your result: 4
Output

Start test



B



B



A



B



A


Input
2

How much is 2*2+2?
1. 6
2. 8

The minimum of 0 and 1 is
1. 1
2. 0

Your result: 2

How much is 2*2+2?
1. 6
2. 8

The minimum of 0 and 1 is
1. 1
2. 0

Your result: 5
Output

Start test



B



A

Start test



A



B

I. Ideal 2B
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a number $$$x$$$. This number is too large, and you would like to write it in a shortened form. For the sake of unambiguity, you have decided to introduce rules for shortening any non-negative number as follows:

  • The shortened form of the number consists of no more than $$$4$$$ characters.
  • If the number $$$x \lt 1000$$$, then its shortened form is the same as the full one, otherwise the shortened form consists of the number $$$a$$$ (possibly a real number) and the character $$$c$$$ (one of K, M, B), indicating the power of ten: K – thousand, M – million, B – billion. The value of the shortened notation is called the number $$$y$$$, equal to $$$a$$$ multiplied by the corresponding power of ten, depending on the character $$$c$$$.
  • The digits of the shortened form match the first digits of the full form.
  • Out of all possible variants, the shortened form of $$$x$$$ is the one whose value does not exceed $$$x$$$ and is closest to $$$x$$$. If there are several such forms, the shortest one is chosen (see examples).

Write the number in its shortened form!

Input

A single line contains one integer $$$x$$$ ($$$0 \le x \lt 10^{12}$$$).

Output

Print a single line – the shortened notation of the number $$$x$$$.

Examples
Input
567
Output
567
Input
1099
Output
1K
Input
9588
Output
9.5K
Input
2000000000
Output
2B
Input
876289
Output
876K
Note

In the second test case, there are several shortened forms that have the closest value to $$$x$$$: 1.0K and 1K. However, according to the fourth point, the shortest one is suitable for us, that is, 1K.

J. Just a map editor
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Maxim is a big fan of various games. This time, he is playing a game called "Heroes of Might and Magic III".

Each scenario in the game is played on a specific map, which is a rectangle consisting of $$$n \times m$$$ cells. Each cell has its own type of terrain, such as "grass", "swamp", "sand", etc. Visually, some cells with the same type of terrain form connected components$$$^{\ast}$$$. There can be many such components, but Maxim prefers scenarios where the map has no more than two types of terrain and the total number of connected components is exactly $$$k$$$.

You, as the most experienced map maker, have promised to come up with a map that Maxim will like. Will you be able to keep this promise?

Connected component$$$^{\ast}$$$ – is a connected area of the table consisting of the same symbol, and for any pair of cells $$$(x_{1}, y_{1})$$$, $$$(x_{2}, y_{2})$$$ belonging to this area, there exists a path from $$$(x_{1}, y_{1})$$$ to $$$(x_{2}, y_{2})$$$$$$^{\ast}$$$, consisting only of cells from this connected area.

Path in the table from $$$(x_{1}, y_{1})$$$ to $$$(x_{2}, y_{2})$$$$$$^{\ast}$$$ – is a sequence of cells that starts at $$$(x_{1}, y_{1})$$$, ends at $$$(x_{2}, y_{2})$$$ and any two adjacent cells in this sequence are neighbors by side.

Input

A single line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \le n, m \le 1000$$$, $$$1 \le k \le n \cdot m$$$).

Output

If such a map can be created, then in the first line print "YES" without quotes and then print the map itself from a new line. It should consist of the symbols '0' and '1' and have exactly $$$k$$$ connected components.

If it is impossible to build such a map, then print "NO" without quotes.

Examples
Input
5 5 5
Output
YES
00001
11111
00000
01001
11101
Input
3 3 6
Output
YES
010
001
010
Input
5 4 19
Output
NO
Input
4 4 11
Output
YES
1010
0010
0101
1010

K. Key anagram
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. You would like to find its key anagram of order $$$k$$$. A key anagram of order $$$k$$$ is the lexicographically smallest string $$$t$$$ of length $$$k$$$, which is obtained from some substring of the original string $$$s$$$ by rearranging its letters. In other words, the key anagram of order $$$k$$$ is the lexicographically smallest anagram of some substring of length $$$k$$$ of the original string $$$s$$$.

We remind you that a string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following conditions holds:

  • $$$a$$$ is a prefix of $$$b$$$, but $$$a \neq b$$$;
  • at the first position where $$$a$$$ and $$$b$$$ differ, the letter in $$$a$$$ occurs earlier in the alphabet than the corresponding letter in $$$b$$$.
Input

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{6}$$$) – the length of the string and the size of the required substring.

The second line contains $$$s$$$.

Output

Print the string $$$t$$$ – the key anagram of order $$$k$$$.

Examples
Input
10 3
teamspirit
Output
aem
Input
16 5
gaminggladiators
Output
aadil

L. Line without beginning, line without end
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

We have conceived a line in the form of $$$y = kx + b$$$. Your task is to deduce this line.

You can make queries, in one question you specify a point ($$$x, y$$$) and receive in return the shortest distance from the point to the line.

Can you manage in no more than $$$5$$$ queries?

Input

It is guaranteed that ($$$-100 \le k, b \le 100$$$).

Interaction

You can start making queries right away. To do this, output:

  • "? x y" ($$$-100 \le x, y \le 100$$$)

on a separate line. After making a query, read a non-negative real number $$$d$$$ with precision up to $$$20$$$ digits – the shortest distance from the point you provided to the line. If you make an incorrect query or exceed the set limit of $$$5$$$ queries, you will receive the number $$$-1$$$ in response, in which case your program should immediately terminate.

To output the answer, output

  • "! k b"

on a separate line. Your answer will be considered correct if the relative or absolute error of the coefficients $$$k$$$ and $$$b$$$ is no more than $$$10^{-3}$$$.

After any output, do not forget to output a newline and flush the output buffer. Otherwise, you will receive the verdict Idleness limit exceeded. To flush the buffer, use:

  • fflush(stdout) or cout.flush() or std::endl in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • refer to the documentation for other languages.
Examples
Input

1.41421356237309504876

0.70710678118654752438

Output
? 0.000 0.000

? 0.000 1.000

! 1.0000 2.0001
Input

0.00000000000000000000

0.00000000000000000000

5.00000000000000000000

5.00000000000000000000

2.50000000000000000000
Output
? 0 5

? 5 5

? 5 0

? 0 0

? 2.5 2.5

! 0.000000011 5.00000003