Igor is renovating again! Once more! This wallpaper! It's everywhere! On every wall!
This renovation is maddening; the next stage of wallpapering has begun. Igor has a very unusual house: it has $$$n$$$ walls, each is $$$3$$$ meters high and $$$a_i$$$ meters wide. Igor came to the hardware store to buy wallpaper. It turns out that there is an infinite number of rolls, each measuring $$$k$$$ meters wide and $$$3$$$ meters high. Our hero wants to save money, so he wants to buy as few rolls as possible. To wallpaper each wall, Igor decided to buy enough rolls so that, for each of wall, all but possibly one roll would be used to its full width of $$$k$$$. If a section less than $$$k$$$ meters wide remains uncovered with wallpaper, Igor cuts the needed piece from a full roll and then doesn't use that roll again for aesthetic reasons (yes, he wants to save money on buying rolls, but not too much). Help Igor calculate how many rolls of wallpaper he needs.
The first line contains two integers $$$n$$$, $$$k$$$ $$$(1 \leq n, k \leq 10^6)$$$ — the number of walls in Igor's house and the width of the wallpaper roll.
The second line contains $$$n$$$ integers $$$a_i$$$ $$$(1 \leq a_i \leq 10^9)$$$ — the width of the $$$i$$$-th wall in Igor's house.
Help Igor determine how many rolls of wallpaper he will need! Igor is too exhausted to calculate it himself.
4 510 13 20 21
14
3 15 6 3
14
4 88 16 32 33
12
In the first test example, each wall will require 2, 3, 4 and 5 rolls, respectively.
Inspired by the matches of the World Classic Tetris Championship, Professor R.'s grandson found Professor R.'s old game console in the pantry and a Tetris cartridge in it. The cartridge game starts at level zero, tetris (clearing four full rows from the playing field) gives 10 points. Every time the player clears 10 rows, the game advances to the next level, and then the score for tetris increases by 10 points. The Professor's grandson became curious: at which level will he be when his total score reaches at least $$$X$$$ points if he clears rows only by making tetrises? Help the grandson by writing a program that determines the level number at the moment his score becomes at least $$$X$$$, as well as the total number of points earned.
A single line contains the number $$$X$$$ $$$(0 \le X \le 10^{1000})$$$.
In a single line, print two numbers separated by a space – the level which the Professor's grandson will reach when his score first becomes at least $$$X$$$ points, and the number of points earned.
0
0 0
1
0 10
90
2 100
70
2 70
Consider the fourth example. At level zero, the grandson will complete 3 tetrises, earning 30 points. During this time, 12 rows are cleared, which causes the game to advance to level one. At level one, he then completes 2 more tetrises, earning 2 * 20 = 40 points. Since a total of 20 rows are now cleared, the game advances to level two. This results in a total score of 70 points (30 + 40).
The level map of a certain game is a rectangular maze with the size of $$$N \times M$$$ cells. The player needs to move from the top-left cell to the bottom-right cell. In one move, the player can step to a side-adjacent cell, if there is no obstacle in it.
After reviewing the game results, the game designer determined that the shortest path from the top-left to the bottom-right cell was too short. Therefore, he wants to place an additional obstacle in one of the free cells so that the shortest path becomes longer, but still exists. Find all possible ways to do this.
The first line contains two numbers $$$N$$$ and $$$M$$$ ($$$1 \le N, M \le 1000$$$).
Next there are $$$N$$$ lines of $$$M$$$ characters each, representing the cells of the maze: the symbol '.' indicates an empty cell, and the 'X' symbol shows an occupied cell.
It is guaranteed that the top-left and bottom-right cells are free and there is a path between them.
Print the maze map (you do not need to print the dimensions), marking with the symbol '*' those cells in which you can put an additional obstacle.
4 5......XX...X......X.
.***. .XX.. .X... ...X.
Student Vasya is preparing to submit a physics lab report and decided to slightly embellish the data obtained as a result of the experiment. During the work, Vasya measured a certain value and recorded the results as a sequence of integers $$$ A = (a_0, a_1, a_2, ..., a_{n - 1}) $$$. Vasya wants to leave in the sequence only those measurements that form an oscillating subsequence $$$ B = (b_0, b_1, b_2, ..., b_{k - 1}) $$$. A sequence is considered oscillating if every element (except the first and the last) is either strictly greater than both of its neighbors $$$(b_{i-1} \gt b_i \lt b_{i+1})$$$ or strictly smaller than them $$$(b_{i-1} \lt b_i \gt b_{i+1})$$$. Help Vasya – write a program that, for a sequence $$$ A = (a_0, a_1, a_2, ..., a_{n - 1}) $$$, finds its longest oscillating subsequence $$$ B $$$ with a length of at least three.
The first line of input data contains a single integer $$$ n $$$ $$$(1 \leq n \leq 50\,000)$$$ – the number of elements in the sequence $$$ A $$$. The second line contains $$$ n $$$ integers separated by spaces – the elements of the sequence $$$ a_i $$$ $$$(0 \leq i \lt n~,~-10^9 \leq a_i \leq 10^9)$$$.
The first line contains an integer $$$ k $$$ $$$(3 \leq k \leq n)$$$ – the number of remaining elements of the sequence $$$ A $$$. The second line contains $$$ k $$$ integers $$$ r_0, r_1, ..., r_{k-1} $$$ $$$(0 \leq r_i \lt n $$$; $$$r_i \lt r_{i+1})$$$, ordered in ascending order and separated by spaces – the indexes of the elements of the sequence $$$ A $$$, forming an oscillating a subsequence. If such a subsequence does not exist, the first line must contain 0.
If there are multiple solutions, print any of them.
31 3 2
3 0 1 2
31 2 3
0
The subsequence $$$ B $$$ can be obtained from the sequence $$$ A $$$ by removing a certain number of elements (possibly none). The order of the elements is preserved.
The solution should not output the subsequence $$$ B $$$ itself, but rather the indexes of those $$$ A $$$ elements that have not been removed.
The input to your program is a valid arithmetic expression that can contain only integers in the range from 0 to 1000, parentheses, and the signs of binary operations '+' and '-'. There are no unary operations.
You are allowed to change any plus sign to a minus sign, and any minus sign to a plus sign. Change the signs so that the value of the expression is as small as possible.
A single line of input data contains an expression in the format described above, no more than $$$10^5$$$ characters long.
Print the resulting expression after changing the characters.
If there are multiple solutions, print any of them.
5+(1+3-2)
5-(1+3+2)
Professor R.'s grandson enjoys watching the classic Tetris World Championships. For anyone who might have forgotten what classic Tetris is, let's take a moment to refresh your memory.
The Classic Tetris World Championship (CTWC) is a video game competition series organized by the Portland Retro Gaming Expo. It was first held in 2010 during the production of the film "Ecstasy of Order: The Tetris Masters". The championship's goal is to determine the world's top Tetris player. For its first two years, the championship took place in Los Angeles, California, but then it moved to Portland, Oregon, where it has been held annually since 2012.
Participants in the tournament compete using the 1989 Nintendo version of Tetris on the Nintendo Entertainment System, played on specialized TVs. The final rounds are streamed online and displayed on screens, with a head-up display added to enhance the viewing experience for the audience.
Let's recall how the game "Tetris" works. There are 7 types of tetramino shapes in the game, each identified by a specific letter (see the image below).
In Tetris, random tetromino shapes fall from the top into a rectangular playfield that is 10 cells wide and 20 cells high. While the piece is falling, the player can rotate it 90 degrees or move it horizontally. It's also possible to "drop" the piece – to make it fall faster once its landing spot is decided. Each piece continues to fall until it lands on another piece or reaches the bottom of the playfield. When a horizontal row of 10 cells is completely filled, it disappears, and all blocks above it shift down by one row. A preview of the next piece is also shown, allowing the player to plan their moves ahead. As the game progresses, the speed gradually increases. The game ends when a new piece can no longer fit into the playfield. Players earn points for each filled row, so the main goal is to complete as many horizontal lines as possible while preventing the playfield from filling up vertically, maximizing their score.
In the Classic Tetris World Championship, players start at level 18, where a player gets 760 points for one filled row, 1900 points for two filled rows, 5700 points for three, and 22800 points for tetris (four filled rows). Once the player clears at least 130 rows, the number of points per row increases by 40, for two rows by 100, for three rows by 300, for tetris by 1200. At the same time, the player advances to level 19, where the falling speed of the pieces also increases. Every time the total number of cleared lines reaches 140, 150, and so on, the player moves up another level, with the points increasing by the values indicated earlier.
Professor R.'s grandson wrote down the game log of the winner of the match he has just watched, but he forgot how many points the winner scored. Help him determine how many points the winner earned by the end of the game.
The first line contains the number $$$N$$$ $$$(1 \le N \le 10^5)$$$ – the number of the player's scoring actions. The following $$$N$$$ lines contain the game log: one of the four lines is $$$single$$$ if the winner filled one row, $$$double$$$ if two, $$$triple$$$ if three, or $$$tetris$$$ if the player filled four rows.
In a single line, print two numbers separated by a space – the number of points scored by the winner of the game and the level at which he finished the game.
4singledoubletripletetris
31160 18
2singlesingle
1520 18
In the first test case, the winner scored 760 + 1900 + 5700 + 22800 = 31160 points.
Student Misha became interested in card tricks, but unfortunately, he never managed to learn professional card shuffling. Since he is studying programming, he came up with the following algorithm for shuffling a deck of cards:
For example, if we have a deck of $$$10$$$ cards numbered from $$$0$$$ to $$$9$$$, shuffling them into $$$3$$$ piles will get the following order: (from top to bottom) " 9, 6, 3, 0, 7, 4, 1, 8, 5, 2 ":
| Before mixing | Pile 1 | Pile 2 | Pile 3 | After mixing |
| 0 | 9 | |||
| 1 | 6 | |||
| 2 | 3 | |||
| 3 | 0 | |||
| 4 | 7 | |||
| 5 | 4 | |||
| 6 | 9 | 1 | ||
| 7 | 6 | 7 | 8 | 8 |
| 8 | 3 | 4 | 5 | 5 |
| 9 | 0 | 1 | 2 | 2 |
Trying to improve the shuffling, Misha applied this algorithm several times in a row and, to his surprise, found that consistent application of this algorithm always brings the cards back to their original order in the end. Only the number of applications of the algorithm depends on the number of initial cards $$$n$$$ and the number of piles $$$k$$$ used when everything returns to its original order. If $$$n = k$$$, then the order of the cards does not change at all.
To shuffle cards well, Misha wants to determine what minimum number of applications of the algorithm with $$$k$$$ piles a deck of $$$n$$$ cards will return to its original order.
A single line contains two integers $$$n$$$ ($$$1 \le n\le 800$$$) and $$$k$$$ ($$$1 \le k \le n$$$), separated by a space – the number of cards in Misha's deck and the number of piles in the algorithm, respectively.
In a single line, print the number – the minimum number of consecutive applications of the algorithm, after which the cards will return to their original order.
10 3
4
The canonical full notation of an IP address in TCP/IP version 6 consists of 8 blocks of 4 hexadecimal digits each, separated by colons. However, this notation is very long, so there are several rules for shortening it:
Operations can be applied to an IP address either separately or together, in any order.
In addition, there is a convention to use lowercase letters when writing the address.
Write a program that, given a shortened IP address, restores its full canonical notation.
The input data consists of a single string, a shortened IP address consisting only of hexadecimal digits and colons. It is guaranteed that the double colon "::" appears in this line no more than once.
Print a single line containing 8 groups of four-digit hexadecimal numbers separated by colons – the full canonical notation of the IP address.
2001:0DB8:85A3:0000:0000:8a2e:0370:7334
2001:0db8:85a3:0000:0000:8a2e:0370:7334
2001:db8:85a3::8a2e:370:7334
2001:0db8:85a3:0000:0000:8a2e:0370:7334
::1
0000:0000:0000:0000:0000:0000:0000:0001
1::1:0:1:0:1:0
0001:0000:0001:0000:0001:0000:0001:0000
More than anything, Professor R. loves working in the garden and even wants to retrain as an agronomist. Since gardening is a true passion of his life, and he just loves mathematics, he tries different ways to plant tomatoes.
The Professor's garden is a rectangle with its bottom-left corner at the point $$$(x, y)$$$, width $$$w$$$ (along the $$$Ox$$$ axis) and height $$$h$$$ (along the $$$Oy$$$ axis) and sides of the rectangle are parallel to the coordinate axes. The Professor can plant tomatoes only at points with integer coordinates in his garden (including the garden's boundary). Initially, he starts at the point with coordinates $$$(0, 0)$$$ and from there he can move to any point with integer coordinates located at a distance of $$$\sqrt{n}$$$, where $$$n$$$ is a number whose prime factorization contains $$$2$$$ to an odd power. From there, he can again move to another point with integer coordinates located at a distance of $$$\sqrt{n}$$$, and so on, so the Professor moves along the plane and plants tomatoes.
The Professor needs to prepare the seedlings for planting in advance; he wants to plant as many tomatoes as possible in his garden, and at the same time so that, after planting in the way described above, no seedlings remain unused — in other words, the number of seedlings must be equal to the number of points with integer coordinates in the garden that he can reach by stepping a distance of $$$\sqrt{n}$$$.
The Professor is on vacation and has not been doing calculations for a long time. Help him write a program that determines how many seedlings need to be prepared in order to plant as many tomato seedlings as possible at points with integer coordinates that can be reached from $$$(0, 0)$$$ by stepping on $$$\sqrt{n}$$$.
The input data contains $$$5$$$ integers: $$$n$$$, $$$x$$$, $$$y$$$, $$$w$$$, $$$h$$$, where $$$n$$$ ($$$2 \le n \le 10^{12}$$$) — the square of the Professor's step length, where $$$n$$$ is such that its factorization contains $$$2$$$ to an odd power, $$$x$$$, $$$y$$$ ($$$-10^9 \le x, y \le 10^9$$$) — coordinates of the lower-left corner of the garden, $$$w$$$, $$$h$$$ ($$$1 \le w, h \le 5 \cdot 10^5$$$) — the width and height of the vegetable garden (horizontal and vertical), respectively.
Print a single number — the total number of tomato seedlings that need to be prepared by Kadyrbechu (that's Professor R.'s name) for planting.
8 0 0 4 4
5
8 -1 -1 5 5
5
10 0 0 30 30
481
10 -10 -10 100 100
5101
One day, Dunno came up with a new cube game – he lined up the cubes in a long line from left to right, and then removed pairs of adjacent cubes with a certain property. After removing a couple of cubes, the line on the right shifted to the left by two positions to fill the empty space. Dunno has exactly $$$n$$$ cubes, and each one is signed with a number from $$$1$$$ to $$$10^9$$$ (some cubes may be repeated).
Dunno experimented with various properties of pairs, but since he is currently studying the divisibility of numbers at school, he decided on the following rule: two adjacent cubes can be removed if the number on one cube is divisible by the number on the other cube (the order of the cubes in the pair is not important).
Unfortunately, with this formulation of the problem, a difficulty arises – not every line of cubes can be completely disassembled. Help Dunno – write a program that, given a preassembled line of cubes, will determine the minimum number of cubes that must be taken away so that the remaining cubes can be fully disassembled by removing pairs according to the rule used by Dunno.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200$$$) – the number of cubes in the line. The second line contains $$$n$$$ numbers separated by spaces – numbers written on cubes in a line if read from left to right.
The first line contains an integer $$$k$$$ ($$$0 \le k \le n$$$) – the number of cubes to be removed. If $$$k \gt 0$$$, then in the second line print the $$$k$$$ integers $$$a_i$$$ ($$$1 \le a_i \le n$$$), separated by spaces – the numbers of the cubes to be removed. The cubes are numbered from left to right, the leftmost one has the number 1.
If there are multiple solutions, print any of them.
42 3 4 9
2 1 3
42 3 9 4
0
Natural numbers are a fascinating subject of study, and mathematicians constantly confirm this by discovering more and more interesting patterns. Equally interesting are integer functions of natural numbers, such as factorials.
It is obvious that any natural $$$n$$$ can be represented as the ratio of two factorials: $$$$$$ n = \frac{n!}{(n - 1)!} .$$$$$$
It is also well known that some integers can be represented as the ratio of one factorial to the product of two others greater than 1: $$$$$$ n = \frac{a!}{b! \times c!} .$$$$$$
An example of such numbers are the binomial coefficients: $$$$$$ C_n^k = \frac{n!}{k! (n-k)!} \quad = \gt \quad 6 = \frac{4!}{2! \times 2!}.$$$$$$
Let us limit ourselves to considering factorials up to $$$ 50\,000! $$$, and numbers up to $$$ 1\,000\,000\,000 $$$. Write a program that, given a number $$$n$$$ , determines whether it can be represented as $$$$$$ n = \frac{a!}{b! \times c!}, $$$$$$ where $$$c \le b \lt a$$$.
The input consists of a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$).
In a single line, print three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \lt c \le b \lt a \le 50\,000$$$), separated by spaces. If this representation is not the only one, print the one with the smallest numerator $$$ a $$$, and if there are several such solutions, then among them, select the one with the smallest number $$$ b $$$. If no solution exists within the constraints, print three numbers $$$-1$$$.
5
6 4 3
50000
-1 -1 -1
1
6 5 3
6
4 2 2
The jury knows that for any number $$$n \gt 1$$$ there exists a representation of the form $$$n = \frac{2n!}{((2n - 1)! \times 2! )} $$$ (and it's not the only one – there are infinitely many similar representations of the form $$$n = \frac{(k!\times n)!}{(k!\times n - 1)!\times k!}$$$, for a total of $$$k \gt 1$$$). For the number $$$50000$$$ from the second example, the solution "-1 -1 -1" means that it cannot be represented under the $$$a\le 50\,000$$$ constraint.
Today in programming class, student Levodt learned about bit operations, specifically the "XOR" operation. This operation exists in all modern programming languages. For instance, in the languages $$$C\!+\!+$$$, $$$Python$$$, and $$$Java$$$, it is designated as "$$$ ^\wedge $$$", while in $$$Pascal$$$, it is designated as "xor". An example of the "xor" operation is: $$$10101_2 \oplus 10001_2 = 00100_2$$$. Note that "XOR" is similar to adding the corresponding bits of numbers modulo 2.
Levodt is given the following homework assignment: find any two numbers whose "XOR" equals a given non-negative number $$$N$$$.
He asks you to help in writing a program that can determine whether there are two natural numbers (not necessarily different), whose "XOR" equals the given $$$N$$$.
A single line contains the number $$$N$$$ $$$(0 \le N \le 10^{18})$$$.
If no two natural numbers exist whose XOR equals to the specified number $$$N$$$, print "NO" (without quotes) on a single line. Otherwise, on the first line, print "YES" (without quotes), on the second line, print two numbers separated by a space, the xor of which is equal to $$$N$$$. The numbers in the output must not exceed $$$10^{18}$$$.
If there are multiple solutions, print any of them.
15
YES 12 3
6
YES 4 2
Memory managers are parts of operating systems and programming systems that manage memory allocation, deallocation, and optimize memory resources for processes. The lowest level of managers operates with pages of physical memory – fix-sized blocks of the same length, into which the entire available address space is divided.
Page managers must work very quickly and implement extremely simple algorithms. Develop a simple page manager that works according to the following rules:
The first line contains two numbers $$$n$$$ $$$(0 \lt n \le 10^5)$$$ and $$$k$$$ $$$(0 \lt k \le 10^5, k \le n)$$$ separated by a space. This is followed by $$$k$$$ lines, each describing a request. Each request consists of a single number $$$h_i$$$ $$$(0 \le h_i \lt n)$$$ – the number of the preferred page.
Print $$$k$$$ lines, each containing a single integer $$$r_i$$$ $$$(0 \le r_i \lt n)$$$ – the number of the page allocated in response to the request $$$h_i$$$.
5 3024
0 2 4
5 3222
2 1 3