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}$$$."
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$$$).
Print a single integer – the answer to the problem.
7 1
14
-4 1
17
25 1
0
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}$$$.
The only line contains two positive integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^{9}$$$).
Output one of the following:
3 5
>
7 7
=
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!
The only line contains a single integer $$$n$$$ ($$$4 \le n \le 1000$$$).
Output a single integer $$$x$$$ - the answer to the problem.
5
4
12
6
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.
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.
Print two numbers separated by a space - the number of mushroom pies that Masha will eat, and then Petya.
71 1 0 1 0 1 1
1 1
241 0 1 1 1 0 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 1
5 2
11
0 0
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:
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?
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:
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$$$.
For each "Get" request, output the response that your system will provide.
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
2 2 1 1
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
0 7 1 1 9
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:
Correct tree drawings.
Incorrect tree 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.
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 the ASCII drawing.
The output data should not contain any extra characters that do not belong to the drawing!
3 1 1 2 2 3 3
+-----------+ | + | | +++ | | +++++ * | |+++++++*** | | # | *****| |###| | | | | | | | +-----------+
41 11 11 11 1
+------------+ | + * + * | |+++***+++***| | | | | | | +------------+
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.
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 a single number - the maximum sum of points that Masha can score.
31 1 6
18
32 3 5
17
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:
Marks $$$3, 4, 5$$$ are considered satisfactory.
You can take the test a maximum of $$$3$$$ times.
Pass the test with a satisfactory mark!
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) – the number of questions in the test.
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:
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
Start test B B A B A
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
Start test B A Start test A B
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:
Write the number in its shortened form!
A single line contains one integer $$$x$$$ ($$$0 \le x \lt 10^{12}$$$).
Print a single line – the shortened notation of the number $$$x$$$.
567
567
1099
1K
9588
9.5K
2000000000
2B
876289
876K
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.
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.
A single line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \le n, m \le 1000$$$, $$$1 \le k \le n \cdot m$$$).
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.
5 5 5
YES 00001 11111 00000 01001 11101
3 3 6
YES 010 001 010
5 4 19
NO
4 4 11
YES 1010 0010 0101 1010
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:
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$$$.
Print the string $$$t$$$ – the key anagram of order $$$k$$$.
10 3teamspirit
aem
16 5gaminggladiators
aadil
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?
It is guaranteed that ($$$-100 \le k, b \le 100$$$).
You can start making queries right away. To do this, output:
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
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:
1.41421356237309504876 0.70710678118654752438
? 0.000 0.000 ? 0.000 1.000 ! 1.0000 2.0001
0.00000000000000000000 0.00000000000000000000 5.00000000000000000000 5.00000000000000000000 2.50000000000000000000
? 0 5 ? 5 5 ? 5 0 ? 0 0 ? 2.5 2.5 ! 0.000000011 5.00000003