contestId
int64 0
1.01k
| name
stringlengths 2
58
| tags
sequencelengths 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
sequencelengths 0
7
| demo-output
sequencelengths 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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
976 | Minimum Binary Number | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use. | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "1"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111",
"output": "10"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "8\n10101010",
"output": "10000"
},
{
"input": "2\n10",
"output": "10"
},
{
"input": "3\n111",
"output": "1"
},
{
"input": "5\n11100",
"output": "100"
},
{
"input": "2\n11",
"output": "1"
},
{
"input": "3\n110",
"output": "10"
},
{
"input": "50\n10010010000000000000000000000000000000001000000000",
"output": "10000000000000000000000000000000000000000000000"
}
] | 31 | 0 | 0 | 238 |
|
351 | Jeff and Permutation | [
"greedy"
] | null | null | Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence *p*1,<=*p*2,<=...,<=*p**n* for his birthday.
Jeff hates inversions in sequences. An inversion in sequence *a*1,<=*a*2,<=...,<=*a**n* is a pair of indexes *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*), such that an inequality *a**i*<=><=*a**j* holds.
Jeff can multiply some numbers of the sequence *p* by -1. At that, he wants the number of inversions in the sequence to be minimum. Help Jeff and find the minimum number of inversions he manages to get. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000). The next line contains *n* integers — sequence *p*1, *p*2, ..., *p**n* (|*p**i*|<=≤<=105). The numbers are separated by spaces. | In a single line print the answer to the problem — the minimum number of inversions Jeff can get. | [
"2\n2 1\n",
"9\n-2 0 -1 0 -1 2 1 0 -1\n"
] | [
"0\n",
"6\n"
] | none | [
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "9\n-2 0 -1 0 -1 2 1 0 -1",
"output": "6"
},
{
"input": "9\n0 0 1 1 0 0 1 0 1",
"output": "5"
},
{
"input": "8\n0 1 2 -1 -2 1 -2 2",
"output": "3"
},
{
"input": "24\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2",
"output": "55"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "31\n-2 2 -2 -1 0 0 1 2 1 1 -1 -2 1 -1 -2 2 0 1 -1 -2 -1 -2 -1 2 2 2 2 1 1 0 1",
"output": "74"
},
{
"input": "9\n1 -1 -1 0 -1 0 1 1 1",
"output": "1"
},
{
"input": "5\n1 0 1 -2 1",
"output": "1"
},
{
"input": "31\n-5 -5 5 3 -1 3 1 -3 -3 -1 -5 -3 -2 -4 -3 3 5 -2 1 0 -1 1 -3 1 -1 1 3 3 2 1 0",
"output": "70"
},
{
"input": "53\n-3 2 -3 -5 -2 7 0 -2 1 6 -1 2 5 -3 3 -6 -2 -5 -3 -6 4 -4 -2 6 1 -7 -6 -4 0 2 -5 -1 -2 -6 2 2 7 -2 -3 1 0 -4 3 4 -2 7 -3 7 7 3 -5 -5 3",
"output": "289"
},
{
"input": "24\n-3 -4 3 -3 3 2 -1 -3 -4 0 -4 0 2 3 3 -1 2 1 2 -2 3 -2 1 0",
"output": "46"
},
{
"input": "50\n-6 1 -3 7 -5 -5 4 0 3 -5 1 2 -1 0 7 0 6 3 -5 4 4 3 -7 -1 4 4 -5 3 7 1 4 2 6 -4 0 3 -3 -2 -3 1 -5 3 -4 2 -2 7 -1 3 -7 4",
"output": "260"
},
{
"input": "17\n-56007 -97423 -66458 -17041 49374 60662 42188 56222 28689 -4117 -1712 11034 17161 43908 -65064 -76642 -73934",
"output": "13"
},
{
"input": "12\n0 1 0 1 1 -1 1 -1 0 1 0 -1",
"output": "12"
}
] | 124 | 7,065,600 | 0 | 239 |
|
409 | Big Data | [
"*special"
] | null | null | Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts:
- The highest mountain above sea level in the world is Mount Everest. Its peak rises to 8848 m. - The largest board game tournament consisted of 958 participants playing chapaev.- The largest online maths competition consisted of 12766 participants.- The Nile is credited as the longest river in the world. From its farthest stream in Burundi, it extends 6695 km in length.- While not in flood, the main stretches of the Amazon river in South America can reach widths of up to 1100 km at its widest points.- Angel Falls is the highest waterfall. Its greatest single drop measures 807 m.- The Hotel Everest View above Namche, Nepal — the village closest to Everest base camp – is at a record height of 31962 m- Uranium is the heaviest of all the naturally occurring elements. Its most common isotope has a nucleus containing 146 neutrons.- The coldest permanently inhabited place is the Siberian village of Oymyakon, where the temperature of -68°C was registered in the twentieth century.- The longest snake held in captivity is over 25 feet long. Its name is Medusa.- Colonel Meow holds the world record for longest fur on a cat — almost 134 centimeters.- Sea otters can have up to 10000 hairs per square inch. This is the most dense fur in the animal kingdom.- The largest state of USA is Alaska; its area is 663268 square miles- Alaska has a longer coastline than all of the other 49 U.S. States put together: it is 154103 miles long.- Lake Baikal is the largest freshwater lake in the world. It reaches 1642 meters in depth and contains around one-fifth of the world’s unfrozen fresh water.- The most colorful national flag is the one of Turkmenistan, with 106 colors. | The input will contain a single integer between 1 and 16. | Output a single integer. | [
"1\n",
"7\n"
] | [
"1\n",
"0\n"
] | none | [
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "0"
},
{
"input": "13",
"output": "1"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "16",
"output": "0"
},
{
"input": "11",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "15",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "12",
"output": "0"
},
{
"input": "6",
"output": "1"
},
{
"input": "14",
"output": "0"
}
] | 77 | 0 | 3 | 240 |
|
518 | Tanya and Postcard | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s*. The newspaper contains string *t*, consisting of uppercase and lowercase English letters. We know that the length of string *t* greater or equal to the length of the string *s*.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some *n* letters out of the newspaper and make a message of length exactly *n*, so that it looked as much as possible like *s*. If the letter in some position has correct value and correct letter case (in the string *s* and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message. | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the length of the string *a*. | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "0 26"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nqrsimtabuvzhnwcdefgjklxyop",
"output": "26 0"
},
{
"input": "l\nFPbAVjsMpPDTLkfwNYFmBDHPTDSWSOUlrBHYJHPM",
"output": "1 0"
},
{
"input": "ncMeXssLHS\nuwyeMcaFatpInZVdEYpwJQSnVxLK",
"output": "6 1"
},
{
"input": "DpiNBmCRFWxpdbfGOzvvOcemjructoAdEwegTvbVbfWWRPGyEAxGdDRWVlqNyGWMWHMrHAIZpyxvgaflrsVZhhZRouvpxrKXFZam\nwwPLFtNfPtJXvMLuHjKfYyaRhreNSWSzOvDpqHCGcqllACNPGHxReeFUCmAqIKXYytsSQwIxJzNiiUtgebVuwRmWpRALLyKAzyDPvgIGxALSaeeTIqm",
"output": "66 12"
},
{
"input": "CCAE\ndcecc",
"output": "0 3"
},
{
"input": "Dccb\nbeeeb",
"output": "1 0"
},
{
"input": "Adc\neadeabcad",
"output": "2 1"
},
{
"input": "DBAdeb\ndeeabcddadaa",
"output": "3 2"
},
{
"input": "EDCED\neebeacdba",
"output": "0 4"
},
{
"input": "CdAbD\ndecbde",
"output": "2 2"
},
{
"input": "a\nB",
"output": "0 0"
},
{
"input": "r\nqA",
"output": "0 0"
}
] | 124 | 21,401,600 | 0 | 241 |
|
727 | Guess the Array | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In this problem you should guess an array *a* which is unknown for you. The only information you have initially is the length *n* of the array *a*.
The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices *i* and *j* (the indices should be distinct). Then your program should read the response: the single integer equals to *a**i*<=+<=*a**j*.
It is easy to prove that it is always possible to guess the array using at most *n* requests.
Write a program that will guess the array *a* by making at most *n* requests. | none | none | [
"5\n \n9\n \n7\n \n9\n \n11\n \n6\n "
] | [
"? 1 5\n \n? 2 3\n \n? 4 1\n \n? 5 2\n \n? 3 4\n \n! 4 6 1 5 5"
] | The format of a test to make a hack is:
- The first line contains an integer number *n* (3 ≤ *n* ≤ 5000) — the length of the array.- The second line contains *n* numbers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>) — the elements of the array to guess. | [
{
"input": "5\n4 6 1 5 5",
"output": "5 out of 5"
},
{
"input": "3\n1 1 1",
"output": "3 out of 3"
},
{
"input": "4\n100 1 100 1",
"output": "4 out of 4"
},
{
"input": "10\n9 5 10 7 4 4 8 5 10 5",
"output": "10 out of 10"
},
{
"input": "3\n1 1 1",
"output": "3 out of 3"
},
{
"input": "3\n100000 100000 100000",
"output": "3 out of 3"
},
{
"input": "3\n91906 50782 19777",
"output": "3 out of 3"
},
{
"input": "15\n5 10 10 7 7 6 4 6 8 10 8 4 10 9 4",
"output": "15 out of 15"
},
{
"input": "30\n2 3 3 4 3 2 4 4 4 3 3 2 4 2 3 4 4 2 4 3 4 2 2 4 3 3 4 4 4 4",
"output": "30 out of 30"
},
{
"input": "35\n4 2 2 2 4 4 3 2 4 2 2 4 2 2 3 2 3 4 4 2 3 2 2 4 3 3 3 3 4 2 3 2 2 2 3",
"output": "35 out of 35"
},
{
"input": "40\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "40 out of 40"
},
{
"input": "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "47 out of 47"
},
{
"input": "100\n76 92 53 18 65 98 100 65 93 72 100 44 70 62 78 61 89 89 80 32 88 64 67 27 46 30 75 14 78 94 8 86 41 9 68 38 76 29 69 44 23 23 14 24 97 14 7 98 45 80 55 71 58 35 41 100 60 54 64 85 56 98 87 93 40 62 92 6 7 27 88 85 10 94 25 43 99 65 82 65 39 34 17 100 49 27 4 15 84 10 35 76 98 52 72 17 43 10 49 5",
"output": "100 out of 100"
}
] | 0 | 0 | -1 | 242 |
|
743 | Chloe and the sequence | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (*n*<=-<=1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,<=2,<=1] after the first step, the sequence [1,<=2,<=1,<=3,<=1,<=2,<=1] after the second step.
The task is to find the value of the element with index *k* (the elements are numbered from 1) in the obtained sequence, i. e. after (*n*<=-<=1) steps.
Please help Chloe to solve the problem! | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 671088640",
"output": "28"
},
{
"input": "38 137438953472",
"output": "38"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "3 3",
"output": "1"
},
{
"input": "4 12",
"output": "3"
},
{
"input": "8 224",
"output": "6"
},
{
"input": "13 1368",
"output": "4"
},
{
"input": "16 49152",
"output": "15"
},
{
"input": "19 1024",
"output": "11"
},
{
"input": "24 15204352",
"output": "20"
},
{
"input": "27 6586544",
"output": "5"
},
{
"input": "31 536870912",
"output": "30"
},
{
"input": "38 94489280512",
"output": "34"
},
{
"input": "42 215268308020",
"output": "3"
},
{
"input": "42 3452074721280",
"output": "21"
},
{
"input": "46 34394312982528",
"output": "15"
},
{
"input": "48 133865540681728",
"output": "39"
},
{
"input": "49 76541041985542",
"output": "2"
},
{
"input": "49 104822971826176",
"output": "34"
},
{
"input": "49 351843720888320",
"output": "47"
},
{
"input": "50 743042492421629",
"output": "1"
},
{
"input": "50 666266740436818",
"output": "2"
},
{
"input": "50 704239287953456",
"output": "5"
},
{
"input": "50 116938486513664",
"output": "17"
},
{
"input": "50 806423059496960",
"output": "37"
},
{
"input": "50 985162418487296",
"output": "48"
},
{
"input": "50 844424930131968",
"output": "49"
},
{
"input": "50 562949953421312",
"output": "50"
},
{
"input": "50 1",
"output": "1"
},
{
"input": "50 1125899906842623",
"output": "1"
},
{
"input": "50 1125899906842620",
"output": "3"
},
{
"input": "39 549755813887",
"output": "1"
},
{
"input": "50 100000000000",
"output": "12"
}
] | 93 | 0 | 0 | 243 |
|
985 | Liebig's Barrels | [
"greedy"
] | null | null | You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above. | The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves. | Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*. | [
"4 2 1\n2 2 1 2 3 2 2 3\n",
"2 1 0\n10 10\n",
"1 2 1\n5 2\n",
"3 2 1\n1 2 3 4 5 6\n"
] | [
"7\n",
"20\n",
"2\n",
"0\n"
] | In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough. | [
{
"input": "4 2 1\n2 2 1 2 3 2 2 3",
"output": "7"
},
{
"input": "2 1 0\n10 10",
"output": "20"
},
{
"input": "1 2 1\n5 2",
"output": "2"
},
{
"input": "3 2 1\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 447 89 983 964 716 32 890 267 164 654 71",
"output": "0"
},
{
"input": "10 3 453\n277 706 727 812 692 686 196 507 911 40 498 704 573 381 463 759 704 381 693 640 326 405 47 834 962 521 463 740 520 494",
"output": "2979"
},
{
"input": "10 3 795\n398 962 417 307 760 534 536 450 421 280 608 111 687 726 941 903 630 900 555 403 795 122 814 188 234 976 679 539 525 104",
"output": "5045"
},
{
"input": "6 2 29\n1 2 3 3 4 5 5 6 7 7 8 9",
"output": "28"
},
{
"input": "2 1 2\n1 2",
"output": "3"
}
] | 155 | 7,782,400 | 0 | 244 |
|
408 | Line to Cashier | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has. | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue. | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3",
"output": "125"
},
{
"input": "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5",
"output": "480"
},
{
"input": "10\n9 10 10 10 9 5 9 7 8 7\n11 6 10 4 4 15 7 15 5\n3 9 11 12 11 1 13 13 1 5\n6 15 9 12 3 2 8 12 11 10\n7 1 1 6 10 2 6 1 14 2\n8 14 2 3 6 1 14 1 12\n6 10 9 3 5\n13 12 12 7 13 4 4 8 10\n5 6 4 3 14 9 13\n8 12 1 5 7 4 13 1\n1 9 5 3 5 1 4",
"output": "240"
},
{
"input": "10\n5 5 5 5 5 5 5 5 5 5\n5 5 4 5 4\n6 5 7 7 6\n5 4 4 5 5\n4 4 5 5 5\n7 6 4 5 7\n4 6 5 4 5\n6 6 7 6 6\n4 5 4 4 7\n7 5 4 4 5\n6 6 7 4 4",
"output": "190"
},
{
"input": "1\n1\n100",
"output": "515"
},
{
"input": "1\n90\n90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90",
"output": "41850"
}
] | 140 | 1,536,000 | 3 | 245 |
|
347 | Fixed Points | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34 73 29 70 83 58 79 82 28 77 67",
"output": "3"
},
{
"input": "3\n0 1 2",
"output": "3"
},
{
"input": "3\n2 1 0",
"output": "3"
},
{
"input": "3\n1 2 0",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 1 2 3 4",
"output": "5"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "7\n0 1 2 4 3 6 5",
"output": "5"
},
{
"input": "6\n0 1 2 3 5 4",
"output": "6"
}
] | 2,000 | 13,107,200 | 0 | 246 |
|
645 | Amity Assessment | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed. | The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position. | Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes). | [
"AB\nXC\nXB\nAC\n",
"AB\nXC\nAC\nBX\n"
] | [
"YES\n",
"NO\n"
] | The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all... | [
{
"input": "AB\nXC\nXB\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nAC\nBX",
"output": "NO"
},
{
"input": "XC\nBA\nCB\nAX",
"output": "NO"
},
{
"input": "AB\nXC\nAX\nCB",
"output": "YES"
},
{
"input": "CB\nAX\nXA\nBC",
"output": "YES"
},
{
"input": "BC\nXA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nXB\nBA\nCX",
"output": "NO"
},
{
"input": "CA\nXB\nAC\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nCB\nBC\nXA",
"output": "YES"
},
{
"input": "CA\nXB\nBA\nXC",
"output": "NO"
},
{
"input": "CX\nAB\nAX\nCB",
"output": "NO"
},
{
"input": "AB\nXC\nAB\nCX",
"output": "YES"
},
{
"input": "XC\nBA\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nXC\nAC\nXB",
"output": "YES"
},
{
"input": "AX\nBC\nAC\nBX",
"output": "YES"
},
{
"input": "XC\nBA\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nXC\nBA",
"output": "NO"
},
{
"input": "AX\nCB\nBC\nAX",
"output": "YES"
},
{
"input": "AB\nXC\nBX\nAC",
"output": "YES"
},
{
"input": "XA\nCB\nBA\nCX",
"output": "NO"
},
{
"input": "CX\nBA\nBX\nAC",
"output": "YES"
},
{
"input": "AB\nXC\nXC\nAB",
"output": "NO"
},
{
"input": "BA\nCX\nAC\nBX",
"output": "YES"
},
{
"input": "XA\nCB\nAB\nXC",
"output": "YES"
},
{
"input": "XC\nBA\nAC\nBX",
"output": "NO"
},
{
"input": "CA\nBX\nBA\nXC",
"output": "NO"
},
{
"input": "AX\nBC\nCA\nXB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nBX\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nAX\nBC",
"output": "NO"
},
{
"input": "XB\nCA\nXC\nBA",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nCA",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nAB",
"output": "NO"
},
{
"input": "CX\nBA\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nCA\nBX",
"output": "YES"
},
{
"input": "BA\nXC\nBC\nAX",
"output": "NO"
},
{
"input": "AC\nXB\nCX\nBA",
"output": "NO"
},
{
"input": "XB\nCA\nCX\nBA",
"output": "NO"
},
{
"input": "AB\nCX\nXA\nBC",
"output": "NO"
},
{
"input": "CX\nAB\nXB\nAC",
"output": "NO"
},
{
"input": "BC\nAX\nAC\nBX",
"output": "NO"
},
{
"input": "XA\nBC\nCB\nAX",
"output": "YES"
},
{
"input": "XC\nAB\nCB\nAX",
"output": "YES"
},
{
"input": "CX\nBA\nCX\nAB",
"output": "NO"
},
{
"input": "CA\nBX\nXC\nBA",
"output": "YES"
},
{
"input": "CX\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "CA\nBX\nCB\nXA",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nAX",
"output": "NO"
},
{
"input": "CB\nAX\nBC\nXA",
"output": "NO"
},
{
"input": "AC\nXB\nCB\nXA",
"output": "YES"
},
{
"input": "AB\nCX\nXB\nAC",
"output": "YES"
},
{
"input": "CX\nBA\nXB\nAC",
"output": "YES"
},
{
"input": "BX\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "CX\nAB\nXC\nBA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nAB",
"output": "NO"
},
{
"input": "CB\nAX\nXB\nAC",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nXB",
"output": "NO"
},
{
"input": "XC\nBA\nBA\nXC",
"output": "NO"
},
{
"input": "AC\nBX\nCB\nAX",
"output": "YES"
},
{
"input": "CA\nBX\nAC\nXB",
"output": "NO"
},
{
"input": "BX\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "XB\nCA\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nXA\nBC\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nCX\nAB",
"output": "NO"
},
{
"input": "BC\nAX\nXC\nAB",
"output": "NO"
},
{
"input": "XB\nCA\nBC\nXA",
"output": "NO"
},
{
"input": "XB\nAC\nCX\nBA",
"output": "YES"
},
{
"input": "BC\nXA\nCB\nXA",
"output": "NO"
},
{
"input": "AX\nCB\nAX\nBC",
"output": "NO"
},
{
"input": "CA\nBX\nBX\nCA",
"output": "NO"
},
{
"input": "BA\nXC\nXB\nAC",
"output": "NO"
},
{
"input": "XA\nBC\nBX\nAC",
"output": "NO"
},
{
"input": "BX\nCA\nAC\nBX",
"output": "YES"
},
{
"input": "XB\nAC\nXC\nBA",
"output": "YES"
},
{
"input": "XB\nAC\nAB\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nCX\nBA",
"output": "NO"
},
{
"input": "CA\nXB\nXB\nCA",
"output": "NO"
},
{
"input": "BA\nCX\nBA\nXC",
"output": "YES"
},
{
"input": "BA\nCX\nAB\nCX",
"output": "NO"
},
{
"input": "BX\nCA\nXA\nBC",
"output": "YES"
},
{
"input": "XC\nBA\nBX\nCA",
"output": "NO"
},
{
"input": "XC\nAB\nBC\nXA",
"output": "NO"
},
{
"input": "BC\nXA\nXC\nAB",
"output": "NO"
},
{
"input": "BX\nCA\nXB\nAC",
"output": "NO"
},
{
"input": "BA\nXC\nCA\nXB",
"output": "NO"
},
{
"input": "CX\nBA\nAC\nXB",
"output": "NO"
},
{
"input": "AB\nCX\nAC\nBX",
"output": "NO"
},
{
"input": "BC\nXA\nBX\nCA",
"output": "NO"
},
{
"input": "XA\nBC\nCX\nAB",
"output": "YES"
},
{
"input": "AX\nBC\nAX\nCB",
"output": "NO"
},
{
"input": "CB\nAX\nCA\nBX",
"output": "NO"
},
{
"input": "CB\nAX\nBA\nXC",
"output": "YES"
},
{
"input": "AB\nCX\nXC\nBA",
"output": "YES"
},
{
"input": "AC\nXB\nBA\nCX",
"output": "YES"
},
{
"input": "AX\nCB\nCB\nAX",
"output": "NO"
},
{
"input": "CX\nBA\nCA\nXB",
"output": "YES"
},
{
"input": "AC\nBX\nAB\nXC",
"output": "NO"
},
{
"input": "XA\nCB\nXA\nBC",
"output": "NO"
},
{
"input": "XC\nBA\nCA\nBX",
"output": "YES"
},
{
"input": "XA\nBC\nXB\nCA",
"output": "YES"
},
{
"input": "CA\nBX\nCB\nAX",
"output": "NO"
}
] | 61 | 28,364,800 | 0 | 247 |
|
701 | Cells Not Under Attack | [
"data structures",
"math"
] | null | null | Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.
You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the column where Vasya will put the *i*-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook. | Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. | [
"3 3\n1 1\n3 1\n2 2\n",
"5 2\n1 5\n5 1\n",
"100000 1\n300 400\n"
] | [
"4 2 0 \n",
"16 9 \n",
"9999800001 \n"
] | On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | [
{
"input": "3 3\n1 1\n3 1\n2 2",
"output": "4 2 0 "
},
{
"input": "5 2\n1 5\n5 1",
"output": "16 9 "
},
{
"input": "100000 1\n300 400",
"output": "9999800001 "
},
{
"input": "10 4\n2 8\n1 8\n9 8\n6 9",
"output": "81 72 63 48 "
},
{
"input": "30 30\n3 13\n27 23\n18 24\n18 19\n14 20\n7 10\n27 13\n20 27\n11 1\n21 10\n2 9\n28 12\n29 19\n28 27\n27 29\n30 12\n27 2\n4 5\n8 19\n21 2\n24 27\n14 22\n20 3\n18 3\n23 9\n28 6\n15 12\n2 2\n16 27\n1 14",
"output": "841 784 729 702 650 600 600 552 506 484 441 400 380 380 361 342 324 289 272 272 255 240 225 225 210 196 182 182 168 143 "
},
{
"input": "70 31\n22 39\n33 43\n50 27\n70 9\n20 67\n61 24\n60 4\n60 28\n4 25\n30 29\n46 47\n51 48\n37 5\n14 29\n45 44\n68 35\n52 21\n7 37\n18 43\n44 22\n26 12\n39 37\n51 55\n50 23\n51 16\n16 49\n22 62\n35 45\n56 2\n20 51\n3 37",
"output": "4761 4624 4489 4356 4225 4096 3969 3906 3782 3660 3540 3422 3306 3249 3136 3025 2916 2809 2756 2652 2550 2499 2450 2401 2352 2256 2208 2115 2024 1978 1935 "
},
{
"input": "330 17\n259 262\n146 20\n235 69\n84 74\n131 267\n153 101\n32 232\n214 212\n239 157\n121 156\n10 45\n266 78\n52 258\n109 279\n193 276\n239 142\n321 89",
"output": "108241 107584 106929 106276 105625 104976 104329 103684 103041 102400 101761 101124 100489 99856 99225 98910 98282 "
},
{
"input": "500 43\n176 85\n460 171\n233 260\n73 397\n474 35\n290 422\n309 318\n280 415\n485 169\n106 22\n355 129\n180 301\n205 347\n197 93\n263 318\n336 382\n314 350\n476 214\n367 277\n333 166\n500 376\n236 17\n94 73\n116 204\n166 50\n168 218\n144 369\n340 91\n274 360\n171 360\n41 251\n262 478\n27 163\n151 491\n208 415\n448 386\n293 486\n371 479\n330 435\n220 374\n163 316\n155 158\n26 126",
"output": "249001 248004 247009 246016 245025 244036 243049 242064 241081 240100 239121 238144 237169 236196 235710 234740 233772 232806 231842 230880 229920 228962 228006 227052 226100 225150 224202 223256 222312 221840 220899 219960 219023 218088 217620 216688 215758 214830 213904 212980 212058 211138 210220 "
},
{
"input": "99999 1\n54016 16192",
"output": "9999600004 "
},
{
"input": "99991 9\n80814 65974\n12100 98787\n9390 76191\n5628 47659\n80075 25361\n75330 1630\n38758 99962\n33848 40352\n43732 52281",
"output": "9998000100 9997800121 9997600144 9997400169 9997200196 9997000225 9996800256 9996600289 9996400324 "
},
{
"input": "1 1\n1 1",
"output": "0 "
}
] | 405 | 15,052,800 | 3 | 251 |
|
215 | Bicycle Chain | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=<<=*b*1<=<<=*b*2<=<<=...<=<<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value .
Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.
In the problem, fraction denotes division in real numbers, that is, no rounding is performed. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing.
It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces. | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input": "4\n3 7 11 13\n4\n51 119 187 221",
"output": "4"
},
{
"input": "4\n2 3 4 5\n3\n1 2 3",
"output": "2"
},
{
"input": "10\n6 12 13 20 48 53 74 92 96 97\n10\n1 21 32 36 47 54 69 75 95 97",
"output": "1"
},
{
"input": "10\n5 9 10 14 15 17 19 22 24 26\n10\n2 11 17 19 21 22 24 25 27 28",
"output": "1"
},
{
"input": "10\n24 53 56 126 354 432 442 740 795 856\n10\n273 438 494 619 689 711 894 947 954 958",
"output": "1"
},
{
"input": "10\n3 4 6 7 8 10 14 16 19 20\n10\n3 4 5 7 8 10 15 16 18 20",
"output": "1"
},
{
"input": "10\n1 6 8 14 15 17 25 27 34 39\n10\n1 8 16 17 19 22 32 39 44 50",
"output": "1"
},
{
"input": "10\n5 21 22 23 25 32 35 36 38 39\n10\n3 7 8 9 18 21 23 24 36 38",
"output": "4"
},
{
"input": "50\n5 8 13 16 19 20 21 22 24 27 28 29 30 32 33 34 35 43 45 48 50 51 54 55 58 59 60 61 62 65 70 71 72 76 78 79 80 81 83 84 85 87 89 91 92 94 97 98 99 100\n50\n2 3 5 6 7 10 15 16 17 20 23 28 29 30 31 34 36 37 40 42 45 46 48 54 55 56 58 59 61 62 69 70 71 72 75 76 78 82 84 85 86 87 88 89 90 91 92 97 99 100",
"output": "1"
},
{
"input": "50\n3 5 6 8 9 11 13 19 21 23 24 32 34 35 42 50 51 52 56 58 59 69 70 72 73 75 76 77 78 80 83 88 90 95 96 100 101 102 108 109 113 119 124 135 138 141 142 143 145 150\n50\n5 8 10 11 18 19 23 30 35 43 51 53 55 58 63 68 69 71 77 78 79 82 83 86 88 89 91 92 93 94 96 102 103 105 109 110 113 114 116 123 124 126 127 132 133 135 136 137 142 149",
"output": "1"
},
{
"input": "50\n6 16 24 25 27 33 36 40 51 60 62 65 71 72 75 77 85 87 91 93 98 102 103 106 117 118 120 121 122 123 125 131 134 136 143 148 155 157 160 161 164 166 170 178 184 187 188 192 194 197\n50\n5 9 17 23 27 34 40 44 47 59 62 70 81 82 87 88 89 90 98 101 102 110 113 114 115 116 119 122 124 128 130 137 138 140 144 150 152 155 159 164 166 169 171 175 185 186 187 189 190 193",
"output": "1"
},
{
"input": "50\n14 22 23 31 32 35 48 63 76 79 88 97 101 102 103 104 106 113 114 115 116 126 136 138 145 152 155 156 162 170 172 173 179 180 182 203 208 210 212 222 226 229 231 232 235 237 245 246 247 248\n50\n2 5 6 16 28 44 45 46 54 55 56 63 72 80 87 93 94 96 97 100 101 103 132 135 140 160 164 165 167 168 173 180 182 185 186 192 194 198 199 202 203 211 213 216 217 227 232 233 236 245",
"output": "1"
},
{
"input": "50\n14 19 33 35 38 41 51 54 69 70 71 73 76 80 84 94 102 104 105 106 107 113 121 128 131 168 180 181 187 191 195 201 205 207 210 216 220 238 249 251 263 271 272 275 281 283 285 286 291 294\n50\n2 3 5 20 21 35 38 40 43 48 49 52 55 64 73 77 82 97 109 113 119 121 125 132 137 139 145 146 149 180 182 197 203 229 234 241 244 251 264 271 274 281 284 285 287 291 292 293 294 298",
"output": "1"
},
{
"input": "50\n2 4 5 16 18 19 22 23 25 26 34 44 48 54 67 79 80 84 92 110 116 133 138 154 163 171 174 202 205 218 228 229 234 245 247 249 250 263 270 272 274 275 277 283 289 310 312 334 339 342\n50\n1 5 17 18 25 37 46 47 48 59 67 75 80 83 84 107 115 122 137 141 159 162 175 180 184 204 221 224 240 243 247 248 249 258 259 260 264 266 269 271 274 293 294 306 329 330 334 335 342 350",
"output": "1"
},
{
"input": "50\n6 9 11 21 28 39 42 56 60 63 81 88 91 95 105 110 117 125 149 165 174 176 185 189 193 196 205 231 233 268 278 279 281 286 289 292 298 303 305 306 334 342 350 353 361 371 372 375 376 378\n50\n6 17 20 43 45 52 58 59 82 83 88 102 111 118 121 131 145 173 190 191 200 216 224 225 232 235 243 256 260 271 290 291 321 322 323 329 331 333 334 341 343 348 351 354 356 360 366 379 387 388",
"output": "1"
},
{
"input": "10\n17 239 443 467 661 1069 1823 2333 3767 4201\n20\n51 83 97 457 593 717 997 1329 1401 1459 1471 1983 2371 2539 3207 3251 3329 5469 6637 6999",
"output": "8"
},
{
"input": "20\n179 359 401 467 521 601 919 941 1103 1279 1709 1913 1949 2003 2099 2143 2179 2213 2399 4673\n20\n151 181 191 251 421 967 1109 1181 1249 1447 1471 1553 1619 2327 2551 2791 3049 3727 6071 7813",
"output": "3"
},
{
"input": "20\n79 113 151 709 809 983 1291 1399 1409 1429 2377 2659 2671 2897 3217 3511 3557 3797 3823 4363\n10\n19 101 659 797 1027 1963 2129 2971 3299 9217",
"output": "3"
},
{
"input": "30\n19 47 109 179 307 331 389 401 461 509 547 569 617 853 883 1249 1361 1381 1511 1723 1741 1783 2459 2531 2621 3533 3821 4091 5557 6217\n20\n401 443 563 941 967 997 1535 1567 1655 1747 1787 1945 1999 2251 2305 2543 2735 4415 6245 7555",
"output": "8"
},
{
"input": "30\n3 43 97 179 257 313 353 359 367 389 397 457 547 599 601 647 1013 1021 1063 1433 1481 1531 1669 3181 3373 3559 3769 4157 4549 5197\n50\n13 15 17 19 29 79 113 193 197 199 215 223 271 293 359 485 487 569 601 683 895 919 941 967 1283 1285 1289 1549 1565 1765 1795 1835 1907 1931 1945 1985 1993 2285 2731 2735 2995 3257 4049 4139 5105 5315 7165 7405 7655 8345",
"output": "20"
},
{
"input": "50\n11 17 23 53 59 109 137 149 173 251 353 379 419 421 439 503 593 607 661 773 821 877 941 997 1061 1117 1153 1229 1289 1297 1321 1609 1747 2311 2389 2543 2693 3041 3083 3137 3181 3209 3331 3373 3617 3767 4201 4409 4931 6379\n50\n55 59 67 73 85 89 101 115 211 263 295 353 545 599 607 685 739 745 997 1031 1255 1493 1523 1667 1709 1895 1949 2161 2195 2965 3019 3035 3305 3361 3373 3673 3739 3865 3881 4231 4253 4385 4985 5305 5585 5765 6145 6445 8045 8735",
"output": "23"
},
{
"input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782",
"output": "3"
},
{
"input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428",
"output": "4"
},
{
"input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959",
"output": "5"
},
{
"input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664",
"output": "24"
},
{
"input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782",
"output": "3"
},
{
"input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428",
"output": "4"
},
{
"input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959",
"output": "5"
},
{
"input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664",
"output": "24"
},
{
"input": "47\n66 262 357 457 513 530 538 540 592 691 707 979 1015 1242 1246 1667 1823 1886 1963 2133 2649 2679 2916 2949 3413 3523 3699 3958 4393 4922 5233 5306 5799 6036 6302 6629 7208 7282 7315 7822 7833 7927 8068 8150 8870 8962 9987\n39\n167 199 360 528 1515 1643 1986 1988 2154 2397 2856 3552 3656 3784 3980 4096 4104 4240 4320 4736 4951 5266 5656 5849 5850 6169 6517 6875 7244 7339 7689 7832 8120 8716 9503 9509 9933 9936 9968",
"output": "12"
},
{
"input": "1\n94\n50\n423 446 485 1214 1468 1507 1853 1930 1999 2258 2271 2285 2425 2543 2715 2743 2992 3196 4074 4108 4448 4475 4652 5057 5250 5312 5356 5375 5731 5986 6298 6501 6521 7146 7255 7276 7332 7481 7998 8141 8413 8665 8908 9221 9336 9491 9504 9677 9693 9706",
"output": "1"
},
{
"input": "50\n51 67 75 186 194 355 512 561 720 876 1077 1221 1503 1820 2153 2385 2568 2608 2937 2969 3271 3311 3481 4081 4093 4171 4255 4256 4829 5020 5192 5636 5817 6156 6712 6717 7153 7436 7608 7612 7866 7988 8264 8293 8867 9311 9879 9882 9889 9908\n1\n5394",
"output": "1"
},
{
"input": "50\n26 367 495 585 675 789 855 1185 1312 1606 2037 2241 2587 2612 2628 2807 2873 2924 3774 4067 4376 4668 4902 5001 5082 5100 5104 5209 5345 5515 5661 5777 5902 5907 6155 6323 6675 6791 7503 8159 8207 8254 8740 8848 8855 8933 9069 9164 9171 9586\n5\n1557 6246 7545 8074 8284",
"output": "1"
},
{
"input": "5\n25 58 91 110 2658\n50\n21 372 909 1172 1517 1554 1797 1802 1843 1977 2006 2025 2137 2225 2317 2507 2645 2754 2919 3024 3202 3212 3267 3852 4374 4487 4553 4668 4883 4911 4916 5016 5021 5068 5104 5162 5683 5856 6374 6871 7333 7531 8099 8135 8173 8215 8462 8776 9433 9790",
"output": "4"
},
{
"input": "45\n37 48 56 59 69 70 79 83 85 86 99 114 131 134 135 145 156 250 1739 1947 2116 2315 2449 3104 3666 4008 4406 4723 4829 5345 5836 6262 6296 6870 7065 7110 7130 7510 7595 8092 8442 8574 9032 9091 9355\n50\n343 846 893 1110 1651 1837 2162 2331 2596 3012 3024 3131 3294 3394 3528 3717 3997 4125 4347 4410 4581 4977 5030 5070 5119 5229 5355 5413 5418 5474 5763 5940 6151 6161 6164 6237 6506 6519 6783 7182 7413 7534 8069 8253 8442 8505 9135 9308 9828 9902",
"output": "17"
},
{
"input": "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 1649 1940 2078 2134 2716 3492 3686 4462 4559 4656 4756 4850 5044 5490 5529 5592 5626 6014 6111 6693 6790 7178 7275 7566 7663 7702 7857 7954 8342 8511 8730 8957 9021 9215 9377 9445 9991",
"output": "28"
},
{
"input": "39\n10 13 21 25 36 38 47 48 58 64 68 69 73 79 86 972 2012 2215 2267 2503 3717 3945 4197 4800 5266 6169 6612 6824 7023 7322 7582 7766 8381 8626 8879 9079 9088 9838 9968\n50\n432 877 970 1152 1202 1223 1261 1435 1454 1578 1843 1907 2003 2037 2183 2195 2215 2425 3065 3492 3615 3637 3686 3946 4189 4415 4559 4656 4665 4707 4886 4887 5626 5703 5955 6208 6521 6581 6596 6693 6985 7013 7081 7343 7663 8332 8342 8637 9207 9862",
"output": "15"
},
{
"input": "50\n7 144 269 339 395 505 625 688 709 950 1102 1152 1350 1381 1641 1830 1977 1999 2093 2180 2718 3308 3574 4168 4232 4259 4393 4689 4982 5154 5476 5581 5635 5721 6159 6302 6741 7010 7152 7315 7417 7482 8116 8239 8640 9347 9395 9614 9661 9822\n20\n84 162 292 1728 1866 2088 3228 3470 4068 5318 5470 6060 6380 6929 7500 8256 8399 8467 8508 9691",
"output": "8"
},
{
"input": "50\n159 880 1070 1139 1358 1608 1691 1841 2073 2171 2213 2597 2692 2759 2879 2931 3173 3217 3441 4201 4878 5106 5129 5253 5395 5647 5968 6019 6130 6276 6286 6330 6409 6728 7488 7713 7765 7828 7899 8064 8264 8457 8483 8685 8900 8946 8965 9133 9187 9638\n45\n57 159 1070 1139 1391 1608 1691 1841 2171 2213 2692 2759 2931 3173 3217 3441 4201 4878 5106 5129 5253 5647 5968 6130 6276 6286 6409 7488 7694 7713 7765 7828 7899 8003 8064 8081 8244 8264 8685 8900 8946 8965 9133 9638 9673",
"output": "38"
},
{
"input": "3\n3 4 5\n3\n6 20 25",
"output": "2"
},
{
"input": "4\n2 3 5 8\n4\n2 6 8 10",
"output": "1"
},
{
"input": "4\n3 5 7 11\n4\n3 5 7 22",
"output": "1"
},
{
"input": "2\n2 3\n3\n20 30 50",
"output": "1"
},
{
"input": "3\n1 2 3\n4\n2 4 6 49",
"output": "1"
},
{
"input": "2\n4 5\n3\n12 15 20",
"output": "1"
},
{
"input": "3\n2 5 7\n3\n4 5 7",
"output": "1"
},
{
"input": "3\n3 5 8\n3\n6 8 10",
"output": "2"
},
{
"input": "2\n2 3\n4\n4 6 9 33",
"output": "1"
},
{
"input": "2\n2 3\n4\n4 6 21 40",
"output": "1"
},
{
"input": "3\n4 9 10\n3\n8 9 10",
"output": "1"
},
{
"input": "5\n1 5 6 9 51\n5\n5 12 18 27 10000",
"output": "1"
},
{
"input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n1\n14",
"output": "1"
}
] | 124 | 0 | 0 | 252 |
|
296 | Yaroslav and Two Strings | [
"combinatorics",
"dp"
] | null | null | Yaroslav thinks that two strings *s* and *w*, consisting of digits and having length *n* are non-comparable if there are two numbers, *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*), such that *s**i*<=><=*w**i* and *s**j*<=<<=*w**j*. Here sign *s**i* represents the *i*-th digit of string *s*, similarly, *w**j* represents the *j*-th digit of string *w*.
A string's template is a string that consists of digits and question marks ("?").
Yaroslav has two string templates, each of them has length *n*. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers.
Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109<=+<=7). | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals *n*. The third line contains the second template in the same format. | In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109<=+<=7). | [
"2\n90\n09\n",
"2\n11\n55\n",
"5\n?????\n?????\n"
] | [
"1\n",
"0\n",
"993531194\n"
] | The first test contains no question marks and both strings are incomparable, so the answer is 1.
The second test has no question marks, but the given strings are comparable, so the answer is 0. | [
{
"input": "2\n90\n09",
"output": "1"
},
{
"input": "2\n11\n55",
"output": "0"
},
{
"input": "5\n?????\n?????",
"output": "993531194"
},
{
"input": "10\n104?3?1??3\n?1755?1??7",
"output": "91015750"
},
{
"input": "10\n6276405116\n6787?352?9",
"output": "46"
},
{
"input": "10\n0844033584\n0031021311",
"output": "0"
},
{
"input": "10\n???0?19?01\n957461????",
"output": "983368000"
},
{
"input": "10\n8703870339\n994987934?",
"output": "9"
},
{
"input": "10\n?8?528?91?\n45??06???1",
"output": "980398000"
},
{
"input": "10\n8030456630\n83406?6890",
"output": "5"
},
{
"input": "1\n?\n?",
"output": "0"
},
{
"input": "2\n12\n?9",
"output": "1"
},
{
"input": "3\n??1\n?12",
"output": "890"
},
{
"input": "3\n?12\n??1",
"output": "890"
},
{
"input": "5\n??15?\n?32??",
"output": "939500"
},
{
"input": "5\n??25?\n?32??",
"output": "812550"
},
{
"input": "5\n??55?\n?32??",
"output": "872950"
},
{
"input": "5\n?32??\n??55?",
"output": "872950"
}
] | 218 | 307,200 | 0 | 253 |
|
981 | Useful Decomposition | [
"implementation",
"trees"
] | null | null | Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.
Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition. | The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.
Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree. | If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$.
Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of the paths in the decomposition is the simple path between nodes $u_i$ and $v_i$.
Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.
If there are multiple decompositions, print any. | [
"4\n1 2\n2 3\n3 4\n",
"6\n1 2\n2 3\n3 4\n2 5\n3 6\n",
"5\n1 2\n1 3\n1 4\n1 5\n"
] | [
"Yes\n1\n1 4\n",
"No\n",
"Yes\n4\n1 2\n1 3\n1 4\n1 5\n"
] | The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.
The tree from the second example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/20704b97182d9bcde3321c00a16edcae4d772d93.png" style="max-width: 100.0%;max-height: 100.0%;"/> We can show that there are no valid decompositions of this tree.
The tree from the third example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/357ff9496a4ed4746401160ee6ee63f5d57d81b9.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. | [
{
"input": "4\n1 2\n2 3\n3 4",
"output": "Yes\n1\n1 4"
},
{
"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6",
"output": "No"
},
{
"input": "5\n1 2\n1 3\n1 4\n1 5",
"output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"
},
{
"input": "2\n1 2",
"output": "Yes\n1\n1 2"
},
{
"input": "8\n1 2\n1 3\n1 4\n1 8\n7 8\n6 8\n5 8",
"output": "No"
},
{
"input": "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9",
"output": "No"
},
{
"input": "3\n2 3\n1 2",
"output": "Yes\n1\n1 3"
}
] | 62 | 0 | 0 | 254 |
|
483 | Counterexample | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "640097987171091792 640097987171091793 640097987171091794"
},
{
"input": "19534350415104721 19534350415104725",
"output": "19534350415104722 19534350415104723 19534350415104724"
},
{
"input": "933700505788726243 933700505788726280",
"output": "933700505788726244 933700505788726245 933700505788726246"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "2 3 4"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "266540997167959130 266540997167959164",
"output": "266540997167959130 266540997167959131 266540997167959132"
},
{
"input": "267367244641009850 267367244641009899",
"output": "267367244641009850 267367244641009851 267367244641009852"
},
{
"input": "268193483524125978 268193483524125993",
"output": "268193483524125978 268193483524125979 268193483524125980"
},
{
"input": "269019726702209402 269019726702209432",
"output": "269019726702209402 269019726702209403 269019726702209404"
},
{
"input": "269845965585325530 269845965585325576",
"output": "269845965585325530 269845965585325531 269845965585325532"
},
{
"input": "270672213058376250 270672213058376260",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492378",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608523",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691962",
"output": "273150934002691930 273150934002691931 273150934002691932"
},
{
"input": "996517375802030516 996517375802030524",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146694",
"output": "997343614685146644 997343614685146645 997343614685146646"
},
{
"input": "998169857863230068 998169857863230083",
"output": "998169857863230068 998169857863230069 998169857863230070"
},
{
"input": "998996101041313492 998996101041313522",
"output": "998996101041313492 998996101041313493 998996101041313494"
},
{
"input": "999822344219396916 999822344219396961",
"output": "999822344219396916 999822344219396917 999822344219396918"
},
{
"input": "648583102513043 648583102513053",
"output": "648583102513044 648583102513045 648583102513046"
},
{
"input": "266540997167959130 266540997167959131",
"output": "-1"
},
{
"input": "267367244641009850 267367244641009850",
"output": "-1"
},
{
"input": "268193483524125978 268193483524125979",
"output": "-1"
},
{
"input": "269019726702209402 269019726702209402",
"output": "-1"
},
{
"input": "269845965585325530 269845965585325530",
"output": "-1"
},
{
"input": "270672213058376250 270672213058376254",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492379",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608508",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691931",
"output": "-1"
},
{
"input": "996517375802030516 996517375802030518",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146644",
"output": "-1"
},
{
"input": "2147483647 2147483649",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "1 7",
"output": "2 3 4"
},
{
"input": "9 12",
"output": "9 11 12"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "11 13",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
}
] | 109 | 6,656,000 | 3 | 256 |
|
931 | Friends Meeting | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6.
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"input": "1000\n999",
"output": "1"
},
{
"input": "1000\n1",
"output": "250000"
},
{
"input": "2\n1",
"output": "1"
},
{
"input": "2\n999",
"output": "249001"
},
{
"input": "2\n998",
"output": "248502"
},
{
"input": "999\n2",
"output": "249001"
},
{
"input": "998\n2",
"output": "248502"
},
{
"input": "2\n1000",
"output": "249500"
},
{
"input": "1000\n2",
"output": "249500"
},
{
"input": "1\n999",
"output": "249500"
},
{
"input": "999\n1",
"output": "249500"
},
{
"input": "188\n762",
"output": "82656"
},
{
"input": "596\n777",
"output": "8281"
},
{
"input": "773\n70",
"output": "123904"
},
{
"input": "825\n729",
"output": "2352"
},
{
"input": "944\n348",
"output": "89102"
},
{
"input": "352\n445",
"output": "2209"
},
{
"input": "529\n656",
"output": "4096"
},
{
"input": "19\n315",
"output": "22052"
},
{
"input": "138\n370",
"output": "13572"
},
{
"input": "546\n593",
"output": "576"
},
{
"input": "285\n242",
"output": "484"
},
{
"input": "773\n901",
"output": "4160"
},
{
"input": "892\n520",
"output": "34782"
},
{
"input": "864\n179",
"output": "117649"
},
{
"input": "479\n470",
"output": "25"
},
{
"input": "967\n487",
"output": "57840"
},
{
"input": "648\n106",
"output": "73712"
},
{
"input": "58\n765",
"output": "125316"
},
{
"input": "235\n56",
"output": "8100"
},
{
"input": "285\n153",
"output": "4422"
},
{
"input": "943\n13",
"output": "216690"
},
{
"input": "675\n541",
"output": "4556"
},
{
"input": "4\n912",
"output": "206570"
}
] | 109 | 0 | 3 | 257 |
|
764 | Taymyr is calling you | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"input": "24 22 9235",
"output": "34"
},
{
"input": "74 8 417",
"output": "1"
},
{
"input": "972 1 203",
"output": "0"
},
{
"input": "550 1 754",
"output": "1"
},
{
"input": "860 1 884",
"output": "1"
},
{
"input": "358 2 809",
"output": "2"
},
{
"input": "33 27 216",
"output": "0"
},
{
"input": "2940 1 9311",
"output": "3"
},
{
"input": "4624 1 1953",
"output": "0"
},
{
"input": "2696 2 7345",
"output": "2"
},
{
"input": "3443 2 6701",
"output": "0"
},
{
"input": "3 613 2275",
"output": "1"
},
{
"input": "1 10000 10000",
"output": "1"
},
{
"input": "10000 1 10000",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1 10000",
"output": "10000"
},
{
"input": "34 27 10000",
"output": "10"
},
{
"input": "2 2 9999",
"output": "4999"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "6 4 36",
"output": "3"
},
{
"input": "33 6 3005",
"output": "45"
},
{
"input": "5 1 20",
"output": "4"
},
{
"input": "1 2 10",
"output": "5"
},
{
"input": "2 1 100",
"output": "50"
},
{
"input": "10 20 10000",
"output": "500"
},
{
"input": "8 12 12",
"output": "0"
}
] | 46 | 0 | 0 | 259 |
|
388 | Fox and Box Accumulation | [
"greedy",
"sortings"
] | null | null | Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct? | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). | Output a single integer — the minimal possible number of piles. | [
"3\n0 0 10\n",
"5\n0 1 2 3 4\n",
"4\n0 0 0 0\n",
"9\n0 1 0 2 0 1 1 2 10\n"
] | [
"2\n",
"1\n",
"4\n",
"3\n"
] | In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | [
{
"input": "3\n0 0 10",
"output": "2"
},
{
"input": "5\n0 1 2 3 4",
"output": "1"
},
{
"input": "4\n0 0 0 0",
"output": "4"
},
{
"input": "9\n0 1 0 2 0 1 1 2 10",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n100 99",
"output": "1"
},
{
"input": "9\n0 1 1 0 2 0 3 45 4",
"output": "3"
},
{
"input": "10\n1 1 1 1 2 2 2 2 2 2",
"output": "4"
},
{
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "2"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "11\n71 34 31 71 42 38 64 60 36 76 67",
"output": "1"
},
{
"input": "39\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54",
"output": "1"
},
{
"input": "59\n61 33 84 76 56 47 70 94 46 77 95 85 35 90 83 62 48 74 36 74 83 97 62 92 95 75 70 82 94 67 82 42 78 70 50 73 80 76 94 83 96 80 80 88 91 79 83 54 38 90 33 93 53 33 86 95 48 34 46",
"output": "1"
},
{
"input": "87\n52 63 93 90 50 35 67 66 46 89 43 64 33 88 34 80 69 59 75 55 55 68 66 83 46 33 72 36 73 34 54 85 52 87 67 68 47 95 52 78 92 58 71 66 84 61 36 77 69 44 84 70 71 55 43 91 33 65 77 34 43 59 83 70 95 38 92 92 74 53 66 65 81 45 55 89 49 52 43 69 78 41 37 79 63 70 67",
"output": "1"
},
{
"input": "15\n20 69 36 63 40 40 52 42 20 43 59 68 64 49 47",
"output": "1"
},
{
"input": "39\n40 20 49 35 80 18 20 75 39 62 43 59 46 37 58 52 67 16 34 65 32 75 59 42 59 41 68 21 41 61 66 19 34 63 19 63 78 62 24",
"output": "1"
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "18"
},
{
"input": "46\n14 13 13 10 13 15 8 8 12 9 11 15 8 10 13 8 12 13 11 8 12 15 12 15 11 13 12 9 13 12 10 8 13 15 9 15 8 13 11 8 9 9 9 8 11 8",
"output": "3"
},
{
"input": "70\n6 1 4 1 1 6 5 2 5 1 1 5 2 1 2 4 1 1 1 2 4 5 2 1 6 6 5 2 1 4 3 1 4 3 6 5 2 1 3 4 4 1 4 5 6 2 1 2 4 4 5 3 6 1 1 2 2 1 5 6 1 6 3 1 4 4 2 3 1 4",
"output": "11"
},
{
"input": "94\n11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11",
"output": "8"
},
{
"input": "18\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "46\n14 8 7 4 8 7 8 8 12 9 9 12 9 12 14 8 10 14 14 6 9 11 7 14 14 13 11 4 13 13 11 13 9 10 10 12 10 8 12 10 13 10 7 13 14 6",
"output": "4"
},
{
"input": "74\n4 4 5 5 5 5 5 5 6 6 5 4 4 4 3 3 5 4 5 3 4 4 5 6 3 3 5 4 4 5 4 3 5 5 4 4 3 5 6 4 3 6 6 3 4 5 4 4 3 3 3 6 3 5 6 5 5 5 5 3 6 4 5 4 4 6 6 3 4 5 6 6 6 6",
"output": "11"
},
{
"input": "100\n48 35 44 37 35 42 42 39 49 53 35 55 41 42 42 39 43 49 46 54 48 39 42 53 55 39 56 43 43 38 48 40 54 36 48 55 46 40 41 39 45 56 38 40 47 46 45 46 53 51 38 41 54 35 35 47 42 43 54 54 39 44 49 41 37 49 36 37 37 49 53 44 47 37 55 49 45 40 35 51 44 40 42 35 46 48 53 48 35 38 42 36 54 46 44 47 41 40 41 42",
"output": "2"
},
{
"input": "100\n34 3 37 35 40 44 38 46 13 31 12 23 26 40 26 18 28 36 5 21 2 4 10 29 3 46 38 41 37 28 44 14 39 10 35 17 24 28 38 16 29 6 2 42 47 34 43 2 43 46 7 16 16 43 33 32 20 47 8 48 32 4 45 38 15 7 25 25 19 41 20 35 16 2 31 5 31 25 27 3 45 29 32 36 9 47 39 35 9 21 32 17 21 41 29 48 11 40 5 25",
"output": "3"
},
{
"input": "100\n2 4 5 5 0 5 3 0 3 0 5 3 4 1 0 3 0 5 5 0 4 3 3 3 0 2 1 2 2 4 4 2 4 0 1 3 4 1 4 2 5 3 5 2 3 0 1 2 5 5 2 0 4 2 5 1 0 0 4 0 1 2 0 1 2 4 1 4 5 3 4 5 5 1 0 0 3 1 4 0 4 5 1 3 3 0 4 2 0 4 5 2 3 0 5 1 4 4 1 0",
"output": "21"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "17"
},
{
"input": "100\n1 1 1 2 2 2 2 2 2 1 1 1 2 0 2 2 0 0 0 0 0 2 0 0 2 2 1 0 2 0 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 0 1 2 2 0 2 2 2 2 1 0 1 0 0 0 2 0 2 0 1 1 0 2 2 2 2 1 1 1 2 1 1 2 1 1 1 2 1 0 2 1 0 1 2 0 1 1 2 0 0 1 1 0 1 1",
"output": "34"
},
{
"input": "100\n0 3 1 0 3 2 1 2 2 1 2 1 3 2 1 2 1 3 2 0 0 2 3 0 0 2 1 2 2 3 1 2 2 2 0 3 3 2 0 0 1 0 1 2 3 1 0 3 3 3 0 2 1 3 0 1 3 2 2 2 2 3 3 2 0 2 0 1 0 1 3 0 1 2 0 1 3 2 0 3 1 1 2 3 1 3 1 0 3 0 3 0 2 1 1 1 2 2 0 1",
"output": "26"
},
{
"input": "100\n1 0 2 2 2 2 1 0 1 2 2 2 0 1 0 1 2 1 2 1 0 1 2 2 2 1 0 1 0 2 1 2 0 2 1 1 2 1 1 0 1 2 1 1 2 1 1 0 2 2 0 0 1 2 0 2 0 0 1 1 0 0 2 1 2 1 0 2 2 2 2 2 2 1 2 0 1 2 1 2 1 0 1 0 1 0 1 1 0 2 1 0 0 1 2 2 1 0 0 1",
"output": "34"
},
{
"input": "100\n3 4 4 4 3 3 3 3 3 4 4 4 3 3 3 4 3 4 4 4 3 4 3 4 3 4 3 3 4 4 3 4 4 3 4 4 4 4 4 3 4 3 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 3 3 3 4 4 3 4 4 3 4 3 3 3 4 4 3 3 3 3 3 4 3 4 4 3 3 4 3 4 3 4 4 4 3 3 3 4 4 4 4 3",
"output": "20"
},
{
"input": "100\n8 7 9 10 2 7 8 11 11 4 7 10 2 5 8 9 10 3 9 4 10 5 5 6 3 8 8 9 6 9 5 5 4 11 4 2 11 8 3 5 6 6 11 9 8 11 9 8 3 3 8 9 8 9 4 8 6 11 4 4 4 9 7 5 3 4 11 3 9 11 8 10 3 5 5 7 6 9 4 5 2 11 3 6 2 10 9 4 6 10 5 11 8 10 10 8 9 8 5 3",
"output": "9"
},
{
"input": "5\n4 1 1 1 1",
"output": "2"
}
] | 62 | 5,632,000 | 0 | 260 |
|
16 | Flag | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888",
"output": "NO"
},
{
"input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555",
"output": "NO"
},
{
"input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333",
"output": "NO"
},
{
"input": "5 5\n88888\n44444\n66666\n55555\n88888",
"output": "YES"
},
{
"input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222",
"output": "YES"
},
{
"input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888",
"output": "YES"
},
{
"input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4",
"output": "YES"
},
{
"input": "1 1\n2",
"output": "YES"
},
{
"input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111",
"output": "NO"
},
{
"input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0",
"output": "YES"
}
] | 218 | 0 | 0 | 261 |
166 | Polygons | [
"geometry",
"sortings"
] | null | null | You've got another geometrical task. You are given two non-degenerate polygons *A* and *B* as vertex coordinates. Polygon *A* is strictly convex. Polygon *B* is an arbitrary polygon without any self-intersections and self-touches. The vertices of both polygons are given in the clockwise order. For each polygon no three consecutively following vertices are located on the same straight line.
Your task is to check whether polygon *B* is positioned strictly inside polygon *A*. It means that any point of polygon *B* should be strictly inside polygon *A*. "Strictly" means that the vertex of polygon *B* cannot lie on the side of the polygon *A*. | The first line contains the only integer *n* (3<=≤<=*n*<=≤<=105) — the number of vertices of polygon *A*. Then *n* lines contain pairs of integers *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=109) — coordinates of the *i*-th vertex of polygon *A*. The vertices are given in the clockwise order.
The next line contains a single integer *m* (3<=≤<=*m*<=≤<=2·104) — the number of vertices of polygon *B*. Then following *m* lines contain pairs of integers *x**j*,<=*y**j* (|*x**j*|,<=|*y**j*|<=≤<=109) — the coordinates of the *j*-th vertex of polygon *B*. The vertices are given in the clockwise order.
The coordinates of the polygon's vertices are separated by a single space. It is guaranteed that polygons *A* and *B* are non-degenerate, that polygon *A* is strictly convex, that polygon *B* has no self-intersections and self-touches and also for each polygon no three consecutively following vertices are located on the same straight line. | Print on the only line the answer to the problem — if polygon *B* is strictly inside polygon *A*, print "YES", otherwise print "NO" (without the quotes). | [
"6\n-2 1\n0 3\n3 3\n4 1\n3 -2\n2 -2\n4\n0 1\n2 2\n3 1\n1 0\n",
"5\n1 2\n4 2\n3 -3\n-2 -2\n-2 1\n4\n0 1\n1 2\n4 1\n2 -1\n",
"5\n-1 2\n2 3\n4 1\n3 -2\n0 -3\n5\n1 0\n1 1\n3 1\n5 -1\n2 -1\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | [
{
"input": "6\n-2 1\n0 3\n3 3\n4 1\n3 -2\n2 -2\n4\n0 1\n2 2\n3 1\n1 0",
"output": "YES"
},
{
"input": "5\n1 2\n4 2\n3 -3\n-2 -2\n-2 1\n4\n0 1\n1 2\n4 1\n2 -1",
"output": "NO"
},
{
"input": "5\n-1 2\n2 3\n4 1\n3 -2\n0 -3\n5\n1 0\n1 1\n3 1\n5 -1\n2 -1",
"output": "NO"
},
{
"input": "7\n1 3\n4 2\n4 -1\n2 -3\n0 -3\n-3 0\n-2 2\n5\n-1 1\n2 2\n3 0\n2 -2\n0 -2",
"output": "YES"
},
{
"input": "4\n3 -2\n-2 2\n2 3\n4 1\n4\n2 1\n1 1\n1 2\n2 2",
"output": "YES"
},
{
"input": "5\n4 3\n2 -3\n-1 -3\n-1 0\n2 2\n5\n-1 -2\n-1 -1\n2 1\n3 0\n2 -2",
"output": "NO"
},
{
"input": "6\n3 3\n3 -3\n0 -4\n-4 -1\n-4 2\n1 5\n9\n0 0\n2 1\n2 -3\n0 -1\n0 -3\n-2 -2\n-1 -1\n-2 1\n2 2",
"output": "YES"
},
{
"input": "6\n2 4\n4 2\n3 -1\n-1 -3\n-3 0\n-2 3\n12\n0 3\n0 2\n1 2\n2 3\n3 2\n1 1\n2 0\n0 -2\n0 0\n-1 -1\n-2 0\n-1 1",
"output": "YES"
},
{
"input": "6\n-2 2\n1 3\n4 3\n5 1\n3 -2\n-1 -2\n7\n1 1\n2 4\n3 2\n6 2\n3 1\n3 0\n2 -3",
"output": "NO"
},
{
"input": "6\n-3 2\n1 4\n3 3\n2 -2\n-1 -3\n-5 0\n3\n3 -2\n4 3\n5 -2",
"output": "NO"
},
{
"input": "4\n4 -1\n-1 -2\n-2 3\n2 3\n6\n2 1\n2 2\n5 3\n5 0\n4 -2\n4 1",
"output": "NO"
},
{
"input": "5\n3 -1\n-1 -1\n-1 2\n3 4\n6 4\n7\n1 0\n1 2\n2 3\n2 2\n4 4\n4 2\n2 -1",
"output": "NO"
},
{
"input": "3\n1 2\n5 5\n6 1\n3\n4 3\n5 2\n3 2",
"output": "YES"
},
{
"input": "3\n0 0\n0 1\n1 0\n3\n0 1\n1 0\n0 0",
"output": "NO"
},
{
"input": "4\n1 0\n0 1\n3 3\n3 0\n8\n-1 2\n4 6\n4 3\n5 4\n3 -2\n3 -3\n2 -2\n1 -2",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n-10 0\n1 5\n2 2",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n10 0\n2 2\n1 5",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n0 -10\n1 5\n2 2",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n0 10\n2 2\n1 5",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n-10 -10\n1 5\n2 2",
"output": "NO"
},
{
"input": "4\n-10 -10\n-10 10\n10 10\n10 -10\n3\n-10 10\n1 5\n2 2",
"output": "NO"
},
{
"input": "4\n0 0\n9 4\n12 -5\n5 -5\n4\n2 0\n2 3\n5 3\n5 0",
"output": "NO"
},
{
"input": "3\n-1000000000 0\n1000000000 1\n1000000000 -2\n3\n-999999999 0\n999999999 0\n999999999 -1",
"output": "YES"
},
{
"input": "4\n0 0\n0 4\n4 4\n4 0\n3\n2 1\n2 3\n4 2",
"output": "NO"
},
{
"input": "4\n0 10\n10 0\n0 -10\n-10 0\n3\n6 6\n6 5\n0 0",
"output": "NO"
},
{
"input": "4\n0 6\n6 0\n0 -6\n-6 0\n4\n4 4\n4 -4\n-4 -4\n-4 4",
"output": "NO"
},
{
"input": "4\n0 0\n0 4\n4 4\n4 0\n3\n3 1\n2 1\n4 3",
"output": "NO"
},
{
"input": "3\n-1000000000 1000000000\n1000000000 0\n1000 -1000000000\n3\n1000 -999999999\n1000 0\n1001 0",
"output": "YES"
},
{
"input": "4\n0 3\n3 0\n0 -3\n-3 0\n4\n2 2\n2 -2\n-2 -2\n-2 2",
"output": "NO"
}
] | 184 | 0 | 0 | 264 |
|
903 | Hungry Student Problem | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks.
Help Ivan to answer this question for several values of *x*! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100",
"output": "NO\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "3\n6\n6\n6",
"output": "YES\nYES\nYES"
},
{
"input": "47\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n1\n52\n76",
"output": "NO\nYES\nYES"
},
{
"input": "87\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "3\n3\n2\n1",
"output": "YES\nNO\nNO"
},
{
"input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 140 | 0 | 3 | 265 |
|
427 | Police Recruits | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 -1 -1 -1 1 -1 1 1",
"output": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 78 | 5,324,800 | 3 | 267 |
|
597 | Divisibility | [
"math"
] | null | null | Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*. | The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018). | Print the required number. | [
"1 1 10\n",
"2 -4 4\n"
] | [
"10\n",
"5\n"
] | none | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "2 -4 4",
"output": "5"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 0 0",
"output": "1"
},
{
"input": "1 0 1",
"output": "2"
},
{
"input": "1 10181 10182",
"output": "2"
},
{
"input": "1 10182 10183",
"output": "2"
},
{
"input": "1 -191 1011",
"output": "1203"
},
{
"input": "2 0 0",
"output": "1"
},
{
"input": "2 0 1",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "2 2 3",
"output": "1"
},
{
"input": "2 -1 0",
"output": "1"
},
{
"input": "2 -1 1",
"output": "1"
},
{
"input": "2 -7 -6",
"output": "1"
},
{
"input": "2 -7 -5",
"output": "1"
},
{
"input": "2 -6 -6",
"output": "1"
},
{
"input": "2 -6 -4",
"output": "2"
},
{
"input": "2 -6 13",
"output": "10"
},
{
"input": "2 -19171 1911",
"output": "10541"
},
{
"input": "3 123 456",
"output": "112"
},
{
"input": "3 124 456",
"output": "111"
},
{
"input": "3 125 456",
"output": "111"
},
{
"input": "3 381 281911",
"output": "93844"
},
{
"input": "3 381 281912",
"output": "93844"
},
{
"input": "3 381 281913",
"output": "93845"
},
{
"input": "3 382 281911",
"output": "93843"
},
{
"input": "3 382 281912",
"output": "93843"
},
{
"input": "3 382 281913",
"output": "93844"
},
{
"input": "3 383 281911",
"output": "93843"
},
{
"input": "3 383 281912",
"output": "93843"
},
{
"input": "3 383 281913",
"output": "93844"
},
{
"input": "3 -381 281911",
"output": "94098"
},
{
"input": "3 -381 281912",
"output": "94098"
},
{
"input": "3 -381 281913",
"output": "94099"
},
{
"input": "3 -380 281911",
"output": "94097"
},
{
"input": "3 -380 281912",
"output": "94097"
},
{
"input": "3 -380 281913",
"output": "94098"
},
{
"input": "3 -379 281911",
"output": "94097"
},
{
"input": "3 -379 281912",
"output": "94097"
},
{
"input": "3 -379 281913",
"output": "94098"
},
{
"input": "3 -191381 -1911",
"output": "63157"
},
{
"input": "3 -191381 -1910",
"output": "63157"
},
{
"input": "3 -191381 -1909",
"output": "63157"
},
{
"input": "3 -191380 -1911",
"output": "63157"
},
{
"input": "3 -191380 -1910",
"output": "63157"
},
{
"input": "3 -191380 -1909",
"output": "63157"
},
{
"input": "3 -191379 -1911",
"output": "63157"
},
{
"input": "3 -191379 -1910",
"output": "63157"
},
{
"input": "3 -191379 -1909",
"output": "63157"
},
{
"input": "3 -2810171 0",
"output": "936724"
},
{
"input": "3 0 29101",
"output": "9701"
},
{
"input": "3 -2810170 0",
"output": "936724"
},
{
"input": "3 0 29102",
"output": "9701"
},
{
"input": "3 -2810169 0",
"output": "936724"
},
{
"input": "3 0 29103",
"output": "9702"
},
{
"input": "1 -1000000000000000000 1000000000000000000",
"output": "2000000000000000001"
},
{
"input": "2 -1000000000000000000 1000000000000000000",
"output": "1000000000000000001"
},
{
"input": "3 -1000000000000000000 1000000000000000000",
"output": "666666666666666667"
},
{
"input": "4 -1000000000000000000 1000000000000000000",
"output": "500000000000000001"
},
{
"input": "5 -1000000000000000000 1000000000000000000",
"output": "400000000000000001"
},
{
"input": "6 -1000000000000000000 1000000000000000000",
"output": "333333333333333333"
},
{
"input": "7 -1000000000000000000 1000000000000000000",
"output": "285714285714285715"
},
{
"input": "1 -1000000000000000000 -100000000000000000",
"output": "900000000000000001"
},
{
"input": "2 -1000000000000000000 -10000000000000000",
"output": "495000000000000001"
},
{
"input": "3 -1000000000000000000 -10218000000000000",
"output": "329927333333333334"
},
{
"input": "4 -1000000000000000000 -320110181919100",
"output": "249919972454520226"
},
{
"input": "5 -1000000000000000000 -402710171917",
"output": "199999919457965617"
},
{
"input": "6 -1000000000000000000 -6666666666",
"output": "166666665555555556"
},
{
"input": "7 -1000000000000000000 -77777777777778",
"output": "142846031746031746"
},
{
"input": "1000000000000000000 -1000000000000000000 1000000000000000000",
"output": "3"
},
{
"input": "1000000000000000000 0 1000000000000000000",
"output": "2"
},
{
"input": "1000000000000000000 1000000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "100000000000000321 1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "100000000000000321 -1000000000000000000 1000000000000000000",
"output": "19"
},
{
"input": "1000000000000000000 0 0",
"output": "1"
},
{
"input": "1000000000000000000 1 1",
"output": "0"
},
{
"input": "1000000000000000000 -1 -1",
"output": "0"
},
{
"input": "1000000000000000000 -2 -1",
"output": "0"
},
{
"input": "142000000000000271 -228118171 -1382811",
"output": "0"
},
{
"input": "1 1 1000000000000000000",
"output": "1000000000000000000"
}
] | 155 | 0 | 3 | 268 |
|
141 | Amusing Joke | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": "YES"
},
{
"input": "ONDOL\nJNPB\nONLNJBODP",
"output": "YES"
},
{
"input": "Y\nW\nYW",
"output": "YES"
},
{
"input": "OI\nM\nIMO",
"output": "YES"
},
{
"input": "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF",
"output": "YES"
},
{
"input": "JUTCN\nPIGMZOPMEUFADQBW\nNWQGZMAIPUPOMCDUB",
"output": "NO"
},
{
"input": "Z\nO\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH",
"output": "NO"
},
{
"input": "IQ\nOQ\nQOQIGGKFNHJSGCGM",
"output": "NO"
},
{
"input": "ROUWANOPNIGTVMIITVMZ\nOQTUPZMTKUGY\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR",
"output": "YES"
},
{
"input": "OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY",
"output": "YES"
},
{
"input": "NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\nNSFQDFUMQDQWQ\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX",
"output": "YES"
},
{
"input": "IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\nNJMWRMBCNPHXTDQQNZ\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW",
"output": "YES"
},
{
"input": "SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU",
"output": "YES"
},
{
"input": "H\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK",
"output": "YES"
},
{
"input": "DSWNZRFVXQ\nPVULCZGOOU\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE",
"output": "NO"
},
{
"input": "EUHTSCENIPXLTSBMLFHD\nIZAVSZPDLXOAGESUSE\nLXAELAZ",
"output": "NO"
},
{
"input": "WYSJFEREGELSKRQRXDXCGBODEFZVSI\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI",
"output": "NO"
},
{
"input": "EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\nECGXACVKEYMCEDOTMKAUFHLHOMT",
"output": "NO"
},
{
"input": "NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY",
"output": "NO"
},
{
"input": "VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT",
"output": "NO"
},
{
"input": "PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\nFUPDLNVIHRWTEEEHOOEC\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY",
"output": "NO"
},
{
"input": "GDSLNIIKTO\nJF\nPDQYFKDTNOLI",
"output": "NO"
},
{
"input": "AHOKHEKKPJLJIIWJRCGY\nORELJCSIX\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE",
"output": "NO"
},
{
"input": "ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\nTEV\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH",
"output": "NO"
},
{
"input": "AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU",
"output": "NO"
},
{
"input": "XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\nZKIWNDGBISDB\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG",
"output": "NO"
},
{
"input": "PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\nTWRRAJLCQJTKOKWCGUH\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM",
"output": "NO"
},
{
"input": "QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\nV\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW",
"output": "NO"
},
{
"input": "XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\nLEXOPFPVPSZK\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ",
"output": "YES"
},
{
"input": "OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS",
"output": "YES"
},
{
"input": "VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\nFE\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH",
"output": "YES"
},
{
"input": "WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\nBLQZRRWP\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB",
"output": "YES"
},
{
"input": "MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP",
"output": "YES"
},
{
"input": "OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\nDJBFVRTARTFZOWN\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR",
"output": "YES"
},
{
"input": "OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\nOHBKWRFDRQUAFRCMT\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT",
"output": "YES"
},
{
"input": "OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\nMYYDQKOOYPOOUELCRIT\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH",
"output": "YES"
},
{
"input": "WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\nYOBMOVYTUATTFGJLYUQD\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG",
"output": "YES"
},
{
"input": "CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\nMUFOSEUEXEQTOVLGDSCWM\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF",
"output": "YES"
},
{
"input": "IDQRX\nWETHO\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA",
"output": "NO"
},
{
"input": "IXFDY\nJRMOU\nDF",
"output": "NO"
},
{
"input": "JPSPZ\nUGCUB\nJMZZZZZZZZ",
"output": "NO"
},
{
"input": "AC\nA\nBBA",
"output": "NO"
},
{
"input": "UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\nKZXQDWJJWRXFHKJDQHJK\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB",
"output": "NO"
},
{
"input": "PXWRXRPFLR\nPJRWWXIVHODV\nXW",
"output": "NO"
},
{
"input": "CHTAZVHGSHCVIBK\nEQINEBKXEPYJSAZIMLDF\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE",
"output": "NO"
},
{
"input": "GXPZFSELJJNDAXYRV\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH",
"output": "NO"
},
{
"input": "LFGJCJJDUTUP\nOVSBILTIYCJCRHKCIXCETJQJJ\nGIJJTJCLTJJJ",
"output": "NO"
},
{
"input": "GIO\nPRL\nPRL",
"output": "NO"
},
{
"input": "A\nB\nABC",
"output": "NO"
},
{
"input": "KKK\nKKK\nZZZZZ",
"output": "NO"
},
{
"input": "ZMYGQLDBLAPN\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA",
"output": "NO"
}
] | 62 | 0 | 0 | 269 |
|
989 | A Blend of Springtime | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order. | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
{
"input": "CACCBAA.BC",
"output": "Yes"
},
{
"input": ".CAACCBBA.CBB.AC..BABCCBCCB..B.BC..CBC.CA.CC.C.CC.B.A.CC.BBCCBB..ACAACAC.CBCCB.AABAAC.CBCC.BA..CCBC.",
"output": "Yes"
},
{
"input": "A",
"output": "No"
},
{
"input": "..",
"output": "No"
},
{
"input": "BC",
"output": "No"
},
{
"input": "CAB",
"output": "Yes"
},
{
"input": "A.CB",
"output": "No"
},
{
"input": "B.ACAA.CA..CBCBBAA.B.CCBCB.CAC.ABC...BC.BCCC.BC.CB",
"output": "Yes"
},
{
"input": "B.B...CC.B..CCCB.CB..CBCB..CBCC.CCBC.B.CB..CA.C.C.",
"output": "No"
},
{
"input": "AA.CBAABABCCC..B..B.ABBABAB.B.B.CCA..CB.B...A..CBC",
"output": "Yes"
},
{
"input": "CA.ABB.CC.B.C.BBBABAAB.BBBAACACAAA.C.AACA.AAC.C.BCCB.CCBC.C..CCACA.CBCCB.CCAABAAB.AACAA..A.AAA.",
"output": "No"
},
{
"input": "CBC...AC.BBBB.BBABABA.CAAACC.AAABB..A.BA..BC.CBBBC.BBBBCCCAA.ACCBB.AB.C.BA..CC..AAAC...AB.A.AAABBA.A",
"output": "No"
},
{
"input": "CC.AAAC.BA.BBB.AABABBCCAA.A.CBCCB.B.BC.ABCBCBBAA.CACA.CCCA.CB.CCB.A.BCCCB...C.A.BCCBC..B.ABABB.C.BCB",
"output": "Yes"
},
{
"input": "CCC..A..CACACCA.CA.ABAAB.BBA..C.AAA...ACB.ACA.CA.B.AB.A..C.BC.BC.A.C....ABBCCACCCBCC.BBBAA.ACCACB.BB",
"output": "Yes"
},
{
"input": "BC.ABACAACC..AC.A..CCCAABBCCACAC.AA.CC.BAABABABBCBB.BA..C.C.C.A.BBA.C..BC.ACACCC.AAAACCCCC.AAC.AC.AB",
"output": "Yes"
},
{
"input": "ACAC.BAA.C..CAAC..ABBAACC..BAA...CC...ACCBBCA.BAABABAACCAC.A.BBCACCC..BCB.BABAAAACCBCB.BCAABBC.C.BBB",
"output": "Yes"
},
{
"input": "CCAC.BCBC.A.ABBAB.C.C.BC.CCABBCBCCBC..B.AA.C.BC...B..BAA.ACCCCBBB.AAAACA.CAACCB.CCB.CC.BCCAB.BBBBABB",
"output": "Yes"
},
{
"input": ".AACAA.AAAAC.BBBB.BC...CCACCACAAA.A..CCA..BCC.AB.ABAAB..AABA...B.C.CBAB.BAAB.A.C.AAC.BBBA.ACAAA.BB.C",
"output": "Yes"
},
{
"input": "CC.ACCC.BCCCCAA.BBAACB.ABABAAAA.A.CBAB.CBACBBC..C.CA.AAA..AA..ABBB.A.C..CBBCAAACC.B..CC.AC..CAABACB.",
"output": "Yes"
},
{
"input": ".BAB.",
"output": "No"
},
{
"input": "BBBBBBBBB",
"output": "No"
},
{
"input": "..AAC..",
"output": "No"
},
{
"input": ".AAABBBCCC.",
"output": "No"
},
{
"input": "AAABC",
"output": "Yes"
},
{
"input": "BBB",
"output": "No"
},
{
"input": "AAAAABABAAAAA",
"output": "No"
},
{
"input": "AABBCC",
"output": "No"
},
{
"input": ".BA",
"output": "No"
},
{
"input": "CAAAAB",
"output": "No"
}
] | 124 | 0 | 3 | 270 |
|
841 | Godsend | [
"games",
"math"
] | null | null | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally? | First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | [
"4\n1 3 2 3\n",
"2\n2 2\n"
] | [
"First\n",
"Second\n"
] | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | [
{
"input": "4\n1 3 2 3",
"output": "First"
},
{
"input": "2\n2 2",
"output": "Second"
},
{
"input": "4\n2 4 6 8",
"output": "Second"
},
{
"input": "5\n1 1 1 1 1",
"output": "First"
},
{
"input": "4\n720074544 345031254 849487632 80870826",
"output": "Second"
},
{
"input": "1\n0",
"output": "Second"
},
{
"input": "1\n999999999",
"output": "First"
},
{
"input": "2\n1 999999999",
"output": "First"
},
{
"input": "4\n3 3 4 4",
"output": "First"
},
{
"input": "2\n1 2",
"output": "First"
},
{
"input": "8\n2 2 2 1 1 2 2 2",
"output": "First"
},
{
"input": "5\n3 3 2 2 2",
"output": "First"
},
{
"input": "4\n0 1 1 0",
"output": "First"
},
{
"input": "3\n1 2 2",
"output": "First"
},
{
"input": "6\n2 2 1 1 4 2",
"output": "First"
},
{
"input": "8\n2 2 2 3 3 2 2 2",
"output": "First"
},
{
"input": "4\n2 3 3 4",
"output": "First"
},
{
"input": "10\n2 2 2 2 3 1 2 2 2 2",
"output": "First"
},
{
"input": "6\n2 2 1 1 2 2",
"output": "First"
},
{
"input": "3\n1 1 2",
"output": "First"
},
{
"input": "6\n2 4 3 3 4 6",
"output": "First"
},
{
"input": "6\n4 4 3 3 4 4",
"output": "First"
},
{
"input": "4\n1 1 2 2",
"output": "First"
},
{
"input": "4\n1 3 5 7",
"output": "First"
},
{
"input": "4\n2 1 1 2",
"output": "First"
},
{
"input": "4\n1 3 3 2",
"output": "First"
},
{
"input": "5\n3 2 2 2 2",
"output": "First"
},
{
"input": "3\n2 1 1",
"output": "First"
},
{
"input": "4\n1000000000 1000000000 1000000000 99999999",
"output": "First"
},
{
"input": "4\n2 2 1 1",
"output": "First"
},
{
"input": "5\n2 3 2 3 2",
"output": "First"
},
{
"input": "1\n1",
"output": "First"
},
{
"input": "4\n1000000000 1000000000 1000000000 1",
"output": "First"
},
{
"input": "5\n2 2 2 1 1",
"output": "First"
},
{
"input": "6\n2 1 1 1 1 2",
"output": "First"
},
{
"input": "6\n1 2 2 2 2 1",
"output": "First"
},
{
"input": "11\n2 2 2 2 2 1 2 2 2 2 2",
"output": "First"
},
{
"input": "5\n1 3 2 2 2",
"output": "First"
},
{
"input": "3\n2 3 2",
"output": "First"
},
{
"input": "2\n1 1",
"output": "First"
},
{
"input": "5\n4 4 4 3 3",
"output": "First"
},
{
"input": "5\n3 3 4 4 4",
"output": "First"
},
{
"input": "1\n2",
"output": "Second"
}
] | 576 | 69,529,600 | 0 | 271 |
|
327 | Flipping Game | [
"brute force",
"dp",
"implementation"
] | null | null | Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*.
The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1. | Print an integer — the maximal number of 1s that can be obtained after exactly one move. | [
"5\n1 0 0 1 0\n",
"4\n1 0 0 1\n"
] | [
"4\n",
"4\n"
] | In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].
In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1. | [
{
"input": "5\n1 0 0 1 0",
"output": "4"
},
{
"input": "4\n1 0 0 1",
"output": "4"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "8\n1 0 0 0 1 0 0 0",
"output": "7"
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "18"
},
{
"input": "23\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "22"
},
{
"input": "100\n0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1",
"output": "70"
},
{
"input": "100\n0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1",
"output": "60"
},
{
"input": "18\n0 1 0 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0",
"output": "11"
},
{
"input": "25\n0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1",
"output": "18"
},
{
"input": "55\n0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 1 1 1",
"output": "36"
},
{
"input": "75\n1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0",
"output": "44"
},
{
"input": "100\n0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 1",
"output": "61"
},
{
"input": "100\n0 0 0 1 0 0 0 1 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 1 1 0",
"output": "61"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "99"
},
{
"input": "100\n0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 0 0 1 0",
"output": "61"
},
{
"input": "100\n0 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1",
"output": "59"
},
{
"input": "99\n1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 1 1 1",
"output": "61"
},
{
"input": "2\n1 1",
"output": "1"
}
] | 62 | 0 | 0 | 272 |
|
373 | Collecting Beats is Fun | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.
You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing. | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If period was written on the panel, he doesn't have to press that panel. | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n9999\n9999",
"output": "NO"
},
{
"input": "2\n4444\n3333\n2222\n1111",
"output": "YES"
},
{
"input": "3\n2123\n1232\n2321\n3213",
"output": "NO"
},
{
"input": "2\n1...\n.1..\n..1.\n...1",
"output": "YES"
},
{
"input": "2\n1.1.\n.1.1\n2.2.\n.222",
"output": "NO"
},
{
"input": "1\n1..2\n.3.4\n567.\n.89.",
"output": "YES"
},
{
"input": "1\n1122\n3344\n5588\n6699",
"output": "YES"
},
{
"input": "4\n1111\n1221\n1221\n1111",
"output": "NO"
},
{
"input": "5\n3141\n5926\n5358\n9793",
"output": "YES"
},
{
"input": "5\n5454\n4343\n3232\n2121",
"output": "YES"
},
{
"input": "5\n1222\n2221\n2221\n1122",
"output": "NO"
},
{
"input": "1\n....\n5..5\n6..6\n7..7",
"output": "YES"
},
{
"input": "1\n9875\n8643\n7421\n531.",
"output": "YES"
},
{
"input": "1\n..1.\n..1.\n..1.\n..1.",
"output": "NO"
},
{
"input": "4\n4.4.\n4.4.\n4444\n..4.",
"output": "NO"
},
{
"input": "5\n4.4.\n4.4.\n4444\n..4.",
"output": "YES"
},
{
"input": "3\n1.1.\n.1.1\n1.1.\n.1.1",
"output": "NO"
},
{
"input": "2\n1131\n4412\n2569\n3478",
"output": "YES"
},
{
"input": "2\n8888\n8888\n8888\n8888",
"output": "NO"
}
] | 155 | 0 | 3 | 273 |
|
722 | Destroying Array | [
"data structures",
"dsu"
] | null | null | You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed.
After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements. | Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed. | [
"4\n1 3 2 5\n3 4 1 2\n",
"5\n1 2 3 4 5\n4 2 3 5 1\n",
"8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n"
] | [
"5\n4\n3\n0\n",
"6\n5\n5\n1\n0\n",
"18\n16\n11\n8\n8\n6\n6\n0\n"
] | Consider the first sample:
1. Third element is destroyed. Array is now 1 3 * 5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3 * * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now * 3 * * . Segment with maximum sum 3 consists of one integer 3. 1. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0. | [
{
"input": "4\n1 3 2 5\n3 4 1 2",
"output": "5\n4\n3\n0"
},
{
"input": "5\n1 2 3 4 5\n4 2 3 5 1",
"output": "6\n5\n5\n1\n0"
},
{
"input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6",
"output": "18\n16\n11\n8\n8\n6\n6\n0"
},
{
"input": "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8",
"output": "34\n29\n14\n11\n11\n11\n8\n3\n1\n0"
},
{
"input": "17\n12 9 17 5 0 6 5 1 3 1 17 17 2 14 5 1 17\n3 7 5 8 12 9 15 13 11 14 6 16 17 1 10 2 4",
"output": "94\n78\n78\n77\n39\n39\n21\n21\n21\n21\n21\n21\n21\n9\n9\n5\n0"
},
{
"input": "17\n1 6 9 2 10 5 15 16 17 14 17 3 9 8 12 0 2\n9 13 15 14 16 17 11 10 12 4 6 5 7 8 2 3 1",
"output": "65\n64\n64\n64\n64\n64\n64\n64\n64\n46\n31\n31\n16\n16\n9\n1\n0"
},
{
"input": "17\n10 10 3 9 8 0 10 13 11 8 11 1 6 9 2 10 5\n9 4 13 2 6 15 11 5 16 10 7 3 14 1 12 8 17",
"output": "63\n52\n31\n31\n26\n23\n23\n23\n23\n23\n13\n13\n13\n13\n13\n5\n0"
},
{
"input": "10\n10 4 9 0 7 5 10 3 10 9\n5 2 8 1 3 9 6 10 4 7",
"output": "37\n37\n19\n19\n19\n15\n10\n10\n10\n0"
},
{
"input": "10\n3 10 9 2 6 8 4 4 1 9\n5 8 6 7 9 10 2 1 3 4",
"output": "26\n24\n24\n24\n24\n24\n11\n11\n2\n0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "7\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 2 3 4 5 6 7",
"output": "6000000000\n5000000000\n4000000000\n3000000000\n2000000000\n1000000000\n0"
}
] | 1,000 | 5,324,800 | 0 | 274 |
|
165 | Supercentral Point | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=<<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=<<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=><=*y*
We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -973\n125 301\n916 414\n-748 -808\n-651 301\n-734 301\n-307 897\n-651 -550\n-651 414\n125 -808\n-748 -550\n916 -808",
"output": "7"
},
{
"input": "1\n487 550",
"output": "0"
},
{
"input": "10\n990 -396\n990 736\n990 646\n990 -102\n990 -570\n990 155\n990 528\n990 489\n990 268\n990 676",
"output": "0"
},
{
"input": "30\n507 836\n525 836\n-779 196\n507 -814\n525 -814\n525 42\n525 196\n525 -136\n-779 311\n507 -360\n525 300\n507 578\n507 311\n-779 836\n507 300\n525 -360\n525 311\n-779 -360\n-779 578\n-779 300\n507 42\n525 578\n-779 379\n507 196\n525 379\n507 379\n-779 -814\n-779 42\n-779 -136\n507 -136",
"output": "8"
},
{
"input": "25\n890 -756\n890 -188\n-37 -756\n-37 853\n523 998\n-261 853\n-351 853\n-351 -188\n523 -756\n-261 -188\n-37 998\n523 -212\n-351 998\n-37 -188\n-351 -756\n-37 -212\n890 998\n890 -212\n523 853\n-351 -212\n-261 -212\n-261 998\n-261 -756\n890 853\n523 -188",
"output": "9"
},
{
"input": "21\n-813 -11\n486 254\n685 254\n-708 254\n-55 -11\n-671 -191\n486 -11\n-671 -11\n685 -11\n685 -191\n486 -191\n-55 254\n-708 -11\n-813 254\n-708 -191\n41 -11\n-671 254\n-813 -191\n41 254\n-55 -191\n41 -191",
"output": "5"
},
{
"input": "4\n1 0\n2 0\n1 1\n1 -1",
"output": "0"
}
] | 434 | 22,323,200 | -1 | 275 |
|
758 | Holiday Of Equality | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281",
"output": "5464380"
},
{
"input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353",
"output": "9535765"
},
{
"input": "3\n1 3 2",
"output": "3"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "3\n2 3 1",
"output": "3"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n228503",
"output": "0"
},
{
"input": "2\n32576 550340",
"output": "517764"
},
{
"input": "3\n910648 542843 537125",
"output": "741328"
},
{
"input": "4\n751720 572344 569387 893618",
"output": "787403"
},
{
"input": "6\n433864 631347 597596 794426 713555 231193",
"output": "1364575"
},
{
"input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107",
"output": "4647430"
},
{
"input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025",
"output": "13488674"
},
{
"input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763",
"output": "21993384"
},
{
"input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351",
"output": "26984185"
},
{
"input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642",
"output": "32816391"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n5 0 0",
"output": "10"
},
{
"input": "5\n2 10 0 0 0",
"output": "38"
}
] | 108 | 0 | 3 | 276 |
|
808 | Anthem of Berland | [
"dp",
"strings"
] | null | null | Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
He has already composed major part of the anthem and now just needs to fill in some letters. King asked you to help him with this work.
The anthem is the string *s* of no more than 105 small Latin letters and question marks. The most glorious victory is the string *t* of no more than 105 small Latin letters. You should replace all the question marks with small Latin letters in such a way that the number of occurrences of string *t* in string *s* is maximal.
Note that the occurrences of string *t* in *s* can overlap. Check the third example for clarification. | The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105).
The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105).
Product of lengths of strings |*s*|·|*t*| won't exceed 107. | Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters. | [
"winlose???winl???w??\nwin\n",
"glo?yto?e??an?\nor\n",
"??c?????\nabcab\n"
] | [
"5\n",
"3\n",
"2\n"
] | In the first example the resulting string *s* is "winlosewinwinlwinwin"
In the second example the resulting string *s* is "glorytoreorand". The last letter of the string can be arbitrary.
In the third example occurrences of string *t* are overlapping. String *s* with maximal number of occurrences of *t* is "abcabcab". | [
{
"input": "winlose???winl???w??\nwin",
"output": "5"
},
{
"input": "glo?yto?e??an?\nor",
"output": "3"
},
{
"input": "??c?????\nabcab",
"output": "2"
},
{
"input": "ddddd\nd",
"output": "5"
},
{
"input": "ww?ww\nw",
"output": "5"
},
{
"input": "?????\nn",
"output": "5"
},
{
"input": "xznxr\nxznxr",
"output": "1"
},
{
"input": "wnfbhg?dkhdbh?hdmfjkcunzbh?hdbjjrbh?hddmh?zubhgh?qbjbhghdpwr?bhghdfjnjf?qbhghdqq?qebhgh?umvbhghdivvj\nbhghd",
"output": "10"
},
{
"input": "emnd?t??m?gd?t?p?s??m?dp??t???m?????m?d?ydo????????i??u?d??dp??h??d?tdp???cj?dm?dpxf?hsf??rdmt?pu?tw\ndmtdp",
"output": "11"
},
{
"input": "t?t?t?xnu?\ntstx",
"output": "1"
},
{
"input": "p??p??????\numpq",
"output": "2"
},
{
"input": "irsdljdahusytoclelxidaaiaiaicaiaiaiaiiaiaiyyexmohdwmeyycaiaiaitclluaiaiaiznxweleaiaiaiixdwehyruhizbc\naiaiai",
"output": "6"
},
{
"input": "qjcenuvdsn?ytytyt?yrznaaqeol?tyttyty?ycfaiphfmo?qpvtmhk?xzfr?tytytytytyty?oeqotyt?tyjhdhjtyt?tyyewxh\ntytyty",
"output": "9"
},
{
"input": "zubxnxnxnxn?xixiox?oxinoxnox?xnoxxnox?xnoxixxnox?oxii?xnoxiin?noxixnoxiox?noxixxnox?noxxnoxi?xnoxinn\nxnoxi",
"output": "13"
},
{
"input": "????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\nrcmcscoffidfyaeeanevbcfloxrhzxnitikwyidszzgmvicjupbfzhlbkzjbyidpdaeagaanokohwofzvfsvmcwvrqkvgbwnxomajvotbpzqgiyifngpnfvmtsoovrstzhtkeqamskzdmspvihochmajwkdoeozqpkdoxffhokosfqnaqshxbsfnkjsbbkxhrzgqhufq",
"output": "1"
},
{
"input": "????ufu\nfufu",
"output": "2"
},
{
"input": "??????c???\nabcabc",
"output": "2"
},
{
"input": "a???????abcax\naxabcax",
"output": "2"
},
{
"input": "cb???????a\ncbacba",
"output": "2"
},
{
"input": "a???????bc\nabcabc",
"output": "2"
},
{
"input": "a????ab\nabab",
"output": "2"
},
{
"input": "pe????????????petooh\npetoohpetooh",
"output": "2"
},
{
"input": "hacking????????????????????????hackingisfun\nhackingisfunhackingisfun",
"output": "2"
},
{
"input": "youdontgiveup????????????????????????????????????youyoudontgiveupdoyo?youyoudontgiveupdoyou\nyoudontgiveupdoyouyoudontgiveupdoyou",
"output": "2"
},
{
"input": "????b?b\nabab",
"output": "2"
},
{
"input": "a\nb",
"output": "0"
},
{
"input": "???a??????a??b?a??a????aabc??a???a?????ab???????b????????????????ab?a?????a????a??a??????b??cb?????????????b?????c????a??????????b????c????????ca?b???????c??bc????????a?b??b??a??cc?b???????a??a?ab?a?ca?a???????c????????b????b?c\nabaab",
"output": "55"
},
{
"input": "????????baaab\naaabaaab",
"output": "2"
},
{
"input": "baaab????????\nbaaabaaa",
"output": "2"
},
{
"input": "??????????????????????????\nabacaba",
"output": "5"
}
] | 358 | 921,600 | 0 | 279 |
|
7 | Line | [
"math",
"number theory"
] | C. Line | 1 | 256 | A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | The first line contains three integers *A*, *B* and *C* (<=-<=2·109<=≤<=*A*,<=*B*,<=*C*<=≤<=2·109) — corresponding coefficients of the line equation. It is guaranteed that *A*2<=+<=*B*2<=><=0. | If the required point exists, output its coordinates, otherwise output -1. | [
"2 5 3\n"
] | [
"6 -3\n"
] | none | [
{
"input": "2 5 3",
"output": "6 -3"
},
{
"input": "0 2 3",
"output": "-1"
},
{
"input": "931480234 -1767614767 -320146190",
"output": "-98880374013340920 -52107006370101410"
},
{
"input": "-1548994394 -1586527767 -1203252104",
"output": "-878123061596147680 857348814150663048"
},
{
"input": "296038088 887120955 1338330394",
"output": "2114412129515872 -705593211994286"
},
{
"input": "1906842444 749552572 -1693767003",
"output": "-1"
},
{
"input": "-1638453107 317016895 -430897103",
"output": "-23538272620589909 -121653945000687008"
},
{
"input": "-1183748658 875864960 -1315510852",
"output": "-97498198168399474 -131770725522871624"
},
{
"input": "427055698 738296578 -52640953",
"output": "-1"
},
{
"input": "-1516373701 -584304312 -746376800",
"output": "202167007852295200 -524659372900676000"
},
{
"input": "200000003 200000001 1",
"output": "100000000 -100000001"
},
{
"input": "0 -1 -2",
"output": "0 -2"
},
{
"input": "0 15 -17",
"output": "-1"
},
{
"input": "-13 0 0",
"output": "0 0"
},
{
"input": "-1000 0 -6",
"output": "-1"
},
{
"input": "1233978557 804808375 539283626",
"output": "3168196851074932 -4857661898189602"
},
{
"input": "532430220 -2899704 -328786059",
"output": "-1"
},
{
"input": "546348890 -29226055 -341135185",
"output": "50549411713300 944965544604433"
},
{
"input": "-1061610169 583743042 1503847115",
"output": "-333340893817405 -606222356685680"
},
{
"input": "10273743 174653631 -628469658",
"output": "-1"
},
{
"input": "1 2000000000 -1",
"output": "1 0"
},
{
"input": "592707810 829317963 -753392742",
"output": "-15849808632976 11327748563154"
},
{
"input": "1300000013 0 -800000008",
"output": "-1"
},
{
"input": "853072 -269205 -1778980",
"output": "7238140 22936620"
},
{
"input": "3162 56 674",
"output": "-4381 247358"
},
{
"input": "19 -5 115",
"output": "115 460"
},
{
"input": "7 5 -17",
"output": "-34 51"
},
{
"input": "-1 1 -2",
"output": "-2 0"
},
{
"input": "12453630 -163142553 -74721780",
"output": "-780 -60"
},
{
"input": "-3416750 528845750 -93743375",
"output": "-1"
},
{
"input": "701408733 1134903170 1836311903",
"output": "-796030994547383611 491974210728665288"
},
{
"input": "1000000013 -1 135",
"output": "0 135"
},
{
"input": "-2000000000 1 2000000000",
"output": "0 -2000000000"
},
{
"input": "2000000000 -2000000000 2000000000",
"output": "-1 0"
},
{
"input": "610684570 628836350 933504357",
"output": "-1"
},
{
"input": "827797728 -613880705 854959653",
"output": "60828197453915544 82024802605070757"
},
{
"input": "1044910887 -700497854 -1772517851",
"output": "572270531415215165 853638173436907976"
},
{
"input": "1663473197 -1943214909 -399995353",
"output": "90913128604458086 77825438652462521"
},
{
"input": "1880586355 -177315705 -478540057",
"output": "-1"
},
{
"input": "-957757861 308710346 45337024",
"output": "587450634832960 1822535171726016"
},
{
"input": "19999 -20000 10000",
"output": "10000 10000"
},
{
"input": "1999999 -2000000 1000000",
"output": "1000000 1000000"
},
{
"input": "999999999 -1000000000 500000000",
"output": "500000000 500000000"
},
{
"input": "999999999 -2 1",
"output": "-1 -499999999"
},
{
"input": "999999993 999999991 1",
"output": "499999995 -499999996"
},
{
"input": "999999993 -999999997 1",
"output": "-249999999 -249999998"
},
{
"input": "1999999993 1999999991 -1",
"output": "-999999995 999999996"
},
{
"input": "1999999993 1999999991 -1999999997",
"output": "-1999999987000000015 1999999989000000012"
}
] | 92 | 0 | -1 | 280 |
996 | Hit the Lottery | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"output": "8"
},
{
"input": "31",
"output": "3"
},
{
"input": "59",
"output": "8"
},
{
"input": "79",
"output": "9"
},
{
"input": "7",
"output": "3"
},
{
"input": "55",
"output": "4"
},
{
"input": "40",
"output": "2"
},
{
"input": "719",
"output": "13"
},
{
"input": "847",
"output": "13"
},
{
"input": "225",
"output": "4"
},
{
"input": "4704",
"output": "51"
},
{
"input": "1132",
"output": "15"
},
{
"input": "7811",
"output": "80"
},
{
"input": "7981",
"output": "84"
},
{
"input": "82655",
"output": "830"
},
{
"input": "6364",
"output": "70"
},
{
"input": "74611",
"output": "748"
},
{
"input": "45391",
"output": "459"
},
{
"input": "620448",
"output": "6210"
},
{
"input": "265145",
"output": "2654"
},
{
"input": "671704",
"output": "6721"
},
{
"input": "365173",
"output": "3658"
},
{
"input": "7130872",
"output": "71314"
},
{
"input": "9628747",
"output": "96292"
},
{
"input": "8898399",
"output": "88993"
},
{
"input": "9497953",
"output": "94985"
},
{
"input": "19070947",
"output": "190714"
},
{
"input": "20185520",
"output": "201856"
},
{
"input": "91402248",
"output": "914028"
},
{
"input": "27035533",
"output": "270360"
},
{
"input": "22717528",
"output": "227180"
},
{
"input": "24403439",
"output": "244041"
},
{
"input": "163565555",
"output": "1635659"
},
{
"input": "152541908",
"output": "1525423"
},
{
"input": "668439837",
"output": "6684403"
},
{
"input": "20",
"output": "1"
},
{
"input": "999999999",
"output": "10000009"
},
{
"input": "10",
"output": "1"
},
{
"input": "7",
"output": "3"
},
{
"input": "6",
"output": "2"
},
{
"input": "99999999",
"output": "1000009"
},
{
"input": "1000001",
"output": "10001"
},
{
"input": "2521",
"output": "27"
}
] | 46 | 0 | 3 | 283 |
|
834 | The Festive Evening | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened. | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
},
{
"input": "6 2\nABCABC",
"output": "YES"
},
{
"input": "8 3\nABCBCDCA",
"output": "NO"
},
{
"input": "73 2\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD",
"output": "YES"
},
{
"input": "44 15\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA",
"output": "NO"
},
{
"input": "41 19\nTMEYYIIELFDCMBDKWWKYNRNDUPRONYROXQCLVQALP",
"output": "NO"
},
{
"input": "377 3\nEADADBBBBDEAABBAEBABACDBDBBCACAADBEAEACDEAABACADEEDEACACDADABBBBDDEECBDABACACBAECBADAEBDEEBDBCDAEADBCDDACACDCCEEDBCCBBCEDBECBABCDDBBDEADEDAEACDECECBEBACBCCDCDBDAECDECADBCBEDBBDAAEBCAAECCDCCDBDDEBADEEBDCAEABBDEDBBDDEAECCBDDCDEACDAECCBDDABABEAEDCDEDBAECBDEACEBCECEACDCBABCBAAEAADACADBBBBABEADBCADEBCBECCABBDDDEEBCDEBADEBDAAABBEABADEDEAEABCEEBEEDEAEBEABCEDDBACBCCADEBAAAAAEABABBCE",
"output": "YES"
},
{
"input": "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVITKNFLVCPMZSDMCHBTVAWYVZLIXXIADXNYILEYNIQHKMOGMVOCWGHCWIYMPEPADSJAAKEGTUSEDWAHMNYJDIHBKHVUHLYGNGZDBULRXLSAJHPCMNWCEAAPYMHDTYWPADOTJTXTXUKLCHWKUSZRHEKQEFPVJEJJHRWCKYOIWALRTIBUMNOCRXLSIKQCJVQXEPGOHRUDJDKMUUUDORURWXJNVRVMNOUNRFKSVMTMZGOIJLXEPAMVGESOADYIGZXRBJDIWKNOWTCSROAQTBECHTOZVSQUOOJRZIBAUHMKAXDCIMDZJFMABGRNTGPUJAUNFPFWCJG",
"output": "YES"
},
{
"input": "5 2\nABCAB",
"output": "YES"
},
{
"input": "5 1\nAZAZA",
"output": "YES"
},
{
"input": "7 2\nABCDBCD",
"output": "YES"
},
{
"input": "3 26\nAAB",
"output": "NO"
}
] | 811 | 3,276,800 | 3 | 284 |
|
366 | Dima and Guards | [
"implementation"
] | null | null | Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly *n* rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that! | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly. | In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them. | [
"10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n",
"10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n",
"5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n"
] | [
"1 5 5\n",
"3 4 6\n",
"-1\n"
] | Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard. | [
{
"input": "10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9",
"output": "1 5 5"
},
{
"input": "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8",
"output": "3 4 6"
},
{
"input": "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3",
"output": "-1"
},
{
"input": "100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000",
"output": "-1"
},
{
"input": "5\n3 2 3 3\n3 2 3 3\n4 4 4 4\n4 4 1 1",
"output": "1 2 3"
},
{
"input": "100\n1 1 2 2\n100 100 2 2\n99 99 2 2\n2 2 99 99",
"output": "1 1 99"
},
{
"input": "1000\n500 500 550 550\n450 450 500 500\n999 1 1 999\n1 999 1 999",
"output": "3 1 999"
},
{
"input": "50\n30 30 30 30\n20 20 40 40\n10 10 50 50\n1 1 50 55",
"output": "-1"
},
{
"input": "10000\n1000 7000 8000 6000\n8000 8000 6000 6000\n5000 6000 6000 6000\n10000 10000 2 3",
"output": "1 1000 9000"
},
{
"input": "40000\n25000 25000 30000 30000\n1 1 1 1\n30000 20000 30000 30000\n40000 40000 40000 50000",
"output": "2 1 39999"
},
{
"input": "4\n2 1 4 4\n4 4 1 1\n3 1 2 2\n4 4 4 4",
"output": "3 1 3"
},
{
"input": "50\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5",
"output": "1 5 45"
},
{
"input": "10\n7 2 3 20\n20 20 20 20\n20 20 20 20\n7 2 3 20",
"output": "1 2 8"
},
{
"input": "10\n8 2 7 8\n20 20 20 20\n20 20 20 20\n8 2 7 8",
"output": "1 2 8"
},
{
"input": "100000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000",
"output": "1 50000 50000"
},
{
"input": "100000\n25000 75000 80000 80000\n99999 99999 2 2\n99999 2 99999 99999\n2 99999 99999 99999",
"output": "-1"
},
{
"input": "1231\n123 132 85 78\n123 5743 139 27\n4598 347 12438 12\n34589 2349 123 123",
"output": "2 123 1108"
},
{
"input": "6\n2 6 2 9\n4 8 5 1\n5 6 4 3\n1 2 5 1",
"output": "4 1 5"
},
{
"input": "8\n5 5 3 3\n1 1 8 8\n2 8 8 7\n10 7 2 2",
"output": "1 5 3"
},
{
"input": "100000\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001",
"output": "1 25000 75000"
},
{
"input": "100000\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001",
"output": "1 25000 75000"
},
{
"input": "5\n3 7 6 2\n100 100 100 100\n100 100 100 100\n100 100 100 100",
"output": "1 3 2"
},
{
"input": "10\n1 100 100 1\n1 100 100 1\n1 100 100 1\n1 100 100 1",
"output": "1 1 9"
},
{
"input": "10\n7 5 5 7\n10 10 10 10\n10 10 10 10\n10 10 10 10",
"output": "1 5 5"
},
{
"input": "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n1 1 1 1",
"output": "4 1 9"
},
{
"input": "10\n8 6 5 3\n8 6 5 3\n8 6 5 3\n8 6 5 3",
"output": "1 6 4"
},
{
"input": "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n9 4 9 6",
"output": "4 4 6"
},
{
"input": "10\n6 6 4 4\n6 6 4 4\n6 6 4 4\n6 6 4 4",
"output": "1 6 4"
},
{
"input": "100000\n99000 100000 999 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000",
"output": "1 99000 1000"
}
] | 46 | 102,400 | 3 | 285 |
|
224 | Parallelepiped | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{
"input": "1022 584 112",
"output": "380"
},
{
"input": "66 174 319",
"output": "184"
},
{
"input": "912 276 1748",
"output": "444"
},
{
"input": "65 156 60",
"output": "120"
},
{
"input": "1 10000 10000",
"output": "40008"
},
{
"input": "1485 55 27",
"output": "332"
},
{
"input": "152 108 4104",
"output": "528"
},
{
"input": "1656 6900 1350",
"output": "740"
},
{
"input": "12 14 42",
"output": "60"
},
{
"input": "615 18 1230",
"output": "856"
},
{
"input": "680 60 408",
"output": "336"
},
{
"input": "644 966 6",
"output": "1308"
},
{
"input": "1 432 432",
"output": "1736"
},
{
"input": "2239 2239 1",
"output": "8964"
},
{
"input": "4106 8212 2",
"output": "16436"
},
{
"input": "10000 10000 10000",
"output": "1200"
},
{
"input": "3623 3623 1",
"output": "14500"
},
{
"input": "9801 9801 9801",
"output": "1188"
},
{
"input": "10000 1 10000",
"output": "40008"
},
{
"input": "9 9 9",
"output": "36"
},
{
"input": "9801 9702 9702",
"output": "1184"
}
] | 0 | 0 | -1 | 286 |
|
78 | Haiku | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not. | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
"output": "YES"
},
{
"input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae",
"output": "NO"
},
{
"input": " furuike ya\nkawazu tobikomu\nmizu no oto ",
"output": "YES"
},
{
"input": " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ",
"output": "NO"
},
{
"input": " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det",
"output": "YES"
},
{
"input": " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel",
"output": "NO"
},
{
"input": "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti",
"output": "NO"
},
{
"input": "kutaburete\nyado karu koro ya\nfuji no hana",
"output": "YES"
},
{
"input": " beginnings of poetry\n the rice planting songs \n of the interior",
"output": "NO"
},
{
"input": " door zomerregens\n zijn de kraanvogelpoten\n korter geworden",
"output": "NO"
},
{
"input": " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut",
"output": "YES"
},
{
"input": "writing in the dark\nunaware that my pen\nhas run out of ink",
"output": "NO"
},
{
"input": "kusaaiu\nuieueua\nuo efaa",
"output": "YES"
},
{
"input": "v\nh\np",
"output": "NO"
},
{
"input": "i\ni\nu",
"output": "NO"
},
{
"input": "awmio eoj\nabdoolceegood\nwaadeuoy",
"output": "YES"
},
{
"input": "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo",
"output": "YES"
},
{
"input": "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr",
"output": "YES"
},
{
"input": "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd",
"output": "YES"
},
{
"input": "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ",
"output": "YES"
},
{
"input": "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs",
"output": "YES"
},
{
"input": "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn",
"output": "NO"
},
{
"input": "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl",
"output": "NO"
},
{
"input": "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr",
"output": "NO"
},
{
"input": "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf",
"output": "NO"
},
{
"input": "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi",
"output": "NO"
},
{
"input": " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu",
"output": "NO"
},
{
"input": "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt",
"output": "NO"
},
{
"input": "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo",
"output": "NO"
},
{
"input": "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau",
"output": "NO"
},
{
"input": "ab\na\na",
"output": "NO"
},
{
"input": "on codeforcs\nbeta round is runnineg\na rustling of keys",
"output": "NO"
},
{
"input": "coooooooooooooooood\nd\nd",
"output": "NO"
},
{
"input": "on codeforces \nbeta round is runninog\n a rustling of keys",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaa\na\na",
"output": "NO"
},
{
"input": "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "YES"
},
{
"input": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "NO"
},
{
"input": "aaaaaa\naaaaaa\naaaaa",
"output": "NO"
}
] | 218 | 20,172,800 | 3.907925 | 288 |
10 | Power Consumption Calculation | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=1440, *r**i*<=<<=*l**i*<=+<=1 for *i*<=<<=*n*), which stand for the start and the end of the *i*-th period of work. | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "52870"
},
{
"input": "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245",
"output": "46995"
},
{
"input": "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434",
"output": "85540"
},
{
"input": "7 46 61 55 28 59\n24 26\n31 61\n66 133\n161 612\n741 746\n771 849\n1345 1357",
"output": "67147"
},
{
"input": "8 83 18 30 28 5\n196 249\n313 544\n585 630\n718 843\n1040 1194\n1207 1246\n1268 1370\n1414 1422",
"output": "85876"
},
{
"input": "9 31 65 27 53 54\n164 176\n194 210\n485 538\n617 690\n875 886\n888 902\n955 957\n1020 1200\n1205 1282",
"output": "38570"
},
{
"input": "30 3 1 58 44 7\n11 13\n14 32\n37 50\n70 74\n101 106\n113 129\n184 195\n197 205\n213 228\n370 394\n443 446\n457 460\n461 492\n499 585\n602 627\n709 776\n812 818\n859 864\n910 913\n918 964\n1000 1010\n1051 1056\n1063 1075\n1106 1145\n1152 1189\n1211 1212\n1251 1259\n1272 1375\n1412 1417\n1430 1431",
"output": "11134"
},
{
"input": "30 42 3 76 28 26\n38 44\n55 66\n80 81\n84 283\n298 314\n331 345\n491 531\n569 579\n597 606\n612 617\n623 701\n723 740\n747 752\n766 791\n801 827\n842 846\n853 891\n915 934\n945 949\n955 964\n991 1026\n1051 1059\n1067 1179\n1181 1191\n1214 1226\n1228 1233\n1294 1306\n1321 1340\n1371 1374\n1375 1424",
"output": "59043"
},
{
"input": "30 46 5 93 20 46\n12 34\n40 41\n54 58\n100 121\n162 182\n220 349\n358 383\n390 398\n401 403\n408 409\n431 444\n466 470\n471 535\n556 568\n641 671\n699 709\n767 777\n786 859\n862 885\n912 978\n985 997\n1013 1017\n1032 1038\n1047 1048\n1062 1080\n1094 1097\n1102 1113\n1122 1181\n1239 1280\n1320 1369",
"output": "53608"
},
{
"input": "30 50 74 77 4 57\n17 23\n24 61\n67 68\n79 87\n93 101\n104 123\n150 192\n375 377\n398 414\n461 566\n600 633\n642 646\n657 701\n771 808\n812 819\n823 826\n827 833\n862 875\n880 891\n919 920\n928 959\n970 1038\n1057 1072\n1074 1130\n1165 1169\n1171 1230\n1265 1276\n1279 1302\n1313 1353\n1354 1438",
"output": "84067"
},
{
"input": "30 54 76 95 48 16\n9 11\n23 97\n112 116\n126 185\n214 223\n224 271\n278 282\n283 348\n359 368\n373 376\n452 463\n488 512\n532 552\n646 665\n681 685\n699 718\n735 736\n750 777\n791 810\n828 838\n841 858\n874 1079\n1136 1171\n1197 1203\n1210 1219\n1230 1248\n1280 1292\n1324 1374\n1397 1435\n1438 1439",
"output": "79844"
},
{
"input": "30 58 78 12 41 28\n20 26\n27 31\n35 36\n38 99\n103 104\n106 112\n133 143\n181 246\n248 251\n265 323\n350 357\n378 426\n430 443\n466 476\n510 515\n517 540\n542 554\n562 603\n664 810\n819 823\n826 845\n869 895\n921 973\n1002 1023\n1102 1136\n1143 1148\n1155 1288\n1316 1388\n1394 1403\n1434 1437",
"output": "82686"
},
{
"input": "30 62 80 97 25 47\n19 20\n43 75\n185 188\n199 242\n252 258\n277 310\n316 322\n336 357\n398 399\n404 436\n443 520\n549 617\n637 649\n679 694\n705 715\n725 730\n731 756\n768 793\n806 833\n834 967\n1003 1079\n1088 1097\n1100 1104\n1108 1121\n1127 1164\n1240 1263\n1274 1307\n1367 1407\n1419 1425\n1433 1437",
"output": "92356"
},
{
"input": "30 100 48 14 9 7\n26 55\n75 107\n145 146\n158 167\n197 199\n201 213\n222 238\n257 265\n271 338\n357 439\n454 462\n463 562\n633 660\n670 691\n696 829\n844 864\n880 888\n891 894\n895 900\n950 973\n1004 1007\n1018 1021\n1045 1049\n1062 1073\n1138 1184\n1240 1272\n1278 1315\n1403 1410\n1412 1418\n1426 1434",
"output": "107490"
},
{
"input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401",
"output": "25258"
},
{
"input": "30 7 52 49 46 37\n2 73\n129 130\n131 140\n143 150\n187 190\n217 238\n248 271\n375 426\n465 470\n475 503\n506 541\n569 571\n578 585\n680 683\n690 738\n742 761\n868 877\n890 892\n904 915\n935 961\n1076 1100\n1103 1114\n1232 1244\n1246 1247\n1257 1261\n1271 1276\n1280 1298\n1346 1360\n1373 1382\n1407 1419",
"output": "23992"
}
] | 92 | 0 | 0 | 289 |
81 | Plug-in | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu".
Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something!
Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"
},
{
"input": "il",
"output": "il"
},
{
"input": "gfj",
"output": "gfj"
},
{
"input": "babbbbbababa",
"output": "babababa"
},
{
"input": "babbbbabbabbbababbabbbbbbabaabaababaaabbbbbabbbbaaaaabbaaabbaabaabbbbabbbababbabaaabbababaaababbbaaa",
"output": "babababababababababababa"
},
{
"input": "aab",
"output": "b"
},
{
"input": "abb",
"output": "a"
},
{
"input": "aba",
"output": "aba"
},
{
"input": "ab",
"output": "ab"
}
] | 280 | 2,457,600 | 3.855422 | 290 |
131 | cAPS lOCK | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
"input": "oops",
"output": "oops"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "a"
},
{
"input": "aA",
"output": "Aa"
},
{
"input": "Zz",
"output": "Zz"
},
{
"input": "Az",
"output": "Az"
},
{
"input": "zA",
"output": "Za"
},
{
"input": "AAA",
"output": "aaa"
},
{
"input": "AAa",
"output": "AAa"
},
{
"input": "AaR",
"output": "AaR"
},
{
"input": "Tdr",
"output": "Tdr"
},
{
"input": "aTF",
"output": "Atf"
},
{
"input": "fYd",
"output": "fYd"
},
{
"input": "dsA",
"output": "dsA"
},
{
"input": "fru",
"output": "fru"
},
{
"input": "hYBKF",
"output": "Hybkf"
},
{
"input": "XweAR",
"output": "XweAR"
},
{
"input": "mogqx",
"output": "mogqx"
},
{
"input": "eOhEi",
"output": "eOhEi"
},
{
"input": "nkdku",
"output": "nkdku"
},
{
"input": "zcnko",
"output": "zcnko"
},
{
"input": "lcccd",
"output": "lcccd"
},
{
"input": "vwmvg",
"output": "vwmvg"
},
{
"input": "lvchf",
"output": "lvchf"
},
{
"input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO",
"output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo"
},
{
"input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG",
"output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg"
},
{
"input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS",
"output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ",
"output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq"
},
{
"input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR",
"output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR"
},
{
"input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE",
"output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE"
},
{
"input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ",
"output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ"
},
{
"input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm",
"output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm"
},
{
"input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm",
"output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm"
},
{
"input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg",
"output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg"
},
{
"input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc",
"output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc"
},
{
"input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv",
"output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv"
},
{
"input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect",
"output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu",
"output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu"
},
{
"input": "aBACABa",
"output": "aBACABa"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAaa",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAaa"
},
{
"input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
{
"input": "dDDDDDDDDDDDDD",
"output": "Dddddddddddddd"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "z",
"output": "Z"
},
{
"input": "AZ",
"output": "az"
},
{
"input": "Z",
"output": "z"
},
{
"input": "aAAAA",
"output": "Aaaaa"
},
{
"input": "F",
"output": "f"
}
] | 77 | 0 | 0 | 291 |
|
917 | The Monster | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him.
Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem.
A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally:
- Empty string is a correct bracket sequence. - if *s* is a correct bracket sequence, then (*s*) is also a correct bracket sequence. - if *s* and *t* are correct bracket sequences, then *st* (concatenation of *s* and *t*) is also a correct bracket sequence.
A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence.
Will gave his mom a string *s* consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (*l*,<=*r*) such that 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*| and the string *s**l**s**l*<=+<=1... *s**r* is pretty, where *s**i* is *i*-th character of *s*.
Joyce doesn't know anything about bracket sequences, so she asked for your help. | The first and only line of input contains string *s*, consisting only of characters '(', ')' and '?' (2<=≤<=|*s*|<=≤<=5000). | Print the answer to Will's puzzle in the first and only line of output. | [
"((?))\n",
"??()??\n"
] | [
"4\n",
"7\n"
] | For the first sample testcase, the pretty substrings of *s* are:
1. "(?" which can be transformed to "()". 1. "?)" which can be transformed to "()". 1. "((?)" which can be transformed to "(())". 1. "(?))" which can be transformed to "(())".
For the second sample testcase, the pretty substrings of *s* are:
1. "??" which can be transformed to "()". 1. "()". 1. "??()" which can be transformed to "()()". 1. "?()?" which can be transformed to "(())". 1. "??" which can be transformed to "()". 1. "()??" which can be transformed to "()()". 1. "??()??" which can be transformed to "()()()". | [
{
"input": "((?))",
"output": "4"
},
{
"input": "??()??",
"output": "7"
},
{
"input": "?????)(???",
"output": "21"
},
{
"input": "()()((?(()(((()()(())(((()((())))(()))(()(((((())))()))(((()()()))))))(((((()))))))))",
"output": "62"
},
{
"input": "))((()(()((((()))())()())((())())(((()()(())))))((())()()(()()(())()))()()(()()()(((()(()(()(()))))(",
"output": "88"
},
{
"input": "????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "2500"
},
{
"input": ")(",
"output": "0"
},
{
"input": "?(",
"output": "0"
},
{
"input": "??",
"output": "1"
},
{
"input": ")?(??((???????()?(?????????)??(????????((?)?????)????)??????(?????)?)?????)??????(??()??????)????????)?)()??????????????())????????(???)??)????????????????????(?????)??)???)??(???????????????)???)??)?",
"output": "8314"
},
{
"input": "()",
"output": "1"
},
{
"input": "(?",
"output": "1"
}
] | 249 | 22,630,400 | 3 | 292 |
|
803 | Roma and Poker | [
"dp",
"graphs"
] | null | null | Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.
Last evening Roma started to play poker. He decided to spend no more than *k* virtual bourles — he will stop immediately if the number of his loses exceeds the number of his wins by *k*. Also Roma will leave the game if he wins enough money for the evening, i.e. if the number of wins exceeds the number of loses by *k*.
Next morning Roma found a piece of paper with a sequence on it representing his results. Roma doesn't remember the results exactly, and some characters in the sequence are written in a way such that it's impossible to recognize this character, so Roma can't recall whether he won *k* bourles or he lost.
The sequence written by Roma is a string *s* consisting of characters W (Roma won the corresponding hand), L (Roma lost), D (draw) and ? (unknown result). Roma wants to restore any valid sequence by changing all ? characters to W, L or D. The sequence is called valid if all these conditions are met:
- In the end the absolute difference between the number of wins and loses is equal to *k*; - There is no hand such that the absolute difference before this hand was equal to *k*.
Help Roma to restore any such sequence. | The first line contains two numbers *n* (the length of Roma's sequence) and *k* (1<=≤<=*n*,<=*k*<=≤<=1000).
The second line contains the sequence *s* consisting of characters W, L, D and ?. There are exactly *n* characters in this sequence. | If there is no valid sequence that can be obtained from *s* by replacing all ? characters by W, L or D, print NO.
Otherwise print this sequence. If there are multiple answers, print any of them. | [
"3 2\nL??\n",
"3 1\nW??\n",
"20 5\n?LLLLLWWWWW?????????\n"
] | [
"LDL\n",
"NO\n",
"WLLLLLWWWWWWWWLWLWDW\n"
] | none | [
{
"input": "3 2\nL??",
"output": "LDL"
},
{
"input": "3 1\nW??",
"output": "NO"
},
{
"input": "20 5\n?LLLLLWWWWW?????????",
"output": "WLLLLLWWWWWWWWLWLWDW"
},
{
"input": "5 5\n?WDDD",
"output": "NO"
},
{
"input": "5 3\n??D??",
"output": "WWDDW"
},
{
"input": "10 1\nD??W?WL?DW",
"output": "NO"
},
{
"input": "10 3\nDWD?DL??LL",
"output": "DWDWDLLLLL"
},
{
"input": "10 2\nLWL?WWDDW?",
"output": "NO"
},
{
"input": "1 1\n?",
"output": "W"
}
] | 31 | 4,915,200 | 0 | 293 |
|
573 | Bear and Poker | [
"implementation",
"math",
"number theory"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058",
"output": "No"
},
{
"input": "2\n1 1",
"output": "Yes"
},
{
"input": "2\n72 72",
"output": "Yes"
},
{
"input": "2\n49 42",
"output": "No"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "Yes"
},
{
"input": "6\n162000 96000 648000 1000 864000 432000",
"output": "Yes"
},
{
"input": "8\n600000 100000 100000 100000 900000 600000 900000 600000",
"output": "Yes"
},
{
"input": "12\n2048 1024 6144 1024 3072 3072 6144 1024 4096 2048 6144 3072",
"output": "Yes"
},
{
"input": "20\n246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246",
"output": "Yes"
},
{
"input": "50\n840868705 387420489 387420489 795385082 634350497 206851546 536870912 536870912 414927754 387420489 387420489 536870912 387420489 149011306 373106005 536870912 700746206 387420489 777952883 847215247 176645254 576664386 387420489 230876513 536870912 536870912 536870912 387420489 387420489 536870912 460495524 528643722 387420489 536870912 470369206 899619085 387420489 631148352 387420489 387420489 536870912 414666674 521349938 776784669 387420489 102428009 536870912 387420489 536870912 718311009",
"output": "No"
},
{
"input": "2\n5 6",
"output": "No"
},
{
"input": "3\n536870912 387420489 257407169",
"output": "No"
},
{
"input": "4\n2 2 5 2",
"output": "No"
},
{
"input": "2\n33554432 59049",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 387420489",
"output": "Yes"
},
{
"input": "2\n1 5",
"output": "No"
},
{
"input": "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 71",
"output": "No"
},
{
"input": "2\n1 30",
"output": "No"
},
{
"input": "3\n335544320 71744535 71744535",
"output": "Yes"
},
{
"input": "5\n1000000000 999999999 999999998 999999997 999999996",
"output": "No"
},
{
"input": "2\n25 5",
"output": "No"
},
{
"input": "4\n75 150 75 5",
"output": "No"
},
{
"input": "3\n536870912 387420489 362797056",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 89",
"output": "No"
},
{
"input": "4\n547 2606459 222763549 143466789",
"output": "No"
},
{
"input": "3\n129140163 33554432 1",
"output": "Yes"
},
{
"input": "10\n244140625 244140625 244140625 244140625 244140625 244140625 244140625 244140625 536870912 387420489",
"output": "No"
},
{
"input": "3\n5 5 1",
"output": "No"
},
{
"input": "5\n3 7 29 36760123 823996703",
"output": "No"
}
] | 779 | 15,872,000 | 3 | 295 |
|
998 | Cutting | [
"dp",
"greedy",
"sortings"
] | null | null | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins. | First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers | Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. | [
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"6 100\n1 2 3 4 5 6\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. | [
{
"input": "6 4\n1 2 5 10 15 20",
"output": "1"
},
{
"input": "4 10\n1 3 2 4",
"output": "0"
},
{
"input": "6 100\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "2 100\n13 78",
"output": "0"
},
{
"input": "10 1\n56 56 98 2 11 64 97 41 95 53",
"output": "0"
},
{
"input": "10 100\n94 65 24 47 29 98 20 65 6 17",
"output": "2"
},
{
"input": "100 1\n35 6 19 84 49 64 36 91 50 65 21 86 20 89 10 52 50 24 98 74 11 48 58 98 51 85 1 29 44 83 9 97 68 41 83 57 1 57 46 42 87 2 32 50 3 57 17 77 22 100 36 27 3 34 55 8 90 61 34 20 15 39 43 46 60 60 14 23 4 22 75 51 98 23 69 22 99 57 63 30 79 7 16 8 34 84 13 47 93 40 48 25 93 1 80 6 82 93 6 21",
"output": "0"
},
{
"input": "100 10\n3 20 3 29 90 69 2 30 70 28 71 99 22 99 34 70 87 48 3 92 71 61 26 90 14 38 51 81 16 33 49 71 14 52 50 95 65 16 80 57 87 47 29 14 40 31 74 15 87 76 71 61 30 91 44 10 87 48 84 12 77 51 25 68 49 38 79 8 7 9 39 19 48 40 15 53 29 4 60 86 76 84 6 37 45 71 46 38 80 68 94 71 64 72 41 51 71 60 79 7",
"output": "2"
},
{
"input": "100 100\n60 83 82 16 17 7 89 6 83 100 85 41 72 44 23 28 64 84 3 23 33 52 93 30 81 38 67 25 26 97 94 78 41 74 74 17 53 51 54 17 20 81 95 76 42 16 16 56 74 69 30 9 82 91 32 13 47 45 97 40 56 57 27 28 84 98 91 5 61 20 3 43 42 26 83 40 34 100 5 63 62 61 72 5 32 58 93 79 7 18 50 43 17 24 77 73 87 74 98 2",
"output": "11"
},
{
"input": "100 100\n70 54 10 72 81 84 56 15 27 19 43 100 49 44 52 33 63 40 95 17 58 2 51 39 22 18 82 1 16 99 32 29 24 94 9 98 5 37 47 14 42 73 41 31 79 64 12 6 53 26 68 67 89 13 90 4 21 93 46 74 75 88 66 57 23 7 25 48 92 62 30 8 50 61 38 87 71 34 97 28 80 11 60 91 3 35 86 96 36 20 59 65 83 45 76 77 78 69 85 55",
"output": "3"
},
{
"input": "100 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "49"
},
{
"input": "10 10\n94 32 87 13 4 22 85 81 18 95",
"output": "1"
},
{
"input": "10 50\n40 40 9 3 64 96 67 19 21 30",
"output": "1"
},
{
"input": "100 50\n13 31 29 86 46 10 2 87 94 2 28 31 29 15 64 3 94 71 37 76 9 91 89 38 12 46 53 33 58 11 98 4 37 72 30 52 6 86 40 98 28 6 34 80 61 47 45 69 100 47 91 64 87 41 67 58 88 75 13 81 36 58 66 29 10 27 54 83 44 15 11 33 49 36 61 18 89 26 87 1 99 19 57 21 55 84 20 74 14 43 15 51 2 76 22 92 43 14 72 77",
"output": "3"
},
{
"input": "100 1\n78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 31 37 12 35 99 67 94 1 87 57 8 61 19 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30",
"output": "0"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "0"
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "1"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "1"
},
{
"input": "100 10\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "10"
},
{
"input": "100 50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "49"
},
{
"input": "100 30\n2 1 2 2 2 2 1 1 1 2 1 1 2 2 1 2 1 2 2 2 2 1 2 1 2 1 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 2 1 2 2 1 1 1 1 2 2 2 1 2 2 1 2 1 1 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1 2 1 1 2",
"output": "11"
},
{
"input": "100 80\n1 1 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 2 2 1 1 2 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 2 1 1 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 1 2",
"output": "12"
},
{
"input": "100 30\n100 99 100 99 99 100 100 99 100 99 99 100 100 100 99 99 99 100 99 99 99 99 100 99 99 100 100 99 100 99 99 99 100 99 100 100 99 100 100 100 100 100 99 99 100 99 99 100 99 100 99 99 100 100 99 100 99 99 100 99 100 100 100 100 99 99 99 100 99 100 99 100 100 100 99 100 100 100 99 100 99 99 100 100 100 100 99 99 99 100 99 100 100 99 99 99 100 100 99 99",
"output": "14"
},
{
"input": "100 80\n99 100 100 100 99 99 99 99 100 99 99 99 99 99 99 99 99 100 100 99 99 99 99 99 100 99 100 99 100 100 100 100 100 99 100 100 99 99 100 100 100 100 100 99 100 99 100 99 99 99 100 99 99 99 99 99 99 99 99 100 99 100 100 99 99 99 99 100 100 100 99 100 100 100 100 100 99 100 100 100 100 100 100 100 100 99 99 99 99 100 99 100 100 100 100 100 99 100 99 100",
"output": "4"
},
{
"input": "100 30\n100 100 39 39 39 100 100 39 39 100 39 39 100 39 100 39 100 100 100 100 100 39 100 100 100 39 39 39 100 39 100 100 39 39 100 39 39 39 100 100 39 100 39 100 39 39 100 100 39 100 39 100 39 39 39 100 39 100 39 39 39 100 39 39 100 100 39 39 39 100 100 39 39 39 100 100 100 100 39 100 100 100 39 39 100 39 100 100 39 100 39 100 39 39 100 39 39 100 100 100",
"output": "5"
},
{
"input": "100 80\n39 100 39 100 100 100 100 39 39 100 100 39 39 100 39 39 39 39 100 39 39 39 39 100 100 100 100 39 100 39 39 100 100 39 39 100 39 100 39 100 100 39 39 100 39 39 39 100 39 100 39 100 100 100 100 100 100 100 39 100 39 100 100 100 39 39 39 39 39 100 100 100 39 100 100 100 100 39 100 100 39 39 100 39 39 39 100 39 100 39 39 100 100 39 100 39 39 39 100 39",
"output": "6"
},
{
"input": "4 1\n1 2 3 4",
"output": "1"
},
{
"input": "4 1\n1 2 1 2",
"output": "1"
},
{
"input": "4 4\n1 2 6 7",
"output": "1"
},
{
"input": "4 8\n1 2 10 11",
"output": "1"
},
{
"input": "6 2\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "6 1\n1 2 1 2 1 2",
"output": "1"
},
{
"input": "6 4\n1 2 4 5 7 8",
"output": "2"
},
{
"input": "6 3\n1 2 5 10 15 20",
"output": "1"
}
] | 93 | 307,200 | 3 | 298 |
|
305 | Strange Addition | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*.
Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? | The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers.
The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100). | In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order. | [
"4\n100 10 1 0\n",
"3\n2 70 3\n"
] | [
"4\n0 1 10 100 ",
"2\n2 70 "
] | none | [
{
"input": "4\n100 10 1 0",
"output": "4\n0 1 10 100 "
},
{
"input": "3\n2 70 3",
"output": "2\n2 70 "
},
{
"input": "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29",
"output": "4\n0 6 30 100 "
},
{
"input": "50\n20 67 96 6 75 12 37 46 38 86 83 22 10 8 21 2 93 9 81 49 69 52 63 62 70 92 97 40 47 99 16 85 48 77 39 100 28 5 11 44 89 1 19 42 35 27 7 14 88 33",
"output": "3\n1 10 100 "
},
{
"input": "2\n1 2",
"output": "1\n1 "
},
{
"input": "73\n39 66 3 59 40 93 72 34 95 79 83 65 99 57 48 44 82 76 31 21 64 19 53 75 37 16 43 5 47 24 15 22 20 55 45 74 42 10 61 49 23 80 35 62 2 9 67 97 51 81 1 70 88 63 33 25 68 13 69 71 73 6 18 52 41 38 96 46 92 85 14 36 100",
"output": "3\n1 10 100 "
},
{
"input": "15\n74 90 73 47 36 44 81 21 66 92 2 38 62 72 49",
"output": "2\n2 90 "
},
{
"input": "96\n17 10 0 85 57 78 15 99 55 6 7 88 12 95 58 19 47 18 96 82 21 80 97 77 46 31 54 70 23 60 59 100 66 92 51 14 91 25 16 27 44 4 35 98 8 52 24 5 81 29 73 13 61 56 45 75 49 71 94 48 3 76 32 65 72 1 84 36 86 40 83 50 22 33 41 11 26 93 90 43 39 79 89 9 64 68 42 74 87 2 62 34 20 63 67 37",
"output": "4\n0 1 10 100 "
},
{
"input": "5\n23 75 38 47 70",
"output": "1\n23 "
},
{
"input": "12\n89 61 45 92 22 3 94 66 48 21 54 14",
"output": "1\n3 "
},
{
"input": "1\n99",
"output": "1\n99 "
},
{
"input": "1\n0",
"output": "1\n0 "
},
{
"input": "2\n100 1",
"output": "2\n1 100 "
},
{
"input": "3\n1 100 99",
"output": "2\n1 100 "
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "3\n1 10 100 "
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 100 0",
"output": "4\n0 1 10 100 "
},
{
"input": "99\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99",
"output": "2\n1 10 "
},
{
"input": "2\n5 6",
"output": "1\n5 "
},
{
"input": "81\n11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 58 59 61 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 78 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 97 98 99",
"output": "1\n11 "
},
{
"input": "3\n99 10 6",
"output": "2\n6 10 "
},
{
"input": "4\n11 10 100 3",
"output": "3\n3 10 100 "
},
{
"input": "2\n99 6",
"output": "1\n6 "
},
{
"input": "3\n23 0 100",
"output": "3\n0 23 100 "
},
{
"input": "2\n43 0",
"output": "2\n0 43 "
},
{
"input": "4\n99 0 100 6",
"output": "3\n0 6 100 "
},
{
"input": "1\n100",
"output": "1\n100 "
},
{
"input": "2\n0 100",
"output": "2\n0 100 "
},
{
"input": "3\n0 100 10",
"output": "3\n0 10 100 "
},
{
"input": "3\n0 100 12",
"output": "3\n0 12 100 "
},
{
"input": "3\n0 100 1",
"output": "3\n0 1 100 "
},
{
"input": "4\n0 100 10 1",
"output": "4\n0 1 10 100 "
},
{
"input": "4\n0 100 10 99",
"output": "3\n0 10 100 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "2\n10 12",
"output": "1\n10 "
},
{
"input": "2\n90 9",
"output": "2\n9 90 "
}
] | 92 | 0 | 0 | 300 |
|
430 | Points and Segments (easy) | [
"constructive algorithms",
"sortings"
] | null | null | Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following.
Iahub wants to draw *n* distinct points and *m* segments on the *OX* axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [*l**i*,<=*r**i*] consider all the red points belong to it (*r**i* points), and all the blue points belong to it (*b**i* points); each segment *i* should satisfy the inequality |*r**i*<=-<=*b**i*|<=≤<=1.
Iahub thinks that point *x* belongs to segment [*l*,<=*r*], if inequality *l*<=≤<=*x*<=≤<=*r* holds.
Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. | The first line of input contains two integers: *n* (1<=≤<=*n*<=≤<=100) and *m* (1<=≤<=*m*<=≤<=100). The next line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100) — the coordinates of the points. The following *m* lines contain the descriptions of the *m* segments. Each line contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=100) — the borders of the *i*-th segment.
It's guaranteed that all the points are distinct. | If there is no good drawing for a given test, output a single integer -1. Otherwise output *n* integers, each integer must be 0 or 1. The *i*-th number denotes the color of the *i*-th point (0 is red, and 1 is blue).
If there are multiple good drawings you can output any of them. | [
"3 3\n3 7 14\n1 5\n6 10\n11 15\n",
"3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2\n"
] | [
"0 0 0",
"1 0 1 "
] | none | [
{
"input": "3 3\n3 7 14\n1 5\n6 10\n11 15",
"output": "0 0 0"
},
{
"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2",
"output": "1 0 1 "
},
{
"input": "10 10\n3 4 2 6 1 9 0 5 8 7\n5 7\n2 6\n0 1\n5 6\n3 4\n2 5\n2 10\n4 6\n3 6\n3 7",
"output": "0 1 1 1 0 0 1 0 1 0 "
},
{
"input": "3 3\n50 51 52\n1 5\n6 10\n11 15",
"output": "1 0 1 "
},
{
"input": "3 1\n1 2 3\n2 3",
"output": "1 0 1 "
}
] | 61 | 0 | 0 | 301 |
|
617 | Elephant | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 140 | 1,331,200 | 3 | 303 |
|
1,009 | Minimum Ternary String | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
- "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201".
Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
"input": "021",
"output": "012"
},
{
"input": "2",
"output": "2"
},
{
"input": "201",
"output": "120"
},
{
"input": "2112120",
"output": "1112220"
},
{
"input": "102",
"output": "012"
},
{
"input": "202",
"output": "202"
},
{
"input": "220201",
"output": "122020"
},
{
"input": "12",
"output": "12"
},
{
"input": "100022202",
"output": "000122202"
},
{
"input": "01",
"output": "01"
},
{
"input": "1",
"output": "1"
}
] | 61 | 0 | 0 | 306 |
|
6 | Exposition | [
"binary search",
"data structures",
"dsu",
"trees",
"two pointers"
] | E. Exposition | 1 | 64 | There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than *k* millimeters.
The library has *n* volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is *h**i*. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. | The first line of the input data contains two integer numbers separated by a space *n* (1<=≤<=*n*<=≤<=105) and *k* (0<=≤<=*k*<=≤<=106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separated by a space. Each number *h**i* (1<=≤<=*h**i*<=≤<=106) is the height of the *i*-th book in millimeters. | In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* — the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and the highest among these books is not more than *k* milllimeters.
In each of the following *b* lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. | [
"3 3\n14 12 10\n",
"2 0\n10 10\n",
"4 5\n8 19 10 13\n"
] | [
"2 2\n1 2\n2 3\n",
"2 1\n1 2\n",
"2 1\n3 4\n"
] | none | [
{
"input": "3 3\n14 12 10",
"output": "2 2\n1 2\n2 3"
},
{
"input": "2 0\n10 10",
"output": "2 1\n1 2"
},
{
"input": "4 5\n8 19 10 13",
"output": "2 1\n3 4"
},
{
"input": "1 1\n1",
"output": "1 1\n1 1"
},
{
"input": "2 10\n35 45",
"output": "2 1\n1 2"
},
{
"input": "4 8\n89 33 54 75",
"output": "1 4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "5 1\n9 6 8 7 5",
"output": "2 1\n3 4"
},
{
"input": "3 3\n3 8 6",
"output": "2 1\n2 3"
},
{
"input": "4 1000000\n100001 1 200001 300001",
"output": "4 1\n1 4"
},
{
"input": "4 1000\n11497 9999 10730 12280",
"output": "2 1\n2 3"
},
{
"input": "3 0\n1000000 1000000 1000000",
"output": "3 1\n1 3"
},
{
"input": "4 50\n165 182 157 132",
"output": "4 1\n1 4"
},
{
"input": "5 173\n350 250 200 300 400",
"output": "4 1\n1 4"
},
{
"input": "4 0\n1 1 1 1",
"output": "4 1\n1 4"
},
{
"input": "2 1000000\n1 1000000",
"output": "2 1\n1 2"
},
{
"input": "7 14\n28 28 29 35 25 29 28",
"output": "7 1\n1 7"
},
{
"input": "10 163\n7541 2535 5883 5775 2821 5962 4489 5548 2852 4595",
"output": "2 1\n3 4"
},
{
"input": "15 793\n98580 27440 3719 73977 34819 64092 89939 75329 72884 66502 17464 73662 6666 47984 45348",
"output": "1 15\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15"
},
{
"input": "28 543\n1921 1700 1363 2580 2693 3144 2269 908 3863 3750 2151 3039 1581 3395 1133 1804 1464 2040 2372 2475 1240 800 3521 3270 2815 1026 3625 2930",
"output": "3 1\n18 20"
},
{
"input": "55 1000\n2612 1306 4300 1790 3173 9493 7209 7763 8563 4534 7466 1281 4483 6863 3787 7292 3957 8775 7221 4016 5743 6556 2070 2119 4795 9094 1913 2077 8786 4520 1865 2357 7871 3288 8231 5808 9383 9820 9974 3056 5343 2169 5177 6299 5805 8132 9315 6747 5226 3531 1206 4073 8290 1423 6720",
"output": "3 1\n37 39"
}
] | 46 | 5,324,800 | 0 | 307 |
177 | Good Matrix Elements | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
Help the Smart Beaver count the sum of good elements of the given matrix. | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 points are:
- 1<=≤<=*n*<=≤<=101 | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
"output": "756"
},
{
"input": "3\n19 7 16\n12 15 5\n15 15 5",
"output": "109"
},
{
"input": "3\n36 4 33\n11 46 32\n20 49 34",
"output": "265"
},
{
"input": "3\n79 91 74\n33 82 22\n18 28 54",
"output": "481"
},
{
"input": "5\n7 0 8 1 7\n5 1 1 0 4\n4 2 8 1 6\n1 2 3 2 7\n6 0 1 9 6",
"output": "65"
},
{
"input": "5\n27 20 28 11 17\n25 21 1 20 14\n14 22 28 1 6\n1 2 23 2 7\n6 0 1 29 6",
"output": "225"
},
{
"input": "5\n57 50 58 41 17\n25 21 1 50 44\n44 22 28 31 36\n31 32 23 32 37\n6 0 31 59 6",
"output": "495"
},
{
"input": "5\n57 80 28 41 47\n85 51 61 50 74\n44 82 28 31 36\n31 32 23 32 37\n66 60 31 59 6",
"output": "705"
},
{
"input": "5\n13 58 10 17 43\n61 73 100 0 9\n52 38 16 22 96\n11 4 14 67 62\n70 89 7 98 83",
"output": "708"
},
{
"input": "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 1 0 1 0\n0 0 0 0 1\n0 0 5 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "5"
},
{
"input": "5\n0 0 0 0 1\n0 1 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "3\n0 0 0\n0 0 0\n0 0 0",
"output": "0"
},
{
"input": "11\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "15\n0 2 1 2 1 0 2 0 2 2 2 2 2 0 2\n2 0 1 0 1 1 2 2 0 2 2 0 3 0 1\n3 3 2 2 2 1 2 3 2 3 1 2 3 3 2\n0 3 0 3 3 3 2 1 0 2 3 2 3 3 2\n3 0 0 2 1 2 3 1 1 1 2 2 2 1 0\n1 3 2 3 3 0 3 2 0 3 1 2 3 0 3\n2 2 3 2 0 0 2 3 0 1 2 1 1 2 1\n2 1 3 2 3 3 2 2 2 0 3 3 1 1 3\n0 2 1 3 1 2 0 0 1 0 0 2 0 0 0\n3 1 2 1 2 3 2 3 2 1 0 2 2 0 3\n0 0 1 3 3 0 1 1 0 0 2 3 0 3 0\n2 3 0 3 1 1 2 2 1 3 2 3 0 0 2\n3 0 2 2 3 3 0 2 2 2 0 1 0 0 3\n2 2 2 1 2 2 2 0 2 2 2 2 0 2 3\n2 2 3 0 0 0 0 2 1 1 1 3 2 2 0",
"output": "97"
}
] | 124 | 307,200 | 3 | 308 |
|
0 | none | [
"none"
] | null | null | Профиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёздочку». Гарантируется, что любой из символов «*» либо находится в нижней строке матрицы, либо непосредственно под ним находится другой символ «*».
Маршрут туриста проходит через весь горный хребет слева направо. Каждый день турист перемещается вправо — в соседний столбец в схематичном изображении. Конечно, каждый раз он поднимается (или опускается) в самую верхнюю точку горы, которая находится в соответствующем столбце.
Считая, что изначально турист находится в самой верхней точке в первом столбце, а закончит свой маршрут в самой верхней точке в последнем столбце, найдите две величины:
- наибольший подъём за день (равен 0, если в профиле горного хребта нет ни одного подъёма), - наибольший спуск за день (равен 0, если в профиле горного хребта нет ни одного спуска). | В первой строке входных данных записаны два целых числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=100) — количество строк и столбцов в схематичном изображении соответственно.
Далее следуют *n* строк по *m* символов в каждой — схематичное изображение горного хребта. Каждый символ схематичного изображения — это либо «.», либо «*». Каждый столбец матрицы содержит хотя бы один символ «*». Гарантируется, что любой из символов «*» либо находится в нижней строке матрицы, либо непосредственно под ним находится другой символ «*». | Выведите через пробел два целых числа:
- величину наибольшего подъёма за день (или 0, если в профиле горного хребта нет ни одного подъёма), - величину наибольшего спуска за день (или 0, если в профиле горного хребта нет ни одного спуска). | [
"6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********\n",
"5 5\n....*\n...**\n..***\n.****\n*****\n",
"8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******\n"
] | [
"3 4\n",
"1 0\n",
"6 2\n"
] | В первом тестовом примере высоты гор равны: 3, 4, 1, 1, 2, 1, 1, 1, 2, 5, 1. Наибольший подъем равен 3 и находится между горой номер 9 (её высота равна 2) и горой номер 10 (её высота равна 5). Наибольший спуск равен 4 и находится между горой номер 10 (её высота равна 5) и горой номер 11 (её высота равна 1).
Во втором тестовом примере высоты гор равны: 1, 2, 3, 4, 5. Наибольший подъём равен 1 и находится, например, между горой номер 2 (ее высота равна 2) и горой номер 3 (её высота равна 3). Так как в данном горном хребте нет спусков, то величина наибольшего спуска равна 0.
В третьем тестовом примере высоты гор равны: 1, 7, 5, 3, 4, 2, 3. Наибольший подъём равен 6 и находится между горой номер 1 (её высота равна 1) и горой номер 2 (её высота равна 7). Наибольший спуск равен 2 и находится между горой номер 2 (её высота равна 7) и горой номер 3 (её высота равна 5). Такой же спуск находится между горой номер 5 (её высота равна 4) и горой номер 6 (её высота равна 2). | [
{
"input": "6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********",
"output": "3 4"
},
{
"input": "5 5\n....*\n...**\n..***\n.****\n*****",
"output": "1 0"
},
{
"input": "8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******",
"output": "6 2"
},
{
"input": "1 1\n*",
"output": "0 0"
},
{
"input": "2 2\n**\n**",
"output": "0 0"
},
{
"input": "1 10\n**********",
"output": "0 0"
},
{
"input": "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*",
"output": "0 0"
},
{
"input": "5 5\n.....\n.....\n*****\n*****\n*****",
"output": "0 0"
},
{
"input": "10 6\n......\n......\n......\n******\n******\n******\n******\n******\n******\n******",
"output": "0 0"
},
{
"input": "5 11\n***********\n***********\n***********\n***********\n***********",
"output": "0 0"
},
{
"input": "10 10\n..........\n..........\n.....*....\n.....*....\n.*...*....\n.*...*....\n.*..**....\n.*..**.*..\n.*..**.*..\n**********",
"output": "5 7"
},
{
"input": "10 20\n.*..................\n.*......*...........\n.**.....*..*........\n.**.....*..*........\n.**.....*..*........\n.**.....*..*........\n.**.*..**..*........\n.**.*****..*........\n**********.*.......*\n********************",
"output": "8 7"
},
{
"input": "10 30\n....*...........*.............\n.*..*.......*...*.............\n.*..*.....*.*...*............*\n.*..*..*..*.*...*............*\n.*..*..*..*.*...*..........*.*\n.*..*..*..*.*...*....*.....***\n.**.*..*..*.**..*.*..*.....***\n***.*..*..*.**..*.*..**.**.***\n***.**********..***..*****.***\n******************************",
"output": "9 8"
},
{
"input": "10 40\n*..................................*....\n*.....*..............*.............*....\n*.....*..............*............**....\n*..*..***...*...*....*.....*.*....**....\n*.**..***...*...*....*.....*.*...***....\n*.**..****.***..*..*.*..*..*.**..***.*..\n*.**..****.***.**..*.*..*.**.**..***.*..\n*.**..************.*.*..*.*****..***.**.\n*.***.************.*.*.*************.***\n****************************************",
"output": "8 9"
},
{
"input": "20 10\n..........\n..........\n..........\n..........\n..........\n.....*....\n.....*....\n.....*....\n.....*....\n.....*....\n.....*....\n.....*....\n...*.*....\n...*.*....\n...*.*....\n...***....\n..****.*..\n..****.**.\n..****.***\n**********",
"output": "10 14"
},
{
"input": "20 20\n........*...........\n........*........*..\n........*........*..\n.**.....*.......**..\n.**.....*.......**..\n.**.....*.....*.**..\n.**.....*.....*.**..\n.**.....*.....*.**..\n.**.....*.....*.**..\n.**.*...*.....*.**..\n.**.*...*.....*.**..\n.**.*...*....**.**..\n.**.*...*..*.**.**..\n.**.*...*..*.**.**..\n.**.*...**.*.**.***.\n.**.*.*.**.*.**.***.\n.**.*.*.**.*.**.***.\n.**.*.*.****.*******\n.****.******.*******\n********************",
"output": "18 15"
},
{
"input": "30 10\n..........\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n.......*..\n......**..\n......**..\n......**..\n.*....**..\n.*....**..\n.*.*..**..\n.*.*..**..\n.*.*..**..\n.*.*.***..\n.*******..\n.*******.*\n.*********\n**********",
"output": "16 27"
},
{
"input": "1 100\n****************************************************************************************************",
"output": "0 0"
},
{
"input": "100 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*",
"output": "0 0"
},
{
"input": "100 2\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n*.\n*.\n*.\n*.\n*.\n*.\n*.\n*.\n*.\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**",
"output": "0 9"
},
{
"input": "2 100\n*..*....*......................*.*..*.*.*....*.*.*....*.........*.*...*....**.........*.**....*.....\n****************************************************************************************************",
"output": "1 1"
},
{
"input": "5 12\n............\n............\n............\n............\n************",
"output": "0 0"
},
{
"input": "5 12\n............\n************\n************\n************\n************",
"output": "0 0"
},
{
"input": "5 12\n************\n************\n************\n************\n************",
"output": "0 0"
}
] | 46 | 4,812,800 | -1 | 309 |
|
259 | Little Elephant and Magic Square | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes. | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions. | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 57 78\n66 60 45"
},
{
"input": "0 17 14\n15 0 15\n16 13 0",
"output": "14 17 14\n15 15 15\n16 13 16"
},
{
"input": "0 97 56\n69 0 71\n84 43 0",
"output": "57 97 56\n69 70 71\n84 43 83"
},
{
"input": "0 1099 1002\n1027 0 1049\n1074 977 0",
"output": "1013 1099 1002\n1027 1038 1049\n1074 977 1063"
},
{
"input": "0 98721 99776\n99575 0 99123\n98922 99977 0",
"output": "99550 98721 99776\n99575 99349 99123\n98922 99977 99148"
},
{
"input": "0 6361 2304\n1433 0 8103\n7232 3175 0",
"output": "5639 6361 2304\n1433 4768 8103\n7232 3175 3897"
},
{
"input": "0 99626 99582\n99766 0 99258\n99442 99398 0",
"output": "99328 99626 99582\n99766 99512 99258\n99442 99398 99696"
},
{
"input": "0 99978 99920\n99950 0 99918\n99948 99890 0",
"output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964"
},
{
"input": "0 840 666\n612 0 948\n894 720 0",
"output": "834 840 666\n612 780 948\n894 720 726"
},
{
"input": "0 28 10\n12 0 24\n26 8 0",
"output": "16 28 10\n12 18 24\n26 8 20"
},
{
"input": "0 120 83\n98 0 90\n105 68 0",
"output": "79 120 83\n98 94 90\n105 68 109"
},
{
"input": "0 86900 85807\n85836 0 86842\n86871 85778 0",
"output": "86310 86900 85807\n85836 86339 86842\n86871 85778 86368"
},
{
"input": "0 74 78\n78 0 74\n74 78 0",
"output": "76 74 78\n78 76 74\n74 78 76"
},
{
"input": "0 505 681\n605 0 657\n581 757 0",
"output": "707 505 681\n605 631 657\n581 757 555"
},
{
"input": "0 662 918\n822 0 854\n758 1014 0",
"output": "934 662 918\n822 838 854\n758 1014 742"
},
{
"input": "0 93 95\n93 0 97\n95 97 0",
"output": "97 93 95\n93 95 97\n95 97 93"
},
{
"input": "0 709 712\n719 0 695\n702 705 0",
"output": "700 709 712\n719 707 695\n702 705 714"
},
{
"input": "0 7 6\n9 0 1\n4 3 0",
"output": "2 7 6\n9 5 1\n4 3 8"
},
{
"input": "0 9 2\n3 0 7\n8 1 0",
"output": "4 9 2\n3 5 7\n8 1 6"
},
{
"input": "0 1 43\n13 0 61\n31 73 0",
"output": "67 1 43\n13 37 61\n31 73 7"
},
{
"input": "0 100000 100000\n100000 0 100000\n100000 100000 0",
"output": "100000 100000 100000\n100000 100000 100000\n100000 100000 100000"
}
] | 280 | 0 | 3 | 310 |
|
878 | Short Program | [
"bitmasks",
"constructive algorithms"
] | null | null | Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.
Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of lines.
Next *n* lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant *x**i* 0<=≤<=*x**i*<=≤<=1023. | Output an integer *k* (0<=≤<=*k*<=≤<=5) — the length of your program.
Next *k* lines must contain commands in the same format as in the input. | [
"3\n| 3\n^ 2\n| 1\n",
"3\n& 1\n& 3\n& 5\n",
"3\n^ 1\n^ 2\n^ 3\n"
] | [
"2\n| 3\n^ 2\n",
"1\n& 1\n",
"0\n"
] | You can read about bitwise operations in [https://en.wikipedia.org/wiki/Bitwise_operation](https://en.wikipedia.org/wiki/Bitwise_operation).
Second sample:
Let *x* be an input of the Petya's program. It's output is ((*x*&1)&3)&5 = *x*&(1&3&5) = *x*&1. So these two programs always give the same outputs. | [
{
"input": "3\n| 3\n^ 2\n| 1",
"output": "2\n| 3\n^ 2"
},
{
"input": "3\n& 1\n& 3\n& 5",
"output": "1\n& 1"
},
{
"input": "3\n^ 1\n^ 2\n^ 3",
"output": "0"
},
{
"input": "2\n| 999\n^ 689",
"output": "2\n| 999\n^ 689"
},
{
"input": "3\n& 242\n^ 506\n^ 522",
"output": "2\n| 781\n^ 253"
},
{
"input": "2\n| 56\n^ 875",
"output": "2\n| 56\n^ 875"
},
{
"input": "3\n^ 125\n^ 377\n& 1019",
"output": "2\n| 4\n^ 260"
},
{
"input": "1\n& 123",
"output": "1\n& 123"
},
{
"input": "1\n| 123",
"output": "1\n| 123"
},
{
"input": "1\n^ 123",
"output": "1\n^ 123"
},
{
"input": "10\n^ 218\n& 150\n| 935\n& 61\n| 588\n& 897\n| 411\n| 584\n^ 800\n| 704",
"output": "2\n| 1023\n^ 260"
},
{
"input": "10\n^ 160\n& 1021\n& 510\n^ 470\n& 1022\n& 251\n& 760\n& 1016\n| 772\n| 515",
"output": "2\n| 775\n^ 112"
},
{
"input": "1\n& 0",
"output": "1\n& 0"
},
{
"input": "1\n| 0",
"output": "0"
},
{
"input": "1\n^ 0",
"output": "0"
},
{
"input": "1\n& 1023",
"output": "0"
},
{
"input": "1\n| 1023",
"output": "1\n| 1023"
},
{
"input": "1\n^ 1023",
"output": "1\n^ 1023"
}
] | 46 | 0 | 0 | 311 |
|
964 | Messages | [
"math"
] | null | null | There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.
Also, each minute Vasya's bank account receives *C*·*k*, where *k* is the amount of received but unread messages.
Vasya's messages are very important to him, and because of that he wants to have all messages read after *T* minutes.
Determine the maximum amount of money Vasya's bank account can hold after *T* minutes. | The first line contains five integers *n*, *A*, *B*, *C* and *T* (1<=≤<=*n*,<=*A*,<=*B*,<=*C*,<=*T*<=≤<=1000).
The second string contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=*T*). | Output one integer — the answer to the problem. | [
"4 5 5 3 5\n1 5 5 4\n",
"5 3 1 1 3\n2 2 2 1 1\n",
"5 5 3 4 5\n1 2 3 4 5\n"
] | [
"20\n",
"15\n",
"35\n"
] | In the first sample the messages must be read immediately after receiving, Vasya receives *A* points for each message, *n*·*A* = 20 in total.
In the second sample the messages can be read at any integer moment.
In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 = - 5 points. This is 35 in total. | [
{
"input": "4 5 5 3 5\n1 5 5 4",
"output": "20"
},
{
"input": "5 3 1 1 3\n2 2 2 1 1",
"output": "15"
},
{
"input": "5 5 3 4 5\n1 2 3 4 5",
"output": "35"
},
{
"input": "1 6 4 3 9\n2",
"output": "6"
},
{
"input": "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3",
"output": "90"
},
{
"input": "44 464 748 420 366\n278 109 293 161 336 9 194 203 13 226 303 303 300 131 134 47 235 110 263 67 185 337 360 253 270 97 162 190 143 267 18 311 329 138 322 167 324 33 3 104 290 260 349 89",
"output": "20416"
},
{
"input": "80 652 254 207 837\n455 540 278 38 19 781 686 110 733 40 434 581 77 381 818 236 444 615 302 251 762 676 771 483 767 479 326 214 316 551 544 95 157 828 813 201 103 502 751 410 84 733 431 90 261 326 731 374 730 748 303 83 302 673 50 822 46 590 248 751 345 579 689 616 331 593 428 344 754 777 178 80 602 268 776 234 637 780 712 539",
"output": "52160"
},
{
"input": "62 661 912 575 6\n3 5 6 6 5 6 6 6 3 2 3 1 4 3 2 5 3 6 1 4 2 5 1 2 6 4 6 6 5 5 4 3 4 1 4 2 4 4 2 6 4 6 3 5 3 4 1 5 3 6 5 6 4 1 2 1 6 5 5 4 2 3",
"output": "40982"
},
{
"input": "49 175 330 522 242\n109 81 215 5 134 185 60 242 154 148 14 221 146 229 45 120 142 43 202 176 231 105 212 69 109 219 58 103 53 211 128 138 157 95 96 122 69 109 35 46 122 118 132 135 224 150 178 134 28",
"output": "1083967"
},
{
"input": "27 27 15 395 590\n165 244 497 107 546 551 232 177 428 237 209 186 135 162 511 514 408 132 11 364 16 482 279 246 30 103 152",
"output": "3347009"
},
{
"input": "108 576 610 844 573\n242 134 45 515 430 354 405 179 174 366 155 4 300 176 96 36 508 70 75 316 118 563 55 340 128 214 138 511 507 437 454 478 341 443 421 573 270 362 208 107 256 471 436 378 336 507 383 352 450 411 297 34 179 551 119 524 141 288 387 9 283 241 304 214 503 559 416 447 495 61 169 228 479 568 368 441 467 401 467 542 370 243 371 315 65 67 161 383 19 144 283 5 369 242 122 396 276 488 401 387 256 128 87 425 124 226 335 238",
"output": "6976440"
},
{
"input": "67 145 951 829 192\n2 155 41 125 20 70 43 47 120 190 141 8 37 183 72 141 52 168 185 71 36 12 31 3 151 98 95 82 148 110 64 10 67 54 176 130 116 5 61 90 24 43 156 49 70 186 165 109 56 11 148 119 139 120 138 124 3 159 75 173 4 101 190 64 90 176 176",
"output": "9715"
},
{
"input": "67 322 317 647 99\n68 33 75 39 10 60 93 40 77 71 90 14 67 26 54 87 91 67 60 76 83 7 20 47 39 79 54 43 35 9 19 39 77 56 83 31 95 15 40 37 56 88 7 89 11 49 72 48 85 95 50 78 12 1 81 53 94 97 9 26 78 62 57 23 18 19 4",
"output": "1066024"
},
{
"input": "32 2 74 772 674\n598 426 358 191 471 667 412 44 183 358 436 654 572 489 79 191 374 33 1 627 154 132 101 236 443 112 77 93 553 53 260 498",
"output": "8161080"
},
{
"input": "111 907 98 340 279\n187 200 223 12 179 57 81 195 250 139 2 190 21 91 145 251 113 41 18 55 235 123 99 154 179 81 59 20 145 244 131 210 76 6 198 43 71 267 60 92 101 265 55 63 231 232 74 233 246 265 102 92 78 111 107 37 51 135 38 62 156 112 70 37 227 25 111 263 175 114 4 128 50 276 226 119 130 33 134 38 48 229 108 88 53 142 233 86 214 173 136 68 2 202 132 49 73 205 208 224 99 96 116 5 74 179 63 197 58 68 50",
"output": "4297441"
}
] | 93 | 7,065,600 | 3 | 313 |
|
514 | Chewbaсca and Number | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
"output": "21223442"
},
{
"input": "91730629",
"output": "91230320"
},
{
"input": "420062703497",
"output": "420032203402"
},
{
"input": "332711047202",
"output": "332211042202"
},
{
"input": "3395184971407775",
"output": "3304114021402224"
},
{
"input": "8464062628894325",
"output": "1434032321104324"
},
{
"input": "164324828731963982",
"output": "134324121231033012"
},
{
"input": "384979173822804784",
"output": "314020123122104214"
},
{
"input": "41312150450968417",
"output": "41312140440031412"
},
{
"input": "2156",
"output": "2143"
},
{
"input": "1932",
"output": "1032"
},
{
"input": "5902",
"output": "4002"
},
{
"input": "5728",
"output": "4221"
},
{
"input": "8537",
"output": "1432"
},
{
"input": "55403857",
"output": "44403142"
},
{
"input": "270739",
"output": "220230"
},
{
"input": "28746918",
"output": "21243011"
},
{
"input": "10279211",
"output": "10220211"
},
{
"input": "40289679",
"output": "40210320"
},
{
"input": "545203238506",
"output": "444203231403"
},
{
"input": "461117063340",
"output": "431112033340"
},
{
"input": "658492686568",
"output": "341402313431"
},
{
"input": "857373361868",
"output": "142323331131"
},
{
"input": "429325660016",
"output": "420324330013"
},
{
"input": "9894448650287940",
"output": "9104441340212040"
},
{
"input": "6354510839296263",
"output": "3344410130203233"
},
{
"input": "6873575462224593",
"output": "3123424432224403"
},
{
"input": "4237951492601449",
"output": "4232041402301440"
},
{
"input": "2680352384836991",
"output": "2310342314133001"
},
{
"input": "606187734191890310",
"output": "303112234101100310"
},
{
"input": "351499943576823355",
"output": "341400043423123344"
},
{
"input": "180593481782177068",
"output": "110403411212122031"
},
{
"input": "999999999999999999",
"output": "900000000000000000"
},
{
"input": "1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "9999",
"output": "9000"
},
{
"input": "99",
"output": "90"
},
{
"input": "9991",
"output": "9001"
}
] | 46 | 0 | 3 | 314 |
|
717 | Paint it really, really dark gray | [
"dfs and similar"
] | null | null | I see a pink boar and I want it painted black. Black boars look much more awesome and mighty than the pink ones. Since Jaggy became the ruler of the forest, he has been trying his best to improve the diplomatic relations between the forest region and the nearby ones.
Some other rulers, however, have requested too much in return for peace between their two regions, so he realized he has to resort to intimidation. Once a delegate for diplomatic relations of a neighboring region visits Jaggy’s forest, if they see a whole bunch of black boars, they might suddenly change their mind about attacking Jaggy. Black boars are really scary, after all.
Jaggy’s forest can be represented as a tree (connected graph without cycles) with *n* vertices. Each vertex represents a boar and is colored either black or pink. Jaggy has sent a squirrel to travel through the forest and paint all the boars black. The squirrel, however, is quite unusually trained and while it traverses the graph, it changes the color of every vertex it visits, regardless of its initial color: pink vertices become black and black vertices become pink.
Since Jaggy is too busy to plan the squirrel’s route, he needs your help. He wants you to construct a walk through the tree starting from vertex 1 such that in the end all vertices are black. A walk is a sequence of vertices, such that every consecutive pair has an edge between them in a tree. | The first line of input contains integer *n* (2<=≤<=*n*<=≤<=200<=000), denoting the number of vertices in the tree. The following *n* lines contains *n* integers, which represent the color of the nodes.
If the *i*-th integer is 1, if the *i*-th vertex is black and <=-<=1 if the *i*-th vertex is pink.
Each of the next *n*<=-<=1 lines contains two integers, which represent the indexes of the vertices which are connected by the edge. Vertices are numbered starting with 1. | Output path of a squirrel: output a sequence of visited nodes' indexes in order of visiting. In case of all the nodes are initially black, you should print 1. Solution is guaranteed to exist. If there are multiple solutions to the problem you can output any of them provided length of sequence is not longer than 107. | [
"5\n1\n1\n-1\n1\n-1\n2 5\n4 3\n2 4\n4 1\n"
] | [
"1 4 2 5 2 4 3 4 1 4 1\n"
] | At the beginning squirrel is at node 1 and its color is black. Next steps are as follows:
- From node 1 we walk to node 4 and change its color to pink. - From node 4 we walk to node 2 and change its color to pink. - From node 2 we walk to node 5 and change its color to black. - From node 5 we return to node 2 and change its color to black. - From node 2 we walk to node 4 and change its color to black. - We visit node 3 and change its color to black. - We visit node 4 and change its color to pink. - We visit node 1 and change its color to pink. - We visit node 4 and change its color to black. - We visit node 1 and change its color to black. | [
{
"input": "5\n1\n1\n-1\n1\n-1\n2 5\n4 3\n2 4\n4 1",
"output": "1 4 2 5 2 4 3 4 1 4 1"
},
{
"input": "2\n-1\n1\n2 1",
"output": "1 2 1 2 1 2 1 2"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n-1\n1\n1\n-1\n1\n-1\n1 3\n1 2\n2 5\n2 4\n3 7\n3 6\n4 9\n4 8\n5 11\n5 10\n12 11",
"output": "1 2 4 8 4 8 4 9 4 9 4 2 5 10 5 11 12 11 5 2 5 2 1 2 1 3 6 3 6 3 7 3 1"
}
] | 93 | 102,400 | -1 | 318 |
|
723 | The New Year: Meeting Friends | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer. | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "71 85 88",
"output": "17"
},
{
"input": "30 38 99",
"output": "69"
},
{
"input": "23 82 95",
"output": "72"
},
{
"input": "22 41 47",
"output": "25"
},
{
"input": "9 94 77",
"output": "85"
},
{
"input": "1 53 51",
"output": "52"
},
{
"input": "25 97 93",
"output": "72"
},
{
"input": "42 53 51",
"output": "11"
},
{
"input": "81 96 94",
"output": "15"
},
{
"input": "21 5 93",
"output": "88"
},
{
"input": "50 13 75",
"output": "62"
},
{
"input": "41 28 98",
"output": "70"
},
{
"input": "69 46 82",
"output": "36"
},
{
"input": "87 28 89",
"output": "61"
},
{
"input": "44 45 40",
"output": "5"
},
{
"input": "86 97 68",
"output": "29"
},
{
"input": "43 92 30",
"output": "62"
},
{
"input": "16 70 1",
"output": "69"
},
{
"input": "40 46 19",
"output": "27"
},
{
"input": "71 38 56",
"output": "33"
},
{
"input": "82 21 80",
"output": "61"
},
{
"input": "75 8 35",
"output": "67"
},
{
"input": "75 24 28",
"output": "51"
},
{
"input": "78 23 56",
"output": "55"
},
{
"input": "85 31 10",
"output": "75"
},
{
"input": "76 50 9",
"output": "67"
},
{
"input": "95 37 34",
"output": "61"
},
{
"input": "84 61 35",
"output": "49"
},
{
"input": "87 85 37",
"output": "50"
},
{
"input": "1 3 2",
"output": "2"
},
{
"input": "4 2 6",
"output": "4"
},
{
"input": "6 9 3",
"output": "6"
},
{
"input": "12 4 8",
"output": "8"
},
{
"input": "15 10 5",
"output": "10"
},
{
"input": "1 50 17",
"output": "49"
},
{
"input": "10 5 15",
"output": "10"
},
{
"input": "8 1 9",
"output": "8"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "2 1 3",
"output": "2"
},
{
"input": "1 8 2",
"output": "7"
},
{
"input": "1 100 2",
"output": "99"
},
{
"input": "1 4 6",
"output": "5"
}
] | 46 | 0 | 3 | 319 |
|
467 | George and Accommodation | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 46 | 0 | 3 | 320 |
|
268 | Games | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 92 | 0 | 3 | 322 |
|
315 | Sereja and Bottles | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
"output": "2"
},
{
"input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730",
"output": "6"
},
{
"input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624",
"output": "6"
},
{
"input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987",
"output": "6"
},
{
"input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222",
"output": "6"
},
{
"input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485",
"output": "8"
},
{
"input": "1\n1000 1000",
"output": "1"
},
{
"input": "1\n500 1000",
"output": "1"
},
{
"input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11",
"output": "11"
},
{
"input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2",
"output": "0"
},
{
"input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330",
"output": "30"
},
{
"input": "2\n7 7\n5 359",
"output": "2"
},
{
"input": "2\n465 706\n706 706",
"output": "1"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "1"
},
{
"input": "5\n1 1\n1 2\n2 3\n3 4\n4 3",
"output": "1"
},
{
"input": "3\n1 2\n1 2\n1 1",
"output": "1"
}
] | 0 | 0 | -1 | 323 |
|
119 | Epic Game | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game. | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that. | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "41 12 65",
"output": "1"
},
{
"input": "13 61 100",
"output": "1"
},
{
"input": "100 100 10",
"output": "0"
},
{
"input": "12 24 26",
"output": "1"
},
{
"input": "73 21 96",
"output": "1"
},
{
"input": "17 22 81",
"output": "1"
},
{
"input": "14 88 97",
"output": "1"
},
{
"input": "42 81 17",
"output": "0"
},
{
"input": "34 36 19",
"output": "1"
},
{
"input": "21 87 12",
"output": "1"
},
{
"input": "97 92 98",
"output": "1"
},
{
"input": "49 25 62",
"output": "1"
},
{
"input": "29 17 44",
"output": "1"
},
{
"input": "10 1 10",
"output": "0"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "100 100 1",
"output": "0"
},
{
"input": "11 99 55",
"output": "0"
},
{
"input": "8 13 21",
"output": "0"
},
{
"input": "34 55 89",
"output": "0"
},
{
"input": "21 34 55",
"output": "1"
},
{
"input": "13 21 34",
"output": "1"
},
{
"input": "34 21 55",
"output": "0"
},
{
"input": "10 20 84",
"output": "1"
},
{
"input": "4 2 5",
"output": "0"
},
{
"input": "3 2 3",
"output": "0"
},
{
"input": "31 23 1",
"output": "0"
},
{
"input": "100 100 100",
"output": "0"
},
{
"input": "100 1 100",
"output": "0"
},
{
"input": "1 100 100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "17 23 100",
"output": "1"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "1 1 2",
"output": "1"
},
{
"input": "2 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "2 1 2",
"output": "0"
},
{
"input": "10 10 3",
"output": "1"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "9 5 1",
"output": "0"
}
] | 186 | 0 | -1 | 324 |
|
369 | Valera and Contest | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
- each student in the team scored at least *l* points and at most *r* points; - in total, all members of the team scored exactly *s**all* points; - the total score of the *k* members of the team who scored the most points is equal to exactly *s**k*; more formally, if *a*1,<=*a*2,<=...,<=*a**n* is the sequence of points earned by the team of students in the non-increasing order (*a*1<=≥<=*a*2<=≥<=...<=≥<=*a**n*), then *s**k*<==<=*a*1<=+<=*a*2<=+<=...<=+<=*a**k*.
However, Valera did not find out exactly how many points each of *n* students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met. | The first line of the input contains exactly six integers *n*,<=*k*,<=*l*,<=*r*,<=*s**all*,<=*s**k* (1<=≤<=*n*,<=*k*,<=*l*,<=*r*<=≤<=1000; *l*<=≤<=*r*; *k*<=≤<=*n*; 1<=≤<=*s**k*<=≤<=*s**all*<=≤<=106).
It's guaranteed that the input is such that the answer exists. | Print exactly *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order. | [
"5 3 1 3 13 9\n",
"5 3 1 3 15 9\n"
] | [
"2 3 2 3 3 ",
"3 3 3 3 3 "
] | none | [
{
"input": "5 3 1 3 13 9",
"output": "2 3 2 3 3 "
},
{
"input": "5 3 1 3 15 9",
"output": "3 3 3 3 3 "
},
{
"input": "50 25 1 1 50 25",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1000 700 782 1000 892330 648282",
"output": "926 926 926 814 926 926 926 926 926 813 926 814 926 813 813 926 814 926 926 926 814 926 814 926 813 927 814 926 813 926 926 813 926 926 926 927 926 813 926 813 926 926 926 926 813 926 926 926 813 813 926 926 814 926 926 926 814 926 813 927 926 926 927 926 926 926 926 926 926 926 927 813 926 814 926 926 926 926 813 813 814 926 927 814 926 926 813 926 813 926 926 814 926 926 926 926 926 926 814 926 926 927 926 926 926 926 926 814 926 926 813 926 926 926 926 927 813 926 926 927 926 926 926 926 926 926 926 926..."
},
{
"input": "1000 999 500 503 501513 501013",
"output": "501 502 502 501 501 502 502 502 501 501 502 501 502 501 501 501 501 502 502 502 501 502 501 502 501 502 501 502 501 501 502 501 501 502 502 502 501 501 502 501 502 501 502 502 501 501 502 502 501 501 502 502 501 502 502 501 501 502 501 502 501 502 502 502 502 502 502 501 502 502 502 501 502 501 502 502 501 502 501 501 501 501 502 501 502 502 501 502 501 501 502 501 502 502 501 502 502 501 501 502 502 502 501 501 502 502 502 501 502 502 501 501 501 501 502 502 500 501 502 502 502 502 502 502 501 502 501 502..."
},
{
"input": "999 998 500 501 500009 499509",
"output": "500 501 501 500 500 501 501 501 500 500 501 500 501 500 500 500 500 501 501 501 500 501 500 501 500 501 500 501 500 500 501 500 500 501 501 501 500 500 501 500 501 500 501 501 500 500 501 501 500 500 501 501 500 501 501 500 500 501 500 501 500 501 501 501 501 501 501 500 501 501 501 500 501 500 501 501 500 501 500 500 500 500 501 500 501 501 500 501 500 500 501 500 501 501 500 501 501 500 500 501 501 501 500 500 501 501 501 500 501 501 500 500 500 500 501 501 501 500 501 501 501 501 501 501 500 501 500 501..."
},
{
"input": "999 998 500 500 499500 499000",
"output": "500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500..."
},
{
"input": "999 997 500 502 500516 499516",
"output": "501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 502 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 501 502 501 501 501 501 501 501 501 501 500 501 501 501 501 501 502 501 501 501 501 501 501 501 501 501 501 501..."
},
{
"input": "1000 300 50 500 269795 127658",
"output": "203 204 203 203 203 203 203 426 203 203 204 203 425 203 203 203 203 204 203 203 203 425 203 204 203 426 203 203 203 203 203 203 203 426 203 426 203 203 426 203 203 203 203 203 203 203 203 204 203 203 425 203 203 425 425 203 203 425 203 426 203 204 426 426 425 426 203 203 425 203 426 203 425 203 425 425 203 425 203 203 203 203 426 203 425 203 203 425 203 203 203 203 203 203 203 203 426 203 203 203 425 426 203 203 203 203 203 203 425 425 203 203 203 203 203 426 203 203 203 426 204 203 203 203 203 203 203 426..."
},
{
"input": "50 25 1000 1000 50000 25000",
"output": "1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 "
},
{
"input": "100 100 500 1000 75589 75589",
"output": "756 756 756 755 755 756 756 756 756 755 756 756 756 756 756 756 755 756 755 756 756 756 756 756 756 756 756 756 756 755 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 755 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 755 756 756 756 756 756 755 756 756 756 755 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 755 756 756 756 756 756 756 756 "
},
{
"input": "1 1 1000 1000 1000 1000",
"output": "1000 "
},
{
"input": "2 2 500 1000 1000 1000",
"output": "500 500 "
},
{
"input": "1000 500 1 1000 500500 500000",
"output": "1 1000 1000 1 1 1000 1000 1000 1 1 1000 1 1000 1 1 1 1 1000 1000 1000 1 1000 1 1000 1 1000 1 1000 1 1 1000 1 1 1000 1000 1000 1 1 1000 1 1000 1 1000 1000 1 1 1 1000 1 1 1000 1000 1 1000 1000 1 1 1000 1 1000 1 1000 1000 1000 1000 1000 1000 1 1000 1000 1000 1 1000 1 1000 1000 1 1000 1 1 1 1 1000 1 1000 1000 1 1000 1 1 1000 1 1000 1000 1 1000 1000 1 1 1000 1000 1000 1 1 1000 1000 1000 1 1000 1000 1 1 1 1 1000 1000 1 1 1000 1000 1000 1000 1000 1000 1 1000 1 1000 1 1 1 1 1000 1 1 1000 1000 1000 1000 1000 1 1 1 ..."
},
{
"input": "1000 500 500 1000 750000 375000",
"output": "750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750..."
},
{
"input": "300 100 1 3 600 200",
"output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..."
},
{
"input": "300 100 1 3 900 300",
"output": "3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3..."
},
{
"input": "300 100 1 3 300 100",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "1 1 1 1 1 1",
"output": "1 "
},
{
"input": "432 32 13 123 28942 3824",
"output": "63 63 63 63 63 63 62 63 63 63 63 63 63 63 62 63 63 63 62 62 63 63 62 63 62 120 62 62 63 63 62 63 63 63 63 63 119 120 63 63 63 62 63 62 63 63 63 63 63 63 63 63 63 63 63 120 63 63 63 63 63 63 63 63 63 63 63 63 63 62 63 63 63 63 63 63 62 63 63 63 63 63 63 63 63 62 63 63 63 63 63 63 63 62 63 63 63 63 63 63 63 119 63 62 62 62 63 63 63 63 63 120 63 63 62 63 120 63 62 63 63 62 62 63 63 62 63 63 63 120 63 120 63 63 63 62 63 63 63 63 62 63 62 62 63 63 63 62 63 63 63 63 63 63 63 62 63 62 63 63 63 62 63 119 62 63 62 ..."
},
{
"input": "504 32 13 123 33704 3791",
"output": "64 63 63 63 63 63 63 64 63 63 63 64 63 63 63 64 63 63 63 63 64 63 63 63 63 119 63 63 64 64 63 63 63 64 63 64 118 119 64 64 63 63 63 63 63 64 63 63 64 64 64 63 63 63 64 118 63 64 63 64 63 63 64 64 63 64 63 64 64 63 64 64 64 64 63 63 63 64 63 64 64 64 64 64 63 63 63 64 64 64 63 63 63 63 64 63 64 63 63 63 63 118 63 63 63 63 63 63 64 63 63 119 63 63 63 64 119 63 63 64 63 63 63 63 64 63 64 64 64 119 63 119 64 64 63 63 63 64 63 63 63 64 63 63 63 63 64 63 64 63 64 64 63 64 63 63 63 63 64 64 64 63 64 118 63 63 63 ..."
},
{
"input": "999 32 13 123 68122 3876",
"output": "66 67 67 66 66 67 67 67 66 66 67 66 67 66 66 66 66 67 67 66 66 67 66 67 66 121 66 66 66 66 67 66 66 67 67 67 66 66 67 66 66 66 66 67 66 66 66 67 66 66 67 67 66 67 67 66 66 67 66 67 66 67 67 67 67 67 67 66 67 67 67 66 67 66 67 67 66 67 66 66 66 66 67 66 67 67 66 67 66 66 66 66 66 66 66 67 67 66 66 66 67 121 66 66 67 67 67 66 67 67 66 66 66 66 67 67 122 66 67 67 67 67 67 66 66 67 66 67 66 66 66 66 67 66 66 67 67 67 67 67 66 66 66 67 67 66 67 67 66 66 66 67 66 67 66 66 66 66 67 67 66 66 66 121 67 66 66 67 66 ..."
},
{
"input": "489 32 13 123 33009 3885",
"output": "64 64 64 64 63 64 63 64 64 64 64 64 64 64 63 64 64 64 63 63 64 64 63 64 63 122 63 63 64 64 63 64 64 64 63 64 121 122 64 64 63 63 63 63 64 64 64 64 64 64 64 64 64 64 64 121 63 64 64 64 64 64 64 64 64 64 63 64 64 63 64 64 64 64 64 64 63 64 63 64 64 64 64 64 64 63 64 64 64 64 63 63 63 63 64 63 64 64 64 63 64 121 64 63 63 64 63 64 64 64 64 122 64 64 63 64 122 64 64 64 64 63 64 64 64 64 64 64 64 122 64 122 64 64 64 63 64 64 64 64 63 64 63 64 64 64 64 63 64 63 64 64 64 64 64 63 64 63 64 64 64 64 64 121 63 64 63 ..."
},
{
"input": "234 32 13 123 16337 3715",
"output": "62 63 62 62 63 62 62 62 62 63 62 63 63 62 63 62 63 63 63 116 62 63 63 63 63 116 62 63 62 63 63 63 62 62 63 63 116 116 62 63 63 63 62 62 116 62 63 116 62 62 62 63 116 62 62 116 63 62 62 63 63 63 63 63 63 63 62 62 62 116 63 62 62 62 62 62 62 62 63 63 62 63 63 63 63 62 62 62 62 62 63 62 63 62 62 63 63 63 63 116 63 116 63 63 116 62 63 63 62 62 62 116 116 63 62 63 117 63 62 63 63 62 63 62 62 116 62 63 63 117 62 116 62 63 62 63 62 62 116 63 62 63 63 62 62 62 63 63 63 62 63 63 62 62 62 62 63 63 63 62 63 62 63 116..."
},
{
"input": "998 997 13 13 12974 12961",
"output": "13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1..."
},
{
"input": "999 999 13 333 169609 169609",
"output": "170 170 170 170 170 170 170 170 170 169 170 170 170 169 169 170 169 170 170 170 170 170 169 170 169 170 169 170 169 170 170 169 170 170 170 170 170 169 170 169 170 170 170 170 169 170 170 170 169 169 170 170 169 170 170 170 170 170 169 170 170 170 170 170 170 170 170 170 170 170 170 169 170 170 170 170 170 170 169 169 170 170 170 170 170 170 169 170 169 170 170 169 170 170 170 170 170 170 169 170 170 170 170 170 170 170 170 169 170 170 169 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170..."
},
{
"input": "999 998 13 533 270345 270332",
"output": "271 271 271 271 271 271 271 271 271 270 271 271 271 270 270 271 271 271 271 271 271 271 271 271 270 271 271 271 270 271 271 270 271 271 271 271 271 271 271 270 271 271 271 271 270 271 271 271 270 270 271 271 271 271 271 271 271 271 270 271 271 271 271 271 271 271 271 271 271 271 271 270 271 271 271 271 271 271 270 270 271 271 271 271 271 271 270 271 270 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 13 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 271 ..."
},
{
"input": "998 123 13 293 151330 33752",
"output": "134 135 135 134 134 135 135 135 134 134 135 134 135 134 134 134 134 135 135 134 134 135 134 135 134 275 134 134 134 134 135 134 134 135 135 275 134 134 135 134 134 134 134 135 134 134 134 135 134 134 135 135 134 135 135 134 134 135 134 275 134 135 275 274 135 274 135 134 135 135 274 134 135 134 135 135 134 135 134 134 134 134 274 134 135 135 134 135 134 134 134 134 134 134 134 135 274 134 134 134 135 275 134 134 135 135 135 134 135 135 135 134 134 134 135 274 275 134 135 275 135 135 135 134 134 135 134 274..."
},
{
"input": "995 993 123 743 437780 437534",
"output": "440 441 441 440 440 441 441 441 440 440 441 440 441 440 440 440 440 441 441 441 440 441 440 441 440 441 440 441 440 440 441 440 440 441 441 441 440 440 441 440 441 441 441 441 440 440 441 441 440 440 441 441 440 441 441 441 440 441 440 441 440 441 441 441 441 441 441 441 441 441 441 440 441 440 441 441 440 441 440 440 440 441 441 440 441 441 440 441 440 440 441 440 441 441 441 441 441 440 440 441 441 441 441 440 441 441 441 440 441 441 441 440 441 441 441 441 441 440 441 441 441 441 441 441 440 441 441 441..."
},
{
"input": "999 999 111 111 110889 110889",
"output": "111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111..."
},
{
"input": "1000 1000 111 111 111000 111000",
"output": "111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 111..."
},
{
"input": "1000 567 999 1000 999489 566922",
"output": "999 1000 1000 999 999 1000 1000 1000 999 999 1000 999 1000 999 999 999 999 1000 1000 1000 999 1000 999 1000 999 1000 999 1000 999 999 1000 999 999 1000 1000 1000 999 999 1000 999 1000 999 1000 1000 999 999 999 1000 999 999 1000 1000 999 1000 1000 999 999 1000 999 1000 999 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 999 1000 999 1000 1000 999 1000 999 999 999 999 1000 999 1000 1000 999 1000 999 999 1000 999 1000 1000 999 1000 1000 999 999 1000 1000 1000 999 999 1000 1000 1000 999 1000 1000 999 999 999 ..."
},
{
"input": "1000 567 998 1000 998981 566754",
"output": "998 1000 999 998 999 999 999 1000 999 998 1000 998 1000 998 998 999 998 999 999 999 998 1000 998 1000 998 1000 998 999 998 998 999 998 999 1000 999 1000 998 998 1000 998 999 999 999 999 998 998 999 1000 998 998 1000 999 998 1000 1000 999 998 1000 998 1000 998 1000 1000 1000 1000 1000 999 999 1000 999 1000 998 1000 998 1000 1000 999 1000 998 998 998 999 1000 998 1000 999 998 1000 998 998 999 998 999 999 999 999 1000 998 998 999 1000 1000 999 999 999 999 999 998 1000 1000 998 998 999 999 999 1000 998 998 999..."
},
{
"input": "1000 567 996 1000 997986 566445",
"output": "997 999 999 997 997 999 999 999 997 996 999 997 999 996 996 997 997 999 999 999 997 999 997 999 996 1000 997 999 996 997 999 996 997 999 999 999 997 996 999 996 999 999 999 999 996 997 999 999 996 996 999 999 997 999 999 997 997 999 996 999 997 999 999 999 999 999 999 999 999 999 999 996 999 997 999 999 997 999 996 996 997 997 999 997 999 999 996 999 996 997 999 997 999 999 999 999 999 997 997 999 999 999 999 997 999 999 999 997 999 999 996 997 997 999 999 999 996 997 999 999 999 999 999 999 997 999 999 99..."
},
{
"input": "1000 567 996 1000 997986 566445",
"output": "997 999 999 997 997 999 999 999 997 996 999 997 999 996 996 997 997 999 999 999 997 999 997 999 996 1000 997 999 996 997 999 996 997 999 999 999 997 996 999 996 999 999 999 999 996 997 999 999 996 996 999 999 997 999 999 997 997 999 996 999 997 999 999 999 999 999 999 999 999 999 999 996 999 997 999 999 997 999 996 996 997 997 999 997 999 999 996 999 996 997 999 997 999 999 999 999 999 997 997 999 999 999 999 997 999 999 999 997 999 999 996 997 997 999 999 999 996 997 999 999 999 999 999 999 997 999 999 99..."
},
{
"input": "1 1 1 1000 656 656",
"output": "656 "
},
{
"input": "2 1 1 1000 683 550",
"output": "550 133 "
},
{
"input": "3 2 1 1000 1816 1652",
"output": "826 826 164 "
},
{
"input": "5 5 1 1000 3288 3288",
"output": "657 658 657 658 658 "
},
{
"input": "5 3 1 1000 2732 2055",
"output": "338 685 339 685 685 "
},
{
"input": "1 1 10 100 50 50",
"output": "50 "
},
{
"input": "3 3 1 5 14 14",
"output": "5 5 4 "
},
{
"input": "1 1 1 100 50 50",
"output": "50 "
},
{
"input": "5 5 1 5 5 5",
"output": "1 1 1 1 1 "
},
{
"input": "1 1 1 10 10 10",
"output": "10 "
},
{
"input": "5 5 1 3 5 5",
"output": "1 1 1 1 1 "
},
{
"input": "1000 1000 1 1000 1000000 1000000",
"output": "1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1..."
},
{
"input": "3 3 1 3 9 9",
"output": "3 3 3 "
},
{
"input": "1000 1000 389 999 686847 686847",
"output": "687 687 687 687 687 687 687 687 687 686 687 687 687 686 686 687 687 687 687 687 687 687 687 687 686 687 687 687 686 687 687 686 687 687 687 687 687 686 687 686 687 687 687 687 686 687 687 687 686 686 687 687 687 687 687 687 687 687 686 687 687 687 687 687 687 687 687 687 687 687 687 686 687 687 687 687 687 687 686 686 687 687 687 687 687 687 686 687 686 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 687 686 687 687 687 687 687 686 687 687 687 687 687 687 687 687 687 687 687..."
},
{
"input": "2 2 2 2 4 4",
"output": "2 2 "
}
] | 202 | 2,355,200 | -1 | 325 |
|
798 | Mike and palindrome | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input": "gqrk",
"output": "NO"
},
{
"input": "glxlg",
"output": "YES"
},
{
"input": "czhfc",
"output": "YES"
},
{
"input": "broon",
"output": "NO"
},
{
"input": "rmggmr",
"output": "NO"
},
{
"input": "wvxxzw",
"output": "YES"
},
{
"input": "ukvciu",
"output": "NO"
},
{
"input": "vrnwnrv",
"output": "YES"
},
{
"input": "vlkjkav",
"output": "YES"
},
{
"input": "guayhmg",
"output": "NO"
},
{
"input": "lkvhhvkl",
"output": "NO"
},
{
"input": "ffdsslff",
"output": "YES"
},
{
"input": "galjjtyw",
"output": "NO"
},
{
"input": "uosgwgsou",
"output": "YES"
},
{
"input": "qjwmjmljq",
"output": "YES"
},
{
"input": "ustrvrodf",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "qjfyjjyfjq",
"output": "NO"
},
{
"input": "ysxibbixsq",
"output": "YES"
},
{
"input": "howfslfwmh",
"output": "NO"
},
{
"input": "ekhajrjahke",
"output": "YES"
},
{
"input": "ucnolsloncw",
"output": "YES"
},
{
"input": "jrzsfrrkrtj",
"output": "NO"
},
{
"input": "typayzzyapyt",
"output": "NO"
},
{
"input": "uwdhkzokhdwu",
"output": "YES"
},
{
"input": "xokxpyyuafij",
"output": "NO"
},
{
"input": "eusneioiensue",
"output": "YES"
},
{
"input": "fuxpuajabpxuf",
"output": "YES"
},
{
"input": "guvggtfhlgruy",
"output": "NO"
},
{
"input": "cojhkhxxhkhjoc",
"output": "NO"
},
{
"input": "mhifbmmmmbmihm",
"output": "YES"
},
{
"input": "kxfqqncnebpami",
"output": "NO"
},
{
"input": "scfwrjevejrwfcs",
"output": "YES"
},
{
"input": "thdaonpepdoadht",
"output": "YES"
},
{
"input": "jsfzcbnhsccuqsj",
"output": "NO"
},
{
"input": "nn",
"output": "NO"
},
{
"input": "nm",
"output": "YES"
},
{
"input": "jdj",
"output": "YES"
},
{
"input": "bbcaa",
"output": "NO"
},
{
"input": "abcde",
"output": "NO"
},
{
"input": "abcdf",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "abecd",
"output": "NO"
},
{
"input": "abccacb",
"output": "NO"
},
{
"input": "aabc",
"output": "NO"
},
{
"input": "anpqb",
"output": "NO"
},
{
"input": "c",
"output": "YES"
},
{
"input": "abcdefg",
"output": "NO"
},
{
"input": "aanbb",
"output": "NO"
},
{
"input": "aabbb",
"output": "NO"
},
{
"input": "aaabbab",
"output": "NO"
},
{
"input": "ab",
"output": "YES"
},
{
"input": "aabbc",
"output": "NO"
},
{
"input": "ecabd",
"output": "NO"
},
{
"input": "abcdrty",
"output": "NO"
},
{
"input": "abcdmnp",
"output": "NO"
},
{
"input": "bbbbbb",
"output": "NO"
},
{
"input": "abcxuio",
"output": "NO"
},
{
"input": "abcdabcde",
"output": "NO"
},
{
"input": "abcxpoi",
"output": "NO"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "aacbb",
"output": "NO"
},
{
"input": "abcedca",
"output": "NO"
},
{
"input": "abcdd",
"output": "NO"
},
{
"input": "abbcs",
"output": "NO"
},
{
"input": "aaabccc",
"output": "NO"
},
{
"input": "paxkxbq",
"output": "NO"
},
{
"input": "z",
"output": "YES"
},
{
"input": "b",
"output": "YES"
},
{
"input": "abcdefghi",
"output": "NO"
},
{
"input": "abcqr",
"output": "NO"
},
{
"input": "abcdc",
"output": "NO"
},
{
"input": "abcb",
"output": "NO"
},
{
"input": "aabcd",
"output": "NO"
},
{
"input": "abbba",
"output": "YES"
},
{
"input": "aaabbb",
"output": "NO"
},
{
"input": "bb",
"output": "NO"
},
{
"input": "aaacbbb",
"output": "NO"
},
{
"input": "abbzcca",
"output": "NO"
},
{
"input": "abxab",
"output": "NO"
},
{
"input": "bbb",
"output": "YES"
},
{
"input": "abcrtyu",
"output": "NO"
},
{
"input": "cbacb",
"output": "NO"
},
{
"input": "acbb",
"output": "NO"
},
{
"input": "ww",
"output": "NO"
},
{
"input": "aaaaaa",
"output": "NO"
},
{
"input": "jizzz",
"output": "NO"
},
{
"input": "aaakcba",
"output": "NO"
},
{
"input": "acbak",
"output": "NO"
},
{
"input": "bddeffd",
"output": "NO"
},
{
"input": "aaa",
"output": "YES"
},
{
"input": "afghqwe",
"output": "NO"
},
{
"input": "abcdfga",
"output": "NO"
}
] | 0 | 0 | -1 | 327 |
|
6 | Triangle | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him. | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length. | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 5 6 11",
"output": "TRIANGLE"
},
{
"input": "1 1 1 1",
"output": "TRIANGLE"
},
{
"input": "10 20 30 40",
"output": "TRIANGLE"
},
{
"input": "45 25 5 15",
"output": "IMPOSSIBLE"
},
{
"input": "20 5 8 13",
"output": "TRIANGLE"
},
{
"input": "10 30 7 20",
"output": "SEGMENT"
},
{
"input": "3 2 3 2",
"output": "TRIANGLE"
},
{
"input": "70 10 100 30",
"output": "SEGMENT"
},
{
"input": "4 8 16 2",
"output": "IMPOSSIBLE"
},
{
"input": "3 3 3 10",
"output": "TRIANGLE"
},
{
"input": "1 5 5 5",
"output": "TRIANGLE"
},
{
"input": "13 25 12 1",
"output": "SEGMENT"
},
{
"input": "10 100 7 3",
"output": "SEGMENT"
},
{
"input": "50 1 50 100",
"output": "TRIANGLE"
},
{
"input": "50 1 100 49",
"output": "SEGMENT"
},
{
"input": "49 51 100 1",
"output": "SEGMENT"
},
{
"input": "5 11 2 25",
"output": "IMPOSSIBLE"
},
{
"input": "91 50 9 40",
"output": "IMPOSSIBLE"
},
{
"input": "27 53 7 97",
"output": "IMPOSSIBLE"
},
{
"input": "51 90 24 8",
"output": "IMPOSSIBLE"
},
{
"input": "3 5 1 1",
"output": "IMPOSSIBLE"
},
{
"input": "13 49 69 15",
"output": "IMPOSSIBLE"
},
{
"input": "16 99 9 35",
"output": "IMPOSSIBLE"
},
{
"input": "27 6 18 53",
"output": "IMPOSSIBLE"
},
{
"input": "57 88 17 8",
"output": "IMPOSSIBLE"
},
{
"input": "95 20 21 43",
"output": "IMPOSSIBLE"
},
{
"input": "6 19 32 61",
"output": "IMPOSSIBLE"
},
{
"input": "100 21 30 65",
"output": "IMPOSSIBLE"
},
{
"input": "85 16 61 9",
"output": "IMPOSSIBLE"
},
{
"input": "5 6 19 82",
"output": "IMPOSSIBLE"
},
{
"input": "1 5 1 3",
"output": "IMPOSSIBLE"
},
{
"input": "65 10 36 17",
"output": "IMPOSSIBLE"
},
{
"input": "81 64 9 7",
"output": "IMPOSSIBLE"
},
{
"input": "11 30 79 43",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 5 3",
"output": "IMPOSSIBLE"
},
{
"input": "21 94 61 31",
"output": "IMPOSSIBLE"
},
{
"input": "49 24 9 74",
"output": "IMPOSSIBLE"
},
{
"input": "11 19 5 77",
"output": "IMPOSSIBLE"
},
{
"input": "52 10 19 71",
"output": "SEGMENT"
},
{
"input": "2 3 7 10",
"output": "SEGMENT"
},
{
"input": "1 2 6 3",
"output": "SEGMENT"
},
{
"input": "2 6 1 8",
"output": "SEGMENT"
},
{
"input": "1 2 4 1",
"output": "SEGMENT"
},
{
"input": "4 10 6 2",
"output": "SEGMENT"
},
{
"input": "2 10 7 3",
"output": "SEGMENT"
},
{
"input": "5 2 3 9",
"output": "SEGMENT"
},
{
"input": "6 1 4 10",
"output": "SEGMENT"
},
{
"input": "10 6 4 1",
"output": "SEGMENT"
},
{
"input": "3 2 9 1",
"output": "SEGMENT"
},
{
"input": "22 80 29 7",
"output": "SEGMENT"
},
{
"input": "2 6 3 9",
"output": "SEGMENT"
},
{
"input": "3 1 2 1",
"output": "SEGMENT"
},
{
"input": "3 4 7 1",
"output": "SEGMENT"
},
{
"input": "8 4 3 1",
"output": "SEGMENT"
},
{
"input": "2 8 3 5",
"output": "SEGMENT"
},
{
"input": "4 1 2 1",
"output": "SEGMENT"
},
{
"input": "8 1 3 2",
"output": "SEGMENT"
},
{
"input": "6 2 1 8",
"output": "SEGMENT"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "3 6 3 3",
"output": "TRIANGLE"
},
{
"input": "4 10 4 4",
"output": "TRIANGLE"
},
{
"input": "1 1 2 1",
"output": "TRIANGLE"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "5 4 5 5",
"output": "TRIANGLE"
},
{
"input": "8 7 8 8",
"output": "TRIANGLE"
},
{
"input": "3 3 3 1",
"output": "TRIANGLE"
},
{
"input": "1 1 6 6",
"output": "TRIANGLE"
},
{
"input": "1 9 1 9",
"output": "TRIANGLE"
},
{
"input": "7 2 2 7",
"output": "TRIANGLE"
},
{
"input": "7 2 3 2",
"output": "TRIANGLE"
},
{
"input": "4 4 10 10",
"output": "TRIANGLE"
},
{
"input": "7 7 10 7",
"output": "TRIANGLE"
},
{
"input": "4 4 4 5",
"output": "TRIANGLE"
},
{
"input": "1 10 9 2",
"output": "TRIANGLE"
},
{
"input": "1 8 2 7",
"output": "TRIANGLE"
},
{
"input": "4 3 2 8",
"output": "TRIANGLE"
},
{
"input": "5 9 5 3",
"output": "TRIANGLE"
},
{
"input": "4 10 3 5",
"output": "TRIANGLE"
}
] | 154 | 0 | 3.9615 | 328 |
796 | Buying A House | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=<<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars.
As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love. | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses.
It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars. | Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away. | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"output": "20"
},
{
"input": "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20",
"output": "10"
},
{
"input": "7 5 1\n0 100 2 2 0 2 1",
"output": "20"
},
{
"input": "100 50 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "10"
},
{
"input": "100 50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "490"
},
{
"input": "100 77 50\n50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 0 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0",
"output": "10"
},
{
"input": "100 1 1\n0 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "980"
},
{
"input": "100 1 100\n0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "10"
},
{
"input": "100 10 99\n0 0 0 0 0 0 0 0 0 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98",
"output": "890"
},
{
"input": "7 4 5\n1 0 6 0 5 6 0",
"output": "10"
},
{
"input": "7 4 5\n1 6 5 0 0 6 0",
"output": "10"
},
{
"input": "100 42 59\n50 50 50 50 50 50 50 50 50 50 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 0",
"output": "90"
},
{
"input": "2 1 100\n0 1",
"output": "10"
},
{
"input": "2 2 100\n1 0",
"output": "10"
},
{
"input": "10 1 88\n0 95 0 0 0 0 0 94 0 85",
"output": "90"
},
{
"input": "10 2 14\n2 0 1 26 77 39 41 100 13 32",
"output": "10"
},
{
"input": "10 3 11\n0 0 0 0 0 62 0 52 1 35",
"output": "60"
},
{
"input": "20 12 44\n27 40 58 69 53 38 31 39 75 95 8 0 28 81 77 90 38 61 21 88",
"output": "10"
},
{
"input": "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82",
"output": "70"
},
{
"input": "40 22 1\n7 95 44 53 0 0 19 93 0 68 65 0 24 91 10 58 17 0 71 0 100 0 94 90 79 73 0 73 4 61 54 81 7 13 21 84 5 41 0 1",
"output": "180"
},
{
"input": "40 22 99\n60 0 100 0 0 100 100 0 0 0 0 100 100 0 0 100 100 0 100 100 100 0 100 100 100 0 100 100 0 0 100 100 100 0 0 100 0 100 0 0",
"output": "210"
},
{
"input": "50 10 82\n56 54 0 0 0 0 88 93 0 0 83 93 0 0 91 89 0 30 62 52 24 84 80 8 38 13 92 78 16 87 23 30 71 55 16 63 15 99 4 93 24 6 3 35 4 42 73 27 86 37",
"output": "80"
},
{
"input": "63 49 22\n18 3 97 52 75 2 12 24 58 75 80 97 22 10 79 51 30 60 68 99 75 2 35 3 97 88 9 7 18 5 0 0 0 91 0 91 56 36 76 0 0 0 52 27 35 0 51 72 0 96 57 0 0 0 0 92 55 28 0 30 0 78 77",
"output": "190"
},
{
"input": "74 38 51\n53 36 55 42 64 5 87 9 0 16 86 78 9 22 19 1 25 72 1 0 0 0 79 0 0 0 77 58 70 0 0 100 64 0 99 59 0 0 0 0 65 74 0 96 0 58 89 93 61 88 0 0 82 89 0 0 49 24 7 77 89 87 94 61 100 31 93 70 39 49 39 14 20 84",
"output": "190"
},
{
"input": "89 22 11\n36 0 68 89 0 85 72 0 38 56 0 44 0 94 0 28 71 0 0 18 0 0 0 89 0 0 0 75 0 0 0 32 66 0 0 0 0 0 0 48 63 0 64 58 0 23 48 0 0 52 93 61 57 0 18 0 0 34 62 17 0 41 0 0 53 59 44 0 0 51 40 0 0 100 100 54 0 88 0 5 45 56 57 67 24 16 88 86 15",
"output": "580"
},
{
"input": "97 44 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 51 19",
"output": "520"
},
{
"input": "100 1 1\n0 0 0 0 10 54 84 6 17 94 65 82 34 0 61 46 42 0 2 16 56 0 100 0 82 0 0 0 89 78 96 56 0 0 0 0 0 0 0 0 77 70 0 96 67 0 0 32 44 1 72 50 14 11 24 61 100 64 19 5 67 69 44 82 93 22 67 93 22 61 53 64 79 41 84 48 43 97 7 24 8 49 23 16 72 52 97 29 69 47 29 49 64 91 4 73 17 18 51 67",
"output": "490"
},
{
"input": "100 1 50\n0 0 0 60 0 0 54 0 80 0 0 0 97 0 68 97 84 0 0 93 0 0 0 0 68 0 0 62 0 0 55 68 65 87 0 69 0 0 0 0 0 52 61 100 0 71 0 82 88 78 0 81 0 95 0 57 0 67 0 0 0 55 86 0 60 72 0 0 73 0 83 0 0 60 64 0 56 0 0 77 84 0 58 63 84 0 0 67 0 16 3 88 0 98 31 52 40 35 85 23",
"output": "890"
},
{
"input": "100 1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 91 70 14",
"output": "970"
},
{
"input": "100 1 29\n0 0 0 0 64 0 89 97 0 0 0 59 0 67 62 0 59 0 0 80 0 0 0 0 0 97 0 57 0 64 32 0 44 0 0 48 0 47 38 0 42 0 0 0 0 0 0 46 74 0 86 33 33 0 44 0 79 0 0 0 0 91 59 0 59 65 55 0 0 58 33 95 0 97 76 0 81 0 41 0 38 81 80 0 85 0 31 0 0 92 0 0 45 96 0 85 91 87 0 10",
"output": "990"
},
{
"input": "100 50 20\n3 0 32 0 48 32 64 0 54 26 0 0 0 0 0 28 0 0 54 0 0 45 49 0 38 74 0 0 39 42 62 48 75 96 89 42 0 44 0 0 30 21 76 0 50 0 79 0 0 0 0 99 0 84 62 0 0 0 0 53 80 0 28 0 0 53 0 0 38 0 62 0 0 62 0 0 88 0 44 32 0 81 35 45 49 0 69 73 38 27 72 0 96 72 69 0 0 22 76 10",
"output": "490"
},
{
"input": "100 50 20\n49 0 56 0 87 25 40 0 50 0 0 97 0 0 36 29 0 0 0 0 0 73 29 71 44 0 0 0 91 92 69 0 0 60 81 49 48 38 0 87 0 82 0 32 0 82 46 39 0 0 29 0 0 29 0 79 47 0 0 0 0 0 49 0 24 33 70 0 63 45 97 90 0 0 29 53 55 0 84 0 0 100 26 0 88 0 0 0 0 81 70 0 30 80 0 75 59 98 0 2",
"output": "500"
},
{
"input": "100 2 2\n0 0 43 90 47 5 2 97 52 69 21 48 64 10 34 97 97 74 8 19 68 56 55 24 47 38 43 73 72 72 60 60 51 36 33 44 100 45 13 54 72 52 0 15 3 6 50 8 88 4 78 26 40 27 30 63 67 83 61 91 33 97 54 20 92 27 89 35 10 7 84 50 11 95 74 88 24 44 74 100 18 56 34 91 41 34 51 51 11 91 89 54 19 100 83 89 10 17 76 20",
"output": "50"
},
{
"input": "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 84 0 0 0 0 37 75 0 66 0 0 0 0 61 0 70 0 37 60 42 78 92 52 0 0 0 55 77 57 0 63 37 0 0 0 96 70 0 94 97 0 0 0",
"output": "990"
},
{
"input": "100 100 100\n43 79 21 87 84 14 28 69 92 16 3 71 79 37 48 37 72 58 12 72 62 49 37 17 60 54 41 99 15 72 40 89 76 1 99 87 14 56 63 48 69 37 96 64 7 14 1 73 85 33 98 70 97 71 96 28 49 71 56 2 67 22 100 2 98 100 62 77 92 76 98 98 47 26 22 47 50 56 9 16 72 47 5 62 29 78 81 1 0 63 32 65 87 3 40 53 8 80 93 0",
"output": "10"
},
{
"input": "100 38 1\n3 59 12 81 33 95 0 41 36 17 63 76 42 77 85 56 3 96 55 41 24 87 18 9 0 37 0 61 69 0 0 0 67 0 0 0 0 0 0 18 0 0 47 56 74 0 0 80 0 42 0 1 60 59 62 9 19 87 92 48 58 30 98 51 99 10 42 94 51 53 50 89 24 5 52 82 50 39 98 8 95 4 57 21 10 0 44 32 19 14 64 34 79 76 17 3 15 22 71 51",
"output": "140"
},
{
"input": "100 72 1\n56 98 8 27 9 23 16 76 56 1 34 43 96 73 75 49 62 20 18 23 51 55 30 84 4 20 89 40 75 16 69 35 1 0 16 0 80 0 41 17 0 0 76 23 0 92 0 34 0 91 82 54 0 0 0 63 85 59 98 24 29 0 8 77 26 0 34 95 39 0 0 0 74 0 0 0 0 12 0 92 0 0 55 95 66 30 0 0 29 98 0 0 0 47 0 0 80 0 0 4",
"output": "390"
},
{
"input": "100 66 1\n38 50 64 91 37 44 74 21 14 41 80 90 26 51 78 85 80 86 44 14 49 75 93 48 78 89 23 72 35 22 14 48 100 71 62 22 7 95 80 66 32 20 17 47 79 30 41 52 15 62 67 71 1 6 0 9 0 0 0 11 0 0 24 0 31 0 77 0 51 0 0 0 0 0 0 77 0 36 44 19 90 45 6 25 100 87 93 30 4 97 36 88 33 50 26 71 97 71 51 68",
"output": "130"
},
{
"input": "100 55 1\n0 33 45 83 56 96 58 24 45 30 38 60 39 69 21 87 59 21 72 73 27 46 61 61 11 97 77 5 39 3 3 35 76 37 53 84 24 75 9 48 31 90 100 84 74 81 83 83 42 23 29 94 18 1 0 53 52 99 86 37 94 54 28 75 28 80 17 14 98 68 76 20 32 23 42 31 57 79 60 14 18 27 1 98 32 3 96 25 15 38 2 6 3 28 59 54 63 2 43 59",
"output": "10"
},
{
"input": "100 55 1\n24 52 41 6 55 11 58 25 63 12 70 39 23 28 72 17 96 85 7 84 21 13 34 37 97 43 36 32 15 30 58 5 14 71 40 70 9 92 44 73 31 58 96 90 19 35 29 91 25 36 48 95 61 78 0 1 99 61 81 88 42 53 61 57 42 55 74 45 41 92 99 30 20 25 89 50 37 4 17 24 6 65 15 44 40 2 38 43 7 90 38 59 75 87 96 28 12 67 24 32",
"output": "10"
},
{
"input": "100 21 1\n62 5 97 80 81 28 83 0 26 0 0 0 0 23 0 0 90 0 0 0 0 0 0 0 0 54 71 8 0 0 42 0 73 0 17 0 1 31 71 78 58 72 84 39 54 59 13 29 16 41 71 35 88 55 70 50 33 100 100 60 52 90 7 66 44 55 51 42 90 17 86 44 46 8 52 74 8 22 2 92 34 37 58 98 70 74 19 91 74 25 4 38 71 68 50 68 63 14 60 98",
"output": "160"
},
{
"input": "5 2 20\n27 0 32 21 19",
"output": "30"
},
{
"input": "6 4 10\n10 0 0 0 0 10",
"output": "20"
},
{
"input": "8 7 100\n1 0 0 0 0 0 0 1",
"output": "10"
},
{
"input": "5 3 20\n1 21 0 0 1",
"output": "20"
},
{
"input": "4 3 1\n0 0 0 1",
"output": "10"
},
{
"input": "5 2 3\n4 0 5 6 1",
"output": "30"
},
{
"input": "5 3 87\n88 89 0 1 90",
"output": "10"
},
{
"input": "5 3 20\n15 30 0 15 35",
"output": "10"
},
{
"input": "6 3 50\n0 0 0 1 2 0",
"output": "10"
},
{
"input": "6 4 9\n100 9 10 0 0 9",
"output": "20"
},
{
"input": "5 4 20\n0 20 0 0 20",
"output": "10"
},
{
"input": "6 3 3\n1 5 0 2 2 0",
"output": "10"
},
{
"input": "5 4 100\n0 1 0 0 1",
"output": "10"
}
] | 109 | 0 | 0 | 329 |
|
263 | Beautiful Matrix | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "4"
},
{
"input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "3"
}
] | 92 | 0 | 3 | 330 |
|
21 | Intersection | [
"implementation",
"math"
] | B. Intersection | 1 | 256 | You are given two set of points. The first set is determined by the equation *A*1*x*<=+<=*B*1*y*<=+<=*C*1<==<=0, and the second one is determined by the equation *A*2*x*<=+<=*B*2*y*<=+<=*C*2<==<=0.
Write the program which finds the number of points in the intersection of two given sets. | The first line of the input contains three integer numbers *A*1,<=*B*1,<=*C*1 separated by space. The second line contains three integer numbers *A*2,<=*B*2,<=*C*2 separated by space. All the numbers are between -100 and 100, inclusive. | Print the number of points in the intersection or -1 if there are infinite number of points. | [
"1 1 0\n2 2 0\n",
"1 1 0\n2 -2 0\n"
] | [
"-1\n",
"1\n"
] | none | [
{
"input": "1 1 0\n2 2 0",
"output": "-1"
},
{
"input": "1 1 0\n2 -2 0",
"output": "1"
},
{
"input": "0 0 0\n0 0 0",
"output": "-1"
},
{
"input": "1 1 1\n1 1 1",
"output": "-1"
},
{
"input": "8 3 -4\n-5 2 7",
"output": "1"
},
{
"input": "-1 -1 0\n0 -1 -1",
"output": "1"
},
{
"input": "-1 -1 0\n1 1 -1",
"output": "0"
},
{
"input": "-1 -1 1\n0 -1 0",
"output": "1"
},
{
"input": "0 0 0\n1 -1 -1",
"output": "-1"
},
{
"input": "0 0 1\n-1 1 -1",
"output": "0"
},
{
"input": "0 1 -1\n-1 1 -1",
"output": "1"
},
{
"input": "1 0 -1\n0 0 -1",
"output": "0"
},
{
"input": "0 1 1\n1 0 0",
"output": "1"
},
{
"input": "1 0 0\n0 0 1",
"output": "0"
},
{
"input": "1 -1 -1\n1 -1 0",
"output": "0"
},
{
"input": "1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1 -1 1\n-1 -1 1",
"output": "1"
},
{
"input": "1 0 0\n0 1 1",
"output": "1"
},
{
"input": "-1 -1 1\n-1 -1 -1",
"output": "0"
},
{
"input": "-1 -1 0\n1 1 -1",
"output": "0"
},
{
"input": "0 0 0\n0 1 -1",
"output": "-1"
},
{
"input": "0 1 1\n0 1 -1",
"output": "0"
},
{
"input": "0 1 0\n1 1 0",
"output": "1"
},
{
"input": "1 0 1\n-1 0 -1",
"output": "-1"
},
{
"input": "1 1 0\n1 0 -1",
"output": "1"
},
{
"input": "0 -1 -1\n-1 0 0",
"output": "1"
},
{
"input": "1 0 0\n1 0 0",
"output": "-1"
},
{
"input": "1 1 1\n-1 -1 0",
"output": "0"
},
{
"input": "-1 -1 -1\n0 -1 1",
"output": "1"
},
{
"input": "0 -1 0\n0 0 1",
"output": "0"
},
{
"input": "0 1 1\n-1 -1 1",
"output": "1"
},
{
"input": "0 -1 0\n0 -1 1",
"output": "0"
},
{
"input": "0 1 1\n0 1 1",
"output": "-1"
},
{
"input": "1 -1 0\n-1 -1 1",
"output": "1"
},
{
"input": "0 1 1\n0 1 -1",
"output": "0"
},
{
"input": "1 0 1\n1 0 0",
"output": "0"
},
{
"input": "1 1 1\n0 0 0",
"output": "-1"
},
{
"input": "1 0 1\n-1 -1 -1",
"output": "1"
},
{
"input": "1 -1 1\n0 0 0",
"output": "-1"
},
{
"input": "0 1 1\n-1 -1 0",
"output": "1"
},
{
"input": "-1 0 1\n1 0 0",
"output": "0"
},
{
"input": "0 1 -1\n0 0 1",
"output": "0"
},
{
"input": "0 -1 0\n1 1 1",
"output": "1"
},
{
"input": "1 0 1\n0 1 1",
"output": "1"
},
{
"input": "0 0 0\n1 1 -1",
"output": "-1"
},
{
"input": "1 -1 1\n1 1 1",
"output": "1"
},
{
"input": "1 0 -1\n-1 0 1",
"output": "-1"
},
{
"input": "1 0 1\n1 -1 1",
"output": "1"
},
{
"input": "1 -1 -1\n-1 -1 -1",
"output": "1"
},
{
"input": "0 -1 1\n0 0 -1",
"output": "0"
},
{
"input": "0 0 -1\n1 -1 -1",
"output": "0"
},
{
"input": "1 1 0\n-1 0 0",
"output": "1"
},
{
"input": "1 0 -1\n0 -1 0",
"output": "1"
},
{
"input": "1 -1 0\n-1 1 0",
"output": "-1"
},
{
"input": "1 -1 1\n1 -1 0",
"output": "0"
},
{
"input": "-1 -1 -1\n-1 1 0",
"output": "1"
},
{
"input": "-1 0 1\n1 -1 1",
"output": "1"
},
{
"input": "1 -1 0\n0 -1 -1",
"output": "1"
},
{
"input": "-1 1 0\n-1 0 -1",
"output": "1"
},
{
"input": "-1 -1 -1\n1 -1 1",
"output": "1"
},
{
"input": "-1 -1 0\n1 1 1",
"output": "0"
},
{
"input": "0 1 -1\n-1 0 0",
"output": "1"
},
{
"input": "0 0 0\n0 0 0",
"output": "-1"
},
{
"input": "0 1 1\n1 0 -1",
"output": "1"
},
{
"input": "0 1 -1\n0 0 0",
"output": "-1"
},
{
"input": "1 -1 0\n-1 1 0",
"output": "-1"
},
{
"input": "0 0 0\n0 1 0",
"output": "-1"
},
{
"input": "0 -1 1\n1 -1 1",
"output": "1"
},
{
"input": "1 0 0\n0 1 0",
"output": "1"
},
{
"input": "-1 1 0\n0 -1 1",
"output": "1"
},
{
"input": "-1 0 -1\n1 1 0",
"output": "1"
},
{
"input": "0 -1 0\n1 1 -1",
"output": "1"
},
{
"input": "-1 -1 1\n-1 0 1",
"output": "1"
},
{
"input": "0 1 0\n1 0 1",
"output": "1"
},
{
"input": "1 0 0\n-1 0 -1",
"output": "0"
},
{
"input": "-1 -1 0\n1 -1 1",
"output": "1"
},
{
"input": "1 1 1\n-1 -1 -1",
"output": "-1"
},
{
"input": "1 -1 0\n-1 1 0",
"output": "-1"
},
{
"input": "-1 -1 1\n-1 1 0",
"output": "1"
},
{
"input": "0 0 1\n1 0 -1",
"output": "0"
},
{
"input": "0 -1 -2\n0 1 0",
"output": "0"
},
{
"input": "0 -1 0\n2 -2 2",
"output": "1"
},
{
"input": "1 -1 2\n-1 0 0",
"output": "1"
},
{
"input": "-2 0 2\n0 0 2",
"output": "0"
},
{
"input": "-1 0 -1\n1 -1 -1",
"output": "1"
},
{
"input": "-1 2 0\n-2 1 -2",
"output": "1"
},
{
"input": "0 2 0\n0 1 2",
"output": "0"
},
{
"input": "2 2 2\n0 -2 0",
"output": "1"
},
{
"input": "-2 0 -2\n2 -2 -2",
"output": "1"
},
{
"input": "2 2 -1\n-2 1 1",
"output": "1"
},
{
"input": "-2 -1 1\n0 -1 0",
"output": "1"
},
{
"input": "-2 1 1\n0 0 -2",
"output": "0"
},
{
"input": "-1 2 -2\n0 2 1",
"output": "1"
},
{
"input": "1 2 -2\n-1 2 0",
"output": "1"
},
{
"input": "0 0 2\n0 -1 -1",
"output": "0"
},
{
"input": "2 1 1\n1 2 1",
"output": "1"
},
{
"input": "-2 -1 2\n1 1 1",
"output": "1"
},
{
"input": "0 -1 -1\n-2 -2 -1",
"output": "1"
},
{
"input": "-1 0 -1\n0 -2 1",
"output": "1"
},
{
"input": "1 1 2\n0 1 0",
"output": "1"
},
{
"input": "-2 1 1\n2 1 -1",
"output": "1"
},
{
"input": "-1 -2 1\n-1 -2 2",
"output": "0"
},
{
"input": "0 -2 1\n-2 2 2",
"output": "1"
},
{
"input": "0 -1 2\n-1 -1 0",
"output": "1"
},
{
"input": "1 -1 -2\n1 2 -2",
"output": "1"
},
{
"input": "-2 -1 0\n-2 2 2",
"output": "1"
},
{
"input": "-1 1 0\n0 -1 0",
"output": "1"
},
{
"input": "-1 -2 2\n-1 0 -2",
"output": "1"
},
{
"input": "0 1 -1\n1 0 -2",
"output": "1"
},
{
"input": "-1 -2 -2\n-2 1 0",
"output": "1"
},
{
"input": "1 -1 2\n0 0 -2",
"output": "0"
},
{
"input": "2 -1 2\n0 -2 1",
"output": "1"
},
{
"input": "1 0 -1\n2 0 1",
"output": "0"
},
{
"input": "-2 -1 0\n-2 0 -1",
"output": "1"
},
{
"input": "-1 1 1\n0 1 1",
"output": "1"
},
{
"input": "1 1 1\n1 1 -2",
"output": "0"
},
{
"input": "1 2 1\n1 -1 1",
"output": "1"
},
{
"input": "-2 -2 0\n0 -2 -1",
"output": "1"
},
{
"input": "-1 -1 0\n-1 -2 -1",
"output": "1"
},
{
"input": "-2 -2 -2\n1 1 -1",
"output": "0"
},
{
"input": "0 0 0\n0 0 1",
"output": "0"
},
{
"input": "0 0 -87\n0 0 0",
"output": "0"
},
{
"input": "0 0 1\n0 0 1",
"output": "0"
},
{
"input": "100 100 100\n-100 100 -100",
"output": "1"
},
{
"input": "12 -32 89\n0 67 -23",
"output": "1"
},
{
"input": "0 0 1\n0 0 2",
"output": "0"
},
{
"input": "0 5 0\n0 0 5",
"output": "0"
},
{
"input": "0 1 1\n0 -1 -1",
"output": "-1"
},
{
"input": "1 1 0\n2 2 1",
"output": "0"
},
{
"input": "0 0 5\n0 0 5",
"output": "0"
},
{
"input": "0 5 0\n0 5 1",
"output": "0"
},
{
"input": "0 1 1\n0 1 2",
"output": "0"
},
{
"input": "0 1 1\n0 2 3",
"output": "0"
},
{
"input": "2 2 -3\n2 2 -2",
"output": "0"
},
{
"input": "3 3 3\n3 3 4",
"output": "0"
},
{
"input": "0 1 2\n0 2 3",
"output": "0"
},
{
"input": "0 0 1\n1 1 1",
"output": "0"
},
{
"input": "5 0 1\n7 0 2",
"output": "0"
},
{
"input": "4 6 1\n2 3 1",
"output": "0"
},
{
"input": "0 0 0\n0 1 2",
"output": "-1"
}
] | 31 | 0 | -1 | 331 |
361 | Levko and Permutation | [
"constructive algorithms",
"math",
"number theory"
] | null | null | Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*.
Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numbers *a* and *b*. Levko assumes that element *p**i* of permutation *p*1,<=*p*2,<=... ,<=*p**n* is good if *gcd*(*i*,<=*p**i*)<=><=1. Levko considers a permutation beautiful, if it has exactly *k* good elements. Unfortunately, he doesn’t know any beautiful permutation. Your task is to help him to find at least one of them. | The single line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*). | In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist.
If there are multiple suitable permutations, you are allowed to print any of them. | [
"4 2\n",
"1 1\n"
] | [
"2 4 3 1",
"-1\n"
] | In the first sample elements 4 and 3 are good because *gcd*(2, 4) = 2 > 1 and *gcd*(3, 3) = 3 > 1. Elements 2 and 1 are not good because *gcd*(1, 2) = 1 and *gcd*(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful.
The second sample has no beautiful permutations. | [
{
"input": "4 2",
"output": "2 1 3 4 "
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "7 4",
"output": "3 1 2 4 5 6 7 "
},
{
"input": "10 9",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10000 5000",
"output": "5000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "7 0",
"output": "7 1 2 3 4 5 6 "
},
{
"input": "1 0",
"output": "1 "
},
{
"input": "7 7",
"output": "-1"
},
{
"input": "100000 47",
"output": "99953 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "100000 100000",
"output": "-1"
},
{
"input": "100000 43425",
"output": "56575 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "7 6",
"output": "1 2 3 4 5 6 7 "
},
{
"input": "100000 99999",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "47 46",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 "
},
{
"input": "5 0",
"output": "5 1 2 3 4 "
},
{
"input": "4 2",
"output": "2 1 3 4 "
},
{
"input": "1533 1052",
"output": "481 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "81314 52747",
"output": "28567 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "17767 145",
"output": "17622 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "18168 7942",
"output": "10226 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "26593 15915",
"output": "10678 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "26593 8877",
"output": "17716 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "13852 12727",
"output": "1125 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "4 1",
"output": "3 1 2 4 "
},
{
"input": "8834 8834",
"output": "-1"
},
{
"input": "8485 8484",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "14564 14564",
"output": "-1"
},
{
"input": "8254 8253",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "81314 81312",
"output": "2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "5795 5792",
"output": "3 1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "6417 3",
"output": "6414 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "6896 0",
"output": "6896 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "6778 1",
"output": "6777 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "9448 1",
"output": "9447 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "5938 2",
"output": "5936 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "3072 0",
"output": "3072 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "8576 0",
"output": "8576 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "2 1",
"output": "1 2 "
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "5 5",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "100000 1",
"output": "99999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "100000 50000",
"output": "50000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "4 1",
"output": "3 1 2 4 "
},
{
"input": "100000 9999",
"output": "90001 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "100000 99000",
"output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "100000 12347",
"output": "87653 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
}
] | 46 | 6,963,200 | 0 | 334 |
|
681 | Heap Operations | [
"constructive algorithms",
"data structures",
"greedy"
] | null | null | Petya has recently learned data structure named "Binary heap".
The heap he is now operating with allows the following operations:
- put the given number into the heap; - get the value of the minimum element in the heap; - extract the minimum element from the heap;
Thus, at any moment of time the heap contains several integers (possibly none), some of them might be equal.
In order to better learn this data structure Petya took an empty heap and applied some operations above to it. Also, he carefully wrote down all the operations and their results to his event log, following the format:
- insert *x* — put the element with value *x* in the heap; - getMin *x* — the value of the minimum element contained in the heap was equal to *x*; - removeMin — the minimum element was extracted from the heap (only one instance, if there were many).
All the operations were correct, i.e. there was at least one element in the heap each time getMin or removeMin operations were applied.
While Petya was away for a lunch, his little brother Vova came to the room, took away some of the pages from Petya's log and used them to make paper boats.
Now Vova is worried, if he made Petya's sequence of operations inconsistent. For example, if one apply operations one-by-one in the order they are written in the event log, results of getMin operations might differ from the results recorded by Petya, and some of getMin or removeMin operations may be incorrect, as the heap is empty at the moment they are applied.
Now Vova wants to add some new operation records to the event log in order to make the resulting sequence of operations correct. That is, the result of each getMin operation is equal to the result in the record, and the heap is non-empty when getMin ad removeMin are applied. Vova wants to complete this as fast as possible, as the Petya may get back at any moment. He asks you to add the least possible number of operation records to the current log. Note that arbitrary number of operations may be added at the beginning, between any two other operations, or at the end of the log. | The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of the records left in Petya's journal.
Each of the following *n* lines describe the records in the current log in the order they are applied. Format described in the statement is used. All numbers in the input are integers not exceeding 109 by their absolute value. | The first line of the output should contain a single integer *m* — the minimum possible number of records in the modified sequence of operations.
Next *m* lines should contain the corrected sequence of records following the format of the input (described in the statement), one per line and in the order they are applied. All the numbers in the output should be integers not exceeding 109 by their absolute value.
Note that the input sequence of operations must be the subsequence of the output sequence.
It's guaranteed that there exists the correct answer consisting of no more than 1<=000<=000 operations. | [
"2\ninsert 3\ngetMin 4\n",
"4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2\n"
] | [
"4\ninsert 3\nremoveMin\ninsert 4\ngetMin 4\n",
"6\ninsert 1\ninsert 1\nremoveMin\nremoveMin\ninsert 2\ngetMin 2\n"
] | In the first sample, after number 3 is inserted into the heap, the minimum number is 3. To make the result of the first getMin equal to 4 one should firstly remove number 3 from the heap and then add number 4 into the heap.
In the second sample case number 1 is inserted two times, so should be similarly removed twice. | [
{
"input": "2\ninsert 3\ngetMin 4",
"output": "4\ninsert 3\nremoveMin\ninsert 4\ngetMin 4"
},
{
"input": "4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2",
"output": "6\ninsert 1\ninsert 1\nremoveMin\nremoveMin\ninsert 2\ngetMin 2"
},
{
"input": "1\ninsert 1",
"output": "1\ninsert 1"
},
{
"input": "1\ngetMin 31",
"output": "2\ninsert 31\ngetMin 31"
},
{
"input": "1\nremoveMin",
"output": "2\ninsert 0\nremoveMin"
},
{
"input": "2\ninsert 2\ngetMin 2",
"output": "2\ninsert 2\ngetMin 2"
},
{
"input": "2\ninsert 31\nremoveMin",
"output": "2\ninsert 31\nremoveMin"
},
{
"input": "2\ngetMin 31\nremoveMin",
"output": "3\ninsert 31\ngetMin 31\nremoveMin"
},
{
"input": "2\nremoveMin\ngetMin 31",
"output": "4\ninsert 0\nremoveMin\ninsert 31\ngetMin 31"
},
{
"input": "8\ninsert 219147240\nremoveMin\ngetMin 923854124\nremoveMin\ngetMin -876779400\nremoveMin\ninsert 387686853\ngetMin 749998368",
"output": "12\ninsert 219147240\nremoveMin\ninsert 923854124\ngetMin 923854124\nremoveMin\ninsert -876779400\ngetMin -876779400\nremoveMin\ninsert 387686853\nremoveMin\ninsert 749998368\ngetMin 749998368"
},
{
"input": "2\nremoveMin\ninsert 450653162",
"output": "3\ninsert 0\nremoveMin\ninsert 450653162"
},
{
"input": "6\ninsert -799688192\ngetMin 491561656\nremoveMin\ninsert -805250162\ninsert -945439443\nremoveMin",
"output": "8\ninsert -799688192\nremoveMin\ninsert 491561656\ngetMin 491561656\nremoveMin\ninsert -805250162\ninsert -945439443\nremoveMin"
},
{
"input": "30\ninsert 62350949\ngetMin -928976719\nremoveMin\ngetMin 766590157\ngetMin -276914351\ninsert 858958907\ngetMin -794653029\ngetMin 505812710\ngetMin -181182543\ninsert -805198995\nremoveMin\ninsert -200361579\nremoveMin\ninsert 988531216\ninsert -474257426\ninsert 579296921\nremoveMin\ninsert -410043658\ngetMin 716684155\nremoveMin\ngetMin -850837161\ngetMin 368670814\ninsert 579000842\nremoveMin\ngetMin -169833018\ninsert 313148949\nremoveMin\nremoveMin\ngetMin 228901059\ngetMin 599172503",
"output": "52\ninsert 62350949\ninsert -928976719\ngetMin -928976719\nremoveMin\nremoveMin\ninsert 766590157\ngetMin 766590157\ninsert -276914351\ngetMin -276914351\ninsert 858958907\ninsert -794653029\ngetMin -794653029\nremoveMin\nremoveMin\ninsert 505812710\ngetMin 505812710\ninsert -181182543\ngetMin -181182543\ninsert -805198995\nremoveMin\ninsert -200361579\nremoveMin\ninsert 988531216\ninsert -474257426\ninsert 579296921\nremoveMin\ninsert -410043658\nremoveMin\nremoveMin\nremoveMin\nremoveMin\ninsert 71668415..."
},
{
"input": "9\ninsert 3\ninsert 4\ninsert 5\nremoveMin\ngetMin 3\nremoveMin\ngetMin 4\nremoveMin\ngetMin 5",
"output": "10\ninsert 3\ninsert 4\ninsert 5\nremoveMin\ninsert 3\ngetMin 3\nremoveMin\ngetMin 4\nremoveMin\ngetMin 5"
},
{
"input": "9\ninsert 3\ninsert 4\ninsert 5\nremoveMin\ngetMin 5\nremoveMin\ngetMin 4\nremoveMin\ngetMin 3",
"output": "12\ninsert 3\ninsert 4\ninsert 5\nremoveMin\nremoveMin\ngetMin 5\nremoveMin\ninsert 4\ngetMin 4\nremoveMin\ninsert 3\ngetMin 3"
},
{
"input": "1\ngetMin 0",
"output": "2\ninsert 0\ngetMin 0"
},
{
"input": "3\ninsert 3\ninsert 4\ngetMin 4",
"output": "4\ninsert 3\ninsert 4\nremoveMin\ngetMin 4"
},
{
"input": "3\ninsert 1\ninsert 2\ngetMin 2",
"output": "4\ninsert 1\ninsert 2\nremoveMin\ngetMin 2"
},
{
"input": "3\ninsert -1\ninsert 0\ngetMin 0",
"output": "4\ninsert -1\ninsert 0\nremoveMin\ngetMin 0"
},
{
"input": "2\ninsert 0\ngetMin 0",
"output": "2\ninsert 0\ngetMin 0"
},
{
"input": "1\ninsert -1",
"output": "1\ninsert -1"
},
{
"input": "3\ninsert 1\ninsert 0\ngetMin 1",
"output": "4\ninsert 1\ninsert 0\nremoveMin\ngetMin 1"
}
] | 46 | 409,600 | -1 | 335 |
|
460 | Vasya and Socks | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day. | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"output": "19"
},
{
"input": "10 9",
"output": "11"
},
{
"input": "100 100",
"output": "101"
},
{
"input": "2 27",
"output": "2"
},
{
"input": "99 100",
"output": "99"
},
{
"input": "99 2",
"output": "197"
},
{
"input": "100 3",
"output": "149"
},
{
"input": "98 3",
"output": "146"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 2",
"output": "199"
},
{
"input": "62 4",
"output": "82"
},
{
"input": "99 10",
"output": "109"
},
{
"input": "100 5",
"output": "124"
},
{
"input": "80 80",
"output": "81"
},
{
"input": "95 16",
"output": "101"
},
{
"input": "75 16",
"output": "79"
},
{
"input": "99 74",
"output": "100"
},
{
"input": "20 21",
"output": "20"
},
{
"input": "52 96",
"output": "52"
},
{
"input": "24 5",
"output": "29"
}
] | 109 | 2,048,000 | -1 | 336 |
|
620 | Grandfather Dovlet’s calculator | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.
For example if *a*<==<=1 and *b*<==<=3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12. | The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. | Print the only integer *a* — the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "28733372"
},
{
"input": "1000000 1000000",
"output": "38"
},
{
"input": "222145 353252",
"output": "3860750"
},
{
"input": "2 1000000",
"output": "28733370"
},
{
"input": "1 999999",
"output": "28733334"
},
{
"input": "192 200",
"output": "122"
}
] | 1,000 | 0 | 0 | 337 |
|
148 | Insomnia cure | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"input": "8\n4\n1\n10\n59392",
"output": "59392"
},
{
"input": "4\n1\n8\n7\n44835",
"output": "44835"
},
{
"input": "6\n1\n7\n2\n62982",
"output": "62982"
},
{
"input": "2\n7\n4\n9\n56937",
"output": "35246"
},
{
"input": "2\n9\n8\n1\n75083",
"output": "75083"
},
{
"input": "8\n7\n7\n6\n69038",
"output": "24656"
},
{
"input": "4\n4\n2\n3\n54481",
"output": "36320"
},
{
"input": "6\n4\n9\n8\n72628",
"output": "28244"
},
{
"input": "9\n7\n8\n10\n42357",
"output": "16540"
},
{
"input": "5\n6\n4\n3\n60504",
"output": "36302"
},
{
"input": "7\n2\n3\n8\n21754",
"output": "15539"
},
{
"input": "1\n2\n10\n4\n39901",
"output": "39901"
},
{
"input": "3\n4\n7\n1\n58048",
"output": "58048"
},
{
"input": "9\n10\n4\n6\n52003",
"output": "21956"
},
{
"input": "5\n10\n9\n3\n70149",
"output": "32736"
},
{
"input": "5\n5\n5\n10\n55592",
"output": "11118"
},
{
"input": "1\n5\n2\n6\n49547",
"output": "49547"
},
{
"input": "3\n7\n7\n7\n84046",
"output": "36019"
},
{
"input": "10\n2\n1\n8\n63537",
"output": "63537"
},
{
"input": "7\n2\n10\n5\n81684",
"output": "53678"
},
{
"input": "7\n1\n6\n8\n99831",
"output": "99831"
},
{
"input": "3\n9\n3\n3\n61082",
"output": "20360"
},
{
"input": "5\n5\n8\n9\n79228",
"output": "29931"
},
{
"input": "1\n5\n5\n6\n89535",
"output": "89535"
},
{
"input": "5\n5\n2\n1\n7682",
"output": "7682"
},
{
"input": "7\n4\n8\n8\n25829",
"output": "9224"
},
{
"input": "3\n4\n3\n3\n87079",
"output": "43539"
},
{
"input": "5\n8\n4\n9\n5226",
"output": "2438"
},
{
"input": "4\n9\n6\n6\n1070",
"output": "415"
},
{
"input": "10\n10\n10\n10\n100000",
"output": "10000"
},
{
"input": "1\n1\n1\n1\n1",
"output": "1"
},
{
"input": "10\n10\n10\n10\n1",
"output": "0"
},
{
"input": "10\n10\n1\n10\n10",
"output": "10"
},
{
"input": "10\n10\n1\n10\n100",
"output": "100"
},
{
"input": "2\n2\n2\n2\n1",
"output": "0"
}
] | 92 | 0 | 0 | 339 |
|
777 | Hanoi Factory | [
"brute force",
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strange order so they had to create this new tower using already produced rings.
There are *n* rings in factory's stock. The *i*-th ring has inner radius *a**i*, outer radius *b**i* and height *h**i*. The goal is to select some subset of rings and arrange them such that the following conditions are satisfied:
- Outer radiuses form a non-increasing sequence, i.e. one can put the *j*-th ring on the *i*-th ring only if *b**j*<=≤<=*b**i*. - Rings should not fall one into the the other. That means one can place ring *j* on the ring *i* only if *b**j*<=><=*a**i*. - The total height of all rings used should be maximum possible. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of rings in factory's stock.
The *i*-th of the next *n* lines contains three integers *a**i*, *b**i* and *h**i* (1<=≤<=*a**i*,<=*b**i*,<=*h**i*<=≤<=109, *b**i*<=><=*a**i*) — inner radius, outer radius and the height of the *i*-th ring respectively. | Print one integer — the maximum height of the tower that can be obtained. | [
"3\n1 5 1\n2 6 2\n3 7 3\n",
"4\n1 2 1\n1 3 3\n4 6 2\n5 7 1\n"
] | [
"6\n",
"4\n"
] | In the first sample, the optimal solution is to take all the rings and put them on each other in order 3, 2, 1.
In the second sample, one can put the ring 3 on the ring 4 and get the tower of height 3, or put the ring 1 on the ring 2 and get the tower of height 4. | [
{
"input": "3\n1 5 1\n2 6 2\n3 7 3",
"output": "6"
},
{
"input": "4\n1 2 1\n1 3 3\n4 6 2\n5 7 1",
"output": "4"
},
{
"input": "1\n1 2 1",
"output": "1"
},
{
"input": "5\n6 10 4\n9 20 19\n8 11 18\n18 20 1\n19 20 8",
"output": "50"
},
{
"input": "5\n21 25 26\n14 30 22\n6 29 30\n13 23 21\n10 11 5",
"output": "99"
},
{
"input": "5\n45 73 26\n59 73 29\n30 74 9\n59 63 72\n73 84 79",
"output": "215"
},
{
"input": "9\n1 5 1000000000\n23 27 834000000\n6 10 1000000000\n26 30 234500000\n5 9 1000000000\n2 6 1000000000\n3 7 1000000000\n24 29 132400000\n25 28 23400000",
"output": "5000000000"
},
{
"input": "10\n312 838 197\n713 996 320\n427 767 520\n490 800 465\n575 681 995\n781 843 908\n545 615 400\n36 667 129\n85 641 27\n396 539 350",
"output": "3961"
},
{
"input": "15\n3 14 531\n28 29 17\n7 10 512\n20 21 264\n8 9 52\n16 19 759\n1 30 391\n2 27 861\n17 18 357\n15 22 428\n24 25 588\n23 26 221\n6 13 413\n11 12 667\n4 5 513",
"output": "2863"
},
{
"input": "15\n7 8 940377876\n5 26 602265950\n18 19 193066910\n23 24 754826087\n2 3 555140266\n6 25 830980693\n27 28 636793242\n20 21 809913904\n1 30 868457738\n10 17 698644057\n9 22 443624155\n13 16 941205435\n14 15 42481040\n4 29 305295425\n11 12 765921496",
"output": "4732954493"
},
{
"input": "15\n10 11 552706512\n24 25 708893662\n18 19 731182554\n12 13 110677554\n28 29 938846280\n1 30 898802132\n16 17 89748120\n2 3 85944653\n6 7 141693677\n14 15 432017874\n4 5 498032180\n22 23 906122257\n8 9 561584264\n20 21 98373932\n26 27 195705303",
"output": "1837648412"
},
{
"input": "15\n1 30 902215054\n12 13 463027806\n9 14 846985104\n20 21 770345346\n17 22 514758030\n2 15 438137019\n18 19 278467923\n16 29 613043570\n10 11 765879041\n6 7 960155075\n26 27 323764310\n24 25 724736351\n4 5 107208241\n3 8 992951987\n23 28 70277204",
"output": "3293459135"
},
{
"input": "3\n1 3 1\n4 5 1\n2 5 1",
"output": "3"
},
{
"input": "5\n1 3 1000000000\n4 5 1000000000\n2 5 1000000000\n4 6 1000000000\n5 6 1000000000",
"output": "5000000000"
}
] | 499 | 21,606,400 | 3 | 341 |
|
355 | Vasya and Digital Root | [
"constructive algorithms",
"implementation"
] | null | null | Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=<<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10.
For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3.
Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000).
Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist. | The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). | In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. | [
"4 4\n",
"5 1\n",
"1 0\n"
] | [
"5881\n",
"36172\n",
"0\n"
] | For the first test sample *dr*(5881) = *dr*(22) = 4.
For the second test sample *dr*(36172) = *dr*(19) = *dr*(10) = 1. | [
{
"input": "4 4",
"output": "5881"
},
{
"input": "5 1",
"output": "36172"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "8 7",
"output": "49722154"
},
{
"input": "487 0",
"output": "No solution"
},
{
"input": "1000 5",
"output": "8541939554067890866522280268745476436249986028349767396372181155840878549622667946850256234534972693110974918858266403731194206972478044933297639886527448596769215803533001453375065914421371731616055420973164037664278812596299678416020519508892847037891229851414508562230407367486468987019052183250172396304562086008837592345867873765321840214188417303688776985319268802181355472294386101622570417737061113209187893810568585166094583478900129912239498334853726870963804475563182775380744565964067602555515611220..."
},
{
"input": "22 9",
"output": "1583569962049529809017"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "13 5",
"output": "1381199538344"
},
{
"input": "100 4",
"output": "6334594910586850938286642284598905674550356974741186703111536643493065423553455569335256292313330478"
},
{
"input": "123 6",
"output": "928024873067884441426263446866614165147002631091527531801777528825238463822318502518751375671158771476735217071878592158343"
},
{
"input": "1000 1",
"output": "8286301124628812353504240076754144327937426329149605334362213339655339076564408659154706137278060590992944494591503606137350736487608756923833530346502466262820452589925067370165968733865814927433418675056573256434073937686361155637721866942352171450747045834987797118866710087297111065178077368748085213082452303815796793489599773148508108295035303578345492871662297456131736137780231762177312635688688714815857818196180724774924848693916003108422682889382923194020205691379066085156078824413573001257245677878..."
},
{
"input": "2 0",
"output": "No solution"
},
{
"input": "734 9",
"output": "5509849803670339733829077693143634799621955270111335907079347964026719040571586127009915057683769302171314977999063915868539391500563742827163274052101515706840652002966522709635011152141196057419086708927225560622675363856445980167733179728663010064912099615416068178748694469047950713834326493597331720572208847439692450327661109751421257198843242305082523510866664350537162158359215265173356615680034808012842300294492281197211603826994471586252822908597603049772690875861970190564793056757768783375525854981..."
},
{
"input": "678 8",
"output": "3301967993506605598118564082793505826927835671912383741219911930496842130418974223636865915672261642456247377827650506657877850580145623499927271391838907804651235401527392426584047219626357010023552497909436550723659221336486898100975437974320483591226280567200180225706948265372905918038750624429412331582504280650041845010449084641487447573160867860208332424835101416924485616494780952529083292227777966546236453553361466209621076748915774965082618181512654546592160909206650552581723190500273752213154329310..."
},
{
"input": "955 7",
"output": "4875434946733568640983465009954221247849488705968833681097920555785434899849497268074436910608289709905212840964404347113134616236366794383005890642796609027376389191650656756216171636192669456464756898600086886269167613161503734300581107122411830728903919402846291350458047685924037685489537178939190129043010338580479169957795695942333133962326316127076129681213167918954090336000635320714955444899171270809399782177230616239894234246885245402806465700760528496316658100834632585364274381823984214942419830421..."
},
{
"input": "893 3",
"output": "3154491812688062338683413382839715419754844054478504300541293341098785797116419835470049101334759365561276155814822131363018164033585874216523127145546903121862283071300185033613164338905028463571111541628115658108609505120357131336651371062955497690723492519748325195227665653129911625684144804656937323976632567108677478936761775342496303735237936919652618323430255701996987753367609559178855599470625167628439986055634187527493497208780060336400261449926469512996188738133678473883670714775784527941804249702..."
},
{
"input": "998 2",
"output": "8948712698877635315965401396781625629035528026219922557326466734622505808493494219669540192792500692387387200924494124219975316993592377253517258369463882172533672158172302951620486954085880606055358057621166471042557383036617719864238933843342304818076672889894622975857106353903546493307325157763617269195570831067239463586554245706859061059010215520785892192165179414199200952765077228454366556358805840526959104496983177402562569401945586771345953166346316987259989961516385311376707950154520512125143059966..."
},
{
"input": "960 6",
"output": "7291446744949293530598651243840704118065364362420848463900543089429494124955982767375712583398715647208330285855809398453361266463042342917037983463277320070057956978767965467358862479678812136400444143489366786562672928727263605336304125661306952421127807059398289873947797478996261161224877129724944902005212399176751167053423457968483336961277157597291131065544350665072172392437597673561840137077580044817979332136630042866681837917711758227272499659805765131669208911408670581308412686469802437930679571593..."
}
] | 46 | 0 | 0 | 342 |
|
551 | GukiZ and Contest | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position. | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4 4 4 2"
},
{
"input": "1\n2000",
"output": "1"
},
{
"input": "2\n2000 2000",
"output": "1 1"
},
{
"input": "3\n500 501 502",
"output": "3 2 1"
},
{
"input": "10\n105 106 1 1 1 11 1000 999 1000 999",
"output": "6 5 8 8 8 7 1 3 1 3"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "6 5 4 3 2 1"
},
{
"input": "7\n6 5 4 3 2 1 1",
"output": "1 2 3 4 5 6 6"
},
{
"input": "8\n153 100 87 14 10 8 6 5",
"output": "1 2 3 4 5 6 7 8"
},
{
"input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10",
"output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63"
},
{
"input": "5\n1 2000 1 1 2000",
"output": "3 1 3 3 1"
}
] | 343 | 512,000 | 3 | 343 |
|
932 | Team Work | [
"combinatorics",
"dp",
"math"
] | null | null | You have a team of *N* people. For a particular task, you can pick any non-empty subset of people. The cost of having *x* people for the task is *x**k*.
Output the sum of costs over all non-empty subsets of people. | Only line of input contains two integers *N* (1<=≤<=*N*<=≤<=109) representing total number of people and *k* (1<=≤<=*k*<=≤<=5000). | Output the sum of costs for all non empty subsets modulo 109<=+<=7. | [
"1 1\n",
"3 2\n"
] | [
"1\n",
"24\n"
] | In the first example, there is only one non-empty subset {1} with cost 1<sup class="upper-index">1</sup> = 1.
In the second example, there are seven non-empty subsets.
- {1} with cost 1<sup class="upper-index">2</sup> = 1
- {2} with cost 1<sup class="upper-index">2</sup> = 1
- {1, 2} with cost 2<sup class="upper-index">2</sup> = 4
- {3} with cost 1<sup class="upper-index">2</sup> = 1
- {1, 3} with cost 2<sup class="upper-index">2</sup> = 4
- {2, 3} with cost 2<sup class="upper-index">2</sup> = 4
- {1, 2, 3} with cost 3<sup class="upper-index">2</sup> = 9
The total cost is 1 + 1 + 4 + 1 + 4 + 4 + 9 = 24. | [
{
"input": "1 1",
"output": "1"
},
{
"input": "3 2",
"output": "24"
},
{
"input": "5 3",
"output": "800"
},
{
"input": "12 4",
"output": "8067072"
},
{
"input": "20 5",
"output": "87486873"
},
{
"input": "522 4575",
"output": "558982611"
},
{
"input": "1426 4445",
"output": "503519668"
},
{
"input": "81 3772",
"output": "420178413"
},
{
"input": "629 3447",
"output": "989788663"
},
{
"input": "2202 3497",
"output": "682330518"
},
{
"input": "2775 4325",
"output": "434053861"
},
{
"input": "3982 4784",
"output": "987043323"
},
{
"input": "2156 3417",
"output": "216656956"
},
{
"input": "902 1932",
"output": "78732216"
},
{
"input": "728 3537",
"output": "957098547"
},
{
"input": "739 3857",
"output": "836213774"
},
{
"input": "1918 4211",
"output": "972992457"
},
{
"input": "3506 4679",
"output": "130374558"
},
{
"input": "1000000000 5000",
"output": "642932262"
},
{
"input": "2500 5000",
"output": "416584034"
},
{
"input": "158260522 4575",
"output": "875142289"
},
{
"input": "602436426 4445",
"output": "582490088"
},
{
"input": "861648772 81",
"output": "939143440"
},
{
"input": "433933447 629",
"output": "396606775"
},
{
"input": "262703497 2202",
"output": "813734619"
},
{
"input": "971407775 4325",
"output": "905271522"
},
{
"input": "731963982 4784",
"output": "7722713"
},
{
"input": "450968417 2156",
"output": "634922960"
},
{
"input": "982631932 902",
"output": "262226561"
},
{
"input": "880895728 3537",
"output": "266659411"
},
{
"input": "4483 4938",
"output": "371059472"
},
{
"input": "4278 3849",
"output": "183616686"
},
{
"input": "3281 4798",
"output": "467929252"
},
{
"input": "12195 4781",
"output": "628055652"
},
{
"input": "5092 4809",
"output": "587575377"
},
{
"input": "2511 4990",
"output": "622898200"
},
{
"input": "9896 4771",
"output": "388524304"
},
{
"input": "493 4847",
"output": "414977957"
},
{
"input": "137 4733",
"output": "279404197"
},
{
"input": "6399 4957",
"output": "639782892"
},
{
"input": "999999376 642",
"output": "842765934"
},
{
"input": "999997777 645",
"output": "31545099"
},
{
"input": "999998604 448",
"output": "642283867"
},
{
"input": "999974772 208",
"output": "268825720"
},
{
"input": "999980457 228",
"output": "848255312"
},
{
"input": "999999335 1040",
"output": "585378634"
},
{
"input": "999976125 157",
"output": "300682474"
},
{
"input": "999974335 786",
"output": "754709460"
},
{
"input": "999985549 266",
"output": "607440620"
},
{
"input": "999999648 34",
"output": "378413808"
}
] | 46 | 5,632,000 | -1 | 344 |
|
688 | Lovely Palindromes | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them.
Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number? | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "2",
"output": "22"
},
{
"input": "3",
"output": "33"
},
{
"input": "4",
"output": "44"
},
{
"input": "5",
"output": "55"
},
{
"input": "6",
"output": "66"
},
{
"input": "7",
"output": "77"
},
{
"input": "8",
"output": "88"
},
{
"input": "9",
"output": "99"
},
{
"input": "13",
"output": "1331"
},
{
"input": "14",
"output": "1441"
},
{
"input": "15",
"output": "1551"
},
{
"input": "16",
"output": "1661"
},
{
"input": "17",
"output": "1771"
},
{
"input": "18",
"output": "1881"
},
{
"input": "19",
"output": "1991"
},
{
"input": "20",
"output": "2002"
},
{
"input": "26550",
"output": "2655005562"
},
{
"input": "16137",
"output": "1613773161"
},
{
"input": "91471",
"output": "9147117419"
},
{
"input": "41242",
"output": "4124224214"
},
{
"input": "30866",
"output": "3086666803"
},
{
"input": "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116",
"output": "44422312327410030099641831997138515664660798829290072534438483719780486106821804312956719051059801166110895015091765921340812860168408791738483443527009292889706646651583179913814699003001472321322444"
},
{
"input": "7806526084732010742850470902979267046151204705563201965818390803445852115032119297648697933316807252",
"output": "78065260847320107428504709029792670461512047055632019658183908034458521150321192976486979333168072522527086133397968467929112305112585443080938185691023655074021516407629792090740582470102374806256087"
},
{
"input": "2244399823612183124978103773977739948197709395321563148611877999503840818596183803323258317041875913",
"output": "22443998236121831249781037739777399481977093953215631486118779995038408185961838033232583170418759133195781407138523233083816958180483059997781168413651235939077918499377793773018794213812163289934422"
},
{
"input": "123451",
"output": "123451154321"
}
] | 1,000 | 11,264,000 | 0 | 345 |
|
706 | Interesting drink | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day. | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "0\n0\n3\n3\n3\n0\n3"
},
{
"input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969",
"output": "1\n1\n0\n1\n1\n1\n0\n1\n1"
},
{
"input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341",
"output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12"
},
{
"input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192",
"output": "4\n4\n4\n4"
},
{
"input": "1\n1\n1\n1000000000",
"output": "1"
},
{
"input": "1\n1\n1\n100005",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100005",
"output": "3"
},
{
"input": "2\n1 2\n3\n100004\n100005\n100006",
"output": "2\n2\n2"
},
{
"input": "3\n1 1 1\n1\n1",
"output": "3"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100000",
"output": "3"
},
{
"input": "5\n1 1 1 1 10\n2\n1\n10",
"output": "4\n5"
},
{
"input": "5\n3 10 8 6 11\n1\n10000000",
"output": "5"
}
] | 2,000 | 13,516,800 | 0 | 346 |
|
49 | Sleuth | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.
Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.
The English alphabet vowels are: A, E, I, O, U, Y
The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
"output": "NO"
},
{
"input": "sZecYdUvZHrXx?",
"output": "NO"
},
{
"input": "uMtXK?",
"output": "NO"
},
{
"input": "U?",
"output": "YES"
},
{
"input": "aqFDkCUKeHMyvZFcAyWlMUSQTFomtaWjoKLVyxLCw vcufPBFbaljOuHWiDCROYTcmbgzbaqHXKPOYEbuEtRqqoxBbOETCsQzhw?",
"output": "NO"
},
{
"input": "dJcNqQiFXzcbsj fItCpBLyXOnrSBPebwyFHlxUJHqCUzzCmcAvMiKL NunwOXnKeIxUZmBVwiCUfPkjRAkTPbkYCmwRRnDSLaz?",
"output": "NO"
},
{
"input": "gxzXbdcAQMuFKuuiPohtMgeypr wpDIoDSyOYTdvylcg SoEBZjnMHHYZGEqKgCgBeTbyTwyGuPZxkxsnSczotBdYyfcQsOVDVC?",
"output": "NO"
},
{
"input": "FQXBisXaJFMiHFQlXjixBDMaQuIbyqSBKGsBfTmBKCjszlGVZxEOqYYqRTUkGpSDDAoOXyXcQbHcPaegeOUBNeSD JiKOdECPOF?",
"output": "NO"
},
{
"input": "YhCuZnrWUBEed?",
"output": "NO"
},
{
"input": "hh?",
"output": "NO"
},
{
"input": "whU?",
"output": "YES"
},
{
"input": "fgwg?",
"output": "NO"
},
{
"input": "GlEmEPKrYcOnBNJUIFjszWUyVdvWw DGDjoCMtRJUburkPToCyDrOtMr?",
"output": "NO"
},
{
"input": "n?",
"output": "NO"
},
{
"input": "BueDOlxgzeNlxrzRrMbKiQdmGujEKmGxclvaPpTuHmTqBp?",
"output": "NO"
},
{
"input": "iehvZNQXDGCuVmJPOEysLyUryTdfaIxIuTzTadDbqRQGoCLXkxnyfWSGoLXebNnQQNTqAQJebbyYvHOfpUnXeWdjx?",
"output": "NO"
},
{
"input": " J ?",
"output": "NO"
},
{
"input": " j ?",
"output": "NO"
},
{
"input": " o ?",
"output": "YES"
},
{
"input": " T ?",
"output": "NO"
},
{
"input": " q ?",
"output": "NO"
},
{
"input": " j ?",
"output": "NO"
},
{
"input": " c ?",
"output": "NO"
},
{
"input": " B ?",
"output": "NO"
},
{
"input": "LuhxDHVwMPTtUIUMIQTuQETgXCOQPsfdFlyHvpfOVedjUTpGLAZGOHloIjJJtOLAlHPivzA?",
"output": "YES"
},
{
"input": "wmztmzFfwbGyOmNHENUFMTsFEMWYA?",
"output": "YES"
},
{
"input": "wGsfZCSwN PEUhNUrLfABrxA?",
"output": "YES"
},
{
"input": "mCDHENXjYbgMdBimAdPnewaHfpGWowjWrVAdvWczjw iDcUbyzMsmsnwbviiKiAyGVA?",
"output": "YES"
},
{
"input": "ARIWnwqFqxsQXsXXzHqvFjxOCttAGPUzDtWzsenPYdNXuFOIUGYZsLLK IaoxiyjBBRThoelwdPTkuCQfcBLUEJpCPIrVZlvUWA?",
"output": "YES"
},
{
"input": " PslvVpgpN BXkMFBEVXsyZFIQbBEFxGkYTeXKrOdcmhbiTUatYRUoYAayrchqbksswIlfIjerZPqptvCGnMUhyrQSvwltRhFzA?",
"output": "YES"
},
{
"input": "HpBkttwSjBXDmyleGiRWNUMPaAIE uzTrp KJDzaUiCdsMYOoWKHoUhWUoecCPmACymMUUbGav UMRpCytPETwNFAObZJA?",
"output": "YES"
}
] | 60 | 0 | 0 | 347 |
12 | Super Agent | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations. | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\nX.X\nX..",
"output": "NO"
},
{
"input": ".X.\nX.X\n.X.",
"output": "YES"
},
{
"input": "X.X\n.X.\nX.X",
"output": "YES"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "XXX\n...\nXXX",
"output": "YES"
},
{
"input": "..X\nX..\n..X",
"output": "NO"
},
{
"input": ".X.\n...\nX.X",
"output": "NO"
},
{
"input": "X.X\nX.X\nX.X",
"output": "YES"
},
{
"input": ".X.\nX.X\nXX.",
"output": "NO"
},
{
"input": "...\nXXX\nXXX",
"output": "NO"
},
{
"input": "XXX\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX.X\n.X.",
"output": "NO"
},
{
"input": "...\n..X\nXXX",
"output": "NO"
},
{
"input": "..X\nX.X\nX..",
"output": "YES"
},
{
"input": "..X\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX..\nX..",
"output": "NO"
},
{
"input": "XXX\n.X.\nXXX",
"output": "YES"
},
{
"input": "..X\n...\nX..",
"output": "YES"
},
{
"input": "...\n...\nX..",
"output": "NO"
},
{
"input": "...\n...\n.X.",
"output": "NO"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "...\n.X.\nX..",
"output": "NO"
}
] | 60 | 0 | -1 | 348 |
605 | Sorting Railway Cars | [
"constructive algorithms",
"greedy"
] | null | null | An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train? | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train.
The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train. | Print a single integer — the minimum number of actions needed to sort the railway cars. | [
"5\n4 1 2 5 3\n",
"4\n4 1 3 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train. | [
{
"input": "5\n4 1 2 5 3",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "6\n5 3 6 1 4 2",
"output": "4"
},
{
"input": "7\n1 2 3 6 7 4 5",
"output": "2"
},
{
"input": "8\n6 2 1 8 5 7 3 4",
"output": "5"
},
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "3\n1 3 2",
"output": "1"
},
{
"input": "3\n2 1 3",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "1"
},
{
"input": "3\n3 1 2",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "7\n1 3 5 7 2 4 6",
"output": "5"
},
{
"input": "7\n1 5 2 6 3 7 4",
"output": "3"
},
{
"input": "5\n1 4 2 3 5",
"output": "2"
},
{
"input": "9\n1 6 4 5 9 8 7 3 2",
"output": "7"
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "6"
},
{
"input": "50\n39 8 41 9 45 1 5 18 38 31 28 7 12 49 33 19 26 6 42 13 37 27 2 21 20 22 14 16 48 47 32 50 25 17 35 24 36 4 29 15 43 10 11 30 40 46 3 23 44 34",
"output": "46"
},
{
"input": "50\n43 15 10 33 32 31 13 7 5 22 36 1 25 14 38 19 8 6 24 42 28 21 44 35 4 3 49 30 27 46 2 9 17 37 45 41 18 39 12 11 16 20 50 26 29 34 40 47 48 23",
"output": "47"
},
{
"input": "50\n10 40 34 43 50 17 15 13 9 2 32 18 11 46 27 24 36 16 29 45 42 4 47 19 48 37 41 5 21 26 22 25 44 31 35 49 20 8 12 23 6 38 14 1 7 28 3 33 39 30",
"output": "46"
},
{
"input": "50\n10 37 3 46 45 29 36 13 21 25 35 5 18 33 12 19 50 16 30 47 20 42 39 28 2 6 38 8 7 31 22 27 26 9 15 14 34 48 4 32 40 43 44 24 11 1 23 17 49 41",
"output": "46"
},
{
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 42 37 38 39 40 41 36 43 44 45 46 47 48 49 50",
"output": "14"
},
{
"input": "50\n1 2 3 4 5 6 7 8 43 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 50 33 34 35 36 37 38 39 40 41 42 9 44 45 46 47 48 49 32",
"output": "27"
},
{
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 49 40 41 47 43 44 45 46 42 50 39 48",
"output": "11"
},
{
"input": "50\n1 2 3 4 27 6 7 8 9 10 30 12 13 14 15 16 17 18 19 20 21 22 23 24 28 26 5 25 29 11 31 32 33 34 38 36 37 35 39 40 41 42 43 44 45 46 47 48 49 50",
"output": "36"
},
{
"input": "50\n1 2 3 4 5 6 7 49 9 10 17 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 27 38 29 36 30 32 33 34 35 31 37 28 39 40 41 42 43 44 45 46 47 48 8 50",
"output": "38"
},
{
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 31 18 19 20 21 23 22 24 25 26 27 28 29 49 17 32 33 34 39 36 37 38 47 44 41 42 43 40 45 46 35 48 30 50",
"output": "33"
},
{
"input": "50\n1 2 15 4 5 6 7 8 9 10 11 12 13 14 3 16 17 18 19 32 21 22 36 28 23 26 27 24 29 30 31 20 33 34 37 25 35 38 40 39 41 42 43 44 45 46 47 48 49 50",
"output": "39"
},
{
"input": "5\n4 3 1 2 5",
"output": "3"
},
{
"input": "6\n1 3 5 6 4 2",
"output": "4"
},
{
"input": "10\n2 1 4 3 6 5 8 7 10 9",
"output": "8"
},
{
"input": "5\n1 2 4 5 3",
"output": "2"
},
{
"input": "7\n1 4 2 3 7 6 5",
"output": "4"
},
{
"input": "4\n3 1 2 4",
"output": "2"
},
{
"input": "6\n2 5 4 3 6 1",
"output": "4"
},
{
"input": "5\n1 3 4 5 2",
"output": "2"
},
{
"input": "6\n2 4 6 5 1 3",
"output": "4"
},
{
"input": "6\n1 2 4 5 6 3",
"output": "3"
},
{
"input": "9\n9 8 7 4 5 6 3 2 1",
"output": "6"
},
{
"input": "7\n4 1 2 3 6 5 7",
"output": "4"
}
] | 77 | 20,172,800 | 0 | 349 |
|
981 | Antipalindrome | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into? | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow",
"output": "49"
},
{
"input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "50"
},
{
"input": "ijvxljt",
"output": "7"
},
{
"input": "fyhcncnchyf",
"output": "10"
},
{
"input": "ffffffffffff",
"output": "0"
},
{
"input": "fyhcncfsepqj",
"output": "12"
},
{
"input": "ybejrrlbcinttnicblrrjeby",
"output": "23"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyy",
"output": "0"
},
{
"input": "ybejrrlbcintahovgjddrqatv",
"output": "25"
},
{
"input": "oftmhcmclgyqaojljoaqyglcmchmtfo",
"output": "30"
},
{
"input": "oooooooooooooooooooooooooooooooo",
"output": "0"
},
{
"input": "oftmhcmclgyqaojllbotztajglsmcilv",
"output": "32"
},
{
"input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg",
"output": "35"
},
{
"input": "gggggggggggggggggggggggggggggggggggg",
"output": "0"
},
{
"input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk",
"output": "36"
},
{
"input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf",
"output": "40"
},
{
"input": "fffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy",
"output": "43"
},
{
"input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "0"
},
{
"input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy",
"output": "49"
},
{
"input": "a",
"output": "0"
},
{
"input": "abca",
"output": "4"
},
{
"input": "aaaaabaaaaa",
"output": "10"
},
{
"input": "aba",
"output": "2"
},
{
"input": "asaa",
"output": "4"
},
{
"input": "aabaa",
"output": "4"
},
{
"input": "aabbaa",
"output": "5"
},
{
"input": "abcdaaa",
"output": "7"
},
{
"input": "aaholaa",
"output": "7"
},
{
"input": "abcdefghijka",
"output": "12"
},
{
"input": "aaadcba",
"output": "7"
},
{
"input": "aaaabaaaa",
"output": "8"
},
{
"input": "abaa",
"output": "4"
},
{
"input": "abcbaa",
"output": "6"
},
{
"input": "ab",
"output": "2"
},
{
"input": "l",
"output": "0"
},
{
"input": "aaaabcaaaa",
"output": "10"
},
{
"input": "abbaaaaaabba",
"output": "11"
},
{
"input": "abaaa",
"output": "5"
},
{
"input": "baa",
"output": "3"
},
{
"input": "aaaaaaabbba",
"output": "11"
},
{
"input": "ccbcc",
"output": "4"
},
{
"input": "bbbaaab",
"output": "7"
},
{
"input": "abaaaaaaaa",
"output": "10"
},
{
"input": "abaaba",
"output": "5"
},
{
"input": "aabsdfaaaa",
"output": "10"
},
{
"input": "aaaba",
"output": "5"
},
{
"input": "aaabaaa",
"output": "6"
},
{
"input": "baaabbb",
"output": "7"
},
{
"input": "ccbbabbcc",
"output": "8"
},
{
"input": "cabc",
"output": "4"
},
{
"input": "aabcd",
"output": "5"
},
{
"input": "abcdea",
"output": "6"
},
{
"input": "bbabb",
"output": "4"
},
{
"input": "aaaaabababaaaaa",
"output": "14"
},
{
"input": "bbabbb",
"output": "6"
},
{
"input": "aababd",
"output": "6"
},
{
"input": "abaaaa",
"output": "6"
},
{
"input": "aaaaaaaabbba",
"output": "12"
},
{
"input": "aabca",
"output": "5"
},
{
"input": "aaabccbaaa",
"output": "9"
},
{
"input": "aaaaaaaaaaaaaaaaaaaab",
"output": "21"
},
{
"input": "babb",
"output": "4"
},
{
"input": "abcaa",
"output": "5"
},
{
"input": "qwqq",
"output": "4"
},
{
"input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa",
"output": "48"
},
{
"input": "aaab",
"output": "4"
},
{
"input": "aaaaaabaaaaa",
"output": "12"
},
{
"input": "wwuww",
"output": "4"
},
{
"input": "aaaaabcbaaaaa",
"output": "12"
},
{
"input": "aaabbbaaa",
"output": "8"
},
{
"input": "aabcbaa",
"output": "6"
},
{
"input": "abccdefccba",
"output": "11"
},
{
"input": "aabbcbbaa",
"output": "8"
},
{
"input": "aaaabbaaaa",
"output": "9"
},
{
"input": "aabcda",
"output": "6"
},
{
"input": "abbca",
"output": "5"
},
{
"input": "aaaaaabbaaa",
"output": "11"
},
{
"input": "sssssspssssss",
"output": "12"
},
{
"input": "sdnmsdcs",
"output": "8"
},
{
"input": "aaabbbccbbbaaa",
"output": "13"
},
{
"input": "cbdbdc",
"output": "6"
},
{
"input": "abb",
"output": "3"
},
{
"input": "abcdefaaaa",
"output": "10"
},
{
"input": "abbbaaa",
"output": "7"
},
{
"input": "v",
"output": "0"
},
{
"input": "abccbba",
"output": "7"
},
{
"input": "axyza",
"output": "5"
},
{
"input": "abcdefgaaaa",
"output": "11"
},
{
"input": "aaabcdaaa",
"output": "9"
},
{
"input": "aaaacaaaa",
"output": "8"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa",
"output": "42"
},
{
"input": "abbbaa",
"output": "6"
},
{
"input": "abcdee",
"output": "6"
},
{
"input": "oom",
"output": "3"
},
{
"input": "aabcaa",
"output": "6"
},
{
"input": "abba",
"output": "3"
},
{
"input": "aaca",
"output": "4"
},
{
"input": "aacbca",
"output": "6"
},
{
"input": "ababa",
"output": "4"
},
{
"input": "abcda",
"output": "5"
},
{
"input": "cccaaccc",
"output": "7"
},
{
"input": "aaabcda",
"output": "7"
},
{
"input": "aa",
"output": "0"
},
{
"input": "aabaaaa",
"output": "7"
},
{
"input": "abbaaaa",
"output": "7"
},
{
"input": "aaabcbaaa",
"output": "8"
},
{
"input": "aabba",
"output": "5"
},
{
"input": "xyxx",
"output": "4"
},
{
"input": "aaaaaaaaaaaabc",
"output": "14"
},
{
"input": "bbaaaabb",
"output": "7"
},
{
"input": "aaabaa",
"output": "6"
},
{
"input": "sssssabsssss",
"output": "12"
},
{
"input": "bbbaaaabbb",
"output": "9"
},
{
"input": "abbbbaaaa",
"output": "9"
},
{
"input": "wwufuww",
"output": "6"
},
{
"input": "oowoo",
"output": "4"
},
{
"input": "cccaccc",
"output": "6"
},
{
"input": "aaa",
"output": "0"
},
{
"input": "bbbcc",
"output": "5"
},
{
"input": "abcdef",
"output": "6"
},
{
"input": "abbba",
"output": "4"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaba",
"output": "4"
},
{
"input": "azbyaaa",
"output": "7"
},
{
"input": "oooooiooooo",
"output": "10"
},
{
"input": "aabbbbbaaaaaa",
"output": "13"
}
] | 93 | 0 | 3 | 351 |
|
186 | Comparing Strings | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "YES"
},
{
"input": "qxolmbkkt\naovlajmlf",
"output": "NO"
},
{
"input": "b\ng",
"output": "NO"
},
{
"input": "ab\naba",
"output": "NO"
},
{
"input": "ba\na",
"output": "NO"
},
{
"input": "a\nab",
"output": "NO"
},
{
"input": "a\naa",
"output": "NO"
},
{
"input": "a\nz",
"output": "NO"
},
{
"input": "aabb\nbbaa",
"output": "NO"
},
{
"input": "ab\nbd",
"output": "NO"
},
{
"input": "bac\ndae",
"output": "NO"
},
{
"input": "abc\nakl",
"output": "NO"
},
{
"input": "cb\naa",
"output": "NO"
},
{
"input": "abaab\naabba",
"output": "NO"
},
{
"input": "aab\naaa",
"output": "NO"
},
{
"input": "abcde\nedcba",
"output": "NO"
},
{
"input": "abab\nbaba",
"output": "NO"
},
{
"input": "ab\nbac",
"output": "NO"
},
{
"input": "abcd\naqcb",
"output": "NO"
},
{
"input": "abc\nbad",
"output": "NO"
},
{
"input": "ab\nca",
"output": "NO"
},
{
"input": "abc\nab",
"output": "NO"
},
{
"input": "ab\nbae",
"output": "NO"
},
{
"input": "aaaabcccca\naaaadccccb",
"output": "NO"
},
{
"input": "acaa\nabca",
"output": "NO"
},
{
"input": "aba\naab",
"output": "YES"
},
{
"input": "ah\nla",
"output": "NO"
},
{
"input": "aab\naa",
"output": "NO"
},
{
"input": "abab\nabcd",
"output": "NO"
},
{
"input": "ed\nab",
"output": "NO"
}
] | 0 | 0 | -1 | 352 |
|
0 | none | [
"none"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"input": "100 99 98 100",
"output": "-1"
},
{
"input": "100 40 30 40",
"output": "-1"
},
{
"input": "100 50 19 25",
"output": "100\n51\n25"
},
{
"input": "100 50 19 30",
"output": "100\n61\n30"
},
{
"input": "49 48 25 49",
"output": "-1"
},
{
"input": "48 47 23 46",
"output": "94\n93\n46"
},
{
"input": "37 23 16 20",
"output": "42\n41\n20"
},
{
"input": "98 2 1 1",
"output": "98\n3\n1"
},
{
"input": "99 22 13 14",
"output": "99\n29\n14"
},
{
"input": "97 95 3 2",
"output": "97\n95\n3"
},
{
"input": "27 3 2 3",
"output": "-1"
},
{
"input": "13 7 6 2",
"output": "-1"
},
{
"input": "19 17 11 6",
"output": "19\n17\n11"
},
{
"input": "15 6 4 5",
"output": "15\n11\n5"
},
{
"input": "21 3 1 3",
"output": "-1"
},
{
"input": "100 99 98 97",
"output": "196\n195\n98"
},
{
"input": "99 32 13 5",
"output": "-1"
},
{
"input": "5 4 3 1",
"output": "-1"
},
{
"input": "50 20 4 8",
"output": "50\n20\n8"
},
{
"input": "60 30 10 1",
"output": "-1"
},
{
"input": "100 50 10 1",
"output": "-1"
},
{
"input": "40 30 20 10",
"output": "40\n30\n20"
},
{
"input": "50 49 5 10",
"output": "50\n49\n10"
},
{
"input": "99 98 50 97",
"output": "196\n195\n97"
},
{
"input": "50 30 10 5",
"output": "50\n30\n10"
},
{
"input": "4 3 2 1",
"output": "4\n3\n2"
},
{
"input": "100 50 3 1",
"output": "-1"
}
] | 717 | 5,529,600 | 0 | 354 |
|
120 | Quiz League | [
"implementation"
] | null | null | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number *k*. | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 if the question from sector *i* hasn't been asked yet (1<=≤<=*i*<=≤<=*n*). The sectors are given in the clockwise order, the first sector follows after the *n*-th one. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | [
"5 5\n0 1 0 1 0\n",
"2 1\n1 1\n"
] | [
"2\n",
"1\n"
] | none | [
{
"input": "5 5\n0 1 0 1 0",
"output": "2"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "3 2\n1 0 0",
"output": "1"
},
{
"input": "3 3\n0 1 0",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "6 3\n0 0 1 1 0 1",
"output": "3"
},
{
"input": "3 1\n0 1 0",
"output": "2"
},
{
"input": "3 3\n1 0 1",
"output": "3"
},
{
"input": "4 4\n1 0 1 0",
"output": "1"
},
{
"input": "5 3\n0 1 0 1 1",
"output": "4"
},
{
"input": "6 4\n1 0 0 0 0 1",
"output": "6"
},
{
"input": "7 5\n1 0 0 0 0 0 1",
"output": "7"
},
{
"input": "101 81\n1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 0 0 1 0",
"output": "82"
},
{
"input": "200 31\n1 0 0 1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 1 0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 0 1 0",
"output": "33"
},
{
"input": "17 13\n0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 1 1",
"output": "13"
},
{
"input": "102 9\n0 0 0 0 1 1 0 1 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1",
"output": "10"
}
] | 92 | 307,200 | -1 | 355 |
|
416 | Guess a number! | [
"greedy",
"implementation",
"two pointers"
] | null | null | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that *y* is strictly larger than number *x*? - Is it true that *y* is strictly smaller than number *x*? - Is it true that *y* is larger than or equal to number *x*? - Is it true that *y* is smaller than or equal to number *x*?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of *y* that meets the criteria of all answers. If there isn't such value, print "Impossible". | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10000) — the number of questions (and answers). Next *n* lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries), - "<" (for the second type queries), - ">=" (for the third type queries), - "<=" (for the fourth type queries).
All values of *x* are integer and meet the inequation <=-<=109<=≤<=*x*<=≤<=109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space. | Print any of such integers *y*, that the answers to all the queries are correct. The printed number *y* must meet the inequation <=-<=2·109<=≤<=*y*<=≤<=2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | [
"4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N\n",
"2\n> 100 Y\n< -100 Y\n"
] | [
"17\n",
"Impossible\n"
] | none | [
{
"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N",
"output": "17"
},
{
"input": "2\n> 100 Y\n< -100 Y",
"output": "Impossible"
},
{
"input": "4\n< 1 N\n> 1 N\n> 1 N\n> 1 N",
"output": "1"
},
{
"input": "4\n<= 1 Y\n>= 1 Y\n>= 1 Y\n<= 1 Y",
"output": "1"
},
{
"input": "4\n< 10 Y\n> -6 Y\n< 10 Y\n< -10 N",
"output": "-5"
},
{
"input": "1\n< 1 N",
"output": "1361956"
},
{
"input": "1\n<= 1 Y",
"output": "-1998638045"
},
{
"input": "1\n> 1 N",
"output": "-1998638045"
},
{
"input": "1\n>= 1 Y",
"output": "1361956"
},
{
"input": "4\n< 1 N\n< 1 N\n< 1 N\n<= 1 Y",
"output": "1"
},
{
"input": "4\n< 1 N\n>= 1 Y\n< 1 N\n< 1 N",
"output": "1361956"
},
{
"input": "4\n> 1 N\n<= 1 Y\n<= 1 Y\n> 1 N",
"output": "-1998638045"
},
{
"input": "4\n>= 1 Y\n> 1 N\n>= 1 Y\n>= 1 Y",
"output": "1"
},
{
"input": "4\n<= 9 Y\n< 3 Y\n< 2 Y\n< 2 Y",
"output": "-1998638045"
},
{
"input": "4\n< 0 N\n< -7 N\n>= 8 N\n>= -5 Y",
"output": "3"
},
{
"input": "4\n<= -6 N\n<= -8 N\n<= 3 Y\n<= 7 Y",
"output": "-2"
},
{
"input": "4\n>= 7 N\n<= -1 N\n>= 5 N\n<= -10 N",
"output": "0"
},
{
"input": "4\n> 5 N\n>= -5 Y\n> -9 Y\n> -9 Y",
"output": "-4"
},
{
"input": "10\n<= -60 N\n>= -59 Y\n> 22 Y\n> 95 N\n<= 91 Y\n> 77 Y\n>= -59 Y\n> -25 Y\n> -22 Y\n>= 52 Y",
"output": "85"
},
{
"input": "10\n>= -18 Y\n>= -35 Y\n> -94 Y\n< -23 N\n< -69 N\n< -68 N\n< 82 Y\n> 92 N\n< 29 Y\n>= -25 Y",
"output": "18"
},
{
"input": "10\n>= 18 Y\n<= -32 N\n>= 85 N\n<= 98 Y\n<= -43 N\n<= -79 N\n>= 97 N\n< -38 N\n< -55 N\n<= -93 N",
"output": "64"
},
{
"input": "10\n<= 2 Y\n< -33 Y\n> 6 N\n> -6 N\n< -28 Y\n> -62 Y\n< 57 Y\n<= 24 Y\n> 23 N\n> -25 N",
"output": "-54"
},
{
"input": "10\n<= -31 N\n>= 66 N\n<= 0 Y\n> -95 Y\n< 27 Y\n< -42 N\n> 3 N\n< 6 Y\n>= -42 Y\n> -70 Y",
"output": "-29"
},
{
"input": "10\n>= 54 N\n<= -52 N\n>= 64 N\n> 65 N\n< 37 Y\n> -84 Y\n>= -94 Y\n>= -95 Y\n> -72 Y\n<= 18 N",
"output": "22"
},
{
"input": "10\n> -24 N\n<= -5 Y\n<= -33 Y\n> 45 N\n> -59 Y\n> -21 N\n<= -48 N\n> 40 N\n< 12 Y\n>= 14 N",
"output": "-47"
},
{
"input": "10\n>= 91 Y\n>= -68 Y\n< 92 N\n>= -15 Y\n> 51 Y\n<= 14 N\n> 17 Y\n< 94 Y\n>= 49 Y\n> -36 Y",
"output": "93"
},
{
"input": "1\n< -1000000000 Y",
"output": "-1998638045"
},
{
"input": "1\n< 1 Y",
"output": "-1998638045"
},
{
"input": "1\n>= -999999999 Y",
"output": "-998638044"
},
{
"input": "1\n> 100000 Y",
"output": "1461956"
},
{
"input": "1\n<= 999999999 Y",
"output": "-1998638045"
},
{
"input": "1\n<= 1000000000 N",
"output": "1001361956"
},
{
"input": "4\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y",
"output": "-1998638045"
},
{
"input": "1\n>= 1000000000 Y",
"output": "1001361955"
},
{
"input": "1\n<= 999999999 N",
"output": "1001361955"
},
{
"input": "1\n<= 100 Y",
"output": "-1998638045"
},
{
"input": "1\n> 1000000000 Y",
"output": "1001361956"
},
{
"input": "1\n<= 1 Y",
"output": "-1998638045"
},
{
"input": "1\n<= 1000000000 Y",
"output": "-1998638045"
},
{
"input": "1\n<= -1000000000 Y",
"output": "-1998638045"
},
{
"input": "1\n<= -999999999 Y",
"output": "-1998638045"
},
{
"input": "1\n> 100 Y",
"output": "1362056"
},
{
"input": "2\n< -1000000000 Y\n< 3 Y",
"output": "-1998638045"
},
{
"input": "1\n<= -1000000 Y",
"output": "-1998638045"
},
{
"input": "8\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y",
"output": "-1998638045"
},
{
"input": "1\n<= 15 Y",
"output": "-1998638045"
},
{
"input": "1\n< 1000000000 Y",
"output": "-1998638045"
},
{
"input": "1\n> 10000000 Y",
"output": "11361956"
},
{
"input": "1\n< 0 Y",
"output": "-1998638045"
},
{
"input": "1\n< 100 Y",
"output": "-1998638045"
},
{
"input": "1\n<= 5 Y",
"output": "-1998638045"
},
{
"input": "3\n> 5 Y\n> 0 Y\n< 4 Y",
"output": "Impossible"
},
{
"input": "1\n>= -1000000000 N",
"output": "-1998638045"
},
{
"input": "3\n>= 1 Y\n<= 1 Y\n> 10 Y",
"output": "Impossible"
},
{
"input": "2\n> 1 Y\n< 2 Y",
"output": "Impossible"
},
{
"input": "3\n>= 5 Y\n<= 5 Y\n< 5 Y",
"output": "Impossible"
},
{
"input": "2\n>= 5 N\n> 5 Y",
"output": "Impossible"
},
{
"input": "3\n>= 4 Y\n> 4 Y\n<= 4 Y",
"output": "Impossible"
},
{
"input": "2\n>= 4 Y\n> 4 Y",
"output": "1361960"
}
] | 61 | 0 | 0 | 357 |
|
859 | Pie Rules | [
"dp",
"games"
] | null | null | You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive? | Input will begin with an integer *N* (1<=≤<=*N*<=≤<=50), the number of slices of pie.
Following this is a line with *N* integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out. | Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally. | [
"3\n141 592 653\n",
"5\n10 21 10 21 10\n"
] | [
"653 733\n",
"31 41\n"
] | In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | [
{
"input": "3\n141 592 653",
"output": "653 733"
},
{
"input": "5\n10 21 10 21 10",
"output": "31 41"
},
{
"input": "1\n100000",
"output": "0 100000"
},
{
"input": "50\n100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000",
"output": "2500000 2500000"
},
{
"input": "2\n1 100000",
"output": "1 100000"
},
{
"input": "17\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536",
"output": "65535 65536"
},
{
"input": "15\n3026 3027 4599 4854 7086 29504 38709 40467 40663 58674 61008 70794 77517 85547 87320",
"output": "306375 306420"
},
{
"input": "30\n2351 14876 66138 87327 29940 73204 19925 50198 13441 54751 1383 92120 90236 13525 3920 16669 80637 94428 54890 71321 77670 57080 82145 39778 69967 38722 46902 82127 1142 21792",
"output": "724302 724303"
},
{
"input": "1\n59139",
"output": "0 59139"
},
{
"input": "2\n9859 48096",
"output": "9859 48096"
},
{
"input": "3\n25987 64237 88891",
"output": "88891 90224"
},
{
"input": "4\n9411 13081 2149 19907",
"output": "19907 24641"
},
{
"input": "5\n25539 29221 6895 82089 18673",
"output": "80328 82089"
},
{
"input": "6\n76259 10770 87448 3054 67926 81667",
"output": "158428 168696"
},
{
"input": "7\n92387 35422 24898 32532 92988 84636 99872",
"output": "192724 270011"
},
{
"input": "8\n8515 51563 5451 94713 9537 30709 63343 41819",
"output": "138409 167241"
},
{
"input": "9\n91939 407 10197 24191 58791 9486 68030 25807 11",
"output": "102429 186430"
},
{
"input": "10\n30518 96518 74071 59971 50121 4862 43967 73607 19138 90754",
"output": "252317 291210"
},
{
"input": "11\n46646 21171 78816 89449 99375 50934 15950 90299 18702 62232 12657",
"output": "288850 297381"
},
{
"input": "12\n30070 37311 92074 18927 91732 29711 12126 41583 52857 99118 73097 33928",
"output": "296580 315954"
},
{
"input": "13\n13494 86155 96820 72596 40986 99976 16813 25571 87013 3301 832 26376 83769",
"output": "325890 327812"
},
{
"input": "14\n96918 67704 10077 34778 90239 11457 80284 42263 53872 74779 93976 53416 83860 74518",
"output": "414474 453667"
},
{
"input": "15\n13046 83844 14823 64255 15301 90234 84972 93547 88028 11665 54415 13159 83950 951 42336",
"output": "362168 392358"
},
{
"input": "16\n29174 32688 95377 26437 64554 60498 56955 10239 22183 15847 47559 40199 92552 70488 4147 73082",
"output": "370791 371188"
},
{
"input": "17\n79894 24637 8634 80107 81104 39275 53130 94227 56339 87326 7999 75751 92642 96921 74470 20999 69688",
"output": "492038 551105"
},
{
"input": "18\n96022 73481 13380 42288 6166 85348 25113 78215 23198 24212 44246 35494 92733 66459 44793 68916 82818 3967",
"output": "436157 470692"
},
{
"input": "19\n79446 55030 93934 39062 88123 88317 21289 62203 57354 28394 37390 95238 92823 92892 39308 16833 54733 51525 58759",
"output": "538648 614005"
},
{
"input": "20\n5440 88704 61481 72140 15810 58854 43034 5150 80684 61360 50516 54301 78790 43678 46138 79893 89899 60260 2881 66499",
"output": "506639 558873"
},
{
"input": "21\n21569 37548 74739 25809 65063 37631 71913 89138 47543 65542 10956 14045 78880 70111 73357 27810 70326 40523 899 6547 87440",
"output": "506467 510922"
},
{
"input": "22\n72289 86393 79484 55287 14317 83704 11192 73126 81699 2429 4100 41085 87482 72352 10976 75727 42240 79569 31621 3492 51189 25936",
"output": "513496 572193"
},
{
"input": "23\n88417 11045 92742 84765 6675 86673 40072 57114 15854 6611 40347 76636 87572 66082 38195 56348 89962 59831 29640 43541 14937 73713 52755",
"output": "602650 616877"
},
{
"input": "24\n71841 27185 73295 46946 55928 65450 12055 73806 82714 78089 787 36380 87663 68323 75814 4265 94581 31581 51850 40486 11390 21491 27560 22678",
"output": "560664 601494"
},
{
"input": "25\n87969 76030 78041 616 13694 11522 84038 25090 16869 14975 61226 96124 20457 62052 70329 76374 42303 11844 15276 37430 99330 77781 35069 64358 45168",
"output": "586407 637558"
},
{
"input": "26\n71393 24874 91299 30093 62947 14491 80214 41782 51025 19158 21666 23163 20547 64293 40653 24291 46922 92106 13294 77479 63079 25559 42579 62933 24433 39507",
"output": "569885 599895"
},
{
"input": "27\n54817 73719 96044 92275 12201 60564 84901 25770 17884 90636 14810 82907 20637 58023 10976 72208 94644 63856 11312 74424 26828 40632 58600 37316 38290 82420 48297",
"output": "716531 728460"
},
{
"input": "28\n70945 22563 76598 21753 4558 39341 48372 77054 52039 27522 75249 18459 96536 60264 5491 20125 42367 44118 42034 38665 47472 88410 66109 78995 52147 68436 9814 71112",
"output": "669482 697066"
},
{
"input": "29\n54369 14511 14048 83934 53812 75014 20356 17938 86195 31704 68393 78202 96626 86697 75814 746 46985 15868 40052 11417 11221 44700 40915 53378 98708 78644 4035 20164 37165",
"output": "678299 683312"
},
{
"input": "30\n4555 13594 57403 75796 14203 12847 66292 60885 9525 40478 57327 69970 15297 37483 39540 31102 14855 412 84174 57684 65591 19837 80431 18385 3107 87740 15433 24854 73472 88205",
"output": "620095 620382"
},
{
"input": "31\n20683 29734 37957 37978 63456 58920 70980 44873 76385 44661 17767 97009 15387 63916 77159 79019 86770 4866 14897 63141 86236 67614 87940 60064 16964 97948 9654 49714 30888 88075 63792",
"output": "825663 838784"
},
{
"input": "32\n71403 78578 75406 67455 12710 37697 67155 28861 10540 48843 10911 56753 15477 33453 4378 26936 34492 19720 12915 27382 49984 91200 95449 34448 63525 83964 3875 98767 77905 63753 83018 58084",
"output": "770578 774459"
},
{
"input": "33\n87531 27423 55960 53829 37771 40665 39138 12849 77399 53025 71350 83793 48271 59887 41997 74854 14919 24175 43637 24327 13733 38978 2959 319 10086 26876 65393 56332 68025 63623 93732 68354 83938",
"output": "741185 823963"
},
{
"input": "34\n70955 19371 60706 50603 54321 86738 11122 29541 11555 57207 31790 19344 24170 29424 36512 22771 86833 4437 41655 64376 34378 19459 86276 74702 23943 69789 59614 48489 49634 63494 12958 11328 69333 1736",
"output": "693927 744637"
},
{
"input": "35\n54379 920 41259 12784 3574 98219 40001 80825 45710 61390 24933 79088 24260 23153 6835 94880 67260 76187 39673 28616 98126 10341 26489 49085 37800 55805 86539 97542 39754 30660 32184 64703 11625 77872 63584",
"output": "823487 862568"
},
{
"input": "36\n37803 17060 78709 42262 28636 68484 79280 97517 12570 98276 52669 6128 57054 58098 68646 75501 39174 56449 3099 1369 94579 58119 1295 90764 51657 66013 48056 55107 54066 30530 75602 74973 21212 21304 22589 4895",
"output": "872694 876851"
},
{
"input": "37\n53932 65904 91967 4443 77890 47261 8160 81505 46725 69754 21621 65871 24440 51828 71673 23418 86896 4008 1117 65610 82519 5897 8804 65148 98218 76221 42277 79968 68379 30401 62125 61052 96207 64737 24698 99495 70720",
"output": "989044 1011845"
},
{
"input": "38\n70060 14749 72520 58113 2951 26037 80143 32789 80881 73936 82060 92911 24531 78261 9292 71335 91515 8462 31839 62555 46268 29482 92121 31019 12075 94942 36498 96317 58499 30271 81351 71322 81602 8169 26807 69903 38154 20539",
"output": "977736 1012543"
},
{
"input": "39\n20780 30889 9970 87591 19501 96302 76318 49481 47740 10823 42500 61167 57325 47798 36511 19252 39237 23316 29857 2603 10016 9964 99630 5402 82828 5150 98015 53882 72811 97437 57473 57400 91189 84305 85811 64503 40179 50614 52044",
"output": "954593 973021"
},
{
"input": "40\n3670 5779 20621 87964 12595 34136 98063 92429 38366 43789 88330 52934 19100 22776 43342 82312 74404 64756 73980 14278 21283 85101 63339 70409 63034 14245 33606 58571 84927 14931 25355 15452 46072 4671 5838 69121 18243 87783 29748 84047",
"output": "909877 959523"
},
{
"input": "41\n87094 21920 58071 41634 29145 45616 94239 76417 5226 47971 48770 79974 19190 25017 37857 30229 11726 12314 71998 54327 85032 8687 46656 12088 9595 24454 27827 7624 66535 14801 44581 25723 55659 48103 75242 39529 52973 17858 16985 41454 44182",
"output": "799467 864856"
},
{
"input": "42\n70518 70764 38625 3816 78399 48585 66222 60405 72085 52153 85018 39717 51984 51451 8180 78146 59448 16768 2720 51272 48780 56464 21461 86471 23452 10470 22048 65189 56655 90480 31103 11801 73758 91536 10055 34129 20407 47933 4223 98861 84475 52291",
"output": "1012190 1036128"
},
{
"input": "43\n86646 19609 43370 33293 3460 94658 95101 44393 6241 56335 78161 66757 52074 53692 2695 58767 31363 64326 738 15513 69425 4242 28971 60855 37309 53382 16269 57346 70968 90350 74522 22072 83345 67672 69060 4537 55137 78008 91461 32075 33280 70405 71607",
"output": "1039942 1109548"
},
{
"input": "44\n70070 68453 23924 95475 52714 73435 34380 61085 40396 60518 38601 26501 52165 47421 73018 6684 79085 68781 31460 88265 33173 52020 44992 2534 8062 96295 77786 39103 85280 24812 93748 75446 92932 11105 71169 66433 89866 75379 11402 22186 73572 31624 70092 10734",
"output": "1141992 1210184"
},
{
"input": "45\n53494 93105 37182 24953 1967 43700 39068 12369 7256 64700 31744 62052 84959 49662 34829 78793 51000 16339 29478 52506 96922 75606 52501 1109 21919 6503 72007 63964 75400 24682 45678 18420 67928 87241 73278 69545 24596 29646 65936 55401 89673 49738 35873 45189 3622",
"output": "1052557 1068976"
},
{
"input": "46\n36918 9246 74631 78622 94325 22476 35243 96357 41411 68882 92184 21796 28153 43392 37856 26710 64130 20793 60200 16747 84862 23383 60010 42788 68480 92519 66229 56121 57009 24553 89096 4499 53323 30673 75386 31442 92030 59721 53173 45511 29966 67853 77462 12347 61811 81517",
"output": "1199490 1212346"
},
{
"input": "47\n53046 58090 55185 8100 43578 1253 7226 13049 75567 73065 19920 48836 28243 45633 75475 74628 11853 68351 90922 89500 81315 71161 34816 49875 82337 2727 27746 37878 79833 24423 75618 82065 95614 82618 34391 1850 94056 57092 73115 70214 46067 29071 75947 46802 95807 42600 11211",
"output": "1214201 1233568"
},
{
"input": "48\n69174 6934 59931 70281 68640 47326 3402 64333 42426 77247 13063 8579 61038 39362 2694 22545 83767 15909 88940 86445 45063 27451 18133 91555 28898 45640 21967 62738 61441 24293 19036 68144 5201 26050 69204 29154 85681 19871 60352 36133 86359 47186 74432 5448 53996 27876 58022 80559",
"output": "1096672 1115247"
},
{
"input": "49\n19894 55779 73188 99759 17893 50295 8089 81025 76582 81429 73503 35619 61128 41603 40313 3166 31490 87660 19662 59197 8812 75229 25642 65938 42755 31656 16188 87599 51562 91460 38262 11118 90596 69482 71313 66858 87707 17242 14886 93539 35164 32596 83317 72606 12185 21664 80642 72099 7525",
"output": "1233007 1259909"
},
{
"input": "50\n70081 97965 40736 24325 2476 20832 54026 23972 91400 47099 95141 27386 79799 49285 4039 818 23552 72203 55273 38168 52783 50365 89351 30945 47154 8047 27586 49184 20573 8953 38849 36466 45479 89848 82827 71475 74283 87115 92590 28903 97800 74550 74140 82514 10849 6786 67881 63456 53022 25051",
"output": "1251581 1255820"
},
{
"input": "4\n10 3 2 1",
"output": "4 12"
},
{
"input": "6\n5245 1414 21632 12159 31783 7412",
"output": "38442 41203"
},
{
"input": "46\n1666 17339 9205 20040 30266 12751 11329 7951 9000 14465 11771 7600 19480 15993 19453 7470 1361 7922 27747 17347 4727 11280 403 16338 6064 11124 25723 18717 26118 271 9242 16952 26381 31795 28226 3646 27589 31472 30108 28354 25281 22429 30956 32264 14729 21685",
"output": "379808 392222"
},
{
"input": "3\n100 90 80",
"output": "90 180"
},
{
"input": "5\n10 9 8 7 6",
"output": "16 24"
},
{
"input": "4\n100 40 50 10",
"output": "50 150"
},
{
"input": "6\n5 4 3 2 1 1",
"output": "7 9"
},
{
"input": "33\n30274 12228 26670 31244 5457 2643 27275 4380 30954 23407 8387 6669 25229 31591 27518 30261 25670 20962 31316 8992 8324 26216 10812 28467 15401 23077 10311 24975 14046 12010 11406 22841 7593",
"output": "299163 327443"
},
{
"input": "3\n4 2 1",
"output": "2 5"
},
{
"input": "3\n10 5 5",
"output": "5 15"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "9 12"
},
{
"input": "4\n5 2 7 3",
"output": "7 10"
}
] | 78 | 921,600 | 3 | 358 |
|
318 | Even Odds | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,000 | 97,996,800 | 0 | 359 |
|
66 | Petya and Countryside | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input": "2\n100 100",
"output": "2"
},
{
"input": "3\n100 100 100",
"output": "3"
},
{
"input": "11\n1 2 3 4 5 6 5 4 3 2 1",
"output": "11"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 1 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "61"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1",
"output": "81"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1",
"output": "85"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 1 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 100 7 6 5 4 3 2 1",
"output": "61"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 100 8 7 6 1 4 3 2 1",
"output": "96"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 100 10 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 1 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 100 11 10 9 8 7 6 5 4 3 2 1",
"output": "55"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 100 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "59"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 100 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "86"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "83"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 100 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 1 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "74"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 100 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 1 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "52"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 100 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 1 2 1",
"output": "98"
},
{
"input": "10\n1 4 4 4 4 4 1 2 4 3",
"output": "7"
}
] | 122 | 307,200 | 0 | 361 |
811 | Vladik and Courtesy | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
"output": "Valera"
},
{
"input": "999963734 999994456",
"output": "Vladik"
},
{
"input": "1000000000 1000000000",
"output": "Vladik"
},
{
"input": "946 879",
"output": "Valera"
},
{
"input": "10819 45238",
"output": "Vladik"
},
{
"input": "101357 236928",
"output": "Vladik"
},
{
"input": "1033090 7376359",
"output": "Vladik"
},
{
"input": "9754309 9525494",
"output": "Valera"
},
{
"input": "90706344 99960537",
"output": "Vladik"
},
{
"input": "965161805 908862070",
"output": "Valera"
},
{
"input": "9 11",
"output": "Valera"
},
{
"input": "3 2",
"output": "Vladik"
},
{
"input": "6 6",
"output": "Vladik"
},
{
"input": "4 4",
"output": "Valera"
},
{
"input": "5 5",
"output": "Valera"
},
{
"input": "5 4",
"output": "Valera"
},
{
"input": "12345680 1",
"output": "Valera"
},
{
"input": "9 10",
"output": "Valera"
},
{
"input": "678 76687",
"output": "Vladik"
},
{
"input": "1 678",
"output": "Vladik"
},
{
"input": "45 1678",
"output": "Vladik"
},
{
"input": "3 3",
"output": "Vladik"
},
{
"input": "10 11",
"output": "Valera"
},
{
"input": "2 1",
"output": "Valera"
},
{
"input": "1 2",
"output": "Vladik"
},
{
"input": "2 2",
"output": "Vladik"
},
{
"input": "4 5",
"output": "Valera"
},
{
"input": "9 6",
"output": "Valera"
},
{
"input": "1 5",
"output": "Vladik"
},
{
"input": "7 8",
"output": "Vladik"
},
{
"input": "1000000000 999982505",
"output": "Valera"
},
{
"input": "12 12",
"output": "Vladik"
},
{
"input": "1000 950",
"output": "Valera"
},
{
"input": "10 9",
"output": "Valera"
},
{
"input": "100 9",
"output": "Valera"
},
{
"input": "1000 996",
"output": "Vladik"
},
{
"input": "9 5",
"output": "Valera"
}
] | 109 | 0 | 3 | 362 |
|
490 | Team Olympiad | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0. | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "1\n1 2 3"
},
{
"input": "12\n3 3 3 3 3 3 3 3 1 3 3 2",
"output": "1\n9 12 2"
},
{
"input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2",
"output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47"
},
{
"input": "12\n3 1 1 1 1 1 1 2 1 1 1 1",
"output": "1\n3 8 1"
},
{
"input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2",
"output": "1\n18 2 11"
},
{
"input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3",
"output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36"
},
{
"input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1",
"output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200"
},
{
"input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3",
"output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64"
},
{
"input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1",
"output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44"
},
{
"input": "5\n1 2 2 3 3",
"output": "1\n1 3 4"
}
] | 46 | 0 | 3 | 364 |
|
746 | Decoding | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba. | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"input": "1\nw",
"output": "w"
},
{
"input": "2\ncb",
"output": "cb"
},
{
"input": "3\nqok",
"output": "oqk"
},
{
"input": "4\naegi",
"output": "gaei"
},
{
"input": "5\noqquy",
"output": "uqoqy"
},
{
"input": "6\nulhpnm",
"output": "nhulpm"
},
{
"input": "7\nijvxljt",
"output": "jxjivlt"
},
{
"input": "8\nwwmiwkeo",
"output": "ewmwwiko"
},
{
"input": "9\ngmwqmpfow",
"output": "opqmgwmfw"
},
{
"input": "10\nhncmexsslh",
"output": "lsechnmxsh"
},
{
"input": "20\nrtcjbjlbtjfmvzdqutuw",
"output": "uudvftlbcrtjjbjmzqtw"
},
{
"input": "21\ngjyiqoebcnpsdegxnsauh",
"output": "usxesnboijgyqecpdgnah"
},
{
"input": "30\nudotcwvcwxajkadxqvxvwgmwmnqrby",
"output": "bqmmwxqdkawvcoudtwcxjaxvvgwnry"
},
{
"input": "31\nipgfrxxcgckksfgexlicjvtnhvrfbmb",
"output": "mfvnvclefkccxfpigrxgksgxijthrbb"
},
{
"input": "50\nwobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "vsolrruoeqehviaqtycivhrbwoevvkhujmhagaholrmsatdjjy"
},
{
"input": "200\nhvayscqiwpcfykibwyudkzuzdkgqqvbnrfeupjefevlvojngmlcjwzijrkzbsaovabkvvwmjgoonyhuiphwmqdoiuueuyqtychbsklflnvghipdgaxhuhiiqlqocpvhldgvnsrtcwxpidrjffwvwcirluyyxzxrglheczeuouklzkvnyubsvgvmdbrylimztotdbmjph",
"output": "pmdoziybmgsunkluuzelrzyurcvfjdpwtsvdhpolihhadignfkbctyeuoqwpuyogmvkaoszriwcmnoleeperbqgdukuwiycwqsahvycipfkbydzzkqvnfujfvvjgljzjkbavbvwjonhihmdiuuqyhsllvhpgxuiqqcvlgnrcxirfwwilyxxghceokzvybvvdrlmttbjh"
},
{
"input": "201\nrpkghhfibtmlkpdiklegblbuyshfirheatjkfoqkfayfbxeeqijwqdwkkrkbdxlhzkhyiifemsghwovorlqedngldskfbhmwrnzmtjuckxoqdszmsdnbuqnlqzswdfhagasmfswanifrjjcuwdsplytvmnfarchgqteedgfpumkssindxndliozojzlpznwedodzwrrus",
"output": "urzoenpzoolndismpgetgcanvypdujriasmaafwzlqbdmsqxcjmnwhfslneloohseiykhxbrkdwiexfakokterfsulglipltihgprkhfbmkdkebbyhihajfqfybeqjqwkkdlzhifmgwvrqdgdkbmrztukodzsnunqsdhgsfwnfjcwsltmfrhqedfuksnxdizjlzwddwrs"
},
{
"input": "500\naopxumqciwxewxvlxzebsztskjvjzwyewjztqrsuvamtvklhqrbodtncqdchjrlpywvmtgnkkwtvpggktewdgvnhydkexwoxkgltaesrtifbwpciqsvrgjtqrdnyqkgqwrryacluaqmgdwxinqieiblolyekcbzahlhxdwqcgieyfgmicvgbbitbzhejkshjunzjteyyfngigjwyqqndtjrdykzrnrpinkwtrlchhxvycrhstpecadszilicrqdeyyidohqvzfnsqfyuemigacysxvtrgxyjcvejkjstsnatfqlkeytxgsksgpcooypsmqgcluzwofaupegxppbupvtumjerohdteuenwcmqaoazohkilgpkjavcrjcslhzkyjcgfzxxzjfufichxcodcawonkxhbqgfimmlycswdzwbnmjwhbwihfoftpcqplncavmbxuwnsabiyvpcrhfgtqyaguoaigknushbqjwqmmyvsxwabrub",
"output": "ubwsymwqhukiogytfrpybswxmanpctohwhjnwdsymigbxnwcoxcffzxfcyzlcrvjplkoaamweedoemtpbpgpaozlgmpocgkgtelfasskecygtxyaieyqnzqoiydriisaethcvhcrwnpnzyrtnqwggfytzuhkeztbgcmfegqdhhzcelliinxdmalarwgqnrtgvqcwftsalkoxkyngwtgptkntvyljcqndbqlvmvsqzwyzvktsexvwxiqupaoxmcwexlzbzsjjwejtruatkhrotcdhrpwmgkwvgkedvhdewxgteribpisrjqdykqrycuqgwiqeboykbalxwciygivbibhjsjnjeynijyqdjdkrriktlhxyrspcdzlcqeydhvfsfumgcsvrxjvjjtntqkyxsspoysqcuwfuexpuvujrhtuncqozhigkacjshkjgzxjuihcdaokhqfmlcwzbmwbiffpqlcvbunaivchgqauagnsbjqmvxarb"
},
{
"input": "501\noilesjbgowlnayckhpoaitijewsyhgavnthycaecwnvzpxgjqfjyxnjcjknvvsmjbjwtcoyfbegmnnheeamvtfjkigqoanhvgdfrjchdqgowrstlmrjmcsuuwvvoeucfyhnxivosrxblfoqwikfxjnnyejdiihpenfcahtjwcnzwvxxseicvdfgqhtvefswznuyohmmljlnxubhevywpmnitnkhecsgccpstxkmdzabsnwxkokdfsogzbpnfvgudvqlstxojzfzugxbfrozveaiofrzksegdelxsdhcjlqwqlgjcqiujptoenxozhkqhcpkarretqzfkwuvbmfdcdoqliyzmlfrfhzrnkbhofuctkpeacqejwvdrlyvepudrlzncbhwrgmxrczphsoymvtuzqjscvbtqpymogupgzctepccravjcrfsadueyraqvwasravkubebojqspdntewnjohvccamvoxdauyakvehjhabpdyzyme",
"output": "mzdbhhvaudomcvonenpqoeuvravayuafcvrcecguoyqbcjztmohzrmrhczrueyrvjqaptuobnzffmylocfbukztraphkzxetjicgqqjhsldekroavofxufjxsqdgfpzofkkwsadktpcsektnpyebxllmouzsetqfvisxwnwtafehijynxkwolxsvxhfuovusmrlswgdcrdvnogkfvaenmefotjjsvkcnyfjxzncaytvgywjtapkynwgjeiolsbolachoiieshanhcewvpgqjxjjnvmbwcybgnhemtjiqahgfjhqortmjcuwvecyniorbfqifjnedipnchjczvxecdghvfwnyhmjnuhvwminhcgcsxmzbnxodsgbnvuvltozzgbrzeifzsgexdclwljquponohqckreqfwvmddqizlrhrkhfckecewdlvpdlnbwgxcpsyvuqsvtpmgpztpcajrsderqwsakbbjsdtwjhcavxaykejapyye"
}
] | 46 | 0 | 3 | 366 |
|
203 | Two Problems | [
"brute force",
"implementation"
] | null | null | A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result.
He knows that the contest number 300 was unusual because there were only two problems. The contest lasted for *t* minutes, the minutes are numbered starting from zero. The first problem had the initial cost of *a* points, and every minute its cost reduced by *d**a* points. The second problem had the initial cost of *b* points, and every minute this cost reduced by *d**b* points. Thus, as soon as the zero minute of the contest is over, the first problem will cost *a*<=-<=*d**a* points, and the second problem will cost *b*<=-<=*d**b* points. It is guaranteed that at any moment of the contest each problem has a non-negative cost.
Arkady asks you to find out whether Valera could have got exactly *x* points for this contest. You should assume that Valera could have solved any number of the offered problems. You should also assume that for each problem Valera made no more than one attempt, besides, he could have submitted both problems at the same minute of the contest, starting with minute 0 and ending with minute number *t*<=-<=1. Please note that Valera can't submit a solution exactly *t* minutes after the start of the contest or later. | The single line of the input contains six integers *x*,<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b* (0<=≤<=*x*<=≤<=600; 1<=≤<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b*<=≤<=300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first and the second problem lose per minute, correspondingly.
It is guaranteed that at each minute of the contest each problem has a non-negative cost, that is, *a*<=-<=*i*·*d**a*<=≥<=0 and *b*<=-<=*i*·*d**b*<=≥<=0 for all 0<=≤<=*i*<=≤<=*t*<=-<=1. | If Valera could have earned exactly *x* points at a contest, print "YES", otherwise print "NO" (without the quotes). | [
"30 5 20 20 3 5\n",
"10 4 100 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points. | [
{
"input": "30 5 20 20 3 5",
"output": "YES"
},
{
"input": "10 4 100 5 5 1",
"output": "NO"
},
{
"input": "0 7 30 50 3 4",
"output": "YES"
},
{
"input": "50 10 30 20 1 2",
"output": "YES"
},
{
"input": "40 1 40 5 11 2",
"output": "YES"
},
{
"input": "35 8 20 20 1 2",
"output": "YES"
},
{
"input": "10 2 27 4 11 1",
"output": "NO"
},
{
"input": "64 12 258 141 10 7",
"output": "YES"
},
{
"input": "5 3 11 100 2 4",
"output": "NO"
},
{
"input": "5 4 11 80 2 4",
"output": "YES"
},
{
"input": "28 3 16 20 3 10",
"output": "NO"
},
{
"input": "6 2 11 1 11 1",
"output": "NO"
},
{
"input": "15 5 230 213 32 25",
"output": "NO"
},
{
"input": "223 92 123 118 1 1",
"output": "YES"
},
{
"input": "375 6 133 267 19 36",
"output": "NO"
},
{
"input": "80 5 39 40 1 1",
"output": "NO"
},
{
"input": "543 4 31 69 6 5",
"output": "NO"
},
{
"input": "38 100 99 245 1 1",
"output": "YES"
},
{
"input": "3 1 20 15 17 5",
"output": "NO"
},
{
"input": "360 5 215 4 52 1",
"output": "NO"
},
{
"input": "363 2 280 239 5 231",
"output": "NO"
},
{
"input": "46 7 18 6 3 1",
"output": "NO"
},
{
"input": "5 3 135 12 21 6",
"output": "NO"
},
{
"input": "15 5 230 213 32 25",
"output": "NO"
},
{
"input": "2 5 29 36 5 6",
"output": "NO"
},
{
"input": "59 4 113 45 25 12",
"output": "YES"
},
{
"input": "74 72 104 71 1 1",
"output": "YES"
},
{
"input": "16 24 26 23 1 1",
"output": "YES"
},
{
"input": "11 1 10 1 10 1",
"output": "YES"
},
{
"input": "13 3 11 14 5 1",
"output": "YES"
},
{
"input": "1 2 1 2 1 2",
"output": "YES"
},
{
"input": "145 26 25 150 1 4",
"output": "YES"
},
{
"input": "59 18 50 17 1 1",
"output": "YES"
},
{
"input": "230 125 175 124 1 1",
"output": "YES"
},
{
"input": "142 1 66 76 18 39",
"output": "YES"
},
{
"input": "0 3 5 6 1 2",
"output": "YES"
},
{
"input": "6 46 95 45 1 1",
"output": "YES"
},
{
"input": "16 73 92 72 1 1",
"output": "YES"
},
{
"input": "3 18 272 17 6 1",
"output": "YES"
},
{
"input": "1 21 178 20 1 1",
"output": "YES"
},
{
"input": "0 15 86 84 5 2",
"output": "YES"
},
{
"input": "0 35 208 98 6 2",
"output": "YES"
},
{
"input": "0 11 67 82 6 4",
"output": "YES"
},
{
"input": "30 9 18 83 1 7",
"output": "NO"
},
{
"input": "18 12 11 54 1 3",
"output": "NO"
},
{
"input": "41 77 96 145 1 1",
"output": "YES"
},
{
"input": "27 45 44 169 1 2",
"output": "YES"
},
{
"input": "50 5 30 60 3 3",
"output": "NO"
},
{
"input": "49 2 50 20 2 1",
"output": "NO"
},
{
"input": "49 2 50 20 2 1",
"output": "NO"
},
{
"input": "17 10 10 20 1 2",
"output": "YES"
}
] | 60 | 0 | 0 | 368 |
|
106 | Choosing Laptop | [
"brute force",
"implementation"
] | B. Choosing Laptop | 2 | 256 | Vasya is choosing a laptop. The shop has *n* laptops to all tastes.
Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.
If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one.
There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. | The first line contains number *n* (1<=≤<=*n*<=≤<=100).
Then follow *n* lines. Each describes a laptop as *speed* *ram* *hdd* *cost*. Besides,
- *speed*, *ram*, *hdd* and *cost* are integers - 1000<=≤<=*speed*<=≤<=4200 is the processor's speed in megahertz - 256<=≤<=*ram*<=≤<=4096 the RAM volume in megabytes - 1<=≤<=*hdd*<=≤<=500 is the HDD in gigabytes - 100<=≤<=*cost*<=≤<=1000 is price in tugriks
All laptops have different prices. | Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to *n* in the order in which they are given in the input data. | [
"5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n"
] | [
"4"
] | In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop. | [
{
"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150",
"output": "4"
},
{
"input": "2\n1500 500 50 755\n1600 600 80 700",
"output": "2"
},
{
"input": "2\n1500 512 50 567\n1600 400 70 789",
"output": "1"
},
{
"input": "4\n1000 300 5 700\n1100 400 10 600\n1200 500 15 500\n1300 600 20 400",
"output": "4"
},
{
"input": "10\n2123 389 397 747\n2705 3497 413 241\n3640 984 470 250\n3013 2004 276 905\n3658 3213 353 602\n1428 626 188 523\n2435 1140 459 824\n2927 2586 237 860\n2361 4004 386 719\n2863 2429 476 310",
"output": "2"
},
{
"input": "25\n2123 389 397 747\n2705 3497 413 241\n3640 984 470 250\n3013 2004 276 905\n3658 3213 353 602\n1428 626 188 523\n2435 1140 459 824\n2927 2586 237 860\n2361 4004 386 719\n2863 2429 476 310\n3447 3875 1 306\n3950 1901 31 526\n4130 1886 152 535\n1951 1840 122 814\n1798 3722 474 106\n2305 3979 82 971\n3656 3148 349 992\n1062 1648 320 491\n3113 3706 302 542\n3545 1317 184 853\n1277 2153 95 492\n2189 3495 427 655\n4014 3030 22 963\n1455 3840 155 485\n2760 717 309 891",
"output": "15"
},
{
"input": "1\n1200 512 300 700",
"output": "1"
},
{
"input": "1\n4200 4096 500 1000",
"output": "1"
},
{
"input": "1\n1000 256 1 100",
"output": "1"
},
{
"input": "2\n2000 500 200 100\n3000 600 100 200",
"output": "1"
},
{
"input": "2\n2000 500 200 200\n3000 600 100 100",
"output": "2"
},
{
"input": "2\n2000 600 100 100\n3000 500 200 200",
"output": "1"
},
{
"input": "2\n2000 700 100 200\n3000 500 200 100",
"output": "2"
},
{
"input": "2\n3000 500 100 100\n1500 600 200 200",
"output": "1"
},
{
"input": "2\n3000 500 100 300\n1500 600 200 200",
"output": "2"
},
{
"input": "3\n3467 1566 191 888\n3047 3917 3 849\n1795 1251 97 281",
"output": "2"
},
{
"input": "4\n3835 1035 5 848\n2222 3172 190 370\n2634 2698 437 742\n1748 3112 159 546",
"output": "2"
},
{
"input": "5\n3511 981 276 808\n3317 2320 354 878\n3089 702 20 732\n1088 2913 327 756\n3837 691 173 933",
"output": "4"
},
{
"input": "6\n1185 894 287 455\n2465 3317 102 240\n2390 2353 81 615\n2884 603 170 826\n3202 2070 320 184\n3074 3776 497 466",
"output": "5"
},
{
"input": "7\n3987 1611 470 720\n1254 4048 226 626\n1747 630 25 996\n2336 2170 402 123\n1902 3952 337 663\n1416 271 77 499\n1802 1399 419 929",
"output": "4"
},
{
"input": "10\n3888 1084 420 278\n2033 277 304 447\n1774 514 61 663\n2055 3437 67 144\n1237 1590 145 599\n3648 663 244 525\n3691 2276 332 504\n1496 2655 324 313\n2462 1930 13 644\n1811 331 390 284",
"output": "4"
},
{
"input": "13\n3684 543 70 227\n3953 1650 151 681\n2452 655 102 946\n3003 990 121 411\n2896 1936 158 155\n1972 717 366 754\n3989 2237 32 521\n2738 2140 445 965\n2884 1772 251 369\n2240 741 465 209\n4073 2812 494 414\n3392 955 425 133\n4028 717 90 123",
"output": "11"
},
{
"input": "17\n3868 2323 290 182\n1253 3599 38 217\n2372 354 332 897\n1286 649 332 495\n1642 1643 301 216\n1578 792 140 299\n3329 3039 359 525\n1362 2006 172 183\n1058 3961 423 591\n3196 914 484 675\n3032 3752 217 954\n2391 2853 171 579\n4102 3170 349 516\n1218 1661 451 354\n3375 1997 196 404\n1030 918 198 893\n2546 2029 399 647",
"output": "14"
},
{
"input": "22\n1601 1091 249 107\n2918 3830 312 767\n4140 409 393 202\n3485 2409 446 291\n2787 530 272 147\n2303 3400 265 206\n2164 1088 143 667\n1575 2439 278 863\n2874 699 369 568\n4017 1625 368 641\n3446 916 53 509\n3627 3229 328 256\n1004 2525 109 670\n2369 3299 57 351\n4147 3038 73 309\n3510 3391 390 470\n3308 3139 268 736\n3733 1054 98 809\n3967 2992 408 873\n2104 3191 83 687\n2223 2910 209 563\n1406 2428 147 673",
"output": "3"
},
{
"input": "27\n1689 1927 40 270\n3833 2570 167 134\n2580 3589 390 300\n1898 2587 407 316\n1841 2772 411 187\n1296 288 407 506\n1215 263 236 307\n2737 1427 84 992\n1107 1879 284 866\n3311 2507 475 147\n2951 2214 209 375\n1352 2582 110 324\n2082 747 289 521\n2226 1617 209 108\n2253 1993 109 835\n2866 2360 29 206\n1431 3581 185 918\n3800 1167 463 943\n4136 1156 266 490\n3511 1396 478 169\n3498 1419 493 792\n2660 2165 204 172\n3509 2358 178 469\n1568 3564 276 319\n3871 2660 472 366\n3569 2829 146 761\n1365 2943 460 611",
"output": "10"
},
{
"input": "2\n1000 2000 300 120\n1000 2000 300 130",
"output": "1"
},
{
"input": "10\n2883 1110 230 501\n2662 821 163 215\n2776 1131 276 870\n2776 1131 276 596\n2776 1131 276 981\n2662 821 163 892\n2662 821 163 997\n2883 1110 230 132\n2776 1131 276 317\n2883 1110 230 481",
"output": "8"
},
{
"input": "23\n1578 3681 380 163\n2640 3990 180 576\n3278 2311 131 386\n3900 513 443 873\n1230 1143 267 313\n2640 3990 180 501\n1230 1143 267 428\n1578 3681 380 199\n1578 3681 380 490\n3900 513 443 980\n3900 513 443 882\n3278 2311 131 951\n3278 2311 131 863\n2640 3990 180 916\n3278 2311 131 406\n3278 2311 131 455\n3278 2311 131 239\n1230 1143 267 439\n3900 513 443 438\n3900 513 443 514\n3278 2311 131 526\n1578 3681 380 123\n1578 3681 380 263",
"output": "22"
},
{
"input": "6\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n1000 256 1 100",
"output": "4"
},
{
"input": "2\n1000 256 1 100\n1000 256 1 101",
"output": "1"
},
{
"input": "2\n1500 500 300 1000\n1500 500 300 900",
"output": "2"
},
{
"input": "4\n1000 256 1 500\n1000 256 1 400\n1000 256 1 300\n1000 256 1 200",
"output": "4"
},
{
"input": "3\n1500 1024 300 150\n1200 512 150 100\n1000 256 50 200",
"output": "1"
}
] | 186 | 0 | 0 | 369 |
0 | none | [
"none"
] | null | null | Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip.
Next line contains a string of length *n* which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d**i*<=≤<=109) — the length of the jump from the *i*-th cell. | Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). | [
"2\n><\n1 2\n",
"3\n>><\n2 1 1\n"
] | [
"FINITE\n",
"INFINITE"
] | In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | [
{
"input": "2\n><\n1 2",
"output": "FINITE"
},
{
"input": "3\n>><\n2 1 1",
"output": "INFINITE"
},
{
"input": "1\n>\n1000000000",
"output": "FINITE"
},
{
"input": "1\n<\n1000000000",
"output": "FINITE"
},
{
"input": "2\n>>\n1 1",
"output": "FINITE"
},
{
"input": "5\n>><><\n1 2 3 1 2",
"output": "FINITE"
},
{
"input": "5\n>><><\n1 2 2 1 2",
"output": "INFINITE"
},
{
"input": "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 10",
"output": "FINITE"
},
{
"input": "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 5",
"output": "INFINITE"
},
{
"input": "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 1",
"output": "INFINITE"
},
{
"input": "3\n><<\n2 1 1",
"output": "INFINITE"
},
{
"input": "10\n>>>>>>>>>>\n1 1 1 1 1 1 1 1 1 100",
"output": "FINITE"
},
{
"input": "3\n><<\n2 100 2",
"output": "INFINITE"
},
{
"input": "3\n><<\n2 3 2",
"output": "INFINITE"
},
{
"input": "3\n>><\n2 3 2",
"output": "INFINITE"
},
{
"input": "3\n><>\n1 1 1",
"output": "INFINITE"
},
{
"input": "3\n>><\n2 2 2",
"output": "INFINITE"
},
{
"input": "4\n>><<\n2 100 2 100",
"output": "INFINITE"
},
{
"input": "3\n><>\n1 1 3",
"output": "INFINITE"
},
{
"input": "5\n><>>>\n1 1 10 10 10",
"output": "INFINITE"
},
{
"input": "5\n><<<<\n500 1 2 3 4",
"output": "FINITE"
},
{
"input": "4\n><><\n2 1000 1 1",
"output": "INFINITE"
},
{
"input": "3\n><<\n2 10 2",
"output": "INFINITE"
},
{
"input": "3\n><<\n2 5 2",
"output": "INFINITE"
},
{
"input": "2\n><\n5 5",
"output": "FINITE"
},
{
"input": "3\n>><\n1 10 10",
"output": "FINITE"
},
{
"input": "4\n><<>\n2 1 1 5",
"output": "INFINITE"
},
{
"input": "5\n<<>>>\n1 1 1 1 1",
"output": "FINITE"
},
{
"input": "3\n><>\n1 1 12345",
"output": "INFINITE"
},
{
"input": "4\n>>><\n3 2 2 3",
"output": "INFINITE"
},
{
"input": "3\n><>\n1 1 100000",
"output": "INFINITE"
}
] | 140 | 12,288,000 | 3 | 373 |
|
339 | Helpful Maths | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "1+2+1+2+2+2+2+1+3+3",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3",
"output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3",
"output": "3"
},
{
"input": "1+1",
"output": "1+1"
},
{
"input": "1+2",
"output": "1+2"
},
{
"input": "1+3",
"output": "1+3"
},
{
"input": "2+1",
"output": "1+2"
},
{
"input": "2+2",
"output": "2+2"
},
{
"input": "2+3",
"output": "2+3"
},
{
"input": "3+1",
"output": "1+3"
},
{
"input": "3+2",
"output": "2+3"
},
{
"input": "3+3",
"output": "3+3"
}
] | 92 | 0 | 3 | 374 |
|
114 | Cifera | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "NO"
},
{
"input": "256\n16777217",
"output": "NO"
},
{
"input": "4638\n21511044",
"output": "YES\n1"
},
{
"input": "24\n191102976",
"output": "YES\n5"
},
{
"input": "52010\n557556453",
"output": "NO"
},
{
"input": "61703211\n1750753082",
"output": "NO"
},
{
"input": "137\n2571353",
"output": "YES\n2"
},
{
"input": "8758\n1746157336",
"output": "NO"
},
{
"input": "2\n64",
"output": "YES\n5"
},
{
"input": "96\n884736",
"output": "YES\n2"
},
{
"input": "1094841453\n1656354409",
"output": "NO"
},
{
"input": "1154413\n1229512809",
"output": "NO"
},
{
"input": "2442144\n505226241",
"output": "NO"
},
{
"input": "11548057\n1033418098",
"output": "NO"
},
{
"input": "581\n196122941",
"output": "YES\n2"
},
{
"input": "146\n1913781536",
"output": "NO"
},
{
"input": "945916\n1403881488",
"output": "NO"
},
{
"input": "68269\n365689065",
"output": "NO"
},
{
"input": "30\n900",
"output": "YES\n1"
},
{
"input": "6\n1296",
"output": "YES\n3"
},
{
"input": "1470193122\n1420950405",
"output": "NO"
},
{
"input": "90750\n1793111557",
"output": "NO"
},
{
"input": "1950054\n1664545956",
"output": "NO"
},
{
"input": "6767692\n123762320",
"output": "NO"
},
{
"input": "1437134\n1622348229",
"output": "NO"
},
{
"input": "444103\n1806462642",
"output": "NO"
},
{
"input": "2592\n6718464",
"output": "YES\n1"
},
{
"input": "50141\n366636234",
"output": "NO"
},
{
"input": "835\n582182875",
"output": "YES\n2"
},
{
"input": "156604\n902492689",
"output": "NO"
},
{
"input": "27385965\n1742270058",
"output": "NO"
},
{
"input": "3\n9",
"output": "YES\n1"
},
{
"input": "35\n1838265625",
"output": "YES\n5"
},
{
"input": "8\n4096",
"output": "YES\n3"
},
{
"input": "85955\n945811082",
"output": "NO"
},
{
"input": "54958832\n956670209",
"output": "NO"
},
{
"input": "1475381\n1348159738",
"output": "NO"
},
{
"input": "7313241\n413670642",
"output": "NO"
},
{
"input": "582470\n2116368165",
"output": "NO"
},
{
"input": "26859739\n595086170",
"output": "NO"
},
{
"input": "249766393\n1582130",
"output": "NO"
},
{
"input": "11734\n137686756",
"output": "YES\n1"
},
{
"input": "925093\n1098566745",
"output": "NO"
},
{
"input": "40\n1600",
"output": "YES\n1"
},
{
"input": "2147483647\n2147483647",
"output": "YES\n0"
},
{
"input": "2147483646\n2147483647",
"output": "NO"
},
{
"input": "2147483647\n2147483646",
"output": "NO"
},
{
"input": "2\n2147483647",
"output": "NO"
},
{
"input": "2\n1073741825",
"output": "NO"
},
{
"input": "2\n1073741824",
"output": "YES\n29"
},
{
"input": "10000\n10",
"output": "NO"
},
{
"input": "10\n10000",
"output": "YES\n3"
},
{
"input": "10\n2000000000",
"output": "NO"
},
{
"input": "10\n1000000000",
"output": "YES\n8"
},
{
"input": "5\n1808548329",
"output": "NO"
},
{
"input": "2\n2147483646",
"output": "NO"
},
{
"input": "25\n125",
"output": "NO"
},
{
"input": "6\n18",
"output": "NO"
},
{
"input": "5\n30",
"output": "NO"
}
] | 248 | 0 | 3 | 378 |
|
393 | Nineteen | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters.
Help her to find the maximum number of "nineteen"s that she can get in her string. | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss",
"output": "1"
},
{
"input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs",
"output": "2"
},
{
"input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi",
"output": "2"
},
{
"input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn",
"output": "1"
},
{
"input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti",
"output": "2"
},
{
"input": "rmeetriiitijmrenmeiijt",
"output": "0"
},
{
"input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne",
"output": "1"
},
{
"input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer",
"output": "2"
},
{
"input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim",
"output": "2"
},
{
"input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm",
"output": "3"
},
{
"input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn",
"output": "3"
},
{
"input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni",
"output": "1"
},
{
"input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm",
"output": "2"
},
{
"input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet",
"output": "3"
},
{
"input": "jrjshtjstteh",
"output": "0"
},
{
"input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn",
"output": "2"
},
{
"input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn",
"output": "2"
},
{
"input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei",
"output": "1"
},
{
"input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin",
"output": "2"
},
{
"input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin",
"output": "1"
},
{
"input": "rnsrsmretjiitrjthhritniijhjmm",
"output": "0"
},
{
"input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj",
"output": "3"
},
{
"input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni",
"output": "0"
},
{
"input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis",
"output": "2"
},
{
"input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh",
"output": "3"
},
{
"input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei",
"output": "3"
},
{
"input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs",
"output": "1"
},
{
"input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj",
"output": "1"
},
{
"input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj",
"output": "2"
},
{
"input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii",
"output": "1"
},
{
"input": "iihienhirmnihh",
"output": "0"
},
{
"input": "ismtthhshjmhisssnmnhe",
"output": "0"
},
{
"input": "rhsmnrmhejshinnjrtmtsssijimimethnm",
"output": "0"
},
{
"input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj",
"output": "3"
},
{
"input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes",
"output": "2"
},
{
"input": "ssrmjmjeeetrnimemrhimes",
"output": "0"
},
{
"input": "n",
"output": "0"
},
{
"input": "ni",
"output": "0"
},
{
"input": "nine",
"output": "0"
},
{
"input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen",
"output": "13"
},
{
"input": "ninetee",
"output": "0"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd",
"output": "0"
},
{
"input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch",
"output": "0"
},
{
"input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq",
"output": "0"
},
{
"input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz",
"output": "13"
},
{
"input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee",
"output": "3"
},
{
"input": "ttttiiiieeeeeeeeeeeennnnnnnnn",
"output": "4"
},
{
"input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn",
"output": "3"
},
{
"input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt",
"output": "4"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn",
"output": "3"
},
{
"input": "nineeen",
"output": "0"
},
{
"input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii",
"output": "0"
},
{
"input": "nineteenieteenieteenieteenieteenieteenieteen",
"output": "4"
},
{
"input": "nineteenineteenineteenineteenineteen",
"output": "5"
}
] | 108 | 0 | 0 | 379 |
|
4 | Watermelon | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 92 | 0 | 3.954 | 380 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.