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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
540 | Ice Cave | [
"dfs and similar"
] | null | null | You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.
The level of the cave where you are is a rectangular square grid of *n* rows and *m* columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.
Let's number the rows with integers from 1 to *n* from top to bottom and the columns with integers from 1 to *m* from left to right. Let's denote a cell on the intersection of the *r*-th row and the *c*-th column as (*r*,<=*c*).
You are staying in the cell (*r*1,<=*c*1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (*r*2,<=*c*2) since the exit to the next level is there. Can you do this? | The first line contains two integers, *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=500) β the number of rows and columns in the cave description.
Each of the next *n* lines describes the initial state of the level of the cave, each line consists of *m* characters "." (that is, intact ice) and "X" (cracked ice).
The next line contains two integers, *r*1 and *c*1 (1<=β€<=*r*1<=β€<=*n*,<=1<=β€<=*c*1<=β€<=*m*) β your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (*r*1,<=*c*1), that is, the ice on the starting cell is initially cracked.
The next line contains two integers *r*2 and *c*2 (1<=β€<=*r*2<=β€<=*n*,<=1<=β€<=*c*2<=β€<=*m*) β the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | If you can reach the destination, print 'YES', otherwise print 'NO'. | [
"4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2\n",
"5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1\n",
"4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test one possible path is:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c61f56de718beea14935ccdc85ae2c4ad45c1454.png" style="max-width: 100.0%;max-height: 100.0%;"/>
After the first visit of cell (2,β2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | [
{
"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2",
"output": "YES"
},
{
"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1",
"output": "NO"
},
{
"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6",
"output": "YES"
},
{
"input": "5 3\n.XX\n...\n.X.\n.X.\n...\n1 3\n4 1",
"output": "YES"
},
{
"input": "1 1\nX\n1 1\n1 1",
"output": "NO"
},
{
"input": "1 6\n.X...X\n1 2\n1 5",
"output": "NO"
},
{
"input": "7 1\nX\n.\n.\n.\nX\n.\n.\n5 1\n3 1",
"output": "YES"
},
{
"input": "1 2\nXX\n1 1\n1 1",
"output": "NO"
},
{
"input": "2 1\n.\nX\n2 1\n2 1",
"output": "YES"
},
{
"input": "3 4\n.X..\n..XX\n..X.\n1 2\n3 4",
"output": "NO"
},
{
"input": "3 5\n.X.XX\nX...X\nX.X..\n2 1\n1 5",
"output": "NO"
},
{
"input": "3 2\n..\nX.\n.X\n3 2\n3 1",
"output": "NO"
},
{
"input": "3 4\nXX.X\nX...\n.X.X\n1 2\n1 1",
"output": "YES"
},
{
"input": "1 2\nX.\n1 1\n1 2",
"output": "NO"
},
{
"input": "2 1\nX\nX\n2 1\n1 1",
"output": "YES"
},
{
"input": "2 2\nXX\nXX\n1 1\n2 2",
"output": "NO"
},
{
"input": "2 2\n..\n.X\n2 2\n1 1",
"output": "YES"
},
{
"input": "2 2\n.X\n.X\n1 2\n2 2",
"output": "YES"
},
{
"input": "2 2\n..\nXX\n2 1\n1 1",
"output": "YES"
},
{
"input": "4 2\nX.\n.X\n.X\nXX\n2 2\n3 1",
"output": "NO"
},
{
"input": "2 4\nX.XX\n.X..\n2 2\n2 3",
"output": "YES"
},
{
"input": "6 4\nX..X\n..X.\n.X..\n..X.\n.X..\nX..X\n1 1\n6 4",
"output": "NO"
},
{
"input": "5 4\nX...\n..X.\n.X..\nX..X\n....\n4 4\n3 1",
"output": "NO"
},
{
"input": "3 4\nX..X\n..XX\n.X..\n2 3\n3 1",
"output": "NO"
},
{
"input": "20 20\n....................\n.......X...........X\n............X......X\n.X...XX..X....X.....\n....X.....X.........\nX..........X........\n......X........X....\n....................\n...................X\n......X.............\n..............X.....\n......X.X...........\n.X.........X.X......\n.........X......X..X\n..................X.\n...X........X.......\n....................\n....................\n..X.....X...........\n........X......X.X..\n20 16\n5 20",
"output": "YES"
},
{
"input": "21 21\n.....X...X.........X.\n...X...XX......X.....\n..X........X.X...XX..\n.........X....X...X..\nX...X...........XX...\n...X...X....XX...XXX.\n.X............X......\n......X.X............\n.X...X.........X.X...\n......XX......X.X....\n....X.......X.XXX....\n.X.......X..XXX.X..X.\n..X........X....X...X\n.........X..........X\n.....XX.....X........\n...XX......X.........\n.....X...XX...X......\n..X.X....XX..XX.X....\nX........X.X..XX..X..\nX..X......X...X.X....\nX.....X.....X.X......\n20 4\n21 5",
"output": "YES"
},
{
"input": "2 1\nX\nX\n2 1\n2 1",
"output": "NO"
},
{
"input": "2 2\nXX\nX.\n1 1\n2 2",
"output": "NO"
},
{
"input": "2 1\nX\nX\n1 1\n1 1",
"output": "NO"
},
{
"input": "1 2\nXX\n1 2\n1 2",
"output": "NO"
},
{
"input": "1 2\nXX\n1 1\n1 2",
"output": "YES"
},
{
"input": "1 2\nXX\n1 2\n1 1",
"output": "YES"
},
{
"input": "2 1\nX\nX\n1 1\n2 1",
"output": "YES"
},
{
"input": "2 1\n.\nX\n2 1\n1 1",
"output": "NO"
},
{
"input": "2 1\nX\n.\n1 1\n2 1",
"output": "NO"
},
{
"input": "1 2\n.X\n1 2\n1 1",
"output": "NO"
},
{
"input": "2 1\nX\n.\n1 1\n1 1",
"output": "YES"
},
{
"input": "1 2\nX.\n1 1\n1 1",
"output": "YES"
},
{
"input": "1 2\n.X\n1 2\n1 2",
"output": "YES"
},
{
"input": "2 2\nX.\n..\n1 1\n2 2",
"output": "YES"
},
{
"input": "2 2\n..\nX.\n2 1\n1 1",
"output": "YES"
},
{
"input": "4 3\n..X\n..X\n.XX\n.XX\n4 2\n2 2",
"output": "YES"
},
{
"input": "3 3\nXXX\nX..\nXXX\n2 1\n2 2",
"output": "YES"
},
{
"input": "5 4\nXXXX\nX..X\nX..X\nXXXX\nXXXX\n4 2\n3 3",
"output": "YES"
}
] | 46 | 2,150,400 | -1 | 1,384 |
|
814 | An abandoned sentiment from past | [
"constructive algorithms",
"greedy",
"implementation",
"sortings"
] | null | null | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.
Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total.
If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing. | The first line of input contains two space-separated positive integers *n* (2<=β€<=*n*<=β€<=100) and *k* (1<=β€<=*k*<=β€<=*n*) β the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=200) β Hitagi's broken sequence with exactly *k* zero elements.
The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=β€<=*b**i*<=β€<=200) β the elements to fill into Hitagi's sequence.
Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total. | Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. | [
"4 2\n11 0 0 14\n5 4\n",
"6 1\n2 3 0 8 9 10\n5\n",
"4 1\n8 94 0 4\n89\n",
"7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first sample:
- Sequence *a* is 11,β0,β0,β14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11,β5,β4,β14 and 11,β4,β5,β14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting sequence is 2,β3,β5,β8,β9,β10, which is an increasing sequence and therefore invalid. | [
{
"input": "4 2\n11 0 0 14\n5 4",
"output": "Yes"
},
{
"input": "6 1\n2 3 0 8 9 10\n5",
"output": "No"
},
{
"input": "4 1\n8 94 0 4\n89",
"output": "Yes"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7",
"output": "Yes"
},
{
"input": "40 1\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\n80",
"output": "No"
},
{
"input": "100 1\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\n58",
"output": "Yes"
},
{
"input": "4 1\n2 1 0 4\n3",
"output": "Yes"
},
{
"input": "2 1\n199 0\n200",
"output": "No"
},
{
"input": "3 2\n115 0 0\n145 191",
"output": "Yes"
},
{
"input": "5 1\n196 197 198 0 200\n199",
"output": "No"
},
{
"input": "5 1\n92 0 97 99 100\n93",
"output": "No"
},
{
"input": "3 1\n3 87 0\n81",
"output": "Yes"
},
{
"input": "3 1\n0 92 192\n118",
"output": "Yes"
},
{
"input": "10 1\n1 3 0 7 35 46 66 72 83 90\n22",
"output": "Yes"
},
{
"input": "100 1\n14 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 0 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\n67",
"output": "No"
},
{
"input": "100 5\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 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 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 0 99 100\n98 64 55 52 29",
"output": "Yes"
},
{
"input": "100 5\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\n121 199 62 193 27",
"output": "Yes"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 0 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\n11",
"output": "Yes"
},
{
"input": "100 1\n0 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\n1",
"output": "No"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\n100",
"output": "No"
},
{
"input": "100 1\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\n65",
"output": "Yes"
},
{
"input": "100 2\n0 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 0 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\n48 1",
"output": "Yes"
},
{
"input": "100 1\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\n69",
"output": "Yes"
},
{
"input": "100 1\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\n129",
"output": "No"
},
{
"input": "5 2\n0 2 7 0 10\n1 8",
"output": "Yes"
},
{
"input": "3 1\n5 4 0\n1",
"output": "Yes"
},
{
"input": "3 1\n1 0 3\n4",
"output": "Yes"
},
{
"input": "2 1\n0 2\n1",
"output": "No"
},
{
"input": "2 1\n0 5\n7",
"output": "Yes"
},
{
"input": "5 1\n10 11 0 12 13\n1",
"output": "Yes"
},
{
"input": "5 1\n0 2 3 4 5\n6",
"output": "Yes"
},
{
"input": "6 2\n1 0 3 4 0 6\n2 5",
"output": "Yes"
},
{
"input": "7 2\n1 2 3 0 0 6 7\n4 5",
"output": "Yes"
},
{
"input": "4 1\n1 2 3 0\n4",
"output": "No"
},
{
"input": "2 2\n0 0\n1 2",
"output": "Yes"
},
{
"input": "3 2\n1 0 0\n2 3",
"output": "Yes"
},
{
"input": "4 2\n1 0 4 0\n5 2",
"output": "Yes"
},
{
"input": "2 1\n0 1\n2",
"output": "Yes"
},
{
"input": "5 2\n1 0 4 0 6\n2 5",
"output": "Yes"
},
{
"input": "5 1\n2 3 0 4 5\n1",
"output": "Yes"
},
{
"input": "3 1\n0 2 3\n5",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 4 5 0\n6",
"output": "No"
},
{
"input": "5 1\n1 2 0 4 5\n6",
"output": "Yes"
},
{
"input": "3 1\n5 0 2\n7",
"output": "Yes"
},
{
"input": "4 1\n4 5 0 8\n3",
"output": "Yes"
},
{
"input": "5 1\n10 11 12 0 14\n13",
"output": "No"
},
{
"input": "4 1\n1 2 0 4\n5",
"output": "Yes"
},
{
"input": "3 1\n0 11 14\n12",
"output": "Yes"
},
{
"input": "4 1\n1 3 0 4\n2",
"output": "Yes"
},
{
"input": "2 1\n0 5\n1",
"output": "No"
},
{
"input": "5 1\n1 2 0 4 7\n5",
"output": "Yes"
},
{
"input": "3 1\n2 3 0\n1",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 0 5 4\n6",
"output": "Yes"
},
{
"input": "4 2\n11 0 0 14\n13 12",
"output": "Yes"
},
{
"input": "2 1\n1 0\n2",
"output": "No"
},
{
"input": "3 1\n1 2 0\n3",
"output": "No"
},
{
"input": "4 1\n1 0 3 2\n4",
"output": "Yes"
},
{
"input": "3 1\n0 1 2\n5",
"output": "Yes"
},
{
"input": "3 1\n0 1 2\n3",
"output": "Yes"
},
{
"input": "4 1\n0 2 3 4\n5",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 0 4 5\n6",
"output": "Yes"
},
{
"input": "3 1\n1 2 0\n5",
"output": "No"
},
{
"input": "4 2\n1 0 0 4\n3 2",
"output": "Yes"
},
{
"input": "5 1\n2 3 0 5 7\n6",
"output": "Yes"
},
{
"input": "3 1\n2 3 0\n4",
"output": "No"
},
{
"input": "3 1\n1 0 11\n5",
"output": "No"
},
{
"input": "4 1\n7 9 5 0\n8",
"output": "Yes"
},
{
"input": "6 2\n1 2 3 0 5 0\n6 4",
"output": "Yes"
},
{
"input": "3 2\n0 1 0\n3 2",
"output": "Yes"
},
{
"input": "4 1\n6 9 5 0\n8",
"output": "Yes"
},
{
"input": "2 1\n0 3\n6",
"output": "Yes"
},
{
"input": "5 2\n1 2 0 0 5\n4 3",
"output": "Yes"
},
{
"input": "4 2\n2 0 0 8\n3 4",
"output": "Yes"
},
{
"input": "2 1\n0 2\n3",
"output": "Yes"
},
{
"input": "3 1\n0 4 5\n6",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 4 0 5\n6",
"output": "Yes"
},
{
"input": "2 1\n2 0\n3",
"output": "No"
},
{
"input": "4 2\n11 0 0 200\n100 199",
"output": "Yes"
},
{
"input": "2 1\n5 0\n4",
"output": "Yes"
},
{
"input": "3 1\n1 0 5\n10",
"output": "Yes"
},
{
"input": "6 2\n1 2 0 0 5 6\n3 4",
"output": "Yes"
},
{
"input": "5 2\n1 0 3 0 5\n2 4",
"output": "Yes"
},
{
"input": "4 1\n1 4 0 8\n3",
"output": "Yes"
},
{
"input": "4 1\n5 9 4 0\n8",
"output": "Yes"
},
{
"input": "4 2\n1 0 0 7\n3 2",
"output": "Yes"
},
{
"input": "3 3\n0 0 0\n1 4 3",
"output": "Yes"
},
{
"input": "5 5\n0 0 0 0 0\n5 4 3 2 1",
"output": "Yes"
},
{
"input": "4 1\n3 9 4 0\n8",
"output": "Yes"
},
{
"input": "4 2\n1 0 0 4\n2 3",
"output": "Yes"
},
{
"input": "6 1\n2 4 0 8 9 10\n3",
"output": "Yes"
},
{
"input": "4 1\n0 3 5 6\n9",
"output": "Yes"
},
{
"input": "4 2\n1 2 0 0\n3 4",
"output": "Yes"
},
{
"input": "5 1\n2 3 4 5 0\n1",
"output": "Yes"
},
{
"input": "3 1\n2 0 4\n5",
"output": "Yes"
}
] | 61 | 0 | 3 | 1,387 |
|
778 | String Game | [
"binary search",
"greedy",
"strings"
] | null | null | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya".
Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.
It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. | The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=β€<=|*p*|<=<<=|*t*|<=β€<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=β€<=*a**i*<=β€<=|*t*|, all *a**i* are distinct). | Print a single integer number, the maximum number of letters that Nastya can remove. | [
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"bbbabb\nbb\n1 6 3 4 2 5\n"
] | [
"3",
"4"
] | In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba"
Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".
So, Nastya will remove only three letters. | [
{
"input": "ababcba\nabb\n5 3 4 1 7 6 2",
"output": "3"
},
{
"input": "bbbabb\nbb\n1 6 3 4 2 5",
"output": "4"
},
{
"input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2",
"output": "9"
},
{
"input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 19 17 15 14 11 20 2",
"output": "16"
},
{
"input": "aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 10 71 98 23 89 36 62 28 51 24 30 74 55 27 80 38 48 93 1 19 84 13 11 86 60 87 33 39 29 83 91 67 72 54 2 17 85 82 14 15 90 64 50 99 26 66 65 31 49 40 45 77 37 25 42 97 47 58 92 59 16",
"output": "57"
}
] | 140 | 307,200 | 0 | 1,390 |
|
160 | Edges in MST | [
"dfs and similar",
"dsu",
"graphs",
"sortings"
] | null | null | You are given a connected weighted undirected graph without any loops and multiple edges.
Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the given graph that includes all of the graph's vertexes. The weight of a tree is defined as the sum of weights of the edges that the given tree contains. The minimum spanning tree (MST) of a graph is defined as the graph's spanning tree having the minimum possible weight. For any connected graph obviously exists the minimum spanning tree, but in the general case, a graph's minimum spanning tree is not unique.
Your task is to determine the following for each edge of the given graph: whether it is either included in any MST, or included at least in one MST, or not included in any MST. | The first line contains two integers *n* and *m* (2<=β€<=*n*<=β€<=105, ) β the number of the graph's vertexes and edges, correspondingly. Then follow *m* lines, each of them contains three integers β the description of the graph's edges as "*a**i* *b**i* *w**i*" (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*,<=1<=β€<=*w**i*<=β€<=106,<=*a**i*<=β <=*b**i*), where *a**i* and *b**i* are the numbers of vertexes connected by the *i*-th edge, *w**i* is the edge's weight. It is guaranteed that the graph is connected and doesn't contain loops or multiple edges. | Print *m* lines β the answers for all edges. If the *i*-th edge is included in any MST, print "any"; if the *i*-th edge is included at least in one MST, print "at least one"; if the *i*-th edge isn't included in any MST, print "none". Print the answers for the edges in the order in which the edges are specified in the input. | [
"4 5\n1 2 101\n1 3 100\n2 3 2\n2 4 2\n3 4 1\n",
"3 3\n1 2 1\n2 3 1\n1 3 2\n",
"3 3\n1 2 1\n2 3 1\n1 3 1\n"
] | [
"none\nany\nat least one\nat least one\nany\n",
"any\nany\nnone\n",
"at least one\nat least one\nat least one\n"
] | In the second sample the MST is unique for the given graph: it contains two first edges.
In the third sample any two edges form the MST for the given graph. That means that each edge is included at least in one MST. | [] | 109 | 16,896,000 | 0 | 1,394 |
|
416 | Art Union | [
"brute force",
"dp",
"implementation"
] | null | null | A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these *n* colors. Adding the *j*-th color to the *i*-th picture takes the *j*-th painter *t**ij* units of time.
Order is important everywhere, so the painters' work is ordered by the following rules:
- Each picture is first painted by the first painter, then by the second one, and so on. That is, after the *j*-th painter finishes working on the picture, it must go to the (*j*<=+<=1)-th painter (if *j*<=<<=*n*); - each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on; - each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest; - as soon as the *j*-th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter.
Given that the painters start working at time 0, find for each picture the time when it is ready for sale. | The first line of the input contains integers *m*,<=*n* (1<=β€<=*m*<=β€<=50000,<=1<=β€<=*n*<=β€<=5), where *m* is the number of pictures and *n* is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains *n* integers *t**i*1,<=*t**i*2,<=...,<=*t**in* (1<=β€<=*t**ij*<=β€<=1000), where *t**ij* is the time the *j*-th painter needs to work on the *i*-th picture. | Print the sequence of *m* integers *r*1,<=*r*2,<=...,<=*r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture. | [
"5 1\n1\n2\n3\n4\n5\n",
"4 2\n2 5\n3 1\n5 3\n10 1\n"
] | [
"1 3 6 10 15 ",
"7 8 13 21 "
] | none | [
{
"input": "5 1\n1\n2\n3\n4\n5",
"output": "1 3 6 10 15 "
},
{
"input": "4 2\n2 5\n3 1\n5 3\n10 1",
"output": "7 8 13 21 "
},
{
"input": "1 1\n66",
"output": "66 "
},
{
"input": "2 2\n1 1\n1 1",
"output": "2 3 "
},
{
"input": "2 2\n10 1\n10 1",
"output": "11 21 "
},
{
"input": "1 5\n1 95 44 14 35",
"output": "189 "
},
{
"input": "7 1\n80\n92\n24\n88\n40\n45\n7",
"output": "80 172 196 284 324 369 376 "
},
{
"input": "1 2\n51 44",
"output": "95 "
},
{
"input": "2 1\n19\n4",
"output": "19 23 "
},
{
"input": "2 2\n1 10\n1 1",
"output": "11 12 "
},
{
"input": "3 3\n3 9 4\n5 10 8\n4 4 7",
"output": "16 30 37 "
},
{
"input": "10 3\n6 10 3\n2 7 9\n10 4 7\n6 3 4\n6 2 6\n8 4 4\n5 9 8\n6 9 7\n2 7 10\n2 6 2",
"output": "19 32 39 43 49 53 61 68 78 80 "
}
] | 374 | 16,896,000 | 3 | 1,395 |
|
190 | Vasya and the Bus | [
"greedy",
"math"
] | null | null | One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had *n* grown-ups and *m* kids..."
The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride.
The bus fare equals one berland ruble in High Bertown. However, not everything is that easy β no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his *k* (*k*<=><=0) children, pays overall *k* rubles: a ticket for himself and (*k*<=-<=1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble.
We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups.
Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total. | The input file consists of a single line containing two space-separated numbers *n* and *m* (0<=β€<=*n*,<=*m*<=β€<=105) β the number of the grown-ups and the number of the children in the bus, correspondingly. | If *n* grown-ups and *m* children could have ridden in the bus, then print on a single line two space-separated integers β the minimum and the maximum possible total bus fare, correspondingly.
Otherwise, print "Impossible" (without the quotes). | [
"1 2\n",
"0 5\n",
"2 2\n"
] | [
"2 2",
"Impossible",
"2 3"
] | In the first sample a grown-up rides with two children and pays two rubles.
In the second sample there are only children in the bus, so the situation is impossible.
In the third sample there are two cases: - Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. - One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total. | [
{
"input": "1 2",
"output": "2 2"
},
{
"input": "0 5",
"output": "Impossible"
},
{
"input": "2 2",
"output": "2 3"
},
{
"input": "2 7",
"output": "7 8"
},
{
"input": "4 10",
"output": "10 13"
},
{
"input": "6 0",
"output": "6 6"
},
{
"input": "7 1",
"output": "7 7"
},
{
"input": "0 0",
"output": "0 0"
},
{
"input": "71 24",
"output": "71 94"
},
{
"input": "16 70",
"output": "70 85"
},
{
"input": "0 1",
"output": "Impossible"
},
{
"input": "1 0",
"output": "1 1"
},
{
"input": "1 1",
"output": "1 1"
},
{
"input": "63 82",
"output": "82 144"
},
{
"input": "8 26",
"output": "26 33"
},
{
"input": "21 27",
"output": "27 47"
},
{
"input": "0 38",
"output": "Impossible"
},
{
"input": "46 84",
"output": "84 129"
},
{
"input": "59 96",
"output": "96 154"
},
{
"input": "63028 0",
"output": "63028 63028"
},
{
"input": "9458 0",
"output": "9458 9458"
},
{
"input": "80236 0",
"output": "80236 80236"
},
{
"input": "26666 0",
"output": "26666 26666"
},
{
"input": "59617 0",
"output": "59617 59617"
},
{
"input": "0 6048",
"output": "Impossible"
},
{
"input": "63028 28217",
"output": "63028 91244"
},
{
"input": "9458 39163",
"output": "39163 48620"
},
{
"input": "80236 14868",
"output": "80236 95103"
},
{
"input": "26666 52747",
"output": "52747 79412"
},
{
"input": "59617 28452",
"output": "59617 88068"
},
{
"input": "6048 4158",
"output": "6048 10205"
},
{
"input": "76826 4210",
"output": "76826 81035"
},
{
"input": "23256 15156",
"output": "23256 38411"
},
{
"input": "56207 53035",
"output": "56207 109241"
},
{
"input": "2637 28740",
"output": "28740 31376"
},
{
"input": "73415 4445",
"output": "73415 77859"
},
{
"input": "82019 4498",
"output": "82019 86516"
},
{
"input": "28449 80204",
"output": "80204 108652"
},
{
"input": "99227 53323",
"output": "99227 152549"
},
{
"input": "45657 29028",
"output": "45657 74684"
},
{
"input": "78608 4733",
"output": "78608 83340"
},
{
"input": "25038 4786",
"output": "25038 29823"
},
{
"input": "95816 80492",
"output": "95816 176307"
},
{
"input": "42246 94024",
"output": "94024 136269"
},
{
"input": "0 100000",
"output": "Impossible"
},
{
"input": "100000 0",
"output": "100000 100000"
},
{
"input": "1 100000",
"output": "100000 100000"
},
{
"input": "100000 1",
"output": "100000 100000"
},
{
"input": "63028 63028",
"output": "63028 126055"
},
{
"input": "9458 9458",
"output": "9458 18915"
},
{
"input": "80236 80236",
"output": "80236 160471"
},
{
"input": "26666 26666",
"output": "26666 53331"
},
{
"input": "59617 59617",
"output": "59617 119233"
},
{
"input": "100000 100000",
"output": "100000 199999"
}
] | 0 | 0 | -1 | 1,403 |
|
817 | Treasure Hunt | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times. | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=β€<=*x*1,<=*y*1,<=*x*2,<=*y*2<=β€<=105) β positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=β€<=*x*,<=*y*<=β€<=105) β values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> β the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> β the third type of move | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81 -17 80\n87 23",
"output": "YES"
},
{
"input": "41 366 218 -240\n3456 1234",
"output": "NO"
},
{
"input": "-61972 -39646 -42371 -24854\n573 238",
"output": "NO"
},
{
"input": "-84870 -42042 94570 98028\n8972 23345",
"output": "YES"
},
{
"input": "-58533 -50999 -1007 -59169\n8972 23345",
"output": "NO"
},
{
"input": "-100000 -100000 100000 100000\n100000 100000",
"output": "YES"
},
{
"input": "-100000 -100000 100000 100000\n1 1",
"output": "YES"
},
{
"input": "5 2 5 3\n1 1",
"output": "NO"
},
{
"input": "5 5 5 5\n5 5",
"output": "YES"
},
{
"input": "0 0 1000 1000\n1 1",
"output": "YES"
},
{
"input": "0 0 0 1\n1 1",
"output": "NO"
},
{
"input": "1 1 4 4\n2 2",
"output": "NO"
},
{
"input": "100000 100000 99999 99999\n100000 100000",
"output": "NO"
},
{
"input": "1 1 1 6\n1 5",
"output": "NO"
},
{
"input": "2 9 4 0\n2 3",
"output": "YES"
},
{
"input": "0 0 0 9\n2 3",
"output": "NO"
},
{
"input": "14 88 14 88\n100 500",
"output": "YES"
},
{
"input": "-1 0 3 0\n4 4",
"output": "NO"
},
{
"input": "0 0 8 9\n2 3",
"output": "NO"
},
{
"input": "-2 5 7 -6\n1 1",
"output": "YES"
},
{
"input": "3 7 -8 8\n2 2",
"output": "NO"
},
{
"input": "-4 -8 -6 -1\n1 3",
"output": "NO"
},
{
"input": "0 8 6 2\n1 1",
"output": "YES"
},
{
"input": "-5 -2 -8 -2\n1 1",
"output": "NO"
},
{
"input": "1 4 -5 0\n1 1",
"output": "YES"
},
{
"input": "8 -4 4 -7\n1 2",
"output": "NO"
},
{
"input": "5 2 2 4\n2 2",
"output": "NO"
},
{
"input": "2 0 -4 6\n1 2",
"output": "NO"
},
{
"input": "-2 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "-6 5 10 6\n2 4",
"output": "NO"
},
{
"input": "3 -7 1 -8\n1 2",
"output": "NO"
},
{
"input": "4 1 4 -4\n9 4",
"output": "NO"
},
{
"input": "9 -3 -9 -3\n2 2",
"output": "NO"
},
{
"input": "-6 -6 -10 -5\n6 7",
"output": "NO"
},
{
"input": "-5 -2 2 2\n1 7",
"output": "NO"
},
{
"input": "9 0 8 1\n7 10",
"output": "NO"
},
{
"input": "-1 6 -7 -6\n6 4",
"output": "YES"
},
{
"input": "2 2 -3 -3\n3 1",
"output": "NO"
},
{
"input": "2 -6 7 2\n2 1",
"output": "NO"
},
{
"input": "-6 2 -7 -7\n1 2",
"output": "NO"
},
{
"input": "-5 -5 -1 -5\n2 2",
"output": "YES"
},
{
"input": "0 5 3 -6\n2 2",
"output": "NO"
},
{
"input": "0 -6 2 -1\n1 1",
"output": "NO"
},
{
"input": "-6 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "7 -7 1 -7\n2 2",
"output": "NO"
},
{
"input": "99966 -99952 -99966 99923\n1 1",
"output": "NO"
},
{
"input": "99921 99980 -99956 -99907\n3 4",
"output": "NO"
},
{
"input": "100000 100000 -100000 -100000\n1 1",
"output": "YES"
},
{
"input": "1 0 2 0\n5 1",
"output": "NO"
},
{
"input": "-3 0 -8 0\n7 2",
"output": "NO"
},
{
"input": "-9 4 -5 -1\n8 2",
"output": "NO"
},
{
"input": "-99999 -100000 100000 100000\n1 1",
"output": "NO"
},
{
"input": "0 0 -100 -100\n2 2",
"output": "YES"
},
{
"input": "9 -5 -3 -2\n1 4",
"output": "NO"
},
{
"input": "1 -10 -10 5\n7 5",
"output": "NO"
},
{
"input": "6 -9 -1 -9\n1 9",
"output": "NO"
}
] | 62 | 0 | 3 | 1,408 |
|
195 | After Training | [
"data structures",
"implementation",
"math"
] | null | null | After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly. The balls are numbered with numbers from 1 to *n*.
Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which is minimum, where *i* is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number.
For every ball print the number of the basket where it will go according to Valeric's scheme.
Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on. | The first line contains two space-separated integers *n*, *m* (1<=β€<=*n*,<=*m*<=β€<=105) β the number of balls and baskets, correspondingly. | Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball. | [
"4 3\n",
"3 1\n"
] | [
"2\n1\n3\n2\n",
"1\n1\n1\n"
] | none | [
{
"input": "4 3",
"output": "2\n1\n3\n2"
},
{
"input": "3 1",
"output": "1\n1\n1"
},
{
"input": "10 3",
"output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2"
},
{
"input": "6 5",
"output": "3\n2\n4\n1\n5\n3"
},
{
"input": "2 6",
"output": "3\n4"
},
{
"input": "5 2",
"output": "1\n2\n1\n2\n1"
},
{
"input": "85702 100000",
"output": "50000\n50001\n49999\n50002\n49998\n50003\n49997\n50004\n49996\n50005\n49995\n50006\n49994\n50007\n49993\n50008\n49992\n50009\n49991\n50010\n49990\n50011\n49989\n50012\n49988\n50013\n49987\n50014\n49986\n50015\n49985\n50016\n49984\n50017\n49983\n50018\n49982\n50019\n49981\n50020\n49980\n50021\n49979\n50022\n49978\n50023\n49977\n50024\n49976\n50025\n49975\n50026\n49974\n50027\n49973\n50028\n49972\n50029\n49971\n50030\n49970\n50031\n49969\n50032\n49968\n50033\n49967\n50034\n49966\n50035\n49965\n50036\n49964\n..."
},
{
"input": "9 2",
"output": "1\n2\n1\n2\n1\n2\n1\n2\n1"
},
{
"input": "45 88",
"output": "44\n45\n43\n46\n42\n47\n41\n48\n40\n49\n39\n50\n38\n51\n37\n52\n36\n53\n35\n54\n34\n55\n33\n56\n32\n57\n31\n58\n30\n59\n29\n60\n28\n61\n27\n62\n26\n63\n25\n64\n24\n65\n23\n66\n22"
},
{
"input": "61 51",
"output": "26\n25\n27\n24\n28\n23\n29\n22\n30\n21\n31\n20\n32\n19\n33\n18\n34\n17\n35\n16\n36\n15\n37\n14\n38\n13\n39\n12\n40\n11\n41\n10\n42\n9\n43\n8\n44\n7\n45\n6\n46\n5\n47\n4\n48\n3\n49\n2\n50\n1\n51\n26\n25\n27\n24\n28\n23\n29\n22\n30\n21"
},
{
"input": "21 57",
"output": "29\n28\n30\n27\n31\n26\n32\n25\n33\n24\n34\n23\n35\n22\n36\n21\n37\n20\n38\n19\n39"
},
{
"input": "677 787",
"output": "394\n393\n395\n392\n396\n391\n397\n390\n398\n389\n399\n388\n400\n387\n401\n386\n402\n385\n403\n384\n404\n383\n405\n382\n406\n381\n407\n380\n408\n379\n409\n378\n410\n377\n411\n376\n412\n375\n413\n374\n414\n373\n415\n372\n416\n371\n417\n370\n418\n369\n419\n368\n420\n367\n421\n366\n422\n365\n423\n364\n424\n363\n425\n362\n426\n361\n427\n360\n428\n359\n429\n358\n430\n357\n431\n356\n432\n355\n433\n354\n434\n353\n435\n352\n436\n351\n437\n350\n438\n349\n439\n348\n440\n347\n441\n346\n442\n345\n443\n344\n444\n343\n4..."
},
{
"input": "37 849",
"output": "425\n424\n426\n423\n427\n422\n428\n421\n429\n420\n430\n419\n431\n418\n432\n417\n433\n416\n434\n415\n435\n414\n436\n413\n437\n412\n438\n411\n439\n410\n440\n409\n441\n408\n442\n407\n443"
},
{
"input": "453 855",
"output": "428\n427\n429\n426\n430\n425\n431\n424\n432\n423\n433\n422\n434\n421\n435\n420\n436\n419\n437\n418\n438\n417\n439\n416\n440\n415\n441\n414\n442\n413\n443\n412\n444\n411\n445\n410\n446\n409\n447\n408\n448\n407\n449\n406\n450\n405\n451\n404\n452\n403\n453\n402\n454\n401\n455\n400\n456\n399\n457\n398\n458\n397\n459\n396\n460\n395\n461\n394\n462\n393\n463\n392\n464\n391\n465\n390\n466\n389\n467\n388\n468\n387\n469\n386\n470\n385\n471\n384\n472\n383\n473\n382\n474\n381\n475\n380\n476\n379\n477\n378\n478\n377\n4..."
},
{
"input": "165 374",
"output": "187\n188\n186\n189\n185\n190\n184\n191\n183\n192\n182\n193\n181\n194\n180\n195\n179\n196\n178\n197\n177\n198\n176\n199\n175\n200\n174\n201\n173\n202\n172\n203\n171\n204\n170\n205\n169\n206\n168\n207\n167\n208\n166\n209\n165\n210\n164\n211\n163\n212\n162\n213\n161\n214\n160\n215\n159\n216\n158\n217\n157\n218\n156\n219\n155\n220\n154\n221\n153\n222\n152\n223\n151\n224\n150\n225\n149\n226\n148\n227\n147\n228\n146\n229\n145\n230\n144\n231\n143\n232\n142\n233\n141\n234\n140\n235\n139\n236\n138\n237\n137\n238\n1..."
},
{
"input": "328 3",
"output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3..."
},
{
"input": "8 80",
"output": "40\n41\n39\n42\n38\n43\n37\n44"
},
{
"input": "90 544",
"output": "272\n273\n271\n274\n270\n275\n269\n276\n268\n277\n267\n278\n266\n279\n265\n280\n264\n281\n263\n282\n262\n283\n261\n284\n260\n285\n259\n286\n258\n287\n257\n288\n256\n289\n255\n290\n254\n291\n253\n292\n252\n293\n251\n294\n250\n295\n249\n296\n248\n297\n247\n298\n246\n299\n245\n300\n244\n301\n243\n302\n242\n303\n241\n304\n240\n305\n239\n306\n238\n307\n237\n308\n236\n309\n235\n310\n234\n311\n233\n312\n232\n313\n231\n314\n230\n315\n229\n316\n228\n317"
},
{
"input": "85 60",
"output": "30\n31\n29\n32\n28\n33\n27\n34\n26\n35\n25\n36\n24\n37\n23\n38\n22\n39\n21\n40\n20\n41\n19\n42\n18\n43\n17\n44\n16\n45\n15\n46\n14\n47\n13\n48\n12\n49\n11\n50\n10\n51\n9\n52\n8\n53\n7\n54\n6\n55\n5\n56\n4\n57\n3\n58\n2\n59\n1\n60\n30\n31\n29\n32\n28\n33\n27\n34\n26\n35\n25\n36\n24\n37\n23\n38\n22\n39\n21\n40\n20\n41\n19\n42\n18"
},
{
"input": "392 5",
"output": "3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3..."
},
{
"input": "8 87",
"output": "44\n43\n45\n42\n46\n41\n47\n40"
},
{
"input": "6 358",
"output": "179\n180\n178\n181\n177\n182"
},
{
"input": "501 70",
"output": "35\n36\n34\n37\n33\n38\n32\n39\n31\n40\n30\n41\n29\n42\n28\n43\n27\n44\n26\n45\n25\n46\n24\n47\n23\n48\n22\n49\n21\n50\n20\n51\n19\n52\n18\n53\n17\n54\n16\n55\n15\n56\n14\n57\n13\n58\n12\n59\n11\n60\n10\n61\n9\n62\n8\n63\n7\n64\n6\n65\n5\n66\n4\n67\n3\n68\n2\n69\n1\n70\n35\n36\n34\n37\n33\n38\n32\n39\n31\n40\n30\n41\n29\n42\n28\n43\n27\n44\n26\n45\n25\n46\n24\n47\n23\n48\n22\n49\n21\n50\n20\n51\n19\n52\n18\n53\n17\n54\n16\n55\n15\n56\n14\n57\n13\n58\n12\n59\n11\n60\n10\n61\n9\n62\n8\n63\n7\n64\n6\n65\n5\n6..."
},
{
"input": "3834 1",
"output": "1\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\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..."
},
{
"input": "1 8828",
"output": "4414"
},
{
"input": "69230 89906",
"output": "44953\n44954\n44952\n44955\n44951\n44956\n44950\n44957\n44949\n44958\n44948\n44959\n44947\n44960\n44946\n44961\n44945\n44962\n44944\n44963\n44943\n44964\n44942\n44965\n44941\n44966\n44940\n44967\n44939\n44968\n44938\n44969\n44937\n44970\n44936\n44971\n44935\n44972\n44934\n44973\n44933\n44974\n44932\n44975\n44931\n44976\n44930\n44977\n44929\n44978\n44928\n44979\n44927\n44980\n44926\n44981\n44925\n44982\n44924\n44983\n44923\n44984\n44922\n44985\n44921\n44986\n44920\n44987\n44919\n44988\n44918\n44989\n44917\n..."
},
{
"input": "27646 59913",
"output": "29957\n29956\n29958\n29955\n29959\n29954\n29960\n29953\n29961\n29952\n29962\n29951\n29963\n29950\n29964\n29949\n29965\n29948\n29966\n29947\n29967\n29946\n29968\n29945\n29969\n29944\n29970\n29943\n29971\n29942\n29972\n29941\n29973\n29940\n29974\n29939\n29975\n29938\n29976\n29937\n29977\n29936\n29978\n29935\n29979\n29934\n29980\n29933\n29981\n29932\n29982\n29931\n29983\n29930\n29984\n29929\n29985\n29928\n29986\n29927\n29987\n29926\n29988\n29925\n29989\n29924\n29990\n29923\n29991\n29922\n29992\n29921\n29993\n..."
},
{
"input": "37006 54783",
"output": "27392\n27391\n27393\n27390\n27394\n27389\n27395\n27388\n27396\n27387\n27397\n27386\n27398\n27385\n27399\n27384\n27400\n27383\n27401\n27382\n27402\n27381\n27403\n27380\n27404\n27379\n27405\n27378\n27406\n27377\n27407\n27376\n27408\n27375\n27409\n27374\n27410\n27373\n27411\n27372\n27412\n27371\n27413\n27370\n27414\n27369\n27415\n27368\n27416\n27367\n27417\n27366\n27418\n27365\n27419\n27364\n27420\n27363\n27421\n27362\n27422\n27361\n27423\n27360\n27424\n27359\n27425\n27358\n27426\n27357\n27427\n27356\n27428\n..."
},
{
"input": "1 100000",
"output": "50000"
},
{
"input": "100000 1",
"output": "1\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\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..."
},
{
"input": "100000 100000",
"output": "50000\n50001\n49999\n50002\n49998\n50003\n49997\n50004\n49996\n50005\n49995\n50006\n49994\n50007\n49993\n50008\n49992\n50009\n49991\n50010\n49990\n50011\n49989\n50012\n49988\n50013\n49987\n50014\n49986\n50015\n49985\n50016\n49984\n50017\n49983\n50018\n49982\n50019\n49981\n50020\n49980\n50021\n49979\n50022\n49978\n50023\n49977\n50024\n49976\n50025\n49975\n50026\n49974\n50027\n49973\n50028\n49972\n50029\n49971\n50030\n49970\n50031\n49969\n50032\n49968\n50033\n49967\n50034\n49966\n50035\n49965\n50036\n49964\n..."
},
{
"input": "100000 13",
"output": "7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n..."
},
{
"input": "100000 44",
"output": "22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21..."
},
{
"input": "100000 37820",
"output": "18910\n18911\n18909\n18912\n18908\n18913\n18907\n18914\n18906\n18915\n18905\n18916\n18904\n18917\n18903\n18918\n18902\n18919\n18901\n18920\n18900\n18921\n18899\n18922\n18898\n18923\n18897\n18924\n18896\n18925\n18895\n18926\n18894\n18927\n18893\n18928\n18892\n18929\n18891\n18930\n18890\n18931\n18889\n18932\n18888\n18933\n18887\n18934\n18886\n18935\n18885\n18936\n18884\n18937\n18883\n18938\n18882\n18939\n18881\n18940\n18880\n18941\n18879\n18942\n18878\n18943\n18877\n18944\n18876\n18945\n18875\n18946\n18874\n..."
},
{
"input": "99999 77777",
"output": "38889\n38888\n38890\n38887\n38891\n38886\n38892\n38885\n38893\n38884\n38894\n38883\n38895\n38882\n38896\n38881\n38897\n38880\n38898\n38879\n38899\n38878\n38900\n38877\n38901\n38876\n38902\n38875\n38903\n38874\n38904\n38873\n38905\n38872\n38906\n38871\n38907\n38870\n38908\n38869\n38909\n38868\n38910\n38867\n38911\n38866\n38912\n38865\n38913\n38864\n38914\n38863\n38915\n38862\n38916\n38861\n38917\n38860\n38918\n38859\n38919\n38858\n38920\n38857\n38921\n38856\n38922\n38855\n38923\n38854\n38924\n38853\n38925\n..."
},
{
"input": "1991 1935",
"output": "968\n967\n969\n966\n970\n965\n971\n964\n972\n963\n973\n962\n974\n961\n975\n960\n976\n959\n977\n958\n978\n957\n979\n956\n980\n955\n981\n954\n982\n953\n983\n952\n984\n951\n985\n950\n986\n949\n987\n948\n988\n947\n989\n946\n990\n945\n991\n944\n992\n943\n993\n942\n994\n941\n995\n940\n996\n939\n997\n938\n998\n937\n999\n936\n1000\n935\n1001\n934\n1002\n933\n1003\n932\n1004\n931\n1005\n930\n1006\n929\n1007\n928\n1008\n927\n1009\n926\n1010\n925\n1011\n924\n1012\n923\n1013\n922\n1014\n921\n1015\n920\n1016\n919\n1017..."
},
{
"input": "17 812",
"output": "406\n407\n405\n408\n404\n409\n403\n410\n402\n411\n401\n412\n400\n413\n399\n414\n398"
},
{
"input": "30078 300",
"output": "150\n151\n149\n152\n148\n153\n147\n154\n146\n155\n145\n156\n144\n157\n143\n158\n142\n159\n141\n160\n140\n161\n139\n162\n138\n163\n137\n164\n136\n165\n135\n166\n134\n167\n133\n168\n132\n169\n131\n170\n130\n171\n129\n172\n128\n173\n127\n174\n126\n175\n125\n176\n124\n177\n123\n178\n122\n179\n121\n180\n120\n181\n119\n182\n118\n183\n117\n184\n116\n185\n115\n186\n114\n187\n113\n188\n112\n189\n111\n190\n110\n191\n109\n192\n108\n193\n107\n194\n106\n195\n105\n196\n104\n197\n103\n198\n102\n199\n101\n200\n100\n201\n9..."
},
{
"input": "10500 5",
"output": "3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3..."
},
{
"input": "90091 322",
"output": "161\n162\n160\n163\n159\n164\n158\n165\n157\n166\n156\n167\n155\n168\n154\n169\n153\n170\n152\n171\n151\n172\n150\n173\n149\n174\n148\n175\n147\n176\n146\n177\n145\n178\n144\n179\n143\n180\n142\n181\n141\n182\n140\n183\n139\n184\n138\n185\n137\n186\n136\n187\n135\n188\n134\n189\n133\n190\n132\n191\n131\n192\n130\n193\n129\n194\n128\n195\n127\n196\n126\n197\n125\n198\n124\n199\n123\n200\n122\n201\n121\n202\n120\n203\n119\n204\n118\n205\n117\n206\n116\n207\n115\n208\n114\n209\n113\n210\n112\n211\n111\n212\n1..."
},
{
"input": "8471 92356",
"output": "46178\n46179\n46177\n46180\n46176\n46181\n46175\n46182\n46174\n46183\n46173\n46184\n46172\n46185\n46171\n46186\n46170\n46187\n46169\n46188\n46168\n46189\n46167\n46190\n46166\n46191\n46165\n46192\n46164\n46193\n46163\n46194\n46162\n46195\n46161\n46196\n46160\n46197\n46159\n46198\n46158\n46199\n46157\n46200\n46156\n46201\n46155\n46202\n46154\n46203\n46153\n46204\n46152\n46205\n46151\n46206\n46150\n46207\n46149\n46208\n46148\n46209\n46147\n46210\n46146\n46211\n46145\n46212\n46144\n46213\n46143\n46214\n46142\n..."
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1\n1"
},
{
"input": "52097 88310",
"output": "44155\n44156\n44154\n44157\n44153\n44158\n44152\n44159\n44151\n44160\n44150\n44161\n44149\n44162\n44148\n44163\n44147\n44164\n44146\n44165\n44145\n44166\n44144\n44167\n44143\n44168\n44142\n44169\n44141\n44170\n44140\n44171\n44139\n44172\n44138\n44173\n44137\n44174\n44136\n44175\n44135\n44176\n44134\n44177\n44133\n44178\n44132\n44179\n44131\n44180\n44130\n44181\n44129\n44182\n44128\n44183\n44127\n44184\n44126\n44185\n44125\n44186\n44124\n44187\n44123\n44188\n44122\n44189\n44121\n44190\n44120\n44191\n44119\n..."
}
] | 186 | 6,963,200 | 0 | 1,413 |
|
913 | Party Lemonade | [
"bitmasks",
"dp",
"greedy"
] | null | null | A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.
Your favorite store sells lemonade in bottles of *n* different volumes at different costs. A single bottle of type *i* has volume 2*i*<=-<=1 liters and costs *c**i* roubles. The number of bottles of each type in the store can be considered infinite.
You want to buy at least *L* liters of lemonade. How many roubles do you have to spend? | The first line contains two integers *n* and *L* (1<=β€<=*n*<=β€<=30; 1<=β€<=*L*<=β€<=109) β the number of types of bottles in the store and the required amount of lemonade in liters, respectively.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=β€<=*c**i*<=β€<=109) β the costs of bottles of different types. | Output a single integer β the smallest number of roubles you have to pay in order to buy at least *L* liters of lemonade. | [
"4 12\n20 30 70 90\n",
"4 3\n10000 1000 100 10\n",
"4 3\n10 100 1000 10000\n",
"5 787787787\n123456789 234567890 345678901 456789012 987654321\n"
] | [
"150\n",
"10\n",
"30\n",
"44981600785557577\n"
] | In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.
In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.
In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles. | [
{
"input": "4 12\n20 30 70 90",
"output": "150"
},
{
"input": "4 3\n10000 1000 100 10",
"output": "10"
},
{
"input": "4 3\n10 100 1000 10000",
"output": "30"
},
{
"input": "5 787787787\n123456789 234567890 345678901 456789012 987654321",
"output": "44981600785557577"
},
{
"input": "30 792520535\n528145579 682850171 79476920 178914057 180053263 538638086 433143781 299775597 723428544 177615223 959893339 639448861 506106572 807471834 42398440 347390133 65783782 988164990 606389825 877178711 513188067 609539702 558894975 271129128 956393790 981348376 608410525 61890513 991440277 682151552",
"output": "371343078"
},
{
"input": "30 719520853\n1 3 7 9 21 44 81 49 380 256 1592 1523 4711 6202 1990 48063 112547 210599 481862 1021025 2016280 643778 4325308 3603826 20964534 47383630 100267203 126018116 187142230 604840362",
"output": "87393281"
},
{
"input": "30 604179824\n501412684 299363783 300175300 375965822 55881706 96888084 842141259 269152598 954400269 589424644 244226611 443088309 914941214 856763895 380059734 9424058 97467018 912446445 609122261 773853033 728987202 239388430 617092754 182847275 385882428 86295843 416876980 952408652 399750639 326299418",
"output": "564859510"
},
{
"input": "1 1000000000\n1000000000",
"output": "1000000000000000000"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "30 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "5 25\n52 91 84 66 93",
"output": "186"
},
{
"input": "10 660\n2316 3782 9667 4268 4985 2256 6854 9312 4388 9913",
"output": "13164"
},
{
"input": "20 807689532\n499795319 630489472 638483114 54844847 209402053 71113129 931903630 213385792 726471950 950559532 396028074 711222849 458354548 937511907 247071934 160971961 333550064 4453536 857363099 464797922",
"output": "27447142368"
},
{
"input": "30 842765745\n2 2 2 4 6 8 12 12 18 28 52 67 92 114 191 212 244 459 738 1078 1338 1716 1860 1863 2990 4502 8575 11353 12563 23326",
"output": "42251"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "1 1000000000\n1",
"output": "1000000000"
},
{
"input": "30 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "30 1000000000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "30 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "1 570846883\n300888960",
"output": "171761524945111680"
},
{
"input": "2 245107323\n357416000 761122471",
"output": "87605278957368000"
},
{
"input": "3 624400466\n824008448 698922561 760128125",
"output": "118656089186285061"
},
{
"input": "5 972921345\n496871039 134331253 959524096 747165691 981088452",
"output": "59657618590751221"
},
{
"input": "8 700735368\n931293374 652764228 183746499 853268148 653623691 684604018 902322304 186452621",
"output": "1020734127854016"
},
{
"input": "13 695896744\n495801986 946818643 421711713 151976207 616318787 713653645 893406153 42255449 871957806 865208878 547381951 478062469 516417162",
"output": "87737726572314"
},
{
"input": "21 186982676\n261355063 273322266 663309548 981847874 432074163 204617748 86151188 381783810 725544703 947880176 870951660 226330358 680228931 959825764 972157951 874066182 208942221 587976360 749662969 377541340 841644620",
"output": "134782258380"
},
{
"input": "29 140874704\n948286516 335531500 165926134 633474522 606947099 21370216 16126534 254131475 624116869 824903957 541685498 351709345 925541565 253434732 759289345 168754543 993046389 636985579 332772332 103110829 311797311 739860627 233674609 950017614 387656468 939870312 161573356 176555912 592529105",
"output": "338129268"
},
{
"input": "6 566613866\n1 3 3 16 11 13",
"output": "230186887"
},
{
"input": "11 435675771\n2 2 2 4 4 5 5 8 10 18 21",
"output": "8934765"
},
{
"input": "13 688240686\n2 4 1 15 7 1 34 129 295 905 1442 1198 3771",
"output": "21507522"
},
{
"input": "15 645491742\n2 2 2 2 3 3 4 8 10 14 19 37 42 74 84",
"output": "3309432"
},
{
"input": "29 592983020\n2 3 7 8 30 45 125 132 124 61 1231 1626 7470 14538 18828 35057 34820 219967 359159 362273 1577550 2434174 1736292 15104217 17689384 39467552 50809520 13580992 414752454",
"output": "61009202"
},
{
"input": "29 42473833\n13 18 21 32 45 72 134 203 320 342 400 565 1039 1093 2142 3383 5360 7894 13056 17053 26524 38453 63285 102775 156618 252874 304854 600862 857837",
"output": "304854"
},
{
"input": "28 48504243\n1 1 6 1 32 37 125 212 187 676 1679 771 485 9030 1895 26084 109430 96769 257473 383668 645160 1550917 6195680 6309095 16595706 13231037 99591007 255861473",
"output": "5610124"
},
{
"input": "28 17734553\n13 22 33 59 93 164 166 308 454 532 771 898 1312 2256 3965 5207 6791 13472 13793 26354 47030 68133 118082 199855 221897 257395 417525 536230",
"output": "257395"
},
{
"input": "27 358801274\n2 3 6 10 2 30 124 35 249 268 79 4013 1693 3522 17730 17110 52968 235714 155787 405063 1809923 667660 2266461 14291190 15502027 54103386 14154765",
"output": "27680968"
},
{
"input": "27 437705674\n13 13 21 21 25 31 49 83 148 243 246 263 268 282 475 867 1709 3333 4587 5947 11467 22629 25843 31715 34392 45690 47657",
"output": "333599"
},
{
"input": "26 519355202\n2 2 6 3 4 23 124 115 312 883 526 3158 2901 14398 797 8137 127577 112515 54101 426458 877533 3978708 6725849 5496068 14408348 27866871",
"output": "25264103"
},
{
"input": "26 707933691\n13 17 31 44 69 70 89 158 246 320 605 934 1635 2364 4351 8660 10262 11664 14090 18908 35845 51033 59963 78775 117479 179510",
"output": "3829673"
},
{
"input": "25 269843721\n1 4 5 12 6 16 123 195 374 475 974 2303 4109 8890 16632 64699 71115 251461 476703 447854 2042296 3095451 2796629 13478163 13314670",
"output": "101191398"
},
{
"input": "25 978161707\n13 22 24 34 66 73 145 287 289 521 693 996 1230 1486 1517 2663 3770 3776 5286 7953 15775 30877 42848 84850 114828",
"output": "6718647"
},
{
"input": "5 304398130\n328619601 758941829 198270024 713154224 371680309",
"output": "7071174590398871"
},
{
"input": "10 354651161\n676522959 11809337 625434179 312329830 399019943 545095979 566206452 292370104 819250687 361397475",
"output": "250332233709431"
},
{
"input": "10 907948615\n369010656 907829481 622481545 200317148 960270397 26028213 655060035 796833494 123373353 324969455",
"output": "437565141462561"
},
{
"input": "10 590326547\n540224591 578261545 271951966 787805881 165741203 795359732 547118852 746648763 284153835 602102300",
"output": "655248513971940"
},
{
"input": "20 264504887\n256244331 292829612 807171068 120710 900798902 214013876 575261859 40214283 293542999 366877272 353675296 705322168 205009788 86530854 620744650 766826836 240331588 700218303 406369581 649737981",
"output": "327898333295"
},
{
"input": "20 749478720\n148277091 195065491 92471169 473441125 104827125 387256363 959435633 241640 395794406 734016994 107553118 129783960 812331272 999596018 837854100 215240378 598412225 653614923 933185587 845929351",
"output": "1209345077739"
},
{
"input": "20 628134337\n706690396 73852246 47785764 655257266 217430459 211108098 623632685 631391825 628008556 962083938 616573502 326152383 7023992 288143889 264733804 886206130 342256543 779010688 657787839 476634612",
"output": "571078505096"
},
{
"input": "20 708413057\n985177466 224645388 772550594 994150052 856456221 65855795 599129505 903908498 200612104 575185982 507918207 574454347 607410366 738301336 274020952 556522307 665003603 363184479 760246523 952436964",
"output": "1287105522843"
},
{
"input": "20 228553575\n966247381 207786628 69006100 269956897 359963312 510868514 95130877 473280024 180071136 34097367 898985854 981155909 369570614 803892852 773207504 603654899 500850166 632114017 442730466 348136258",
"output": "151787408488"
},
{
"input": "25 975185569\n680624205 925575600 711019438 10306 879760994 355425133 204004301 536007340 585477874 216944098 296555029 104013726 892946593 309410720 689188172 687796636 375461496 689356349 680367324 137692780 879054435 925597905 677631315 592123801 742526898",
"output": "43630079726"
},
{
"input": "30 16804972\n38413642 603358594 93465125 772633637 516421484 75369617 249460374 6747 89975200 3230679 944379663 407211965 820471861 763861258 4711346 787274019 447412797 861015104 104795044 430023687 445411345 316560503 908322702 232775431 33149898 101978638 453254685 587956325 920401353 237657930",
"output": "34613997"
},
{
"input": "30 939625169\n799744449 316941501 911543330 868167665 272876554 951480855 826347879 102948940 684991931 833689399 277289558 186462 220073415 602419892 22234767 320279157 908288280 357866038 758158565 784960311 772460297 956631291 623631325 328145434 76400621 637950037 63094834 358429163 210185094 824743978",
"output": "766068050"
},
{
"input": "30 649693919\n523756282 905125099 661420695 854128708 504404014 33547776 632846834 593955985 19432317 644543651 552904895 988070696 321825330 923971248 718082642 900061181 310986828 14810582 525301 623288859 578749693 424452633 901712228 411022879 757920556 825042513 796572495 544557755 747250675 987028137",
"output": "1213432868"
},
{
"input": "30 941342434\n719914212 905507045 191898825 570606628 687781371 937025497 673960221 557202851 29071681 518803370 894863536 212709126 614432746 924724833 699415275 748075226 796159664 198063404 56538360 649136911 46540367 337023198 45896775 548611961 777908744 873523820 99863819 335685200 503317538 894159729",
"output": "1443990241"
},
{
"input": "30 810430346\n807519316 377786333 874568334 100500951 872031247 252690899 923103133 769288634 300502982 184749135 481527896 932556233 978317077 980235169 677287 308980653 527243473 763242606 219639015 712288933 901059456 30978091 127839849 9946626 456644060 226102694 611552752 816642473 434613587 723611518",
"output": "964822722"
},
{
"input": "30 187125289\n660214771 614231774 943973836 50780694 214277957 695192266 425421684 100830325 236002350 233594142 318777769 611117973 758216803 141783036 487402819 42225289 132824573 354540681 64152506 838447015 853800951 605421421 151364012 455396619 928950961 236389207 47829341 743089941 577129072 792900471",
"output": "143488023"
},
{
"input": "30 129428748\n954910836 756938357 407311375 992660029 134837594 230127140 815239978 545145316 559077075 373018190 923169774 981420723 349998683 971610245 428903049 879106876 229199860 842029694 817413103 141736569 236414627 263122579 394309719 946134085 550877425 544748100 732982715 933907937 67960170 145090225",
"output": "67960170"
},
{
"input": "30 12544876\n528459681 350718911 432940853 266976578 679316371 959899124 158423966 471112176 136348553 752311334 979696813 624253517 374825117 338804760 506350966 717644199 528671610 10427712 256677344 288800318 711338213 778230088 616184102 968447942 275963441 257842321 753599064 812398057 815035849 207576747",
"output": "207576747"
},
{
"input": "30 7\n476599619 58464676 796410905 224866489 780155470 404375041 576176595 767831428 598766545 225605178 819316136 781962412 217423411 484904923 194288977 597593185 181464481 65918422 225080972 53705844 584415879 463767806 845989273 434760924 477902363 145682570 721445310 803966515 927906514 191883417",
"output": "53705844"
},
{
"input": "30 9324\n205304890 806562207 36203756 437374231 230840114 828741258 227108614 937997270 74150322 673068857 353683258 757136864 274921753 418595773 638411312 307919005 304470011 439118457 402187013 371389195 981316766 26764964 293610954 177952828 49223547 718589642 982551043 395151318 564895171 138874187",
"output": "26764964"
},
{
"input": "30 512443535\n2 10 30 20 26 9 2 4 24 25 4 27 27 9 13 30 30 5 3 24 10 4 14 14 8 3 2 22 25 25",
"output": "16"
},
{
"input": "30 553648256\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913",
"output": "553648259"
},
{
"input": "30 536870912\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913",
"output": "536870913"
},
{
"input": "30 504365056\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913",
"output": "504365061"
},
{
"input": "30 536870913\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913",
"output": "536870915"
},
{
"input": "30 536870911\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913",
"output": "536870913"
},
{
"input": "30 571580555\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913",
"output": "571580565"
},
{
"input": "1 1000000000\n1",
"output": "1000000000"
},
{
"input": "4 8\n8 4 4 1",
"output": "1"
},
{
"input": "2 3\n10 1",
"output": "2"
},
{
"input": "30 915378355\n459233266 779915330 685344552 78480977 949046834 774589421 94223415 727865843 464996500 268056254 591348850 753027575 142328565 174597246 47001711 810641112 130836837 251339580 624876035 850690451 290550467 119641933 998066976 791349365 549089363 492937533 140746908 265213422 27963549 109184295",
"output": "111854196"
},
{
"input": "3 7\n20 20 30",
"output": "60"
},
{
"input": "1 1000000000\n1000000000",
"output": "1000000000000000000"
},
{
"input": "5 787787787\n1 2 3 4 5",
"output": "246183685"
},
{
"input": "2 3\n10 5",
"output": "10"
},
{
"input": "28 146201893\n79880639 962577454 837935105 770531287 992949199 401766756 805281924 931353274 246173135 378375823 456356972 120503545 811958850 126793843 720341477 413885800 272086545 758855930 979214555 491838924 465216943 706180852 786946242 646685999 436847726 625436 360241773 620056496",
"output": "3127180"
},
{
"input": "5 9\n2 100 100 10 13",
"output": "12"
},
{
"input": "1 134217728\n1000000000",
"output": "134217728000000000"
},
{
"input": "1 536870912\n1000000000",
"output": "536870912000000000"
},
{
"input": "5 5\n34 22 21 20 30",
"output": "20"
},
{
"input": "1 787787787\n1",
"output": "787787787"
},
{
"input": "7 7\n34 22 21 20 30 20 20",
"output": "20"
},
{
"input": "5 5\n34 22 21 25 30",
"output": "25"
},
{
"input": "5 787787787\n123456789 234567890 345678901 456789012 1",
"output": "49236737"
},
{
"input": "6 6\n34 22 21 25 30 35",
"output": "25"
}
] | 140 | 20,172,800 | 0 | 1,415 |
|
697 | Barnicle | [
"brute force",
"implementation",
"math",
"strings"
] | null | null | Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number *x* is the notation of form *AeB*, where *A* is a real number and *B* is an integer and *x*<==<=*A*<=Γ<=10*B* is true. In our case *A* is between 0 and 9 and *B* is non-negative.
Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding. | The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=β€<=*a*<=β€<=9,<=0<=β€<=*d*<=<<=10100,<=0<=β€<=*b*<=β€<=100) β the scientific notation of the desired distance value.
*a* and *b* contain no leading zeros and *d* contains no trailing zeros (but may be equal to 0). Also, *b* can not be non-zero if *a* is zero. | Print the only real number *x* (the desired distance value) in the only line in its decimal notation.
Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.
Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroes (but may be equal to zero), and *q* is an integer that have no trailing zeroes (and may not be equal to zero). | [
"8.549e2\n",
"8.549e3\n",
"0.33e0\n"
] | [
"854.9\n",
"8549\n",
"0.33\n"
] | none | [
{
"input": "8.549e2",
"output": "854.9"
},
{
"input": "8.549e3",
"output": "8549"
},
{
"input": "0.33e0",
"output": "0.33"
},
{
"input": "1.31e1",
"output": "13.1"
},
{
"input": "1.038e0",
"output": "1.038"
},
{
"input": "8.25983e5",
"output": "825983"
},
{
"input": "8.77056e6",
"output": "8770560"
},
{
"input": "4.28522890224373996236468418851564462623381500262405e30",
"output": "4285228902243739962364684188515.64462623381500262405"
},
{
"input": "4.09336275522154223604344399571355118601483591618747e85",
"output": "40933627552215422360434439957135511860148359161874700000000000000000000000000000000000"
},
{
"input": "2.0629094807595491132306264747042243928486303384791951220362096240931158821630792563855724946791054152e85",
"output": "20629094807595491132306264747042243928486303384791951220362096240931158821630792563855.724946791054152"
},
{
"input": "0.7e0",
"output": "0.7"
},
{
"input": "0.75e0",
"output": "0.75"
},
{
"input": "0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451e0",
"output": "0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451"
},
{
"input": "0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197e0",
"output": "0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197"
},
{
"input": "1.7282220592677586155528202123627915992640276211396528871e0",
"output": "1.7282220592677586155528202123627915992640276211396528871"
},
{
"input": "1.91641639840522198229453882518758458881136053577016034847369545687354908120008812644841021662133251e89",
"output": "191641639840522198229453882518758458881136053577016034847369545687354908120008812644841021.662133251"
},
{
"input": "7.0e100",
"output": "70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1.7390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051e100",
"output": "17390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051"
},
{
"input": "4.6329496401734172195e50",
"output": "463294964017341721950000000000000000000000000000000"
},
{
"input": "2.806303180541991592302230754797823269634e39",
"output": "2806303180541991592302230754797823269634"
},
{
"input": "5.8743505652112692964508303637002e64",
"output": "58743505652112692964508303637002000000000000000000000000000000000"
},
{
"input": "6.8778661934058405217475274375560252344373481358834598914724956711e31",
"output": "68778661934058405217475274375560.252344373481358834598914724956711"
},
{
"input": "9.4e100",
"output": "94000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "3.2371070627618799335840070613481911588919091676203766004638236894609230433739617153911544972468224113e50",
"output": "323710706276187993358400706134819115889190916762037.66004638236894609230433739617153911544972468224113"
},
{
"input": "4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929e0",
"output": "4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929"
},
{
"input": "7.7060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625e1",
"output": "77.060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625"
},
{
"input": "8.1089882894234341219420177467603732503076124872188628349726911362800974096687340341040683238197289136e31",
"output": "81089882894234341219420177467603.732503076124872188628349726911362800974096687340341040683238197289136"
},
{
"input": "9.6576660076120385279859051742522204516365367878315639937449558670629833997839913220859648564428655877e99",
"output": "9657666007612038527985905174252220451636536787831563993744955867062983399783991322085964856442865587.7"
},
{
"input": "0.0e0",
"output": "0"
},
{
"input": "1.0e0",
"output": "1"
},
{
"input": "8.0e0",
"output": "8"
},
{
"input": "3.0e0",
"output": "3"
},
{
"input": "4.0e0",
"output": "4"
},
{
"input": "2.0e0",
"output": "2"
},
{
"input": "9.0e0",
"output": "9"
},
{
"input": "0.888888e0",
"output": "0.888888"
},
{
"input": "9.99999999999999999999999999999999999999999999999999999999999999999999999999999999e100",
"output": "99999999999999999999999999999999999999999999999999999999999999999999999999999999900000000000000000000"
},
{
"input": "5.0e0",
"output": "5"
},
{
"input": "1.0e10",
"output": "10000000000"
},
{
"input": "1.0e5",
"output": "100000"
},
{
"input": "6.0e0",
"output": "6"
},
{
"input": "1.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e1",
"output": "11.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
}
] | 140 | 7,270,400 | 3 | 1,419 |
|
387 | George and Sleep | [
"implementation"
] | null | null | George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample). | The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" β the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=β€<=*hh*<=β€<=23, 00<=β€<=*mm*<=β€<=59. | In the single line print time *p* β the time George went to bed in the format similar to the format of the time in the input. | [
"05:50\n05:44\n",
"00:00\n01:00\n",
"00:01\n00:00\n"
] | [
"00:06\n",
"23:00\n",
"00:01\n"
] | In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all. | [
{
"input": "05:50\n05:44",
"output": "00:06"
},
{
"input": "00:00\n01:00",
"output": "23:00"
},
{
"input": "00:01\n00:00",
"output": "00:01"
},
{
"input": "23:59\n23:59",
"output": "00:00"
},
{
"input": "23:44\n23:55",
"output": "23:49"
},
{
"input": "00:00\n13:12",
"output": "10:48"
},
{
"input": "12:00\n23:59",
"output": "12:01"
},
{
"input": "12:44\n12:44",
"output": "00:00"
},
{
"input": "05:55\n07:12",
"output": "22:43"
},
{
"input": "07:12\n05:55",
"output": "01:17"
},
{
"input": "22:22\n22:22",
"output": "00:00"
},
{
"input": "22:22\n22:23",
"output": "23:59"
},
{
"input": "23:24\n23:23",
"output": "00:01"
},
{
"input": "00:00\n00:00",
"output": "00:00"
},
{
"input": "23:30\n00:00",
"output": "23:30"
},
{
"input": "01:00\n00:00",
"output": "01:00"
},
{
"input": "05:44\n06:00",
"output": "23:44"
},
{
"input": "00:00\n23:59",
"output": "00:01"
},
{
"input": "21:00\n01:00",
"output": "20:00"
},
{
"input": "21:21\n12:21",
"output": "09:00"
},
{
"input": "12:21\n21:12",
"output": "15:09"
},
{
"input": "12:33\n23:33",
"output": "13:00"
},
{
"input": "07:55\n05:53",
"output": "02:02"
},
{
"input": "19:30\n02:00",
"output": "17:30"
},
{
"input": "21:30\n02:00",
"output": "19:30"
},
{
"input": "19:30\n09:30",
"output": "10:00"
},
{
"input": "13:08\n00:42",
"output": "12:26"
},
{
"input": "13:04\n09:58",
"output": "03:06"
},
{
"input": "21:21\n23:06",
"output": "22:15"
},
{
"input": "20:53\n10:23",
"output": "10:30"
},
{
"input": "12:59\n00:45",
"output": "12:14"
},
{
"input": "12:39\n22:21",
"output": "14:18"
},
{
"input": "21:10\n13:50",
"output": "07:20"
},
{
"input": "03:38\n23:46",
"output": "03:52"
},
{
"input": "03:48\n00:41",
"output": "03:07"
},
{
"input": "07:43\n12:27",
"output": "19:16"
},
{
"input": "03:23\n08:52",
"output": "18:31"
},
{
"input": "16:04\n10:28",
"output": "05:36"
},
{
"input": "12:53\n08:37",
"output": "04:16"
},
{
"input": "13:43\n17:23",
"output": "20:20"
},
{
"input": "00:00\n00:01",
"output": "23:59"
},
{
"input": "10:10\n01:01",
"output": "09:09"
},
{
"input": "10:05\n00:00",
"output": "10:05"
},
{
"input": "09:09\n00:00",
"output": "09:09"
},
{
"input": "09:10\n00:01",
"output": "09:09"
},
{
"input": "23:24\n00:28",
"output": "22:56"
},
{
"input": "10:00\n01:00",
"output": "09:00"
}
] | 109 | 6,656,000 | 3 | 1,422 |
|
347 | Fixed Points | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 β the given permutation. | Print a single integer β the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34 73 29 70 83 58 79 82 28 77 67",
"output": "3"
},
{
"input": "3\n0 1 2",
"output": "3"
},
{
"input": "3\n2 1 0",
"output": "3"
},
{
"input": "3\n1 2 0",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 1 2 3 4",
"output": "5"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "7\n0 1 2 4 3 6 5",
"output": "5"
},
{
"input": "6\n0 1 2 3 5 4",
"output": "6"
}
] | 342 | 33,382,400 | 0 | 1,426 |
|
803 | Magazine Ad | [
"binary search",
"greedy"
] | null | null | The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more than one hyphen.
It is guaranteed that there are no adjacent spaces and no adjacent hyphens. No hyphen is adjacent to space. There are no spaces and no hyphens before the first word and after the last word.
When the word is wrapped, the part of the word before hyphen and the hyphen itself stay on current line and the next part of the word is put on the next line. You can also put line break between two words, in that case the space stays on current line. Check notes for better understanding.
The ad can occupy no more that *k* lines and should have minimal width. The width of the ad is the maximal length of string (letters, spaces and hyphens are counted) in it.
You should write a program that will find minimal width of the ad. | The first line contains number *k* (1<=β€<=*k*<=β€<=105).
The second line contains the text of the ad β non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed 106 characters. | Output minimal width of the ad. | [
"4\ngarage for sa-le\n",
"4\nEdu-ca-tion-al Ro-unds are so fun\n"
] | [
"7\n",
"10\n"
] | Here all spaces are replaced with dots.
In the first example one of possible results after all word wraps looks like this:
The second example: | [
{
"input": "4\ngarage for sa-le",
"output": "7"
},
{
"input": "4\nEdu-ca-tion-al Ro-unds are so fun",
"output": "10"
},
{
"input": "1\nj",
"output": "1"
},
{
"input": "10\nb",
"output": "1"
},
{
"input": "1\nQGVsfZevMD",
"output": "10"
},
{
"input": "1\nqUOYCytbKgoGRgaqhjrohVRxKTKjjOUPPnEjiXJWlvpCyqiRzbnpyNqDylWverSTrcgZpEoDKhJCrOOvsuXHzkPtbXeKCKMwUTVk",
"output": "100"
},
{
"input": "100000\nBGRHXGrqgjMxCBCdQTCpQyHNMkraTRxhyZBztkxXNFEKnCNjHWeCWmmrRjiczJAdfQqdQfnuupPqzRhEKnpuTCsVPNVTIMiuiQUJ",
"output": "100"
},
{
"input": "1\nrHPBSGKzxoSLerxkDVxJG PfUqVrdSdOgJBySsRHYryfLKOvIcU",
"output": "51"
},
{
"input": "2\nWDJDSbGZbGLcDB-GuDJxmjHEeruCdJNdr wnEbYVxUZbgfjEHlHx",
"output": "34"
},
{
"input": "2\nZeqxDLfPrSzHmZMjwSIoGeEdkWWmyvMqYkaXDzOeoFYRwFGamjYbjKYCIyMgjYoxhKnAQHmGAhkwIoySySumVOYmMDBYXDYkmwErqCrjZWkSisPtNczKRofaLOaJhgUbVOtZqjoJYpCILTmGkVpzCiYETFdgnTbTIVCqAoCZqRhJvWrBZjaMqicyLwZNRMfOFxjxDfNatDFmpmOyOQyGdiTvnprfkWGiaFdrwFVYKOrviRXdhYTdIfEjfzhb HrReddDwSntvOGtnNQFjoOnNDdAejrmNXxDmUdWTKTynngKTnHVSOiZZhggAbXaksqKyxuhhjisYDfzPLtTcKBZJCcuGLjhdZcgbrYQtqPnLoMmCKgusOmkLbBKGnKAEvgeLVmzwaYjvcyCZfngSJBlZwDimHsCctSkAhgqakEvXembgLVLbPfcQsmgxTCgCvSNliSyroTYpRmJGCwQlfcKXoptvkrYijULaUKWeVoaFTBFQvinGXGRj",
"output": "253"
},
{
"input": "2\nWjrWBWqKIeSndDHeiVmfChQNsoUiRQHVplnIWkwBtxAJhOdTigAAzKtbNEqcgvbWHOopfCNgWHfwXyzSCfNqGMLnmlIdKQonLsmGSJlPBcYfHNJJDGlKNnOGtrWUhaTWuilHWMUlFEzbJYbeAWvgnSOOOPLxX-eJEKRsKqSnMjrPbFDprCqgbTfwAnPjFapVKiTjCcWEzhahwPRHScfcLnUixnxckQJzuHzshyBFKPwVGzHeJWniiRKynDFQdaazmTZtDGnFVTmTUZCRCpUHFmUHAVtEdweCImRztqrkQInyCsnMnYBbjjAdKZjXzyPGS TUZjnPyjnjyRCxfKkvpNicAzGqKQgiRreJIMVZPuKyFptrqhgIeWwpZFYetHqvZKUIscYuQttIRNuklmgqRYhbCWPgXpEygxYWMggVbQbiWNNBFMxRoPIRxcBLhayOizbixIRgaXczSibmlTnnYsnlltfDDwPolEIsjPilMiQQjUGeEyAWES",
"output": "322"
},
{
"input": "10\nIBgDZeAHSUFhJxcZkQKqaTZT gqErHjXUahQpfDTcZZW nhLsPIrfflZWnwiQEWpt dcTGNMjzkuWNIVXrshBowdQ ugLvpovZZVWryM",
"output": "25"
},
{
"input": "10\nlELWTeKqHCohtEOB PLhjMMwfpFlcnfft nWGsnztStldkrbGkJZz EtSrgwffzJSspzWpoMXGK-jmbVygQC BoIwaGSYKRsgmxBVwkoa",
"output": "22"
},
{
"input": "100000\nBvbikpOjCTXWr-zqGzpEGswptPksN IsJVeilKfqoiicTMcmZeduDs KtZKEFZQztKq ynKDcPxbVfOKrjxAfQvKIIR HlsgVUeeGvfSc",
"output": "25"
},
{
"input": "10\nTQEKPQiFXCqY iugCuECYdemF RqdrrpurDgeYK-fLJIgvtgWkPHma-kqoGdxPXvloehNNire JShAkvoJxjDMEoHiOp nHgyCAQMfiQSz",
"output": "19"
},
{
"input": "4\na-aa",
"output": "2"
},
{
"input": "6\na aa-aaa-aa a-aaa-a",
"output": "5"
},
{
"input": "4\nasd asd asd asdf",
"output": "4"
}
] | 1,000 | 13,619,200 | 0 | 1,427 |
|
639 | Bear and Forgotten Tree 3 | [
"constructive algorithms",
"graphs",
"trees"
] | null | null | A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree β he can tell you only three values *n*, *d* and *h*:
- The tree had exactly *n* vertices. - The tree had diameter *d*. In other words, *d* was the biggest distance between two vertices. - Limak also remembers that he once rooted the tree in vertex 1 and after that its height was *h*. In other words, *h* was the biggest distance between vertex 1 and some other vertex.
The distance between two vertices of the tree is the number of edges on the simple path between them.
Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree β in this case print "-1". | The first line contains three integers *n*, *d* and *h* (2<=β€<=*n*<=β€<=100<=000,<=1<=β€<=*h*<=β€<=*d*<=β€<=*n*<=-<=1) β the number of vertices, diameter, and height after rooting in vertex 1, respectively. | If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes).
Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers β indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order. | [
"5 3 2\n",
"8 5 2\n",
"8 4 2\n"
] | [
"1 2\n1 3\n3 4\n3 5",
"-1\n",
"4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n"
] | Below you can see trees printed to the output in the first sample and the third sample. | [
{
"input": "5 3 2",
"output": "1 2\n2 3\n1 4\n5 1"
},
{
"input": "8 5 2",
"output": "-1"
},
{
"input": "8 4 2",
"output": "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5"
},
{
"input": "2 1 1",
"output": "1 2"
},
{
"input": "10 3 3",
"output": "1 2\n2 3\n3 4\n5 2\n6 2\n7 2\n8 2\n9 2\n10 2"
},
{
"input": "15 6 4",
"output": "1 2\n2 3\n3 4\n4 5\n1 6\n6 7\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1"
},
{
"input": "16 15 14",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n1 16"
},
{
"input": "1000 51 25",
"output": "-1"
},
{
"input": "100000 10 7",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n1 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..."
},
{
"input": "3 1 1",
"output": "-1"
},
{
"input": "3 2 1",
"output": "1 2\n1 3"
},
{
"input": "3 2 2",
"output": "1 2\n2 3"
},
{
"input": "4 1 1",
"output": "-1"
},
{
"input": "4 2 1",
"output": "1 2\n1 3\n4 1"
},
{
"input": "4 2 2",
"output": "1 2\n2 3\n4 2"
},
{
"input": "4 3 1",
"output": "-1"
},
{
"input": "4 3 2",
"output": "1 2\n2 3\n1 4"
},
{
"input": "4 3 3",
"output": "1 2\n2 3\n3 4"
},
{
"input": "8 5 3",
"output": "1 2\n2 3\n3 4\n1 5\n5 6\n7 1\n8 1"
},
{
"input": "20 19 19",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20"
},
{
"input": "30 14 14",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2"
},
{
"input": "33 5 3",
"output": "1 2\n2 3\n3 4\n1 5\n5 6\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1"
},
{
"input": "5432 200 100",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "5433 200 99",
"output": "-1"
},
{
"input": "99999 1 1",
"output": "-1"
},
{
"input": "99999 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "99999 7 4",
"output": "1 2\n2 3\n3 4\n4 5\n1 6\n6 7\n7 8\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "9999 7 3",
"output": "-1"
},
{
"input": "100000 1 1",
"output": "-1"
},
{
"input": "100000 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "100000 2 2",
"output": "1 2\n2 3\n4 2\n5 2\n6 2\n7 2\n8 2\n9 2\n10 2\n11 2\n12 2\n13 2\n14 2\n15 2\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2\n31 2\n32 2\n33 2\n34 2\n35 2\n36 2\n37 2\n38 2\n39 2\n40 2\n41 2\n42 2\n43 2\n44 2\n45 2\n46 2\n47 2\n48 2\n49 2\n50 2\n51 2\n52 2\n53 2\n54 2\n55 2\n56 2\n57 2\n58 2\n59 2\n60 2\n61 2\n62 2\n63 2\n64 2\n65 2\n66 2\n67 2\n68 2\n69 2\n70 2\n71 2\n72 2\n73 2\n74 2\n75 2\n76 2\n77 2\n78 2\n79 2\n80 2\n81 2\n82 2\n83 2\n84 2\n85 2\n86 2\n87 2\n88 ..."
},
{
"input": "100000 3 1",
"output": "-1"
},
{
"input": "100000 10 5",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n1 7\n7 8\n8 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..."
},
{
"input": "100000 10 6",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..."
},
{
"input": "100000 10 9",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n1 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "100000 10 10",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n12 2\n13 2\n14 2\n15 2\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2\n31 2\n32 2\n33 2\n34 2\n35 2\n36 2\n37 2\n38 2\n39 2\n40 2\n41 2\n42 2\n43 2\n44 2\n45 2\n46 2\n47 2\n48 2\n49 2\n50 2\n51 2\n52 2\n53 2\n54 2\n55 2\n56 2\n57 2\n58 2\n59 2\n60 2\n61 2\n62 2\n63 2\n64 2\n65 2\n66 2\n67 2\n68 2\n69 2\n70 2\n71 2\n72 2\n73 2\n74 2\n75 2\n76 2\n77 2\n78 2\n79 2\n80 2\n81 2\n82 2\n83 2\n84 2\n85 2\n86 2\n87 2\n88..."
},
{
"input": "100000 99900 78900",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 1",
"output": "-1"
},
{
"input": "100000 99998 49999",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 50000",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 69001",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 99055",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99998 99998",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 1",
"output": "-1"
},
{
"input": "100000 99999 49999",
"output": "-1"
},
{
"input": "100000 99999 50000",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 50001",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 77777",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 99998",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "100000 99999 99999",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..."
},
{
"input": "3 1 1",
"output": "-1"
},
{
"input": "5 1 1",
"output": "-1"
},
{
"input": "10 1 1",
"output": "-1"
},
{
"input": "3 2 1",
"output": "1 2\n1 3"
},
{
"input": "8 1 1",
"output": "-1"
},
{
"input": "4 1 1",
"output": "-1"
},
{
"input": "6 1 1",
"output": "-1"
},
{
"input": "20 1 1",
"output": "-1"
},
{
"input": "5 2 1",
"output": "1 2\n1 3\n4 1\n5 1"
},
{
"input": "100 1 1",
"output": "-1"
},
{
"input": "10 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1"
},
{
"input": "100 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "47 1 1",
"output": "-1"
},
{
"input": "7 1 1",
"output": "-1"
},
{
"input": "4 2 1",
"output": "1 2\n1 3\n4 1"
},
{
"input": "5 2 2",
"output": "1 2\n2 3\n4 2\n5 2"
},
{
"input": "8 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1"
},
{
"input": "1000 1 1",
"output": "-1"
},
{
"input": "11 1 1",
"output": "-1"
},
{
"input": "15 2 1",
"output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1"
},
{
"input": "3 2 2",
"output": "1 2\n2 3"
},
{
"input": "8 2 2",
"output": "1 2\n2 3\n4 2\n5 2\n6 2\n7 2\n8 2"
}
] | 46 | 4,608,000 | 0 | 1,429 |
|
883 | Field of Wonders | [
"implementation",
"strings"
] | null | null | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows *m* words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these *m* words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. | The first line contains one integer *n* (1<=β€<=*n*<=β€<=50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length *n*, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer *m* (1<=β€<=*m*<=β€<=1000) β the number of words of length *n*, which Polycarpus knows. The following *m* lines contain the words themselves β *n*-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given *m* words. Before the current move Polycarp has told exactly the letters which are currently revealed. | Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | [
"4\na**d\n2\nabcd\nacbd\n",
"5\nlo*er\n2\nlover\nloser\n",
"3\na*a\n2\naaa\naba\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. | [
{
"input": "4\na**d\n2\nabcd\nacbd",
"output": "2"
},
{
"input": "5\nlo*er\n2\nlover\nloser",
"output": "0"
},
{
"input": "3\na*a\n2\naaa\naba",
"output": "1"
},
{
"input": "1\n*\n1\na",
"output": "1"
},
{
"input": "1\n*\n1\nz",
"output": "1"
},
{
"input": "1\n*\n2\na\nz",
"output": "0"
},
{
"input": "2\n**\n1\naa",
"output": "1"
},
{
"input": "2\n**\n1\nfx",
"output": "2"
},
{
"input": "2\n**\n2\nfx\nab",
"output": "0"
},
{
"input": "2\n**\n2\nfx\naf",
"output": "1"
},
{
"input": "2\na*\n2\naa\nab",
"output": "1"
},
{
"input": "4\na*b*\n2\nabbc\nadbd",
"output": "1"
},
{
"input": "4\na*b*\n3\nabbc\nadbd\nacbe",
"output": "0"
},
{
"input": "4\na*b*\n3\nabbc\nadbd\nacbd",
"output": "1"
},
{
"input": "3\n***\n2\naaa\nbbb",
"output": "0"
},
{
"input": "3\n***\n2\naab\nabb",
"output": "2"
},
{
"input": "3\n*a*\n4\naaa\ncac\naab\nbaa",
"output": "1"
},
{
"input": "42\n*****o*******t********************oo******\n10\nvcrccobltkeidtxhsxhccaslkjhfyeqsetoowaemso\nuimjsoxifamvctkgqmrwhyjrgmlydczzqjoobnnwch\nuvmjsoqizfavctkxemrpaycngmlyemzzqjoobszwbh\nusmjsoviskzvctkljmrlmylugmlydfzzqvoobzawgh\nfeqweodinkhiatqmfokaxwcmlmbmvskssyookgcrax\ntackfosjhxeqftkgjynbbedrczegtimuvooosypczy\nxanuvoeismzmctruyplxgmfcpyrpqopyctoozlquvg\nurmjsouirdrvctkepmrwjyaxgmlyzvzzqcoobjgwih\nuymjsogivzivctkydmrgwyavgmlyphzzquoobclwhh\nkodyeoyihylgrtrdwudrsyonmuhtxaqklcoolsaclu",
"output": "18"
},
{
"input": "50\n***********************************o**************\n5\nwrubnrgpqmduhgxtlxymsmcaiimivvypkkeouspglhzkfbpzcu\nfrubkrgplrduhgjuuxdmsgeaiimavvypkkeousulbhnkebpzcu\nwrubkrgpdrduhgfanxdmsufaiimgvvypkkeouwvsshikhbpzcu\nvhyfvnnobcguishyvuswkaxhkesgatuvbkyodxdrvlwwifiimd\nwrubwrgpvaduhgfnqxtmsjqaiimcvvypkkeouiqpyhckkbpzcu",
"output": "20"
},
{
"input": "10\n**********\n10\nmvsthotcmi\nhmivtctsmo\nmmcostthiv\ntmomihtsvc\nmottsivmch\nhtomvcsmit\nsvhmotmcti\nmitotmvhcs\nvomcttmish\ncmostitvmh",
"output": "8"
},
{
"input": "20\n********************\n1\nlaizpfbafxrugjcytfbs",
"output": "16"
},
{
"input": "50\n**************************************************\n1\nqgaeytghzvvtgeitpovqozyclectzcohivbggudhiylaecbdzq",
"output": "17"
},
{
"input": "50\n**************************************************\n2\nhvjbrfkhdaobruoptrrachzuvkxvvsckycfiroipqicoqvcqpr\nuirvabciccxdvpryroisvpoqvthrpurkzhoovcfqcjbhkarkqf",
"output": "20"
},
{
"input": "26\n**************************\n10\nevfsnczuiodgbhqmlypkjatxrw\nuapqfdtoxkzynlbrehgwismvjc\nwjuyacngtzmvhqelikxoprdfbs\nyjgstlkvrhoqadxwfbiucpznem\nvebnxtrlocgkajqmwfuiszhypd\nroaqchwlpvtzxymnbkjigfedsu\noxmwaqpcendihzkutsybrjgfvl\nbnfzlwcsagxojdiyktqvruemhp\npdjahwnvmouxgqlciktzrfeysb\nbznurcyefxiapgktmqwjvsdloh",
"output": "26"
},
{
"input": "26\n**************************\n1\nayvguplhjsoiencbkxdrfwmqtz",
"output": "26"
},
{
"input": "26\n*lmnotuvwxyzjkabcdehiqfgrs\n2\nblmnotuvwxyzjkabcdehiqfgrs\nplmnotuvwxyzjkabcdehiqfgrs",
"output": "1"
},
{
"input": "16\nx*d**s******xd*u\n22\nxfdeoshogyqjxdmu\nxvdvdsnwfwakxdyu\nxfdjoshftykjxdmu\nxfdcoshfwyajxdmu\nxfdfoshkmyajxdmu\nxfdyoshpoycjxdmu\nxmdhcswqnhxjxdtu\nxxdxwsoogqzwxdcu\nxxdhhsxqzciuxdfu\nxddcmswqzksqxdhu\nxfdtoshioyvjxdmu\nxsdxmsfmgjbyxdgu\nxadfssplfnlbxdru\nxndcasykmqmbxdru\nxrdxgszaisicxdlu\nxfdfoshhmypjxdmu\nxfdioshfiyhjxdmu\nxvdzysydlmyuxdnu\nxjdbqszgkuwhxdmu\nxfdfoshjyymjxdmu\nxgdjksubrmrfxdpu\nxkdshsfszixmxdcu",
"output": "2"
},
{
"input": "3\n*vt\n2\ncvt\nqvb",
"output": "1"
},
{
"input": "3\ntv*\n2\ntvc\nbvq",
"output": "1"
},
{
"input": "41\n*z*hjcxxdgkny*tc*rmaov***fra**efs*lbi*puw\n1\nqzqhjcxxdgknyqtcqrmaovqqqfraqqefsqlbiqpuw",
"output": "1"
},
{
"input": "48\n*h*i**ag**um**fuxvmxlj*dsyt*gb*dxkzp*brnelctkq*w\n1\nohoiooagooumoofuxvmxljodsytogbodxkzpobrnelctkqow",
"output": "1"
}
] | 62 | 6,041,600 | 3 | 1,434 |
|
353 | Find Maximum | [
"implementation",
"math",
"number theory"
] | null | null | Valera has array *a*, consisting of *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1, and function *f*(*x*), taking an integer from 0 to 2*n*<=-<=1 as its single argument. Value *f*(*x*) is calculated by formula , where value *bit*(*i*) equals one if the binary representation of number *x* contains a 1 on the *i*-th position, and zero otherwise.
For example, if *n*<==<=4 and *x*<==<=11 (11<==<=20<=+<=21<=+<=23), then *f*(*x*)<==<=*a*0<=+<=*a*1<=+<=*a*3.
Help Valera find the maximum of function *f*(*x*) among all *x*, for which an inequality holds: 0<=β€<=*x*<=β€<=*m*. | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the number of array elements. The next line contains *n* space-separated integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (0<=β€<=*a**i*<=β€<=104) β elements of array *a*.
The third line contains a sequence of digits zero and one without spaces *s*0*s*1... *s**n*<=-<=1 β the binary representation of number *m*. Number *m* equals . | Print a single integer β the maximum value of function *f*(*x*) for all . | [
"2\n3 8\n10\n",
"5\n17 0 10 2 1\n11010\n"
] | [
"3\n",
"27\n"
] | In the first test case *m*β=β2<sup class="upper-index">0</sup>β=β1,β*f*(0)β=β0,β*f*(1)β=β*a*<sub class="lower-index">0</sub>β=β3.
In the second sample *m*β=β2<sup class="upper-index">0</sup>β+β2<sup class="upper-index">1</sup>β+β2<sup class="upper-index">3</sup>β=β11, the maximum value of function equals *f*(5)β=β*a*<sub class="lower-index">0</sub>β+β*a*<sub class="lower-index">2</sub>β=β17β+β10β=β27. | [
{
"input": "2\n3 8\n10",
"output": "3"
},
{
"input": "5\n17 0 10 2 1\n11010",
"output": "27"
},
{
"input": "18\n4382 3975 9055 7554 8395 204 5313 5739 1555 2306 5423 828 8108 9736 2683 7940 1249 5495\n110001100101110111",
"output": "88691"
},
{
"input": "43\n475 2165 8771 7146 8980 7209 9170 9006 6278 6661 4740 6321 7532 6869 3788 7918 1707 5070 3809 5189 2494 8255 1123 3197 190 5712 9873 3286 9997 133 9030 3067 8043 5297 5398 4240 8315 2141 1436 3297 247 8438 2300\n0111011100100011110010011110011011010001101",
"output": "222013"
},
{
"input": "1\n0\n1",
"output": "0"
},
{
"input": "1\n1\n0",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "1"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "2\n10000 10000\n11",
"output": "20000"
},
{
"input": "2\n10000 9999\n10",
"output": "10000"
},
{
"input": "2\n9999 10000\n10",
"output": "9999"
},
{
"input": "2\n10000 10000\n00",
"output": "0"
}
] | 186 | 1,126,400 | 0 | 1,439 |
|
169 | Replacing Digits | [
"greedy"
] | null | null | You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=β€<=*j*<=β€<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=β€<=*i*<=β€<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. Each element in the sequence *s* can participate in no more than one replacing operation.
Your task is to perform such sequence of replacements, that the given number *a* gets maximum value. You are allowed to use not all elements from *s*. | The first line contains positive integer *a*. Its length *n* is positive and doesn't exceed 105. The second line contains sequence of digits *s*. Its length *m* is positive and doesn't exceed 105. The digits in the sequence *s* are written consecutively without any separators.
The given number *a* doesn't contain leading zeroes. | Print the maximum value that can be obtained from *a* after a series of replacements. You are allowed to use not all elements from *s*. The printed number shouldn't contain any leading zeroes. | [
"1024\n010\n",
"987\n1234567\n"
] | [
"1124\n",
"987\n"
] | none | [
{
"input": "1024\n010",
"output": "1124"
},
{
"input": "987\n1234567",
"output": "987"
},
{
"input": "10\n1",
"output": "11"
},
{
"input": "11\n1",
"output": "11"
},
{
"input": "12\n2",
"output": "22"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "123456\n9999",
"output": "999956"
},
{
"input": "909090\n000111",
"output": "919191"
},
{
"input": "588\n24",
"output": "588"
},
{
"input": "25206\n88",
"output": "88206"
},
{
"input": "9776247464\n8629",
"output": "9986647464"
},
{
"input": "3666566898\n3001",
"output": "3666566898"
},
{
"input": "3338860467\n5848",
"output": "8858864467"
},
{
"input": "9768757689\n1010",
"output": "9768757689"
},
{
"input": "6669490269\n6240849376",
"output": "9879696469"
},
{
"input": "1794210278\n50931901955213461294",
"output": "9999965578"
},
{
"input": "6997854871\n15113453341706470344",
"output": "7997876875"
},
{
"input": "8947769539\n22900332144661023400",
"output": "9967769649"
},
{
"input": "9885783638\n20241242140301231211",
"output": "9885784648"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "1\n1234567890",
"output": "9"
},
{
"input": "123\n987987",
"output": "998"
},
{
"input": "1000\n32119",
"output": "9321"
},
{
"input": "31\n4",
"output": "41"
},
{
"input": "504\n91111",
"output": "914"
},
{
"input": "100001\n23",
"output": "320001"
},
{
"input": "87\n9",
"output": "97"
},
{
"input": "786796787566545376\n00101",
"output": "786796787566545376"
},
{
"input": "123456789012345678905764345\n00001",
"output": "123456789112345678905764345"
},
{
"input": "111\n2222222299999999",
"output": "999"
},
{
"input": "111\n789",
"output": "987"
},
{
"input": "1\n99",
"output": "9"
},
{
"input": "1099\n9",
"output": "9099"
},
{
"input": "123\n456",
"output": "654"
}
] | 248 | 0 | 0 | 1,441 |
|
727 | T-shirts Distribution | [
"constructive algorithms",
"flows",
"greedy"
] | null | null | The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size.
During the registration, the organizers asked each of the *n* participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes β this means that any of these two sizes suits him.
Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size:
- the size he wanted, if he specified one size; - any of the two neibouring sizes, if he specified two sizes.
If it is possible, the program should find any valid distribution of the t-shirts. | The first line of the input contains six non-negative integers β the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100<=000.
The second line contains positive integer *n* (1<=β€<=*n*<=β€<=100<=000) β the number of participants.
The following *n* lines contain the sizes specified by the participants, one line per participant. The *i*-th line contains information provided by the *i*-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring. | If it is not possible to present a t-shirt to each participant, print Β«NOΒ» (without quotes).
Otherwise, print *n*<=+<=1 lines. In the first line print Β«YESΒ» (without quotes). In the following *n* lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input.
If there are multiple solutions, print any of them. | [
"0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL\n",
"1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL\n"
] | [
"YES\nXL\nM\nXXL\n",
"NO\n"
] | none | [
{
"input": "0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL",
"output": "YES\nXL\nM\nXXL"
},
{
"input": "1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL",
"output": "NO"
},
{
"input": "1 2 4 4 1 1\n10\nXL\nXL\nS,M\nL\nM,L\nL\nS,M\nM\nXL,XXL\nXL",
"output": "YES\nXL\nXL\nS\nL\nL\nL\nM\nM\nXL\nXL"
},
{
"input": "1 3 0 2 2 2\n10\nL,XL\nS,M\nXXL,XXXL\nS,M\nS,M\nXXXL\nXL,XXL\nXXL\nS,M\nXL",
"output": "YES\nXL\nS\nXXXL\nM\nM\nXXXL\nXXL\nXXL\nM\nXL"
},
{
"input": "5 1 5 2 4 3\n20\nL,XL\nS,M\nL,XL\nXXL,XXXL\nS,M\nS,M\nXL,XXL\nL,XL\nS,M\nL,XL\nS,M\nM,L\nXXL,XXXL\nXXL,XXXL\nL\nXXL,XXXL\nXL,XXL\nM,L\nS,M\nXXL",
"output": "YES\nL\nS\nL\nXXL\nS\nS\nXXL\nXL\nS\nXL\nS\nL\nXXXL\nXXXL\nL\nXXXL\nXXL\nL\nM\nXXL"
},
{
"input": "4 8 8 1 6 3\n30\nS,M\nM,L\nM\nXXL,XXXL\nXXL\nM,L\nS,M\nS,M\nXXL,XXXL\nL\nL\nS,M\nM\nL,XL\nS,M\nM,L\nL\nXXL,XXXL\nS,M\nXXL\nM,L\nM,L\nM,L\nXXL\nXXL,XXXL\nM,L\nS,M\nXXL\nM,L\nXXL,XXXL",
"output": "YES\nS\nM\nM\nXXL\nXXL\nM\nS\nS\nXXL\nL\nL\nS\nM\nXL\nM\nM\nL\nXXXL\nM\nXXL\nL\nL\nL\nXXL\nXXXL\nL\nM\nXXL\nL\nXXXL"
},
{
"input": "1 0 0 0 0 0\n1\nS",
"output": "YES\nS"
},
{
"input": "0 1 0 0 0 0\n1\nS",
"output": "NO"
},
{
"input": "1 0 0 0 0 0\n1\nM",
"output": "NO"
},
{
"input": "0 1 0 0 0 0\n1\nM",
"output": "YES\nM"
},
{
"input": "0 0 0 0 0 1\n1\nL",
"output": "NO"
},
{
"input": "0 0 1 0 0 0\n1\nL",
"output": "YES\nL"
},
{
"input": "0 0 0 1 0 0\n1\nXL",
"output": "YES\nXL"
},
{
"input": "1 0 0 0 0 0\n1\nXL",
"output": "NO"
},
{
"input": "0 0 0 0 1 0\n1\nXXL",
"output": "YES\nXXL"
},
{
"input": "0 1 0 0 0 0\n1\nXXL",
"output": "NO"
},
{
"input": "0 0 0 0 0 1\n1\nXXXL",
"output": "YES\nXXXL"
},
{
"input": "0 0 1 0 0 0\n1\nXXXL",
"output": "NO"
},
{
"input": "1 2 3 6 1 2\n10\nXL\nXL\nM\nL,XL\nL,XL\nL,XL\nS\nS,M\nXL\nL,XL",
"output": "YES\nXL\nXL\nM\nL\nL\nL\nS\nM\nXL\nXL"
},
{
"input": "9 8 1 7 2 3\n20\nL,XL\nM,L\nS\nXL,XXL\nM,L\nXL,XXL\nS\nL,XL\nS,M\nS,M\nXXL,XXXL\nS,M\nS,M\nS,M\nXL,XXL\nL\nXXL,XXXL\nS,M\nXL,XXL\nM,L",
"output": "YES\nXL\nM\nS\nXL\nM\nXL\nS\nXL\nS\nS\nXXL\nS\nS\nS\nXL\nL\nXXL\nS\nXL\nM"
},
{
"input": "9 12 3 8 4 14\n30\nS,M\nS,M\nXL\nXXXL\nXXL,XXXL\nXXL,XXXL\nXXXL\nS,M\nXXL,XXXL\nM,L\nXXL\nXXL,XXXL\nXL,XXL\nL,XL\nXXL,XXXL\nM\nS,M\nXXXL\nXXL,XXXL\nXXL,XXXL\nM\nM,L\nS,M\nS,M\nXXL,XXXL\nXL,XXL\nXXL,XXXL\nXXL,XXXL\nS,M\nM,L",
"output": "YES\nS\nS\nXL\nXXXL\nXXL\nXXL\nXXXL\nS\nXXL\nM\nXXL\nXXXL\nXL\nL\nXXXL\nM\nS\nXXXL\nXXXL\nXXXL\nM\nM\nS\nS\nXXXL\nXL\nXXXL\nXXXL\nS\nM"
},
{
"input": "1 3 0 0 4 2\n10\nXXL\nS,M\nXXXL\nS,M\nS\nXXL,XXXL\nXXL\nXXL,XXXL\nM\nXXL,XXXL",
"output": "YES\nXXL\nM\nXXXL\nM\nS\nXXL\nXXL\nXXL\nM\nXXXL"
},
{
"input": "5 6 0 0 6 3\n20\nXXL,XXXL\nS,M\nS,M\nXXL,XXXL\nS\nS\nXXL,XXXL\nM\nS,M\nXXL,XXXL\nS\nM\nXXXL\nXXL,XXXL\nS,M\nXXXL\nXXL,XXXL\nS,M\nS\nXXL,XXXL",
"output": "YES\nXXL\nS\nM\nXXL\nS\nS\nXXL\nM\nM\nXXL\nS\nM\nXXXL\nXXL\nM\nXXXL\nXXL\nM\nS\nXXXL"
}
] | 358 | 4,403,200 | 0 | 1,443 |
|
120 | Elevator | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=β€<=*a*<=β€<=2) which denotes the number of the rail at which the person was holding. | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 60 | 0 | 0 | 1,444 |
|
276 | Little Girl and Maximum Sum | [
"data structures",
"greedy",
"implementation",
"sortings"
] | null | null | The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive.
The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum. | The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) β the number of elements in the array and the number of queries, correspondingly.
The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) β the array elements.
Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) β the $i$-th query. | In a single line print, a single integer β the maximum sum of query replies after the array elements are reordered.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3 3\n5 3 2\n1 2\n2 3\n1 3\n",
"5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n"
] | [
"25\n",
"33\n"
] | none | [
{
"input": "3 3\n5 3 2\n1 2\n2 3\n1 3",
"output": "25"
},
{
"input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3",
"output": "33"
},
{
"input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17",
"output": "9382"
},
{
"input": "16 13\n40 32 15 16 35 36 45 23 30 42 25 8 29 21 39 23\n2 9\n3 11\n8 9\n4 14\n1 6\n5 10\n5 14\n5 11\n13 13\n2 8\n9 16\n6 10\n7 8",
"output": "2838"
},
{
"input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n13 31\n21 27\n9 25\n6 18\n6 8\n28 30\n2 4\n15 21\n1 1\n8 30\n3 31\n11 27\n28 29\n6 22\n20 22\n9 25",
"output": "17471"
},
{
"input": "22 7\n44 41 40 41 37 42 46 16 50 47 30 7 32 6 20 14 47 25 11 1 35 12\n1 10\n10 20\n4 5\n1 8\n2 12\n8 8\n2 16",
"output": "2202"
},
{
"input": "3 2\n1 2 3\n2 3\n1 2",
"output": "9"
}
] | 499 | 26,316,800 | 3 | 1,445 |
|
425 | Sereja and Squares | [
"binary search",
"data structures",
"hashing"
] | null | null | Sereja has painted *n* distinct points on the plane. The coordinates of each point are integers. Now he is wondering: how many squares are there with sides parallel to the coordinate axes and with points painted in all its four vertexes? Help him, calculate this number. | The first line contains integer *n* (1<=β€<=*n*<=β€<=105). Each of the next *n* lines contains two integers *x**i*,<=*y**i* (0<=β€<=*x**i*,<=*y**i*<=β€<=105), the integers represent the coordinates of the *i*-th point. It is guaranteed that all the given points are distinct. | In a single line print the required number of squares. | [
"5\n0 0\n0 2\n2 0\n2 2\n1 1\n",
"9\n0 0\n1 1\n2 2\n0 1\n1 0\n0 2\n2 0\n1 2\n2 1\n"
] | [
"1\n",
"5\n"
] | none | [
{
"input": "5\n0 0\n0 2\n2 0\n2 2\n1 1",
"output": "1"
},
{
"input": "9\n0 0\n1 1\n2 2\n0 1\n1 0\n0 2\n2 0\n1 2\n2 1",
"output": "5"
},
{
"input": "54\n0 8\n3 2\n9 3\n7 2\n8 2\n2 8\n10 10\n7 6\n1 1\n9 7\n4 0\n6 10\n10 1\n10 8\n5 1\n0 4\n7 10\n3 6\n0 5\n4 3\n3 0\n5 10\n6 9\n5 4\n6 6\n8 5\n0 7\n5 8\n1 2\n2 2\n9 4\n2 4\n0 10\n5 9\n10 9\n7 9\n9 9\n2 5\n4 10\n8 9\n7 7\n5 2\n6 5\n4 1\n10 6\n6 3\n9 6\n0 9\n7 3\n7 5\n8 4\n1 3\n0 3\n2 10",
"output": "14"
},
{
"input": "87\n5 10\n5 0\n9 2\n2 4\n6 6\n4 4\n3 4\n0 3\n10 6\n1 0\n7 1\n2 5\n6 10\n5 3\n1 6\n8 7\n5 6\n5 9\n9 8\n2 6\n6 9\n6 4\n3 2\n10 10\n0 4\n8 9\n8 8\n4 8\n10 2\n10 0\n3 8\n8 2\n3 1\n9 5\n9 1\n5 4\n4 6\n10 7\n2 0\n10 9\n9 0\n9 9\n6 2\n3 9\n10 8\n7 0\n7 3\n6 0\n5 2\n6 5\n4 7\n1 3\n9 7\n1 5\n4 1\n7 10\n0 2\n0 8\n9 10\n0 5\n4 10\n7 4\n1 8\n2 7\n10 3\n9 3\n10 5\n6 1\n8 3\n10 1\n8 0\n5 1\n3 10\n10 4\n2 10\n4 5\n5 7\n7 9\n1 7\n8 6\n1 1\n7 2\n7 5\n5 5\n1 4\n6 8\n6 3",
"output": "101"
},
{
"input": "3\n1 6\n10 8\n4 3",
"output": "0"
},
{
"input": "72\n8 2\n2 4\n3 5\n9 10\n7 6\n1 5\n0 0\n3 3\n1 6\n7 10\n8 8\n7 9\n6 0\n3 6\n9 3\n8 1\n3 4\n3 7\n0 7\n10 8\n2 6\n6 8\n0 6\n5 6\n6 6\n6 5\n6 4\n0 2\n9 9\n4 8\n7 2\n8 0\n9 4\n0 10\n4 5\n9 8\n10 3\n8 7\n8 5\n7 7\n6 7\n5 7\n5 4\n8 4\n3 2\n7 3\n9 0\n0 8\n0 5\n3 9\n2 10\n7 1\n4 3\n1 10\n3 0\n5 9\n10 1\n6 1\n4 10\n1 0\n2 1\n2 0\n3 8\n10 7\n7 4\n0 9\n1 1\n1 8\n8 3\n5 2\n6 3\n4 2",
"output": "51"
},
{
"input": "71\n5 3\n1 10\n10 3\n5 2\n3 5\n10 9\n10 2\n1 5\n9 5\n8 9\n2 3\n2 6\n8 4\n6 3\n0 2\n9 4\n2 0\n7 7\n10 0\n4 0\n1 4\n1 6\n4 5\n6 1\n8 2\n0 0\n0 1\n3 7\n3 10\n4 8\n4 6\n3 8\n1 0\n9 10\n9 9\n6 5\n7 1\n10 1\n6 6\n3 4\n4 3\n4 2\n4 10\n9 6\n7 3\n6 8\n5 5\n4 9\n0 7\n0 9\n8 10\n2 7\n1 7\n7 2\n5 8\n1 2\n3 6\n10 8\n0 8\n3 1\n1 3\n9 3\n7 6\n6 7\n4 4\n0 3\n2 2\n5 10\n2 9\n0 5\n7 0",
"output": "40"
},
{
"input": "81\n9 4\n6 8\n6 4\n4 6\n4 8\n9 10\n0 2\n5 4\n8 9\n7 7\n10 5\n4 4\n7 8\n3 7\n2 1\n5 5\n2 7\n8 6\n2 8\n10 7\n5 8\n0 10\n10 0\n4 9\n4 2\n10 3\n6 6\n3 8\n5 3\n8 8\n10 9\n1 1\n0 9\n8 1\n1 8\n0 7\n10 4\n3 6\n7 6\n1 9\n8 3\n8 10\n4 5\n3 4\n7 5\n2 0\n0 6\n2 4\n7 4\n6 3\n1 6\n10 8\n1 5\n6 5\n0 0\n9 0\n7 3\n3 2\n2 6\n4 0\n8 7\n10 10\n3 0\n0 5\n3 9\n5 1\n6 0\n1 4\n0 1\n1 2\n6 2\n9 7\n6 10\n1 3\n1 7\n2 5\n5 10\n10 2\n5 6\n6 7\n2 3",
"output": "85"
},
{
"input": "3\n5 1\n4 1\n2 6",
"output": "0"
},
{
"input": "49\n2 9\n7 0\n8 0\n10 3\n2 10\n6 10\n6 2\n9 7\n1 9\n4 6\n5 4\n1 0\n9 4\n6 9\n5 6\n7 9\n10 10\n8 2\n3 10\n0 8\n4 4\n5 7\n0 0\n9 1\n0 7\n2 0\n1 7\n10 0\n3 5\n8 5\n6 4\n0 4\n2 7\n4 1\n10 2\n2 4\n8 4\n0 9\n3 4\n4 9\n7 7\n10 9\n2 3\n7 2\n5 8\n4 7\n10 8\n7 6\n1 8",
"output": "11"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100000 100000",
"output": "0"
}
] | 62 | 2,867,200 | -1 | 1,452 |
|
846 | Curriculum Vitae | [
"brute force",
"implementation"
] | null | null | Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV.
More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one β to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one.
Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. | The first line contains one integer number *n* (1<=β€<=*n*<=β€<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=β€<=*s**i*<=β€<=1). 0 corresponds to an unsuccessful game, 1 β to a successful one. | Print one integer β the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. | [
"4\n1 1 0 1\n",
"6\n0 1 0 0 1 0\n",
"1\n0\n"
] | [
"3\n",
"4\n",
"1\n"
] | none | [
{
"input": "4\n1 1 0 1",
"output": "3"
},
{
"input": "6\n0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"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": "100"
},
{
"input": "100\n0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "80"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1",
"output": "53"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "3\n1 0 0",
"output": "2"
},
{
"input": "10\n1 1 0 0 0 1 1 0 0 0",
"output": "6"
},
{
"input": "90\n1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0",
"output": "52"
},
{
"input": "78\n0 0 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0",
"output": "42"
},
{
"input": "4\n1 0 0 1",
"output": "3"
},
{
"input": "2\n0 1",
"output": "2"
},
{
"input": "5\n0 1 0 0 1",
"output": "4"
},
{
"input": "3\n1 0 1",
"output": "2"
},
{
"input": "3\n1 1 0",
"output": "2"
},
{
"input": "16\n1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 1",
"output": "9"
}
] | 61 | 0 | 3 | 1,454 |
|
599 | Patrick and Shopping | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.
Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=β€<=*d*1,<=*d*2,<=*d*3<=β€<=108) β the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
{
"input": "789 101112 131415",
"output": "203802"
},
{
"input": "27485716 99999999 35182",
"output": "55041796"
},
{
"input": "1 293548 5",
"output": "12"
},
{
"input": "12059 259855 5874875",
"output": "543828"
},
{
"input": "46981 105809 585858",
"output": "305580"
},
{
"input": "9889 1221 2442",
"output": "7326"
},
{
"input": "100500 200600 300700",
"output": "601800"
},
{
"input": "318476 318476 318476",
"output": "955428"
},
{
"input": "23985 3353 75633",
"output": "54676"
},
{
"input": "120 1298 2222",
"output": "2836"
},
{
"input": "98437 23487 666672",
"output": "243848"
},
{
"input": "100000000 100000000 100000000",
"output": "300000000"
},
{
"input": "2 5 2",
"output": "8"
},
{
"input": "1 1000 1",
"output": "4"
},
{
"input": "1 100000000 1",
"output": "4"
}
] | 93 | 0 | 0 | 1,455 |
|
608 | Hamming Distance Sum | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2.
Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | The first line of the input contains binary string *a* (1<=β€<=|*a*|<=β€<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=β€<=|*b*|<=β€<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer β the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0β-β0|β+β|1β-β0|β=β1. The distance between "01" and "01" is |0β-β0|β+β|1β-β1|β=β0. The distance between "01" and "11" is |0β-β1|β+β|1β-β1|β=β1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1β+β0β+β1β+β1β=β3.
The second sample case is described in the statement. | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1001101001101110101101000\n01111000010011111111110010001101000100011110101111",
"output": "321"
},
{
"input": "1110010001000101001011111\n00011011000000100001010000010100110011010001111010",
"output": "316"
}
] | 2,000 | 8,908,800 | 0 | 1,458 |
|
892 | Wrath | [
"greedy",
"implementation",
"two pointers"
] | null | null | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *j*<=β₯<=*i*<=-<=*L**i*.
You are given lengths of the claws. You need to find the total number of alive people after the bell rings. | The first line contains one integer *n* (1<=β€<=*n*<=β€<=106) β the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=β€<=*L**i*<=β€<=109), where *L**i* is the length of the *i*-th person's claw. | Print one integer β the total number of alive people after the bell rings. | [
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] | [
"1\n",
"2\n",
"3\n"
] | In first sample the last person kills everyone in front of him. | [
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0",
"output": "4"
},
{
"input": "6\n3 1 1 0 3 3",
"output": "1"
},
{
"input": "8\n0 0 0 1 0 0 1 2",
"output": "5"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "2\n1 3",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "11\n1 0 0 1 1 3 2 0 0 2 3",
"output": "4"
},
{
"input": "1\n1",
"output": "1"
}
] | 31 | 4,198,400 | 0 | 1,459 |
|
411 | Password Check | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.
Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions:
- the password length is at least 5 characters; - the password contains at least one large English letter; - the password contains at least one small English letter; - the password contains at least one digit.
You are given a password. Please implement the automatic check of its complexity for company Q. | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA___",
"output": "Too weak"
},
{
"input": "1A___",
"output": "Too weak"
},
{
"input": "z1___",
"output": "Too weak"
},
{
"input": "0",
"output": "Too weak"
},
{
"input": "_",
"output": "Too weak"
},
{
"input": "a",
"output": "Too weak"
},
{
"input": "D",
"output": "Too weak"
},
{
"input": "_",
"output": "Too weak"
},
{
"input": "?",
"output": "Too weak"
},
{
"input": "?",
"output": "Too weak"
},
{
"input": "._,.!.,...?_,!.",
"output": "Too weak"
},
{
"input": "!_?_,?,?.,.,_!!!.!,.__,?!!,_!,?_,!??,?!..._!?_,?_!,?_.,._,,_.,.",
"output": "Too weak"
},
{
"input": "?..!.,,?,__.,...????_???__!,?...?.,,,,___!,.!,_,,_,??!_?_,!!?_!_??.?,.!!?_?_.,!",
"output": "Too weak"
},
{
"input": "XZX",
"output": "Too weak"
},
{
"input": "R",
"output": "Too weak"
},
{
"input": "H.FZ",
"output": "Too weak"
},
{
"input": "KSHMICWPK,LSBM_JVZ!IPDYDG_GOPCHXFJTKJBIFY,FPHMY,CB?PZEAG..,X,.GFHPIDBB,IQ?MZ",
"output": "Too weak"
},
{
"input": "EFHI,,Y?HMMUI,,FJGAY?FYPBJQMYM!DZHLFCTFWT?JOPDW,S_!OR?ATT?RWFBMAAKUHIDMHSD?LCZQY!UD_CGYGBAIRDPICYS",
"output": "Too weak"
},
{
"input": "T,NDMUYCCXH_L_FJHMCCAGX_XSCPGOUZSY?D?CNDSYRITYS,VAT!PJVKNTBMXGGRYKACLYU.RJQ_?UWKXYIDE_AE",
"output": "Too weak"
},
{
"input": "y",
"output": "Too weak"
},
{
"input": "qgw",
"output": "Too weak"
},
{
"input": "g",
"output": "Too weak"
},
{
"input": "loaray",
"output": "Too weak"
},
{
"input": "d_iymyvxolmjayhwpedocopqwmy.oalrdg!_n?.lrxpamhygps?kkzxydsbcaihfs.j?eu!oszjsy.vzu?!vs.bprz_j",
"output": "Too weak"
},
{
"input": "txguglvclyillwnono",
"output": "Too weak"
},
{
"input": "FwX",
"output": "Too weak"
},
{
"input": "Zi",
"output": "Too weak"
},
{
"input": "PodE",
"output": "Too weak"
},
{
"input": "SdoOuJ?nj_wJyf",
"output": "Too weak"
},
{
"input": "MhnfZjsUyXYw?f?ubKA",
"output": "Too weak"
},
{
"input": "CpWxDVzwHfYFfoXNtXMFuAZr",
"output": "Too weak"
},
{
"input": "9.,0",
"output": "Too weak"
},
{
"input": "5,8",
"output": "Too weak"
},
{
"input": "7",
"output": "Too weak"
},
{
"input": "34__39_02!,!,82!129!2!566",
"output": "Too weak"
},
{
"input": "96156027.65935663!_87!,44,..7914_!0_1,.4!!62!.8350!17_282!!9.2584,!!7__51.526.7",
"output": "Too weak"
},
{
"input": "90328_",
"output": "Too weak"
},
{
"input": "B9",
"output": "Too weak"
},
{
"input": "P1H",
"output": "Too weak"
},
{
"input": "J2",
"output": "Too weak"
},
{
"input": "M6BCAKW!85OSYX1D?.53KDXP42F",
"output": "Too weak"
},
{
"input": "C672F429Y8X6XU7S,.K9111UD3232YXT81S4!729ER7DZ.J7U1R_7VG6.FQO,LDH",
"output": "Too weak"
},
{
"input": "W2PI__!.O91H8OFY6AB__R30L9XOU8800?ZUD84L5KT99818NFNE35V.8LJJ5P2MM.B6B",
"output": "Too weak"
},
{
"input": "z1",
"output": "Too weak"
},
{
"input": "p1j",
"output": "Too weak"
},
{
"input": "j9",
"output": "Too weak"
},
{
"input": "v8eycoylzv0qkix5mfs_nhkn6k!?ovrk9!b69zy!4frc?k",
"output": "Too weak"
},
{
"input": "l4!m_44kpw8.jg!?oh,?y5oraw1tg7_x1.osl0!ny?_aihzhtt0e2!mr92tnk0es!1f,9he40_usa6c50l",
"output": "Too weak"
},
{
"input": "d4r!ak.igzhnu!boghwd6jl",
"output": "Too weak"
},
{
"input": "It0",
"output": "Too weak"
},
{
"input": "Yb1x",
"output": "Too weak"
},
{
"input": "Qf7",
"output": "Too weak"
},
{
"input": "Vu7jQU8.!FvHBYTsDp6AphaGfnEmySP9te",
"output": "Correct"
},
{
"input": "Ka4hGE,vkvNQbNolnfwp",
"output": "Correct"
},
{
"input": "Ee9oluD?amNItsjeQVtOjwj4w_ALCRh7F3eaZah",
"output": "Correct"
},
{
"input": "Um3Fj?QLhNuRE_Gx0cjMLOkGCm",
"output": "Correct"
},
{
"input": "Oq2LYmV9HmlaW",
"output": "Correct"
},
{
"input": "Cq7r3Wrb.lDb_0wsf7!ruUUGSf08RkxD?VsBEDdyE?SHK73TFFy0f8gmcATqGafgTv8OOg8or2HyMPIPiQ2Hsx8q5rn3_WZe",
"output": "Correct"
},
{
"input": "Wx4p1fOrEMDlQpTlIx0p.1cnFD7BnX2K8?_dNLh4cQBx_Zqsv83BnL5hGKNcBE9g3QB,!fmSvgBeQ_qiH7",
"output": "Correct"
},
{
"input": "k673,",
"output": "Too weak"
},
{
"input": "LzuYQ",
"output": "Too weak"
},
{
"input": "Pasq!",
"output": "Too weak"
},
{
"input": "x5hve",
"output": "Too weak"
},
{
"input": "b27fk",
"output": "Too weak"
},
{
"input": "h6y1l",
"output": "Too weak"
},
{
"input": "i9nij",
"output": "Too weak"
},
{
"input": "Gf5Q6",
"output": "Correct"
},
{
"input": "Uf24o",
"output": "Correct"
},
{
"input": "Oj9vu",
"output": "Correct"
},
{
"input": "c7jqaudcqmv8o7zvb5x_gp6zcgl6nwr7tz5or!28.tj8s1m2.wxz5a4id03!rq07?662vy.7.p5?vk2f2mc7ag8q3861rgd0rmbr",
"output": "Too weak"
},
{
"input": "i6a.,8jb,n0kv4.1!7h?p.96pnhhgy6cl7dg7e4o6o384ys3z.t71kkq,,w,oqi4?u,,m5!rzu6wym_4hm,ohjy!.vvksl?pt,,1",
"output": "Too weak"
},
{
"input": "M10V_MN_1K8YX2LA!89EYV7!5V9?,.IDHDP6JEC.OGLY.180LMZ6KW3Z5E17IT94ZNHS!79GN09Q6LH0,F3AYNKP?KM,QP_?XRD6",
"output": "Too weak"
},
{
"input": "Hi7zYuVXCPhaho68YgCMzzgLILM6toQTJq8akMqqrnUn6ZCD36iA1yVVpvlsIiMpCu!1QZd4ycIrQ5Kcrhk5k0jTrwdAAEEP_T2f",
"output": "Correct"
},
{
"input": "Bk2Q38vDSW5JqYu.077iYC.9YoiPc!Dh6FJWOVze6?YXiFjPNa4F1RG?154m9mY2jQobBnbxM,cDV8l1UX1?v?p.tTYIyJO!NYmE",
"output": "Correct"
},
{
"input": "Ro1HcZ.piN,JRR88DLh,WtW!pbFM076?wCSbqfK7N2s5zUySFBtzk7HV,BxHXR0zALAr016z5jvvB.WUdEcKgYFav5TygwHQC..C",
"output": "Correct"
},
{
"input": "!?.,_",
"output": "Too weak"
}
] | 46 | 0 | 3 | 1,460 |
|
1,006 | Polycarp's Practice | [
"greedy",
"implementation",
"sortings"
] | null | null | Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all $n$ problems in exactly $k$ days.
Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in $k$ days he will solve all the $n$ problems.
The profit of the $j$-th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the $j$-th day (i.e. if he solves problems with indices from $l$ to $r$ during a day, then the profit of the day is $\max\limits_{l \le i \le r}a_i$). The total profit of his practice is the sum of the profits over all $k$ days of his practice.
You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all $n$ problems between $k$ days satisfying the conditions above in such a way, that the total profit is maximum.
For example, if $n = 8, k = 3$ and $a = [5, 4, 2, 6, 5, 1, 9, 2]$, one of the possible distributions with maximum total profit is: $[5, 4, 2], [6, 5], [1, 9, 2]$. Here the total profit equals $5 + 6 + 9 = 20$. | The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) β the number of problems and the number of days, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) β difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them). | In the first line of the output print the maximum possible total profit.
In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible total profit of his practice.
If there are many possible answers, you may print any of them. | [
"8 3\n5 4 2 6 5 1 9 2\n",
"5 1\n1 1 1 1 1\n",
"4 2\n1 2000 2000 2\n"
] | [
"20\n3 2 3",
"1\n5\n",
"4000\n2 2\n"
] | The first example is described in the problem statement.
In the second example there is only one possible distribution.
In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. | [
{
"input": "8 3\n5 4 2 6 5 1 9 2",
"output": "20\n4 1 3"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "1\n5"
},
{
"input": "4 2\n1 2000 2000 2",
"output": "4000\n2 2"
},
{
"input": "1 1\n2000",
"output": "2000\n1"
},
{
"input": "1 1\n1234",
"output": "1234\n1"
},
{
"input": "3 2\n1 1 1",
"output": "2\n2 1"
},
{
"input": "4 2\n3 5 1 1",
"output": "8\n1 3"
},
{
"input": "5 3\n5 5 6 7 1",
"output": "18\n2 1 2"
},
{
"input": "6 4\n1 1 1 1 2 2",
"output": "6\n3 1 1 1"
},
{
"input": "5 3\n5 5 6 6 4",
"output": "17\n2 1 2"
},
{
"input": "16 15\n14 4 9 12 17 1 1 8 12 13 6 9 17 2 18 12",
"output": "154\n1 1 1 1 1 2 1 1 1 1 1 1 1 1 1"
},
{
"input": "1 1\n1996",
"output": "1996\n1"
},
{
"input": "5 3\n5 5 5 9 10",
"output": "24\n3 1 1"
},
{
"input": "18 15\n18 2 13 1 18 3 2 18 18 20 9 2 20 20 4 20 9 12",
"output": "204\n1 2 2 1 2 1 1 1 1 1 1 1 1 1 1"
},
{
"input": "5 3\n1 20 20 50 50",
"output": "120\n3 1 1"
},
{
"input": "8 3\n15 14 11 19 17 14 14 8",
"output": "51\n1 3 4"
},
{
"input": "5 2\n15 20 6 19 6",
"output": "39\n2 3"
},
{
"input": "6 3\n5 5 5 5 6 9",
"output": "20\n4 1 1"
},
{
"input": "5 3\n2 2 2 3 3",
"output": "8\n3 1 1"
},
{
"input": "7 3\n2 2 2 2 2 3 3",
"output": "8\n5 1 1"
},
{
"input": "6 5\n1 1 6 6 6 6",
"output": "25\n2 1 1 1 1"
},
{
"input": "8 4\n1 2 2 2 2 3 4 5",
"output": "14\n5 1 1 1"
},
{
"input": "6 4\n1 1 1 5 5 5",
"output": "16\n3 1 1 1"
},
{
"input": "6 3\n1 2 2 2 4 5",
"output": "11\n4 1 1"
},
{
"input": "18 6\n17 17 19 14 10 20 18 16 6 7 2 15 14 16 13 6 12 11",
"output": "107\n1 1 1 3 1 11"
},
{
"input": "6 3\n1 1 2 2 3 4",
"output": "9\n4 1 1"
},
{
"input": "8 3\n5 4 2 5 6 1 9 2",
"output": "20\n4 1 3"
}
] | 108 | 6,963,200 | 3 | 1,462 |
|
845 | Two TVs | [
"data structures",
"greedy",
"sortings"
] | null | null | Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV.
Polycarp wants to check out all *n* shows. Are two TVs enough to do so? | The first line contains one integer *n* (1<=β€<=*n*<=β€<=2Β·105) β the number of shows.
Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=β€<=*l**i*<=<<=*r**i*<=β€<=109) β starting and ending time of *i*-th show. | If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). | [
"3\n1 2\n2 3\n4 5\n",
"4\n1 2\n2 3\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n"
] | none | [
{
"input": "3\n1 2\n2 3\n4 5",
"output": "YES"
},
{
"input": "4\n1 2\n2 3\n2 3\n1 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 2\n2 3\n3 4",
"output": "YES"
},
{
"input": "3\n1 2\n2 3\n2 4",
"output": "NO"
},
{
"input": "3\n0 100\n0 100\n0 100",
"output": "NO"
},
{
"input": "1\n0 1000000000",
"output": "YES"
},
{
"input": "2\n0 1\n0 1",
"output": "YES"
},
{
"input": "3\n2 3\n4 5\n1 6",
"output": "YES"
},
{
"input": "5\n1 3\n1 4\n4 10\n5 8\n9 11",
"output": "YES"
},
{
"input": "3\n1 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "4\n1 100\n10 15\n20 25\n30 35",
"output": "YES"
},
{
"input": "3\n1 8\n6 7\n8 11",
"output": "YES"
},
{
"input": "5\n1 2\n3 5\n4 7\n8 9\n5 10",
"output": "NO"
},
{
"input": "4\n1 7\n2 3\n4 5\n6 7",
"output": "YES"
},
{
"input": "4\n1 100\n50 51\n60 90\n51 52",
"output": "NO"
},
{
"input": "3\n1 10\n2 9\n3 8",
"output": "NO"
},
{
"input": "2\n0 4\n0 4",
"output": "YES"
},
{
"input": "2\n0 2\n0 6",
"output": "YES"
},
{
"input": "5\n3 4\n21 26\n12 17\n9 14\n15 16",
"output": "YES"
},
{
"input": "5\n1 4\n13 15\n11 12\n9 15\n2 5",
"output": "YES"
},
{
"input": "4\n16 19\n9 14\n14 15\n15 19",
"output": "YES"
},
{
"input": "5\n16 19\n23 29\n3 8\n23 26\n22 23",
"output": "NO"
},
{
"input": "5\n19 23\n12 17\n16 21\n20 23\n8 10",
"output": "NO"
},
{
"input": "5\n8 10\n4 10\n3 4\n14 15\n17 19",
"output": "YES"
},
{
"input": "3\n2 8\n5 7\n6 7",
"output": "NO"
},
{
"input": "5\n10 12\n4 6\n21 24\n9 12\n7 13",
"output": "NO"
},
{
"input": "5\n0 3\n14 16\n6 8\n5 9\n9 15",
"output": "YES"
},
{
"input": "5\n6 12\n23 25\n6 7\n19 25\n10 11",
"output": "YES"
},
{
"input": "5\n15 18\n23 24\n23 28\n22 24\n15 19",
"output": "NO"
},
{
"input": "4\n1 8\n8 9\n5 7\n1 4",
"output": "YES"
},
{
"input": "3\n6 10\n1 9\n2 5",
"output": "YES"
},
{
"input": "3\n1 8\n5 6\n6 9",
"output": "NO"
},
{
"input": "4\n2 3\n5 9\n8 10\n9 10",
"output": "NO"
},
{
"input": "4\n0 8\n6 7\n5 9\n1 4",
"output": "NO"
},
{
"input": "3\n6 9\n0 1\n0 2",
"output": "YES"
},
{
"input": "5\n0 6\n21 25\n18 19\n0 3\n6 12",
"output": "YES"
},
{
"input": "4\n1 5\n6 9\n4 8\n1 3",
"output": "YES"
},
{
"input": "2\n2 5\n0 5",
"output": "YES"
},
{
"input": "4\n5 8\n11 15\n3 7\n10 14",
"output": "YES"
},
{
"input": "3\n12 14\n0 4\n2 3",
"output": "YES"
},
{
"input": "4\n4 10\n0 1\n2 10\n0 5",
"output": "NO"
},
{
"input": "4\n0 3\n0 1\n2 4\n2 5",
"output": "NO"
}
] | 2,000 | 21,504,000 | 0 | 1,466 |
|
560 | Currency System in Geraldion | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum? | The first line contains number *n* (1<=β€<=*n*<=β€<=1000) β the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=106) β the values of the banknotes. | Print a single line β the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"output": "1"
},
{
"input": "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97866 124255 950067 697612 244256 782385 789882 37608 82153 399889 598867 416717 377988 535636 511221 792568 683271 131077 290194 496712 330720 587436 563481 645817 942562 654093 980561 382937 48293 582608 116156",
"output": "-1"
},
{
"input": "50\n474421 421097 217233 156339 27075 733996 281778 863492 184707 956857 288561 70997 393786 337382 663642 131184 637 273801 799870 295017 392338 842567 161819 297705 102013 930684 375703 838048 154915 138503 629056 256591 893619 19263 787927 684541 320265 841090 421423 490879 394582 493952 619247 633202 612928 50907 276653 407819 489945 153173",
"output": "1"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "1\n1000000",
"output": "1"
},
{
"input": "2\n3 2",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
}
] | 46 | 6,758,400 | -1 | 1,471 |
|
372 | Counting Kangaroos is Fun | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.
The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. | The first line contains a single integer β *n* (1<=β€<=*n*<=β€<=5Β·105). Each of the next *n* lines contains an integer *s**i* β the size of the *i*-th kangaroo (1<=β€<=*s**i*<=β€<=105). | Output a single integer β the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
},
{
"input": "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n267\n791\n595\n465\n8\n327\n855\n174\n339\n946\n184\n250\n807\n422\n679\n980\n64\n530\n312\n351\n676\n911\n803\n991\n669\n50\n293\n841\n545\n598\n737\n894\n231\n754\n588\n83\n873\n767\n833\n482\n905\n903\n970\n571\n715\n59\n777\n697\n537\n861\n339\n212\n149\n889\n905\n70\n970\n307\n830\n465\n968\n291\n430\n317\n942\n944\n330\n235\n814\n880\n415\n76",
"output": "58"
},
{
"input": "100\n154\n60\n97\n638\n139\n150\n570\n579\n601\n647\n804\n237\n245\n549\n288\n347\n778\n282\n916\n441\n974\n145\n957\n886\n655\n702\n930\n618\n132\n520\n972\n48\n94\n54\n682\n433\n896\n134\n845\n636\n242\n842\n125\n141\n240\n130\n409\n666\n948\n938\n604\n110\n474\n484\n364\n40\n807\n271\n438\n288\n201\n814\n754\n589\n341\n576\n146\n952\n819\n923\n222\n535\n336\n83\n314\n911\n303\n911\n384\n601\n249\n330\n735\n271\n142\n204\n405\n783\n775\n449\n590\n139\n109\n276\n45\n205\n454\n836\n82\n841",
"output": "50"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "4\n1\n1\n1\n2",
"output": "3"
},
{
"input": "5\n1\n2\n4\n8\n16",
"output": "3"
},
{
"input": "7\n1\n2\n4\n8\n16\n32\n64",
"output": "4"
},
{
"input": "3\n1\n2\n4",
"output": "2"
}
] | 561 | 33,075,200 | 3 | 1,475 |
|
14 | Four Segments | [
"brute force",
"constructive algorithms",
"geometry",
"implementation",
"math"
] | C. Four Segments | 2 | 64 | Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. | The input data contain four lines. Each of these lines contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=109<=β€<=*x*1,<=*y*1,<=*x*2,<=*y*2<=β€<=109) β coordinates of segment's beginning and end positions. The given segments can degenerate into points. | Output the word Β«YESΒ», if the given four segments form the required rectangle, otherwise output Β«NOΒ». | [
"1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n",
"0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n"
] | [
"YES\n",
"NO\n"
] | none | [
{
"input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0",
"output": "YES"
},
{
"input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "YES"
},
{
"input": "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5",
"output": "NO"
},
{
"input": "0 0 4 0\n4 0 3 0\n3 0 2 0\n2 0 0 0",
"output": "NO"
},
{
"input": "0 0 3 0\n0 0 0 3\n0 3 3 3\n3 3 3 0",
"output": "YES"
},
{
"input": "0 0 1 0\n1 0 1 1\n0 1 1 1\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 1 0\n1 0 1 1\n1 1 1 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 1\n1 1 2 0\n2 0 1 -1\n1 -1 0 0",
"output": "NO"
},
{
"input": "0 0 0 10\n0 10 0 9\n0 9 0 8\n0 8 0 0",
"output": "NO"
},
{
"input": "0 0 4 0\n4 0 4 0\n4 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 2\n0 2 2 2\n0 0 2 2\n2 2 2 0",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 2 2\n0 2 0 0\n2 2 2 0",
"output": "NO"
},
{
"input": "13 13 13 13\n13 13 13 13\n13 13 13 13\n13 13 13 13",
"output": "NO"
},
{
"input": "0 0 2 0\n0 1 0 3\n0 4 3 4\n3 0 3 3",
"output": "NO"
},
{
"input": "1 1 1 1\n0 1 -1 1\n-1 1 1 1\n-1 1 1 1",
"output": "NO"
},
{
"input": "1 -1 1 -1\n1 -1 1 -1\n1 -1 1 -1\n1 -1 1 -1",
"output": "NO"
},
{
"input": "-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0",
"output": "NO"
},
{
"input": "-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0",
"output": "NO"
},
{
"input": "0 -1 0 1\n0 0 0 1\n0 -1 0 -1\n0 -1 0 -1",
"output": "NO"
},
{
"input": "0 0 -1 0\n-1 0 0 0\n-1 0 -1 0\n-1 0 -1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "-1 1 -1 1\n-1 1 -1 1\n-1 1 -1 1\n-1 1 -1 1",
"output": "NO"
},
{
"input": "-1 1 -1 1\n0 1 1 1\n1 -1 -1 1\n-1 1 1 1",
"output": "NO"
},
{
"input": "-1 -1 -1 -1\n-1 0 -1 0\n-1 0 -1 0\n-1 -1 -1 -1",
"output": "NO"
},
{
"input": "1 2 1 2\n-2 2 1 2\n1 -2 -2 2\n-2 -2 1 -2",
"output": "NO"
},
{
"input": "-2 1 -2 -1\n-2 -2 -2 -2\n-2 -1 -2 -2\n-2 1 -2 -1",
"output": "NO"
},
{
"input": "1 2 1 2\n1 -1 1 -1\n1 -1 1 -1\n1 -1 1 -1",
"output": "NO"
},
{
"input": "-2 0 -2 -1\n-2 2 -2 0\n-2 2 -2 2\n-2 0 -2 -1",
"output": "NO"
},
{
"input": "-1 1 -2 1\n0 -1 -1 1\n-2 1 -1 -1\n0 1 0 -1",
"output": "NO"
},
{
"input": "2 -1 -2 -1\n2 -1 2 -1\n2 -1 -2 -1\n2 -1 2 -1",
"output": "NO"
},
{
"input": "0 2 0 2\n0 2 0 1\n0 1 0 1\n0 2 0 1",
"output": "NO"
},
{
"input": "1 0 1 0\n1 0 1 0\n1 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "-1 1 2 1\n0 1 0 1\n0 1 2 1\n2 1 -1 1",
"output": "NO"
},
{
"input": "0 0 2 0\n0 0 2 0\n0 -2 0 0\n0 -2 0 0",
"output": "NO"
},
{
"input": "0 -3 0 -1\n1 -1 1 -1\n0 -1 1 -2\n0 -2 -2 -3",
"output": "NO"
},
{
"input": "-3 -2 -2 -2\n3 -2 3 -2\n-3 -2 -2 -2\n3 -2 3 -2",
"output": "NO"
},
{
"input": "1 2 -2 2\n-2 2 3 2\n1 2 -2 2\n-2 2 3 2",
"output": "NO"
},
{
"input": "0 -2 1 3\n1 3 1 3\n1 3 1 3\n1 3 1 -2",
"output": "NO"
},
{
"input": "0 -3 -2 -3\n0 1 0 -3\n0 1 0 -3\n0 1 0 -3",
"output": "NO"
},
{
"input": "1 -3 1 -3\n1 -3 1 -3\n1 -3 1 -3\n1 -3 1 -3",
"output": "NO"
},
{
"input": "-3 2 -2 1\n0 2 0 -3\n0 -3 -2 1\n0 1 -3 -3",
"output": "NO"
},
{
"input": "-3 3 2 3\n2 3 2 3\n-3 3 -3 3\n-3 3 2 3",
"output": "NO"
},
{
"input": "2 -2 2 -2\n2 -2 2 -2\n2 -2 2 -2\n2 -2 2 -2",
"output": "NO"
},
{
"input": "2 -1 0 -2\n-3 -2 -3 3\n2 -2 2 -2\n0 3 -3 -2",
"output": "NO"
},
{
"input": "1 -3 -1 1\n0 -2 1 -3\n1 1 0 1\n1 -3 0 1",
"output": "NO"
},
{
"input": "-2 4 -2 4\n-2 4 -2 -2\n-2 4 -2 -2\n-2 4 -2 -2",
"output": "NO"
},
{
"input": "3 1 3 1\n-3 1 3 1\n3 3 -3 1\n-3 1 3 1",
"output": "NO"
},
{
"input": "0 1 4 1\n0 1 4 1\n4 1 0 1\n0 -2 4 1",
"output": "NO"
},
{
"input": "0 -2 0 -1\n0 -1 0 -2\n0 -2 0 -2\n0 -2 0 -2",
"output": "NO"
},
{
"input": "-1 1 -1 1\n-1 1 -1 1\n-1 1 -1 3\n-3 1 -3 1",
"output": "NO"
},
{
"input": "578327678 518066351 578327678 498442467\n583129774 498442467 578327678 518066351\n583129774 518066351 578327678 518066351\n583129774 498442467 578327678 518066351",
"output": "NO"
},
{
"input": "-973576966 32484917 -973576966 32484917\n-973576966 32484917 347173379 32484917\n-973576966 32484917 347173379 32484917\n-973576966 32484917 347173379 32484917",
"output": "NO"
},
{
"input": "572793036 194804279 572793036 -866298887\n572793036 461349977 -860420833 194804279\n572793036 461349977 572793036 -866298887\n-860420833 461349977 572793036 -866298887",
"output": "NO"
},
{
"input": "949753871 -467933239 -72251156 462207752\n949753871 462207752 425479768 -467933239\n425479768 462207752 425479768 -467933239\n949753871 -467933239 949753871 462207752",
"output": "NO"
},
{
"input": "1 -1 1 -1\n-1 -1 -1 -1\n1 0 -1 -1\n1 -1 -1 -1",
"output": "NO"
},
{
"input": "1 -1 1 -1\n1 0 1 0\n1 0 1 -1\n1 0 1 -1",
"output": "NO"
},
{
"input": "0 0 0 1\n0 1 0 1\n0 1 0 0\n0 1 0 1",
"output": "NO"
},
{
"input": "1 -1 1 0\n1 0 1 0\n0 0 0 -1\n1 -1 1 0",
"output": "NO"
},
{
"input": "0 0 2 2\n0 0 2 0\n2 2 2 2\n0 2 0 2",
"output": "NO"
},
{
"input": "-2 -1 -1 -1\n-2 -1 -1 -1\n-2 -1 -2 2\n-2 2 -1 2",
"output": "NO"
},
{
"input": "2 1 -1 0\n-1 0 2 1\n2 1 2 1\n-1 0 2 1",
"output": "NO"
},
{
"input": "1 -1 2 -1\n1 -2 2 -2\n1 -2 2 -2\n1 -2 2 -2",
"output": "NO"
},
{
"input": "-1 -2 -1 2\n-1 -2 -1 -2\n-1 2 -1 2\n-1 -2 -1 -2",
"output": "NO"
},
{
"input": "2 0 2 -1\n2 -1 -1 0\n2 -1 -1 0\n2 -1 -1 0",
"output": "NO"
},
{
"input": "2 -3 1 3\n1 -3 1 3\n2 3 2 -3\n2 -3 2 -3",
"output": "NO"
},
{
"input": "130120899 550158649 130120899 831843953\n130120899 550158649 130120899 831843953\n130120899 550158649 434006978 831843953\n434006978 550158649 434006978 550158649",
"output": "NO"
},
{
"input": "-214484034 559719641 -214484034 559719641\n-214484034 559719641 -214484034 559719641\n-214484034 2764087 -214484034 559719641\n-214484034 2764087 734280017 2764087",
"output": "NO"
},
{
"input": "-966947426 664261857 -994206270 664261857\n-966947426 664261857 -994206270 664261857\n-966947426 789165019 -966947426 789165019\n-966947426 664261857 -966947426 789165019",
"output": "NO"
},
{
"input": "264411509 -329579381 264411509 -329579381\n-726758913 -329579381 264411509 357369289\n-726758913 -329579381 264411509 -329579381\n264411509 -329579381 264411509 -329579381",
"output": "NO"
},
{
"input": "-193720583 -547078093 -570748852 58725936\n-570748852 -547078093 -570748852 58725936\n-193720583 58725936 -570748852 -547078093\n-570748852 -547078093 -193720583 58725936",
"output": "NO"
},
{
"input": "-534094150 -333730697 120658438 -333730697\n-534094150 -333730697 120658438 869464313\n-534094150 -333730697 -534094150 -333730697\n-534094150 869464313 -534094150 -333730697",
"output": "NO"
},
{
"input": "-328545071 835751660 -345950135 835751660\n-345950135 243569491 -328545071 835751660\n-328545071 835751660 -345950135 243569491\n-328545071 243569491 -328545071 243569491",
"output": "NO"
},
{
"input": "-985236057 -809433993 -985236057 -225363622\n-484344733 -225363622 -484344733 -225363622\n-985236057 -225363622 -985236057 -809433993\n-484344733 -225363622 -484344733 -809433993",
"output": "NO"
},
{
"input": "774287068 919049158 774287068 919049158\n250033372 653817677 250033372 653817677\n250033372 919049158 774287068 653817677\n250033372 653817677 250033372 653817677",
"output": "NO"
},
{
"input": "15319063 -661389770 632904085 -661389770\n15319063 834266473 632904085 834266473\n15319063 834266473 15319063 -661389770\n632904085 -661389770 632904085 834266473",
"output": "YES"
},
{
"input": "157550209 -594704878 157550209 524666828\n671878188 -594704878 157550209 -594704878\n671878188 -594704878 671878188 524666828\n671878188 524666828 157550209 524666828",
"output": "YES"
},
{
"input": "-887135208 728202342 127569272 728202342\n127569272 728202342 127569272 -932260532\n-887135208 -932260532 -887135208 728202342\n127569272 -932260532 -887135208 -932260532",
"output": "YES"
},
{
"input": "-777411660 -392696120 -777411660 878250237\n461320023 878250237 -777411660 878250237\n461320023 878250237 461320023 -392696120\n461320023 -392696120 -777411660 -392696120",
"output": "YES"
},
{
"input": "-892785315 567101756 -892785315 212349618\n-403060667 212349618 -403060667 567101756\n-403060667 567101756 -892785315 567101756\n-892785315 212349618 -403060667 212349618",
"output": "YES"
},
{
"input": "-360046034 -871603961 -37695563 -871603961\n-37695563 664955871 -37695563 -871603961\n-360046034 664955871 -360046034 -871603961\n-360046034 664955871 -37695563 664955871",
"output": "YES"
},
{
"input": "375089524 -852468724 -952575952 -852468724\n-952575952 -852468724 -952575952 -883150295\n-952575952 -883150295 375089524 -883150295\n375089524 -852468724 375089524 -883150295",
"output": "YES"
},
{
"input": "851113265 -893293930 851113265 -444742025\n-864765585 -893293930 -864765585 -444742025\n-864765585 -893293930 851113265 -893293930\n-864765585 -444742025 851113265 -444742025",
"output": "YES"
},
{
"input": "-309306779 559081237 255096743 559081237\n-309306779 -359724178 255096743 -359724178\n255096743 -359724178 255096743 559081237\n-309306779 559081237 -309306779 -359724178",
"output": "YES"
},
{
"input": "542957347 -480242202 566995046 -480242202\n542957347 -480242202 542957347 -298569507\n566995046 -298569507 542957347 -298569507\n566995046 -298569507 566995046 -480242202",
"output": "YES"
},
{
"input": "724715871 -943657730 964573294 -943657730\n724715871 -943657730 724715871 -216459206\n964573294 -216459206 964573294 -943657730\n724715871 -216459206 964573294 -216459206",
"output": "YES"
},
{
"input": "-394306310 -279360055 -394306310 771835446\n-394306310 -279360055 -358661829 -279360055\n-358661829 771835446 -358661829 -279360055\n-358661829 771835446 -394306310 771835446",
"output": "YES"
},
{
"input": "-204472047 -894485730 -204472047 640004355\n960702643 -894485730 960702643 640004355\n960702643 -894485730 -204472047 -894485730\n-204472047 640004355 960702643 640004355",
"output": "YES"
},
{
"input": "747591 5158024 -837871358 5158024\n-837871358 -874026904 747591 -874026904\n747591 -874026904 747591 5158024\n-837871358 -874026904 -837871358 5158024",
"output": "YES"
},
{
"input": "-442585231 90863587 800882871 90863587\n800882871 288218107 800882871 90863587\n800882871 288218107 -442585231 288218107\n-442585231 90863587 -442585231 288218107",
"output": "YES"
},
{
"input": "-969490772 476931470 -969490772 929999730\n-426216863 929999730 -969490772 929999730\n-426216863 929999730 -426216863 476931470\n-969490772 476931470 -426216863 476931470",
"output": "YES"
},
{
"input": "-683046010 -125472203 -683046010 418507423\n817863270 418507423 817863270 -125472203\n817863270 418507423 -683046010 418507423\n817863270 -125472203 -683046010 -125472203",
"output": "YES"
},
{
"input": "231996287 974811621 -923122611 974811621\n-923122611 646880519 -923122611 974811621\n231996287 646880519 231996287 974811621\n-923122611 646880519 231996287 646880519",
"output": "YES"
},
{
"input": "-83429272 -350159212 -990378619 -350159212\n-990378619 -350159212 -990378619 247777831\n-83429272 -350159212 -83429272 247777831\n-990378619 247777831 -83429272 247777831",
"output": "YES"
},
{
"input": "-679599706 974881765 -679599706 -84192294\n-554774137 -84192294 -554774137 974881765\n-554774137 974881765 -679599706 974881765\n-554774137 -84192294 -679599706 -84192294",
"output": "YES"
},
{
"input": "-155221108 -190475340 -155221108 -819044368\n-155221108 -190475340 -155875856 -190475340\n-155875856 -190475340 -155875856 -819044368\n-155875856 -819044368 -155221108 -819044368",
"output": "YES"
},
{
"input": "377126871 -877660066 -633390329 -877660066\n377126871 -175686511 377126871 -877660066\n-633390329 -877660066 -633390329 -175686511\n-633390329 -175686511 377126871 -175686511",
"output": "YES"
},
{
"input": "919022298 897009314 77151365 897009314\n77151365 579795002 919022298 579795002\n77151365 579795002 77151365 897009314\n919022298 579795002 919022298 897009314",
"output": "YES"
},
{
"input": "146411776 -188986353 146411776 -808042296\n-381166510 -808042296 -381166510 -188986353\n146411776 -188986353 -381166510 -188986353\n146411776 -808042296 -381166510 -808042296",
"output": "YES"
},
{
"input": "438703475 871560515 571565350 871560515\n571565350 -204157747 438703475 -204157747\n438703475 -204157747 438703475 871560515\n571565350 -204157747 571565350 871560515",
"output": "YES"
},
{
"input": "0 0 0 0\n5 5 5 5\n5 0 5 5\n0 5 0 0",
"output": "NO"
},
{
"input": "0 1 1 2\n2 1 1 2\n1 0 0 1\n2 1 1 0",
"output": "NO"
},
{
"input": "-3 0 -3 3\n0 0 0 3\n3 3 -3 3\n3 0 -3 0",
"output": "NO"
},
{
"input": "0 0 0 0\n1 1 1 1\n0 1 0 1\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 1 0\n1 1 1 1",
"output": "NO"
},
{
"input": "0 0 1 0\n1 1 0 1\n0 0 1 0\n1 1 0 1",
"output": "NO"
},
{
"input": "0 0 0 1\n0 1 1 1\n1 1 1 0\n1 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 1\n0 1 1 0\n1 1 0 0\n1 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n1 1 1 1\n0 1 1 0\n1 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 1 1 1\n0 0 1 0\n0 1 1 1",
"output": "NO"
}
] | 92 | 0 | 3.977 | 1,476 |
459 | Pashmak and Parmida's problem | [
"data structures",
"divide and conquer",
"sortings"
] | null | null | Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.
There is a sequence *a* that consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Let's denote *f*(*l*,<=*r*,<=*x*) the number of indices *k* such that: *l*<=β€<=*k*<=β€<=*r* and *a**k*<==<=*x*. His task is to calculate the number of pairs of indicies *i*,<=*j* (1<=β€<=*i*<=<<=*j*<=β€<=*n*) such that *f*(1,<=*i*,<=*a**i*)<=><=*f*(*j*,<=*n*,<=*a**j*).
Help Pashmak with the test. | The first line of the input contains an integer *n* (1<=β€<=*n*<=β€<=106). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109). | Print a single integer β the answer to the problem. | [
"7\n1 2 1 1 2 2 1\n",
"3\n1 1 1\n",
"5\n1 2 3 4 5\n"
] | [
"8\n",
"1\n",
"0\n"
] | none | [
{
"input": "7\n1 2 1 1 2 2 1",
"output": "8"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "5\n1 2 3 4 5",
"output": "0"
},
{
"input": "24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4",
"output": "114"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "4\n1 1 2 2",
"output": "1"
},
{
"input": "5\n1 1 2 2 2",
"output": "2"
}
] | 3,000 | 121,241,600 | 0 | 1,481 |
|
20 | Dijkstra? | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=β€<=*n*<=β€<=105,<=0<=β€<=*m*<=β€<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*,<=1<=β€<=*w**i*<=β€<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices. | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input": "3 3\n1 2 1\n1 3 2\n2 3 1",
"output": "1 3 "
},
{
"input": "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173",
"output": "1 5 8 7 3 10 "
},
{
"input": "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "1 8 10 "
},
{
"input": "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135",
"output": "1 9 5 8 10 "
},
{
"input": "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "1 4 6 10 "
}
] | 108 | 9,830,400 | 0 | 1,482 |
1,003 | Binary String Constructing | [
"constructive algorithms"
] | null | null | You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i < n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists.
For example, for the string "01010" there are four indices $i$ such that $1 \le i < n$ and $s_i \ne s_{i + 1}$ ($i = 1, 2, 3, 4$). For the string "111001" there are two such indices $i$ ($i = 3, 5$).
Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1. | The first line of the input contains three integers $a$, $b$ and $x$ ($1 \le a, b \le 100, 1 \le x < a + b)$. | Print only one string $s$, where $s$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists. | [
"2 2 1\n",
"3 3 3\n",
"5 3 6\n"
] | [
"1100\n",
"101100\n",
"01010100\n"
] | All possible answers for the first example:
- 1100; - 0011.
All possible answers for the second example:
- 110100; - 101100; - 110010; - 100110; - 011001; - 001101; - 010011; - 001011. | [
{
"input": "2 2 1",
"output": "1100"
},
{
"input": "3 3 3",
"output": "101100"
},
{
"input": "5 3 6",
"output": "01010100"
},
{
"input": "100 1 2",
"output": "01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 1 1",
"output": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"
},
{
"input": "1 100 1",
"output": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "1 100 2",
"output": "10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "7 8 7",
"output": "101010111110000"
},
{
"input": "100 100 199",
"output": "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010"
},
{
"input": "50 47 18",
"output": "0101010101010101011111111111111111111111111111111111111100000000000000000000000000000000000000000"
},
{
"input": "2 3 3",
"output": "10110"
},
{
"input": "100 100 100",
"output": "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111"
},
{
"input": "2 2 2",
"output": "1001"
},
{
"input": "3 4 6",
"output": "1010101"
},
{
"input": "1 1 1",
"output": "10"
},
{
"input": "5 6 2",
"output": "10000011111"
},
{
"input": "5 4 2",
"output": "011110000"
},
{
"input": "2 3 4",
"output": "10101"
},
{
"input": "3 3 2",
"output": "100011"
},
{
"input": "100 99 100",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000"
},
{
"input": "3 2 1",
"output": "00011"
},
{
"input": "12 74 22",
"output": "10101010101010101010100111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "6 84 12",
"output": "101010101010111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "3 2 4",
"output": "01010"
},
{
"input": "66 11 22",
"output": "01010101010101010101010000000000000000000000000000000000000000000000000000000"
},
{
"input": "83 83 83",
"output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010111111111111111111111111111111111111111111000000000000000000000000000000000000000000"
},
{
"input": "9 89 18",
"output": "10101010101010101011111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "2 1 2",
"output": "010"
},
{
"input": "52 12 17",
"output": "0101010101010101000000000000000000000000000000000000000000001111"
},
{
"input": "55 56 110",
"output": "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"input": "67 81 40",
"output": "1010101010101010101010101010101010101010000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "15 26 24",
"output": "10101010101010101010101000011111111111111"
},
{
"input": "7 99 14",
"output": "1010101010101011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "99 41 17",
"output": "01010101010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111"
},
{
"input": "91 87 11",
"output": "0101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "73 61 122",
"output": "01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101000000000000"
},
{
"input": "10 40 1",
"output": "11111111111111111111111111111111111111110000000000"
},
{
"input": "10 6 10",
"output": "0101010101100000"
},
{
"input": "78 67 117",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000000000000000000111111111"
},
{
"input": "3 5 6",
"output": "10101011"
},
{
"input": "30 34 44",
"output": "1010101010101010101010101010101010101010101000000000111111111111"
},
{
"input": "2 15 4",
"output": "10101111111111111"
},
{
"input": "4 9 6",
"output": "1010100111111"
}
] | 140 | 0 | 3 | 1,484 |
|
544 | Set of Strings | [
"implementation",
"strings"
] | null | null | You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first characters of these strings are distinct.
Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist. | The first line contains a positive integer *k* (1<=β€<=*k*<=β€<=26) β the number of strings that should be in a beautiful sequence.
The second line contains string *q*, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive. | If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next *k* lines print the beautiful sequence of strings *s*1,<=*s*2,<=...,<=*s**k*.
If there are multiple possible answers, print any of them. | [
"1\nabca\n",
"2\naaacas\n",
"4\nabc\n"
] | [
"YES\nabca\n",
"YES\naaa\ncas\n",
"NO\n"
] | In the second sample there are two possible answers: {"*aaaca*",β"*s*"} and {"*aaa*",β"*cas*"}. | [
{
"input": "1\nabca",
"output": "YES\nabca"
},
{
"input": "2\naaacas",
"output": "YES\naaa\ncas"
},
{
"input": "4\nabc",
"output": "NO"
},
{
"input": "3\nnddkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk",
"output": "YES\nn\ndd\nkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk"
},
{
"input": "26\nbiibfmmfifmffbmmfmbmbmiimbmiffmffibibfbiffibibiiimbffbbfbifmiibffbmbbbfmfibmibfffibfbffmfmimbmmmfmfm",
"output": "NO"
},
{
"input": "3\nkydoybxlfeugtrbvqnrjtzshorrsrwsxkvlwyolbaadtzpmyyfllxuciia",
"output": "YES\nk\ny\ndoybxlfeugtrbvqnrjtzshorrsrwsxkvlwyolbaadtzpmyyfllxuciia"
},
{
"input": "3\nssussususskkskkskuusksuuussksukkskuksukukusssususuususkkuukssuksskusukkssuksskskuskusussusskskksksus",
"output": "YES\nss\nussususs\nkkskkskuusksuuussksukkskuksukukusssususuususkkuukssuksskusukkssuksskskuskusussusskskksksus"
},
{
"input": "5\naaaaabcdef",
"output": "YES\naaaaa\nb\nc\nd\nef"
},
{
"input": "3\niiiiiiimiriiriwmimtmwrhhxmbmhwgghhgbqhywebrblyhlxjrthoooltehrmdhqhuodjmsjwcgrfnttiitpmqvbhlafwtzyikc",
"output": "YES\niiiiiii\nmi\nriiriwmimtmwrhhxmbmhwgghhgbqhywebrblyhlxjrthoooltehrmdhqhuodjmsjwcgrfnttiitpmqvbhlafwtzyikc"
},
{
"input": "20\ngggggllglgllltgtlglttstsgtttsslhhlssghgagtlsaghhoggtfgsaahtotdodthfltdxggxislnttlanxonhnkddtigppitdh",
"output": "NO"
},
{
"input": "16\nkkkkkkyykkynkknkkonyokdndkyonokdywkwykdkdotknnwzkoywiooinkcyzyntcdnitnppnpziomyzdspomoqmomcyrrospppn",
"output": "NO"
},
{
"input": "15\nwwwgggowgwwhoohwgwghwyohhggywhyyodgwydwgggkhgyydqyggkgkpokgthqghidhworprodtcogqkwgtfiodwdurcctkmrfmh",
"output": "YES\nwww\nggg\nowgww\nhoohwgwghw\nyohhggywhyyo\ndgwydwggg\nkhgyyd\nqyggkgk\npokg\nthqgh\nidhwo\nrprodt\ncogqkwgt\nfiodwd\nurcctkmrfmh"
},
{
"input": "15\nnnnnnntnttttttqqnqqynnqqwwnnnwneenhwtyhhoqeyeqyeuthwtnhtpnphhwetjhouhwnpojvvovoswwjryrwerbwwpbvrwvjj",
"output": "YES\nnnnnnn\ntntttttt\nqqnqq\nynnqq\nwwnnnwn\neen\nhwtyhh\noqeyeqye\nuthwtnht\npnphhwet\njhouhwnpoj\nvvovo\nswwj\nryrwer\nbwwpbvrwvjj"
},
{
"input": "15\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv",
"output": "NO"
},
{
"input": "1\niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiaaaaaiiiiaiaiiiiaaiaiiiaiiaiaaiaiiaiiiiiaiiiaiiiaiaiaai",
"output": "YES\niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiaaaaaiiiiaiaiiiiaaiaiiiaiiaiaaiaiiaiiiiiaiiiaiiiaiaiaai"
},
{
"input": "26\nvvvnnsnnnpsnnswwspncvshtncwphaphmwnwkhvvhuvctvnehemowkmtzissswjaxuuvphzrmfzihamdqmmyhhijbitlipgltyy",
"output": "YES\nvvv\nnn\nsnnn\npsnns\nwwspn\ncvs\nh\ntncwph\naph\nmwnw\nkhvvh\nuvctvn\nehem\nowkmt\nz\nisssw\nja\nxuuvphz\nrm\nfziham\nd\nqmm\nyhhij\nbit\nlip\ngltyy"
},
{
"input": "26\njexzsbwaih",
"output": "NO"
},
{
"input": "1\nk",
"output": "YES\nk"
},
{
"input": "1\nzz",
"output": "YES\nzz"
},
{
"input": "3\nziw",
"output": "YES\nz\ni\nw"
},
{
"input": "26\ntjmbyqwuahlixegopkzrfndcsv",
"output": "YES\nt\nj\nm\nb\ny\nq\nw\nu\na\nh\nl\ni\nx\ne\ng\no\np\nk\nz\nr\nf\nn\nd\nc\ns\nv"
},
{
"input": "25\nvobekscyadzqwnjxruplifmthg",
"output": "YES\nv\no\nb\ne\nk\ns\nc\ny\na\nd\nz\nq\nw\nn\nj\nx\nr\nu\np\nl\ni\nf\nm\nt\nhg"
},
{
"input": "26\nlllplzkkzflzflffzznnnnfgflqlttlmtnkzlztskngyymitqagattkdllyutzimsrskpapcmuupjdopxqlnhqcscwvdtxbflefy",
"output": "YES\nlll\npl\nz\nkkz\nflzflffzz\nnnnnf\ngfl\nql\nttl\nmtnkzlzt\nskng\nyym\nitq\nagattk\ndlly\nutzims\nrskpap\ncmuup\njd\nop\nxqln\nhqcsc\nw\nvdtx\nbfl\nefy"
},
{
"input": "25\nkkrrkrkrkrsrskpskbrppdsdbgbkrbllkbswdwcchgskmkhwiidicczlscsodtjglxbmeotzxnmbjmoqgkquglaoxgcykxvbhdi",
"output": "YES\nkk\nrrkrkrkr\nsrsk\npsk\nbrpp\ndsdb\ngbkrb\nllkbs\nwdw\ncc\nhgsk\nmkhw\niidicc\nzlscs\nod\nt\njgl\nxbm\neotzx\nnmbjmo\nqgkq\nugl\naoxgc\nykx\nvbhdi"
},
{
"input": "25\nuuuuuccpucubccbupxubcbpujiliwbpqbpyiweuywaxwqasbsllwehceruytjvphytraawgbjmerfeymoayujqranlvkpkiypadr",
"output": "YES\nuuuuu\ncc\npucu\nbccbup\nxubcbpu\nj\ni\nli\nwbp\nqbp\nyiw\neuyw\naxwqa\nsbsllwe\nhce\nruy\ntj\nvphytraaw\ngbj\nmer\nfeym\noayujqra\nnlv\nkpkiypa\ndr"
},
{
"input": "26\nxxjxodrogovufvohrodliretxxyjqnrbzmicorptkjafiwmsbwml",
"output": "YES\nxx\njx\no\nd\nro\ngo\nv\nu\nfvo\nhrod\nl\nir\ne\ntxx\nyj\nq\nnr\nb\nz\nmi\ncor\npt\nkj\nafi\nwm\nsbwml"
},
{
"input": "26\npjhsxjbvkqntwmsdnrguecaofylzti",
"output": "YES\np\nj\nh\ns\nxj\nb\nv\nk\nq\nn\nt\nw\nms\ndn\nr\ng\nu\ne\nc\na\no\nf\ny\nl\nzt\ni"
},
{
"input": "25\nrrrrqqwrlqrwglrlylwhrrwyvrhvzgvqahrhgsvavtggyduayivxzgeicinlnrkapoepbsfyjjrt",
"output": "YES\nrrrr\nqq\nwr\nlqrw\nglrl\nylw\nhrrwy\nvrhv\nzgvq\nahrhg\nsvav\ntggy\nd\nuay\niv\nxzg\nei\nci\nnlnr\nka\np\noep\nbs\nfy\njjrt"
},
{
"input": "26\ncccccccaacwwaxxaacczacnnnqqwnaggzqrwagcnabxnrcvgjqjamqzgdntzanaxvjfwqlvdttuzjoxiwtkqvrydospmpeirhg",
"output": "YES\nccccccc\naac\nwwa\nxxaacc\nzac\nnnn\nqqwna\nggzq\nrwagcna\nbxnrc\nvg\njqja\nmqzg\ndn\ntzanaxvj\nfwq\nlvdtt\nuzj\nox\niwt\nkqvr\nydo\ns\npmp\neir\nhg"
},
{
"input": "4\nsssssssssssssssssssssssssslsslslsllsslssslslssllaaslsaalsasaassllasasalrlrslarlaarlsrsaslasarlr",
"output": "YES\nssssssssssssssssssssssssss\nlsslslsllsslssslslssll\naaslsaalsasaassllasasal\nrlrslarlaarlsrsaslasarlr"
},
{
"input": "26\na",
"output": "NO"
},
{
"input": "26\nab",
"output": "NO"
},
{
"input": "2\nab",
"output": "YES\na\nb"
}
] | 62 | 0 | 3 | 1,487 |
|
402 | Searching for Graph | [
"brute force",
"constructive algorithms",
"graphs"
] | null | null | Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill:
- the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - for any integer *k* (1<=β€<=*k*<=β€<=*n*), any subgraph consisting of *k* vertices contains at most 2*k*<=+<=*p* edges.
A subgraph of a graph is some set of the graph vertices and some set of the graph edges. At that, the set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices.
Your task is to find a *p*-interesting graph consisting of *n* vertices. | The first line contains a single integer *t* (1<=β€<=*t*<=β€<=5) β the number of tests in the input. Next *t* lines each contains two space-separated integers: *n*, *p* (5<=β€<=*n*<=β€<=24; *p*<=β₯<=0; ) β the number of vertices in the graph and the interest value for the appropriate test.
It is guaranteed that the required graph exists. | For each of the *t* tests print 2*n*<=+<=*p* lines containing the description of the edges of a *p*-interesting graph: the *i*-th line must contain two space-separated integers *a**i*,<=*b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*; *a**i*<=β <=*b**i*) β two vertices, connected by an edge in the resulting graph. Consider the graph vertices numbered with integers from 1 to *n*.
Print the answers to the tests in the order the tests occur in the input. If there are multiple solutions, you can print any of them. | [
"1\n6 0\n"
] | [
"1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n"
] | none | [
{
"input": "1\n6 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6"
},
{
"input": "1\n5 0",
"output": "1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5"
},
{
"input": "5\n6 0\n5 0\n7 0\n8 0\n9 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6"
},
{
"input": "5\n6 1\n5 0\n7 1\n8 1\n9 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6\n3 7"
},
{
"input": "5\n24 0\n23 0\n22 0\n21 0\n24 1",
"output": "1 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\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\n3 4\n3 5\n3 6\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\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..."
},
{
"input": "5\n24 1\n23 1\n22 1\n21 1\n20 1",
"output": "1 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\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\n3 4\n3 5\n3 6\n3 7\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\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\n..."
},
{
"input": "5\n20 0\n19 0\n18 0\n17 0\n16 0",
"output": "1 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\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\n3 4\n3 5\n3 6\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\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\n3 4\n3 5\n3 6\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 1..."
},
{
"input": "5\n15 0\n14 0\n13 0\n12 0\n11 0",
"output": "1 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\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\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\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n2 3..."
},
{
"input": "5\n10 0\n20 0\n24 0\n19 0\n17 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\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\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\n3 4\n3 5\n3 6\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\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13..."
},
{
"input": "5\n24 0\n23 0\n24 1\n23 1\n22 0",
"output": "1 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\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\n3 4\n3 5\n3 6\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\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..."
},
{
"input": "5\n24 0\n24 0\n24 0\n24 0\n24 0",
"output": "1 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\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\n3 4\n3 5\n3 6\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\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..."
},
{
"input": "5\n23 0\n23 0\n23 0\n23 0\n23 0",
"output": "1 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\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\n3 4\n3 5\n3 6\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\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\n3 4\n3 5\n..."
},
{
"input": "5\n19 1\n18 1\n17 1\n16 1\n15 1",
"output": "1 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\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\n3 4\n3 5\n3 6\n3 7\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\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\n3 4\n3 5\n3 6\n3 7\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\n2 3\n..."
},
{
"input": "5\n15 1\n14 1\n13 1\n12 1\n11 1",
"output": "1 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\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\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\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n..."
},
{
"input": "5\n24 2\n24 1\n24 0\n23 0\n23 1",
"output": "1 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\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\n3 4\n3 5\n3 6\n3 7\n3 8\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\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\n..."
},
{
"input": "5\n24 10\n23 50\n24 228\n24 200\n23 150",
"output": "1 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\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\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\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\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2..."
},
{
"input": "5\n24 228\n24 228\n24 228\n24 228\n24 228",
"output": "1 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\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\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\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\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\n4 18\n4 19\n4 20\n4 21\n4 22\n4 23\n4 24\n5 6\n5 7\n5 8\n5 9\n5..."
},
{
"input": "5\n20 1\n20 0\n19 0\n20 0\n20 0",
"output": "1 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\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\n3 4\n3 5\n3 6\n3 7\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\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\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13..."
},
{
"input": "5\n21 1\n19 1\n18 1\n20 1\n17 1",
"output": "1 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\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\n3 4\n3 5\n3 6\n3 7\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\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\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n..."
},
{
"input": "5\n10 1\n11 1\n12 1\n13 1\n14 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\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\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1..."
},
{
"input": "1\n24 100",
"output": "1 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\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\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\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\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\n4 18\n4 19\n4 20\n4 21\n4 22\n4 23\n4 24\n5 6\n5 7\n5 8\n5 9\n5..."
}
] | 124 | 4,915,200 | 3 | 1,489 |
|
93 | Frames | [
"implementation"
] | A. Frames | 2 | 256 | Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.
This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good.
Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, *m* icons can fit in a horizontal row in any window.
Igor K.'s computer contains *n* folders in the D: disk's root catalog. The folders are numbered from 1 to *n* in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from *a* to *b* inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from *a* to *b* and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders. | The only line contains four integers *n*, *m*, *a*, *b* (1<=β€<=*n*,<=*m*<=β€<=109, 1<=β€<=*a*<=β€<=*b*<=β€<=*n*). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted. | Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from *a* to *b*. | [
"11 4 3 9\n",
"20 5 2 20\n"
] | [
"3\n",
"2\n"
] | The images below illustrate statement tests.
The first test:
<img class="tex-graphics" src="https://espresso.codeforces.com/a0e4ba690dd16e3c68210a28afd82020b23fb605.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection.
The second test:
<img class="tex-graphics" src="https://espresso.codeforces.com/289e2666a3d8b3dfe5b22ff3d88976df711640f7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In this test we can first select all folders in the first row (2, 3, 4, 5), then β all other ones. | [
{
"input": "11 4 3 9",
"output": "3"
},
{
"input": "20 5 2 20",
"output": "2"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "26 5 2 18",
"output": "3"
},
{
"input": "21 5 1 15",
"output": "1"
},
{
"input": "21 5 1 21",
"output": "1"
},
{
"input": "21 5 8 14",
"output": "2"
},
{
"input": "20 4 1 20",
"output": "1"
},
{
"input": "21 5 1 13",
"output": "2"
},
{
"input": "21 5 4 15",
"output": "2"
},
{
"input": "17 3 1 16",
"output": "2"
},
{
"input": "19 5 7 19",
"output": "2"
},
{
"input": "18 2 1 13",
"output": "2"
},
{
"input": "21 3 6 11",
"output": "2"
},
{
"input": "21 5 3 12",
"output": "2"
},
{
"input": "21 3 6 10",
"output": "3"
},
{
"input": "28 5 4 26",
"output": "3"
},
{
"input": "21 5 6 18",
"output": "2"
},
{
"input": "21 5 4 21",
"output": "2"
},
{
"input": "17 5 6 17",
"output": "1"
},
{
"input": "21 5 9 12",
"output": "2"
},
{
"input": "21 3 6 7",
"output": "2"
},
{
"input": "21 5 7 9",
"output": "1"
},
{
"input": "12 4 5 8",
"output": "1"
},
{
"input": "21 3 6 8",
"output": "2"
},
{
"input": "21 1 5 17",
"output": "1"
},
{
"input": "5 5 2 4",
"output": "1"
},
{
"input": "18 4 6 17",
"output": "2"
},
{
"input": "18 4 6 18",
"output": "2"
},
{
"input": "16 4 1 16",
"output": "1"
},
{
"input": "20 4 7 14",
"output": "2"
},
{
"input": "17 3 12 16",
"output": "3"
},
{
"input": "12 4 8 9",
"output": "2"
},
{
"input": "11 8 2 7",
"output": "1"
},
{
"input": "27 5 4 24",
"output": "3"
},
{
"input": "29 5 12 27",
"output": "3"
},
{
"input": "30 5 5 29",
"output": "2"
},
{
"input": "91 2 15 72",
"output": "1"
},
{
"input": "41 1 8 27",
"output": "1"
},
{
"input": "26 5 7 21",
"output": "2"
},
{
"input": "70 5 31 33",
"output": "1"
},
{
"input": "84 9 6 80",
"output": "3"
},
{
"input": "79 8 41 64",
"output": "1"
},
{
"input": "63 11 23 48",
"output": "2"
},
{
"input": "97 9 18 54",
"output": "2"
},
{
"input": "75 18 20 23",
"output": "1"
},
{
"input": "66 42 43 44",
"output": "1"
},
{
"input": "92 54 20 53",
"output": "1"
},
{
"input": "32 90 31 32",
"output": "1"
},
{
"input": "18 100 6 6",
"output": "1"
},
{
"input": "458 12 203 310",
"output": "2"
},
{
"input": "149 49 92 129",
"output": "2"
},
{
"input": "264 2 9 63",
"output": "2"
},
{
"input": "908 6 407 531",
"output": "3"
},
{
"input": "410 36 109 191",
"output": "2"
},
{
"input": "301 38 97 171",
"output": "3"
},
{
"input": "691 27 313 499",
"output": "3"
},
{
"input": "939 42 86 827",
"output": "3"
},
{
"input": "280 32 64 277",
"output": "3"
},
{
"input": "244 25 94 199",
"output": "3"
},
{
"input": "134 110 11 52",
"output": "1"
},
{
"input": "886 251 61 672",
"output": "3"
},
{
"input": "261 686 243 254",
"output": "1"
},
{
"input": "162 309 68 98",
"output": "1"
},
{
"input": "476 398 77 256",
"output": "1"
},
{
"input": "258 224 84 174",
"output": "1"
},
{
"input": "357 182 73 247",
"output": "2"
},
{
"input": "488 655 290 457",
"output": "1"
},
{
"input": "149 334 78 105",
"output": "1"
},
{
"input": "488 519 203 211",
"output": "1"
},
{
"input": "192293793 2864 5278163 190776899",
"output": "3"
},
{
"input": "38644205 2729 9325777 31658388",
"output": "3"
},
{
"input": "268836959 6117 166683294 249843000",
"output": "3"
},
{
"input": "831447817 8377 549549158 577671489",
"output": "3"
},
{
"input": "444819690 3519 48280371 117052060",
"output": "3"
},
{
"input": "729584406 8367 456501516 557088265",
"output": "3"
},
{
"input": "629207296 3735 112288653 309364482",
"output": "3"
},
{
"input": "775589210 6930 266348458 604992807",
"output": "3"
},
{
"input": "249414894 1999 34827655 127026562",
"output": "3"
},
{
"input": "566377385 227 424126063 478693454",
"output": "3"
},
{
"input": "960442940 572344654 77422042 406189391",
"output": "1"
},
{
"input": "291071313 592207814 6792338 181083636",
"output": "1"
},
{
"input": "191971162 306112722 18212391 188328807",
"output": "1"
},
{
"input": "609162932 300548167 21640850 411089609",
"output": "2"
},
{
"input": "645010014 34698301 217620581 416292490",
"output": "3"
},
{
"input": "51474721 867363452 12231088 43489285",
"output": "1"
},
{
"input": "484381636 927869638 57278216 175514226",
"output": "1"
},
{
"input": "491259590 529594367 305425951 326414536",
"output": "1"
},
{
"input": "733405771 830380469 19971607 389270995",
"output": "1"
},
{
"input": "446237720 920085248 296916273 439113596",
"output": "1"
},
{
"input": "12 6 3 10",
"output": "2"
},
{
"input": "25 2 8 11",
"output": "2"
},
{
"input": "17 8 3 15",
"output": "2"
},
{
"input": "9 2 4 7",
"output": "2"
},
{
"input": "6 7 5 6",
"output": "1"
},
{
"input": "13 2 1 6",
"output": "1"
},
{
"input": "15 8 10 14",
"output": "1"
},
{
"input": "27 2 5 13",
"output": "2"
},
{
"input": "14 8 2 12",
"output": "2"
},
{
"input": "61 1 10 38",
"output": "1"
},
{
"input": "15 6 7 15",
"output": "1"
},
{
"input": "100 1 2 15",
"output": "1"
},
{
"input": "10 1 4 5",
"output": "1"
},
{
"input": "6 3 1 6",
"output": "1"
},
{
"input": "4 3 3 4",
"output": "2"
},
{
"input": "5 2 1 5",
"output": "1"
},
{
"input": "7 3 1 1",
"output": "1"
},
{
"input": "7 3 1 2",
"output": "1"
},
{
"input": "7 3 1 3",
"output": "1"
},
{
"input": "7 3 1 4",
"output": "2"
},
{
"input": "7 3 1 5",
"output": "2"
},
{
"input": "7 3 1 6",
"output": "1"
},
{
"input": "7 3 1 7",
"output": "1"
},
{
"input": "7 3 2 2",
"output": "1"
},
{
"input": "7 3 2 3",
"output": "1"
},
{
"input": "7 3 2 4",
"output": "2"
},
{
"input": "7 3 2 5",
"output": "2"
},
{
"input": "7 3 2 6",
"output": "2"
},
{
"input": "7 3 2 7",
"output": "2"
},
{
"input": "7 3 3 3",
"output": "1"
},
{
"input": "7 3 3 4",
"output": "2"
},
{
"input": "7 3 3 5",
"output": "2"
},
{
"input": "7 3 3 6",
"output": "2"
},
{
"input": "7 3 3 7",
"output": "2"
},
{
"input": "7 3 4 4",
"output": "1"
},
{
"input": "7 3 4 5",
"output": "1"
},
{
"input": "7 3 4 6",
"output": "1"
},
{
"input": "7 3 4 7",
"output": "1"
},
{
"input": "7 3 5 5",
"output": "1"
},
{
"input": "7 3 5 6",
"output": "1"
},
{
"input": "7 3 5 7",
"output": "2"
},
{
"input": "7 3 6 6",
"output": "1"
},
{
"input": "7 3 6 7",
"output": "2"
},
{
"input": "7 3 7 7",
"output": "1"
},
{
"input": "8 3 1 1",
"output": "1"
},
{
"input": "8 3 1 2",
"output": "1"
},
{
"input": "8 3 1 3",
"output": "1"
},
{
"input": "8 3 1 4",
"output": "2"
},
{
"input": "8 3 1 5",
"output": "2"
},
{
"input": "8 3 1 6",
"output": "1"
},
{
"input": "8 3 1 7",
"output": "2"
},
{
"input": "8 3 1 8",
"output": "1"
},
{
"input": "8 3 2 2",
"output": "1"
},
{
"input": "8 3 2 3",
"output": "1"
},
{
"input": "8 3 2 4",
"output": "2"
},
{
"input": "8 3 2 5",
"output": "2"
},
{
"input": "8 3 2 6",
"output": "2"
},
{
"input": "8 3 2 7",
"output": "2"
},
{
"input": "8 3 2 8",
"output": "2"
},
{
"input": "8 3 3 3",
"output": "1"
},
{
"input": "8 3 3 4",
"output": "2"
},
{
"input": "8 3 3 5",
"output": "2"
},
{
"input": "8 3 3 6",
"output": "2"
},
{
"input": "8 3 3 7",
"output": "3"
},
{
"input": "8 3 3 8",
"output": "2"
},
{
"input": "8 3 4 4",
"output": "1"
},
{
"input": "8 3 4 5",
"output": "1"
},
{
"input": "8 3 4 6",
"output": "1"
},
{
"input": "8 3 4 7",
"output": "2"
},
{
"input": "8 3 4 8",
"output": "1"
},
{
"input": "8 3 5 5",
"output": "1"
},
{
"input": "8 3 5 6",
"output": "1"
},
{
"input": "8 3 5 7",
"output": "2"
},
{
"input": "8 3 5 8",
"output": "2"
},
{
"input": "8 3 6 6",
"output": "1"
},
{
"input": "8 3 6 7",
"output": "2"
},
{
"input": "8 3 6 8",
"output": "2"
},
{
"input": "8 3 7 7",
"output": "1"
},
{
"input": "8 3 7 8",
"output": "1"
},
{
"input": "8 3 8 8",
"output": "1"
}
] | 124 | 0 | 3.969 | 1,494 |
807 | Is it rated? | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=1000) β the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=4126) β the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n1 1\n1 1",
"output": "maybe"
},
{
"input": "2\n4126 4126\n4126 4126",
"output": "maybe"
},
{
"input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423",
"output": "rated"
},
{
"input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110",
"output": "unrated"
},
{
"input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143",
"output": "maybe"
},
{
"input": "2\n3936 3936\n2967 2967",
"output": "maybe"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 1\n1 2",
"output": "rated"
},
{
"input": "2\n2967 2967\n3936 3936",
"output": "unrated"
},
{
"input": "3\n1200 1200\n1200 1200\n1300 1300",
"output": "unrated"
},
{
"input": "3\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n3 2\n3 2",
"output": "rated"
},
{
"input": "3\n5 5\n4 4\n3 4",
"output": "rated"
},
{
"input": "3\n200 200\n200 200\n300 300",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n3 3",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699",
"output": "maybe"
},
{
"input": "2\n10 10\n8 8",
"output": "maybe"
},
{
"input": "3\n1500 1500\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n100 100\n100 100\n70 70\n80 80",
"output": "unrated"
},
{
"input": "2\n1 2\n2 1",
"output": "rated"
},
{
"input": "3\n5 5\n4 3\n3 3",
"output": "rated"
},
{
"input": "3\n1600 1650\n1500 1550\n1400 1450",
"output": "rated"
},
{
"input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700",
"output": "unrated"
},
{
"input": "2\n1600 1600\n1400 1400",
"output": "maybe"
},
{
"input": "2\n3 1\n9 8",
"output": "rated"
},
{
"input": "2\n2 1\n1 1",
"output": "rated"
},
{
"input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670",
"output": "unrated"
},
{
"input": "2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n10 11\n5 4",
"output": "rated"
},
{
"input": "2\n15 14\n13 12",
"output": "rated"
},
{
"input": "2\n2 1\n2 2",
"output": "rated"
},
{
"input": "3\n2670 2670\n3670 3670\n4106 4106",
"output": "unrated"
},
{
"input": "3\n4 5\n3 3\n2 2",
"output": "rated"
},
{
"input": "2\n10 9\n10 10",
"output": "rated"
},
{
"input": "3\n1011 1011\n1011 999\n2200 2100",
"output": "rated"
},
{
"input": "2\n3 3\n5 5",
"output": "unrated"
},
{
"input": "2\n1500 1500\n3000 2000",
"output": "rated"
},
{
"input": "2\n5 6\n5 5",
"output": "rated"
},
{
"input": "3\n2000 2000\n1500 1501\n500 500",
"output": "rated"
},
{
"input": "2\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n1 2\n1 1",
"output": "rated"
},
{
"input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n15 14\n14 13",
"output": "rated"
},
{
"input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900",
"output": "unrated"
},
{
"input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884",
"output": "rated"
},
{
"input": "2\n100 99\n100 100",
"output": "rated"
},
{
"input": "4\n2 2\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n100 101\n100 100\n100 100",
"output": "rated"
},
{
"input": "4\n1000 1001\n900 900\n950 950\n890 890",
"output": "rated"
},
{
"input": "2\n2 3\n1 1",
"output": "rated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n3 2\n2 2",
"output": "rated"
},
{
"input": "2\n3 2\n3 3",
"output": "rated"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n3 2\n3 3\n3 3",
"output": "rated"
},
{
"input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "3\n1000 1000\n500 500\n400 300",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000",
"output": "unrated"
},
{
"input": "2\n1 1\n2 3",
"output": "rated"
},
{
"input": "2\n6 2\n6 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246",
"output": "unrated"
},
{
"input": "2\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699",
"output": "maybe"
},
{
"input": "2\n20 30\n10 5",
"output": "rated"
},
{
"input": "3\n1 1\n2 2\n1 1",
"output": "unrated"
},
{
"input": "2\n1 2\n3 3",
"output": "rated"
},
{
"input": "5\n5 5\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 2\n2 1",
"output": "rated"
},
{
"input": "2\n100 100\n90 89",
"output": "rated"
},
{
"input": "2\n1000 900\n2000 2000",
"output": "rated"
},
{
"input": "2\n50 10\n10 50",
"output": "rated"
},
{
"input": "2\n200 200\n100 100",
"output": "maybe"
},
{
"input": "3\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "3\n1000 1000\n300 300\n100 100",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n3 3\n4 4",
"output": "unrated"
},
{
"input": "2\n5 3\n6 3",
"output": "rated"
},
{
"input": "2\n1200 1100\n1200 1000",
"output": "rated"
},
{
"input": "2\n5 5\n4 4",
"output": "maybe"
},
{
"input": "2\n5 5\n3 3",
"output": "maybe"
},
{
"input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100",
"output": "unrated"
},
{
"input": "5\n10 10\n9 9\n8 8\n7 7\n6 6",
"output": "maybe"
},
{
"input": "3\n1000 1000\n300 300\n10 10",
"output": "maybe"
},
{
"input": "5\n6 6\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n3 3\n1 1",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n1000 1000\n700 700",
"output": "maybe"
},
{
"input": "2\n4 3\n5 3",
"output": "rated"
},
{
"input": "2\n1000 1000\n1100 1100",
"output": "unrated"
},
{
"input": "4\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "3\n1 1\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n1 2\n1 3",
"output": "rated"
},
{
"input": "2\n3 3\n1 2",
"output": "rated"
},
{
"input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "5\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "2\n10 10\n1 2",
"output": "rated"
},
{
"input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900",
"output": "unrated"
},
{
"input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699",
"output": "unrated"
},
{
"input": "2\n100 100\n110 110",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n3 3\n3 2\n4 4",
"output": "rated"
},
{
"input": "3\n5 2\n4 4\n3 3",
"output": "rated"
},
{
"input": "4\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n1 1\n3 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n3 4",
"output": "rated"
},
{
"input": "3\n1 2\n2 2\n3 3",
"output": "rated"
},
{
"input": "3\n1 2\n1 2\n1 2",
"output": "rated"
},
{
"input": "2\n2 1\n2 1",
"output": "rated"
},
{
"input": "2\n1 2\n3 4",
"output": "rated"
},
{
"input": "2\n3 2\n2 3",
"output": "rated"
},
{
"input": "3\n1500 1500\n1600 1600\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1 1\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n2 2",
"output": "unrated"
},
{
"input": "2\n10 12\n8 8",
"output": "rated"
},
{
"input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500",
"output": "unrated"
},
{
"input": "2\n1 2\n2 2",
"output": "rated"
},
{
"input": "3\n1500 1400\n1200 1200\n1100 1100",
"output": "rated"
},
{
"input": "2\n10 12\n10 10",
"output": "rated"
},
{
"input": "3\n1500 1500\n1400 1400\n1300 1300",
"output": "maybe"
},
{
"input": "3\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "3\n2 6\n3 5\n4 4",
"output": "rated"
},
{
"input": "2\n5 6\n4 6",
"output": "rated"
},
{
"input": "4\n10 10\n10 10\n7 7\n8 8",
"output": "unrated"
},
{
"input": "2\n4 4\n3 3",
"output": "maybe"
}
] | 46 | 0 | 3 | 1,495 |
|
382 | Number Busters | [
"binary search",
"math"
] | null | null | Arthur and Alexander are number busters. Today they've got a competition.
Arthur took a group of four integers *a*,<=*b*,<=*w*,<=*x* (0<=β€<=*b*<=<<=*w*,<=0<=<<=*x*<=<<=*w*) and Alexander took integer *Ρ*. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each second, he subtracts one from his number. In other words, he performs the assignment: *c*<==<=*c*<=-<=1. Arthur is a sophisticated guy. Each second Arthur performs a complex operation, described as follows: if *b*<=β₯<=*x*, perform the assignment *b*<==<=*b*<=-<=*x*, if *b*<=<<=*x*, then perform two consecutive assignments *a*<==<=*a*<=-<=1; *b*<==<=*w*<=-<=(*x*<=-<=*b*).
You've got numbers *a*,<=*b*,<=*w*,<=*x*,<=*c*. Determine when Alexander gets ahead of Arthur if both guys start performing the operations at the same time. Assume that Alexander got ahead of Arthur if *c*<=β€<=*a*. | The first line contains integers *a*,<=*b*,<=*w*,<=*x*,<=*c* (1<=β€<=*a*<=β€<=2Β·109,<=1<=β€<=*w*<=β€<=1000,<=0<=β€<=*b*<=<<=*w*,<=0<=<<=*x*<=<<=*w*,<=1<=β€<=*c*<=β€<=2Β·109). | Print a single integer β the minimum time in seconds Alexander needs to get ahead of Arthur. You can prove that the described situation always occurs within the problem's limits. | [
"4 2 3 1 6\n",
"4 2 3 1 7\n",
"1 2 3 2 6\n",
"1 1 2 1 1\n"
] | [
"2\n",
"4\n",
"13\n",
"0\n"
] | none | [
{
"input": "4 2 3 1 6",
"output": "2"
},
{
"input": "4 2 3 1 7",
"output": "4"
},
{
"input": "1 2 3 2 6",
"output": "13"
},
{
"input": "1 1 2 1 1",
"output": "0"
},
{
"input": "1 0 1000 999 2000000000",
"output": "1999999999000"
},
{
"input": "10 1 6 4 20",
"output": "30"
},
{
"input": "10 3 6 5 30",
"output": "117"
},
{
"input": "10 3 5 1 30",
"output": "25"
},
{
"input": "10 32 312 72 1000",
"output": "1287"
},
{
"input": "1 102 123 27 2321",
"output": "2972"
},
{
"input": "2000000000 159 1000 870 2000000000",
"output": "0"
},
{
"input": "200000000 794 1000 117 2000000000",
"output": "2038505096"
},
{
"input": "20000000 280 1000 25 2000000000",
"output": "2030769231"
},
{
"input": "1999999999 47 1000 527 2000000000",
"output": "3"
},
{
"input": "19999 346 1000 141 2000000000",
"output": "2328265426"
},
{
"input": "1 142 1000 673 2000000000",
"output": "6116207948"
},
{
"input": "1 851 999 721 2000000000",
"output": "7187050354"
},
{
"input": "1 504 998 900 2000000000",
"output": "20367346924"
},
{
"input": "1 250 997 55 2000000000",
"output": "2116772823"
},
{
"input": "1 2 3 2 2000000000",
"output": "5999999995"
},
{
"input": "1 0 2 1 1232132",
"output": "2464262"
},
{
"input": "1 999 1000 1 2000000000",
"output": "2002002001"
},
{
"input": "1 999 1000 2 2000000000",
"output": "2004008015"
}
] | 46 | 0 | 0 | 1,500 |
|
489 | Given Length and Sum of Digits... | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=β€<=*m*<=β€<=100,<=0<=β€<=*s*<=β€<=900) β the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1 900",
"output": "-1 -1"
},
{
"input": "1 9",
"output": "9 9"
},
{
"input": "1 0",
"output": "0 0"
},
{
"input": "1 1",
"output": "1 1"
},
{
"input": "1 2",
"output": "2 2"
},
{
"input": "1 8",
"output": "8 8"
},
{
"input": "1 10",
"output": "-1 -1"
},
{
"input": "1 11",
"output": "-1 -1"
},
{
"input": "2 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "2 2",
"output": "11 20"
},
{
"input": "2 8",
"output": "17 80"
},
{
"input": "2 10",
"output": "19 91"
},
{
"input": "2 11",
"output": "29 92"
},
{
"input": "2 16",
"output": "79 97"
},
{
"input": "2 17",
"output": "89 98"
},
{
"input": "2 18",
"output": "99 99"
},
{
"input": "2 19",
"output": "-1 -1"
},
{
"input": "2 20",
"output": "-1 -1"
},
{
"input": "2 900",
"output": "-1 -1"
},
{
"input": "3 1",
"output": "100 100"
},
{
"input": "3 2",
"output": "101 200"
},
{
"input": "3 3",
"output": "102 300"
},
{
"input": "3 9",
"output": "108 900"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "3 20",
"output": "299 992"
},
{
"input": "3 21",
"output": "399 993"
},
{
"input": "3 26",
"output": "899 998"
},
{
"input": "3 27",
"output": "999 999"
},
{
"input": "3 28",
"output": "-1 -1"
},
{
"input": "3 100",
"output": "-1 -1"
},
{
"input": "100 0",
"output": "-1 -1"
},
{
"input": "100 1",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 2",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 9",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 10",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 11",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 296",
"output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 297",
"output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 298",
"output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 299",
"output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 300",
"output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 301",
"output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 895",
"output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994"
},
{
"input": "100 896",
"output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995"
},
{
"input": "100 897",
"output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996"
},
{
"input": "100 898",
"output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997"
},
{
"input": "100 899",
"output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998"
},
{
"input": "100 900",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "99 900",
"output": "-1 -1"
},
{
"input": "99 891",
"output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "99 892",
"output": "-1 -1"
},
{
"input": "96 364",
"output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000"
},
{
"input": "97 206",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "98 250",
"output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "99 96",
"output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 215",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "5 18",
"output": "10089 99000"
},
{
"input": "2 19",
"output": "-1 -1"
},
{
"input": "3 3",
"output": "102 300"
}
] | 1,000 | 0 | 0 | 1,505 |
|
768 | Oath of the Night's Watch | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." β The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support? | First line consists of a single integer *n* (1<=β€<=*n*<=β€<=105) β the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1",
"output": "174"
},
{
"input": "4\n1000000000 99999999 1000000000 1000000000",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "6\n1 1 3 3 2 2",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "4\n1 1 2 5",
"output": "1"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n1 1 1 1 5",
"output": "0"
},
{
"input": "5\n1 1 2 3 3",
"output": "1"
},
{
"input": "3\n1 1 3",
"output": "0"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "5\n1 5 3 5 1",
"output": "1"
},
{
"input": "7\n1 2 2 2 2 2 3",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "9\n2 2 2 3 4 5 6 6 6",
"output": "3"
},
{
"input": "10\n1 1 1 2 3 3 3 3 3 3",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n0 0 1",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "0"
},
{
"input": "5\n2 2 2 2 2",
"output": "0"
},
{
"input": "5\n5 5 5 5 5",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "1"
},
{
"input": "5\n1 2 3 3 3",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "0"
},
{
"input": "6\n1 1 1 1 1 2",
"output": "0"
},
{
"input": "5\n1 1 2 4 4",
"output": "1"
},
{
"input": "3\n999999 5999999 9999999",
"output": "1"
},
{
"input": "4\n1 1 5 5",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 4 4 4",
"output": "3"
},
{
"input": "5\n1 3 4 5 1",
"output": "2"
},
{
"input": "5\n3 3 3 3 3",
"output": "0"
},
{
"input": "5\n1 1 2 2 2",
"output": "0"
},
{
"input": "5\n2 1 1 1 3",
"output": "1"
},
{
"input": "5\n0 0 0 1 2",
"output": "1"
},
{
"input": "4\n2 2 2 3",
"output": "0"
},
{
"input": "7\n1 1 1 1 5 5 5",
"output": "0"
},
{
"input": "5\n1 2 3 4 4",
"output": "2"
},
{
"input": "2\n5 4",
"output": "0"
},
{
"input": "4\n5 5 5 5",
"output": "0"
},
{
"input": "5\n1 1 1 5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "4\n1 2 2 2",
"output": "0"
},
{
"input": "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998",
"output": "3"
},
{
"input": "5\n1 1 3 4 4",
"output": "1"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "0"
},
{
"input": "9\n1 2 3 4 1 5 6 7 8",
"output": "6"
},
{
"input": "8\n5 4 4 6 6 4 4 3",
"output": "5"
},
{
"input": "8\n4 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "0"
},
{
"input": "6\n4 3 3 3 3 3",
"output": "0"
},
{
"input": "5\n4 3 3 3 3",
"output": "0"
}
] | 15 | 0 | 0 | 1,506 |
|
0 | none | [
"none"
] | null | null | Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is *T**i*, each pile will reduce its volume by *T**i*. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day *i* already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. | The first line contains a single integer *N* (1<=β€<=*N*<=β€<=105) β the number of days.
The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=β€<=*V**i*<=β€<=109), where *V**i* is the initial size of a snow pile made on the day *i*.
The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=β€<=*T**i*<=β€<=109), where *T**i* is the temperature on the day *i*. | Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*. | [
"3\n10 10 5\n5 7 2\n",
"5\n30 25 20 15 10\n9 10 12 4 13\n"
] | [
"5 12 4\n",
"9 20 35 11 25\n"
] | In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | [
{
"input": "3\n10 10 5\n5 7 2",
"output": "5 12 4"
},
{
"input": "5\n30 25 20 15 10\n9 10 12 4 13",
"output": "9 20 35 11 25"
},
{
"input": "4\n0 0 0 0\n1 2 3 4",
"output": "0 0 0 0"
},
{
"input": "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2",
"output": "10 0 9 27 27 30 28 17 12 4"
},
{
"input": "10\n20 35 4 0 6 29 4 9 17 10\n0 9 4 7 5 1 4 3 9 4",
"output": "0 18 12 14 10 3 12 9 26 12"
},
{
"input": "1\n4\n5",
"output": "4"
},
{
"input": "1\n5\n4",
"output": "4"
},
{
"input": "1\n5\n5",
"output": "5"
},
{
"input": "2\n9 3\n8 2",
"output": "8 3"
},
{
"input": "2\n9 3\n4 4",
"output": "4 7"
},
{
"input": "2\n9 3\n10 2",
"output": "9 2"
},
{
"input": "13\n1 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",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1"
}
] | 1,000 | 15,360,000 | 0 | 1,512 |
|
625 | Guest From the Past | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs *a* rubles, or in glass liter bottle, that costs *b* rubles. Also, you may return empty glass bottle and get *c* (*c*<=<<=*b*) rubles back, but you cannot return plastic bottles.
Kolya has *n* rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help. | First line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=1018) β the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=β€<=*a*<=β€<=1018, 1<=β€<=*c*<=<<=*b*<=β€<=1018) β the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively. | Print the only integer β maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir. | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"output": "5"
},
{
"input": "9\n2\n4\n1",
"output": "4"
},
{
"input": "9\n2\n2\n1",
"output": "8"
},
{
"input": "9\n10\n10\n1",
"output": "0"
},
{
"input": "10\n2\n2\n1",
"output": "9"
},
{
"input": "1000000000000000000\n2\n10\n9",
"output": "999999999999999995"
},
{
"input": "501000000000000000\n300000000000000000\n301000000000000000\n100000000000000000",
"output": "2"
},
{
"input": "10\n1\n9\n8",
"output": "10"
},
{
"input": "10\n8\n8\n7",
"output": "3"
},
{
"input": "10\n5\n5\n1",
"output": "2"
},
{
"input": "29\n3\n3\n1",
"output": "14"
},
{
"input": "45\n9\n9\n8",
"output": "37"
},
{
"input": "45\n9\n9\n1",
"output": "5"
},
{
"input": "100\n10\n10\n9",
"output": "91"
},
{
"input": "179\n10\n9\n1",
"output": "22"
},
{
"input": "179\n2\n2\n1",
"output": "178"
},
{
"input": "179\n179\n179\n1",
"output": "1"
},
{
"input": "179\n59\n59\n58",
"output": "121"
},
{
"input": "500\n250\n250\n1",
"output": "2"
},
{
"input": "500\n1\n250\n1",
"output": "500"
},
{
"input": "501\n500\n500\n499",
"output": "2"
},
{
"input": "501\n450\n52\n1",
"output": "9"
},
{
"input": "501\n300\n301\n100",
"output": "2"
},
{
"input": "500\n179\n10\n1",
"output": "55"
},
{
"input": "1000\n500\n10\n9",
"output": "991"
},
{
"input": "1000\n2\n10\n9",
"output": "995"
},
{
"input": "1001\n1000\n1000\n999",
"output": "2"
},
{
"input": "10000\n10000\n10000\n1",
"output": "1"
},
{
"input": "10000\n10\n5000\n4999",
"output": "5500"
},
{
"input": "1000000000\n999999998\n999999999\n999999998",
"output": "3"
},
{
"input": "1000000000\n50\n50\n49",
"output": "999999951"
},
{
"input": "1000000000\n500\n5000\n4999",
"output": "999995010"
},
{
"input": "1000000000\n51\n100\n98",
"output": "499999952"
},
{
"input": "1000000000\n100\n51\n50",
"output": "999999950"
},
{
"input": "1000000000\n2\n5\n4",
"output": "999999998"
},
{
"input": "1000000000000000000\n999999998000000000\n999999999000000000\n999999998000000000",
"output": "3"
},
{
"input": "1000000000\n2\n2\n1",
"output": "999999999"
},
{
"input": "999999999\n2\n999999998\n1",
"output": "499999999"
},
{
"input": "999999999999999999\n2\n2\n1",
"output": "999999999999999998"
},
{
"input": "999999999999999999\n10\n10\n9",
"output": "999999999999999990"
},
{
"input": "999999999999999999\n999999999999999998\n999999999999999998\n999999999999999997",
"output": "2"
},
{
"input": "999999999999999999\n501\n501\n1",
"output": "1999999999999999"
},
{
"input": "999999999999999999\n2\n50000000000000000\n49999999999999999",
"output": "974999999999999999"
},
{
"input": "999999999999999999\n180\n180\n1",
"output": "5586592178770949"
},
{
"input": "1000000000000000000\n42\n41\n1",
"output": "24999999999999999"
},
{
"input": "1000000000000000000\n41\n40\n1",
"output": "25641025641025641"
},
{
"input": "100000000000000000\n79\n100\n25",
"output": "1333333333333333"
},
{
"input": "1\n100\n5\n4",
"output": "0"
},
{
"input": "1000000000000000000\n1000000000000000000\n10000000\n9999999",
"output": "999999999990000001"
},
{
"input": "999999999999999999\n999999999000000000\n900000000000000000\n899999999999999999",
"output": "100000000000000000"
},
{
"input": "13\n10\n15\n11",
"output": "1"
},
{
"input": "1\n1000\n5\n4",
"output": "0"
},
{
"input": "10\n100\n10\n1",
"output": "1"
},
{
"input": "3\n2\n100000\n99999",
"output": "1"
},
{
"input": "4\n2\n4\n2",
"output": "2"
},
{
"input": "5\n3\n6\n4",
"output": "1"
},
{
"input": "1\n7\n65\n49",
"output": "0"
},
{
"input": "10\n20\n100\n99",
"output": "0"
},
{
"input": "10000000000\n10000000000\n9000000000\n8999999999",
"output": "1000000001"
},
{
"input": "90\n30\n101\n100",
"output": "3"
},
{
"input": "999999999999999\n5\n500000000000000\n499999999999999",
"output": "599999999999999"
},
{
"input": "1000000000000000000\n1000000000000000000\n1000000000\n999999999",
"output": "999999999000000001"
},
{
"input": "1\n1000000000000000000\n1000000000\n999999999",
"output": "0"
},
{
"input": "100000000000000000\n100000000000000000\n1000000000\n999999999",
"output": "99999999000000001"
},
{
"input": "100000000000000009\n100\n1000000000000000\n999999999999999",
"output": "99010000000000009"
},
{
"input": "10\n20\n10\n9",
"output": "1"
},
{
"input": "10\n4\n14\n13",
"output": "2"
},
{
"input": "11\n3\n9\n7",
"output": "4"
},
{
"input": "1000000000\n5\n7\n4",
"output": "333333332"
},
{
"input": "12155\n1943\n28717\n24074",
"output": "6"
},
{
"input": "1000000000000000000\n10\n20\n5",
"output": "100000000000000000"
},
{
"input": "98\n33\n440\n314",
"output": "2"
},
{
"input": "1070252292\n57449678\n237309920\n221182550",
"output": "56"
},
{
"input": "100\n3\n102\n101",
"output": "33"
},
{
"input": "100000000000000000\n100000000000000001\n1000000000000000\n999999999999999",
"output": "99000000000000001"
},
{
"input": "66249876257975628\n302307316\n406102416\n182373516",
"output": "296116756"
},
{
"input": "10\n5\n10\n1",
"output": "2"
},
{
"input": "1000000000000000000\n10\n1000000000\n999999998",
"output": "499999999600000000"
}
] | 62 | 0 | 0 | 1,513 |
|
199 | Hexadecimal's theorem | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. | The input contains of a single integer *n* (0<=β€<=*n*<=<<=109) β the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "3",
"output": "1 1 1"
},
{
"input": "5",
"output": "1 1 3"
},
{
"input": "8",
"output": "1 2 5"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "21",
"output": "3 5 13"
},
{
"input": "34",
"output": "5 8 21"
},
{
"input": "55",
"output": "8 13 34"
},
{
"input": "89",
"output": "13 21 55"
},
{
"input": "144",
"output": "21 34 89"
},
{
"input": "233",
"output": "34 55 144"
},
{
"input": "377",
"output": "55 89 233"
},
{
"input": "610",
"output": "89 144 377"
},
{
"input": "987",
"output": "144 233 610"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "2584",
"output": "377 610 1597"
},
{
"input": "4181",
"output": "610 987 2584"
},
{
"input": "6765",
"output": "987 1597 4181"
},
{
"input": "10946",
"output": "1597 2584 6765"
},
{
"input": "17711",
"output": "2584 4181 10946"
},
{
"input": "28657",
"output": "4181 6765 17711"
},
{
"input": "46368",
"output": "6765 10946 28657"
},
{
"input": "75025",
"output": "10946 17711 46368"
},
{
"input": "121393",
"output": "17711 28657 75025"
},
{
"input": "196418",
"output": "28657 46368 121393"
},
{
"input": "317811",
"output": "46368 75025 196418"
},
{
"input": "514229",
"output": "75025 121393 317811"
},
{
"input": "832040",
"output": "121393 196418 514229"
},
{
"input": "1346269",
"output": "196418 317811 832040"
},
{
"input": "2178309",
"output": "317811 514229 1346269"
},
{
"input": "3524578",
"output": "514229 832040 2178309"
},
{
"input": "5702887",
"output": "832040 1346269 3524578"
},
{
"input": "9227465",
"output": "1346269 2178309 5702887"
},
{
"input": "14930352",
"output": "2178309 3524578 9227465"
},
{
"input": "24157817",
"output": "3524578 5702887 14930352"
},
{
"input": "39088169",
"output": "5702887 9227465 24157817"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "165580141",
"output": "24157817 39088169 102334155"
},
{
"input": "267914296",
"output": "39088169 63245986 165580141"
},
{
"input": "433494437",
"output": "63245986 102334155 267914296"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
}
] | 92 | 0 | 3 | 1,517 |
|
570 | Replacement | [
"constructive algorithms",
"data structures",
"implementation"
] | null | null | Daniel has a string *s*, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string *s*, of all occurrences of the substring let's choose the first one, and replace this substring with string ".". In other words, during the replacement operation, the first two consecutive periods are replaced by one. If string *s* contains no two consecutive periods, then nothing happens.
Let's define *f*(*s*) as the minimum number of operations of replacement to perform, so that the string does not have any two consecutive periods left.
You need to process *m* queries, the *i*-th results in that the character at position *x**i* (1<=β€<=*x**i*<=β€<=*n*) of string *s* is assigned value *c**i*. After each operation you have to calculate and output the value of *f*(*s*).
Help Daniel to process all queries. | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=300<=000) the length of the string and the number of queries.
The second line contains string *s*, consisting of *n* lowercase English letters and period signs.
The following *m* lines contain the descriptions of queries. The *i*-th line contains integer *x**i* and *c**i* (1<=β€<=*x**i*<=β€<=*n*, *c**i* β a lowercas English letter or a period sign), describing the query of assigning symbol *c**i* to position *x**i*. | Print *m* numbers, one per line, the *i*-th of these numbers must be equal to the value of *f*(*s*) after performing the *i*-th assignment. | [
"10 3\n.b..bz....\n1 h\n3 c\n9 f\n",
"4 4\n.cc.\n2 .\n3 .\n2 a\n1 a\n"
] | [
"4\n3\n1\n",
"1\n3\n1\n1\n"
] | Note to the first sample test (replaced periods are enclosed in square brackets).
The original string is ".b..bz....".
- after the first query *f*(hb..bz....) = 4 ("hb[..]bz...." βββ "hb.bz[..].." βββ "hb.bz[..]." βββ "hb.bz[..]" βββ "hb.bz.")- after the second query *f*(hbΡ.bz....) = 3 ("hbΡ.bz[..].." βββ "hbΡ.bz[..]." βββ "hbΡ.bz[..]" βββ "hbΡ.bz.")- after the third query *f*(hbΡ.bz..f.) = 1 ("hbΡ.bz[..]f." βββ "hbΡ.bz.f.")
Note to the second sample test.
The original string is ".cc.".
- after the first query: *f*(..c.) = 1 ("[..]c." βββ ".c.")- after the second query: *f*(....) = 3 ("[..].." βββ "[..]." βββ "[..]" βββ ".")- after the third query: *f*(.a..) = 1 (".a[..]" βββ ".a.")- after the fourth query: *f*(aa..) = 1 ("aa[..]" βββ "aa.") | [
{
"input": "10 3\n.b..bz....\n1 h\n3 c\n9 f",
"output": "4\n3\n1"
},
{
"input": "4 4\n.cc.\n2 .\n3 .\n2 a\n1 a",
"output": "1\n3\n1\n1"
},
{
"input": "3 3\n...\n1 .\n2 a\n3 b",
"output": "2\n0\n0"
},
{
"input": "5 1\n.....\n5 z",
"output": "3"
},
{
"input": "1 5\n.\n1 .\n1 w\n1 w\n1 .\n1 .",
"output": "0\n0\n0\n0\n0"
},
{
"input": "2 7\nab\n1 w\n2 w\n1 c\n2 .\n2 .\n1 .\n2 b",
"output": "0\n0\n0\n0\n0\n1\n0"
}
] | 2,000 | 54,681,600 | 0 | 1,518 |
|
862 | Mahmoud and Ehab and the bipartiteness | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.
Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?
A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | The first line of input contains an integer *n* β the number of nodes in the tree (1<=β€<=*n*<=β€<=105).
The next *n*<=-<=1 lines contain integers *u* and *v* (1<=β€<=*u*,<=*v*<=β€<=*n*, *u*<=β <=*v*) β the description of the edges of the tree.
It's guaranteed that the given graph is a tree. | Output one integer β the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | [
"3\n1 2\n1 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n"
] | [
"0\n",
"2\n"
] | Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory))
Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph)
In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2,β3), but adding this edge will make the graph non-bipartite so the answer is 0.
In the second test case Mahmoud and Ehab can add edges (1,β4) and (2,β5). | [
{
"input": "3\n1 2\n1 3",
"output": "0"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6",
"output": "16"
},
{
"input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4",
"output": "16"
},
{
"input": "10\n2 6\n3 7\n8 4\n4 10\n6 9\n9 7\n3 10\n1 2\n5 8",
"output": "16"
},
{
"input": "10\n6 9\n9 7\n9 4\n10 9\n9 1\n9 8\n9 2\n9 5\n3 9",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
}
] | 61 | 6,963,200 | 0 | 1,519 |
|
99 | Help Chef Gerasim | [
"implementation",
"sortings"
] | B. Help Chef Gerasim | 0 | 256 | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.
To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice. | The first line contains integer *n* β the number of cups on the royal table (1<=β€<=*n*<=β€<=1000). Next *n* lines contain volumes of juice in each cup β non-negative integers, not exceeding 104. | If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), *b* represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes). | [
"5\n270\n250\n250\n230\n250\n",
"5\n250\n250\n250\n250\n250\n",
"5\n270\n250\n249\n230\n250\n"
] | [
"20 ml. from cup #4 to cup #1.\n",
"Exemplary pages.\n",
"Unrecoverable configuration.\n"
] | none | [
{
"input": "5\n270\n250\n250\n230\n250",
"output": "20 ml. from cup #4 to cup #1."
},
{
"input": "5\n250\n250\n250\n250\n250",
"output": "Exemplary pages."
},
{
"input": "5\n270\n250\n249\n230\n250",
"output": "Unrecoverable configuration."
},
{
"input": "4\n200\n190\n210\n200",
"output": "10 ml. from cup #2 to cup #3."
},
{
"input": "4\n1\n2\n3\n4",
"output": "Unrecoverable configuration."
},
{
"input": "1\n0",
"output": "Exemplary pages."
},
{
"input": "2\n0\n0",
"output": "Exemplary pages."
},
{
"input": "2\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "2\n0\n2",
"output": "1 ml. from cup #1 to cup #2."
},
{
"input": "2\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "2\n1\n1",
"output": "Exemplary pages."
},
{
"input": "2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "2\n2\n0",
"output": "1 ml. from cup #2 to cup #1."
},
{
"input": "2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "2\n2\n2",
"output": "Exemplary pages."
},
{
"input": "3\n0\n0\n0",
"output": "Exemplary pages."
},
{
"input": "3\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n1\n2",
"output": "1 ml. from cup #1 to cup #3."
},
{
"input": "3\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n2\n1",
"output": "1 ml. from cup #1 to cup #2."
},
{
"input": "3\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n0\n2",
"output": "1 ml. from cup #2 to cup #3."
},
{
"input": "3\n1\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n1\n1",
"output": "Exemplary pages."
},
{
"input": "3\n1\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n2\n0",
"output": "1 ml. from cup #3 to cup #2."
},
{
"input": "3\n1\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n0\n1",
"output": "1 ml. from cup #2 to cup #1."
},
{
"input": "3\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n1\n0",
"output": "1 ml. from cup #3 to cup #1."
},
{
"input": "3\n2\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n2\n2",
"output": "Exemplary pages."
},
{
"input": "4\n0\n0\n0\n0",
"output": "Exemplary pages."
},
{
"input": "4\n0\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n1\n2",
"output": "1 ml. from cup #1 to cup #4."
},
{
"input": "4\n0\n1\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n2\n1",
"output": "1 ml. from cup #1 to cup #3."
},
{
"input": "4\n0\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n1\n1",
"output": "1 ml. from cup #1 to cup #2."
},
{
"input": "4\n0\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n1\n2",
"output": "1 ml. from cup #2 to cup #4."
},
{
"input": "4\n1\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n2\n1",
"output": "1 ml. from cup #2 to cup #3."
},
{
"input": "4\n1\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n0\n2",
"output": "1 ml. from cup #3 to cup #4."
},
{
"input": "4\n1\n1\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n1\n1",
"output": "Exemplary pages."
},
{
"input": "4\n1\n1\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n2\n0",
"output": "1 ml. from cup #4 to cup #3."
},
{
"input": "4\n1\n1\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n0\n1",
"output": "1 ml. from cup #3 to cup #2."
},
{
"input": "4\n1\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n1\n0",
"output": "1 ml. from cup #4 to cup #2."
},
{
"input": "4\n1\n2\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n1\n1",
"output": "1 ml. from cup #2 to cup #1."
},
{
"input": "4\n2\n0\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n0\n1",
"output": "1 ml. from cup #3 to cup #1."
},
{
"input": "4\n2\n1\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n1\n0",
"output": "1 ml. from cup #4 to cup #1."
},
{
"input": "4\n2\n1\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n2\n2",
"output": "Exemplary pages."
},
{
"input": "27\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n2626\n5599\n5599\n5599\n5599\n5599\n8572\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599",
"output": "2973 ml. from cup #11 to cup #17."
},
{
"input": "98\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n1204\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n197\n702\n702\n702\n702\n702\n702\n702\n702\n702",
"output": "Unrecoverable configuration."
},
{
"input": "54\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6859\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n5389\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124",
"output": "735 ml. from cup #37 to cup #29."
},
{
"input": "50\n9636\n9678\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9596\n9636\n9636\n9636\n9636\n9636\n9636",
"output": "Unrecoverable configuration."
},
{
"input": "19\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n82\n5001\n9919\n5001\n5001",
"output": "Unrecoverable configuration."
},
{
"input": "74\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n3918\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n6742\n5330\n5330",
"output": "1412 ml. from cup #36 to cup #72."
}
] | 31 | 0 | 0 | 1,521 |
18 | Stripe | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem? | The first input line contains integer *n* (1<=β€<=*n*<=β€<=105) β amount of squares in the stripe. The second line contains *n* space-separated numbers β they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "10\n0 -1 2 2 -1 1 0 0 0 2",
"output": "0"
},
{
"input": "10\n-1 -1 1 -1 0 1 0 1 1 1",
"output": "1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "9"
},
{
"input": "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -4 3",
"output": "3"
},
{
"input": "15\n0 4 0 3 -1 4 -2 -2 -4 -4 3 2 4 -1 -3",
"output": "0"
},
{
"input": "10\n3 -1 -3 -1 3 -2 0 3 1 -2",
"output": "0"
},
{
"input": "100\n-4 2 4 4 1 3 -3 -3 2 1 -4 0 0 2 3 -1 -4 -3 4 -2 -3 -3 -3 -1 -2 -3 -1 -4 0 4 0 -1 4 0 -4 -4 4 -4 -2 1 -4 1 -3 -2 3 -4 4 0 -1 3 -1 4 -1 4 -1 3 -3 -3 -2 -2 4 -3 -3 4 -3 -2 -1 0 -2 4 0 -3 -1 -2 -3 1 -4 1 -3 -3 -3 -2 -3 0 1 -2 -2 -4 -3 -1 2 3 -1 1 1 0 3 -3 -1 -2",
"output": "1"
},
{
"input": "100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -1 -2 2 -2 2 -2 -2 2 1 1 1 -2 2 0 0 2 -1 2 2 2 0 -1 -1 -1 1 -2 2 2 2 -2 0 0 -2 0 -2 -2 0 -1 -1 -2 -1 1 2 -2 -1 1 -2 -1 0 -2 2 2 -1 -2 2 0 0 0 1 0 1 2 1 -2 -2 -1 -1 -2 -2 -2 -1 2 2 2 -2",
"output": "6"
},
{
"input": "100\n2 7 6 0 8 -2 0 1 8 -1 7 -4 -1 1 0 3 4 -4 3 7 8 -4 -6 6 4 -2 -5 7 4 6 1 6 3 8 -2 6 -6 -3 0 -1 -7 -8 -2 5 8 6 -2 -2 -5 -4 -7 -3 -5 -3 -3 -1 5 8 4 0 -7 -6 8 -4 -1 7 2 6 6 4 -5 -4 -5 -2 2 -2 -7 -1 5 -8 -6 -2 -5 4 2 8 -6 7 -8 -1 -5 8 6 -3 -1 7 -1 2 -8 -8",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n10000",
"output": "0"
},
{
"input": "1\n-10000",
"output": "0"
}
] | 466 | 8,499,200 | 3.820176 | 1,523 |
38 | The Great Marathon | [
"dp"
] | H. The Great Marathon | 4 | 256 | On the Berland Dependence Day it was decided to organize a great marathon. Berland consists of *n* cities, some of which are linked by two-way roads. Each road has a certain length. The cities are numbered from 1 to *n*. It is known that one can get from any city to any other one by the roads.
*n* runners take part in the competition, one from each city. But Berland runners are talkative by nature and that's why the juries took measures to avoid large crowds of marathon participants. The jury decided that every runner should start the marathon from their hometown. Before the start every sportsman will get a piece of paper containing the name of the city where the sportsman's finishing line is. The finish is chosen randomly for every sportsman but it can't coincide with the sportsman's starting point. Several sportsmen are allowed to finish in one and the same city. All the sportsmen start simultaneously and everyone runs the shortest route from the starting point to the finishing one. All the sportsmen run at one speed which equals to 1.
After the competition a follow-up table of the results will be composed where the sportsmen will be sorted according to the nondecrease of time they spent to cover the distance. The first *g* sportsmen in the table will get golden medals, the next *s* sportsmen will get silver medals and the rest will get bronze medals. Besides, if two or more sportsmen spend the same amount of time to cover the distance, they are sorted according to the number of the city where a sportsman started to run in the ascending order. That means no two sportsmen share one and the same place.
According to the rules of the competition the number of gold medals *g* must satisfy the inequation *g*1<=β€<=*g*<=β€<=*g*2, where *g*1 and *g*2 are values formed historically. In a similar way, the number of silver medals *s* must satisfy the inequation *s*1<=β€<=*s*<=β€<=*s*2, where *s*1 and *s*2 are also values formed historically.
At present, before the start of the competition, the destination points of every sportsman are unknown. However, the press demands details and that's why you are given the task of counting the number of the ways to distribute the medals. Two ways to distribute the medals are considered different if at least one sportsman could have received during those distributions different kinds of medals. | The first input line contains given integers *n* and *m* (3<=β€<=*n*<=β€<=50, *n*<=-<=1<=β€<=*m*<=β€<=1000), where *n* is the number of Berland towns and *m* is the number of roads.
Next in *m* lines road descriptions are given as groups of three integers *v*, *u*, *c*, which are the numbers of linked towns and its length (1<=β€<=*v*,<=*u*<=β€<=*n*, *v*<=β <=*u*, 1<=β€<=*c*<=β€<=1000). Every pair of cities have no more than one road between them.
The last line contains integers *g*1, *g*2, *s*1, *s*2 (1<=β€<=*g*1<=β€<=*g*2, 1<=β€<=*s*1<=β€<=*s*2, *g*2<=+<=*s*2<=<<=*n*). The input data numbers, located on one line, are space-separated. | Print the single number β the number of ways to distribute the medals. It is guaranteed that the number fits in the standard 64-bit signed data type. | [
"3 2\n1 2 1\n2 3 1\n1 1 1 1\n",
"4 5\n1 2 2\n2 3 1\n3 4 2\n4 1 2\n1 3 3\n1 2 1 1\n",
"3 3\n1 2 2\n2 3 1\n3 1 2\n1 1 1 1\n"
] | [
"3\n",
"19\n",
"4\n"
] | none | [] | 62 | 0 | 0 | 1,530 |
784 | Numbers Joke | [
"*special"
] | null | null | The input contains a single integer *a* (1<=β€<=*a*<=β€<=30).
Output a single integer. | The input contains a single integer *a* (1<=β€<=*a*<=β€<=30). | Output a single integer. | [
"3\n"
] | [
"27\n"
] | none | [
{
"input": "3",
"output": "27"
},
{
"input": "1",
"output": "4"
},
{
"input": "2",
"output": "22"
},
{
"input": "4",
"output": "58"
},
{
"input": "5",
"output": "85"
},
{
"input": "6",
"output": "94"
},
{
"input": "7",
"output": "121"
},
{
"input": "8",
"output": "166"
},
{
"input": "9",
"output": "202"
},
{
"input": "10",
"output": "265"
},
{
"input": "11",
"output": "274"
},
{
"input": "12",
"output": "319"
},
{
"input": "13",
"output": "346"
},
{
"input": "14",
"output": "355"
},
{
"input": "15",
"output": "378"
},
{
"input": "16",
"output": "382"
},
{
"input": "17",
"output": "391"
},
{
"input": "18",
"output": "438"
},
{
"input": "19",
"output": "454"
},
{
"input": "20",
"output": "483"
},
{
"input": "21",
"output": "517"
},
{
"input": "22",
"output": "526"
},
{
"input": "23",
"output": "535"
},
{
"input": "24",
"output": "562"
},
{
"input": "25",
"output": "576"
},
{
"input": "26",
"output": "588"
},
{
"input": "27",
"output": "627"
},
{
"input": "28",
"output": "634"
},
{
"input": "29",
"output": "636"
},
{
"input": "30",
"output": "645"
}
] | 109 | 0 | 0 | 1,531 |
|
223 | Partial Sums | [
"combinatorics",
"math",
"number theory"
] | null | null | You've got an array *a*, consisting of *n* integers. The array elements are indexed from 1 to *n*. Let's determine a two step operation like that:
1. First we build by the array *a* an array *s* of partial sums, consisting of *n* elements. Element number *i* (1<=β€<=*i*<=β€<=*n*) of array *s* equals . The operation *x* *mod* *y* means that we take the remainder of the division of number *x* by number *y*. 1. Then we write the contents of the array *s* to the array *a*. Element number *i* (1<=β€<=*i*<=β€<=*n*) of the array *s* becomes the *i*-th element of the array *a* (*a**i*<==<=*s**i*).
You task is to find array *a* after exactly *k* described operations are applied. | The first line contains two space-separated integers *n* and *k* (1<=β€<=*n*<=β€<=2000, 0<=β€<=*k*<=β€<=109). The next line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* β elements of the array *a* (0<=β€<=*a**i*<=β€<=109). | Print *n* integers β elements of the array *a* after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array *a*. Separate the printed numbers by spaces. | [
"3 1\n1 2 3\n",
"5 0\n3 14 15 92 6\n"
] | [
"1 3 6\n",
"3 14 15 92 6\n"
] | none | [
{
"input": "3 1\n1 2 3",
"output": "1 3 6"
},
{
"input": "5 0\n3 14 15 92 6",
"output": "3 14 15 92 6"
},
{
"input": "1 1\n3",
"output": "3"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n123",
"output": "123"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "4 1\n3 20 3 4",
"output": "3 23 26 30"
},
{
"input": "5 20\n11 5 6 8 11",
"output": "11 225 2416 18118 106536"
},
{
"input": "17 239\n663 360 509 307 311 501 523 370 302 601 541 42 328 200 196 110 573",
"output": "663 158817 19101389 537972231 259388293 744981080 6646898 234671418 400532510 776716020 52125061 263719534 192023697 446278138 592149678 33061993 189288187"
},
{
"input": "13 666\n84 89 29 103 128 233 190 122 117 208 119 97 200",
"output": "84 56033 18716627 174151412 225555860 164145872 451267967 434721493 224270207 253181081 361500071 991507723 152400567"
},
{
"input": "42 42\n42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42",
"output": "42 1806 39732 595980 6853770 64425438 515403504 607824507 548903146 777117811 441012592 397606113 289227498 685193257 740773014 214937435 654148201 446749626 489165413 202057369 926377846 779133524 993842970 721730118 484757814 939150939 225471671 20649822 51624555 850529088 441269800 845570818 580382507 773596603 435098280 957216216 73968454 779554271 588535300 530034849 736571438 149644609"
},
{
"input": "10 1000000\n1 2 3 4 84 5 6 7 8 9",
"output": "1 1000002 2496503 504322849 591771075 387496712 683276420 249833545 23968189 474356595"
}
] | 92 | 0 | 0 | 1,532 |
|
922 | Cloning Toys | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. | The only line contains two integers *x* and *y* (0<=β€<=*x*,<=*y*<=β€<=109) β the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",
"output": "Yes"
},
{
"input": "365289629 223844571",
"output": "No"
},
{
"input": "247579518 361164458",
"output": "No"
},
{
"input": "424836699 793451637",
"output": "No"
},
{
"input": "602093880 930771525",
"output": "No"
},
{
"input": "779351061 773124120",
"output": "Yes"
},
{
"input": "661640950 836815080",
"output": "No"
},
{
"input": "543930839 974134967",
"output": "No"
},
{
"input": "16155311 406422145",
"output": "No"
},
{
"input": "81601559 445618240",
"output": "No"
},
{
"input": "963891449 582938127",
"output": "No"
},
{
"input": "141148629 351661795",
"output": "No"
},
{
"input": "318405810 783948974",
"output": "No"
},
{
"input": "495662991 921268861",
"output": "No"
},
{
"input": "1 0",
"output": "No"
},
{
"input": "0 1",
"output": "Yes"
},
{
"input": "0 0",
"output": "No"
},
{
"input": "453462237 167520068",
"output": "Yes"
},
{
"input": "630719418 9872663",
"output": "Yes"
},
{
"input": "807976599 442159843",
"output": "No"
},
{
"input": "690266488 579479730",
"output": "No"
},
{
"input": "771581370 589752968",
"output": "No"
},
{
"input": "948838551 727072855",
"output": "No"
},
{
"input": "831128440 790763814",
"output": "No"
},
{
"input": "303352912 928083702",
"output": "No"
},
{
"input": "185642801 65403588",
"output": "Yes"
},
{
"input": "67932690 202723476",
"output": "No"
},
{
"input": "540157163 340043363",
"output": "No"
},
{
"input": "422447052 772330542",
"output": "No"
},
{
"input": "599704233 541054210",
"output": "Yes"
},
{
"input": "481994122 678374097",
"output": "No"
},
{
"input": "48564714 743566477",
"output": "No"
},
{
"input": "225821895 880886365",
"output": "No"
},
{
"input": "403079076 313173543",
"output": "Yes"
},
{
"input": "1000000000 1000000000",
"output": "No"
},
{
"input": "1 1",
"output": "No"
},
{
"input": "1 2",
"output": "Yes"
},
{
"input": "2 1",
"output": "No"
},
{
"input": "2 2",
"output": "No"
},
{
"input": "2 0",
"output": "No"
},
{
"input": "0 2",
"output": "No"
},
{
"input": "1000000000 1",
"output": "No"
},
{
"input": "777777 0",
"output": "No"
},
{
"input": "10 1",
"output": "No"
},
{
"input": "7 0",
"output": "No"
},
{
"input": "3 0",
"output": "No"
},
{
"input": "3 2",
"output": "Yes"
}
] | 30 | 0 | 0 | 1,538 |
|
366 | Dima and Guards | [
"implementation"
] | null | null | Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly *n* rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that! | The first line of the input contains integer *n* (1<=β€<=*n*<=β€<=105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=β€<=*a*,<=*b*,<=*c*,<=*d*<=β€<=105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly. | In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them. | [
"10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n",
"10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n",
"5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n"
] | [
"1 5 5\n",
"3 4 6\n",
"-1\n"
] | Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard. | [
{
"input": "10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9",
"output": "1 5 5"
},
{
"input": "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8",
"output": "3 4 6"
},
{
"input": "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3",
"output": "-1"
},
{
"input": "100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000",
"output": "-1"
},
{
"input": "5\n3 2 3 3\n3 2 3 3\n4 4 4 4\n4 4 1 1",
"output": "1 2 3"
},
{
"input": "100\n1 1 2 2\n100 100 2 2\n99 99 2 2\n2 2 99 99",
"output": "1 1 99"
},
{
"input": "1000\n500 500 550 550\n450 450 500 500\n999 1 1 999\n1 999 1 999",
"output": "3 1 999"
},
{
"input": "50\n30 30 30 30\n20 20 40 40\n10 10 50 50\n1 1 50 55",
"output": "-1"
},
{
"input": "10000\n1000 7000 8000 6000\n8000 8000 6000 6000\n5000 6000 6000 6000\n10000 10000 2 3",
"output": "1 1000 9000"
},
{
"input": "40000\n25000 25000 30000 30000\n1 1 1 1\n30000 20000 30000 30000\n40000 40000 40000 50000",
"output": "2 1 39999"
},
{
"input": "4\n2 1 4 4\n4 4 1 1\n3 1 2 2\n4 4 4 4",
"output": "3 1 3"
},
{
"input": "50\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5",
"output": "1 5 45"
},
{
"input": "10\n7 2 3 20\n20 20 20 20\n20 20 20 20\n7 2 3 20",
"output": "1 2 8"
},
{
"input": "10\n8 2 7 8\n20 20 20 20\n20 20 20 20\n8 2 7 8",
"output": "1 2 8"
},
{
"input": "100000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000",
"output": "1 50000 50000"
},
{
"input": "100000\n25000 75000 80000 80000\n99999 99999 2 2\n99999 2 99999 99999\n2 99999 99999 99999",
"output": "-1"
},
{
"input": "1231\n123 132 85 78\n123 5743 139 27\n4598 347 12438 12\n34589 2349 123 123",
"output": "2 123 1108"
},
{
"input": "6\n2 6 2 9\n4 8 5 1\n5 6 4 3\n1 2 5 1",
"output": "4 1 5"
},
{
"input": "8\n5 5 3 3\n1 1 8 8\n2 8 8 7\n10 7 2 2",
"output": "1 5 3"
},
{
"input": "100000\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001",
"output": "1 25000 75000"
},
{
"input": "100000\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001",
"output": "1 25000 75000"
},
{
"input": "5\n3 7 6 2\n100 100 100 100\n100 100 100 100\n100 100 100 100",
"output": "1 3 2"
},
{
"input": "10\n1 100 100 1\n1 100 100 1\n1 100 100 1\n1 100 100 1",
"output": "1 1 9"
},
{
"input": "10\n7 5 5 7\n10 10 10 10\n10 10 10 10\n10 10 10 10",
"output": "1 5 5"
},
{
"input": "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n1 1 1 1",
"output": "4 1 9"
},
{
"input": "10\n8 6 5 3\n8 6 5 3\n8 6 5 3\n8 6 5 3",
"output": "1 6 4"
},
{
"input": "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n9 4 9 6",
"output": "4 4 6"
},
{
"input": "10\n6 6 4 4\n6 6 4 4\n6 6 4 4\n6 6 4 4",
"output": "1 6 4"
},
{
"input": "100000\n99000 100000 999 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000",
"output": "1 99000 1000"
}
] | 124 | 307,200 | 3 | 1,544 |
|
877 | Alex and broken contest | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive. | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
},
{
"input": "Danil_and_part_time_job",
"output": "YES"
},
{
"input": "Ann_and_books",
"output": "YES"
},
{
"input": "Olya",
"output": "YES"
},
{
"input": "Nikita",
"output": "YES"
},
{
"input": "Slava",
"output": "YES"
},
{
"input": "Vanya",
"output": "NO"
},
{
"input": "I_dont_know_what_to_write_here",
"output": "NO"
},
{
"input": "danil_and_work",
"output": "NO"
},
{
"input": "Ann",
"output": "YES"
},
{
"input": "Batman_Nananananananan_Batman",
"output": "NO"
},
{
"input": "Olya_Nikita_Ann_Slava_Danil",
"output": "NO"
},
{
"input": "its_me_Mario",
"output": "NO"
},
{
"input": "A",
"output": "NO"
},
{
"input": "Wake_up_Neo",
"output": "NO"
},
{
"input": "Hardest_problem_ever",
"output": "NO"
},
{
"input": "Nikita_Nikita",
"output": "NO"
},
{
"input": "____________________________________________________________________________________________________",
"output": "NO"
},
{
"input": "Nikitb",
"output": "NO"
},
{
"input": "Unn",
"output": "NO"
},
{
"input": "oLya_adn_smth",
"output": "NO"
},
{
"input": "FloorISLava",
"output": "NO"
},
{
"input": "ann",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "AAnnnnn",
"output": "YES"
},
{
"input": "AnnAnn",
"output": "NO"
},
{
"input": "Annn",
"output": "YES"
},
{
"input": "Dilzhan",
"output": "NO"
},
{
"input": "Danilaaa",
"output": "YES"
},
{
"input": "AndAnn",
"output": "YES"
},
{
"input": "OlyaAnnAnn",
"output": "NO"
},
{
"input": "DanilDanilOlya",
"output": "NO"
},
{
"input": "DDanil",
"output": "YES"
},
{
"input": "AnnAnnDanil",
"output": "NO"
},
{
"input": "And_Danil",
"output": "YES"
},
{
"input": "abcddddDanil",
"output": "YES"
},
{
"input": "DanilOlyaOlya",
"output": "NO"
},
{
"input": "Nikitaaa",
"output": "YES"
},
{
"input": "aaabbba",
"output": "NO"
},
{
"input": "Ann_Ann_Danil",
"output": "NO"
},
{
"input": "Danil_Danil_Nikita",
"output": "NO"
},
{
"input": "AlexaaaaaaBBBBBOlyaDDDDD",
"output": "YES"
},
{
"input": "IloveDaniland",
"output": "YES"
},
{
"input": "AnAnn",
"output": "YES"
},
{
"input": "Danil_Danil_Olya",
"output": "NO"
},
{
"input": "DanilDanilSlava",
"output": "NO"
},
{
"input": "DanilDanil",
"output": "NO"
},
{
"input": "OlyOlya",
"output": "YES"
},
{
"input": "NikitaNikitb",
"output": "YES"
},
{
"input": "ababaca",
"output": "NO"
},
{
"input": "AnnNikitaNikitaNikitaNikita__good_luck",
"output": "NO"
}
] | 46 | 0 | 0 | 1,545 |
|
893 | Rumor | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm β a well-known game developing company β published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely. | The first line contains two integer numbers *n* and *m* (1<=β€<=*n*<=β€<=105,<=0<=β€<=*m*<=β€<=105) β the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=β€<=*c**i*<=β€<=109) β the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=β€<=*x**i*,<=*y**i*<=β€<=*n*, *x**i*<=β <=*y**i*). It is guaranteed that each pair is listed at most once. | Print one number β the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters. | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n1000000000",
"output": "1000000000"
},
{
"input": "2 0\n0 0",
"output": "0"
},
{
"input": "2 0\n1000000000 0",
"output": "1000000000"
},
{
"input": "2 0\n0 1000000000",
"output": "1000000000"
},
{
"input": "2 0\n1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 1\n0 0\n1 2",
"output": "0"
}
] | 1,747 | 11,366,400 | 0 | 1,547 |
|
793 | Presents in Bankopolis | [
"dp",
"graphs",
"shortest paths"
] | null | null | Bankopolis is an incredible city in which all the *n* crossroads are located on a straight line and numbered from 1 to *n* along it. On each crossroad there is a bank office.
The crossroads are connected with *m* oriented bicycle lanes (the *i*-th lane goes from crossroad *u**i* to crossroad *v**i*), the difficulty of each of the lanes is known.
Oleg the bank client wants to gift happiness and joy to the bank employees. He wants to visit exactly *k* offices, in each of them he wants to gift presents to the employees.
The problem is that Oleg don't want to see the reaction on his gifts, so he can't use a bicycle lane which passes near the office in which he has already presented his gifts (formally, the *i*-th lane passes near the office on the *x*-th crossroad if and only if *min*(*u**i*,<=*v**i*)<=<<=*x*<=<<=*max*(*u**i*,<=*v**i*))). Of course, in each of the offices Oleg can present gifts exactly once. Oleg is going to use exactly *k*<=-<=1 bicycle lane to move between offices. Oleg can start his path from any office and finish it in any office.
Oleg wants to choose such a path among possible ones that the total difficulty of the lanes he will use is minimum possible. Find this minimum possible total difficulty. | The first line contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=80) β the number of crossroads (and offices) and the number of offices Oleg wants to visit.
The second line contains single integer *m* (0<=β€<=*m*<=β€<=2000) β the number of bicycle lanes in Bankopolis.
The next *m* lines contain information about the lanes.
The *i*-th of these lines contains three integers *u**i*, *v**i* and *c**i* (1<=β€<=*u**i*,<=*v**i*<=β€<=*n*, 1<=β€<=*c**i*<=β€<=1000), denoting the crossroads connected by the *i*-th road and its difficulty. | In the only line print the minimum possible total difficulty of the lanes in a valid path, or -1 if there are no valid paths. | [
"7 4\n4\n1 6 2\n6 2 2\n2 4 2\n2 7 1\n",
"4 3\n4\n2 1 2\n1 3 2\n3 4 2\n4 1 1\n"
] | [
"6\n",
"3\n"
] | In the first example Oleg visiting banks by path 1βββ6βββ2βββ4.
Path 1βββ6βββ2βββ7 with smaller difficulity is incorrect because crossroad 2βββ7 passes near already visited office on the crossroad 6.
In the second example Oleg can visit banks by path 4βββ1βββ3. | [
{
"input": "7 4\n4\n1 6 2\n6 2 2\n2 4 2\n2 7 1",
"output": "6"
},
{
"input": "4 3\n4\n2 1 2\n1 3 2\n3 4 2\n4 1 1",
"output": "3"
},
{
"input": "3 2\n10\n2 3 290\n3 1 859\n3 1 852\n1 2 232\n1 2 358\n2 1 123\n1 3 909\n2 1 296\n1 3 119\n1 2 584",
"output": "119"
},
{
"input": "3 3\n4\n1 2 545\n1 3 716\n3 1 3\n2 3 338",
"output": "548"
},
{
"input": "5 3\n20\n5 2 515\n4 1 865\n3 4 570\n1 5 371\n3 1 420\n5 2 464\n4 3 130\n4 1 381\n1 2 702\n5 1 97\n5 2 402\n5 2 314\n1 4 272\n3 1 505\n5 4 662\n2 3 893\n1 3 20\n4 2 601\n1 3 4\n4 2 474",
"output": "101"
},
{
"input": "5 5\n20\n2 5 174\n4 3 496\n5 2 103\n2 1 345\n2 4 942\n3 5 131\n3 2 451\n5 2 299\n2 4 285\n4 5 241\n4 5 706\n2 1 639\n1 5 94\n1 2 844\n3 4 194\n2 4 812\n2 5 566\n3 5 293\n3 4 356\n2 5 717",
"output": "978"
},
{
"input": "5 5\n10\n2 4 420\n4 5 974\n5 1 910\n1 3 726\n1 2 471\n5 2 94\n3 2 307\n2 5 982\n5 4 848\n3 5 404",
"output": "-1"
},
{
"input": "3 2\n4\n2 3 716\n3 2 239\n3 2 646\n3 2 39",
"output": "39"
},
{
"input": "5 4\n4\n5 4 614\n4 1 177\n1 3 66\n5 2 43",
"output": "857"
},
{
"input": "10 4\n10\n1 4 662\n4 7 555\n7 9 172\n1 8 481\n8 10 609\n1 2 705\n1 10 225\n8 2 939\n2 10 329\n6 10 477",
"output": "1389"
},
{
"input": "10 7\n50\n4 7 655\n7 3 220\n3 5 15\n5 10 811\n10 1 490\n1 2 800\n7 10 200\n1 5 377\n1 4 656\n6 4 432\n3 7 563\n1 8 122\n2 9 777\n3 2 157\n5 8 912\n9 8 496\n9 2 740\n3 2 201\n6 7 653\n1 7 554\n6 9 660\n3 2 622\n6 10 227\n9 1 42\n2 6 346\n2 7 944\n3 10 654\n5 2 501\n1 6 786\n3 8 306\n6 1 998\n6 2 581\n10 1 843\n10 9 993\n10 9 93\n2 9 770\n1 5 89\n1 7 761\n6 1 387\n7 1 24\n5 9 922\n1 8 480\n9 7 814\n4 3 682\n9 3 73\n9 6 436\n4 1 685\n10 8 46\n8 2 725\n4 1 892",
"output": "1760"
},
{
"input": "6 4\n10\n2 5 609\n5 6 805\n6 4 814\n5 6 322\n4 3 689\n4 6 30\n2 1 949\n2 1 650\n2 4 217\n4 2 362",
"output": "1826"
},
{
"input": "1 1\n0",
"output": "0"
}
] | 124 | 409,600 | 0 | 1,548 |
|
831 | Unimodal Array | [
"implementation"
] | null | null | Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6].
Write a program that checks if an array is unimodal. | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=1<=000) β the elements of the array. | Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower). | [
"6\n1 5 5 5 4 2\n",
"5\n10 20 30 20 10\n",
"4\n1 2 1 2\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | [
{
"input": "6\n1 5 5 5 4 2",
"output": "YES"
},
{
"input": "5\n10 20 30 20 10",
"output": "YES"
},
{
"input": "4\n1 2 1 2",
"output": "NO"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "YES"
},
{
"input": "6\n5 7 11 11 2 1",
"output": "YES"
},
{
"input": "1\n7",
"output": "YES"
},
{
"input": "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527",
"output": "YES"
},
{
"input": "5\n5 5 6 6 1",
"output": "NO"
},
{
"input": "3\n4 4 2",
"output": "YES"
},
{
"input": "4\n4 5 5 6",
"output": "NO"
},
{
"input": "3\n516 516 515",
"output": "YES"
},
{
"input": "5\n502 503 508 508 507",
"output": "YES"
},
{
"input": "10\n538 538 538 538 538 538 538 538 538 538",
"output": "YES"
},
{
"input": "15\n452 454 455 455 450 448 443 442 439 436 433 432 431 428 426",
"output": "YES"
},
{
"input": "20\n497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513",
"output": "YES"
},
{
"input": "50\n462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337",
"output": "YES"
},
{
"input": "70\n290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479",
"output": "YES"
},
{
"input": "99\n433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393",
"output": "YES"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543",
"output": "YES"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521",
"output": "YES"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504",
"output": "YES"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496",
"output": "YES"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173",
"output": "YES"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333",
"output": "YES"
},
{
"input": "1\n1000",
"output": "YES"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "100\n1000 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": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1",
"output": "YES"
},
{
"input": "100\n1 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": "YES"
},
{
"input": "100\n1000 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 999 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": "NO"
},
{
"input": "100\n998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 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 999",
"output": "NO"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543",
"output": "NO"
},
{
"input": "100\n527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527",
"output": "NO"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521",
"output": "NO"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504",
"output": "NO"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496",
"output": "NO"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173",
"output": "NO"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333",
"output": "NO"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "NO"
},
{
"input": "3\n2 1 1",
"output": "NO"
},
{
"input": "3\n2 1 2",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346",
"output": "YES"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475",
"output": "YES"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271",
"output": "YES"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346",
"output": "NO"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475",
"output": "NO"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271",
"output": "YES"
},
{
"input": "2\n1 3",
"output": "YES"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "5\n2 2 1 1 1",
"output": "NO"
},
{
"input": "4\n1 3 2 2",
"output": "NO"
},
{
"input": "6\n1 2 1 2 2 1",
"output": "NO"
},
{
"input": "2\n4 2",
"output": "YES"
},
{
"input": "3\n3 2 2",
"output": "NO"
},
{
"input": "9\n1 2 2 3 3 4 3 2 1",
"output": "NO"
},
{
"input": "4\n5 5 4 4",
"output": "NO"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "5\n5 4 3 2 1",
"output": "YES"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 2 3 4 5",
"output": "YES"
},
{
"input": "3\n2 2 1",
"output": "YES"
},
{
"input": "3\n4 3 3",
"output": "NO"
},
{
"input": "7\n1 5 5 4 3 3 1",
"output": "NO"
},
{
"input": "6\n3 3 1 2 2 1",
"output": "NO"
},
{
"input": "5\n1 2 1 2 1",
"output": "NO"
},
{
"input": "2\n5 1",
"output": "YES"
},
{
"input": "9\n1 2 3 4 4 3 2 2 1",
"output": "NO"
},
{
"input": "3\n2 2 3",
"output": "NO"
},
{
"input": "2\n5 4",
"output": "YES"
},
{
"input": "5\n1 3 3 2 2",
"output": "NO"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 99",
"output": "YES"
},
{
"input": "4\n1 2 3 4",
"output": "YES"
},
{
"input": "3\n5 5 2",
"output": "YES"
},
{
"input": "4\n1 4 2 3",
"output": "NO"
},
{
"input": "2\n3 2",
"output": "YES"
},
{
"input": "5\n1 2 2 1 1",
"output": "NO"
},
{
"input": "4\n3 3 2 2",
"output": "NO"
},
{
"input": "5\n1 2 3 2 2",
"output": "NO"
},
{
"input": "5\n5 6 6 5 5",
"output": "NO"
},
{
"input": "4\n2 2 1 1",
"output": "NO"
},
{
"input": "5\n5 4 3 3 2",
"output": "NO"
},
{
"input": "7\n1 3 3 3 2 1 1",
"output": "NO"
},
{
"input": "9\n5 6 6 5 5 4 4 3 3",
"output": "NO"
},
{
"input": "6\n1 5 5 3 2 2",
"output": "NO"
},
{
"input": "5\n2 1 3 3 1",
"output": "NO"
},
{
"input": "2\n4 3",
"output": "YES"
},
{
"input": "5\n3 2 2 1 1",
"output": "NO"
},
{
"input": "4\n5 4 3 2",
"output": "YES"
},
{
"input": "4\n4 4 1 1",
"output": "NO"
},
{
"input": "4\n3 3 1 1",
"output": "NO"
},
{
"input": "4\n4 4 2 2",
"output": "NO"
},
{
"input": "5\n4 4 3 2 2",
"output": "NO"
},
{
"input": "8\n4 4 4 4 5 6 7 8",
"output": "NO"
},
{
"input": "5\n3 5 4 4 3",
"output": "NO"
},
{
"input": "6\n2 5 3 3 2 2",
"output": "NO"
},
{
"input": "4\n5 5 2 2",
"output": "NO"
},
{
"input": "5\n1 2 2 3 5",
"output": "NO"
}
] | 46 | 0 | 3 | 1,549 |
|
12 | Fruits | [
"greedy",
"implementation",
"sortings"
] | C. Fruits | 1 | 256 | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags). | The first line of the input contains two integer number *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100) β the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following *m* lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to *n*. Also it is known that the seller has in stock all fruits that Valera wants to buy. | Print two numbers *a* and *b* (*a*<=β€<=*b*) β the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. | [
"5 3\n4 2 1 10 5\napple\norange\nmango\n",
"6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n"
] | [
"7 19\n",
"11 30\n"
] | none | [
{
"input": "5 3\n4 2 1 10 5\napple\norange\nmango",
"output": "7 19"
},
{
"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange",
"output": "11 30"
},
{
"input": "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl",
"output": "173 173"
},
{
"input": "1 4\n1\nu\nu\nu\nu",
"output": "4 4"
},
{
"input": "3 3\n4 2 3\nwivujdxzjm\nawagljmtc\nwivujdxzjm",
"output": "7 11"
},
{
"input": "3 4\n10 10 10\nodchpcsdhldqnkbhwtwnx\nldqnkbhwtwnxk\nodchpcsdhldqnkbhwtwnx\nldqnkbhwtwnxk",
"output": "40 40"
},
{
"input": "3 1\n14 26 22\naag",
"output": "14 26"
},
{
"input": "2 2\n5 5\ndcypj\npiyqiagzjlvbhgfndhfu",
"output": "10 10"
},
{
"input": "4 3\n5 3 10 3\nxzjhplrzkbbzkypfazf\nxzjhplrzkbbzkypfazf\nh",
"output": "9 25"
},
{
"input": "5 5\n10 10 6 7 9\niyerjkvzibxhllkeuagptnoqrzm\nvzibxhllkeuag\niyerjkvzibxhllkeuagptnoqrzm\nnoq\nnoq",
"output": "35 49"
},
{
"input": "10 8\n19 18 20 13 19 13 11 10 19 16\nkayangqlsqmcd\nqls\nqydawlbludrgrjfjrhd\nfjrh\nqls\nqls\nrnmmayh\nkayangqlsqmcd",
"output": "94 154"
},
{
"input": "5 15\n61 56 95 42 85\noq\ndwxivk\ntxdxzsfdj\noq\noq\ndwxivk\ntxdxzsfdj\ndwxivk\ntxdxzsfdj\nk\nk\ndwxivk\noq\nk\ntxdxzsfdj",
"output": "891 1132"
},
{
"input": "12 18\n42 44 69 16 81 64 12 68 70 75 75 67\nfm\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nl\nl\nl\nfm\nqamklzfmrjnqgdspwfasjnplg\nl\nnplgwotfm\np\nl\namklzfm\ntkpubqamklzfmrjn\npwf\nfm\np",
"output": "606 1338"
},
{
"input": "24 24\n34 69 89 45 87 30 78 14 53 16 27 54 75 95 10 69 80 71 43 3 91 9 8 7\nswtcofrcpeyszydwkrg\nszyd\npeyszyd\nrcpeyszydwkrgfj\npeyszydwkrgf\nzydw\nsmzginydyrtua\nj\nj\ntzwsw\ngfj\nyssoqnlpsm\ninydyrtuatzw\ninydy\nlpsmzginydyrtuatzwswtcofrcpeyszy\nyssoqnlpsm\npeyszyd\nyssoqnlpsm\ninydy\npeyszyd\ninydyrtuatzw\nat\nfj\nswtcofrcpeyszydwkrg",
"output": "552 1769"
}
] | 46 | 102,400 | 3.976809 | 1,553 |
182 | Vasya's Calendar | [
"implementation"
] | null | null | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present β the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=β€<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1.
Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.
A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1. | The first line contains the single number *d* β the maximum number of the day that Vasya's clock can show (1<=β€<=*d*<=β€<=106).
The second line contains a single integer *n* β the number of months in the year (1<=β€<=*n*<=β€<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=β€<=*a**i*<=β€<=*d*) β the number of days in each month in the order in which they follow, starting from the first one. | Print a single number β the number of times Vasya manually increased the day number by one throughout the last year. | [
"4\n2\n2 2\n",
"5\n3\n3 4 3\n",
"31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n"
] | [
"2\n",
"3\n",
"7\n"
] | In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing. | [
{
"input": "4\n2\n2 2",
"output": "2"
},
{
"input": "5\n3\n3 4 3",
"output": "3"
},
{
"input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31",
"output": "7"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n1 1",
"output": "0"
},
{
"input": "2\n2\n1 1",
"output": "1"
},
{
"input": "10\n2\n10 2",
"output": "0"
},
{
"input": "10\n3\n6 3 6",
"output": "11"
},
{
"input": "10\n4\n8 7 1 5",
"output": "14"
},
{
"input": "10\n5\n2 7 8 4 4",
"output": "19"
},
{
"input": "10\n6\n8 3 4 9 6 1",
"output": "20"
},
{
"input": "10\n7\n10 5 3 1 1 9 1",
"output": "31"
},
{
"input": "10\n8\n6 5 10 6 8 1 3 2",
"output": "31"
},
{
"input": "10\n9\n6 2 7 5 5 4 8 6 2",
"output": "37"
},
{
"input": "10\n10\n1 10 1 10 1 1 7 8 6 7",
"output": "45"
},
{
"input": "100\n100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "5099"
},
{
"input": "101\n100\n19 17 15 16 28 69 41 47 75 42 19 98 16 90 92 47 21 4 98 17 27 31 90 10 14 92 62 73 56 55 6 60 62 22 78 1 3 86 18 59 92 41 21 34 67 9 92 78 77 45 50 92 57 61 11 98 89 72 57 93 100 12 61 48 5 48 38 9 65 64 77 29 18 55 94 42 10 77 43 46 7 89 8 13 5 53 80 59 23 100 30 28 29 24 85 56 10 22 24 16",
"output": "5301"
},
{
"input": "102\n100\n31 22 59 16 11 56 81 4 19 31 8 72 4 92 18 7 13 12 62 40 34 67 40 23 96 4 90 28 3 18 54 49 10 71 73 79 69 7 41 75 59 13 2 78 72 6 95 33 52 97 7 86 57 94 12 93 19 94 59 28 5 96 46 102 2 101 57 85 53 69 72 39 14 75 8 16 10 57 26 4 85 18 89 84 48 93 54 21 78 6 67 35 11 78 91 91 97 15 8 32",
"output": "5447"
},
{
"input": "103\n100\n68 38 41 54 37 11 35 26 43 97 70 3 13 11 64 83 3 95 99 16 4 13 22 27 64 20 95 38 40 87 6 17 95 67 31 24 85 33 98 24 89 101 66 38 42 5 95 18 95 13 103 85 72 73 68 93 22 59 48 59 72 46 5 41 54 32 48 69 3 76 2 26 102 44 39 58 55 85 40 16 81 78 92 63 25 97 83 2 54 16 20 63 19 8 84 34 1 22 43 93",
"output": "5358"
},
{
"input": "104\n100\n65 74 94 71 98 38 88 67 71 84 45 79 55 86 55 51 27 89 14 66 29 63 8 103 98 94 87 81 58 68 24 96 60 36 48 95 28 72 95 42 87 7 14 23 99 77 34 14 90 31 8 99 29 30 9 88 42 1 77 61 55 85 17 98 62 78 27 1 58 69 82 62 62 81 56 104 66 8 17 23 7 61 59 70 79 64 78 16 32 11 59 4 24 73 55 2 95 39 62 13",
"output": "4773"
}
] | 1,000 | 6,963,200 | 0 | 1,554 |
|
598 | Igor In the Museum | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=Γ<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture.
At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one.
For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see. | First line of the input contains three integers *n*, *m* and *k* (3<=β€<=*n*,<=*m*<=β€<=1000,<=1<=β€<=*k*<=β€<=*min*(*n*Β·*m*,<=100<=000)) β the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' β the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum.
Each of the last *k* lines contains two integers *x* and *y* (1<=β€<=*x*<=β€<=*n*,<=1<=β€<=*y*<=β€<=*m*) β the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns β from left to right. It is guaranteed that all starting positions are empty cells. | Print *k* integers β the maximum number of pictures, that Igor can see if he starts in corresponding position. | [
"5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n",
"4 4 1\n****\n*..*\n*.**\n****\n3 2\n"
] | [
"6\n4\n10\n",
"8\n"
] | none | [
{
"input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3",
"output": "6\n4\n10"
},
{
"input": "4 4 1\n****\n*..*\n*.**\n****\n3 2",
"output": "8"
},
{
"input": "3 3 1\n***\n*.*\n***\n2 2",
"output": "4"
},
{
"input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\n2 4\n4 2\n2 2\n2 3\n2 2\n2 2\n2 4\n3 2\n2 2\n2 2",
"output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12"
},
{
"input": "10 3 10\n***\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n2 2\n2 2\n2 2\n2 2\n8 2\n2 2\n2 2\n7 2\n8 2\n6 2",
"output": "6\n6\n6\n6\n10\n6\n6\n10\n10\n10"
},
{
"input": "3 10 10\n**********\n***.*.*..*\n**********\n2 6\n2 6\n2 9\n2 9\n2 4\n2 9\n2 6\n2 6\n2 4\n2 6",
"output": "4\n4\n6\n6\n4\n6\n4\n4\n4\n4"
},
{
"input": "10 10 50\n**********\n*......***\n***..**..*\n***....***\n**..***..*\n**..**.*.*\n*****..***\n*.***..***\n*..****.**\n**********\n5 9\n5 9\n7 7\n6 4\n6 7\n8 7\n6 7\n9 2\n3 9\n9 2\n4 7\n4 6\n2 7\n9 2\n7 7\n5 8\n8 7\n8 6\n7 7\n5 9\n8 7\n3 8\n3 8\n5 9\n9 8\n9 3\n8 7\n5 9\n9 2\n9 8\n9 3\n3 8\n9 2\n8 6\n2 4\n6 9\n6 3\n9 8\n3 9\n9 8\n4 5\n8 6\n3 8\n5 9\n8 7\n5 8\n6 9\n8 2\n3 9\n3 9",
"output": "8\n8\n10\n28\n10\n10\n10\n8\n6\n8\n28\n28\n28\n8\n10\n8\n10\n10\n10\n8\n10\n6\n6\n8\n4\n8\n10\n8\n8\n4\n8\n6\n8\n10\n28\n8\n28\n4\n6\n4\n28\n10\n6\n8\n10\n8\n8\n8\n6\n6"
},
{
"input": "5 5 21\n*****\n*.***\n*****\n*****\n*****\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2",
"output": "4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4"
}
] | 1,000 | 87,552,000 | 0 | 1,555 |
|
922 | Magic Forest | [
"brute force"
] | null | null | Imp is in a magic forest, where xorangles grow (wut?)
A xorangle of order *n* is such a non-degenerate triangle, that lengths of its sides are integers not exceeding *n*, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order *n* to get out of the forest.
Formally, for a given integer *n* you have to find the number of such triples (*a*,<=*b*,<=*c*), that:
- 1<=β€<=*a*<=β€<=*b*<=β€<=*c*<=β€<=*n*; - , where denotes the [bitwise xor](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of integers *x* and *y*. - (*a*,<=*b*,<=*c*) form a non-degenerate (with strictly positive area) triangle. | The only line contains a single integer *n* (1<=β€<=*n*<=β€<=2500). | Print the number of xorangles of order *n*. | [
"6\n",
"10\n"
] | [
"1\n",
"2\n"
] | The only xorangle in the first sample is (3,β5,β6). | [
{
"input": "6",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "2500",
"output": "700393"
},
{
"input": "952",
"output": "118547"
},
{
"input": "88",
"output": "536"
},
{
"input": "1216",
"output": "160822"
},
{
"input": "2140",
"output": "614785"
},
{
"input": "564",
"output": "35087"
},
{
"input": "1488",
"output": "239580"
},
{
"input": "116",
"output": "1332"
},
{
"input": "1040",
"output": "145820"
},
{
"input": "1965",
"output": "545494"
},
{
"input": "593",
"output": "36605"
},
{
"input": "779",
"output": "63500"
},
{
"input": "1703",
"output": "352045"
},
{
"input": "331",
"output": "9877"
},
{
"input": "1051",
"output": "145985"
},
{
"input": "2179",
"output": "618074"
},
{
"input": "603",
"output": "37312"
},
{
"input": "1731",
"output": "369691"
},
{
"input": "2451",
"output": "681980"
},
{
"input": "1079",
"output": "146833"
},
{
"input": "2207",
"output": "621708"
},
{
"input": "2394",
"output": "663240"
},
{
"input": "818",
"output": "73972"
},
{
"input": "1946",
"output": "529383"
},
{
"input": "166",
"output": "2200"
},
{
"input": "1294",
"output": "175915"
},
{
"input": "2218",
"output": "623386"
},
{
"input": "846",
"output": "82106"
},
{
"input": "1566",
"output": "273341"
},
{
"input": "194",
"output": "3240"
},
{
"input": "1322",
"output": "183405"
},
{
"input": "1508",
"output": "247634"
},
{
"input": "2433",
"output": "675245"
},
{
"input": "857",
"output": "85529"
},
{
"input": "1781",
"output": "402718"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "2444",
"output": "679373"
},
{
"input": "2498",
"output": "699536"
}
] | 171 | 1,638,400 | 3 | 1,557 |
|
525 | Arthur and Walls | [
"constructive algorithms",
"data structures",
"graphs",
"greedy",
"shortest paths"
] | null | null | Finally it is a day when Arthur has enough money for buying an apartment. He found a great option close to the center of the city with a nice price.
Plan of the apartment found by Arthur looks like a rectangle *n*<=Γ<=*m* consisting of squares of size 1<=Γ<=1. Each of those squares contains either a wall (such square is denoted by a symbol "*" on the plan) or a free space (such square is denoted on the plan by a symbol ".").
Room in an apartment is a maximal connected area consisting of free squares. Squares are considered adjacent if they share a common side.
The old Arthur dream is to live in an apartment where all rooms are rectangles. He asks you to calculate minimum number of walls you need to remove in order to achieve this goal. After removing a wall from a square it becomes a free square. While removing the walls it is possible that some rooms unite into a single one. | The first line of the input contains two integers *n*,<=*m* (1<=β€<=*n*,<=*m*<=β€<=2000) denoting the size of the Arthur apartments.
Following *n* lines each contain *m* symbols β the plan of the apartment.
If the cell is denoted by a symbol "*" then it contains a wall.
If the cell is denoted by a symbol "." then it this cell is free from walls and also this cell is contained in some of the rooms. | Output *n* rows each consisting of *m* symbols that show how the Arthur apartment plan should look like after deleting the minimum number of walls in order to make each room (maximum connected area free from walls) be a rectangle.
If there are several possible answers, output any of them. | [
"5 5\n.*.*.\n*****\n.*.*.\n*****\n.*.*.\n",
"6 7\n***.*.*\n..*.*.*\n*.*.*.*\n*.*.*.*\n..*...*\n*******\n",
"4 5\n.....\n.....\n..***\n..*..\n"
] | [
".*.*.\n*****\n.*.*.\n*****\n.*.*.\n",
"***...*\n..*...*\n..*...*\n..*...*\n..*...*\n*******\n",
".....\n.....\n.....\n.....\n"
] | none | [
{
"input": "5 5\n.*.*.\n*****\n.*.*.\n*****\n.*.*.",
"output": ".*.*.\n*****\n.*.*.\n*****\n.*.*."
},
{
"input": "6 7\n***.*.*\n..*.*.*\n*.*.*.*\n*.*.*.*\n..*...*\n*******",
"output": "***...*\n..*...*\n..*...*\n..*...*\n..*...*\n*******"
},
{
"input": "4 5\n.....\n.....\n..***\n..*..",
"output": ".....\n.....\n.....\n....."
},
{
"input": "6 6\n******\n*.*..*\n*.****\n****.*\n*..*.*\n******",
"output": "******\n*.*..*\n*.****\n****.*\n*..*.*\n******"
},
{
"input": "4 4\n.*..\n.***\n***.\n..*.",
"output": ".*..\n.***\n***.\n..*."
},
{
"input": "3 5\n..*..\n**.**\n..*..",
"output": "..*..\n**.**\n..*.."
},
{
"input": "6 3\n.*.\n.*.\n*.*\n.*.\n.*.\n.*.",
"output": ".*.\n.*.\n*.*\n.*.\n.*.\n.*."
},
{
"input": "5 5\n..*..\n..*..\n**.**\n..*..\n..*..",
"output": "..*..\n..*..\n**.**\n..*..\n..*.."
},
{
"input": "4 4\n**.*\n.***\n***.\n..**",
"output": "**.*\n.***\n***.\n..**"
},
{
"input": "4 4\n.*..\n.***\n***.\n*.*.",
"output": ".*..\n.***\n***.\n*.*."
},
{
"input": "6 3\n.*.\n**.\n*.*\n.**\n**.\n.*.",
"output": ".*.\n**.\n*.*\n.**\n**.\n.*."
},
{
"input": "1 1\n.",
"output": "."
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "1 2\n.*",
"output": ".*"
},
{
"input": "2 1\n.\n.",
"output": ".\n."
},
{
"input": "2 2\n**\n**",
"output": "**\n**"
},
{
"input": "2 2\n.*\n*.",
"output": ".*\n*."
},
{
"input": "2 2\n*.\n..",
"output": "..\n.."
},
{
"input": "2 2\n.*\n.*",
"output": ".*\n.*"
},
{
"input": "3 4\n.***\n..*.\n**..",
"output": "....\n....\n...."
},
{
"input": "5 2\n..\n.*\n*.\n.*\n.*",
"output": "..\n..\n..\n..\n.."
},
{
"input": "4 4\n.*..\n*.*.\n****\n***.",
"output": "....\n....\n****\n***."
},
{
"input": "5 3\n.**\n*.*\n**.\n..*\n*..",
"output": "...\n...\n...\n...\n..."
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "1 1\n.",
"output": "."
}
] | 2,000 | 49,356,800 | 0 | 1,558 |
|
952 | A Map of the Cat | [
"brute force",
"interactive"
] | null | null | If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
You have met a cat. Can you figure out whether it's normal or grumpy? | none | none | [] | [] | Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer. | [
{
"input": "5 0 1 2 5 3 5 4 5 5",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 5 6 6 7 8 9 10 11",
"output": "Correct answer 'grumpy'"
},
{
"input": "10 6 5 7 5 6 11 5 8 9",
"output": "Correct answer 'grumpy'"
},
{
"input": "7 10 8 9 6 5 5 11 5 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 5 4 5 2 5 5 0 1 3",
"output": "Correct answer 'normal'"
},
{
"input": "0 4 3 5 5 5 2 1 5 5",
"output": "Correct answer 'normal'"
},
{
"input": "3 5 5 0 5 5 2 5 4 1",
"output": "Correct answer 'normal'"
},
{
"input": "5 4 5 1 5 5 0 5 2 3",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 1 2 5 5 4 3 0 5",
"output": "Correct answer 'normal'"
},
{
"input": "7 10 5 5 11 6 5 9 6 8",
"output": "Correct answer 'grumpy'"
},
{
"input": "6 5 10 5 5 7 8 11 9 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 5 5 5 5 0 4 2 3 1",
"output": "Correct answer 'normal'"
},
{
"input": "11 5 6 5 9 5 10 8 7 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 9 8 10 7 11 5 6 5 6",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 8 10 11 5 6 5 6 7 9",
"output": "Correct answer 'grumpy'"
},
{
"input": "5 5 6 11 6 10 9 5 8 7",
"output": "Correct answer 'grumpy'"
},
{
"input": "1 5 5 2 5 0 3 5 5 4",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 2 5 4 5 3 1 0 5",
"output": "Correct answer 'normal'"
}
] | 109 | 0 | 0 | 1,559 |
|
213 | Game | [
"dfs and similar",
"greedy"
] | null | null | Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of *n* parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.
Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions:
- Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer. - Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that. - Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that. - Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that. - Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that. - Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that. - Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.
Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary. | The first line contains integer *n* (1<=β€<=*n*<=β€<=200) β the number of game parts. The next line contains *n* integers, the *i*-th integer β *c**i* (1<=β€<=*c**i*<=β€<=3) represents the number of the computer, on which you can complete the game part number *i*.
Next *n* lines contain descriptions of game parts. The *i*-th line first contains integer *k**i* (0<=β€<=*k**i*<=β€<=*n*<=-<=1), then *k**i* distinct integers *a**i*,<=*j* (1<=β€<=*a**i*,<=*j*<=β€<=*n*; *a**i*,<=*j*<=β <=*i*) β the numbers of parts to complete before part *i*.
Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to *n* in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game. | On a single line print the answer to the problem. | [
"1\n1\n0\n",
"5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0\n"
] | [
"1\n",
"7\n"
] | Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours. | [
{
"input": "1\n1\n0",
"output": "1"
},
{
"input": "5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0",
"output": "7"
},
{
"input": "7\n1 3 3 1 2 1 1\n0\n1 1\n1 1\n2 1 6\n3 1 2 7\n1 1\n1 1",
"output": "11"
},
{
"input": "2\n2 1\n0\n1 1",
"output": "4"
},
{
"input": "3\n2 1 2\n0\n0\n0",
"output": "4"
},
{
"input": "4\n2 1 1 1\n0\n0\n1 1\n1 3",
"output": "6"
},
{
"input": "6\n1 1 2 3 3 1\n2 2 3\n0\n0\n0\n2 2 1\n1 1",
"output": "10"
},
{
"input": "8\n2 2 2 1 1 2 1 1\n3 5 6 7\n1 5\n2 5 6\n1 5\n0\n1 5\n1 5\n2 5 6",
"output": "11"
},
{
"input": "9\n3 3 2 1 3 1 2 2 1\n2 4 3\n0\n2 4 2\n0\n1 4\n2 4 2\n0\n1 4\n3 4 3 8",
"output": "13"
},
{
"input": "10\n3 1 2 2 2 1 2 1 1 1\n0\n2 6 9\n0\n1 9\n0\n1 3\n4 3 6 5 2\n3 6 4 2\n0\n1 3",
"output": "14"
},
{
"input": "11\n1 2 2 3 3 2 2 2 2 3 1\n1 4\n2 7 11\n0\n0\n1 2\n1 11\n0\n1 2\n3 7 11 2\n3 3 2 9\n0",
"output": "14"
},
{
"input": "12\n1 3 2 2 1 3 2 1 3 2 2 2\n2 3 4\n3 12 11 10\n1 8\n2 8 7\n2 9 10\n1 3\n0\n0\n1 4\n4 3 1 12 9\n3 8 3 4\n1 4",
"output": "18"
},
{
"input": "13\n3 3 2 2 1 3 1 1 1 1 2 1 2\n5 6 3 11 13 12\n1 6\n2 10 6\n3 6 3 11\n1 6\n1 10\n3 6 2 3\n4 6 3 9 11\n3 6 2 3\n0\n3 6 2 3\n4 6 3 4 13\n2 6 3",
"output": "21"
},
{
"input": "14\n3 2 2 1 2 1 1 3 1 2 2 3 1 1\n2 9 13\n3 9 13 8\n2 9 6\n3 9 6 13\n1 9\n1 9\n3 9 6 13\n2 9 13\n0\n4 9 3 13 4\n4 9 6 13 2\n2 9 13\n1 9\n8 9 5 6 3 13 7 4 11",
"output": "20"
},
{
"input": "15\n1 2 3 2 3 2 2 2 3 3 3 2 3 1 3\n5 2 7 4 3 6\n0\n2 7 4\n2 2 15\n1 7\n1 7\n0\n2 4 6\n1 6\n2 15 3\n4 12 2 15 7\n0\n3 2 5 6\n3 2 4 6\n1 2",
"output": "20"
},
{
"input": "16\n3 3 1 3 2 3 2 2 3 1 2 3 2 2 2 3\n1 14\n4 14 10 13 6\n3 14 15 6\n1 14\n4 14 10 9 7\n4 14 10 13 9\n4 14 10 13 6\n4 14 4 12 3\n2 14 4\n1 14\n1 14\n2 14 1\n4 14 10 4 1\n0\n2 14 10\n1 14",
"output": "22"
},
{
"input": "17\n3 2 3 2 2 2 1 3 3 3 3 2 3 3 3 1 1\n0\n0\n2 8 10\n4 12 8 6 16\n0\n2 8 13\n3 2 8 10\n1 12\n4 8 17 3 16\n2 2 8\n0\n1 2\n2 8 10\n2 12 8\n2 8 10\n1 8\n2 12 8",
"output": "21"
},
{
"input": "18\n2 1 1 3 2 1 3 2 3 3 2 2 1 1 3 1 1 3\n3 16 8 6\n3 16 6 1\n4 6 13 5 7\n2 6 2\n4 16 6 17 1\n2 16 8\n3 6 17 12\n1 16\n0\n3 6 15 1\n3 16 6 12\n7 16 9 8 6 13 17 14\n1 6\n1 6\n3 8 6 13\n0\n1 6\n3 9 6 13",
"output": "26"
},
{
"input": "19\n2 1 2 3 3 3 2 1 1 1 1 3 3 1 1 1 2 2 3\n0\n2 1 7\n0\n4 3 2 17 13\n1 17\n1 3\n3 1 3 6\n4 1 17 9 13\n3 1 16 17\n0\n3 3 6 17\n1 6\n6 10 6 7 17 9 11\n3 10 17 13\n4 3 17 13 8\n1 3\n3 6 7 16\n0\n6 1 7 17 11 13 15",
"output": "29"
},
{
"input": "20\n1 2 2 2 1 3 3 2 2 1 2 2 3 1 2 2 2 1 1 1\n2 10 8\n5 10 12 3 20 7\n0\n3 10 15 3\n0\n3 14 17 3\n2 12 20\n0\n3 17 10 12\n1 17\n1 5\n1 5\n0\n1 18\n3 18 5 12\n5 5 12 8 3 19\n0\n0\n1 12\n1 18",
"output": "24"
},
{
"input": "11\n3 1 3 2 3 2 3 2 3 1 3\n6 2 3 9 5 7 10\n1 6\n2 6 2\n5 6 2 3 9 5\n2 3 9\n0\n5 3 9 5 8 4\n4 2 3 9 5\n2 2 3\n8 6 2 3 9 5 4 11 7\n4 2 3 9 5",
"output": "21"
},
{
"input": "12\n2 3 3 1 1 3 2 2 3 1 3 3\n1 9\n1 1\n2 2 11\n5 1 2 11 5 8\n4 9 10 1 11\n5 9 10 12 11 5\n4 1 12 11 5\n5 10 1 2 12 11\n0\n1 9\n1 12\n0",
"output": "19"
},
{
"input": "13\n3 2 2 1 3 3 2 3 2 2 1 2 3\n7 4 3 2 5 9 8 13\n1 4\n1 4\n0\n3 4 2 6\n2 4 2\n4 4 3 2 9\n5 4 2 6 9 7\n3 4 2 6\n6 4 3 2 5 9 7\n6 4 3 2 6 9 7\n8 4 2 6 5 9 8 11 10\n7 4 3 2 6 9 8 11",
"output": "21"
},
{
"input": "14\n2 3 1 3 1 1 1 2 2 3 1 1 3 1\n4 14 9 8 5\n4 4 8 5 1\n9 4 14 9 8 1 2 13 7 12\n0\n2 14 8\n2 4 14\n7 9 6 10 8 1 2 13\n2 4 6\n1 14\n1 9\n8 4 6 10 8 5 1 2 3\n7 14 6 10 8 1 2 7\n5 10 8 5 1 2\n0",
"output": "21"
},
{
"input": "15\n3 2 2 2 1 1 2 1 1 2 2 3 3 3 2\n1 13\n4 13 1 8 14\n10 5 13 1 8 14 4 2 11 15 10\n6 5 13 1 8 9 14\n0\n11 5 13 1 8 14 4 2 11 10 3 12\n11 13 1 8 14 4 2 11 15 10 3 6\n2 13 1\n4 5 13 1 8\n8 5 13 1 8 14 2 11 15\n6 5 13 1 8 14 2\n10 5 13 1 8 14 2 11 15 10 3\n0\n4 13 1 8 9\n8 5 13 1 8 9 14 2 11",
"output": "23"
},
{
"input": "16\n3 1 2 3 3 2 3 1 3 2 2 1 2 2 1 2\n0\n0\n7 2 8 4 12 5 9 11\n1 1\n4 1 8 4 12\n5 2 4 12 5 11\n4 4 12 5 10\n0\n5 1 8 4 12 5\n6 1 4 12 5 9 11\n6 2 1 8 4 12 5\n2 4 13\n3 1 8 4\n8 1 4 13 12 5 10 3 6\n4 4 12 5 6\n8 8 4 13 12 5 9 6 14",
"output": "26"
},
{
"input": "17\n2 3 1 3 3 3 1 1 1 2 2 2 3 2 3 3 2\n5 4 14 2 11 7\n3 13 4 14\n7 6 4 14 2 1 10 12\n2 6 13\n9 4 2 9 8 7 17 1 10 12\n0\n5 4 14 2 9 11\n4 13 4 2 11\n4 13 4 14 2\n7 13 4 2 11 8 7 1\n4 13 4 14 2\n8 6 4 2 8 7 17 1 10\n0\n1 4\n7 13 4 14 2 9 8 7\n6 4 2 17 1 10 12\n5 13 4 2 9 8",
"output": "27"
},
{
"input": "18\n1 2 3 3 2 2 1 1 3 1 2 3 2 3 1 2 2 3\n5 9 3 14 12 2\n7 9 4 3 14 16 7 12\n1 9\n1 9\n6 9 14 12 1 6 15\n6 9 14 12 2 1 11\n2 9 14\n7 9 14 7 12 2 1 6\n0\n6 9 18 14 7 1 6\n4 9 14 7 1\n2 9 14\n6 9 3 14 7 1 6\n2 9 3\n9 9 3 14 16 12 2 1 6 17\n4 9 4 18 14\n8 9 18 14 12 1 11 6 13\n2 9 4",
"output": "26"
},
{
"input": "19\n2 3 3 2 3 1 3 1 2 2 2 1 1 1 2 2 1 3 3\n0\n3 1 10 6\n8 1 6 2 17 18 12 15 7\n5 6 2 9 17 18\n6 6 2 17 18 12 16\n1 11\n9 1 11 6 2 17 18 4 12 15\n3 1 6 2\n4 1 6 2 8\n0\n1 1\n5 1 6 2 17 18\n12 1 10 6 2 8 17 18 4 12 15 7 3\n10 11 6 2 17 18 4 12 16 15 7\n8 1 6 2 8 17 18 12 16\n8 11 6 2 9 17 18 4 12\n3 11 6 2\n5 10 6 2 9 17\n10 1 6 2 17 18 12 5 15 7 3",
"output": "30"
},
{
"input": "20\n2 2 3 2 3 1 1 3 1 1 1 1 1 3 2 1 3 1 1 1\n1 7\n13 7 1 11 4 6 16 20 12 5 18 19 15 10\n8 7 1 11 4 6 17 8 16\n3 7 1 11\n9 7 1 11 4 6 8 20 12 3\n4 7 1 11 4\n0\n6 7 1 11 4 6 17\n4 7 1 11 4\n7 7 1 11 4 6 17 5\n2 7 1\n9 7 1 11 4 6 17 8 14 20\n11 7 1 11 4 6 20 3 5 15 10 2\n5 7 1 11 4 6\n9 7 1 11 4 6 8 16 14 5\n5 7 1 11 4 6\n5 7 1 11 4 6\n11 7 1 11 4 9 6 17 8 20 3 5\n11 7 1 11 4 6 17 16 20 12 5 18\n6 7 1 11 4 6 14",
"output": "35"
},
{
"input": "21\n1 2 1 3 3 3 1 1 2 2 3 1 3 1 3 3 1 1 1 2 2\n1 5\n0\n1 11\n0\n0\n0\n1 8\n0\n1 11\n1 1\n1 19\n0\n1 2\n0\n0\n0\n0\n1 19\n0\n0\n0",
"output": "25"
},
{
"input": "22\n2 3 2 3 3 2 1 2 3 3 1 3 1 1 2 2 3 3 1 3 2 2\n0\n1 8\n1 22\n1 12\n0\n1 14\n0\n0\n0\n2 22 14\n1 12\n0\n0\n0\n0\n0\n0\n0\n0\n1 16\n1 13\n0",
"output": "25"
},
{
"input": "23\n3 1 3 3 2 2 2 1 3 2 3 1 1 1 1 2 3 1 2 1 3 1 1\n0\n1 11\n1 11\n2 11 16\n1 2\n3 11 1 12\n2 11 16\n2 12 2\n1 13\n2 12 2\n0\n0\n0\n2 13 11\n0\n1 11\n2 12 2\n3 16 6 21\n1 11\n0\n0\n2 11 12\n0",
"output": "27"
},
{
"input": "24\n1 2 1 1 2 2 1 1 3 2 3 1 3 2 3 3 1 1 3 2 3 2 1 2\n1 16\n0\n0\n1 2\n0\n0\n0\n0\n1 2\n0\n0\n0\n0\n0\n0\n0\n2 12 24\n0\n0\n1 11\n0\n0\n0\n0",
"output": "27"
},
{
"input": "25\n3 3 1 1 1 2 2 2 3 1 2 3 2 1 2 2 2 3 2 1 2 3 2 1 1\n0\n0\n0\n0\n0\n0\n1 12\n0\n1 19\n0\n2 12 21\n2 3 10\n0\n1 21\n0\n1 9\n1 3\n0\n0\n2 3 2\n0\n1 12\n0\n1 3\n2 21 9",
"output": "29"
},
{
"input": "26\n1 2 2 1 1 2 1 1 2 1 3 1 3 1 2 3 3 3 2 1 2 1 3 3 2 2\n1 9\n1 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 5\n0\n2 15 12\n1 8\n0\n0\n0\n0\n2 3 26\n0\n0\n0\n1 22\n0\n1 8",
"output": "30"
},
{
"input": "27\n2 1 1 3 2 1 1 2 3 1 1 2 2 2 1 2 1 1 3 3 3 1 1 1 3 1 1\n0\n0\n0\n1 12\n0\n0\n0\n0\n0\n0\n1 26\n0\n0\n0\n0\n1 27\n0\n0\n0\n0\n0\n0\n1 5\n0\n2 20 27\n1 18\n0",
"output": "30"
},
{
"input": "28\n2 1 1 3 2 3 2 2 1 3 2 3 3 2 3 1 2 2 3 3 3 3 1 3 2 1 3 3\n0\n1 7\n0\n2 28 18\n1 28\n0\n0\n0\n0\n0\n0\n2 10 18\n3 8 10 18\n0\n2 1 20\n0\n1 18\n1 27\n2 27 18\n0\n0\n1 28\n0\n0\n0\n0\n1 28\n1 9",
"output": "33"
},
{
"input": "29\n3 3 3 3 3 1 1 1 3 2 2 1 1 3 1 1 1 2 1 2 3 1 1 2 1 3 1 2 3\n0\n0\n0\n0\n0\n1 1\n0\n0\n2 28 15\n0\n0\n0\n2 24 23\n1 28\n0\n1 28\n1 20\n0\n0\n0\n0\n1 28\n0\n0\n2 23 16\n0\n0\n1 7\n1 28",
"output": "32"
},
{
"input": "30\n1 3 3 3 2 3 1 3 3 3 3 2 3 1 3 2 1 1 1 1 2 3 2 1 1 3 3 2 2 2\n0\n1 20\n0\n1 7\n2 6 9\n1 20\n1 20\n3 7 6 9\n2 10 6\n0\n0\n2 6 9\n0\n0\n1 20\n2 6 9\n2 6 9\n0\n2 6 9\n0\n2 6 9\n3 27 6 9\n2 6 9\n2 6 9\n0\n0\n0\n2 6 9\n3 6 9 19\n3 27 6 9",
"output": "34"
},
{
"input": "4\n1 1 2 3\n1 2\n1 3\n0\n1 1",
"output": "8"
}
] | 92 | 0 | 0 | 1,563 |
|
617 | Elephant | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=β€<=*x*<=β€<=1<=000<=000) β The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 46 | 0 | 3 | 1,564 |
|
28 | Bath Queue | [
"combinatorics",
"dp",
"probabilities"
] | C. Bath Queue | 2 | 256 | There are *n* students living in the campus. Every morning all students wake up at the same time and go to wash. There are *m* rooms with wash basins. The *i*-th of these rooms contains *a**i* wash basins. Every student independently select one the rooms with equal probability and goes to it. After all students selected their rooms, students in each room divide into queues by the number of wash basins so that the size of the largest queue is the least possible. Calculate the expected value of the size of the largest queue among all rooms. | The first line contains two positive integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=50) β the amount of students and the amount of rooms. The second line contains *m* integers *a*1,<=*a*2,<=... ,<=*a**m* (1<=β€<=*a**i*<=β€<=50). *a**i* means the amount of wash basins in the *i*-th room. | Output single number: the expected value of the size of the largest queue. Your answer must have an absolute or relative error less than 10<=-<=9. | [
"1 1\n2\n",
"2 2\n1 1\n",
"2 3\n1 1 1\n",
"7 5\n1 1 2 3 1\n"
] | [
"1.00000000000000000000\n",
"1.50000000000000000000\n",
"1.33333333333333350000\n",
"2.50216960000000070000\n"
] | none | [
{
"input": "1 1\n2",
"output": "1.00000000000000000000"
},
{
"input": "2 2\n1 1",
"output": "1.50000000000000000000"
},
{
"input": "2 3\n1 1 1",
"output": "1.33333333333333350000"
},
{
"input": "7 5\n1 1 2 3 1",
"output": "2.50216960000000070000"
},
{
"input": "10 4\n8 4 7 6",
"output": "1.08210754394531210000"
},
{
"input": "5 5\n5 5 5 5 5",
"output": "1.00000000000000020000"
},
{
"input": "7 4\n1 2 3 4",
"output": "2.11712646484374910000"
},
{
"input": "50 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3.80545467981579130000"
},
{
"input": "30 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3.49298980907245000000"
},
{
"input": "20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3.23123684379753670000"
},
{
"input": "1 50\n47 24 49 50 4 21 42 22 34 48 45 15 31 18 12 10 4 45 45 42 49 13 12 9 7 5 30 18 22 50 15 16 25 18 5 41 3 26 19 18 22 5 8 10 16 50 43 44 6 43",
"output": "1.00000000000000000000"
},
{
"input": "1 50\n46 45 44 49 48 48 47 42 48 47 47 48 39 47 48 49 50 48 50 46 48 46 50 47 45 50 41 49 39 44 46 47 43 47 42 47 49 40 49 50 50 50 48 50 48 47 49 46 46 42",
"output": "1.00000000000000000000"
},
{
"input": "1 50\n9 1 1 4 1 9 7 4 3 10 1 7 4 7 2 5 13 2 3 3 2 1 2 1 1 7 7 5 2 6 1 8 2 6 2 15 2 3 1 2 4 8 6 2 6 11 1 2 1 1",
"output": "1.00000000000000000000"
},
{
"input": "50 1\n27",
"output": "2.00000000000000000000"
},
{
"input": "50 1\n48",
"output": "2.00000000000000000000"
},
{
"input": "50 1\n4",
"output": "13.00000000000000000000"
},
{
"input": "20 35\n48 40 49 37 36 44 48 42 37 42 18 44 47 47 41 45 49 47 47 50 16 24 42 24 36 37 45 48 36 43 44 25 34 30 42",
"output": "0.99999999999999978000"
},
{
"input": "50 50\n3 12 1 3 6 2 5 14 2 4 4 1 6 9 4 2 3 19 7 6 4 1 7 4 1 3 6 3 2 4 4 1 6 1 3 1 1 4 1 6 1 2 2 4 12 12 1 5 5 2",
"output": "2.83614403586073620000"
},
{
"input": "50 50\n21 35 15 42 44 1 50 4 26 21 43 41 50 33 47 3 21 14 33 34 43 44 16 41 35 27 3 4 7 14 15 35 27 36 46 13 3 48 32 20 15 33 38 36 39 22 45 7 16 50",
"output": "1.40898003277183290000"
},
{
"input": "50 50\n50 48 38 45 50 48 38 48 49 49 50 50 49 50 38 48 45 40 43 49 48 43 50 50 50 42 47 50 49 34 48 47 48 50 50 50 49 47 48 49 48 48 50 39 45 47 48 47 45 50",
"output": "0.99999999999999156000"
},
{
"input": "50 50\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 49 49 49 50 49 50 50 50 50 48 50 49 50 50 50 50 48 50 50 50 49 50 50 50 50 50 50 50 50 50 50 49 50 50",
"output": "0.99999999999999156000"
},
{
"input": "50 50\n2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1",
"output": "3.71403384155135140000"
},
{
"input": "44 5\n40 48 45 43 17",
"output": "1.00121533621041100000"
},
{
"input": "3 49\n4 2 9 21 22 25 6 9 15 10 37 3 8 6 14 1 3 3 18 1 9 11 8 5 20 21 10 25 35 16 14 18 2 5 12 6 9 8 3 6 19 18 1 13 12 33 4 2 16",
"output": "1.00374843815077060000"
},
{
"input": "19 17\n50 46 38 48 41 41 40 45 47 50 49 33 46 44 46 48 36",
"output": "0.99999999999999967000"
},
{
"input": "12 34\n47 50 49 45 48 50 49 45 50 48 43 49 50 47 49 49 50 50 45 43 45 44 50 47 50 49 47 49 49 42 50 50 50 49",
"output": "1.00000000000000000000"
},
{
"input": "35 40\n12 1 4 8 1 9 1 11 1 1 8 8 16 1 6 5 3 1 6 4 6 2 4 6 2 1 1 16 2 2 3 1 1 2 2 3 8 12 1 4",
"output": "2.65978492228475400000"
},
{
"input": "10 6\n1 1 1 1 1 1",
"output": "3.44474669607021380000"
},
{
"input": "50 50\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "0.99999999999999156000"
},
{
"input": "50 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3.80545467981579130000"
},
{
"input": "50 50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50",
"output": "1.44158938050050490000"
},
{
"input": "1 1\n50",
"output": "1.00000000000000000000"
}
] | 0 | 0 | -1 | 1,565 |
515 | Drazil and Date | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1).
Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling.
Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? | You are given three integers *a*, *b*, and *s* (<=-<=109<=β€<=*a*,<=*b*<=β€<=109, 1<=β€<=*s*<=β€<=2Β·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 998320124 820674098",
"output": "No"
},
{
"input": "948253616 -83299062 1031552680",
"output": "Yes"
},
{
"input": "711980199 216568284 928548487",
"output": "Yes"
},
{
"input": "-453961301 271150176 725111473",
"output": "No"
},
{
"input": "0 0 2000000000",
"output": "Yes"
},
{
"input": "0 0 1999999999",
"output": "No"
},
{
"input": "1000000000 1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 -1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 -1000000000 1000000000",
"output": "No"
},
{
"input": "-1 -1 3",
"output": "No"
},
{
"input": "919785634 216774719 129321944",
"output": "No"
},
{
"input": "-467780354 -721273539 1369030008",
"output": "No"
},
{
"input": "-232833910 -880680184 1774549792",
"output": "Yes"
},
{
"input": "45535578 402686155 1011249824",
"output": "No"
},
{
"input": "-203250176 -30379840 233630015",
"output": "No"
},
{
"input": "-814516648 -75830576 890347222",
"output": "No"
},
{
"input": "869184175 -511854751 1381038923",
"output": "No"
},
{
"input": "552884998 -262338193 815223187",
"output": "No"
},
{
"input": "-133874494 857573117 991447611",
"output": "Yes"
},
{
"input": "169406792 786701289 956108082",
"output": "No"
},
{
"input": "30237137 -989203246 1019440385",
"output": "Yes"
},
{
"input": "576608216 -617624133 1194232352",
"output": "No"
},
{
"input": "-662360368 97618995 759979367",
"output": "Yes"
},
{
"input": "-115989290 321714461 437703756",
"output": "No"
},
{
"input": "-1 -3 2",
"output": "No"
},
{
"input": "-2 -2 2",
"output": "No"
},
{
"input": "0 0 1",
"output": "No"
},
{
"input": "0 -1 7",
"output": "Yes"
},
{
"input": "1 2 7",
"output": "Yes"
},
{
"input": "0 5 6",
"output": "No"
},
{
"input": "0 -4 2",
"output": "No"
},
{
"input": "-5 5 2",
"output": "No"
},
{
"input": "-5 -2 7",
"output": "Yes"
},
{
"input": "5 -5 2",
"output": "No"
}
] | 46 | 0 | 3 | 1,570 |
|
439 | Devu, the Dumb Guy | [
"implementation",
"sortings"
] | null | null | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other words he can learn a chapter of a particular subject in *x* hours.
Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.
You can teach him the *n* subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.
Please be careful that answer might not fit in 32 bit data type. | The first line will contain two space separated integers *n*, *x* (1<=β€<=*n*,<=*x*<=β€<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=β€<=*c**i*<=β€<=105). | Output a single integer representing the answer to the problem. | [
"2 3\n4 1\n",
"4 2\n5 1 2 1\n",
"3 3\n1 1 1\n"
] | [
"11\n",
"10\n",
"6\n"
] | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2βΓβ1β=β2 hours. Hence you will need to spend 12β+β2β=β14 hours.
Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3βΓβ1β=β3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2βΓβ4β=β8 hours. Hence you will need to spend 11 hours.
So overall, minimum of both the cases is 11 hours.
Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. | [
{
"input": "2 3\n4 1",
"output": "11"
},
{
"input": "4 2\n5 1 2 1",
"output": "10"
},
{
"input": "3 3\n1 1 1",
"output": "6"
},
{
"input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3",
"output": "65"
},
{
"input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3",
"output": "196"
},
{
"input": "1 1\n9273",
"output": "9273"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 2\n1",
"output": "2"
},
{
"input": "1 2\n2",
"output": "4"
},
{
"input": "2 1\n1 2",
"output": "3"
}
] | 218 | 7,680,000 | 3 | 1,572 |
|
272 | Dima and Friends | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 310 | 0 | 3 | 1,574 |
|
27 | Tournament | [
"bitmasks",
"brute force",
"dfs and similar",
"greedy"
] | B. Tournament | 2 | 256 | The tournament Β«Sleepyhead-2010Β» in the rapid falling asleep has just finished in Berland. *n* best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. *n*Β·(*n*<=-<=1)<=/<=2 games were played during the tournament, and each participant had a match with each other participant.
The rules of the game are quite simple β the participant who falls asleep first wins. The secretary made a record of each game in the form Β«*x**i* *y**i*Β», where *x**i* and *y**i* are the numbers of participants. The first number in each pair is a winner (i.e. *x**i* is a winner and *y**i* is a loser). There is no draws.
Recently researches form the Β«Institute Of SleepΒ» have found that every person is characterized by a value *p**j* β the speed of falling asleep. The person who has lower speed wins. Every person has its own value *p**j*, constant during the life.
It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game. | The first line contains one integer *n* (3<=β€<=*n*<=β€<=50) β the number of participants. The following *n*Β·(*n*<=-<=1)<=/<=2<=-<=1 lines contain the results of the games. Each game is described in a single line by two integers *x**i*,<=*y**i* (1<=β€<=*x**i*,<=*y**i*<=β€<=*n*,<=*x**i*<=β <=*y**i*), where *x**i* ΠΈ *y**i* are the numbers of the opponents in this game. It is known that during the tournament each of the *n* participants played *n*<=-<=1 games, one game with each other participant. | Output two integers *x* and *y* β the missing record. If there are several solutions, output any of them. | [
"4\n4 2\n4 1\n2 3\n2 1\n3 1\n"
] | [
"4 3\n"
] | none | [
{
"input": "3\n3 2\n1 2",
"output": "1 3"
},
{
"input": "4\n2 4\n3 4\n1 2\n1 4\n1 3",
"output": "2 3"
},
{
"input": "5\n3 5\n2 5\n1 5\n1 4\n4 3\n1 3\n2 3\n4 5\n4 2",
"output": "1 2"
},
{
"input": "6\n3 4\n3 5\n5 4\n1 2\n5 6\n2 6\n5 2\n3 6\n3 2\n4 6\n2 4\n1 3\n1 5\n1 4",
"output": "1 6"
},
{
"input": "7\n2 4\n6 1\n6 5\n3 4\n6 3\n2 6\n6 4\n3 7\n7 1\n1 4\n7 4\n7 5\n2 7\n2 3\n5 4\n3 5\n3 1\n5 1\n6 7\n2 1",
"output": "2 5"
},
{
"input": "8\n4 3\n6 8\n1 5\n8 3\n1 4\n1 7\n5 6\n5 3\n5 8\n7 3\n7 8\n2 3\n1 3\n2 8\n1 6\n5 4\n1 2\n2 5\n4 8\n1 8\n2 6\n2 7\n4 7\n2 4\n6 4\n6 7\n6 3",
"output": "5 7"
},
{
"input": "9\n4 5\n9 6\n5 6\n8 7\n5 1\n8 5\n9 5\n4 7\n2 6\n7 6\n3 5\n2 1\n8 2\n3 7\n9 1\n2 5\n2 7\n4 2\n8 9\n8 1\n3 6\n7 1\n8 6\n3 2\n3 1\n9 2\n4 6\n5 7\n1 6\n4 8\n4 1\n4 3\n4 9\n9 3\n9 7",
"output": "8 3"
},
{
"input": "3\n3 2\n1 2",
"output": "1 3"
},
{
"input": "3\n1 3\n2 3",
"output": "1 2"
},
{
"input": "3\n2 1\n3 1",
"output": "2 3"
},
{
"input": "4\n3 1\n4 1\n4 2\n3 2\n3 4",
"output": "1 2"
},
{
"input": "4\n3 4\n1 4\n2 3\n2 1\n2 4",
"output": "1 3"
},
{
"input": "4\n2 3\n1 3\n2 1\n4 1\n4 3",
"output": "2 4"
},
{
"input": "5\n5 2\n3 1\n5 3\n5 1\n3 4\n1 4\n3 2\n1 2\n5 4",
"output": "2 4"
},
{
"input": "5\n2 1\n4 1\n5 1\n4 5\n3 5\n2 3\n3 1\n2 5\n2 4",
"output": "3 4"
},
{
"input": "5\n4 5\n4 3\n5 3\n4 1\n3 1\n3 2\n5 2\n4 2\n5 1",
"output": "1 2"
},
{
"input": "5\n4 5\n1 5\n4 3\n2 5\n2 1\n2 4\n3 5\n2 3\n1 3",
"output": "1 4"
},
{
"input": "5\n2 4\n5 3\n5 4\n2 5\n1 4\n2 3\n1 5\n1 3\n1 2",
"output": "3 4"
},
{
"input": "6\n6 1\n5 6\n4 1\n3 1\n3 4\n4 6\n4 5\n3 2\n4 2\n6 2\n5 1\n3 5\n3 6\n5 2",
"output": "1 2"
},
{
"input": "6\n6 2\n6 4\n4 1\n4 3\n5 6\n5 2\n6 3\n5 1\n5 3\n2 1\n2 3\n6 1\n3 1\n5 4",
"output": "2 4"
},
{
"input": "6\n5 3\n6 5\n3 4\n1 5\n2 3\n6 2\n2 5\n5 4\n6 4\n1 4\n6 3\n6 1\n2 4\n1 3",
"output": "1 2"
},
{
"input": "6\n3 1\n5 4\n2 1\n6 2\n5 2\n3 6\n6 4\n3 2\n3 4\n6 1\n6 5\n5 1\n2 4\n3 5",
"output": "1 4"
},
{
"input": "6\n6 1\n1 3\n3 4\n6 3\n2 4\n6 2\n1 5\n5 3\n5 4\n6 4\n1 2\n1 4\n6 5\n5 2",
"output": "2 3"
}
] | 216 | 0 | 0 | 1,575 |
287 | Pipeline | [
"binary search",
"math"
] | null | null | Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.
A splitter is a construction that consists of one input (it can be connected to a water pipe) and *x* output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe.
Vova has one splitter of each kind: with 2, 3, 4, ..., *k* outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.
Vova needs the pipeline to have exactly *n* pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters. | The first line contains two space-separated integers *n* and *k* (1<=β€<=*n*<=β€<=1018, 2<=β€<=*k*<=β€<=109).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print a single integer β the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1. | [
"4 3\n",
"5 5\n",
"8 4\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | [
{
"input": "4 3",
"output": "2"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "1000000000000000000 1000000000",
"output": "-1"
},
{
"input": "499999998500000001 1000000000",
"output": "999955279"
},
{
"input": "499999998500000000 1000000000",
"output": "999955279"
},
{
"input": "499999999500000000 1000000000",
"output": "999999998"
},
{
"input": "499999999500000001 1000000000",
"output": "999999999"
},
{
"input": "525 34",
"output": "25"
},
{
"input": "223265034477 726990",
"output": "440662"
},
{
"input": "15597035789572051 185473109",
"output": "128849771"
},
{
"input": "499999999500000002 1000000000",
"output": "-1"
},
{
"input": "1 1000000000",
"output": "0"
},
{
"input": "1000000000 2",
"output": "-1"
},
{
"input": "462498979 204468265",
"output": "3"
},
{
"input": "2107921 542531",
"output": "4"
},
{
"input": "131 49",
"output": "3"
},
{
"input": "20171878992939541 200857557",
"output": "200853401"
},
{
"input": "399812655947 894219",
"output": "893030"
},
{
"input": "93 17",
"output": "8"
},
{
"input": "1000000000 999999999",
"output": "2"
},
{
"input": "100000000000000000 1000000000",
"output": "105572810"
}
] | 62 | 307,200 | 0 | 1,577 |
|
330 | Road Construction | [
"constructive algorithms",
"graphs"
] | null | null | A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given *m* pairs of cities β roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible. | The first line consists of two integers *n* and *m* .
Then *m* lines follow, each consisting of two integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*, *a**i*<=β <=*b**i*), which means that it is not possible to construct a road connecting cities *a**i* and *b**i*. Consider the cities are numbered from 1 to *n*.
It is guaranteed that every pair of cities will appear at most once in the input. | You should print an integer *s*: the minimum number of roads that should be constructed, in the first line. Then *s* lines should follow, each consisting of two integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*,<=*a**i*<=β <=*b**i*), which means that a road should be constructed between cities *a**i* and *b**i*.
If there are several solutions, you may print any of them. | [
"4 1\n1 3\n"
] | [
"3\n1 2\n4 2\n2 3\n"
] | This is one possible solution of the example:
These are examples of wrong solutions: | [
{
"input": "4 1\n1 3",
"output": "3\n1 2\n4 2\n2 3"
},
{
"input": "1000 0",
"output": "999\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 87..."
},
{
"input": "484 11\n414 97\n414 224\n444 414\n414 483\n414 399\n414 484\n414 189\n414 246\n414 115\n89 414\n14 414",
"output": "483\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 87..."
},
{
"input": "150 3\n112 30\n61 45\n37 135",
"output": "149\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 87..."
},
{
"input": "34 7\n10 28\n10 19\n10 13\n24 10\n10 29\n20 10\n10 26",
"output": "33\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"
},
{
"input": "1000 48\n816 885\n576 357\n878 659\n610 647\n37 670\n192 184\n393 407\n598 160\n547 995\n177 276\n788 44\n14 184\n604 281\n176 97\n176 293\n10 57\n852 579\n223 669\n313 260\n476 691\n667 22\n851 792\n411 489\n526 66\n233 566\n35 396\n964 815\n672 123\n148 210\n163 339\n379 598\n382 675\n132 955\n221 441\n253 490\n856 532\n135 119\n276 319\n525 835\n996 270\n92 778\n434 369\n351 927\n758 983\n798 267\n272 830\n539 728\n166 26",
"output": "999\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 87..."
},
{
"input": "534 0",
"output": "533\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 87..."
},
{
"input": "226 54\n80 165\n2 53\n191 141\n107 207\n95 196\n61 82\n42 168\n118 94\n205 182\n172 160\n84 224\n113 143\n122 93\n37 209\n176 32\n56 83\n151 81\n70 190\n99 171\n68 204\n212 48\n4 67\n116 7\n206 199\n105 62\n158 51\n178 147\n17 129\n22 47\n72 162\n188 77\n24 111\n184 26\n175 128\n110 89\n139 120\n127 92\n121 39\n217 75\n145 69\n20 161\n30 220\n222 154\n54 46\n21 87\n144 185\n164 115\n73 202\n173 35\n9 132\n74 180\n137 5\n157 117\n31 177",
"output": "225\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 87..."
},
{
"input": "84 3\n39 19\n55 73\n42 43",
"output": "83\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"
},
{
"input": "207 35\n34 116\n184 5\n90 203\n12 195\n138 101\n40 150\n189 109\n115 91\n93 201\n106 18\n51 187\n139 197\n168 130\n182 64\n31 42\n86 107\n158 111\n159 132\n119 191\n53 127\n81 13\n153 112\n38 2\n87 84\n121 82\n120 22\n21 177\n151 202\n23 58\n68 192\n29 46\n105 70\n8 167\n56 54\n149 15",
"output": "206\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 87..."
},
{
"input": "91 37\n50 90\n26 82\n61 1\n50 17\n51 73\n45 9\n39 53\n78 35\n12 45\n43 47\n83 20\n9 59\n18 48\n68 31\n47 33\n10 25\n15 78\n5 3\n73 65\n77 4\n62 31\n73 3\n53 7\n29 58\n52 14\n56 20\n6 87\n71 16\n17 19\n77 86\n1 50\n74 79\n15 54\n55 80\n13 77\n4 69\n24 69",
"output": "90\n2 1\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 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..."
},
{
"input": "226 54\n197 107\n181 146\n218 115\n36 169\n199 196\n116 93\n152 75\n213 164\n156 95\n165 58\n90 42\n141 58\n203 221\n179 204\n186 69\n27 127\n76 189\n40 195\n111 29\n85 189\n45 88\n84 135\n82 186\n185 17\n156 217\n8 123\n179 112\n92 137\n114 89\n10 152\n132 24\n135 36\n61 218\n10 120\n155 102\n222 79\n150 92\n184 34\n102 180\n154 196\n171 9\n217 105\n84 207\n56 189\n152 179\n43 165\n115 209\n208 167\n52 14\n92 47\n197 95\n13 78\n222 138\n75 36",
"output": "225\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 87..."
},
{
"input": "207 35\n154 79\n174 101\n189 86\n137 56\n66 23\n199 69\n18 28\n32 53\n13 179\n182 170\n199 12\n24 158\n105 133\n25 10\n40 162\n64 72\n108 9\n172 125\n43 190\n15 39\n128 150\n102 129\n90 97\n64 196\n70 123\n163 41\n12 126\n127 186\n107 23\n182 51\n29 46\n46 123\n89 35\n59 80\n206 171",
"output": "206\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 87..."
},
{
"input": "84 0",
"output": "83\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"
},
{
"input": "226 54\n5 29\n130 29\n55 29\n19 29\n29 92\n29 38\n185 29\n29 150\n29 202\n29 25\n29 66\n184 29\n29 189\n177 29\n50 29\n87 29\n138 29\n29 48\n151 29\n125 29\n16 29\n42 29\n29 157\n90 29\n21 29\n29 45\n29 80\n29 67\n29 26\n29 173\n74 29\n29 193\n29 40\n172 29\n29 85\n29 102\n88 29\n29 182\n116 29\n180 29\n161 29\n10 29\n171 29\n144 29\n29 218\n190 29\n213 29\n29 71\n29 191\n29 160\n29 137\n29 58\n29 135\n127 29",
"output": "225\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 87..."
},
{
"input": "207 35\n25 61\n188 61\n170 61\n113 61\n35 61\n61 177\n77 61\n61 39\n61 141\n116 61\n61 163\n30 61\n192 61\n19 61\n61 162\n61 133\n185 61\n8 61\n118 61\n61 115\n7 61\n61 105\n107 61\n61 11\n161 61\n61 149\n136 61\n82 61\n20 61\n151 61\n156 61\n12 61\n87 61\n61 205\n61 108",
"output": "206\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 87..."
},
{
"input": "34 7\n11 32\n33 29\n17 16\n15 5\n13 25\n8 19\n20 4",
"output": "33\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"
},
{
"input": "43 21\n38 19\n43 8\n40 31\n3 14\n24 21\n12 17\n1 9\n5 27\n25 37\n11 6\n13 26\n16 22\n10 32\n36 7\n30 29\n42 35\n20 33\n4 23\n18 15\n41 34\n2 28",
"output": "42\n39 1\n39 2\n39 3\n39 4\n39 5\n39 6\n39 7\n39 8\n39 9\n39 10\n39 11\n39 12\n39 13\n39 14\n39 15\n39 16\n39 17\n39 18\n39 19\n39 20\n39 21\n39 22\n39 23\n39 24\n39 25\n39 26\n39 27\n39 28\n39 29\n39 30\n39 31\n39 32\n39 33\n39 34\n39 35\n39 36\n39 37\n39 38\n39 40\n39 41\n39 42\n39 43"
},
{
"input": "34 7\n22 4\n5 25\n15 7\n5 9\n27 7\n34 21\n3 13",
"output": "33\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"
},
{
"input": "50 7\n19 37\n30 32\n43 20\n48 14\n30 29\n18 36\n9 46",
"output": "49\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"
},
{
"input": "41 12\n41 12\n29 13\n3 37\n2 20\n4 24\n27 6\n39 20\n28 41\n30 1\n35 9\n5 39\n12 31",
"output": "40\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\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 20\n7 21\n7 22\n7 23\n7 24\n7 25\n7 26\n7 27\n7 28\n7 29\n7 30\n7 31\n7 32\n7 33\n7 34\n7 35\n7 36\n7 37\n7 38\n7 39\n7 40\n7 41"
},
{
"input": "26 2\n22 1\n14 10",
"output": "25\n2 1\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"
},
{
"input": "7 3\n4 7\n4 6\n6 5",
"output": "6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7"
},
{
"input": "484 11\n459 166\n12 217\n14 231\n477 111\n365 225\n62 412\n221 223\n258 184\n266 404\n425 236\n83 269",
"output": "483\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 87..."
},
{
"input": "50 24\n18 36\n11 18\n22 18\n18 47\n18 10\n45 18\n18 29\n13 18\n8 18\n18 30\n26 18\n18 6\n5 18\n18 7\n46 18\n50 18\n18 3\n18 32\n4 18\n18 24\n18 19\n23 18\n35 18\n31 18",
"output": "49\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"
},
{
"input": "7 3\n3 4\n7 3\n3 2",
"output": "6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "2 0",
"output": "1\n1 2"
},
{
"input": "4 1\n1 2",
"output": "3\n3 1\n3 2\n3 4"
},
{
"input": "3 1\n1 2",
"output": "2\n3 1\n3 2"
},
{
"input": "5 1\n1 5",
"output": "4\n2 1\n2 3\n2 4\n2 5"
}
] | 342 | 3,072,000 | 3 | 1,578 |
|
545 | Woodcutters | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=β€<=*x**i*,<=*h**i*<=β€<=109) β the coordinate and the height of the *Ρ*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. | Print a single number β the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left β now it occupies segment [β-β1;1] - fell the 2-nd tree to the right β now it occupies segment [2;3] - leave the 3-rd tree β it occupies point 5 - leave the 4-th tree β it occupies point 10 - fell the 5-th tree to the right β now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4",
"output": "10"
},
{
"input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1",
"output": "2"
},
{
"input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8",
"output": "5"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1",
"output": "9"
},
{
"input": "3\n1 1\n1000 1000\n1000000000 1000000000",
"output": "3"
},
{
"input": "2\n1 999999999\n1000000000 1000000000",
"output": "2"
},
{
"input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000",
"output": "2"
},
{
"input": "2\n100000000 1000000000\n1000000000 1000000000",
"output": "2"
}
] | 343 | 8,089,600 | 0 | 1,580 |
|
295 | Greg and Array | [
"data structures",
"implementation"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=β€<=*l**i*<=β€<=*r**i*<=β€<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=β€<=*x**i*<=β€<=*y**i*<=β€<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array.
Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg. | The first line contains integers *n*, *m*, *k* (1<=β€<=*n*,<=*m*,<=*k*<=β€<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=105) β the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=β€<=*l**i*<=β€<=*r**i*<=β€<=*n*), (0<=β€<=*d**i*<=β€<=105).
Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=β€<=*x**i*<=β€<=*y**i*<=β€<=*m*).
The numbers in the lines are separated by single spaces. | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1",
"output": "0"
}
] | 920 | 22,016,000 | 3 | 1,581 |
|
411 | Kicker | [
"implementation"
] | null | null | Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the half-backs and forwards (plays attack).
Two teams of company Q decided to battle each other. Let's enumerate players from both teams by integers from 1 to 4. The first and second player play in the first team, the third and the fourth one play in the second team. For each of the four players we know their game skills in defence and attack. The defence skill of the *i*-th player is *a**i*, the attack skill is *b**i*.
Before the game, the teams determine how they will play. First the players of the first team decide who will play in the attack, and who will play in the defence. Then the second team players do the same, based on the choice of their opponents.
We will define a team's defence as the defence skill of player of the team who plays defence. Similarly, a team's attack is the attack skill of the player of the team who plays attack. We assume that one team is guaranteed to beat the other one, if its defence is strictly greater than the opponent's attack and its attack is strictly greater than the opponent's defence.
The teams of company Q know each other's strengths and therefore arrange their teams optimally. Identify the team that is guaranteed to win (if both teams act optimally) or tell that there is no such team. | The input contain the players' description in four lines. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=100) β the defence and the attack skill of the *i*-th player, correspondingly. | If the first team can win, print phrase "Team 1" (without the quotes), if the second team can win, print phrase "Team 2" (without the quotes). If no of the teams can definitely win, print "Draw" (without the quotes). | [
"1 100\n100 1\n99 99\n99 99\n",
"1 1\n2 2\n3 3\n2 2\n",
"3 3\n2 2\n1 1\n2 2\n"
] | [
"Team 1\n",
"Team 2\n",
"Draw\n"
] | Let consider the first test sample. The first team can definitely win if it will choose the following arrangement: the first player plays attack, the second player plays defence.
Consider the second sample. The order of the choosing roles for players makes sense in this sample. As the members of the first team choose first, the members of the second team can beat them (because they know the exact defence value and attack value of the first team). | [
{
"input": "1 100\n100 1\n99 99\n99 99",
"output": "Team 1"
},
{
"input": "1 1\n2 2\n3 3\n2 2",
"output": "Team 2"
},
{
"input": "3 3\n2 2\n1 1\n2 2",
"output": "Draw"
},
{
"input": "80 79\n79 30\n80 81\n40 80",
"output": "Team 2"
},
{
"input": "10 10\n4 9\n8 9\n7 6",
"output": "Team 1"
},
{
"input": "10 2\n9 3\n3 1\n9 4",
"output": "Draw"
},
{
"input": "6 3\n6 10\n2 5\n4 4",
"output": "Team 1"
},
{
"input": "8 7\n1 5\n7 4\n8 8",
"output": "Draw"
},
{
"input": "2 7\n8 4\n4 6\n10 8",
"output": "Draw"
},
{
"input": "8 3\n4 9\n6 1\n5 6",
"output": "Team 1"
},
{
"input": "10 5\n3 1\n1 9\n1 2",
"output": "Draw"
},
{
"input": "6 5\n10 6\n8 1\n3 2",
"output": "Draw"
},
{
"input": "6 2\n7 5\n5 4\n8 6",
"output": "Draw"
},
{
"input": "1 10\n1 10\n1 1\n7 8",
"output": "Draw"
},
{
"input": "16 7\n9 3\n11 2\n11 4",
"output": "Draw"
},
{
"input": "20 17\n14 10\n10 7\n19 18",
"output": "Draw"
},
{
"input": "12 7\n3 17\n4 15\n2 8",
"output": "Draw"
},
{
"input": "8 14\n8 12\n7 20\n14 6",
"output": "Draw"
},
{
"input": "4 4\n4 15\n2 4\n10 12",
"output": "Draw"
},
{
"input": "4 10\n9 9\n9 12\n13 10",
"output": "Team 2"
},
{
"input": "20 20\n18 8\n15 5\n17 20",
"output": "Draw"
},
{
"input": "12 10\n7 3\n10 5\n1 14",
"output": "Draw"
},
{
"input": "8 16\n12 10\n13 18\n8 4",
"output": "Draw"
},
{
"input": "16 15\n19 1\n16 16\n20 9",
"output": "Draw"
},
{
"input": "12 29\n44 8\n18 27\n43 19",
"output": "Draw"
},
{
"input": "28 46\n50 27\n23 50\n21 45",
"output": "Draw"
},
{
"input": "40 6\n9 1\n16 18\n4 23",
"output": "Draw"
},
{
"input": "4 16\n6 28\n12 32\n28 3",
"output": "Draw"
},
{
"input": "16 22\n11 3\n17 5\n12 27",
"output": "Draw"
},
{
"input": "32 32\n10 28\n14 23\n39 5",
"output": "Draw"
},
{
"input": "48 41\n15 47\n11 38\n19 31",
"output": "Team 1"
},
{
"input": "8 9\n11 17\n11 6\n5 9",
"output": "Draw"
},
{
"input": "24 19\n18 44\n8 29\n30 39",
"output": "Draw"
},
{
"input": "22 4\n29 38\n31 43\n47 21",
"output": "Team 2"
},
{
"input": "51 54\n95 28\n42 28\n17 48",
"output": "Team 1"
},
{
"input": "11 64\n92 47\n88 93\n41 26",
"output": "Draw"
},
{
"input": "27 74\n97 22\n87 65\n24 52",
"output": "Draw"
},
{
"input": "43 32\n49 48\n42 33\n60 30",
"output": "Draw"
},
{
"input": "55 50\n54 23\n85 6\n32 60",
"output": "Team 2"
},
{
"input": "19 56\n59 46\n40 70\n67 34",
"output": "Team 2"
},
{
"input": "31 67\n8 13\n86 91\n43 12",
"output": "Team 2"
},
{
"input": "47 77\n13 88\n33 63\n75 38",
"output": "Draw"
},
{
"input": "59 35\n10 14\n88 23\n58 16",
"output": "Draw"
},
{
"input": "63 4\n18 60\n58 76\n44 93",
"output": "Draw"
},
{
"input": "14 47\n47 42\n21 39\n40 7",
"output": "Team 1"
},
{
"input": "67 90\n63 36\n79 56\n25 56",
"output": "Team 1"
},
{
"input": "64 73\n59 46\n8 19\n57 18",
"output": "Team 1"
},
{
"input": "23 80\n62 56\n56 31\n9 50",
"output": "Team 1"
},
{
"input": "86 95\n86 38\n59 66\n44 78",
"output": "Team 1"
},
{
"input": "10 3\n2 5\n1 10\n2 10",
"output": "Draw"
},
{
"input": "62 11\n79 14\n46 36\n91 52",
"output": "Draw"
},
{
"input": "8 4\n9 10\n7 3\n6 5",
"output": "Team 1"
},
{
"input": "21 12\n29 28\n16 4\n10 1",
"output": "Team 1"
},
{
"input": "91 71\n87 45\n28 73\n9 48",
"output": "Team 1"
},
{
"input": "4 1\n4 3\n6 4\n2 8",
"output": "Team 2"
},
{
"input": "11 7\n12 8\n15 14\n14 14",
"output": "Team 2"
},
{
"input": "12 7\n3 15\n20 18\n20 8",
"output": "Team 2"
},
{
"input": "4 7\n24 11\n17 30\n21 4",
"output": "Team 2"
},
{
"input": "21 22\n21 16\n32 14\n39 35",
"output": "Team 2"
},
{
"input": "16 48\n16 49\n10 68\n60 64",
"output": "Team 2"
},
{
"input": "46 33\n12 3\n11 67\n98 77",
"output": "Team 2"
},
{
"input": "19 9\n47 28\n83 41\n76 14",
"output": "Draw"
},
{
"input": "36 68\n65 82\n37 6\n21 60",
"output": "Team 1"
},
{
"input": "70 98\n62 5\n30 50\n66 96",
"output": "Draw"
},
{
"input": "45 69\n91 96\n72 67\n24 30",
"output": "Draw"
},
{
"input": "34 38\n91 17\n2 12\n83 90",
"output": "Draw"
},
{
"input": "30 31\n98 15\n40 62\n10 22",
"output": "Draw"
}
] | 62 | 0 | 0 | 1,585 |
|
729 | Spotlights | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=Γ<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) β left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
A position is good if two conditions hold:
- there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ. | The first line contains two positive integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=1000) β the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each β the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan. | Print one integer β the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example. | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 1\n1\n0\n0",
"output": "2"
},
{
"input": "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0",
"output": "25"
},
{
"input": "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 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\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\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\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\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "5 7\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1\n0 1 1 1 1 1 1\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1",
"output": "26"
},
{
"input": "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "121"
},
{
"input": "1 2\n0 1",
"output": "1"
},
{
"input": "1 2\n1 0",
"output": "1"
},
{
"input": "1 2\n1 1",
"output": "0"
},
{
"input": "2 1\n1\n0",
"output": "1"
},
{
"input": "2 1\n0\n1",
"output": "1"
},
{
"input": "2 1\n1\n1",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "4 4\n1 1 1 1\n1 0 0 1\n1 0 0 1\n1 1 1 1",
"output": "16"
}
] | 233 | 11,366,400 | 3 | 1,594 |
|
0 | none | [
"none"
] | null | null | You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. | The first line contains two integers, *n* and *p* (1<=β€<=*n*<=β€<=100<=000, 1<=β€<=*p*<=β€<=109) β the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=100<=000) β the power of the device and the amount of power stored in the device in the beginning. | If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
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 . | [
"2 1\n2 2\n2 1000\n",
"1 100\n1 1\n",
"3 5\n4 3\n5 2\n6 1\n"
] | [
"2.0000000000",
"-1\n",
"0.5000000000"
] | In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2β/β5 of a second, then switch to charge the second device for a 1β/β10 of a second. | [
{
"input": "2 1\n2 2\n2 1000",
"output": "2.0000000000"
},
{
"input": "1 100\n1 1",
"output": "-1"
},
{
"input": "3 5\n4 3\n5 2\n6 1",
"output": "0.5000000000"
},
{
"input": "1 1\n1 87",
"output": "-1"
},
{
"input": "1 1\n100 77",
"output": "0.7777777778"
},
{
"input": "5 10\n3 81\n3 49\n1 20\n1 12\n1 30",
"output": "-1"
},
{
"input": "5 10\n4 3\n1 54\n2 57\n2 31\n1 99",
"output": "-1"
},
{
"input": "5 10\n2 81\n3 31\n4 49\n1 35\n1 67",
"output": "263.0000000000"
},
{
"input": "10 1\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92",
"output": "102.2222222222"
},
{
"input": "10 1\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16",
"output": "17.7777777778"
},
{
"input": "10 1\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40",
"output": "44.4444444444"
},
{
"input": "2 1\n1 10\n1 10",
"output": "20.0000000000"
},
{
"input": "20 16807\n75250 50074\n43659 8931\n11273 27545\n50879 77924\n37710 64441\n38166 84493\n43043 7988\n22504 82328\n31730 78841\n42613 44304\n33170 17710\n97158 29561\n70934 93100\n80279 51817\n95336 99098\n7827 13513\n29268 23811\n77634 80980\n79150 36580\n58822 11968",
"output": "0.2244225704"
}
] | 46 | 4,812,800 | 0 | 1,595 |
|
846 | Math Show | [
"brute force",
"greedy"
] | null | null | Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all *k* of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is *k*<=+<=1.
Polycarp has *M* minutes of time. What is the maximum number of points he can earn? | The first line contains three integer numbers *n*, *k* and *M* (1<=β€<=*n*<=β€<=45, 1<=β€<=*k*<=β€<=45, 0<=β€<=*M*<=β€<=2Β·109).
The second line contains *k* integer numbers, values *t**j* (1<=β€<=*t**j*<=β€<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task. | Print the maximum amount of points Polycarp can earn in *M* minutes. | [
"3 4 11\n1 2 3 4\n",
"5 5 10\n1 2 4 8 16\n"
] | [
"6\n",
"7\n"
] | In the first example Polycarp can complete the first task and spend 1β+β2β+β3β+β4β=β10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5Β·1β=β5 minutes. Also he can solve the second subtasks of two tasks and spend 2Β·2β=β4 minutes. Thus, he earns 5β+β2β=β7 points in total. | [
{
"input": "3 4 11\n1 2 3 4",
"output": "6"
},
{
"input": "5 5 10\n1 2 4 8 16",
"output": "7"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "2"
},
{
"input": "2 1 0\n2",
"output": "0"
},
{
"input": "2 2 2\n2 3",
"output": "1"
},
{
"input": "4 2 15\n1 4",
"output": "9"
},
{
"input": "24 42 126319796\n318996 157487 174813 189765 259136 406743 138997 377982 244813 16862 95438 346702 454882 274633 67361 387756 61951 448901 427272 288847 316578 416035 56608 211390 187241 191538 299856 294995 442139 95784 410894 439744 455044 301002 196932 352004 343622 73438 325186 295727 21130 32856",
"output": "677"
},
{
"input": "5 3 10\n1 3 6",
"output": "6"
},
{
"input": "5 3 50\n1 3 6",
"output": "20"
},
{
"input": "5 3 2000000000\n1 3 6",
"output": "20"
},
{
"input": "5 3 49\n1 3 6",
"output": "18"
},
{
"input": "3 4 16\n1 2 3 4",
"output": "9"
},
{
"input": "11 2 20\n1 9",
"output": "13"
},
{
"input": "11 3 38\n1 9 9",
"output": "15"
},
{
"input": "5 3 11\n1 1 2",
"output": "11"
},
{
"input": "5 4 36\n1 3 7 7",
"output": "13"
},
{
"input": "1 13 878179\n103865 43598 180009 528483 409585 449955 368163 381135 713512 645876 241515 20336 572091",
"output": "5"
},
{
"input": "1 9 262522\n500878 36121 420012 341288 139726 362770 462113 261122 394426",
"output": "2"
},
{
"input": "45 32 252252766\n282963 74899 446159 159106 469932 288063 297289 501442 241341 240108 470371 316076 159136 72720 37365 108455 82789 529789 303825 392553 153053 389577 327929 277446 505280 494678 159006 505007 328366 460640 18354 313300",
"output": "1094"
},
{
"input": "44 41 93891122\n447 314862 48587 198466 73450 166523 247421 50078 14115 229926 11070 53089 73041 156924 200782 53225 290967 219349 119034 88726 255048 59778 287298 152539 55104 170525 135722 111341 279873 168400 267489 157697 188015 94306 231121 304553 27684 46144 127122 166022 150941",
"output": "1084"
},
{
"input": "12 45 2290987\n50912 189025 5162 252398 298767 154151 164139 185891 121047 227693 93549 284244 312843 313833 285436 131672 135248 324541 194905 205729 241315 32044 131902 305884 263 27717 173077 81428 285684 66470 220938 282471 234921 316283 30485 244283 170631 224579 72899 87066 6727 161661 40556 89162 314616",
"output": "95"
},
{
"input": "42 9 4354122\n47443 52983 104606 84278 5720 55971 100555 90845 91972",
"output": "124"
},
{
"input": "45 28 33631968\n5905 17124 64898 40912 75855 53868 27056 18284 63975 51975 27182 94373 52477 260 87551 50223 73798 77430 17510 15226 6269 43301 39592 27043 15546 60047 83400 63983",
"output": "979"
},
{
"input": "18 3 36895\n877 2054 4051",
"output": "28"
},
{
"input": "13 30 357\n427 117 52 140 162 58 5 149 438 327 103 357 202 1 148 238 442 200 438 97 414 301 224 166 254 322 378 422 90 312",
"output": "31"
},
{
"input": "44 11 136\n77 38 12 71 81 15 66 47 29 22 71",
"output": "11"
},
{
"input": "32 6 635\n3 4 2 1 7 7",
"output": "195"
},
{
"input": "30 19 420\n2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 1 2",
"output": "309"
},
{
"input": "37 40 116\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "118"
},
{
"input": "7 37 133\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "136"
},
{
"input": "40 1 8\n3",
"output": "4"
},
{
"input": "1 28 1\n3 3 2 2 1 1 3 1 1 2 2 1 1 3 3 1 1 1 1 1 3 1 3 3 3 2 2 3",
"output": "1"
},
{
"input": "12 1 710092\n145588",
"output": "8"
},
{
"input": "1 7 47793\n72277 45271 85507 39251 45440 101022 105165",
"output": "1"
},
{
"input": "1 1 0\n4",
"output": "0"
},
{
"input": "1 2 3\n2 2",
"output": "1"
},
{
"input": "1 1 0\n5",
"output": "0"
},
{
"input": "1 1 3\n5",
"output": "0"
},
{
"input": "1 3 0\n6 3 4",
"output": "0"
},
{
"input": "1 2 0\n1 2",
"output": "0"
},
{
"input": "1 1 3\n5",
"output": "0"
},
{
"input": "1 1 0\n5",
"output": "0"
},
{
"input": "2 2 3\n7 2",
"output": "1"
},
{
"input": "2 4 5\n1 2 8 6",
"output": "3"
},
{
"input": "2 1 0\n3",
"output": "0"
},
{
"input": "1 3 3\n16 4 5",
"output": "0"
},
{
"input": "2 1 0\n1",
"output": "0"
},
{
"input": "3 2 2\n6 1",
"output": "2"
},
{
"input": "3 2 1\n1 1",
"output": "1"
},
{
"input": "1 3 19\n12 15 6",
"output": "2"
},
{
"input": "2 2 8\n12 1",
"output": "2"
},
{
"input": "1 6 14\n15 2 6 13 14 4",
"output": "3"
},
{
"input": "4 1 0\n1",
"output": "0"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "2 2 5\n5 6",
"output": "1"
},
{
"input": "1 3 8\n5 4 4",
"output": "2"
},
{
"input": "1 5 44\n2 19 18 6 8",
"output": "4"
},
{
"input": "1 1 0\n4",
"output": "0"
},
{
"input": "3 2 7\n5 1",
"output": "4"
},
{
"input": "4 2 9\n8 6",
"output": "1"
},
{
"input": "4 3 3\n6 12 7",
"output": "0"
},
{
"input": "4 1 2\n1",
"output": "4"
},
{
"input": "2 4 15\n8 3 7 8",
"output": "3"
},
{
"input": "6 1 2\n4",
"output": "0"
},
{
"input": "2 1 1\n1",
"output": "2"
},
{
"input": "1 1 2\n3",
"output": "0"
},
{
"input": "2 2 2\n1 4",
"output": "2"
},
{
"input": "6 2 78\n12 10",
"output": "10"
},
{
"input": "1 3 10\n17 22 15",
"output": "0"
},
{
"input": "6 3 13\n1 2 3",
"output": "10"
},
{
"input": "21 3 26\n1 2 3",
"output": "24"
},
{
"input": "3 7 20012\n1 1 1 1 1 1 10000",
"output": "20"
},
{
"input": "5 4 40\n4 2 3 3",
"output": "17"
},
{
"input": "4 5 40\n4 1 3 2 4",
"output": "18"
},
{
"input": "3 5 22\n1 1 4 1 1",
"output": "16"
},
{
"input": "5 2 17\n3 4",
"output": "7"
},
{
"input": "5 4 32\n4 2 1 1",
"output": "21"
},
{
"input": "5 5 34\n4 1 1 2 4",
"output": "20"
},
{
"input": "3 3 15\n1 2 1",
"output": "12"
},
{
"input": "3 2 11\n1 2",
"output": "9"
},
{
"input": "5 4 11\n2 1 3 4",
"output": "8"
},
{
"input": "45 45 2000000000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2070"
}
] | 46 | 0 | 0 | 1,606 |
|
4 | Registration System | [
"data structures",
"hashing",
"implementation"
] | C. Registration system | 5 | 64 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database. | The first line contains number *n* (1<=β€<=*n*<=β€<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | [
"4\nabacaba\nacaba\nabacaba\nacab\n",
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n"
] | [
"OK\nOK\nabacaba1\nOK\n",
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n"
] | none | [
{
"input": "4\nabacaba\nacaba\nabacaba\nacab",
"output": "OK\nOK\nabacaba1\nOK"
},
{
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1"
},
{
"input": "1\nn",
"output": "OK"
},
{
"input": "2\nu\nu",
"output": "OK\nu1"
},
{
"input": "3\nb\nb\nb",
"output": "OK\nb1\nb2"
},
{
"input": "2\nc\ncn",
"output": "OK\nOK"
},
{
"input": "3\nvhn\nvhn\nh",
"output": "OK\nvhn1\nOK"
},
{
"input": "4\nd\nhd\nd\nh",
"output": "OK\nOK\nd1\nOK"
},
{
"input": "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp",
"output": "OK\nbhnqaptmp1\nbhnqaptmp2\nbhnqaptmp3\nbhnqaptmp4\nbhnqaptmp5\nbhnqaptmp6\nbhnqaptmp7\nbhnqaptmp8\nbhnqaptmp9"
},
{
"input": "10\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh",
"output": "OK\nfpqhfouqdldravpjttarh1\nfpqhfouqdldravpjttarh2\nfpqhfouqdldravpjttarh3\nfpqhfouqdldravpjttarh4\nfpqhfouqdldravpjttarh5\nOK\nfpqhfouqdldravpjttarh6\njmvlplnrmba1\nfpqhfouqdldravpjttarh7"
},
{
"input": "10\niwexcrupuubwzbooj\niwexcrupuubwzbooj\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\niwexcrupuubwzbooj\niwexcrupuubwzbooj\niwexcrupuubwzbooj",
"output": "OK\niwexcrupuubwzbooj1\nOK\njzsyjnxttliyfpunxyhsouhunenzxedi1\njzsyjnxttliyfpunxyhsouhunenzxedi2\njzsyjnxttliyfpunxyhsouhunenzxedi3\njzsyjnxttliyfpunxyhsouhunenzxedi4\niwexcrupuubwzbooj2\niwexcrupuubwzbooj3\niwexcrupuubwzbooj4"
},
{
"input": "10\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "OK\nzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nOK\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4\nzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzz4"
},
{
"input": "20\nzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "OK\nOK\nOK\nzzzzzzzzzzzzz1\nzzzzzzzzz1\nzzzzzzzzz2\nzzzzzzzzzzzzz2\nzzzzzzzzzzzzz3\nOK\nzzzzzzzzzzzzz4\nzzzzzzzzzzzzz5\nzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzz6\nzzzzzzzzzzzzz7\nz1\nzzzzzzzzz3\nzzzzzzzzz4\nzzzzzzzzzzzzz8\nzzzzzzzzzzzzzzzzzzzzzzzz3"
}
] | 92 | 0 | 0 | 1,607 |
620 | New Year Tree | [
"bitmasks",
"data structures",
"trees"
] | null | null | The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.
The New Year tree is an undirected tree with *n* vertices and root in the vertex 1.
You should process the queries of the two types:
1. Change the colours of all vertices in the subtree of the vertex *v* to the colour *c*. 1. Find the number of different colours in the subtree of the vertex *v*. | The first line contains two integers *n*,<=*m* (1<=β€<=*n*,<=*m*<=β€<=4Β·105) β the number of vertices in the tree and the number of the queries.
The second line contains *n* integers *c**i* (1<=β€<=*c**i*<=β€<=60) β the colour of the *i*-th vertex.
Each of the next *n*<=-<=1 lines contains two integers *x**j*,<=*y**j* (1<=β€<=*x**j*,<=*y**j*<=β€<=*n*) β the vertices of the *j*-th edge. It is guaranteed that you are given correct undirected tree.
The last *m* lines contains the description of the queries. Each description starts with the integer *t**k* (1<=β€<=*t**k*<=β€<=2) β the type of the *k*-th query. For the queries of the first type then follows two integers *v**k*,<=*c**k* (1<=β€<=*v**k*<=β€<=*n*,<=1<=β€<=*c**k*<=β€<=60) β the number of the vertex whose subtree will be recoloured with the colour *c**k*. For the queries of the second type then follows integer *v**k* (1<=β€<=*v**k*<=β€<=*n*) β the number of the vertex for which subtree you should find the number of different colours. | For each query of the second type print the integer *a* β the number of different colours in the subtree of the vertex given in the query.
Each of the numbers should be printed on a separate line in order of query appearing in the input. | [
"7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3\n",
"23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n1 12 1\n1 13 1\n1 14 1\n1 15 1\n1 16 1\n1 17 1\n1 18 1\n1 19 1\n1 20 1\n1 21 1\n1 22 1\n1 23 1\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n"
] | [
"2\n3\n4\n5\n1\n2\n",
"6\n1\n3\n3\n2\n1\n2\n3\n5\n5\n1\n2\n2\n1\n1\n1\n2\n3\n"
] | none | [
{
"input": "7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3",
"output": "2\n3\n4\n5\n1\n2"
},
{
"input": "23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4\n1 12 1\n1 13 1\n1 14 1\n1 15 1\n1 16 1\n1 17 1\n1 18 1\n1 19 1\n1 20 1\n1 21 1\n1 22 1\n1 23 1\n2 1\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 4",
"output": "6\n1\n3\n3\n2\n1\n2\n3\n5\n5\n1\n2\n2\n1\n1\n1\n2\n3"
},
{
"input": "1 1\n14\n2 1",
"output": "1"
},
{
"input": "1 1\n36\n2 1",
"output": "1"
},
{
"input": "1 1\n3\n2 1",
"output": "1"
},
{
"input": "1 1\n43\n2 1",
"output": "1"
},
{
"input": "1 1\n41\n2 1",
"output": "1"
},
{
"input": "10 10\n59 59 59 59 59 59 59 59 59 59\n6 8\n6 10\n2 6\n2 5\n7 2\n10 1\n4 2\n7 3\n9 1\n1 8 59\n2 8\n1 3 59\n1 4 59\n1 8 59\n1 2 59\n1 5 59\n1 10 59\n2 2\n2 5",
"output": "1\n1\n1"
},
{
"input": "10 10\n8 8 14 32 14 8 32 8 14 32\n4 5\n4 1\n4 8\n4 9\n7 4\n2 5\n3 5\n4 6\n10 4\n2 2\n1 9 8\n1 1 40\n1 7 32\n1 4 8\n2 8\n1 1 8\n2 2\n2 8\n2 4",
"output": "1\n1\n1\n1\n1"
},
{
"input": "10 10\n39 50 50 7 39 7 46 7 39 7\n10 7\n7 3\n3 5\n3 4\n6 4\n1 4\n1 8\n8 2\n2 9\n2 8\n1 6 50\n2 4\n2 6\n1 7 39\n1 3 39\n2 9\n1 1 15\n2 7\n1 10 7",
"output": "3\n4\n1\n1\n1"
},
{
"input": "10 10\n23 25 23 42 23 53 49 40 28 44\n1 7\n1 2\n2 4\n4 10\n8 10\n6 8\n3 8\n5 3\n9 5\n2 10\n1 6 52\n1 8 43\n2 3\n1 4 39\n1 8 44\n1 9 39\n2 1\n2 4\n1 6 36",
"output": "5\n1\n5\n2"
},
{
"input": "10 10\n16 25 25 27 39 29 29 58 50 30\n8 2\n2 10\n4 2\n2 1\n6 2\n2 3\n9 2\n5 2\n2 7\n2 4\n1 3 31\n2 5\n1 7 27\n1 4 56\n1 4 52\n1 5 25\n1 6 32\n1 6 22\n1 7 42",
"output": "1\n1"
},
{
"input": "10 10\n60 46 56 7 4 27 43 28 4 9\n1 5\n5 8\n10 8\n10 6\n7 6\n2 10\n4 2\n9 4\n9 3\n2 3\n1 9 57\n2 2\n1 6 50\n1 5 34\n1 8 45\n1 9 39\n2 2\n1 10 1\n2 4",
"output": "1\n3\n2\n1"
},
{
"input": "10 10\n15 39 52 24 36 30 46 21 40 24\n5 9\n5 3\n5 10\n1 3\n9 4\n9 8\n9 7\n7 2\n3 6\n1 4 47\n1 7 25\n1 10 42\n2 10\n1 2 18\n1 1 60\n1 7 56\n2 7\n2 9\n2 10",
"output": "1\n1\n2\n1"
},
{
"input": "10 10\n39 28 21 20 11 11 40 30 42 14\n7 1\n10 1\n6 1\n1 9\n5 1\n8 1\n1 3\n1 4\n2 10\n1 7 55\n2 3\n1 8 18\n1 10 48\n2 7\n1 6 26\n2 2\n1 1 4\n2 9\n1 5 31",
"output": "1\n1\n1\n1"
}
] | 0 | 0 | -1 | 1,608 |
|
299 | Ksusha and Array | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=β€<=*n*<=β€<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β the array elements. | Print a single integer β the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
},
{
"input": "2\n500000000 1000000000",
"output": "500000000"
},
{
"input": "2\n4 6",
"output": "-1"
},
{
"input": "5\n10 8 6 4 2",
"output": "2"
},
{
"input": "2\n6 10",
"output": "-1"
},
{
"input": "1\n1000000000",
"output": "1000000000"
},
{
"input": "2\n6 8",
"output": "-1"
},
{
"input": "5\n2 2 2 2 1000000000",
"output": "2"
},
{
"input": "2\n6 4",
"output": "-1"
}
] | 372 | 8,192,000 | 3 | 1,612 |
|
468 | Hack it! | [
"binary search",
"constructive algorithms",
"math"
] | null | null | Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: | The first line contains a single integer *a* (1<=β€<=*a*<=β€<=1018). | Print two integers: *l*,<=*r* (1<=β€<=*l*<=β€<=*r*<=<<=10200) β the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. | [
"46\n",
"126444381000032\n"
] | [
"1 10\n",
"2333333 2333333333333\n"
] | none | [
{
"input": "46",
"output": "1 10"
},
{
"input": "126444381000032",
"output": "2333333 2333333333333"
},
{
"input": "69645082595",
"output": "613752823618441225798858488535 713259406474207764329704856394"
},
{
"input": "70602205995",
"output": "11 249221334020432074498656960922"
},
{
"input": "33898130785",
"output": "9 558855506346909386939077840182"
},
{
"input": "58929554039",
"output": "22 855783114773435710171914224422"
},
{
"input": "81696185182",
"output": "499118531974994927425925323518 956291458400902769638235161661"
},
{
"input": "1",
"output": "149268802942315027273202513064 277551734280589260570057105889"
},
{
"input": "2",
"output": "119692200833686078608961312319 629363568954685219494592939495"
},
{
"input": "3",
"output": "2 302254410562920936884653943506"
},
{
"input": "4",
"output": "284378053387469023431537894255 317250990020830090421009164911"
},
{
"input": "5",
"output": "2 62668056583245293799710157951"
},
{
"input": "6",
"output": "3 93810188780011787541394067841"
},
{
"input": "7",
"output": "2 834286447477504059026206246185"
},
{
"input": "8",
"output": "3 257583347960907690857477857197"
},
{
"input": "10",
"output": "3 163048811987317819669274448265"
},
{
"input": "11",
"output": "3 919618203693907154039906935669"
},
{
"input": "12",
"output": "448221703341269567451520778454 698029790336105644790102859494"
},
{
"input": "43",
"output": "9 172412961300207091437973214327"
},
{
"input": "36",
"output": "8 619355518777647869838990701242"
},
{
"input": "65",
"output": "6 709024330418134127413755925068"
},
{
"input": "43",
"output": "7 669540448846929747909766131221"
},
{
"input": "23",
"output": "2 104579054315773428039906118259"
},
{
"input": "100",
"output": "15 324437778467489559125023403167"
},
{
"input": "10000",
"output": "2 936791129091842315790163514642"
},
{
"input": "1000000",
"output": "18 369591628030718549289473454545"
},
{
"input": "100000000",
"output": "7 870405265198051697453938746950"
},
{
"input": "10000000000",
"output": "20 972749766921651560604778558599"
},
{
"input": "1000000000000",
"output": "6 68997070398311657294228230677"
},
{
"input": "100000000000000",
"output": "249537318528661282822184562278 397003438246047829818181818181"
},
{
"input": "10000000000000000",
"output": "10 778165727326620883431915444624"
},
{
"input": "1000000000000000000",
"output": "408256298986776744812953390000 824018301451167837914299999999"
},
{
"input": "450000000000000000",
"output": "2 357722688084551093593033993033"
},
{
"input": "432022",
"output": "3 333556238531076799985515487090"
},
{
"input": "428033",
"output": "22 730314748425770554502599499142"
},
{
"input": "776930",
"output": "20 521232359366297130685112811874"
},
{
"input": "329824",
"output": "308969571112207311167474021348 745620588073413831210052337999"
},
{
"input": "85058261498638",
"output": "16 931187081941564769324316582547"
},
{
"input": "2130909834463",
"output": "21 895378349209612431051450316022"
},
{
"input": "3427089130241",
"output": "10 676758114393938690602742889714"
},
{
"input": "22881472397923",
"output": "174523915446146844994793303441 429392837423394397373605399524"
},
{
"input": "756499070280135900",
"output": "17 414254565210363110239866979636"
},
{
"input": "348919756917359012",
"output": "15 148711424846749040017925495268"
},
{
"input": "789136710974630947",
"output": "13 214740524663440316532540770911"
},
{
"input": "32851678509090784",
"output": "15 728787006985867306455350840047"
},
{
"input": "219760524792138559",
"output": "8 51530430692061277616906746431"
},
{
"input": "1000000007",
"output": "19 96093944063249823335491170999"
},
{
"input": "999999874000003969",
"output": "306259936121099507549028331741 983025349899931537481252156006"
},
{
"input": "999999999999999989",
"output": "140766388309929586494194507367 705096656792775954903252198639"
},
{
"input": "999999999999999983",
"output": "4 365946710276937286091309116340"
},
{
"input": "999999999999999999",
"output": "26 983966655749419565978291923474"
}
] | 62 | 0 | 3 | 1,613 |
|
688 | Lovely Palindromes | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them.
Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number? | The only line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11,β22,β33,β... ,β88,β99 and 1001. | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "2",
"output": "22"
},
{
"input": "3",
"output": "33"
},
{
"input": "4",
"output": "44"
},
{
"input": "5",
"output": "55"
},
{
"input": "6",
"output": "66"
},
{
"input": "7",
"output": "77"
},
{
"input": "8",
"output": "88"
},
{
"input": "9",
"output": "99"
},
{
"input": "13",
"output": "1331"
},
{
"input": "14",
"output": "1441"
},
{
"input": "15",
"output": "1551"
},
{
"input": "16",
"output": "1661"
},
{
"input": "17",
"output": "1771"
},
{
"input": "18",
"output": "1881"
},
{
"input": "19",
"output": "1991"
},
{
"input": "20",
"output": "2002"
},
{
"input": "26550",
"output": "2655005562"
},
{
"input": "16137",
"output": "1613773161"
},
{
"input": "91471",
"output": "9147117419"
},
{
"input": "41242",
"output": "4124224214"
},
{
"input": "30866",
"output": "3086666803"
},
{
"input": "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116",
"output": "44422312327410030099641831997138515664660798829290072534438483719780486106821804312956719051059801166110895015091765921340812860168408791738483443527009292889706646651583179913814699003001472321322444"
},
{
"input": "7806526084732010742850470902979267046151204705563201965818390803445852115032119297648697933316807252",
"output": "78065260847320107428504709029792670461512047055632019658183908034458521150321192976486979333168072522527086133397968467929112305112585443080938185691023655074021516407629792090740582470102374806256087"
},
{
"input": "2244399823612183124978103773977739948197709395321563148611877999503840818596183803323258317041875913",
"output": "22443998236121831249781037739777399481977093953215631486118779995038408185961838033232583170418759133195781407138523233083816958180483059997781168413651235939077918499377793773018794213812163289934422"
},
{
"input": "123451",
"output": "123451154321"
}
] | 77 | 409,600 | 3 | 1,618 |
|
870 | Maximum of Maximums of Minimums | [
"greedy"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible integer you can get?
Definitions of subsegment and array splitting are given in notes. | The first line contains two integers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=<=105) β the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=β€<=<=*a**i*<=β€<=<=109). | Print single integer β the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*,ββ*r*] (*l*ββ€β*r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>,ββ*a*<sub class="lower-index">*l*β+β1</sub>,ββ...,ββ*a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>,β*r*<sub class="lower-index">1</sub>], [*l*<sub class="lower-index">2</sub>,β*r*<sub class="lower-index">2</sub>], ..., [*l*<sub class="lower-index">*k*</sub>,β*r*<sub class="lower-index">*k*</sub>] (*l*<sub class="lower-index">1</sub>β=β1, *r*<sub class="lower-index">*k*</sub>β=β*n*, *l*<sub class="lower-index">*i*</sub>β=β*r*<sub class="lower-index">*i*β-β1</sub>β+β1 for all *i*β>β1) is *k* sequences (*a*<sub class="lower-index">*l*<sub class="lower-index">1</sub></sub>,β...,β*a*<sub class="lower-index">*r*<sub class="lower-index">1</sub></sub>),β...,β(*a*<sub class="lower-index">*l*<sub class="lower-index">*k*</sub></sub>,β...,β*a*<sub class="lower-index">*r*<sub class="lower-index">*k*</sub></sub>).
In the first example you should split the array into subsegments [1,β4] and [5,β5] that results in sequences (1,β2,β3,β4) and (5). The minimums are *min*(1,β2,β3,β4)β=β1 and *min*(5)β=β5. The resulting maximum is *max*(1,β5)β=β5. It is obvious that you can't reach greater result.
In the second example the only option you have is to split the array into one subsegment [1,β5], that results in one sequence (β-β4,ββ-β5,ββ-β3,ββ-β2,ββ-β1). The only minimum is *min*(β-β4,ββ-β5,ββ-β3,ββ-β2,ββ-β1)β=ββ-β5. The resulting maximum is β-β5. | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output": "504262064"
},
{
"input": "3 3\n-54481850 -878017339 -486296116",
"output": "-54481850"
},
{
"input": "2 2\n-333653905 224013643",
"output": "224013643"
},
{
"input": "14 2\n-14 84 44 46 -75 -75 77 -49 44 -82 -74 -51 -9 -50",
"output": "-14"
},
{
"input": "88 71\n-497 -488 182 104 40 183 201 282 -384 44 -29 494 224 -80 -491 -197 157 130 -52 233 -426 252 -61 -51 203 -50 195 -442 -38 385 232 -243 -49 163 340 -200 406 -254 -29 227 -194 193 487 -325 230 146 421 158 20 447 -97 479 493 -130 164 -471 -198 -330 -152 359 -554 319 544 -444 235 281 -467 337 -385 227 -366 -210 266 69 -261 525 526 -234 -355 177 109 275 -301 7 -41 553 -284 540",
"output": "553"
},
{
"input": "39 1\n676941771 -923780377 -163050076 -230110947 -208029500 329620771 13954060 158950156 -252501602 926390671 -678745080 -921892226 -100127643 610420285 602175224 -839193819 471391946 910035173 777969600 -736144413 -489685522 60986249 830784148 278642552 -375298304 197973611 -354482364 187294011 636628282 25350767 636184407 -550869740 53830680 -42049274 -451383278 900048257 93225803 877923341 -279506435",
"output": "-923780377"
},
{
"input": "3 2\n1 5 3",
"output": "3"
},
{
"input": "5 2\n1 2 5 4 3",
"output": "3"
},
{
"input": "3 2\n1 3 2",
"output": "2"
},
{
"input": "3 2\n1 3 1",
"output": "1"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "-2"
},
{
"input": "5 2\n1 2 3 5 4",
"output": "4"
},
{
"input": "5 2\n1 1 11 1 1",
"output": "1"
},
{
"input": "3 3\n3 8 4",
"output": "8"
},
{
"input": "6 3\n4 3 1 5 6 2",
"output": "6"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "5 2\n2 5 4 3 1",
"output": "2"
},
{
"input": "5 2\n-1 1 5 4 3",
"output": "3"
},
{
"input": "5 2\n5 2 1 9 3",
"output": "5"
},
{
"input": "2 1\n1000000000 1000000000",
"output": "1000000000"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "5 2\n1 5 3 4 1",
"output": "1"
},
{
"input": "3 2\n-1000000000 -1000000000 -1000000000",
"output": "-1000000000"
},
{
"input": "2 2\n5 2",
"output": "5"
},
{
"input": "7 3\n1 1 1 10 1 1 1",
"output": "10"
},
{
"input": "9 3\n1 2 1 1 5 1 1 1 2",
"output": "5"
},
{
"input": "9 3\n2 2 2 2 9 2 2 2 2",
"output": "9"
},
{
"input": "3 3\n-1000000000 -1000000000 -1000000000",
"output": "-1000000000"
}
] | 108 | 0 | 0 | 1,619 |
|
492 | Vanya and Lanterns | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? | The first line contains two integers *n*, *l* (1<=β€<=*n*<=β€<=1000, 1<=β€<=*l*<=β€<=109) β the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=β€<=*a**i*<=β€<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d*β=β2 the first lantern will light the segment [0,β4] of the street, and the second lantern will light segment [3,β5]. Thus, the whole street will be lit. | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307",
"output": "22258199.5000000000"
},
{
"input": "2 1000000000\n0 1000000000",
"output": "500000000.0000000000"
},
{
"input": "2 555\n200 300",
"output": "255.0000000000"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n0",
"output": "1.0000000000"
},
{
"input": "1 1000000000\n0",
"output": "1000000000.0000000000"
},
{
"input": "1 1000000000\n1000000000",
"output": "1000000000.0000000000"
},
{
"input": "1 999999999\n499999999",
"output": "500000000.0000000000"
},
{
"input": "4 700\n0 250 475 700",
"output": "125.0000000000"
},
{
"input": "4 700\n0 225 450 700",
"output": "125.0000000000"
},
{
"input": "5 1000\n0 250 500 750 1000",
"output": "125.0000000000"
},
{
"input": "5 2000\n1001 1001 1001 1001 1001",
"output": "1001.0000000000"
},
{
"input": "1 999\n501",
"output": "501.0000000000"
},
{
"input": "2 1000\n400 600",
"output": "400.0000000000"
},
{
"input": "4 15\n1 3 9 11",
"output": "4.0000000000"
},
{
"input": "1 5\n2",
"output": "3.0000000000"
}
] | 46 | 0 | 0 | 1,620 |
|
510 | Fox And Snake | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern. | The only line contains two integers: *n* and *m* (3<=β€<=*n*,<=*m*<=β€<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########"
},
{
"input": "3 5",
"output": "#####\n....#\n#####"
},
{
"input": "3 6",
"output": "######\n.....#\n######"
},
{
"input": "7 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "7 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####"
},
{
"input": "49 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 27",
"output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................."
},
{
"input": "11 15",
"output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############"
},
{
"input": "11 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "19 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "23 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "49 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "33 43",
"output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................."
},
{
"input": "33 44",
"output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......."
},
{
"input": "45 45",
"output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..."
},
{
"input": "45 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "45 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###"
},
{
"input": "45 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####"
},
{
"input": "5 4",
"output": "####\n...#\n####\n#...\n####"
},
{
"input": "5 5",
"output": "#####\n....#\n#####\n#....\n#####"
},
{
"input": "5 6",
"output": "######\n.....#\n######\n#.....\n######"
},
{
"input": "7 5",
"output": "#####\n....#\n#####\n#....\n#####\n....#\n#####"
},
{
"input": "7 6",
"output": "######\n.....#\n######\n#.....\n######\n.....#\n######"
},
{
"input": "7 7",
"output": "#######\n......#\n#######\n#......\n#######\n......#\n#######"
}
] | 46 | 0 | 3 | 1,625 |
|
0 | none | [
"none"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.
Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add. | The first line of input will contain three integers *n*, *m* and *k* (1<=β€<=*n*<=β€<=1<=000, 0<=β€<=*m*<=β€<=100<=000, 1<=β€<=*k*<=β€<=*n*) β the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=β€<=*c**i*<=β€<=*n*). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.
The following *m* lines of input will contain two integers *u**i* and *v**i* (1<=β€<=*u**i*,<=*v**i*<=β€<=*n*). This denotes an undirected edge between nodes *u**i* and *v**i*.
It is guaranteed that the graph described by the input is stable. | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
"input": "24 38 2\n4 13\n7 1\n24 1\n2 8\n17 2\n2 18\n22 2\n23 3\n5 9\n21 5\n6 7\n6 19\n6 20\n11 7\n7 20\n13 8\n16 8\n9 10\n14 9\n21 9\n12 10\n10 22\n23 10\n17 11\n11 24\n20 12\n13 16\n13 23\n15 14\n17 14\n14 20\n19 16\n17 20\n17 23\n18 22\n18 23\n22 19\n21 20\n23 24",
"output": "215"
},
{
"input": "10 30 1\n4\n1 2\n3 1\n4 1\n1 6\n1 8\n10 1\n2 4\n2 7\n3 4\n3 5\n7 3\n3 9\n10 3\n5 4\n6 4\n7 4\n9 4\n10 4\n6 5\n5 8\n9 5\n10 5\n6 7\n9 6\n10 6\n7 8\n9 7\n10 7\n9 8\n10 8",
"output": "15"
},
{
"input": "10 13 2\n5 10\n2 1\n1 4\n2 3\n2 8\n3 4\n7 3\n4 6\n8 4\n4 9\n6 7\n6 9\n10 6\n7 8",
"output": "23"
},
{
"input": "10 10 3\n2 5 6\n1 3\n4 1\n4 3\n5 3\n3 9\n8 4\n9 4\n5 10\n8 7\n10 8",
"output": "18"
},
{
"input": "10 5 3\n1 5 9\n1 3\n1 8\n2 3\n8 4\n5 7",
"output": "17"
},
{
"input": "6 4 2\n1 4\n1 2\n2 3\n4 5\n5 6",
"output": "2"
},
{
"input": "7 8 2\n1 4\n1 2\n2 3\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7",
"output": "1"
},
{
"input": "5 2 3\n1 3 4\n1 5\n2 4",
"output": "0"
},
{
"input": "5 3 2\n1 2\n2 3\n2 4\n1 5",
"output": "1"
},
{
"input": "9 5 2\n1 5\n1 2\n2 3\n3 4\n5 6\n6 7",
"output": "13"
},
{
"input": "6 4 1\n1\n2 3\n3 4\n4 5\n5 6",
"output": "11"
},
{
"input": "6 4 2\n1 5\n1 2\n2 3\n3 4\n5 6",
"output": "3"
},
{
"input": "7 3 3\n1 5 6\n1 2\n1 3\n6 7",
"output": "4"
},
{
"input": "5 2 2\n1 2\n1 3\n2 4",
"output": "2"
},
{
"input": "11 7 2\n1 4\n1 2\n1 3\n4 5\n4 6\n5 6\n9 10\n1 11",
"output": "24"
},
{
"input": "20 4 5\n1 3 9 10 20\n5 6\n1 2\n7 9\n4 10",
"output": "89"
}
] | 31 | 4,608,000 | 0 | 1,627 |
|
366 | Dima and To-do List | [
"brute force",
"implementation"
] | null | null | You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.
Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.
Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible. | The first line of the input contains two integers *n*,<=*k* (1<=β€<=*k*<=β€<=*n*<=β€<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n* is divisible by *k*. | In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do. | [
"6 2\n3 2 1 6 5 4\n",
"10 5\n1 3 5 7 9 9 4 1 8 5\n"
] | [
"1\n",
"3\n"
] | Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.
Explanation of the second example.
In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3. | [
{
"input": "6 2\n3 2 1 6 5 4",
"output": "1"
},
{
"input": "10 5\n1 3 5 7 9 9 4 1 8 5",
"output": "3"
},
{
"input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 10\n8 4 5 7 6 9 2 2 3 5",
"output": "7"
},
{
"input": "50 10\n1 2 3 4 5 6 7 8 9 10 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "4 2\n2 1 1 3",
"output": "1"
},
{
"input": "15 5\n5 5 5 5 5 1 2 3 4 5 1 2 3 4 5",
"output": "1"
},
{
"input": "20 10\n3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 6 4",
"output": "1"
}
] | 1,000 | 9,830,400 | 0 | 1,631 |
|
1,011 | Stages | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string β concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' β $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once. | The first line of input contains two integers β $n$ and $k$ ($1 \le k \le n \le 50$) β the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once. | Print a single integer β the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "169"
},
{
"input": "50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "1 1\na",
"output": "1"
},
{
"input": "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "1"
},
{
"input": "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "13 13\nuwgmkyqeiaocs",
"output": "169"
},
{
"input": "13 13\nhzdxpbfvrltnj",
"output": "182"
},
{
"input": "1 1\nn",
"output": "14"
},
{
"input": "10 8\nsmzeblyjqw",
"output": "113"
},
{
"input": "20 20\ntzmvhskkyugkuuxpvtbh",
"output": "-1"
},
{
"input": "30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav",
"output": "-1"
},
{
"input": "40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv",
"output": "-1"
},
{
"input": "50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz",
"output": "-1"
},
{
"input": "10 7\niuiukrxcml",
"output": "99"
},
{
"input": "38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa",
"output": "5"
},
{
"input": "12 6\nfwseyrarkwcd",
"output": "61"
},
{
"input": "2 2\nac",
"output": "4"
},
{
"input": "1 1\nc",
"output": "3"
},
{
"input": "2 2\nad",
"output": "5"
},
{
"input": "2 1\nac",
"output": "1"
},
{
"input": "4 3\nadjz",
"output": "15"
},
{
"input": "3 3\naoz",
"output": "42"
},
{
"input": "3 1\nzzz",
"output": "26"
},
{
"input": "2 1\nxz",
"output": "24"
},
{
"input": "5 1\naaddd",
"output": "1"
}
] | 109 | 0 | 0 | 1,635 |
|
220 | Little Elephant and Problem | [
"implementation",
"sortings"
] | null | null | The Little Elephant has got a problem β somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.
Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself. | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=105) β the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, β array *a*.
Note that the elements of the array are not necessarily distinct numbers. | In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. | [
"2\n1 2\n",
"3\n3 2 1\n",
"4\n4 3 2 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we can't sort the array in more than one swap operation, so the answer is "NO". | [
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "4\n4 3 2 1",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "9\n7 7 8 8 10 10 10 10 1000000000",
"output": "YES"
},
{
"input": "10\n1 2 9 4 5 6 7 8 3 10",
"output": "YES"
},
{
"input": "4\n2 2 2 1",
"output": "YES"
},
{
"input": "10\n1 2 4 4 4 5 5 7 7 10",
"output": "YES"
},
{
"input": "10\n4 5 11 12 13 14 16 16 16 18",
"output": "YES"
},
{
"input": "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321",
"output": "YES"
},
{
"input": "47\n6 277 329 393 410 432 434 505 529 545 650 896 949 1053 1543 1554 1599 1648 1927 1976 1998 2141 2248 2384 2542 2638 2995 3155 3216 3355 3409 3597 3851 3940 4169 4176 4378 4378 4425 4490 4627 4986 5025 5033 5374 5453 5644",
"output": "YES"
},
{
"input": "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5",
"output": "NO"
},
{
"input": "100\n3 7 7 8 15 25 26 31 37 41 43 43 46 64 65 82 94 102 102 103 107 124 125 131 140 145 146 150 151 160 160 161 162 165 169 175 182 191 201 211 214 216 218 304 224 229 236 241 244 249 252 269 270 271 273 289 285 295 222 307 312 317 319 319 320 321 325 330 340 341 345 347 354 356 366 366 375 376 380 383 386 398 401 407 414 417 423 426 431 438 440 444 446 454 457 458 458 466 466 472",
"output": "NO"
},
{
"input": "128\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 200 332 342 393 349 350 350 369 375 381 381 385 385 387 393 347 397 398 115 402 407 407 408 410 411 411 416 423 426 429 429 430 440 447 449 463 464 466 471 473 480 480 483 497 503",
"output": "NO"
},
{
"input": "4\n5 12 12 6",
"output": "YES"
},
{
"input": "5\n1 3 3 3 2",
"output": "YES"
},
{
"input": "4\n2 1 1 1",
"output": "YES"
},
{
"input": "2\n1 1",
"output": "YES"
},
{
"input": "4\n1000000000 1 1000000000 1",
"output": "YES"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 1",
"output": "YES"
},
{
"input": "6\n1 2 3 4 5 3",
"output": "NO"
},
{
"input": "9\n3 3 3 2 2 2 1 1 1",
"output": "NO"
},
{
"input": "4\n4 1 2 3",
"output": "NO"
},
{
"input": "6\n3 4 5 6 7 2",
"output": "NO"
},
{
"input": "4\n4 2 1 3",
"output": "NO"
},
{
"input": "4\n3 3 2 2",
"output": "NO"
},
{
"input": "4\n3 2 1 1",
"output": "NO"
},
{
"input": "4\n4 5 1 1",
"output": "NO"
},
{
"input": "6\n1 6 2 4 3 5",
"output": "NO"
},
{
"input": "5\n1 4 5 2 3",
"output": "NO"
},
{
"input": "4\n2 2 1 1",
"output": "NO"
},
{
"input": "5\n1 4 3 2 1",
"output": "NO"
},
{
"input": "5\n1 4 2 2 3",
"output": "NO"
},
{
"input": "6\n1 2 3 1 2 3",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "NO"
},
{
"input": "5\n5 1 2 3 4",
"output": "NO"
},
{
"input": "5\n3 3 3 2 2",
"output": "NO"
},
{
"input": "5\n100 5 6 10 7",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "NO"
},
{
"input": "5\n4 4 1 1 1",
"output": "NO"
},
{
"input": "5\n1 2 5 3 4",
"output": "NO"
},
{
"input": "4\n3 4 1 2",
"output": "NO"
},
{
"input": "4\n2 4 1 5",
"output": "NO"
},
{
"input": "5\n1 3 3 2 2",
"output": "NO"
},
{
"input": "5\n1 5 4 4 4",
"output": "YES"
},
{
"input": "7\n3 2 1 2 3 5 4",
"output": "NO"
},
{
"input": "5\n1 1 3 2 2",
"output": "YES"
},
{
"input": "9\n1 8 7 7 7 7 7 8 3",
"output": "YES"
},
{
"input": "5\n1 3 2 3 3",
"output": "YES"
},
{
"input": "10\n4 4 4 4 10 4 4 4 4 4",
"output": "YES"
},
{
"input": "8\n3 6 6 6 6 6 4 9",
"output": "YES"
},
{
"input": "4\n4 4 3 3",
"output": "NO"
},
{
"input": "4\n3 2 2 4",
"output": "YES"
},
{
"input": "5\n2 2 1 3 3",
"output": "YES"
},
{
"input": "5\n1 2 7 3 5",
"output": "NO"
},
{
"input": "5\n2 3 4 5 1",
"output": "NO"
},
{
"input": "6\n1 4 3 6 2 5",
"output": "NO"
},
{
"input": "5\n3 3 1 5 4",
"output": "NO"
},
{
"input": "4\n1 2 1 2",
"output": "YES"
},
{
"input": "6\n4 5 3 4 2 6",
"output": "NO"
},
{
"input": "11\n1 2 3 4 5 1 2 3 4 5 1",
"output": "NO"
},
{
"input": "6\n6 1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n4 1 1 1 1",
"output": "YES"
},
{
"input": "9\n1 2 3 5 4 6 7 8 9",
"output": "YES"
},
{
"input": "6\n6 1 2 3 4 2",
"output": "NO"
},
{
"input": "6\n2 2 2 2 3 2",
"output": "YES"
},
{
"input": "3\n2 1 1",
"output": "YES"
},
{
"input": "5\n1 2 1 1 2",
"output": "YES"
},
{
"input": "5\n1 2 2 1 2",
"output": "YES"
},
{
"input": "8\n5 5 5 5 5 5 1 1",
"output": "NO"
}
] | 155 | 8,192,000 | 3 | 1,646 |
|
66 | Petya and Java | [
"implementation",
"strings"
] | A. Petya and Java | 2 | 256 | Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger.
But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it is much easier to use small data types. That's why a question arises: "Which integer type to use if one wants to store a positive integer *n*?"
Petya knows only 5 integer types:
1) byte occupies 1 byte and allows you to store numbers from <=-<=128 to 127
2) short occupies 2 bytes and allows you to store numbers from <=-<=32768 to 32767
3) int occupies 4 bytes and allows you to store numbers from <=-<=2147483648 to 2147483647
4) long occupies 8 bytes and allows you to store numbers from <=-<=9223372036854775808 to 9223372036854775807
5) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower.
For all the types given above the boundary values are included in the value range.
From this list, Petya wants to choose the smallest type that can store a positive integer *n*. Since BigInteger works much slower, Peter regards it last. Help him. | The first line contains a positive number *n*. It consists of no more than 100 digits and doesn't contain any leading zeros. The number *n* can't be represented as an empty string.
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). | Print the first type from the list "byte, short, int, long, BigInteger", that can store the natural number *n*, in accordance with the data given above. | [
"127\n",
"130\n",
"123456789101112131415161718192021222324\n"
] | [
"byte\n",
"short\n",
"BigInteger\n"
] | none | [
{
"input": "127",
"output": "byte"
},
{
"input": "130",
"output": "short"
},
{
"input": "123456789101112131415161718192021222324",
"output": "BigInteger"
},
{
"input": "6",
"output": "byte"
},
{
"input": "16",
"output": "byte"
},
{
"input": "126",
"output": "byte"
},
{
"input": "128",
"output": "short"
},
{
"input": "32766",
"output": "short"
},
{
"input": "111111",
"output": "int"
},
{
"input": "22222",
"output": "short"
},
{
"input": "32767",
"output": "short"
},
{
"input": "32768",
"output": "int"
},
{
"input": "32769",
"output": "int"
},
{
"input": "2147483645",
"output": "int"
},
{
"input": "2147483646",
"output": "int"
},
{
"input": "2147483647",
"output": "int"
},
{
"input": "2147483648",
"output": "long"
},
{
"input": "2147483649",
"output": "long"
},
{
"input": "9223372036854775805",
"output": "long"
},
{
"input": "9223372036854775806",
"output": "long"
},
{
"input": "9223372036854775807",
"output": "long"
},
{
"input": "9223372036854775808",
"output": "BigInteger"
},
{
"input": "9223372036854775809",
"output": "BigInteger"
},
{
"input": "1111111111111111111111111111111111111111111111",
"output": "BigInteger"
},
{
"input": "232",
"output": "short"
},
{
"input": "241796563564014133460267652699",
"output": "BigInteger"
},
{
"input": "29360359146807441660707083821018832188095237636414144034857851003419752010124705615779249",
"output": "BigInteger"
},
{
"input": "337300529263821789926982715723773719445001702036602052198530564",
"output": "BigInteger"
},
{
"input": "381127467969689863953686682245136076127159921",
"output": "BigInteger"
},
{
"input": "2158324958633591462",
"output": "long"
},
{
"input": "268659422768117401499491767189496733446324586965055954729177892248858259490346",
"output": "BigInteger"
},
{
"input": "3023764505449745844381036446038799100004717936344985",
"output": "BigInteger"
},
{
"input": "13408349824892484976400774",
"output": "BigInteger"
},
{
"input": "18880842614378213198381172973704766723997934818440985546083314104481253291692101136681",
"output": "BigInteger"
},
{
"input": "1180990956946757129733650596194933741",
"output": "BigInteger"
},
{
"input": "73795216631038776655609800540262114612084443385902708034055020082090470662930545328551",
"output": "BigInteger"
},
{
"input": "1658370691480968202384509492140362150472696196949",
"output": "BigInteger"
},
{
"input": "59662093286671707493190399502717308574459619342109544431740791973099298641871347858082458491958703",
"output": "BigInteger"
},
{
"input": "205505005582428018613354752739589866670902346355933720701937",
"output": "BigInteger"
},
{
"input": "53348890623013817139699",
"output": "BigInteger"
},
{
"input": "262373979958859125198440634134122707574734706745701184688685117904709744",
"output": "BigInteger"
},
{
"input": "69113784278456828987289369893745977",
"output": "BigInteger"
},
{
"input": "2210209454022702335652564247406666491086662454147967686455330365147159266087",
"output": "BigInteger"
},
{
"input": "630105816139991597267787581532092408135",
"output": "BigInteger"
},
{
"input": "800461429306907809762708270",
"output": "BigInteger"
},
{
"input": "7685166910821197056344900917707673568669808490600751439157",
"output": "BigInteger"
},
{
"input": "713549841568602590705962611607726022334779480510421458817648621376683672722573289661127894",
"output": "BigInteger"
},
{
"input": "680504312323996476676434432",
"output": "BigInteger"
},
{
"input": "3376595620091080825479292544658464163405755746884100218035",
"output": "BigInteger"
},
{
"input": "303681723783491968617491075591006152690484825330764215796396316561122383310011589365655481",
"output": "BigInteger"
},
{
"input": "4868659422768117401499491767189496733446324586965055954729177892248858259490346614099717639491763430",
"output": "BigInteger"
},
{
"input": "3502376450544974584438103644603879910000471793634498544789130945841846713263971487355748226237288709",
"output": "BigInteger"
},
{
"input": "2334083498248924849764007740114454487565621932425948046430072197452845278935316358800789014185793377",
"output": "BigInteger"
},
{
"input": "1988808426143782131983811729737047667239979348184409855460833141044812532916921011366813880911319644",
"output": "BigInteger"
},
{
"input": "1018099095694675712973365059619493374113337270925179793757322992466016001294122941535439492265169131",
"output": "BigInteger"
},
{
"input": "8437952166310387766556098005402621146120844433859027080340550200820904706629305453285512716464931911",
"output": "BigInteger"
},
{
"input": "6965837069148096820238450949214036215047269619694967357734070611376013382163559966747678150791825071",
"output": "BigInteger"
},
{
"input": "4596620932866717074931903995027173085744596193421095444317407919730992986418713478580824584919587030",
"output": "BigInteger"
},
{
"input": "1905505005582428018613354752739589866670902346355933720701937408006000562951996789032987808118459990",
"output": "BigInteger"
},
{
"input": "8433488906230138171396997888322916936677429522910871017295155818340819168386140293774243244435122950",
"output": "BigInteger"
},
{
"input": "6862373979958859125198440634134122707574734706745701184688685117904709744830303784215298687654884810",
"output": "BigInteger"
},
{
"input": "4491137842784568289872893698937459777201151060689848471272003426250808340375567208957554901863756992",
"output": "BigInteger"
},
{
"input": "9721020945402270233565256424740666649108666245414796768645533036514715926608741510409618545180420952",
"output": "BigInteger"
},
{
"input": "7330105816139991597267787581532092408135003429259616955239761315950805521264994021242873979309182812",
"output": "BigInteger"
},
{
"input": "2000461429306907809762708270752707617318091579531521957022940951538737203583768926365382290530636885",
"output": "BigInteger"
},
{
"input": "9868516691082119705634490091770767356866980849060075143915700796802700437762260163478754592094654326",
"output": "BigInteger"
},
{
"input": "8713549841568602590705962611607726022334779480510421458817648621376683672722573289661127894678771177",
"output": "BigInteger"
},
{
"input": "4580504312323996476676434432646986768872786931159974634901608445720467716981185426771899006352697916",
"output": "BigInteger"
},
{
"input": "2537659562009108082547929254465846416340575574688410021803548570097340949141688442074263189944614467",
"output": "BigInteger"
},
{
"input": "1403681723783491968617491075591006152690484825330764215796396316561122383310011589365655481428540208",
"output": "BigInteger"
},
{
"input": "26",
"output": "byte"
},
{
"input": "302376450544",
"output": "long"
},
{
"input": "13",
"output": "byte"
},
{
"input": "188808426143",
"output": "long"
},
{
"input": "118099095694675",
"output": "long"
},
{
"input": "73795216631038",
"output": "long"
},
{
"input": "1658370691480",
"output": "long"
},
{
"input": "596620932866",
"output": "long"
},
{
"input": "2055050055",
"output": "int"
},
{
"input": "533488906",
"output": "int"
},
{
"input": "26237397",
"output": "int"
},
{
"input": "6911378",
"output": "int"
},
{
"input": "221020945402270233",
"output": "long"
},
{
"input": "63010581613999159",
"output": "long"
},
{
"input": "80046142930",
"output": "long"
},
{
"input": "7685166910821197",
"output": "long"
},
{
"input": "71",
"output": "byte"
},
{
"input": "6805043123239964766",
"output": "long"
},
{
"input": "3376",
"output": "short"
},
{
"input": "3036817237",
"output": "long"
}
] | 154 | 0 | 3.9615 | 1,651 |
92 | Binary Number | [
"greedy"
] | B. Binary Number | 1 | 256 | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time.
How many actions should Fangy perform to get a number one from number *x*? | The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. | Print the required number of actions. | [
"1\n",
"1001001\n",
"101110\n"
] | [
"0\n",
"12\n",
"8\n"
] | Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1. | [
{
"input": "1",
"output": "0"
},
{
"input": "1001001",
"output": "12"
},
{
"input": "101110",
"output": "8"
},
{
"input": "11",
"output": "3"
},
{
"input": "11110001101",
"output": "16"
},
{
"input": "1010101001001111000111110011111000010101011111101010",
"output": "74"
},
{
"input": "1100000010010100111011100011110101111",
"output": "55"
},
{
"input": "11000111111110110110100110110101111100010100110110010",
"output": "74"
},
{
"input": "11100000110100011110101001101111100000011001111000011110000000111110111",
"output": "106"
},
{
"input": "1000101100110000000001111010110000000010001001111110011011000011101011001001010010111",
"output": "133"
},
{
"input": "1000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "72"
},
{
"input": "10000100000",
"output": "16"
}
] | 93 | 0 | 0 | 1,652 |
63 | Sinking Ship | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:
The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.
If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).
For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | The first line contains an integer *n*, which is the number of people in the crew (1<=β€<=*n*<=β€<=100). Then follow *n* lines. The *i*-th of those lines contains two words β the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain\nB man\nD woman\nC child\nE rat",
"output": "E\nD\nC\nB\nA"
},
{
"input": "10\nCap captain\nD child\nC woman\nA woman\nE child\nMan man\nB child\nF woman\nRat rat\nRatt rat",
"output": "Rat\nRatt\nD\nC\nA\nE\nB\nF\nMan\nCap"
},
{
"input": "5\nJoyxnkypf captain\nDxssgr woman\nKeojmnpd rat\nGdv man\nHnw man",
"output": "Keojmnpd\nDxssgr\nGdv\nHnw\nJoyxnkypf"
},
{
"input": "11\nJue rat\nWyglbyphk rat\nGjlgu child\nGi man\nAttx rat\nTheorpkgx man\nYm rat\nX child\nB captain\nEnualf rat\nKktsgyuyv woman",
"output": "Jue\nWyglbyphk\nAttx\nYm\nEnualf\nGjlgu\nX\nKktsgyuyv\nGi\nTheorpkgx\nB"
},
{
"input": "22\nWswwcvvm woman\nBtmfats rat\nI rat\nOcmtsnwx man\nUrcqv rat\nYghnogt woman\nWtyfc man\nWqle child\nUjfrelpu rat\nDstixj man\nAhksnio woman\nKhkvaap woman\nSjppvwm rat\nEgdmsv rat\nDank rat\nNquicjnw rat\nLh captain\nTdyaqaqln rat\nQtj rat\nTfgwijvq rat\nNbiso child\nNqthvbf woman",
"output": "Btmfats\nI\nUrcqv\nUjfrelpu\nSjppvwm\nEgdmsv\nDank\nNquicjnw\nTdyaqaqln\nQtj\nTfgwijvq\nWswwcvvm\nYghnogt\nWqle\nAhksnio\nKhkvaap\nNbiso\nNqthvbf\nOcmtsnwx\nWtyfc\nDstixj\nLh"
},
{
"input": "36\nKqxmtwmsf child\nIze woman\nDlpr child\nK woman\nF captain\nRjwfeuhba rat\nBbv rat\nS rat\nMnmg woman\nSmzyx woman\nSr man\nQmhroracn rat\nSoqpuqock rat\nPibdq man\nIlrkrptx rat\nZaecfyqka man\nMmersfs child\nVvvocqi man\nHjeqxvq rat\nMpmb woman\nWmgu woman\nCerelmhoxi child\nA man\nDylv man\nXrdgmmtcpq woman\nXj woman\nCeh child\nOfccguo man\nNevr man\nAknkwdkq child\nBmo man\nLqo woman\nVej child\nT child\nRlijc man\nNsdtpdg woman",
"output": "Rjwfeuhba\nBbv\nS\nQmhroracn\nSoqpuqock\nIlrkrptx\nHjeqxvq\nKqxmtwmsf\nIze\nDlpr\nK\nMnmg\nSmzyx\nMmersfs\nMpmb\nWmgu\nCerelmhoxi\nXrdgmmtcpq\nXj\nCeh\nAknkwdkq\nLqo\nVej\nT\nNsdtpdg\nSr\nPibdq\nZaecfyqka\nVvvocqi\nA\nDylv\nOfccguo\nNevr\nBmo\nRlijc\nF"
},
{
"input": "2\nA captain\nB man",
"output": "B\nA"
},
{
"input": "2\nB woman\nA captain",
"output": "B\nA"
},
{
"input": "2\nX child\nY captain",
"output": "X\nY"
},
{
"input": "2\nX captain\nY rat",
"output": "Y\nX"
},
{
"input": "6\nAbdelrhman captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nAbdelrhman"
},
{
"input": "4\nAratos captain\nMind child\nAman woman\nCarrot man",
"output": "Mind\nAman\nCarrot\nAratos"
}
] | 62 | 0 | 0 | 1,653 |
30 | King's Problem? | [
"geometry",
"greedy"
] | D. King's Problem? | 3 | 256 | Every true king during his life must conquer the world, hold the Codeforces world finals, win pink panda in the shooting gallery and travel all over his kingdom.
King Copa has already done the first three things. Now he just needs to travel all over the kingdom. The kingdom is an infinite plane with Cartesian coordinate system on it. Every city is a point on this plane. There are *n* cities in the kingdom at points with coordinates (*x*1,<=0),<=(*x*2,<=0),<=...,<=(*x**n*,<=0), and there is one city at point (*x**n*<=+<=1,<=*y**n*<=+<=1).
King starts his journey in the city number *k*. Your task is to find such route for the king, which visits all cities (in any order) and has minimum possible length. It is allowed to visit a city twice. The king can end his journey in any city. Between any pair of cities there is a direct road with length equal to the distance between the corresponding points. No two cities may be located at the same point. | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=105,<=1<=β€<=*k*<=β€<=*n*<=+<=1) β amount of cities and index of the starting city. The second line contains *n*<=+<=1 numbers *x**i*. The third line contains *y**n*<=+<=1. All coordinates are integers and do not exceed 106 by absolute value. No two cities coincide. | Output the minimum possible length of the journey. Your answer must have relative or absolute error less than 10<=-<=6. | [
"3 1\n0 1 2 1\n1\n",
"3 1\n1 0 2 1\n1\n",
"4 5\n0 5 -1 -5 2\n3\n"
] | [
"3.41421356237309490000",
"3.82842712474619030000",
"14.24264068711928400000"
] | none | [
{
"input": "3 1\n0 1 2 1\n1",
"output": "3.41421356237309490000"
},
{
"input": "3 1\n1 0 2 1\n1",
"output": "3.82842712474619030000"
},
{
"input": "4 5\n0 5 -1 -5 2\n3",
"output": "14.24264068711928400000"
},
{
"input": "4 1\n0 5 -1 -5 2\n3",
"output": "16.85841379298319300000"
},
{
"input": "10 5\n-231 598 312 -837 -711 553 -439 351 83 -605 -738\n791",
"output": "2928.27473344969580000000"
},
{
"input": "100 31\n-577 101 691 -95 809 125 -934 -645 -838 -548 259 312 -501 -962 -629 -637 -797 -259 -258 -687 537 303 -6 431 64 229 -897 -942 -805 804 -608 84 992 -563 279 -546 -523 -28 4 -296 120 -306 456 -334 625 821 -9 525 572 -36 -642 594 207 429 -859 -408 -428 280 389 304 -683 800 97 578 -1 46 981 -271 585 -913 761 367 0 -360 529 -302 598 -660 295 -785 756 759 -446 -826 -627 687 -459 637 -509 -582 825 34 -911 -383 49 -343 791 471 -574 -267 -954\n-462",
"output": "2983.22016716350340000000"
},
{
"input": "4 2\n0 2 3 9 2\n5",
"output": "17.98749007417713100000"
},
{
"input": "1 1\n8 4\n5",
"output": "6.40312423743284850000"
},
{
"input": "1 2\n104 13\n455",
"output": "464.01077573694340000000"
},
{
"input": "2 2\n-80 -28 -41\n-61",
"output": "124.40165743959182000000"
},
{
"input": "3 1\n6 -7 40 -39\n28",
"output": "123.52058325093860000000"
},
{
"input": "4 4\n-58 14 70 34 -12\n84",
"output": "259.77055915050300000000"
},
{
"input": "5 1\n78 35 -100 57 99 -92\n58",
"output": "278.54912467321776000000"
},
{
"input": "6 6\n14 6 -19 -71 59 -17 24\n-76",
"output": "267.67197858303581000000"
},
{
"input": "7 6\n-51 27 12 -48 -31 7 -10 -10\n-35",
"output": "146.93132631298738000000"
},
{
"input": "8 9\n36 48 42 -25 80 32 -44 6 -80\n-50",
"output": "185.61168720299744000000"
},
{
"input": "9 6\n-28 69 -78 48 41 57 73 75 -38 30\n-94",
"output": "307.09503873251936000000"
},
{
"input": "10 1\n-42 -13 68 -73 -39 81 -9 -47 -74 -84 -2\n-70",
"output": "299.34407871396292000000"
},
{
"input": "11 6\n41 -64 51 67 -8 -99 -94 -81 -30 -60 37 -66\n26",
"output": "205.09347166041786000000"
},
{
"input": "12 3\n74 -65 84 -44 23 -78 22 86 65 -86 76 -61 66\n-87",
"output": "316.05212760071760000000"
},
{
"input": "13 4\n-43 -65 67 95 -97 -56 -63 53 -42 -62 -86 -7 -45 12\n44",
"output": "240.06852768030663000000"
},
{
"input": "14 12\n-10 85 50 34 -67 -35 53 -31 -89 -47 -3 -5 -90 10 -100\n50",
"output": "315.99019513592782000000"
},
{
"input": "15 7\n23 84 83 -28 -36 36 -82 -64 -54 -65 -8 51 35 9 -74 -19\n37",
"output": "222.67938366055708000000"
},
{
"input": "16 6\n-94 83 66 62 45 58 34 -98 40 -91 81 56 -76 -93 43 75 -49\n57",
"output": "259.75902391002091000000"
},
{
"input": "17 17\n-61 32 99 1 76 79 -51 20 -66 83 -80 60 -36 6 -41 93 -89 65\n35",
"output": "236.79549159502341000000"
},
{
"input": "18 11\n22 31 82 -61 -94 -100 65 -14 28 -41 -87 54 -96 -75 -27 100 -73 63 2\n-15",
"output": "223.93171219946132000000"
},
{
"input": "19 12\n55 30 65 79 -63 -79 -20 -48 73 81 -2 -83 94 3 42 54 -64 40 91 24\n48",
"output": "250.76629407951023000000"
},
{
"input": "1 2\n-5 -4\n-2",
"output": "2.23606797749978980000"
},
{
"input": "2 1\n-2 -1 -1\n-4",
"output": "5.00000000000000000000"
},
{
"input": "3 1\n-1 1 4 0\n-5",
"output": "11.40312423743284900000"
},
{
"input": "4 3\n3 0 -3 1 -3\n-3",
"output": "10.24264068711928400000"
},
{
"input": "5 6\n-5 2 -1 5 0 0\n2",
"output": "15.38516480713450500000"
},
{
"input": "6 3\n-1 3 1 -4 5 -3 -4\n5",
"output": "18.00000000000000000000"
},
{
"input": "7 7\n0 4 3 -5 -3 -1 5 3\n4",
"output": "16.00000000000000000000"
},
{
"input": "8 5\n3 -4 2 -1 4 0 5 1 3\n4",
"output": "16.47213595499958000000"
},
{
"input": "9 2\n-4 -2 4 3 -5 5 0 -3 -1 1\n-3",
"output": "16.76782893563237000000"
},
{
"input": "10 6\n4 -3 0 -2 2 5 1 -5 -4 -1 2\n5",
"output": "18.38516480713450500000"
},
{
"input": "1 2\n-6 -5\n-13",
"output": "13.03840481040529800000"
},
{
"input": "2 1\n-3 20 2\n8",
"output": "29.13169673564881300000"
},
{
"input": "3 4\n0 5 18 -13\n-4",
"output": "31.60147050873544600000"
},
{
"input": "4 5\n3 -10 -8 5 -15\n5",
"output": "22.07106781186547600000"
},
{
"input": "5 4\n7 16 9 -16 13 -5\n4",
"output": "33.35381055139314600000"
},
{
"input": "6 6\n10 0 -16 2 5 -20 -16\n18",
"output": "56.08318915758459200000"
},
{
"input": "7 1\n13 -15 -1 -19 -5 -14 14 -6\n5",
"output": "39.53300064564938800000"
},
{
"input": "8 2\n16 11 1 -14 -6 5 8 -15 16\n-15",
"output": "60.00000000000000000000"
},
{
"input": "9 9\n19 -4 -9 17 2 -6 -19 -3 -10 20\n-19",
"output": "66.02629759044045000000"
},
{
"input": "10 10\n-7 -4 -5 17 20 -6 -1 10 -8 13 3\n19",
"output": "56.95449840010015000000"
},
{
"input": "3 1\n0 1 2 1\n1",
"output": "3.41421356237309490000"
},
{
"input": "3 1\n1 0 2 1\n1",
"output": "3.82842712474619030000"
},
{
"input": "4 5\n0 5 -1 -5 2\n3",
"output": "14.24264068711928400000"
},
{
"input": "4 1\n0 5 -1 -5 2\n3",
"output": "16.85841379298319300000"
},
{
"input": "5 1\n0 1 3 100 -1000 2\n1",
"output": "1200.00560090988460000000"
},
{
"input": "5 1\n0 -1 -3 -100 1000 -2\n1",
"output": "1200.00560090988460000000"
},
{
"input": "1 2\n-1 9\n0",
"output": "10.00000000000000000000"
},
{
"input": "2 2\n4 -2 -8\n0",
"output": "18.00000000000000000000"
},
{
"input": "3 2\n7 -2 3 -8\n0",
"output": "21.00000000000000000000"
},
{
"input": "4 5\n-9 -2 0 4 -4\n0",
"output": "18.00000000000000000000"
},
{
"input": "5 5\n-4 -2 0 6 -6 -8\n0",
"output": "16.00000000000000000000"
},
{
"input": "6 6\n10 0 -16 2 5 -20 18\n0",
"output": "38.00000000000000000000"
},
{
"input": "7 1\n13 -15 -1 -19 -5 -14 14 5\n0",
"output": "34.00000000000000000000"
},
{
"input": "8 2\n16 11 1 -14 -6 5 8 -15 -19\n0",
"output": "40.00000000000000000000"
},
{
"input": "9 9\n19 -4 -9 17 2 -6 -19 -3 -10 3\n0",
"output": "47.00000000000000000000"
},
{
"input": "10 10\n-7 -4 -5 17 20 -6 -1 10 -8 13 19\n0",
"output": "35.00000000000000000000"
},
{
"input": "11 7\n-2 20 -16 19 -5 3 13 17 -15 16 -10 -19\n0",
"output": "46.00000000000000000000"
},
{
"input": "12 8\n0 15 -20 17 -8 11 1 20 -2 -13 8 -3 4\n0",
"output": "40.00000000000000000000"
},
{
"input": "15 16\n9 -15 -16 12 -17 -4 -19 -9 -11 -14 -13 4 5 8 -18 1\n0",
"output": "42.00000000000000000000"
},
{
"input": "15 7\n11 -30 -5 -3 19 -11 -27 3 22 -4 10 -16 -13 -8 -26 25\n0",
"output": "58.00000000000000000000"
},
{
"input": "20 1\n-7 -28 -2 27 -12 6 -1 10 -11 -8 29 16 -14 -18 23 -10 13 -29 -25 30 7\n0",
"output": "81.00000000000000000000"
},
{
"input": "20 8\n-36 -18 13 11 5 18 23 -2 -39 2 4 -34 -20 24 7 19 -13 14 6 -35 -4\n0",
"output": "89.00000000000000000000"
},
{
"input": "20 8\n62 -52 -96 -68 -13 59 65 21 -47 90 -21 58 -71 39 -35 -98 -19 -90 -57 -62 -48\n0",
"output": "257.00000000000000000000"
},
{
"input": "100 31\n-577 101 691 -95 809 125 -934 -645 -838 -548 259 312 -501 -962 -629 -637 -797 -259 -258 -687 537 303 -6 431 64 229 -897 -942 -805 804 -608 84 992 -563 279 -546 -523 -28 4 -296 120 -306 456 -334 625 821 -9 525 572 -36 -642 594 207 429 -859 -408 -428 280 389 304 -683 800 97 578 -1 46 981 -271 585 -913 761 367 0 -360 529 -302 598 -660 295 -785 756 759 -446 -826 -627 687 -459 637 -509 -582 825 34 -911 -383 49 -343 791 471 -574 -267 -462\n0",
"output": "2308.00000000000000000000"
},
{
"input": "5 2\n0 2 3 8 9 2\n5",
"output": "18.19541448304115900000"
},
{
"input": "4 2\n0 2 3 9 2\n5",
"output": "17.98749007417713100000"
},
{
"input": "4 3\n0 6 7 9 7\n5",
"output": "17.98749007417713100000"
},
{
"input": "1 2\n-1 -3\n9",
"output": "9.21954445729288710000"
},
{
"input": "2 2\n4 -2 5\n-8",
"output": "14.06225774829854900000"
},
{
"input": "3 2\n7 -2 3 8\n-8",
"output": "17.06225774829854900000"
},
{
"input": "4 5\n-9 -2 0 4 10\n-4",
"output": "20.21110255092797900000"
},
{
"input": "5 5\n-4 -2 0 6 -6 5\n-8",
"output": "20.06225774829854900000"
},
{
"input": "6 6\n1 -1 -6 -2 5 -9 -1\n-1",
"output": "15.23606797749979000000"
},
{
"input": "100 9\n52 24 17 12 57 95 94 36 -3 63 -69 71 23 -72 77 -55 2 -5 -25 -18 -39 -100 6 -43 18 74 -61 54 47 5 -68 9 -41 -42 34 31 -4 -16 67 -65 -56 -50 -84 27 -87 62 70 -14 10 90 -46 97 43 -88 99 75 -34 -36 92 -17 29 -52 -80 -92 44 -44 -32 -89 -82 -74 98 38 -10 93 -24 96 -28 -98 76 -83 -29 -27 35 53 37 -67 64 -21 72 -20 -54 49 28 26 83 46 59 -2 -12 32 -44\n37",
"output": "321.09250465482546000000"
}
] | 372 | 11,059,200 | 3.917401 | 1,655 |
672 | Different is Good | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".
If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible. | The first line of the input contains an integer *n* (1<=β€<=*n*<=β€<=100<=000) β the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"output": "12"
},
{
"input": "25\ntcqpchnqskqjacruoaqilgebu",
"output": "7"
},
{
"input": "13\naebaecedabbee",
"output": "8"
},
{
"input": "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "10\nbababbdaee",
"output": "6"
},
{
"input": "11\ndbadcdbdbca",
"output": "7"
},
{
"input": "12\nacceaabddaaa",
"output": "7"
},
{
"input": "13\nabddfbfaeecfa",
"output": "7"
},
{
"input": "14\neeceecacdbcbbb",
"output": "9"
},
{
"input": "15\ndcbceaaggabaheb",
"output": "8"
},
{
"input": "16\nhgiegfbadgcicbhd",
"output": "7"
},
{
"input": "17\nabhfibbdddfghgfdi",
"output": "10"
},
{
"input": "26\nbbbbbabbaababaaabaaababbaa",
"output": "24"
},
{
"input": "26\nahnxdnbfbcrirerssyzydihuee",
"output": "11"
},
{
"input": "26\nhwqeqhkpxwulbsiwmnlfyhgknc",
"output": "8"
},
{
"input": "26\nrvxmulriorilidecqwmfaemifj",
"output": "10"
},
{
"input": "26\naowpmreooavnmamogdoopuisge",
"output": "12"
},
{
"input": "26\ninimevtuefhvuefirdehmmfudh",
"output": "15"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "25"
},
{
"input": "27\nqdcfjtblgglnilgassirrjekcjt",
"output": "-1"
},
{
"input": "27\nabcdefghijklmnopqrstuvwxyza",
"output": "-1"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "0"
},
{
"input": "5\nzzzzz",
"output": "4"
},
{
"input": "27\naaaaaaaaaaaaaaaaabaaaaaaaaa",
"output": "-1"
},
{
"input": "1\nq",
"output": "0"
},
{
"input": "27\nqwertyuioplkjhgfdsazxcvbnmm",
"output": "-1"
},
{
"input": "9\nxxxyyyzzz",
"output": "6"
},
{
"input": "45\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk",
"output": "-1"
},
{
"input": "27\nqwertyuiopasdfghjklzxcvbnmm",
"output": "-1"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyz",
"output": "0"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxya",
"output": "1"
},
{
"input": "27\nabcdefghijklmnopqrstuvwxyzz",
"output": "-1"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "25"
},
{
"input": "26\nqwertyuioplkjhgfdsazxcvbnm",
"output": "0"
},
{
"input": "10\nzzzzzzzzzz",
"output": "9"
},
{
"input": "1\na",
"output": "0"
},
{
"input": "30\nabcdefghtyabcdefghtyabcdefghty",
"output": "-1"
}
] | 93 | 204,800 | 0 | 1,656 |
|
271 | Beautiful Year | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. | The single line contains integer *y* (1000<=β€<=*y*<=β€<=9000) β the year number. | Print a single integer β the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"input": "9000",
"output": "9012"
},
{
"input": "1111",
"output": "1203"
},
{
"input": "8999",
"output": "9012"
},
{
"input": "4572",
"output": "4573"
},
{
"input": "6666",
"output": "6701"
},
{
"input": "2001",
"output": "2013"
},
{
"input": "3000",
"output": "3012"
},
{
"input": "7712",
"output": "7801"
},
{
"input": "8088",
"output": "8091"
},
{
"input": "1594",
"output": "1596"
},
{
"input": "6016",
"output": "6017"
},
{
"input": "8800",
"output": "8901"
},
{
"input": "3331",
"output": "3401"
},
{
"input": "5090",
"output": "5091"
},
{
"input": "2342",
"output": "2345"
},
{
"input": "2334",
"output": "2340"
},
{
"input": "1123",
"output": "1203"
},
{
"input": "8989",
"output": "9012"
},
{
"input": "8977",
"output": "9012"
},
{
"input": "6869",
"output": "6870"
},
{
"input": "8999",
"output": "9012"
}
] | 62 | 0 | 0 | 1,658 |
|
327 | Hungry Sequence | [
"math"
] | null | null | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in increasing order. That is an inequality *a**i*<=<<=*a**j* holds for any two indices *i*,<=*j* (*i*<=<<=*j*). - For any two indices *i* and *j* (*i*<=<<=*j*), *a**j* must not be divisible by *a**i*.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with *n* elements. | The input contains a single integer: *n* (1<=β€<=*n*<=β€<=105). | Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one. | [
"3\n",
"5\n"
] | [
"2 9 15\n",
"11 14 20 27 31\n"
] | none | [
{
"input": "3",
"output": "2 9 15"
},
{
"input": "5",
"output": "11 14 20 27 31"
},
{
"input": "1",
"output": "3"
},
{
"input": "1000",
"output": "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 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3..."
},
{
"input": "100000",
"output": "300000 300001 300002 300003 300004 300005 300006 300007 300008 300009 300010 300011 300012 300013 300014 300015 300016 300017 300018 300019 300020 300021 300022 300023 300024 300025 300026 300027 300028 300029 300030 300031 300032 300033 300034 300035 300036 300037 300038 300039 300040 300041 300042 300043 300044 300045 300046 300047 300048 300049 300050 300051 300052 300053 300054 300055 300056 300057 300058 300059 300060 300061 300062 300063 300064 300065 300066 300067 300068 300069 300070 300071 300072 ..."
},
{
"input": "46550",
"output": "139650 139651 139652 139653 139654 139655 139656 139657 139658 139659 139660 139661 139662 139663 139664 139665 139666 139667 139668 139669 139670 139671 139672 139673 139674 139675 139676 139677 139678 139679 139680 139681 139682 139683 139684 139685 139686 139687 139688 139689 139690 139691 139692 139693 139694 139695 139696 139697 139698 139699 139700 139701 139702 139703 139704 139705 139706 139707 139708 139709 139710 139711 139712 139713 139714 139715 139716 139717 139718 139719 139720 139721 139722 ..."
},
{
"input": "61324",
"output": "183972 183973 183974 183975 183976 183977 183978 183979 183980 183981 183982 183983 183984 183985 183986 183987 183988 183989 183990 183991 183992 183993 183994 183995 183996 183997 183998 183999 184000 184001 184002 184003 184004 184005 184006 184007 184008 184009 184010 184011 184012 184013 184014 184015 184016 184017 184018 184019 184020 184021 184022 184023 184024 184025 184026 184027 184028 184029 184030 184031 184032 184033 184034 184035 184036 184037 184038 184039 184040 184041 184042 184043 184044 ..."
},
{
"input": "13176",
"output": "39528 39529 39530 39531 39532 39533 39534 39535 39536 39537 39538 39539 39540 39541 39542 39543 39544 39545 39546 39547 39548 39549 39550 39551 39552 39553 39554 39555 39556 39557 39558 39559 39560 39561 39562 39563 39564 39565 39566 39567 39568 39569 39570 39571 39572 39573 39574 39575 39576 39577 39578 39579 39580 39581 39582 39583 39584 39585 39586 39587 39588 39589 39590 39591 39592 39593 39594 39595 39596 39597 39598 39599 39600 39601 39602 39603 39604 39605 39606 39607 39608 39609 39610 39611 39612 3..."
},
{
"input": "73274",
"output": "219822 219823 219824 219825 219826 219827 219828 219829 219830 219831 219832 219833 219834 219835 219836 219837 219838 219839 219840 219841 219842 219843 219844 219845 219846 219847 219848 219849 219850 219851 219852 219853 219854 219855 219856 219857 219858 219859 219860 219861 219862 219863 219864 219865 219866 219867 219868 219869 219870 219871 219872 219873 219874 219875 219876 219877 219878 219879 219880 219881 219882 219883 219884 219885 219886 219887 219888 219889 219890 219891 219892 219893 219894 ..."
},
{
"input": "86947",
"output": "260841 260842 260843 260844 260845 260846 260847 260848 260849 260850 260851 260852 260853 260854 260855 260856 260857 260858 260859 260860 260861 260862 260863 260864 260865 260866 260867 260868 260869 260870 260871 260872 260873 260874 260875 260876 260877 260878 260879 260880 260881 260882 260883 260884 260885 260886 260887 260888 260889 260890 260891 260892 260893 260894 260895 260896 260897 260898 260899 260900 260901 260902 260903 260904 260905 260906 260907 260908 260909 260910 260911 260912 260913 ..."
},
{
"input": "26342",
"output": "79026 79027 79028 79029 79030 79031 79032 79033 79034 79035 79036 79037 79038 79039 79040 79041 79042 79043 79044 79045 79046 79047 79048 79049 79050 79051 79052 79053 79054 79055 79056 79057 79058 79059 79060 79061 79062 79063 79064 79065 79066 79067 79068 79069 79070 79071 79072 79073 79074 79075 79076 79077 79078 79079 79080 79081 79082 79083 79084 79085 79086 79087 79088 79089 79090 79091 79092 79093 79094 79095 79096 79097 79098 79099 79100 79101 79102 79103 79104 79105 79106 79107 79108 79109 79110 7..."
},
{
"input": "22345",
"output": "67035 67036 67037 67038 67039 67040 67041 67042 67043 67044 67045 67046 67047 67048 67049 67050 67051 67052 67053 67054 67055 67056 67057 67058 67059 67060 67061 67062 67063 67064 67065 67066 67067 67068 67069 67070 67071 67072 67073 67074 67075 67076 67077 67078 67079 67080 67081 67082 67083 67084 67085 67086 67087 67088 67089 67090 67091 67092 67093 67094 67095 67096 67097 67098 67099 67100 67101 67102 67103 67104 67105 67106 67107 67108 67109 67110 67111 67112 67113 67114 67115 67116 67117 67118 67119 6..."
},
{
"input": "19639",
"output": "58917 58918 58919 58920 58921 58922 58923 58924 58925 58926 58927 58928 58929 58930 58931 58932 58933 58934 58935 58936 58937 58938 58939 58940 58941 58942 58943 58944 58945 58946 58947 58948 58949 58950 58951 58952 58953 58954 58955 58956 58957 58958 58959 58960 58961 58962 58963 58964 58965 58966 58967 58968 58969 58970 58971 58972 58973 58974 58975 58976 58977 58978 58979 58980 58981 58982 58983 58984 58985 58986 58987 58988 58989 58990 58991 58992 58993 58994 58995 58996 58997 58998 58999 59000 59001 5..."
},
{
"input": "12337",
"output": "37011 37012 37013 37014 37015 37016 37017 37018 37019 37020 37021 37022 37023 37024 37025 37026 37027 37028 37029 37030 37031 37032 37033 37034 37035 37036 37037 37038 37039 37040 37041 37042 37043 37044 37045 37046 37047 37048 37049 37050 37051 37052 37053 37054 37055 37056 37057 37058 37059 37060 37061 37062 37063 37064 37065 37066 37067 37068 37069 37070 37071 37072 37073 37074 37075 37076 37077 37078 37079 37080 37081 37082 37083 37084 37085 37086 37087 37088 37089 37090 37091 37092 37093 37094 37095 3..."
},
{
"input": "67989",
"output": "203967 203968 203969 203970 203971 203972 203973 203974 203975 203976 203977 203978 203979 203980 203981 203982 203983 203984 203985 203986 203987 203988 203989 203990 203991 203992 203993 203994 203995 203996 203997 203998 203999 204000 204001 204002 204003 204004 204005 204006 204007 204008 204009 204010 204011 204012 204013 204014 204015 204016 204017 204018 204019 204020 204021 204022 204023 204024 204025 204026 204027 204028 204029 204030 204031 204032 204033 204034 204035 204036 204037 204038 204039 ..."
},
{
"input": "57610",
"output": "172830 172831 172832 172833 172834 172835 172836 172837 172838 172839 172840 172841 172842 172843 172844 172845 172846 172847 172848 172849 172850 172851 172852 172853 172854 172855 172856 172857 172858 172859 172860 172861 172862 172863 172864 172865 172866 172867 172868 172869 172870 172871 172872 172873 172874 172875 172876 172877 172878 172879 172880 172881 172882 172883 172884 172885 172886 172887 172888 172889 172890 172891 172892 172893 172894 172895 172896 172897 172898 172899 172900 172901 172902 ..."
},
{
"input": "63287",
"output": "189861 189862 189863 189864 189865 189866 189867 189868 189869 189870 189871 189872 189873 189874 189875 189876 189877 189878 189879 189880 189881 189882 189883 189884 189885 189886 189887 189888 189889 189890 189891 189892 189893 189894 189895 189896 189897 189898 189899 189900 189901 189902 189903 189904 189905 189906 189907 189908 189909 189910 189911 189912 189913 189914 189915 189916 189917 189918 189919 189920 189921 189922 189923 189924 189925 189926 189927 189928 189929 189930 189931 189932 189933 ..."
},
{
"input": "952",
"output": "2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2..."
},
{
"input": "77840",
"output": "233520 233521 233522 233523 233524 233525 233526 233527 233528 233529 233530 233531 233532 233533 233534 233535 233536 233537 233538 233539 233540 233541 233542 233543 233544 233545 233546 233547 233548 233549 233550 233551 233552 233553 233554 233555 233556 233557 233558 233559 233560 233561 233562 233563 233564 233565 233566 233567 233568 233569 233570 233571 233572 233573 233574 233575 233576 233577 233578 233579 233580 233581 233582 233583 233584 233585 233586 233587 233588 233589 233590 233591 233592 ..."
},
{
"input": "42157",
"output": "126471 126472 126473 126474 126475 126476 126477 126478 126479 126480 126481 126482 126483 126484 126485 126486 126487 126488 126489 126490 126491 126492 126493 126494 126495 126496 126497 126498 126499 126500 126501 126502 126503 126504 126505 126506 126507 126508 126509 126510 126511 126512 126513 126514 126515 126516 126517 126518 126519 126520 126521 126522 126523 126524 126525 126526 126527 126528 126529 126530 126531 126532 126533 126534 126535 126536 126537 126538 126539 126540 126541 126542 126543 ..."
},
{
"input": "46375",
"output": "139125 139126 139127 139128 139129 139130 139131 139132 139133 139134 139135 139136 139137 139138 139139 139140 139141 139142 139143 139144 139145 139146 139147 139148 139149 139150 139151 139152 139153 139154 139155 139156 139157 139158 139159 139160 139161 139162 139163 139164 139165 139166 139167 139168 139169 139170 139171 139172 139173 139174 139175 139176 139177 139178 139179 139180 139181 139182 139183 139184 139185 139186 139187 139188 139189 139190 139191 139192 139193 139194 139195 139196 139197 ..."
},
{
"input": "55142",
"output": "165426 165427 165428 165429 165430 165431 165432 165433 165434 165435 165436 165437 165438 165439 165440 165441 165442 165443 165444 165445 165446 165447 165448 165449 165450 165451 165452 165453 165454 165455 165456 165457 165458 165459 165460 165461 165462 165463 165464 165465 165466 165467 165468 165469 165470 165471 165472 165473 165474 165475 165476 165477 165478 165479 165480 165481 165482 165483 165484 165485 165486 165487 165488 165489 165490 165491 165492 165493 165494 165495 165496 165497 165498 ..."
},
{
"input": "60299",
"output": "180897 180898 180899 180900 180901 180902 180903 180904 180905 180906 180907 180908 180909 180910 180911 180912 180913 180914 180915 180916 180917 180918 180919 180920 180921 180922 180923 180924 180925 180926 180927 180928 180929 180930 180931 180932 180933 180934 180935 180936 180937 180938 180939 180940 180941 180942 180943 180944 180945 180946 180947 180948 180949 180950 180951 180952 180953 180954 180955 180956 180957 180958 180959 180960 180961 180962 180963 180964 180965 180966 180967 180968 180969 ..."
},
{
"input": "28862",
"output": "86586 86587 86588 86589 86590 86591 86592 86593 86594 86595 86596 86597 86598 86599 86600 86601 86602 86603 86604 86605 86606 86607 86608 86609 86610 86611 86612 86613 86614 86615 86616 86617 86618 86619 86620 86621 86622 86623 86624 86625 86626 86627 86628 86629 86630 86631 86632 86633 86634 86635 86636 86637 86638 86639 86640 86641 86642 86643 86644 86645 86646 86647 86648 86649 86650 86651 86652 86653 86654 86655 86656 86657 86658 86659 86660 86661 86662 86663 86664 86665 86666 86667 86668 86669 86670 8..."
},
{
"input": "48251",
"output": "144753 144754 144755 144756 144757 144758 144759 144760 144761 144762 144763 144764 144765 144766 144767 144768 144769 144770 144771 144772 144773 144774 144775 144776 144777 144778 144779 144780 144781 144782 144783 144784 144785 144786 144787 144788 144789 144790 144791 144792 144793 144794 144795 144796 144797 144798 144799 144800 144801 144802 144803 144804 144805 144806 144807 144808 144809 144810 144811 144812 144813 144814 144815 144816 144817 144818 144819 144820 144821 144822 144823 144824 144825 ..."
},
{
"input": "2",
"output": "6 7"
},
{
"input": "4",
"output": "12 13 14 15"
}
] | 1,000 | 68,812,800 | 0 | 1,661 |
|
461 | Appleman and Toastman | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=3Β·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=106) β the initial group that is given to Toastman. | Print a single integer β the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\n1 2 2 2 4 5 6 7 8 10",
"output": "376"
},
{
"input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002",
"output": "40204082"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "10\n10 8 7 6 5 4 2 2 2 1",
"output": "376"
},
{
"input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821",
"output": "40204082"
},
{
"input": "10\n5 2 6 10 10 10 10 2 2 5",
"output": "485"
},
{
"input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255",
"output": "36742665"
},
{
"input": "10\n2 2 2 5 5 6 10 10 10 10",
"output": "485"
},
{
"input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 6 5 5 2 2 2",
"output": "485"
},
{
"input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 10 10 10 10 10 10",
"output": "640"
},
{
"input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "64000000"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "2\n1 2",
"output": "6"
},
{
"input": "2\n2 3",
"output": "10"
},
{
"input": "2\n1 1",
"output": "4"
}
] | 2,000 | 6,041,600 | 0 | 1,666 |
|
453 | Little Pony and Expected Maximum | [
"probabilities"
] | null | null | Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times. | A single line contains two integers *m* and *n* (1<=β€<=*m*,<=*n*<=β€<=105). | Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4. | [
"6 1\n",
"6 3\n",
"2 2\n"
] | [
"3.500000000000\n",
"4.958333333333\n",
"1.750000000000\n"
] | Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value | [
{
"input": "6 1",
"output": "3.500000000000"
},
{
"input": "6 3",
"output": "4.958333333333"
},
{
"input": "2 2",
"output": "1.750000000000"
},
{
"input": "5 4",
"output": "4.433600000000"
},
{
"input": "5 8",
"output": "4.814773760000"
},
{
"input": "3 10",
"output": "2.982641534996"
},
{
"input": "3 6",
"output": "2.910836762689"
},
{
"input": "1 8",
"output": "1.000000000000"
},
{
"input": "24438 9",
"output": "21994.699969310015"
},
{
"input": "94444 9",
"output": "85000.099992058866"
},
{
"input": "8 66716",
"output": "8.000000000000"
},
{
"input": "4 25132",
"output": "4.000000000000"
},
{
"input": "51520 73331",
"output": "51519.682650242677"
},
{
"input": "54230 31747",
"output": "54228.743352775018"
},
{
"input": "24236 90163",
"output": "24235.975171545670"
},
{
"input": "26946 99523",
"output": "26945.974480086279"
},
{
"input": "50323 7",
"output": "44033.124988408454"
},
{
"input": "53033 3",
"output": "39775.249995286234"
},
{
"input": "55743 5",
"output": "46452.999992525307"
},
{
"input": "59964 79",
"output": "59214.949890211828"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "3 1",
"output": "2.000000000000"
},
{
"input": "1 2",
"output": "1.000000000000"
},
{
"input": "53513 34040",
"output": "53511.875329020870"
},
{
"input": "100000 100000",
"output": "99999.418033254507"
},
{
"input": "1 100000",
"output": "1.000000000000"
},
{
"input": "100000 1",
"output": "50000.499999999935"
},
{
"input": "2 100000",
"output": "2.000000000000"
},
{
"input": "100000 2",
"output": "66667.166665000332"
},
{
"input": "50000 100000",
"output": "49999.843487110789"
},
{
"input": "99999 1111",
"output": "99909.571915885972"
},
{
"input": "99999 99999",
"output": "99998.418033254609"
},
{
"input": "1000 1000",
"output": "999.419018443269"
},
{
"input": "50000 50000",
"output": "49999.418043215679"
},
{
"input": "88888 88888",
"output": "88887.418034499773"
},
{
"input": "99999 100000",
"output": "99998.418042461126"
},
{
"input": "100000 555",
"output": "99820.643422392372"
},
{
"input": "10000 10000",
"output": "9999.418122897887"
},
{
"input": "100000 5001",
"output": "99980.503829474910"
},
{
"input": "100000 1000",
"output": "99900.599066768002"
}
] | 249 | 102,400 | -1 | 1,673 |
|
641 | Little Artem and Dance | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Little Artem is fond of dancing. Most of all dances Artem likes rueda β Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:
1. Value *x* and some direction are announced, and all boys move *x* positions in the corresponding direction. 1. Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number 3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that *n* is even.
Your task is to determine the final position of each boy. | The first line of the input contains two integers *n* and *q* (2<=β€<=*n*<=β€<=1<=000<=000, 1<=β€<=*q*<=β€<=2<=000<=000) β the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that *n* is even.
Next *q* lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as *x* (<=-<=*n*<=β€<=*x*<=β€<=*n*), where 0<=β€<=*x*<=β€<=*n* means all boys moves *x* girls in clockwise direction, while <=-<=*x* means all boys move *x* positions in counter-clockwise direction. There is no other input for commands of the second type. | Output *n* integers, the *i*-th of them should be equal to the index of boy the *i*-th girl is dancing with after performing all *q* moves. | [
"6 3\n1 2\n2\n1 2\n",
"2 3\n1 1\n2\n1 -2\n",
"4 2\n2\n1 3\n"
] | [
"4 3 6 5 2 1\n",
"1 2\n",
"1 4 3 2\n"
] | none | [
{
"input": "6 3\n1 2\n2\n1 2",
"output": "4 3 6 5 2 1"
},
{
"input": "2 3\n1 1\n2\n1 -2",
"output": "1 2"
},
{
"input": "4 2\n2\n1 3",
"output": "1 4 3 2"
},
{
"input": "6 8\n1 2\n2\n2\n2\n2\n1 1\n1 -5\n2",
"output": "4 3 6 5 2 1"
},
{
"input": "6 8\n1 -1\n2\n2\n1 4\n1 0\n1 -1\n1 0\n1 -1",
"output": "6 1 2 3 4 5"
},
{
"input": "10 5\n1 8\n1 -3\n1 -3\n2\n1 5",
"output": "3 6 5 8 7 10 9 2 1 4"
},
{
"input": "10 10\n1 2\n1 -10\n1 -5\n2\n2\n1 -4\n2\n2\n1 -10\n1 -9",
"output": "7 8 9 10 1 2 3 4 5 6"
},
{
"input": "6 9\n2\n1 -2\n2\n1 -6\n1 -6\n1 4\n2\n1 -1\n2",
"output": "2 5 4 1 6 3"
},
{
"input": "2 5\n2\n1 -1\n2\n1 1\n2",
"output": "2 1"
},
{
"input": "2 8\n2\n2\n2\n1 -2\n1 -1\n1 -1\n2\n1 1",
"output": "2 1"
},
{
"input": "36 86\n1 -25\n2\n2\n2\n1 16\n1 -14\n1 12\n2\n1 -21\n2\n1 -12\n1 34\n1 -4\n1 19\n1 5\n2\n2\n2\n2\n1 -1\n1 -31\n2\n1 -6\n1 1\n2\n2\n1 27\n1 19\n2\n1 -14\n2\n1 -17\n2\n2\n2\n2\n1 -35\n1 -31\n1 7\n2\n2\n2\n1 -12\n2\n2\n2\n2\n1 7\n1 -9\n1 -2\n2\n1 -3\n2\n2\n1 33\n1 -8\n1 -17\n1 2\n2\n1 -29\n1 -19\n2\n1 22\n2\n2\n2\n2\n1 -15\n1 7\n1 -29\n2\n2\n1 -30\n2\n2\n1 -6\n2\n1 -25\n2\n1 -18\n2\n1 33\n1 23\n2\n2\n2",
"output": "25 22 27 24 29 26 31 28 33 30 35 32 1 34 3 36 5 2 7 4 9 6 11 8 13 10 15 12 17 14 19 16 21 18 23 20"
},
{
"input": "10 71\n1 -4\n1 -3\n2\n2\n2\n1 -3\n1 4\n2\n2\n2\n2\n1 5\n2\n2\n2\n2\n2\n1 1\n2\n1 2\n1 1\n2\n1 -5\n2\n2\n2\n2\n1 8\n1 -9\n1 -3\n1 2\n1 3\n1 -2\n1 -6\n2\n2\n1 -2\n2\n1 -6\n1 5\n1 2\n1 -10\n1 3\n2\n1 6\n2\n2\n1 4\n1 -8\n1 -4\n1 -1\n2\n2\n1 1\n2\n2\n1 3\n1 8\n1 7\n1 4\n2\n1 -10\n2\n2\n1 5\n1 9\n1 -5\n2\n2\n1 -2\n2",
"output": "1 2 3 4 5 6 7 8 9 10"
},
{
"input": "74 85\n2\n1 -69\n2\n2\n2\n2\n2\n1 74\n2\n2\n1 -41\n2\n2\n1 15\n2\n2\n2\n1 -12\n2\n1 -3\n1 28\n1 -46\n2\n1 -39\n2\n1 6\n2\n2\n1 -30\n2\n1 16\n1 30\n1 -50\n1 -17\n1 41\n1 56\n2\n1 -45\n1 -21\n1 63\n1 -7\n2\n1 -6\n1 26\n2\n1 -71\n2\n2\n2\n1 11\n2\n1 70\n1 13\n2\n1 -51\n1 -9\n1 -72\n1 55\n2\n1 3\n2\n2\n1 47\n2\n2\n2\n1 -6\n1 -37\n2\n2\n1 -1\n1 72\n2\n1 -23\n2\n2\n2\n1 70\n1 38\n2\n2\n1 74\n1 -1\n2\n1 -9",
"output": "71 18 73 20 1 22 3 24 5 26 7 28 9 30 11 32 13 34 15 36 17 38 19 40 21 42 23 44 25 46 27 48 29 50 31 52 33 54 35 56 37 58 39 60 41 62 43 64 45 66 47 68 49 70 51 72 53 74 55 2 57 4 59 6 61 8 63 10 65 12 67 14 69 16"
},
{
"input": "24 8\n1 17\n2\n1 -10\n2\n2\n2\n2\n1 19",
"output": "22 1 24 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23"
},
{
"input": "242 11\n1 -202\n1 46\n2\n1 -144\n2\n1 134\n1 104\n2\n1 -32\n2\n1 36",
"output": "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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 ..."
},
{
"input": "364 57\n1 -101\n1 110\n1 -76\n1 329\n2\n2\n2\n1 -191\n1 97\n1 189\n1 305\n1 -313\n1 312\n1 -148\n2\n1 -104\n1 85\n1 -55\n1 -79\n1 230\n1 -94\n1 58\n1 -72\n2\n2\n2\n1 -104\n1 -351\n1 23\n2\n1 215\n2\n2\n2\n1 58\n1 -237\n2\n2\n2\n1 198\n2\n1 83\n2\n1 -205\n2\n2\n2\n2\n1 -110\n2\n2\n2\n2\n1 153\n1 -344\n1 -281\n1 -159",
"output": "218 215 220 217 222 219 224 221 226 223 228 225 230 227 232 229 234 231 236 233 238 235 240 237 242 239 244 241 246 243 248 245 250 247 252 249 254 251 256 253 258 255 260 257 262 259 264 261 266 263 268 265 270 267 272 269 274 271 276 273 278 275 280 277 282 279 284 281 286 283 288 285 290 287 292 289 294 291 296 293 298 295 300 297 302 299 304 301 306 303 308 305 310 307 312 309 314 311 316 313 318 315 320 317 322 319 324 321 326 323 328 325 330 327 332 329 334 331 336 333 338 335 340 337 342 339 344 341..."
},
{
"input": "6 5\n1 5\n1 5\n1 6\n1 6\n1 6",
"output": "3 4 5 6 1 2"
}
] | 2,000 | 5,836,800 | 0 | 1,676 |
Subsets and Splits