Author: | Антон Карабанов | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Astrologer Timofey considers a year to be happy if different consecutive digits are used in its notation. For example, the nearest such year will occur in 2031. Determine, by the year number, how many years it will take for a happy year to come?
The input consists of a single line containing a natural number n — the year number.
Output a single non-negative integer — the answer to the problem.
1 ≤ n ≤ 9876543210
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Let's consider a set of n two-dimensional bricks with arbitrary widths Wi and height 1.
It is required to build a wall of width L and maximum possible height (but no greater than 5) using minimum possible count of the bricks.
The bricks are arranged in layers, and each layer should be fully filled, meaning no gaps between bricks are allowed.
One is not allowed turn the bricks. They all should remain a horizontal position.
The input contains the number n, followed by exactly n integers Wi representing the widths of the bricks.
Next is the number L specifying the width of each layer.
The output should contain a sequence of brick numbers, arranged in the order of layer formation:
the bricks of the first layer, followed by those of the second layer, and so on.
It is assumed that the bricks are numbered starting from zero.
0 < Wi ≤ L ≤ 20, 0 < n ≤ 100
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|
Author: | A. Usmanov | Time limit: | 1 sec | |
Input / output: | interactive | Memory limit: | 256 Mb |
This is an interactive problem. Your program will interact with a jury program by sending and receiving particular messages.
The jury has a two-dimensional matrix with N rows and M columns filled with numbers, where each number can be either 1 or 0. Rows are numbered from 1 to N from top to bottom, and columns are numbered from 1 to M from left to right.
Your program can make queries of the form "? Xi Yi Ai Bi
",
where i is the query number,
Xi, Yi represent the coordinates of the top-left corner of the rectangle, denoting the row and column numbers, respectively.
On the other hand, Ai, Bi indicate the dimensions of the rectangle, representing the number of rows and columns, respectively.
In response to the query, the jury's program will report the number of ones in the rectangle specified by the query.
Each rectangle must be entirely within the matrix, meaning the following inequalities must be satisfied:
1 ≤ Xi, Ai ≤ N and 1 ≤ Yi, Bi ≤ M
Xi + Ai − 1 ≤ N and Yi + Bi − 1 ≤ M
There are also constraints on the sizes of rectangles. The first rectangle must be smaller than the matrix on each side without considering orientation, and each subsequent rectangle must be smaller than the previous one on each side without considering orientation. More formally, the following inequalities must be satisfied:
min(A1, B1) < min(N, M) and max(A1, B1) < max(N, M)
min(Ai, Bi) < min(Ai − 1, Bi − 1) and max(Ai, Bi) < max(Ai − 1, Bi − 1) by i > 1
The goal is to determine the number of ones in the matrix by making any number of queries. It is guaranteed that the values in the matrix are predefined and do not depend on the queries.
The first line of input contains two integers N and M, the dimensions of the matrix.
To make the i-th query, your program should output "? Xi Yi Ai Bi
",
where Xi, Yi are integers, the coordinates of the top-left corner of the rectangle, row and column numbers respectively.
On the other hand Ai, Bi are integers, the dimensions of the rectangle, representing the number of rows and columns, respectively.
After the query, the jury's program responds to your program with an integer S, the number of ones in the specified rectangle.
When your program determines the answer to the task, it should output "! S
",
where S is an integer, the number of ones in the matrix.
After outputting the answer, the program should terminate.
If your program makes incorrect query, it will receive "Presentation error" verdict.
Every query and final output must be a single line ending with single end-of-line (\n
).
Output buffers must be flushed after every line:
Language | C++ | Pascal | Java | Python |
Code | cout.flush() |
flush(output) |
System.out.flush() |
stdout.flush() |
10 ≤ N, M ≤ 100
0 ≤ S ≤ 104
The matrices from the examples are represented in the picture.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
The scientists of Flatland have discovered that the universe they live in is topologically similar to the surface of a torus.
This means that along each coordinate axis x and y, the periodicity condition is satisfied with a respective period Lx and Ly.
In other words, points at coordinates (x + u ⋅ Lx, y + v ⋅ Ly) with any integer values u and v are identical.
For the purpose of a scientific experiment, a ray is emitted from a point with coordinates (0, 0), directed by the vector D⃗ = (dx, dy).
It is required to determine the distance the ray will travel before reaching the initial point.
The result should be expressed in units equal to the length of the vector D⃗,
In other words, the task is to find the minimum coefficient λ > 0, such that by shifting the vector, one can reach the initial point.
The obtained number should be represented as an irreducible fraction: λ = αβ.
The beginning of the input data contains a natural numbe n, followed by exactly n queries,
each specified by a set of integers: Lxi, Lyi, dxi и dyi.
The output data should contain the values αi и βi,
obtained in response to each i-th query.
1 ≤ (Lxi, Lyi) ≤ 106, − 106 ≤ (dxi, dyi) ≤ 106,
|dxi| + |dyi| > 0,
1 ≤ n ≤ 105.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | Антон Карабанов | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
In the research institute where Timofey works, a successful study of the sequence of natural numbers is underway. Every day, his colleagues discover new and new properties of this sequence, and Timofey tries to keep up with them. Today, as usual, Timofey wrote down a row of natural numbers from 1 to n on the board and tries to answer the question of whether it is possible to erase several (at least one) consecutive numbers in the middle of the list so that the sum of the remaining numbers on the left is equal to the sum of the remaining numbers on the right.
The input consists of a single line containing a natural number n.
The output should include a non-negative integer, representing the number of different ways to erase numbers.
3 ≤ n ≤ 105
In the first example, n = 5. Let's list all the ways to erase numbers in the middle of the row:
In none of them does the required property hold.
In the second example, n = 21. Let's list all the good ways to erase numbers in the middle of the row:
In the first list, the sum of the numbers on the left and right is 21, in the second — 78. There are two ways in total.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
Author: | Антон Карабанов | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
The flag of Chita is a rectangular cloth divided into four elements. The ratio of the width of the flag to its length is 2:3. In the hoist part of the flag is an equilateral triangle of yellow color, which has a base equal to the width of the flag (vertical size of the cloth) and a height equal to half of its length (horizontal size of the cloth). The triangle is flanked by equal-sized stripes of green, white, and red colors.
The colors of the flag reflect the colors of the coat of arms of the urban district of "City of Chita", carrying the traditional heraldic meaning:
A flag of Chita with height of h is drawn on the coordinate plane as shown in the figure (in the first quadrant, the lower left corner coincides with the origin). Determine the color of the point with the specified coordinates.
Three lines of the input file contain three natural numbers, separated by a space: h - the height of the flag, as well as x and y — the coordinates of the point. It is guaranteed that h is divisible by 12.
Print Green
, White
, Red
or Yellow
— the answer to the problem. Print Line
if the point lies on the boundary of the flag or on the line separating two or three colored areas.
12 ≤ h ≤ 109
0 ≤ x ≤ 3 × h2
0 ≤ y ≤ h
See the picture.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | Евгений Татаринов | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
In the class, there are N students, conveniently numbered from 1 to N.
One day, the computer science teacher gave a very challenging test. Naturally, some students will copy it, while others will attempt it independently and receive the maximum score (the school uses a K-point grading system, meaning a student can receive a grade as a natural number in the range from 1 to K). However, if student U copies from student V, and student V's score is X, then student U's score will be X − 1 (if X = 1, then the student will receive a grade of 1, as there is no lower grade).
Due to the limited time for the test, it could happen that the first student copied from the second, the second copied from the third, ..., the T-th copied from the first. In this case, all students would have empty answer sheets, and therefore, they would receive a grade of 1.
You know who copied from whom. Help the class and determine the grade each student will receive!
The first line contains natural numbers N и K — the number of students and the grading system value. The next line contains a sequence A of N natural numbers, where the i-th number indicates that the i-th student copied from the Ai-th student.
In a single line, output N numbers, where the i-th number indicates the grade received by the i-th student.
1 ≤ K ≤ N ≤ 105, 1 ≤ Ai ≤ N
The first student copied from the second, the second copied from the fourth, the fourth copied from the first. These three students received a grade of 1. The third student did the work independently and received a grade of 3, while the fifth copied the work from the third and received a grade of 2.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Young historian Vasya, as part of his dissertation work, is engaged in comparing records from documents stored in the archive.
Each document covers a specific time interval and contains information about events that occurred during that time.
Vasya is interested in how the same event was covered in different sources.
To achieve this, he has to search for documents each time that could contain a record of the event he is interested in.
As there could be too many such events, you are required to write a program that, for a given event, would perform a search for all relevant documents.
At the beginning of the input data there is a natural number N, followed by 2 × N integers specifying the time interval [Ai, Bi] for each document.
Then, there is a number M and exactly M queries containing the time of the event Cj.
The output data should contain a set of answers to each of these queries.
It starts with the number of detected documents, followed by their numbers.
It is assumed that the numbering of documents starts from zero.
Constraints: The total number of documents in the output does not exceed 106.
− 106 ≤ Ai ≤ Bi ≤ 106, − 106 ≤ Cj ≤ 106, 1 ≤ N ≤ 2 ⋅ 104, 1 ≤ M ≤ 105
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Matrix of camera represents a rectangular table of dimensions [n × m], consisting of photosensitive elements (cells). At the moment of shooting, each cell of this table is assigned a real value Xi j, indicating its state (intensity).
It is known that when reading the state of a particular cell, a weighted sum of the states of the surrounding cells is added to it, forming an ordered set of layers (see the figure). In this case, each subsequent layer has half the influence of the previous one.
The influence coefficient of each such cell on the obtained value is equal to 1 / (2l ⋅ Nl), where l is the number of the layer containing it, and, Nl is the number of cells in the l-th layer.
Also, for a separately taken camera model, the maximum number of layers k, influencing the measurement result is known.
For a given matrix Y, obtained as a result of measurements and an impact radius k it is required to restore the original values Xi j.
The values of dummy cells (located outside the matrix) are considered to be zero.
At the beginning of the input data three natural numbers are stored: n, m и k. Then follows the matrix of measurement results Y, recorded in row format.
The output data should contain the restored matrix X. All values should be specified with an accuracy of up to 5 decimal places.
0 ≤ Yi j ≤ 10, 0 < n ⋅ m ≤ 40 000, 0 < k ≤ 6
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | Евгений Татаринов | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Once upon a time, Eugene and Angelica found themselves at a javelin throwing competition as spectators. N athletes were participating in the competition.
Each time the i-th athlete threw the javelin, Eugene would inform Angelica about the distance the athlete threw the javelin (it happened that all the numbers Eugene mentioned were pairwise distinct). At the same time, Angelica recorded on a piece of paper the place that the i-th athlete would take after their throw.
Unfortunately, when the competition ended, Angelica lost the sheet of paper and was very upset. But Eugene remembers how many meters each athlete threw their javelin. Help the kids restore the lost sheet!
The first line of input contains a natural number N — the number of athletes.
The second line contains a sequence of distinct natural numbers L, where Li — is the number indicating how many meters the i-th athlete threw their javelin.
In a single line, output a sequence of N natural numbers, where the i-th number indicates the place that the i-th athlete takes after their throw.
1 ≤ N ≤ 105, 1 ≤ Li ≤ 109
The first athlete threw the javelin and became the first in the list. The second athlete threw the javelin farther than the first and became the first in the list. The third athlete threw farther than the first but closer than the second, so the third became the second in the list. The fourth athlete threw farther than the first but closer than the second and the third, so the fourth became the third in the list.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | И. Блинов | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 512 Mb | |
Output file: | Standard output |
Paulundra is participating in speed climbing competitions. This discipline involves participants undergoing qualification rounds, followed by paired races. The following rules apply during a paired race:
Paulundra won the qualification with the best time and observed the strategy of each of the n participants in the competition. She knows that participant number i plans to complete the route in ti seconds and knows the probability in percentage that this participant will fall pi. Paulundra also knows that she can complete the route in any time between a and b, and the probability of falling at the chosen time x can be calculated as 1 − x − ab − a.
Help Paulundra choose the optimal time xi for each opponent so that the probability of Paulundra's victory is maximized. If there are multiple optimal times, choose the one that is smaller.
The first line of input contains two integers a and b. The second line of input contains an integer n. The following n lines each contain two integers ti and pi.
Output n integers xi.
1 ≤ n ≤ 105
1 ≤ a, b, ti ≤ 109
1 ≤ pi ≤ 100
a < b
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | Антон Карабанов | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
On the board, a natural number is written. Timofey wants to maximize this number, meaning he wants all nines to be at the beginning, followed by eights, and so on. In one operation, he can swap any two adjacent digits of the number. Determine the minimum number of operations he needs to achieve this goal.
A single line of input contains a natural number n.
Output a single non-negative integer, the answer to the problem.
1 ≤ n ≤ 10100000.
Initial string: 2023.
1) 2032.
2) 2302.
3) 3202.
4) 3220.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | И. Блинов | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 512 Mb | |
Output file: | Standard output |
Elephant Pakhom is a novice developer. Pakhom's first task at his new workplace is to develop a program for removing personal data from text composed of Latin alphabet letters, digits, and spaces.
Personal data in this context consists of two consecutive numbers separated by a space, where the first number comprises four digits, and the second number comprises six digits (passport series and number, respectively). They need to be replaced with the character sequence "#### ******
".
Pakhom smoothly handled this task. Now it's your turn.
The input contains a single line S.
Print the line S after deleting personal data.
1 ≤ |S| ≤ 1000
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|