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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
975 | Mancala | [
"brute force",
"implementation"
] | null | null | Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.
Note that the counter-clockwise order means if the player takes the stones from hole $i$, he will put one stone in the $(i+1)$-th hole, then in the $(i+2)$-th, etc. If he puts a stone in the $14$-th hole, the next one will be put in the first hole.
After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.
Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move. | The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$)Β β the number of stones in each hole.
It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board. | Output one integer, the maximum possible score after one move. | [
"0 1 1 0 0 0 0 0 0 7 0 0 0 0\n",
"5 1 1 1 1 0 0 0 0 0 0 0 0 0\n"
] | [
"4\n",
"8\n"
] | In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$. | [
{
"input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0",
"output": "4"
},
{
"input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0",
"output": "8"
},
{
"input": "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1",
"output": "54294"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 0 15",
"output": "2"
},
{
"input": "1 0 0 0 0 1 0 0 0 0 1 0 0 0",
"output": "0"
},
{
"input": "5 5 1 1 1 3 3 3 5 7 5 3 7 5",
"output": "38"
},
{
"input": "787 393 649 463 803 365 81 961 989 531 303 407 579 915",
"output": "7588"
},
{
"input": "8789651 4466447 1218733 6728667 1796977 6198853 8263135 6309291 8242907 7136751 3071237 5397369 6780785 9420869",
"output": "81063456"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 0 29",
"output": "26"
},
{
"input": "282019717 109496191 150951267 609856495 953855615 569750143 6317733 255875779 645191029 572053369 290936613 338480779 879775193 177172893",
"output": "5841732816"
},
{
"input": "105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505 105413505",
"output": "120472578"
},
{
"input": "404418821 993626161 346204297 122439813 461187221 628048227 625919459 628611733 938993057 701270099 398043779 684205961 630975553 575964835",
"output": "8139909016"
},
{
"input": "170651077 730658441 824213789 583764177 129437345 717005779 675398017 314979709 380861369 265878463 746564659 797260041 506575735 335169317",
"output": "6770880638"
},
{
"input": "622585025 48249287 678950449 891575125 637411965 457739735 829353393 235216425 284006447 875591469 492839209 296444305 513776057 810057753",
"output": "7673796644"
},
{
"input": "475989857 930834747 786217439 927967137 489188151 869354161 276693267 56154399 131055697 509249443 143116853 426254423 44465165 105798821",
"output": "6172339560"
},
{
"input": "360122921 409370351 226220005 604004145 85173909 600403773 624052991 138163383 729239967 189036661 619842883 270087537 749500483 243727913",
"output": "5848946922"
},
{
"input": "997102881 755715147 273805839 436713689 547411799 72470207 522269145 647688957 137422311 422612659 197751751 679663349 821420227 387967237",
"output": "6900015198"
},
{
"input": "690518849 754551537 652949719 760695679 491633619 477564457 11669279 700467439 470069297 782338983 718169393 884421719 24619427 215745577",
"output": "7635414974"
},
{
"input": "248332749 486342237 662201929 917696895 555278549 252122023 850296207 463343655 832574345 954281071 168282553 825538865 996753493 461254663",
"output": "6400166934"
},
{
"input": "590789361 636464947 404477303 337309187 476703809 426863069 120608741 703406277 645444697 761482231 996635839 33459441 677458865 483861751",
"output": "7294965518"
},
{
"input": "297857621 238127103 749085829 139033277 597985489 202617713 982184715 183932743 278551059 297781685 330124279 338959601 682874531 187519685",
"output": "5201808164"
},
{
"input": "1 1 1 1 1 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "1 1 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "1 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "2"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 1 1",
"output": "2"
}
] | 0 | 0 | -1 | 3,363 |
|
920 | Water The Garden | [
"implementation"
] | null | null | It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *x**i* is turned on, then after one second has passed, the bed *x**i* will be watered; after two seconds have passed, the beds from the segment [*x**i*<=-<=1,<=*x**i*<=+<=1] will be watered (if they exist); after *j* seconds have passed (*j* is an integer number), the beds from the segment [*x**i*<=-<=(*j*<=-<=1),<=*x**i*<=+<=(*j*<=-<=1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [*x**i*<=-<=2.5,<=*x**i*<=+<=2.5] will be watered after 2.5 seconds have passed; only the segment [*x**i*<=-<=2,<=*x**i*<=+<=2] will be watered at that moment.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer! | The first line contains one integer *t* β the number of test cases to solve (1<=β€<=*t*<=β€<=200).
Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=β€<=*n*<=β€<=200, 1<=β€<=*k*<=β€<=*n*) β the number of garden beds and water taps, respectively.
Next line contains *k* integers *x**i* (1<=β€<=*x**i*<=β€<=*n*) β the location of *i*-th water tap. It is guaranteed that for each condition *x**i*<=-<=1<=<<=*x**i* holds.
It is guaranteed that the sum of *n* over all test cases doesn't exceed 200.
Note that in hacks you have to set *t*<==<=1. | For each test case print one integer β the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered. | [
"3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n"
] | [
"3\n1\n4\n"
] | The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1,β3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes. 1. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | [
{
"input": "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1",
"output": "3\n1\n4"
},
{
"input": "26\n1 1\n1\n2 1\n2\n2 1\n1\n2 2\n1 2\n3 1\n3\n3 1\n2\n3 2\n2 3\n3 1\n1\n3 2\n1 3\n3 2\n1 2\n3 3\n1 2 3\n4 1\n4\n4 1\n3\n4 2\n3 4\n4 1\n2\n4 2\n2 4\n4 2\n2 3\n4 3\n2 3 4\n4 1\n1\n4 2\n1 4\n4 2\n1 3\n4 3\n1 3 4\n4 2\n1 2\n4 3\n1 2 4\n4 3\n1 2 3\n4 4\n1 2 3 4",
"output": "1\n2\n2\n1\n3\n2\n2\n3\n2\n2\n1\n4\n3\n3\n3\n2\n2\n2\n4\n2\n2\n2\n3\n2\n2\n1"
},
{
"input": "31\n5 1\n5\n5 1\n4\n5 2\n4 5\n5 1\n3\n5 2\n3 5\n5 2\n3 4\n5 3\n3 4 5\n5 1\n2\n5 2\n2 5\n5 2\n2 4\n5 3\n2 4 5\n5 2\n2 3\n5 3\n2 3 5\n5 3\n2 3 4\n5 4\n2 3 4 5\n5 1\n1\n5 2\n1 5\n5 2\n1 4\n5 3\n1 4 5\n5 2\n1 3\n5 3\n1 3 5\n5 3\n1 3 4\n5 4\n1 3 4 5\n5 2\n1 2\n5 3\n1 2 5\n5 3\n1 2 4\n5 4\n1 2 4 5\n5 3\n1 2 3\n5 4\n1 2 3 5\n5 4\n1 2 3 4\n5 5\n1 2 3 4 5",
"output": "5\n4\n4\n3\n3\n3\n3\n4\n2\n2\n2\n3\n2\n2\n2\n5\n3\n2\n2\n3\n2\n2\n2\n4\n2\n2\n2\n3\n2\n2\n1"
},
{
"input": "1\n200 1\n200",
"output": "200"
},
{
"input": "1\n5 1\n5",
"output": "5"
},
{
"input": "1\n177 99\n1 4 7 10 11 13 14 15 16 17 19 21 22 24 25 26 27 28 32 34 35 38 39 40 42 45 46 52 54 55 57 58 59 60 62 64 65 67 70 71 74 77 78 79 80 81 83 84 88 92 93 94 95 100 101 102 104 106 107 108 109 110 112 113 114 115 116 118 122 123 124 125 127 128 129 130 134 135 137 138 139 140 142 146 148 149 154 158 160 161 162 165 166 167 169 171 172 173 176",
"output": "4"
},
{
"input": "1\n69 12\n5 7 10 11 12 18 20 27 28 31 47 67",
"output": "11"
},
{
"input": "1\n74 7\n19 39 40 47 55 57 61",
"output": "19"
},
{
"input": "1\n170 11\n14 18 37 39 80 83 103 112 124 127 131",
"output": "40"
},
{
"input": "1\n200 1\n8",
"output": "193"
},
{
"input": "1\n155 53\n2 3 7 9 10 11 12 20 24 26 28 31 38 39 40 51 53 56 58 63 65 66 69 70 72 74 79 81 83 88 90 92 100 103 104 106 111 113 114 115 116 121 124 126 127 128 133 136 142 143 145 148 150",
"output": "6"
},
{
"input": "1\n161 69\n2 5 8 11 12 13 17 18 23 25 28 29 30 33 34 35 36 38 39 44 45 49 52 53 56 57 58 60 62 70 71 74 76 77 82 83 86 90 94 95 97 104 105 108 109 112 113 118 120 123 126 127 132 135 137 139 140 141 142 143 144 146 147 148 151 152 153 154 161",
"output": "5"
},
{
"input": "1\n8 4\n1 2 3 7",
"output": "3"
},
{
"input": "1\n12 2\n5 12",
"output": "5"
},
{
"input": "1\n13 2\n6 12",
"output": "6"
},
{
"input": "1\n13 2\n8 13",
"output": "8"
},
{
"input": "1\n10 4\n1 2 3 5",
"output": "6"
},
{
"input": "1\n200 2\n50 150",
"output": "51"
},
{
"input": "1\n110 2\n1 110",
"output": "55"
}
] | 93 | 3,584,000 | -1 | 3,370 |
|
733 | Parade | [
"math"
] | null | null | Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.
There will be *n* columns participating in the parade, the *i*-th column consists of *l**i* soldiers, who start to march from left leg, and *r**i* soldiers, who start to march from right leg.
The beauty of the parade is calculated by the following formula: if *L* is the total number of soldiers on the parade who start to march from the left leg, and *R* is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |*L*<=-<=*R*|.
No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index *i* and swap values *l**i* and *r**i*.
Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty. | The first line contains single integer *n* (1<=β€<=*n*<=β€<=105)Β β the number of columns.
The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=β€<=*l**i*,<=*r**i*<=β€<=500)Β β the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively. | Print single integer *k*Β β the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to *n* in the order they are given in the input data.
If there are several answers, print any of them. | [
"3\n5 6\n8 9\n10 3\n",
"2\n6 5\n5 6\n",
"6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n"
] | [
"3\n",
"1\n",
"0\n"
] | In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5β+β8β+β10β=β23, and from the right legΒ β 6β+β9β+β3β=β18. In this case the beauty of the parade will equal |23β-β18|β=β5.
If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5β+β8β+β3β=β16, and who march from the right legΒ β 6β+β9β+β10β=β25. In this case the beauty equals |16β-β25|β=β9.
It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9. | [
{
"input": "3\n5 6\n8 9\n10 3",
"output": "3"
},
{
"input": "2\n6 5\n5 6",
"output": "1"
},
{
"input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32",
"output": "0"
},
{
"input": "2\n500 499\n500 500",
"output": "0"
},
{
"input": "1\n139 252",
"output": "0"
},
{
"input": "10\n18 18\n71 471\n121 362\n467 107\n138 254\n13 337\n499 373\n337 387\n147 417\n76 417",
"output": "4"
},
{
"input": "4\n4 1\n5 3\n7 6\n3 5",
"output": "4"
},
{
"input": "3\n6 5\n9 8\n3 10",
"output": "3"
},
{
"input": "3\n100 9\n1 3\n1 5",
"output": "1"
},
{
"input": "4\n10 1\n10 2\n10 3\n1 10",
"output": "4"
},
{
"input": "5\n25 1\n24 1\n2 3\n2 3\n2 3",
"output": "3"
},
{
"input": "3\n90 1\n1 90\n100 1",
"output": "2"
},
{
"input": "3\n1 123\n22 1\n12 1",
"output": "1"
},
{
"input": "3\n4 5\n7 6\n10 9",
"output": "1"
},
{
"input": "4\n50 1\n50 1\n50 1\n1 49",
"output": "4"
},
{
"input": "7\n2 1\n2 1\n2 1\n2 1\n1 200\n1 200\n1 200",
"output": "1"
},
{
"input": "5\n10 8\n7 6\n2 8\n9 1\n7 1",
"output": "3"
},
{
"input": "3\n22 1\n12 1\n1 123",
"output": "3"
},
{
"input": "3\n10 8\n9 7\n4 5",
"output": "3"
},
{
"input": "5\n1 2\n4 8\n4 8\n32 16\n128 64",
"output": "2"
},
{
"input": "5\n10 1\n10 1\n10 1\n100 1\n1 5",
"output": "5"
}
] | 1,000 | 10,240,000 | 0 | 3,371 |
|
809 | Do you want a date? | [
"implementation",
"math",
"sortings"
] | null | null | Leha decided to move to a quiet town ViΔkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in ViΔkopolis.
Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to *n*. So the *i*-th hacked computer is located at the point *x**i*. Moreover the coordinates of all computers are distinct.
Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task.
Leha should calculate a sum of *F*(*a*) for all *a*, where *a* is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote *A* the set of all integers from 1 to *n*. Noora asks the hacker to find value of the expression . Here *F*(*a*) is calculated as the maximum among the distances between all pairs of computers from the set *a*. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109<=+<=7.
Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date. | The first line contains one integer *n* (1<=β€<=*n*<=β€<=3Β·105) denoting the number of hacked computers.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=β€<=*x**i*<=β€<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct. | Print a single integerΒ β the required sum modulo 109<=+<=7. | [
"2\n4 7\n",
"3\n4 3 1\n"
] | [
"3\n",
"9\n"
] | There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c86b3e28ddb8aaca28a7cdd219a8c.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7d0f73b3e94e13cb797f39e93d9da74835c5a02d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7β-β4β=β3. In total the answer is 0β+β0β+β3β=β3.
There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f368c407c8e85e2b5fedfffaff39d471d765f026.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bb8f2118a3ac352db393b1f067b28e398ce7f816.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/049032074c04b16bc0cc153f95471c40b222072b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc93c7f5b3d122314c9c5a707fae556a8f72a574.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In total the sum is (4β-β3)β+β(4β-β1)β+β(3β-β1)β+β(4β-β1)β=β9. | [
{
"input": "2\n4 7",
"output": "3"
},
{
"input": "3\n4 3 1",
"output": "9"
},
{
"input": "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95",
"output": "83396599"
},
{
"input": "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73",
"output": "68059140"
},
{
"input": "20\n2 6 8 9 20 23 27 36 43 49 63 65 70 71 85 87 89 91 94 97",
"output": "92743989"
},
{
"input": "1\n78091781",
"output": "0"
},
{
"input": "2\n1000000000 1",
"output": "999999999"
},
{
"input": "3\n999999998 999999999 999999992",
"output": "21"
},
{
"input": "3\n465343471 465343474 465343473",
"output": "9"
},
{
"input": "10\n10 3 6 2 1 9 8 4 5 7",
"output": "7181"
},
{
"input": "10\n756734546 756734524 756734550 756734529 756734553 756734538 756734541 756734536 756734579 756734537",
"output": "36489"
},
{
"input": "10\n877105545 939360757 849826701 845946140 803128820 926787996 967305000 904694971 921301848 971203310",
"output": "861364152"
},
{
"input": "5\n4 7 13 17 18",
"output": "270"
},
{
"input": "5\n20 17 13 7 2",
"output": "330"
},
{
"input": "5\n3 17 2 5 4",
"output": "237"
},
{
"input": "5\n999999980 999999985 999999986 999999990 999999992",
"output": "210"
},
{
"input": "5\n1000000000 999999988 999999982 999999981 999999980",
"output": "342"
},
{
"input": "5\n999999984 999999997 999999994 999999991 999999982",
"output": "285"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "5\n9 10 7 4 5",
"output": "114"
}
] | 545 | 268,390,400 | 0 | 3,373 |
|
911 | Three Garlands | [
"brute force",
"constructive algorithms"
] | null | null | Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state β sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th second, then it is lit only during seconds *x*, *x*<=+<=*k**i*, *x*<=+<=2*k**i*, *x*<=+<=3*k**i* and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers *x*1, *x*2 and *x*3 (not necessarily distinct) so that he will switch on the first garland during *x*1-th second, the second one β during *x*2-th second, and the third one β during *x*3-th second, respectively, and during each second starting from *max*(*x*1,<=*x*2,<=*x*3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this! | The first line contains three integers *k*1, *k*2 and *k*3 (1<=β€<=*k**i*<=β€<=1500) β time intervals of the garlands. | If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO. | [
"2 2 3\n",
"4 2 3\n"
] | [
"YES\n",
"NO\n"
] | In the first example Mishka can choose *x*<sub class="lower-index">1</sub>β=β1, *x*<sub class="lower-index">2</sub>β=β2, *x*<sub class="lower-index">3</sub>β=β1. The first garland will be lit during seconds 1,β3,β5,β7,β..., the second β 2,β4,β6,β8,β..., which already cover all the seconds after the 2-nd one. It doesn't even matter what *x*<sub class="lower-index">3</sub> is chosen. Our choice will lead third to be lit during seconds 1,β4,β7,β10,β..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit. | [
{
"input": "2 2 3",
"output": "YES"
},
{
"input": "4 2 3",
"output": "NO"
},
{
"input": "1499 1498 1500",
"output": "NO"
},
{
"input": "1500 1500 1500",
"output": "NO"
},
{
"input": "100 4 1",
"output": "YES"
},
{
"input": "4 2 4",
"output": "YES"
},
{
"input": "3 3 3",
"output": "YES"
},
{
"input": "2 3 6",
"output": "NO"
},
{
"input": "2 3 3",
"output": "NO"
},
{
"input": "4 4 2",
"output": "YES"
},
{
"input": "1 1 1",
"output": "YES"
},
{
"input": "2 11 2",
"output": "YES"
},
{
"input": "4 4 4",
"output": "NO"
},
{
"input": "4 4 5",
"output": "NO"
},
{
"input": "3 3 2",
"output": "NO"
},
{
"input": "3 6 6",
"output": "NO"
},
{
"input": "2 3 2",
"output": "YES"
},
{
"input": "1 1 3",
"output": "YES"
},
{
"input": "3 3 4",
"output": "NO"
},
{
"input": "2 4 4",
"output": "YES"
},
{
"input": "2 2 2",
"output": "YES"
},
{
"input": "2 10 10",
"output": "NO"
},
{
"input": "3 4 4",
"output": "NO"
},
{
"input": "2 5 5",
"output": "NO"
},
{
"input": "2 4 5",
"output": "NO"
},
{
"input": "228 2 2",
"output": "YES"
},
{
"input": "2 998 1000",
"output": "NO"
},
{
"input": "2 6 6",
"output": "NO"
},
{
"input": "6 4 7",
"output": "NO"
},
{
"input": "2 5 2",
"output": "YES"
},
{
"input": "2 100 100",
"output": "NO"
},
{
"input": "7 7 2",
"output": "NO"
},
{
"input": "3 3 6",
"output": "NO"
},
{
"input": "82 3 82",
"output": "NO"
},
{
"input": "2 3 5",
"output": "NO"
},
{
"input": "1 218 924",
"output": "YES"
},
{
"input": "4 4 123",
"output": "NO"
},
{
"input": "4 4 3",
"output": "NO"
},
{
"input": "3 4 2",
"output": "NO"
},
{
"input": "2 2 5",
"output": "YES"
},
{
"input": "2 10 2",
"output": "YES"
},
{
"input": "5 2 2",
"output": "YES"
},
{
"input": "3 3 9",
"output": "NO"
},
{
"input": "1 5 5",
"output": "YES"
},
{
"input": "2 4 6",
"output": "NO"
},
{
"input": "15 3 3",
"output": "NO"
},
{
"input": "1 5 10",
"output": "YES"
},
{
"input": "2 3 14",
"output": "NO"
},
{
"input": "1265 2 593",
"output": "NO"
},
{
"input": "2 2 567",
"output": "YES"
},
{
"input": "1 6 5",
"output": "YES"
},
{
"input": "2 2 7",
"output": "YES"
},
{
"input": "2 2 1500",
"output": "YES"
},
{
"input": "3 6 9",
"output": "NO"
},
{
"input": "1 46 79",
"output": "YES"
},
{
"input": "4 3 3",
"output": "NO"
},
{
"input": "2 4 8",
"output": "NO"
},
{
"input": "1493 1489 1487",
"output": "NO"
},
{
"input": "1 2 3",
"output": "YES"
},
{
"input": "1 2 5",
"output": "YES"
},
{
"input": "1 2 8",
"output": "YES"
},
{
"input": "3 4 5",
"output": "NO"
},
{
"input": "2 2 4",
"output": "YES"
},
{
"input": "3 2 3",
"output": "NO"
},
{
"input": "7 2 2",
"output": "YES"
},
{
"input": "3 2 2",
"output": "YES"
},
{
"input": "6 7 4",
"output": "NO"
}
] | 61 | 5,632,000 | 0 | 3,377 |
|
216 | Forming Teams | [
"dfs and similar",
"implementation"
] | null | null | One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then student *B* is an archenemy to student *A*.
The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.
Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | The first line contains two integers *n* and *m* (2<=β€<=*n*<=β€<=100, 1<=β€<=*m*<=β€<=100) β the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*, *a**i*<=β <=*b**i*) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies.
You can consider the students indexed in some manner with distinct integers from 1 to *n*. | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | [
"5 4\n1 2\n2 4\n5 3\n1 4\n",
"6 2\n1 4\n3 4\n",
"6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n"
] | [
"1",
"0",
"2"
] | none | [
{
"input": "5 4\n1 2\n2 4\n5 3\n1 4",
"output": "1"
},
{
"input": "6 2\n1 4\n3 4",
"output": "0"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "2"
},
{
"input": "5 1\n1 2",
"output": "1"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1",
"output": "0"
},
{
"input": "28 3\n15 3\n10 19\n17 25",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "3 1\n2 3",
"output": "1"
},
{
"input": "3 2\n1 2\n3 2",
"output": "1"
},
{
"input": "3 3\n1 2\n1 3\n2 3",
"output": "1"
},
{
"input": "4 1\n1 4",
"output": "0"
},
{
"input": "4 2\n4 1\n2 1",
"output": "0"
},
{
"input": "4 3\n1 3\n3 2\n2 4",
"output": "0"
},
{
"input": "4 3\n3 2\n4 2\n4 3",
"output": "2"
},
{
"input": "5 3\n4 2\n3 4\n5 1",
"output": "1"
},
{
"input": "10 7\n8 9\n3 6\n2 4\n4 1\n1 3\n2 7\n7 10",
"output": "0"
},
{
"input": "29 20\n15 9\n21 15\n14 12\n12 16\n3 28\n5 13\n19 1\n19 21\n23 17\n27 9\n26 10\n20 5\n8 16\n11 6\n4 22\n29 22\n29 11\n14 17\n28 6\n1 23",
"output": "1"
},
{
"input": "68 50\n10 9\n28 25\n53 46\n38 32\n46 9\n35 13\n65 21\n64 1\n15 52\n43 52\n31 7\n61 67\n41 49\n30 1\n14 4\n17 44\n25 7\n24 31\n57 51\n27 12\n3 37\n17 11\n41 16\n65 23\n10 2\n16 22\n40 36\n15 51\n58 44\n61 2\n50 30\n48 35\n45 32\n56 59\n37 49\n62 55\n62 11\n6 19\n34 33\n53 66\n67 39\n47 21\n56 40\n12 58\n4 23\n26 42\n42 5\n60 8\n5 63\n6 47",
"output": "0"
},
{
"input": "89 30\n86 72\n43 16\n32 80\n17 79\n29 8\n89 37\n84 65\n3 41\n55 79\n33 56\n60 40\n43 45\n59 38\n26 23\n66 61\n81 30\n65 25\n13 71\n25 8\n56 59\n46 13\n22 30\n87 3\n26 32\n75 44\n48 87\n47 4\n63 21\n36 6\n42 86",
"output": "1"
},
{
"input": "100 1\n3 87",
"output": "0"
},
{
"input": "100 10\n88 82\n5 78\n66 31\n65 100\n92 25\n71 62\n47 31\n17 67\n69 68\n59 49",
"output": "0"
},
{
"input": "100 50\n82 99\n27 56\n74 38\n16 68\n90 27\n77 4\n7 88\n77 33\n25 85\n18 70\n50 7\n31 5\n21 20\n50 83\n55 5\n46 83\n55 81\n73 6\n76 58\n60 67\n66 99\n71 23\n100 13\n76 8\n52 14\n6 54\n53 54\n88 22\n12 4\n33 60\n43 62\n42 31\n19 67\n98 80\n15 17\n78 79\n62 37\n66 96\n40 44\n37 86\n71 58\n42 92\n8 38\n92 13\n73 70\n46 41\n30 34\n15 65\n97 19\n14 53",
"output": "0"
},
{
"input": "10 9\n5 10\n3 2\n8 6\n4 5\n4 10\n6 1\n1 8\n9 2\n3 9",
"output": "4"
},
{
"input": "50 48\n33 21\n1 46\n43 37\n1 48\n42 32\n31 45\n14 29\n34 28\n38 19\n46 48\n49 31\n8 3\n27 23\n26 37\n15 9\n27 17\n9 35\n18 7\n35 15\n32 4\n23 17\n36 22\n16 33\n39 6\n40 13\n11 6\n21 16\n10 40\n30 36\n20 5\n24 3\n43 26\n22 30\n41 20\n50 38\n25 29\n5 41\n34 44\n12 7\n8 24\n44 28\n25 14\n12 18\n39 11\n42 4\n45 49\n50 19\n13 10",
"output": "16"
},
{
"input": "19 16\n2 16\n7 10\n17 16\n17 14\n1 5\n19 6\n11 13\n15 19\n7 9\n13 5\n4 6\n1 11\n12 9\n10 12\n2 14\n4 15",
"output": "1"
},
{
"input": "70 70\n27 54\n45 23\n67 34\n66 25\n64 38\n30 68\n51 65\n19 4\n15 33\n47 14\n3 9\n42 29\n69 56\n10 50\n34 58\n51 23\n55 14\n18 53\n27 68\n17 6\n48 6\n8 5\n46 37\n37 33\n21 36\n69 24\n16 13\n50 12\n59 31\n63 38\n22 11\n46 28\n67 62\n63 26\n70 31\n7 59\n55 52\n28 43\n18 35\n53 3\n16 60\n43 40\n61 9\n20 44\n47 41\n35 1\n32 4\n13 54\n30 60\n45 19\n39 42\n2 20\n2 26\n52 8\n12 25\n5 41\n21 10\n58 48\n29 11\n7 56\n49 57\n65 32\n15 40\n66 36\n64 44\n22 57\n1 61\n39 49\n24 70\n62 17",
"output": "10"
},
{
"input": "33 33\n2 16\n28 20\n13 9\n4 22\n18 1\n6 12\n13 29\n32 1\n17 15\n10 7\n6 15\n16 5\n11 10\n31 29\n25 8\n23 21\n14 32\n8 2\n19 3\n11 4\n21 25\n31 30\n33 5\n26 7\n27 26\n27 12\n30 24\n33 17\n28 22\n18 24\n19 9\n3 23\n14 20",
"output": "1"
},
{
"input": "10 8\n8 3\n9 7\n6 1\n10 9\n2 6\n2 1\n3 4\n4 8",
"output": "2"
},
{
"input": "20 12\n16 20\n8 3\n20 5\n5 10\n17 7\n13 2\n18 9\n17 18\n1 6\n14 4\n11 12\n10 16",
"output": "0"
},
{
"input": "35 21\n15 3\n13 5\n2 28\n26 35\n9 10\n22 18\n17 1\n31 32\n35 33\n5 15\n14 24\n29 12\n16 2\n14 10\n7 4\n29 4\n23 27\n30 34\n19 26\n23 11\n25 21",
"output": "1"
},
{
"input": "49 36\n17 47\n19 27\n41 23\n31 27\n11 29\n34 10\n35 2\n42 24\n19 16\n38 24\n5 9\n26 9\n36 14\n18 47\n28 40\n45 13\n35 22\n2 15\n31 30\n20 48\n39 3\n8 34\n36 7\n25 17\n5 39\n29 1\n32 33\n16 30\n38 49\n25 18\n1 11\n7 44\n12 43\n15 22\n49 21\n8 23",
"output": "3"
},
{
"input": "77 54\n18 56\n72 2\n6 62\n58 52\n5 70\n24 4\n67 66\n65 47\n43 77\n61 66\n24 51\n70 7\n48 39\n46 11\n77 28\n65 76\n15 6\n22 13\n34 75\n33 42\n59 37\n7 31\n50 23\n28 9\n17 29\n1 14\n11 45\n36 46\n32 39\n59 21\n22 34\n53 21\n29 47\n16 44\n69 4\n62 16\n36 3\n68 75\n51 69\n49 43\n30 55\n40 20\n57 60\n45 3\n38 33\n49 9\n71 19\n73 20\n48 32\n63 67\n8 54\n42 38\n26 12\n5 74",
"output": "5"
},
{
"input": "93 72\n3 87\n88 60\n73 64\n45 35\n61 85\n68 80\n54 29\n4 88\n19 91\n82 48\n50 2\n40 53\n56 8\n66 82\n83 81\n62 8\n79 30\n89 26\n77 10\n65 15\n27 47\n15 51\n70 6\n59 85\n63 20\n64 92\n7 1\n93 52\n74 38\n71 23\n83 12\n86 52\n46 56\n34 36\n37 84\n18 16\n11 42\n69 72\n53 20\n78 84\n54 91\n14 5\n65 49\n90 19\n42 39\n68 57\n75 27\n57 32\n44 9\n79 74\n48 66\n43 93\n31 30\n58 24\n80 67\n6 60\n39 5\n23 17\n25 1\n18 36\n32 67\n10 9\n14 11\n63 21\n92 73\n13 43\n28 78\n33 51\n4 70\n75 45\n37 28\n62 46",
"output": "5"
},
{
"input": "100 72\n2 88\n55 80\n22 20\n78 52\n66 74\n91 82\n59 77\n97 93\n46 44\n99 35\n73 62\n58 24\n6 16\n47 41\n98 86\n23 19\n39 68\n32 28\n85 29\n37 40\n16 62\n19 61\n84 72\n17 15\n76 96\n37 31\n67 35\n48 15\n80 85\n90 47\n79 36\n39 54\n57 87\n42 60\n34 56\n23 61\n92 2\n88 63\n20 42\n27 81\n65 84\n6 73\n64 100\n76 95\n43 4\n65 86\n21 46\n11 64\n72 98\n63 92\n7 50\n14 22\n89 30\n31 40\n8 57\n90 70\n53 59\n69 24\n96 49\n67 99\n51 70\n18 66\n91 3\n26 38\n13 58\n51 41\n9 11\n5 74\n3 25\n4 32\n28 43\n71 56",
"output": "6"
},
{
"input": "6 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "2"
},
{
"input": "6 4\n1 2\n1 3\n4 5\n4 6",
"output": "0"
},
{
"input": "16 16\n1 2\n2 3\n1 3\n4 5\n5 6\n4 6\n7 8\n8 9\n9 10\n10 11\n11 7\n12 13\n13 14\n14 15\n15 16\n16 12",
"output": "4"
},
{
"input": "4 4\n1 2\n4 3\n1 4\n2 3",
"output": "0"
},
{
"input": "9 9\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n7 8\n8 9\n9 7",
"output": "3"
},
{
"input": "20 11\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 1",
"output": "2"
},
{
"input": "4 3\n1 2\n3 4\n1 3",
"output": "0"
},
{
"input": "4 2\n2 4\n3 4",
"output": "0"
},
{
"input": "10 10\n1 2\n2 3\n3 4\n4 5\n5 1\n6 7\n7 8\n8 9\n9 10\n10 6",
"output": "2"
},
{
"input": "6 5\n2 1\n3 4\n2 3\n4 5\n5 6",
"output": "0"
},
{
"input": "8 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "2"
},
{
"input": "6 5\n1 2\n2 3\n3 4\n4 5\n1 5",
"output": "2"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n1 4\n5 6\n6 7\n7 8\n5 8",
"output": "0"
},
{
"input": "6 5\n1 3\n1 2\n2 4\n5 3\n5 4",
"output": "2"
}
] | 810 | 31,539,200 | 0 | 3,379 |
|
702 | Cellular Network | [
"binary search",
"implementation",
"two pointers"
] | null | null | You are given *n* points on the straight line β the positions (*x*-coordinates) of the cities and *m* points on the same line β the positions (*x*-coordinates) of the cellular towers. All towers work in the same way β they provide cellular network for all cities, which are located at the distance which is no more than *r* from this tower.
Your task is to find minimal *r* that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than *r*.
If *r*<==<=0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than *r* from this tower. | The first line contains two positive integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=105) β the number of cities and the number of cellular towers.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=β€<=*a**i*<=β€<=109) β the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates *a**i* are given in non-decreasing order.
The third line contains a sequence of *m* integers *b*1,<=*b*2,<=...,<=*b**m* (<=-<=109<=β€<=*b**j*<=β€<=109) β the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates *b**j* are given in non-decreasing order. | Print minimal *r* so that each city will be covered by cellular network. | [
"3 2\n-2 2 4\n-3 0\n",
"5 3\n1 5 10 14 17\n4 11 15\n"
] | [
"4\n",
"3\n"
] | none | [
{
"input": "3 2\n-2 2 4\n-3 0",
"output": "4"
},
{
"input": "5 3\n1 5 10 14 17\n4 11 15",
"output": "3"
},
{
"input": "1 1\n-1000000000\n1000000000",
"output": "2000000000"
},
{
"input": "1 1\n1000000000\n-1000000000",
"output": "2000000000"
},
{
"input": "10 10\n1 1 2 2 2 4 4 6 7 9\n0 1 3 3 3 6 7 8 9 10",
"output": "1"
},
{
"input": "10 10\n2 52 280 401 416 499 721 791 841 943\n246 348 447 486 507 566 568 633 953 986",
"output": "244"
},
{
"input": "7 7\n1 2 3 3 4 5 6\n1 1 2 3 4 5 6",
"output": "0"
},
{
"input": "1 3\n-3\n-1 -1 8",
"output": "2"
},
{
"input": "1 2\n8\n-7 5",
"output": "3"
},
{
"input": "2 1\n4 8\n-1",
"output": "9"
},
{
"input": "1 2\n6\n-8 -8",
"output": "14"
},
{
"input": "1 4\n4\n-8 0 1 7",
"output": "3"
},
{
"input": "1 2\n2\n4 7",
"output": "2"
},
{
"input": "2 2\n-5 2\n-7 4",
"output": "2"
},
{
"input": "1 21\n3\n3 10 23 32 34 40 42 49 49 50 50 58 70 71 71 74 76 79 79 80 83",
"output": "0"
},
{
"input": "1 3\n-4\n-8 -1 1",
"output": "3"
},
{
"input": "4 1\n-6 -3 -1 2\n-7",
"output": "9"
},
{
"input": "2 3\n-2 7\n-7 -2 5",
"output": "2"
},
{
"input": "1 1\n-1\n0",
"output": "1"
},
{
"input": "1 3\n0\n-4 0 5",
"output": "0"
}
] | 31 | 0 | -1 | 3,382 |
|
221 | Little Elephant and Numbers | [
"implementation"
] | null | null | The Little Elephant loves numbers.
He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations.
Help the Little Elephant to find the described number. | A single line contains a single integer *x* (1<=β€<=*x*<=β€<=109). | In a single line print an integer β the answer to the problem. | [
"1\n",
"10\n"
] | [
"1\n",
"2\n"
] | none | [
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "47",
"output": "1"
},
{
"input": "100",
"output": "5"
},
{
"input": "128",
"output": "6"
},
{
"input": "2",
"output": "1"
},
{
"input": "17",
"output": "2"
},
{
"input": "1000000",
"output": "41"
},
{
"input": "1000000000",
"output": "91"
},
{
"input": "4584725",
"output": "5"
},
{
"input": "999999999",
"output": "6"
},
{
"input": "9",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "20",
"output": "3"
},
{
"input": "24",
"output": "4"
},
{
"input": "48",
"output": "4"
},
{
"input": "2458450",
"output": "11"
},
{
"input": "97648850",
"output": "44"
},
{
"input": "96488450",
"output": "21"
},
{
"input": "879541",
"output": "7"
},
{
"input": "111111111",
"output": "5"
},
{
"input": "222222222",
"output": "6"
},
{
"input": "777777777",
"output": "9"
},
{
"input": "211768200",
"output": "244"
},
{
"input": "536870912",
"output": "29"
},
{
"input": "654885000",
"output": "698"
},
{
"input": "223092870",
"output": "479"
},
{
"input": "901800900",
"output": "639"
},
{
"input": "101871000",
"output": "460"
},
{
"input": "49",
"output": "1"
},
{
"input": "999999993",
"output": "5"
},
{
"input": "999999666",
"output": "8"
},
{
"input": "999999997",
"output": "6"
},
{
"input": "960690025",
"output": "8"
},
{
"input": "16",
"output": "2"
},
{
"input": "999000011",
"output": "2"
},
{
"input": "999999937",
"output": "1"
},
{
"input": "999999998",
"output": "6"
}
] | 248 | 21,606,400 | 3 | 3,394 |
|
811 | Vladik and Memorable Trip | [
"dp",
"implementation"
] | null | null | Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now *n* people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code *a**i* is known (the code of the city in which they are going to).
Train chief selects some number of disjoint segments of the original sequence of people (covering entire sequence by segments is not necessary). People who are in the same segment will be in the same train carriage. The segments are selected in such way that if at least one person travels to the city *x*, then all people who are going to city *x* should be in the same railway carriage. This means that they canβt belong to different segments. Note, that all people who travel to the city *x*, either go to it and in the same railway carriage, or do not go anywhere at all.
Comfort of a train trip with people on segment from position *l* to position *r* is equal to XOR of all distinct codes of cities for people on the segment from position *l* to position *r*. XOR operation also known as exclusive OR.
Total comfort of a train trip is equal to sum of comfort for each segment.
Help Vladik to know maximal possible total comfort. | First line contains single integer *n* (1<=β€<=*n*<=β€<=5000)Β β number of people.
Second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=5000), where *a**i* denotes code of the city to which *i*-th person is going. | The output should contain a single integerΒ β maximal possible total comfort. | [
"6\n4 4 2 5 2 3\n",
"9\n5 1 3 1 5 2 4 2 5\n"
] | [
"14\n",
"9\n"
] | In the first test case best partition into segments is: [4,β4] [2,β5,β2] [3], answer is calculated as follows: 4β+β(2 *xor* 5)β+β3β=β4β+β7β+β3β=β14
In the second test case best partition into segments is: 5 1 [3] 1 5 [2,β4,β2] 5, answer calculated as follows: 3β+β(2 *xor* 4)β=β3β+β6β=β9. | [
{
"input": "6\n4 4 2 5 2 3",
"output": "14"
},
{
"input": "9\n5 1 3 1 5 2 4 2 5",
"output": "9"
},
{
"input": "5\n1558 4081 3591 1700 3232",
"output": "14162"
},
{
"input": "10\n3838 1368 4825 2068 4755 2048 1342 4909 2837 4854",
"output": "32844"
},
{
"input": "10\n4764 4867 2346 1449 1063 2002 2577 2089 1566 614",
"output": "23337"
},
{
"input": "10\n689 3996 3974 4778 1740 3481 2916 2744 294 1376",
"output": "25988"
},
{
"input": "100\n1628 4511 4814 3756 4625 1254 906 1033 2420 2622 2640 3225 3570 2925 465 2093 4614 2856 4004 4254 2292 2026 415 2777 905 4452 4737 529 4571 3221 2064 2495 420 1291 493 4073 3207 1217 3463 3047 3627 1783 1723 3586 800 2403 4378 4373 535 64 4014 346 2597 2502 3667 2904 3153 1061 3104 1847 4741 315 1212 501 4504 3947 842 2388 2868 3430 1018 560 2840 4477 2903 2810 3600 4352 1106 1102 4747 433 629 2043 1669 2695 436 403 650 530 1318 1348 4677 3245 2426 1056 702 203 1132 4471",
"output": "238706"
},
{
"input": "100\n2554 1060 1441 4663 301 3629 1245 3214 4623 4909 4283 1596 959 687 2981 1105 122 3820 3205 488 3755 2998 3243 3621 2707 3771 1302 2611 4545 2737 762 173 2513 2204 2433 4483 3095 2620 3265 4215 3085 947 425 144 659 1660 3295 2315 2281 2617 1887 2931 3494 2762 559 3690 3590 3826 3438 2203 101 1316 3688 3532 819 1069 2573 3127 3894 169 547 1305 2085 4753 4292 2116 1623 960 4809 3694 1047 501 1193 4987 1179 1470 647 113 4223 2154 3222 246 3321 1276 2340 1561 4477 665 2256 626",
"output": "233722"
},
{
"input": "100\n931 4584 2116 3004 3813 62 2819 2998 2080 4906 3198 2443 2952 3793 1958 3864 3985 3169 3134 4011 4525 995 4163 308 4362 1148 4906 3092 1647 244 1370 1424 2753 84 2997 1197 2606 425 3501 2606 683 4747 3884 4787 2166 3017 3080 4303 3352 1667 2636 3994 757 2388 870 1788 988 1303 0 1230 1455 4213 2113 2908 871 1997 3878 4604 1575 3385 236 847 2524 3937 1803 2678 4619 1125 3108 1456 3017 1532 3845 3293 2355 2230 4282 2586 2892 4506 3132 4570 1872 2339 2166 3467 3080 2693 1925 2308",
"output": "227685"
},
{
"input": "100\n5 1085 489 2096 1610 108 4005 3869 1826 4145 2450 2546 2719 1030 4443 4222 1 2205 2407 4303 4588 1549 1965 4465 2560 2459 1814 1641 148 728 3566 271 2186 696 1952 4262 2088 4023 4594 1437 4700 2531 1707 1702 1413 4391 4162 3309 1606 4116 1287 1410 3336 2128 3978 1002 552 64 1192 4980 4569 3212 1163 2457 3661 2296 2147 391 550 2540 707 101 4805 2608 4785 4898 1595 1043 4406 3865 1716 4044 1756 4456 1319 4350 4965 2876 4320 4409 3177 671 2596 4308 2253 2962 830 4179 800 1782",
"output": "251690"
},
{
"input": "100\n702 1907 2292 1953 2421 1300 2092 1904 3691 1861 4472 1379 1811 2583 529 3977 4735 997 856 4545 2354 2581 1692 2563 4104 763 1645 4080 3967 3705 4261 448 4854 1903 4449 2768 4214 4815 185 3404 3538 199 4548 4608 46 4673 4406 3379 3790 3567 1139 1236 2755 2242 3723 2118 2716 4824 2770 595 274 840 261 1576 3188 2720 637 4071 2737 2585 4964 4184 120 1622 884 1555 4681 4269 2404 3511 4972 3840 66 4100 1528 1340 1119 2641 1183 3908 1363 28 401 4319 3408 2077 3454 1689 8 3946",
"output": "254107"
},
{
"input": "100\n4 3 5 5 2 0 4 0 1 5 1 2 5 5 2 0 2 3 0 0 0 5 4 4 3 0 5 5 4 0 4 4 1 2 0 4 3 5 4 3 5 1 1 0 0 4 2 0 5 0 1 5 3 3 4 5 1 2 2 5 0 3 3 1 2 0 1 3 0 4 5 4 4 1 5 3 0 2 3 4 1 5 5 0 5 0 0 3 2 1 4 3 4 1 4 5 3 0 5 3",
"output": "1"
},
{
"input": "100\n0 0 0 0 0 1 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 0 1 1 0",
"output": "1"
},
{
"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\n5 1 12 15 10 0 5 7 12 13 3 11 13 10 0 5 3 1 3 13 1 11 2 6 9 15 8 3 13 3 0 4 11 10 12 10 9 3 13 15 10 11 7 10 1 15 0 7 7 8 12 2 5 2 4 11 7 1 16 14 10 6 14 2 4 15 10 8 6 10 2 7 5 15 9 8 15 6 7 1 5 7 1 15 9 11 2 0 8 12 8 9 4 7 11 2 5 13 12 8",
"output": "16"
},
{
"input": "100\n8 16 16 2 5 7 9 12 14 15 5 11 0 5 9 12 15 13 4 15 10 11 13 2 2 15 15 16 10 7 4 14 9 5 4 10 4 16 2 6 11 0 3 14 12 14 9 5 0 8 11 15 2 14 2 0 3 5 4 4 8 15 14 6 14 5 0 14 12 15 0 15 15 14 2 14 13 7 11 7 2 4 13 11 8 16 9 1 10 13 8 2 7 12 1 14 16 11 15 7",
"output": "16"
},
{
"input": "100\n4 9 4 13 18 17 13 10 28 11 29 32 5 23 14 32 20 17 25 0 18 30 10 17 27 2 13 8 1 20 8 13 6 5 16 1 27 27 24 16 2 18 24 1 0 23 10 21 7 3 21 21 18 27 31 28 10 17 26 27 3 0 6 0 30 9 3 0 3 30 8 3 23 21 18 27 10 16 30 4 1 9 3 8 2 5 20 23 16 22 9 7 11 9 12 30 17 27 14 17",
"output": "145"
},
{
"input": "100\n6 25 23 14 19 5 26 28 5 14 24 2 19 32 4 12 32 12 9 29 23 10 25 31 29 10 3 30 29 13 32 27 13 19 2 24 30 8 11 5 25 32 13 9 28 28 27 1 8 24 15 11 8 6 30 16 29 13 6 11 3 0 8 2 6 9 29 26 11 30 7 21 16 31 23 3 29 18 26 9 26 15 0 31 19 0 0 21 24 15 0 5 19 21 18 32 32 29 5 32",
"output": "51"
},
{
"input": "100\n11 4 31 11 59 23 62 21 49 40 21 1 56 51 22 53 37 28 43 27 15 39 39 33 3 28 60 52 58 21 16 11 10 61 26 59 23 51 26 32 40 21 43 56 55 0 44 48 16 7 26 37 61 19 44 15 63 11 58 62 48 14 38 3 27 50 47 6 46 23 50 16 64 19 45 18 15 30 20 45 50 61 50 57 38 60 61 46 42 39 22 52 7 36 57 23 33 46 29 6",
"output": "598"
},
{
"input": "100\n60 30 6 15 23 15 25 34 55 53 27 23 51 4 47 61 57 62 44 22 18 42 33 29 50 37 62 28 16 4 52 37 33 58 39 36 17 21 59 59 28 26 35 15 37 13 35 29 29 8 56 26 23 18 10 1 3 61 30 11 50 42 48 11 17 47 26 10 46 49 9 29 4 28 40 12 62 33 8 13 26 52 40 30 34 40 40 27 55 42 15 53 53 5 12 47 21 9 23 25",
"output": "656"
},
{
"input": "100\n10 19 72 36 30 38 116 112 65 122 74 62 104 82 64 52 119 109 2 86 114 105 56 12 3 52 35 48 99 68 98 18 68 117 7 76 112 2 57 39 43 2 93 45 1 128 112 90 21 91 61 6 4 53 83 72 120 72 82 111 108 48 12 83 70 78 116 33 22 102 59 31 72 111 33 6 19 91 30 108 110 22 10 93 55 92 20 20 98 10 119 58 17 60 33 4 29 110 127 100",
"output": "2946"
},
{
"input": "100\n83 54 28 107 75 48 55 68 7 33 31 124 22 54 24 83 8 3 10 58 39 106 50 110 17 91 119 87 126 29 40 4 50 44 78 49 41 79 82 6 34 61 80 19 113 67 104 50 15 60 65 97 118 7 48 64 81 5 23 105 64 122 95 25 97 124 97 33 61 20 89 77 24 9 20 84 30 69 12 3 50 122 75 106 41 19 126 112 10 91 42 11 66 20 74 16 120 70 52 43",
"output": "3126"
},
{
"input": "100\n915 7 282 162 24 550 851 240 39 302 538 76 131 150 104 848 507 842 32 453 998 990 1002 225 887 1005 259 199 873 87 258 318 837 511 663 1008 861 516 445 426 335 743 672 345 320 461 650 649 612 9 1017 113 169 722 643 253 562 661 879 522 524 878 600 894 312 1005 283 911 322 509 836 261 424 976 68 606 661 331 830 177 279 772 573 1017 157 250 42 478 582 23 847 119 359 198 839 761 54 1003 270 900",
"output": "45323"
},
{
"input": "100\n139 827 953 669 78 369 980 770 945 509 878 791 550 555 324 682 858 771 525 673 751 746 848 534 573 613 930 135 390 958 60 614 728 444 1018 463 445 662 632 907 536 865 465 974 137 973 386 843 326 314 555 910 258 429 560 559 274 307 409 751 527 724 485 276 18 45 1014 13 321 693 910 397 664 513 110 915 622 76 433 84 704 975 653 716 292 614 218 50 482 620 410 557 862 388 348 1022 663 580 987 149",
"output": "50598"
},
{
"input": "100\n2015 1414 748 1709 110 1094 441 1934 273 1796 451 902 610 914 1613 255 1838 963 1301 1999 393 948 161 510 485 1544 1742 19 12 1036 2007 1394 1898 532 1403 1390 2004 1016 45 675 1264 1696 1511 1523 1335 1997 688 1778 1939 521 222 92 1014 155 135 30 543 1449 229 976 382 654 1827 1158 570 64 1353 1672 295 1573 23 1368 728 597 1263 213 991 1673 1360 183 1256 1539 459 1480 374 1779 1541 858 1470 653 979 342 381 179 388 247 655 198 1762 1249",
"output": "96427"
},
{
"input": "100\n1928 445 1218 1164 1501 1284 973 1503 1132 1999 2046 1259 1604 1279 1044 684 89 733 1431 1133 1141 1954 181 76 997 187 1088 1265 1721 2039 1724 1986 308 402 1777 751 97 484 880 14 936 876 1226 1105 110 1587 588 363 169 296 1087 1490 1640 1378 433 1684 293 153 492 2040 1229 1754 950 1573 771 1052 366 382 88 186 1340 1212 1195 2005 36 2001 248 72 1309 1371 1381 653 1972 1503 571 1490 278 1590 288 183 949 361 1162 639 2003 1271 254 796 987 159",
"output": "93111"
},
{
"input": "100\n3108 2117 3974 3127 3122 796 1234 1269 1723 3313 3522 869 3046 557 334 3085 557 2528 1028 169 2203 595 388 2435 408 2712 2363 2088 2064 1185 3076 2073 2717 492 775 3351 3538 3050 85 3495 2335 1124 2891 3108 284 1123 500 502 808 3352 3988 1318 222 3452 3896 1024 2789 2480 1958 2976 1358 1225 3007 1817 1672 3667 1511 1147 2803 2632 3439 3066 3864 1942 2526 3574 1179 3375 406 782 3866 3157 3396 245 2401 2378 1258 684 2400 2809 3375 1225 1345 3630 2760 2546 1761 3138 2539 1616",
"output": "194223"
},
{
"input": "100\n1599 2642 1471 2093 3813 329 2165 254 3322 629 3286 2332 279 3756 1167 2607 2499 2411 2626 4040 2406 3468 1617 118 2083 2789 1571 333 1815 2600 2579 572 3193 249 1880 2226 1722 1771 3475 4038 951 2942 1135 3348 2785 1947 1937 108 3861 307 3052 2060 50 837 1107 2383 2633 2280 1122 1726 2800 522 714 2322 661 554 2444 3534 1440 2229 718 3311 1834 462 2348 3444 692 17 2866 347 2655 58 483 2298 1074 2163 3007 1858 2435 998 1506 707 1287 3821 2486 1496 3819 3529 1310 3926",
"output": "194571"
}
] | 30 | 0 | 0 | 3,396 |
|
567 | Berland National Library | [
"implementation"
] | null | null | Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.
Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library β it's a unique integer from 1 to 106. Thus, the system logs events of two forms:
- "+ *r**i*" β the reader with registration number *r**i* entered the room; - "- *r**i*" β the reader with registration number *r**i* left the room.
The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.
Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.
Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you. | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=100) β the number of records in the system log. Next follow *n* events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ *r**i*" or "- *r**i*", where *r**i* is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers).
It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors. | Print a single integer β the minimum possible capacity of the reading room. | [
"6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7\n",
"2\n- 1\n- 2\n",
"2\n+ 1\n- 1\n"
] | [
"3",
"2",
"1"
] | In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3. | [
{
"input": "6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7",
"output": "3"
},
{
"input": "2\n- 1\n- 2",
"output": "2"
},
{
"input": "2\n+ 1\n- 1",
"output": "1"
},
{
"input": "5\n+ 1\n- 1\n+ 2\n+ 3\n- 4",
"output": "3"
},
{
"input": "3\n- 1\n- 2\n- 3",
"output": "3"
},
{
"input": "4\n+ 1\n+ 2\n- 1\n+ 3",
"output": "2"
},
{
"input": "6\n+ 1\n+ 2\n- 1\n+ 3\n- 2\n+ 4",
"output": "2"
},
{
"input": "3\n+ 1\n+ 2\n- 3",
"output": "3"
},
{
"input": "3\n- 1\n+ 2\n- 2",
"output": "1"
},
{
"input": "4\n- 1\n- 2\n+ 3\n+ 4",
"output": "2"
},
{
"input": "1\n+ 1",
"output": "1"
},
{
"input": "1\n- 1",
"output": "1"
},
{
"input": "3\n- 1\n+ 1\n- 1",
"output": "1"
},
{
"input": "10\n+ 1\n+ 2\n+ 3\n+ 4\n+ 5\n+ 6\n+ 7\n+ 8\n+ 9\n+ 10",
"output": "10"
},
{
"input": "5\n+ 5\n+ 4\n- 4\n- 5\n+ 5",
"output": "2"
},
{
"input": "50\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100\n+ 100\n- 100",
"output": "1"
},
{
"input": "10\n- 8\n- 4\n+ 8\n+ 10\n+ 6\n- 8\n+ 9\n- 2\n- 7\n+ 4",
"output": "5"
},
{
"input": "20\n+ 3\n- 3\n- 2\n+ 2\n+ 3\n- 5\n- 1\n+ 1\n- 3\n+ 4\n- 1\n+ 1\n+ 3\n- 3\n+ 5\n- 2\n- 1\n+ 2\n+ 1\n- 5",
"output": "4"
},
{
"input": "50\n+ 4\n+ 5\n+ 3\n+ 2\n- 2\n- 3\n- 4\n+ 3\n+ 2\n- 3\n+ 4\n- 2\n- 4\n+ 2\n+ 3\n- 3\n- 5\n- 1\n+ 4\n+ 5\n- 5\n+ 3\n- 4\n- 3\n- 2\n+ 4\n+ 3\n+ 2\n- 2\n- 4\n+ 5\n+ 1\n+ 4\n+ 2\n- 2\n+ 2\n- 3\n- 5\n- 4\n- 1\n+ 5\n- 2\n- 5\n+ 5\n+ 3\n- 3\n+ 1\n+ 3\n+ 2\n- 1",
"output": "5"
},
{
"input": "10\n- 2\n+ 1\n- 1\n+ 2\n- 2\n+ 2\n+ 1\n- 1\n- 2\n+ 1",
"output": "2"
},
{
"input": "50\n+ 1\n+ 2\n+ 3\n+ 4\n+ 5\n+ 6\n+ 7\n+ 8\n+ 9\n+ 10\n+ 11\n+ 12\n+ 13\n+ 14\n+ 15\n+ 16\n+ 17\n+ 18\n+ 19\n+ 20\n+ 21\n+ 22\n+ 23\n+ 24\n+ 25\n+ 26\n+ 27\n+ 28\n+ 29\n+ 30\n+ 31\n+ 32\n+ 33\n+ 34\n+ 35\n+ 36\n+ 37\n+ 38\n+ 39\n+ 40\n+ 41\n+ 42\n+ 43\n+ 44\n+ 45\n+ 46\n+ 47\n+ 48\n+ 49\n+ 50",
"output": "50"
},
{
"input": "50\n- 1\n- 2\n- 3\n- 4\n- 5\n- 6\n- 7\n- 8\n- 9\n- 10\n- 11\n- 12\n- 13\n- 14\n- 15\n- 16\n- 17\n- 18\n- 19\n- 20\n- 21\n- 22\n- 23\n- 24\n- 25\n- 26\n- 27\n- 28\n- 29\n- 30\n- 31\n- 32\n- 33\n- 34\n- 35\n- 36\n- 37\n- 38\n- 39\n- 40\n- 41\n- 42\n- 43\n- 44\n- 45\n- 46\n- 47\n- 48\n- 49\n- 50",
"output": "50"
}
] | 46 | 102,400 | 0 | 3,411 |
|
746 | Compote | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruitsΒ β lemons, apples and pearsΒ β should be put in the compote as whole fruits.
Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. | The first line contains the positive integer *a* (1<=β€<=*a*<=β€<=1000)Β β the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=β€<=*b*<=β€<=1000)Β β the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=β€<=*c*<=β€<=1000)Β β the number of pears Nikolay has. | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1β+β2β+β4β=β7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3β+β6β+β12β=β21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
},
{
"input": "1\n1\n4",
"output": "0"
},
{
"input": "1\n2\n3",
"output": "0"
},
{
"input": "1\n1000\n1000",
"output": "7"
},
{
"input": "1000\n1\n1000",
"output": "0"
},
{
"input": "1000\n2\n1000",
"output": "7"
},
{
"input": "1000\n500\n1000",
"output": "1750"
},
{
"input": "1000\n1000\n4",
"output": "7"
},
{
"input": "1000\n1000\n3",
"output": "0"
},
{
"input": "4\n8\n12",
"output": "21"
},
{
"input": "10\n20\n40",
"output": "70"
},
{
"input": "100\n200\n399",
"output": "693"
},
{
"input": "200\n400\n800",
"output": "1400"
},
{
"input": "199\n400\n800",
"output": "1393"
},
{
"input": "201\n400\n800",
"output": "1400"
},
{
"input": "200\n399\n800",
"output": "1393"
},
{
"input": "200\n401\n800",
"output": "1400"
},
{
"input": "200\n400\n799",
"output": "1393"
},
{
"input": "200\n400\n801",
"output": "1400"
},
{
"input": "139\n252\n871",
"output": "882"
},
{
"input": "109\n346\n811",
"output": "763"
},
{
"input": "237\n487\n517",
"output": "903"
},
{
"input": "161\n331\n725",
"output": "1127"
},
{
"input": "39\n471\n665",
"output": "273"
},
{
"input": "9\n270\n879",
"output": "63"
},
{
"input": "137\n422\n812",
"output": "959"
},
{
"input": "15\n313\n525",
"output": "105"
},
{
"input": "189\n407\n966",
"output": "1323"
},
{
"input": "18\n268\n538",
"output": "126"
},
{
"input": "146\n421\n978",
"output": "1022"
},
{
"input": "70\n311\n685",
"output": "490"
},
{
"input": "244\n405\n625",
"output": "1092"
},
{
"input": "168\n454\n832",
"output": "1176"
},
{
"input": "46\n344\n772",
"output": "322"
},
{
"input": "174\n438\n987",
"output": "1218"
},
{
"input": "144\n387\n693",
"output": "1008"
},
{
"input": "22\n481\n633",
"output": "154"
},
{
"input": "196\n280\n848",
"output": "980"
},
{
"input": "190\n454\n699",
"output": "1218"
},
{
"input": "231\n464\n928",
"output": "1617"
},
{
"input": "151\n308\n616",
"output": "1057"
},
{
"input": "88\n182\n364",
"output": "616"
},
{
"input": "12\n26\n52",
"output": "84"
},
{
"input": "204\n412\n824",
"output": "1428"
},
{
"input": "127\n256\n512",
"output": "889"
},
{
"input": "224\n446\n896",
"output": "1561"
},
{
"input": "146\n291\n584",
"output": "1015"
},
{
"input": "83\n164\n332",
"output": "574"
},
{
"input": "20\n38\n80",
"output": "133"
},
{
"input": "198\n393\n792",
"output": "1372"
},
{
"input": "120\n239\n480",
"output": "833"
},
{
"input": "208\n416\n831",
"output": "1449"
},
{
"input": "130\n260\n517",
"output": "903"
},
{
"input": "67\n134\n267",
"output": "462"
},
{
"input": "245\n490\n979",
"output": "1708"
},
{
"input": "182\n364\n727",
"output": "1267"
},
{
"input": "104\n208\n413",
"output": "721"
},
{
"input": "10\n2\n100",
"output": "7"
},
{
"input": "2\n100\n100",
"output": "14"
},
{
"input": "2\n3\n8",
"output": "7"
},
{
"input": "1\n2\n8",
"output": "7"
},
{
"input": "1\n2\n200",
"output": "7"
},
{
"input": "5\n4\n16",
"output": "14"
},
{
"input": "1\n10\n10",
"output": "7"
},
{
"input": "1\n4\n8",
"output": "7"
},
{
"input": "100\n4\n1000",
"output": "14"
},
{
"input": "2\n6\n12",
"output": "14"
},
{
"input": "10\n7\n4",
"output": "7"
},
{
"input": "2\n10\n100",
"output": "14"
},
{
"input": "2\n3\n4",
"output": "7"
},
{
"input": "1\n2\n999",
"output": "7"
},
{
"input": "1\n10\n20",
"output": "7"
},
{
"input": "100\n18\n20",
"output": "35"
},
{
"input": "100\n1\n100",
"output": "0"
},
{
"input": "3\n7\n80",
"output": "21"
},
{
"input": "2\n8\n24",
"output": "14"
},
{
"input": "1\n100\n100",
"output": "7"
},
{
"input": "2\n1\n8",
"output": "0"
},
{
"input": "10\n5\n23",
"output": "14"
}
] | 77 | 6,758,400 | 3 | 3,414 |
|
0 | none | [
"none"
] | null | null | Ivan had string *s* consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string *s*. Ivan preferred making a new string to finding the old one.
Ivan knows some information about the string *s*. Namely, he remembers, that string *t**i* occurs in string *s* at least *k**i* times or more, he also remembers exactly *k**i* positions where the string *t**i* occurs in string *s*: these positions are *x**i*,<=1,<=*x**i*,<=2,<=...,<=*x**i*,<=*k**i*. He remembers *n* such strings *t**i*.
You are to reconstruct lexicographically minimal string *s* such that it fits all the information Ivan remembers. Strings *t**i* and string *s* consist of small English letters only. | The first line contains single integer *n* (1<=β€<=*n*<=β€<=105) β the number of strings Ivan remembers.
The next *n* lines contain information about the strings. The *i*-th of these lines contains non-empty string *t**i*, then positive integer *k**i*, which equal to the number of times the string *t**i* occurs in string *s*, and then *k**i* distinct positive integers *x**i*,<=1,<=*x**i*,<=2,<=...,<=*x**i*,<=*k**i* in increasing order β positions, in which occurrences of the string *t**i* in the string *s* start. It is guaranteed that the sum of lengths of strings *t**i* doesn't exceed 106, 1<=β€<=*x**i*,<=*j*<=β€<=106, 1<=β€<=*k**i*<=β€<=106, and the sum of all *k**i* doesn't exceed 106. The strings *t**i* can coincide.
It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists. | Print lexicographically minimal string that fits all the information Ivan remembers. | [
"3\na 4 1 3 5 7\nab 2 1 5\nca 1 4\n",
"1\na 1 3\n",
"3\nab 1 1\naba 1 3\nab 2 3 5\n"
] | [
"abacaba\n",
"aaa\n",
"ababab\n"
] | none | [
{
"input": "3\na 4 1 3 5 7\nab 2 1 5\nca 1 4",
"output": "abacaba"
},
{
"input": "1\na 1 3",
"output": "aaa"
},
{
"input": "3\nab 1 1\naba 1 3\nab 2 3 5",
"output": "ababab"
},
{
"input": "6\nba 2 16 18\na 1 12\nb 3 4 13 20\nbb 2 6 8\nababbbbbaab 1 3\nabababbbbb 1 1",
"output": "abababbbbbaabaababab"
},
{
"input": "17\na 4 2 7 8 9\nbbaa 1 5\nba 2 1 6\naa 2 7 8\nb 6 1 3 4 5 6 10\nbbbaa 1 4\nbbba 1 4\nbab 1 1\nbba 1 5\nbbb 2 3 4\nbb 3 3 4 5\nab 1 2\nabbb 1 2\nbbbb 1 3\nabb 1 2\nabbbba 1 2\nbbbbaaa 1 3",
"output": "babbbbaaab"
},
{
"input": "9\nfab 1 32\nb 2 38 54\nbadab 1 38\nba 1 62\na 1 25\nab 1 37\nbacaba 1 26\ncabaeab 1 12\nacab 1 3",
"output": "aaacabaaaaacabaeabaaaaaaabacabafabaaabadabaaaaaaaaaaabaaaaaaaba"
},
{
"input": "18\nabacab 2 329 401\nabadabacabae 1 293\nbacab 1 2\nabacabadabacabaga 1 433\nc 1 76\nbaca 1 26\ndab 1 72\nabagabaca 1 445\nabaea 1 397\ndabac 1 280\nab 2 201 309\nca 1 396\nabacabadab 1 497\nac 1 451\ncaba 1 444\nad 1 167\nbadab 1 358\naba 1 421",
"output": "abacabaaaaaaaaaaaaaaaaaaabacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadabacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadabacaaaaaaaaabadabacabaeaaaaabaaaaaaaaaaaaaaaaaaabacabaaaaaaaaaaaaaaaaaaaaaaabadabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacabaeabacabaaaaaaaaaaaaaaabaaaaaaaaaaabacabadabacabagabacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabacabadab"
},
{
"input": "10\ndabacabafa 1 24\nbacabadab 1 18\ndabaca 1 8\nbacabaea 1 42\nbacaba 1 34\nabadabaca 1 5\nbadabacaba 1 54\nbacabaeaba 1 10\nabacabaeab 1 9\nadabacaba 1 23",
"output": "aaaaabadabacabaeabacabadabacabafabacabaaabacabaeaaaaabadabacaba"
},
{
"input": "20\nadabacabaeabacabada 1 359\nabadabacabafabaca 1 213\nacabagabacaba 1 315\ncabaeabacabadabacab 1 268\nfabacabadabacabaeab 1 352\ncabafabacabada 1 28\nacabadabacabaea 1 67\ncabadabacabaeabacaba 1 484\nabacabadabacaba 1 209\nacabaiabacaba 1 251\nacabafabacabadabac 1 475\nabacabaeabacabadaba 1 105\ncabadabacabaeaba 1 68\nafabacabadabacab 1 287\nacabafab 1 91\ndabacabaea 1 328\nabaeabacabadab 1 461\nabadabacabaeabaca 1 421\nabadabacabafabac 1 277\nfabacabadabac 1 96",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaacabafabacabadaaaaaaaaaaaaaaaaaaaaaaaaaaacabadabacabaeabaaaaaaaaacabafabacabadabacabaeabacabadabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabacabadabacabafabacaaaaaaaaaaaaaaaaaaaaaaacabaiabacabaaaaacabaeabacabadabacabafabacabadabacabaaaaaaaaaaaaacabagabacabadabacabaeaaaaaaaaaaaaaaafabacabadabacabaeabacabadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabadabacabaeabacaaaaaaaaaaaaaaaaaaaaaaaaabaeabacabadabacabafabacabadabacabaeabacaba"
},
{
"input": "4\na 2 1 10\na 3 1 2 9\na 2 3 8\na 2 4 7",
"output": "aaaaaaaaaa"
},
{
"input": "10\nvvvvvvv 2 63649 456347\nvvvv 3 779 201571 458642\nvvvv 4 283450 377377 534312 583774\nvvvvv 10 78946 79066 346469 509974 665096 705906 711499 764350 815149 841106\nvvvvvvvvv 4 337796 374187 593756 618501\nvvvvvvvvv 3 89760 647846 984050\nvv 10 24048 93536 143218 211825 350809 406501 428953 572318 584177 839086\nvvvvvv 2 558325 764134\nvvvvvvv 9 174822 379712 412113 521028 542452 565481 678944 681435 747267\nvvvvv 9 43091 80962 212547 261108 528620 824068 873847 892141 974878",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..."
},
{
"input": "2\naba 1 1\nb 1 2",
"output": "aba"
}
] | 46 | 4,812,800 | -1 | 3,419 |
|
140 | New Year Table | [
"geometry",
"math"
] | null | null | Gerald is setting the New Year table. The table has the form of a circle; its radius equals *R*. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal *r*. Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other. Help Gerald determine whether the table is large enough for *n* plates. | The first line contains three integers *n*, *R* and *r* (1<=β€<=*n*<=β€<=100, 1<=β€<=*r*,<=*R*<=β€<=1000) β the number of plates, the radius of the table and the plates' radius. | Print "YES" (without the quotes) if it is possible to place *n* plates on the table by the rules given above. If it is impossible, print "NO".
Remember, that each plate must touch the edge of the table. | [
"4 10 4\n",
"5 10 4\n",
"1 10 10\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | The possible arrangement of the plates for the first sample is: | [
{
"input": "4 10 4",
"output": "YES"
},
{
"input": "5 10 4",
"output": "NO"
},
{
"input": "1 10 10",
"output": "YES"
},
{
"input": "3 10 20",
"output": "NO"
},
{
"input": "2 20 11",
"output": "NO"
},
{
"input": "6 9 3",
"output": "YES"
},
{
"input": "1 999 1000",
"output": "NO"
},
{
"input": "1 1000 999",
"output": "YES"
},
{
"input": "2 1000 500",
"output": "YES"
},
{
"input": "2 1000 499",
"output": "YES"
},
{
"input": "10 1000 236",
"output": "YES"
},
{
"input": "10 1000 237",
"output": "NO"
},
{
"input": "6 999 334",
"output": "NO"
},
{
"input": "100 1000 1",
"output": "YES"
},
{
"input": "100 1000 50",
"output": "NO"
},
{
"input": "13 927 179",
"output": "YES"
},
{
"input": "13 145 28",
"output": "NO"
},
{
"input": "37 307 24",
"output": "YES"
},
{
"input": "37 857 67",
"output": "NO"
},
{
"input": "100 821 25",
"output": "YES"
},
{
"input": "100 197 6",
"output": "NO"
},
{
"input": "93 704 23",
"output": "YES"
},
{
"input": "93 857 28",
"output": "NO"
},
{
"input": "85 870 31",
"output": "YES"
},
{
"input": "85 449 16",
"output": "NO"
},
{
"input": "29 10 1",
"output": "NO"
},
{
"input": "3 10 5",
"output": "NO"
},
{
"input": "2 4 2",
"output": "YES"
},
{
"input": "2 10 5",
"output": "YES"
},
{
"input": "4 2 1",
"output": "NO"
},
{
"input": "3 2 1",
"output": "NO"
},
{
"input": "59 486 43",
"output": "NO"
},
{
"input": "4 997 413",
"output": "NO"
},
{
"input": "100 100 5",
"output": "NO"
},
{
"input": "2 100 50",
"output": "YES"
},
{
"input": "2 2 1",
"output": "YES"
},
{
"input": "1 100 45",
"output": "YES"
},
{
"input": "2 20 10",
"output": "YES"
},
{
"input": "36 474 38",
"output": "NO"
},
{
"input": "6 996 333",
"output": "NO"
},
{
"input": "23 100 12",
"output": "NO"
},
{
"input": "100 886 27",
"output": "NO"
},
{
"input": "7 997 332",
"output": "NO"
},
{
"input": "10 72 17",
"output": "NO"
},
{
"input": "85 449 16",
"output": "NO"
},
{
"input": "2 10 10",
"output": "NO"
}
] | 92 | 0 | 0 | 3,420 |
|
710 | Optimal Point on a Line | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=β€<=*n*<=β€<=3Β·105) β the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=β€<=*x**i*<=β€<=109) β the coordinates of the given *n* points. | Print the only integer *x* β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -239 826 318 811 20 -732 -91 460 551 -610 555 -493 -154 442 -141 946 -913 -104 704 -380 699 32 106 -455 -518 214 -464 -861 243 -798 -472 559 529 -844 -32 871 -459 236 387 626 -318 -580 -611 -842 790 486 64 951 81 78 -693 403 -731 309 678 696 891 846 -106 918 212 -44 994 606 -829 -454 243 -477 -402 -818 -819 -310 -837 -209 736 424",
"output": "64"
},
{
"input": "2\n-1 0",
"output": "-1"
},
{
"input": "48\n-777 -767 -764 -713 -688 -682 -606 -586 -585 -483 -465 -440 -433 -397 -390 -377 -299 -252 -159 -147 -96 -29 -15 15 52 109 124 129 142 218 231 314 320 339 442 496 505 548 575 576 594 624 694 827 891 979 981 981",
"output": "15"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "4\n-1 -1 0 1",
"output": "-1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 1000000000",
"output": "0"
},
{
"input": "2\n1 -1",
"output": "-1"
},
{
"input": "2\n100 50",
"output": "50"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n606194955 -856471310 117647402",
"output": "117647402"
},
{
"input": "2\n615002717 -843553590",
"output": "-843553590"
},
{
"input": "2\n-1 2",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "5\n-638512131 348325781 -550537933 -618161835 -567935532",
"output": "-567935532"
},
{
"input": "1\n120",
"output": "120"
},
{
"input": "2\n-1000000000 1000000000",
"output": "-1000000000"
},
{
"input": "1\n618309368",
"output": "618309368"
}
] | 249 | 37,171,200 | -1 | 3,424 |
|
0 | none | [
"none"
] | null | null | Polycarpus has a finite sequence of opening and closing brackets. In order not to fall asleep in a lecture, Polycarpus is having fun with his sequence. He is able to perform two operations:
- adding any bracket in any position (in the beginning, the end, or between any two existing brackets); - cyclic shift β moving the last bracket from the end of the sequence to the beginning.
Polycarpus can apply any number of operations to his sequence and adding a cyclic shift in any order. As a result, he wants to get the correct bracket sequence of the minimum possible length. If there are several such sequences, Polycarpus is interested in the lexicographically smallest one. Help him find such a sequence.
Acorrect bracket sequence is a sequence of opening and closing brackets, from which you can get a correct arithmetic expression by adding characters "1" and "+" . Each opening bracket must correspond to a closed one. For example, the sequences "(())()", "()", "(()(()))" are correct and ")(", "(()" and "(()))(" are not.
The sequence *a*1 *a*2... *a**n* is lexicographically smaller than sequence *b*1 *b*2... *b**n*, if there is such number *i* from 1 to *n*, that*a**k*<==<=*b**k* for 1<=β€<=*k*<=<<=*i* and *a**i*<=<<=*b**i*. Consider that "(" <=<<= ")". | The first line contains Polycarpus's sequence consisting of characters "(" and ")". The length of a line is from 1 to 1<=000<=000. | Print a correct bracket sequence of the minimum length that Polycarpus can obtain by his operations. If there are multiple such sequences, print the lexicographically minimum one. | [
"()(())\n",
"()(\n"
] | [
"(())()",
"(())"
] | The sequence in the first example is already correct, but to get the lexicographically minimum answer, you need to perform four cyclic shift operations. In the second example you need to add a closing parenthesis between the second and third brackets and make a cyclic shift. You can first make the shift, and then add the bracket at the end. | [] | 62 | 0 | 0 | 3,433 |
|
399 | Pages | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page *n*. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
- If page 1 is in the navigation, the button "<<" must not be printed. - If page *n* is in the navigation, the button ">>" must not be printed. - If the page number is smaller than 1 or greater than *n*, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation. | The first and the only line contains three integers *n*, *p*, *k* (3<=β€<=*n*<=β€<=100; 1<=β€<=*p*<=β€<=*n*; 1<=β€<=*k*<=β€<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{
"input": "10 6 3",
"output": "<< 3 4 5 (6) 7 8 9 >> "
},
{
"input": "8 5 4",
"output": "1 2 3 4 (5) 6 7 8 "
},
{
"input": "100 10 20",
"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 >> "
},
{
"input": "100 25 11",
"output": "<< 14 15 16 17 18 19 20 21 22 23 24 (25) 26 27 28 29 30 31 32 33 34 35 36 >> "
},
{
"input": "5 2 1",
"output": "1 (2) 3 >> "
},
{
"input": "5 3 1",
"output": "<< 2 (3) 4 >> "
},
{
"input": "79 35 12",
"output": "<< 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": "100 99 5",
"output": "<< 94 95 96 97 98 (99) 100 "
},
{
"input": "100 99 15",
"output": "<< 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 (99) 100 "
},
{
"input": "100 100 17",
"output": "<< 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 (100) "
},
{
"input": "100 35 28",
"output": "<< 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 >> "
},
{
"input": "100 46 38",
"output": "<< 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 >> "
},
{
"input": "100 46 48",
"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 >> "
},
{
"input": "100 10 100",
"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 "
},
{
"input": "3 1 1",
"output": "(1) 2 >> "
},
{
"input": "3 2 1",
"output": "1 (2) 3 "
},
{
"input": "17 5 3",
"output": "<< 2 3 4 (5) 6 7 8 >> "
},
{
"input": "3 1 3",
"output": "(1) 2 3 "
},
{
"input": "7 5 1",
"output": "<< 4 (5) 6 >> "
},
{
"input": "5 5 5",
"output": "1 2 3 4 (5) "
},
{
"input": "5 3 5",
"output": "1 2 (3) 4 5 "
}
] | 109 | 0 | 3 | 3,437 |
|
620 | Professor GukiZ's Robot | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position. | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=β€<=*x*1,<=*y*1<=β€<=109) β the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=β€<=*x*2,<=*y*2<=β€<=109) β the finish position of the robot. | Print the only integer *d* β the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4,β4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one three times. | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output": "99"
},
{
"input": "-1000000000 -1000000000\n1000000000 1000000000",
"output": "2000000000"
},
{
"input": "-1000000000 -1000000000\n0 999999999",
"output": "1999999999"
},
{
"input": "0 0\n2 1",
"output": "2"
},
{
"input": "10 0\n100 0",
"output": "90"
},
{
"input": "1 5\n6 4",
"output": "5"
},
{
"input": "0 0\n5 4",
"output": "5"
},
{
"input": "10 1\n20 1",
"output": "10"
},
{
"input": "1 1\n-3 4",
"output": "4"
},
{
"input": "-863407280 504312726\n786535210 -661703810",
"output": "1649942490"
},
{
"input": "-588306085 -741137832\n341385643 152943311",
"output": "929691728"
},
{
"input": "0 0\n4 0",
"output": "4"
},
{
"input": "93097194 -48405232\n-716984003 -428596062",
"output": "810081197"
},
{
"input": "9 1\n1 1",
"output": "8"
},
{
"input": "4 6\n0 4",
"output": "4"
},
{
"input": "2 4\n5 2",
"output": "3"
},
{
"input": "-100000000 -100000000\n100000000 100000123",
"output": "200000123"
},
{
"input": "5 6\n5 7",
"output": "1"
},
{
"input": "12 16\n12 1",
"output": "15"
},
{
"input": "0 0\n5 1",
"output": "5"
},
{
"input": "0 1\n1 1",
"output": "1"
},
{
"input": "-44602634 913365223\n-572368780 933284951",
"output": "527766146"
},
{
"input": "-2 0\n2 -2",
"output": "4"
},
{
"input": "0 0\n3 1",
"output": "3"
},
{
"input": "-458 2\n1255 4548",
"output": "4546"
},
{
"input": "-5 -4\n-3 -3",
"output": "2"
},
{
"input": "4 5\n7 3",
"output": "3"
},
{
"input": "-1000000000 -999999999\n1000000000 999999998",
"output": "2000000000"
},
{
"input": "-1000000000 -1000000000\n1000000000 -1000000000",
"output": "2000000000"
},
{
"input": "-464122675 -898521847\n656107323 -625340409",
"output": "1120229998"
},
{
"input": "-463154699 -654742385\n-699179052 -789004997",
"output": "236024353"
},
{
"input": "982747270 -593488945\n342286841 -593604186",
"output": "640460429"
},
{
"input": "-80625246 708958515\n468950878 574646184",
"output": "549576124"
},
{
"input": "0 0\n1 0",
"output": "1"
},
{
"input": "109810 1\n2 3",
"output": "109808"
},
{
"input": "-9 0\n9 9",
"output": "18"
},
{
"input": "9 9\n9 9",
"output": "0"
},
{
"input": "1 1\n4 3",
"output": "3"
},
{
"input": "1 2\n45 1",
"output": "44"
},
{
"input": "207558188 -313753260\n-211535387 -721675423",
"output": "419093575"
},
{
"input": "-11 0\n0 0",
"output": "11"
},
{
"input": "-1000000000 1000000000\n1000000000 -1000000000",
"output": "2000000000"
},
{
"input": "0 0\n1 1",
"output": "1"
},
{
"input": "0 0\n0 1",
"output": "1"
},
{
"input": "0 0\n-1 1",
"output": "1"
},
{
"input": "0 0\n-1 0",
"output": "1"
},
{
"input": "0 0\n-1 -1",
"output": "1"
},
{
"input": "0 0\n0 -1",
"output": "1"
},
{
"input": "0 0\n1 -1",
"output": "1"
},
{
"input": "10 90\n90 10",
"output": "80"
},
{
"input": "851016864 573579544\n-761410925 -380746263",
"output": "1612427789"
},
{
"input": "1 9\n9 9",
"output": "8"
},
{
"input": "1000 1000\n1000 1000",
"output": "0"
},
{
"input": "1 9\n9 1",
"output": "8"
},
{
"input": "1 90\n90 90",
"output": "89"
},
{
"input": "100 100\n1000 1000",
"output": "900"
},
{
"input": "-1 0\n0 0",
"output": "1"
},
{
"input": "-750595959 -2984043\n649569876 -749608783",
"output": "1400165835"
},
{
"input": "958048496 712083589\n423286949 810566863",
"output": "534761547"
},
{
"input": "146316710 53945094\n-523054748 147499505",
"output": "669371458"
},
{
"input": "50383856 -596516251\n-802950224 -557916272",
"output": "853334080"
},
{
"input": "-637204864 -280290367\n-119020929 153679771",
"output": "518183935"
},
{
"input": "-100 -100\n-60 -91",
"output": "40"
},
{
"input": "337537326 74909428\n-765558776 167951547",
"output": "1103096102"
},
{
"input": "0 81\n18 90",
"output": "18"
},
{
"input": "283722202 -902633305\n-831696497 -160868946",
"output": "1115418699"
},
{
"input": "1000 1000\n-1000 1000",
"output": "2000"
},
{
"input": "5 6\n4 8",
"output": "2"
},
{
"input": "40572000 597493595\n-935051731 368493185",
"output": "975623731"
},
{
"input": "-5 5\n5 5",
"output": "10"
}
] | 92 | 20,172,800 | 0 | 3,441 |
|
712 | Memory and De-Evolution | [
"greedy",
"math"
] | null | null | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle of side length *y*.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y*? | The first and only line contains two integers *x* and *y* (3<=β€<=*y*<=<<=*x*<=β€<=100<=000)Β β the starting and ending equilateral triangle side lengths respectively. | Print a single integerΒ β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y* if he starts with the equilateral triangle of side length *x*. | [
"6 3\n",
"8 5\n",
"22 4\n"
] | [
"4\n",
"3\n",
"6\n"
] | In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides *a*, *b*, and *c* as (*a*,β*b*,β*c*). Then, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18af21f738bad490df83097a90e1f2879a4b21c6.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcfd51d1b2d764a1cf5fbc255cc02e6f5aaed3b1.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test, Memory can do: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0969b7d413854c1e7528991d926bef1f7ffba008.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/63e9e66b882c03e4c73e93ad92204dc255329309.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [
{
"input": "6 3",
"output": "4"
},
{
"input": "8 5",
"output": "3"
},
{
"input": "22 4",
"output": "6"
},
{
"input": "4 3",
"output": "3"
},
{
"input": "57 27",
"output": "4"
},
{
"input": "61 3",
"output": "9"
},
{
"input": "5 4",
"output": "3"
},
{
"input": "10 6",
"output": "3"
},
{
"input": "20 10",
"output": "4"
},
{
"input": "30 5",
"output": "6"
},
{
"input": "25 24",
"output": "3"
},
{
"input": "25 3",
"output": "7"
},
{
"input": "12 7",
"output": "3"
},
{
"input": "18 6",
"output": "5"
},
{
"input": "100000 3",
"output": "25"
},
{
"input": "100000 9999",
"output": "7"
},
{
"input": "9999 3",
"output": "20"
},
{
"input": "5323 32",
"output": "13"
},
{
"input": "6666 66",
"output": "12"
},
{
"input": "38578 32201",
"output": "3"
},
{
"input": "49449 5291",
"output": "7"
},
{
"input": "65310 32879",
"output": "3"
},
{
"input": "41183 4453",
"output": "7"
},
{
"input": "49127 9714",
"output": "6"
},
{
"input": "19684 12784",
"output": "3"
},
{
"input": "15332 5489",
"output": "4"
},
{
"input": "33904 32701",
"output": "3"
},
{
"input": "9258 2966",
"output": "5"
},
{
"input": "21648 11231",
"output": "3"
},
{
"input": "90952 47239",
"output": "3"
},
{
"input": "49298 23199",
"output": "4"
},
{
"input": "33643 24915",
"output": "3"
},
{
"input": "40651 5137",
"output": "6"
},
{
"input": "52991 15644",
"output": "5"
},
{
"input": "97075 62157",
"output": "3"
},
{
"input": "82767 53725",
"output": "3"
},
{
"input": "58915 26212",
"output": "4"
},
{
"input": "86516 16353",
"output": "6"
},
{
"input": "14746 7504",
"output": "3"
},
{
"input": "20404 7529",
"output": "4"
},
{
"input": "52614 8572",
"output": "6"
},
{
"input": "50561 50123",
"output": "3"
},
{
"input": "37509 7908",
"output": "5"
},
{
"input": "36575 23933",
"output": "3"
},
{
"input": "75842 8002",
"output": "7"
},
{
"input": "47357 2692",
"output": "8"
},
{
"input": "23214 4255",
"output": "6"
},
{
"input": "9474 46",
"output": "13"
},
{
"input": "79874 76143",
"output": "3"
},
{
"input": "63784 31333",
"output": "4"
},
{
"input": "70689 29493",
"output": "4"
},
{
"input": "43575 4086",
"output": "7"
},
{
"input": "87099 7410",
"output": "7"
},
{
"input": "75749 55910",
"output": "3"
},
{
"input": "87827 20996",
"output": "5"
},
{
"input": "31162 4580",
"output": "6"
},
{
"input": "63175 33696",
"output": "3"
},
{
"input": "15108 10033",
"output": "3"
},
{
"input": "82991 29195",
"output": "4"
},
{
"input": "48258 12837",
"output": "5"
},
{
"input": "59859 33779",
"output": "3"
},
{
"input": "93698 23890",
"output": "5"
},
{
"input": "42724 379",
"output": "12"
},
{
"input": "70434 39286",
"output": "3"
},
{
"input": "69826 18300",
"output": "5"
},
{
"input": "57825 17636",
"output": "5"
},
{
"input": "64898 2076",
"output": "9"
},
{
"input": "76375 67152",
"output": "3"
},
{
"input": "30698 3778",
"output": "7"
},
{
"input": "100 3",
"output": "10"
},
{
"input": "41 3",
"output": "8"
},
{
"input": "28 4",
"output": "7"
},
{
"input": "2487 19",
"output": "12"
},
{
"input": "100000 25000",
"output": "5"
},
{
"input": "10000 3",
"output": "20"
},
{
"input": "16 3",
"output": "6"
}
] | 124 | 0 | 3 | 3,444 |
|
979 | Kuro and GCD and XOR and SUM | [
"binary search",
"bitmasks",
"brute force",
"data structures",
"dp",
"dsu",
"greedy",
"math",
"number theory",
"strings",
"trees"
] | null | null | Kuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much that he solves levels by levels day by day.
Sadly, he's going on a vacation for a day, and he isn't able to continue his solving streak on his own. As Katie is a reliable person, Kuro kindly asked her to come to his house on this day to play the game for him.
Initally, there is an empty array $a$. The game consists of $q$ tasks of two types. The first type asks Katie to add a number $u_i$ to $a$. The second type asks Katie to find a number $v$ existing in $a$ such that $k_i \mid GCD(x_i, v)$, $x_i + v \leq s_i$, and $x_i \oplus v$ is maximized, where $\oplus$ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR), $GCD(c, d)$ denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers $c$ and $d$, and $y \mid x$ means $x$ is divisible by $y$, or report -1 if no such numbers are found.
Since you are a programmer, Katie needs you to automatically and accurately perform the tasks in the game to satisfy her dear friend Kuro. Let's help her! | The first line contains one integer $q$ ($2 \leq q \leq 10^{5}$) β the number of tasks the game wants you to perform.
$q$ lines follow, each line begins with an integer $t_i$ β the type of the task:
- If $t_i = 1$, an integer $u_i$ follow ($1 \leq u_i \leq 10^{5}$) β you have to add $u_i$ to the array $a$. - If $t_i = 2$, three integers $x_i$, $k_i$, and $s_i$ follow ($1 \leq x_i, k_i, s_i \leq 10^{5}$) β you must find a number $v$ existing in the array $a$ such that $k_i \mid GCD(x_i, v)$, $x_i + v \leq s_i$, and $x_i \oplus v$ is maximized, where $\oplus$ denotes the XOR operation, or report -1 if no such numbers are found.
It is guaranteed that the type of the first task is type $1$, and there exists at least one task of type $2$. | For each task of type $2$, output on one line the desired number $v$, or -1 if no such numbers are found. | [
"5\n1 1\n1 2\n2 1 1 3\n2 1 1 2\n2 1 1 1\n",
"10\n1 9\n2 9 9 22\n2 3 3 18\n1 25\n2 9 9 20\n2 25 25 14\n1 20\n2 26 26 3\n1 14\n2 20 20 9\n"
] | [
"2\n1\n-1\n",
"9\n9\n9\n-1\n-1\n-1\n"
] | In the first example, there are 5 tasks:
- The first task requires you to add $1$ into $a$. $a$ is now $\left\{1\right\}$. - The second task requires you to add $2$ into $a$. $a$ is now $\left\{1, 2\right\}$. - The third task asks you a question with $x = 1$, $k = 1$ and $s = 3$. Taking both $1$ and $2$ as $v$ satisfies $1 \mid GCD(1, v)$ and $1 + v \leq 3$. Because $2 \oplus 1 = 3 > 1 \oplus 1 = 0$, $2$ is the answer to this task. - The fourth task asks you a question with $x = 1$, $k = 1$ and $s = 2$. Only $v = 1$ satisfies $1 \mid GCD(1, v)$ and $1 + v \leq 2$, so $1$ is the answer to this task. - The fifth task asks you a question with $x = 1$, $k = 1$ and $s = 1$. There are no elements in $a$ that satisfy the conditions, so we report -1 as the answer to this task. | [] | 2,000 | 104,243,200 | 0 | 3,451 |
|
171 | Star | [
"*special",
"combinatorics"
] | null | null | The input contains a single integer *a* (1<=β€<=*a*<=β€<=18257). | Print a single integer *output* (1<=β€<=*output*<=β€<=2Β·109). | [
"2\n"
] | [
"13"
] | none | [
{
"input": "2",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "73"
},
{
"input": "5",
"output": "121"
},
{
"input": "6",
"output": "181"
},
{
"input": "7",
"output": "253"
},
{
"input": "8",
"output": "337"
},
{
"input": "9",
"output": "433"
},
{
"input": "15000",
"output": "1349910001"
},
{
"input": "4845",
"output": "140815081"
},
{
"input": "6914",
"output": "286778893"
},
{
"input": "3994",
"output": "95688253"
},
{
"input": "12504",
"output": "938025073"
},
{
"input": "13170",
"output": "1040614381"
},
{
"input": "427",
"output": "1091413"
},
{
"input": "11877",
"output": "846307513"
},
{
"input": "3202",
"output": "61497613"
},
{
"input": "5689",
"output": "194154193"
},
{
"input": "15302",
"output": "1404815413"
},
{
"input": "17042",
"output": "1742476333"
},
{
"input": "1481",
"output": "13151281"
},
{
"input": "15592",
"output": "1458569233"
},
{
"input": "16344",
"output": "1602659953"
},
{
"input": "4222",
"output": "106926373"
},
{
"input": "11808",
"output": "836502337"
},
{
"input": "13366",
"output": "1071819541"
},
{
"input": "3823",
"output": "87669037"
},
{
"input": "581",
"output": "2021881"
},
{
"input": "15479",
"output": "1437503773"
},
{
"input": "6543",
"output": "256825837"
},
{
"input": "11136",
"output": "743996161"
},
{
"input": "16331",
"output": "1600111381"
},
{
"input": "8543",
"output": "437845837"
},
{
"input": "7530",
"output": "340160221"
},
{
"input": "3154",
"output": "59667373"
},
{
"input": "11501",
"output": "793569001"
},
{
"input": "12038",
"output": "869408437"
},
{
"input": "13082",
"output": "1026753853"
},
{
"input": "18257",
"output": "1999798753"
}
] | 248 | 0 | 3 | 3,453 |
||
607 | Zuma | [
"dp"
] | null | null | Genos recently installed the game Zuma on his phone. In Zuma there exists a line of *n* gemstones, the *i*-th of which has color *c**i*. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is a palindrome and remove it from the line. After the substring is removed, the remaining gemstones shift to form a solid line again. What is the minimum number of seconds needed to destroy the entire line?
Let us remind, that the string (or substring) is called palindrome, if it reads same backwards or forward. In our case this means the color of the first gemstone is equal to the color of the last one, the color of the second gemstone is equal to the color of the next to last and so on. | The first line of input contains a single integer *n* (1<=β€<=*n*<=β€<=500)Β β the number of gemstones.
The second line contains *n* space-separated integers, the *i*-th of which is *c**i* (1<=β€<=*c**i*<=β€<=*n*)Β β the color of the *i*-th gemstone in a line. | Print a single integerΒ β the minimum number of seconds needed to destroy the entire line. | [
"3\n1 2 1\n",
"3\n1 2 3\n",
"7\n1 4 4 2 3 2 1\n"
] | [
"1\n",
"3\n",
"2\n"
] | In the first sample, Genos can destroy the entire line in one second.
In the second sample, Genos can only destroy one gemstone at a time, so destroying three gemstones takes three seconds.
In the third sample, to achieve the optimal time of two seconds, destroy palindrome 4 4 first and then destroy palindrome 1 2 3 2 1. | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "7\n1 4 4 2 3 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "8\n1 2 1 3 4 1 2 1",
"output": "2"
},
{
"input": "50\n5 7 5 10 7 9 1 9 10 2 8 3 5 7 3 10 2 3 7 6 2 7 1 2 2 2 4 7 3 5 8 3 4 4 1 6 7 10 5 4 8 1 9 5 5 3 4 4 8 3",
"output": "21"
},
{
"input": "50\n13 17 20 5 14 19 4 17 9 13 10 19 16 13 17 2 18 3 1 9 19 4 19 10 17 12 16 20 10 11 15 10 3 19 8 6 2 8 9 15 13 7 8 8 5 8 15 18 9 4",
"output": "28"
},
{
"input": "50\n22 19 14 22 20 11 16 28 23 15 3 23 6 16 30 15 15 10 24 28 19 19 22 30 28 1 27 12 12 14 17 30 17 26 21 26 27 1 11 23 9 30 18 19 17 29 11 20 29 24",
"output": "25"
},
{
"input": "50\n30 17 31 15 10 3 39 36 5 29 16 11 31 2 38 1 32 40 7 15 39 34 24 11 4 23 9 35 39 32 4 5 14 37 10 34 11 33 30 14 4 34 23 10 34 34 26 34 26 16",
"output": "36"
},
{
"input": "50\n19 25 46 17 1 41 50 19 7 1 43 8 19 38 42 32 38 22 8 5 5 31 29 35 43 12 23 48 40 29 30 9 46 3 39 24 36 36 32 22 21 29 43 33 36 49 48 22 47 37",
"output": "36"
},
{
"input": "6\n1 2 1 1 3 1",
"output": "2"
}
] | 2,000 | 5,120,000 | 0 | 3,457 |
|
346 | Lucky Common Subsequence | [
"dp",
"strings"
] | null | null | In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF.
You are given two strings *s*1, *s*2 and another string called *virus*. Your task is to find the longest common subsequence of *s*1 and *s*2, such that it doesn't contain *virus* as a substring. | The input contains three strings in three separate lines: *s*1, *s*2 and *virus* (1<=β€<=|*s*1|,<=|*s*2|,<=|*virus*|<=β€<=100). Each string consists only of uppercase English letters. | Output the longest common subsequence of *s*1 and *s*2 without *virus* as a substring. If there are multiple answers, any of them will be accepted.
If there is no valid common subsequence, output 0. | [
"AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ\n",
"AA\nA\nA\n"
] | [
"ORZ\n",
"0\n"
] | none | [
{
"input": "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ",
"output": "ORZ"
},
{
"input": "AA\nA\nA",
"output": "0"
},
{
"input": "PWBJTZPQHA\nZJMKLWSROQ\nUQ",
"output": "WQ"
},
{
"input": "QNHRPFYMAAPJDUHBAEXNEEZSTMYHVGQPYKNMVKMBVSVLIYGUVMJHEFLJEPIWFHSLISTGOKRXNMSCXYKMAXBPKCOCNTIRPCUEPHXM\nRRFCZUGFDRKKMQTOETNELXMEWGOCDHFKIXOPVHHEWTCDNXVFKFKTKNWKEIKTCMHMHDNCLLVQSGKHBCDDYVVVQIRPZEOPUGQUGRHH\nR",
"output": "QNHFPHEXNETMHMHLLSGKCYPOPUH"
},
{
"input": "CGPWTAPEVBTGANLCLVSHQIIKHDPVUHRSQPXHSNYAHPGBECICFQYDFRTRELLLEDZYWJSLOBSKDGRRDHNRRGIXAMEBGFJJTEIGUGRU\nHAWYVKRRBEIWNOGYMIYQXDCFXMMCSAYSOXQFHHIFRRCJRAWHLDDHHHAKHXVKCVPBFGGEXUKWTFWMOUUGMXTSBUTHXCJCWHCQQTYQ\nANKFDWLYSX",
"output": "WVBGCSSQHHIFRRWLDDHXBGFUGU"
},
{
"input": "AUNBEKNURNUPHXQYKUTAHCOLMPRQZZTVDUYCTNIRACQQTQAIDTAWJXBUTIZUASDIJZWLHAQVGCAHKTZMXSDVVWAIGQEALRFKFYTT\nQBVRFKPKLYZLYNRFTRJZZQEYAEKPFXVICUVFVQSDENBJYYNCFTOZHULSWJQTNELYLKCZTGHOARDCFXBXQGGSQIVUCJVNGFZEEZQE\nN",
"output": "BKPYTRZZVICQDJTZUSJZHAQGSVVGQE"
},
{
"input": "BGIIURZTEUJJULBWKHDQBRFGEUOMQSREOTILICRSBUHBGTSRDHKVDDEBVHGMHXUVFJURSMFDJOOOWCYPJDVRVKLDHICPNKTBFXDJ\nXOADNTKNILGNHHBNFYNDWUNXBGDFUKUVHLPDOGOYRMOTAQELLRMHFAQEOXFWGAQUROVUSWOAWFRVIRJQVXPCXLSCQLCUWKBZUFQP\nYVF",
"output": "ILBWKHDGOMQELRHEGUVUSOWVRVLCKBF"
},
{
"input": "AXBPBDEYIYKKCZBTLKBUNEQLCXXLKIUTOOATYDXYYQCLFAXAEIGTFMNTTQKCQRMEEFRYVYXAOLMUQNPJBMFBUGVXFZAJSBXWALSI\nVWFONLLKSHGHHQSFBBFWTXAITPUKNDANOCLMNFTAAMJVDLXYPILPCJCFWTNBQWEOMMXHRYHEGBJIVSXBBGQKXRIYNZFIWSZPPUUM\nPPKKLHXWWT",
"output": "BBITKNCLTADXYCFTNQMRYVXBBGXFWS"
},
{
"input": "XKTAOCPCVMIOGCQKPENDKIZRZBZVRTBTGCDRQUIMVHABDIHSCGWPUTQKLPBOXAYICPWJBFLFSEPERGJZHRINEHQMYTOTKLCQCSMZ\nAITFIOUTUVZLSSIYWXSYTQMFLICCXOFSACHTKGPXRHRCGXFZXPYWKWPUOIDNEEZOKMOUYGVUJRQTIRQFCSBCWXVFCIAOLZDGENNI\nDBHOIORVCPNXCDOJKSYYIENQRJGZFHOWBYQIITMTVWXRMAMYILTHBBAJRJELWMIZOZBGPDGSTIRTQIILJRYICMUQTUAFKDYGECPY",
"output": "TOVMIOCKPRRCGWPUOIEEGJRQTQCSZ"
},
{
"input": "UNGXODEEINVYVPHYVGSWPIPFMFLZJYRJIPCUSWVUDLLSLRPJJFWCUOYDUGXBRKWPARGLXFJCNNFUIGEZUCTPFYUIMQMJLQHTIVPO\nBWDEGORKXYCXIDWZKGFCUYIDYLTWLCDBUVHPAPFLIZPEUINQSTNRAOVYKZCKFWIJQVLSVCGLTCOEMAYRCDVVQWQENTWZALWUKKKA\nXDGPZXADAFCHKILONSXFGRHIQVMIYWUTJUPCCEKYQVYAENRHVWERJSNPVEMRYSZGYBNTQLIFKFISKZJQIQQGSKVGCNMPNIJDRTXI",
"output": "GODIYVHPPFLZPUSWVLSLCOYDWALU"
},
{
"input": "KOROXDDWEUVYWJIXSFPEJFYZJDDUXISOFJTIFJSBTWIJQHMTQWLAGGMXTFALRXYCMGZNKYQRCDVTPRQDBAALTWAXTNLDPYWNSFKE\nNHZGRZFMFQGSAYOJTFKMMUPOOQXWCPPAIVRJHINJPHXTTBWRIYNOHMJKBBGXVXYZDBVBBTQRXTOFLBBCXGNICBKAAGOKAYCCJYCW\nXCXLBESCRBNKWYGFDZFKWYNLFAKEWWGRUIAQGNCFDQXCHDBEQDSWSNGVKUFOGGSPFFZWTXGZQMMFJXDWOPUEZCMZEFDHXTRJTNLW",
"output": "KOOXWVJIPXTBWIHMTQXTFLCGNCBAAAYW"
},
{
"input": "ESQZPIRAWBTUZSOWLYKIYCHZJPYERRXPJANKPZVPEDCXCJIDTLCARMAOTZMHJVDJXRDNQRIIOFIUTALVSCKDUSAKANKKOFKWINLQ\nGKSTYEAXFJQQUTKPZDAKHZKXCJDONKBZOTYGLYQJOGKOYMYNNNQRRVAGARKBQYJRVYYPFXTIBJJYQUWJUGAUQZUVMUHXLIQWGRMP\nUFPHNRDXLNYRIIYVOFRKRUQCWAICQUUBPHHEGBCILXHHGLOBKADQVPSQCMXJRLIZQPSRLZJNZVQPIURDQUKNHVVYNVBYGXXXXJDI",
"output": "STYEXJKPZDXCJDTLOMVRQRFIUAVUIQ"
},
{
"input": "UAYQUMTSNGMYBORUYXJJQZVAGBRVDWUTGUYYYOTWAHVKGGOHADXULFUFQULSAGDWFJCSDKPWBROYZIFRGGRVZQMEHKHCKNHTQSMK\nSVKVTPUZOBRKGLEAAXMIUSRISOTDIFFUCODYGNYIPSWEEBHGNWRZETXSVVMQTRBVFZMYHOHUCMLBUXBMPMSNCSHFZTAFUVTMQFGL\nTNICVANBEBOQASUEJJAOJXWNMDGAAVYNHRPSMKGMXZDJHCZHFHRRMIDWUOQCZSBKDPLSGHNHFKFYDRGVKXOLPOOWBPOWSDFLEJVX",
"output": "SVVTUOKGAXUFFUCDPWBRZRVZMHHCNHTQ"
},
{
"input": "KEJHTOKHMKWTYSJEAJAXGADRHUKBCRHACSRDNSZIHTPQNLOSRKYBGYIIJDINTXRPMWSVMMBODAYPVVDDTIXGDIOMWUAKZVFKDAUM\nWTEVPIFAAJYIDTZSZKPPQKIOMHDZTKDMFVKSJRUFMNHZJPVSQYELWYAFACGGNRORSLGYVXAEYVLZBLDEHYDGOFDSWUYCXLXDKFSU\nTUZEQBWVBVTKETQ",
"output": "EJTOKMKSJRUHZPQLYGNRSVAYVDDGDWUKFU"
},
{
"input": "EGQYYSKTFTURZNRDVIWBYXMRDGFWMYKFXGIFOGYJSXKDCJUAGZPVTYCHIXVFTVTCXMKHZFTXSMMQVFXZGKHCIYODDRZEYECDLKNG\nPEXXCTRFJAAKPOTBAEFRLDRZKORNMXHHXTLKMKCGPVPUOBELPLFQFXOBZWIVIQCHEJQPXKGSCQAWIMETCJVTAGXJIINTADDXJTKQ\nQURSEKPMSSEVQZI",
"output": "EKTFRZNXMGFFXIJXKCATCVTXTDDK"
},
{
"input": "ZFFBNYVXOZCJPSRAEACVPAUKVTCVZYQPHVENTKOCMHNIYYMIKKLNKHLWHHWAQMWFTSYEOQQFEYAAYGMPNZCRYBVNAQTDSLXZGBCG\nPIQHLNEWAMFAKGHBGZAWRWAXCSKUDZBDOCTXAHSVFZACXGFMDSYBYYDDNQNBEZCYCULSMMPBTQOJQNRPZTRCSDLIYPLVUGJPKDTG\nZBFJPLNAKWQBTUVJKMHVBATAM",
"output": "FBZRACUZOCHAMSYYYNZCYBNTDLGG"
},
{
"input": "BTWZLIKDACZVLCKMVTIQHLFBNRCBDSWPFFKGPCQFPTOIJLPFCDMFGQKFHTDFFCCULUAYPXXIIIWBZIDMOPNHPZBEXLVARJFTBFOE\nMDXYKKWZVASJPPWRCYNMRAOBBLUNBSMQAPCPSFAGLXWJRBQTBRWXYNQGWECYNFIAJXDMUHIIMDFMSHLPIMYQXNRRUSSNXALGNWIK\nKNFVBVAOWXMZVUHAVUDKDBUVAKNHACZBGBHMUOPHWGQSDFXLHB",
"output": "WZACLMQLBRWGCFIJDMHDFLPIMNXL"
},
{
"input": "GOZVMIRQIGYGVAGOREQTXFXPEZYOJOXPNDGAESICXHMKQDXQPRLMRVWHXFEJVCWZDLYMQLDURUXZPTLEHPTSKXGSNEQDKLVFFLDX\nIMEVFCZXACKRRJVXDRKFWTLTRTLQQDHEBZLCOCNVPABQMIWJHRLKFUKWOVVWGGNWCJNRYOYOAJFQWCLHQIQRBZTVWKBFOXKEHHQP\nSZ",
"output": "MVARXFEZOPAIHRLVWFCLQRZTKXEQ"
},
{
"input": "BBYUVCIYLNUJPSEYCAAPQSDNSDDTNEHQZDPBEKQAWNAKEYFBNEEBGPDPRLCSVOWYDEDRPPEDOROCHRCNQUSPNVXGRXHNLKDETWQC\nBQCQXCAHADGJHBYIKEUWNXFUOOTVCCKJPJJCMWLAWWKSDGHFNZTCPSQNRTPCBLXDTSJLRHSCCZXQXCVLVGTROOUCUQASIQHZGNEI\nRYE",
"output": "BBYUVCJPCASDNTPQNBDRLVROOCQSGNE"
},
{
"input": "WZRKLETJRBBRZKGHEFBVEFVLIERBPSEGJVSNUZUICONWWBOOTHCOJLLZFNOCNOFJQZTZWBLKHGIWWWPBUYWBAHYJGEBJZJDTNBGN\nZINFGDCNKHYFZYYWHTIHZTKWXXXMSWOVOPQDTRWSQKBWWCPEMYFVGARELELBLGEVJCMOCFTTUVCYUQUSFONAMWKVDWMGXVNZJBWH\nAFPA",
"output": "WZKTRBEFVELEBEJCOTCFONWKWGZJB"
},
{
"input": "ABABABB\nABABABB\nABABB",
"output": "ABABAB"
},
{
"input": "ABBB\nABBB\nABB",
"output": "BBB"
},
{
"input": "A\nBABAABAAABABABABABABAABABABABBABABABABAABBABBABAABABAABAABBAAAAAABBABABABABAABABAABABABABAABAABABABA\nB",
"output": "A"
},
{
"input": "ABBAABAAABABAABAABABABABAABBBABABABAAABBABAAABABABABBABBABABAABABABABABABBABAABABAABABABAAABBABABABA\nA\nB",
"output": "A"
},
{
"input": "ABBBABABABABABBABAABAAABABAABABABABBABAAAABABABBABAABABAAABAABBAAABAABABBABBABABBABAABABABAAAAABABAB\nB\nBABBABAABABABABABABABABABBAABABBABABBAAABAAABABBAABAABBABABBABABAABBABAABABBAABAABAABABABABABBABABAB",
"output": "B"
},
{
"input": "AABABAABAAABABAAABAAAABBAAABABAAABABAABAABAAAABAABAAAABAAAABAAAABBAABAAAAABAAAAABABAAAAAABABAABAAAAA\nABAABABABAAABABAABABBAABAABAABABAABABAAABBAABAAAABABABAAAAABAAAAABABABABAABAABAABAABABAABABAABAABAAB\nBABAAABABBAABABAABAA",
"output": "ABAABABABAAABAAAABBAABAAAABABAABABAAABAABAAAABAAAAAAABAAAAAAABAAAAABAAAAAAABABAABAAAA"
},
{
"input": "AABABABABAAAABBAAAABABABABAAAAABABAAAA\nAABABAAABABABAAABAAAAABAAABAAABABABBBABBAAABAABAAAAABABBABAAABAABAABABAAAABABAAABAAABAABABBBABBABABA\nAAAAA",
"output": "AABABABABAAAABBAAAABABABABAAAABABAAAA"
},
{
"input": "ZZXXAAZZAXAAZZAZZXXAAZZAXAXZZXXAAZZZZXXAZZXXAAAZZXXAAAZZXXZZXXXAAAZZXZZXXAZZXXZXXAAXAAZZZXXAXAXAZZXZ\nAZZXXAAZZXXAAXZXXAZZXAZZXZZXXAAZZXXAAZAAZZAAZZXXAA\nAAZZXAAXXAAAZZXXAZZXXAAZZXXAAAZZXXZ",
"output": "ZZXXAAZZXXAAXZXXAZZXAZZXZZXXAAZZXXAAZAZZAAZZXXAA"
},
{
"input": "SDASSDADASDASDASDSDADASASDAAASDASDDASDDASDADASDASDSSDASDD\nSDASDASDDASDASDASDSDSDASDASDASDASDASDASDASDADASDASDASDSDASDASDDDASSD\nSDASDSDDAA",
"output": "SDASSDADASDASDSDSDADASASDAAASDASDDASDDASDDASDASDDASD"
},
{
"input": "DASSDASDASDDAASDASDADASDASASDAS\nSDADASDASSDAASDASDASDADASSDDA\nSD",
"output": "DADADADAADADADADASSA"
},
{
"input": "ASDASSDASDS\nDASDASDDDASDADASDASDASDASSDADASDDAASDA\nDSD",
"output": "ASDASSDASDS"
},
{
"input": "ASDASASDASDASDAASDASDASDASASDDAASDASSASDSDAD\nDASDASSSDASDASDASASDASSDAASDASSDDSASDASDAASDDAASDASDAASDASDDASDASDASDASDASS\nDASD",
"output": "ASDASASDASASDAASDASASDASASDDAASDASSASDSDAD"
},
{
"input": "DASDSDASDADASDDDSDASSDDAASDA\nDASDDASDSDADSDASDADSDSDADDASDASDDASDASDASDSDASD\nDAASD",
"output": "DASDSDASDADASDDDSDASSDDASDA"
},
{
"input": "ABAAAABABADABAABAABCCABADABACABACABCABADABADABACABBACAADABACABABACABADABACABABA\nBACAACABABABACABCABADABAACABADABACABAA\nABBAB",
"output": "BAAACABABABACABCABADABAACABADABACABAA"
},
{
"input": "ABAABACABADAACADABACAAB\nBAACABADABACABAAAADADAABACABACABADABABADABACABAADABBADABACAAACAABACABADABBBAA\nDABACA",
"output": "ABAABACABADAACADABAAAB"
},
{
"input": "BACABACABAACABADABABACAABACABBACAACAACABCABADAACABAABAABBADABACABADABCABAD\nBACAABADABABADABACABABACABADABACABCBADABACADABCABABADAABA\nBADABAA",
"output": "BACAABAAABADABACAABACABAAACABCBADAACADABCABADAABA"
},
{
"input": "ACABADABACABCABAAB\nBADAB\nACAACABA",
"output": "BADAB"
},
{
"input": "ABABAC\nABABAC\nABAC",
"output": "ABABA"
},
{
"input": "BCBCBC\nBCBCBC\nBC",
"output": "CCB"
},
{
"input": "AAACAAACAAADAAAAAAA\nAADAAAAAAAACDAAAAAAAAAAACAAAAABCACAAACAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADA\nAAACAADAAAAADD",
"output": "AAACAAACAAAAAAAAAA"
},
{
"input": "ABABBB\nABABBB\nABB",
"output": "ABAB"
},
{
"input": "ABABABAC\nABABABAC\nABABAC",
"output": "ABABABA"
},
{
"input": "BBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBABBABBBABAABBBBBBAABAAAAAAAAABABAAABBABBAAAAAABAABABBAAABB\nBBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBABBABBBABAABBBBBBAABAAAAAAAAABABAAABBABBAAAAAABAABABBAAABB\nBBBAA",
"output": "BBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBABBABBBABAABBBBBBABAAAAAAAAABABAAABBABBAAAAAABAABABBAAABB"
},
{
"input": "ABABC\nABABC\nABC",
"output": "ABAB"
},
{
"input": "BABBB\nBABBB\nABB",
"output": "BBBB"
},
{
"input": "ABCCCCCCCC\nABCCCCCCCC\nABC",
"output": "BCCCCCCCC"
}
] | 62 | 0 | 0 | 3,459 |
|
776 | Molly's Chemicals | [
"binary search",
"brute force",
"data structures",
"implementation",
"math"
] | null | null | Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of *k*. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments. | The first line of input contains two integers, *n* and *k*, the number of chemicals and the number, such that the total affection value is a non-negative power of this number *k*. (1<=β€<=*n*<=β€<=105, 1<=β€<=|*k*|<=β€<=10).
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=β€<=*a**i*<=β€<=109)Β β affection values of chemicals. | Output a single integerΒ β the number of valid segments. | [
"4 2\n2 2 2 2\n",
"4 -3\n3 -6 -3 12\n"
] | [
"8\n",
"3\n"
] | Do keep in mind that *k*<sup class="upper-index">0</sup>β=β1.
In the first sample, Molly can get following different affection values:
- 2: segments [1,β1], [2,β2], [3,β3], [4,β4]; - 4: segments [1,β2], [2,β3], [3,β4]; - 6: segments [1,β3], [2,β4]; - 8: segments [1,β4].
Out of these, 2, 4 and 8 are powers of *k*β=β2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1,β2], [3,β3], [3,β4]. | [
{
"input": "4 2\n2 2 2 2",
"output": "8"
},
{
"input": "4 -3\n3 -6 -3 12",
"output": "3"
},
{
"input": "14 -9\n-2 -4 62 53 90 41 35 21 85 74 85 57 10 39",
"output": "0"
},
{
"input": "20 9\n90 21 -6 -61 14 -21 -17 -65 -84 -75 -48 56 67 -50 16 65 -79 -61 92 85",
"output": "1"
},
{
"input": "89 -7\n5972 4011 3914 670 3727 2913 6935 6927 2118 6645 7141 3585 9811 2859 459 8870 6578 8667 468 5152 3241 7455 7323 8817 4866 1040 5102 9146 621 5002 396 4967 9822 4200 3899 4416 5225 9415 9606 4802 5589 1798 9094 5453 7163 264 1026 6187 3918 4237 -17 4306 8960 3321 2927 9205 6248 7607 564 364 3503 8149 2235 8278 6249 3987 524 5718 9359 3549 1474 9204 3870 6996 3932 8295 612 6310 4461 1129 6441 3465 4654 7583 3274 6309 4831 4918 558",
"output": "0"
},
{
"input": "10 2\n2 4 8 16 32 64 128 256 512 1024",
"output": "10"
},
{
"input": "10 1\n-1 1 -1 1 -1 1 -1 1 -1 1",
"output": "15"
},
{
"input": "32 2\n8 16384 32768 65536 32 8388608 1048576 16777216 65536 8 16384 128 2097152 1024 16777216 4 8192 8388608 65536 1024 1024 16 8 16 128 2 1024 128 8 33554432 32768 2048",
"output": "33"
},
{
"input": "1 2\n2",
"output": "1"
},
{
"input": "14 2\n2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "45"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "10"
},
{
"input": "4 1\n1 1 1 1",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "3"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "10 -1\n1 0 -1 1 0 -1 1 0 -1 1",
"output": "28"
},
{
"input": "4 1\n-1 -2 3 1",
"output": "3"
},
{
"input": "26 -1\n0 0 1 1 -1 -1 0 0 1 0 0 0 -1 1 0 0 -1 1 -1 1 -1 1 0 0 5 -4",
"output": "168"
},
{
"input": "1 -1\n-1",
"output": "1"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "1 2\n1048576",
"output": "1"
},
{
"input": "4 -1\n1 1 1 1",
"output": "4"
},
{
"input": "5 -1\n1 1 1 1 1",
"output": "5"
},
{
"input": "33 2\n536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912",
"output": "141"
},
{
"input": "1 1\n-1",
"output": "0"
}
] | 2,500 | 63,488,000 | 0 | 3,461 |
|
0 | none | [
"none"
] | null | null | Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.
Let's assume that strings *s* and *t* have the same length *n*, then the function *h*(*s*,<=*t*) is defined as the number of positions in which the respective symbols of *s* and *t* are the same. Function *h*(*s*,<=*t*) can be used to define the function of Vasya distance Ο(*s*,<=*t*):
Vasya found a string *s* of length *n* on the Internet. Now he wants to count how many strings *t* there are such that the Vasya distance from the string *s* attains maximum possible value. Formally speaking, *t* must satisfy the equation: .
Vasya could not try all possible strings to find an answer, so he needs your help. As the answer may be very large, count the number of such strings modulo 109<=+<=7. | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=105).
The second line of the input contains a single string of length *n*, consisting of characters "ACGT". | Print a single numberΒ β the answer modulo 109<=+<=7. | [
"1\nC\n",
"2\nAG\n",
"3\nTTT\n"
] | [
"1\n",
"4\n",
"1\n"
] | Please note that if for two distinct strings *t*<sub class="lower-index">1</sub> and *t*<sub class="lower-index">2</sub> values Ο(*s*,β*t*<sub class="lower-index">1</sub>) ΠΈ Ο(*s*,β*t*<sub class="lower-index">2</sub>) are maximum among all possible *t*, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.
In the first sample, there is Ο("*C*",β"*C*")β=β1, for the remaining strings *t* of length 1 the value of Ο(*s*,β*t*) is 0.
In the second sample, Ο("*AG*",β"*AG*")β=βΟ("*AG*",β"*GA*")β=βΟ("*AG*",β"*AA*")β=βΟ("*AG*",β"*GG*")β=β4.
In the third sample, Ο("*TTT*",β"*TTT*")β=β27 | [
{
"input": "1\nC",
"output": "1"
},
{
"input": "2\nAG",
"output": "4"
},
{
"input": "3\nTTT",
"output": "1"
},
{
"input": "4\nGACT",
"output": "256"
},
{
"input": "1\nT",
"output": "1"
},
{
"input": "2\nAG",
"output": "4"
},
{
"input": "3\nGCA",
"output": "27"
},
{
"input": "5\nACGTC",
"output": "1"
},
{
"input": "15\nAGCGAATCCCATTGT",
"output": "14348907"
},
{
"input": "20\nTAAGCGACCAGGTGCTTTAC",
"output": "511620083"
},
{
"input": "30\nCCTTTCGGGGCGCGTTGGCCTTTGTCCTGC",
"output": "130653412"
},
{
"input": "318\nTATCAATCGGTACGTGCGCATCATTGTCAATCGGGCTTCATGGCTTGCGGGCGCTACCCGAGGGGAAGCTGCGGACAGGTAGGTAAGATACACACGAACCAAACGGAGTTATGTTGGATAAATTGGCTGGAAGGGCGTAGGTATATCGAGTCGCGGACCTGGCATAGACTATCAGGGGCAGCGGTACAAGGCAACCGTGAGCGGGGTCTGCCCACCATTAGACCGATGCGCCGGCTCGTATATGTGATTCTGGTGAAAAGTATCATGCCGGGACGCGTAATGACCCGGCTGGCTAATCCACCGTGGCAGCAAAATAAC",
"output": "1"
}
] | 0 | 0 | -1 | 3,463 |
|
39 | Cubical Planet | [
"math"
] | D. Cubical Planet | 2 | 64 | You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube. | The first line contains three space-separated integers (0 or 1) β the coordinates of the first fly, the second line analogously contains the coordinates of the second fly. | Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO". | [
"0 0 0\n0 1 0\n",
"1 1 0\n0 1 0\n",
"0 0 0\n1 1 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | [
{
"input": "0 0 0\n0 1 0",
"output": "YES"
},
{
"input": "1 1 0\n0 1 0",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1",
"output": "NO"
},
{
"input": "0 0 0\n1 0 0",
"output": "YES"
},
{
"input": "0 0 0\n0 1 0",
"output": "YES"
},
{
"input": "0 0 0\n1 1 0",
"output": "YES"
},
{
"input": "0 0 0\n0 0 1",
"output": "YES"
},
{
"input": "0 0 0\n1 0 1",
"output": "YES"
},
{
"input": "0 0 0\n0 1 1",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1",
"output": "NO"
},
{
"input": "1 0 0\n0 0 0",
"output": "YES"
},
{
"input": "1 0 0\n0 1 0",
"output": "YES"
},
{
"input": "1 0 0\n1 1 0",
"output": "YES"
},
{
"input": "1 0 0\n0 0 1",
"output": "YES"
},
{
"input": "1 0 0\n1 0 1",
"output": "YES"
},
{
"input": "1 0 0\n0 1 1",
"output": "NO"
},
{
"input": "1 0 0\n1 1 1",
"output": "YES"
},
{
"input": "0 1 0\n0 0 0",
"output": "YES"
},
{
"input": "0 1 0\n1 0 0",
"output": "YES"
},
{
"input": "0 1 0\n1 1 0",
"output": "YES"
},
{
"input": "0 1 0\n0 0 1",
"output": "YES"
},
{
"input": "0 1 0\n1 0 1",
"output": "NO"
},
{
"input": "0 1 0\n0 1 1",
"output": "YES"
},
{
"input": "0 1 0\n1 1 1",
"output": "YES"
},
{
"input": "1 1 0\n0 0 0",
"output": "YES"
},
{
"input": "1 1 0\n1 0 0",
"output": "YES"
},
{
"input": "1 1 0\n0 1 0",
"output": "YES"
},
{
"input": "1 1 0\n0 0 1",
"output": "NO"
},
{
"input": "1 1 0\n1 0 1",
"output": "YES"
},
{
"input": "1 1 0\n0 1 1",
"output": "YES"
},
{
"input": "1 1 0\n1 1 1",
"output": "YES"
},
{
"input": "0 0 1\n0 0 0",
"output": "YES"
},
{
"input": "0 0 1\n1 0 0",
"output": "YES"
},
{
"input": "0 0 1\n0 1 0",
"output": "YES"
},
{
"input": "0 0 1\n1 1 0",
"output": "NO"
},
{
"input": "0 0 1\n1 0 1",
"output": "YES"
},
{
"input": "0 0 1\n0 1 1",
"output": "YES"
},
{
"input": "0 0 1\n1 1 1",
"output": "YES"
},
{
"input": "1 0 1\n0 0 0",
"output": "YES"
},
{
"input": "1 0 1\n1 0 0",
"output": "YES"
},
{
"input": "1 0 1\n0 1 0",
"output": "NO"
},
{
"input": "1 0 1\n1 1 0",
"output": "YES"
},
{
"input": "1 0 1\n0 0 1",
"output": "YES"
},
{
"input": "1 0 1\n0 1 1",
"output": "YES"
},
{
"input": "1 0 1\n1 1 1",
"output": "YES"
},
{
"input": "0 1 1\n0 0 0",
"output": "YES"
},
{
"input": "0 1 1\n1 0 0",
"output": "NO"
},
{
"input": "0 1 1\n0 1 0",
"output": "YES"
},
{
"input": "0 1 1\n1 1 0",
"output": "YES"
},
{
"input": "0 1 1\n0 0 1",
"output": "YES"
},
{
"input": "0 1 1\n1 0 1",
"output": "YES"
},
{
"input": "0 1 1\n1 1 1",
"output": "YES"
},
{
"input": "1 1 1\n0 0 0",
"output": "NO"
},
{
"input": "1 1 1\n1 0 0",
"output": "YES"
},
{
"input": "1 1 1\n0 1 0",
"output": "YES"
},
{
"input": "1 1 1\n1 1 0",
"output": "YES"
},
{
"input": "1 1 1\n0 0 1",
"output": "YES"
},
{
"input": "1 1 1\n1 0 1",
"output": "YES"
},
{
"input": "1 1 1\n0 1 1",
"output": "YES"
}
] | 218 | 0 | 3.9455 | 3,467 |
936 | Save Energy! | [
"binary search",
"implementation",
"math"
] | null | null | Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on.
During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs *t* minutes to be cooked on the stove, if it is turned on, and 2*t* minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. | The single line contains three integers *k*, *d* and *t* (1<=β€<=*k*,<=*d*,<=*t*<=β€<=1018). | Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10<=-<=9.
Namely, let's assume that your answer is *x* and the answer of the jury is *y*. The checker program will consider your answer correct if . | [
"3 2 6\n",
"4 2 20\n"
] | [
"6.5\n",
"20.0\n"
] | In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cce5d3f2f46552034d5ae5d487725705429ec7a5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a10fa55d1324328f9ba60c9343ed0ecb0506d678.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, after four minutes the chicken will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6fcc8bd6c2188b260d9d18e7b6c9e3908848df71.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a86c8e9632089279245fff912c077126c4e704.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes. | [
{
"input": "3 2 6",
"output": "6.5"
},
{
"input": "4 2 20",
"output": "20.0"
},
{
"input": "8 10 9",
"output": "10.0"
},
{
"input": "43 50 140",
"output": "150.5"
},
{
"input": "251 79 76",
"output": "76.0"
},
{
"input": "892 67 1000",
"output": "1023.0"
},
{
"input": "1000 1000 1000",
"output": "1000.0"
},
{
"input": "87 4 1000",
"output": "1005.5"
},
{
"input": "1 629 384378949109878497",
"output": "767537647587662141"
},
{
"input": "2124 6621 12695",
"output": "19018"
},
{
"input": "27548 68747 111",
"output": "111.0"
},
{
"input": "74974 46016 1000000000",
"output": "1102134775.0"
},
{
"input": "223 844 704",
"output": "1014.5"
},
{
"input": "1 558 743",
"output": "1483"
},
{
"input": "43 387 402",
"output": "718"
},
{
"input": "972 2 763",
"output": "763.0"
},
{
"input": "330 167 15",
"output": "15.0"
},
{
"input": "387 43 650",
"output": "650.0"
},
{
"input": "1 314 824",
"output": "1642"
},
{
"input": "2 4 18",
"output": "24.0"
},
{
"input": "3 5 127",
"output": "158.0"
},
{
"input": "3260 4439 6837",
"output": "7426.5"
},
{
"input": "3950 7386 195",
"output": "195.0"
},
{
"input": "18036 47899 1000000000",
"output": "1452914012"
},
{
"input": "29 46 1000000000",
"output": "1226666661.0"
},
{
"input": "403 957 1000000000000000000",
"output": "1407352941176470446"
},
{
"input": "999999999999999999 1000000000000000000 1000000000000000000",
"output": "1000000000000000000.5"
},
{
"input": "9 1000000000000000000 1000000000000000000",
"output": "1999999999999999982"
},
{
"input": "1 2 1000000000000000000",
"output": "1333333333333333333.0"
},
{
"input": "2 5 1000000000000000000",
"output": "1428571428571428571.0"
},
{
"input": "81413279254461199 310548139128293806 1000000000000000000",
"output": "1572837149684581517.5"
},
{
"input": "6 3 417701740543616353",
"output": "417701740543616353.0"
},
{
"input": "17 68 4913",
"output": "7854"
},
{
"input": "68 17 4913",
"output": "4913.0"
},
{
"input": "121 395 621154158314692955",
"output": "950991831528308936"
},
{
"input": "897 443 134730567336441375",
"output": "160877739434079591.0"
},
{
"input": "200 10 979220166595737684",
"output": "979220166595737684.0"
},
{
"input": "740 251 930540301905511549",
"output": "938642796161889076.5"
},
{
"input": "4 232 801899894850800409",
"output": "1576616742418522838"
},
{
"input": "472 499 166288453006087540",
"output": "170912333779686266.5"
},
{
"input": "42 9 1000000000000000000",
"output": "1034482758620689654.0"
},
{
"input": "312 93 1000000000000000000",
"output": "1087719298245614020.0"
},
{
"input": "1000 1000 1000000000000000000",
"output": "1000000000000000000.0"
},
{
"input": "6000 1000 1000000000",
"output": "1000000000.0"
},
{
"input": "9999999999 33333 1000000000",
"output": "1000000000.0"
},
{
"input": "33333 9999999999 1000000000",
"output": "1999966667"
},
{
"input": "25441360464 2658201820 1000000000",
"output": "1000000000.0"
},
{
"input": "20958318104 46685 253251869",
"output": "253251869.0"
},
{
"input": "963276084 698548036 1000000000",
"output": "1036723916"
},
{
"input": "574520976350867177 413897686591532160 1000000000000000000",
"output": "1126637198416098571.5"
},
{
"input": "575556838390916379 15 1000000000000000000",
"output": "1000000000000000003.0"
},
{
"input": "1000000000000000000 1000000000000000000 1000000000000000000",
"output": "1000000000000000000.0"
},
{
"input": "1 1000000000000000000 1000000000000000000",
"output": "1999999999999999998"
},
{
"input": "8 1000000000000000000 1000000000000000000",
"output": "1999999999999999984"
},
{
"input": "1 976958144546785462 1000000000000000000",
"output": "1999999999999999997"
},
{
"input": "3 10 1000000000000000000",
"output": "1538461538461538461.0"
},
{
"input": "312200625484460654 543737694709247394 1000000000000000000",
"output": "1231537069224786740.0"
},
{
"input": "2 99 53",
"output": "102"
},
{
"input": "900000000000000000 1 1234",
"output": "1234.0"
}
] | 77 | 0 | 0 | 3,473 |
|
961 | Tufurama | [
"data structures"
] | null | null | One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused β what if he decides to rewatch the entire series someday and won't be able to find the right episodes to watch? Polycarp now wants to count the number of times he will be forced to search for an episode using some different method.
TV series have *n* seasons (numbered 1 through *n*), the *i*-th season has *a**i* episodes (numbered 1 through *a**i*). Polycarp thinks that if for some pair of integers *x* and *y* (*x*<=<<=*y*) exist both season *x* episode *y* and season *y* episode *x* then one of these search queries will include the wrong results. Help Polycarp to calculate the number of such pairs! | The first line contains one integer *n* (1<=<=β€<=*n*<=<=β€<=<=2Β·105) β the number of seasons.
The second line contains *n* integers separated by space *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β number of episodes in each season. | Print one integer β the number of pairs *x* and *y* (*x*<=<<=*y*) such that there exist both season *x* episode *y* and season *y* episode *x*. | [
"5\n1 2 3 4 5\n",
"3\n8 12 7\n",
"3\n3 2 1\n"
] | [
"0\n",
"3\n",
"2\n"
] | Possible pairs in the second example:
1. *x*β=β1, *y*β=β2 (season 1 episode 2 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 2 episode 1); 1. *x*β=β2, *y*β=β3 (season 2 episode 3 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 3 episode 2); 1. *x*β=β1, *y*β=β3 (season 1 episode 3 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 3 episode 1).
In the third example:
1. *x*β=β1, *y*β=β2 (season 1 episode 2 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 2 episode 1); 1. *x*β=β1, *y*β=β3 (season 1 episode 3 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 3 episode 1). | [
{
"input": "5\n1 2 3 4 5",
"output": "0"
},
{
"input": "3\n8 12 7",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "5\n2 3 4 5 6",
"output": "4"
},
{
"input": "8\n7 2 6 6 5 1 4 9",
"output": "9"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "45"
},
{
"input": "1\n1",
"output": "0"
}
] | 655 | 22,528,000 | 3 | 3,474 |
|
417 | Football | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into *n* teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member β Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.
Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly *k* times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table. | The first line contains two integers β *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=1000). | In the first line print an integer *m* β number of the played games. The following *m* lines should contain the information about all the matches, one match per line. The *i*-th line should contain two integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*; *a**i*<=β <=*b**i*). The numbers *a**i* and *b**i* mean, that in the *i*-th match the team with number *a**i* won against the team with number *b**i*. You can assume, that the teams are numbered from 1 to *n*.
If a tournir that meets the conditions of the problem does not exist, then print -1. | [
"3 1\n"
] | [
"3\n1 2\n2 3\n3 1\n"
] | none | [
{
"input": "3 1",
"output": "3\n1 2\n2 3\n3 1"
},
{
"input": "7 3",
"output": "21\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n3 6\n4 5\n4 6\n4 7\n5 6\n5 7\n5 1\n6 7\n6 1\n6 2\n7 1\n7 2\n7 3"
},
{
"input": "4 1",
"output": "4\n1 2\n2 3\n3 4\n4 1"
},
{
"input": "5 2",
"output": "10\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 1\n5 1\n5 2"
},
{
"input": "5 2",
"output": "10\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 1\n5 1\n5 2"
},
{
"input": "11 6",
"output": "-1"
},
{
"input": "11 5",
"output": "55\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n4 8\n4 9\n5 6\n5 7\n5 8\n5 9\n5 10\n6 7\n6 8\n6 9\n6 10\n6 11\n7 8\n7 9\n7 10\n7 11\n7 1\n8 9\n8 10\n8 11\n8 1\n8 2\n9 10\n9 11\n9 1\n9 2\n9 3\n10 11\n10 1\n10 2\n10 3\n10 4\n11 1\n11 2\n11 3\n11 4\n11 5"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "2 1",
"output": "-1"
},
{
"input": "3 1",
"output": "3\n1 2\n2 3\n3 1"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "3 2",
"output": "-1"
},
{
"input": "531 265",
"output": "140715\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
},
{
"input": "775 388",
"output": "-1"
},
{
"input": "648 581",
"output": "-1"
},
{
"input": "57 13",
"output": "741\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n5 12\n5 13\n5 14\n5 15\n5 16\n5 17\n5 18\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n6 13\n6 14\n6 15\n6 16\n6 17\n6 18\n6 19\n7 8\n7 9\n7 10\n7 11\n7 12\n7 13\n7 14\n7 15\n7 16\n7 17\n7 18\n7 19\n7..."
},
{
"input": "131 65",
"output": "8515\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24..."
},
{
"input": "609 305",
"output": "-1"
},
{
"input": "197 182",
"output": "-1"
},
{
"input": "248 54",
"output": "13392\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 3..."
},
{
"input": "137 68",
"output": "9316\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21..."
},
{
"input": "47 24",
"output": "-1"
},
{
"input": "947 868",
"output": "-1"
},
{
"input": "205 50",
"output": "10250\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 3..."
},
{
"input": "863 431",
"output": "371953\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
},
{
"input": "445 223",
"output": "-1"
},
{
"input": "786 393",
"output": "-1"
},
{
"input": "122 52",
"output": "6344\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37..."
},
{
"input": "629 314",
"output": "197506\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
},
{
"input": "571 286",
"output": "-1"
},
{
"input": "980 680",
"output": "-1"
},
{
"input": "869 239",
"output": "207691\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
},
{
"input": "999 499",
"output": "498501\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
},
{
"input": "999 500",
"output": "-1"
},
{
"input": "1000 751",
"output": "-1"
},
{
"input": "1000 162",
"output": "162000\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
},
{
"input": "1000 936",
"output": "-1"
},
{
"input": "1000 178",
"output": "178000\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
},
{
"input": "1000 499",
"output": "499000\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
},
{
"input": "999 499",
"output": "498501\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "2 1",
"output": "-1"
},
{
"input": "4 2",
"output": "-1"
},
{
"input": "6 3",
"output": "-1"
},
{
"input": "10 5",
"output": "-1"
},
{
"input": "999 2",
"output": "1998\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 6\n5 6\n5 7\n6 7\n6 8\n7 8\n7 9\n8 9\n8 10\n9 10\n9 11\n10 11\n10 12\n11 12\n11 13\n12 13\n12 14\n13 14\n13 15\n14 15\n14 16\n15 16\n15 17\n16 17\n16 18\n17 18\n17 19\n18 19\n18 20\n19 20\n19 21\n20 21\n20 22\n21 22\n21 23\n22 23\n22 24\n23 24\n23 25\n24 25\n24 26\n25 26\n25 27\n26 27\n26 28\n27 28\n27 29\n28 29\n28 30\n29 30\n29 31\n30 31\n30 32\n31 32\n31 33\n32 33\n32 34\n33 34\n33 35\n34 35\n34 36\n35 36\n35 37\n36 37\n36 38\n37 38\n37 39\n38 39\n38 40\n39 40\n..."
},
{
"input": "1000 490",
"output": "490000\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1..."
}
] | 1,000 | 307,200 | 0 | 3,475 |
|
427 | Prison Transfer | [
"data structures",
"implementation"
] | null | null | The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city.
For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the *c* prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
- The chosen *c* prisoners has to form a contiguous segment of prisoners. - Any of the chosen prisoner's crime level should not be greater then *t*. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the *c* prisoners. | The first line of input will contain three space separated integers *n*Β (1<=β€<=*n*<=β€<=2Β·105), *t*Β (0<=β€<=*t*<=β€<=109) and *c*Β (1<=β€<=*c*<=β€<=*n*). The next line will contain *n* space separated integers, the *i**th* integer is the severity *i**th* prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. | Print a single integer β the number of ways you can choose the *c* prisoners. | [
"4 3 3\n2 3 1 1\n",
"1 1 1\n2\n",
"11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n"
] | [
"2\n",
"0\n",
"6\n"
] | none | [
{
"input": "4 3 3\n2 3 1 1",
"output": "2"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "11 4 2\n2 2 0 7 3 2 2 4 9 1 4",
"output": "6"
},
{
"input": "57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 1 9 6",
"output": "0"
},
{
"input": "2 228885628 1\n90897004 258427916",
"output": "1"
},
{
"input": "3 1 1\n1 2 1",
"output": "2"
},
{
"input": "3 3 3\n3 2 3",
"output": "1"
},
{
"input": "4 2 2\n1 3 3 2",
"output": "0"
},
{
"input": "1 228 1\n1",
"output": "1"
}
] | 0 | 0 | -1 | 3,486 |
|
39 | Pacifist frogs | [
"implementation"
] | F. Pacifist frogs | 2 | 64 | Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much.
One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to *n* and the number of a hill is equal to the distance in meters between it and the island. The distance between the *n*-th hill and the shore is also 1 meter.
Thumbelina is too small to make such jumps. Fortunately, a family of frogs living in the swamp suggests to help her. Each frog agrees to give Thumbelina a ride but Thumbelina should choose only one frog. Each frog has a certain jump length. If Thumbelina agrees to accept help from a frog whose jump length is *d*, the frog will jump from the island on the hill *d*, then β on the hill 2*d*, then 3*d* and so on until they get to the shore (i.e. find itself beyond the hill *n*).
However, there is one more problem: mosquitoes also live in the swamp. At the moment they have a siesta, and they are having a nap on some hills. If the frog jumps on a hill with a mosquito the frog will smash it. The frogs Thumbelina has met are pacifists, so they will find the death of each mosquito very much sad. Help Thumbelina choose a frog that will bring her to the shore and smash as small number of mosquitoes as possible. | The first line contains three integers *n*, *m* and *k* (1<=β€<=*n*<=β€<=109, 1<=β€<=*m*,<=*k*<=β€<=100) β the number of hills, frogs and mosquitoes respectively. The second line contains *m* integers *d**i* (1<=β€<=*d**i*<=β€<=109) β the lengths of the frogsβ jumps. The third line contains *k* integers β the numbers of the hills on which each mosquito is sleeping. No more than one mosquito can sleep on each hill. The numbers in the lines are separated by single spaces. | In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line β their numbers in increasing order separated by spaces. The frogs are numbered from 1 to *m* in the order of the jump length given in the input data. | [
"5 3 5\n2 3 4\n1 2 3 4 5\n",
"1000000000 2 3\n2 5\n999999995 999999998 999999996\n"
] | [
"2\n2 3\n",
"1\n2\n"
] | none | [
{
"input": "5 3 5\n2 3 4\n1 2 3 4 5",
"output": "2\n2 3"
},
{
"input": "1000000000 2 3\n2 5\n999999995 999999998 999999996",
"output": "1\n2"
},
{
"input": "1 1 1\n1\n1",
"output": "1\n1"
},
{
"input": "2 2 1\n2 1\n1",
"output": "1\n1"
},
{
"input": "3 2 2\n2 4\n3 2",
"output": "1\n2"
},
{
"input": "10 3 6\n5 2 8\n5 6 7 8 9 10",
"output": "1\n3"
},
{
"input": "10 10 9\n10 9 8 7 6 5 4 3 2 1\n10 9 8 7 5 4 3 2 1",
"output": "1\n5"
},
{
"input": "20 3 5\n2 3 5\n2 5 6 10 15",
"output": "1\n2"
},
{
"input": "20 4 8\n1 2 3 4\n2 4 6 8 10 12 14 16",
"output": "1\n3"
},
{
"input": "10 5 5\n1 5 3 5 1\n1 6 5 7 2",
"output": "3\n2 3 4"
},
{
"input": "20 10 5\n1 12 6 11 9 21 15 16 8 9\n11 13 15 2 1",
"output": "7\n2 3 5 6 8 9 10"
},
{
"input": "20 10 10\n9 8 21 8 7 2 13 17 20 18\n7 16 20 3 6 1 11 18 15 17",
"output": "2\n3 7"
},
{
"input": "20 10 10\n6 17 14 12 13 15 6 14 16 17\n1 6 16 14 7 8 9 12 10 2",
"output": "4\n2 5 6 10"
},
{
"input": "100 30 30\n25 34 81 32 96 79 36 21 53 15 51 69 78 99 60 2 80 37 61 70 32 31 31 6 7 38 95 70 81 39\n1 50 75 8 90 69 13 57 6 4 60 19 94 52 45 42 95 88 21 22 96 2 56 61 31 78 7 62 68 72",
"output": "11\n3 6 9 11 14 17 18 20 26 28 29"
},
{
"input": "200 35 67\n152 112 102 46 54 189 56 76 10 39 157 6 84 188 122 117 51 163 6 50 195 34 44 178 28 32 100 67 74 48 88 100 91 50 91\n126 68 138 157 92 128 183 36 175 49 168 198 116 20 31 88 61 46 12 179 137 130 185 5 171 96 184 85 37 147 50 75 93 103 160 10 120 140 59 98 131 124 121 190 169 141 165 39 47 28 90 139 148 119 73 6 51 94 21 52 89 35 97 79 3 13 142",
"output": "17\n1 2 3 5 6 8 14 15 16 18 21 24 27 28 32 33 35"
},
{
"input": "200 72 29\n201 145 169 163 32 126 131 71 26 130 2 61 110 17 179 114 79 30 192 91 141 70 101 119 185 66 72 76 164 144 106 162 122 146 119 181 184 61 131 131 140 152 60 65 183 154 32 33 108 77 29 102 67 5 125 26 126 104 20 89 183 21 126 195 198 24 123 173 135 164 141 32\n160 65 136 22 194 110 155 138 92 118 87 40 49 191 190 99 157 3 23 17 34 123 31 81 67 86 196 45 109",
"output": "59\n1 2 3 4 6 7 8 9 10 12 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 45 46 49 50 52 55 56 57 58 60 61 62 63 64 65 66 68 69 70 71"
},
{
"input": "500 46 46\n363 441 170 289 389 394 488 72 332 285 445 185 221 183 397 175 98 192 202 16 123 436 336 260 212 229 459 473 66 19 445 153 476 234 396 159 289 137 331 18 268 224 71 133 196 7\n454 64 417 129 95 162 496 300 234 359 224 354 334 155 191 82 35 319 244 126 292 108 321 93 77 311 107 487 121 431 235 100 445 68 338 467 133 307 4 220 245 84 468 141 436 363",
"output": "35\n2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 21 23 24 25 26 27 28 29 32 33 35 36 37 38 39 41 43 45"
},
{
"input": "1000 19 27\n656 162 264 790 579 786 877 998 516 247 650 150 858 281 279 549 354 353 533\n349 411 1 248 22 649 726 382 423 832 172 864 17 658 840 572 564 287 800 919 500 575 461 40 1000 383 624",
"output": "19\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19"
}
] | 154 | 2,150,400 | 3.945478 | 3,488 |
269 | Greenhouse Effect | [
"dp"
] | null | null | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.
Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species numbered from 1 to *m*. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.
Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange *m*<=-<=1 borders that would divide the greenhouse into *m* sections numbered from 1 to *m* from left to right with each section housing a single species. He is free to place the borders, but in the end all of the *i*-th species plants must reside in *i*-th section from the left.
Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | The first line of input contains two space-separated integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=5000, *n*<=β₯<=*m*), the number of plants and the number of different species. Each of the following *n* lines contain two space-separated numbers: one integer number *s**i* (1<=β€<=*s**i*<=β€<=*m*), and one real number *x**i* (0<=β€<=*x**i*<=β€<=109), the species and position of the *i*-th plant. Each *x**i* will contain no more than 6 digits after the decimal point.
It is guaranteed that all *x**i* are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their *x**i* coordinates (*x**i*<=<<=*x**i*<=+<=1,<=1<=β€<=*i*<=<<=*n*). | Output a single integer β the minimum number of plants to be replanted. | [
"3 2\n2 1\n1 2.0\n1 3.100\n",
"3 3\n1 5.0\n2 5.5\n3 6.0\n",
"6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.
In the second test case, the species are already in the correct order, so no replanting is needed. | [
{
"input": "3 2\n2 1\n1 2.0\n1 3.100",
"output": "1"
},
{
"input": "3 3\n1 5.0\n2 5.5\n3 6.0",
"output": "0"
},
{
"input": "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125",
"output": "2"
},
{
"input": "1 1\n1 0",
"output": "0"
},
{
"input": "8 2\n1 0.000000\n1 1.000000\n1 2.000000\n2 2.000001\n1 999999997.000000\n2 999999998.000000\n2 999999999.999999\n2 1000000000.000000",
"output": "1"
},
{
"input": "15 5\n4 6.039627\n2 7.255149\n2 14.469785\n2 15.108572\n4 22.570081\n5 26.642253\n5 32.129202\n5 44.288220\n5 53.231909\n5 60.548042\n4 62.386581\n2 77.828816\n1 87.998512\n3 96.163559\n2 99.412872",
"output": "6"
},
{
"input": "10 7\n4 70882.412953\n1 100461.912159\n3 100813.254090\n7 121632.112636\n2 424085.529781\n6 510966.713362\n6 543441.105338\n7 680094.776949\n1 721404.212606\n5 838754.272757",
"output": "5"
},
{
"input": "5 5\n5 0\n4 1\n3 2\n2 3\n1 4",
"output": "4"
},
{
"input": "12 5\n2 0\n2 1\n3 2\n3 3\n3 4\n1 5\n5 6\n3 7\n3 8\n3 9\n4 999999999\n4 1000000000",
"output": "2"
},
{
"input": "3 3\n2 0\n1 1\n3 2",
"output": "1"
},
{
"input": "3 3\n3 0\n1 1\n2 2",
"output": "1"
},
{
"input": "4 2\n1 10\n2 20\n1 30\n2 40",
"output": "1"
},
{
"input": "20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.999990\n2 999999999.999991\n3 999999999.999992\n4 999999999.999993\n5 999999999.999994\n6 999999999.999995\n7 999999999.999996\n8 999999999.999997\n9 999999999.999998\n10 999999999.999999",
"output": "9"
},
{
"input": "12 4\n3 0\n3 1\n3 2\n3 3\n3 4\n1 5\n1 6\n2 7\n4 8\n4 9\n2 10\n3 11",
"output": "5"
},
{
"input": "16 2\n1 0\n1 1\n2 2\n2 3\n2 4\n2 5\n1 6\n1 7\n2 8\n2 9\n1 10\n1 11\n2 12\n2 13\n2 14\n2 15",
"output": "4"
},
{
"input": "10 10\n1 100\n2 101\n3 102\n5 103\n9 1000\n8 10000\n6 100000\n7 1000000\n4 10000000\n10 100000000",
"output": "3"
},
{
"input": "10 6\n5 50837.108162\n3 111993.624183\n1 207268.919250\n6 567963.419694\n1 621364.247371\n2 630118.065585\n1 642135.221942\n6 642673.884754\n5 647004.198361\n4 735196.102629",
"output": "6"
},
{
"input": "20 2\n1 39277.770446\n1 131242.472574\n2 131745.437889\n1 261920.593789\n2 323611.256365\n1 341693.666730\n2 378611.498102\n2 568433.562368\n1 667757.789581\n1 674662.040626\n2 690065.099817\n2 724737.429934\n1 774858.513301\n2 783681.914774\n1 808327.402925\n2 867697.070403\n1 880911.396984\n1 929807.064277\n2 942269.265950\n1 999503.792481",
"output": "9"
},
{
"input": "20 15\n6 8719.787178\n10 13066.663722\n15 58623.690996\n9 184321.819759\n3 227999.294560\n2 279836.330518\n9 282806.308675\n8 311056.507765\n1 312315.562927\n5 459200.373445\n14 563454.265947\n7 647364.984868\n13 679761.613732\n4 684192.647497\n1 733119.607626\n7 748637.778398\n12 828048.945890\n11 893690.736585\n8 965323.895167\n5 967641.708962",
"output": "15"
},
{
"input": "15 3\n1 0\n2 1\n3 2\n1 3\n2 4\n3 5\n1 6\n2 7\n3 8\n1 9\n2 10\n3 11\n1 12\n2 13\n3 14",
"output": "8"
},
{
"input": "10 2\n2 0\n2 1\n2 2\n2 3\n2 4\n1 5\n1 6\n1 7\n1 8\n1 9",
"output": "5"
},
{
"input": "11 3\n2 0\n2 1\n2 2\n2 3\n2 4\n3 5\n1 6\n1 7\n1 8\n1 9\n1 10",
"output": "5"
}
] | 30 | 0 | -1 | 3,496 |
|
346 | Alice and Bob | [
"games",
"math",
"number theory"
] | null | null | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers *x* and *y* from the set, such that the set doesn't contain their absolute difference |*x*<=-<=*y*|. Then this player adds integer |*x*<=-<=*y*| to the set (so, the size of the set increases by one).
If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first. | The first line contains an integer *n* (2<=β€<=*n*<=β€<=100) β the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β the elements of the set. | Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n"
] | Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | [
{
"input": "2\n2 3",
"output": "Alice"
},
{
"input": "2\n5 3",
"output": "Alice"
},
{
"input": "3\n5 6 7",
"output": "Bob"
},
{
"input": "10\n72 96 24 66 6 18 12 30 60 48",
"output": "Bob"
},
{
"input": "10\n78 66 6 60 18 84 36 96 72 48",
"output": "Bob"
},
{
"input": "10\n98 63 42 56 14 77 70 35 84 21",
"output": "Bob"
},
{
"input": "2\n1 1000000000",
"output": "Bob"
},
{
"input": "2\n1000000000 999999999",
"output": "Bob"
},
{
"input": "3\n2 4 6",
"output": "Bob"
},
{
"input": "2\n4 6",
"output": "Alice"
},
{
"input": "2\n2 6",
"output": "Alice"
},
{
"input": "2\n6 2",
"output": "Alice"
},
{
"input": "10\n100000000 200000000 300000000 400000000 500000000 600000000 700000000 800000000 900000000 1000000000",
"output": "Bob"
},
{
"input": "2\n1 2",
"output": "Bob"
},
{
"input": "10\n1 999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991",
"output": "Alice"
},
{
"input": "3\n6 14 21",
"output": "Bob"
},
{
"input": "3\n4 12 18",
"output": "Bob"
},
{
"input": "4\n2 3 15 30",
"output": "Bob"
},
{
"input": "2\n10 4",
"output": "Alice"
}
] | 186 | 0 | 0 | 3,501 |
|
707 | Pythagorean Triples | [
"math",
"number theory"
] | null | null | Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, triples (3,<=4,<=5), (5,<=12,<=13) and (6,<=8,<=10) are Pythagorean triples.
Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.
Katya had no problems with completing this task. Will you do the same? | The only line of the input contains single integer *n* (1<=β€<=*n*<=β€<=109)Β β the length of some side of a right triangle. | Print two integers *m* and *k* (1<=β€<=*m*,<=*k*<=β€<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them. | [
"3\n",
"6\n",
"1\n",
"17\n",
"67\n"
] | [
"4 5",
"8 10",
"-1",
"144 145",
"2244 2245"
] | Illustration for the first sample. | [
{
"input": "3",
"output": "4 5"
},
{
"input": "6",
"output": "8 10"
},
{
"input": "1",
"output": "-1"
},
{
"input": "17",
"output": "144 145"
},
{
"input": "67",
"output": "2244 2245"
},
{
"input": "10",
"output": "24 26"
},
{
"input": "14",
"output": "48 50"
},
{
"input": "22",
"output": "120 122"
},
{
"input": "23",
"output": "264 265"
},
{
"input": "246",
"output": "15128 15130"
},
{
"input": "902",
"output": "203400 203402"
},
{
"input": "1000000000",
"output": "1250000000 750000000"
},
{
"input": "1998",
"output": "998000 998002"
},
{
"input": "2222222",
"output": "1234567654320 1234567654322"
},
{
"input": "2222226",
"output": "1234572098768 1234572098770"
},
{
"input": "1111110",
"output": "308641358024 308641358026"
},
{
"input": "9999998",
"output": "24999990000000 24999990000002"
},
{
"input": "1024",
"output": "1280 768"
},
{
"input": "8388608",
"output": "10485760 6291456"
},
{
"input": "4",
"output": "5 3"
},
{
"input": "8",
"output": "10 6"
},
{
"input": "16",
"output": "20 12"
},
{
"input": "492",
"output": "615 369"
},
{
"input": "493824",
"output": "617280 370368"
},
{
"input": "493804",
"output": "617255 370353"
},
{
"input": "493800",
"output": "617250 370350"
},
{
"input": "2048",
"output": "2560 1536"
},
{
"input": "8388612",
"output": "10485765 6291459"
},
{
"input": "44",
"output": "55 33"
},
{
"input": "444",
"output": "555 333"
},
{
"input": "4444",
"output": "5555 3333"
},
{
"input": "44444",
"output": "55555 33333"
},
{
"input": "444444",
"output": "555555 333333"
},
{
"input": "4444444",
"output": "5555555 3333333"
},
{
"input": "100000000",
"output": "125000000 75000000"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "4 5"
},
{
"input": "5",
"output": "12 13"
},
{
"input": "7",
"output": "24 25"
},
{
"input": "9",
"output": "40 41"
},
{
"input": "11",
"output": "60 61"
},
{
"input": "13",
"output": "84 85"
},
{
"input": "15",
"output": "112 113"
},
{
"input": "19",
"output": "180 181"
},
{
"input": "111",
"output": "6160 6161"
},
{
"input": "113",
"output": "6384 6385"
},
{
"input": "115",
"output": "6612 6613"
},
{
"input": "117",
"output": "6844 6845"
},
{
"input": "119",
"output": "7080 7081"
},
{
"input": "111111",
"output": "6172827160 6172827161"
},
{
"input": "111113",
"output": "6173049384 6173049385"
},
{
"input": "111115",
"output": "6173271612 6173271613"
},
{
"input": "111117",
"output": "6173493844 6173493845"
},
{
"input": "111119",
"output": "6173716080 6173716081"
},
{
"input": "9999993",
"output": "49999930000024 49999930000025"
},
{
"input": "9999979",
"output": "49999790000220 49999790000221"
},
{
"input": "9999990",
"output": "24999950000024 24999950000026"
},
{
"input": "9999991",
"output": "49999910000040 49999910000041"
},
{
"input": "9999992",
"output": "12499990 7499994"
},
{
"input": "9999973",
"output": "49999730000364 49999730000365"
},
{
"input": "9999994",
"output": "24999970000008 24999970000010"
},
{
"input": "9999995",
"output": "49999950000012 49999950000013"
},
{
"input": "9999996",
"output": "12499995 7499997"
},
{
"input": "9999997",
"output": "49999970000004 49999970000005"
},
{
"input": "9999978",
"output": "24999890000120 24999890000122"
},
{
"input": "99999993",
"output": "4999999300000024 4999999300000025"
},
{
"input": "99999979",
"output": "4999997900000220 4999997900000221"
},
{
"input": "99999990",
"output": "2499999500000024 2499999500000026"
},
{
"input": "99999991",
"output": "4999999100000040 4999999100000041"
},
{
"input": "99999992",
"output": "124999990 74999994"
},
{
"input": "99999973",
"output": "4999997300000364 4999997300000365"
},
{
"input": "99999994",
"output": "2499999700000008 2499999700000010"
},
{
"input": "99999995",
"output": "4999999500000012 4999999500000013"
},
{
"input": "99999996",
"output": "124999995 74999997"
},
{
"input": "99999997",
"output": "4999999700000004 4999999700000005"
},
{
"input": "99999978",
"output": "2499998900000120 2499998900000122"
},
{
"input": "987654323",
"output": "487730530870294164 487730530870294165"
},
{
"input": "2",
"output": "-1"
},
{
"input": "4",
"output": "5 3"
},
{
"input": "8",
"output": "10 6"
},
{
"input": "64",
"output": "80 48"
},
{
"input": "999999999",
"output": "499999999000000000 499999999000000001"
},
{
"input": "16",
"output": "20 12"
},
{
"input": "999999937",
"output": "499999937000001984 499999937000001985"
},
{
"input": "999999998",
"output": "249999999000000000 249999999000000002"
},
{
"input": "433494437",
"output": "93958713454973484 93958713454973485"
},
{
"input": "484916147",
"output": "117571834810662804 117571834810662805"
},
{
"input": "999999929",
"output": "499999929000002520 499999929000002521"
},
{
"input": "982451653",
"output": "482605625241216204 482605625241216205"
},
{
"input": "2048",
"output": "2560 1536"
}
] | 62 | 0 | 3 | 3,502 |
|
229 | Planets | [
"binary search",
"data structures",
"graphs",
"shortest paths"
] | null | null | Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet.
Overall the galaxy has *n* planets, indexed with numbers from 1 to *n*. Jack is on the planet with index 1, and Apophis will land on the planet with index *n*. Jack can move between some pairs of planets through stargates (he can move in both directions); the transfer takes a positive, and, perhaps, for different pairs of planets unequal number of seconds. Jack begins his journey at time 0.
It can be that other travellers are arriving to the planet where Jack is currently located. In this case, Jack has to wait for exactly 1 second before he can use the stargate. That is, if at time *t* another traveller arrives to the planet, Jack can only pass through the stargate at time *t*<=+<=1, unless there are more travellers arriving at time *t*<=+<=1 to the same planet.
Knowing the information about travel times between the planets, and the times when Jack would not be able to use the stargate on particular planets, determine the minimum time in which he can get to the planet with index *n*. | The first line contains two space-separated integers: *n* (2<=β€<=*n*<=β€<=105), the number of planets in the galaxy, and *m* (0<=β€<=*m*<=β€<=105) β the number of pairs of planets between which Jack can travel using stargates. Then *m* lines follow, containing three integers each: the *i*-th line contains numbers of planets *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*, *a**i*<=β <=*b**i*), which are connected through stargates, and the integer transfer time (in seconds) *c**i* (1<=β€<=*c**i*<=β€<=104) between these planets. It is guaranteed that between any pair of planets there is at most one stargate connection.
Then *n* lines follow: the *i*-th line contains an integer *k**i* (0<=β€<=*k**i*<=β€<=105) that denotes the number of moments of time when other travellers arrive to the planet with index *i*. Then *k**i* distinct space-separated integers *t**ij* (0<=β€<=*t**ij*<=<<=109) follow, sorted in ascending order. An integer *t**ij* means that at time *t**ij* (in seconds) another traveller arrives to the planet *i*. It is guaranteed that the sum of all *k**i* does not exceed 105. | Print a single number β the least amount of time Jack needs to get from planet 1 to planet *n*. If Jack can't get to planet *n* in any amount of time, print number -1. | [
"4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n3 4 3\n0\n1 3\n2 3 4\n0\n",
"3 1\n1 2 3\n0\n1 3\n0\n"
] | [
"7\n",
"-1\n"
] | In the first sample Jack has three ways to go from planet 1. If he moves to planet 4 at once, he spends 8 seconds. If he transfers to planet 3, he spends 3 seconds, but as other travellers arrive to planet 3 at time 3 and 4, he can travel to planet 4 only at time 5, thus spending 8 seconds in total. But if Jack moves to planet 2, and then β to planet 4, then he spends a total of only 2β+β5β=β7 seconds.
In the second sample one can't get from planet 1 to planet 3 by moving through stargates. | [
{
"input": "4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n3 4 3\n0\n1 3\n2 3 4\n0",
"output": "7"
},
{
"input": "3 1\n1 2 3\n0\n1 3\n0",
"output": "-1"
},
{
"input": "2 1\n1 2 3\n0\n1 3",
"output": "3"
},
{
"input": "2 1\n1 2 3\n1 0\n0",
"output": "4"
},
{
"input": "3 3\n1 2 5\n2 3 6\n1 3 7\n0\n0\n0",
"output": "7"
},
{
"input": "3 3\n1 2 3\n2 3 2\n1 3 7\n0\n0\n0",
"output": "5"
},
{
"input": "2 0\n0\n0",
"output": "-1"
},
{
"input": "3 1\n1 2 3\n1 1\n1 5\n0",
"output": "-1"
},
{
"input": "2 1\n1 2 3\n0\n2 2 4",
"output": "3"
},
{
"input": "2 1\n1 2 1\n0\n0",
"output": "1"
},
{
"input": "2 1\n2 1 10000\n0\n0",
"output": "10000"
},
{
"input": "2 1\n1 2 3\n0\n3 3 4 5",
"output": "3"
},
{
"input": "3 0\n0\n0\n0",
"output": "-1"
},
{
"input": "3 2\n1 2 5\n2 3 7\n2 0 1\n3 4 5 6\n3 11 12 13",
"output": "14"
},
{
"input": "2 1\n1 2 3\n3 0 1 2\n3 5 6 7",
"output": "6"
},
{
"input": "3 3\n1 2 3\n2 3 2\n1 3 7\n0\n4 3 4 5 6\n0",
"output": "7"
},
{
"input": "6 7\n1 2 1\n1 3 8\n2 4 2\n4 3 3\n3 5 4\n4 6 100\n5 6 5\n0\n0\n1 7\n2 3 4\n0\n0",
"output": "17"
},
{
"input": "3 3\n1 2 3\n2 3 2\n1 3 6\n0\n1 3\n0",
"output": "6"
},
{
"input": "7 7\n1 2 1\n2 4 2\n2 3 2\n3 6 2\n6 5 2\n4 5 3\n5 7 7\n0\n0\n0\n3 3 4 5\n0\n0\n0",
"output": "14"
},
{
"input": "7 6\n1 2 1\n1 3 1\n1 4 1\n1 5 1\n1 6 1\n1 7 1\n1 0\n0\n0\n0\n0\n0\n0",
"output": "2"
},
{
"input": "8 10\n1 2 3\n2 8 3\n1 4 1\n4 3 6\n3 7 7\n4 5 5\n5 7 2\n7 8 1\n1 6 8\n6 8 7\n0\n4 1 2 3 4\n0\n0\n0\n0\n0\n0",
"output": "8"
},
{
"input": "7 6\n1 2 1\n1 3 2\n2 4 3\n2 5 4\n3 5 6\n3 6 7\n0\n3 1 2 3\n2 2 3\n0\n2 7 8\n0\n0",
"output": "-1"
}
] | 2,000 | 19,968,000 | 0 | 3,507 |
|
813 | The Tag Game | [
"dfs and similar",
"graphs"
] | null | null | Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree.
Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=β <=1). The moves are made in turns, Bob goes first. In one move one can either stay at the current vertex or travel to the neighbouring one.
The game ends when Alice goes to the same vertex where Bob is standing. Alice wants to minimize the total number of moves and Bob wants to maximize it.
You should write a program which will determine how many moves will the game last. | The first line contains two integer numbers *n* and *x* (2<=β€<=*n*<=β€<=2Β·105, 2<=β€<=*x*<=β€<=*n*).
Each of the next *n*<=-<=1 lines contains two integer numbers *a* and *b* (1<=β€<=*a*,<=*b*<=β€<=*n*) β edges of the tree. It is guaranteed that the edges form a valid tree. | Print the total number of moves Alice and Bob will make. | [
"4 3\n1 2\n2 3\n2 4\n",
"5 2\n1 2\n2 3\n3 4\n2 5\n"
] | [
"4\n",
"6\n"
] | In the first example the tree looks like this:
The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves:
B: stay at vertex 3
A: go to vertex 2
B: stay at vertex 3
A: go to vertex 3
In the second example the tree looks like this:
The moves in the optimal strategy are:
B: go to vertex 3
A: go to vertex 2
B: go to vertex 4
A: go to vertex 3
B: stay at vertex 4
A: go to vertex 4 | [
{
"input": "4 3\n1 2\n2 3\n2 4",
"output": "4"
},
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "6"
},
{
"input": "2 2\n2 1",
"output": "2"
},
{
"input": "3 3\n2 1\n3 1",
"output": "2"
},
{
"input": "3 3\n1 2\n3 2",
"output": "4"
},
{
"input": "10 4\n5 4\n8 3\n4 6\n5 3\n7 9\n1 3\n5 10\n2 9\n9 8",
"output": "8"
},
{
"input": "10 7\n8 7\n2 8\n2 3\n10 6\n4 6\n4 1\n10 5\n7 5\n9 8",
"output": "16"
},
{
"input": "8 3\n2 1\n3 1\n4 3\n5 1\n6 1\n7 1\n8 6",
"output": "4"
},
{
"input": "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 5\n9 7\n10 8\n11 7\n12 7\n13 8\n14 2\n15 10\n16 1\n17 9\n18 14\n19 1\n20 2\n21 8\n22 21\n23 9\n24 6\n25 2\n26 20\n27 5\n28 20\n29 2\n30 10\n31 14\n32 12\n33 15\n34 8",
"output": "12"
}
] | 62 | 0 | 0 | 3,512 |
|
490 | Queue | [
"dsu",
"implementation"
] | null | null | During the lunch break all *n* Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1).
After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task.
Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue. | The first line contains integer *n* (2<=β€<=*n*<=β€<=2Β·105) β the number of students in the queue.
Then *n* lines follow, *i*-th line contains the pair of integers *a**i*,<=*b**i* (0<=β€<=*a**i*,<=*b**i*<=β€<=106), where *a**i* is the ID number of a person in front of a student and *b**i* is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist.
The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order. | Print a sequence of *n* integers *x*1,<=*x*2,<=...,<=*x**n* β the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | [
"4\n92 31\n0 7\n31 0\n7 141\n"
] | [
"92 7 31 141 \n"
] | The picture illustrates the queue for the first sample. | [
{
"input": "4\n92 31\n0 7\n31 0\n7 141",
"output": "92 7 31 141 "
},
{
"input": "2\n0 1\n2 0",
"output": "2 1 "
},
{
"input": "3\n0 2\n1 3\n2 0",
"output": "1 2 3 "
},
{
"input": "4\n101 0\n0 102\n102 100\n103 101",
"output": "103 102 101 100 "
},
{
"input": "5\n0 1\n1 4\n4 0\n3 2\n5 3",
"output": "5 1 3 4 2 "
},
{
"input": "6\n10001 0\n0 10005\n10003 10001\n10002 10000\n10005 10002\n10004 10003",
"output": "10004 10005 10003 10002 10001 10000 "
},
{
"input": "3\n0 743259\n72866 70294\n743259 0",
"output": "72866 743259 70294 "
},
{
"input": "4\n263750 0\n513707 263750\n0 718595\n718595 148112",
"output": "513707 718595 263750 148112 "
},
{
"input": "5\n645873 145459\n638930 82975\n0 645873\n82975 389665\n145459 0",
"output": "638930 645873 82975 145459 389665 "
},
{
"input": "6\n341637 51795\n0 809471\n51795 0\n244669 341637\n852537 508622\n809471 852537",
"output": "244669 809471 341637 852537 51795 508622 "
},
{
"input": "7\n111283 0\n496010 510417\n423431 921854\n510417 111283\n0 496010\n758535 423431\n921854 59208",
"output": "758535 496010 423431 510417 921854 111283 59208 "
},
{
"input": "8\n611412 115521\n114290 712424\n115521 242491\n242491 0\n0 114290\n712424 282922\n282922 589147\n359823 611412",
"output": "359823 114290 611412 712424 115521 282922 242491 589147 "
},
{
"input": "9\n308992 348750\n0 6496\n487447 676506\n874677 985199\n260782 487447\n985199 260782\n348750 0\n570981 308992\n6496 570981",
"output": "874677 6496 985199 570981 260782 308992 487447 348750 676506 "
},
{
"input": "10\n419946 201769\n245945 0\n842799 113073\n836998 245945\n0 794376\n692107 836998\n113073 904403\n904403 987165\n201769 692107\n794376 842799",
"output": "419946 794376 201769 842799 692107 113073 836998 904403 245945 987165 "
},
{
"input": "10\n189071 852255\n227133 652124\n329720 4848\n652124 329720\n0 72517\n943168 0\n72517 544697\n4848 943168\n538963 189071\n544697 538963",
"output": "227133 72517 652124 544697 329720 538963 4848 189071 943168 852255 "
},
{
"input": "2\n0 300000\n1000000 0",
"output": "1000000 300000 "
}
] | 218 | 10,444,800 | -1 | 3,513 |
|
49 | Disposition | [
"constructive algorithms",
"math"
] | C. Disposition | 2 | 256 | Vasya bought the collected works of a well-known Berland poet Petya in *n* volumes. The volumes are numbered from 1 to *n*. He thinks that it does not do to arrange the book simply according to their order. Vasya wants to minimize the number of the dispositionβs divisors β the positive integers *i* such that for at least one *j* (1<=β€<=*j*<=β€<=*n*) is true both: *j* *mod* *i*<==<=0 and at the same time *p*(*j*) *mod* *i*<==<=0, where *p*(*j*) is the number of the tome that stands on the *j*-th place and *mod* is the operation of taking the division remainder. Naturally, one volume can occupy exactly one place and in one place can stand exactly one volume.
Help Vasya β find the volume disposition with the minimum number of divisors. | The first line contains number *n* (1<=β€<=*n*<=β€<=100000) which represents the number of volumes and free places. | Print *n* numbers β the sought disposition with the minimum divisor number. The *j*-th number (1<=β€<=*j*<=β€<=*n*) should be equal to *p*(*j*) β the number of tome that stands on the *j*-th place. If there are several solutions, print any of them. | [
"2\n",
"3\n"
] | [
"2 1 \n",
"1 3 2 \n"
] | none | [
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "5",
"output": "1 3 2 5 4 "
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "1",
"output": "1 "
},
{
"input": "7",
"output": "1 3 2 5 4 7 6 "
},
{
"input": "8",
"output": "2 1 4 3 6 5 8 7 "
},
{
"input": "9",
"output": "1 3 2 5 4 7 6 9 8 "
},
{
"input": "10",
"output": "2 1 4 3 6 5 8 7 10 9 "
},
{
"input": "96",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 "
},
{
"input": "97",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 "
},
{
"input": "98",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 "
},
{
"input": "99",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 "
},
{
"input": "100",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 "
},
{
"input": "9996",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "9997",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "9998",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "9999",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "10000",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "99996",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "99997",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "99998",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "99999",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "100000",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "9149",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "72877",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "52956",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "33035",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "13114",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "93193",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "73273",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "37000",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "17079",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "84653",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "27251",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "53496",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "96093",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
},
{
"input": "22338",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 156..."
},
{
"input": "64935",
"output": "1 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 27 26 29 28 31 30 33 32 35 34 37 36 39 38 41 40 43 42 45 44 47 46 49 48 51 50 53 52 55 54 57 56 59 58 61 60 63 62 65 64 67 66 69 68 71 70 73 72 75 74 77 76 79 78 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 99 98 101 100 103 102 105 104 107 106 109 108 111 110 113 112 115 114 117 116 119 118 121 120 123 122 125 124 127 126 129 128 131 130 133 132 135 134 137 136 139 138 141 140 143 142 145 144 147 146 149 148 151 150 153 152 155 154..."
}
] | 218 | 12,288,000 | 3.922612 | 3,518 |
351 | Jeff and Brackets | [
"dp",
"matrices"
] | null | null | Jeff loves regular bracket sequences.
Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of *nm* brackets. Let's number all brackets of this sequence from 0 to *nm* - 1 from left to right. Jeff knows that he is going to spend *a**i* *mod* *n* liters of ink on the *i*-th bracket of the sequence if he paints it opened and *b**i* *mod* *n* liters if he paints it closed.
You've got sequences *a*, *b* and numbers *n*, *m*. What minimum amount of ink will Jeff need to paint a regular bracket sequence of length *nm*?
Operation *x* *mod* *y* means taking the remainder after dividing number *x* by number *y*. | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=20;Β 1<=β€<=*m*<=β€<=107; *m* is even). The next line contains *n* integers: *a*0, *a*1, ..., *a**n*<=-<=1 (1<=β€<=*a**i*<=β€<=10). The next line contains *n* integers: *b*0, *b*1, ..., *b**n*<=-<=1 (1<=β€<=*b**i*<=β€<=10). The numbers are separated by spaces. | In a single line print the answer to the problem β the minimum required amount of ink in liters. | [
"2 6\n1 2\n2 1\n",
"1 10000000\n2\n3\n"
] | [
"12\n",
"25000000\n"
] | In the first test the optimal sequence is: ()()()()()(), the required number of ink liters is 12. | [
{
"input": "2 6\n1 2\n2 1",
"output": "12"
},
{
"input": "1 10000000\n2\n3",
"output": "25000000"
},
{
"input": "3 184\n3 2 8\n3 9 2",
"output": "1288"
},
{
"input": "4 26\n10 2 5 9\n5 4 2 5",
"output": "444"
},
{
"input": "3 76\n4 7 9\n10 1 1",
"output": "684"
},
{
"input": "3 98\n6 1 9\n10 2 4",
"output": "1127"
},
{
"input": "5 114\n7 5 8 10 10\n2 7 9 4 5",
"output": "3021"
},
{
"input": "1 14\n7\n6",
"output": "91"
},
{
"input": "5 142\n8 7 6 2 2\n8 2 6 1 7",
"output": "2703"
},
{
"input": "1 184\n8\n8",
"output": "1472"
},
{
"input": "2 1900670\n10 3\n9 6",
"output": "22808044"
},
{
"input": "6 17656\n2 7 4 7 7 3\n3 5 3 6 9 10",
"output": "459064"
},
{
"input": "16 3273408\n3 2 8 8 10 1 1 7 1 4 5 7 5 8 10 10\n4 4 3 4 7 9 5 1 7 10 7 2 7 9 4 5",
"output": "186584261"
},
{
"input": "11 4532614\n7 3 4 1 8 3 5 2 8 10 9\n6 10 3 7 5 1 1 8 4 9 7",
"output": "201701323"
},
{
"input": "7 3952828\n1 1 9 3 5 9 2\n3 5 6 2 7 9 4",
"output": "106726356"
},
{
"input": "20 807878\n9 4 2 5 2 7 9 3 4 4 9 2 8 3 8 9 5 7 4 7\n8 4 8 7 10 4 10 6 8 1 7 9 3 10 2 2 6 7 3 9",
"output": "67053877"
},
{
"input": "3 3684044\n8 6 4\n3 1 2",
"output": "38682465"
},
{
"input": "9 7683580\n4 6 8 5 10 6 3 4 7\n6 7 3 10 3 10 1 4 10",
"output": "303501412"
},
{
"input": "10 6007734\n4 7 6 7 4 3 4 7 7 6\n8 9 5 7 6 3 2 2 10 4",
"output": "270348030"
},
{
"input": "7 859320\n10 1 4 9 2 5 5\n5 10 3 6 6 5 10",
"output": "23201650"
},
{
"input": "20 10000000\n10 3 2 6 2 3 9 2 8 4 4 4 3 4 7 9 5 1 7 10\n9 6 2 8 3 2 8 10 6 3 2 8 8 10 1 1 7 1 4 5",
"output": "730000001"
},
{
"input": "20 10000000\n7 10 9 2 9 7 6 10 3 7 5 1 1 8 4 9 7 9 6 8\n9 4 3 6 1 7 3 4 1 8 3 5 2 8 10 9 1 2 10 4",
"output": "780000008"
},
{
"input": "20 10000000\n2 7 9 4 1 9 8 4 6 10 5 10 4 5 9 9 10 9 1 6\n5 9 2 9 8 9 1 10 1 9 5 6 4 9 1 10 3 9 9 7",
"output": "890000001"
},
{
"input": "20 10000000\n6 7 3 9 10 10 1 9 4 6 8 5 10 6 3 4 7 8 6 6\n7 4 7 2 7 3 10 10 6 7 3 10 3 10 1 4 10 10 7 3",
"output": "920000004"
},
{
"input": "20 10000000\n7 4 3 4 7 7 6 5 4 6 5 8 3 5 3 8 4 3 4 8\n7 6 3 2 2 10 4 3 5 7 9 9 8 5 4 9 4 3 3 4",
"output": "880000001"
},
{
"input": "1 2\n1\n1",
"output": "2"
},
{
"input": "20 10000000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "200000000"
},
{
"input": "20 10000000\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "2000000000"
}
] | 62 | 0 | 0 | 3,521 |
|
23 | Party | [
"constructive algorithms",
"graphs",
"math"
] | B. Party | 2 | 256 | *n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amount of people that could stay at the party in the end? | The first input line contains one number *t* β amount of tests (1<=β€<=*t*<=β€<=105). Each of the following *t* lines contains one integer number *n* (1<=β€<=*n*<=β€<=105). | For each test output in a separate line one number β the maximum amount of people that could stay in the end. | [
"1\n3\n"
] | [
"1\n"
] | none | [
{
"input": "1\n3",
"output": "1"
}
] | 1,496 | 0 | 3.626 | 3,522 |
300 | Beautiful Numbers | [
"brute force",
"combinatorics"
] | null | null | Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number.
For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't.
Now Vitaly is wondering, how many excellent numbers of length exactly *n* are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109<=+<=7).
A number's length is the number of digits in its decimal representation without leading zeroes. | The first line contains three integers: *a*, *b*, *n* (1<=β€<=*a*<=<<=*b*<=β€<=9,<=1<=β€<=*n*<=β€<=106). | Print a single integer β the answer to the problem modulo 1000000007 (109<=+<=7). | [
"1 3 3\n",
"2 3 10\n"
] | [
"1\n",
"165\n"
] | none | [
{
"input": "1 3 3",
"output": "1"
},
{
"input": "2 3 10",
"output": "165"
},
{
"input": "6 8 14215",
"output": "651581472"
},
{
"input": "4 9 104671",
"output": "329390901"
},
{
"input": "6 7 78755",
"output": "0"
},
{
"input": "1 8 265",
"output": "461320265"
},
{
"input": "3 9 37413",
"output": "461358757"
},
{
"input": "1 7 49055",
"output": "461364774"
},
{
"input": "3 4 11028",
"output": "461668105"
},
{
"input": "2 6 32377",
"output": "887598327"
},
{
"input": "3 5 80791",
"output": "999993599"
},
{
"input": "4 8 11857",
"output": "999991923"
},
{
"input": "1 3 10785",
"output": "999952603"
},
{
"input": "4 6 11808",
"output": "999925731"
},
{
"input": "1 2 11857",
"output": "999991923"
},
{
"input": "2 4 88193",
"output": "999976846"
},
{
"input": "1 4 37226",
"output": "999970594"
},
{
"input": "2 5 53049",
"output": "259705254"
},
{
"input": "3 6 1000000",
"output": "786609214"
},
{
"input": "7 9 999999",
"output": "53911803"
},
{
"input": "8 9 999999",
"output": "447886447"
},
{
"input": "3 8 1000000",
"output": "0"
},
{
"input": "2 8 999999",
"output": "0"
},
{
"input": "1 6 997695",
"output": "0"
},
{
"input": "1 5 997694",
"output": "0"
},
{
"input": "5 9 997693",
"output": "0"
},
{
"input": "5 8 997690",
"output": "21735480"
},
{
"input": "7 8 2",
"output": "0"
},
{
"input": "6 9 1",
"output": "2"
},
{
"input": "8 9 111111",
"output": "900401372"
},
{
"input": "8 9 1000000",
"output": "573697309"
},
{
"input": "1 2 1000000",
"output": "786609214"
}
] | 810 | 62,054,400 | 3 | 3,525 |
|
893 | Chess For Three | [
"implementation"
] | null | null | Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.
So they play with each other according to following rules:
- Alex and Bob play the first game, and Carl is spectating; - When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner.
Alex, Bob and Carl play in such a way that there are no draws.
Today they have played *n* games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it! | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100) β the number of games Alex, Bob and Carl played.
Then *n* lines follow, describing the game log. *i*-th line contains one integer *a**i* (1<=β€<=*a**i*<=β€<=3) which is equal to 1 if Alex won *i*-th game, to 2 if Bob won *i*-th game and 3 if Carl won *i*-th game. | Print YES if the situation described in the log was possible. Otherwise print NO. | [
"3\n1\n1\n2\n",
"2\n1\n2\n"
] | [
"YES\n",
"NO\n"
] | In the first example the possible situation is:
1. Alex wins, Carl starts playing instead of Bob; 1. Alex wins, Bob replaces Carl; 1. Bob wins.
The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one. | [
{
"input": "3\n1\n1\n2",
"output": "YES"
},
{
"input": "2\n1\n2",
"output": "NO"
},
{
"input": "100\n2\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n3\n3\n3\n3\n3\n3\n1\n2\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n3\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n1\n2\n2\n2\n3\n3\n2\n1\n3\n3\n1\n2\n3\n1\n1\n1\n2\n2\n2\n3\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n2\n2\n2\n3\n1\n2\n2\n2\n2\n2\n3\n3\n2\n1\n1",
"output": "YES"
},
{
"input": "99\n1\n3\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n1\n1\n3\n3\n3\n3\n1\n1\n3\n2\n1\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n1\n3\n3\n1\n1\n3\n2\n1\n3\n3\n1\n2\n3\n3\n3\n1\n2\n2\n2\n3\n3\n3\n3\n3\n3\n2\n2\n2\n2\n3\n3\n3\n1\n1\n3\n2\n1\n1\n2\n2\n2\n3\n3\n2\n1\n1\n2\n2\n1\n3\n2\n1\n1\n2\n3\n3\n3\n3\n2\n2\n2\n2\n2\n1\n3",
"output": "YES"
},
{
"input": "100\n2\n2\n1\n3\n1\n3\n3\n1\n1\n3\n1\n1\n3\n2\n1\n3\n1\n1\n3\n3\n2\n2\n3\n1\n1\n2\n3\n2\n2\n3\n1\n1\n2\n3\n2\n1\n2\n2\n3\n3\n1\n1\n3\n1\n2\n1\n3\n1\n1\n3\n2\n2\n2\n1\n1\n1\n3\n1\n3\n2\n1\n2\n2\n2\n3\n3\n2\n1\n1\n3\n3\n2\n1\n2\n1\n1\n3\n1\n2\n3\n2\n3\n3\n3\n2\n2\n1\n3\n1\n2\n3\n1\n2\n3\n3\n1\n2\n1\n3\n1",
"output": "NO"
},
{
"input": "10\n2\n3\n3\n3\n3\n2\n2\n2\n3\n2",
"output": "NO"
},
{
"input": "100\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\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\n1\n1\n1\n1\n1\n1",
"output": "YES"
},
{
"input": "1\n3",
"output": "NO"
},
{
"input": "1\n2",
"output": "YES"
},
{
"input": "42\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": "YES"
},
{
"input": "4\n2\n3\n3\n3",
"output": "YES"
},
{
"input": "3\n1\n2\n3",
"output": "NO"
},
{
"input": "5\n1\n1\n1\n1\n3",
"output": "NO"
},
{
"input": "5\n2\n3\n3\n3\n3",
"output": "YES"
},
{
"input": "2\n3\n3",
"output": "NO"
},
{
"input": "4\n1\n2\n2\n1",
"output": "NO"
},
{
"input": "3\n2\n2\n3",
"output": "NO"
},
{
"input": "5\n2\n3\n3\n1\n1",
"output": "NO"
},
{
"input": "3\n3\n1\n3",
"output": "NO"
},
{
"input": "3\n3\n3\n1",
"output": "NO"
},
{
"input": "2\n2\n1",
"output": "NO"
},
{
"input": "3\n1\n1\n3",
"output": "NO"
},
{
"input": "6\n2\n2\n2\n3\n1\n3",
"output": "NO"
},
{
"input": "2\n3\n1",
"output": "NO"
},
{
"input": "2\n3\n2",
"output": "NO"
},
{
"input": "2\n1\n3",
"output": "YES"
},
{
"input": "3\n1\n3\n1",
"output": "NO"
},
{
"input": "5\n1\n1\n2\n2\n3",
"output": "NO"
},
{
"input": "3\n2\n1\n1",
"output": "NO"
},
{
"input": "2\n2\n2",
"output": "YES"
},
{
"input": "3\n2\n2\n1",
"output": "YES"
},
{
"input": "5\n2\n2\n2\n2\n2",
"output": "YES"
},
{
"input": "8\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "YES"
},
{
"input": "3\n3\n2\n2",
"output": "NO"
},
{
"input": "3\n3\n2\n3",
"output": "NO"
},
{
"input": "7\n2\n2\n2\n2\n2\n2\n2",
"output": "YES"
},
{
"input": "3\n2\n2\n2",
"output": "YES"
}
] | 46 | 0 | 3 | 3,533 |
|
52 | 123-sequence | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=β€<=*n*<=β€<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "2\n3 2",
"output": "1"
},
{
"input": "2\n3 1",
"output": "1"
},
{
"input": "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2",
"output": "10"
},
{
"input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1",
"output": "19"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
}
] | 498 | 13,619,200 | 3.850132 | 3,549 |
446 | DZY Loves Sequences | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=β€<=*i*<=β€<=*j*<=β€<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find. | The first line contains integer *n*Β (1<=β€<=*n*<=β€<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*Β (1<=β€<=*a**i*<=β€<=109). | In a single line print the answer to the problem β the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>,β*a*<sub class="lower-index">3</sub>,β*a*<sub class="lower-index">4</sub>,β*a*<sub class="lower-index">5</sub>,β*a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371",
"output": "19"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "2"
},
{
"input": "5\n1 2 3 4 1",
"output": "5"
},
{
"input": "10\n1 2 3 4 5 5 6 7 8 9",
"output": "6"
},
{
"input": "5\n1 1 1 1 1",
"output": "2"
},
{
"input": "5\n1 1 2 3 4",
"output": "5"
},
{
"input": "5\n1 2 3 1 6",
"output": "5"
},
{
"input": "1\n42",
"output": "1"
},
{
"input": "5\n1 2 42 3 4",
"output": "4"
},
{
"input": "5\n1 5 9 6 10",
"output": "4"
},
{
"input": "5\n5 2 3 4 5",
"output": "5"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "5\n1 2 3 3 4",
"output": "4"
},
{
"input": "8\n1 2 3 4 1 5 6 7",
"output": "5"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "3\n5 1 2",
"output": "3"
},
{
"input": "4\n1 4 3 4",
"output": "4"
},
{
"input": "6\n7 2 12 4 5 6",
"output": "5"
},
{
"input": "6\n7 2 3 1 4 5",
"output": "4"
},
{
"input": "6\n2 3 5 5 6 7",
"output": "6"
},
{
"input": "5\n2 4 7 6 8",
"output": "5"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "5\n4 1 2 3 4",
"output": "5"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6",
"output": "7"
},
{
"input": "4\n1 2 1 3",
"output": "3"
},
{
"input": "4\n4 3 1 2",
"output": "3"
},
{
"input": "6\n1 2 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 1 1 2",
"output": "3"
},
{
"input": "4\n5 1 2 3",
"output": "4"
},
{
"input": "5\n9 1 2 3 4",
"output": "5"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "5\n1 3 2 4 5",
"output": "4"
},
{
"input": "6\n1 2 1 2 4 5",
"output": "5"
},
{
"input": "10\n1 1 5 3 2 9 9 7 7 6",
"output": "3"
},
{
"input": "6\n1 2 3 100000 100 101",
"output": "6"
},
{
"input": "4\n3 3 3 4",
"output": "3"
},
{
"input": "3\n4 3 5",
"output": "3"
},
{
"input": "5\n1 3 2 3 4",
"output": "4"
},
{
"input": "10\n1 2 3 4 5 10 10 11 12 13",
"output": "10"
},
{
"input": "7\n11 2 1 2 13 4 14",
"output": "5"
},
{
"input": "3\n5 1 3",
"output": "3"
},
{
"input": "4\n1 5 3 4",
"output": "4"
},
{
"input": "10\n1 2 3 4 100 6 7 8 9 10",
"output": "10"
},
{
"input": "3\n5 3 5",
"output": "3"
},
{
"input": "5\n100 100 7 8 9",
"output": "4"
},
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "5\n1 2 4 4 5",
"output": "5"
},
{
"input": "6\n7 4 5 6 7 8",
"output": "6"
},
{
"input": "9\n3 4 1 6 3 4 5 6 7",
"output": "7"
},
{
"input": "3\n1000 1 2",
"output": "3"
},
{
"input": "3\n20 1 9",
"output": "3"
},
{
"input": "6\n7 2 3 1 4 6",
"output": "4"
},
{
"input": "3\n100 5 10",
"output": "3"
},
{
"input": "4\n2 2 2 3",
"output": "3"
},
{
"input": "6\n4 2 8 1 2 5",
"output": "4"
},
{
"input": "3\n25 1 6",
"output": "3"
},
{
"input": "10\n17 99 23 72 78 36 5 43 95 9",
"output": "5"
},
{
"input": "7\n21 16 22 21 11 13 19",
"output": "4"
},
{
"input": "5\n1 2 5 3 4",
"output": "4"
},
{
"input": "6\n2 2 2 3 4 5",
"output": "5"
},
{
"input": "5\n1 3 1 2 3",
"output": "4"
},
{
"input": "3\n81 33 64",
"output": "3"
},
{
"input": "7\n14 3 3 19 13 19 15",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 42 7 8 9",
"output": "9"
},
{
"input": "5\n2 3 7 5 6",
"output": "5"
},
{
"input": "5\n1 3 3 4 5",
"output": "5"
},
{
"input": "6\n1 5 4 3 4 5",
"output": "4"
}
] | 108 | 0 | 0 | 3,552 |
|
710 | King Moves | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wiki/King_(chess)). | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* β the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
},
{
"input": "c7",
"output": "8"
},
{
"input": "h6",
"output": "5"
},
{
"input": "c8",
"output": "5"
},
{
"input": "h2",
"output": "5"
},
{
"input": "h5",
"output": "5"
},
{
"input": "a8",
"output": "3"
},
{
"input": "f8",
"output": "5"
},
{
"input": "h1",
"output": "3"
},
{
"input": "f2",
"output": "8"
},
{
"input": "e8",
"output": "5"
},
{
"input": "h3",
"output": "5"
},
{
"input": "b8",
"output": "5"
},
{
"input": "g8",
"output": "5"
},
{
"input": "d8",
"output": "5"
},
{
"input": "h4",
"output": "5"
},
{
"input": "b1",
"output": "5"
},
{
"input": "a2",
"output": "5"
}
] | 46 | 0 | 3 | 3,555 |
|
448 | Suffix Structures | [
"implementation",
"strings"
] | null | null | Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order. | The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters. | In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton. | [
"automaton\ntomat\n",
"array\narary\n",
"both\nhot\n",
"need\ntree\n"
] | [
"automaton\n",
"array\n",
"both\n",
"need tree\n"
] | In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot". | [
{
"input": "automaton\ntomat",
"output": "automaton"
},
{
"input": "array\narary",
"output": "array"
},
{
"input": "both\nhot",
"output": "both"
},
{
"input": "need\ntree",
"output": "need tree"
},
{
"input": "abacaba\naaaa",
"output": "automaton"
},
{
"input": "z\nzz",
"output": "need tree"
},
{
"input": "itwtyhhsdjjffmmoqkkhxjouypznewstyorotxhozlytndehmaxogrohccnqcgkrjrdmnuaogiwmnmsbdaizqkxnkqxxiihbwepc\nsnixfywvcntitcefsgqxjcodwtumurcglfmnamnowzbjzmfzspbfuldraiepeeiyasmrsneekydsbvazoqszyjxkjiotushsddet",
"output": "need tree"
},
{
"input": "y\nu",
"output": "need tree"
},
{
"input": "nbjigpsbammkuuqrxfnmhtimwpflrflehffykbylmnxgadldchdbqklqbremcmzlpxieozgpfgrhegmdcxxfyehzzelcwgkierrj\nbjbakuqrnhimwhffykylmngadhbqkqbrcziefredxxezcgkerj",
"output": "automaton"
},
{
"input": "gzvvawianfysfuxhruarhverinqsbrfxvkcsermuzowahevgskmpvfdljtcztnbkzftfhvnarvkfkqjgrzbrcfthqmspvpqcva\nwnm",
"output": "automaton"
},
{
"input": "dvzohfzgzdjavqwhjcrdphpdqjwtqijabbrhformstqaonlhbglmxugkwviigqaohwvqfhdwwcvdkjrcgxblhvtashhcxssbvpo\nzgvqhpjhforlugkwfwrchvhp",
"output": "automaton"
},
{
"input": "wkfoyetcjivofxaktmauapzeuhcpzjloszzxwydgavebgniiuzrscytsokjkjfkpylvxtlqlquzduywbhqdzmtwprfdohmwgmysy\ny",
"output": "automaton"
},
{
"input": "npeidcoiulxdxzjozsonkdwnoazsbntfclnpubgweaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf\nnpeidcoiulxdxzjozsonkdwnoazsbntfclnpubgeaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf",
"output": "automaton"
},
{
"input": "gahcqpgmypeahjcwkzahnhmsmxosnikucqwyzklbfwtujjlzvwklqzxakcrcqalhsvsgvknpxsoqkjnyjkypfsiogbcaxjyugeet\ngahcqpgmypeahjwwkzahnhmsmxopnikucacyzklbfwtujjlzvwkoqzxakcrcqqlhsvsgvknpxslgkjnyjkysfoisqbcaxjyuteeg",
"output": "array"
},
{
"input": "vwesbxsifsjqapwridrenumrukgemlldpbtdhxivsrmzbgprtkqgaryniudkjgpjndluwxuohwwysmyuxyrulwsodgunzirudgtx\nugeabdszfshqsksddireguvsukieqlluhngdpxjvwwnzdrtrtrdjiuxgadtgjpxrmlynspyyryngxuiibrmurwpmoxwwuklbwumo",
"output": "array"
},
{
"input": "kjnohlseyntrslfssrshjxclzlsbkfzfwwwgyxsysvmfkxugdwjodfyxhdsveruoioutwmtcbaljomaorvzjsbmglqckmsyieeiu\netihhycsjgdysowuljmaoksoecxawsgsljofkrjftuweidrkwtymyswdlilsozsxevfbformnbsumlxzqzykjvsnrlxufvgbmshc",
"output": "array"
},
{
"input": "ezbpsylkfztypqrefinexshtgglmkoinrktkloitqhfkivoabrfrivvqrcxkjckzvcozpchhiodrbbxuhnwcjigftnrjfiqyxakh\niacxghqffzdbsiqunhxbiooqvfohzticjpvrzykcrlrxklgknyrkrhjxcetmfocierekatfvkbslkkrbhftwngoijpipvqyznthi",
"output": "array"
},
{
"input": "smywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhuqqcttokbljfbppdinzqgdupkfevmke\nsmywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhufqcttokbljfbppdinzqgdupkqevmke",
"output": "array"
},
{
"input": "hxsvvydmzhxrswvhkvrbjrfqkazbkjabnrdghposgyfeslzumaovfkallszzumztftgpcilwfrzpvhhbgdzdvnmseqywlzmhhoxh\ndbelhtzgkssyfrqgzuurdjhwvmdbhylhmvphjgxpzhxbb",
"output": "both"
},
{
"input": "nppjzscfgcvdcnsjtiaudvutmgswqbewejlzibczzowgkdrjgxrpirfdaekvngcsonroheepdoeoeevaullbfwprcnhlxextbxpd\nifilrvacohnwcgzuleicucebrfxphosrgwnglxxkqrcorsxegjoppbb",
"output": "both"
},
{
"input": "ggzmtrhkpdswwqgcbtviahqrgzhyhzddtdekchrpjgngupitzyyuipwstgzewktcqpwezidwvvxgjixnflpjhfznokmpbyzczrzk\ngpgwhtzrcytstezmhettkppgmvxlxqnkjzibiqdtceczkbfhdziuajwjqzgwnhnkdzizprgzwud",
"output": "both"
},
{
"input": "iypjqiiqxhtinlmywpetgqqsdopxhghthjopgbodkwrdxzaaxmtaqcfuiarhrvasusanklzcqaytdyzndakcpljqupowompjjved\nhxeatriypptbhnokarhgqdrkqkypqzdttixphngmpqjodzjqlmcztyjfgoswjelwwdaqdjayavsdocuhqsluxaaopniviaumxip",
"output": "both"
},
{
"input": "ypyhyabmljukejpltkgunwuanhxblhiouyltdiczttndrhdprqtlpfanmzlyzbqanfwfyurxhepuzspdvehxnblhajczqcxlqebx\nlladxuucky",
"output": "both"
},
{
"input": "ddmgoarkuhknbtjggnomyxvvavobmylixwuxnnsdrrbibitoteaiydptnvtfblathihflefuggfnyayniragbtkommycpdyhft\ntejwybmyrhmalraptqwhghsckvnnaagtmzhnpwbhzzgfgritqwqqamgssllnicjqdkivrwaqyxngsqopwieljfxcdywjaal",
"output": "need tree"
},
{
"input": "kipjuscf\nkbwfqfwuvkyhmvnaznzsgdgdnpipikbicmlcwehjirmhgwpxwpgfztqjwfqfaapmsgskr",
"output": "need tree"
},
{
"input": "kobhhrqgwbgqkzcoacrhpkegyepzfds\nhlwcgbvvlegoyrcrjhsjywpdnccxtzgmeujxciuwjlnefllwldidlnjswmetkarxqjigokfvmpxpzfxarhkpdcia",
"output": "need tree"
},
{
"input": "lllolloloolllloolollololololollllooololoooloooolololloolloollllolloolloooooooololllolllolllloolllool\nlollollololololooooloooooooooolloolllololooollllol",
"output": "automaton"
},
{
"input": "lloloooolooollololloooloololooollooloollolllloolllllllloollollllolooloollloololollllooloooololooolol\nlooooollooolllololloollooooololollollloloollollolo",
"output": "both"
},
{
"input": "yyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxyxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx\nyyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxxxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx",
"output": "need tree"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "automaton"
},
{
"input": "abracadabra\nlol",
"output": "need tree"
},
{
"input": "abc\naa",
"output": "need tree"
},
{
"input": "ba\naa",
"output": "need tree"
},
{
"input": "abbb\naaab",
"output": "need tree"
},
{
"input": "baaa\nbb",
"output": "need tree"
},
{
"input": "boosss\nosos",
"output": "both"
}
] | 93 | 0 | 0 | 3,556 |
|
691 | Exponential notation | [
"implementation",
"strings"
] | null | null | You are given a positive decimal number *x*.
Your task is to convert it to the "simple exponential notation".
Let *x*<==<=*a*Β·10*b*, where 1<=β€<=*a*<=<<=10, then in general case the "simple exponential notation" looks like "aEb". If *b* equals to zero, the part "Eb" should be skipped. If *a* is an integer, it should be written without decimal point. Also there should not be extra zeroes in *a* and *b*. | The only line contains the positive decimal number *x*. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other. | Print the only line β the "simple exponential notation" of the given number *x*. | [
"16\n",
"01.23400\n",
".100\n",
"100.\n"
] | [
"1.6E1\n",
"1.234\n",
"1E-1\n",
"1E2\n"
] | none | [
{
"input": "16",
"output": "1.6E1"
},
{
"input": "01.23400",
"output": "1.234"
},
{
"input": ".100",
"output": "1E-1"
},
{
"input": "100.",
"output": "1E2"
},
{
"input": "9000",
"output": "9E3"
},
{
"input": "0.0012",
"output": "1.2E-3"
},
{
"input": "0001100",
"output": "1.1E3"
},
{
"input": "1",
"output": "1"
},
{
"input": "1.0000",
"output": "1"
},
{
"input": "2206815224318443962208128404511577750057653265995300414539703580103256087275661997018352502651118684",
"output": "2.206815224318443962208128404511577750057653265995300414539703580103256087275661997018352502651118684E99"
},
{
"input": ".642190250125247518637240673193254850619739079359757454472743329719747684651927659872735961709249479",
"output": "6.42190250125247518637240673193254850619739079359757454472743329719747684651927659872735961709249479E-1"
},
{
"input": "143529100720960530144687499862369157252883621496987867683546098241081752607457981824764693332677189.",
"output": "1.43529100720960530144687499862369157252883621496987867683546098241081752607457981824764693332677189E98"
},
{
"input": "5649388306043547446322173224045662327678394712363.27277681139968970424738731716530805786323956813790",
"output": "5.6493883060435474463221732240456623276783947123632727768113996897042473873171653080578632395681379E48"
},
{
"input": "0.1",
"output": "1E-1"
},
{
"input": ".1",
"output": "1E-1"
},
{
"input": "1.",
"output": "1"
},
{
"input": "0.111",
"output": "1.11E-1"
},
{
"input": ".111",
"output": "1.11E-1"
},
{
"input": "1.1",
"output": "1.1"
},
{
"input": "01.1",
"output": "1.1"
},
{
"input": "1.10",
"output": "1.1"
},
{
"input": "01.10",
"output": "1.1"
},
{
"input": "10.0",
"output": "1E1"
},
{
"input": "16.00",
"output": "1.6E1"
},
{
"input": "0016.",
"output": "1.6E1"
},
{
"input": ".000016",
"output": "1.6E-5"
},
{
"input": "16000.000",
"output": "1.6E4"
},
{
"input": "016.00",
"output": "1.6E1"
},
{
"input": "0016.00",
"output": "1.6E1"
},
{
"input": "0.16",
"output": "1.6E-1"
},
{
"input": "00.16",
"output": "1.6E-1"
},
{
"input": "00.160",
"output": "1.6E-1"
}
] | 62 | 9,011,200 | 3 | 3,557 |
|
0 | none | [
"none"
] | null | null | Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0.
There are also *n* cards, each card has 2 attributes: length *l**i* and cost *c**i*. If she pays *c**i* dollars then she can apply *i*-th card. After applying *i*-th card she becomes able to make jumps of length *l**i*, i. e. from cell *x* to cell (*x*<=-<=*l**i*) or cell (*x*<=+<=*l**i*).
She wants to be able to jump to any cell on the tape (possibly, visiting some intermediate cells). For achieving this goal, she wants to buy some cards, paying as little money as possible.
If this is possible, calculate the minimal cost. | The first line contains an integer *n* (1<=β€<=*n*<=β€<=300), number of cards.
The second line contains *n* numbers *l**i* (1<=β€<=*l**i*<=β€<=109), the jump lengths of cards.
The third line contains *n* numbers *c**i* (1<=β€<=*c**i*<=β€<=105), the costs of cards. | If it is impossible to buy some cards and become able to jump to any cell, output -1. Otherwise output the minimal cost of buying such set of cards. | [
"3\n100 99 9900\n1 1 1\n",
"5\n10 20 30 40 50\n1 1 1 1 1\n",
"7\n15015 10010 6006 4290 2730 2310 1\n1 1 1 1 1 1 10\n",
"8\n4264 4921 6321 6984 2316 8432 6120 1026\n4264 4921 6321 6984 2316 8432 6120 1026\n"
] | [
"2\n",
"-1\n",
"6\n",
"7237\n"
] | In first sample test, buying one card is not enough: for example, if you buy a card with length 100, you can't jump to any cell whose index is not a multiple of 100. The best way is to buy first and second card, that will make you be able to jump to any cell.
In the second sample test, even if you buy all cards, you can't jump to any cell whose index is not a multiple of 10, so you should output -1. | [
{
"input": "3\n100 99 9900\n1 1 1",
"output": "2"
},
{
"input": "5\n10 20 30 40 50\n1 1 1 1 1",
"output": "-1"
},
{
"input": "7\n15015 10010 6006 4290 2730 2310 1\n1 1 1 1 1 1 10",
"output": "6"
},
{
"input": "8\n4264 4921 6321 6984 2316 8432 6120 1026\n4264 4921 6321 6984 2316 8432 6120 1026",
"output": "7237"
},
{
"input": "6\n1 2 4 8 16 32\n32 16 8 4 2 1",
"output": "32"
},
{
"input": "1\n1\n1",
"output": "1"
},
{
"input": "1\n2\n2",
"output": "-1"
},
{
"input": "8\n2 3 5 7 11 13 17 19\n4 8 7 1 5 2 6 3",
"output": "3"
},
{
"input": "1\n1000000000\n100000",
"output": "-1"
},
{
"input": "2\n1000000000 999999999\n100000 100000",
"output": "200000"
},
{
"input": "39\n692835 4849845 22610 1995 19019 114 6270 15 85085 27170 1365 1155 7410 238 3135 546 373065 715 110 969 15 10374 2730 19019 85 65 5187 26 3233230 1122 399 1122 53295 910 110 12597 16302 125970 67830\n4197 6490 2652 99457 65400 96257 33631 23456 14319 22288 16179 74656 89713 31503 45895 31777 64534 27989 60861 69846 44586 87185 96589 62279 62478 6180 26977 12112 9975 72933 73239 65856 98253 18875 55266 55867 36397 40743 47977",
"output": "18961"
},
{
"input": "35\n512 268435456 8 128 134217728 8192 33554432 33554432 536870912 512 65536 1048576 32768 512 524288 1024 536870912 536870912 16 32 33554432 134217728 2 16 16777216 8192 262144 65536 33554432 128 4096 2097152 33554432 2097152 2\n36157 67877 79710 63062 12683 36255 61053 83828 93590 74236 5281 28143 7350 45953 96803 15998 11240 45207 63010 74076 85227 83498 68320 77288 48100 51373 87843 70054 28986 25365 98581 11195 43674 75769 22053",
"output": "-1"
}
] | 77 | 2,867,200 | -1 | 3,560 |
|
757 | Bash's Big Day | [
"greedy",
"math",
"number theory"
] | null | null | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*} tend to fight among each other if *gcd*(*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*)<==<=1 (see notes for *gcd* definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself. | The input consists of two lines.
The first line contains an integer *n* (1<=β€<=*n*<=β€<=105), the number of Pokemon in the lab.
The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=β€<=*s**i*<=β€<=105), the strength of the *i*-th Pokemon. | Print single integerΒ β the maximum number of Pokemons Bash can take. | [
"3\n2 3 4\n",
"5\n2 3 4 6 7\n"
] | [
"2\n",
"3\n"
] | *gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>,β*a*<sub class="lower-index">2</sub>,β...,β*a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>,β*a*<sub class="lower-index">2</sub>,β...,β*a*<sub class="lower-index">*n*</sub>}.
In the first sample, we can take Pokemons with strengths {2,β4} since *gcd*(2,β4)β=β2.
In the second sample, we can take Pokemons with strengths {2,β4,β6}, and there is no larger group with *gcd*ββ β1. | [
{
"input": "3\n2 3 4",
"output": "2"
},
{
"input": "5\n2 3 4 6 7",
"output": "3"
},
{
"input": "3\n5 6 4",
"output": "2"
},
{
"input": "8\n41 74 4 27 85 39 100 36",
"output": "4"
},
{
"input": "6\n89 20 86 81 62 23",
"output": "3"
},
{
"input": "71\n23 84 98 8 14 4 42 56 83 87 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10",
"output": "38"
},
{
"input": "95\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50",
"output": "48"
},
{
"input": "44\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684",
"output": "19"
},
{
"input": "35\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557",
"output": "20"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n10 7 9 8 3 3 10 7 3 3",
"output": "5"
},
{
"input": "9\n10 10 6 10 9 1 8 3 5",
"output": "5"
},
{
"input": "7\n9 4 2 3 3 9 8",
"output": "4"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "6\n1623 45906 37856 34727 27156 12598",
"output": "4"
},
{
"input": "30\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566",
"output": "15"
},
{
"input": "23\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16",
"output": "22"
},
{
"input": "46\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33",
"output": "27"
},
{
"input": "43\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34",
"output": "21"
},
{
"input": "25\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "2\n3 6",
"output": "2"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "5\n3 3 3 3 3",
"output": "5"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "2\n541 541",
"output": "2"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n99989 99989",
"output": "2"
},
{
"input": "3\n3 9 27",
"output": "3"
},
{
"input": "2\n1009 1009",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "6\n2 10 20 5 15 25",
"output": "5"
},
{
"input": "3\n3 3 6",
"output": "3"
},
{
"input": "3\n457 457 457",
"output": "3"
},
{
"input": "2\n34 17",
"output": "2"
},
{
"input": "3\n12 24 3",
"output": "3"
},
{
"input": "10\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991",
"output": "10"
},
{
"input": "2\n1009 2018",
"output": "2"
},
{
"input": "3\n3 3 3",
"output": "3"
},
{
"input": "7\n6 9 12 15 21 27 33",
"output": "7"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n557 557",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "5\n2 2 101 101 101",
"output": "3"
},
{
"input": "2\n122 3721",
"output": "2"
},
{
"input": "2\n49201 98402",
"output": "2"
},
{
"input": "2\n88258 44129",
"output": "2"
},
{
"input": "2\n7919 47514",
"output": "2"
},
{
"input": "5\n1 2 1 1 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "5\n1 1 1 1 2",
"output": "1"
},
{
"input": "3\n10007 20014 30021",
"output": "3"
},
{
"input": "4\n10 10 5 5",
"output": "4"
},
{
"input": "2\n6 9",
"output": "2"
},
{
"input": "3\n6 12 9",
"output": "3"
},
{
"input": "2\n14 7",
"output": "2"
},
{
"input": "2\n199 199",
"output": "2"
},
{
"input": "3\n49999 49999 99998",
"output": "3"
},
{
"input": "5\n1009 1009 1009 1009 1009",
"output": "5"
},
{
"input": "3\n17 17 17",
"output": "3"
},
{
"input": "2\n503 1509",
"output": "2"
},
{
"input": "3\n49999 99998 99998",
"output": "3"
},
{
"input": "2\n28657 28657",
"output": "2"
},
{
"input": "3\n121 22 33",
"output": "3"
},
{
"input": "2\n10079 20158",
"output": "2"
},
{
"input": "2\n6 15",
"output": "2"
},
{
"input": "4\n6 6 6 3",
"output": "4"
},
{
"input": "2\n991 1982",
"output": "2"
},
{
"input": "3\n20362 30543 50905",
"output": "3"
},
{
"input": "2\n443 886",
"output": "2"
},
{
"input": "4\n3 7 7 21",
"output": "3"
},
{
"input": "3\n3 6 9",
"output": "3"
},
{
"input": "2\n217 31",
"output": "2"
},
{
"input": "6\n10 10 10 5 5 5",
"output": "6"
},
{
"input": "4\n49441 25225 9081 4036",
"output": "4"
},
{
"input": "2\n4 9",
"output": "1"
},
{
"input": "2\n18 27",
"output": "2"
},
{
"input": "2\n13 26",
"output": "2"
},
{
"input": "4\n6 6 6 15",
"output": "4"
}
] | 1,419 | 13,209,600 | 3 | 3,564 |
|
452 | Eevee | [
"brute force",
"implementation",
"strings"
] | null | null | You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.
You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it. | First line contains an integer *n* (6<=β€<=*n*<=β€<=8) β the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). | Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). | [
"7\nj......\n",
"7\n...feon\n",
"7\n.l.r.o.\n"
] | [
"jolteon\n",
"leafeon\n",
"flareon\n"
] | Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | [
{
"input": "7\n...feon",
"output": "leafeon"
},
{
"input": "7\n.l.r.o.",
"output": "flareon"
},
{
"input": "6\n.s..o.",
"output": "espeon"
},
{
"input": "7\nglaceon",
"output": "glaceon"
},
{
"input": "8\n.a.o.e.n",
"output": "vaporeon"
},
{
"input": "7\n.laceon",
"output": "glaceon"
},
{
"input": "7\n..lveon",
"output": "sylveon"
},
{
"input": "7\n.l.ceon",
"output": "glaceon"
},
{
"input": "7\n..areon",
"output": "flareon"
}
] | 46 | 0 | 0 | 3,575 |
|
625 | K-special Tables | [
"constructive algorithms",
"implementation"
] | null | null | People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you forget, the table *n*<=Γ<=*n* is called *k*-special if the following three conditions are satisfied:
- every integer from 1 to *n*2 appears in the table exactly once; - in each row numbers are situated in increasing order; - the sum of numbers in the *k*-th column is maximum possible.
Your goal is to help Alice and find at least one *k*-special table of size *n*<=Γ<=*n*. Both rows and columns are numbered from 1 to *n*, with rows numbered from top to bottom and columns numbered from left to right. | The first line of the input contains two integers *n* and *k* (1<=β€<=*n*<=β€<=500,<=1<=β€<=*k*<=β€<=*n*)Β β the size of the table Alice is looking for and the column that should have maximum possible sum. | First print the sum of the integers in the *k*-th column of the required table.
Next *n* lines should contain the description of the table itself: first line should contains *n* elements of the first row, second line should contain *n* elements of the second row and so on.
If there are multiple suitable table, you are allowed to print any. | [
"4 1\n",
"5 3\n"
] | [
"28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n",
"85\n5 6 17 18 19\n9 10 23 24 25\n7 8 20 21 22\n3 4 14 15 16\n1 2 11 12 13\n\n"
] | none | [
{
"input": "4 1",
"output": "28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16"
},
{
"input": "5 3",
"output": "85\n1 2 11 12 13\n3 4 14 15 16\n5 6 17 18 19\n7 8 20 21 22\n9 10 23 24 25"
},
{
"input": "1 1",
"output": "1\n1"
},
{
"input": "2 1",
"output": "4\n1 2\n3 4"
},
{
"input": "2 2",
"output": "7\n1 3\n2 4"
},
{
"input": "500 1",
"output": "62375500\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 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 1..."
},
{
"input": "3 1",
"output": "12\n1 2 3\n4 5 6\n7 8 9"
},
{
"input": "3 2",
"output": "18\n1 4 5\n2 6 7\n3 8 9"
},
{
"input": "3 3",
"output": "24\n1 2 7\n3 4 8\n5 6 9"
},
{
"input": "4 2",
"output": "38\n1 5 6 7\n2 8 9 10\n3 11 12 13\n4 14 15 16"
},
{
"input": "4 3",
"output": "48\n1 2 9 10\n3 4 11 12\n5 6 13 14\n7 8 15 16"
},
{
"input": "4 4",
"output": "58\n1 2 3 13\n4 5 6 14\n7 8 9 15\n10 11 12 16"
},
{
"input": "5 1",
"output": "55\n1 2 3 4 5\n6 7 8 9 10\n11 12 13 14 15\n16 17 18 19 20\n21 22 23 24 25"
},
{
"input": "5 2",
"output": "70\n1 6 7 8 9\n2 10 11 12 13\n3 14 15 16 17\n4 18 19 20 21\n5 22 23 24 25"
},
{
"input": "5 4",
"output": "100\n1 2 3 16 17\n4 5 6 18 19\n7 8 9 20 21\n10 11 12 22 23\n13 14 15 24 25"
},
{
"input": "5 5",
"output": "115\n1 2 3 4 21\n5 6 7 8 22\n9 10 11 12 23\n13 14 15 16 24\n17 18 19 20 25"
},
{
"input": "6 1",
"output": "96\n1 2 3 4 5 6\n7 8 9 10 11 12\n13 14 15 16 17 18\n19 20 21 22 23 24\n25 26 27 28 29 30\n31 32 33 34 35 36"
},
{
"input": "6 2",
"output": "117\n1 7 8 9 10 11\n2 12 13 14 15 16\n3 17 18 19 20 21\n4 22 23 24 25 26\n5 27 28 29 30 31\n6 32 33 34 35 36"
},
{
"input": "6 3",
"output": "138\n1 2 13 14 15 16\n3 4 17 18 19 20\n5 6 21 22 23 24\n7 8 25 26 27 28\n9 10 29 30 31 32\n11 12 33 34 35 36"
},
{
"input": "6 4",
"output": "159\n1 2 3 19 20 21\n4 5 6 22 23 24\n7 8 9 25 26 27\n10 11 12 28 29 30\n13 14 15 31 32 33\n16 17 18 34 35 36"
},
{
"input": "6 5",
"output": "180\n1 2 3 4 25 26\n5 6 7 8 27 28\n9 10 11 12 29 30\n13 14 15 16 31 32\n17 18 19 20 33 34\n21 22 23 24 35 36"
},
{
"input": "6 6",
"output": "201\n1 2 3 4 5 31\n6 7 8 9 10 32\n11 12 13 14 15 33\n16 17 18 19 20 34\n21 22 23 24 25 35\n26 27 28 29 30 36"
},
{
"input": "500 500",
"output": "124875250\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 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 ..."
},
{
"input": "500 250",
"output": "93562750\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 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 1..."
},
{
"input": "94 3",
"output": "419898\n1 2 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280\n3 4 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 31..."
},
{
"input": "22 4",
"output": "5863\n1 2 3 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85\n4 5 6 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104\n7 8 9 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123\n10 11 12 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142\n13 14 15 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161\n16 17 18 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180\n19 20 21 181 182 183 184 185 18..."
},
{
"input": "15 12",
"output": "2910\n1 2 3 4 5 6 7 8 9 10 11 166 167 168 169\n12 13 14 15 16 17 18 19 20 21 22 170 171 172 173\n23 24 25 26 27 28 29 30 31 32 33 174 175 176 177\n34 35 36 37 38 39 40 41 42 43 44 178 179 180 181\n45 46 47 48 49 50 51 52 53 54 55 182 183 184 185\n56 57 58 59 60 61 62 63 64 65 66 186 187 188 189\n67 68 69 70 71 72 73 74 75 76 77 190 191 192 193\n78 79 80 81 82 83 84 85 86 87 88 194 195 196 197\n89 90 91 92 93 94 95 96 97 98 99 198 199 200 201\n100 101 102 103 104 105 106 107 108 109 110 202 203 204 205\n111..."
},
{
"input": "37 35",
"output": "48581\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 1259 1260 1261\n35 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 1262 1263 1264\n69 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 1265 1266 1267\n103 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 1268 1269 1270\n137 ..."
},
{
"input": "87 51",
"output": "516954\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 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387\n51 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 4388 4389 4390 4391 4392 ..."
},
{
"input": "15 4",
"output": "1950\n1 2 3 46 47 48 49 50 51 52 53 54 55 56 57\n4 5 6 58 59 60 61 62 63 64 65 66 67 68 69\n7 8 9 70 71 72 73 74 75 76 77 78 79 80 81\n10 11 12 82 83 84 85 86 87 88 89 90 91 92 93\n13 14 15 94 95 96 97 98 99 100 101 102 103 104 105\n16 17 18 106 107 108 109 110 111 112 113 114 115 116 117\n19 20 21 118 119 120 121 122 123 124 125 126 127 128 129\n22 23 24 130 131 132 133 134 135 136 137 138 139 140 141\n25 26 27 142 143 144 145 146 147 148 149 150 151 152 153\n28 29 30 154 155 156 157 158 159 160 161 162 1..."
},
{
"input": "183 2",
"output": "3064518\n1 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 ..."
},
{
"input": "103 6",
"output": "567942\n1 2 3 4 5 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613\n6 7 8 9 10 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 6..."
},
{
"input": "131 11",
"output": "1202056\n1 2 3 4 5 6 7 8 9 10 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1..."
},
{
"input": "193 186",
"output": "7039482\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 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 15..."
},
{
"input": "117 109",
"output": "1539603\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 101 102 103 104 105 106 107 108 12637 12638 12639 12640 12641 12642 12643 12644 12645\n109 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..."
},
{
"input": "116 91",
"output": "1384576\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 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466\n91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 1..."
},
{
"input": "140 79",
"output": "2132200\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 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 1..."
},
{
"input": "350 14",
"output": "22175125\n1 2 3 4 5 6 7 8 9 10 11 12 13 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4..."
},
{
"input": "374 9",
"output": "26648248\n1 2 3 4 5 6 7 8 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 ..."
},
{
"input": "265 255",
"output": "18222195\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 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 1..."
},
{
"input": "289 287",
"output": "24012143\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 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 1..."
},
{
"input": "276 11",
"output": "10856736\n1 2 3 4 5 6 7 8 9 10 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 ..."
},
{
"input": "204 7",
"output": "4349688\n1 2 3 4 5 6 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 ..."
},
{
"input": "425 15",
"output": "39560275\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 604..."
},
{
"input": "449 6",
"output": "45664198\n1 2 3 4 5 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2..."
},
{
"input": "477 19",
"output": "56204433\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8..."
},
{
"input": "448 437",
"output": "88708928\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 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 1..."
},
{
"input": "472 459",
"output": "103591728\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 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 ..."
},
{
"input": "500 494",
"output": "124123750\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 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 ..."
},
{
"input": "462 318",
"output": "83103405\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 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 1..."
},
{
"input": "486 481",
"output": "114081696\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 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 ..."
},
{
"input": "410 361",
"output": "64708660\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 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 1..."
}
] | 358 | 7,680,000 | 3 | 3,581 |
|
171 | A Piece of Cake | [
"*special",
"implementation"
] | null | null | How to make a cake you'll never eat.
Ingredients.
- 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg
Method.
1. Put calories into the mixing bowl. 1. Take carrots from refrigerator. 1. Chop carrots. 1. Take chocolate spread from refrigerator. 1. Put chocolate spread into the mixing bowl. 1. Combine pack of flour into the mixing bowl. 1. Fold chocolate spread into the mixing bowl. 1. Add chocolate spread into the mixing bowl. 1. Put pack of flour into the mixing bowl. 1. Add egg into the mixing bowl. 1. Fold pack of flour into the mixing bowl. 1. Chop carrots until choped. 1. Pour contents of the mixing bowl into the baking dish.
Serves 1. | The only line of input contains a sequence of integers *a*0,<=*a*1,<=... (1<=β€<=*a*0<=β€<=100, 0<=β€<=*a**i*<=β€<=1000 for *i*<=β₯<=1). | Output a single integer. | [
"4 1 2 3 4\n"
] | [
"30\n"
] | none | [
{
"input": "4 1 2 3 4",
"output": "30"
},
{
"input": "4 802 765 992 1",
"output": "5312"
},
{
"input": "4 220 380 729 969",
"output": "7043"
},
{
"input": "3 887 104 641",
"output": "3018"
},
{
"input": "12 378 724 582 387 583 241 294 159 198 653 369 418",
"output": "30198"
},
{
"input": "14 36 901 516 623 703 971 304 394 491 525 464 219 183 648",
"output": "49351"
},
{
"input": "3 287 979 395",
"output": "3430"
},
{
"input": "19 702 667 743 976 908 728 134 106 380 193 214 71 920 114 587 543 817 248 537",
"output": "87024"
},
{
"input": "11 739 752 364 649 626 702 444 913 681 529 959",
"output": "45653"
},
{
"input": "19 196 392 738 103 119 872 900 189 65 113 260 985 228 537 217 735 785 445 636",
"output": "92576"
},
{
"input": "22 196 690 553 822 392 687 425 763 216 73 525 412 155 263 205 965 825 105 153 580 218 103",
"output": "96555"
},
{
"input": "10 136 641 472 872 115 607 197 19 494 577",
"output": "22286"
},
{
"input": "10 5 659 259 120 421 165 194 637 577 39",
"output": "17712"
},
{
"input": "5 472 4 724 577 157",
"output": "5745"
},
{
"input": "23 486 261 249 312 592 411 874 397 18 70 417 512 338 679 517 997 938 328 418 793 522 745 59",
"output": "141284"
},
{
"input": "17 644 532 255 57 108 413 51 284 364 300 597 646 712 470 42 730 231",
"output": "61016"
},
{
"input": "26 932 569 829 138 565 766 466 673 559 678 417 618 930 751 840 184 809 639 287 550 923 341 851 209 987 252",
"output": "207547"
},
{
"input": "16 29 672 601 178 603 860 6 431 114 463 588 788 712 956 895 19",
"output": "73502"
},
{
"input": "5 336 860 760 835 498",
"output": "10166"
},
{
"input": "29 384 110 78 925 320 755 176 690 784 848 981 653 140 840 659 262 954 812 850 431 523 495 16 233 70 352 92 520 877",
"output": "216056"
},
{
"input": "21 256 260 390 24 185 400 780 51 89 253 900 760 906 730 599 565 992 243 66 531 364",
"output": "114365"
},
{
"input": "19 26 380 823 787 422 605 306 298 885 562 249 965 277 124 365 56 175 144 309",
"output": "67719"
},
{
"input": "41 595 215 495 884 470 176 126 536 398 181 816 114 251 328 901 674 933 206 662 507 458 601 162 735 725 217 481 591 51 791 355 646 696 540 530 165 717 346 391 114 527",
"output": "406104"
},
{
"input": "20 228 779 225 819 142 849 24 494 45 172 95 207 908 510 424 78 100 166 869 456",
"output": "78186"
},
{
"input": "15 254 996 341 109 402 688 501 206 905 398 124 373 313 943 515",
"output": "57959"
},
{
"input": "45 657 700 898 830 795 104 427 995 219 505 95 385 64 241 196 318 927 228 428 329 606 619 535 200 707 660 574 19 292 88 872 950 788 769 779 272 563 896 267 782 400 52 857 154 293",
"output": "507143"
},
{
"input": "41 473 219 972 591 238 267 209 464 467 916 814 40 625 105 820 496 54 297 264 523 570 828 418 527 299 509 269 156 663 562 900 826 471 561 416 710 828 315 864 985 230",
"output": "463602"
},
{
"input": "48 25 856 782 535 41 527 832 306 49 91 824 158 618 122 357 887 969 710 138 868 536 610 118 642 9 946 958 873 931 878 549 646 733 20 180 775 547 11 771 287 103 594 135 411 406 492 989 375",
"output": "597376"
},
{
"input": "57 817 933 427 116 51 69 125 687 717 688 307 594 927 643 17 638 823 482 184 525 943 161 318 226 296 419 632 478 97 697 370 915 320 797 30 371 556 847 748 272 224 746 557 151 388 264 789 211 746 663 426 688 825 744 914 811 853",
"output": "900997"
},
{
"input": "55 980 951 933 349 865 252 836 585 313 392 431 751 354 656 496 601 497 885 865 976 786 300 638 211 678 152 645 281 654 187 517 633 137 139 672 692 81 507 968 84 589 398 835 944 744 331 234 931 906 99 906 691 89 234 592",
"output": "810147"
},
{
"input": "100 768 386 927 48 730 113 255 362 942 394 33 323 165 231 290 249 820 379 775 763 813 796 688 744 701 787 339 81 566 573 363 333 650 980 382 379 783 327 432 724 722 155 47 577 386 27 827 206 406 601 659 219 86 346 963 787 823 301 558 389 565 921 412 214 590 484 283 372 812 715 787 533 871 524 109 947 551 626 843 958 917 502 176 2 538 829 479 51 820 36 130 384 647 542 288 236 26 572 609 838",
"output": "2547238"
},
{
"input": "100 977 395 60 537 919 860 484 159 486 326 116 92 518 983 95 747 501 264 798 321 301 928 395 948 469 374 875 185 636 173 22 612 568 82 149 176 633 323 335 118 339 142 901 858 124 686 604 626 951 91 637 251 709 722 889 177 95 453 363 731 626 75 33 193 849 182 59 481 505 395 289 844 537 189 391 351 876 685 667 826 466 994 767 174 716 345 352 501 799 405 923 424 480 956 308 18 828 367 499 22",
"output": "2437955"
},
{
"input": "100 452 788 556 679 978 638 30 543 322 697 368 789 691 825 653 96 169 4 287 968 99 209 392 270 855 700 288 682 757 788 394 209 265 951 888 242 588 918 785 600 305 843 78 686 667 732 472 837 426 759 494 216 969 886 486 513 275 464 886 32 942 279 932 207 920 819 449 197 427 925 798 422 457 566 107 124 988 579 651 414 337 144 320 996 721 806 509 686 960 394 408 902 363 339 108 283 849 247 480 275",
"output": "2696135"
},
{
"input": "100 862 968 697 319 224 494 133 211 763 784 315 99 618 635 786 28 130 985 715 90 68 122 992 431 152 99 404 0 36 575 275 899 542 662 217 456 846 350 668 608 824 673 707 131 308 182 160 438 166 565 218 234 377 209 356 529 999 760 529 35 334 494 624 567 846 841 22 691 881 380 298 394 53 696 215 51 878 375 489 735 630 398 659 7 607 14 536 296 465 756 21 799 249 645 365 786 485 78 476 55",
"output": "2232342"
},
{
"input": "100 458 775 449 511 160 354 252 37 730 432 462 49 830 121 56 126 826 283 422 290 38 443 780 978 87 835 763 262 913 930 317 371 394 456 572 554 811 825 281 230 256 744 970 776 555 26 902 380 1000 324 361 37 457 140 705 545 975 158 497 578 87 505 949 171 651 210 725 151 725 5 71 671 749 41 446 994 67 38 374 66 362 425 794 509 565 188 744 229 346 241 807 123 746 445 294 86 346 709 238 70",
"output": "2200721"
},
{
"input": "100 715 309 432 153 350 568 147 107 606 211 173 658 636 657 167 891 846 911 810 882 842 617 696 277 752 680 364 97 389 602 859 794 601 290 947 952 548 784 58 154 995 923 502 320 579 359 901 424 270 711 997 802 17 692 79 769 371 443 867 760 735 725 553 335 705 190 977 252 974 35 96 659 648 599 669 226 648 570 341 918 971 337 410 988 719 489 446 89 622 312 540 46 727 783 381 431 663 48 374 327",
"output": "2688801"
},
{
"input": "100 774 470 986 421 759 654 647 407 914 678 14 574 705 424 561 423 603 7 203 224 9 743 270 737 215 342 858 569 80 231 896 854 392 881 274 150 224 611 247 829 289 953 402 994 376 654 417 670 351 310 584 360 743 545 787 958 887 645 526 657 876 421 510 267 992 784 108 907 84 355 735 373 307 136 57 374 480 164 43 831 474 317 191 216 862 668 864 438 312 80 94 188 501 604 145 183 77 253 89 162",
"output": "2204266"
},
{
"input": "100 299 824 225 296 650 282 360 130 136 93 651 610 411 842 516 272 200 380 711 512 460 805 390 651 99 536 524 176 479 613 28 468 126 254 765 777 226 124 597 363 218 247 663 629 780 870 901 980 249 301 491 399 106 572 740 205 107 264 71 276 877 791 745 3 44 509 470 961 323 66 13 541 3 367 860 783 236 451 762 175 752 944 574 858 515 313 753 312 577 515 588 454 305 22 147 39 221 617 1000 545",
"output": "2316930"
},
{
"input": "100 373 704 776 376 70 326 850 997 777 611 171 528 244 745 76 449 748 519 451 15 33 730 159 338 752 306 377 974 613 67 208 986 461 984 51 221 309 901 217 776 202 388 304 136 823 70 586 260 589 36 275 623 766 434 651 208 430 28 181 42 786 389 718 246 62 770 467 62 670 684 838 562 762 832 699 274 902 284 224 181 10 500 804 467 624 454 675 54 172 546 96 958 625 505 203 687 274 360 439 634",
"output": "2297827"
},
{
"input": "100 734 968 887 495 799 585 459 391 559 684 572 569 874 375 726 187 519 400 241 382 636 28 339 260 533 233 638 497 283 76 821 17 43 707 512 533 291 662 924 540 35 185 800 599 250 525 786 769 616 27 150 251 746 180 512 969 103 149 465 386 916 976 403 960 683 606 182 664 958 796 204 993 981 3 591 230 218 66 689 834 784 840 85 529 710 597 497 503 746 652 889 661 318 983 310 691 278 182 354 235",
"output": "2604711"
},
{
"input": "100 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",
"output": "5050000"
}
] | 62 | 0 | 3 | 3,589 |
|
1,010 | Fly | [
"binary search",
"math"
] | null | null | Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists of two phases: take-off from planet $x$ and landing to planet $y$. This way, the overall itinerary of the trip will be: the $1$-st planet $\to$ take-off from the $1$-st planet $\to$ landing to the $2$-nd planet $\to$ $2$-nd planet $\to$ take-off from the $2$-nd planet $\to$ $\ldots$ $\to$ landing to the $n$-th planet $\to$ the $n$-th planet $\to$ take-off from the $n$-th planet $\to$ landing to the $1$-st planet $\to$ the $1$-st planet.
The mass of the rocket together with all the useful cargo (but without fuel) is $m$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $1$ ton of fuel can lift off $a_i$ tons of rocket from the $i$-th planet or to land $b_i$ tons of rocket onto the $i$-th planet.
For example, if the weight of rocket is $9$ tons, weight of fuel is $3$ tons and take-off coefficient is $8$ ($a_i = 8$), then $1.5$ tons of fuel will be burnt (since $1.5 \cdot 8 = 9 + 3$). The new weight of fuel after take-off will be $1.5$ tons.
Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.
Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. | The first line contains a single integer $n$ ($2 \le n \le 1000$)Β β number of planets.
The second line contains the only integer $m$ ($1 \le m \le 1000$)Β β weight of the payload.
The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted off by one ton of fuel.
The fourth line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 1000$), where $b_i$ is the number of tons, which can be landed by one ton of fuel.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel. | If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
The answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$. Formally, let your answer be $p$, and the jury's answer be $q$. Your answer is considered correct if $\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$. | [
"2\n12\n11 8\n7 5\n",
"3\n1\n1 4 1\n2 5 3\n",
"6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n"
] | [
"10.0000000000\n",
"-1\n",
"85.4800000000\n"
] | Let's consider the first example.
Initially, the mass of a rocket with fuel is $22$ tons.
- At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fuel can land $5$ tons of cargo, so for landing $20$ tons you will need to burn $4$ tons of fuel. There will be $16$ tons of the rocket with fuel remaining.- While taking off from Mars, one ton of fuel can raise $8$ tons of cargo, so to lift off $16$ tons you will need to burn $2$ tons of fuel. There will be $14$ tons of rocket with fuel after that.- During landing on Earth, one ton of fuel can land $7$ tons of cargo, so for landing $14$ tons you will need to burn $2$ tons of fuel. Remaining weight is $12$ tons, that is, a rocket without any fuel.
In the second case, the rocket will not be able even to take off from Earth. | [
{
"input": "2\n12\n11 8\n7 5",
"output": "10.0000000000"
},
{
"input": "3\n1\n1 4 1\n2 5 3",
"output": "-1"
},
{
"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3",
"output": "85.4800000000"
},
{
"input": "3\n3\n1 2 1\n2 2 2",
"output": "-1"
},
{
"input": "4\n4\n2 3 2 2\n2 3 4 3",
"output": "284.0000000000"
},
{
"input": "5\n2\n1 2 2 1 2\n4 5 1 4 1",
"output": "-1"
},
{
"input": "7\n7\n3 2 6 2 2 2 5\n4 7 5 6 2 2 2",
"output": "4697.0000000000"
},
{
"input": "2\n1000\n12 34\n56 78",
"output": "159.2650775220"
},
{
"input": "8\n4\n1 1 4 1 3 1 8 1\n1 1 1 1 1 3 1 2",
"output": "-1"
},
{
"input": "9\n2\n8 7 1 1 3 7 1 2 4\n4 1 1 8 7 7 1 1 5",
"output": "-1"
},
{
"input": "10\n10\n9 8 8 7 2 10 2 9 2 4\n3 10 6 2 6 6 5 9 4 5",
"output": "3075.7142857143"
},
{
"input": "20\n12\n3 9 12 13 16 18 9 9 19 7 2 5 17 14 7 7 15 16 5 7\n16 9 13 5 14 10 4 3 16 16 12 20 17 11 4 5 5 14 6 15",
"output": "4670.8944493007"
},
{
"input": "30\n5\n25 1 28 1 27 25 24 1 28 1 12 1 29 16 1 1 1 1 27 1 24 1 1 1 1 1 1 1 30 3\n1 22 1 1 24 2 13 1 16 21 1 27 14 16 1 1 7 1 1 18 1 23 10 1 15 16 16 15 10 1",
"output": "-1"
},
{
"input": "40\n13\n1 1 1 23 21 1 1 1 1 1 40 32 1 21 1 8 1 1 36 15 33 1 30 1 1 37 22 1 4 39 7 1 9 37 1 1 1 28 1 1\n1 34 17 1 38 20 8 14 1 18 29 3 21 21 18 14 1 11 1 1 23 1 25 1 14 1 7 31 9 20 25 1 1 1 1 8 26 12 1 1",
"output": "-1"
},
{
"input": "50\n19\n17 7 13 42 19 25 10 25 2 36 17 40 30 48 34 43 34 20 5 15 8 7 43 35 21 40 40 19 30 11 49 7 24 23 43 30 38 49 10 8 30 11 28 50 48 25 25 20 48 24\n49 35 10 22 24 50 50 7 6 13 16 35 12 43 50 44 35 33 38 49 26 18 23 37 7 38 23 20 28 48 41 16 6 32 32 34 11 39 38 9 38 23 16 31 37 47 33 20 46 30",
"output": "7832.1821424977"
},
{
"input": "60\n21\n11 35 1 28 39 13 19 56 13 13 21 25 1 1 23 1 52 26 53 1 1 1 30 39 1 7 1 1 3 1 1 10 1 1 37 1 1 25 1 1 1 53 1 3 48 1 6 5 4 15 1 14 25 53 25 38 27 1 1 1\n1 1 1 35 40 58 10 22 1 56 1 59 1 6 33 1 1 1 1 18 14 1 1 40 25 47 1 34 1 1 53 1 1 25 1 45 1 1 25 34 3 1 1 1 53 27 11 58 1 1 1 10 12 1 1 1 31 52 1 1",
"output": "-1"
},
{
"input": "70\n69\n70 66 57 58 24 60 39 2 48 61 65 22 10 26 68 62 48 25 12 14 45 57 6 30 48 15 46 33 42 28 69 42 64 25 24 8 62 12 68 53 55 20 32 70 3 5 41 49 16 26 2 34 34 20 39 65 18 47 62 31 39 28 61 67 7 14 31 31 53 54\n40 33 24 20 68 20 22 39 53 56 48 38 59 45 47 46 7 69 11 58 61 40 35 38 62 66 18 36 44 48 67 24 14 27 67 63 68 30 50 6 58 7 6 35 20 58 6 12 12 23 14 2 63 27 29 22 49 16 55 40 70 27 27 70 42 38 66 55 69 47",
"output": "217989.4794743629"
},
{
"input": "80\n21\n65 4 26 25 1 1 1 1 1 1 60 1 29 43 48 6 48 13 29 1 1 62 1 1 1 1 1 1 1 26 9 1 22 1 35 13 66 36 1 1 1 38 55 21 70 1 58 70 1 1 38 1 1 20 1 1 51 1 1 28 1 23 11 1 39 47 1 52 41 1 63 1 1 52 1 45 11 10 80 1\n1 1 25 30 1 1 55 54 1 48 10 37 22 1 74 1 78 13 1 65 32 1 1 1 1 69 5 59 1 1 65 1 40 1 31 1 1 75 54 1 60 1 1 1 1 1 1 1 11 29 36 1 72 71 52 1 1 1 37 1 1 75 43 9 53 1 62 1 29 1 40 27 59 74 41 53 19 30 1 73",
"output": "-1"
},
{
"input": "90\n35\n1 68 16 30 24 1 1 1 35 1 1 67 1 1 1 1 33 16 37 77 83 1 77 26 1 1 68 67 70 62 1 47 1 1 1 84 1 65 1 32 83 1 1 1 28 1 71 76 84 1 1 5 1 74 10 1 1 1 38 87 13 1 7 66 81 49 1 9 1 11 1 25 1 1 1 1 7 1 1 36 61 47 51 1 1 69 40 1 37 1\n40 1 21 1 19 51 37 52 64 1 86 1 5 24 1 1 1 19 36 1 1 77 24 4 1 18 89 1 1 1 1 1 29 22 1 80 32 36 6 1 63 1 30 1 1 1 86 79 73 52 9 1 1 11 7 1 25 20 1 20 1 49 1 37 1 41 1 1 1 1 54 55 1 10 1 1 1 1 1 1 66 1 68 1 1 1 1 53 1 1",
"output": "-1"
},
{
"input": "2\n1\n1 1\n1 1",
"output": "-1"
},
{
"input": "2\n1\n1 1\n2 2",
"output": "-1"
},
{
"input": "2\n1\n2 2\n1 1",
"output": "-1"
},
{
"input": "2\n1\n2 2\n2 2",
"output": "15.0000000000"
},
{
"input": "2\n2\n1 1\n1 1",
"output": "-1"
},
{
"input": "2\n2\n1 1\n2 2",
"output": "-1"
},
{
"input": "2\n2\n2 2\n1 1",
"output": "-1"
},
{
"input": "2\n2\n2 2\n2 2",
"output": "30.0000000000"
},
{
"input": "40\n55\n1 382 1 1 1 629 111 689 396 614 1 1 995 148 7 820 913 1 1 169 157 1 702 1 159 1 1 226 1 253 1 319 1 130 1 1 1 466 1 756\n1 23 555 1 412 1 1 373 316 234 888 1 112 818 33 443 313 1 235 1 1 610 110 535 1 445 1 386 1 1 758 1 292 1 862 1 244 428 530 1",
"output": "-1"
},
{
"input": "49\n1\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\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 3 3",
"output": "695580114.6380882263"
},
{
"input": "2\n12\n11 8\n1 1",
"output": "-1"
},
{
"input": "3\n3\n7 11 17\n19 31 33",
"output": "1.6012429470"
}
] | 77 | 1,843,200 | 3 | 3,615 |
|
698 | LRU | [
"bitmasks",
"dp",
"math",
"probabilities"
] | null | null | While creating high loaded systems one should pay a special attention to caching. This problem will be about one of the most popular caching algorithms called LRU (Least Recently Used).
Suppose the cache may store no more than *k* objects. At the beginning of the workflow the cache is empty. When some object is queried we check if it is present in the cache and move it here if it's not. If there are more than *k* objects in the cache after this, the least recently used one should be removed. In other words, we remove the object that has the smallest time of the last query.
Consider there are *n* videos being stored on the server, all of the same size. Cache can store no more than *k* videos and caching algorithm described above is applied. We know that any time a user enters the server he pick the video *i* with probability *p**i*. The choice of the video is independent to any events before.
The goal of this problem is to count for each of the videos the probability it will be present in the cache after 10100 queries. | The first line of the input contains two integers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=20)Β β the number of videos and the size of the cache respectively. Next line contains *n* real numbers *p**i* (0<=β€<=*p**i*<=β€<=1), each of them is given with no more than two digits after decimal point.
It's guaranteed that the sum of all *p**i* is equal to 1. | Print *n* real numbers, the *i*-th of them should be equal to the probability that the *i*-th video will be present in the cache after 10100 queries. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"3 1\n0.3 0.2 0.5\n",
"2 1\n0.0 1.0\n",
"3 2\n0.3 0.2 0.5\n",
"3 3\n0.2 0.3 0.5\n"
] | [
"0.3 0.2 0.5 ",
"0.0 1.0 ",
"0.675 0.4857142857142857 0.8392857142857143 ",
"1.0 1.0 1.0 "
] | none | [
{
"input": "3 1\n0.3 0.2 0.5",
"output": "0.3 0.2 0.5 "
},
{
"input": "2 1\n0.0 1.0",
"output": "0.0 1.0 "
},
{
"input": "3 2\n0.3 0.2 0.5",
"output": "0.675 0.4857142857142857 0.8392857142857143 "
},
{
"input": "3 3\n0.2 0.3 0.5",
"output": "1.0 1.0 1.0 "
},
{
"input": "1 1\n1.0",
"output": "1.0 "
},
{
"input": "10 1\n0.12 0.14 0.13 0.08 0.15 0.10 0.15 0.04 0.02 0.07",
"output": "0.12 0.14 0.13 0.08 0.15 0.1 0.15 0.04 0.02 0.07 "
},
{
"input": "10 5\n0.02 0.17 0.04 0.07 0.21 0.06 0.09 0.11 0.17 0.06",
"output": "0.1399910871034487 0.7479501842209872 0.2655803706306279 0.4263090048227962 0.8140604521856322 0.3764316851562892 0.5151587224363868 0.5901366240665537 0.747950184220987 0.3764316851562893 "
},
{
"input": "10 10\n0.02 0.03 0.12 0.21 0.07 0.15 0.21 0.14 0.01 0.04",
"output": "0.9999999999999996 0.9999999999999993 1.0000000000000004 1.0000000000000002 0.9999999999999994 1.0000000000000002 1.0000000000000002 1.0000000000000007 0.9999999999999984 0.9999999999999984 "
},
{
"input": "20 10\n0.07 0.03 0.02 0.02 0.09 0.07 0.07 0.09 0.01 0.08 0.05 0.06 0.04 0.08 0.03 0.02 0.01 0.06 0.08 0.02",
"output": "0.6690974251255742 0.37305204013382764 0.26536469553087033 0.26536469553087033 0.7578934285796217 0.6690974251255744 0.6690974251255744 0.7578934285796214 0.14136644265973128 0.717224662240763 0.5449021980374016 0.6121580456838637 0.4657328436268002 0.7172246622407633 0.37305204013382287 0.2653646955308738 0.1413664426597324 0.6121580456838935 0.7172246622407644 0.2653646955308683 "
},
{
"input": "20 10\n0.02 0.07 0.06 0.05 0.07 0.06 0.04 0.01 0.04 0.03 0.03 0.02 0.07 0.06 0.07 0.04 0.06 0.07 0.07 0.06",
"output": "0.25099104075340506 0.644512766322346 0.5875204969870276 0.5210106645274739 0.644512766322346 0.5875204969870277 0.44363944860925325 0.1332915344470896 0.44363944860925325 0.354059145410146 0.354059145410146 0.25099104075340534 0.6445127663223461 0.5875204969870305 0.6445127663223461 0.4436394486092542 0.5875204969870291 0.6445127663223555 0.6445127663223555 0.5875204969869904 "
},
{
"input": "20 10\n0.02 0.04 0.01 0.04 0.09 0.09 0.09 0.02 0.04 0.03 0.11 0.07 0.06 0.02 0.03 0.01 0.01 0.03 0.11 0.08",
"output": "0.2795437203043747 0.4869171151926799 0.14942046819622407 0.4869171151926799 0.7782038002899797 0.7782038002899797 0.7782038002899797 0.27954372030437463 0.48691711519268027 0.39154156049777117 0.838922780730839 0.6915248110074876 0.6350078181751538 0.2795437203043719 0.3915415604977727 0.14942046819622568 0.14942046819622568 0.3915415604977847 0.8389227807307885 0.7387418159128292 "
},
{
"input": "20 10\n0.03 0.06 0.07 0.01 0.02 0.05 0.04 0.02 0.04 0.03 0.01 0.08 0.07 0.07 0.08 0.08 0.06 0.08 0.09 0.01",
"output": "0.3712914845948875 0.6099748765150452 0.6669519822288402 0.1405998407706366 0.26401518486789877 0.5427519025083002 0.46371385128623027 0.26401518486789854 0.46371385128623027 0.3712914845948875 0.14059984077063664 0.7151639223296767 0.6669519822288443 0.6669519822288443 0.7151639223296734 0.7151639223296734 0.6099748765150346 0.7151639223296734 0.7559461446464355 0.14059984077062102 "
},
{
"input": "20 10\n0.03 0.04 0.05 0.00 0.00 0.08 0.03 0.08 0.07 0.02 0.07 0.09 0.04 0.01 0.05 0.09 0.04 0.05 0.07 0.09",
"output": "0.3778442856123409 0.47134785689920056 0.5510150378675547 0.0 0.0 0.7234472395365301 0.37784428561234096 0.7234472395365301 0.6754563322295303 0.26896450581056675 0.6754563322295305 0.7638736323225985 0.4713478568991996 0.14337386593467152 0.5510150378675541 0.7638736323225961 0.47134785689919867 0.5510150378675526 0.67545633222953 0.763873632322598 "
},
{
"input": "20 10\n0.03 0.05 0.02 0.08 0.04 0.05 0.08 0.08 0.08 0.02 0.08 0.01 0.05 0.05 0.02 0.07 0.09 0.00 0.07 0.03",
"output": "0.37243950639307966 0.544208458773671 0.2648804623070527 0.7166425092013716 0.46505497136760304 0.544208458773671 0.7166425092013716 0.7166425092013716 0.7166425092013716 0.2648804623070529 0.7166425092013721 0.14108407922769203 0.5442084587736682 0.5442084587736682 0.26488046230705525 0.66846334603609 0.757367476523396 0.0 0.66846334603609 0.3724395063931443 "
},
{
"input": "20 10\n0.00 0.00 0.00 0.08 0.16 0.00 0.26 0.02 0.00 0.03 0.19 0.00 0.00 0.14 0.00 0.05 0.00 0.01 0.06 0.00",
"output": "0.0 0.0 0.0 1.000000000000001 1.0000000000000004 0.0 0.9999999999999997 0.9999999999999997 0.0 0.9999999999999998 0.9999999999999996 0.0 0.0 1.0000000000000004 0.0 0.9999999999999997 0.0 0.9999999999999998 0.9999999999999992 0.0 "
},
{
"input": "20 10\n0.10 0.11 0.06 0.11 0.03 0.00 0.00 0.01 0.00 0.00 0.08 0.00 0.01 0.10 0.14 0.16 0.00 0.00 0.00 0.09",
"output": "0.9702782007919801 0.9769622705276968 0.9058158749047228 0.9769622705276967 0.7170340277090191 0.0 0.0 0.29571986132381933 0.0 0.0 0.948715515948032 0.0 0.29571986132381944 0.9702782007919795 0.9886519061716066 0.9926478600635664 0.0 0.0 0.0 0.9612141499160587 "
},
{
"input": "20 10\n0.17 0.09 0.01 0.00 0.05 0.00 0.10 0.00 0.19 0.00 0.08 0.00 0.13 0.00 0.18 0.00 0.00 0.00 0.00 0.00",
"output": "1.0000000000000004 1.0000000000000004 0.9999999999999994 0.0 0.9999999999999998 0.0 0.9999999999999999 0.0 1.0000000000000002 0.0 1.0 0.0 1.0000000000000004 0.0 1.0000000000000007 0.0 0.0 0.0 0.0 0.0 "
},
{
"input": "20 10\n0.10 0.01 0.00 0.00 0.00 0.00 0.00 0.58 0.03 0.00 0.14 0.00 0.11 0.00 0.00 0.00 0.03 0.00 0.00 0.00",
"output": "1.0000000000000002 0.999999999999998 0.0 0.0 0.0 0.0 0.0 1.0 0.9999999999999987 0.0 0.9999999999999996 0.0 1.0000000000000002 0.0 0.0 0.0 0.9999999999999989 0.0 0.0 0.0 "
},
{
"input": "10 2\n0.03 0.23 0.18 0.00 0.03 0.08 0.26 0.08 0.04 0.07",
"output": "0.06574023622726129 0.4424205811028936 0.36049623255089486 0.0 0.06574023622726129 0.1708250016710234 0.4864385997316486 0.17082500167102338 0.08722409503841025 0.15029001577958354 "
},
{
"input": "10 3\n0.02 0.21 0.03 0.17 0.11 0.21 0.10 0.06 0.04 0.05",
"output": "0.0707671665235638 0.572620351642748 0.1050266762091833 0.4946967070259397 0.3494970231490039 0.572620351642748 0.32199621653284904 0.20306812742332853 0.1385100970253048 0.1711972828253307 "
},
{
"input": "10 4\n0.02 0.06 0.23 0.17 0.01 0.07 0.03 0.11 0.24 0.06",
"output": "0.10975537665502762 0.3051984542478531 0.7678129184658183 0.6636945863049896 0.05583801838076966 0.34877017466415117 0.16169970181895205 0.5008950990137218 0.7811372162008635 0.30519845424785336 "
},
{
"input": "10 6\n0.02 0.16 0.13 0.02 0.05 0.17 0.17 0.09 0.14 0.05",
"output": "0.1908891127632005 0.8378650050267057 0.7760529267484847 0.19088911276320047 0.4260110846599223 0.8538288809282245 0.8538288809282245 0.6452986631606833 0.7993252483614335 0.4260110846599222 "
},
{
"input": "10 7\n0.02 0.21 0.03 0.17 0.11 0.21 0.10 0.06 0.04 0.05",
"output": "0.2842926499039299 0.9644317779231261 0.40270634337736644 0.9403336125112673 0.8564352604856355 0.9644317779231263 0.8312918049552955 0.6606737030665756 0.5048019502306894 0.5906011196229873 "
},
{
"input": "10 8\n0.02 0.08 0.09 0.09 0.08 0.19 0.14 0.07 0.19 0.05",
"output": "0.32594681031186507 0.8213376231015499 0.8540871594909123 0.8540871594909123 0.82133762310155 0.9735634149906833 0.9415368103143239 0.7794744071864103 0.9735634149906834 0.6550655770211107 "
},
{
"input": "10 9\n0.02 0.00 0.16 0.03 0.20 0.12 0.17 0.14 0.07 0.09",
"output": "1.000000000000003 0.0 1.0000000000000007 1.000000000000002 1.0000000000000002 0.9999999999999999 1.0000000000000009 1.0000000000000002 1.0000000000000004 1.000000000000001 "
},
{
"input": "3 2\n0.08 0.79 0.13",
"output": "0.3929064039408868 0.9767416291854074 0.6303519668737061 "
},
{
"input": "1 1\n1.00",
"output": "1.0 "
},
{
"input": "4 2\n0.05 0.50 0.40 0.05",
"output": "0.1359649122807018 0.8859649122807017 0.8421052631578948 0.1359649122807018 "
},
{
"input": "10 4\n0.17 0.08 0.25 0.01 0.00 0.00 0.00 0.00 0.15 0.34",
"output": "0.807383060835042 0.5056591310919583 0.8997295433518943 0.07312969011105623 0.0 0.0 0.0 0.0 0.7681890555425176 0.9459095190675326 "
},
{
"input": "10 2\n0.26 0.00 0.17 0.05 0.00 0.04 0.33 0.15 0.00 0.00",
"output": "0.5117126103415558 0.0 0.35949177476769784 0.11334225983972909 0.0 0.09111240436301137 0.6028900225620077 0.3214509281259984 0.0 0.0 "
},
{
"input": "10 7\n0.00 0.09 0.00 0.00 0.47 0.00 0.00 0.00 0.24 0.20",
"output": "0.0 0.9999999999999994 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.9999999999999997 "
},
{
"input": "10 8\n0.27 0.00 0.09 0.08 0.00 0.00 0.13 0.43 0.00 0.00",
"output": "1.0 0.0 1.0 0.9999999999999998 0.0 0.0 0.9999999999999999 1.0 0.0 0.0 "
},
{
"input": "20 1\n0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00",
"output": "0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 "
},
{
"input": "20 2\n1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00",
"output": "1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 "
},
{
"input": "20 3\n0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00",
"output": "0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 "
},
{
"input": "20 20\n0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00",
"output": "0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 "
},
{
"input": "5 2\n1.00 0.00 0.00 0.00 0.00",
"output": "1.0 0.0 0.0 0.0 0.0 "
},
{
"input": "20 19\n0.01 0.01 0.01 0.11 0.01 0.01 0.02 0.08 0.00 0.06 0.09 0.12 0.02 0.08 0.07 0.01 0.05 0.04 0.11 0.09",
"output": "0.9999999999999774 0.9999999999999774 0.9999999999999774 0.9999999999999416 0.9999999999999775 0.9999999999999775 1.0000000000000326 0.9999999999998995 0.0 0.9999999999999348 1.0000000000000095 1.0000000000000588 1.0000000000000338 0.9999999999998964 1.000000000000197 0.9999999999999984 0.999999999999947 1.0000000000000104 0.9999999999999113 1.0000000000000189 "
},
{
"input": "20 20\n0.02 0.04 0.10 0.03 0.09 0.02 0.05 0.05 0.00 0.08 0.02 0.03 0.04 0.10 0.02 0.06 0.05 0.08 0.07 0.05",
"output": "0.9999999999999967 1.000000000000045 1.0000000000000897 1.0000000000000033 0.9999999999998742 0.9999999999999971 0.9999999999999493 0.9999999999999493 0.0 1.0000000000000073 0.9999999999999973 1.000000000000003 1.0000000000000437 1.0000000000000897 0.9999999999999967 1.0000000000000187 0.9999999999999478 0.9999999999999858 1.0000000000001537 1.0000000000000426 "
},
{
"input": "2 1\n0.5 0.5",
"output": "0.5 0.5 "
},
{
"input": "2 2\n0.5 0.5",
"output": "1.0 1.0 "
},
{
"input": "2 2\n0 1",
"output": "0.0 1.0 "
},
{
"input": "2 2\n1.0 0.0",
"output": "1.0 0.0 "
},
{
"input": "3 3\n0 0 1",
"output": "0.0 0.0 1.0 "
},
{
"input": "4 4\n0 0.5 0 0.5",
"output": "0.0 1.0 0.0 1.0 "
},
{
"input": "2 2\n0.0 1.0",
"output": "0.0 1.0 "
},
{
"input": "5 4\n0.3 0.2 0.5 0 0",
"output": "1.0 1.0 1.0 0.0 0.0 "
},
{
"input": "2 2\n1 0",
"output": "1.0 0.0 "
},
{
"input": "5 4\n0.3 0.2 0.5 0.0 0.0",
"output": "1.0 1.0 1.0 0.0 0.0 "
},
{
"input": "3 3\n0.0 1.0 0.0",
"output": "0.0 1.0 0.0 "
},
{
"input": "5 3\n1.0 0.0 0.0 0.0 0.0",
"output": "1.0 0.0 0.0 0.0 0.0 "
},
{
"input": "2 2\n1.00 0.00",
"output": "1.0 0.0 "
},
{
"input": "4 3\n0.5 0 0.5 0",
"output": "1.0 0.0 1.0 0.0 "
},
{
"input": "5 5\n0.5 0.5 0 0 0",
"output": "1.0 1.0 0.0 0.0 0.0 "
},
{
"input": "3 3\n0 0.5 0.5",
"output": "0.0 1.0 1.0 "
},
{
"input": "5 4\n0.50 0.50 0.00 0.00 0.00",
"output": "1.0 1.0 0.0 0.0 0.0 "
},
{
"input": "3 2\n1 0 0",
"output": "1.0 0.0 0.0 "
},
{
"input": "3 3\n1 0 0",
"output": "1.0 0.0 0.0 "
},
{
"input": "10 5\n0.4 0.4 0.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0",
"output": "1.0000000000000002 1.0000000000000002 1.0000000000000002 0.0 0.0 0.0 0.0 0.0 0.0 0.0 "
},
{
"input": "6 6\n0 0.5 0 0.5 0 0",
"output": "0.0 1.0 0.0 1.0 0.0 0.0 "
},
{
"input": "4 4\n0.0 0.0 1.0 0.0",
"output": "0.0 0.0 1.0 0.0 "
},
{
"input": "10 5\n0.5 0 0 0.5 0 0 0 0 0 0",
"output": "1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 "
},
{
"input": "3 2\n0.0 0.0 1.0",
"output": "0.0 0.0 1.0 "
},
{
"input": "4 3\n1.00 0.00 0.00 0.00",
"output": "1.0 0.0 0.0 0.0 "
},
{
"input": "20 19\n0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05",
"output": "0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 0.9499999999975302 "
},
{
"input": "3 3\n0.5 0.5 0",
"output": "1.0 1.0 0.0 "
}
] | 77 | 2,867,200 | -1 | 3,627 |
|
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"
}
] | 92 | 5,529,600 | 0 | 3,629 |
|
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 | 0 | 0 | 3,631 |
|
868 | Bark to Unlock | [
"brute force",
"implementation",
"strings"
] | null | null | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not. | The first line contains two lowercase English lettersΒ β the password on the phone.
The second line contains single integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of words Kashtanka knows.
The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct. | Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ah\n1\nha\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.
In the third example the string "hahahaha" contains "ah" as a substring. | [
{
"input": "ya\n4\nah\noy\nto\nha",
"output": "YES"
},
{
"input": "hp\n2\nht\ntp",
"output": "NO"
},
{
"input": "ah\n1\nha",
"output": "YES"
},
{
"input": "bb\n4\nba\nab\naa\nbb",
"output": "YES"
},
{
"input": "bc\n4\nca\nba\nbb\ncc",
"output": "YES"
},
{
"input": "ba\n4\ncd\nad\ncc\ncb",
"output": "YES"
},
{
"input": "pg\n4\nzl\nxs\ndi\nxn",
"output": "NO"
},
{
"input": "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza\nuf\nhq\nmc\nmn\nti\nwn\nsh\nax\nsi\nnd\ntz\ndu\nfj\nkl\nws\now\nnf\nvr\nye\nzc\niw\nfv\nkv\noo\nsm\nbc\nrs\nau\nuz\nuv\ngh\nsu\njn\ndz\nrl\nwj\nbk\nzl\nas\nms\nit\nwu",
"output": "YES"
},
{
"input": "bb\n1\naa",
"output": "NO"
},
{
"input": "qm\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm",
"output": "NO"
},
{
"input": "mq\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm",
"output": "YES"
},
{
"input": "aa\n1\naa",
"output": "YES"
},
{
"input": "bb\n1\nbb",
"output": "YES"
},
{
"input": "ba\n1\ncc",
"output": "NO"
},
{
"input": "ha\n1\nha",
"output": "YES"
},
{
"input": "aa\n1\naa",
"output": "YES"
},
{
"input": "ez\n1\njl",
"output": "NO"
},
{
"input": "aa\n2\nab\nba",
"output": "YES"
},
{
"input": "aa\n2\nca\ncc",
"output": "NO"
},
{
"input": "dd\n2\nac\ndc",
"output": "NO"
},
{
"input": "qc\n2\nyc\nkr",
"output": "NO"
},
{
"input": "aa\n3\nba\nbb\nab",
"output": "YES"
},
{
"input": "ca\n3\naa\nbb\nab",
"output": "NO"
},
{
"input": "ca\n3\nbc\nbd\nca",
"output": "YES"
},
{
"input": "dd\n3\nmt\nrg\nxl",
"output": "NO"
},
{
"input": "be\n20\nad\ncd\ncb\ndb\ndd\naa\nab\nca\nae\ned\ndc\nbb\nba\nda\nee\nea\ncc\nac\nec\neb",
"output": "YES"
},
{
"input": "fc\n20\nca\nbb\nce\nfd\nde\nfa\ncc\nec\nfb\nfc\nff\nbe\ncf\nba\ndb\ned\naf\nae\nda\nef",
"output": "YES"
},
{
"input": "ca\n20\ndc\naf\ndf\neg\naa\nbc\nea\nbd\nab\ndb\ngc\nfb\nba\nbe\nee\ngf\ncf\nag\nga\nca",
"output": "YES"
},
{
"input": "ke\n20\nzk\nra\nbq\nqz\nwt\nzg\nmz\nuk\nge\nuv\nud\nfd\neh\ndm\nsk\nki\nfv\ntp\nat\nfb",
"output": "YES"
},
{
"input": "hh\n50\nag\nhg\ndg\nfh\neg\ngh\ngd\nda\nbh\nab\nhf\ndc\nhb\nfe\nad\nec\nac\nfd\nca\naf\ncg\nhd\neb\nce\nhe\nha\ngb\nea\nae\nfb\nff\nbe\nch\nhh\nee\nde\nge\ngf\naa\ngg\neh\ned\nbf\nfc\nah\nga\nbd\ncb\nbg\nbc",
"output": "YES"
},
{
"input": "id\n50\nhi\ndc\nfg\nee\ngi\nhc\nac\nih\ndg\nfc\nde\ned\nie\neb\nic\ncf\nib\nfa\ngc\nba\nbe\nga\nha\nhg\nia\ndf\nab\nei\neh\nad\nii\nci\ndh\nec\nif\ndi\nbg\nag\nhe\neg\nca\nae\ndb\naa\nid\nfh\nhh\ncc\nfb\ngb",
"output": "YES"
},
{
"input": "fe\n50\nje\nbi\nbg\ngc\nfb\nig\ndf\nji\ndg\nfe\nfc\ncf\ngf\nai\nhe\nac\nch\nja\ngh\njf\nge\ncb\nij\ngb\ncg\naf\neh\nee\nhd\njd\njb\nii\nca\nci\nga\nab\nhi\nag\nfj\nej\nfi\nie\ndj\nfg\nef\njc\njg\njh\nhf\nha",
"output": "YES"
},
{
"input": "rn\n50\nba\nec\nwg\nao\nlk\nmz\njj\ncf\nfa\njk\ndy\nsz\njs\nzr\nqv\ntx\nwv\nrd\nqw\nls\nrr\nvt\nrx\nkc\neh\nnj\niq\nyi\nkh\nue\nnv\nkz\nrn\nes\nua\nzf\nvu\nll\neg\nmj\ncz\nzj\nxz\net\neb\nci\nih\nig\nam\nvd",
"output": "YES"
},
{
"input": "ee\n100\nah\nfb\ncd\nbi\nii\nai\nid\nag\nie\nha\ndi\nec\nae\nce\njb\ndg\njg\ngd\ngf\nda\nih\nbd\nhj\ngg\nhb\ndf\ned\nfh\naf\nja\nci\nfc\nic\nji\nac\nhi\nfj\nch\nbc\njd\naa\nff\nad\ngj\nej\nde\nee\nhe\ncf\nga\nia\ncg\nbb\nhc\nbe\ngi\njf\nbg\naj\njj\nbh\nfe\ndj\nef\ngb\nge\ndb\nig\ncj\ndc\nij\njh\nei\ndd\nib\nhf\neg\nbf\nfg\nab\ngc\nfd\nhd\ngh\neh\njc\neb\nhh\nca\nje\nbj\nif\nea\nhg\nfa\ncc\nba\ndh\ncb\nfi",
"output": "YES"
},
{
"input": "if\n100\njd\nbc\nje\nhi\nga\nde\nkb\nfc\ncd\ngd\naj\ncb\nei\nbf\ncf\ndk\ndb\ncg\nki\ngg\nkg\nfa\nkj\nii\njf\njg\ngb\nbh\nbg\neh\nhj\nhb\ndg\ndj\njc\njb\nce\ndi\nig\nci\ndf\nji\nhc\nfk\naf\nac\ngk\nhd\nae\nkd\nec\nkc\neb\nfh\nij\nie\nca\nhh\nkf\nha\ndd\nif\nef\nih\nhg\nej\nfe\njk\nea\nib\nck\nhf\nak\ngi\nch\ndc\nba\nke\nad\nka\neg\njh\nja\ngc\nfd\ncc\nab\ngj\nik\nfg\nbj\nhe\nfj\nge\ngh\nhk\nbk\ned\nid\nfi",
"output": "YES"
},
{
"input": "kd\n100\nek\nea\nha\nkf\nkj\ngh\ndl\nfj\nal\nga\nlj\nik\ngd\nid\ncb\nfh\ndk\nif\nbh\nkb\nhc\nej\nhk\ngc\ngb\nef\nkk\nll\nlf\nkh\ncl\nlh\njj\nil\nhh\nci\ndb\ndf\ngk\njg\nch\nbd\ncg\nfg\nda\neb\nlg\ndg\nbk\nje\nbg\nbl\njl\ncj\nhb\nei\naa\ngl\nka\nfa\nfi\naf\nkc\nla\ngi\nij\nib\nle\ndi\nck\nag\nlc\nca\nge\nie\nlb\nke\nii\nae\nig\nic\nhe\ncf\nhd\nak\nfb\nhi\ngf\nad\nba\nhg\nbi\nkl\nac\ngg\ngj\nbe\nlk\nld\naj",
"output": "YES"
},
{
"input": "ab\n1\nab",
"output": "YES"
},
{
"input": "ya\n1\nya",
"output": "YES"
},
{
"input": "ay\n1\nyb",
"output": "NO"
},
{
"input": "ax\n2\nii\nxa",
"output": "YES"
},
{
"input": "hi\n1\nhi",
"output": "YES"
},
{
"input": "ag\n1\nag",
"output": "YES"
},
{
"input": "th\n1\nth",
"output": "YES"
},
{
"input": "sb\n1\nsb",
"output": "YES"
},
{
"input": "hp\n1\nhp",
"output": "YES"
},
{
"input": "ah\n1\nah",
"output": "YES"
},
{
"input": "ta\n1\nta",
"output": "YES"
},
{
"input": "tb\n1\ntb",
"output": "YES"
},
{
"input": "ab\n5\nca\nda\nea\nfa\nka",
"output": "NO"
},
{
"input": "ac\n1\nac",
"output": "YES"
},
{
"input": "ha\n2\nha\nzz",
"output": "YES"
},
{
"input": "ok\n1\nok",
"output": "YES"
},
{
"input": "bc\n1\nbc",
"output": "YES"
},
{
"input": "az\n1\nzz",
"output": "NO"
},
{
"input": "ab\n2\nba\ntt",
"output": "YES"
},
{
"input": "ah\n2\nap\nhp",
"output": "NO"
},
{
"input": "sh\n1\nsh",
"output": "YES"
},
{
"input": "az\n1\nby",
"output": "NO"
},
{
"input": "as\n1\nas",
"output": "YES"
},
{
"input": "ab\n2\nab\ncd",
"output": "YES"
},
{
"input": "ab\n2\nxa\nza",
"output": "NO"
},
{
"input": "ab\n2\net\nab",
"output": "YES"
},
{
"input": "ab\n1\naa",
"output": "NO"
},
{
"input": "ab\n2\nab\nde",
"output": "YES"
},
{
"input": "ah\n2\nba\nha",
"output": "YES"
},
{
"input": "ha\n3\ndd\ncc\nha",
"output": "YES"
},
{
"input": "oo\n1\nox",
"output": "NO"
},
{
"input": "ab\n2\nax\nbx",
"output": "NO"
},
{
"input": "ww\n4\nuw\now\npo\nko",
"output": "NO"
},
{
"input": "ay\n1\nay",
"output": "YES"
},
{
"input": "yo\n1\nyo",
"output": "YES"
},
{
"input": "ba\n1\nba",
"output": "YES"
},
{
"input": "qw\n1\nqw",
"output": "YES"
},
{
"input": "la\n1\nla",
"output": "YES"
},
{
"input": "ab\n2\nbb\nbc",
"output": "NO"
},
{
"input": "aa\n2\nab\nac",
"output": "NO"
},
{
"input": "ah\n2\nbb\nha",
"output": "YES"
},
{
"input": "ya\n42\nab\nac\nad\nae\naf\nag\nah\nai\nak\naj\nba\nbc\nbd\nbe\nbf\nbg\nbh\nbi\nbk\nbj\ncb\nca\ncd\nce\ncf\ncg\nch\nci\nck\ncj\ndb\ndc\nda\nde\ndf\ndg\ndh\ndi\ndk\ndj\nef\nek",
"output": "NO"
},
{
"input": "ab\n3\nab\nxx\nyy",
"output": "YES"
},
{
"input": "ab\n2\nab\ncc",
"output": "YES"
},
{
"input": "sa\n2\nxx\nas",
"output": "YES"
},
{
"input": "ma\n1\nma",
"output": "YES"
},
{
"input": "ba\n1\nbb",
"output": "NO"
},
{
"input": "bc\n1\nab",
"output": "NO"
},
{
"input": "fa\n1\nfa",
"output": "YES"
},
{
"input": "ap\n1\nap",
"output": "YES"
},
{
"input": "ab\n1\nbb",
"output": "NO"
},
{
"input": "bk\n1\nbk",
"output": "YES"
},
{
"input": "xy\n2\nxy\naa",
"output": "YES"
},
{
"input": "ab\n2\nza\nbz",
"output": "YES"
}
] | 108 | 0 | 0 | 3,639 |
|
0 | none | [
"none"
] | null | null | Π ΠΠ΅ΡΠ»ΡΠ½Π΄ΡΠΊΠΎΠΌ Π³ΠΎΡΡΠ΄Π°ΡΡΡΠ²Π΅Π½Π½ΠΎΠΌ ΡΠ½ΠΈΠ²Π΅ΡΡΠΈΡΠ΅ΡΠ΅ Π»ΠΎΠΊΠ°Π»ΡΠ½Π°Ρ ΡΠ΅ΡΡ ΠΌΠ΅ΠΆΠ΄Ρ ΡΠ΅ΡΠ²Π΅ΡΠ°ΠΌΠΈ Π½Π΅ Π²ΡΠ΅Π³Π΄Π° ΡΠ°Π±ΠΎΡΠ°Π΅Ρ Π±Π΅Π· ΠΎΡΠΈΠ±ΠΎΠΊ. ΠΡΠΈ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΠ΅ Π΄Π²ΡΡ
ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²ΡΡ
ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠΉ ΠΏΠΎΠ΄ΡΡΠ΄ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Π° ΠΎΡΠΈΠ±ΠΊΠ°, Π² ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ΅ ΠΊΠΎΡΠΎΡΠΎΠΉ ΡΡΠΈ Π΄Π²Π° ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ ΡΠ»ΠΈΠ²Π°ΡΡΡΡ Π² ΠΎΠ΄Π½ΠΎ. ΠΡΠΈ ΡΠ°ΠΊΠΎΠΌ ΡΠ»ΠΈΡΠ½ΠΈΠΈ ΠΊΠΎΠ½Π΅Ρ ΠΏΠ΅ΡΠ²ΠΎΠ³ΠΎ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ ΡΠΎΠ²ΠΌΠ΅ΡΠ°Π΅ΡΡΡ Ρ Π½Π°ΡΠ°Π»ΠΎΠΌ Π²ΡΠΎΡΠΎΠ³ΠΎ. ΠΠΎΠ½Π΅ΡΠ½ΠΎ, ΡΠΎΠ²ΠΌΠ΅ΡΠ΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ ΠΏΡΠΎΠΈΡΡ
ΠΎΠ΄ΠΈΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΠΏΠΎ ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²ΡΠΌ ΡΠΈΠΌΠ²ΠΎΠ»Π°ΠΌ. ΠΠ»ΠΈΠ½Π° ΡΠΎΠ²ΠΌΠ΅ΡΠ΅Π½ΠΈΡ Π΄ΠΎΠ»ΠΆΠ½Π° Π±ΡΡΡ ΠΏΠΎΠ»ΠΎΠΆΠΈΡΠ΅Π»ΡΠ½ΡΠΌ ΡΠΈΡΠ»ΠΎΠΌ, ΠΌΠ΅Π½ΡΡΠΈΠΌ Π΄Π»ΠΈΠ½Ρ ΡΠ΅ΠΊΡΡΠ° ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ.
ΠΠ°ΠΏΡΠΈΠΌΠ΅Ρ, ΠΏΡΠΈ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΠ΅ Π΄Π²ΡΡ
ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠΉ Β«abrakadabraΒ» ΠΏΠΎΠ΄ΡΡΠ΄ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, ΡΡΠΎ ΠΎΠ½ΠΎ Π±ΡΠ΄Π΅Ρ ΠΏΠ΅ΡΠ΅Π΄Π°Π½ΠΎ Ρ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ ΠΎΠΏΠΈΡΠ°Π½Π½ΠΎΠ³ΠΎ Π²ΠΈΠ΄Π°, ΠΈ ΡΠΎΠ³Π΄Π° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΎ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠ΅ Π²ΠΈΠ΄Π° Β«abrakadabrabrakadabraΒ» ΠΈΠ»ΠΈ Β«abrakadabrakadabraΒ» (Π² ΠΏΠ΅ΡΠ²ΠΎΠΌ ΡΠ»ΡΡΠ°Π΅ ΡΠΎΠ²ΠΌΠ΅ΡΠ΅Π½ΠΈΠ΅ ΠΏΡΠΎΠΈΠ·ΠΎΡΠ»ΠΎ ΠΏΠΎ ΠΎΠ΄Π½ΠΎΠΌΡ ΡΠΈΠΌΠ²ΠΎΠ»Ρ, Π° Π²ΠΎ Π²ΡΠΎΡΠΎΠΌ β ΠΏΠΎ ΡΠ΅ΡΡΡΠ΅ΠΌ).
ΠΠΎ ΠΏΠΎΠ»ΡΡΠ΅Π½Π½ΠΎΠΌΡ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ *t* ΠΎΠΏΡΠ΅Π΄Π΅Π»ΠΈΡΠ΅, Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Π»ΠΈ, ΡΡΠΎ ΡΡΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΠΎΡΠΈΠ±ΠΊΠΈ ΠΎΠΏΠΈΡΠ°Π½Π½ΠΎΠ³ΠΎ Π²ΠΈΠ΄Π° ΡΠ°Π±ΠΎΡΡ Π»ΠΎΠΊΠ°Π»ΡΠ½ΠΎΠΉ ΡΠ΅ΡΠΈ, ΠΈ Π΅ΡΠ»ΠΈ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, ΠΎΠΏΡΠ΅Π΄Π΅Π»ΠΈΡΠ΅ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ *s*.
ΠΠ΅ ΡΠ»Π΅Π΄ΡΠ΅Ρ ΡΡΠΈΡΠ°ΡΡ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ ΡΠΈΡΡΠ°ΡΠΈΡ ΠΏΠΎΠ»Π½ΠΎΠ³ΠΎ Π½Π°Π»ΠΎΠΆΠ΅Π½ΠΈΡ Π΄ΡΡΠ³Π° Π½Π° Π΄ΡΡΠ³Π° Π΄Π²ΡΡ
ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠΉ. Π ΠΏΡΠΈΠΌΠ΅ΡΡ, Π΅ΡΠ»ΠΈ ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΎ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠ΅ Β«abcdΒ», ΡΠ»Π΅Π΄ΡΠ΅Ρ ΡΡΠΈΡΠ°ΡΡ, ΡΡΠΎ Π² Π½ΡΠΌ ΠΎΡΠΈΠ±ΠΊΠΈ Π½Π΅Ρ. ΠΠ½Π°Π»ΠΎΠ³ΠΈΡΠ½ΠΎ, ΠΏΡΠΎΡΡΠΎΠ΅ Π΄ΠΎΠΏΠΈΡΡΠ²Π°Π½ΠΈΠ΅ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ Π²ΡΠ»Π΅Π΄ Π·Π° Π΄ΡΡΠ³ΠΈΠΌ Π½Π΅ ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΏΡΠΈΠ·Π½Π°ΠΊΠΎΠΌ ΠΎΡΠΈΠ±ΠΊΠΈ. ΠΠ°ΠΏΡΠΈΠΌΠ΅Ρ, Π΅ΡΠ»ΠΈ ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΎ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠ΅ Β«abcabcΒ», ΡΠ»Π΅Π΄ΡΠ΅Ρ ΡΡΠΈΡΠ°ΡΡ, ΡΡΠΎ Π² Π½ΡΠΌ ΠΎΡΠΈΠ±ΠΊΠΈ Π½Π΅Ρ. | Π Π΅Π΄ΠΈΠ½ΡΡΠ²Π΅Π½Π½ΠΎΠΉ ΡΡΡΠΎΠΊΠ΅ Π²ΡΡ
ΠΎΠ΄Π½ΡΡ
Π΄Π°Π½Π½ΡΡ
ΡΠ»Π΅Π΄ΡΠ΅Ρ Π½Π΅ΠΏΡΡΡΠ°Ρ ΡΡΡΠΎΠΊΠ° *t*, ΡΠΎΡΡΠΎΡΡΠ°Ρ ΠΈΠ· ΡΡΡΠΎΡΠ½ΡΡ
Π±ΡΠΊΠ² Π»Π°ΡΠΈΠ½ΡΠΊΠΎΠ³ΠΎ Π°Π»ΡΠ°Π²ΠΈΡΠ°. ΠΠ»ΠΈΠ½Π° ΡΡΡΠΎΠΊΠΈ *t* Π½Π΅ ΠΏΡΠ΅Π²ΠΎΡΡ
ΠΎΠ΄ΠΈΡ 100 ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠ². | ΠΡΠ»ΠΈ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠ΅ *t* Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΡ ΠΎΡΠΈΠ±ΠΊΠΈ, Π²ΡΠ²Π΅Π΄ΠΈΡΠ΅ Β«NOΒ» (Π±Π΅Π· ΠΊΠ°Π²ΡΡΠ΅ΠΊ) Π² Π΅Π΄ΠΈΠ½ΡΡΠ²Π΅Π½Π½ΡΡ ΡΡΡΠΎΠΊΡ Π²ΡΡ
ΠΎΠ΄Π½ΡΡ
Π΄Π°Π½Π½ΡΡ
.
Π ΠΏΡΠΎΡΠΈΠ²Π½ΠΎΠΌ ΡΠ»ΡΡΠ°Π΅ Π² ΠΏΠ΅ΡΠ²ΠΎΠΉ ΡΡΡΠΎΠΊΠ΅ Π²ΡΠ²Π΅Π΄ΠΈΡΠ΅ Β«YESΒ» (Π±Π΅Π· ΠΊΠ°Π²ΡΡΠ΅ΠΊ), Π° Π² ΡΠ»Π΅Π΄ΡΡΡΠ΅ΠΉ ΡΡΡΠΎΠΊΠ΅ Π²ΡΠ²Π΅Π΄ΠΈΡΠ΅ ΡΡΡΠΎΠΊΡ *s*Β β Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΠ΅ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠ΅, ΠΊΠΎΡΠΎΡΠΎΠ΅ ΠΌΠΎΠ³Π»ΠΎ ΠΏΡΠΈΠ²Π΅ΡΡΠΈ ΠΊ ΠΎΡΠΈΠ±ΠΊΠ΅. ΠΡΠ»ΠΈ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΡΡ
ΠΎΡΠ²Π΅ΡΠΎΠ² Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ, ΡΠ°Π·ΡΠ΅ΡΠ°Π΅ΡΡΡ Π²ΡΠ²Π΅ΡΡΠΈ Π»ΡΠ±ΠΎΠΉ ΠΈΠ· Π½ΠΈΡ
. | [
"abrakadabrabrakadabra\n",
"acacacaca\n",
"abcabc\n",
"abababab\n",
"tatbt\n"
] | [
"YES\nabrakadabra\n",
"YES\nacaca\n",
"NO\n",
"YES\nababab\n",
"NO\n"
] | ΠΠΎ Π²ΡΠΎΡΠΎΠΌ ΠΏΡΠΈΠΌΠ΅ΡΠ΅ ΠΏΠΎΠ΄Ρ
ΠΎΠ΄ΡΡΠΈΠΌ ΠΎΡΠ²Π΅ΡΠΎΠΌ ΡΠ°ΠΊΠΆΠ΅ ΡΠ²Π»ΡΠ΅ΡΡΡ ΡΡΡΠΎΠΊΠ° acacaca. | [
{
"input": "abrakadabrabrakadabra",
"output": "YES\nabrakadabra"
},
{
"input": "acacacaca",
"output": "YES\nacaca"
},
{
"input": "abcabc",
"output": "NO"
},
{
"input": "abababab",
"output": "YES\nababab"
},
{
"input": "tatbt",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "r",
"output": "NO"
},
{
"input": "zaz",
"output": "NO"
},
{
"input": "zaza",
"output": "NO"
},
{
"input": "gg",
"output": "NO"
},
{
"input": "gagaga",
"output": "YES\ngaga"
},
{
"input": "hhhh",
"output": "YES\nhhh"
},
{
"input": "sssss",
"output": "YES\nsss"
},
{
"input": "nxnxnx",
"output": "YES\nnxnx"
},
{
"input": "vygvygv",
"output": "YES\nvygv"
},
{
"input": "rlrlrlrl",
"output": "YES\nrlrlrl"
},
{
"input": "zyzyzyzyz",
"output": "YES\nzyzyz"
},
{
"input": "jjjjjjjjjj",
"output": "YES\njjjjjj"
},
{
"input": "kkhuskkhusk",
"output": "YES\nkkhusk"
},
{
"input": "gzgzgzgzgzgz",
"output": "YES\ngzgzgzgz"
},
{
"input": "vkyxvkyxvkyxv",
"output": "YES\nvkyxvkyxv"
},
{
"input": "uuuuuuuuuuuuuu",
"output": "YES\nuuuuuuuu"
},
{
"input": "esxwpesxwpesxwp",
"output": "YES\nesxwpesxwp"
},
{
"input": "qltrajqltrajqltr",
"output": "YES\nqltrajqltr"
},
{
"input": "alxalxalxalxalxal",
"output": "YES\nalxalxalxal"
},
{
"input": "ijtojrijtojrijtojr",
"output": "YES\nijtojrijtojr"
},
{
"input": "yhbhamyhbhamyhbhamy",
"output": "YES\nyhbhamyhbhamy"
},
{
"input": "cdrcuccdrcuccdrcuccd",
"output": "YES\ncdrcuccdrcuccd"
},
{
"input": "ddoaxeaddoaxeaddoaxea",
"output": "YES\nddoaxeaddoaxea"
},
{
"input": "ejfrayejfrayejfrayejfr",
"output": "YES\nejfrayejfrayejfr"
},
{
"input": "oxciazoxciazoxciazoxcia",
"output": "YES\noxciazoxciazoxcia"
},
{
"input": "zfusxizfusxizfusxizfusxi",
"output": "YES\nzfusxizfusxizfusxi"
},
{
"input": "kqkqkqkqkqkqkqkqkqkqkqkqk",
"output": "YES\nkqkqkqkqkqkqk"
},
{
"input": "mrmrmrmrmrmrmrmrmrmrmrmrmr",
"output": "YES\nmrmrmrmrmrmrmr"
},
{
"input": "wnwnwnwnwnwnwnwnwnwnwnwnwnw",
"output": "YES\nwnwnwnwnwnwnwnw"
},
{
"input": "zchvhrmcrzchvhrmcrzchvhrmcrz",
"output": "YES\nzchvhrmcrzchvhrmcrz"
},
{
"input": "hngryskhngryskhngryskhngryskh",
"output": "YES\nhngryskhngryskh"
},
{
"input": "papapapapapapapapapapapapapapa",
"output": "YES\npapapapapapapapa"
},
{
"input": "qqgedqkewrelydzqqgedqkewrelydzq",
"output": "YES\nqqgedqkewrelydzq"
},
{
"input": "mtphoncwmtphoncwmtphoncwmtphoncw",
"output": "YES\nmtphoncwmtphoncwmtphoncw"
},
{
"input": "sypfetgsuhifxzsypfetgsuhifxzsypfe",
"output": "YES\nsypfetgsuhifxzsypfe"
},
{
"input": "avhiggygrtudeavhiggygrtudeavhiggyg",
"output": "YES\navhiggygrtudeavhiggyg"
},
{
"input": "hphhiattwnahphhiattwnahphhiattwnahp",
"output": "YES\nhphhiattwnahphhiattwnahp"
},
{
"input": "lpuilpuilpuilpuilpuilpuilpuilpuilpui",
"output": "YES\nlpuilpuilpuilpuilpui"
},
{
"input": "bbztwlxbocpbbztwlxbocpbbztwlxbocpbbzt",
"output": "YES\nbbztwlxbocpbbztwlxbocpbbzt"
},
{
"input": "dvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdv",
"output": "YES\ndvdvdvdvdvdvdvdvdvdv"
},
{
"input": "mnvkmnvkmnvkmnvkmnvkmnvkmnvkmnvkmnvkmnv",
"output": "YES\nmnvkmnvkmnvkmnvkmnvkmnv"
},
{
"input": "ugugugugugugugugugugugugugugugugugugugug",
"output": "YES\nugugugugugugugugugugug"
},
{
"input": "nyilpgayabfzpqifnyilpgayabfzpqifnyilpgaya",
"output": "YES\nnyilpgayabfzpqifnyilpgaya"
},
{
"input": "awxmegcmrkzawxmegcmrkzawxmegcmrkzawxmegcmr",
"output": "YES\nawxmegcmrkzawxmegcmrkzawxmegcmr"
},
{
"input": "ugduygugduygugduygugduygugduygugduygugduygu",
"output": "YES\nugduygugduygugduygugduygu"
},
{
"input": "dkwelorlspdltsdkwelorlspdltsdkwelorlspdltsdk",
"output": "YES\ndkwelorlspdltsdkwelorlspdltsdk"
},
{
"input": "xwyxssvcedrwtpgxwyxssvcedrwtpgxwyxssvcedrwtpg",
"output": "YES\nxwyxssvcedrwtpgxwyxssvcedrwtpg"
},
{
"input": "pwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpw",
"output": "YES\npwjkpwjkpwjkpwjkpwjkpwjkpw"
},
{
"input": "vxumrzwwzrzzfuvxumrzwwzrzzfuvxumrzwwzrzzfuvxumr",
"output": "YES\nvxumrzwwzrzzfuvxumrzwwzrzzfuvxumr"
},
{
"input": "kkkkrhhkkkkrhhkkkkrhhkkkkrhhkkkkrhhkkkkrhhkkkkrh",
"output": "YES\nkkkkrhhkkkkrhhkkkkrhhkkkkrh"
},
{
"input": "lfbpinxnjsfvjsfbshblyvlfbpinxnjsfvjsfbshblyvlfbpi",
"output": "YES\nlfbpinxnjsfvjsfbshblyvlfbpi"
},
{
"input": "sqdrmjqbfbmjmqfbcemrjtsqdrmjqbfbmjmqfbcemrjtsqdrmj",
"output": "YES\nsqdrmjqbfbmjmqfbcemrjtsqdrmj"
},
{
"input": "eeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiae",
"output": "YES\neeaiaeeaiaeeaiaeeaiaeeaiae"
},
{
"input": "fhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfh",
"output": "YES\nfhfhfhfhfhfhfhfhfhfhfhfhfhfh"
},
{
"input": "ouygsznbnotbouygsznbnotbouygsznbnotbouygsznbnotbouygs",
"output": "YES\nouygsznbnotbouygsznbnotbouygs"
},
{
"input": "wtqqagwaguqgaffuqgqtwtwawtqqagwaguqgaffuqgqtwtwawtqqag",
"output": "YES\nwtqqagwaguqgaffuqgqtwtwawtqqag"
},
{
"input": "sogoiyexpwmpaixsogoiyexpwmpaixsogoiyexpwmpaixsogoiyexpw",
"output": "YES\nsogoiyexpwmpaixsogoiyexpwmpaixsogoiyexpw"
},
{
"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv",
"output": "YES\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
},
{
"input": "hlyjflfbvbtvtqtsjklkfsbqthvshlyjflfbvbtvtqtsjklkfsbqthvsh",
"output": "YES\nhlyjflfbvbtvtqtsjklkfsbqthvsh"
},
{
"input": "mlymfzfkmkfjomlymfzfkmkfjomlymfzfkmkfjomlymfzfkmkfjomlymfz",
"output": "YES\nmlymfzfkmkfjomlymfzfkmkfjomlymfz"
},
{
"input": "swylxswylxswylxswylxswylxswylxswylxswylxswylxswylxswylxswyl",
"output": "YES\nswylxswylxswylxswylxswylxswylxswyl"
},
{
"input": "cifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcif",
"output": "YES\ncifcifcifcifcifcifcifcifcifcifcif"
},
{
"input": "lvifmwwfkvewsezsufghillvifmwwfkvewsezsufghillvifmwwfkvewsezsu",
"output": "YES\nlvifmwwfkvewsezsufghillvifmwwfkvewsezsu"
},
{
"input": "mhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtg",
"output": "YES\nmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtg"
},
{
"input": "szfsdufuduiofckbszfsdufuduiofckbszfsdufuduiofckbszfsdufuduiofck",
"output": "YES\nszfsdufuduiofckbszfsdufuduiofckbszfsdufuduiofck"
},
{
"input": "ceypvrszdqljkzezlcceypvrszdqljkzezlcceypvrszdqljkzezlcceypvrszdq",
"output": "YES\nceypvrszdqljkzezlcceypvrszdqljkzezlcceypvrszdq"
},
{
"input": "ojmtpzmojamdjydojmtpzmojamdjydojmtpzmojamdjydojmtpzmojamdjydojmtp",
"output": "YES\nojmtpzmojamdjydojmtpzmojamdjydojmtp"
},
{
"input": "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu",
"output": "YES\nuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"
},
{
"input": "uhkuqbhrhlqjhgbshsvtqouquhkuqbhrhlqjhgbshsvtqouquhkuqbhrhlqjhgbshsv",
"output": "YES\nuhkuqbhrhlqjhgbshsvtqouquhkuqbhrhlqjhgbshsv"
},
{
"input": "xcgtgdpomjvngwdtrvrttldigxcgtgdpomjvngwdtrvrttldigxcgtgdpomjvngwdtrv",
"output": "YES\nxcgtgdpomjvngwdtrvrttldigxcgtgdpomjvngwdtrv"
},
{
"input": "vuuovdvktdjvuaafiguzdrrtratjyvuuovdvktdjvuaafiguzdrrtratjyvuuovdvktdj",
"output": "YES\nvuuovdvktdjvuaafiguzdrrtratjyvuuovdvktdj"
},
{
"input": "yukcccrccccyukcccrccccyukcccrccccyukcccrccccyukcccrccccyukcccrccccyukc",
"output": "YES\nyukcccrccccyukcccrccccyukcccrccccyukc"
},
{
"input": "rrriiiiaaainnrrrainniiarirrriiiiaaainnrrrainniiarirrriiiiaaainnrrrainni",
"output": "YES\nrrriiiiaaainnrrrainniiarirrriiiiaaainnrrrainni"
},
{
"input": "xmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdf",
"output": "YES\nxmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdf"
},
{
"input": "xovouvxuxtcvvovpxnhruswcphrstctxovouvxuxtcvvovpxnhruswcphrstctxovouvxuxtc",
"output": "YES\nxovouvxuxtcvvovpxnhruswcphrstctxovouvxuxtc"
},
{
"input": "howwwscoebckiatfzarhowwwscoebckiatfzarhowwwscoebckiatfzarhowwwscoebckiatfz",
"output": "YES\nhowwwscoebckiatfzarhowwwscoebckiatfzarhowwwscoebckiatfz"
},
{
"input": "ickpakvkbaljifqdifjfcdxpashuickpakvkbaljifqdifjfcdxpashuickpakvkbaljifqdifj",
"output": "YES\nickpakvkbaljifqdifjfcdxpashuickpakvkbaljifqdifj"
},
{
"input": "zgzwgwggzggwzzwwwhzgzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzww",
"output": "YES\nzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzww"
},
{
"input": "ppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyh",
"output": "YES\nppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyh"
},
{
"input": "itlmmmqfkflfamdaqekrjlocitlmmmqfkflfamdaqekrjlocitlmmmqfkflfamdaqekrjlocitlmmm",
"output": "YES\nitlmmmqfkflfamdaqekrjlocitlmmmqfkflfamdaqekrjlocitlmmm"
},
{
"input": "yqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqy",
"output": "YES\nyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqy"
},
{
"input": "ijdghvidfbqqpajplojvtlppdiftzvhuqatijdghvidfbqqpajplojvtlppdiftzvhuqatijdghvidfb",
"output": "YES\nijdghvidfbqqpajplojvtlppdiftzvhuqatijdghvidfb"
},
{
"input": "jozbicochmmtmmhogkgrfutknpjozbicochmmtmmhogkgrfutknpjozbicochmmtmmhogkgrfutknpjoz",
"output": "YES\njozbicochmmtmmhogkgrfutknpjozbicochmmtmmhogkgrfutknpjoz"
},
{
"input": "tvsyxhopzmbebwoimyxhjbjuyszplhhggftvsyxhopzmbebwoimyxhjbjuyszplhhggftvsyxhopzmbebw",
"output": "YES\ntvsyxhopzmbebwoimyxhjbjuyszplhhggftvsyxhopzmbebw"
},
{
"input": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk",
"output": "YES\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
},
{
"input": "zyqxlypnlpavjxuydvxcnnzszyqxlypnlpavjxuydvxcnnzszyqxlypnlpavjxuydvxcnnzszyqxlypnlpav",
"output": "YES\nzyqxlypnlpavjxuydvxcnnzszyqxlypnlpavjxuydvxcnnzszyqxlypnlpav"
},
{
"input": "irlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlg",
"output": "YES\nirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlg"
},
{
"input": "hththththththththththththththththththththththththththththththththththththththththththt",
"output": "YES\nhthththththththththththththththththththththt"
},
{
"input": "wlladflfanfmlljbbldamdjabtfbnftawbfnllfjwlladflfanfmlljbbldamdjabtfbnftawbfnllfjwlladfl",
"output": "YES\nwlladflfanfmlljbbldamdjabtfbnftawbfnllfjwlladfl"
},
{
"input": "frxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxa",
"output": "YES\nfrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxa"
},
{
"input": "uzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbif",
"output": "YES\nuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbif"
},
{
"input": "dzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpo",
"output": "YES\ndzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpo"
},
{
"input": "avqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaa",
"output": "YES\navqriqniaavqriqniaavqriqniaavqriqniaavqriqniaa"
},
{
"input": "qqpppqqpqqqqqpqqpqpqqqpqpqqqqqqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqq",
"output": "YES\nqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqq"
},
{
"input": "mnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmn",
"output": "YES\nmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmn"
},
{
"input": "qzcgreoroxoxqzwvvoeiggriwrzotcxizqzcgreoroxoxqzwvvoeiggriwrzotcxizqzcgreoroxoxqzwvvoeiggriwrzo",
"output": "YES\nqzcgreoroxoxqzwvvoeiggriwrzotcxizqzcgreoroxoxqzwvvoeiggriwrzo"
},
{
"input": "pymvkuoucpujkekgnjrvnkrvodtszsbkmoabtlgdbpymvkuoucpujkekgnjrvnkrvodtszsbkmoabtlgdbpymvkuoucpujk",
"output": "YES\npymvkuoucpujkekgnjrvnkrvodtszsbkmoabtlgdbpymvkuoucpujk"
},
{
"input": "yguclskcmiuobsgckhotgkzqykebvttqaqmtzsyguclskcmiuobsgckhotgkzqykebvttqaqmtzsyguclskcmiuobsgckhot",
"output": "YES\nyguclskcmiuobsgckhotgkzqykebvttqaqmtzsyguclskcmiuobsgckhot"
},
{
"input": "kowiovfyffitkipvmccesjhatgyqaekowiovfyffitkipvmccesjhatgyqaekowiovfyffitkipvmccesjhatgyqaekowiovf",
"output": "YES\nkowiovfyffitkipvmccesjhatgyqaekowiovfyffitkipvmccesjhatgyqaekowiovf"
},
{
"input": "mrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdreps",
"output": "YES\nmrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdreps"
},
{
"input": "hgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiy",
"output": "YES\nhgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiy"
},
{
"input": "foxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfo",
"output": "YES\nfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfo"
},
{
"input": "bkwdegdnxtnvtczozttjitzmfienbtxhoipldptluxbtvhmybkwdegdnxtnvtczozttjitzmfienbtxhoipldptluxbtvhmybkwd",
"output": "YES\nbkwdegdnxtnvtczozttjitzmfienbtxhoipldptluxbtvhmybkwd"
},
{
"input": "cftorbxtglokyoxsemzlysptutvldtlzqbhawyecivljlcftorbxtglokyoxsemzlysptutvldtlzqbhawyecivljlcftorbxtgl",
"output": "YES\ncftorbxtglokyoxsemzlysptutvldtlzqbhawyecivljlcftorbxtgl"
},
{
"input": "twfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkjobbgoubmybfkbmmcon",
"output": "YES\ntwfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkjobbgoubmybfkbmmcon"
},
{
"input": "wajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmk",
"output": "YES\nwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmk"
},
{
"input": "pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp",
"output": "YES\nppppppppppppppppppppppppppppppppppppppppppppppppppp"
},
{
"input": "axquczgfdshcpqjcqaxquczgfdshcpqjcqaxquczgfdshcpqjcqaxquczxfdshcpqjcqaxquczgfdshcpqjcqaxquc",
"output": "NO"
},
{
"input": "vyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvshsqvvyhsqvv",
"output": "NO"
},
{
"input": "bpqxbraxrcxwdoftbpqxbraxryxwdoftbpqxbraxrcxwdoftbpqxbraxrcxwdoftbpqxbraxrcxwdoftbpqxbraxrcxw",
"output": "NO"
},
{
"input": "renpsuotrenpsuotrenpsuotrenpsuotrenpsuotrenpsuoprenpsuotrenpsuotrenpsuotrenpsuotrenpsuotrenps",
"output": "NO"
},
{
"input": "qqeemdmddqddkmudbmaabaedquqmqqdqqqeemdmddqddkmudbmaabaedquqmqqdqqqeemdmddqddkmudbmaabaedquqmqq",
"output": "YES\nqqeemdmddqddkmudbmaabaedquqmqqdqqqeemdmddqddkmudbmaabaedquqmqq"
},
{
"input": "gfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpis",
"output": "YES\ngfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpis"
},
{
"input": "nnsssnnngsbnngnsnnbgbgnbnbnnsssnnngsbnngnsnnbgbgnbnbnnsssnnngsbnngnbnnbgbgnbnbnnsssnnngsbnngnsnn",
"output": "NO"
},
{
"input": "qimxxxojmmjqmxqfxfqiximjxqimxxxojqmjqmxqfxfqiximjxqimxxxojmmjqmxqfxfqiximjxqimxxxojmmjqmxqfxfqixi",
"output": "NO"
},
{
"input": "otjwmbgahamrbbhnttmoqahohbhbjxwkbtotjwmbgahamrbbhnttmoqahohbhyjxwkbtotjwmbgahamrbbhnttmoqahohbhbjx",
"output": "NO"
},
{
"input": "hligdsxyzyjejeskxapshligdsxyzyjejeskxapshligdsxyzyjejeskxapshligdsxyzyjejeskxapshligdsxyzljejeskxap",
"output": "NO"
},
{
"input": "ooogesrsajsnzroyhabbckrnovooogesrsajsnzroyhabbckrnovooogesrsajsnzroyhabbckrnovooogesrsajsnzroyhadbck",
"output": "NO"
}
] | 46 | 4,608,000 | 0 | 3,642 |
|
689 | Mike and Cellphone | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? | The first line of the input contains the only integer *n* (1<=β€<=*n*<=β€<=9)Β β the number of digits in the phone number that Mike put in.
The second line contains the string consisting of *n* digits (characters from '0' to '9') representing the number that Mike put in. | If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line. | [
"3\n586\n",
"2\n09\n",
"9\n123456789\n",
"3\n911\n"
] | [
"NO\n",
"NO\n",
"YES\n",
"YES\n"
] | You can find the picture clarifying the first sample case in the statement above. | [
{
"input": "3\n586",
"output": "NO"
},
{
"input": "2\n09",
"output": "NO"
},
{
"input": "9\n123456789",
"output": "YES"
},
{
"input": "3\n911",
"output": "YES"
},
{
"input": "3\n089",
"output": "NO"
},
{
"input": "3\n159",
"output": "YES"
},
{
"input": "9\n000000000",
"output": "NO"
},
{
"input": "4\n0874",
"output": "NO"
},
{
"input": "6\n235689",
"output": "NO"
},
{
"input": "2\n10",
"output": "YES"
},
{
"input": "3\n358",
"output": "NO"
},
{
"input": "6\n123456",
"output": "NO"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "4\n0068",
"output": "NO"
},
{
"input": "6\n021149",
"output": "YES"
},
{
"input": "5\n04918",
"output": "YES"
},
{
"input": "2\n05",
"output": "NO"
},
{
"input": "4\n0585",
"output": "NO"
},
{
"input": "4\n0755",
"output": "NO"
},
{
"input": "2\n08",
"output": "NO"
},
{
"input": "4\n0840",
"output": "NO"
},
{
"input": "9\n103481226",
"output": "YES"
},
{
"input": "4\n1468",
"output": "NO"
},
{
"input": "7\n1588216",
"output": "NO"
},
{
"input": "9\n188758557",
"output": "NO"
},
{
"input": "1\n2",
"output": "NO"
},
{
"input": "2\n22",
"output": "NO"
},
{
"input": "8\n23482375",
"output": "YES"
},
{
"input": "9\n246112056",
"output": "YES"
},
{
"input": "9\n256859223",
"output": "NO"
},
{
"input": "6\n287245",
"output": "NO"
},
{
"input": "8\n28959869",
"output": "NO"
},
{
"input": "9\n289887167",
"output": "YES"
},
{
"input": "4\n3418",
"output": "NO"
},
{
"input": "4\n3553",
"output": "NO"
},
{
"input": "2\n38",
"output": "NO"
},
{
"input": "6\n386126",
"output": "NO"
},
{
"input": "6\n392965",
"output": "NO"
},
{
"input": "1\n4",
"output": "NO"
},
{
"input": "6\n423463",
"output": "NO"
},
{
"input": "4\n4256",
"output": "NO"
},
{
"input": "8\n42937903",
"output": "YES"
},
{
"input": "1\n5",
"output": "NO"
},
{
"input": "8\n50725390",
"output": "YES"
},
{
"input": "9\n515821866",
"output": "NO"
},
{
"input": "2\n56",
"output": "NO"
},
{
"input": "2\n57",
"output": "NO"
},
{
"input": "7\n5740799",
"output": "NO"
},
{
"input": "9\n582526521",
"output": "NO"
},
{
"input": "9\n585284126",
"output": "NO"
},
{
"input": "1\n6",
"output": "NO"
},
{
"input": "3\n609",
"output": "NO"
},
{
"input": "2\n63",
"output": "NO"
},
{
"input": "3\n633",
"output": "NO"
},
{
"input": "7\n6668940",
"output": "NO"
},
{
"input": "5\n66883",
"output": "NO"
},
{
"input": "2\n68",
"output": "NO"
},
{
"input": "5\n69873",
"output": "YES"
},
{
"input": "1\n7",
"output": "NO"
},
{
"input": "4\n7191",
"output": "YES"
},
{
"input": "9\n722403540",
"output": "YES"
},
{
"input": "9\n769554547",
"output": "NO"
},
{
"input": "3\n780",
"output": "NO"
},
{
"input": "5\n78248",
"output": "NO"
},
{
"input": "4\n7844",
"output": "NO"
},
{
"input": "4\n7868",
"output": "NO"
},
{
"input": "1\n8",
"output": "NO"
},
{
"input": "6\n817332",
"output": "YES"
},
{
"input": "7\n8465393",
"output": "YES"
},
{
"input": "7\n8526828",
"output": "NO"
},
{
"input": "8\n85812664",
"output": "NO"
},
{
"input": "8\n93008225",
"output": "YES"
},
{
"input": "7\n9454566",
"output": "NO"
},
{
"input": "4\n9625",
"output": "NO"
},
{
"input": "8\n97862407",
"output": "YES"
},
{
"input": "3\n993",
"output": "NO"
},
{
"input": "3\n267",
"output": "YES"
},
{
"input": "3\n249",
"output": "YES"
},
{
"input": "3\n672",
"output": "YES"
},
{
"input": "3\n176",
"output": "YES"
},
{
"input": "3\n123",
"output": "NO"
},
{
"input": "3\n367",
"output": "YES"
},
{
"input": "2\n12",
"output": "NO"
},
{
"input": "4\n2580",
"output": "YES"
},
{
"input": "2\n20",
"output": "YES"
},
{
"input": "3\n492",
"output": "YES"
},
{
"input": "3\n167",
"output": "YES"
},
{
"input": "3\n970",
"output": "NO"
},
{
"input": "3\n460",
"output": "NO"
},
{
"input": "4\n4268",
"output": "NO"
},
{
"input": "4\n9394",
"output": "YES"
},
{
"input": "2\n13",
"output": "NO"
},
{
"input": "3\n729",
"output": "YES"
},
{
"input": "6\n456893",
"output": "YES"
}
] | 46 | 0 | -1 | 3,650 |
|
253 | Physics Practical | [
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=β€<=2Β·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times. | The first line contains integer *n* (2<=β€<=*n*<=β€<=105) β the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=β€<=*c**i*<=β€<=5000) β the results of the measurements. The numbers on the second line are separated by single spaces. | Print a single integer β the minimum number of results Vasya will have to remove. | [
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] | [
"2\n",
"0\n"
] | In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4. | [
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 1 24",
"output": "5"
},
{
"input": "20\n43 49 46 46 40 41 49 49 48 30 35 36 33 34 42 38 40 46 50 45",
"output": "0"
},
{
"input": "30\n6 1 26 13 16 30 16 23 9 1 5 14 7 2 17 22 21 23 16 3 5 17 22 10 1 24 4 30 8 18",
"output": "15"
},
{
"input": "50\n3 61 16 13 13 12 3 8 14 16 1 32 8 23 29 7 28 13 8 5 9 2 3 2 29 13 1 2 18 29 28 4 13 3 14 9 20 26 1 19 13 7 8 22 7 5 13 14 10 23",
"output": "29"
},
{
"input": "10\n135 188 160 167 179 192 195 192 193 191",
"output": "0"
},
{
"input": "15\n2 19 19 22 15 24 6 36 20 3 18 27 20 1 10",
"output": "6"
},
{
"input": "25\n8 1 2 1 2 5 3 4 2 6 3 3 4 1 6 1 6 1 4 5 2 9 1 2 1",
"output": "13"
},
{
"input": "40\n4784 4824 4707 4343 4376 4585 4917 4848 3748 4554 3390 4944 4845 3922 4617 4606 4815 4698 4595 4942 4327 4983 4833 4507 3721 4863 4633 4553 4991 4922 4733 4396 4747 4724 4886 4226 4025 4928 4990 4792",
"output": "0"
},
{
"input": "60\n1219 19 647 1321 21 242 677 901 10 165 434 978 448 163 919 517 1085 10 516 920 653 1363 62 98 629 928 998 1335 1448 85 357 432 1298 561 663 182 2095 801 59 208 765 1653 642 645 1378 221 911 749 347 849 43 1804 62 73 613 143 860 297 278 148",
"output": "37"
},
{
"input": "100\n4204 4719 4688 3104 4012 4927 4696 4614 4826 4792 3891 4672 4914 4740 4968 3879 4424 4755 3856 3837 4965 4939 4030 4941 4504 4668 4908 4608 3660 4822 4846 3945 4539 4819 4895 3746 4324 4233 4135 4956 4983 4546 4673 4617 3533 4851 4868 4838 4998 4769 4899 4578 3841 4974 4627 4990 4524 4939 4469 4233 4434 4339 4446 4979 4354 4912 4558 4609 4436 3883 4379 4927 4824 4819 4984 4660 4874 3732 4853 4268 4761 4402 4642 4577 4635 4564 4113 4896 4943 4122 4413 4597 3768 4731 4669 4958 4548 4263 4657 3651",
"output": "0"
},
{
"input": "100\n1354 1797 588 3046 1290 745 217 907 113 381 523 935 791 415 92 1597 1739 1774 240 27 1262 2498 52 1339 1031 1355 2036 230 489 7 69 877 530 2664 1230 940 2712 2651 3410 480 332 699 957 2257 1877 1940 452 1652 1216 3144 236 165 1109 888 1649 346 24 183 1061 1226 2694 3225 2021 1145 907 1671 1599 3395 942 1959 555 1281 675 1125 1386 732 1081 326 256 26 1009 1772 2687 1173 491 709 390 992 519 203 1029 1381 846 1515 705 2859 282 147 1824 299",
"output": "63"
},
{
"input": "100\n2794 2201 4935 564 2876 4472 4196 2571 2260 1479 1451 3497 245 2805 4834 3872 4294 1299 937 2983 1458 3278 1098 2990 4447 4337 4388 947 3708 3382 3694 4562 3827 2312 3760 1181 2830 1256 1054 1583 2094 931 86 2526 998 3420 2248 3461 3662 1715 5 4123 1051 545 3704 1084 1916 695 794 121 1000 1611 3674 1910 4795 2805 825 2392 3551 1148 3738 4650 791 288 1064 2011 2991 2116 2179 3333 1303 498 1610 3092 1935 3450 3524 2624 1596 2801 2290 2297 2327 1602 4779 3135 1231 4203 3283 3580",
"output": "51"
},
{
"input": "2\n1 5",
"output": "1"
}
] | 30 | 0 | 0 | 3,680 |
|
331 | Oh Sweet Beaverette | [
"data structures",
"sortings"
] | null | null | β Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me?
β Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night?
At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees.
Let's consider the woodland belt as a sequence of trees. Each tree *i* is described by the esthetic appeal *a**i* β some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly!
The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart:
- The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible; - the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same; - and of course, the walk should be successful: there must be at least two trees in the woodland belt left.
Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart? | The first line contains a single integer *n* β the initial number of trees in the woodland belt, 2<=β€<=*n*. The second line contains space-separated integers *a**i* β the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value.
- to get 30 points, you need to solve the problem with constraints: *n*<=β€<=100 (subproblem A1); - to get 100 points, you need to solve the problem with constraints: *n*<=β€<=3Β·105 (subproblems A1+A2). | In the first line print two integers β the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees *k*.
In the next line print *k* integers β the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to *n* from left to right.
If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal. | [
"5\n1 2 3 1 2\n",
"5\n1 -2 3 1 -2\n"
] | [
"8 1\n1 ",
"5 2\n2 5 "
] | none | [
{
"input": "5\n1 2 3 1 2",
"output": "8 1\n1 "
},
{
"input": "5\n1 -2 3 1 -2",
"output": "5 2\n2 5 "
},
{
"input": "2\n0 0",
"output": "0 0"
},
{
"input": "3\n0 -1 0",
"output": "0 1\n2 "
},
{
"input": "3\n1 1 1",
"output": "3 0"
},
{
"input": "4\n-1 1 1 -1",
"output": "2 2\n1 4 "
},
{
"input": "4\n-1 1 -1 1",
"output": "2 2\n1 3 "
},
{
"input": "2\n-1 -1",
"output": "-2 0"
},
{
"input": "3\n-1 0 -1",
"output": "-2 0"
},
{
"input": "6\n-1 3 3 5 5 -1",
"output": "14 0"
},
{
"input": "2\n-1000000000 -1000000000",
"output": "-2000000000 0"
},
{
"input": "3\n-1000000000 -1000000000 -1000000000",
"output": "-2000000000 1\n3 "
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "3000000000 0"
},
{
"input": "10\n-589330597 -126288833 -126288833 -834860352 -834860352 -834860352 -834860352 -21170405 -834860352 -834860352",
"output": "-252577666 8\n1 4 5 6 7 8 9 10 "
},
{
"input": "20\n-808998072 733614990 579897311 -337992089 579897311 120800519 -337992089 -803027570 733614990 -686536765 733614990 -803027570 -803027570 733614990 120800519 -803027570 -686536765 579897311 -808998072 -686536765",
"output": "4215055101 13\n1 4 7 8 10 12 13 15 16 17 18 19 20 "
}
] | 310 | 20,275,200 | 0 | 3,685 |
|
15 | Cottage Village | [
"implementation",
"sortings"
] | A. Cottage Village | 2 | 64 | A new cottage village called Β«FlatvilleΒ» is being built in Flatland. By now they have already built in Β«FlatvilleΒ» *n* square houses with the centres on the *Πx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Peter works, was commissioned to build a new house in Β«FlatvilleΒ». The customer wants his future house to be on the *Πx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village.
Peter was given a list of all the houses in Β«FlatvilleΒ». Would you help him find the amount of possible positions of the new house? | The first line of the input data contains numbers *n* and *t* (1<=β€<=*n*,<=*t*<=β€<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* β *x*-coordinate of the centre of the *i*-th house, and *a**i* β length of its side (<=-<=1000<=β€<=*x**i*<=β€<=1000, 1<=β€<=*a**i*<=β€<=1000). | Output the amount of possible positions of the new house. | [
"2 2\n0 4\n6 2\n",
"2 2\n0 4\n5 2\n",
"2 3\n0 4\n5 2\n"
] | [
"4\n",
"3\n",
"2\n"
] | It is possible for the *x*-coordinate of the new house to have non-integer value. | [
{
"input": "2 2\n0 4\n6 2",
"output": "4"
},
{
"input": "2 2\n0 4\n5 2",
"output": "3"
},
{
"input": "2 3\n0 4\n5 2",
"output": "2"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 2\n2 1",
"output": "2"
},
{
"input": "2 1\n2 1\n1 1",
"output": "2"
},
{
"input": "2 2\n0 4\n7 4",
"output": "4"
},
{
"input": "4 1\n-12 1\n-14 1\n4 1\n-11 1",
"output": "5"
},
{
"input": "6 15\n19 1\n2 3\n6 2\n-21 2\n-15 2\n23 1",
"output": "2"
},
{
"input": "10 21\n-61 6\n55 2\n-97 1\n37 1\n-39 1\n26 2\n21 1\n64 3\n-68 1\n-28 6",
"output": "6"
},
{
"input": "26 51\n783 54\n-850 6\n-997 59\n573 31\n-125 20\n472 52\n101 5\n-561 4\n625 35\n911 14\n-47 33\n677 55\n-410 54\n13 53\n173 31\n968 30\n-497 7\n832 42\n271 59\n-638 52\n-301 51\n378 36\n-813 7\n-206 22\n-737 37\n-911 9",
"output": "35"
},
{
"input": "14 101\n121 88\n-452 91\n635 28\n-162 59\n-872 26\n-996 8\n468 86\n742 63\n892 89\n-249 107\n300 51\n-753 17\n-620 31\n-13 34",
"output": "16"
},
{
"input": "3 501\n827 327\n-85 480\n-999 343",
"output": "6"
},
{
"input": "2 999\n-999 471\n530 588",
"output": "4"
},
{
"input": "22 54\n600 43\n806 19\n-269 43\n-384 78\n222 34\n392 10\n318 30\n488 73\n-756 49\n-662 22\n-568 50\n-486 16\n-470 2\n96 66\n864 16\n934 15\n697 43\n-154 30\n775 5\n-876 71\n-33 78\n-991 31",
"output": "30"
},
{
"input": "17 109\n52 7\n216 24\n-553 101\n543 39\n391 92\n-904 67\n95 34\n132 14\n730 103\n952 118\n-389 41\n-324 36\n-74 2\n-147 99\n-740 33\n233 1\n-995 3",
"output": "16"
},
{
"input": "4 512\n-997 354\n-568 216\n-234 221\n603 403",
"output": "4"
},
{
"input": "3 966\n988 5\n15 2\n-992 79",
"output": "6"
},
{
"input": "2 1000\n-995 201\n206 194",
"output": "4"
},
{
"input": "50 21\n-178 1\n49 1\n-98 1\n-220 1\n152 1\n-160 3\n17 2\n77 1\n-24 1\n214 2\n-154 2\n-141 1\n79 1\n206 1\n8 1\n-208 1\n36 1\n231 3\n-2 2\n-130 2\n-14 2\n34 1\n-187 2\n14 1\n-83 2\n-241 1\n149 2\n73 1\n-233 3\n-45 1\n197 1\n145 2\n-127 2\n-229 4\n-85 1\n-66 1\n-76 2\n104 1\n175 1\n70 1\n131 3\n-108 1\n-5 4\n140 1\n33 1\n248 3\n-36 3\n134 1\n-183 1\n56 2",
"output": "9"
},
{
"input": "50 1\n37 1\n-38 1\n7 1\n47 1\n-4 1\n24 1\n-32 1\n-23 1\n-3 1\n-19 1\n5 1\n-50 1\n11 1\n-11 1\n49 1\n-39 1\n0 1\n43 1\n-10 1\n6 1\n19 1\n1 1\n27 1\n29 1\n-47 1\n-40 1\n-46 1\n-26 1\n-42 1\n-37 1\n13 1\n-29 1\n-30 1\n3 1\n44 1\n10 1\n4 1\n-14 1\n-2 1\n34 1\n18 1\n-33 1\n-44 1\n9 1\n-36 1\n-7 1\n25 1\n22 1\n-20 1\n-41 1",
"output": "43"
},
{
"input": "50 1\n-967 7\n696 7\n-366 4\n557 1\n978 2\n800 4\n-161 2\n-773 2\n-248 2\n134 3\n869 6\n-932 2\n-262 14\n191 3\n669 2\n72 5\n0 1\n757 8\n859 2\n-131 8\n-169 3\n543 10\n-120 2\n-87 8\n-936 6\n-620 3\n-281 11\n684 3\n886 10\n497 4\n380 4\n833 1\n-727 6\n470 11\n584 9\n66 6\n-609 12\n-661 4\n-57 8\n628 7\n635 4\n-924 3\n-982 4\n-201 7\n-9 8\n-560 9\n712 7\n-330 8\n-191 1\n-892 7",
"output": "96"
},
{
"input": "1 1000\n0 1000",
"output": "2"
}
] | 746 | 0 | 3.8135 | 3,691 |
789 | Anastasia and pebbles | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket. | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=105, 1<=β€<=*k*<=β€<=109)Β β the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=β€<=*w**i*<=β€<=104)Β β number of pebbles of each type. | The only line of output contains one integerΒ β the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second typeΒ β on the second day, and of third typeΒ β on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type. | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 87 200 62 168 51 185 192 118",
"output": "48"
},
{
"input": "1 1\n10000",
"output": "5000"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "2 2\n2 2",
"output": "1"
}
] | 1,000 | 11,059,200 | 0 | 3,695 |
|
467 | George and Job | [
"dp",
"implementation"
] | null | null | The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. You are to choose *k* pairs of integers:
in such a way that the value of sum is maximal possible. Help George to cope with the task. | The first line contains three integers *n*, *m* and *k* (1<=β€<=(*m*<=Γ<=*k*)<=β€<=*n*<=β€<=5000). The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (0<=β€<=*p**i*<=β€<=109). | Print an integer in a single line β the maximum possible value of sum. | [
"5 2 1\n1 2 3 4 5\n",
"7 1 3\n2 10 7 18 5 33 0\n"
] | [
"9\n",
"61\n"
] | none | [
{
"input": "5 2 1\n1 2 3 4 5",
"output": "9"
},
{
"input": "7 1 3\n2 10 7 18 5 33 0",
"output": "61"
},
{
"input": "13 8 1\n73 7 47 91 54 74 99 11 67 35 84 18 19",
"output": "515"
},
{
"input": "8 3 1\n8 46 37 81 81 57 11 2",
"output": "219"
},
{
"input": "20 5 3\n96 46 67 36 59 95 88 43 92 58 1 31 69 35 36 77 56 27 3 23",
"output": "953"
},
{
"input": "16 2 2\n50 78 5 26 26 16 14 35 46 8 37 31 92 52 97 24",
"output": "277"
},
{
"input": "22 1 6\n21 34 48 26 37 85 24 85 57 92 88 53 17 7 47 2 60 50 91 3 3 26",
"output": "501"
},
{
"input": "58 19 3\n48 40 71 80 100 53 52 74 36 3 77 1 87 93 57 98 21 46 78 13 69 29 33 96 36 9 90 30 52 82 70 92 40 34 81 33 20 66 0 64 64 80 16 90 17 42 55 92 17 1 67 0 97 14 84 90 93 13",
"output": "3086"
},
{
"input": "26 4 3\n21 97 29 7 22 27 96 99 52 63 30 12 2 9 32 18 95 50 22 67 43 63 64 35 64 11",
"output": "770"
},
{
"input": "79 7 7\n100 78 47 26 94 48 31 56 50 42 1 93 73 83 25 77 83 72 16 21 92 93 91 60 16 9 67 92 22 30 92 38 9 57 77 61 79 28 79 91 29 2 88 79 20 18 46 32 32 14 63 25 82 12 87 17 84 8 34 45 26 38 69 85 52 47 5 89 88 2 0 60 77 2 1 12 98 95 24",
"output": "2980"
},
{
"input": "141 12 6\n66 53 86 91 12 27 5 74 79 50 33 2 100 26 2 73 16 14 50 86 75 9 66 48 19 34 25 1 22 50 63 39 38 42 98 71 76 27 80 16 74 21 36 1 32 20 65 28 68 40 41 6 0 77 65 84 0 34 60 0 42 65 2 16 25 85 35 57 74 66 26 33 39 14 0 6 2 15 87 99 47 67 75 63 72 32 93 7 5 63 35 99 89 61 18 25 76 5 39 80 37 17 78 23 61 98 16 7 21 70 74 32 28 81 25 4 31 19 86 28 55 16 9 92 16 69 97 78 36 89 15 60 46 97 26 23 37 61 51 85 42",
"output": "3887"
},
{
"input": "1 1 1\n1",
"output": "1"
},
{
"input": "2 2 1\n1 0",
"output": "1"
},
{
"input": "2 1 1\n10 11",
"output": "11"
},
{
"input": "2 1 1\n0 0",
"output": "0"
},
{
"input": "6 2 1\n1 1 10 1 20 10",
"output": "30"
},
{
"input": "23 2 4\n965481468 524609549 327408602 598336282 745920261 141281382 661619186 475657944 798069657 19918618 428716536 140019227 432712846 201739661 639584480 639986280 125110008 156951910 45355489 331043204 811313708 662402183 999999999",
"output": "5776320502"
},
{
"input": "5 2 2\n1 5 3 7 9",
"output": "24"
},
{
"input": "3 2 1\n1 2 3",
"output": "5"
},
{
"input": "6 2 2\n1 100 10 10000000 7 99",
"output": "10000117"
},
{
"input": "6 2 3\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "6000000000"
},
{
"input": "10 1 10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "10000000000"
}
] | 1,000 | 0 | 0 | 3,708 |
|
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 | 6,451,200 | 0 | 3,710 |
|
53 | Autocomplete | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*. | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=β€<=*n*<=β€<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only. | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages. | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszjebdoad\nchz\na",
"output": "kudljmxcse"
},
{
"input": "ntqwpa\n5\nvvepyowvn\nntqwpakay\nhh\nygiafasda\nntqwpadm",
"output": "ntqwpadm"
},
{
"input": "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt",
"output": "aflb"
},
{
"input": "dzwzyj\n7\nwvixktp\ndzwzyjuhn\ndzwzyjqrbd\ndzwzyji\ndzwzyjyfys\ndzwzyjrcb\nxptb",
"output": "dzwzyji"
},
{
"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\n1\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn",
"output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg"
},
{
"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\n1\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb",
"output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb"
},
{
"input": "msjnqudojxtzvpc\n2\nvlxclsvqbucmbrkwwtoxek\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld",
"output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld"
}
] | 216 | 0 | 3.946 | 3,715 |
471 | MUH and Cube Walls | [
"string suffix structures",
"strings"
] | null | null | Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of different heights.
Horace was the first to finish making his wall. He called his wall an elephant. The wall consists of *w* towers. The bears also finished making their wall but they didn't give it a name. Their wall consists of *n* towers. Horace looked at the bears' tower and wondered: in how many parts of the wall can he "see an elephant"? He can "see an elephant" on a segment of *w* contiguous towers if the heights of the towers on the segment match as a sequence the heights of the towers in Horace's wall. In order to see as many elephants as possible, Horace can raise and lower his wall. He even can lower the wall below the ground level (see the pictures to the samples for clarification).
Your task is to count the number of segments where Horace can "see an elephant". | The first line contains two integers *n* and *w* (1<=β€<=*n*,<=*w*<=β€<=2Β·105) β the number of towers in the bears' and the elephant's walls correspondingly. The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=109) β the heights of the towers in the bears' wall. The third line contains *w* integers *b**i* (1<=β€<=*b**i*<=β€<=109) β the heights of the towers in the elephant's wall. | Print the number of segments in the bears' wall where Horace can "see an elephant". | [
"13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2\n"
] | [
"2"
] | The picture to the left shows Horace's wall from the sample, the picture to the right shows the bears' wall. The segments where Horace can "see an elephant" are in gray. | [
{
"input": "13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2",
"output": "2"
},
{
"input": "5 1\n8 71 1 24 2\n31",
"output": "5"
},
{
"input": "6 3\n2 2 2 2 2 2\n5 5 5",
"output": "4"
},
{
"input": "1 1\n576560149\n691846236",
"output": "1"
},
{
"input": "10 5\n5 10 8 10 11 9 11 12 10 15\n4 2 4 5 3",
"output": "2"
},
{
"input": "10 10\n6 8 1 2 5 1 4 24 2 4\n6 8 1 2 5 1 4 24 2 4",
"output": "1"
},
{
"input": "10 10\n6 8 1 2 5 1 14 24 12 4\n7 9 2 3 6 2 15 25 13 5",
"output": "1"
},
{
"input": "8 4\n1 2 3 4 5 6 7 8\n10 11 12 13",
"output": "5"
},
{
"input": "10 5\n172960147 951061917 502625539 319177159 720665763 402410416 880790711 734191412 452846733 449904402\n640219326 792464591 173792179 691347674 125427306",
"output": "0"
},
{
"input": "10 3\n2 3 3 2 1 1 3 1 3 1\n2 1 2",
"output": "0"
},
{
"input": "10 5\n260725416 260725506 260725422 260725512 260725428 260725518 260725434 260725524 260725440 260725530\n925033135 925033225 925033141 925033231 925033147",
"output": "3"
},
{
"input": "2 2\n1000000000 10\n1 20",
"output": "0"
},
{
"input": "7 3\n1 1 1 1 1 1 1\n1000 1256 1512",
"output": "0"
},
{
"input": "3 3\n1 132 3\n2 1 3",
"output": "0"
},
{
"input": "53 3\n1 3 4 4 5 7 10 14 19 25 32 40 49 59 70 82 95 109 124 140 157 175 194 214 235 257 280 304 329 355 382 410 439 469 500 532 565 599 634 670 707 745 784 824 865 907 950 994 1039 1085 1132 1180 1229\n1 2 40",
"output": "0"
}
] | 31 | 0 | 0 | 3,718 |
|
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..."
}
] | 77 | 0 | 0 | 3,723 |
|
0 | none | [
"none"
] | null | null | Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L. | The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use. | Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly. | [
"1\n",
"2\n",
"10\n"
] | [
"4\n",
"10\n",
"244\n"
] | In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | [
{
"input": "1",
"output": "4"
},
{
"input": "2",
"output": "10"
},
{
"input": "10",
"output": "244"
},
{
"input": "1000",
"output": "48753"
},
{
"input": "2000",
"output": "97753"
},
{
"input": "5000",
"output": "244753"
},
{
"input": "10000",
"output": "489753"
},
{
"input": "111199",
"output": "5448504"
},
{
"input": "101232812",
"output": "4960407541"
},
{
"input": "1000000000",
"output": "48999999753"
},
{
"input": "3",
"output": "20"
},
{
"input": "4",
"output": "35"
},
{
"input": "5",
"output": "56"
},
{
"input": "6",
"output": "83"
},
{
"input": "7",
"output": "116"
},
{
"input": "8",
"output": "155"
},
{
"input": "9",
"output": "198"
},
{
"input": "11",
"output": "292"
},
{
"input": "12",
"output": "341"
},
{
"input": "13",
"output": "390"
},
{
"input": "55",
"output": "2448"
},
{
"input": "100",
"output": "4653"
},
{
"input": "150",
"output": "7103"
},
{
"input": "1200",
"output": "58553"
},
{
"input": "9999999",
"output": "489999704"
},
{
"input": "100000000",
"output": "4899999753"
},
{
"input": "500000000",
"output": "24499999753"
},
{
"input": "600000000",
"output": "29399999753"
},
{
"input": "709000900",
"output": "34741043853"
},
{
"input": "999999999",
"output": "48999999704"
},
{
"input": "12",
"output": "341"
},
{
"input": "10",
"output": "244"
},
{
"input": "20",
"output": "733"
},
{
"input": "35",
"output": "1468"
},
{
"input": "56",
"output": "2497"
},
{
"input": "83",
"output": "3820"
},
{
"input": "116",
"output": "5437"
},
{
"input": "155",
"output": "7348"
},
{
"input": "198",
"output": "9455"
},
{
"input": "244",
"output": "11709"
},
{
"input": "292",
"output": "14061"
},
{
"input": "14",
"output": "439"
}
] | 124 | 409,600 | 3 | 3,746 |
|
729 | Road to Cinema | [
"binary search",
"greedy",
"sortings"
] | null | null | Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in *t* minutes. There is a straight road of length *s* from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point *s*.
There are *k* gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are *n* cars in the rental service, *i*-th of them is characterized with two integers *c**i* and *v**i*Β β the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity *v**i*. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in *t* minutes. Assume that all cars are completely fueled initially. | The first line contains four positive integers *n*, *k*, *s* and *t* (1<=β€<=*n*<=β€<=2Β·105, 1<=β€<=*k*<=β€<=2Β·105, 2<=β€<=*s*<=β€<=109, 1<=β€<=*t*<=β€<=2Β·109)Β β the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next *n* lines contains two positive integers *c**i* and *v**i* (1<=β€<=*c**i*,<=*v**i*<=β€<=109)Β β the price of the *i*-th car and its fuel tank capacity.
The next line contains *k* distinct integers *g*1,<=*g*2,<=...,<=*g**k* (1<=β€<=*g**i*<=β€<=*s*<=-<=1)Β β the positions of the gas stations on the road in arbitrary order. | Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in *t* minutes). If there is no appropriate car, print -1. | [
"3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"2 2 10 18\n10 4\n20 6\n5 3\n"
] | [
"10\n",
"20\n"
] | In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel. | [
{
"input": "3 1 8 10\n10 8\n5 7\n11 9\n3",
"output": "10"
},
{
"input": "2 2 10 18\n10 4\n20 6\n5 3",
"output": "20"
},
{
"input": "2 1 1000000000 2000000000\n111 1000000000\n101 1000000000\n5",
"output": "101"
},
{
"input": "2 1 1000000000 2000000000\n111 999999998\n101 999999998\n1",
"output": "-1"
},
{
"input": "2 1 1000000000 2000000000\n111 999999999\n101 999999998\n1",
"output": "111"
},
{
"input": "1 15 100 200\n283 8\n30 58 16 45 80 82 55 95 24 23 86 28 51 47 20",
"output": "-1"
},
{
"input": "3 2 300 400\n24 68\n13 65\n15 113\n127 177",
"output": "-1"
},
{
"input": "4 13 400 600\n13 30\n1 19\n1 160\n1 113\n58 73 15 319 194 362 128 157 336 162 77 90 96",
"output": "1"
},
{
"input": "1 1 2 2\n1000000000 1000000000\n1",
"output": "1000000000"
},
{
"input": "1 1 2 1\n1 10\n1",
"output": "-1"
},
{
"input": "1 1 1000000000 1000000000\n1 1000000000\n1",
"output": "-1"
},
{
"input": "1 1 1000000000 1000000000\n100 1000000000\n1",
"output": "-1"
},
{
"input": "4 2 7 15\n10 9\n4 4\n9 3\n4 10\n1 6",
"output": "4"
},
{
"input": "1 1 10 18\n5 6\n5",
"output": "5"
}
] | 1,000 | 37,376,000 | 0 | 3,770 |
|
52 | Right Triangles | [
"combinatorics"
] | B. Right Triangles | 2 | 256 | You are given a *n*<=Γ<=*m* field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle). | The first line contains two positive integer numbers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=1000). The following *n* lines consist of *m* characters each, describing the field. Only '.' and '*' are allowed. | Output a single number β total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"2 2\n**\n*.\n",
"3 4\n*..*\n.**.\n*.**\n"
] | [
"1\n",
"9\n"
] | none | [
{
"input": "2 2\n**\n*.",
"output": "1"
},
{
"input": "3 4\n*..*\n.**.\n*.**",
"output": "9"
},
{
"input": "3 2\n..\n..\n*.",
"output": "0"
},
{
"input": "1 2\n**",
"output": "0"
},
{
"input": "1 3\n*.*",
"output": "0"
},
{
"input": "5 2\n*.\n**\n.*\n..\n.*",
"output": "3"
},
{
"input": "2 3\n...\n..*",
"output": "0"
},
{
"input": "10 9\n..*..**..\n*.*...**.\n.*...*.*.\n.*****.*.\n.*.*.**.*\n.**.*....\n**.......\n**..*.*.*\n*.*.**.*.\n*.*.*.*.*",
"output": "541"
},
{
"input": "2 3\n.*.\n**.",
"output": "1"
},
{
"input": "5 3\n**.\n..*\n*.*\n*.*\n*..",
"output": "13"
},
{
"input": "4 2\n**\n**\n.*\n**",
"output": "15"
},
{
"input": "5 2\n**\n**\n**\n*.\n*.",
"output": "18"
},
{
"input": "2 3\n***\n.*.",
"output": "2"
},
{
"input": "4 2\n.*\n.*\n..\n..",
"output": "0"
},
{
"input": "10 26\n..**..***.**.*.***.*.***.*\n*.*.*..***.*.**..*********\n*.*.*...***.*.*.*.**....*.\n..**.**.....*....***..***.\n**..*******.*..**.********\n*.**..****.***....***..***\n.*..**.*****.**.**..******\n.*.*...***.*.**.*..**.***.\n*****....**..*..**.*******\n....*******...***.*...****",
"output": "12950"
},
{
"input": "20 11\n...*.....*.\n..**..*....\n....*..***.\n...*.......\n.*..*..*..*\n.*.*....**.\n....*..**.*\n..*.*..*...\n.*....*.**.\n.*.*****...\n.**.***....\n.....*...*.\n.....*..*..\n.*...*.....\n...**..*...\n.*.*.*.***.\n.*...**....\n...*.......\n...*....**.\n.*.....*..*",
"output": "1129"
},
{
"input": "14 29\n**.*************..*.*********\n**..****.*********.**.*.****.\n********.**..*..*...*....**..\n****.**.***.*.***..*..***.*..\n***.****.***..*.***.*.****.*.\n*.*..***.***********.*.*.****\n****.*.***.*..****.**.**..***\n.*******..**...***.*.********\n*...**********...**...*.***.*\n*.******...*.***.**..****...*\n.******...**.*..*************\n.*.******.**.*****..****.**..\n**...*****.*.*.*.*.*.*****..*\n**.****...**.*******..***.***",
"output": "48985"
},
{
"input": "13 26\n.**.****.*****************\n*************.**.*.*******\n.*.***.*********..********\n******.******.**.**.*****.\n.******.*************.*.**\n***********.*.************\n**.***.**.*.*********.*.**\n******.*****************.*\n*****.***.*.**********.***\n*.************************\n************.*************\n*..*******.******.********\n******.***.**.*.******.***",
"output": "65889"
},
{
"input": "2 1\n.\n.",
"output": "0"
},
{
"input": "2 1\n*\n*",
"output": "0"
},
{
"input": "1 1\n.",
"output": "0"
},
{
"input": "1 1\n*",
"output": "0"
}
] | 218 | 3,891,200 | 3.938252 | 3,785 |
898 | Squares and not squares | [
"constructive algorithms",
"greedy"
] | null | null | Ann and Borya have *n* piles with candies and *n* is even number. There are *a**i* candies in pile with number *i*.
Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is new and doesn't belong to any other pile) or remove one candy (if there is at least one candy in this pile).
Find out minimal number of moves that is required to make exactly *n*<=/<=2 piles contain number of candies that is a square of some integer and exactly *n*<=/<=2 piles contain number of candies that is not a square of any integer. | First line contains one even integer *n* (2<=β€<=*n*<=β€<=200<=000)Β β number of piles with candies.
Second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=109)Β β amounts of candies in each pile. | Output minimal number of steps required to make exactly *n*<=/<=2 piles contain number of candies that is a square of some integer and exactly *n*<=/<=2 piles contain number of candies that is not a square of any integer. If condition is already satisfied output 0. | [
"4\n12 14 30 4\n",
"6\n0 0 0 0 0 0\n",
"6\n120 110 23 34 25 45\n",
"10\n121 56 78 81 45 100 1 0 54 78\n"
] | [
"2\n",
"6\n",
"3\n",
"0\n"
] | In first example you can satisfy condition in two moves. During each move you should add one candy to second pile. After it size of second pile becomes 16. After that Borya and Ann will have two piles with number of candies which is a square of integer (second and fourth pile) and two piles with number of candies which is not a square of any integer (first and third pile).
In second example you should add two candies to any three piles. | [
{
"input": "4\n12 14 30 4",
"output": "2"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "6"
},
{
"input": "6\n120 110 23 34 25 45",
"output": "3"
},
{
"input": "10\n121 56 78 81 45 100 1 0 54 78",
"output": "0"
},
{
"input": "10\n0 675178538 310440616 608075179 0 0 0 0 0 0",
"output": "4"
},
{
"input": "10\n49727640 89440577 0 957792200 0 0 0 0 623726477 0",
"output": "2"
},
{
"input": "20\n4 595258838 0 305922562 0 471450344 1 1 29794053 307197649 0 32960227 1 0 0 1 1 0 0 1",
"output": "4"
},
{
"input": "100\n444272562 25 25 0 49 73291074 64 100 638092144 756033694 0 700405846 16 25 25 100 36 25 269573395 288578186 366853675 36 81 49 4 0 25 49 9 64 0 4 36 36 49 0 64 64 532899768 1 64 9 549673690 25 64 4 817183855 25 146555318 36 495564252 100 49 9 36 100 49 100 4 100 9 64 9 432227412 756728309 25 0 332072516 100 64 0 92286436 49 0 81 49 0 49 0 100 409473792 25 814343057 81 1 16 0 16 886097466 64 492116229 81 270298243 64 81 100 0 49 16 16",
"output": "28"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n0 2",
"output": "0"
},
{
"input": "2\n2 0",
"output": "0"
},
{
"input": "2\n0 1000000000",
"output": "0"
},
{
"input": "2\n31622 31623",
"output": "61"
},
{
"input": "2\n31622 31622",
"output": "62"
}
] | 1,684 | 21,708,800 | 3 | 3,791 |
|
490 | Hacking Cypher | [
"brute force",
"math",
"number theory",
"strings"
] | null | null | Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by *a* as a separate number, and the second (right) part is divisible by *b* as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values *a* and *b*.
Help Polycarpus and find any suitable method to cut the public key. | The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers *a*, *b* (1<=β€<=*a*,<=*b*<=β€<=108). | In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by *a*, and the right part must be divisible by *b*. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes). | [
"116401024\n97 1024\n",
"284254589153928171911281811000\n1009 1000\n",
"120\n12 1\n"
] | [
"YES\n11640\n1024\n",
"YES\n2842545891539\n28171911281811000\n",
"NO\n"
] | none | [
{
"input": "116401024\n97 1024",
"output": "YES\n11640\n1024"
},
{
"input": "284254589153928171911281811000\n1009 1000",
"output": "YES\n2842545891539\n28171911281811000"
},
{
"input": "120\n12 1",
"output": "NO"
},
{
"input": "604\n6 4",
"output": "YES\n60\n4"
},
{
"input": "2108\n7 8",
"output": "YES\n210\n8"
},
{
"input": "7208\n10 1",
"output": "YES\n720\n8"
},
{
"input": "97502821\n25 91",
"output": "YES\n9750\n2821"
},
{
"input": "803405634\n309 313",
"output": "YES\n80340\n5634"
},
{
"input": "15203400\n38 129",
"output": "NO"
},
{
"input": "8552104774\n973 76",
"output": "NO"
},
{
"input": "2368009434\n320 106",
"output": "YES\n236800\n9434"
},
{
"input": "425392502895812\n4363 2452",
"output": "YES\n42539250\n2895812"
},
{
"input": "142222201649130\n4854 7853",
"output": "YES\n14222220\n1649130"
},
{
"input": "137871307228140\n9375 9092",
"output": "NO"
},
{
"input": "8784054131798916\n9 61794291",
"output": "YES\n87840\n54131798916"
},
{
"input": "24450015102786098\n75 55729838",
"output": "YES\n244500\n15102786098"
},
{
"input": "100890056766780885\n177 88010513",
"output": "YES\n1008900\n56766780885"
},
{
"input": "2460708054301924950\n9428 85246350",
"output": "YES\n24607080\n54301924950"
},
{
"input": "39915186055525904358\n90102 63169402",
"output": "YES\n399151860\n55525904358"
},
{
"input": "199510140021146591389\n458644 28692797",
"output": "YES\n1995101400\n21146591389"
},
{
"input": "4802711808015050898224\n8381696 51544172",
"output": "YES\n48027118080\n15050898224"
},
{
"input": "6450225349035040017740\n8872387 56607460",
"output": "YES\n64502253490\n35040017740"
},
{
"input": "4530228043401488\n71454701 8",
"output": "YES\n453022804340\n1488"
},
{
"input": "18769213650033200\n56876405 100",
"output": "YES\n187692136500\n33200"
},
{
"input": "389744672208415\n17019418 765",
"output": "YES\n38974467220\n8415"
},
{
"input": "1256363256202133560\n26228878 7460",
"output": "YES\n125636325620\n2133560"
},
{
"input": "10213094404080691512\n64639838 83359",
"output": "YES\n102130944040\n80691512"
},
{
"input": "14525757302059286788\n44151238 152801",
"output": "YES\n145257573020\n59286788"
},
{
"input": "443852406270256089240\n54194433 423288",
"output": "YES\n443852406270\n256089240"
},
{
"input": "6450225349035040017740\n8872387 56607460",
"output": "YES\n64502253490\n35040017740"
},
{
"input": "16375289070073689\n33903290 216",
"output": "NO"
},
{
"input": "3415280033041307294\n15179 79809921",
"output": "NO"
},
{
"input": "4261508098904115227\n52546339 6430",
"output": "NO"
},
{
"input": "15016\n15 16",
"output": "YES\n150\n16"
},
{
"input": "120007\n120 7",
"output": "YES\n12000\n7"
},
{
"input": "23\n2 3",
"output": "YES\n2\n3"
}
] | 77 | 2,867,200 | -1 | 3,792 |
|
606 | Magic Spheres | [
"implementation"
] | null | null | Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible, in multiple actions)? | The first line of the input contains three integers *a*, *b* and *c* (0<=β€<=*a*,<=*b*,<=*c*<=β€<=1<=000<=000)Β β the number of blue, violet and orange spheres that are in the magician's disposal.
The second line of the input contains three integers, *x*, *y* and *z* (0<=β€<=*x*,<=*y*,<=*z*<=β€<=1<=000<=000)Β β the number of blue, violet and orange spheres that he needs to get. | If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". | [
"4 4 0\n2 1 2\n",
"5 6 1\n2 7 2\n",
"3 3 3\n2 2 2\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs. | [
{
"input": "4 4 0\n2 1 2",
"output": "Yes"
},
{
"input": "5 6 1\n2 7 2",
"output": "No"
},
{
"input": "3 3 3\n2 2 2",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 0",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 1",
"output": "No"
},
{
"input": "0 1 0\n0 0 0",
"output": "Yes"
},
{
"input": "1 0 0\n1 0 0",
"output": "Yes"
},
{
"input": "2 2 1\n1 1 2",
"output": "No"
},
{
"input": "1 3 1\n2 1 1",
"output": "Yes"
},
{
"input": "1000000 1000000 1000000\n1000000 1000000 1000000",
"output": "Yes"
},
{
"input": "1000000 500000 500000\n0 750000 750000",
"output": "Yes"
},
{
"input": "500000 1000000 500000\n750001 0 750000",
"output": "No"
},
{
"input": "499999 500000 1000000\n750000 750000 0",
"output": "No"
},
{
"input": "500000 500000 0\n0 0 500000",
"output": "Yes"
},
{
"input": "0 500001 499999\n500000 0 0",
"output": "No"
},
{
"input": "1000000 500000 1000000\n500000 1000000 500000",
"output": "Yes"
},
{
"input": "1000000 1000000 499999\n500000 500000 1000000",
"output": "No"
},
{
"input": "500000 1000000 1000000\n1000000 500001 500000",
"output": "No"
},
{
"input": "1000000 500000 500000\n0 1000000 500000",
"output": "Yes"
},
{
"input": "500000 500000 1000000\n500001 1000000 0",
"output": "No"
},
{
"input": "500000 999999 500000\n1000000 0 500000",
"output": "No"
},
{
"input": "4 0 3\n2 2 1",
"output": "Yes"
},
{
"input": "0 2 4\n2 0 2",
"output": "Yes"
},
{
"input": "3 1 0\n1 1 1",
"output": "Yes"
},
{
"input": "4 4 1\n1 3 2",
"output": "Yes"
},
{
"input": "1 2 4\n2 1 3",
"output": "No"
},
{
"input": "1 1 0\n0 0 1",
"output": "No"
},
{
"input": "4 0 0\n0 1 1",
"output": "Yes"
},
{
"input": "0 3 0\n1 0 1",
"output": "No"
},
{
"input": "0 0 3\n1 0 1",
"output": "Yes"
},
{
"input": "1 12 1\n4 0 4",
"output": "Yes"
},
{
"input": "4 0 4\n1 2 1",
"output": "Yes"
},
{
"input": "4 4 0\n1 1 3",
"output": "No"
},
{
"input": "0 9 0\n2 2 2",
"output": "No"
},
{
"input": "0 10 0\n2 2 2",
"output": "Yes"
},
{
"input": "9 0 9\n0 8 0",
"output": "Yes"
},
{
"input": "0 9 9\n9 0 0",
"output": "No"
},
{
"input": "9 10 0\n0 0 9",
"output": "Yes"
},
{
"input": "10 0 9\n0 10 0",
"output": "No"
},
{
"input": "0 10 10\n10 0 0",
"output": "Yes"
},
{
"input": "10 10 0\n0 0 11",
"output": "No"
},
{
"input": "307075 152060 414033\n381653 222949 123101",
"output": "No"
},
{
"input": "569950 228830 153718\n162186 357079 229352",
"output": "No"
},
{
"input": "149416 303568 749016\n238307 493997 190377",
"output": "No"
},
{
"input": "438332 298094 225324\n194220 400244 245231",
"output": "No"
},
{
"input": "293792 300060 511272\n400687 382150 133304",
"output": "No"
},
{
"input": "295449 518151 368838\n382897 137148 471892",
"output": "No"
},
{
"input": "191789 291147 691092\n324321 416045 176232",
"output": "Yes"
},
{
"input": "286845 704749 266526\n392296 104421 461239",
"output": "Yes"
},
{
"input": "135522 188282 377041\n245719 212473 108265",
"output": "Yes"
},
{
"input": "404239 359124 133292\n180069 184791 332544",
"output": "No"
},
{
"input": "191906 624432 244408\n340002 367217 205432",
"output": "No"
},
{
"input": "275980 429361 101824\n274288 302579 166062",
"output": "No"
},
{
"input": "136092 364927 395302\n149173 343146 390922",
"output": "No"
},
{
"input": "613852 334661 146012\n363786 326286 275233",
"output": "No"
},
{
"input": "348369 104625 525203\n285621 215396 366411",
"output": "No"
},
{
"input": "225307 153572 114545\n154753 153282 149967",
"output": "Yes"
},
{
"input": "438576 124465 629784\n375118 276028 390116",
"output": "Yes"
},
{
"input": "447521 327510 158732\n395759 178458 259139",
"output": "Yes"
},
{
"input": "8 5 5\n5 5 5",
"output": "Yes"
},
{
"input": "100 100 100\n1 1 1",
"output": "Yes"
},
{
"input": "100 100 100\n0 0 0",
"output": "Yes"
},
{
"input": "3 2 3\n2 3 2",
"output": "No"
},
{
"input": "5 4 3\n2 2 2",
"output": "Yes"
},
{
"input": "14 9 8\n12 5 10",
"output": "Yes"
},
{
"input": "10 10 10\n1 1 1",
"output": "Yes"
},
{
"input": "6 3 3\n3 3 3",
"output": "Yes"
},
{
"input": "10 0 4\n2 4 2",
"output": "Yes"
},
{
"input": "100 100 100\n2 2 2",
"output": "Yes"
},
{
"input": "4 6 0\n2 1 2",
"output": "Yes"
},
{
"input": "4 6 3\n4 2 3",
"output": "Yes"
},
{
"input": "5 5 5\n1 1 1",
"output": "Yes"
},
{
"input": "41 17 34\n0 19 24",
"output": "Yes"
},
{
"input": "8 8 8\n3 3 3",
"output": "Yes"
},
{
"input": "7 7 1\n1 1 2",
"output": "Yes"
},
{
"input": "6 6 0\n2 2 2",
"output": "Yes"
},
{
"input": "5 5 5\n2 2 2",
"output": "Yes"
},
{
"input": "400 400 400\n1 1 1",
"output": "Yes"
},
{
"input": "4 4 4\n2 2 2",
"output": "Yes"
}
] | 62 | 0 | 0 | 3,802 |
|
975 | Aramic script | [
"implementation",
"strings"
] | null | null | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". - Any word in Aramic represents the same object as its root.
You have an ancient script in Aramic. What is the number of different objects mentioned in the script? | The first line contains one integer $n$ ($1 \leq n \leq 10^3$)Β β the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$Β β the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters. | Output one integerΒ β the number of different objects mentioned in the given ancient Aramic script. | [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n"
] | [
"2",
"1"
] | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | [
{
"input": "5\na aa aaa ab abb",
"output": "2"
},
{
"input": "3\namer arem mrea",
"output": "1"
},
{
"input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd",
"output": "6"
},
{
"input": "2\nfhjlqs aceginpr",
"output": "2"
},
{
"input": "2\nbcdfghimn efghijlmo",
"output": "2"
}
] | 93 | 2,969,600 | 3 | 3,808 |
|
745 | Hongcow Solves A Puzzle | [
"implementation"
] | null | null | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.
The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.
You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | The first line of input will contain two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=500), the dimensions of the puzzle piece.
The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | [
"2 3\nXXX\nXXX\n",
"2 2\n.X\nXX\n",
"5 5\n.....\n..X..\n.....\n.....\n.....\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [
{
"input": "2 3\nXXX\nXXX",
"output": "YES"
},
{
"input": "2 2\n.X\nXX",
"output": "NO"
},
{
"input": "1 500\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.",
"output": "YES"
},
{
"input": "10 1\n.\n.\n.\n.\nX\n.\n.\n.\n.\n.",
"output": "YES"
},
{
"input": "8 5\nXX.XX\nX.XXX\nX.XXX\nXXX.X\nXX.XX\nXX..X\nXXX.X\nXXXX.",
"output": "NO"
},
{
"input": "6 8\nXXXXXX..\nXXXXXXXX\n.X.X..X.\n.XXXX..X\nXX.XXXXX\nX...X..X",
"output": "NO"
},
{
"input": "10 2\n.X\n.X\nXX\nXX\nX.\nXX\nX.\nX.\n..\n..",
"output": "NO"
},
{
"input": "1 1\nX",
"output": "YES"
},
{
"input": "3 3\nXXX\nX.X\nX..",
"output": "NO"
},
{
"input": "3 3\nXX.\nXXX\n.XX",
"output": "NO"
},
{
"input": "4 4\nXXXX\nXXXX\nXX..\nXX..",
"output": "NO"
},
{
"input": "3 3\nX.X\nX.X\nXXX",
"output": "NO"
},
{
"input": "3 2\nX.\nXX\n.X",
"output": "NO"
},
{
"input": "2 1\nX\nX",
"output": "YES"
},
{
"input": "1 2\nXX",
"output": "YES"
},
{
"input": "2 3\n.XX\nXX.",
"output": "NO"
},
{
"input": "5 5\nXXX..\n.XXX.\n..XXX\nXXX..\n.XXX.",
"output": "NO"
},
{
"input": "2 4\nXX..\n.XX.",
"output": "NO"
},
{
"input": "4 4\nXXX.\nXXX.\nX.X.\n..X.",
"output": "NO"
},
{
"input": "2 3\nXX.\n.XX",
"output": "NO"
},
{
"input": "3 5\nXXXX.\n.XXXX\nXXXX.",
"output": "NO"
},
{
"input": "2 4\nXXX.\n.XXX",
"output": "NO"
},
{
"input": "3 3\n...\n.X.\nXXX",
"output": "NO"
},
{
"input": "3 3\n.X.\nXX.\nX..",
"output": "NO"
},
{
"input": "3 4\nXXX.\nX.X.\nXXX.",
"output": "NO"
},
{
"input": "4 4\n....\n....\n.XX.\n..X.",
"output": "NO"
},
{
"input": "4 4\n....\n....\n.XXX\n..X.",
"output": "NO"
},
{
"input": "2 6\nXXXXX.\nXXXXXX",
"output": "NO"
},
{
"input": "3 3\nX.X\nXXX\n.X.",
"output": "NO"
},
{
"input": "3 3\nXXX\nX.X\n..X",
"output": "NO"
},
{
"input": "3 3\n.XX\nXX.\n.XX",
"output": "NO"
},
{
"input": "3 8\n.XXXXXX.\nXXX..XXX\n.XXXXXX.",
"output": "NO"
},
{
"input": "3 3\nXX.\n.XX\nXX.",
"output": "NO"
},
{
"input": "3 3\n.XX\nXX.\nXX.",
"output": "NO"
},
{
"input": "4 4\n....\nXXX.\nX.XX\nXXX.",
"output": "NO"
},
{
"input": "2 2\nX.\nX.",
"output": "YES"
},
{
"input": "2 5\n...XX\n..XX.",
"output": "NO"
},
{
"input": "3 5\nXXX..\n.XXX.\n..XXX",
"output": "NO"
},
{
"input": "2 6\n...XXX\n.XXX..",
"output": "NO"
},
{
"input": "5 5\n.X.XX\n.XXX.\n.XXX.\n.XXX.\n.XXX.",
"output": "NO"
},
{
"input": "4 4\n....\n.XXX\n..X.\n.XX.",
"output": "NO"
},
{
"input": "2 4\n..XX\n.XX.",
"output": "NO"
},
{
"input": "3 6\nXXX...\n.XXX..\n..XXX.",
"output": "NO"
},
{
"input": "3 4\n.XXX\nXXX.\n.XXX",
"output": "NO"
}
] | 62 | 5,529,600 | 3 | 3,817 |
|
859 | Declined Finalists | [
"greedy",
"implementation"
] | null | null | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.
After the qualifying round completes, you know *K* of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round. | The first line of input contains *K* (1<=β€<=*K*<=β€<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=β€<=*r**i*<=β€<=106), the qualifying ranks of the finalists you know. All these ranks are distinct. | Print the minimum possible number of contestants that declined the invitation to compete onsite. | [
"25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n",
"5\n16 23 8 15 4\n",
"3\n14 15 92\n"
] | [
"3\n",
"0\n",
"67\n"
] | In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | [
{
"input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28",
"output": "3"
},
{
"input": "5\n16 23 8 15 4",
"output": "0"
},
{
"input": "3\n14 15 92",
"output": "67"
},
{
"input": "1\n1000000",
"output": "999975"
},
{
"input": "25\n1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976",
"output": "999975"
},
{
"input": "25\n13 15 24 2 21 18 9 4 16 6 10 25 20 11 23 17 8 3 1 12 5 19 22 14 7",
"output": "0"
},
{
"input": "10\n17 11 7 13 18 12 14 5 16 2",
"output": "0"
},
{
"input": "22\n22 14 23 20 11 21 4 12 3 8 7 9 19 10 13 17 15 1 5 18 16 2",
"output": "0"
},
{
"input": "21\n6 21 24 3 10 23 14 2 26 12 8 1 15 13 9 5 19 20 4 16 22",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n100 60",
"output": "75"
},
{
"input": "4\n999 581 787 236",
"output": "974"
},
{
"input": "6\n198 397 732 1234 309 827",
"output": "1209"
},
{
"input": "11\n6494 3961 1858 4351 8056 780 7720 6211 1961 8192 3621",
"output": "8167"
},
{
"input": "14\n18809 9534 11652 6493 8929 9370 4125 23888 16403 3559 23649 19243 14289 17852",
"output": "23863"
},
{
"input": "18\n24939 35558 47058 70307 26221 12866 3453 40422 47557 36322 40698 64060 10825 77777 48645 26124 4859 64222",
"output": "77752"
},
{
"input": "24\n633483 654321 122445 481150 347578 37803 525083 151084 211073 358699 339420 452023 219553 119727 74852 66750 371279 405099 618894 649977 235337 607819 81649 649804",
"output": "654296"
},
{
"input": "25\n58115 794098 753382 484882 238434 674285 690118 858677 196185 173301 349729 918792 600745 636016 122678 366783 137179 377098 917081 369620 449039 379412 503678 1000000 292099",
"output": "999975"
},
{
"input": "2\n26 27",
"output": "2"
},
{
"input": "3\n40 30 35",
"output": "15"
},
{
"input": "2\n46 45",
"output": "21"
},
{
"input": "3\n1 25 90",
"output": "65"
},
{
"input": "5\n14 15 16 30 92",
"output": "67"
},
{
"input": "2\n1000 1001",
"output": "976"
},
{
"input": "25\n3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28 2",
"output": "3"
}
] | 31 | 0 | -1 | 3,840 |
|
105 | Transmigration | [
"implementation"
] | A. Transmigration | 2 | 256 | In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills.
Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration.
Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life.
As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the *k* coefficient (if the skill level was equal to *x*, then after transmigration it becomes equal to [*kx*], where [*y*] is the integral part of *y*). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0.
Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible.
You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | The first line contains three numbers *n*, *m* and *k* β the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; *n* and *m* are integers, and *k* is a real number with exactly two digits after decimal point (1<=β€<=*n*,<=*m*<=β€<=20, 0.01<=β€<=*k*<=β€<=0.99).
Then follow *n* lines, each of which describes a character's skill in the form "*name* *exp*" β the skill's name and the character's skill level: *name* is a string and *exp* is an integer in range from 0 to 9999, inclusive.
Then follow *m* lines each of which contains names of skills specific for the class, into which the character transmigrates.
All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | Print on the first line number *z* β the number of skills the character will have after the transmigration. Then print *z* lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | [
"5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost\n"
] | [
"6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0\n"
] | none | [
{
"input": "5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost",
"output": "6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"
},
{
"input": "1 1 0.50\nstaff 1005\nionize",
"output": "2\nionize 0\nstaff 502"
},
{
"input": "4 3 0.32\ninrf 48\nfdgdf 200\nvbkdfk 450\nfdbvfdd 1000\ndff\ninrf\nnfdkd",
"output": "5\ndff 0\nfdbvfdd 320\ninrf 0\nnfdkd 0\nvbkdfk 144"
},
{
"input": "5 1 0.99\na 1\nb 2\nc 3\nd 4\ne 5\nf",
"output": "1\nf 0"
},
{
"input": "2 2 0.02\nfn 1003\nzz 7000\nkk\nau",
"output": "3\nau 0\nkk 0\nzz 140"
},
{
"input": "3 3 0.10\naa 900\nbb 990\ncc 999\naa\nbb\ncc",
"output": "3\naa 0\nbb 0\ncc 0"
},
{
"input": "1 1 0.99\nfdvedvrgfckdkvfpmkjd 100\nfdvedvrgfckdkvfpmkjd",
"output": "1\nfdvedvrgfckdkvfpmkjd 0"
},
{
"input": "1 1 0.01\na 9999\na",
"output": "1\na 0"
},
{
"input": "1 1 0.80\nxyz 125\nxyz",
"output": "1\nxyz 100"
},
{
"input": "5 1 0.67\ndjdn 6699\nolkj 6700\nhgvg 6698\noijggt 6701\nyfyv 6700\nyfyv",
"output": "5\ndjdn 4488\nhgvg 4487\noijggt 4489\nolkj 4489\nyfyv 4489"
},
{
"input": "5 2 0.73\njcyuc 136\npooj 137\nojnbg 138\ninng 135\nuuv 139\nhg\nouohoiivuvu",
"output": "5\nhg 0\nojnbg 100\nouohoiivuvu 0\npooj 100\nuuv 101"
},
{
"input": "4 1 0.99\nutctc 101\nijh 100\nfyyui 99\ntctxxx 102\nojohiobib",
"output": "2\nojohiobib 0\ntctxxx 100"
},
{
"input": "4 4 0.80\nyfcyccyyccccc 123\nkkkkk 124\noops 125\nabfgg 126\nh\njkl\nqwerty\noops",
"output": "5\nabfgg 100\nh 0\njkl 0\noops 100\nqwerty 0"
},
{
"input": "4 6 0.68\na 146\nb 147\nc 148\nd 149\ne\nf\ng\nh\ni\nj",
"output": "8\nc 100\nd 101\ne 0\nf 0\ng 0\nh 0\ni 0\nj 0"
},
{
"input": "5 1 0.02\nirn 4999\nsdfc 5000\nzzzzzz 5001\ndcw 100\nfvvv 22\ndcw",
"output": "3\ndcw 0\nsdfc 100\nzzzzzz 100"
},
{
"input": "5 5 0.18\nxwjxvrgz 9492\ndhpe 5259\nbnbkznfgyuluho 5070\nygpluaefwefxmhuaqi 2975\nvqstuwkaqk 8892\ndhpe\nbnbkznfgyuluho\nygpluaefwefxmhuaqi\nvyaefiicj\nxwjxvrgz",
"output": "6\nbnbkznfgyuluho 912\ndhpe 946\nvqstuwkaqk 1600\nvyaefiicj 0\nxwjxvrgz 1708\nygpluaefwefxmhuaqi 535"
},
{
"input": "10 10 0.28\nszyiekxcixeyqyfm 7701\ncdxkfpggugy 5344\ngqyvyzwkajhc 3674\ntmo 8865\ntbp 8932\nwbrzxccfmdxbzw 4566\nvpgcejyragzhm 1554\ncqqjrh 7868\nw 1548\nxkbitfl 588\nlpcwvverv\nborcfgittei\nw\nzqtzpicsndbxfcbaduds\ncdxkfpggugy\ntmo\nmvmdaltjmy\nbzhykrayudljyj\nyktrcowlgwkvqucbqh\nvtm",
"output": "17\nborcfgittei 0\nbzhykrayudljyj 0\ncdxkfpggugy 1496\ncqqjrh 2203\ngqyvyzwkajhc 1028\nlpcwvverv 0\nmvmdaltjmy 0\nszyiekxcixeyqyfm 2156\ntbp 2500\ntmo 2482\nvpgcejyragzhm 435\nvtm 0\nw 433\nwbrzxccfmdxbzw 1278\nxkbitfl 164\nyktrcowlgwkvqucbqh 0\nzqtzpicsndbxfcbaduds 0"
},
{
"input": "13 13 0.20\nbbdtfrykzf 6189\nnqwei 7327\ndtigwnbwevnnlinhk 3662\nxokqjtylly 1274\nsdpnhipam 5672\npfjmflvtuvctwxr 9580\nybqgomvwoguzcqvzkx 2062\nvowzavh 6345\nbfidjslqlesdtyjkreou 6780\nsvpzwtwn 1945\ninvzueipnifajadhjk 7034\nsz 6494\nce 1323\nybqgomvwoguzcqvzkx\nbbdtfrykzf\nvunbpghae\ndtigwnbwevnnlinhk\nuqdlfskhgo\nvdemdnxifb\nvowzavh\npfjmflvtuvctwxr\nbfidjslqlesdtyjkreou\nnqwei\nsz\njiemqkytxtqnxgjvhzjl\nce",
"output": "17\nbbdtfrykzf 1237\nbfidjslqlesdtyjkreou 1356\nce 264\ndtigwnbwevnnlinhk 732\ninvzueipnifajadhjk 1406\njiemqkytxtqnxgjvhzjl 0\nnqwei 1465\npfjmflvtuvctwxr 1916\nsdpnhipam 1134\nsvpzwtwn 389\nsz 1298\nuqdlfskhgo 0\nvdemdnxifb 0\nvowzavh 1269\nvunbpghae 0\nxokqjtylly 254\nybqgomvwoguzcqvzkx 412"
},
{
"input": "1 17 0.97\nsfidbvqbvx 562\npmuvtjkw\nysxuhhfgwgifkf\nnsgdgacfdstvsf\ngggnzgevrtykq\nvmeytgyobqpmq\nrbzif\nfqbr\nepcy\ntvtgk\nsdwsny\nhuzsrlvxvufyb\niallwqylqga\nsemxysiafu\nodrxgpjgiiizlubtuv\nlenenatgyqep\nlzakhvoxfccct\nijkhhuppdghdwz",
"output": "18\nepcy 0\nfqbr 0\ngggnzgevrtykq 0\nhuzsrlvxvufyb 0\niallwqylqga 0\nijkhhuppdghdwz 0\nlenenatgyqep 0\nlzakhvoxfccct 0\nnsgdgacfdstvsf 0\nodrxgpjgiiizlubtuv 0\npmuvtjkw 0\nrbzif 0\nsdwsny 0\nsemxysiafu 0\nsfidbvqbvx 545\ntvtgk 0\nvmeytgyobqpmq 0\nysxuhhfgwgifkf 0"
},
{
"input": "5 19 0.38\nmwfhslniu 2324\njyzifusxbigcagch 6167\nkccudxutkgb 9673\nuccmkylmiqcn 4773\niuawwcyefaimhro 214\njyzifusxbigcagch\nfalsionuewiyvseurg\nrkrvudkrhophdflqln\nahsybnxitvpm\nx\nancpcxgr\nsvs\nvvssivqobhdfqggahqu\npf\nwjtrtcvjqydxuwwvsqpc\nyllpzfjdojpymwy\nepjhkxffsymowea\nyztamblsfzk\nbej\nwy\nvnkvonk\nymsnsngzcvxeilbitknn\nlmaajt\nmwfhslniu",
"output": "21\nahsybnxitvpm 0\nancpcxgr 0\nbej 0\nepjhkxffsymowea 0\nfalsionuewiyvseurg 0\njyzifusxbigcagch 2343\nkccudxutkgb 3675\nlmaajt 0\nmwfhslniu 883\npf 0\nrkrvudkrhophdflqln 0\nsvs 0\nuccmkylmiqcn 1813\nvnkvonk 0\nvvssivqobhdfqggahqu 0\nwjtrtcvjqydxuwwvsqpc 0\nwy 0\nx 0\nyllpzfjdojpymwy 0\nymsnsngzcvxeilbitknn 0\nyztamblsfzk 0"
},
{
"input": "13 10 0.35\napjqdcdylyads 948\ni 618\nsbifpsvflzngfziwx 6815\nlhuzbitj 8455\nzhoro 657\nfm 6899\nbhigr 6743\net 3322\nljbkmxj 3023\nloxxykp 6048\naiibfjdgd 965\nmmpylhw 5483\nyrbikjks 7426\nfm\njvj\napjqdcdylyads\nbhigr\naiibfjdgd\nljbkmxj\nauftuqyphmz\nloxxykp\nzhoro\ndmqdfmfjq",
"output": "16\naiibfjdgd 337\napjqdcdylyads 331\nauftuqyphmz 0\nbhigr 2360\ndmqdfmfjq 0\net 1162\nfm 2414\ni 216\njvj 0\nlhuzbitj 2959\nljbkmxj 1058\nloxxykp 2116\nmmpylhw 1919\nsbifpsvflzngfziwx 2385\nyrbikjks 2599\nzhoro 229"
},
{
"input": "17 6 0.44\nhefojxlinlzhynuleh 9008\nufy 7485\ngmgjrihvgxsbcu 7575\nrnlz 3789\nnkvcpt 5813\nm 9066\nsjxpwpxrkbpydkjcojvq 8679\nftvk 9385\nyygdlclq 759\nvkltswaflkg 5183\notosgwfe 639\nmaayvyqtvxkudpbcfj 7425\nhys 935\ngwucwol 6087\nbrkmjhnmmrkjzhar 1247\ntea 205\nhyxhj 6600\nmaayvyqtvxkudpbcfj\nm\nrnlz\nbrkmjhnmmrkjzhar\nhys\ngwucwol",
"output": "16\nbrkmjhnmmrkjzhar 548\nftvk 4129\ngmgjrihvgxsbcu 3333\ngwucwol 2678\nhefojxlinlzhynuleh 3963\nhys 411\nhyxhj 2904\nm 3989\nmaayvyqtvxkudpbcfj 3267\nnkvcpt 2557\notosgwfe 281\nrnlz 1667\nsjxpwpxrkbpydkjcojvq 3818\nufy 3293\nvkltswaflkg 2280\nyygdlclq 333"
},
{
"input": "19 3 0.40\npwmgdtn 817\nikzw 8809\nyjltrwizoumwvvtivqmm 2126\ntvdguvmepsvvp 9945\ndvhoxdvqyqmyl 5998\nalpxryere 7048\nchnprj 3029\ntnsrxilkay 1076\nquamvicl 7260\nzdzahaxmxnbkuqavmb 174\nywgyrbmmhwbrcx 3637\noicdsxki 7516\nzftrgvmtbuhqsmv 6831\njlfjgvzgmkmzbsjhwhy 8042\nzuy 2049\nhsahihp 1975\nkcfsycnilwqyqvsf 6896\ntdlgs 4302\nim 4476\nkcfsycnilwqyqvsf\nim\ndvhoxdvqyqmyl",
"output": "18\nalpxryere 2819\nchnprj 1211\ndvhoxdvqyqmyl 2399\nhsahihp 790\nikzw 3523\nim 1790\njlfjgvzgmkmzbsjhwhy 3216\nkcfsycnilwqyqvsf 2758\noicdsxki 3006\npwmgdtn 326\nquamvicl 2904\ntdlgs 1720\ntnsrxilkay 430\ntvdguvmepsvvp 3978\nyjltrwizoumwvvtivqmm 850\nywgyrbmmhwbrcx 1454\nzftrgvmtbuhqsmv 2732\nzuy 819"
},
{
"input": "20 1 0.78\nxc 6799\nztrfjsq 3023\nkhbcbsaztwigxeidh 2974\nkksvbmtjiiqlguwv 188\nwvqzzjrpmxsdbfvua 4547\niqkqqwtqifdpxfhslpv 6264\nwarmknju 9472\nfheisuiufwmtagl 292\nwge 4338\nzaklermeji 6733\nfcn 6282\nbjyjzgzkgzy 1778\ngufpvhdnsesyfuegef 4998\nxnhuhwzzxqbaphktqbc 8485\ncokabaqahfw 8645\nbtgeopbwekffdadgj 1791\nsgvrgyhidnhecvt 7264\ncczstyyxhbpwj 3244\nguaykdl 3786\nmabamfnewwrykizn 4705\nbjyjzgzkgzy",
"output": "20\nbjyjzgzkgzy 1386\nbtgeopbwekffdadgj 1396\ncczstyyxhbpwj 2530\ncokabaqahfw 6743\nfcn 4899\nfheisuiufwmtagl 227\nguaykdl 2953\ngufpvhdnsesyfuegef 3898\niqkqqwtqifdpxfhslpv 4885\nkhbcbsaztwigxeidh 2319\nkksvbmtjiiqlguwv 146\nmabamfnewwrykizn 3669\nsgvrgyhidnhecvt 5665\nwarmknju 7388\nwge 3383\nwvqzzjrpmxsdbfvua 3546\nxc 5303\nxnhuhwzzxqbaphktqbc 6618\nzaklermeji 5251\nztrfjsq 2357"
},
{
"input": "1 1 0.94\na 8700\nb",
"output": "2\na 8178\nb 0"
},
{
"input": "1 1 0.70\na 1000\na",
"output": "1\na 700"
},
{
"input": "2 1 0.50\naxe 200\nmegafire 120\nmegafire",
"output": "2\naxe 100\nmegafire 0"
},
{
"input": "5 4 0.99\naxe 350\nimpaler 300\nionize 102\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost",
"output": "7\naxe 346\nheal 0\nimpaler 297\nionize 100\nmagicboost 217\nmegafire 118\nshield 0"
},
{
"input": "1 1 0.94\na 8700\nb",
"output": "2\na 8178\nb 0"
},
{
"input": "1 1 0.50\nlho 200\nhai",
"output": "2\nhai 0\nlho 100"
},
{
"input": "20 3 0.29\na 100\nb 200\nc 300\nd 400\ne 500\nf 600\ng 700\nh 800\ni 900\nj 1000\nk 1100\nl 1200\nm 1300\nn 1400\no 1500\np 1600\nq 1700\nr 1800\ns 1900\nt 2000\nz\nm\nk",
"output": "18\nd 116\ne 145\nf 174\ng 203\nh 232\ni 261\nj 290\nk 319\nl 348\nm 377\nn 406\no 435\np 464\nq 493\nr 522\ns 551\nt 580\nz 0"
},
{
"input": "2 2 0.50\nabcd 200\naaa 201\nfff\nffff",
"output": "4\naaa 100\nabcd 100\nfff 0\nffff 0"
},
{
"input": "1 1 0.94\na 8700\nb",
"output": "2\na 8178\nb 0"
},
{
"input": "1 1 0.29\nhren 400\nblin",
"output": "2\nblin 0\nhren 116"
},
{
"input": "5 4 0.30\naxe 350\nimpaler 9000\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost",
"output": "6\naxe 105\nheal 0\nimpaler 2700\nmagicboost 0\nmegafire 0\nshield 0"
},
{
"input": "1 1 0.03\naxe 9900\nheal",
"output": "2\naxe 297\nheal 0"
}
] | 156 | 0 | 0 | 3,846 |
888 | Buggy Robot | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U β move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D β move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L β move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R β move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*).
Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations! | The first line contains one number *n* β the length of sequence of commands entered by Ivan (1<=β€<=*n*<=β€<=100).
The second line contains the sequence itself β a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU",
"output": "80"
},
{
"input": "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDULDDLLLRRLRDLLLLR",
"output": "84"
},
{
"input": "91\nRLDRLRRLLDLULULLURULLRRULUDUULLUDULDUULURUDRUDUURDULDUDDUUUDRRUUDLLRULRULURLDRDLDRURLLLRDDD",
"output": "76"
},
{
"input": "92\nRLRDDLULRLLUURRDDDLDDDLDDUURRRULLRDULDULLLUUULDUDLRLRRDRDRDDULDRLUDRDULDRURUDUULLRDRRLLDRLRR",
"output": "86"
},
{
"input": "93\nRLLURLULRURDDLUURLUDDRDLUURLRDLRRRDUULLRDRRLRLDURRDLLRDDLLLDDDLDRRURLLDRUDULDDRRULRRULRLDRDLR",
"output": "84"
},
{
"input": "94\nRDULDDDLULRDRUDRUUDUUDRRRULDRRUDURUULRDUUDLULLLUDURRDRDLUDRULRRRULUURUDDDDDUDLLRDLDRLLRUUURLUL",
"output": "86"
},
{
"input": "95\nRDLUUULLUURDDRLDLLRRRULRLRDULULRULRUDURLULDDDRLURLDRULDUDUUULLRDDURUULULLDDLDRDRLLLURLRDLLDDDDU",
"output": "86"
},
{
"input": "96\nRDDRLRLLDDULRLRURUDLRLDUDRURLLUUDLLURDLRRUURDRRUDRURLLDLLRDURDURLRLUDURULLLRDUURULUUULRRURRDLURL",
"output": "84"
},
{
"input": "97\nRURDDLRLLRULUDURDLRLLUUDURRLLUDLLLDUDRUULDRUUURURULRDLDRRLLUUUDLLLDDLLLLRLLDUDRRDLLUDLRURUDULRLUR",
"output": "82"
},
{
"input": "98\nRUDURLULLDDLLRDLLRDDLLLLRLDDDDRRRDDRRURLDRLLRUUUDLUUUDDDUDRUURLURUUDUUDRULRRULLRRLRULLULDLUURLULRD",
"output": "92"
},
{
"input": "99\nRRULLDULRRDRULLDUDRUDDDRLLUUDRDDUDURLDDRUUDRRUUURRRURDDLDUURDLRLURRDDLUDDLUDURDRUDDURLURURLRUDRURLD",
"output": "86"
},
{
"input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL",
"output": "88"
},
{
"input": "1\nU",
"output": "0"
},
{
"input": "5\nUUULD",
"output": "2"
},
{
"input": "1\nD",
"output": "0"
},
{
"input": "5\nURLUL",
"output": "2"
},
{
"input": "5\nDDDRU",
"output": "2"
},
{
"input": "2\nLR",
"output": "2"
},
{
"input": "8\nDDRDLDUR",
"output": "4"
},
{
"input": "6\nLLLLUD",
"output": "2"
},
{
"input": "13\nRRRLLLLLLLLLL",
"output": "6"
}
] | 62 | 5,632,000 | 0 | 3,848 |
|
363 | Soroban | [
"implementation"
] | null | null | You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban β an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about them. Let's have a look at the Soroban's construction.
Soroban consists of some number of rods, each rod contains five beads. We will assume that the rods are horizontal lines. One bead on each rod (the leftmost one) is divided from the others by a bar (the reckoning bar). This single bead is called go-dama and four others are ichi-damas. Each rod is responsible for representing a single digit from 0 to 9. We can obtain the value of a digit by following simple algorithm:
- Set the value of a digit equal to 0. - If the go-dama is shifted to the right, add 5. - Add the number of ichi-damas shifted to the left.
Thus, the upper rod on the picture shows digit 0, the middle one shows digit 2 and the lower one shows 7. We will consider the top rod to represent the last decimal digit of a number, so the picture shows number 720.
Write the program that prints the way Soroban shows the given number *n*. | The first line contains a single integer *n* (0<=β€<=*n*<=<<=109). | Print the description of the decimal digits of number *n* from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal representation of number *n* without leading zeroes. We can assume that number 0 has no leading zeroes. | [
"2\n",
"13\n",
"720\n"
] | [
"O-|OO-OO\n",
"O-|OOO-O\nO-|O-OOO\n",
"O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n"
] | none | [
{
"input": "2",
"output": "O-|OO-OO"
},
{
"input": "13",
"output": "O-|OOO-O\nO-|O-OOO"
},
{
"input": "720",
"output": "O-|-OOOO\nO-|OO-OO\n-O|OO-OO"
},
{
"input": "0",
"output": "O-|-OOOO"
},
{
"input": "1",
"output": "O-|O-OOO"
},
{
"input": "3",
"output": "O-|OOO-O"
},
{
"input": "4",
"output": "O-|OOOO-"
},
{
"input": "5",
"output": "-O|-OOOO"
},
{
"input": "6",
"output": "-O|O-OOO"
},
{
"input": "637",
"output": "-O|OO-OO\nO-|OOO-O\n-O|O-OOO"
},
{
"input": "7",
"output": "-O|OO-OO"
},
{
"input": "8",
"output": "-O|OOO-O"
},
{
"input": "9",
"output": "-O|OOOO-"
},
{
"input": "10",
"output": "O-|-OOOO\nO-|O-OOO"
},
{
"input": "11",
"output": "O-|O-OOO\nO-|O-OOO"
},
{
"input": "100",
"output": "O-|-OOOO\nO-|-OOOO\nO-|O-OOO"
},
{
"input": "99",
"output": "-O|OOOO-\n-O|OOOO-"
},
{
"input": "245",
"output": "-O|-OOOO\nO-|OOOO-\nO-|OO-OO"
},
{
"input": "118",
"output": "-O|OOO-O\nO-|O-OOO\nO-|O-OOO"
},
{
"input": "429",
"output": "-O|OOOO-\nO-|OO-OO\nO-|OOOO-"
},
{
"input": "555",
"output": "-O|-OOOO\n-O|-OOOO\n-O|-OOOO"
},
{
"input": "660",
"output": "O-|-OOOO\n-O|O-OOO\n-O|O-OOO"
},
{
"input": "331",
"output": "O-|O-OOO\nO-|OOO-O\nO-|OOO-O"
},
{
"input": "987",
"output": "-O|OO-OO\n-O|OOO-O\n-O|OOOO-"
},
{
"input": "123456789",
"output": "-O|OOOO-\n-O|OOO-O\n-O|OO-OO\n-O|O-OOO\n-O|-OOOO\nO-|OOOO-\nO-|OOO-O\nO-|OO-OO\nO-|O-OOO"
},
{
"input": "234567890",
"output": "O-|-OOOO\n-O|OOOO-\n-O|OOO-O\n-O|OO-OO\n-O|O-OOO\n-O|-OOOO\nO-|OOOO-\nO-|OOO-O\nO-|OO-OO"
},
{
"input": "100000000",
"output": "O-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|O-OOO"
},
{
"input": "111111111",
"output": "O-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO"
},
{
"input": "90909090",
"output": "O-|-OOOO\n-O|OOOO-\nO-|-OOOO\n-O|OOOO-\nO-|-OOOO\n-O|OOOO-\nO-|-OOOO\n-O|OOOO-"
},
{
"input": "987654321",
"output": "O-|O-OOO\nO-|OO-OO\nO-|OOO-O\nO-|OOOO-\n-O|-OOOO\n-O|O-OOO\n-O|OO-OO\n-O|OOO-O\n-O|OOOO-"
},
{
"input": "45165125",
"output": "-O|-OOOO\nO-|OO-OO\nO-|O-OOO\n-O|-OOOO\n-O|O-OOO\nO-|O-OOO\n-O|-OOOO\nO-|OOOO-"
},
{
"input": "445511006",
"output": "-O|O-OOO\nO-|-OOOO\nO-|-OOOO\nO-|O-OOO\nO-|O-OOO\n-O|-OOOO\n-O|-OOOO\nO-|OOOO-\nO-|OOOO-"
},
{
"input": "999999999",
"output": "-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-"
},
{
"input": "984218523",
"output": "O-|OOO-O\nO-|OO-OO\n-O|-OOOO\n-O|OOO-O\nO-|O-OOO\nO-|OO-OO\nO-|OOOO-\n-O|OOO-O\n-O|OOOO-"
},
{
"input": "19",
"output": "-O|OOOO-\nO-|O-OOO"
},
{
"input": "10000000",
"output": "O-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|O-OOO"
}
] | 62 | 0 | 3 | 3,853 |
|
633 | A Trivial Problem | [
"brute force",
"constructive algorithms",
"math",
"number theory"
] | null | null | Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? | The only line of input contains an integer *m* (1<=β€<=*m*<=β€<=100<=000)Β β the required number of trailing zeroes in factorial. | First print *k*Β β the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order. | [
"1\n",
"5\n"
] | [
"5\n5 6 7 8 9 ",
"0"
] | The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*!β=β1Β·2Β·3Β·...Β·*n*.
In the first sample, 5!β=β120, 6!β=β720, 7!β=β5040, 8!β=β40320 and 9!β=β362880. | [
{
"input": "1",
"output": "5\n5 6 7 8 9 "
},
{
"input": "5",
"output": "0"
},
{
"input": "2",
"output": "5\n10 11 12 13 14 "
},
{
"input": "3",
"output": "5\n15 16 17 18 19 "
},
{
"input": "7",
"output": "5\n30 31 32 33 34 "
},
{
"input": "12",
"output": "5\n50 51 52 53 54 "
},
{
"input": "15",
"output": "5\n65 66 67 68 69 "
},
{
"input": "18",
"output": "5\n75 76 77 78 79 "
},
{
"input": "38",
"output": "5\n155 156 157 158 159 "
},
{
"input": "47",
"output": "5\n195 196 197 198 199 "
},
{
"input": "58",
"output": "5\n240 241 242 243 244 "
},
{
"input": "66",
"output": "5\n270 271 272 273 274 "
},
{
"input": "70",
"output": "5\n285 286 287 288 289 "
},
{
"input": "89",
"output": "5\n365 366 367 368 369 "
},
{
"input": "417",
"output": "5\n1675 1676 1677 1678 1679 "
},
{
"input": "815",
"output": "5\n3265 3266 3267 3268 3269 "
},
{
"input": "394",
"output": "5\n1585 1586 1587 1588 1589 "
},
{
"input": "798",
"output": "0"
},
{
"input": "507",
"output": "5\n2035 2036 2037 2038 2039 "
},
{
"input": "406",
"output": "5\n1630 1631 1632 1633 1634 "
},
{
"input": "570",
"output": "5\n2290 2291 2292 2293 2294 "
},
{
"input": "185",
"output": "0"
},
{
"input": "765",
"output": "0"
},
{
"input": "967",
"output": "0"
},
{
"input": "112",
"output": "5\n455 456 457 458 459 "
},
{
"input": "729",
"output": "5\n2925 2926 2927 2928 2929 "
},
{
"input": "4604",
"output": "5\n18425 18426 18427 18428 18429 "
},
{
"input": "8783",
"output": "5\n35140 35141 35142 35143 35144 "
},
{
"input": "1059",
"output": "0"
},
{
"input": "6641",
"output": "5\n26575 26576 26577 26578 26579 "
},
{
"input": "9353",
"output": "5\n37425 37426 37427 37428 37429 "
},
{
"input": "1811",
"output": "5\n7250 7251 7252 7253 7254 "
},
{
"input": "2528",
"output": "0"
},
{
"input": "8158",
"output": "5\n32640 32641 32642 32643 32644 "
},
{
"input": "3014",
"output": "5\n12070 12071 12072 12073 12074 "
},
{
"input": "7657",
"output": "5\n30640 30641 30642 30643 30644 "
},
{
"input": "4934",
"output": "0"
},
{
"input": "9282",
"output": "5\n37140 37141 37142 37143 37144 "
},
{
"input": "2610",
"output": "5\n10450 10451 10452 10453 10454 "
},
{
"input": "2083",
"output": "5\n8345 8346 8347 8348 8349 "
},
{
"input": "26151",
"output": "5\n104620 104621 104622 104623 104624 "
},
{
"input": "64656",
"output": "5\n258640 258641 258642 258643 258644 "
},
{
"input": "46668",
"output": "5\n186690 186691 186692 186693 186694 "
},
{
"input": "95554",
"output": "5\n382235 382236 382237 382238 382239 "
},
{
"input": "37320",
"output": "0"
},
{
"input": "52032",
"output": "5\n208140 208141 208142 208143 208144 "
},
{
"input": "11024",
"output": "5\n44110 44111 44112 44113 44114 "
},
{
"input": "63218",
"output": "5\n252885 252886 252887 252888 252889 "
},
{
"input": "40095",
"output": "5\n160390 160391 160392 160393 160394 "
},
{
"input": "42724",
"output": "5\n170910 170911 170912 170913 170914 "
},
{
"input": "24381",
"output": "5\n97530 97531 97532 97533 97534 "
},
{
"input": "73138",
"output": "5\n292570 292571 292572 292573 292574 "
},
{
"input": "93346",
"output": "5\n373400 373401 373402 373403 373404 "
},
{
"input": "18338",
"output": "5\n73370 73371 73372 73373 73374 "
},
{
"input": "42662",
"output": "5\n170660 170661 170662 170663 170664 "
},
{
"input": "81221",
"output": "5\n324900 324901 324902 324903 324904 "
},
{
"input": "100000",
"output": "5\n400005 400006 400007 400008 400009 "
},
{
"input": "100000",
"output": "5\n400005 400006 400007 400008 400009 "
},
{
"input": "99998",
"output": "0"
},
{
"input": "30",
"output": "0"
},
{
"input": "11",
"output": "0"
},
{
"input": "780",
"output": "0"
},
{
"input": "97656",
"output": "5\n390625 390626 390627 390628 390629 "
},
{
"input": "12499",
"output": "5\n50000 50001 50002 50003 50004 "
},
{
"input": "65",
"output": "5\n265 266 267 268 269 "
},
{
"input": "41",
"output": "5\n170 171 172 173 174 "
},
{
"input": "31",
"output": "5\n125 126 127 128 129 "
},
{
"input": "86577",
"output": "0"
}
] | 124 | 0 | 0 | 3,860 |
|
656 | Scrambled | [
"*special",
"implementation"
] | null | null | Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht *D*Β *mod*Β *M*[*i*]<==<=*R*[*i*], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo. | The first line of input contains a single integer N (1<=β€<=*N*<=β€<=16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All *M*[*i*] are positive, for each *i* *R*[*i*]<=<<=*M*[*i*]. | Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=4. | [
"1\n2\n0\n",
"2\n2 3\n1 0\n"
] | [
"0.500000\n",
"0.666667\n"
] | none | [
{
"input": "1\n2\n0",
"output": "0.500000"
},
{
"input": "2\n2 3\n1 0",
"output": "0.666667"
},
{
"input": "3\n2 4 4\n0 1 3",
"output": "1.000000"
},
{
"input": "1\n16\n15",
"output": "0.062500"
},
{
"input": "16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "1.000000"
},
{
"input": "16\n5 6 9 13 13 15 9 10 2 6 10 11 12 7 4 8\n4 3 3 5 8 3 6 5 1 4 2 6 7 4 0 1",
"output": "0.959707"
},
{
"input": "8\n15 3 7 11 14 10 16 2\n0 2 1 4 0 0 13 1",
"output": "0.826840"
},
{
"input": "1\n7\n5",
"output": "0.142857"
},
{
"input": "9\n6 12 3 10 15 14 6 9 3\n5 2 0 6 1 1 2 2 2",
"output": "0.752381"
},
{
"input": "3\n9 12 6\n0 5 0",
"output": "0.305556"
},
{
"input": "5\n3 3 13 5 10\n1 0 1 4 2",
"output": "0.784615"
},
{
"input": "7\n3 15 11 4 12 15 12\n2 9 3 0 9 13 6",
"output": "0.757576"
},
{
"input": "2\n13 3\n6 0",
"output": "0.384615"
},
{
"input": "9\n15 9 7 4 14 14 2 11 13\n2 6 2 3 11 12 0 3 3",
"output": "0.876790"
},
{
"input": "1\n15\n1",
"output": "0.066667"
},
{
"input": "1\n6\n3",
"output": "0.166667"
},
{
"input": "4\n3 8 9 4\n1 6 7 3",
"output": "0.583333"
},
{
"input": "7\n15 9 9 2 6 8 3\n10 2 7 1 3 2 0",
"output": "0.850000"
},
{
"input": "10\n9 8 7 7 16 3 10 13 5 6\n2 0 0 4 1 0 3 12 1 5",
"output": "0.832418"
},
{
"input": "4\n10 15 2 9\n8 14 0 0",
"output": "0.588889"
},
{
"input": "12\n5 16 12 3 10 15 11 14 2 3 4 11\n3 14 1 0 7 9 10 12 1 2 2 6",
"output": "0.953247"
},
{
"input": "5\n16 6 4 15 2\n13 3 0 13 0",
"output": "0.737500"
},
{
"input": "14\n12 11 7 12 2 4 14 10 7 4 15 3 5 16\n2 8 0 9 0 1 4 0 5 3 11 1 0 6",
"output": "1.000000"
},
{
"input": "12\n8 5 5 12 12 14 14 16 5 11 9 3\n1 4 0 11 10 0 2 3 1 8 8 2",
"output": "0.859307"
},
{
"input": "10\n3 16 16 9 5 16 9 7 8 2\n0 1 7 2 1 9 0 4 4 1",
"output": "0.857143"
},
{
"input": "9\n14 14 5 8 16 2 11 7 11\n9 7 0 2 7 1 10 2 4",
"output": "0.789610"
},
{
"input": "7\n13 12 4 2 7 13 8\n4 6 0 0 3 9 3",
"output": "0.728022"
},
{
"input": "5\n4 15 9 16 6\n3 9 8 14 1",
"output": "0.518056"
},
{
"input": "3\n16 13 3\n11 5 1",
"output": "0.423077"
},
{
"input": "7\n10 15 9 5 9 15 16\n2 7 2 4 0 12 13",
"output": "0.543056"
},
{
"input": "10\n16 10 16 15 12 5 4 9 3 10\n9 0 1 2 9 4 1 8 0 8",
"output": "0.811111"
},
{
"input": "14\n14 8 6 12 13 15 2 3 16 15 15 15 16 8\n10 0 5 6 1 7 0 2 1 4 2 11 14 2",
"output": "0.784615"
},
{
"input": "2\n10 14\n2 5",
"output": "0.171429"
},
{
"input": "10\n2 15 15 4 3 10 8 14 12 12\n1 8 13 0 0 6 4 2 4 5",
"output": "0.914286"
},
{
"input": "3\n6 14 7\n4 2 0",
"output": "0.333333"
},
{
"input": "13\n3 4 16 11 12 13 12 12 3 16 8 13 4\n0 1 14 5 8 5 11 7 1 6 4 1 0",
"output": "0.967949"
}
] | 77 | 5,836,800 | 0 | 3,881 |
|
920 | Connected Components? | [
"data structures",
"dfs and similar",
"dsu",
"graphs"
] | null | null | You are given an undirected graph consisting of *n* vertices and edges. Instead of giving you the edges that exist in the graph, we give you *m* unordered pairs (*x*,<=*y*) such that there is no edge between *x* and *y*, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.
You have to find the number of connected components in the graph and the size of each component. A connected component is a set of vertices *X* such that for every two vertices from this set there exists at least one path in the graph connecting these vertices, but adding any other vertex to *X* violates this rule. | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=200000, ).
Then *m* lines follow, each containing a pair of integers *x* and *y* (1<=β€<=*x*,<=*y*<=β€<=*n*, *x*<=β <=*y*) denoting that there is no edge between *x* and *y*. Each pair is listed at most once; (*x*,<=*y*) and (*y*,<=*x*) are considered the same (so they are never listed in the same test). If some pair of vertices is not listed in the input, then there exists an edge between those vertices. | Firstly print *k* β the number of connected components in this graph.
Then print *k* integers β the sizes of components. You should output these integers in non-descending order. | [
"5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n"
] | [
"2\n1 4 "
] | none | [
{
"input": "5 5\n1 2\n3 4\n3 2\n4 2\n2 5",
"output": "2\n1 4 "
},
{
"input": "8 15\n2 1\n4 5\n2 4\n3 4\n2 5\n3 5\n2 6\n3 6\n5 6\n4 6\n2 7\n3 8\n2 8\n3 7\n6 7",
"output": "1\n8 "
},
{
"input": "12 58\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 10\n1 11\n1 12\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n4 5\n4 6\n4 8\n4 11\n4 12\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n7 8\n7 9\n7 10\n7 11\n7 12\n8 9\n8 10\n8 11\n9 10\n9 11\n9 12\n10 12",
"output": "4\n1 1 1 9 "
},
{
"input": "5 7\n1 2\n2 3\n3 4\n1 5\n2 5\n3 5\n4 5",
"output": "2\n1 4 "
},
{
"input": "6 10\n1 2\n1 3\n1 4\n1 6\n2 3\n2 4\n2 5\n3 5\n3 6\n4 6",
"output": "1\n6 "
},
{
"input": "8 23\n1 2\n1 4\n1 6\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n5 6\n5 7\n5 8\n6 8\n7 8",
"output": "3\n1 2 5 "
},
{
"input": "4 3\n2 1\n3 1\n4 2",
"output": "1\n4 "
},
{
"input": "6 9\n1 2\n1 4\n1 5\n2 3\n2 5\n2 6\n3 5\n4 6\n5 6",
"output": "1\n6 "
},
{
"input": "2 0",
"output": "1\n2 "
},
{
"input": "8 18\n1 4\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 8\n4 7\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8",
"output": "1\n8 "
},
{
"input": "4 3\n1 2\n3 1\n4 3",
"output": "1\n4 "
},
{
"input": "8 23\n2 7\n7 5\n8 6\n8 2\n6 3\n3 5\n8 1\n8 4\n8 3\n3 4\n1 2\n2 6\n5 2\n6 4\n7 6\n6 5\n7 8\n7 1\n5 4\n3 7\n1 4\n3 1\n3 2",
"output": "3\n1 3 4 "
},
{
"input": "4 4\n2 1\n3 1\n1 4\n3 2",
"output": "2\n1 3 "
},
{
"input": "2 1\n1 2",
"output": "2\n1 1 "
},
{
"input": "4 3\n1 3\n1 4\n2 3",
"output": "1\n4 "
},
{
"input": "3 1\n2 3",
"output": "1\n3 "
},
{
"input": "5 4\n1 4\n2 3\n4 3\n4 2",
"output": "1\n5 "
},
{
"input": "10 36\n7 8\n7 9\n2 3\n2 4\n2 5\n9 10\n2 7\n2 8\n2 9\n2 10\n4 5\n4 6\n4 7\n4 8\n4 10\n6 7\n6 9\n6 10\n1 2\n1 3\n1 4\n8 9\n1 5\n8 10\n1 7\n1 8\n1 9\n1 10\n3 4\n3 6\n3 7\n3 9\n5 6\n5 7\n5 9\n5 10",
"output": "2\n2 8 "
},
{
"input": "10 34\n7 10\n2 3\n2 4\n2 5\n9 10\n2 7\n2 8\n2 10\n4 5\n4 6\n4 7\n4 8\n4 9\n6 7\n6 8\n6 9\n6 10\n1 2\n1 3\n1 5\n8 9\n1 6\n1 7\n1 8\n1 9\n1 10\n3 4\n3 5\n3 6\n3 8\n3 10\n5 6\n5 9\n5 10",
"output": "1\n10 "
},
{
"input": "12 56\n9 5\n2 6\n9 8\n5 4\n1 11\n1 6\n4 1\n1 10\n10 3\n8 4\n5 1\n9 1\n5 10\n2 7\n11 5\n6 11\n5 8\n7 6\n3 2\n12 7\n8 6\n12 3\n1 2\n8 1\n2 11\n10 12\n4 6\n5 12\n2 4\n10 2\n7 3\n12 11\n7 10\n7 1\n9 2\n11 9\n9 10\n8 7\n11 3\n7 9\n5 7\n4 12\n3 5\n12 2\n4 10\n9 12\n5 2\n9 4\n11 8\n8 2\n3 6\n4 11\n8 10\n6 10\n3 9\n3 4",
"output": "3\n1 4 7 "
},
{
"input": "11 49\n10 3\n6 4\n11 3\n7 6\n10 6\n6 1\n4 3\n10 2\n4 5\n9 2\n10 1\n5 7\n1 5\n9 7\n2 11\n8 6\n3 9\n2 5\n9 5\n6 5\n1 4\n11 9\n1 7\n8 10\n3 6\n3 7\n11 5\n6 9\n4 10\n8 7\n4 9\n8 2\n4 2\n8 11\n7 4\n9 10\n8 1\n10 7\n3 2\n5 8\n8 9\n1 3\n2 7\n10 11\n5 3\n10 5\n4 11\n1 11\n8 3",
"output": "5\n1 1 1 2 6 "
}
] | 561 | 54,272,000 | 3 | 3,884 |
|
98 | Help King | [
"implementation",
"probabilities",
"trees"
] | B. Help King | 2 | 256 | This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, but not happily ever after: one day a vicious dragon attacked the kingdom and stole Victoria. The King was full of grief, yet he gathered his noble knights and promised half of his kingdom and Victoria's hand in marriage to the one who will save the girl from the infernal beast.
Having travelled for some time, the knights found the dragon's lair and all of them rushed there to save Victoria. Each knight spat on the dragon once and, as the dragon had quite a fragile and frail heart, his heart broke and poor beast died. As for the noble knights, they got Victoria right to the King and started brawling as each one wanted the girl's hand in marriage.
The problem was that all the noble knights were equally noble and equally handsome, and Victoria didn't want to marry any of them anyway. Then the King (and he was a very wise man and didn't want to hurt anybody's feelings) decided to find out who will get his daughter randomly, i.e. tossing a coin. However, there turned out to be *n* noble knights and the coin only has two sides. The good thing is that when a coin is tossed, the coin falls on each side with equal probability. The King got interested how to pick one noble knight using this coin so that all knights had equal probability of being chosen (the probability in that case should always be equal to 1<=/<=*n*). First the King wants to know the expected number of times he will need to toss a coin to determine the winner. Besides, while tossing the coin, the King should follow the optimal tossing strategy (i.e. the strategy that minimizes the expected number of tosses). Help the King in this challenging task. | The first line contains a single integer *n* from the problem's statement (1<=β€<=*n*<=β€<=10000). | Print the sought expected number of tosses as an irreducible fraction in the following form: "*a*/*b*" (without the quotes) without leading zeroes. | [
"2\n",
"3\n",
"4\n"
] | [
"1/1\n",
"8/3\n",
"2/1\n"
] | none | [
{
"input": "2",
"output": "1/1"
},
{
"input": "3",
"output": "8/3"
},
{
"input": "4",
"output": "2/1"
},
{
"input": "8",
"output": "3/1"
},
{
"input": "7",
"output": "24/7"
},
{
"input": "6",
"output": "11/3"
},
{
"input": "1",
"output": "0/1"
},
{
"input": "5",
"output": "18/5"
},
{
"input": "96",
"output": "23/3"
},
{
"input": "54",
"output": "377/57"
},
{
"input": "49",
"output": "1985714/299593"
},
{
"input": "57",
"output": "1118/171"
},
{
"input": "21",
"output": "38/7"
},
{
"input": "43",
"output": "896/129"
},
{
"input": "56",
"output": "45/7"
},
{
"input": "46",
"output": "13719/2047"
},
{
"input": "91",
"output": "704/91"
},
{
"input": "13",
"output": "306/65"
},
{
"input": "82",
"output": "7739/1025"
},
{
"input": "69",
"output": "32740246/4194303"
},
{
"input": "77",
"output": "8215881550/1073741823"
},
{
"input": "27",
"output": "320/57"
},
{
"input": "63",
"output": "128/21"
},
{
"input": "60",
"output": "94/15"
},
{
"input": "42",
"output": "45/7"
},
{
"input": "29",
"output": "89074/16385"
},
{
"input": "99",
"output": "82792/10923"
},
{
"input": "19",
"output": "2936/513"
},
{
"input": "89",
"output": "15942/2047"
},
{
"input": "356",
"output": "20036/2047"
},
{
"input": "377",
"output": "42877948701338/4398046511105"
},
{
"input": "376",
"output": "81794781/8388607"
},
{
"input": "199",
"output": "5416016912792671923933831206744/633825300114114700748351602687"
},
{
"input": "563",
"output": "13880251801665520090148870069821814422429790384486504048582895486382118580803670864520/1295112594817152713946307937882345937761604559368093014167874939825936190136805665451"
},
{
"input": "768",
"output": "32/3"
},
{
"input": "777",
"output": "242912325346/22906492245"
},
{
"input": "721",
"output": "24323770714557246/2251799813685247"
},
{
"input": "629",
"output": "49843473149688266962934/4722366482869645213695"
},
{
"input": "589",
"output": "13383001136884230836493585742/1237940039285380274899124223"
},
{
"input": "698",
"output": "261084475895343697268604849722313704014143081638278003/23945242826029513411849172299223580994042798784118785"
},
{
"input": "897",
"output": "6303910445469575479185224346195379698702/604946430081668379490443746545365709255"
},
{
"input": "100",
"output": "1548/205"
},
{
"input": "898",
"output": "54181807382553033285317903788494851/5192296858534827628530496329220097"
},
{
"input": "778",
"output": "266081190240146347461776796003542832080357458393960689731819/25108406941546723055343157692830665664409421777856138051585"
},
{
"input": "408",
"output": "481/51"
},
{
"input": "915",
"output": "24489920882263416/2329134352741105"
},
{
"input": "659",
"output": "11506864999305980525685467247724160971763964558240405270397991163704744844086671519176045618744739064/1093625362391505962186251113558810682676584715446606218212885303204976499599687961611756588511526913"
},
{
"input": "380",
"output": "17089848754/1762037865"
},
{
"input": "826",
"output": "28584112877549284603281069376719144007233968270323045/2660582536225501490205463588802620110449199864902087"
},
{
"input": "570",
"output": "81780152549/7635497415"
},
{
"input": "8947",
"output": "9221776965061394108063074537665193339719130234791259353035383369908276748232005329587397633526133839630977366288410166284245740877083371222474025826991630911939336371916388075479778450420492837649418370715068725438291562232309367997828789596177392059429297899551357796421577750411209045517378683903876507895356659650107620108241824167563644901510340265372019179673453724120802026261156279978925379653814720997930734349648232984115741566886698873835913569553263892609588155620638724704727598288959685621550249737..."
},
{
"input": "5379",
"output": "369970662679510300707473720654925140999880897391589444623141436368705516892112173326991585567498714963884175295883677699016/27543998699593691622996471168032126659516861790178384136860366469766907968179639409382883768321470201982967167709306596011"
},
{
"input": "2614",
"output": "467288820759363880397722656040592964020719930972683440703193351374700405080631777580381050558531644513848619882285655907104502715940077345333622944378242416293600447930921066507506568704500773773633/37375513539561023231108477793896786533525327931380202951304745106630862169773485150256437750311906506986637800026885384689161869077507588081685801531164378630160340372359290471078905382884178132993"
},
{
"input": "6212",
"output": "718828780749497450032379379564/52818775009509558395695966891"
},
{
"input": "3586",
"output": "1026714465140783036738474632330359205383783819874722347437634384119469704928190591460057095203615899196742515080053210107395/82631996098781074868989413504096379978550585370535152410581099409300723904538918228148651304964410605948901503127919788033"
},
{
"input": "6629",
"output": "2887307659130237302642554273423838808127851411579740408603950850448329124209429578113205979182558694432261838498919298006073282090488747091133824076367223385537560048772408256051559991222428913480943619030448796454451464748405569577077070495809049315150455270612613741854545427076463694803465943631755282225609026765330663439059215627258266275926212560658364641003632351846514061002732653254081394744335331237509798266695411546509090369792904212760685221160746857281893822469878668200610823671894328098385881817..."
},
{
"input": "9861",
"output": "48205401549715737511233606679265031152996036546952288925330285615396586708825956490117819026249283326464870369563186432330830706792989284262067110327971987394928549360770263191516012692848869076552182149927367930957872055698792311482405327082065553619653685393875355497796244989262571944371234203749880818792381890143341459002264984197001955297069409069640536538793687219440766877509028035223421720178766484630650779161811795215598122460003343408475412680746717692338/3290879900222849827608052539430658202162644..."
},
{
"input": "1649",
"output": "1103258059369546/93824992236885"
},
{
"input": "1108",
"output": "829108303866668/70368744177665"
},
{
"input": "6704",
"output": "3747509385261755254210316751920800389821077334621726013635892116/274250759553534340359161530426225084163789310938929977224768171"
},
{
"input": "8771",
"output": "3770311067804988086442280897982793233953991174834038671591744622664235928848771481024534828492198884087581040596792755307166862630362254070801530083149662062951269890316117808935983174156710048296936374305714276676638609402088826404322038255398708095256451326373150897864019805504212731596330281332804357336587199175247125958363190591680678576959242590696722761770737808874948948372052533640442104091203823298252400438183921494229420351844306480773904754871502489649028646657382266084070860349033005494965904934..."
},
{
"input": "4710",
"output": "62214231544449127/4503599627370495"
},
{
"input": "2337",
"output": "6429067313146769086191243390708972817399071295570593226/510831846955296286119449009050103061206246374061200725"
},
{
"input": "7708",
"output": "39413297508974631726391031213171923271142554912679270458193728426423636026646334915727139650713682692479792411879633606353758285856351703126/2977131414714805823690030317109266572712515013375254774912983855843898524112477893944078543723575564536883288499266264815757728270805630975"
},
{
"input": "5484",
"output": "211086977989859276474150/15111572745182864683827"
},
{
"input": "2050",
"output": "2663/205"
},
{
"input": "5157",
"output": "1244202699616577925257908854992502879105187462860652753500143979369064245723363816152901984642185318105227079924186855121298620779636669909099525176016720566980036738379840484201060840762226140891649195248344160034243456960969500434409559402400997785076262368243485151264623913446406300409714366263836544017408112602389622392168343772273329588989257854547075621647134412375571624421845467345018113608142941220069412256286427238705568845394057266549279844034564540504288723831871872613761385100219013571797574528..."
},
{
"input": "9556",
"output": "61105610582596188064013632976018238169594847263124154642386689594807697097885447064570207703083797375229286491941164437689434529990291086697099939303795410031817348526076989232509267027565641811597218817018817025267674646870116016782259903322684685324891049798873702815116504349778081974046190242424181610803910534907237209386333892868457625884598750479036332/4139057561631190052420042715397268145091328063809781231185874234711716512317727312355164552220203407039993009382683073987640607521830928131007598529502..."
},
{
"input": "7901",
"output": "1545248712235484231234951857976545065744617617020030658469109057466859986475148250693905886674893272489053581743278765525029576600572532534838775161015285299867097071351763023768221772211614326132946083723216283578235838641012739144142278748089419497887052400481010672846336748523045688232788476455926025596760805229671163941642019404158795532714920358340283273984860096000931574655035232114889550219531272686479161110317036826198314000803468166009351225032738229182153921483640756378743625620038865132469106047..."
},
{
"input": "8622",
"output": "2346970612497798292051684863778787677688918498337895665035233783242368128286257851467636458012981817792946447606933694463959158768680516918810044760234529638520868683195790661167605124671831213269266007988150361676380026247303195939614144448935172977317349504257500667344413574778276538084533093523373859439640543406392557232735743996270882880554311714917225257533788072187384837827098726745502145040757646538864148126423442625937245/15845010358053163603682882776020046370855826407419789577061413023873354878758..."
},
{
"input": "16",
"output": "4/1"
},
{
"input": "32",
"output": "5/1"
},
{
"input": "64",
"output": "6/1"
},
{
"input": "128",
"output": "7/1"
},
{
"input": "256",
"output": "8/1"
},
{
"input": "512",
"output": "9/1"
},
{
"input": "1024",
"output": "10/1"
},
{
"input": "2048",
"output": "11/1"
},
{
"input": "4096",
"output": "12/1"
},
{
"input": "8192",
"output": "13/1"
},
{
"input": "9749",
"output": "2442073850489536993602927585016307199165621395304075025177694875024679607796284569131767726963170591399402108675638309823508923120869023271471818205166195909414421298770225330343221707377312426015931814666620011704161259290684411521150904067521292013955185317667861253504565429204675752674949251324122812583751343895693341865871684651273036507250959013187746544944138162398891218537343348931977619498001506833868902121065893913936425349903046456157409756042496452120477911621545767772676861905004685673876448424..."
},
{
"input": "9803",
"output": "3273210180788326072665779956874407303695209430301336271835983946088930098968971592446649088493870209185601637297946849124915345946101994703881396454817629317067995483358046696632270413949397783371061147815617923539634120806955265009854911188530306501324761896490486400736980978270851173985761450205468514371802366150508965142349402634775190541932571215772934087049601511151015580218962449832712507548850463067009640345032653747650848021793733486635063672276271184797891474270402353352104959589784879937226619631..."
},
{
"input": "9851",
"output": "1826526826552054078590833159938859608660168689393622926697593614966325247523385486843148169222905802492343158938765988786790268008018346250425185590729454696317705467641275241528094330016670372495410419378141651879792828682641532533284092879418090040903735626785107378204659838740412715571880884453837366724444432895654221478996531206045405344762139424591887085118650734474741760565377558510969213435666224432175984910232854534478442066899535808519463012771143160247271088007881997468588868391395961360449311260..."
},
{
"input": "9859",
"output": "9737556487585955271085725726347548524587201515015415940974212696477918276264308244608931996051014559947727871548525843984646030062506833242765111803441650144268637762679345636011358150115775908768896005580214321628703868435548404239676226435996040392670484414990942576376634145721680636769353606720643265107519869112758891642047680407647874665865802380346668006876206490814588938569751811311435939234659864088396761136789798899162439354805109166450795279173094212597156554710639295669120966978022955523520243885..."
},
{
"input": "9883",
"output": "3585169013008320587733453934540655406968508071250655174069676351966247095891666666457951370861261022535907218197677774600785190516321049571099175528120462561383326438548822604717683501452327840790897918994708328294710567693091965543331903184071652577937298158191755916197924842106107578819028940776121678861464188820255086932973183740793372165945865009415954786595728774195980645745127346052687115724325004061229398519190748075580806663121266449693574278118081790297078495193488775980028423355059820522243653725..."
},
{
"input": "9901",
"output": "1838099364825091485842998238489502638352163208605775246129613825541675258139803932850287467779059152113767067936585018625986257156889365449198856216156597215096982506298229063072584364817360767528951048690402306736891920567120457283597208730483707878597646111737127186752299112571526574444743928839110241560725998077538870670908652964981237795923920133705668072188172055098674658571105524472734987571439013958589827622877679807533101349696441175687163721291688130495577638100992957486490904022264860238167307326..."
},
{
"input": "9907",
"output": "1633354865670482634892575473274177878269848372373759525765811325846788929611278968402771127221384695483915945198456285004476851582174958025985911899376499975337986661537173411180428490907671107896805361798951388912266345066652077866312114944286489782939084013056891167373799137114155515056010000276816186615290579398553645497061457349859874907706345855178899820840538136570385474191197090563464515778875629438803382571649568677198891486414476226932831825123576296441036124053704853315256369077062694497961110434..."
},
{
"input": "9923",
"output": "3760299283807515305392881669921685380087483626665387583310740045779392618490518061864438198412014466565364228291295311284131760183238506480296641521584717001189575119537493891940454933801650905249443352246953782854872613017048635048443614120554701976326536039594670095564945312513189153593550500517921950184962024588992584781239533465993501341159180970745350678104403343694528834994019085606787711931776684194936418570665879951352474415566347678136222813280481902061127946763865268688300550988394467968839427831..."
},
{
"input": "9941",
"output": "3848534499658219667049727329663074105337547166730018729906447543650907057565599099052599064685569838374730308744072576703962547115876952975258439787965733453851059665347937329225608515273601271650034928543860491219634012020498814661622840677950496926059282612940876829862296013101963794076610277533664472961283348371953697283523069103642217248197905842345904997732309684469494496541394358109215746512001993248263898375663673449385592381926788206401567212276907962968353724108187030299614264372186122509235461661..."
},
{
"input": "9949",
"output": "3077194576897431282984928614971803243979867746742349396701033435828399498432602651550466130139454008014151230282733882472359320178948173983098259522962570058314958623895543103765377873930945767189012935127692368514283490255979891724625021542152152743761996609145171758487359833408232379642800156557718632212879833607371512214716299467380836645557808645986902660996771461355482482475905883289978390754379236092379144196172866264243566348794250784667125654370098361595124994920872496780086986738805458903185126030..."
},
{
"input": "9991",
"output": "6382125632197575640171909108366323999672572433833222272392411654952806480364944179628596547334889065794512754663260535014179926913634410060297543083266944529654281991142775738499030710183320227853166673816892482763220210176769895648821886542105816/436994993873214129706097166956708350993678881411295357199729151951767944417616335439228580716318181998128654620651240845861768505204366709906692902245553277900892247131030458103436298545516643924637451297481464347472084863384057367177715867713535"
},
{
"input": "9992",
"output": "882713207347291313029281/60446290980731458735309"
},
{
"input": "9993",
"output": "12637244675354581352253260560857374/865382809755804604755082721536683"
},
{
"input": "9994",
"output": "3281117414508879498426129146296635638706673857559146714758804687655977321336441892014774756310161571021964653093136031059973674988535235552194295743721563055893425769046817776696216427896857321525164709814889404834572227298884316348149960471145881924249349826195785903333523568245055998853462086046866400139120072781311401680748431799894049040989328677849586317964939112513229643421712863477114408475285877161526889717094721450283390765651073229738491488236723709404792790505935059388430226031866694290751309103..."
},
{
"input": "9995",
"output": "1368770541403820619075110203708490210616145992745821521870208914365828115565556194877572535511077690510688277376757546565243584175363368143317667278940670502781186329534839008398699279841764334491329910860701074569229951248069967340109056226002539889667430100999595433067983400778886042165596127864919572486395941238704720403024794261441096255620000217687954366591408789194462597191661175824028310400352/93746319107175952683864071964918454730461746778024627464635174121600584812748548703282543376385452193806936..."
},
{
"input": "9996",
"output": "2016420396858486097238844042485568452071214924046/138111634978483258420134114867245645268334710595"
},
{
"input": "9997",
"output": "115045178372494165897872226686512107429178048300340407805913417043457084371526821355671616896548808082243735275331446/7880401239278895842455808020028722761015947854093089333589658680849144354299442122282853250976983128161325598061363"
},
{
"input": "9998",
"output": "4285402091468445389426164244750423198106729816197961669529078982307315890678968433526215498100171962888335447/293567822846729153486185074598667128421960318613539983838411371441526128139326055432962374798096087878991871"
},
{
"input": "9999",
"output": "396504919788033353440140876437127916065460257739670266843919813860579129943101204509709504/27160479684459814483579275845458375480686245248879150008481872658058417330177822749111965"
},
{
"input": "10000",
"output": "211285126026764324876224334024814529251789998319439411297242149907456038558/14474011154664524427946373126085988481658748083205070504932198000989141205"
}
] | 30 | 0 | 0 | 3,887 |
237 | Build String | [
"flows",
"graphs"
] | null | null | You desperately need to build some string *t*. For that you've got *n* more strings *s*1,<=*s*2,<=...,<=*s**n*. To build string *t*, you are allowed to perform exactly |*t*| (|*t*| is the length of string *t*) operations on these strings. Each operation looks like that:
1. choose any non-empty string from strings *s*1,<=*s*2,<=...,<=*s**n*; 1. choose an arbitrary character from the chosen string and write it on a piece of paper; 1. remove the chosen character from the chosen string.
Note that after you perform the described operation, the total number of characters in strings *s*1,<=*s*2,<=...,<=*s**n* decreases by 1. We are assumed to build string *t*, if the characters, written on the piece of paper, in the order of performed operations form string *t*.
There are other limitations, though. For each string *s**i* you know number *a**i* β the maximum number of characters you are allowed to delete from string *s**i*. You also know that each operation that results in deleting a character from string *s**i*, costs *i* rubles. That is, an operation on string *s*1 is the cheapest (it costs 1 ruble), and the operation on string *s**n* is the most expensive one (it costs *n* rubles).
Your task is to count the minimum amount of money (in rubles) you will need to build string *t* by the given rules. Consider the cost of building string *t* to be the sum of prices of the operations you use. | The first line of the input contains string *t* β the string that you need to build.
The second line contains a single integer *n* (1<=β€<=*n*<=β€<=100) β the number of strings to which you are allowed to apply the described operation. Each of the next *n* lines contains a string and an integer. The *i*-th line contains space-separated string *s**i* and integer *a**i* (0<=β€<=*a**i*<=β€<=100). Number *a**i* represents the maximum number of characters that can be deleted from string *s**i*.
All strings in the input only consist of lowercase English letters. All strings are non-empty. The lengths of all strings do not exceed 100 characters. | Print a single number β the minimum money (in rubles) you need in order to build string *t*. If there is no solution, print -1. | [
"bbaze\n3\nbzb 2\naeb 3\nba 10\n",
"abacaba\n4\naba 2\nbcc 1\ncaa 2\nbbb 5\n",
"xyz\n4\naxx 8\nza 1\nefg 4\nt 1\n"
] | [
"8\n",
"18\n",
"-1\n"
] | Notes to the samples:
In the first sample from the first string you should take characters "b" and "z" with price 1 ruble, from the second string characters "a", "e" ΠΈ "b" with price 2 rubles. The price of the string *t* in this case is 2Β·1β+β3Β·2β=β8.
In the second sample from the first string you should take two characters "a" with price 1 ruble, from the second string character "c" with price 2 rubles, from the third string two characters "a" with price 3 rubles, from the fourth string two characters "b" with price 4 rubles. The price of the string *t* in this case is 2Β·1β+β1Β·2β+β2Β·3β+β2Β·4β=β18.
In the third sample the solution doesn't exist because there is no character "y" in given strings. | [
{
"input": "bbaze\n3\nbzb 2\naeb 3\nba 10",
"output": "8"
},
{
"input": "abacaba\n4\naba 2\nbcc 1\ncaa 2\nbbb 5",
"output": "18"
},
{
"input": "xyz\n4\naxx 8\nza 1\nefg 4\nt 1",
"output": "-1"
},
{
"input": "aaabbtttefg\n6\nabbbca 3\nffatgg 2\nyioa 4\nppaeg 2\naetgffff 4\ntreiiaav 10",
"output": "34"
},
{
"input": "tatarioispoe\n5\ntyfad 3\npopsia 10\ntszza 3\nioioioio 4\nrarartteea 3",
"output": "33"
},
{
"input": "abcdabcd\n4\nabc 10\nab 3\nefg 3\nsahdjqwegadjhgasddddd 5",
"output": "-1"
},
{
"input": "jnwjjnj\n5\njwjj 10\nw 3\njn 8\nnnjnnjw 0\nnjn 4",
"output": "15"
},
{
"input": "jjrrj\n10\nrrr 1\njjr 1\nrjjj 2\nrjr 1\njjj 2\njj 0\njjr 1\nr 0\nj 3\nrj 4",
"output": "13"
},
{
"input": "ttkdddjffp\n10\npjpeds 10\nsikkj 3\ni 0\nbie 4\nttbk 7\nsdbtiijb 2\nss 3\nebjt 10\np 8\nsfeppt 9",
"output": "-1"
},
{
"input": "twjlurqzfgayvrtpxhim\n30\ndwrvsqel 5\nvynx 3\nztsffsqw 6\ntxbdos 8\njahla 9\nk 6\np 5\ntqkrooxqtu 0\ntnpgcoxs 10\neuvxbsm 4\nnrbhmh 9\nii 4\nqmqsndmcvg 9\nhdtj 10\nnukhd 9\nqcknuopm 3\nolzxz 8\njt 5\nvtjlfqrjmb 6\nlevduxh 6\nde 7\nbxctx 5\nsocuozifj 1\nyvvd 3\nq 1\nbrmjhasvjk 6\nj 7\ntemzqxb 3\npxpi 6\nxegdemdgzi 6",
"output": "96"
},
{
"input": "vwwvwwvwvwwv\n50\nwwvww 2\nwvv 0\nwvvv 1\nvww 5\nvv 4\nw 0\nv 6\nwvvwvv 6\nwwv 1\nvvvw 0\nvvv 1\nvvvvv 3\nvv 5\nvvvvww 4\nwwvwwv 1\nwwwvvw 2\nwvwww 4\nww 5\nwvvw 4\nww 3\nvvvv 6\nwwwvv 4\nvwvw 6\nv 0\nwvvwvv 3\nvv 0\nww 2\nvv 6\nwvvw 3\nw 6\nwwvwwv 0\nvwww 5\nwwvw 3\nw 5\nvw 4\nwv 2\nwvvvwv 6\nwvwwvw 3\nwwwwww 6\nvvvwww 6\nvvv 6\nwwvw 0\nvwwvw 3\nw 4\nvv 3\nwvvwvv 6\nvvwwv 5\nvv 6\nvww 5\nv 5",
"output": "58"
},
{
"input": "gjvloevyfiwysrzapfyyh\n3\nt 1\nr 0\nc 0",
"output": "-1"
},
{
"input": "z\n5\ng 9\nkfpocdpy 5\nblrxt 10\ndsxgcf 6\nyiasu 1",
"output": "-1"
},
{
"input": "ffbj\n10\nyzzyu 10\njaujvabz 9\nuqvbqyazcz 10\nzzbcq 3\nvzczjja 1\nbjbquzz 3\naf 8\nvj 6\nzbjbaucj 3\nqucafqq 8",
"output": "21"
},
{
"input": "pmjafkxnjsmhebnmdmbm\n5\nennerpkefuisnbwiupwripixpwbjhamkumbbeifsxsbpaofbpkfzyzanybp 76\nkrzefdpni 82\noybmamibkknobxxeaodeapwozirddjrdbroskfadzsxmepdoembuapemniuhjwsp 84\nwxzxadinxubeeoumszozxnexnxhynhfsxwmojhyzjzpounfkximnohrxsapjmkjhxfaymzu 90\nozfsdprykiuusajddxzemxrxsxmrfhnjyfyyisuuorxkpmoeupfxbhufraiyahxunukmhkeuaakbhwp 35",
"output": "29"
},
{
"input": "bhtqhbqttnnnhnbnqbqnbhqqhnhbqhqhthhhttnbbhbnqtqbqnntnnqthhtt\n20\nhbnh 3\nbtnn 5\nttq 0\nbhnh 2\nqntqt 1\nhnbb 0\nhq 0\nqtnbn 4\nh 0\nt 0\nbq 3\nbh 0\ntqqnn 3\nqbnh 0\nntbt 1\nnbb 1\nnqnnn 3\nqh 1\nhqn 3\nn 3",
"output": "-1"
},
{
"input": "zzttfhudetfskeekfkkuffsdbpdbuttcsrjdbsfdfodopuhzcfkubospmrsoeohmbbjmsbfe\n10\ncmod 2\nub 5\nssbzfj 0\nce 1\nzdz 2\nfm 0\ndz 3\njsd 5\nssjpjtf 3\nrbur 4",
"output": "-1"
},
{
"input": "wwhiwjwwihxxxjhxxxxwjxjijhjjhwhhjixxhxjjixxxjiwiwxh\n1\nijwii 86",
"output": "-1"
},
{
"input": "upumummuumpmumumupppp\n10\np 3\np 1\nu 1\nu 3\nupm 1\num 1\npu 0\nm 1\nm 1\nmum 0",
"output": "-1"
},
{
"input": "wvokxtxxeh\n40\nvjf 4\nxxh 4\nzdh 0\nkzk 4\nhgpeb 1\njee 3\nllg 4\nyr 4\nulmbi 4\nt 4\njjg 0\nn 1\nnf 5\nrd 0\nm 1\ntaacp 2\nt 4\nirnf 1\nq 1\nqadr 1\nggis 0\nllo 2\npng 3\nxu 2\njha 1\njyik 2\ncx 3\nhdey 0\nxhh 4\nh 4\nu 5\nv 3\nx 1\ngzy 0\nvwz 2\nm 3\ncvgst 0\npevwn 0\nxkt 3\nuuj 5",
"output": "107"
},
{
"input": "jdnpjbbeenepebwudwujwppdppbjepenwb\n50\ndu 2\nnjdp 4\np 3\nj 1\nebnb 5\ndu 1\nup 1\nb 2\nujn 1\nednun 2\nepd 2\nwuune 3\nwdjbb 2\njwpn 2\nw 5\nuw 1\njjund 1\nuwwen 2\nedwjn 4\nu 1\nep 1\nuudpd 4\nue 5\nju 4\nej 2\nwew 3\nbb 2\nddwuj 2\npnu 5\njwnn 4\nwnb 0\nnjuu 1\ndne 1\newbwb 4\nejpjb 0\nn 0\nn 2\njdnn 0\nbwwj 5\nuw 1\nwddnu 4\njbe 2\nj 0\nu 0\nn 2\njwj 1\nwnpn 5\nne 3\nwdeb 2\nu 5",
"output": "327"
},
{
"input": "loqlqshq\n29\ngsgqlass 9\naoqglllh 3\ngqqqgo 1\nqoqnou 3\nhsuaquunus 1\nqghlnunl 0\ngsahq 3\nqouqogasa 2\nllu 0\nh 1\nlghl 1\nl 7\nhhoahn 1\naoghqhaau 10\nnso 2\ngaul 1\nnaagonusln 5\naagooa 9\naaqnlgnsqs 10\nql 7\nnuuooqlq 9\nuq 5\nlhslnha 1\noslglosuah 7\nglqulguooo 8\nnguoaouqu 8\naqohshaq 3\noounho 6\nnnh 7",
"output": "16"
},
{
"input": "d\n100\nq 0\nj 0\nl 1\nn 1\nv 0\nx 1\nj 1\np 1\nb 1\nv 1\nu 1\ng 0\nk 1\nu 1\nc 1\nj 0\nd 1\nc 0\nv 1\nv 0\nu 1\nq 0\nf 0\ni 0\nn 1\nd 1\nh 1\ni 1\nj 1\ns 0\ni 0\nx 0\nb 0\nc 1\np 0\np 1\no 1\nc 1\nn 1\nf 0\no 0\nx 0\nu 0\ni 0\ng 0\ni 1\nl 0\np 0\nl 1\nl 1\nn 0\nq 1\nn 1\ng 1\nd 0\nb 0\nl 1\ni 1\nv 0\nl 1\nf 0\nx 0\nf 0\no 0\nl 1\ny 0\nc 0\nj 0\nx 1\no 0\nj 0\nn 1\nx 1\nq 0\ny 0\nu 0\nu 0\nd 1\nk 0\nv 1\nd 0\nk 0\ni 0\nv 0\ns 0\nx 0\np 1\nh 1\nq 1\ny 0\nb 1\nn 0\nj 1\nl 0\ni 1\nc 1\ng 1\nj 1\nq 0\nj 0",
"output": "17"
},
{
"input": "xxwxxxxppwpxwpxwppxppwwwwwppxpw\n37\nwpwpx 2\nxp 0\nppx 1\npx 5\nppww 5\nxp 2\npxp 3\nwxppp 1\nw 2\npwx 5\npwwp 5\nxxxwp 4\npp 2\npwx 3\npxxw 4\nwwxp 0\np 4\np 3\nxw 4\nx 4\nwxxxp 4\nxxx 1\nwxw 2\np 4\np 2\nxww 2\npwx 4\nwpp 2\nxw 4\nxpxp 4\nw 4\nwwpw 2\nwpw 2\nxwwpx 5\nwxw 2\nwpx 5\npwpxx 4",
"output": "259"
},
{
"input": "tkwkxtvwvtekejkwlwmtxvjxexlxlkmtjxklvjlekljxwleewmxekwtwexvjjwmwjmvjwmeetwjvw\n33\njmwexm 9\nmlvl 11\nltkmvjlvkmtxl 1\njwe 4\nllmkxewtkxkk 2\nveeewmjjlw 0\nexmtwwxkw 8\nexjklmvkkejwx 13\nmmjwkmemwwm 0\ntxetttxe 9\ne 9\nmw 7\nmkmt 3\nwk 0\nmvltketkvww 6\nj 5\nmjmemtjew 11\nvwmmvvlvljvtv 0\nttvx 11\njkmwwkkl 1\nxkvvel 9\neljwejjjwjj 3\ntmjlwx 0\nktvvkmjvkkx 4\net 10\ne 13\nkljxemllkmj 12\nwmmkell 8\nwm 1\nxm 9\nwjj 5\ntmm 6\nelw 6",
"output": "838"
},
{
"input": "clegxixgziecxzcsgexcglsxccszzlzggzellxseiselcsexsszxxx\n21\nc 9\nsxiixzgelcsxx 1\nzlllllzlllgzlixgxl 22\neslxese 0\ncxszxzgclcgecieixsleee 6\nxxecxilceisscisxecigez 12\niceissizceizsze 1\ngzxigs 14\neixsligzsli 22\neceeeizzsezzzee 15\nselgxs 18\nzseggxgcczcxzgcxi 21\neixixslllgzc 18\ngiceicezzxgcgsigsxgxx 16\nxlsseeslzg 11\nzxgil 9\negczii 1\nxzexscgggl 6\nllegxggsleezcggeieis 17\nieeliesell 7\nxsxlsxsxcicce 6",
"output": "325"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\n26\na 2\nb 8\nc 5\nd 1\ne 10\nf 5\ng 9\nh 9\ni 3\nj 5\nk 6\nl 6\nm 2\nn 8\no 2\np 2\nq 6\nr 3\ns 8\nt 7\nu 2\nv 5\nw 3\nx 4\ny 3\nz 3",
"output": "351"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\n26\na 2\nb 8\nc 5\nd 1\ne 10\nf 5\ng 9\nh 9\ni 3\nj 5\nk 6\nl 6\nm 2\nn 8\no 2\np 2\nq 6\nr 3\ns 8\nt 7\nu 2\nv 5\nw 3\nx 4\ny 3\nz 3",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 100",
"output": "100"
},
{
"input": "abc\n10\nabc 2\nb 1\nd 1\nd 1\nd 1\nd 1\nd 1\nd 1\nd 1\nc 1",
"output": "4"
},
{
"input": "a\n1\na 0",
"output": "-1"
}
] | 92 | 0 | 0 | 3,892 |
|
982 | Billiard | [
"geometry",
"number theory"
] | null | null | Consider a [billiard table](https://en.wikipedia.org/wiki/Billiard_table) of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture).
There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $45^{\circ}$ angle with them. We will assume that:
1. the angles between the directions of the ball before and after a collision with a side are equal, 1. the ball moves indefinitely long, it only stops when it falls into a pocket, 1. the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets, 1. initially the ball is not in a pocket.
Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side.
Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be. | The only line contains $6$ integers $n$, $m$, $x$, $y$, $v_x$, $v_y$ ($1 \leq n, m \leq 10^9$, $0 \leq x \leq n$; $0 \leq y \leq m$; $-1 \leq v_x, v_y \leq 1$; $(v_x, v_y) \neq (0, 0)$)Β β the width of the table, the length of the table, the $x$-coordinate of the initial position of the ball, the $y$-coordinate of the initial position of the ball, the $x$-component of its initial speed and the $y$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket. | Print the coordinates of the pocket the ball will fall into, or $-1$ if the ball will move indefinitely. | [
"4 3 2 2 -1 1\n",
"4 4 2 0 1 1\n",
"10 10 10 1 -1 0\n"
] | [
"0 0",
"-1",
"-1"
] | The first sample:
The second sample:
In the third sample the ball will never change its $y$ coordinate, so the ball will never fall into a pocket. | [
{
"input": "4 3 2 2 -1 1",
"output": "0 0"
},
{
"input": "4 4 2 0 1 1",
"output": "-1"
},
{
"input": "10 10 10 1 -1 0",
"output": "-1"
},
{
"input": "1000000000 1000000000 1 1000000000 0 1",
"output": "-1"
},
{
"input": "2 1 1 0 -1 -1",
"output": "0 1"
},
{
"input": "4 2 1 2 1 1",
"output": "-1"
},
{
"input": "5 3 4 3 1 -1",
"output": "0 3"
},
{
"input": "15 9 1 1 1 1",
"output": "15 9"
},
{
"input": "15 9 1 1 -1 -1",
"output": "0 0"
},
{
"input": "15 9 2 1 1 1",
"output": "-1"
},
{
"input": "15 9 2 1 -1 1",
"output": "15 0"
},
{
"input": "1000000000 999999999 999999998 999999999 -1 -1",
"output": "1000000000 999999999"
},
{
"input": "1000000000 999999999 999999998 999999999 -1 1",
"output": "1000000000 999999999"
},
{
"input": "15 9 3 2 1 1",
"output": "-1"
},
{
"input": "15 9 3 2 1 -1",
"output": "-1"
},
{
"input": "4 4 0 1 0 1",
"output": "0 4"
},
{
"input": "4 4 4 2 0 -1",
"output": "4 0"
},
{
"input": "1000000000 999999999 999999999 999999999 1 1",
"output": "1000000000 0"
},
{
"input": "1000000000 999999999 999999998 999999999 1 1",
"output": "0 999999999"
},
{
"input": "1000000000 999999999 999999998 999999999 1 -1",
"output": "0 999999999"
},
{
"input": "1000000000 999999999 999999998 999999999 0 1",
"output": "-1"
},
{
"input": "1000000000 999999999 999999998 999999999 -1 0",
"output": "0 999999999"
},
{
"input": "1 99 0 16 -1 1",
"output": "1 99"
},
{
"input": "6 8 1 1 1 1",
"output": "0 8"
},
{
"input": "6 10 1 1 1 1",
"output": "6 10"
},
{
"input": "8 6 7 1 -1 1",
"output": "0 0"
},
{
"input": "10009 10007 1 1 1 1",
"output": "10009 10007"
},
{
"input": "10007 10009 10006 10008 -1 -1",
"output": "0 0"
},
{
"input": "1000 999 1 998 1 -1",
"output": "1000 999"
},
{
"input": "500 500 250 250 -1 1",
"output": "0 500"
},
{
"input": "2705444 415131525 949293 337120042 1 -1",
"output": "2705444 415131525"
},
{
"input": "603278410 844534002 499505824 32181172 1 -1",
"output": "603278410 844534002"
},
{
"input": "316347709 122791181 255721626 19148895 -1 1",
"output": "316347709 0"
},
{
"input": "226591495 303844168 64300938 148467902 -1 -1",
"output": "0 303844168"
},
{
"input": "682138812 116415655 516825996 73682791 -1 1",
"output": "0 116415655"
},
{
"input": "305675046 505376350 144451750 295580797 -1 1",
"output": "-1"
},
{
"input": "313157692 571680270 238352863 235464142 1 -1",
"output": "-1"
},
{
"input": "120717601 973035857 103171773 511250918 -1 1",
"output": "120717601 0"
},
{
"input": "41373770 597127671 31867608 404367855 -1 1",
"output": "41373770 597127671"
},
{
"input": "827285013 307724101 775951207 175683367 -1 -1",
"output": "827285013 307724101"
},
{
"input": "110474424 613900860 31471099 442410471 -1 1",
"output": "-1"
},
{
"input": "84035810 39157280 10865763 24269978 1 -1",
"output": "-1"
},
{
"input": "75744115 329085002 22395692 81831548 -1 1",
"output": "0 0"
},
{
"input": "20597226 82154419 5899110 71189386 1 1",
"output": "0 0"
},
{
"input": "550269655 264187669 141601786 53516425 1 -1",
"output": "550269655 0"
},
{
"input": "224819588 978615384 68538326 805268586 1 1",
"output": "224819588 978615384"
},
{
"input": "979444430 110858783 607921615 88320790 1 -1",
"output": "979444430 110858783"
},
{
"input": "853950494 911554949 428001551 108479491 1 1",
"output": "853950494 0"
},
{
"input": "810387002 412176212 187695958 236085023 1 1",
"output": "-1"
},
{
"input": "20877471 722211317 8457280 75966699 -1 -1",
"output": "0 722211317"
},
{
"input": "542708351 3475408 103232934 399149 1 1",
"output": "542708351 3475408"
},
{
"input": "30609041 976052297 4229728 158676967 -1 1",
"output": "30609041 0"
},
{
"input": "495082283 937762241 250777046 412284609 1 1",
"output": "495082283 0"
},
{
"input": "68076815 985943633 40657983 165191148 1 -1",
"output": "0 985943633"
},
{
"input": "209408006 202717192 115684862 96677080 -1 -1",
"output": "209408006 202717192"
},
{
"input": "651520659 433737829 645844796 133999548 1 -1",
"output": "0 0"
},
{
"input": "835624982 341676615 379293679 54053933 1 -1",
"output": "835624982 0"
},
{
"input": "943609111 405753192 556398014 348647907 1 -1",
"output": "943609111 0"
},
{
"input": "590709848 332238455 546245223 240305069 -1 1",
"output": "0 0"
},
{
"input": "320049957 92820858 176731509 15650804 1 1",
"output": "-1"
},
{
"input": "233140029 827954502 99465884 170396111 1 1",
"output": "233140029 827954502"
},
{
"input": "760904646 962606170 641547160 113696561 -1 1",
"output": "-1"
},
{
"input": "584801838 775270595 121061956 644380885 -1 1",
"output": "0 775270595"
},
{
"input": "141190266 126518281 76515989 109124404 1 1",
"output": "0 126518281"
},
{
"input": "225067174 487662889 175063389 447988824 1 1",
"output": "225067174 487662889"
},
{
"input": "814170008 703690544 6953086 439080555 -1 1",
"output": "-1"
},
{
"input": "12671644 216092609 3707378 92213588 1 1",
"output": "12671644 0"
},
{
"input": "686521539 766868053 668178904 36804229 1 1",
"output": "686521539 0"
},
{
"input": "43760214 59779641 32562470 43565961 -1 1",
"output": "-1"
},
{
"input": "281776735 833828834 271604381 491447288 -1 1",
"output": "281776735 833828834"
},
{
"input": "362762211 732244195 63812822 258610562 -1 1",
"output": "362762211 732244195"
},
{
"input": "312319019 933972106 103989975 544805243 1 -1",
"output": "0 0"
},
{
"input": "142096067 231234738 40134344 206132422 -1 1",
"output": "0 231234738"
},
{
"input": "289285219 692430999 249276742 628721059 1 -1",
"output": "0 692430999"
},
{
"input": "490696330 492707826 183410939 115542637 -1 -1",
"output": "490696330 0"
},
{
"input": "916524063 555774494 499847875 268662592 -1 1",
"output": "916524063 555774494"
},
{
"input": "101123973 722433301 46988094 586973439 -1 1",
"output": "101123973 0"
},
{
"input": "808357574 854008109 9323335 342356143 -1 -1",
"output": "0 0"
},
{
"input": "257447593 468889343 162885112 15431794 1 1",
"output": "-1"
},
{
"input": "688226257 305863798 134250684 285725084 -1 -1",
"output": "0 305863798"
},
{
"input": "836255310 741706431 648685681 396741892 1 -1",
"output": "-1"
},
{
"input": "480678700 670120443 423401724 177051387 1 1",
"output": "480678700 670120443"
},
{
"input": "35550087 590484118 10858303 37118846 1 1",
"output": "35550087 590484118"
},
{
"input": "491475453 334831307 136826756 228553610 1 -1",
"output": "491475453 334831307"
},
{
"input": "172057628 368934073 117631597 83410362 1 1",
"output": "172057628 368934073"
},
{
"input": "611927194 869083092 295778083 541333563 -1 -1",
"output": "0 869083092"
},
{
"input": "329666407 901295668 90510437 485008861 1 -1",
"output": "-1"
},
{
"input": "978089453 426264909 388420346 53798427 -1 1",
"output": "0 426264909"
},
{
"input": "242449067 548221648 24810672 63078584 1 1",
"output": "0 548221648"
},
{
"input": "583053442 353408 240939980 17207 -1 1",
"output": "-1"
},
{
"input": "10 9 8 9 -1 1",
"output": "10 9"
},
{
"input": "999999997 999999999 500 500 -1 1",
"output": "0 0"
},
{
"input": "1000000000 1000000000 999 100 -1 -1",
"output": "-1"
},
{
"input": "7 5 2 3 1 0",
"output": "-1"
},
{
"input": "11 13 5 7 -1 -1",
"output": "0 0"
},
{
"input": "500 1000 200 200 1 1",
"output": "0 1000"
},
{
"input": "500 995 1 1 1 1",
"output": "500 0"
},
{
"input": "1 100 0 1 1 1",
"output": "1 100"
},
{
"input": "1 100 0 1 1 0",
"output": "-1"
},
{
"input": "999999999 999999998 2 3 -1 1",
"output": "999999999 0"
},
{
"input": "500000000 499999999 499999999 499999999 1 1",
"output": "500000000 0"
}
] | 78 | 307,200 | 0 | 3,901 |
|
156 | Message | [
"brute force"
] | null | null | Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string *s*.
String *p* is called a substring of string *s* if you can read it starting from some position in the string *s*. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba".
Dr. Moriarty plans to take string *s* and cut out some substring from it, let's call it *t*. Then he needs to change the substring *t* zero or more times. As a result, he should obtain a fixed string *u* (which is the string that should be sent to Sherlock Holmes). One change is defined as making one of the following actions:
- Insert one letter to any end of the string. - Delete one letter from any end of the string. - Change one letter into any other one.
Moriarty is very smart and after he chooses some substring *t*, he always makes the minimal number of changes to obtain *u*.
Help Moriarty choose the best substring *t* from all substrings of the string *s*. The substring *t* should minimize the number of changes Moriarty should make to obtain the string *u* from it. | The first line contains a non-empty string *s*, consisting of lowercase Latin letters. The second line contains a non-empty string *u*, consisting of lowercase Latin letters. The lengths of both strings are in the range from 1 to 2000, inclusive. | Print the only integer β the minimum number of changes that Dr. Moriarty has to make with the string that you choose. | [
"aaaaa\naaa\n",
"abcabc\nbcd\n",
"abcdef\nklmnopq\n"
] | [
"0\n",
"1\n",
"7\n"
] | In the first sample Moriarty can take any substring of length 3, and it will be equal to the required message *u*, so Moriarty won't have to make any changes.
In the second sample you should take a substring consisting of characters from second to fourth ("bca") or from fifth to sixth ("bc"). Then you will only have to make one change: to change or to add the last character.
In the third sample the initial string *s* doesn't contain any character that the message should contain, so, whatever string you choose, you will have to make at least 7 changes to obtain the required message. | [
{
"input": "aaaaa\naaa",
"output": "0"
},
{
"input": "abcabc\nbcd",
"output": "1"
},
{
"input": "abcdef\nklmnopq",
"output": "7"
},
{
"input": "aaabbbaaa\naba",
"output": "1"
},
{
"input": "a\na",
"output": "0"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "a\nz",
"output": "1"
},
{
"input": "d\nt",
"output": "1"
},
{
"input": "o\nu",
"output": "1"
},
{
"input": "a\nm",
"output": "1"
},
{
"input": "t\nv",
"output": "1"
},
{
"input": "n\ng",
"output": "1"
},
{
"input": "c\nh",
"output": "1"
},
{
"input": "r\ni",
"output": "1"
},
{
"input": "h\nb",
"output": "1"
},
{
"input": "r\na",
"output": "1"
},
{
"input": "c\np",
"output": "1"
},
{
"input": "wbdbzf\nfpvlerhsuf",
"output": "9"
},
{
"input": "zafsqbsu\nhl",
"output": "2"
},
{
"input": "juhlp\nycqugugk",
"output": "7"
},
{
"input": "ladfasxt\ncpvtd",
"output": "4"
},
{
"input": "ally\ncjidwuj",
"output": "7"
},
{
"input": "rgug\npgqwslo",
"output": "6"
},
{
"input": "wmjwu\nrfew",
"output": "3"
},
{
"input": "cpnwcdqff\nq",
"output": "0"
},
{
"input": "dkwh\nm",
"output": "1"
},
{
"input": "zfinrlju\nwiiegborjl",
"output": "9"
},
{
"input": "swconajiqpgziitbpwjsfcalqvmwbfed\nridfnsyumichlhpnurrnwkyjcdzchznpmno",
"output": "32"
},
{
"input": "vfjofvgkdwgqdlomtmcvedtmimdnxavhfirienxfdflldkbwjsynablhdvgaipvcghgaxipotwmmlzxekipgbvpfivlgzfwqz\njkdfjnessjfgcqpnxgtqdxtqimolbdlnipkoqht",
"output": "34"
},
{
"input": "dtvxepnxfkzcaoh\nkpdzbtwjitzlyzvsbwcsrfglaycrhzwsdtidrelndsq",
"output": "41"
},
{
"input": "sweaucynwsnduofyaqunoxttbipgrbfpssplfp\nuifmuxmczznobefdsyoclwzekewxmcwfqryuevnxxlgxsuhoytkaddorbdaygo",
"output": "57"
},
{
"input": "eohztfsxoyhirnzxgwaevfqstinlxeiyywmpmlbedkjihaxfdtsocof\nbloqrjbidxiqozvwregxxgmxuqcvhwzhytfckbafd",
"output": "37"
},
{
"input": "ybshzefoxkqdigcjafs\nnffvaxdmditsolfxbyquira",
"output": "19"
},
{
"input": "ytfqnuhqzbjjheejjbzcaorilcyvuxvviaiba\nxnhgkdfceialuujgcxmrhjbzvibcoknofafmdjnhij",
"output": "37"
},
{
"input": "ibdjtvgaveujdyidqldrxgwhsammmfpgxwljkptmeyejdvudhctmqjazalyzmzfgebetyqncu\nercdngwctdarcennbuqhsjlwfwrcqjbcjxqftycoulrhrimwhznogjmrrqdygtmllottpjgmkndraearezvxxmdhcuokhyngu",
"output": "90"
},
{
"input": "bwhvaanyxupicwobeevcwewhcriwowfovnylalpuhxzqxtzyjrzlxcmejujvliomdfedgtaioauwrcluhfxtzu\nplinvtsvytepojsecnjisxlmqkfhgknitvuw",
"output": "28"
},
{
"input": "sjxykdmrzpescabubcjflhnpckgytklc\nsxirpuqnmjqhlnvdeyvxvzzcygkpsujyifzgzmtvxsimddjahiephqlgfzngrzjtcrgrimewsxipczsgu",
"output": "76"
},
{
"input": "ksmbytfyhhnstlecripupiwdhbkhfpfmimrbqgszohcqnezcybvwasxmkxfupvuecsctcpadccnqexsglwaiyxcoyheefcjmdedesgjqdtqgrvfjonzesffousooutsjumrxl\nhgjqihcfbnmgufonaiudbjegexexthrzcdkuimwogpbyovemztzcmqnrbhabxyyxyfuzpyhjgnioexbezzupcxlyzuuncstiiqsjzdtqppqhxilvqimlpjejiqbwpeekzweeyvthvjffgfvqauqrugajjjzibgzhxphcvtncjzecbtupwkehcrgsgfgkvwwnifglyamjkzfvabybsstwrwugnmiwflhemgnfbrtskzfxcepqhtelgiowzeuujpkuzsfsipcvtfoeshawvryaubilcbwukdhlwamsqenzvr",
"output": "287"
},
{
"input": "abcd\ndabc",
"output": "1"
},
{
"input": "medxx\nahmed",
"output": "2"
},
{
"input": "ab\ndab",
"output": "1"
},
{
"input": "nasldkfnsb\nyyyynasld",
"output": "4"
},
{
"input": "abcde\ncabc",
"output": "1"
},
{
"input": "a\nzzzzzzzzzza",
"output": "10"
},
{
"input": "abcde\nabde",
"output": "2"
},
{
"input": "bac\ntbdca",
"output": "3"
},
{
"input": "abcdef\nxyzabc",
"output": "3"
},
{
"input": "abcdef\nbctsf",
"output": "2"
},
{
"input": "xxxabaxxx\nxxxaaxxx",
"output": "2"
},
{
"input": "bcd\nabc",
"output": "1"
},
{
"input": "d\nabcdef",
"output": "5"
}
] | 342 | 2,048,000 | 3 | 3,903 |
|
191 | Dynasty Puzzles | [
"dp"
] | null | null | The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the king, whose name was Victorious Vasily Pupkin, was always called by the berlanders VVP.
In Berland over its long history many dynasties of kings replaced each other, but they were all united by common traditions. Thus, according to one Berland traditions, to maintain stability in the country, the first name of the heir should be the same as the last name his predecessor (hence, the first letter of the abbreviated name of the heir coincides with the last letter of the abbreviated name of the predecessor). Berlanders appreciate stability, so this tradition has never been broken. Also Berlanders like perfection, so another tradition requires that the first name of the first king in the dynasty coincides with the last name of the last king in this dynasty (hence, the first letter of the abbreviated name of the first king coincides with the last letter of the abbreviated name of the last king). This tradition, of course, has also been always observed.
The name of a dynasty is formed by very simple rules: we take all the short names of the kings in the order in which they ruled, and write them in one line. Thus, a dynasty of kings "ab" and "ba" is called "abba", and the dynasty, which had only the king "abca", is called "abca".
Vasya, a historian, has recently found a list of abbreviated names of all Berland kings and their relatives. Help Vasya to find the maximally long name of the dynasty that could have existed in Berland.
Note that in his list all the names are ordered by the time, that is, if name *A* is earlier in the list than *B*, then if *A* and *B* were kings, then king *A* ruled before king *B*. | The first line contains integer *n* (1<=β€<=*n*<=β€<=5Β·105) β the number of names in Vasya's list. Next *n* lines contain *n* abbreviated names, one per line. An abbreviated name is a non-empty sequence of lowercase Latin letters. Its length does not exceed 10 characters. | Print a single number β length of the sought dynasty's name in letters.
If Vasya's list is wrong and no dynasty can be found there, print a single number 0. | [
"3\nabc\nca\ncba\n",
"4\nvvp\nvvp\ndam\nvvp\n",
"3\nab\nc\ndef\n"
] | [
"6\n",
"0\n",
"1\n"
] | In the first sample two dynasties can exist: the one called "abcca" (with the first and second kings) and the one called "abccba" (with the first and third kings).
In the second sample there aren't acceptable dynasties.
The only dynasty in the third sample consists of one king, his name is "c". | [
{
"input": "3\nabc\nca\ncba",
"output": "6"
},
{
"input": "4\nvvp\nvvp\ndam\nvvp",
"output": "0"
},
{
"input": "3\nab\nc\ndef",
"output": "1"
},
{
"input": "5\nab\nbc\ncd\nde\nffffffffff",
"output": "10"
},
{
"input": "5\ncab\nbbc\ncaa\nccc\naca",
"output": "9"
},
{
"input": "10\nabdcced\nbdacdac\necb\ndc\neaeeebdd\nadcdbadcac\neb\naadecccde\nedbaeacad\naccd",
"output": "0"
},
{
"input": "50\nagecd\ncghafi\nfiide\niecc\njbdcfjhgd\ndiee\nhfeg\nehc\ngfijgjh\ngacaifebg\ndicbbddc\nhjgciaei\njjcdh\ng\ngc\ncf\nhfdjhd\nc\nicidbec\nji\neeh\ncgeejggc\nacfd\njjg\najefdj\neghhebiic\nbih\ngbb\njjaa\nidc\ngafi\necg\ndbigbjiehj\ncedif\nahidfaaajg\nhfhhiccbgb\ndgegjgieif\nhgjebhfdc\nj\nahehd\nahdah\nbijbhh\na\ndabiggfhac\ndedigbjbf\nihbdj\niihagchd\ngfebhfdi\njbjdcggdh\nf",
"output": "37"
},
{
"input": "10\na\nb\na\nc\nb\na\nb\na\na\na",
"output": "6"
},
{
"input": "100\nd\na\ne\neb\nc\nd\nd\ne\nc\ne\nac\nd\nc\naa\na\ne\nda\ne\ne\nc\ne\na\nc\nc\nbc\nbd\nd\nda\ncc\nbe\nb\na\nee\nd\nbe\nbe\ne\nb\na\ned\ncb\nab\na\nea\nac\naa\ned\nd\nb\neb\ne\ned\nc\nce\nc\nd\nc\nd\nd\nee\ne\nb\nea\nea\nda\nab\nba\ned\nda\nec\nea\nbd\nee\ndc\nd\nbd\nd\nc\ncc\nab\nbd\na\nad\ne\nd\ne\nbc\nbb\nc\nbc\na\na\ne\nca\nac\nc\nad\nc\nbe\nd",
"output": "35"
},
{
"input": "16\nddgcb\nfgbhgbdg\ngha\ndh\nddfb\nfggbc\nedb\nhd\nd\nhfgcabf\nhdaef\nfhbcdgba\nchee\ncafeggc\nf\necb",
"output": "7"
},
{
"input": "3\nab\nacb\nba",
"output": "5"
},
{
"input": "3\nac\nabc\nca",
"output": "5"
}
] | 2,000 | 29,388,800 | 0 | 3,908 |
|
952 | I'm Feeling Lucky! | [
"probabilities"
] | null | null | You have one chip and one chance to play roulette. Are you feeling lucky? | none | Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares). | [] | [] | none | [
{
"input": "1",
"output": "Red"
},
{
"input": "2",
"output": "Red"
}
] | 77 | 0 | 0 | 3,909 |
|
84 | Biathlon | [
"binary search",
"implementation"
] | C. Biathlon | 1 | 256 | Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section.
Of course, biathlon as any sport, proved very difficult in practice. It takes much time and effort. Workouts, workouts, and workouts, β that's what awaited Valera on his way to great achievements in biathlon.
As for the workouts, you all probably know that every professional biathlete should ski fast and shoot precisely at the shooting range. Only in this case you can hope to be successful, because running and shooting are the two main components of biathlon. Valera has been diligent in his ski trainings, which is why he runs really fast, however, his shooting accuracy is nothing to write home about.
On a biathlon base where Valera is preparing for the competition, there is a huge rifle range with *n* targets. Each target have shape of a circle, and the center of each circle is located on the *Ox* axis. At the last training session Valera made the total of *m* shots. To make monitoring of his own results easier for him, one rather well-known programmer (of course it is you) was commissioned to write a program that would reveal how many and which targets Valera hit. More specifically, for each target the program must print the number of the first successful shot (in the target), or "-1" if this was not hit. The target is considered hit if the shot is inside the circle or on its boundary. Valera is counting on you and perhaps, thanks to you he will one day win international competitions. | The first line of the input file contains the integer *n* (1<=β€<=*n*<=β€<=104), which is the number of targets. The next *n* lines contain descriptions of the targets. Each target is a circle whose center is located on the *Ox* axis. Each circle is given by its coordinate of the center *x* (<=-<=2Β·104<=β€<=*x*<=β€<=2Β·104) and its radius *r* (1<=β€<=*r*<=β€<=1000). It is guaranteed that no two targets coincide, intersect or are nested into each other, but they can touch each other.
The next line contains integer *m* (1<=β€<=*m*<=β€<=2Β·105), which is the number of shots. Next *m* lines contain descriptions of the shots, which are points on the plane, given by their coordinates *x* and *y* (<=-<=2Β·104<=β€<=*x*,<=*y*<=β€<=2Β·104).
All the numbers in the input are integers.
Targets and shots are numbered starting from one in the order of the input. | Print on the first line a single number, the number of targets hit by Valera. Print on the second line for each of the targets the number of its first hit or "-1" (without quotes) if this number does not exist. Separate numbers with spaces. | [
"3\n2 1\n5 2\n10 1\n5\n0 1\n1 3\n3 0\n4 0\n4 0\n",
"3\n3 2\n7 1\n11 2\n4\n2 1\n6 0\n6 4\n11 2\n"
] | [
"2\n3 3 -1 \n",
"3\n1 2 4 \n"
] | none | [
{
"input": "3\n2 1\n5 2\n10 1\n5\n0 1\n1 3\n3 0\n4 0\n4 0",
"output": "2\n3 3 -1 "
},
{
"input": "3\n3 2\n7 1\n11 2\n4\n2 1\n6 0\n6 4\n11 2",
"output": "3\n1 2 4 "
},
{
"input": "2\n0 5\n10 5\n2\n7 2\n6 1",
"output": "1\n-1 1 "
},
{
"input": "3\n-3 3\n-10 2\n10 2\n4\n10 2\n2 -2\n-11 -1\n10 0",
"output": "2\n-1 3 1 "
},
{
"input": "5\n3 2\n-1 2\n6 1\n-6 1\n20 5\n6\n1 -2\n5 0\n5 1\n1 0\n-4 0\n3 2",
"output": "3\n2 4 2 -1 -1 "
},
{
"input": "4\n2 1\n5 1\n-6 1\n10 2\n3\n-6 0\n-6 1\n-5 0",
"output": "1\n-1 -1 1 -1 "
},
{
"input": "2\n10 10\n-20 20\n4\n-1 6\n-1 -2\n21 0\n0 0",
"output": "2\n4 1 "
},
{
"input": "3\n6 2\n-2 2\n2 1\n5\n2 0\n5 1\n2 0\n2 1\n2 -3",
"output": "2\n2 -1 1 "
},
{
"input": "3\n1 1\n3 1\n-4 2\n1\n-4 -3",
"output": "0\n-1 -1 -1 "
},
{
"input": "10\n67 5\n-69 5\n-58 3\n-5 6\n27 2\n95 3\n36 2\n-82 2\n-18 6\n-33 4\n20\n-41 3\n-47 -2\n37 3\n29 -6\n90 -8\n-40 -4\n-46 0\n70 -6\n93 -9\n84 -6\n-66 -1\n-44 6\n37 -8\n-29 3\n39 -4\n-77 -3\n-21 4\n-70 7\n97 -6\n-61 -5",
"output": "2\n-1 11 -1 -1 -1 -1 -1 -1 17 -1 "
},
{
"input": "10\n57 5\n-59 5\n-28 3\n27 2\n46 2\n-48 6\n-3 2\n-21 2\n8 8\n-9 1\n30\n-26 3\n-29 9\n-66 -1\n-1 -9\n56 2\n-18 -9\n3 4\n-24 -12\n-33 -11\n44 0\n37 12\n-46 -11\n-25 0\n-41 -5\n-1 -1\n-27 7\n57 3\n35 4\n-1 -2\n-66 -3\n-60 12\n50 9\n58 10\n32 -1\n-64 -6\n48 3\n-21 -8\n28 0\n-67 8\n8 2",
"output": "5\n5 -1 13 28 10 -1 -1 -1 7 -1 "
},
{
"input": "15\n17 5\n-19 5\n-8 3\n27 2\n45 3\n36 2\n-32 2\n49 1\n-3 2\n-41 2\n-35 1\n-46 1\n-29 1\n33 1\n0 1\n50\n24 -4\n41 3\n37 3\n9 2\n38 -4\n-30 2\n-41 -5\n-9 -5\n-33 3\n0 2\n-20 -3\n-49 -4\n34 1\n-38 -2\n17 -1\n-33 3\n-17 4\n16 3\n-49 2\n-3 -4\n-9 2\n35 3\n37 -5\n0 0\n-46 -5\n48 1\n-22 -4\n-29 -5\n-41 4\n-11 0\n-5 -2\n-36 5\n42 0\n48 -3\n49 0\n-39 2\n-10 1\n38 3\n23 -1\n-35 -4\n7 -2\n4 5\n-29 0\n5 -1\n12 0\n-3 3\n46 1\n37 -1\n45 4\n-5 -4",
"output": "8\n15 11 21 -1 33 48 -1 35 -1 -1 -1 -1 43 -1 24 "
},
{
"input": "10\n2467 35\n-3169 25\n-5358 63\n-5705 46\n827 62\n2995 43\n5436 92\n-3902 54\n-4382 22\n-3718 96\n1\n5726 38",
"output": "0\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 "
},
{
"input": "1\n467 335\n10\n-169 -478\n-962 -705\n281 961\n995 -827\n-391 -902\n292 -421\n-718 447\n-771 -869\n-667 35\n-703 322",
"output": "0\n-1 "
},
{
"input": "2\n15000 1000\n-5000 1000\n2\n15000 0\n-5000 0",
"output": "2\n1 2 "
}
] | 623 | 27,340,800 | 3.637574 | 3,913 |
196 | Lexicographically Maximum Subsequence | [
"greedy",
"strings"
] | null | null | You've got string *s*, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*]<==<=*s**p*1*s**p*2... *s**p**k*(1<=β€<=*p*1<=<<=*p*2<=<<=...<=<<=*p**k*<=β€<=|*s*|) a subsequence of string *s*<==<=*s*1*s*2... *s*|*s*|.
String *x*<==<=*x*1*x*2... *x*|*x*| is lexicographically larger than string *y*<==<=*y*1*y*2... *y*|*y*|, if either |*x*|<=><=|*y*| and *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x*|*y*|<==<=*y*|*y*|, or exists such number *r* (*r*<=<<=|*x*|,<=*r*<=<<=|*y*|), that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**r*<==<=*y**r* and *x**r*<=+<=1<=><=*y**r*<=+<=1. Characters in lines are compared like their ASCII codes. | The single line contains a non-empty string *s*, consisting only of lowercase English letters. The string's length doesn't exceed 105. | Print the lexicographically maximum subsequence of string *s*. | [
"ababba\n",
"abbcbccacbbcbaaba\n"
] | [
"bbba\n",
"cccccbba\n"
] | Let's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).
The first sample: aBaBBA
The second sample: abbCbCCaCbbCBaaBA | [
{
"input": "ababba",
"output": "bbba"
},
{
"input": "abbcbccacbbcbaaba",
"output": "cccccbba"
},
{
"input": "thankstosamarasauteddybearsforthiscontest",
"output": "yttt"
},
{
"input": "cantouristsolveitlessthaninoneminute",
"output": "vute"
},
{
"input": "arepretestsstrongforthisproblem",
"output": "ttttsrom"
},
{
"input": "whyareyoulookingfortestsdoyouhavewa",
"output": "yyywa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "zz",
"output": "zz"
},
{
"input": "a",
"output": "a"
},
{
"input": "z",
"output": "z"
},
{
"input": "b",
"output": "b"
},
{
"input": "y",
"output": "y"
},
{
"input": "zaz",
"output": "zz"
},
{
"input": "aza",
"output": "za"
},
{
"input": "dcbaedcba",
"output": "edcba"
},
{
"input": "abcdeabcd",
"output": "ed"
},
{
"input": "abcdedcba",
"output": "edcba"
},
{
"input": "zyxzxzwyxywxxwabcdabdacdbcacdbcacabaaba",
"output": "zzzyyxxwddddccbba"
},
{
"input": "zzyzyy",
"output": "zzzyy"
},
{
"input": "aababb",
"output": "bbb"
}
] | 1,308 | 614,400 | 3 | 3,922 |
|
9 | Running Student | [
"brute force",
"geometry",
"implementation"
] | B. Running Student | 1 | 64 | And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direction of increasing *x*.
Poor Student knows the following:
- during one run the minibus makes *n* stops, the *i*-th stop is in point (*x**i*,<=0) - coordinates of all the stops are different - the minibus drives at a constant speed, equal to *v**b* - it can be assumed the passengers get on and off the minibus at a bus stop momentarily - Student can get off the minibus only at a bus stop - Student will have to get off the minibus at a terminal stop, if he does not get off earlier - the University, where the exam will be held, is in point (*x**u*,<=*y**u*) - Student can run from a bus stop to the University at a constant speed *v**s* as long as needed - a distance between two points can be calculated according to the following formula: - Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University. | The first line contains three integer numbers: 2<=β€<=*n*<=β€<=100, 1<=β€<=*v**b*,<=*v**s*<=β€<=1000. The second line contains *n* non-negative integers in ascending order: coordinates *x**i* of the bus stop with index *i*. It is guaranteed that *x*1 equals to zero, and *x**n*<=β€<=105. The third line contains the coordinates of the University, integers *x**u* and *y**u*, not exceeding 105 in absolute value. | In the only line output the answer to the problem β index of the optimum bus stop. | [
"4 5 2\n0 2 4 6\n4 1\n",
"2 1 1\n0 100000\n100000 100000\n"
] | [
"3",
"2"
] | As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus. | [
{
"input": "4 5 2\n0 2 4 6\n4 1",
"output": "3"
},
{
"input": "2 1 1\n0 100000\n100000 100000",
"output": "2"
},
{
"input": "6 5 1\n0 1 2 3 4 5\n0 0",
"output": "2"
},
{
"input": "4 100 10\n0 118 121 178\n220 220",
"output": "4"
},
{
"input": "4 3 3\n0 6 8 10\n7 -4",
"output": "2"
},
{
"input": "5 900 1\n0 37474 80030 85359 97616\n-1 -1",
"output": "2"
},
{
"input": "5 200 400\n0 8068 28563 51720 66113\n5423 -34",
"output": "2"
},
{
"input": "6 10 3\n0 12 14 16 19 20\n14 0",
"output": "3"
},
{
"input": "6 13 11\n0 16 27 31 39 42\n54 3",
"output": "6"
},
{
"input": "11 853 721\n0 134 1971 2369 3381 3997 4452 6875 8983 9360 9399\n7345 333",
"output": "8"
},
{
"input": "35 35 12\n0 90486 90543 90763 91127 91310 92047 92405 93654 93814 94633 94752 94969 94994 95287 96349 96362 96723 96855 96883 97470 97482 97683 97844 97926 98437 98724 98899 98921 99230 99253 99328 99444 99691 99947\n96233 -7777",
"output": "9"
},
{
"input": "55 11 44\n0 3343 3387 3470 3825 3832 3971 4026 4043 4389 4492 4886 5015 5084 5161 5436 5595 5616 5677 5987 6251 6312 6369 6469 6487 6493 6507 6641 6928 7067 7159 7280 7303 7385 7387 7465 7536 7572 7664 7895 7921 7955 8110 8191 8243 8280 8523 8525 8581 8877 9221 9462 9505 9594 9596\n8000 0",
"output": "2"
},
{
"input": "72 1000 777\n0 215 2814 5104 5226 5925 6734 9213 11697 13739 14015 16101 17234 19013 19566 19683 20283 20837 21332 21432 25490 26284 27728 29911 30112 30133 31494 31595 32499 32932 33289 36611 37736 43548 44440 44537 47656 47699 48327 50942 52178 53759 56925 57671 62024 65441 67958 70346 71606 75235 75466 75553 75905 76173 76512 77784 78183 80425 81339 81543 84537 88384 89953 90214 92107 92274 93328 93550 93987 97546 99459 99532\n63421 35",
"output": "45"
},
{
"input": "76 1 1\n0 1000 1754 2749 3687 4983 8121 10299 11043 12986 14125 15910 17070 17189 17551 17953 17973 20816 25436 26150 27446 27788 28466 28941 29537 33965 37566 40845 40930 41304 41614 41615 43042 45098 45844 49878 50453 50936 55480 58410 59258 59287 62789 64127 64333 64450 64862 65404 66451 67626 69294 69804 71988 72165 74196 74560 75407 76611 77055 77344 79470 83566 84550 87458 87627 88205 89880 90255 90586 91970 93795 95308 99032 99442 99547 99549\n0 0",
"output": "2"
},
{
"input": "94 2 1\n0 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093\n5050 -100000",
"output": "2"
},
{
"input": "100 1 2\n0 1 2 3 4 5 6 7 8 9 10 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\n100 0",
"output": "2"
},
{
"input": "100 1000 1\n0 505 506 514 515 520 523 527 529 530 538 547 550 554 559 562 566 568 569 580 582 584 588 597 609 621 624 629 630 631 634 641 646 653 657 666 673 678 680 683 685 690 695 698 699 700 705 709 716 731 734 735 736 738 756 761 762 765 769 772 776 779 784 790 794 812 814 816 833 837 842 845 850 854 855 863 868 872 882 892 893 898 899 900 901 902 915 916 917 932 936 954 962 968 975 978 983 992 996 998\n600 7778",
"output": "23"
},
{
"input": "2 1 1\n0 100000\n-100000 -100000",
"output": "2"
},
{
"input": "2 1000 1000\n0 1\n1 0",
"output": "2"
},
{
"input": "3 1 1\n0 1 2\n2 0",
"output": "3"
}
] | 218 | 307,200 | 3.888711 | 3,925 |
149 | Coloring Brackets | [
"dp"
] | null | null | Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it.
You are given string *s*. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a correct mathematical expression from it, inserting numbers and operators between the brackets. For example, such sequences as "(())()" and "()" are correct bracket sequences and such sequences as ")()" and "(()" are not.
In a correct bracket sequence each bracket corresponds to the matching bracket (an opening bracket corresponds to the matching closing bracket and vice versa). For example, in a bracket sequence shown of the figure below, the third bracket corresponds to the matching sixth one and the fifth bracket corresponds to the fourth one.
You are allowed to color some brackets in the bracket sequence so as all three conditions are fulfilled:
- Each bracket is either not colored any color, or is colored red, or is colored blue. - For any pair of matching brackets exactly one of them is colored. In other words, for any bracket the following is true: either it or the matching bracket that corresponds to it is colored. - No two neighboring colored brackets have the same color.
Find the number of different ways to color the bracket sequence. The ways should meet the above-given conditions. Two ways of coloring are considered different if they differ in the color of at least one bracket. As the result can be quite large, print it modulo 1000000007 (109<=+<=7). | The first line contains the single string *s* (2<=β€<=|*s*|<=β€<=700) which represents a correct bracket sequence. | Print the only number β the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109<=+<=7). | [
"(())\n",
"(()())\n",
"()\n"
] | [
"12\n",
"40\n",
"4\n"
] | Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below.
The two ways of coloring shown below are incorrect. | [
{
"input": "(())",
"output": "12"
},
{
"input": "(()())",
"output": "40"
},
{
"input": "()",
"output": "4"
},
{
"input": "((()))",
"output": "36"
},
{
"input": "()(())",
"output": "42"
},
{
"input": "()()()",
"output": "48"
},
{
"input": "(())(())",
"output": "126"
},
{
"input": "()()()()()()()()()()()(())",
"output": "9085632"
},
{
"input": "()(())()((()))",
"output": "4428"
},
{
"input": "()()(())()(())",
"output": "5040"
},
{
"input": "()()()()()()()()()()()()()()()()",
"output": "411525376"
},
{
"input": "(()()())",
"output": "136"
},
{
"input": "()(()())()",
"output": "480"
},
{
"input": "(())()(())()",
"output": "1476"
},
{
"input": "()()(()())(())()()()",
"output": "195840"
},
{
"input": "()()()((((())))())()()()()()((()))()()(())()(((())))()(()())((())())((()())(((((()()()())()()())))))",
"output": "932124942"
},
{
"input": "((()(((((()(()(())))()((((((((())))()(((((())()((((())())(()(()(())())((()))()((()))))))))))))))))))))",
"output": "90824888"
},
{
"input": "((()))((())())((()()))()(())(()())(())()()()((()(((()())))()())()((((()((()((())))(())(()(())())))((()())()()()((())()))()(())(())))()(((((()())))))))",
"output": "100627207"
},
{
"input": "()(((()((((()())))())(())(((((()(()()))))()()))((())))()())((())))(())()((()())())()(()(()())())(()())()(()(((((()))()((()()(())()(())(()((()((()))))()(())()()(()()()((((()())()))))()(((()(((((()()((((())(())))()())(()))(((())((()())(()))())(((()()()(()(())())())(()()()))))())))()((()(()()(()))())((())(()()()(())()))()()(((())))((()))(()((()(((()))((((()())))())(((())()(()((())))))))))))))))))))))",
"output": "306199947"
},
{
"input": "(())(((((()()()()())(())))(()()((()(()(((((())(()())))())(()()(()((())()(()()))))))(())()())))()((()()())))()()(()(())())()())()(())(((((()(()()(((()())()))((())((((()()()))())(((())(((())))))))))))))",
"output": "270087235"
},
{
"input": "()()()((()))(())(((())()(())(())))()()(((()((()()()))(()()(())(())))(()()((()((())(()()(()(())))))))(((())()((((()())))()(((()()())))()))()())))()(()(()())((()((()))))())(((((()())()((((()))(((((()())()))(((()()()((((((()()(())(()))((()(()(()((()((((()(((()(()()(()()((((()))()()()(()((((()(((())(((()()()(())()))((()()()(()))))())()))))(((((((()))())))(((()(()())(())))())))((((())(())())(((()()()))((()()))())(()))(())((()(()))(()()((()(()((()(())(()))()()))))))))))))))))))))))))))))))))))))))))))",
"output": "461776571"
},
{
"input": "()()(((((()((()(())()(()))(()(()(()(()(())(())(())(()(()((())))()))())((()((()(()(((()(()))()(()())(()()()()(((((()(((()))((((())())(((()((((()((((((())())))()))))))))(())())))(((()((()))))((())(()()))()(()(()((()())())()))))((()))))()((())())(()())()())))())())())())()((()((())((()()())()())())()(())()))(()(()))())))(()()()())()())))))))((((()())))((((()()()))())((()(())))))()((()(((())()()()(()()()()()))))(((()())()))()()(((())(()())(()()))))))",
"output": "66338682"
},
{
"input": "(()())()()()((((()(()()(())()((())(((()((()()(()))()))()()))))()(()(())(()))))))",
"output": "639345575"
},
{
"input": "()((()))((((()((())((()()((((()))()()((())((()(((((()(()))((())()))((((())()(()(()))()))))))))))))))))))",
"output": "391997323"
},
{
"input": "(((((()())))))()()()()()(())()()()((()()))()()()()()(((()(())))())(((()())))",
"output": "422789312"
},
{
"input": "((()((()))()((()(()))())))()((()())())()(()())((()))(()())(())()(())()(())(())((()()))((()))()()()()(())()",
"output": "140121189"
},
{
"input": "()()",
"output": "14"
}
] | 62 | 0 | 0 | 3,929 |
|
1,003 | Abbreviation | [
"dp",
"hashing",
"strings"
] | null | null | You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words consist only of lowercase Latin letters.
Let's denote a segment of words $w[i..j]$ as a sequence of words $w_i, w_{i + 1}, \dots, w_j$. Two segments of words $w[i_1 .. j_1]$ and $w[i_2 .. j_2]$ are considered equal if $j_1 - i_1 = j_2 - i_2$, $j_1 \ge i_1$, $j_2 \ge i_2$, and for every $t \in [0, j_1 - i_1]$ $w_{i_1 + t} = w_{i_2 + t}$. For example, for the text "to be or not to be" the segments $w[1..2]$ and $w[5..6]$ are equal, they correspond to the words "to be".
An abbreviation is a replacement of some segments of words with their first uppercase letters. In order to perform an abbreviation, you have to choose at least two non-intersecting equal segments of words, and replace each chosen segment with the string consisting of first letters of the words in the segment (written in uppercase). For example, for the text "a ab a a b ab a a b c" you can replace segments of words $w[2..4]$ and $w[6..8]$ with an abbreviation "AAA" and obtain the text "a AAA b AAA b c", or you can replace segments of words $w[2..5]$ and $w[6..9]$ with an abbreviation "AAAB" and obtain the text "a AAAB AAAB c".
What is the minimum length of the text after at most one abbreviation? | The first line of the input contains one integer $n$ ($1 \le n \le 300$) β the number of words in the text.
The next line contains $n$ space-separated words of the text $w_1, w_2, \dots, w_n$. Each word consists only of lowercase Latin letters.
It is guaranteed that the length of text does not exceed $10^5$. | Print one integer β the minimum length of the text after at most one abbreviation. | [
"6\nto be or not to be\n",
"10\na ab a a b ab a a b c\n",
"6\naa bb aa aa bb bb\n"
] | [
"12\n",
"13\n",
"11\n"
] | In the first example you can obtain the text "TB or not TB".
In the second example you can obtain the text "a AAAB AAAB c".
In the third example you can obtain the text "AB aa AB bb". | [
{
"input": "6\nto be or not to be",
"output": "12"
},
{
"input": "10\na ab a a b ab a a b c",
"output": "13"
},
{
"input": "6\naa bb aa aa bb bb",
"output": "11"
},
{
"input": "45\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of",
"output": "106"
},
{
"input": "250\nf r s d b f f k d e k v m b t k k j t t a o m m s n d w l v g e k x d w k v a j h c a g x s d e t z z w q z d h n r i k b z k u s q l k c v o d o w w c y i a q v r i g i m l b x z h t a i j t h q u e v j o h w m o v k g r r x j a c m z z i s i r a p p i i l e i g m f f f y v k m c l p n n n j j u t t q s o y b t m x n n t z f c g s r f h w z b b d q d y h t v g y e w p l n m f v c s b r g p v w z c o h k u r c g c s v w r t w k z v t v y z i x r f o l e o u q z k x c o l e c b d j v f z y e r k",
"output": "495"
},
{
"input": "1\nu",
"output": "1"
},
{
"input": "1\nvpdgzvgvgbichiiqdhytvcooetcgeecyueoylqzbtzzgaqhalt",
"output": "50"
},
{
"input": "1\nxdhlmtnvecsbwbycahddxnvwpsxwxgfmidfetpkpeevpjzfbgfafbjpyuevupuptoxutnketcxwrllooyxtxjzwxpzcbpiqzeiplcqvdxyyznjxgkwstpxogdihsamoqhyspbjlelxpbarzqawsgidjtmnpmmupohnslirorliapvntasudhpuuxynyoipuqxdiysbyctpmfpbxqfdlmlsmsvtbxoypkbhwrtpwbsbcdhypsbqhqpdlilquppdwsszrpavcowudreygmpwckbzlpnxxqxjdpqmtidjatvgcbxjrpqqxhhsvlpyxxkoqxutsvebrlxqeggvsnshetkpnfygpwbmnuujfvqnlgavwppufxadhxtffsrdknfmqbsjjegcwokbauzivhnldkvykkytkyrwhimmkznkkofcuioqmpbshskvdhsetyidubcgvuerbozqfbkcmaguaszaivtuswzmtnqcpoiqlvronibiqyeoqm",
"output": "500"
},
{
"input": "2\nvjrvahvokiudpiocpvoqsqhukavyrckhcbctr prqxizcofrfr",
"output": "50"
},
{
"input": "2\nxxwxpgalijfbdbdmluuaubobxztpkfn parzxczfzchinxdtaevbepdxlouzfzaizkinuaufhckjvydmgnkuaneqohcqocfrsbmmohgpoacnqlgspppfogdkkbrkrhdpdlnknjyeccbqssqtaqmyamtkedlhpbjmchfnmwhxepzfrfmlrxrirbvvlryzmulxqjlthclocmiudxbtqpihlnielggjxjmvqjbeozjpskenampuszybcorplicekprqbsdkidwpgwkrpvbpcsdcngawcgeyxsjimalrrwttjjualmhypzrmyauvtothnermlednvjbpgkehxbtbpxolmaapmlcuetghikbgtaspqesjkqwxtvccphjdqpuairsaypfudwvelmupbzhxwuchnfumcxmhflkpyzeppddtczbcjrookncgtojmujyvponennuudppqwwjtnwpgapokwzvbxohrdcvcckzbcrwwvfqlbnwbnmmv",
"output": "500"
},
{
"input": "4\ncongratulations for being first",
"output": "31"
},
{
"input": "4\njngen hype xfckaovxfckaovxfckaovxfckaovxfckaovfegkbwzxfckaovxfckaovfegkbwzfegkbwzfegkbwzxfckaovxfckaovfegkbwzfegkbwzfegkbwzxfckaovxfckaovfegkbwzfegkbwzfegkbwz fegkbwzxfckaovfegkbwzxfckaovxfckaovxfckaovfegkbwzfegkbwzxfckaovxfckaovxfckaovfegkbwzfegkbwzxfckaovxfckaovxfckaovxfckaovxfckaovxfckaovfegkbwzxfckaov",
"output": "306"
},
{
"input": "4\njngen hype acpumodacpumodacpumodulhiwuoulhiwuoulhiwuoacpumodacpumodulhiwuoulhiwuoacpumodulhiwuoacpumodulhiwuoacpumodacpumodulhiwuoacpumodulhiwuoacpumod ulhiwuoulhiwuoacpumodacpumodacpumodulhiwuoulhiwuoacpumodulhiwuoacpumodacpumodacpumodacpumodacpumodulhiwuoulhiwuoulhiwuoulhiwuoacpumodulhiwuo",
"output": "292"
},
{
"input": "4\nraraaraaarrraraaaaaaaaaaaaaaaaraaraararaarraarrraaarrarrraaaarrrarrrrraaraaaarrararrarraarrrararaaar arrararaararaarraaaraararraararaarrraarrrarrrrarrraaaaraaraaaaaaaraaararrarararrarrraarrarrrrraaaaar arrararaararaarraaaraararraararaarrraarrrarrrrarrraaaaraaraaaaaaaraaararrarararrarrraarrarrrrraaaaar raraaraaarrraraaaaaaaaaaaaaaaaraaraararaarraarrraaarrarrraaaarrrarrrrraaraaaarrararrarraarrrararaaar",
"output": "205"
},
{
"input": "4\njngen hype wlvgjpibylpibylwlvgjpibylwlvgjwlvgjwlvgjwlvgjwlvgjpibylwlvgjwlvgjpibylpibylpibylwlvgjpibylpibyl pibylpibylpibylpibylpibylwlvgjwlvgjpibylwlvgjwlvgjpibylpibylwlvgjwlvgjwlvgjpibylwlvgjpibylwlvgj",
"output": "202"
},
{
"input": "29\nqiozjl ghgehr xewbil hwovzr keodgb foobar dvorak barfoo xjjfgm wybwaz jizzzz jizzij tjdqba jiyiqj jizziz inforr icagmg jizjiz tdxtfv jhkhdw pgvlzq qvfpbx ymhmll kzaodh xccnda ugywmk jijizz lkkhfs qwerty",
"output": "202"
},
{
"input": "4\naahahhhaaaaaahhaaahaaahahhhahahhhhhhahhahhhhhhahah ahaahahahaaaahahahaaahaaaahhhaaahhahaaahhaahhaaaah ahaahahahaaaahahahaaahaaaahhhaaahhahaaahhaahhaaaah aahahhhaaaaaahhaaahaaahahhhahahhhhhhahhahhhhhhahah",
"output": "105"
},
{
"input": "4\naaaahaaahahhaaahaaahaahhhahhaaaaahahaahaahaahhaaha hhahhahhaaahhhhhhhhahhhhahaahhhaahhahhhhaahahhhhaa hhahhahhaaahhhhhhhhahhhhahaahhhaahhahhhhaahahhhhaa aaaahaaahahhaaahaaahaahhhahhaaaaahahaahaahaahhaaha",
"output": "105"
},
{
"input": "4\njngen hype flnhgpflnhgpwdxrlvwdxrlvflnhgpwdxrlvflnhgpwdxrlvflnhgpwdxrlvflnhgpflnhgpwdxrlvflnhgpflnhgpflnhgpwdxrlvflnhgp wdxrlvwdxrlvflnhgpwdxrlvflnhgpflnhgpflnhgpwdxrlvflnhgpwdxrlvwdxrlvflnhgpflnhgpwdxrlvflnhgpflnhgpflnhgpflnhgp",
"output": "228"
},
{
"input": "40\naanvs aaikp afkib abrzm abnrq aaxdo aaqxz aalhq afhrw aeets acmlb aazzc acphl aanlr abdfc aatdv adfxe abrud acare abbao aauui aacyx aannq aafwd adirh aafiz accgm aalfz aeeac abrja acfkl aabmr aayub aairn acoqw aavlo afgjf aetbp acbbx abmqy",
"output": "239"
},
{
"input": "2\nrmdkgswpghuszbnq oveleebkwopbnmbr",
"output": "33"
},
{
"input": "2\naisajfcrtzfmrpth fninkxwvnqzjvfdq",
"output": "33"
},
{
"input": "40\naclsp aafgb abvlq aazfz aajjt aacts acbfz aawkl abozz aawlg acmre aapqu acodc aaapn aezbx abhjl adhdt aauxj afggb aafbm acbah abgbo abafl aazow acfwx ablad acifb aayly aemkr acsxa aeuzv abvqj actoq aazzc aayye aaxpo advso aanym abtls aahre",
"output": "239"
},
{
"input": "4\njngen hypee acpumodacpumodacpumodulhiwuoulhiwuoulhiwuoacpumodacpumodulhiwuoulhiwuoacpumodulhiwuoacpumodulhiwuoacpumodacpumodulhiwuoacpumodulhiwuoacpumod ulhiwuoulhiwuoacpumodacpumodacpumodulhiwuoulhiwuoacpumodulhiwuoacpumodacpumodacpumodacpumodacpumodulhiwuoulhiwuoulhiwuoulhiwuoacpumodulhiwuo",
"output": "293"
},
{
"input": "7\na a b a a a b",
"output": "9"
},
{
"input": "13\nv w s e n g j m g v g o asdf",
"output": "28"
},
{
"input": "2\nxnnlpp jpymdh",
"output": "13"
}
] | 140 | 1,433,600 | 0 | 3,957 |
|
667 | Pouring Rain | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.
Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom.
You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.
Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.
Note one milliliter equals to one cubic centimeter. | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=β€<=*d*,<=*h*,<=*v*,<=*e*<=β€<=104), where:
- *d* β the diameter of your cylindrical cup, - *h* β the initial level of water in the cup, - *v* β the speed of drinking process from the cup in milliliters per second, - *e* β the growth of water because of rain if you do not drink from the cup. | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number β time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104. | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds. | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input": "20 287 3845 5",
"output": "YES\n39.646277165210"
},
{
"input": "48 6428 9807 83",
"output": "NO"
},
{
"input": "72 5272 4552 64",
"output": "NO"
},
{
"input": "100 4117 5106 34",
"output": "NO"
},
{
"input": "20 2961 9852 15",
"output": "YES\n180.991437129723"
},
{
"input": "48 1805 3109 93",
"output": "NO"
},
{
"input": "72 8534 7042 65",
"output": "NO"
},
{
"input": "1 47 80 68",
"output": "YES\n1.388102806810"
},
{
"input": "4 495 8813 1",
"output": "YES\n0.706823517575"
},
{
"input": "5 2797 5925 9",
"output": "YES\n9.553973511669"
},
{
"input": "1 8324 4362 23",
"output": "YES\n1.505007106354"
},
{
"input": "6 1976 8455 3",
"output": "YES\n6.674898722265"
},
{
"input": "7 2644 8080 5",
"output": "YES\n12.900417790197"
},
{
"input": "3 4183 5491 98",
"output": "YES\n6.162185601824"
},
{
"input": "2 8591 320 101",
"output": "YES\n9999.259991757254"
},
{
"input": "10000 10000 10000 10000",
"output": "NO"
},
{
"input": "2 5000 12 3",
"output": "YES\n6099.653943875812"
},
{
"input": "10 1000 100 1",
"output": "YES\n3659.792366325487"
}
] | 46 | 0 | 3 | 3,961 |
|
978 | File Name | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.
Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".
You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii". | The first line contains integer $n$ $(3 \le n \le 100)$ β the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only β the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
"input": "99\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa",
"output": "0"
},
{
"input": "3\nxxx",
"output": "1"
},
{
"input": "77\naaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxyyyzzz",
"output": "0"
},
{
"input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx",
"output": "41"
},
{
"input": "100\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc",
"output": "49"
},
{
"input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx",
"output": "41"
},
{
"input": "34\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "5\nfcyju",
"output": "0"
},
{
"input": "100\nihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx",
"output": "2"
}
] | 46 | 0 | 3 | 3,962 |
|
62 | A Student's Dream | [
"greedy",
"math"
] | A. A Student's Dream | 2 | 256 | Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable professor of all times, a three times Soviet Union Hero, a Noble Prize laureate in student expulsion, venerable Petr Palych.
The poor student couldn't answer a single question. Thus, instead of a large spacious office he is going to apply for a job to thorium mines. But wait a minute! Petr Palych decided to give the student the last chance! Yes, that is possible only in dreams.
So the professor began: "Once a Venusian girl and a Marsian boy met on the Earth and decided to take a walk holding hands. But the problem is the girl has *a**l* fingers on her left hand and *a**r* fingers on the right one. The boy correspondingly has *b**l* and *b**r* fingers. They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other. Determine if they can hold hands so that the both were comfortable."
The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa. | The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly. | Print YES or NO, that is, the answer to Petr Palych's question. | [
"5 1\n10 5\n",
"4 5\n3 3\n",
"1 2\n11 6\n"
] | [
"YES",
"YES",
"NO"
] | The boy and the girl don't really care who goes to the left. | [
{
"input": "5 1\n10 5",
"output": "YES"
},
{
"input": "4 5\n3 3",
"output": "YES"
},
{
"input": "1 2\n11 6",
"output": "NO"
},
{
"input": "1 1\n1 1",
"output": "YES"
},
{
"input": "2 2\n1 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "NO"
},
{
"input": "4 4\n1 1",
"output": "NO"
},
{
"input": "100 100\n50 50",
"output": "NO"
},
{
"input": "100 3\n4 1",
"output": "YES"
},
{
"input": "100 5\n1 1",
"output": "NO"
},
{
"input": "100 4\n1 1",
"output": "NO"
},
{
"input": "100 1\n4 1",
"output": "YES"
},
{
"input": "1 100\n1 4",
"output": "YES"
},
{
"input": "1 100\n5 4",
"output": "YES"
},
{
"input": "1 100\n1 5",
"output": "NO"
},
{
"input": "43 100\n65 24",
"output": "NO"
},
{
"input": "4 2\n12 1",
"output": "NO"
},
{
"input": "6 11\n13 11",
"output": "YES"
},
{
"input": "2 6\n12 12",
"output": "YES"
},
{
"input": "14 7\n2 9",
"output": "NO"
},
{
"input": "1 14\n7 14",
"output": "NO"
},
{
"input": "6 11\n2 10",
"output": "YES"
},
{
"input": "5 12\n13 11",
"output": "YES"
},
{
"input": "15 1\n11 9",
"output": "NO"
},
{
"input": "7 12\n10 6",
"output": "YES"
},
{
"input": "15 7\n15 15",
"output": "YES"
},
{
"input": "1 5\n14 1",
"output": "YES"
},
{
"input": "2 4\n6 6",
"output": "YES"
},
{
"input": "12 8\n4 12",
"output": "YES"
},
{
"input": "6 14\n5 5",
"output": "YES"
},
{
"input": "19 17\n5 8",
"output": "NO"
},
{
"input": "9 21\n13 16",
"output": "YES"
},
{
"input": "11 2\n11 22",
"output": "YES"
},
{
"input": "15 3\n12 16",
"output": "YES"
},
{
"input": "13 2\n13 5",
"output": "NO"
},
{
"input": "21 1\n5 19",
"output": "NO"
},
{
"input": "9 15\n16 2",
"output": "YES"
},
{
"input": "7 18\n23 19",
"output": "YES"
},
{
"input": "13 17\n19 1",
"output": "YES"
},
{
"input": "5 15\n13 9",
"output": "YES"
},
{
"input": "11 17\n6 4",
"output": "NO"
},
{
"input": "18 3\n16 15",
"output": "NO"
},
{
"input": "5 23\n12 17",
"output": "NO"
},
{
"input": "25 8\n14 24",
"output": "YES"
},
{
"input": "18 22\n22 19",
"output": "YES"
},
{
"input": "2 25\n8 24",
"output": "NO"
},
{
"input": "7 25\n18 15",
"output": "YES"
},
{
"input": "8 22\n2 3",
"output": "NO"
},
{
"input": "25 9\n16 12",
"output": "YES"
},
{
"input": "19 4\n25 17",
"output": "NO"
},
{
"input": "24 43\n96 39",
"output": "YES"
},
{
"input": "13 23\n19 63",
"output": "NO"
},
{
"input": "93 12\n87 54",
"output": "NO"
},
{
"input": "94 35\n53 79",
"output": "YES"
},
{
"input": "65 8\n73 25",
"output": "NO"
},
{
"input": "25 14\n19 91",
"output": "YES"
},
{
"input": "58 86\n40 46",
"output": "NO"
},
{
"input": "82 60\n100 38",
"output": "YES"
},
{
"input": "36 62\n81 12",
"output": "YES"
},
{
"input": "30 38\n12 100",
"output": "NO"
}
] | 92 | 0 | 0 | 3,969 |
886 | ACM ICPC | [
"brute force"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. | The single line contains six integers *a*1,<=...,<=*a*6 (0<=β€<=*a**i*<=β€<=1000) β scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β of 3rd, 4th and 5th: team scores are 1β+β3β+β1β=β2β+β1β+β2β=β5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
"input": "353 313 327 470 597 31",
"output": "NO"
},
{
"input": "835 638 673 624 232 266",
"output": "NO"
},
{
"input": "936 342 19 398 247 874",
"output": "NO"
},
{
"input": "417 666 978 553 271 488",
"output": "NO"
},
{
"input": "71 66 124 199 67 147",
"output": "YES"
},
{
"input": "54 26 0 171 239 12",
"output": "YES"
},
{
"input": "72 8 186 92 267 69",
"output": "YES"
},
{
"input": "180 179 188 50 75 214",
"output": "YES"
},
{
"input": "16 169 110 136 404 277",
"output": "YES"
},
{
"input": "101 400 9 200 300 10",
"output": "YES"
},
{
"input": "101 400 200 9 300 10",
"output": "YES"
},
{
"input": "101 200 400 9 300 10",
"output": "YES"
},
{
"input": "101 400 200 300 9 10",
"output": "YES"
},
{
"input": "101 200 400 300 9 10",
"output": "YES"
},
{
"input": "4 4 4 4 5 4",
"output": "NO"
},
{
"input": "2 2 2 2 2 1",
"output": "NO"
},
{
"input": "1000 1000 999 1000 1000 1000",
"output": "NO"
},
{
"input": "129 1 10 29 8 111",
"output": "NO"
},
{
"input": "1000 1000 1000 999 999 1000",
"output": "YES"
},
{
"input": "101 200 300 400 9 10",
"output": "YES"
},
{
"input": "101 400 200 300 10 9",
"output": "YES"
},
{
"input": "101 200 400 300 10 9",
"output": "YES"
},
{
"input": "101 200 300 400 10 9",
"output": "YES"
},
{
"input": "101 200 300 10 400 9",
"output": "YES"
},
{
"input": "1 1 1 1 1 5",
"output": "NO"
},
{
"input": "8 1 1 3 3 0",
"output": "NO"
},
{
"input": "1 1 2 2 3 3",
"output": "YES"
},
{
"input": "1 2 2 5 2 5",
"output": "NO"
},
{
"input": "1 2 3 6 6 6",
"output": "NO"
},
{
"input": "36 91 7 86 51 89",
"output": "NO"
},
{
"input": "10 1 1 1 23 24",
"output": "NO"
},
{
"input": "1 1 1 10 23 24",
"output": "NO"
},
{
"input": "20 10 1 2 3 44",
"output": "NO"
},
{
"input": "7 0 14 11 8 6",
"output": "NO"
},
{
"input": "100 496 1 1 1 1",
"output": "NO"
},
{
"input": "5 4 2 5 11 3",
"output": "NO"
},
{
"input": "1 3 7 8 8 9",
"output": "YES"
},
{
"input": "1 3 4 5 18 19",
"output": "YES"
},
{
"input": "5 5 1 2 2 15",
"output": "NO"
},
{
"input": "2 1 0 0 0 5",
"output": "NO"
},
{
"input": "1 6 6 1 20 2",
"output": "NO"
},
{
"input": "2 10 0 0 0 0",
"output": "NO"
},
{
"input": "1 1 3 1 1 11",
"output": "NO"
},
{
"input": "10 10 1 1 1 37",
"output": "NO"
},
{
"input": "1 1 0 0 0 4",
"output": "NO"
},
{
"input": "1 1 10 1 1 28",
"output": "NO"
},
{
"input": "1 5 5 5 6 8",
"output": "YES"
},
{
"input": "0 2 3 4 4 5",
"output": "YES"
}
] | 62 | 5,632,000 | 0 | 3,970 |
|
847 | Preparing for Merge Sort | [
"binary search",
"data structures"
] | null | null | Ivan has an array consisting of *n* different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.
Ivan represent his array with increasing sequences with help of the following algorithm.
While there is at least one unused number in array Ivan repeats the following procedure:
- iterate through array from the left to the right; - Ivan only looks at unused numbers on current iteration; - if current number is the first unused number on this iteration or this number is greater than previous unused number on current iteration, then Ivan marks the number as used and writes it down.
For example, if Ivan's array looks like [1, 3, 2, 5, 4] then he will perform two iterations. On first iteration Ivan will use and write numbers [1, 3, 5], and on second one β [2, 4].
Write a program which helps Ivan and finds representation of the given array with one or several increasing sequences in accordance with algorithm described above. | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=2Β·105) β the number of elements in Ivan's array.
The second line contains a sequence consisting of distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β Ivan's array. | Print representation of the given array in the form of one or more increasing sequences in accordance with the algorithm described above. Each sequence must be printed on a new line. | [
"5\n1 3 2 5 4\n",
"4\n4 3 2 1\n",
"4\n10 30 50 101\n"
] | [
"1 3 5 \n2 4 \n",
"4 \n3 \n2 \n1 \n",
"10 30 50 101 \n"
] | none | [
{
"input": "5\n1 3 2 5 4",
"output": "1 3 5 \n2 4 "
},
{
"input": "4\n4 3 2 1",
"output": "4 \n3 \n2 \n1 "
},
{
"input": "4\n10 30 50 101",
"output": "10 30 50 101 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "1\n200000",
"output": "200000 "
},
{
"input": "2\n1 2",
"output": "1 2 "
},
{
"input": "2\n2 1",
"output": "2 \n1 "
},
{
"input": "2\n1 200000",
"output": "1 200000 "
},
{
"input": "2\n200000 1",
"output": "200000 \n1 "
},
{
"input": "10\n71550121 446173607 640274071 402690754 802030518 598196518 796619138 96204862 983359971 799843967",
"output": "71550121 446173607 640274071 802030518 983359971 \n402690754 598196518 796619138 799843967 \n96204862 "
},
{
"input": "3\n1 100 1000000000",
"output": "1 100 1000000000 "
},
{
"input": "3\n1000000000 100 1",
"output": "1000000000 \n100 \n1 "
}
] | 2,000 | 7,372,800 | 0 | 3,976 |
|
896 | Willem, Chtholly and Seniorious | [
"data structures",
"probabilities"
] | null | null | β Willem...
β What's the matter?
β It seems that there's something wrong with Seniorious...
β I'll have a look...
Seniorious is made by linking special talismans in particular order.
After over 500 years, the carillon is now in bad condition, so Willem decides to examine it thoroughly.
Seniorious has *n* pieces of talisman. Willem puts them in a line, the *i*-th of which is an integer *a**i*.
In order to maintain it, Willem needs to perform *m* operations.
There are four types of operations:
- 1 *l* *r* *x*: For each *i* such that *l*<=β€<=*i*<=β€<=*r*, assign *a**i*<=+<=*x* to *a**i*.- 2 *l* *r* *x*: For each *i* such that *l*<=β€<=*i*<=β€<=*r*, assign *x* to *a**i*.- 3 *l* *r* *x*: Print the *x*-th smallest number in the index range [*l*,<=*r*], i.e. the element at the *x*-th position if all the elements *a**i* such that *l*<=β€<=*i*<=β€<=*r* are taken and sorted into an array of non-decreasing integers. It's guaranteed that 1<=β€<=*x*<=β€<=*r*<=-<=*l*<=+<=1.- 4 *l* *r* *x* *y*: Print the sum of the *x*-th power of *a**i* such that *l*<=β€<=*i*<=β€<=*r*, modulo *y*, i.e. . | The only line contains four integers *n*,<=*m*,<=*seed*,<=*v**max* (1<=β€<=*n*,<=*m*<=β€<=105,<=0<=β€<=*seed*<=<<=109<=+<=7,<=1<=β€<=*vmax*<=β€<=109).
The initial values and operations are generated using following pseudo code:
Here *op* is the type of the operation mentioned in the legend. | For each operation of types 3 or 4, output a line containing the answer. | [
"10 10 7 9\n",
"10 10 9 9\n"
] | [
"2\n1\n0\n3\n",
"1\n1\n3\n3\n"
] | In the first example, the initial array is {8,β9,β7,β2,β3,β1,β5,β6,β4,β8}.
The operations are:
- 2 6 7 9 - 1 3 10 8 - 4 4 6 2 4 - 1 4 5 8 - 2 1 7 1 - 4 7 9 4 4 - 1 2 7 9 - 4 5 8 1 1 - 2 5 7 5 - 4 3 10 8 5 | [
{
"input": "10 10 7 9",
"output": "2\n1\n0\n3"
},
{
"input": "10 10 9 9",
"output": "1\n1\n3\n3"
},
{
"input": "1000 1000 658073485 946088556",
"output": "375432604\n52885108\n732131239\n335583873\n375432604\n582199284\n235058938\n682619432\n62026709\n631048460\n51394660\n25596188\n244696891\n1009575922\n9787768\n9787768\n618642640\n278237785\n251668359\n321813234\n563194827\n101752810\n208858224\n262327445\n11344020\n907542692\n275574805\n1182618779\n20489113\n1215012508\n838060601\n15849943\n168527462\n537661946\n301301341\n838060601\n46928748\n656331376\n1656165287\n181551648\n31803656\n1136481\n836554656\n836554656\n836554656\n487461834\n653789051\n24729..."
},
{
"input": "1000 1000 663001819 921338426",
"output": "549050815\n1494447218\n123274718\n949106303\n363391514\n1550246060\n107855794\n206930179\n462058384\n167101179\n858273570\n356404756\n156657135\n591408459\n315837577\n277556562\n423807049\n57871554\n207585345\n207585345\n711053606\n62414948\n736991621\n141019877\n15668980\n1659611655\n39231619\n202790129\n3196038\n236864151\n56524932\n313582670\n72493924\n535770507\n88995537\n194484599\n539736025\n273631024\n149972180\n416123619\n323570345\n695471102\n71796515\n66127408\n1269337883\n296472622\n72864255\n42..."
},
{
"input": "1000 1000 811605498 961464625",
"output": "230231691\n50907792\n772872116\n28726758\n20957398\n48216401\n564116048\n70658978\n9545021\n789851575\n993564693\n754556313\n1407453357\n281963589\n624055178\n50804159\n50804159\n894467226\n24436906\n209344702\n583604216\n545435223\n399103514\n286455036\n672601056\n112440928\n28906651\n285384887\n437165549\n672601056\n672601056\n672601056\n418317887\n1156656565\n123389163\n939398850\n323019445\n1040606872\n181812742\n631705944\n1252601229\n1270982340\n2020261282\n209344702\n661730192\n61860166\n140819245\n..."
},
{
"input": "100000 100000 585767874 969488314",
"output": "488773319\n425485657\n31451411\n125354121\n198709192\n1297027050\n915846188\n865847922\n865847922\n495955788\n430259012\n38112058\n655555207\n269554140\n655555207\n655555207\n865847922\n655555207\n330862299\n257742484\n881124869\n278870276\n623597474\n530082948\n1127525850\n1204398738\n1730577047\n37072555\n694048\n31371749\n9135760\n33463298\n1057194805\n770383482\n565637501\n520029864\n991846906\n1371315075\n97454049\n300044161\n1305967176\n519456769\n74989894\n519456769\n14719300\n880742495\n196109958\n..."
},
{
"input": "100000 100000 456616815 974410294",
"output": "29694410\n114810283\n27479618\n509651935\n1377955711\n1853568141\n48591174\n550185772\n1377733875\n3188073431\n552494826\n162623392\n119629080\n961540301\n13098980\n961540301\n73386869\n81666310\n556381646\n556381646\n16557046\n585391759\n513708058\n835481600\n835481600\n196542142\n155864374\n390537976\n556381646\n272417853\n2018159187\n36749272\n123046338\n556381646\n292126506\n292126506\n292126506\n438730662\n15137105\n292126506\n138122700\n231556955\n119940584\n118400300\n851007817\n551381231\n41556221\n..."
},
{
"input": "35293 65394 377702722 965499399",
"output": "239665146\n662971035\n63311606\n197632809\n411726834\n310795966\n240415864\n2536670\n5613\n202237164\n104440580\n72640017\n570409322\n114470532\n15706744\n576574650\n495809922\n2202598461\n230071751\n131974040\n921695668\n2206028955\n142512706\n154685285\n921695668\n439798074\n3278435837\n206871252\n611644713\n150614106\n24485187\n3485714729\n2523738028\n3485714729\n247403172\n215325649\n590457343\n3485714729\n1729280554\n25140341\n351532943\n1729280554\n252624780\n1083769695\n188669787\n332592766\n4313876..."
},
{
"input": "96334 53956 282409557 989731155",
"output": "264424564\n831132059\n72908436\n368090942\n227423644\n311506102\n194783295\n206318770\n56695549\n211863709\n56695549\n214634804\n297831496\n365649379\n247715382\n293899239\n635203088\n137366134\n24683564\n1445257517\n98960586\n325902360\n114187617\n292648787\n431543187\n46443921\n716759516\n1430137540\n1430137540\n431543187\n574046806\n248546906\n1126047236\n2649836\n759894053\n706270467\n223031249\n759894053\n316507989\n119726966\n1213065175\n68123952\n68123952\n13792714\n331483558\n446844394\n446844394\n..."
},
{
"input": "34281 4646 305421312 941787985",
"output": "29743039\n480172415\n140640480\n856939452\n98074616\n3035375\n644241474\n644241474\n279358712\n279358712\n17376223\n182274578\n333883463\n509541754\n310952850\n685788527\n223266725\n253520950\n26530950\n501280346\n24526068\n117438324\n5300076\n117438324\n117438324\n313193846\n9007832\n305109765\n1728525074\n28677313\n28506441\n363836046\n28677313\n810490379\n630323845\n303089169\n211750693\n20586044\n1727991144\n13537401\n789731968\n789731968\n71774445\n430486019\n456241150\n430486019\n99829885\n106821794\n..."
},
{
"input": "65410 84158 299309076 977599182",
"output": "685446942\n701897521\n809216029\n455806624\n249004690\n273488789\n92895066\n971005418\n127013721\n1249277917\n147217558\n139154621\n821049631\n1375797794\n157402634\n1198902618\n1620738977\n24571589\n1481406668\n1459610003\n98342934\n98342934\n2238344471\n190638960\n971005418\n347261832\n804800693\n561476144\n804800693\n804800693\n1238964356\n220043336\n1238964356\n350972540\n54846606\n444625629\n186497410\n435072732\n105203033\n609625024\n435072732\n609625024\n67644091\n609625024\n367494\n609625024\n53480..."
},
{
"input": "75424 85046 913047528 985636135",
"output": "452443538\n919821162\n214758190\n538602859\n599290738\n1380479354\n91\n30402955\n313667506\n46450616\n430822033\n1064551056\n1589735072\n885640637\n53728070\n4773196\n1622583932\n195603732\n72827616\n61957289\n2299040254\n75818259\n642736943\n507230783\n241032135\n373689191\n1460529968\n1253584727\n65126128\n24852939\n137801751\n318674322\n60000306\n318674322\n1253584727\n1253584727\n318674322\n579230242\n982770772\n398108613\n694874412\n6896765\n30216757\n10782747\n694874412\n450833972\n654671372\n6546713..."
},
{
"input": "96011 69484 952656656 949837239",
"output": "32539942\n221637648\n6685807\n221637648\n130499111\n749816296\n749816296\n465720281\n169837107\n434579635\n434579635\n434579635\n140347135\n80756745\n917825533\n176391976\n388876628\n24154597\n52986937\n749816296\n143381298\n115970301\n8487472\n578697326\n129033564\n129033564\n342075018\n129033564\n129033564\n215260680\n62781742\n377703498\n215260680\n215260680\n823964653\n229054709\n215260680\n543738340\n377703498\n215260680\n288700027\n839891288\n823964653\n148164475\n215260680\n868684479\n868684479\n308..."
},
{
"input": "69971 85577 806771998 978710230",
"output": "129329933\n68385719\n540565769\n56655160\n1686967476\n1541942367\n503262086\n1262717021\n1917927442\n89532045\n331110012\n285803527\n214266325\n622411716\n501726093\n418940034\n501726093\n119341174\n514438082\n288349614\n574659327\n312054790\n2954052\n1519871905\n1519871905\n148270297\n285803527\n2141292212\n2644011758\n952023412\n211365450\n101906015\n952023412\n81336979\n1142528136\n1124663438\n623313617\n328980988\n73743051\n734701813\n8348685\n792032598\n167646751\n1079261493\n546235003\n500693783\n792..."
},
{
"input": "53834 13558 705236852 914473856",
"output": "227634968\n75533466\n692001026\n372458402\n4199748\n372458402\n1011605540\n148163245\n1082313030\n1876361538\n252764794\n1082313030\n213855976\n20679522\n213855976\n39289356\n227865875\n2316098912\n767062628\n485927680\n767062628\n266488539\n745842201\n22734895\n609911878\n111182647\n100331484\n1753687996\n167171744\n485927680\n3238342\n65048581\n675400107\n102847960\n79627523\n99751245\n75065723\n446974685\n69768843\n234926533\n1346413189\n268814655\n99751245\n113231745\n123381304\n52895998\n162960402\n13..."
},
{
"input": "92855 38088 901131679 905998083",
"output": "55981088\n160365879\n198841463\n16748732\n1486157\n940679842\n90710681\n324660985\n166529288\n535567417\n151558952\n218974486\n331522181\n760674601\n760674601\n332166026\n246407870\n79818860\n5979574\n536221952\n50773637\n79818860\n519436559\n331522181\n127744454\n98592365\n83358985\n275931666\n732449614\n405457829\n1353659460\n11058078\n729708778\n342000739\n1162214\n1162214\n1162214\n310867040\n148135539\n574118370\n928983682\n524479467\n41969224\n511281496\n649137291\n285473957\n285473957\n300759177\n10..."
},
{
"input": "48858 21838 231460178 954692031",
"output": "370847937\n463563365\n367380589\n341817660\n106844349\n631218936\n1903253855\n152677346\n2122059099\n527292097\n3519900\n13012943\n84734828\n1520810540\n226192657\n1978951417\n1386685276\n1682768810\n9119707\n1521671071\n2776435178\n33398758\n1528015541\n226489528\n571104910\n243497460\n400780750\n420100208\n1043989628\n1451057360\n434594375\n327308470\n16499992\n901126852\n1453786073\n268548975\n901126852\n327308470\n118609516\n447919118\n555690825\n1092279693\n3750710219\n3709774734\n5866129199\n53198154..."
},
{
"input": "32475 84541 799815170 924502267",
"output": "1476622863\n620575616\n620575616\n78358606\n438229787\n864343294\n12338748\n1533951174\n22149457\n225899435\n116727262\n2363454966\n23802028\n126121524\n47524507\n360201478\n58493311\n58493311\n363006653\n1659243219\n1898547080\n111467637\n151197193\n17047098\n481900146\n523981654\n667787844\n193996944\n906407106\n5613772\n561747384\n355019510\n755462348\n45612357\n552152736\n467700213\n133377364\n667678683\n523981654\n1041743225\n25175667\n689741016\n689741016\n27813939\n118945345\n577631414\n928133446\n2..."
},
{
"input": "56021 2857 942001819 920619100",
"output": "220073701\n727295171\n403209389\n57913378\n533442531\n590064935\n219334821\n934651827\n1276456256\n367157678\n123336941\n385398504\n957948763\n205735222\n1299753192\n456943243\n366180607\n435417349\n607104570\n56298134\n193843556\n300856292\n173076391\n636606525\n313268237\n677092026\n172995482\n412475584\n20029368\n32735150\n467452356\n210066452\n210066452\n210066452\n136919226\n1382145697\n914945606\n194540184\n624906162\n624906162\n588138580\n624906162\n115762671\n122995130\n602863059\n473714412\n187136..."
},
{
"input": "83662 39961 277703709 950449724",
"output": "126252222\n849892280\n167866056\n127364128\n127364128\n450004640\n458130870\n127364128\n585334262\n14475851\n127364128\n38910263\n224539282\n825993384\n127364128\n96652010\n18604923\n47266399\n906040086\n46391759\n318595826\n127364128\n318595826\n104497172\n318595826\n841837314\n119474015\n202909906\n186683697\n161340425\n890054689\n207667046\n186683697\n186683697\n982483372\n982483372\n970578805\n1509014350\n169911047\n399527384\n148321924\n260202217\n1079582546\n341511245\n1704702615\n206165042\n30995511..."
},
{
"input": "34134 37276 316383536 923096494",
"output": "870247680\n35828540\n10693546\n198698070\n8284050\n7996330\n184167090\n211946972\n581355602\n413509769\n238825775\n288191626\n120306907\n784563961\n695255246\n173030372\n322425686\n987458693\n1047783977\n7655871\n695255246\n1273433928\n1574983481\n151640495\n227480251\n224928429\n227480251\n42411840\n232624919\n224928429\n189372927\n224928429\n194449043\n906749416\n258234237\n3253928010\n43269307\n218951276\n474442785\n421639939\n18679100\n51715037\n421639939\n474442785\n389762766\n3176639\n39619784\n16759..."
},
{
"input": "34736 88419 280789856 941687084",
"output": "183818278\n205903405\n163799308\n114262258\n473958519\n374203788\n7412532\n789150889\n339153118\n133450986\n339153118\n355870030\n213438639\n72371912\n897178997\n567245519\n9226262\n61273072\n482571152\n61273072\n25069173\n26289124\n157227437\n9064234\n91919653\n769517395\n392022677\n138881826\n482961641\n276680584\n513335054\n16319149\n513335054\n513335054\n513335054\n484706460\n90429697\n265064608\n274690262\n264818705\n117287263\n1131988503\n329064115\n1074580206\n596447015\n9064234\n596447015\n1233496\n..."
},
{
"input": "65839 45757 768591103 998790277",
"output": "678126807\n1032303763\n443892850\n2900162\n359867860\n909321721\n282237191\n32476392\n909321721\n909321721\n909321721\n395833688\n909321721\n111393833\n1862877827\n9657375\n1841936689\n200749704\n112435038\n736555479\n1206250982\n9356050\n736555479\n297818932\n290875157\n322725717\n206227944\n932542054\n630169903\n1206250982\n1206250982\n311006658\n966119600\n966119600\n381477\n326255604\n85400943\n3891748251\n98327387\n120588804\n480537833\n16411381\n924545423\n618680484\n442365821\n186723124\n1570384675\n..."
},
{
"input": "92582 97744 474444887 902071104",
"output": "615962324\n871938501\n46758368\n771582484\n23362941\n483737060\n645934514\n360312782\n143955012\n37888632\n87503654\n24280201\n380445709\n558574575\n29583810\n56351351\n20177884\n3763903\n20652\n225045569\n139842734\n34921510\n76167018\n62940058\n202172786\n675330569\n856736574\n17852626\n1348761106\n1348761106\n151879079\n59349419\n1479504273\n675524105\n30936840\n246296399\n1647188865\n151010160\n448224904\n1647188865\n44525093\n2262297944\n625076927\n244983906\n60408560\n534966611\n534966611\n42959560\n..."
},
{
"input": "46031 42537 451207636 982647444",
"output": "20264423\n153434450\n164995661\n577060066\n564247456\n260347857\n720604311\n329587356\n351913053\n1412130719\n962683528\n7311281\n1488665438\n1419729339\n46949459\n1488665438\n124051366\n1488665438\n8135269\n1159282\n239565871\n229564151\n18448464\n1426435681\n46900807\n644262799\n268629120\n56343862\n163559110\n73270721\n59427856\n644262799\n644262799\n644262799\n1426435681\n644262799\n644262799\n1538104637\n1427165695\n416453692\n579373083\n40662989\n149471664\n873195434\n11027753\n606249189\n1302016003\n..."
},
{
"input": "64909 20063 18579507 927481501",
"output": "269516549\n642864303\n25032469\n115372744\n46740774\n422004558\n308450120\n292670932\n1225114614\n308450120\n586984082\n308450120\n831925309\n782629281\n195873104\n1338669052\n831925309\n846888619\n3593834\n979073\n4143263\n71565650\n339206737\n869962395\n272554744\n394452983\n80076701\n219349564\n236647603\n95367812\n189131938\n15570719\n5499337\n813294149\n96253960\n178177637\n339136655\n64762330\n2444408353\n3311130099\n181458657\n2208828278\n252557929\n223375980\n3447406493\n163783624\n181458657\n32068..."
},
{
"input": "90798 73851 189131066 992703032",
"output": "82268803\n823120145\n22437793\n79305058\n141058630\n454513528\n50278331\n286975891\n71675090\n1280701409\n199601434\n1224942235\n145318910\n145318910\n175299998\n413619613\n33333661\n356101636\n15085552\n88093049\n660604153\n69342898\n9661704\n41141377\n825929676\n1661301459\n62218513\n1993966592\n281100568\n532143708\n514062254\n81371299\n73984632\n849331146\n42454875\n812612262\n236025988\n376131279\n981695252\n129041988\n2959698729\n1655673084\n81054581\n1655673084\n206317887\n1529748115\n828696819\n587..."
},
{
"input": "72580 68306 62781726 916636983",
"output": "955231872\n1345938897\n37809236\n1023745536\n193327830\n436196190\n1390545560\n981804553\n1045391793\n851876301\n687402477\n687402477\n42268493\n328559844\n24034514\n252182937\n279807511\n106057230\n1039492777\n7502068\n511880431\n2318324125\n45502261\n563695247\n462332546\n672588582\n624384702\n672588582\n31449928\n72203770\n684180552\n709466604\n709466604\n684180552\n759166137\n67435990\n405911259\n277606868\n1076032126\n759166137\n21671606\n1980595676\n843191728\n61650249\n612025245\n472605762\n61202524..."
},
{
"input": "1924 16436 604734001 960651460",
"output": "224407039\n21629501\n51671061\n618123933\n66618374\n349548646\n1707651063\n21984485\n745056175\n66017917\n294185410\n519710292\n513436148\n24316769\n158658898\n612865248\n225546641\n368908923\n1127927911\n209356404\n583748672\n607372677\n718946905\n722922265\n8318377\n299512174\n918433001\n50651876\n324485498\n415234261\n17609483\n82606475\n184620922\n5720471\n1287572969\n1080877827\n86077625\n1660997030\n479967009\n389354602\n159084510\n639166732\n766227609\n1940884570\n521559131\n1304554719\n2296012179\n..."
},
{
"input": "41309 15973 780671431 932433911",
"output": "75563798\n403789976\n6393139\n254976448\n805601247\n6393139\n254976448\n175939840\n1389369508\n922395878\n61632625\n1686490793\n23750495\n625527070\n434310777\n113496156\n460480347\n261196051\n2583744434\n505830077\n280326977\n77318221\n430992600\n410525376\n902799147\n132626784\n851717663\n476352311\n545543140\n9677235\n849072777\n1496482050\n150578755\n55426222\n815693999\n1369752719\n2326528906\n7493896\n50909437\n808378541\n313315600\n808378541\n91608487\n2649723\n683362929\n42620542\n818196368\n648192..."
},
{
"input": "100000 100000 1000000006 1",
"output": "1\n0\n1\n1\n1\n1\n0\n2\n0\n2\n0\n2\n3\n0\n1\n2\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n1\n2\n0\n0\n0\n0\n1\n0\n0\n2\n2\n0\n0\n0\n3\n0\n0\n1\n3\n1\n0\n1\n1\n1\n1\n0\n1\n0\n2\n1\n0\n2\n2\n0\n1\n0\n0\n1\n1\n1\n0\n0\n0\n2\n1\n1\n1\n1\n0\n2\n1\n2\n2\n1\n0\n0\n0\n0\n1\n1\n0\n2\n0\n0\n0\n0\n0\n0\n0\n1\n1\n0\n1\n0\n0\n0\n0\n1\n2\n2\n0\n0\n2\n2\n0\n2\n2\n0\n2\n2\n0\n0\n1\n0\n3\n0\n0\n3\n5\n1\n4\n0\n0\n0\n0\n1\n0\n1\n2\n0\n0\n3\n1\n1\n2\n0\n0\n0\n1\n1\n2\n0\n0\n0\n5\n0\n0\n0\n0\n0\n0\n3\n1\n0\n0\n4\n0\n0\n1\n1\n0\n0..."
},
{
"input": "100000 100000 1000000006 1000000000",
"output": "882118768\n227532426\n982370702\n89007427\n485790874\n634312928\n49251089\n627764763\n80706419\n1397244924\n272967282\n1397244924\n1350824337\n670835165\n760200096\n767082446\n172014978\n293563707\n338455390\n326300712\n148951496\n883219864\n966553744\n159024974\n174268768\n150366372\n11996640\n444249353\n142162688\n467511457\n696083115\n204657135\n284818568\n44568313\n262909776\n594416395\n202008512\n519417095\n337769547\n337769547\n28098864\n35755678\n326275262\n2694086723\n569314771\n221615842\n16755104..."
},
{
"input": "100000 100000 0 1000000000",
"output": "10169893\n16014934\n817242366\n909155662\n909155662\n64934185\n63188268\n294217675\n78389509\n71850126\n71850126\n100243750\n898699956\n133848650\n1054178187\n133848650\n22516864\n62515496\n537279455\n124507892\n440708118\n124507892\n217708272\n133848650\n125674761\n458997492\n253085860\n377119511\n1595531354\n377119511\n455176528\n621245765\n1268020473\n1268020473\n1471497703\n2437200935\n612553989\n244788470\n1503454951\n313339152\n565198602\n585007836\n861854621\n98979356\n570051021\n681628204\n48341592..."
}
] | 0 | 0 | -1 | 3,977 |
|
294 | Shaass and Lights | [
"combinatorics",
"number theory"
] | null | null | There are *n* lights aligned in a row. These lights are numbered 1 to *n* from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007Β (109<=+<=7). | The first line of the input contains two integers *n* and *m* where *n* is the number of lights in the sequence and *m* is the number of lights which are initially switched on, (1<=β€<=*n*<=β€<=1000,<=1<=β€<=*m*<=β€<=*n*). The second line contains *m* distinct integers, each between 1 to *n* inclusive, denoting the indices of lights which are initially switched on. | In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007Β (109<=+<=7). | [
"3 1\n1\n",
"4 2\n1 4\n",
"11 2\n4 8\n"
] | [
"1\n",
"2\n",
"6720\n"
] | none | [
{
"input": "3 1\n1",
"output": "1"
},
{
"input": "4 2\n1 4",
"output": "2"
},
{
"input": "11 2\n4 8",
"output": "6720"
},
{
"input": "4 2\n1 3",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "1"
},
{
"input": "4 2\n1 3",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "1"
},
{
"input": "1000 3\n100 900 10",
"output": "727202008"
},
{
"input": "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73",
"output": "16623551"
},
{
"input": "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73",
"output": "16623551"
},
{
"input": "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73",
"output": "16623551"
},
{
"input": "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73",
"output": "16623551"
},
{
"input": "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73",
"output": "16623551"
},
{
"input": "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73",
"output": "16623551"
},
{
"input": "68 37\n1 2 3 6 7 8 10 11 12 14 16 18 22 23 24 26 30 31 32 35 37 39 41 42 45 47 50 51 52 54 58 59 61 62 63 64 68",
"output": "867201120"
},
{
"input": "132 48\n6 7 8 12 15 17 18 19 22 24 25 26 30 33 35 38 40 43 46 49 50 51 52 54 59 60 66 70 76 79 87 89 91 92 94 98 99 101 102 105 106 109 113 115 116 118 120 129",
"output": "376947760"
},
{
"input": "36 24\n1 7 8 10 11 12 13 14 15 16 17 19 21 22 25 26 27 28 29 30 31 32 35 36",
"output": "63866880"
},
{
"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": "1"
},
{
"input": "100 2\n11 64",
"output": "910895596"
},
{
"input": "100 90\n1 2 3 4 5 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 27 28 29 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 58 59 60 61 62 63 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 82 83 84 86 87 88 89 90 91 92 94 95 96 98 99 100",
"output": "3628800"
},
{
"input": "1000 1\n35",
"output": "253560421"
},
{
"input": "1000 2\n747 798",
"output": "474746180"
},
{
"input": "1000 3\n804 811 984",
"output": "600324842"
},
{
"input": "1 1\n1",
"output": "1"
}
] | 108 | 307,200 | 3 | 3,984 |
Subsets and Splits