contestId int64 0 1.01k | name stringlengths 2 58 | tags listlengths 0 11 | title stringclasses 523
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | test_cases listlengths 0 402 | timeConsumedMillis int64 0 8k | memoryConsumedBytes int64 0 537M | score float64 -1 3.99 | __index_level_0__ int64 0 621k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
707 | Pythagorean Triples | [
"math",
"number theory"
] | null | null | Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, tripl... | The only line of the input contains single integer *n* (1<=≤<=*n*<=≤<=109) — the length of some side of a right triangle. | Print two integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them. | [
"3\n",
"6\n",
"1\n",
"17\n",
"67\n"
] | [
"4 5",
"8 10",
"-1",
"144 145",
"2244 2245"
] | Illustration for the first sample. | [
{
"input": "3",
"output": "4 5"
},
{
"input": "6",
"output": "8 10"
},
{
"input": "1",
"output": "-1"
},
{
"input": "17",
"output": "144 145"
},
{
"input": "67",
"output": "2244 2245"
},
{
"input": "10",
"output": "24 26"
},
{
"input": "14"... | 46 | 0 | 3 | 83,651 | |
798 | Mike and distribution | [
"constructive algorithms",
"sortings"
] | null | null | Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers *A*<==<=[*a*1,<=*a*2,<=...,<=*a**n*] and *B*<==<=[*b*1,<=*b*2,<=...,<=*b**n*] of length *n* each which he... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the sequences.
On the second line there are *n* space-separated integers *a*1,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — elements of sequence *A*.
On the third line there are also *n* space-separated integers *b*1,<=...,<=*b**n* (1<=≤<=... | On the first line output an integer *k* which represents the size of the found subset. *k* should be less or equal to .
On the next line print *k* integers *p*1,<=*p*2,<=...,<=*p**k* (1<=≤<=*p**i*<=≤<=*n*) — the elements of sequence *P*. You can print the numbers in any order you want. Elements in sequence *P* should ... | [
"5\n8 7 4 8 3\n4 2 5 3 7\n"
] | [
"3\n1 4 5\n"
] | none | [
{
"input": "5\n8 7 4 8 3\n4 2 5 3 7",
"output": "3\n1 4 5"
},
{
"input": "27\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864\n67108864 33554432 16777216 8388608 4194304 2097152 1048576 524288 262144 1... | 0 | 0 | -1 | 83,787 | |
559 | Randomizer | [
"combinatorics",
"geometry",
"probabilities"
] | null | null | Gerald got tired of playing board games with the usual six-sided die, and he bought a toy called Randomizer. It functions as follows.
A Randomizer has its own coordinate plane on which a strictly convex polygon is painted, the polygon is called a basic polygon. If you shake a Randomizer, it draws some nondegenerate (i... | The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=100<=000) — the number of vertices of the basic polygon.
Next *n* lines contain the coordinates of the vertices of the basic polygon. The *i*-th of these lines contain two integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — the c... | Print the sought expected value with absolute or relative error at most 10<=-<=9. | [
"4\n0 0\n2 0\n2 2\n0 2\n",
"5\n0 0\n2 0\n2 2\n1 3\n0 2\n"
] | [
"0.2\n",
"0.8125\n"
] | A polygon is called strictly convex if it is convex and no its vertices lie on the same line.
Let's assume that a random variable takes values *x*<sub class="lower-index">1</sub>, ..., *x*<sub class="lower-index">*n*</sub> with probabilities *p*<sub class="lower-index">1</sub>, ..., *p*<sub class="lower-index">*n*</su... | [
{
"input": "4\n0 0\n2 0\n2 2\n0 2",
"output": "0.2"
},
{
"input": "5\n0 0\n2 0\n2 2\n1 3\n0 2",
"output": "0.8125"
},
{
"input": "4\n0 0\n3 0\n2 2\n0 3",
"output": "1.2"
},
{
"input": "4\n0 0\n100 0\n67 69\n0 100",
"output": "3999.6"
},
{
"input": "20\n89100 45399... | 77 | 8,396,800 | 0 | 83,789 | |
201 | Thoroughly Bureaucratic Organization | [
"binary search",
"combinatorics"
] | null | null | Once *n* people simultaneously signed in to the reception at the recently opened, but already thoroughly bureaucratic organization (abbreviated TBO). As the organization is thoroughly bureaucratic, it can accept and cater for exactly one person per day. As a consequence, each of *n* people made an appointment on one of... | The first line contains a single integer *t* (1<=≤<=*t*<=≤<=1000) — the number of test cases. Each of the following *t* lines contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the number of people who have got an appointment at TBO and the number of empty lines in the request form, correspondingly. | Print *t* lines, each containing an answer for the corresponding test case (in the order they are given in the input) — the minimum number of requests to submit to TBO. | [
"5\n4 1\n4 2\n7 3\n1 1\n42 7\n"
] | [
"3\n2\n3\n0\n11\n"
] | In the first sample, you need to submit three requests to TBO with three different names. When you learn the appointment dates of three people out of four, you can find out the fourth person's date by elimination, so you do not need a fourth request.
In the second sample you need only two requests. Let's number the pe... | [
{
"input": "5\n4 1\n4 2\n7 3\n1 1\n42 7",
"output": "3\n2\n3\n0\n11"
},
{
"input": "12\n11 4\n9 2\n10000 100\n1000000000 2345\n123456 1234567\n123456 65536\n5 55\n5 3\n2323 10\n999111000 232323\n999888777 777888999\n999888777 777",
"output": "4\n6\n198\n852515\n17\n17\n3\n3\n423\n12562\n30\n2570... | 92 | 0 | 0 | 83,851 | |
687 | Dividing Kingdom II | [
"brute force",
"data structures",
"dsu",
"graphs",
"sortings"
] | null | null | Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves.
The great kingdom consisted of *n* cities numbered from 1 to *n* and *m* bidirectional roads bet... | The first line of the input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*q*<=≤<=1000, ) — the number of cities and roads in the great kingdom, and the number of guesses, respectively.
The *i*-th line of the following *m* lines contains three integers *u**i*,<=*v**i* and *w**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<... | For each guess print the minimum possible hardness of the division in described scenario. | [
"5 6 5\n5 4 86\n5 1 0\n1 3 38\n2 1 33\n2 4 28\n2 3 40\n3 5\n2 6\n1 3\n2 3\n1 6\n"
] | [
"-1\n33\n-1\n-1\n33\n"
] | none | [] | 46 | 0 | 0 | 83,968 | |
494 | Helping People | [
"dp",
"probabilities"
] | null | null | Malek is a rich man. He also is very generous. That's why he decided to split his money between poor people. A charity institute knows *n* poor people numbered from 1 to *n*. The institute gave Malek *q* recommendations. A recommendation is a segment of people like [*l*,<=*r*] which means the institute recommended that... | In the first line two space-separated integers *n*,<=*q* (1<=≤<=*n*<=≤<=105, 1<=≤<=*q*<=≤<=5000) are given.
In the second line *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) are given meaning that person number *i* initially has *a**i* dollars.
Each of the next *q* lines contains thre... | Output the sought value. Your answer will be considered correct if its absolute or relative error is less than 10<=-<=6. | [
"5 2\n1 7 2 4 3\n1 3 0.500\n2 2 0.500\n",
"5 2\n281 280 279 278 282\n1 4 1.000\n1 4 0.000\n",
"3 5\n1 2 3\n1 3 0.500\n2 2 0.250\n1 2 0.800\n1 1 0.120\n2 2 0.900\n"
] | [
"8.000000000\n",
"282.000000000\n",
"4.465000000\n"
] | none | [] | 2,000 | 5,836,800 | 0 | 84,023 | |
794 | Labelling Cities | [
"dfs and similar",
"graphs",
"hashing"
] | null | null | Oleg the bank client lives in Bankopolia. There are *n* cities in Bankopolia and some pair of cities are connected directly by bi-directional roads. The cities are numbered from 1 to *n*. There are a total of *m* roads in Bankopolia, the *i*-th road connects cities *u**i* and *v**i*. It is guaranteed that from each cit... | The first line of input contains two space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*m*<=≤<=3·105) — the number of cities and the number of roads.
Next, *m* lines follow. The *i*-th line contains two space-separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the c... | If the required labeling is not possible, output a single line containing the string "NO" (without quotes).
Otherwise, output the string "YES" (without quotes) on the first line. On the next line, output *n* space-separated integers, *x*1,<=*x*2,<=...,<=*x**n*. The condition 1<=≤<=*x**i*<=≤<=109 must hold for all *i*,... | [
"4 4\n1 2\n1 3\n1 4\n3 4\n",
"5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n5 4\n",
"4 3\n1 2\n1 3\n1 4\n"
] | [
"YES\n2 3 1 1 \n",
"YES\n1 1 1 1 1 \n",
"NO\n"
] | For the first sample, *x*<sub class="lower-index">1</sub> = 2, *x*<sub class="lower-index">2</sub> = 3, *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">4</sub> = 1 is a valid labeling. Indeed, (3, 4), (1, 2), (1, 3), (1, 4) are the only pairs of cities with difference of labels not greater than 1, and... | [
{
"input": "4 4\n1 2\n1 3\n1 4\n3 4",
"output": "YES\n2 3 1 1 "
},
{
"input": "5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n5 4",
"output": "YES\n1 1 1 1 1 "
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "NO"
},
{
"input": "8 12\n1 2\n1 3\n1 4\n2 3\n2 4\n4 5\n5 6\n5 7\n... | 62 | 0 | 0 | 84,082 | |
533 | Work Group | [
"dfs and similar",
"dp",
"graphs",
"strings",
"trees"
] | null | null | One Big Software Company has *n* employees numbered from 1 to *n*. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.
We will call person *a* a subordinates of another person *b*, if either *b* is an... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of workers of the Big Software Company.
Then *n* lines follow, describing the company employees. The *i*-th line contains two integers *p**i*,<=*a**i* (1<=≤<=*a**i*<=≤<=105) — the number of the person who is the *i*-th employee's immediate superio... | Print a single integer — the maximum possible efficiency of the workgroup. | [
"7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2\n"
] | [
"17\n"
] | In the sample test the most effective way is to make a workgroup from employees number 1, 2, 4, 5, 6. | [
{
"input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2",
"output": "17"
},
{
"input": "1\n-1 42",
"output": "42"
},
{
"input": "2\n-1 3\n1 2",
"output": "3"
},
{
"input": "3\n-1 3\n1 1\n1 2",
"output": "6"
},
{
"input": "3\n-1 1\n1 2\n1 3",
"output": "6"
},
{
... | 0 | 0 | -1 | 84,177 | |
333 | Lucky Tickets | [
"brute force",
"constructive algorithms"
] | null | null | Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by the arithmetic expression was number 100. But he quickly analyzed all such ... | The single line contains two integers *k* and *m* (0<=≤<=*k*<=≤<=104, 1<=≤<=*m*<=≤<=3·105). | Print *m* lines. Each line must contain exactly 8 digits — the *k*-winning ticket. The tickets may begin with 0, all tickets must be distinct. If there are more than *m* distinct *k*-lucky tickets, print any *m* of them. It is guaranteed that at least *m* distinct *k*-lucky tickets exist. The tickets can be printed in ... | [
"0 3\n",
"7 4\n"
] | [
"00000000\n00000001\n00000002\n",
"00000007\n00000016\n00000017\n00000018\n"
] | none | [
{
"input": "0 3",
"output": "00000000\n00000001\n00000002"
},
{
"input": "7 4",
"output": "00000007\n00000016\n00000017\n00000018"
},
{
"input": "0 10000",
"output": "00000000\n00000001\n00000002\n00000003\n00000004\n00000005\n00000006\n00000007\n00000008\n00000009\n00000010\n0000001... | 4,000 | 204,800 | 0 | 84,208 | |
82 | Two out of Three | [
"dp"
] | D. Two out of Three | 2 | 256 | Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem.
Let the queue to the cashier contain *n* people, at that each of them is characterized by a positive integer *a**i* — that is the time needed to work with this customer. What is special abou... | The first line of the input file contains a single number *n* (1<=≤<=*n*<=≤<=1000), which is the number of people in the sequence. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106). The people are numbered starting from the cashier to the end of the queue. | Print on the first line a single number — the minimum time needed to process all *n* people. Then on ⌈*n*<=/<=2⌉ lines print the order in which customers will be served. Each line (probably, except for the last one) must contain two numbers separated by a space — the numbers of customers who will be served at the curre... | [
"4\n1 2 3 4\n",
"5\n2 4 3 1 4\n"
] | [
"6\n1 2\n3 4\n",
"8\n1 3\n2 5\n4\n"
] | none | [
{
"input": "4\n1 2 3 4",
"output": "6\n1 2\n3 4"
},
{
"input": "5\n2 4 3 1 4",
"output": "8\n1 3\n2 5\n4"
},
{
"input": "1\n10",
"output": "10\n1"
},
{
"input": "2\n3 5",
"output": "5\n1 2"
},
{
"input": "3\n1 10 1",
"output": "11\n1 2\n3"
},
{
"input"... | 92 | 0 | 0 | 84,217 |
85 | Sum of Medians | [
"binary search",
"brute force",
"data structures",
"implementation"
] | D. Sum of Medians | 3 | 256 | In one well-known algorithm of finding the *k*-th order statistics we should divide all elements into groups of five consecutive elements and find the median of each five. A median is called the middle element of a sorted array (it's the third largest element for a group of five). To increase the algorithm's performanc... | The first line contains number *n* (1<=≤<=*n*<=≤<=105), the number of operations performed.
Then each of *n* lines contains the description of one of the three operations:
- add *x* — add the element *x* to the set; - del *x* — delete the element *x* from the set; - sum — find the sum of medians of the set.
For ... | For each operation sum print on the single line the sum of medians of the current set. If the set is empty, print 0.
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams (also you may use the %I64d specificator). | [
"6\nadd 4\nadd 5\nadd 1\nadd 2\nadd 3\nsum\n",
"14\nadd 1\nadd 7\nadd 2\nadd 5\nsum\nadd 6\nadd 8\nadd 9\nadd 3\nadd 4\nadd 10\nsum\ndel 1\nsum\n"
] | [
"3\n",
"5\n11\n13\n"
] | none | [
{
"input": "6\nadd 4\nadd 5\nadd 1\nadd 2\nadd 3\nsum",
"output": "3"
},
{
"input": "14\nadd 1\nadd 7\nadd 2\nadd 5\nsum\nadd 6\nadd 8\nadd 9\nadd 3\nadd 4\nadd 10\nsum\ndel 1\nsum",
"output": "5\n11\n13"
},
{
"input": "11\nadd 1\nsum\nadd 2\nsum\nadd 3\nsum\nadd 4\nsum\nadd 5\nsum\nadd ... | 3,000 | 28,569,600 | 0 | 84,333 |
798 | Mike and code of a permutation | [
"constructive algorithms",
"data structures",
"graphs",
"sortings"
] | null | null | Mike has discovered a new way to encode permutations. If he has a permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], he will encode it in the following way:
Denote by *A*<==<=[*a*1,<=*a*2,<=...,<=*a**n*] a sequence of length *n* which will represent the code of the permutation. For each *i* from 1 to *n* sequentially, ... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=500<=000) — length of permutation.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n* or *a**i*<==<=<=-<=1) — the code of Mike's permutation.
You may assume that all positive values from *A* are different. | In first and only line print *n* numbers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — a permutation *P* which has the same code as the given one. Note that numbers in permutation are distinct. | [
"6\n2 -1 1 5 -1 4\n",
"8\n2 -1 4 -1 6 -1 8 -1\n"
] | [
"2 6 1 4 5 3\n",
"1 8 2 7 3 6 4 5\n"
] | For the permutation from the first example:
*i* = 1, the smallest *j* is 2 because *p*<sub class="lower-index">2</sub> = 6 > *p*<sub class="lower-index">1</sub> = 2.
*i* = 2, there is no *j* because *p*<sub class="lower-index">2</sub> = 6 is the greatest element in the permutation.
*i* = 3, the smallest *j* is 1 ... | [] | 0 | 0 | -1 | 84,709 | |
164 | Polycarpus and Tasks | [] | null | null | Polycarpus has many tasks. Each task is characterized by three integers *l**i*, *r**i* and *t**i*. Three integers (*l**i*,<=*r**i*,<=*t**i*) mean that to perform task *i*, one needs to choose an integer *s**i* (*l**i*<=≤<=*s**i*; *s**i*<=+<=*t**i*<=-<=1<=≤<=*r**i*), then the task will be carried out continuously for *t... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of tasks in set *A*.
Then *n* lines describe the tasks. The *i*-th line contains three space-separated integers *l**i*, *r**i*, *t**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109, 1<=≤<=*t**i*<=≤<=*r**i*<=-<=*l**i*<=+<=1) — the descriptio... | For each task *i* print a single integer — the result of processing task *i* on the *i*-th iteration of the cycle (step 3) in function *f*(*A*). In the *i*-th line print:
- 0 — if you managed to add task *i* on step 4. - -1 — if you didn't manage to add or replace task *i* (step 7). - *res**i* (1<=≤<=*res**i*<=≤<=*... | [
"5\n1 8 5\n2 9 3\n3 10 3\n8 11 4\n11 12 2\n",
"13\n1 8 5\n2 9 4\n3 10 1\n4 11 3\n8 12 5\n9 13 5\n10 14 5\n11 15 1\n12 16 1\n13 17 1\n14 18 3\n15 19 3\n16 20 2\n"
] | [
"0 0 1 0 -1 ",
"0 0 0 2 -1 -1 0 0 0 0 7 0 12 "
] | none | [] | 60 | 0 | 0 | 84,765 | |
720 | Cipher | [
"implementation"
] | null | null | Borya has recently found a big electronic display. The computer that manages the display stores some integer number. The number has *n* decimal digits, the display shows the encoded version of the number, where each digit is shown using some lowercase letter of the English alphabet.
There is a legend near the display,... | Input data contains multiple test cases. The first line of input contains *t* (1<=≤<=*t*<=≤<=100) — the number of test cases.
Each test case is described as follows. The first line of the description contains *n* (1<=≤<=*n*<=≤<=18) — the number of digits in the number. The second line contains *n* decimal digits with... | For each test case print an integer: the number of seconds until Borya definitely knows what was the initial number stored on the display of the computer. Do not print leading zeroes. | [
"3\n2\n42\nabcdefghij\njihgfedcba\n2\n42\naaaaaaaaaa\naaaaaaaaaa\n1\n2\nabcdabcdff\n"
] | [
"0\n58\n2\n"
] | none | [] | 15 | 0 | 0 | 84,796 | |
612 | Simba on the Circle | [
"dp"
] | null | null | You are given a circular array with *n* elements. The elements are numbered from some element with values from 1 to *n* in clockwise order. The *i*-th cell contains the value *a**i*. The robot Simba is in cell *s*.
Each moment of time the robot is in some of the *n* cells (at the begin he is in *s*). In one turn the r... | The first line contains two integers *n* and *s* (1<=≤<=*s*<=≤<=*n*<=≤<=2000) — the number of cells in the circular array and the starting position of Simba.
The second line contains *n* integers *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the number written in the *i*-th cell. The numbers are given for cells in order from... | In the first line print the number *t* — the least number of time units.
Each of the next *n* lines should contain the direction of robot movement and the number of cells to move in that direction. After that movement the robot writes out the number from the cell in which it turns out. The direction and the number of ... | [
"9 1\n0 1 2 2 2 1 0 1 1\n",
"8 1\n0 1 0 1 0 1 0 1\n",
"8 1\n1 2 3 4 5 6 7 8\n",
"8 1\n0 0 0 0 0 0 0 0\n"
] | [
"12\n+0\n-3\n-1\n+2\n+1\n+2\n+1\n+1\n+1\n",
"13\n+0\n+2\n+2\n+2\n-1\n+2\n+2\n+2\n",
"7\n+0\n+1\n+1\n+1\n+1\n+1\n+1\n+1\n",
"7\n+0\n+1\n+1\n+1\n+1\n+1\n+1\n+1\n"
] | none | [
{
"input": "9 1\n0 1 2 2 2 1 0 1 1",
"output": "12\n+0\n-3\n-1\n+2\n+1\n+2\n+1\n+1\n+1"
},
{
"input": "8 1\n0 1 0 1 0 1 0 1",
"output": "13\n+0\n+2\n+2\n+2\n-1\n+2\n+2\n+2"
},
{
"input": "8 1\n1 2 3 4 5 6 7 8",
"output": "7\n+0\n+1\n+1\n+1\n+1\n+1\n+1\n+1"
},
{
"input": "8 1\... | 62 | 614,400 | 0 | 84,964 | |
991 | Concise and clear | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a number less than 1000000000. However, sometimes it's hard to understand the ... | The only line contains a single integer $n$ ($1 \leq n \leq 10\,000\,000\,000$). | Output a concise notation of the number $n$. If there are several concise notations, output any of them. | [
"2018\n",
"1000000007\n",
"10000000000\n",
"2000000000\n"
] | [
"2018\n",
"10^9+7\n",
"100^5\n",
"2*10^9\n"
] | The third sample allows the answer 10^10 also of the length $5$. | [] | 30 | 0 | 0 | 85,024 | |
309 | Context Advertising | [
"dp",
"two pointers"
] | null | null | Advertising has become part of our routine. And now, in the era of progressive technologies, we need your ideas to make advertising better!
In this problem we'll look at a simplified version of context advertising. You've got a text, consisting of exactly *n* words. A standard advertising banner has exactly *r* lines,... | The first input line contains three integers *n*, *r*, *c* (1<=≤<=*n*,<=*r*,<=*c*<=≤<=106; *r*<=×<=*c*<=≤<=106). The next line contains a text, consisting of *n* words. The words consist only of lowercase English letters and are not empty. The words in the lines are separated by single spaces. The total number of chara... | Print at most *r* lines, in each line print at most *c* characters — the optimal advertisement banner. If there are multiple advertisement banners, print any of them.
Note that some lines of the banner can be empty. You are allowed not to print such lines. | [
"9 4 12\nthis is a sample text for croc final round\n",
"9 1 9\nthis is a sample text for croc final round\n",
"6 2 3\ncroc a a a croc a\n",
"2 2 5\nfirst second\n"
] | [
"this is a\nsample text\nfor croc\nfinal round\n",
"this is a\n",
"a a\na\n",
"first\n"
] | none | [] | 30 | 0 | 0 | 85,737 | |
566 | Replicating Processes | [
"constructive algorithms",
"greedy"
] | null | null | A Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more frequently, resulting in great load increase on the infrastructure.
As part of this task, we assume that the social network is... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=30<=000) — the number of servers of the social network.
Next 4*n* lines contain the rules of replicating processes, the *i*-th (1<=≤<=*i*<=≤<=4*n*) of these lines as form *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=*n*) and describes rule... | If the required order of performing rules does not exist, print "NO" (without the quotes).
Otherwise, print in the first line "YES" (without the quotes), and in the second line — a sequence of 4*n* numbers from 1 to 4*n*, giving the numbers of the rules in the order they are applied. The sequence should be a permutati... | [
"2\n1 2 2\n1 2 2\n1 2 2\n1 2 2\n2 1 1\n2 1 1\n2 1 1\n2 1 1\n",
"3\n1 2 3\n1 1 1\n1 1 1\n1 1 1\n2 1 3\n2 2 2\n2 2 2\n2 2 2\n3 1 2\n3 3 3\n3 3 3\n3 3 3\n"
] | [
"YES\n1 2 5 6 3 7 4 8\n",
"YES\n2 3 4 6 7 8 10 11 12 1 5 9\n"
] | <sup class="upper-index">(1)</sup> To be extremely accurate, we should note that the amount of server memory is 1 GiB = 1024 MiB and processes require 100 MiB RAM where a gibibyte (GiB) is the amount of RAM of 2<sup class="upper-index">30</sup> bytes and a mebibyte (MiB) is the amount of RAM of 2<sup class="upper-index... | [
{
"input": "2\n1 2 2\n1 2 2\n1 2 2\n1 2 2\n2 1 1\n2 1 1\n2 1 1\n2 1 1",
"output": "YES\n1 2 5 3 6 7 4 8"
},
{
"input": "3\n1 2 3\n1 1 1\n1 1 1\n1 1 1\n2 1 3\n2 2 2\n2 2 2\n2 2 2\n3 1 2\n3 3 3\n3 3 3\n3 3 3",
"output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12"
},
{
"input": "3\n1 2 3\n2 3 1\n3 1 ... | 124 | 409,600 | 0 | 85,777 | |
394 | Dominoes | [
"constructive algorithms",
"greedy"
] | null | null | During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put *nm* dominoes on the table as an *n*<=×<=2*m* rectangle so that each of the *n* rows contained *m* dominoes arranged horizontall... | The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=103).
In the next lines there is a description of the teachers' matrix. Each of next *n* lines contains *m* dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino. | Print the resulting matrix of dominoes in the format: *n* lines, each of them contains *m* space-separated dominoes.
If there are multiple optimal solutions, print any of them. | [
"2 3\n01 11 00\n00 01 11\n",
"4 1\n11\n10\n01\n00\n"
] | [
"11 11 10\n00 00 01\n",
"11\n10\n01\n00\n"
] | Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees. | [
{
"input": "2 3\n01 11 00\n00 01 11",
"output": "11 11 10\n00 00 01"
},
{
"input": "4 1\n11\n10\n01\n00",
"output": "11\n10\n01\n00"
},
{
"input": "1 1\n00",
"output": "00"
},
{
"input": "1 1\n01",
"output": "10"
},
{
"input": "1 1\n11",
"output": "11"
},
... | 46 | 0 | 0 | 85,836 | |
771 | Bear and Isomorphic Points | [
"geometry",
"two pointers"
] | null | null | Bearland is a big square on the plane. It contains all points with coordinates not exceeding 106 by the absolute value.
There are *n* houses in Bearland. The *i*-th of them is located at the point (*x**i*,<=*y**i*). The *n* points are distinct, but some subsets of them may be collinear.
Bear Limak lives in the first ... | The first line of the input contains an integer *T* (1<=≤<=*T*<=≤<=500) — the number of test cases. The description of the test cases follows.
The first line of the description of a test case contains an integer *n* (3<=≤<=*n*<=≤<=200<=000) — the number of houses.
The *i*-th of the next *n* lines contains two integer... | Print one real value, denoting the area of the set of points that are possible new placements of Limak's house.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. More precisely, let the jury's answer be *b*, and your answer be *a*. Then your answer will be accepted if an... | [
"4\n4\n5 3\n0 1\n10 1\n3 51\n3\n-999123 700000\n-950000 123456\n-950000 987654\n3\n2 3\n10 -1\n-4 6\n5\n1 3\n5 2\n6 1\n4 4\n-3 3\n"
] | [
"250.000000000000\n100000000000.000000000000\n0.000000000000\n6.562500000000\n"
] | In the sample test, there are 4 test cases.
In the first test case, there are four houses and Limak's one is in (5, 3). The set of valid new placements form a triangle with vertices in points (0, 1), (10, 1) and (3, 51), without its sides. The area of such a triangle is 250.
In the second test case, the set of valid ... | [] | 46 | 0 | 0 | 86,011 | |
62 | Wormhouse | [
"dfs and similar",
"graphs"
] | D. Wormhouse | 2 | 256 | Arnie the Worm has finished eating an apple house yet again and decided to move. He made up his mind on the plan, the way the rooms are located and how they are joined by corridors. He numbered all the rooms from 1 to *n*. All the corridors are bidirectional.
Arnie wants the new house to look just like the previous on... | The first line contains two integers *n* and *m* (3<=≤<=*n*<=≤<=100,<=3<=≤<=*m*<=≤<=2000). It is the number of rooms and corridors in Arnie's house correspondingly. The next line contains *m*<=+<=1 positive integers that do not exceed *n*. They are the description of Arnie's old path represented as a list of rooms he v... | Print *m*<=+<=1 positive integers that do not exceed *n*. Those numbers are the description of the new path, according to which Arnie should gnaw out his new house. If it is impossible to find new path you should print out No solution. The first number in your answer should be equal to the last one. Also it should be e... | [
"3 3\n1 2 3 1\n",
"3 3\n1 3 2 1\n"
] | [
"1 3 2 1 ",
"No solution"
] | none | [
{
"input": "3 3\n1 2 3 1",
"output": "1 3 2 1 "
},
{
"input": "3 3\n1 3 2 1",
"output": "No solution"
},
{
"input": "4 4\n1 2 4 3 1",
"output": "1 3 4 2 1 "
},
{
"input": "6 7\n3 2 4 1 6 5 1 3",
"output": "No solution"
},
{
"input": "8 12\n4 6 5 1 4 3 1 8 3 7 8 5 ... | 280 | 2,662,400 | 0 | 86,183 |
254 | Dormitory | [
"dp",
"implementation"
] | null | null | Student Vasya came to study in Berland State University from the country, so he is living in a dormitory. A semester has *n* days, and in each of those days his parents send him some food. In the morning of the *i*-th day he receives *a**i* kilograms of food that can be eaten on that day and on the next one (then the f... | The first line contains two integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=400). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=400), separated by single spaces. Value *a**i* means that in the morning of the *i*-th day *a**i* kilograms of food come, the food is good for eating on day *i* ... | In the first line print the highest rating Vasya can reach. In the next *n* lines print, which friends Vasya needs to feed on each day. In the *i*-th of these lines first print the number of friends to feed on the *i*-th day, and then list the indexes of these friends. Print the friends in these lists in any order. If ... | [
"4 1\n3 2 5 4\n3\n1 3 2\n1 4 1\n3 4 2\n"
] | [
"7\n1 2\n1 2\n3 2 1 3\n2 2 3\n"
] | none | [] | 124 | 1,843,200 | 0 | 86,391 | |
802 | Fake News (medium) | [
"constructive algorithms",
"strings"
] | null | null | Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she... | The first and only line of input contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000<=000). | The output should contain two nonempty strings *s* and *p* separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of *p* in *s* as a subsequence should be exactly *n*. If there are many possibl... | [
"2\n",
"4\n",
"6\n"
] | [
"hHheidi Hei",
"bbbba ba",
"aaabb ab"
] | An occurrence of *p* as a subsequence in *s* should be thought of as a set of positions in *s* such that the letters at these positions, in order, form *p*. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {... | [
{
"input": "2",
"output": "aa a"
},
{
"input": "4",
"output": "bbbba ba"
},
{
"input": "6",
"output": "bbabba ba"
},
{
"input": "1",
"output": "a a"
},
{
"input": "3",
"output": "bbba ba"
},
{
"input": "5",
"output": "bbaba ba"
},
{
"input"... | 374 | 0 | 0 | 86,432 | |
853 | Boredom | [
"data structures"
] | null | null | Ilya is sitting in a waiting area of Metropolis airport and is bored of looking at time table that shows again and again that his plane is delayed. So he took out a sheet of paper and decided to solve some problems.
First Ilya has drawn a grid of size *n*<=×<=*n* and marked *n* squares on it, such that no two marked s... | The first line of input contains two integers *n* and *q* (2<=≤<=*n*<=≤<=200<=000, 1<=≤<=*q*<=≤<=200<=000) — the size of the grid and the number of query rectangles.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n*, separated by spaces (1<=≤<=*p**i*<=≤<=*n*, all *p**i* are different), they specify grid... | For each query rectangle output its beauty degree on a separate line. | [
"2 3\n1 2\n1 1 1 1\n1 1 1 2\n1 1 2 2\n",
"4 2\n1 3 2 4\n4 1 4 4\n1 1 2 3\n"
] | [
"1\n1\n1\n",
"3\n5\n"
] | The first sample test has one beautiful rectangle that occupies the whole grid, therefore the answer to any query is 1.
In the second sample test the first query rectangle intersects 3 beautiful rectangles, as shown on the picture below:
<img class="tex-graphics" src="https://espresso.codeforces.com/ab1c66ff4bb212f2e... | [] | 62 | 0 | 0 | 86,530 | |
618 | Robot Arm | [
"data structures",
"geometry"
] | null | null | Roger is a robot. He has an arm that is a series of *n* segments connected to each other. The endpoints of the *i*-th segment are initially located at points (*i*<=-<=1,<=0) and (*i*,<=0). The endpoint at (*i*<=-<=1,<=0) is colored red and the endpoint at (*i*,<=0) is colored blue for all segments. Thus, the blue endpo... | The first line of the input will contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300<=000) — the number of segments and the number of operations to perform.
Each of the next *m* lines contains three integers *x**i*, *y**i* and *z**i* describing a move. If *x**i*<==<=1, this line describes a move of type 1, where... | Print *m* lines. The *i*-th line should contain two real values, denoting the coordinates of the blue endpoint of the last segment after applying operations 1,<=...,<=*i*. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
Namely, let's assume that your answer for a part... | [
"5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1\n"
] | [
"8.0000000000 0.0000000000\n5.0000000000 -3.0000000000\n4.2568551745 -2.6691306064\n4.2568551745 -3.6691306064\n"
] | The following pictures shows the state of the arm after each operation. The coordinates of point *F* are printed after applying each operation. For simplicity, we only show the blue endpoints of a segment (with the exception for the red endpoint of the first segment). For instance, the point labeled *B* is the blue end... | [
{
"input": "5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1",
"output": "8.0000000000 0.0000000000\n5.0000000000 -3.0000000000\n4.2568551745 -2.6691306064\n4.2568551745 -3.6691306064"
},
{
"input": "1 1\n2 1 302",
"output": "0.5299192642 0.8480480962"
},
{
"input": "50 50\n1 41 261\n2 47 324\n1 41 256... | 8,000 | 48,025,600 | 0 | 86,695 | |
354 | Lucky Number Representation | [
"constructive algorithms",
"dfs and similar",
"dp"
] | null | null | We know that lucky digits are digits 4 and 7, however Vasya's got another favorite digit 0 and he assumes it also is lucky! Lucky numbers are such non-negative integers whose decimal record only contains lucky digits. For example, numbers 0,<=47,<=7074 are lucky, but 1,<=7377,<=895,<= -7 are not.
Vasya has *t* importa... | The first line contains a single integer *t* (1<=≤<=*t*<=≤<=5000).
Next *t* lines contain a single positive integer *n**i* (1<=≤<=*n**i*<=≤<=1018) — the list of important numbers.
Please, do not use the %lld to read or write 64-bit integers С++. It is preferred to read the cin, cout streams or the %I64d specifier. | Print *t* lines. The *i*-th line must contain the answer for the *i*-th important number: if the solution exists, the line must contain exactly six lucky numbers the sum of which equals *n**i*, if the solution doesn't exist the string must contain a single integer -1.
If there are multiple answers print any of them. | [
"5\n42\n17\n444\n7\n51\n"
] | [
"7 7 7 7 7 7\n-1\n400 0 40 0 4 0\n7 0 0 0 0 0\n47 4 0 0 0 0\n"
] | none | [] | 30 | 0 | 0 | 86,851 | |
93 | End of Exams | [
"greedy"
] | B. End of Exams | 1 | 256 | Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams!
Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe... | The only input data file contains three integers *n*, *w* and *m* (1<=≤<=*n*<=≤<=50, 100<=≤<=*w*<=≤<=1000, 2<=≤<=*m*<=≤<=50), where *n* stands for the number of ordered bottles, *w* stands for the volume of each of them and *m* stands for the number of friends in the company. | Print on the first line "YES" if it is possible to pour the milk so that the milk from each bottle was in no more than two different cups. If there's no solution, print "NO".
If there is a solution, then print *m* more lines, where the *i*-th of them describes the content of the *i*-th student's cup. The line should c... | [
"2 500 3\n",
"4 100 5\n",
"4 100 7\n",
"5 500 2\n"
] | [
"YES\n1 333.333333\n2 333.333333\n2 166.666667 1 166.666667\n",
"YES\n3 20.000000 4 60.000000\n1 80.000000\n4 40.000000 2 40.000000\n3 80.000000\n2 60.000000 1 20.000000\n",
"NO\n",
"YES\n4 250.000000 5 500.000000 2 500.000000\n3 500.000000 1 500.000000 4 250.000000\n"
] | none | [
{
"input": "2 500 3",
"output": "YES\n1 333.333333\n2 333.333333\n2 166.666667 1 166.666667"
},
{
"input": "4 100 5",
"output": "YES\n3 20.000000 4 60.000000\n1 80.000000\n4 40.000000 2 40.000000\n3 80.000000\n2 60.000000 1 20.000000"
},
{
"input": "4 100 7",
"output": "NO"
},
{
... | 46 | 102,400 | 3.976809 | 87,018 |
173 | Camping Groups | [
"data structures",
"sortings"
] | null | null | A club wants to take its members camping. In order to organize the event better the club directors decided to partition the members into several groups.
Club member *i* has a responsibility value *r**i* and an age value *a**i*. A group is a non-empty subset of club members with one member known as group leader. A gro... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=109) — the number of club members and the age restriction for one group.
The next line contains integer numbers *r*1,<=*r*2,<=...,<=*r**n* (1<=≤<=*r**i*<=≤<=109) separated by space: *r**i* denotes the *i*-th club member's responsibili... | For each question print the maximum size of the group in a line. If making such a group is impossible print -1 instead. | [
"5 1\n1 5 4 1 2\n4 4 3 2 2\n4\n5 3\n2 3\n2 5\n4 1\n"
] | [
"4\n3\n-1\n4\n"
] | In the first query the largest group with members 3 and 5 is {1, 3, 4, 5} where member 3 is the leader.
In the second query member 2 should be the leader so the group will be {1, 2, 3}.
In the third query the leader of the group should have age 3 so the only leader can be member 3, who is less responsible than member... | [] | 0 | 0 | -1 | 87,101 | |
671 | Ultimate Weirdness of an Array | [
"data structures",
"number theory"
] | null | null | Yasin has an array *a* containing *n* integers. Yasin is a 5 year old, so he loves ultimate weird things.
Yasin denotes weirdness of an array as maximum *gcd*(*a**i*,<=<=*a**j*) value among all 1<=≤<=*i*<=<<=*j*<=≤<=*n*. For *n*<=≤<=1 weirdness is equal to 0, *gcd*(*x*,<=<=*y*) is the greatest common divisor of int... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of elements in *a*.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=200<=000), where the *i*-th number is equal to the *i*-th element of the array *a*. It is guaranteed that all *a**i* are distinct. | Print a single line containing the value of ultimate weirdness of the array *a*. | [
"3\n2 6 3\n"
] | [
"6\n"
] | Consider the first sample.
- *f*(1, 1) is equal to 3. - *f*(2, 2) is equal to 1. - *f*(3, 3) is equal to 2. - *f*(1, 2), *f*(1, 3) and *f*(2, 3) are equal to 0. | [] | 46 | 0 | 0 | 87,302 | |
611 | New Year and Ancient Prophecy | [
"dp",
"hashing",
"strings"
] | null | null | Limak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know any ancient languages and thus is unable to understand the prophecy. But he knows digits!
One fragment of the prophecy is a sequence of *n* digits. The first digit isn't zero. Limak thinks that it's a list of some... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — the number of digits.
The second line contains a string of digits and has length equal to *n*. It's guaranteed that the first digit is not '0'. | Print the number of ways to correctly split the given sequence modulo 109<=+<=7. | [
"6\n123434\n",
"8\n20152016\n"
] | [
"8\n",
"4\n"
] | In the first sample there are 8 ways to split the sequence:
- "123434" = "123434" (maybe the given sequence is just one big number) - "123434" = "1" + "23434" - "123434" = "12" + "3434" - "123434" = "123" + "434" - "123434" = "1" + "23" + "434" - "123434" = "1" + "2" + "3434" - "123434" = "1" + "2" + "3" + "434... | [] | 2,500 | 2,252,800 | 0 | 87,330 | |
98 | Help Victoria the Wise | [
"brute force",
"implementation"
] | A. Help Victoria the Wise | 1 | 256 | Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.
The box's lock is constructed... | The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} — they are the colors of gems with which the box should be decorated. | Print the required number of different ways to decorate the box. | [
"YYYYYY\n",
"BOOOOB\n",
"ROYGBV\n"
] | [
"1\n",
"2\n",
"30\n"
] | none | [
{
"input": "YYYYYY",
"output": "1"
},
{
"input": "BOOOOB",
"output": "2"
},
{
"input": "ROYGBV",
"output": "30"
},
{
"input": "RRRRRR",
"output": "1"
},
{
"input": "BOOOOO",
"output": "1"
},
{
"input": "GOGGVG",
"output": "2"
},
{
"input": ... | 0 | 0 | -1 | 87,396 |
571 | Campus | [
"binary search",
"data structures",
"dsu",
"trees"
] | null | null | Oscolcovo city has a campus consisting of *n* student dormitories, *n* universities and *n* military offices. Initially, the *i*-th dormitory belongs to the *i*-th university and is assigned to the *i*-th military office.
Life goes on and the campus is continuously going through some changes. The changes can be of fou... | The first line contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5·105) — the number of dormitories and the number of queries, respectively.
Next *m* lines contain the queries, each of them is given in one of the following formats:
- «U *a**j* *b**j*» — merging universities; - «M *c**j* *d**j*» — merging mil... | In the *i*-th line print the answer to the *i*-th query asking the number of people in the dormitory. | [
"2 7\nA 1\nQ 1\nU 1 2\nA 1\nZ 1\nQ 1\nQ 2\n",
"5 12\nU 1 2\nM 4 5\nA 1\nQ 1\nA 3\nA 4\nQ 3\nQ 4\nZ 4\nQ 4\nA 5\nQ 5\n"
] | [
"1\n0\n2\n",
"2\n1\n1\n0\n1\n"
] | Consider the first sample test:
- In the first query university 1 owns only dormitory 1, so after the query dormitory 1 will have 1 student. - After the third query university 1 owns dormitories 1 and 2. - The fourth query increases by 2 the number of students living in dormitories 1 and 2 that belong to universit... | [] | 77 | 0 | 0 | 87,426 | |
786 | ALT | [
"data structures",
"flows",
"graphs",
"trees"
] | null | null | ALT is a planet in a galaxy called "Encore". Humans rule this planet but for some reason there's no dog in their planet, so the people there are sad and depressed. Rick and Morty are universal philanthropists and they want to make people in ALT happy.
ALT has *n* cities numbered from 1 to *n* and *n*<=-<=1 bidirectio... | The first line of input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2<=×<=104, 1<=≤<=*m*<=≤<=104) — number of cities and number of citizens respectively.
The next *n*<=-<=1 lines contain the roads, *i*-th line contains endpoint of *i*-th edge, *v* and *u* (1<=≤<=*v*,<=*u*<=≤<=*n*, *v*<=≠<=*u*).
The next *m* line... | In the first line of input print a single integer *k*, the total number of puppies they need (1<=≤<=*k*<=≤<=*n*).
In the second line print an integer *q*, the number of puppies to give to citizens, followed by *q* distinct integers *a*1,<=*a*2,<=...,<=*a**q*, index of citizens to give puppy to (0<=≤<=*q*<=≤<=*min*(*m*... | [
"4 5\n2 4\n3 4\n1 4\n2 4\n2 1\n2 4\n1 2\n2 3\n",
"4 7\n3 4\n1 4\n2 1\n4 2\n4 2\n2 4\n1 4\n2 1\n3 1\n4 2\n"
] | [
"3\n1 5 \n2 3 1 \n",
"3\n1 6 \n2 2 3 \n"
] | Map of ALT in the first sample testcase (numbers written on a road is its index):
Map of ALT in the second sample testcase (numbers written on a road is its index): | [] | 46 | 5,529,600 | 0 | 87,580 | |
983 | Arkady and Rectangles | [
"data structures"
] | null | null | Arkady has got an infinite plane painted in color $0$. Then he draws $n$ rectangles filled with paint with sides parallel to the Cartesian coordinate axes, one after another. The color of the $i$-th rectangle is $i$ (rectangles are enumerated from $1$ to $n$ in the order he draws them). It is possible that new rectangl... | The first line contains a single integer $n$ ($1 \le n \le 100\,000$) — the number of rectangles.
The $i$-th of the next $n$ lines contains $4$ integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) — the coordinates of corners of the $i$-th rectangle. | In the single line print the number of different colors in the plane, including color $0$. | [
"5\n-1 -1 1 1\n-4 0 0 4\n0 0 4 4\n-4 -4 0 0\n0 -4 4 0\n",
"4\n0 0 4 4\n-4 -4 0 0\n0 -4 4 0\n-2 -4 2 4\n"
] | [
"5",
"5"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/b84e29026ee49b5972ce2479ad7cb4e72b99e516.png" style="max-width: 100.0%;max-height: 100.0%;" width="454px"/> That's how the plane looks in the second sample
$0$ = white, $1$ = cyan, $2$ = blue, $3$ = purple, $4$ = yellow, $5$ = red. | [] | 0 | 0 | -1 | 87,585 | |
628 | Zbazi in Zeydabad | [
"data structures",
"implementation"
] | null | null | A tourist wants to visit country Zeydabad for Zbazi (a local game in Zeydabad).
The country Zeydabad is a rectangular table consisting of *n* rows and *m* columns. Each cell on the country is either 'z' or '.'.
The tourist knows this country is named Zeydabad because there are lots of ''Z-pattern"s in the country. A ... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the number of rows and columns respectively.
Each of the next *n* lines contains *m* characters 'z' or '.' — the description of Zeydabad. | Print the only integer *a* — the number of ''Z-pattern"s in Zeydabad. | [
"4 4\nzzzz\nzzz.\n.z..\nzzzz\n",
"1 4\nz.z.\n",
"2 2\nzz\nzz\n"
] | [
"16\n",
"2\n",
"5\n"
] | none | [
{
"input": "4 4\nzzzz\nzzz.\n.z..\nzzzz",
"output": "16"
},
{
"input": "1 4\nz.z.",
"output": "2"
},
{
"input": "2 2\nzz\nzz",
"output": "5"
}
] | 46 | 0 | 0 | 87,721 | |
149 | Martian Strings | [
"string suffix structures",
"strings"
] | null | null | During the study of the Martians Petya clearly understood that the Martians are absolutely lazy. They like to sleep and don't like to wake up.
Imagine a Martian who has exactly *n* eyes located in a row and numbered from the left to the right from 1 to *n*. When a Martian sleeps, he puts a patch on each eye (so that ... | The first line contains a non-empty string *s* consisting of uppercase Latin letters. The strings' length is *n* (2<=≤<=*n*<=≤<=105). The second line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of beautiful words. Next *m* lines contain the beautiful words *p**i*, consisting of uppercase Latin letters. The... | Print the single integer — the number of different beautiful strings the Martian can see this morning. | [
"ABCBABA\n2\nBAAB\nABBA\n"
] | [
"1\n"
] | Let's consider the sample test. There the Martian can get only the second beautiful string if he opens segments of eyes *a* = 1, *b* = 2 and *c* = 4, *d* = 5 or of he opens segments of eyes *a* = 1, *b* = 2 and *c* = 6, *d* = 7. | [
{
"input": "ABCBABA\n2\nBAAB\nABBA",
"output": "1"
},
{
"input": "AAAAAAAAAA\n4\nAA\nAAAA\nA\nAAAAAAA",
"output": "3"
},
{
"input": "AABABBAAAB\n4\nABBA\nBABAABBABA\nA\nAABBBAABABB",
"output": "1"
},
{
"input": "AABBB\n1\nBBABAB",
"output": "0"
},
{
"input": "BA\n... | 92 | 0 | 0 | 87,924 | |
859 | Third Month Insanity | [
"dp",
"probabilities",
"trees"
] | null | null | The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2*N* teams participating in the tournament, numbered from 1 to 2*N*. The tournament lasts *N* rounds, with each round eliminating half the teams. The first round consists of... | Input will begin with a line containing *N* (2<=≤<=*N*<=≤<=6).
2*N* lines follow, each with 2*N* integers. The *j*-th column of the *i*-th row indicates the percentage chance that team *i* will defeat team *j*, unless *i*<==<=*j*, in which case the value will be 0. It is guaranteed that the *i*-th column of the *j*-th... | Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10<=-<=9.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer will be considered correct, if . | [
"2\n0 40 100 100\n60 0 40 40\n0 60 0 45\n0 60 55 0\n",
"3\n0 0 100 0 100 0 0 0\n100 0 100 0 0 0 100 100\n0 0 0 100 100 0 0 0\n100 100 0 0 0 0 100 100\n0 100 0 100 0 0 100 0\n100 100 100 100 100 0 0 0\n100 0 100 0 0 100 0 0\n100 0 100 0 100 100 100 0\n",
"2\n0 21 41 26\n79 0 97 33\n59 3 0 91\n74 67 9 0\n"
] | [
"1.75\n",
"12\n",
"3.141592\n"
] | In the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1. | [
{
"input": "2\n0 40 100 100\n60 0 40 40\n0 60 0 45\n0 60 55 0",
"output": "1.75"
},
{
"input": "3\n0 0 100 0 100 0 0 0\n100 0 100 0 0 0 100 100\n0 0 0 100 100 0 0 0\n100 100 0 0 0 0 100 100\n0 100 0 100 0 0 100 0\n100 100 100 100 100 0 0 0\n100 0 100 0 0 100 0 0\n100 0 100 0 100 100 100 0",
"out... | 30 | 0 | 0 | 88,025 | |
0 | none | [
"none"
] | null | null | You have a rectangular *n*<=×<=*m*-cell board. Some cells are already painted some of *k* colors. You need to paint each uncolored cell one of the *k* colors so that any path from the upper left square to the lower right one doesn't contain any two cells of the same color. The path can go only along side-adjacent cells... | The first line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=10). The next *n* lines contain *m* integers each — the board. The first of them contains *m* uppermost cells of the board from the left to the right and the second one contains *m* cells from the second uppermost row and s... | Print the number of possible paintings modulo 1000000007 (109<=+<=7). | [
"2 2 4\n0 0\n0 0\n",
"2 2 4\n1 2\n2 1\n",
"5 6 10\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n",
"2 6 10\n1 2 3 4 5 6\n0 0 0 0 0 0\n"
] | [
"48\n",
"0\n",
"3628800\n",
"4096\n"
] | none | [] | 92 | 0 | 0 | 88,178 | |
798 | Mike and strings | [
"brute force",
"dp",
"strings"
] | null | null | Mike has *n* strings *s*1,<=*s*2,<=...,<=*s**n* each consisting of lowercase English letters. In one move he can choose a string *s**i*, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".
Now Mike a... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of strings.
This is followed by *n* lines which contain a string each. The *i*-th line corresponding to string *s**i*. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | Print the minimal number of moves Mike needs in order to make all the strings equal or print <=-<=1 if there is no solution. | [
"4\nxzzwo\nzwoxz\nzzwox\nxzzwo\n",
"2\nmolzv\nlzvmo\n",
"3\nkc\nkc\nkc\n",
"3\naa\naa\nab\n"
] | [
"5\n",
"2\n",
"0\n",
"-1\n"
] | In the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | [
{
"input": "4\nxzzwo\nzwoxz\nzzwox\nxzzwo",
"output": "5"
},
{
"input": "2\nmolzv\nlzvmo",
"output": "2"
},
{
"input": "3\nkc\nkc\nkc",
"output": "0"
},
{
"input": "3\naa\naa\nab",
"output": "-1"
},
{
"input": "3\nkwkb\nkbkw\nbkwk",
"output": "3"
},
{
... | 93 | 1,740,800 | 3 | 88,179 | |
412 | Giving Awards | [
"dfs and similar"
] | null | null | The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else.
Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ... | The first line contains space-separated integers *n* and *m* — the number of employees in R1 and the number of debt relations. Each of the following *m* lines contains two space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*), these integers indicate that the person number *a**i* o... | Print -1 if the described order does not exist. Otherwise, print the permutation of *n* distinct integers. The first number should denote the number of the person who goes to the CEO office first, the second number denote the person who goes second and so on.
If there are multiple correct orders, you are allowed to pr... | [
"2 1\n1 2\n",
"3 3\n1 2\n2 3\n3 1\n"
] | [
"2 1 \n",
"2 1 3 \n"
] | none | [
{
"input": "2 1\n1 2",
"output": "2 1 "
},
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "2 1 3 "
},
{
"input": "10 45\n10 5\n10 7\n6 1\n5 8\n3 5\n6 5\n1 2\n6 10\n2 9\n9 5\n4 1\n7 5\n1 8\n6 8\n10 9\n7 2\n7 9\n4 10\n7 3\n4 8\n10 3\n10 8\n2 10\n8 2\n4 2\n5 2\n9 1\n4 5\n1 3\n9 6\n3 8\n5 1\n6 4... | 374 | 11,673,600 | 3 | 88,196 | |
208 | Prizes, Prizes, more Prizes | [
"implementation"
] | null | null | Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=50) — the number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=109). The third line contains 5 integers *a*, *b*, *c*, *d*, *e* (1<=≤<=*a*<=<<=*b*<=<... | Print on the first line 5 integers, separated by a space — the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. On the second line print a single integer — the number of points Vasya will have left after all operations of exchange are completed.
Please, do not use the %lld specifier to... | [
"3\n3 10 4\n2 4 10 15 20\n",
"4\n10 4 39 2\n3 5 10 11 12\n"
] | [
"1 1 1 0 0 \n1\n",
"3 0 1 0 3 \n0\n"
] | In the first sample Vasya gets 3 points after eating the first chocolate bar. Then he exchanges 2 points and gets a mug. Vasya wins a bag after eating the second chocolate bar. Then he wins a towel after eating the third chocolate bar. After all chocolate bars 3 - 2 + 10 - 10 + 4 - 4 = 1 points remains. | [
{
"input": "3\n3 10 4\n2 4 10 15 20",
"output": "1 1 1 0 0 \n1"
},
{
"input": "4\n10 4 39 2\n3 5 10 11 12",
"output": "3 0 1 0 3 \n0"
},
{
"input": "1\n45\n1 2 3 4 5",
"output": "0 0 0 0 9 \n0"
},
{
"input": "1\n50\n1 2 4 5 6",
"output": "0 1 0 0 8 \n0"
},
{
"inpu... | 124 | 2,867,200 | -1 | 88,448 | |
250 | Mad Joe | [
"brute force"
] | null | null | Joe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path.
Joe's house has *n* floors, each floor is a segment of *m* cells. Each cell either contains nothing (it is an empty cell), or has a brick or a concrete wall (always something one of three). It is believed that ea... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=104).
Next *n* lines contain the description of Joe's house. The *i*-th of these lines contains the description of the (*n*<=-<=*i*<=+<=1)-th floor of the house — a line that consists of *m* characters: "." means an empty cell, "+" mean... | Print a single number — the number of seconds Joe needs to reach the first floor; or else, print word "Never" (without the quotes), if it can never happen.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3 5\n..+.#\n#+..+\n+.#+.\n",
"4 10\n...+.##+.+\n+#++..+++#\n++.#++++..\n.+##.++#.+\n",
"2 2\n..\n++\n"
] | [
"14",
"42\n",
"Never"
] | none | [
{
"input": "3 5\n..+.#\n#+..+\n+.#+.",
"output": "14"
},
{
"input": "4 10\n...+.##+.+\n+#++..+++#\n++.#++++..\n.+##.++#.+",
"output": "42"
},
{
"input": "2 2\n..\n++",
"output": "Never"
},
{
"input": "5 1\n.\n.\n.\n.\n.",
"output": "4"
},
{
"input": "20 20\n..+#+.... | 436 | 11,059,200 | 3 | 88,470 | |
220 | Little Elephant and Triangle | [
"geometry",
"math"
] | null | null | The Little Elephant is playing with the Cartesian coordinates' system. Most of all he likes playing with integer points. The Little Elephant defines an integer point as a pair of integers (*x*; *y*), such that 0<=≤<=*x*<=≤<=*w* and 0<=≤<=*y*<=≤<=*h*. Thus, the Little Elephant knows only (*w*<=+<=1)·(*h*<=+<=1) distinct... | A single line contains two integers *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=4000). | In a single output line print an integer — the remainder of dividing the answer to the problem by 1000000007 (109<=+<=7). | [
"2 1\n",
"2 2\n"
] | [
"36\n",
"240\n"
] | none | [] | 92 | 0 | 0 | 88,590 | |
167 | Wizards and Bets | [
"dfs and similar",
"graphs",
"math",
"matrices"
] | null | null | In some country live wizards. They like to make weird bets.
Two wizards draw an acyclic directed graph with *n* vertices and *m* edges (the graph's vertices are numbered from 1 to *n*). A source is a vertex with no incoming edges, and a sink is the vertex with no outgoing edges. Note that a vertex could be the sink an... | The first line contains three space-separated integers *n*, *m*, *p* (1<=≤<=*n*<=≤<=600, 0<=≤<=*m*<=≤<=105, 2<=≤<=*p*<=≤<=109<=+<=7). It is guaranteed that *p* is prime number.
Next *m* lines contain edges of the graph. Each line contains a pair of space-separated integers, *a**i* *b**i* — an edge from vertex *a**i* t... | Print the answer to the problem — the total winnings of the first player modulo a prime number *p*. Please note that the winnings may be negative, but the modulo residue must be non-negative (see the sample). | [
"4 2 1000003\n1 3\n2 4\n",
"4 2 1000003\n4 1\n3 2\n",
"4 4 1000003\n2 1\n2 4\n3 1\n3 4\n",
"6 5 1000003\n1 4\n1 5\n1 6\n2 6\n3 6\n",
"5 2 1000003\n5 1\n3 4\n"
] | [
"1\n",
"1000002\n",
"0\n",
"0\n",
"1\n"
] | In the first sample, there is exactly one set of paths — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4c100300071b70505c9eb8fd6f97456068e38f93.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The number of inversions is 0, which is an even number. Therefore, the first wizard gets 1 ... | [] | 124 | 0 | 0 | 88,829 | |
920 | List Of Integers | [
"binary search",
"bitmasks",
"brute force",
"combinatorics",
"math",
"number theory"
] | null | null | Let's denote as *L*(*x*,<=*p*) an infinite sequence of integers *y* such that *gcd*(*p*,<=*y*)<==<=1 and *y*<=><=*x* (where *gcd* is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of *L*(*x*,<=*p*) are 1-indexed; for example, 9, 13 and 15 are the first, the second and th... | The first line contains one integer *t* (1<=≤<=*t*<=≤<=30000) — the number of queries to process.
Then *t* lines follow. *i*-th line contains three integers *x*, *p* and *k* for *i*-th query (1<=≤<=*x*,<=*p*,<=*k*<=≤<=106). | Print *t* integers, where *i*-th integer is the answer to *i*-th query. | [
"3\n7 22 1\n7 22 2\n7 22 3\n",
"5\n42 42 42\n43 43 43\n44 44 44\n45 45 45\n46 46 46\n"
] | [
"9\n13\n15\n",
"187\n87\n139\n128\n141\n"
] | none | [
{
"input": "3\n7 22 1\n7 22 2\n7 22 3",
"output": "9\n13\n15"
},
{
"input": "5\n42 42 42\n43 43 43\n44 44 44\n45 45 45\n46 46 46",
"output": "187\n87\n139\n128\n141"
}
] | 0 | 0 | -1 | 89,419 | |
797 | Mice and Holes | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | One day Masha came home and noticed *n* mice in the corridor of her flat. Of course, she shouted loudly, so scared mice started to run to the holes in the corridor.
The corridor can be represeted as a numeric axis with *n* mice and *m* holes on it. *i*th mouse is at the coordinate *x**i*, and *j*th hole — at coordinat... | The first line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=5000) — the number of mice and the number of holes, respectively.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the coordinate of *i*th mouse.
Next *m* lines contain pairs of int... | Print one integer number — the minimum sum of distances. If there is no solution, print -1 instead. | [
"4 5\n6 2 8 9\n3 6\n2 1\n3 6\n4 7\n4 7\n",
"7 2\n10 20 30 40 50 45 35\n-1000000000 10\n1000000000 1\n"
] | [
"11\n",
"7000000130\n"
] | none | [
{
"input": "4 5\n6 2 8 9\n3 6\n2 1\n3 6\n4 7\n4 7",
"output": "11"
},
{
"input": "7 2\n10 20 30 40 50 45 35\n-1000000000 10\n1000000000 1",
"output": "7000000130"
},
{
"input": "1 1\n1\n1 1",
"output": "0"
},
{
"input": "1 1\n1\n1 5000",
"output": "0"
},
{
"input"... | 1,500 | 11,673,600 | 0 | 89,551 | |
382 | Ksenia and Combinatorics | [
"combinatorics",
"dp"
] | null | null | Ksenia has her winter exams. Today she is learning combinatorics. Here's one of the problems she needs to learn to solve.
How many distinct trees are there consisting of *n* vertices, each with the following properties:
- the tree is marked, that is, the vertices of the tree are numbered from 1 to *n*; - each verte... | The first line contains two integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=50). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"1 1\n",
"2 1\n",
"3 1\n",
"4 2\n"
] | [
"0\n",
"1\n",
"3\n",
"12\n"
] | If you aren't familiar with matchings, please, read the following link: http://en.wikipedia.org/wiki/Matching_(graph_theory). | [] | 265 | 4,300,800 | 0 | 89,629 | |
36 | Bowls | [
"geometry",
"implementation"
] | C. Bowls | 2 | 64 | Once Petya was in such a good mood that he decided to help his mum with the washing-up. There were *n* dirty bowls in the sink. From the geometrical point of view each bowl looks like a blunted cone. We can disregard the width of the walls and bottom. Petya puts the clean bowls one on another naturally, i. e. so that t... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=3000). Each of the following *n* lines contains 3 integers *h*, *r* and *R* (1<=≤<=*h*<=≤<=10000,<=1<=≤<=*r*<=<<=*R*<=≤<=10000). They are the height of a bowl, the radius of its bottom and the radius of its top. The plates are given in the order Petya puts the... | Output the height of the plate pile accurate to at least 10<=-<=6. | [
"2\n40 10 50\n60 20 30\n",
"3\n50 30 80\n35 25 70\n40 10 90\n"
] | [
"70.00000000\n",
"55.00000000\n"
] | none | [
{
"input": "2\n40 10 50\n60 20 30",
"output": "70.00000000"
},
{
"input": "3\n50 30 80\n35 25 70\n40 10 90",
"output": "55.00000000"
},
{
"input": "1\n5 3 10",
"output": "5.00000000"
},
{
"input": "3\n1 1 2\n2 2 3\n3 3 4",
"output": "6.00000000"
},
{
"input": "3\n... | 280 | 1,331,200 | 0 | 89,644 |
48 | Black and White | [
"constructive algorithms"
] | H. Black and White | 2 | 256 | According to the legends the king of Berland Berl I was noted for his love of beauty and order. One day he ordered to tile the palace hall's floor where balls and receptions used to take place with black and white tiles according to a regular geometrical pattern invented by him. However, as is after the case, due to lo... | The first line contains given integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) which represent the sizes of the rectangle that needs to be tiled. The next line contains non-negative numbers *a*, *b* and *c*, *a*<=+<=*b*<=+<=*c*<==<=*nm*, *c*<=≥<=*m*. | Print 2*n* lines containing 2*m* characters each — the tiling scheme. Every tile is represented by a square 2<=×<=2 in the following manner (the order corresponds to the order of the picture above): | [
"2 2\n0 0 4\n",
"2 3\n1 2 3\n"
] | [
"\\../\n#\\/#\n\\##/\n.\\/.\n",
"###/\\#\n##/..\\\n#/....\n/.....\n"
] | none | [] | 92 | 0 | 0 | 90,081 |
567 | Mausoleum | [
"dp"
] | null | null | King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital.
The mausoleum will be constructed from 2*n* blocks, each of them has the shape of a cuboid. Each block has ... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=35, 0<=≤<=*k*<=≤<=100) — the number of pairs of blocks and the number of additional requirements.
Next *k* lines contain listed additional requirements, one per line in the format "*x**i* sign*i* *y**i*" (1<=≤<=*x**i*,<=*y**i*<=≤<=2*n*), and the ... | Print the sought number of ways. | [
"3 0\n",
"3 1\n2 > 3\n",
"4 1\n3 = 6\n"
] | [
"9\n",
"1\n",
"3\n"
] | none | [
{
"input": "3 0",
"output": "9"
},
{
"input": "3 1\n2 > 3",
"output": "1"
},
{
"input": "4 1\n3 = 6",
"output": "3"
},
{
"input": "5 2\n1 < 2\n9 > 10",
"output": "27"
},
{
"input": "35 0",
"output": "16677181699666569"
},
{
"input": "10 5\n17 <= 10\n16... | 92 | 1,536,000 | 0 | 90,226 | |
279 | Ladder | [
"dp",
"implementation",
"two pointers"
] | null | null | You've got an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Also, you've got *m* queries, the *i*-th query is described by two integers *l**i*,<=*r**i*. Numbers *l**i*,<=*r**i* define a subsegment of the original array, that is, the sequence of numbers *a**l**i*,<=*a**l**i*<=+<=1,<=*a**l**i*<=+<=2,<=...... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of array elements and the number of queries. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where number *a**i* stands for the *i*-th array element.
The following *m* lines cont... | Print *m* lines, in the *i*-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the *i*-th query is the ladder, or word "No" (without the quotes) otherwise. | [
"8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8\n"
] | [
"Yes\nYes\nNo\nYes\nNo\nYes\n"
] | none | [
{
"input": "8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8",
"output": "Yes\nYes\nNo\nYes\nNo\nYes"
},
{
"input": "1 1\n6\n1 1",
"output": "Yes"
},
{
"input": "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2",
"output": "Yes\nYes\nYes\nYes\nYes"
},
{
"input": "10 10\n4 7 2 6 4 8 1 2 1 ... | 92 | 0 | 0 | 90,264 | |
878 | Teams Formation | [
"data structures",
"implementation"
] | null | null | This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has *n* passenger seats, seat *i* can be occupied only by a participant from the city *a**i*.
Today the bus has completed *m* trips, each time bringing *n* participants. The participants were then... | The first line contains three integers *n*,<=*k* and *m* (1<=≤<=*n*<=≤<=105, 2<=≤<=*k*<=≤<=109, 1<=≤<=*m*<=≤<=109).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105), where *a**i* is the number of city, person from which must take seat *i* in the bus. | Output the number of remaining participants in the line. | [
"4 2 5\n1 2 3 1\n",
"1 9 10\n1\n",
"3 2 10\n1 2 1\n"
] | [
"12\n",
"1\n",
"0\n"
] | In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line. | [
{
"input": "4 2 5\n1 2 3 1",
"output": "12"
},
{
"input": "1 9 10\n1",
"output": "1"
},
{
"input": "3 2 10\n1 2 1",
"output": "0"
},
{
"input": "1 10 10\n1",
"output": "0"
},
{
"input": "1 1000000000 1000000000\n100000",
"output": "0"
},
{
"input": "2 ... | 62 | 5,632,000 | 0 | 90,517 | |
406 | Hamming Triples | [
"implementation",
"math",
"two pointers"
] | null | null | Little Chris is having a nightmare. Even in dreams all he thinks about is math.
Chris dreams about *m* binary strings of length *n*, indexed with numbers from 1 to *m*. The most horrifying part is that the bits of each string are ordered in either ascending or descending order. For example, Chris could be dreaming abo... | The first line of input contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=109; 3<=≤<=*m*<=≤<=105), the length and the number of strings. The next *m* lines contain the description of the strings. The *i*-th line contains two space-separated integers *s**i* and *f**i* (0<=≤<=*s**i*<=≤<=1; 1<=≤<=*f**i*<=≤<... | Output a single integer, the number of such string triples among the given that the sum of the Hamming distances between the strings of the triple is maximal. | [
"5 4\n0 3\n0 5\n1 4\n1 5\n",
"10 4\n1 5\n0 5\n0 5\n1 5\n"
] | [
"3\n",
"4\n"
] | none | [] | 46 | 0 | 0 | 90,536 | |
436 | Dungeons and Candies | [
"dsu",
"graphs",
"greedy",
"trees"
] | null | null | During the loading of the game "Dungeons and Candies" you are required to get descriptions of *k* levels from the server. Each description is a map of an *n*<=×<=*m* checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if... | The first line contains four integers *n*,<=*m*,<=*k*,<=*w* (1<=≤<=*n*,<=*m*<=≤<=10; 1<=≤<=*k*,<=*w*<=≤<=1000). Then follows the description of *k* levels. Each level is described by *n* lines, each line contains *m* characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that ... | In the first line print the required minimum number of transferred bytes.
Then print *k* pairs of integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=...,<=*x**k*,<=*y**k*, describing the way to transfer levels. Pair *x**i*, *y**i* means that level *x**i* needs to be transferred by way *y**i*. If *y**i* equals 0, that means that the... | [
"2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...\n",
"1 1 4 1\nA\n.\nB\n.\n",
"1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB\n"
] | [
"14\n1 0\n2 1\n3 1\n",
"3\n1 0\n2 0\n4 2\n3 0\n",
"11\n1 0\n3 1\n2 3\n4 2\n5 1\n"
] | none | [
{
"input": "1 1 4 1\nA\n.\nB\n.",
"output": "3\n1 0\n2 0\n4 2\n3 0"
},
{
"input": "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB",
"output": "11\n1 0\n3 1\n2 3\n4 2\n5 1"
},
{
"input": "2 2 5 1\n..\nBA\n.A\nB.\n..\nA.\nAB\n.B\n..\n..",
"output": "12\n1 0\n2 1\n3 1\n5 3\n4 5"
},
{
"input":... | 46 | 614,400 | 0 | 90,804 | |
566 | Matching Names | [
"dfs and similar",
"strings",
"trees"
] | null | null | Teachers of one programming summer school decided to make a surprise for the students by giving them names in the style of the "Hobbit" movie. Each student must get a pseudonym maximally similar to his own name. The pseudonym must be a name of some character of the popular saga and now the teachers are busy matching ps... | The first line contains number *n* (1<=≤<=*n*<=≤<=100<=000) — the number of students in the summer school.
Next *n* lines contain the name of the students. Each name is a non-empty word consisting of lowercase English letters. Some names can be repeating.
The last *n* lines contain the given pseudonyms. Each pseudony... | In the first line print the maximum possible quality of matching pseudonyms to students.
In the next *n* lines describe the optimal matching. Each line must have the form *a* *b* (1<=≤<=*a*,<=*b*<=≤<=*n*), that means that the student who was number *a* in the input, must match to the pseudonym number *b* in the input.... | [
"5\ngennady\ngalya\nboris\nbill\ntoshik\nbilbo\ntorin\ngendalf\nsmaug\ngaladriel\n"
] | [
"11\n4 1\n2 5\n1 3\n5 2\n3 4\n"
] | The first test from the statement the match looks as follows:
- bill → bilbo (lcp = 3) - galya → galadriel (lcp = 3) - gennady → gendalf (lcp = 3) - toshik → torin (lcp = 2) - boris → smaug (lcp = 0) | [
{
"input": "5\ngennady\ngalya\nboris\nbill\ntoshik\nbilbo\ntorin\ngendalf\nsmaug\ngaladriel",
"output": "11\n4 1\n2 5\n1 3\n5 2\n3 4"
},
{
"input": "1\na\na",
"output": "1\n1 1"
},
{
"input": "2\na\na\na\na",
"output": "2\n1 1\n2 2"
},
{
"input": "2\na\nb\na\na",
"output"... | 46 | 0 | 0 | 90,951 | |
257 | Greedy Elevator | [
"data structures",
"implementation"
] | null | null | The *m*-floor (*m*<=><=1) office of international corporation CodeForces has the advanced elevator control system established. It works as follows.
All office floors are sequentially numbered with integers from 1 to *m*. At time *t*<==<=0, the elevator is on the first floor, the elevator is empty and nobody is wait... | The first line contains two space-separated integers: *n*,<=*m* (1<=≤<=*n*<=≤<=105,<=2<=≤<=*m*<=≤<=105) — the number of people and floors in the building, correspondingly.
Next *n* lines each contain three space-separated integers: *t**i*,<=*s**i*,<=*f**i* (1<=≤<=*t**i*<=≤<=109,<=1<=≤<=*s**i*,<=*f**i*<=≤<=*m*,<=*s**i*... | Print *n* lines. In the *i*-th line print a single number — the moment of time, when the *i*-th person gets to the floor he needs. The people are numbered in the order, in which they are given in the input.
Please don't use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, co... | [
"3 10\n1 2 7\n3 6 5\n3 4 8\n",
"2 10\n1 2 5\n7 4 5\n"
] | [
"7\n11\n8\n",
"5\n9\n"
] | In the first sample the elevator worked as follows:
- *t* = 1. The elevator is on the floor number 1. The elevator is empty. The floor number 2 has one person waiting. *p*<sub class="lower-index">*up*</sub> = 1 + 0 = 1, *p*<sub class="lower-index">*down*</sub> = 0 + 0 = 0, *p*<sub class="lower-index">*up*</sub> ≥ *p... | [] | 92 | 0 | 0 | 90,991 | |
1,007 | Ants | [
"2-sat",
"data structures",
"trees"
] | null | null | There is a tree with $n$ vertices. There are also $m$ ants living on it. Each ant has its own color. The $i$-th ant has two favorite pairs of vertices: ($a_i, b_i$) and ($c_i, d_i$). You need to tell if it is possible to paint the edges of the tree in $m$ colors so that every ant will be able to walk between vertices f... | The first line contains a single integer $n$ ($2 \leq n \leq 10^5$) — the number of vertices.
Each of the next $n-1$ lines contains two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$), meaning that there is an edge between vertices $u_i$ and $v_i$.
The next line contains a single integer $m$ ($1 \leq m \leq 10^4$... | Print "NO" (without quotes) if the wanted painting is impossible.
Otherwise, print "YES" (without quotes). Print $m$ lines. On the $i$-th line, print $1$ if the $i$-th ant will use the first pair and $2$ otherwise. If there are multiple answers, print any. | [
"6\n1 2\n3 1\n4 1\n5 2\n6 2\n3\n2 6 3 4\n1 6 6 5\n1 4 5 2\n",
"5\n1 2\n1 3\n1 4\n1 5\n2\n2 3 4 5\n3 4 5 2\n"
] | [
"YES\n2\n1\n2\n",
"NO\n"
] | In the sample, the second and the third edge should be painted in the first color, the first and the fifth should be painted in the second color, and the fourth should be painted in the third color. | [] | 93 | 2,150,400 | -1 | 91,077 | |
685 | Kay and Eternity | [
"brute force",
"implementation",
"sortings"
] | null | null | Snow Queen told Kay to form a word "eternity" using pieces of ice. Kay is eager to deal with the task, because he will then become free, and Snow Queen will give him all the world and a pair of skates.
Behind the palace of the Snow Queen there is an infinite field consisting of cells. There are *n* pieces of ice sprea... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=300) — the number of pieces of the ice and the value *k*, respectively. Each of the next *n* lines contains two integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — coordinates of the cell containing *i*-... | Print *n* integers: the number of squares of size *k*<=×<=*k* containing exactly 1,<=2,<=...,<=*n* pieces of the ice. | [
"5 3\n4 5\n4 6\n5 5\n5 6\n7 7\n"
] | [
"10 8 1 4 0 \n"
] | none | [
{
"input": "5 3\n4 5\n4 6\n5 5\n5 6\n7 7",
"output": "10 8 1 4 0 "
},
{
"input": "10 2\n4 7\n-9 -9\n9 2\n4 4\n7 10\n9 8\n-6 -2\n-9 2\n-7 -6\n0 5",
"output": "40 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10 5\n-7 -3\n-2 7\n4 4\n-1 5\n9 4\n-2 -3\n-5 8\n8 -4\n-6 -6\n8 8",
"output": "182 31 2 0... | 0 | 0 | -1 | 91,096 | |
0 | none | [
"none"
] | null | null | It's May in Flatland, and there are $m$ days in this month. Despite the fact that May Holidays are canceled long time ago, employees of some software company still have a habit of taking short or long vacations in May.
Of course, not all managers of the company like this. There are $n$ employees in the company that fo... | The first line contains two integers $n$ and $m$ ($2 \leq n, m \leq 10^5$) — the number of employees in the company and the number of days in May.
The second line contains $n - 1$ integers $p_2, p_3, \ldots, p_n$ ($1 \leq p_i \leq n$), denoting the direct managers of employees.
The third line contains $n$ integers $t... | Print a sequence of $m$ integers $a_1, a_2, \ldots, a_m$, where $a_i$ is the number of displeased employees on the $i$-th day. | [
"7 8\n4 5 1 1 5 5\n0 0 0 1 2 0 0\n2 6 3 7 -2 4 -3 1\n",
"5 6\n1 2 3 4\n4 0 0 1 0\n1 5 2 3 -5 -1\n"
] | [
"1 1 1 2 2 2 1 0\n",
"0 2 1 0 0 0\n"
] | In the first sample test after employee with id 2 leaves for a vacation at the first day, the head manager with id 1 becomes displeased as he does not want any of his subordinates to go for a vacation. At the fourth day employee with id 5 becomes displeased as his last remaining employee with id 7 leaves for a vacation... | [] | 77 | 2,867,200 | -1 | 91,150 | |
893 | Subtree Minimum Query | [
"data structures",
"trees"
] | null | null | You are given a rooted tree consisting of *n* vertices. Each vertex has a number written on it; number *a**i* is written on vertex *i*.
Let's denote *d*(*i*,<=*j*) as the distance between vertices *i* and *j* in the tree (that is, the number of edges in the shortest path from *i* to *j*). Also let's denote the *k*-blo... | The first line contains two integers *n* and *r* (1<=≤<=*r*<=≤<=*n*<=≤<=100000) — the number of vertices in the tree and the index of the root, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the numbers written on the vertices.
Then *n*<=-<=1 lines follow, each... | Print *m* integers. *i*-th of them has to be equal to the answer to *i*-th query. | [
"5 2\n1 3 2 3 5\n2 3\n5 1\n3 4\n4 1\n2\n1 2\n2 3\n"
] | [
"2\n5\n"
] | none | [
{
"input": "5 2\n1 3 2 3 5\n2 3\n5 1\n3 4\n4 1\n2\n1 2\n2 3",
"output": "2\n5"
},
{
"input": "3 3\n1 3 2\n1 2\n1 3\n2\n2 3\n1 1",
"output": "2\n1"
},
{
"input": "1 1\n1\n1\n1 1",
"output": "1"
}
] | 0 | 0 | -1 | 91,765 | |
280 | Rectangle Puzzle | [
"geometry"
] | null | null | You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the *Ox* axis, equals *w*, the length of the side... | The first line contains three integers *w*,<=*h*,<=α (1<=≤<=*w*,<=*h*<=≤<=106; 0<=≤<=α<=≤<=180). Angle α is given in degrees. | In a single line print a real number — the area of the region which belongs to both given rectangles.
The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=6. | [
"1 1 45\n",
"6 4 30\n"
] | [
"0.828427125\n",
"19.668384925\n"
] | The second sample has been drawn on the picture above. | [
{
"input": "1 1 45",
"output": "0.828427125"
},
{
"input": "6 4 30",
"output": "19.668384925"
},
{
"input": "100 100 0",
"output": "10000.000000000"
},
{
"input": "100 100 30",
"output": "8452.994616207"
},
{
"input": "303304 904227 3",
"output": "262706079399... | 280 | 0 | 3 | 91,830 | |
758 | Ability To Convert | [
"constructive algorithms",
"dp",
"greedy",
"math",
"strings"
] | null | null | Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter *A* he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he ge... | The first line contains the integer *n* (2<=≤<=*n*<=≤<=109). The second line contains the integer *k* (0<=≤<=*k*<=<<=1060), it is guaranteed that the number *k* contains no more than 60 symbols. All digits in the second line are strictly less than *n*.
Alexander guarantees that the answer exists and does not exceed... | Print the number *x* (0<=≤<=*x*<=≤<=1018) — the answer to the problem. | [
"13\n12\n",
"16\n11311\n",
"20\n999\n",
"17\n2016\n"
] | [
"12",
"475",
"3789",
"594"
] | In the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·13<sup class="upper-index">0</sup> or 15 = 1·13<sup class="upper-index">1</sup> + 2·13<sup class="upper-index">0</sup>. | [
{
"input": "13\n12",
"output": "12"
},
{
"input": "16\n11311",
"output": "475"
},
{
"input": "20\n999",
"output": "3789"
},
{
"input": "17\n2016",
"output": "594"
},
{
"input": "1000\n1001",
"output": "100001"
},
{
"input": "1000\n1000",
"output": ... | 46 | 0 | 0 | 91,835 | |
690 | Tree of Life (medium) | [
"constructive algorithms",
"hashing",
"trees"
] | null | null | Heidi got tired of deciphering the prophecy hidden in the Tree of Life and decided to go back to her headquarters, rest a little and try there. Of course, she cannot uproot the Tree and take it with her, so she made a drawing of the Tree on a piece of paper. On second thought, she made more identical drawings so as to ... | The first line of the input contains *Z*<=≤<=20 – the number of test cases. *Z* descriptions of single test cases follow.
In each test case, the first line of input contains numbers *n* (2<=≤<=*n*<=≤<=100) and *k* (where *k* is the number of drawings; we have *k*<==<=*n*). In the following lines, the descriptions of t... | If Heidi's drawings cannot possibly come from a single tree, you should output the word NO. Otherwise, output one line containing the word YES and *n*<=-<=1 lines describing any tree that Heidi's drawings could have come from. For every edge you should output the numbers of the vertices that it connects, separated with... | [
"1\n5 5\n2\n4 1\n2 1\n1\n3 1\n3\n4 1\n4 3\n2 1\n3\n3 1\n3 2\n4 1\n3\n2 1\n3 2\n4 2\n"
] | [
"YES\n2 5\n4 2\n3 2\n5 1\n"
] | none | [] | 5,000 | 7,884,800 | 0 | 91,872 | |
207 | Military Trainings | [] | null | null | The Smart Beaver from ABBYY started cooperating with the Ministry of Defence. Now they train soldiers to move armoured columns. The training involves testing a new type of tanks that can transmit information. To test the new type of tanks, the training has a special exercise, its essence is as follows.
Initially, the ... | The first line contains integer *n* — the number of tanks in the column. Each of the next *n* lines contains one integer *a**i* (1<=≤<=*a**i*<=≤<=250000, 1<=≤<=*i*<=≤<=*n*) — the message receiving radii of the tanks in the order from tank 1 to tank *n* (let us remind you that initially the tanks are located in the colu... | Print a single integer — the minimum possible total time of transmitting the messages.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n2\n1\n1\n",
"5\n2\n2\n2\n2\n2\n"
] | [
"5\n",
"10\n"
] | In the first sample the original order of tanks is 1, 2, 3. The first tank sends a message to the second one, then the second tank sends it to the third one — it takes two seconds. The third tank moves to the beginning of the column and the order of tanks now is 3, 1, 2. The third tank sends a message to the first one,... | [] | 60 | 0 | 0 | 92,069 | |
198 | Delivering Carcinogen | [
"binary search",
"geometry"
] | null | null | Qwerty the Ranger arrived to the Diatar system with a very important task. He should deliver a special carcinogen for scientific research to planet Persephone. This is urgent, so Qwerty has to get to the planet as soon as possible. A lost day may fail negotiations as nobody is going to pay for an overdue carcinogen.
Y... | The first line contains space-separated integers *x**p*, *y**p* and *v**p* (<=-<=104<=≤<=*x**p*,<=*y**p*<=≤<=104, 1<=≤<=*v**p*<=<<=104) — Persephone's initial position and the speed at which it goes round Diatar.
The second line contains space-separated integers *x*, *y*, *v* and *r* (<=-<=104<=≤<=*x*,<=*y*<=≤<=104... | Print a single real number — the minimum possible delivery time. The answer will be considered valid if its absolute or relative error does not exceed 10<=-<=6. | [
"10 0 1\n-10 0 2 8\n",
"50 60 10\n50 60 20 40\n"
] | [
"9.584544103",
"0.000000000"
] | none | [
{
"input": "10 0 1\n-10 0 2 8",
"output": "9.584544103"
},
{
"input": "50 60 10\n50 60 20 40",
"output": "0.000000000"
},
{
"input": "86 -67 50\n-60 -20 91 35",
"output": "2.047618248"
},
{
"input": "-137 -45 64\n-86 -61 91 61",
"output": "0.447407904"
},
{
"input... | 124 | 0 | 0 | 92,241 | |
717 | Dexterina’s Lab | [
"games",
"matrices",
"probabilities"
] | null | null | Dexterina and Womandark have been arch-rivals since they’ve known each other. Since both are super-intelligent teenage girls, they’ve always been trying to solve their disputes in a peaceful and nonviolent way. After god knows how many different challenges they’ve given to one another, their score is equal and they’re ... | The first line of the input contains two integers *n* (1<=≤<=*n*<=≤<=109) and *x* (1<=≤<=*x*<=≤<=100) — the number of heaps and the maximum number of objects in a heap, respectively. The second line contains *x*<=+<=1 real numbers, given with up to 6 decimal places each: *P*(0),<=*P*(1),<=... ,<=*P*(*X*). Here, *P*(*i*... | Output a single real number, the probability that the first player wins. The answer will be judged as correct if it differs from the correct answer by at most 10<=-<=6. | [
"2 2\n0.500000 0.250000 0.250000\n"
] | [
"0.62500000\n"
] | none | [
{
"input": "2 2\n0.500000 0.250000 0.250000",
"output": "0.62500000"
},
{
"input": "9 9\n0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000",
"output": "0.93687014"
},
{
"input": "1000001 5\n0.000000 0.300000 0.000000 0.500000 0.000000 0.200000",
... | 46 | 0 | 0 | 92,392 | |
180 | Divisibility Rules | [
"math",
"number theory"
] | null | null | Vasya studies divisibility rules at school. Here are some of them:
- Divisibility by 2. A number is divisible by 2 if and only if its last digit is divisible by 2 or in other words, is even.- Divisibility by 3. A number is divisible by 3 if and only if the sum of its digits is divisible by 3.- Divisibility by 4. A n... | The first input line contains two integers *b* and *d* (2<=≤<=*b*,<=*d*<=≤<=100) — the notation system base and the divisor. Both numbers are given in the decimal notation. | On the first output line print the type of the rule in the *b*-based notation system, where the divisor is *d*: "2-type", "3-type", "11-type", "6-type" or "7-type". If there are several such types, print the one that goes earlier in the given sequence. If a number belongs to the 2-type, print on the second line the lea... | [
"10 10\n",
"2 3\n"
] | [
"2-type\n1\n",
"11-type\n"
] | The divisibility rule for number 3 in binary notation looks as follows: "A number is divisible by 3 if and only if the sum of its digits that occupy the even places differs from the sum of digits that occupy the odd places, in a number that is divisible by 3". That's an 11-type rule. For example, 21<sub class="lower-in... | [
{
"input": "10 10",
"output": "2-type\n1"
},
{
"input": "2 3",
"output": "11-type"
},
{
"input": "2 2",
"output": "2-type\n1"
},
{
"input": "2 3",
"output": "11-type"
},
{
"input": "2 4",
"output": "2-type\n2"
},
{
"input": "2 5",
"output": "7-type... | 92 | 102,400 | 3 | 92,475 | |
821 | Okabe and El Psy Kongroo | [
"dp",
"matrices"
] | null | null | Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points (*x*,<=*y*) such that *x* and *y* are non-negative. Okabe starts at the origin (point (0,<=0)), and n... | The first line of input contains the integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1018) — the number of segments and the destination *x* coordinate.
The next *n* lines contain three space-separated integers *a**i*, *b**i*, and *c**i* (0<=≤<=*a**i*<=<<=*b**i*<=≤<=1018, 0<=≤<=*c**i*<=≤<=15) — the left and r... | Print the number of walks satisfying the conditions, modulo 1000000007 (109<=+<=7). | [
"1 3\n0 3 3\n",
"2 6\n0 3 0\n3 10 2\n"
] | [
"4\n",
"4\n"
] | The graph above corresponds to sample 1. The possible walks are:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7fcce410dbd2cf4e427a6b50e0f159b7ce538901.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/... | [
{
"input": "1 3\n0 3 3",
"output": "4"
},
{
"input": "2 6\n0 3 0\n3 10 2",
"output": "4"
},
{
"input": "2 3\n0 2 13\n2 3 11",
"output": "4"
},
{
"input": "2 9\n0 8 0\n8 10 10",
"output": "1"
},
{
"input": "1 1\n0 3 9",
"output": "1"
},
{
"input": "3 8\... | 46 | 0 | 0 | 92,599 | |
839 | Winter is here | [
"combinatorics",
"dp",
"math",
"number theory"
] | null | null | Winter is here at the North and the White Walkers are close. John Snow has an army consisting of *n* soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers.
He has created a method to know how strong his army is. Let the *i*-th soldier’s stre... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200000) — the size of the army.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000000) — denoting the strengths of his soldiers. | Print one integer — the strength of John Snow's army modulo 1000000007 (109<=+<=7). | [
"3\n3 3 1\n",
"4\n2 3 4 6\n"
] | [
"12\n",
"39\n"
] | In the first sample the clans are {1}, {2}, {1, 2} so the answer will be 1·3 + 1·3 + 2·3 = 12 | [
{
"input": "3\n3 3 1",
"output": "12"
},
{
"input": "4\n2 3 4 6",
"output": "39"
}
] | 1,106 | 51,404,800 | 3 | 92,714 | |
633 | Fibonacci-ish II | [
"data structures",
"implementation"
] | null | null | Yash is finally tired of computing the length of the longest Fibonacci-ish sequence. He now plays around with more complex things such as Fibonacci-ish potentials.
Fibonacci-ish potential of an array *a**i* is computed as follows:
1. Remove all elements *j* if there exists *i*<=<<=*j* such that *a**i*<==<=*a**j... | The first line of the input contains integers of *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=30<=000) — the length of the initial array and the modulo, respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109) — elements of the array.
Then follow the number of ranges *q* (1<=≤<=*q*<=≤<=30<=000).
Last *q* ... | Print *q* lines, *i*-th of them must contain the Fibonacci-ish potential of the *i*-th range modulo *m*. | [
"5 10\n2 1 2 1 2\n2\n2 4\n4 5\n"
] | [
"3\n3\n"
] | For the purpose of this problem define Fibonacci numbers as follows:
1. *F*<sub class="lower-index">1</sub> = *F*<sub class="lower-index">2</sub> = 1. 1. *F*<sub class="lower-index">*n*</sub> = *F*<sub class="lower-index">*n* - 1</sub> + *F*<sub class="lower-index">*n* - 2</sub> for each *n* > 2.
In the first q... | [] | 30 | 0 | 0 | 92,818 | |
394 | Lightbulb for Minister | [
"geometry"
] | null | null | The Minister for education is coming! Naturally, nobody wants to perform poorly in front of such a honored guest. However, two hours before the arrival it turned out that one of the classes has a malfunctioning lightbulb — for some reason it doesn't get enough energy. The solution was found quickly: all we've got to do... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of generators. Each of the next *n* lines contains a pair of integers *x**i*, *y**i*, representing the coordinates of the *i*-th generator in the plane of the class ceiling. It's guaranteed that no two generators have the same location.
The next line... | Print a single real number — the minimum value of the sum of squares of distances from the generators to the point of the lightbulb's optimal position. The answer will be considered valid if its absolute or relative error doesn't exceed 10<=-<=4. | [
"4\n3 2\n3 4\n5 4\n5 2\n4\n3 3\n4 4\n5 3\n4 2\n"
] | [
"8.00000000"
] | We'll define a strictly convex polygon as a convex polygon with the following property: no three vertices of the polygon lie on the same line. | [] | 108 | 307,200 | 0 | 92,890 | |
285 | Positions in Permutations | [
"combinatorics",
"dp",
"math"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
We'l... | The single line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=*n*). | Print the number of permutations of length *n* with exactly *k* good positions modulo 1000000007 (109<=+<=7). | [
"1 0\n",
"2 1\n",
"3 2\n",
"4 1\n",
"7 4\n"
] | [
"1\n",
"0\n",
"4\n",
"6\n",
"328\n"
] | The only permutation of size 1 has 0 good positions.
Permutation (1, 2) has 0 good positions, and permutation (2, 1) has 2 positions.
Permutations of size 3:
1. (1, 2, 3) — 0 positions1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eacaee9ed78760263daaea6c99f00e6bed9f63f4.png" style=... | [
{
"input": "1 0",
"output": "1"
},
{
"input": "2 1",
"output": "0"
},
{
"input": "3 2",
"output": "4"
},
{
"input": "4 1",
"output": "6"
},
{
"input": "7 4",
"output": "328"
},
{
"input": "7 7",
"output": "0"
},
{
"input": "8 4",
"outpu... | 60 | 0 | 0 | 92,934 | |
815 | Karen and Neighborhood | [
"binary search",
"constructive algorithms",
"implementation"
] | null | null | It's been long after the events of the previous problems, and Karen has now moved on from student life and is looking to relocate to a new neighborhood.
The neighborhood consists of *n* houses in a straight line, labelled 1 to *n* from left to right, all an equal distance apart.
Everyone in this neighborhood loves pe... | The first and only line of input contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018), describing the number of houses in the neighborhood, and that Karen was the *k*-th person to move in, respectively. | Output a single integer on a line by itself, the label of the house Karen will move into. | [
"6 4\n",
"39 3\n"
] | [
"2\n",
"20\n"
] | In the first test case, there are 6 houses in the neighborhood, and Karen is the fourth person to move in:
1. The first person moves into house 1. 1. The second person moves into house 6. 1. The third person moves into house 3. 1. The fourth person moves into house 2.
In the second test case, there are 39 houses ... | [
{
"input": "6 4",
"output": "2"
},
{
"input": "39 3",
"output": "20"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000000000 1",
"output": "1"
},
{
"input": "1000000000000000000 2",
"output": "1000000000000000000"
},
{
"input": "69 69",
... | 62 | 0 | 0 | 92,983 | |
351 | Jeff and Furik | [
"combinatorics",
"dp",
"probabilities"
] | null | null | Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of *n* numbers: *p*1, *p*2, ..., *p**n*. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3000). The next line contains *n* distinct integers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the permutation *p*. The numbers are separated by spaces. | In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"2\n1 2\n",
"5\n3 5 2 4 1\n"
] | [
"0.000000\n",
"13.000000\n"
] | In the first test the sequence is already sorted, so the answer is 0. | [
{
"input": "2\n1 2",
"output": "0.000000"
},
{
"input": "5\n3 5 2 4 1",
"output": "13.000000"
},
{
"input": "16\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12",
"output": "108.000000"
},
{
"input": "9\n1 7 8 5 3 4 6 9 2",
"output": "33.000000"
},
{
"input": "5\n2 3 4 5 1... | 124 | 102,400 | 3 | 93,059 | |
959 | Mahmoud and Ehab and another array construction task | [
"constructive algorithms",
"greedy",
"math",
"number theory"
] | null | null | Mahmoud has an array *a* consisting of *n* integers. He asked Ehab to find another array *b* of the same length such that:
- *b* is lexicographically greater than or equal to *a*. - *b**i*<=≥<=2. - *b* is pairwise coprime: for every 1<=≤<=*i*<=<<=*j*<=≤<=*n*, *b**i* and *b**j* are coprime, i. e. *GCD*(*b**i*,<=*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of elements in *a* and *b*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=105), the elements of *a*. | Output *n* space-separated integers, the *i*-th of them representing *b**i*. | [
"5\n2 3 5 4 13\n",
"3\n10 3 7\n"
] | [
"2 3 5 7 11 ",
"10 3 7 "
] | Note that in the second sample, the array is already pairwise coprime so we printed it. | [
{
"input": "5\n2 3 5 4 13",
"output": "2 3 5 7 11 "
},
{
"input": "3\n10 3 7",
"output": "10 3 7 "
},
{
"input": "5\n7 10 2 5 5",
"output": "7 10 3 11 13 "
},
{
"input": "7\n20 9 7 6 7 9 15",
"output": "20 9 7 11 13 17 19 "
},
{
"input": "10\n5 3 2 2 3 3 3 4 2 5",... | 3,000 | 13,312,000 | 0 | 93,245 | |
553 | Love Triangles | [
"dfs and similar",
"dsu",
"graphs"
] | null | null | There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has *n* characters. The characters are labeled from 1 to *n*. Every pair of two characters can either mutually love each other or mutually hate each other ... | The first line of input will contain two integers *n*,<=*m* (3<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000).
The next *m* lines will contain the description of the known relationships. The *i*-th line will contain three integers *a**i*,<=*b**i*,<=*c**i*. If *c**i* is 1, then *a**i* and *b**i* are in love, otherwise, ... | Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo 1<=000<=000<=007. | [
"3 0\n",
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n",
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1\n"
] | [
"4\n",
"1\n",
"0\n"
] | In the first sample, the four ways are to:
- Make everyone love each other - Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this).
In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other. | [
{
"input": "3 0",
"output": "4"
},
{
"input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0",
"output": "1"
},
{
"input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1",
"output": "0"
},
{
"input": "100000 0",
"output": "303861760"
},
{
"input": "100 3\n1 2 0\n2 3 0\n3 1 0",
"output": ... | 1,044 | 23,142,400 | -1 | 93,336 | |
763 | Timofey and our friends animals | [
"data structures",
"divide and conquer",
"dsu"
] | null | null | After his birthday party, Timofey went to his favorite tree alley in a park. He wants to feed there his favorite birds — crows.
It's widely known that each tree is occupied by a single crow family. The trees in the alley form a row and are numbered from 1 to *n*. Some families are friends to each other. For some reaso... | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=5), where *n* is the number of trees, and *k* is the maximum possible distance between friend families.
The next line contains single integer *m* (0<=≤<=*m*<=≤<=*n*·*k*) — the number of pair of friend families.
Each of the next *m* lines ... | Print *q* lines. Line *i* should contain single integer — the answer in the *i*-th situation. | [
"5 3\n3\n1 3\n2 3\n4 5\n5\n1 1\n1 2\n2 3\n1 3\n1 5\n"
] | [
"1\n2\n1\n1\n2\n"
] | In the first example the following family pairs are friends: (1, 3), (2, 3) and (4, 5).
- In the first situation only the first family has remained, so the answer is 1. - In the second situation the first two families have remained, and they aren't friends, so the answer is 2. - In the third situation the families ... | [] | 46 | 4,608,000 | 0 | 93,852 | |
8 | Beads | [
"dp",
"graphs"
] | E. Beads | 5 | 64 | One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if on... | The input file contains two integers *n* and *k* (2<=≤<=*n*<=≤<=50;1<=≤<=*k*<=≤<=1016) —the length of a string of beads, and the index of the string, chosen by Zorg. | Output the *k*-th string of beads, putting 0 for a red bead, and 1 — for a blue one. If it s impossible to find the required string, output the only number -1. | [
"4 4\n"
] | [
"0101\n"
] | Let's consider the example of strings of length 4 — 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110. Zorg will divide them into heaps: {0001, 0111, 1000, 1110}, {0010, 0100, 1011, 1101}, {0011, 1100}, {0101, 1010}, {0110, 1001}. Then he will choose the minimum strings of beads in each... | [
{
"input": "4 4",
"output": "0101"
},
{
"input": "2 1",
"output": "01"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "3 1",
"output": "001"
},
{
"input": "3 2",
"output": "010"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "4 1",
... | 92 | 0 | 0 | 93,916 |
41 | 3-cycles | [
"constructive algorithms",
"graphs",
"greedy"
] | E. 3-cycles | 2 | 256 | During a recent research Berland scientists found out that there were *n* cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose thr... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of cities in Berland. | On the first line must be printed number *m* — the maximal number of roads in Berland. Then print *m* lines containing two numbers each — the numbers of cities that the given road joins. The cities are numbered with integers from 1 to *n*. If there are several variants of solving the problem, print any of them. | [
"3\n",
"4\n"
] | [
"2\n1 2\n2 3\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | none | [
{
"input": "3",
"output": "2\n1 2\n1 3"
},
{
"input": "4",
"output": "4\n1 3\n1 4\n2 3\n2 4"
},
{
"input": "5",
"output": "6\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5"
},
{
"input": "6",
"output": "9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6"
},
{
"input": "7",
"output... | 280 | 2,150,400 | 3.925995 | 93,953 |
786 | Rap God | [
"data structures",
"dfs and similar",
"hashing",
"strings",
"trees"
] | null | null | Rick is in love with Unity. But Mr. Meeseeks also love Unity, so Rick and Mr. Meeseeks are "love rivals".
Unity loves rap, so it decided that they have to compete in a rap game (battle) in order to choose the best. Rick is too nerds, so instead he's gonna make his verse with running his original algorithm on lyrics "... | The first line of input contain two integers *n* and *q* (2<=≤<=*n*<=≤<=20000, 1<=≤<=*q*<=≤<=20000) — number of vertices in tree and number of queries respectively.
The next *n*<=-<=1 lines contain the edges. Each line contains two integers *v* and *u* (endpoints of the edge) followed by an English lowercase letter *c... | Print the answer for each query in one line. | [
"4 3\n4 1 t\n3 2 p\n1 2 s\n3 2\n1 3\n2 1\n",
"8 4\n4 6 p\n3 7 o\n7 8 p\n4 5 d\n1 3 o\n4 3 p\n3 2 e\n8 6\n3 7\n8 1\n4 3\n"
] | [
"0\n1\n1\n",
"6\n1\n3\n1\n"
] | Here's the tree of first sample testcase:
Here's the tree of second sample testcase:
In this test:
- *str*(8, 1) = poo - *str*(8, 2) = poe - *str*(8, 3) = po - *str*(8, 4) = pop - *str*(8, 5) = popd - *str*(8, 6) = popp - *str*(8, 7) = p
So, for the first query, <img align="middle" class="tex-formula" src="h... | [] | 15 | 0 | -1 | 93,995 | |
535 | Tavas and Pashmaks | [
"geometry",
"math"
] | null | null | Tavas is a cheerleader in the new sports competition named "Pashmaks".
This competition consists of two part: swimming and then running. People will immediately start running *R* meters after they finished swimming exactly *S* meters. A winner is a such person that nobody else finishes running before him/her (there ma... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=2<=×<=105).
The next *n* lines contain the details of competitors. *i*-th line contains two integers *s**i* and *r**i* (1<=≤<=*s**i*,<=*r**i*<=≤<=104). | In the first and the only line of output, print a sequence of numbers of possible winners in increasing order. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 2\n1 1\n2 1\n"
] | [
"1 2 3 \n",
"1 3 \n"
] | none | [] | 1,000 | 29,286,400 | 0 | 94,019 | |
887 | Row of Models | [
"greedy",
"sortings"
] | null | null | During the final part of fashion show all models come to the stage and stay in one row and fashion designer stays to right to model on the right. During the rehearsal, Izabella noticed, that row isn't nice, but she can't figure out how to fix it.
Like many other creative people, Izabella has a specific sense of beaut... | In first line there are two integers *n* and *k* (1<=≤<=*n*<=≤<=5·105, 1<=≤<=*k*<=≤<=*n*) — number of models and required distance.
Second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — height of each model. Pay attention that height of fashion designer is not given and can be less than 1. | Print «YES» (without quotes) if it's possible to make row nice using at most one exchange, and «NO» (without quotes) otherwise. | [
"5 4\n2 3 5 2 5\n",
"5 2\n3 6 2 2 1\n",
"5 2\n5 3 6 5 2\n"
] | [
"NO",
"YES",
"YES"
] | none | [] | 30 | 0 | 0 | 94,216 | |
223 | Spider | [
"geometry",
"graphs"
] | null | null | A plane contains a not necessarily convex polygon without self-intersections, consisting of *n* vertexes, numbered from 1 to *n*. There is a spider sitting on the border of the polygon, the spider can move like that:
1. Transfer. The spider moves from the point *p*1 with coordinates (*x*1,<=*y*1), lying on the polygo... | The first line contains integer *n* (3<=≤<=*n*<=≤<=105) — the number of vertexes of the given polygon. Next *n* lines contain two space-separated integers each — the coordinates of the polygon vertexes. The vertexes are listed in the counter-clockwise order. The coordinates of the polygon vertexes do not exceed 104 in ... | In the output print a single real number — the length of the shortest way from vertex *s* to vertex *t*. The answer is considered correct, if its absolute or relative error does not exceed 10<=-<=6. | [
"4\n0 0\n1 0\n1 1\n0 1\n1 4\n",
"4\n0 0\n1 1\n0 2\n-1 1\n3 3\n",
"5\n0 0\n5 0\n1 4\n0 2\n2 1\n3 1\n"
] | [
"1.000000000000000000e+000\n",
"0.000000000000000000e+000\n",
"5.650281539872884700e+000\n"
] | In the first sample the spider transfers along the side that connects vertexes 1 and 4.
In the second sample the spider doesn't have to transfer anywhere, so the distance equals zero.
In the third sample the best strategy for the spider is to transfer from vertex 3 to point (2,3), descend to point (2,1), and then tra... | [] | 46 | 0 | 0 | 94,336 | |
641 | Little Artem and Random Variable | [
"dp",
"implementation",
"math",
"probabilities"
] | null | null | Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to *n* inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and d... | First line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of different values for both dices.
Second line contains an array consisting of *n* real values with up to 8 digits after the decimal point — probability distribution for *max*(*a*,<=*b*), the *i*-th of these values equals to the probability th... | Output two descriptions of the probability distribution for *a* on the first line and for *b* on the second line.
The answer will be considered correct if each value of max(*a*,<=*b*) and min(*a*,<=*b*) probability distribution values does not differ by more than 10<=-<=6 from ones given in input. Also, probabilities... | [
"2\n0.25 0.75\n0.75 0.25\n",
"3\n0.125 0.25 0.625\n0.625 0.25 0.125\n"
] | [
"0.5 0.5 \n0.5 0.5 \n",
"0.25 0.25 0.5 \n0.5 0.25 0.25 \n"
] | none | [
{
"input": "2\n0.25 0.75\n0.75 0.25",
"output": "0.5 0.5 \n0.5 0.5 "
},
{
"input": "3\n0.125 0.25 0.625\n0.625 0.25 0.125",
"output": "0.25 0.25 0.5 \n0.5 0.25 0.25 "
},
{
"input": "10\n0.01 0.01 0.01 0.01 0.01 0.1 0.2 0.2 0.4 0.05\n1.0 0 0 0 0 0 0 0 0 0",
"output": "0.01000000000000... | 482 | 21,606,400 | 0 | 94,603 | |
311 | Biologist | [
"flows"
] | null | null | SmallR is a biologist. Her latest research finding is how to change the sex of dogs. In other words, she can change female dogs into male dogs and vice versa.
She is going to demonstrate this technique. Now SmallR has *n* dogs, the costs of each dog's change may be different. The dogs are numbered from 1 to *n*. The c... | The first line contains three integers *n*, *m*, *g* (1<=≤<=*n*<=≤<=104,<=0<=≤<=*m*<=≤<=2000,<=0<=≤<=*g*<=≤<=104). The second line contains *n* integers, each is 0 or 1, the sex of each dog, 0 represent the female and 1 represent the male. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤... | Print a single integer, the maximum money SmallR can gain. Note that the integer is negative if SmallR will lose money. | [
"5 5 9\n0 1 1 1 0\n1 8 6 2 3\n0 7 3 3 2 1 1\n1 8 1 5 1\n1 0 3 2 1 4 1\n0 8 3 4 2 1 0\n1 7 2 4 1 1\n",
"5 5 8\n1 0 1 1 1\n6 5 4 2 8\n0 6 3 2 3 4 0\n0 8 3 3 2 4 0\n0 0 3 3 4 1 1\n0 10 3 4 3 1 1\n0 4 3 3 4 1 1\n"
] | [
"2\n",
"16\n"
] | none | [
{
"input": "5 5 9\n0 1 1 1 0\n1 8 6 2 3\n0 7 3 3 2 1 1\n1 8 1 5 1\n1 0 3 2 1 4 1\n0 8 3 4 2 1 0\n1 7 2 4 1 1",
"output": "2"
},
{
"input": "5 5 8\n1 0 1 1 1\n6 5 4 2 8\n0 6 3 2 3 4 0\n0 8 3 3 2 4 0\n0 0 3 3 4 1 1\n0 10 3 4 3 1 1\n0 4 3 3 4 1 1",
"output": "16"
},
{
"input": "5 5 8\n0 1 0... | 1,500 | 15,257,600 | 0 | 94,701 | |
26 | Multithreading | [
"constructive algorithms"
] | E. Multithreading | 2 | 256 | You are given the following concurrent program. There are *N* processes and the *i*-th process has the following pseudocode:
Here *y* is a shared variable. Everything else is local for the process. All actions on a given row are atomic, i.e. when the process starts executing a row it is never interrupted. Beyond that... | In the first line of the input you will be given two space separated integers *N* (1<=≤<=*N*<=≤<=100) and *W* (<=-<=109<=≤<=*W*<=≤<=109). In the second line there are *N* space separated integers *n**i* (1<=≤<=*n**i*<=≤<=1000). | On the first line of the output write Yes if it is possible that at the end *y*<==<=*W*, or No otherwise. If the answer is No then there is no second line, but if the answer is Yes, then on the second line output a space separated list of integers representing some schedule that leads to the desired result. For more in... | [
"1 10\n11\n",
"2 3\n4 4\n",
"3 6\n1 2 3\n"
] | [
"No\n",
"Yes\n1 1 2 1 2 2 2 2 2 1 2 1 1 1 1 2\n",
"Yes\n1 1 2 2 2 2 3 3 3 3 3 3\n"
] | For simplicity, assume that there is no repeat statement in the code of the processes, but the code from the loop is written the correct amount of times. The processes are numbered starting from 1. The list of integers represent which process works on its next instruction at a given step. For example, consider the sche... | [
{
"input": "1 10\n11",
"output": "No"
},
{
"input": "3 -1\n1 2 3",
"output": "No"
},
{
"input": "3 6\n1 2 3",
"output": "Yes\n1 1 2 2 2 2 3 3 3 3 3 3"
},
{
"input": "3 5\n3 1 4",
"output": "Yes\n2 1 1 1 1 1 1 2 3 3 3 3 3 3 3 3"
},
{
"input": "2 3\n4 4",
"outpu... | 0 | 0 | -1 | 94,785 |
50 | Happy Farm 5 | [
"geometry"
] | C. Happy Farm 5 | 2 | 256 | The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them.
For that a young player Vasya decided to make the shepherd run round the cows a... | The first line contains an integer *N* which represents the number of cows in the herd (1<=≤<=*N*<=≤<=105). Each of the next *N* lines contains two integers *X**i* and *Y**i* which represent the coordinates of one cow of (|*X**i*|,<=|*Y**i*|<=≤<=106). Several cows can stand on one point. | Print the single number — the minimum number of moves in the sought path. | [
"4\n1 1\n5 1\n5 3\n1 3\n"
] | [
"16\n"
] | Picture for the example test: The coordinate grid is painted grey, the coordinates axes are painted black, the cows are painted red and the sought route is painted green. | [
{
"input": "4\n1 1\n5 1\n5 3\n1 3",
"output": "16"
},
{
"input": "3\n0 0\n5 0\n0 5",
"output": "19"
},
{
"input": "5\n0 0\n7 7\n7 5\n5 7\n1 1",
"output": "22"
},
{
"input": "5\n1 0\n-1 0\n1 0\n-1 0\n0 0",
"output": "8"
},
{
"input": "9\n1 0\n-1 0\n1 0\n-1 0\n0 0\n... | 2,000 | 43,315,200 | 0 | 94,852 |
469 | Chat Online | [
"implementation"
] | null | null | Little X and Little Z are good friends. They always chat online. But both of them have schedules.
Little Z has fixed schedule. He always online at any moment of time between *a*1 and *b*1, between *a*2 and *b*2, ..., between *a**p* and *b**p* (all borders inclusive). But the schedule of Little X is quite strange, it d... | The first line contains four space-separated integers *p*,<=*q*,<=*l*,<=*r* (1<=≤<=<=*p*,<=*q*<=≤<=50; 0<=≤<=*l*<=≤<=*r*<=≤<=1000).
Each of the next *p* lines contains two space-separated integers *a**i*,<=*b**i* (0<=≤<=*a**i*<=<<=*b**i*<=≤<=1000). Each of the next *q* lines contains two space-separated integers *c... | Output a single integer — the number of moments of time from the segment [*l*,<=*r*] which suit for online conversation. | [
"1 1 0 4\n2 3\n0 1\n",
"2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17\n"
] | [
"3\n",
"20\n"
] | none | [
{
"input": "1 1 0 4\n2 3\n0 1",
"output": "3"
},
{
"input": "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17",
"output": "20"
},
{
"input": "5 2 27 452\n148 154\n421 427\n462 470\n777 786\n969 978\n245 247\n313 322",
"output": "54"
},
{
"input": "3 6 25 785\n273 275\n391 397\n775 78... | 77 | 2,969,600 | 3 | 94,879 | |
237 | T-decomposition | [
"dfs and similar",
"graphs",
"greedy",
"trees"
] | null | null | You've got a undirected tree *s*, consisting of *n* nodes. Your task is to build an optimal T-decomposition for it. Let's define a T-decomposition as follows.
Let's denote the set of all nodes *s* as *v*. Let's consider an undirected tree *t*, whose nodes are some non-empty subsets of *v*, we'll call them *x**i* . The... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105), that denotes the number of nodes in tree *s*.
Each of the following *n*<=-<=1 lines contains two space-separated integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*), denoting that the nodes of tree *s* with indices *a**i* and *b*... | In the first line print a single integer *m* that denotes the number of nodes in the required T-decomposition.
Then print *m* lines, containing descriptions of the T-decomposition nodes. In the *i*-th (1<=≤<=*i*<=≤<=*m*) of them print the description of node *x**i* of the T-decomposition. The description of each node ... | [
"2\n1 2\n",
"3\n1 2\n2 3\n",
"4\n2 1\n3 1\n4 1\n"
] | [
"1\n2 1 2\n",
"2\n2 1 2\n2 2 3\n1 2\n",
"3\n2 2 1\n2 3 1\n2 4 1\n1 2\n2 3\n"
] | none | [
{
"input": "2\n1 2",
"output": "1\n2 1 2"
},
{
"input": "3\n1 2\n2 3",
"output": "2\n2 1 2\n2 2 3\n1 2"
},
{
"input": "4\n2 1\n3 1\n4 1",
"output": "3\n2 2 1\n2 3 1\n2 4 1\n1 2\n2 3"
},
{
"input": "6\n2 5\n4 3\n4 2\n4 6\n3 1",
"output": "5\n2 2 5\n2 4 3\n2 4 2\n2 4 6\n2 3... | 92 | 0 | 0 | 95,045 | |
40 | Berland Square | [
"implementation",
"math"
] | C. Berland Square | 2 | 256 | Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1,<=2,<=...,<=*K* and the cen... | The first line contains integers *N*,<=*x*,<=*M*,<=*y*. (1<=≤<=*N*,<=*M*<=≤<=100000,<=<=-<=100000<=≤<=*x*,<=*y*<=≤<=100000,<=*x*<=≠<=*y*). | Print the sought number of parts. | [
"1 0 1 1\n",
"1 0 1 2\n",
"3 3 4 7\n"
] | [
"4\n",
"3\n",
"17\n"
] | Picture for the third sample: | [
{
"input": "1 0 1 1",
"output": "4"
},
{
"input": "1 0 1 2",
"output": "3"
},
{
"input": "3 3 4 7",
"output": "17"
},
{
"input": "2 2 2 3",
"output": "8"
},
{
"input": "1 100000 1 99999",
"output": "4"
},
{
"input": "4 7 3 3",
"output": "17"
},
... | 186 | 0 | 0 | 95,291 |
722 | Cyclic Cipher | [
"chinese remainder theorem",
"data structures",
"implementation",
"number theory",
"two pointers"
] | null | null | You are given *n* sequences. Each sequence consists of positive integers, not exceeding *m*. All integers in one sequence are distinct, but the same integer may appear in multiple sequences. The length of the *i*-th sequence is *k**i*.
Each second integers in each of the sequences are shifted by one to the left, i.e. ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — the number of sequences and the maximum integer that can appear in the sequences.
Then follow *n* lines providing the sequences. Each of them starts with an integer *k**i* (1<=≤<=*k**i*<=≤<=40) — the number of integers in t... | Print *m* integers, the *i*-th of them should be equal to the length of the longest segment of the array with all its values equal to *i* during the first 10100 seconds. | [
"3 4\n3 3 4 1\n4 1 3 4 2\n3 3 1 4\n",
"5 5\n2 3 1\n4 5 1 3 2\n4 2 1 3 5\n1 3\n2 5 3\n",
"4 6\n3 4 5 3\n2 6 3\n2 3 6\n3 3 6 5\n"
] | [
"2\n1\n3\n2\n",
"3\n1\n4\n0\n1\n",
"0\n0\n2\n1\n1\n2\n"
] | none | [
{
"input": "3 4\n3 3 4 1\n4 1 3 4 2\n3 3 1 4",
"output": "2\n1\n3\n2"
},
{
"input": "5 5\n2 3 1\n4 5 1 3 2\n4 2 1 3 5\n1 3\n2 5 3",
"output": "3\n1\n4\n0\n1"
},
{
"input": "4 6\n3 4 5 3\n2 6 3\n2 3 6\n3 3 6 5",
"output": "0\n0\n2\n1\n1\n2"
},
{
"input": "10 5\n2 2 4\n2 4 5\n2... | 2,000 | 11,264,000 | 0 | 95,368 | |
59 | Team Arrangement | [
"constructive algorithms",
"greedy",
"implementation"
] | D. Team Arrangement | 3 | 256 | Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3*n*, and... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) which is the number of resulting teams. The second line contains 3*n* space-separated integers from 1 to 3*n* which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once.
Then follow *n* lines ea... | Print 3*n*<=-<=1 numbers — the lexicographically smallest list of priorities for the student number *k*.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The list *a* is lexicographically less that the list *b* if exists such an *i* (1<=≤<=*i*<=≤<=3*n*), that ... | [
"3\n5 4 1 2 6 3 7 8 9\n5 6 2\n9 3 4\n1 7 8\n4\n",
"3\n5 4 1 2 6 3 7 8 9\n5 6 2\n9 3 4\n1 7 8\n8\n",
"2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n4\n"
] | [
"2 3 5 6 9 1 7 8 ",
"1 2 3 4 5 6 7 9 ",
"5 6 1 2 3 "
] | none | [] | 124 | 0 | 0 | 95,672 |
154 | Double Profiles | [
"graphs",
"hashing",
"sortings"
] | null | null | You have been offered a job in a company developing a large social network. Your first task is connected with searching profiles that most probably belong to the same user.
The social network contains *n* registered profiles, numbered from 1 to *n*. Some pairs there are friends (the "friendship" relationship is mutual... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=106, 0<=≤<=*m*<=≤<=106), — the number of profiles and the number of pairs of friends, correspondingly.
Next *m* lines contains descriptions of pairs of friends in the format "*v* *u*", where *v* and *u* (1<=≤<=*v*,<=*u*<=≤<=*n*,<=*v*<=≠<=... | Print the single integer — the number of unordered pairs of profiles that are doubles.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator. | [
"3 3\n1 2\n2 3\n1 3\n",
"3 0\n",
"4 1\n1 3\n"
] | [
"3\n",
"3\n",
"2\n"
] | In the first and second sample any two profiles are doubles.
In the third sample the doubles are pairs of profiles (1, 3) and (2, 4). | [
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "3"
},
{
"input": "3 0",
"output": "3"
},
{
"input": "4 1\n1 3",
"output": "2"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "2 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"in... | 124 | 0 | -1 | 96,038 | |
377 | Developing Game | [
"data structures"
] | null | null | Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired *n* workers of staff. Now he wants to pick *n* workers from the staff who will be directly responsible for developing a game.
Each worker has a certain skill level *v**i*. Beside... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of workers Pavel hired.
Each of the following *n* lines contains three space-separated integers *l**i*, *v**i*, *r**i* (1<=≤<=*l**i*<=≤<=*v**i*<=≤<=*r**i*<=≤<=3·105) — the minimum skill value of the workers that the *i*-th worker can work wi... | In the first line print a single integer *m* — the number of workers Pavel must pick for developing the game.
In the next line print *m* space-separated integers — the numbers of the workers in any order.
If there are multiple optimal solutions, print any of them. | [
"4\n2 8 9\n1 4 7\n3 6 8\n5 8 10\n",
"6\n3 5 16\n1 6 11\n4 8 12\n7 9 16\n2 10 14\n8 13 15\n"
] | [
"3\n1 3 4\n",
"4\n1 2 3 5\n"
] | none | [
{
"input": "4\n2 8 9\n1 4 7\n3 6 8\n5 8 10",
"output": "3\n1 3 4"
},
{
"input": "6\n3 5 16\n1 6 11\n4 8 12\n7 9 16\n2 10 14\n8 13 15",
"output": "4\n1 2 3 5"
},
{
"input": "1\n299998 299999 300000",
"output": "1\n1"
},
{
"input": "2\n1 3 6\n2 4 5",
"output": "2\n1 2"
},... | 139 | 307,200 | 0 | 96,068 | |
630 | Pyramids | [
"geometry",
"math"
] | null | null | IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of co... | The only line of the input contains three integers *l*3,<=*l*4,<=*l*5 (1<=≤<=*l*3,<=*l*4,<=*l*5<=≤<=1000) — the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly. | Output one number — the total volume of the pyramids. Absolute or relative error should not be greater than 10<=-<=9. | [
"2 5 3\n"
] | [
"38.546168065709"
] | none | [
{
"input": "2 5 3",
"output": "38.546168065709"
},
{
"input": "3 4 5",
"output": "55.954779230131"
},
{
"input": "1 1 1",
"output": "0.655056222989"
},
{
"input": "1000 1000 1000",
"output": "655056222.989098310000"
},
{
"input": "999 997 998",
"output": "6507... | 46 | 0 | 0 | 96,258 | |
291 | Network Mask | [
"*special",
"bitmasks",
"brute force",
"implementation"
] | null | null | The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively.
Polycarpus has found a job, he is a system administrator. One day he came across *n* IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separ... | The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the number of IP addresses and networks. The next *n* lines contain the IP addresses. It is guaranteed that all IP addresses are distinct. | In a single line print the IP address of the subnet mask in the format that is described in the statement, if the required subnet mask exists. Otherwise, print -1. | [
"5 3\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3\n",
"5 2\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3\n",
"2 1\n255.0.0.1\n0.0.0.2\n"
] | [
"255.255.254.0",
"255.255.0.0",
"-1\n"
] | none | [
{
"input": "5 3\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3",
"output": "255.255.254.0"
},
{
"input": "5 2\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3",
"output": "255.255.0.0"
},
{
"input": "2 1\n255.0.0.1\n0.0.0.2",
"output": "-1"
},
{
"input": "10 2\n57.11.146.42\n200.13... | 31 | 0 | 0 | 96,378 | |
468 | Permanent | [
"dp",
"graph matchings",
"math",
"meet-in-the-middle"
] | null | null | Little X has solved the #P-complete problem in polynomial time recently. So he gives this task to you.
There is a special *n*<=×<=*n* matrix *A*, you should calculate its permanent modulo 1000000007 (109<=+<=7). The special property of matrix *A* is almost all its elements equal to 1. Only *k* elements have specified... | The first line contains two space-separated integers *n*,<=*k* (1<=≤<=*n*<=≤<=105; 1<=≤<=*k*<=≤<=50).
The next *k* lines contain the description of the matrix. The *i*-th line contains three space-separated integers *x**i*,<=*y**i*,<=*w**i* (1<=≤<=*x**i*,<=<=*y**i*<=≤<=<=*n*; 0<=<=≤<=<=*w**i*<=<=≤<=109). These numbers... | Print the permanent of the matrix modulo 1000000007 (109<=<=+<=<=7). | [
"3 1\n1 1 2\n",
"10 10\n3 3 367056794\n6 2 124561273\n1 3 46718146\n6 9 415916869\n10 5 985968336\n3 1 526792265\n1 4 386357058\n10 4 349304187\n2 7 102032499\n3 6 502679075\n"
] | [
"8\n",
"233333333\n"
] | none | [] | 15 | 0 | 0 | 96,841 | |
992 | Nastya and King-Shamans | [
"binary search",
"data structures"
] | null | null | Nastya likes reading and even spends whole days in a library sometimes. Today she found a chronicle of Byteland in the library, and it stated that there lived shamans long time ago. It is known that at every moment there was exactly one shaman in Byteland, and there were *n* shamans in total enumerated with integers fr... | The first line contains two integers *n* and *q* (1<=≤<=*n*,<=*q*<=≤<=2·105).
The second line contains *n* integers *a*1,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109), where *a**i* is the magic power of the *i*-th shaman.
After that *q* lines follow, the *i*-th of them contains two integers *p**i* and *x**i* (1<=≤<=*p**i*<=≤... | Print *q* lines, the *i*-th of them should contain <=-<=1, if after the *i*-th change there are no shaman-kings, and otherwise a single integer *j*, where *j* is an index of some king-shaman after the *i*-th change.
If there are multiple king-shamans after each change, print the index of any of them. | [
"2 1\n1 3\n1 2\n",
"3 4\n2 2 3\n1 1\n1 2\n2 4\n3 6\n",
"10 7\n0 3 1 4 6 2 7 8 10 1\n2 5\n1 3\n9 36\n4 10\n4 9\n1 2\n1 0\n"
] | [
"-1\n",
"3\n2\n-1\n3\n",
"1\n-1\n9\n-1\n4\n-1\n1\n"
] | In the first example powers of shamans after the first change are equal to (2, 3). The answer equals - 1, because the sum of powers of shamans before the first shaman is equal to 0, and before the second is equal to 2.
In the second example after the first change the powers are equal to (1, 2, 3). The answer is equal... | [
{
"input": "2 1\n1 3\n1 2",
"output": "-1"
},
{
"input": "3 4\n2 2 3\n1 1\n1 2\n2 4\n3 6",
"output": "3\n2\n-1\n3"
},
{
"input": "10 7\n0 3 1 4 6 2 7 8 10 1\n2 5\n1 3\n9 36\n4 10\n4 9\n1 2\n1 0",
"output": "1\n-1\n9\n-1\n4\n-1\n1"
},
{
"input": "21 21\n10733833 40401599 15143... | 3,000 | 0 | 0 | 96,860 | |
453 | Little Pony and Summer Sun Celebration | [
"constructive algorithms",
"dfs and similar",
"graphs"
] | null | null | Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Celebration after one thousand years of imprisonment on the moon. She tried to warn her mentor Princess Celestia, but the princess ignored her and sent her to Ponyville to check on the preparations for the celebration.
Twi... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105; 0<=≤<=*m*<=≤<=105) — the number of places and the number of roads in Ponyville. Each of the following *m* lines contains two integers *u**i*,<=*v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*), these integers describe a road between places *u*... | Output the number of visited places *k* in the first line (0<=≤<=*k*<=≤<=4*n*). Then output *k* integers — the numbers of places in the order of path. If *x**i*<==<=0, then the *i*-th place must appear in the path even number of times, else *i*-th place must appear in the path odd number of times. Note, that given road... | [
"3 2\n1 2\n2 3\n1 1 1\n",
"5 7\n1 2\n1 3\n1 4\n1 5\n3 4\n3 5\n4 5\n0 1 0 1 0\n",
"2 0\n0 0\n"
] | [
"3\n1 2 3\n",
"10\n2 1 3 4 5 4 5 4 3 1 ",
"0\n"
] | none | [
{
"input": "3 2\n1 2\n2 3\n1 1 1",
"output": "3\n1 2 3"
},
{
"input": "5 7\n1 2\n1 3\n1 4\n1 5\n3 4\n3 5\n4 5\n0 1 0 1 0",
"output": "10\n2 1 3 4 5 4 5 4 3 1 "
},
{
"input": "2 0\n0 0",
"output": "0"
},
{
"input": "10 10\n2 1\n2 3\n4 2\n4 5\n3 6\n5 7\n8 4\n4 9\n5 10\n4 7\n0 0... | 93 | 0 | 0 | 97,159 | |
15 | Map | [
"data structures",
"implementation",
"sortings"
] | D. Map | 2 | 128 | There is an area map that is a rectangular matrix *n*<=×<=*m*, each cell of the matrix contains the average height of a corresponding area part. Peter works for a company that has to build several cities within this area, each of the cities will occupy a rectangle *a*<=×<=*b* cells on the map. To start construction wor... | The first line contains four space-separated integers: map sizes *n*, *m* and city sizes *a*, *b* (1<=≤<=*a*<=≤<=*n*<=≤<=1000, 1<=≤<=*b*<=≤<=*m*<=≤<=1000). Then there follow *n* lines, each contains *m* non-negative space-separated numbers, describing the height matrix. Each number doesn't exceed 109. | In the first line output *k* — the amount of constructed cities. In each of the following *k* lines output 3 space-separated numbers — the row number and the column number of the upper-left corner of a subsequent construction site, and the amount of the ground to remove from it. Output the sites in the order of their b... | [
"2 2 1 2\n1 2\n3 5\n",
"4 4 2 2\n1 5 3 4\n2 7 6 1\n1 1 2 2\n2 2 1 2\n"
] | [
"2\n1 1 1\n2 1 2\n",
"3\n3 1 2\n3 3 3\n1 2 9\n"
] | none | [] | 622 | 7,168,000 | 0 | 97,234 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.