contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
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
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162",
"output": "2 23"
},
{
"input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193",
"output": "2 43"
},
{
"input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111",
"output": "2 57"
},
{
"input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642",
"output": "2 80"
},
{
"input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188",
"output": "2 92"
},
{
"input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233",
"output": "3 101"
},
{
"input": "5\n5 5 5 5 5",
"output": "5 1"
},
{
"input": "3\n1000 1000 1000",
"output": "3 1"
},
{
"input": "1\n1000",
"output": "1 1"
},
{
"input": "1\n1",
"output": "1 1"
},
{
"input": "5\n1 1000 1000 1000 1000",
"output": "4 2"
},
{
"input": "5\n1000 1000 1000 8 7",
"output": "3 3"
}
] | 1,533,569,880 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 248 | 0 | n = int(input())
max_len = 1
cur_len = 1
unique = 1
seq = sorted(list(map(int, input().split())))
for i in range(n - 1):
if seq[i] == seq[i + 1]:
cur_len += 1
if cur_len > max_len:
max_len = cur_len
else:
unique += 1
cur_len = 1
print(max_len, unique)
| Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
Input Specification:
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
Output Specification:
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Demo Input:
['3\n1 2 3\n', '4\n6 5 6 7\n']
Demo Output:
['1 3\n', '2 3\n']
Note:
none | ```python
n = int(input())
max_len = 1
cur_len = 1
unique = 1
seq = sorted(list(map(int, input().split())))
for i in range(n - 1):
if seq[i] == seq[i + 1]:
cur_len += 1
if cur_len > max_len:
max_len = cur_len
else:
unique += 1
cur_len = 1
print(max_len, unique)
``` | 3.938 |
330 | B | Road Construction | PROGRAMMING | 1,300 | [
"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: | 1,000 | [
{
"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"
}
] | 1,621,507,556 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 154 | 0 | # m,n=map(int,input().split())
str=str(input())
m=int(str[0])
n=int(str[2])
prov=set(range(1,m+1))
for i in range(n):
ira=map(int, input().split())
prov=prov-set(ira)
prov=list(prov)[0]
print(m-1)
for i in range(1,m+1):
if i!=prov:
print(prov, i) | Title: Road Construction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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.
Input Specification:
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.
Output Specification:
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.
Demo Input:
['4 1\n1 3\n']
Demo Output:
['3\n1 2\n4 2\n2 3\n']
Note:
This is one possible solution of the example:
These are examples of wrong solutions: | ```python
# m,n=map(int,input().split())
str=str(input())
m=int(str[0])
n=int(str[2])
prov=set(range(1,m+1))
for i in range(n):
ira=map(int, input().split())
prov=prov-set(ira)
prov=list(prov)[0]
print(m-1)
for i in range(1,m+1):
if i!=prov:
print(prov, i)
``` | 0 |
|
45 | A | Codecraft III | PROGRAMMING | 900 | [
"implementation"
] | A. Codecraft III | 2 | 256 | Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understand that.
All the twelve months in Vasya's calendar are named using their usual English names: January, February, March, April, May, June, July, August, September, October, November, December. | The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III. | Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December. | [
"November\n3\n",
"May\n24\n"
] | [
"February\n",
"May\n"
] | none | 0 | [
{
"input": "November\n3",
"output": "February"
},
{
"input": "May\n24",
"output": "May"
},
{
"input": "April\n0",
"output": "April"
},
{
"input": "September\n0",
"output": "September"
},
{
"input": "August\n0",
"output": "August"
},
{
"input": "June\n1",
"output": "July"
},
{
"input": "July\n2",
"output": "September"
},
{
"input": "September\n3",
"output": "December"
},
{
"input": "July\n4",
"output": "November"
},
{
"input": "August\n24",
"output": "August"
},
{
"input": "May\n48",
"output": "May"
},
{
"input": "November\n47",
"output": "October"
},
{
"input": "December\n49",
"output": "January"
},
{
"input": "June\n99",
"output": "September"
},
{
"input": "March\n100",
"output": "July"
},
{
"input": "December\n1",
"output": "January"
},
{
"input": "January\n11",
"output": "December"
},
{
"input": "December\n0",
"output": "December"
},
{
"input": "January\n0",
"output": "January"
},
{
"input": "July\n77",
"output": "December"
},
{
"input": "February\n11",
"output": "January"
},
{
"input": "February\n22",
"output": "December"
},
{
"input": "July\n33",
"output": "April"
},
{
"input": "May\n44",
"output": "January"
},
{
"input": "June\n97",
"output": "July"
}
] | 1,602,149,033 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 11 | 374 | 2,150,400 | l=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
a=l.index(input())
b=int(input())
try:
print(l[a+b%12])
except:
print(l[a-(12-b)]) | Title: Codecraft III
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understand that.
All the twelve months in Vasya's calendar are named using their usual English names: January, February, March, April, May, June, July, August, September, October, November, December.
Input Specification:
The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III.
Output Specification:
Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December.
Demo Input:
['November\n3\n', 'May\n24\n']
Demo Output:
['February\n', 'May\n']
Note:
none | ```python
l=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
a=l.index(input())
b=int(input())
try:
print(l[a+b%12])
except:
print(l[a-(12-b)])
``` | -1 |
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
"output": "2"
},
{
"input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730",
"output": "6"
},
{
"input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624",
"output": "6"
},
{
"input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987",
"output": "6"
},
{
"input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222",
"output": "6"
},
{
"input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485",
"output": "8"
},
{
"input": "1\n1000 1000",
"output": "1"
},
{
"input": "1\n500 1000",
"output": "1"
},
{
"input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11",
"output": "11"
},
{
"input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2",
"output": "0"
},
{
"input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330",
"output": "30"
},
{
"input": "2\n7 7\n5 359",
"output": "2"
},
{
"input": "2\n465 706\n706 706",
"output": "1"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "1"
},
{
"input": "5\n1 1\n1 2\n2 3\n3 4\n4 3",
"output": "1"
},
{
"input": "3\n1 2\n1 2\n1 1",
"output": "1"
}
] | 1,696,328,837 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 280 | 0 | import sys
n=int(input())
res=[]
maxi=-sys.maxsize
for i in range(n):
t=list(map(int,input().split(" ")))
maxi=max(maxi,t[0],t[1])
res.append(t)
ans=[False for i in range(maxi+1)]
for i in range(len(res)):
temp=res[i]
if temp[0]==temp[1]:
continue
else:
ans[temp[1]]=True
count=0
for i in range(1,len(ans)):
if ans[i]==False:
count=count+1
print(count)
| Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n']
Demo Output:
['4\n', '0\n']
Note:
none | ```python
import sys
n=int(input())
res=[]
maxi=-sys.maxsize
for i in range(n):
t=list(map(int,input().split(" ")))
maxi=max(maxi,t[0],t[1])
res.append(t)
ans=[False for i in range(maxi+1)]
for i in range(len(res)):
temp=res[i]
if temp[0]==temp[1]:
continue
else:
ans[temp[1]]=True
count=0
for i in range(1,len(ans)):
if ans[i]==False:
count=count+1
print(count)
``` | 0 |
|
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "7\n7 7 7 7 7 7 7",
"output": "7"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "4"
},
{
"input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99",
"output": "49"
},
{
"input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15",
"output": "50"
},
{
"input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38",
"output": "7"
},
{
"input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87",
"output": "39"
},
{
"input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53",
"output": "37"
},
{
"input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32",
"output": "51"
},
{
"input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80",
"output": "21"
},
{
"input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81",
"output": "37"
},
{
"input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59",
"output": "28"
},
{
"input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94",
"output": "47"
},
{
"input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28",
"output": "15"
},
{
"input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42",
"output": "11"
},
{
"input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35",
"output": "33"
},
{
"input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22",
"output": "37"
},
{
"input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14",
"output": "15"
},
{
"input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77",
"output": "35"
},
{
"input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75",
"output": "42"
},
{
"input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26",
"output": "23"
},
{
"input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78",
"output": "15"
},
{
"input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78",
"output": "13"
},
{
"input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51",
"output": "17"
},
{
"input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59",
"output": "45"
},
{
"input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43",
"output": "53"
},
{
"input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8",
"output": "40"
},
{
"input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54",
"output": "53"
},
{
"input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77",
"output": "55"
},
{
"input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66",
"output": "52"
},
{
"input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89",
"output": "51"
},
{
"input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2",
"output": "53"
},
{
"input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23",
"output": "48"
},
{
"input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25",
"output": "48"
},
{
"input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71",
"output": "58"
},
{
"input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45",
"output": "53"
},
{
"input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17",
"output": "54"
},
{
"input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52",
"output": "49"
},
{
"input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31",
"output": "44"
},
{
"input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74",
"output": "46"
},
{
"input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75",
"output": "53"
},
{
"input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37",
"output": "43"
},
{
"input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82",
"output": "51"
},
{
"input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5",
"output": "47"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 1 3 2 2",
"output": "3"
}
] | 1,644,289,268 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 154 | 0 | n=int(input())
a=list(map(int,input().split()))
b=sum(a);ans=0
if b%2==0:
for x in a:
if x%2==0:ans+=1
else:
for x in a:
if x%2==1:ans+=1
print(ans) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Output Specification:
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
Demo Input:
['1\n1\n', '10\n1 2 2 3 4 4 4 2 2 2\n', '11\n2 2 2 2 2 2 2 2 2 2 99\n']
Demo Output:
['1\n', '8\n', '1\n']
Note:
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | ```python
n=int(input())
a=list(map(int,input().split()))
b=sum(a);ans=0
if b%2==0:
for x in a:
if x%2==0:ans+=1
else:
for x in a:
if x%2==1:ans+=1
print(ans)
``` | 3 |
|
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4",
"output": "9 2"
},
{
"input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8",
"output": "31 68"
},
{
"input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1",
"output": "15 15"
},
{
"input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2",
"output": "27 13"
},
{
"input": "4\n1 3 2 4\n4\n3 1 2 3",
"output": "8 12"
},
{
"input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2",
"output": "15 17"
}
] | 1,639,437,567 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,457,600 | a=[]
b=[]
I=[0]*100005
n=int(input());
for i in range(1,n+1):
l=int(input())
a.append(l)
I[l]=i
v=0
p=0
m=int(input())
for i in range(1,m+1):
l=int(input())
v+=I[l]
p+=n-I[l]+1
print(v,p) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Output Specification:
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n']
Demo Output:
['1 2\n', '2 1\n', '6 6\n']
Note:
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | ```python
a=[]
b=[]
I=[0]*100005
n=int(input());
for i in range(1,n+1):
l=int(input())
a.append(l)
I[l]=i
v=0
p=0
m=int(input())
for i in range(1,m+1):
l=int(input())
v+=I[l]
p+=n-I[l]+1
print(v,p)
``` | -1 |
|
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates.
It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs.
Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance. | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers — the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -979619603",
"output": "1 4"
},
{
"input": "5\n-799147771 -799147773 -799147764 -799147774 -799147770",
"output": "1 2"
},
{
"input": "20\n553280626 553280623 553280627 553280624 553280625 553280618 553280620 553280629 553280637 553280631 553280628 553280636 553280635 553280632 553280634 553280622 553280633 553280621 553280630 553280619",
"output": "1 19"
},
{
"input": "20\n105619866 106083760 106090730 105809555 106115212 105155938 105979518 106075627 106145216 105637844 105925719 105498536 105927000 106155938 106134226 106125969 106130588 105464813 106145509 106114971",
"output": "241 1"
},
{
"input": "10\n570685866 570685854 570685858 570685850 570685856 570685864 570685860 570685852 570685862 570685868",
"output": "2 9"
},
{
"input": "2\n1 1000000000",
"output": "999999999 1"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "1 5"
},
{
"input": "3\n7 10 12",
"output": "2 1"
},
{
"input": "5\n-7 -5 -4 -3 -1",
"output": "1 2"
},
{
"input": "4\n-6 -4 -2 1",
"output": "2 2"
},
{
"input": "4\n3 5 7 8",
"output": "1 1"
},
{
"input": "9\n-9 -8 -7 -6 -5 -4 -3 -2 -1",
"output": "1 8"
},
{
"input": "2\n15 13",
"output": "2 1"
},
{
"input": "2\n14 13",
"output": "1 1"
},
{
"input": "2\n12 13",
"output": "1 1"
},
{
"input": "2\n-1000000000 13265920",
"output": "1013265920 1"
},
{
"input": "2\n8 10",
"output": "2 1"
}
] | 1,490,625,819 | 519 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 13,107,200 | import math
input1=list(map(int,input().split()))
input2=list(map(int,input().split()))
min=1e10
quantity=0
for i in range(len(input2)):
for j in range(i+1,len(input2)):
if math.fabs(input2[i]-input2[j])<min:
quantity=1
min=math.fabs(input2[i]-input2[j])
elif math.fabs(input2[i]-input2[j])==min:
quantity+=1
print(str(int(min)) +" "+ str(quantity))
| Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates.
It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs.
Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.
Input Specification:
The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct.
Output Specification:
Print two integer numbers — the minimal distance and the quantity of pairs with this distance.
Demo Input:
['4\n6 -3 0 4\n', '3\n-2 0 2\n']
Demo Output:
['2 1\n', '2 2\n']
Note:
In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | ```python
import math
input1=list(map(int,input().split()))
input2=list(map(int,input().split()))
min=1e10
quantity=0
for i in range(len(input2)):
for j in range(i+1,len(input2)):
if math.fabs(input2[i]-input2[j])<min:
quantity=1
min=math.fabs(input2[i]-input2[j])
elif math.fabs(input2[i]-input2[j])==min:
quantity+=1
print(str(int(min)) +" "+ str(quantity))
``` | 0 |
|
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 1,691,669,235 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | a=int(input())
k=0
for i in range(a):
c=input()
c=c.split(" ")
x,y=int(c[0]),int(c[1])
if y-x>=2:
k+=1
else:
continue
print(k) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Output Specification:
Print a single integer — the number of rooms where George and Alex can move in.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n']
Demo Output:
['0\n', '2\n']
Note:
none | ```python
a=int(input())
k=0
for i in range(a):
c=input()
c=c.split(" ")
x,y=int(c[0]),int(c[1])
if y-x>=2:
k+=1
else:
continue
print(k)
``` | 3 |
|
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable. | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven. | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"
},
{
"input": "599 97 54 992",
"output": "YES"
},
{
"input": "11 22 18 17",
"output": "NO"
},
{
"input": "1 13 22 11",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "NO"
},
{
"input": "3 1 1 1",
"output": "YES"
},
{
"input": "1000 1000 1000 1000",
"output": "NO"
},
{
"input": "1000 1000 1 1",
"output": "YES"
},
{
"input": "1000 1000 1 400",
"output": "YES"
},
{
"input": "1000 1000 1 1000",
"output": "YES"
},
{
"input": "1000 1000 1 999",
"output": "YES"
},
{
"input": "53 11 3 166",
"output": "YES"
},
{
"input": "313 2 3 385",
"output": "NO"
},
{
"input": "214 9 9 412",
"output": "NO"
},
{
"input": "349 9 5 268",
"output": "YES"
},
{
"input": "611 16 8 153",
"output": "YES"
},
{
"input": "877 13 3 191",
"output": "YES"
},
{
"input": "340 9 9 10",
"output": "YES"
},
{
"input": "31 8 2 205",
"output": "NO"
},
{
"input": "519 3 2 148",
"output": "YES"
},
{
"input": "882 2 21 219",
"output": "NO"
},
{
"input": "982 13 5 198",
"output": "YES"
},
{
"input": "428 13 6 272",
"output": "YES"
},
{
"input": "436 16 14 26",
"output": "YES"
},
{
"input": "628 10 9 386",
"output": "YES"
},
{
"input": "77 33 18 31",
"output": "YES"
},
{
"input": "527 36 4 8",
"output": "YES"
},
{
"input": "128 18 2 169",
"output": "YES"
},
{
"input": "904 4 2 288",
"output": "YES"
},
{
"input": "986 4 3 25",
"output": "YES"
},
{
"input": "134 8 22 162",
"output": "NO"
},
{
"input": "942 42 3 69",
"output": "YES"
},
{
"input": "894 4 9 4",
"output": "YES"
},
{
"input": "953 8 10 312",
"output": "YES"
},
{
"input": "43 8 1 121",
"output": "YES"
},
{
"input": "12 13 19 273",
"output": "NO"
},
{
"input": "204 45 10 871",
"output": "YES"
},
{
"input": "342 69 50 425",
"output": "NO"
},
{
"input": "982 93 99 875",
"output": "NO"
},
{
"input": "283 21 39 132",
"output": "YES"
},
{
"input": "1000 45 83 686",
"output": "NO"
},
{
"input": "246 69 36 432",
"output": "NO"
},
{
"input": "607 93 76 689",
"output": "NO"
},
{
"input": "503 21 24 435",
"output": "NO"
},
{
"input": "1000 45 65 989",
"output": "NO"
},
{
"input": "30 21 2 250",
"output": "YES"
},
{
"input": "1000 49 50 995",
"output": "NO"
},
{
"input": "383 69 95 253",
"output": "YES"
},
{
"input": "393 98 35 999",
"output": "YES"
},
{
"input": "1000 22 79 552",
"output": "NO"
},
{
"input": "268 294 268 154",
"output": "NO"
},
{
"input": "963 465 706 146",
"output": "YES"
},
{
"input": "304 635 304 257",
"output": "NO"
},
{
"input": "4 2 1 6",
"output": "NO"
},
{
"input": "1 51 10 50",
"output": "NO"
},
{
"input": "5 5 4 4",
"output": "YES"
},
{
"input": "3 2 1 1",
"output": "YES"
},
{
"input": "3 4 3 3",
"output": "NO"
},
{
"input": "7 3 4 1",
"output": "YES"
},
{
"input": "101 10 1 1000",
"output": "NO"
},
{
"input": "5 1 1 1",
"output": "YES"
},
{
"input": "5 10 5 5",
"output": "NO"
},
{
"input": "19 1 7 1",
"output": "YES"
},
{
"input": "763 572 745 262",
"output": "YES"
},
{
"input": "1 2 1 1",
"output": "NO"
},
{
"input": "5 1 1 3",
"output": "YES"
},
{
"input": "170 725 479 359",
"output": "NO"
},
{
"input": "6 2 1 7",
"output": "YES"
},
{
"input": "6 2 5 1",
"output": "YES"
},
{
"input": "1 2 2 1",
"output": "NO"
},
{
"input": "24 2 8 3",
"output": "YES"
},
{
"input": "7 3 3 3",
"output": "YES"
},
{
"input": "5 2 2 2",
"output": "YES"
},
{
"input": "3 2 1 2",
"output": "YES"
},
{
"input": "1000 2 200 8",
"output": "NO"
},
{
"input": "3 100 2 100",
"output": "NO"
},
{
"input": "2 999 1 1000",
"output": "NO"
},
{
"input": "2 1 1 1",
"output": "NO"
},
{
"input": "2 3 5 1",
"output": "NO"
},
{
"input": "100 1 5 1",
"output": "YES"
},
{
"input": "7 2 3 3",
"output": "YES"
},
{
"input": "4 1 1 3",
"output": "NO"
},
{
"input": "3 2 2 1",
"output": "YES"
},
{
"input": "1 1 1 2",
"output": "NO"
},
{
"input": "91 8 7 13",
"output": "YES"
},
{
"input": "3 1 2 1",
"output": "NO"
},
{
"input": "5 3 2 3",
"output": "YES"
},
{
"input": "9 6 6 3",
"output": "YES"
}
] | 1,679,047,497 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,t,k,d = map(int,input().split())
p=(t+d)/t
if k*p<n:
print("YES")
else:
print("NO") | Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
Input Specification:
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
Output Specification:
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
Demo Input:
['8 6 4 5\n', '8 6 4 6\n', '10 3 11 4\n', '4 2 1 4\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n', 'YES\n']
Note:
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven. | ```python
n,t,k,d = map(int,input().split())
p=(t+d)/t
if k*p<n:
print("YES")
else:
print("NO")
``` | -1 |
|
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
"output": "9"
},
{
"input": "10\n10 5 8 9 5 6 8 7 2 8",
"output": "46"
},
{
"input": "10\n1 1 1 1 1 1 2 3 4 4",
"output": "14"
},
{
"input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4",
"output": "296"
},
{
"input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2",
"output": "313"
},
{
"input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9",
"output": "298"
},
{
"input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5",
"output": "312"
},
{
"input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2",
"output": "287"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2",
"output": "265"
},
{
"input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9",
"output": "328"
},
{
"input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9",
"output": "324"
},
{
"input": "10\n7 4 5 3 9 1 10 3 4 5",
"output": "34"
},
{
"input": "10\n8 9 6 5 6 4 10 9 1 4",
"output": "39"
},
{
"input": "10\n1 7 1 4 9 10 8 2 9 9",
"output": "40"
},
{
"input": "1\n100000",
"output": "100000"
}
] | 1,696,491,968 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 1,126,400 | # https://codeforces.com/problemset/problem/455/A
from typing import List, Dict
lookup: Dict[int, int] = {}
def solve(n: int) -> int:
if n == 0:
return 0
if n == 1 and 1 in lookup:
return lookup[1]
else:
return 0
return max(solve(n - 1), solve(n - 2) + lookup[n] * n)
def main() -> None:
n: int = int(input())
a: List[int] = list(map(int, input().split()))
for ak in a:
if ak not in lookup:
lookup[ak] = 1
else:
lookup[ak] += 1
print(solve(n))
# 3 3 4 4 5
# 6 6 6 6 6 7 8 9 9 9 9
if __name__ == "__main__":
main()
| Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print a single integer — the maximum number of points that Alex can earn.
Demo Input:
['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n']
Demo Output:
['2\n', '4\n', '10\n']
Note:
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | ```python
# https://codeforces.com/problemset/problem/455/A
from typing import List, Dict
lookup: Dict[int, int] = {}
def solve(n: int) -> int:
if n == 0:
return 0
if n == 1 and 1 in lookup:
return lookup[1]
else:
return 0
return max(solve(n - 1), solve(n - 2) + lookup[n] * n)
def main() -> None:
n: int = int(input())
a: List[int] = list(map(int, input().split()))
for ak in a:
if ak not in lookup:
lookup[ak] = 1
else:
lookup[ak] += 1
print(solve(n))
# 3 3 4 4 5
# 6 6 6 6 6 7 8 9 9 9 9
if __name__ == "__main__":
main()
``` | 0 |
|
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake.
Help Ivan to calculate this number *x*! | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"input": "3 70 58",
"output": "35"
},
{
"input": "5 7 10",
"output": "3"
},
{
"input": "5 30 22",
"output": "10"
},
{
"input": "5 5 6",
"output": "2"
},
{
"input": "2 4 3",
"output": "3"
},
{
"input": "10 10 31",
"output": "3"
},
{
"input": "2 1 1",
"output": "1"
},
{
"input": "10 98 99",
"output": "19"
},
{
"input": "4 10 16",
"output": "5"
},
{
"input": "11 4 8",
"output": "1"
},
{
"input": "5 10 14",
"output": "4"
},
{
"input": "6 7 35",
"output": "7"
},
{
"input": "5 6 7",
"output": "2"
},
{
"input": "4 15 3",
"output": "3"
},
{
"input": "7 48 77",
"output": "16"
},
{
"input": "4 4 10",
"output": "3"
},
{
"input": "4 7 20",
"output": "6"
},
{
"input": "5 2 8",
"output": "2"
},
{
"input": "3 2 3",
"output": "1"
},
{
"input": "14 95 1",
"output": "1"
},
{
"input": "99 82 53",
"output": "1"
},
{
"input": "10 71 27",
"output": "9"
},
{
"input": "5 7 8",
"output": "2"
},
{
"input": "11 77 77",
"output": "12"
},
{
"input": "10 5 28",
"output": "3"
},
{
"input": "7 3 12",
"output": "2"
},
{
"input": "10 15 17",
"output": "3"
},
{
"input": "7 7 7",
"output": "1"
},
{
"input": "4 11 18",
"output": "6"
},
{
"input": "3 3 4",
"output": "2"
},
{
"input": "9 2 10",
"output": "1"
},
{
"input": "100 90 20",
"output": "1"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "12 45 60",
"output": "8"
},
{
"input": "3 94 79",
"output": "47"
},
{
"input": "41 67 34",
"output": "2"
},
{
"input": "9 3 23",
"output": "2"
},
{
"input": "10 20 57",
"output": "7"
},
{
"input": "55 27 30",
"output": "1"
},
{
"input": "100 100 10",
"output": "1"
},
{
"input": "20 8 70",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 9 15",
"output": "5"
},
{
"input": "3 1 3",
"output": "1"
},
{
"input": "2 94 94",
"output": "94"
},
{
"input": "5 3 11",
"output": "2"
},
{
"input": "4 3 2",
"output": "1"
},
{
"input": "12 12 100",
"output": "9"
},
{
"input": "6 75 91",
"output": "25"
},
{
"input": "3 4 3",
"output": "2"
},
{
"input": "3 2 5",
"output": "2"
},
{
"input": "6 5 15",
"output": "3"
},
{
"input": "4 3 6",
"output": "2"
},
{
"input": "3 9 9",
"output": "4"
},
{
"input": "26 93 76",
"output": "6"
},
{
"input": "41 34 67",
"output": "2"
},
{
"input": "6 12 6",
"output": "3"
},
{
"input": "5 20 8",
"output": "5"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "35 66 99",
"output": "4"
},
{
"input": "30 7 91",
"output": "3"
},
{
"input": "5 22 30",
"output": "10"
},
{
"input": "8 19 71",
"output": "10"
},
{
"input": "3 5 6",
"output": "3"
},
{
"input": "5 3 8",
"output": "2"
},
{
"input": "2 4 2",
"output": "2"
},
{
"input": "4 3 7",
"output": "2"
},
{
"input": "5 20 10",
"output": "5"
},
{
"input": "5 100 50",
"output": "25"
},
{
"input": "6 3 10",
"output": "2"
},
{
"input": "2 90 95",
"output": "90"
},
{
"input": "4 8 6",
"output": "3"
},
{
"input": "6 10 3",
"output": "2"
},
{
"input": "3 3 5",
"output": "2"
},
{
"input": "5 33 33",
"output": "11"
},
{
"input": "5 5 8",
"output": "2"
},
{
"input": "19 24 34",
"output": "3"
},
{
"input": "5 5 12",
"output": "3"
},
{
"input": "8 7 10",
"output": "2"
},
{
"input": "5 56 35",
"output": "17"
},
{
"input": "4 3 5",
"output": "1"
},
{
"input": "18 100 50",
"output": "8"
},
{
"input": "5 6 8",
"output": "2"
},
{
"input": "5 98 100",
"output": "33"
},
{
"input": "6 5 8",
"output": "2"
},
{
"input": "3 40 80",
"output": "40"
},
{
"input": "4 8 11",
"output": "4"
},
{
"input": "66 100 99",
"output": "3"
},
{
"input": "17 100 79",
"output": "10"
},
{
"input": "3 2 10",
"output": "2"
},
{
"input": "99 100 99",
"output": "2"
},
{
"input": "21 100 5",
"output": "5"
},
{
"input": "3 10 2",
"output": "2"
},
{
"input": "4 100 63",
"output": "33"
},
{
"input": "2 2 10",
"output": "2"
},
{
"input": "5 94 79",
"output": "31"
},
{
"input": "4 12 5",
"output": "4"
},
{
"input": "5 5 40",
"output": "5"
},
{
"input": "99 99 99",
"output": "1"
},
{
"input": "8 97 44",
"output": "16"
},
{
"input": "11 4 10",
"output": "1"
},
{
"input": "6 3 3",
"output": "1"
},
{
"input": "7 3 4",
"output": "1"
},
{
"input": "8 4 4",
"output": "1"
},
{
"input": "9 4 5",
"output": "1"
},
{
"input": "12 6 6",
"output": "1"
},
{
"input": "4 48 89",
"output": "29"
},
{
"input": "8 3 6",
"output": "1"
},
{
"input": "4 6 3",
"output": "2"
},
{
"input": "5 5 1",
"output": "1"
},
{
"input": "11 6 5",
"output": "1"
},
{
"input": "4 5 4",
"output": "2"
},
{
"input": "6 6 4",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "4 1 3",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "9 4 6",
"output": "1"
},
{
"input": "6 5 6",
"output": "1"
},
{
"input": "2 2 3",
"output": "2"
},
{
"input": "4 5 1",
"output": "1"
},
{
"input": "13 6 7",
"output": "1"
},
{
"input": "14 7 7",
"output": "1"
},
{
"input": "12 97 13",
"output": "8"
},
{
"input": "4 2 9",
"output": "2"
},
{
"input": "10 20 59",
"output": "7"
},
{
"input": "12 34 56",
"output": "7"
},
{
"input": "4 5 9",
"output": "3"
},
{
"input": "2 2 2",
"output": "2"
},
{
"input": "4 66 41",
"output": "22"
}
] | 1,622,308,111 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 15 | 108 | 0 | n,a,b=list(map(int,input().split()))
ans=min(min(a,b),max(a,b)//(n-1))
if n%2==0:
print(max(min(a//(n//2),b//(n//2)),ans))
else:
print(max(min(max(a,b)//(n//2 + 1),min(a,b)//(n//2)),ans)) | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake.
Help Ivan to calculate this number *x*!
Input Specification:
The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Output Specification:
Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake.
Demo Input:
['5 2 3\n', '4 7 10\n']
Demo Output:
['1\n', '3\n']
Note:
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | ```python
n,a,b=list(map(int,input().split()))
ans=min(min(a,b),max(a,b)//(n-1))
if n%2==0:
print(max(min(a//(n//2),b//(n//2)),ans))
else:
print(max(min(max(a,b)//(n//2 + 1),min(a,b)//(n//2)),ans))
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,618,471,106 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | a,b=map(int,input().split())
x=(a*b)/2
print(int(x)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
a,b=map(int,input().split())
x=(a*b)/2
print(int(x))
``` | 3.969 |
864 | C | Bus | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"math"
] | null | null | A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* and so on. Thus, the bus moves from *x*<==<=0 to *x*<==<=*a* and back. Moving from the point *x*<==<=0 to *x*<==<=*a* or from the point *x*<==<=*a* to *x*<==<=0 is called a bus journey. In total, the bus must make *k* journeys.
The petrol tank of the bus can hold *b* liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.
There is a gas station in point *x*<==<=*f*. This point is between points *x*<==<=0 and *x*<==<=*a*. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain *b* liters of gasoline.
What is the minimum number of times the bus needs to refuel at the point *x*<==<=*f* to make *k* journeys? The first journey starts in the point *x*<==<=0. | The first line contains four integers *a*, *b*, *f*, *k* (0<=<<=*f*<=<<=*a*<=≤<=106, 1<=≤<=*b*<=≤<=109, 1<=≤<=*k*<=≤<=104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. | Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1. | [
"6 9 2 4\n",
"6 10 2 4\n",
"6 5 4 3\n"
] | [
"4\n",
"2\n",
"-1\n"
] | In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty.
In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling. | 1,500 | [
{
"input": "6 9 2 4",
"output": "4"
},
{
"input": "6 10 2 4",
"output": "2"
},
{
"input": "6 5 4 3",
"output": "-1"
},
{
"input": "2 2 1 1",
"output": "0"
},
{
"input": "10 4 6 10",
"output": "-1"
},
{
"input": "3 1 1 1",
"output": "-1"
},
{
"input": "2 1 1 1",
"output": "1"
},
{
"input": "1000000 51923215 2302 10000",
"output": "199"
},
{
"input": "10 11 3 2",
"output": "-1"
},
{
"input": "20 50 10 25",
"output": "11"
},
{
"input": "10 10 5 20",
"output": "20"
},
{
"input": "15 65 5 50",
"output": "12"
},
{
"input": "10 19 1 5",
"output": "3"
},
{
"input": "10 19 9 5",
"output": "3"
},
{
"input": "23 46 12 2",
"output": "0"
},
{
"input": "23 46 12 3",
"output": "1"
},
{
"input": "20 20 19 1",
"output": "0"
},
{
"input": "20 23 17 2",
"output": "1"
},
{
"input": "100 70 50 1",
"output": "1"
},
{
"input": "100 70 70 2",
"output": "2"
},
{
"input": "140 480 139 40",
"output": "18"
},
{
"input": "1000000 1000000000 1 1000",
"output": "0"
},
{
"input": "100000 1000000 50000 1000",
"output": "100"
},
{
"input": "1000000 1000000 500000 1000",
"output": "1000"
},
{
"input": "1000000 1000000 500000 10000",
"output": "10000"
},
{
"input": "1000000 2500000 500000 9999",
"output": "4998"
},
{
"input": "1000000 1500000 500000 9999",
"output": "9997"
},
{
"input": "1000000 1500000 500000 10000",
"output": "9998"
},
{
"input": "1000000 1 1 1",
"output": "-1"
},
{
"input": "2 1000000000 1 1",
"output": "0"
},
{
"input": "1000000 1000000000 1 1",
"output": "0"
},
{
"input": "1000000 1 999999 1",
"output": "-1"
},
{
"input": "1000000 1000000000 999999 1",
"output": "0"
},
{
"input": "2 1 1 10000",
"output": "-1"
},
{
"input": "1000000 1 1 10000",
"output": "-1"
},
{
"input": "1000000 1000000000 1 10000",
"output": "10"
},
{
"input": "1000000 1 999999 10000",
"output": "-1"
},
{
"input": "2 1000000000 1 10000",
"output": "0"
},
{
"input": "1000000 1000000000 999999 10000",
"output": "10"
},
{
"input": "10000 78393 3000 9999",
"output": "1428"
},
{
"input": "1000000 8839233 302200 9999",
"output": "1249"
},
{
"input": "900005 3333333 210000 9999",
"output": "3332"
},
{
"input": "6 7 4 2",
"output": "2"
},
{
"input": "3 1 2 1",
"output": "-1"
},
{
"input": "150 100 1 1",
"output": "-1"
},
{
"input": "10 5 6 1",
"output": "-1"
},
{
"input": "51 81 36 38",
"output": "36"
},
{
"input": "100 159 80 2",
"output": "1"
}
] | 1,615,510,104 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 62 | 307,200 | a, b, f, k = map(int, input().split())
start = True
tank = b
refuels = 0
possible = True
while k > 0 and possible:
if k == 1:
# can reach end
if tank >= a:
k -= 1
continue
if start:
# need to refuel
# can reach fuel gas station, and can go from gas station to end
if tank >= f and b >= (a - f):
refuels += 1
else:
possible = False
else:
# we are at end
if tank >= (a - f) and b >= f:
refuels += 1
else:
possible = False
else:
# check if we need to refuel at each step
if start:
if tank < f:
possible = False
elif tank >= (a + (a - f)):
# we don't need to refuel
tank -= a
else:
# need to refuel
tank = (b - (a - f))
refuels += 1
else:
if tank < (a - f):
possible = False
elif tank >= (a + f):
tank -= a
else:
# need to refuel
tank = b - f
refuels += 1
start = not start
k -= 1
if not possible:
print(-1)
else:
print(refuels)
| Title: Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* and so on. Thus, the bus moves from *x*<==<=0 to *x*<==<=*a* and back. Moving from the point *x*<==<=0 to *x*<==<=*a* or from the point *x*<==<=*a* to *x*<==<=0 is called a bus journey. In total, the bus must make *k* journeys.
The petrol tank of the bus can hold *b* liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.
There is a gas station in point *x*<==<=*f*. This point is between points *x*<==<=0 and *x*<==<=*a*. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain *b* liters of gasoline.
What is the minimum number of times the bus needs to refuel at the point *x*<==<=*f* to make *k* journeys? The first journey starts in the point *x*<==<=0.
Input Specification:
The first line contains four integers *a*, *b*, *f*, *k* (0<=<<=*f*<=<<=*a*<=≤<=106, 1<=≤<=*b*<=≤<=109, 1<=≤<=*k*<=≤<=104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.
Output Specification:
Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1.
Demo Input:
['6 9 2 4\n', '6 10 2 4\n', '6 5 4 3\n']
Demo Output:
['4\n', '2\n', '-1\n']
Note:
In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty.
In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling. | ```python
a, b, f, k = map(int, input().split())
start = True
tank = b
refuels = 0
possible = True
while k > 0 and possible:
if k == 1:
# can reach end
if tank >= a:
k -= 1
continue
if start:
# need to refuel
# can reach fuel gas station, and can go from gas station to end
if tank >= f and b >= (a - f):
refuels += 1
else:
possible = False
else:
# we are at end
if tank >= (a - f) and b >= f:
refuels += 1
else:
possible = False
else:
# check if we need to refuel at each step
if start:
if tank < f:
possible = False
elif tank >= (a + (a - f)):
# we don't need to refuel
tank -= a
else:
# need to refuel
tank = (b - (a - f))
refuels += 1
else:
if tank < (a - f):
possible = False
elif tank >= (a + f):
tank -= a
else:
# need to refuel
tank = b - f
refuels += 1
start = not start
k -= 1
if not possible:
print(-1)
else:
print(refuels)
``` | 3 |
|
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "640097987171091792 640097987171091793 640097987171091794"
},
{
"input": "19534350415104721 19534350415104725",
"output": "19534350415104722 19534350415104723 19534350415104724"
},
{
"input": "933700505788726243 933700505788726280",
"output": "933700505788726244 933700505788726245 933700505788726246"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "2 3 4"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "266540997167959130 266540997167959164",
"output": "266540997167959130 266540997167959131 266540997167959132"
},
{
"input": "267367244641009850 267367244641009899",
"output": "267367244641009850 267367244641009851 267367244641009852"
},
{
"input": "268193483524125978 268193483524125993",
"output": "268193483524125978 268193483524125979 268193483524125980"
},
{
"input": "269019726702209402 269019726702209432",
"output": "269019726702209402 269019726702209403 269019726702209404"
},
{
"input": "269845965585325530 269845965585325576",
"output": "269845965585325530 269845965585325531 269845965585325532"
},
{
"input": "270672213058376250 270672213058376260",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492378",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608523",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691962",
"output": "273150934002691930 273150934002691931 273150934002691932"
},
{
"input": "996517375802030516 996517375802030524",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146694",
"output": "997343614685146644 997343614685146645 997343614685146646"
},
{
"input": "998169857863230068 998169857863230083",
"output": "998169857863230068 998169857863230069 998169857863230070"
},
{
"input": "998996101041313492 998996101041313522",
"output": "998996101041313492 998996101041313493 998996101041313494"
},
{
"input": "999822344219396916 999822344219396961",
"output": "999822344219396916 999822344219396917 999822344219396918"
},
{
"input": "648583102513043 648583102513053",
"output": "648583102513044 648583102513045 648583102513046"
},
{
"input": "266540997167959130 266540997167959131",
"output": "-1"
},
{
"input": "267367244641009850 267367244641009850",
"output": "-1"
},
{
"input": "268193483524125978 268193483524125979",
"output": "-1"
},
{
"input": "269019726702209402 269019726702209402",
"output": "-1"
},
{
"input": "269845965585325530 269845965585325530",
"output": "-1"
},
{
"input": "270672213058376250 270672213058376254",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492379",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608508",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691931",
"output": "-1"
},
{
"input": "996517375802030516 996517375802030518",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146644",
"output": "-1"
},
{
"input": "2147483647 2147483649",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "1 7",
"output": "2 3 4"
},
{
"input": "9 12",
"output": "9 11 12"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "11 13",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
}
] | 1,597,487,859 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 307,200 | a, b = map(int, input().split())
superbreak = 0
for i in range(a, b+1):
for j in range(i+1, b+1):
for k in range(j+1, b+1):
j2, i2, k2 = j, i, k
lst = sorted([j, i, k])
while j > 0:
i, j = j, i%j
if i == 1:
while k > 0:
j2, k = k, j2%k
if j2 == 1:
while k2 > 0:
i2, k2 = k2, i2%k2
if i2 != 1:
print(*lst)
superbreak = 1
if superbreak:
break
if superbreak:
break
else:
print(-1) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=<<=*b*<=<<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
Input Specification:
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Output Specification:
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Demo Input:
['2 4\n', '10 11\n', '900000000000000009 900000000000000029\n']
Demo Output:
['2 3 4\n', '-1\n', '900000000000000009 900000000000000010 900000000000000021\n']
Note:
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | ```python
a, b = map(int, input().split())
superbreak = 0
for i in range(a, b+1):
for j in range(i+1, b+1):
for k in range(j+1, b+1):
j2, i2, k2 = j, i, k
lst = sorted([j, i, k])
while j > 0:
i, j = j, i%j
if i == 1:
while k > 0:
j2, k = k, j2%k
if j2 == 1:
while k2 > 0:
i2, k2 = k2, i2%k2
if i2 != 1:
print(*lst)
superbreak = 1
if superbreak:
break
if superbreak:
break
else:
print(-1)
``` | 3 |
|
46 | G | Emperor's Problem | PROGRAMMING | 2,500 | [
"geometry"
] | G. Emperor's Problem | 2 | 256 | It happened at the times of the Great Berland Empire. Once the Emperor dreamt that the Messenger from the gods ordered to build a temple whose base would be a convex polygon with *n* angles. Next morning the Emperor gave the command to build a temple whose base was a regular polygon with *n* angles. The temple was built but soon the Empire was shaken with disasters and crop failures. After an earthquake destroyed the temple, the Emperor understood that he somehow caused the wrath of gods to fall on his people. He ordered to bring the wise man. When the wise man appeared, the Emperor retold the dream to him and asked "Oh the wisest among the wisest, tell me how could I have infuriated the Gods?". "My Lord," the wise man answered. "As far as I can judge, the gods are angry because you were too haste to fulfill their order and didn't listen to the end of the message".
Indeed, on the following night the Messenger appeared again. He reproached the Emperor for having chosen an imperfect shape for the temple. "But what shape can be more perfect than a regular polygon!?" cried the Emperor in his dream. To that the Messenger gave a complete and thorough reply.
- All the vertices of the polygon should be positioned in the lattice points. - All the lengths of its sides should be different. - From the possible range of such polygons a polygon which maximum side is minimal possible must be chosen.
You are an obedient architect who is going to make the temple's plan. Note that the polygon should be simple (having a border without self-intersections and overlapping) and convex, however, it is acceptable for three consecutive vertices to lie on the same line. | The first line contains the single number *n* (3<=≤<=*n*<=≤<=10000). | Print "YES" (without quotes) in the first line if it is possible to build a polygon possessing the needed qualities. In the next *n* lines print integer coordinates of the polygon vertices in the order in which they would be passed counter clockwise. The absolute value of the coordinates shouldn't exceed 109. No two vertices can coincide. It is permitted to print any of the possible solutions. Print "NO" if to build the polygon is impossible. | [
"3\n",
"3\n"
] | [
"YES\n0 0\n1 0\n0 2\n",
"YES\n0 1\n-1 0\n-1 -1\n"
] | none | 0 | [] | 1,584,712,098 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | def main():
n = int(input())
print("YES")
if n == 3:
return print("0 0\n1 0\n0 2")
f = (n - 2) * (n - 1) // 2
k = f // 2
for i in range(1, n - 1):
print(0, k)
k -= i
if f % 2 == 0:
k -= 1
print(0, k)
print(1, 0)
main()
| Title: Emperor's Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
It happened at the times of the Great Berland Empire. Once the Emperor dreamt that the Messenger from the gods ordered to build a temple whose base would be a convex polygon with *n* angles. Next morning the Emperor gave the command to build a temple whose base was a regular polygon with *n* angles. The temple was built but soon the Empire was shaken with disasters and crop failures. After an earthquake destroyed the temple, the Emperor understood that he somehow caused the wrath of gods to fall on his people. He ordered to bring the wise man. When the wise man appeared, the Emperor retold the dream to him and asked "Oh the wisest among the wisest, tell me how could I have infuriated the Gods?". "My Lord," the wise man answered. "As far as I can judge, the gods are angry because you were too haste to fulfill their order and didn't listen to the end of the message".
Indeed, on the following night the Messenger appeared again. He reproached the Emperor for having chosen an imperfect shape for the temple. "But what shape can be more perfect than a regular polygon!?" cried the Emperor in his dream. To that the Messenger gave a complete and thorough reply.
- All the vertices of the polygon should be positioned in the lattice points. - All the lengths of its sides should be different. - From the possible range of such polygons a polygon which maximum side is minimal possible must be chosen.
You are an obedient architect who is going to make the temple's plan. Note that the polygon should be simple (having a border without self-intersections and overlapping) and convex, however, it is acceptable for three consecutive vertices to lie on the same line.
Input Specification:
The first line contains the single number *n* (3<=≤<=*n*<=≤<=10000).
Output Specification:
Print "YES" (without quotes) in the first line if it is possible to build a polygon possessing the needed qualities. In the next *n* lines print integer coordinates of the polygon vertices in the order in which they would be passed counter clockwise. The absolute value of the coordinates shouldn't exceed 109. No two vertices can coincide. It is permitted to print any of the possible solutions. Print "NO" if to build the polygon is impossible.
Demo Input:
['3\n', '3\n']
Demo Output:
['YES\n0 0\n1 0\n0 2\n', 'YES\n0 1\n-1 0\n-1 -1\n']
Note:
none | ```python
def main():
n = int(input())
print("YES")
if n == 3:
return print("0 0\n1 0\n0 2")
f = (n - 2) * (n - 1) // 2
k = f // 2
for i in range(1, n - 1):
print(0, k)
k -= i
if f % 2 == 0:
k -= 1
print(0, k)
print(1, 0)
main()
``` | 0 |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)? | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north). | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSSWESNSSEESNSESWSWNSWESNENWNWEE",
"output": "4"
},
{
"input": "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
"output": "41"
},
{
"input": "34 -1000000000 -1000000000 -999999983 -1000000000\nEEEEESSEWNSSSESWEWSWESEWSEESNEWEEE",
"output": "-1"
},
{
"input": "1 0 0 0 -1\nS",
"output": "1"
},
{
"input": "1 5 5 5 6\nE",
"output": "-1"
},
{
"input": "15 1 1 1 2\nNNNNNNNNNNNNNNN",
"output": "1"
},
{
"input": "11 1 1 1 2\nNNNNNNNNNNN",
"output": "1"
}
] | 1,653,909,933 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 218 | 204,800 | inputs = [int(num) for num in input().split()]
t = inputs[0]
sx = inputs[1]
sy = inputs[2]
ex = inputs[3]
ey = inputs[4]
s = input()
if(ex>=sx):
right = abs(ex-sx)
left=0
else:
left = abs(sx-ex)
right=0
if(ey>=sy):
up = abs(ey-sy)
down =0
else:
up=0
down = abs(ey-sy)
time=0
flag=0
for i in range(0,len(s)):
if(s[i]=='S' and down>0):
down-=1
elif(s[i]=='N'and up>0):
up-=1
elif(s[i]=='E'and right>0):
right-=1
elif(s[i]=='W' and left>0):
left-=1
time+=1
if(down==0 and up==0 and left==0 and right==0):
flag=1
break
if(flag==1):
print(time)
else:
print(-1) | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
Input Specification:
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
Output Specification:
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
Demo Input:
['5 0 0 1 1\nSESNW\n', '10 5 3 3 6\nNENSWESNEE\n']
Demo Output:
['4\n', '-1\n']
Note:
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | ```python
inputs = [int(num) for num in input().split()]
t = inputs[0]
sx = inputs[1]
sy = inputs[2]
ex = inputs[3]
ey = inputs[4]
s = input()
if(ex>=sx):
right = abs(ex-sx)
left=0
else:
left = abs(sx-ex)
right=0
if(ey>=sy):
up = abs(ey-sy)
down =0
else:
up=0
down = abs(ey-sy)
time=0
flag=0
for i in range(0,len(s)):
if(s[i]=='S' and down>0):
down-=1
elif(s[i]=='N'and up>0):
up-=1
elif(s[i]=='E'and right>0):
right-=1
elif(s[i]=='W' and left>0):
left-=1
time+=1
if(down==0 and up==0 and left==0 and right==0):
flag=1
break
if(flag==1):
print(time)
else:
print(-1)
``` | 3 |
|
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874",
"output": "11 9 8 2 2 1 5 5 0 0 1"
},
{
"input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897",
"output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11"
},
{
"input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9",
"output": "1 1 2 2 3 3 4 4 5"
},
{
"input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1",
"output": "1"
},
{
"input": "5 1\n1 3 3 3 5\n3",
"output": "4"
},
{
"input": "4 5\n1 1 1 4\n1 5 5 4 3",
"output": "3 4 4 4 3"
},
{
"input": "5 4\n0 5 5 5 6\n5 1 6 3",
"output": "4 1 5 1"
},
{
"input": "1 3\n0\n-1 0 1",
"output": "0 1 1"
},
{
"input": "96 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1",
"output": "96"
},
{
"input": "7 1\n1 2 3 4 5 6 7\n1",
"output": "1"
},
{
"input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000",
"output": "7 13 7 13 7 13 7 13 7 13 7 13 7"
},
{
"input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5",
"output": "1 2 3 4 5"
},
{
"input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1",
"output": "3 3 3 3 3 3 3 3"
},
{
"input": "1 1\n-11111\n-5938",
"output": "1"
},
{
"input": "1 1\n1\n400000009",
"output": "1"
},
{
"input": "1 1\n1\n300000009",
"output": "1"
},
{
"input": "1 1\n1\n200000009",
"output": "1"
},
{
"input": "1 1\n1\n200000003",
"output": "1"
}
] | 1,626,202,118 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 6,963,200 | def processo(e, seq,l, r):
if r == l:
return 0
if e >= seq[r-1]:
return r
if e < seq[l]:
return 0
k = int((r+l)/2)
midi = seq[k]
if e == midi:
return k + 1
elif e < midi:
return processo(e, seq, l, k)
elif e > midi:
return processo(e,seq, k, r )
| Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Output Specification:
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
Demo Input:
['5 4\n1 3 5 7 9\n6 4 2 8\n', '5 5\n1 2 1 2 5\n3 1 4 1 5\n']
Demo Output:
['3 2 1 4\n', '4 2 4 2 5\n']
Note:
none | ```python
def processo(e, seq,l, r):
if r == l:
return 0
if e >= seq[r-1]:
return r
if e < seq[l]:
return 0
k = int((r+l)/2)
midi = seq[k]
if e == midi:
return k + 1
elif e < midi:
return processo(e, seq, l, k)
elif e > midi:
return processo(e,seq, k, r )
``` | 0 |
|
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"input": "2 3",
"output": "2 0 4"
},
{
"input": "5 6",
"output": "5 0 1"
},
{
"input": "4 4",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
},
{
"input": "6 4",
"output": "1 1 4"
},
{
"input": "1 4",
"output": "2 0 4"
},
{
"input": "5 5",
"output": "0 6 0"
},
{
"input": "4 5",
"output": "4 0 2"
},
{
"input": "4 3",
"output": "3 0 3"
},
{
"input": "1 5",
"output": "2 1 3"
},
{
"input": "6 5",
"output": "1 0 5"
},
{
"input": "2 2",
"output": "0 6 0"
},
{
"input": "1 3",
"output": "1 1 4"
},
{
"input": "3 6",
"output": "4 0 2"
},
{
"input": "3 1",
"output": "4 1 1"
},
{
"input": "3 2",
"output": "4 0 2"
},
{
"input": "3 5",
"output": "3 1 2"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "6 2",
"output": "2 1 3"
},
{
"input": "4 1",
"output": "4 0 2"
},
{
"input": "5 2",
"output": "3 0 3"
},
{
"input": "4 2",
"output": "3 1 2"
},
{
"input": "2 1",
"output": "5 0 1"
},
{
"input": "6 1",
"output": "3 0 3"
},
{
"input": "4 6",
"output": "4 1 1"
},
{
"input": "2 6",
"output": "3 1 2"
},
{
"input": "3 4",
"output": "3 0 3"
},
{
"input": "1 2",
"output": "1 0 5"
},
{
"input": "6 6",
"output": "0 6 0"
},
{
"input": "5 4",
"output": "2 0 4"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
}
] | 1,659,316,307 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 46 | 0 | a, b = list(map(int,input().split(" ")))
w, d, l = 0, 0, 0
for i in range(1,7):
t1, t2 = abs(i - a), abs(i - b)
if(t1 < t2):
w += 1
elif(t1 == t2):
d += 1
else:
l += 1
print(w,d,l)
| Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
Input Specification:
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Output Specification:
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
Demo Input:
['2 5\n', '2 4\n']
Demo Output:
['3 0 3\n', '2 1 3\n']
Note:
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | ```python
a, b = list(map(int,input().split(" ")))
w, d, l = 0, 0, 0
for i in range(1,7):
t1, t2 = abs(i - a), abs(i - b)
if(t1 < t2):
w += 1
elif(t1 == t2):
d += 1
else:
l += 1
print(w,d,l)
``` | 3 |
|
557 | B | Pasha and Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"math",
"sortings"
] | null | null | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends. | The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters. | Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"2 4\n1 1 1 1\n",
"3 18\n4 4 4 2 2 2\n",
"1 5\n2 3\n"
] | [
"3",
"18",
"4.5"
] | Pasha also has candies that he is going to give to girls but that is another task... | 1,000 | [
{
"input": "2 4\n1 1 1 1",
"output": "3.0000000000"
},
{
"input": "3 18\n4 4 4 2 2 2",
"output": "18.0000000000"
},
{
"input": "1 5\n2 3",
"output": "4.5000000000"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 1 1 1 1",
"output": "6.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 2 2 2 2",
"output": "12.0000000000"
},
{
"input": "4 1\n3 3 3 3 4 4 4 4",
"output": "1.0000000000"
},
{
"input": "2 19\n3 3 5 5",
"output": "15.0000000000"
},
{
"input": "3 31\n3 3 3 5 5 5",
"output": "22.5000000000"
},
{
"input": "5 15\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "5 14\n2 3 4 1 2 4 5 3 5 10",
"output": "14.0000000000"
},
{
"input": "5 16\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "1 100\n1 200",
"output": "3.0000000000"
},
{
"input": "1 1\n1 1",
"output": "1.0000000000"
},
{
"input": "2 1000000000\n1 1 1 100",
"output": "3.0000000000"
},
{
"input": "4 30\n3 3 3 3 4 5 6 7",
"output": "24.0000000000"
},
{
"input": "2 100\n1 1 1 10",
"output": "3.0000000000"
},
{
"input": "3 18\n1 1 1 1 1 5",
"output": "4.5000000000"
}
] | 1,441,197,166 | 1,066 | Python 3 | OK | TESTS | 50 | 233 | 16,896,000 | def main():
n, w = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
a = sorted(a)
x = w / (3*n)
if (x <= a[0] and 2*x <= a[n]):
print(w)
else:
print(3*min(a[0], a[n]/2)*n)
if __name__ == "__main__":
main()
| Title: Pasha and Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends.
Input Specification:
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters.
Output Specification:
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['2 4\n1 1 1 1\n', '3 18\n4 4 4 2 2 2\n', '1 5\n2 3\n']
Demo Output:
['3', '18', '4.5']
Note:
Pasha also has candies that he is going to give to girls but that is another task... | ```python
def main():
n, w = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
a = sorted(a)
x = w / (3*n)
if (x <= a[0] and 2*x <= a[n]):
print(w)
else:
print(3*min(a[0], a[n]/2)*n)
if __name__ == "__main__":
main()
``` | 3 |
|
355 | A | Vasya and Digital Root | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=<<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10.
For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3.
Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000).
Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist. | The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). | In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. | [
"4 4\n",
"5 1\n",
"1 0\n"
] | [
"5881\n",
"36172\n",
"0\n"
] | For the first test sample *dr*(5881) = *dr*(22) = 4.
For the second test sample *dr*(36172) = *dr*(19) = *dr*(10) = 1. | 500 | [
{
"input": "4 4",
"output": "5881"
},
{
"input": "5 1",
"output": "36172"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "8 7",
"output": "49722154"
},
{
"input": "487 0",
"output": "No solution"
},
{
"input": "1000 5",
"output": "8541939554067890866522280268745476436249986028349767396372181155840878549622667946850256234534972693110974918858266403731194206972478044933297639886527448596769215803533001453375065914421371731616055420973164037664278812596299678416020519508892847037891229851414508562230407367486468987019052183250172396304562086008837592345867873765321840214188417303688776985319268802181355472294386101622570417737061113209187893810568585166094583478900129912239498334853726870963804475563182775380744565964067602555515611220..."
},
{
"input": "22 9",
"output": "1583569962049529809017"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "13 5",
"output": "1381199538344"
},
{
"input": "100 4",
"output": "6334594910586850938286642284598905674550356974741186703111536643493065423553455569335256292313330478"
},
{
"input": "123 6",
"output": "928024873067884441426263446866614165147002631091527531801777528825238463822318502518751375671158771476735217071878592158343"
},
{
"input": "1000 1",
"output": "8286301124628812353504240076754144327937426329149605334362213339655339076564408659154706137278060590992944494591503606137350736487608756923833530346502466262820452589925067370165968733865814927433418675056573256434073937686361155637721866942352171450747045834987797118866710087297111065178077368748085213082452303815796793489599773148508108295035303578345492871662297456131736137780231762177312635688688714815857818196180724774924848693916003108422682889382923194020205691379066085156078824413573001257245677878..."
},
{
"input": "2 0",
"output": "No solution"
},
{
"input": "734 9",
"output": "5509849803670339733829077693143634799621955270111335907079347964026719040571586127009915057683769302171314977999063915868539391500563742827163274052101515706840652002966522709635011152141196057419086708927225560622675363856445980167733179728663010064912099615416068178748694469047950713834326493597331720572208847439692450327661109751421257198843242305082523510866664350537162158359215265173356615680034808012842300294492281197211603826994471586252822908597603049772690875861970190564793056757768783375525854981..."
},
{
"input": "678 8",
"output": "3301967993506605598118564082793505826927835671912383741219911930496842130418974223636865915672261642456247377827650506657877850580145623499927271391838907804651235401527392426584047219626357010023552497909436550723659221336486898100975437974320483591226280567200180225706948265372905918038750624429412331582504280650041845010449084641487447573160867860208332424835101416924485616494780952529083292227777966546236453553361466209621076748915774965082618181512654546592160909206650552581723190500273752213154329310..."
},
{
"input": "955 7",
"output": "4875434946733568640983465009954221247849488705968833681097920555785434899849497268074436910608289709905212840964404347113134616236366794383005890642796609027376389191650656756216171636192669456464756898600086886269167613161503734300581107122411830728903919402846291350458047685924037685489537178939190129043010338580479169957795695942333133962326316127076129681213167918954090336000635320714955444899171270809399782177230616239894234246885245402806465700760528496316658100834632585364274381823984214942419830421..."
},
{
"input": "893 3",
"output": "3154491812688062338683413382839715419754844054478504300541293341098785797116419835470049101334759365561276155814822131363018164033585874216523127145546903121862283071300185033613164338905028463571111541628115658108609505120357131336651371062955497690723492519748325195227665653129911625684144804656937323976632567108677478936761775342496303735237936919652618323430255701996987753367609559178855599470625167628439986055634187527493497208780060336400261449926469512996188738133678473883670714775784527941804249702..."
},
{
"input": "998 2",
"output": "8948712698877635315965401396781625629035528026219922557326466734622505808493494219669540192792500692387387200924494124219975316993592377253517258369463882172533672158172302951620486954085880606055358057621166471042557383036617719864238933843342304818076672889894622975857106353903546493307325157763617269195570831067239463586554245706859061059010215520785892192165179414199200952765077228454366556358805840526959104496983177402562569401945586771345953166346316987259989961516385311376707950154520512125143059966..."
},
{
"input": "960 6",
"output": "7291446744949293530598651243840704118065364362420848463900543089429494124955982767375712583398715647208330285855809398453361266463042342917037983463277320070057956978767965467358862479678812136400444143489366786562672928727263605336304125661306952421127807059398289873947797478996261161224877129724944902005212399176751167053423457968483336961277157597291131065544350665072172392437597673561840137077580044817979332136630042866681837917711758227272499659805765131669208911408670581308412686469802437930679571593..."
}
] | 1,508,709,965 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 93 | 23,142,400 | def df(s):
x = sum(list(map(int, list(str(s)))))
if x < 10:
return x
return df(x)
def main():
def f(k, d):
if k == 1:
return str(d)
if d == 1:
x = "9" * (k - 1)
xx = int(x) * 10
for i in range(9):
if df(xx + i) == d:
return xx + i
s = "No Solution"
if d // 2 != 0:
s = f(k // 2, d // 2) + f((k + 1) // 2, (d + 1) // 2)
return s
(k, d) = map(int, input().split(' '))
return f(k, d)
print(main())
| Title: Vasya and Digital Root
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=<<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10.
For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3.
Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000).
Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist.
Input Specification:
The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9).
Output Specification:
In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes.
Demo Input:
['4 4\n', '5 1\n', '1 0\n']
Demo Output:
['5881\n', '36172\n', '0\n']
Note:
For the first test sample *dr*(5881) = *dr*(22) = 4.
For the second test sample *dr*(36172) = *dr*(19) = *dr*(10) = 1. | ```python
def df(s):
x = sum(list(map(int, list(str(s)))))
if x < 10:
return x
return df(x)
def main():
def f(k, d):
if k == 1:
return str(d)
if d == 1:
x = "9" * (k - 1)
xx = int(x) * 10
for i in range(9):
if df(xx + i) == d:
return xx + i
s = "No Solution"
if d // 2 != 0:
s = f(k // 2, d // 2) + f((k + 1) // 2, (d + 1) // 2)
return s
(k, d) = map(int, input().split(' '))
return f(k, d)
print(main())
``` | -1 |
|
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem. | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}. | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",
"output": "2"
},
{
"input": "51 52",
"output": "2"
},
{
"input": "47 52",
"output": "2"
},
{
"input": "38 98",
"output": "2"
},
{
"input": "30 37",
"output": "2"
},
{
"input": "56 92",
"output": "2"
},
{
"input": "900000000 1000000000",
"output": "2"
},
{
"input": "37622224 162971117",
"output": "2"
},
{
"input": "760632746 850720703",
"output": "2"
},
{
"input": "908580370 968054552",
"output": "2"
},
{
"input": "951594860 953554446",
"output": "2"
},
{
"input": "347877978 913527175",
"output": "2"
},
{
"input": "620769961 988145114",
"output": "2"
},
{
"input": "820844234 892579936",
"output": "2"
},
{
"input": "741254764 741254768",
"output": "2"
},
{
"input": "80270976 80270977",
"output": "2"
},
{
"input": "392602363 392602367",
"output": "2"
},
{
"input": "519002744 519002744",
"output": "519002744"
},
{
"input": "331900277 331900277",
"output": "331900277"
},
{
"input": "419873015 419873018",
"output": "2"
},
{
"input": "349533413 349533413",
"output": "349533413"
},
{
"input": "28829775 28829776",
"output": "2"
},
{
"input": "568814539 568814539",
"output": "568814539"
},
{
"input": "720270740 720270743",
"output": "2"
},
{
"input": "871232720 871232722",
"output": "2"
},
{
"input": "305693653 305693653",
"output": "305693653"
},
{
"input": "634097178 634097179",
"output": "2"
},
{
"input": "450868287 450868290",
"output": "2"
},
{
"input": "252662256 252662260",
"output": "2"
},
{
"input": "575062045 575062049",
"output": "2"
},
{
"input": "273072892 273072894",
"output": "2"
},
{
"input": "770439256 770439256",
"output": "770439256"
},
{
"input": "2 1000000000",
"output": "2"
},
{
"input": "6 8",
"output": "2"
},
{
"input": "2 879190747",
"output": "2"
},
{
"input": "5 5",
"output": "5"
},
{
"input": "999999937 999999937",
"output": "999999937"
},
{
"input": "3 3",
"output": "3"
},
{
"input": "5 100",
"output": "2"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 18",
"output": "2"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "39916801 39916801",
"output": "39916801"
},
{
"input": "3 8",
"output": "2"
},
{
"input": "13 13",
"output": "13"
},
{
"input": "4 8",
"output": "2"
},
{
"input": "3 12",
"output": "2"
},
{
"input": "6 12",
"output": "2"
},
{
"input": "999999103 999999103",
"output": "999999103"
},
{
"input": "100000007 100000007",
"output": "100000007"
},
{
"input": "3 99",
"output": "2"
},
{
"input": "999999733 999999733",
"output": "999999733"
},
{
"input": "5 10",
"output": "2"
},
{
"input": "982451653 982451653",
"output": "982451653"
},
{
"input": "999900001 1000000000",
"output": "2"
},
{
"input": "999727999 999727999",
"output": "999727999"
},
{
"input": "2 999999999",
"output": "2"
},
{
"input": "242 244",
"output": "2"
},
{
"input": "3 10",
"output": "2"
},
{
"input": "15 27",
"output": "2"
},
{
"input": "998244353 998244353",
"output": "998244353"
},
{
"input": "5 15",
"output": "2"
},
{
"input": "999999797 999999797",
"output": "999999797"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "999999929 999999929",
"output": "999999929"
},
{
"input": "3 111111",
"output": "2"
},
{
"input": "12 18",
"output": "2"
},
{
"input": "479001599 479001599",
"output": "479001599"
},
{
"input": "10000019 10000019",
"output": "10000019"
},
{
"input": "715827883 715827883",
"output": "715827883"
},
{
"input": "999992977 999992977",
"output": "999992977"
},
{
"input": "11 11",
"output": "11"
},
{
"input": "29 29",
"output": "29"
},
{
"input": "1000003 1000003",
"output": "1000003"
},
{
"input": "6 15",
"output": "2"
},
{
"input": "1200007 1200007",
"output": "1200007"
},
{
"input": "3 1000000000",
"output": "2"
},
{
"input": "990000023 990000023",
"output": "990000023"
},
{
"input": "1717 1717",
"output": "1717"
},
{
"input": "141650963 141650963",
"output": "141650963"
},
{
"input": "1002523 1002523",
"output": "1002523"
},
{
"input": "900000011 900000011",
"output": "900000011"
},
{
"input": "104729 104729",
"output": "104729"
},
{
"input": "4 12",
"output": "2"
},
{
"input": "100003 100003",
"output": "100003"
},
{
"input": "17 17",
"output": "17"
},
{
"input": "10 100",
"output": "2"
}
] | 1,640,972,947 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 93 | 109 | 0 | Homura = [int(i) for i in input().split()]
l = Homura[0]
r = Homura[1]
if l == r:
print(l)
else:
print(2)
| Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem.
Input Specification:
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Output Specification:
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
Demo Input:
['19 29\n', '3 6\n']
Demo Output:
['2\n', '3\n']
Note:
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}. | ```python
Homura = [int(i) for i in input().split()]
l = Homura[0]
r = Homura[1]
if l == r:
print(l)
else:
print(2)
``` | 3 |
|
8 | B | Obsession with Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"graphs",
"implementation"
] | B. Obsession with Robots | 2 | 64 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. | The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. | In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). | [
"LLUUUR\n",
"RRUULLDD\n"
] | [
"OK\n",
"BUG\n"
] | none | 0 | [
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"output": "OK"
},
{
"input": "LD",
"output": "OK"
},
{
"input": "RUL",
"output": "BUG"
},
{
"input": "ULD",
"output": "BUG"
},
{
"input": "DDR",
"output": "OK"
},
{
"input": "RRDD",
"output": "OK"
},
{
"input": "RRLR",
"output": "BUG"
},
{
"input": "RRDL",
"output": "BUG"
},
{
"input": "LRUD",
"output": "BUG"
},
{
"input": "RDRLL",
"output": "BUG"
},
{
"input": "DRDRD",
"output": "OK"
},
{
"input": "ULURL",
"output": "BUG"
},
{
"input": "LUUDU",
"output": "BUG"
},
{
"input": "RDLUR",
"output": "BUG"
},
{
"input": "DLDLDDRR",
"output": "OK"
},
{
"input": "RDRDDD",
"output": "OK"
},
{
"input": "UULLDLUR",
"output": "BUG"
},
{
"input": "LULU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "URRRRRURRURUURRRRRDDDDLDDDRDDDDLLDLL",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "UL",
"output": "OK"
},
{
"input": "UDR",
"output": "BUG"
},
{
"input": "DDDR",
"output": "OK"
},
{
"input": "UUUDU",
"output": "BUG"
},
{
"input": "LULULL",
"output": "OK"
},
{
"input": "DLURUUU",
"output": "BUG"
},
{
"input": "UURUURRUUU",
"output": "OK"
},
{
"input": "DDDDRDDLDDDDDDDRDDLD",
"output": "OK"
},
{
"input": "URRRLULUURURLRLLLLULLRLRURLULRLULLULRRUU",
"output": "BUG"
},
{
"input": "RURRRRLURRRURRUURRRRRRRRDDULULRRURRRDRRRRRRRRRRLDR",
"output": "BUG"
},
{
"input": "RLRRRRRDRRDRRRRDLRRRRRRRDLRLDDLRRRRLDLDRDRRRRDRDRDRDLRRURRLRRRRDRRRRRRRRLDDRLRRDRRRRRRRDRDRLDRDDDRDR",
"output": "BUG"
},
{
"input": "DDUL",
"output": "BUG"
},
{
"input": "UUULLLLRDD",
"output": "BUG"
},
{
"input": "LLLLLLLLRRRRDDDDDDDUUUUUU",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDUUUUUUUUUUUURRRRRRRRRRRRRLLLLLLLLLLLLLLL",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "BUG"
},
{
"input": "DLUR",
"output": "BUG"
},
{
"input": "UUUURDLLLL",
"output": "BUG"
},
{
"input": "RRRRRRRRRRRURLLLLLLLLLLLL",
"output": "BUG"
},
{
"input": "LLLLLLLLLLLLLLLLLLLLLLLLLLRUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "BUG"
},
{
"input": "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BUG"
},
{
"input": "DDLDRRR",
"output": "BUG"
},
{
"input": "RRUULLD",
"output": "BUG"
},
{
"input": "LUUUULLLLDDDDRRRD",
"output": "BUG"
},
{
"input": "DDDDLLLDDDRRRUURRRR",
"output": "BUG"
},
{
"input": "DDDDDDDLLDDRRURRRRRRR",
"output": "BUG"
},
{
"input": "DDDDDDDDDDLLLLLLLLLLLDDDDDDDDDDDRRRRRRRRRRRUUUUUUUUUURRRRRRRRRR",
"output": "BUG"
},
{
"input": "DDDLLLLLLLDDDDDDDRRRRRRRUUUUUURRR",
"output": "BUG"
},
{
"input": "RRRUUULLLDD",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLLLLDDDDRRRRUUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BUG"
},
{
"input": "RRRRRRRRRRRDDDDDDDDDDDDDDDDDDDRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLUUUUUUUUUUU",
"output": "BUG"
}
] | 1,585,464,962 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 218 | 307,200 | # maa chudaaye duniya
d = [[0,1], [0, -1], [1, 0], [-1, 0], [0, 0]]
path = input()
vis = []
cur = [0, 0]
f = True
for p in path:
prev = cur
if p == 'L': index = 0
elif p == 'R' : index = 1
elif p == 'U' : index = 2
else: index = 3
cur = [cur[0] + d[index][0], cur[1] + d[index][1]]
if cur in vis:
f = False
print('BUG')
break
for dx, dy in d:
vis.append([prev[0] + dx, prev[1] + dy])
if f:
print('OK') | Title: Obsession with Robots
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
Input Specification:
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
Output Specification:
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
Demo Input:
['LLUUUR\n', 'RRUULLDD\n']
Demo Output:
['OK\n', 'BUG\n']
Note:
none | ```python
# maa chudaaye duniya
d = [[0,1], [0, -1], [1, 0], [-1, 0], [0, 0]]
path = input()
vis = []
cur = [0, 0]
f = True
for p in path:
prev = cur
if p == 'L': index = 0
elif p == 'R' : index = 1
elif p == 'U' : index = 2
else: index = 3
cur = [cur[0] + d[index][0], cur[1] + d[index][1]]
if cur in vis:
f = False
print('BUG')
break
for dx, dy in d:
vis.append([prev[0] + dx, prev[1] + dy])
if f:
print('OK')
``` | 3.943211 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,664,377,900 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | y,w=map(int,input().split())
mx=max(y,w)
a,b=0,0
mx=6-mx+1
if(mx==0):
a=0
b=1
elif(mx==1):
a=1
b=6
elif(mx==2):
a=1
b=3
elif(mx==3):
a=1
b=2
elif(mx==4):
a=2
b=3
elif(mx==5):
a=5
b=6
else:
a,b=1,1
print(a,end='')
print( '/' , end='')
print(b)
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
y,w=map(int,input().split())
mx=max(y,w)
a,b=0,0
mx=6-mx+1
if(mx==0):
a=0
b=1
elif(mx==1):
a=1
b=6
elif(mx==2):
a=1
b=3
elif(mx==3):
a=1
b=2
elif(mx==4):
a=2
b=3
elif(mx==5):
a=5
b=6
else:
a,b=1,1
print(a,end='')
print( '/' , end='')
print(b)
``` | 3.954 |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10000",
"output": "10800100"
},
{
"input": "2333",
"output": "310060"
},
{
"input": "9139",
"output": "10134010"
},
{
"input": "9859",
"output": "10422001"
},
{
"input": "5987",
"output": "2221201"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "46"
},
{
"input": "5",
"output": "55"
},
{
"input": "7",
"output": "73"
},
{
"input": "9",
"output": "91"
},
{
"input": "10",
"output": "109"
},
{
"input": "15",
"output": "154"
},
{
"input": "51",
"output": "613"
},
{
"input": "99",
"output": "1414"
},
{
"input": "138",
"output": "2224"
},
{
"input": "233",
"output": "5050"
},
{
"input": "666",
"output": "27100"
},
{
"input": "1234",
"output": "110206"
},
{
"input": "3567",
"output": "1033003"
},
{
"input": "4445",
"output": "1221301"
},
{
"input": "5689",
"output": "2114002"
},
{
"input": "6666",
"output": "3102004"
},
{
"input": "7777",
"output": "5300200"
},
{
"input": "8888",
"output": "10110061"
},
{
"input": "9411",
"output": "10214200"
},
{
"input": "5539",
"output": "2101114"
},
{
"input": "6259",
"output": "2511100"
},
{
"input": "2387",
"output": "312220"
},
{
"input": "8515",
"output": "10030114"
}
] | 1,650,130,299 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 264 | 4,096,000 | import time
h=[]
f=int(input())
t=time.time()
for i in range(10,10**8//9,9):
u=sum(map(int, str(i)))
if u==10:
h.append(i)
print(h[f-1])
#print(time.time()-t) | Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
Output Specification:
A single number, denoting the $k$-th smallest perfect integer.
Demo Input:
['1\n', '2\n']
Demo Output:
['19\n', '28\n']
Note:
The first perfect integer is $19$ and the second one is $28$. | ```python
import time
h=[]
f=int(input())
t=time.time()
for i in range(10,10**8//9,9):
u=sum(map(int, str(i)))
if u==10:
h.append(i)
print(h[f-1])
#print(time.time()-t)
``` | 3 |
|
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
"output": "90"
},
{
"input": "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88",
"output": "90"
},
{
"input": "90\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",
"output": "90"
},
{
"input": "1\n1",
"output": "16"
},
{
"input": "5\n15 30 45 60 75",
"output": "90"
},
{
"input": "6\n14 29 43 59 70 74",
"output": "58"
},
{
"input": "1\n15",
"output": "30"
},
{
"input": "1\n16",
"output": "15"
},
{
"input": "14\n14 22 27 31 35 44 46 61 62 69 74 79 88 89",
"output": "90"
},
{
"input": "76\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 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",
"output": "90"
},
{
"input": "1\n90",
"output": "15"
},
{
"input": "6\n13 17 32 47 60 66",
"output": "81"
},
{
"input": "84\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",
"output": "90"
},
{
"input": "9\n6 20 27 28 40 53 59 70 85",
"output": "90"
},
{
"input": "12\n14 22 27 31 35 44 62 69 74 79 88 89",
"output": "59"
},
{
"input": "5\n15 30 45 60 74",
"output": "89"
},
{
"input": "72\n3 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 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",
"output": "54"
},
{
"input": "8\n1 16 30 31 32 33 34 50",
"output": "49"
},
{
"input": "12\n1 3 6 10 15 21 28 36 45 55 66 78",
"output": "90"
},
{
"input": "25\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90",
"output": "80"
},
{
"input": "8\n5 17 20 35 42 53 67 76",
"output": "90"
},
{
"input": "9\n15 28 39 48 55 60 63 64 74",
"output": "89"
},
{
"input": "10\n15 28 39 48 55 60 63 64 74 82",
"output": "90"
},
{
"input": "2\n1 18",
"output": "16"
},
{
"input": "9\n10 20 30 40 50 60 70 80 84",
"output": "90"
},
{
"input": "2\n16 50",
"output": "15"
},
{
"input": "6\n15 30 45 60 75 84",
"output": "90"
},
{
"input": "8\n15 20 30 40 50 60 73 83",
"output": "90"
},
{
"input": "8\n10 20 30 40 50 60 70 80",
"output": "90"
},
{
"input": "3\n1 20 90",
"output": "16"
},
{
"input": "6\n15 30 45 60 74 89",
"output": "90"
}
] | 1,540,440,077 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | n = int(input())
moment = list(map(int, input().split()))
def stupid_bear (a):
for i in range (len(a)):
if i == 0:
if a[i] > 15:
ans = 15
return ans
else:
if a[i]- a[i-1] > 15:
ans = a[i-1]+15
return ans
if a[i]- a[i-1] <= 15 and i == len(a)-1:
ans = a[i]
return ans
moment.append(90)
print (stupid_bear(moment)) | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order.
Output Specification:
Print the number of minutes Limak will watch the game.
Demo Input:
['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n']
Demo Output:
['35\n', '15\n', '90\n']
Note:
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | ```python
n = int(input())
moment = list(map(int, input().split()))
def stupid_bear (a):
for i in range (len(a)):
if i == 0:
if a[i] > 15:
ans = 15
return ans
else:
if a[i]- a[i-1] > 15:
ans = a[i-1]+15
return ans
if a[i]- a[i-1] <= 15 and i == len(a)-1:
ans = a[i]
return ans
moment.append(90)
print (stupid_bear(moment))
``` | 3 |
|
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string. | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
},
{
"input": "5\naaaaa",
"output": "aaaaa"
},
{
"input": "3\naabaaaaabb",
"output": "-1"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "2\nbabac",
"output": "-1"
},
{
"input": "3\nbbbccc",
"output": "bcbcbc"
},
{
"input": "2\naa",
"output": "aa"
},
{
"input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece",
"output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece"
},
{
"input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa",
"output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc"
},
{
"input": "1\naaa",
"output": "aaa"
},
{
"input": "1\naabaab",
"output": "aaaabb"
},
{
"input": "2\naabbbbccccccdddddddd",
"output": "abbcccddddabbcccdddd"
},
{
"input": "3\naaaaaaaaacccdddddd",
"output": "aaacddaaacddaaacdd"
},
{
"input": "3\naaaaaaaaacccbbbbbb",
"output": "aaabbcaaabbcaaabbc"
},
{
"input": "2\naazzzz",
"output": "azzazz"
},
{
"input": "2\naaaa",
"output": "aaaa"
},
{
"input": "2\naaaazz",
"output": "aazaaz"
},
{
"input": "2\naaaabb",
"output": "aabaab"
},
{
"input": "2\naabbbb",
"output": "abbabb"
},
{
"input": "2\naaaazzzz",
"output": "aazzaazz"
},
{
"input": "2\naaazz",
"output": "-1"
},
{
"input": "2\nbbbbaa",
"output": "abbabb"
},
{
"input": "2\naaaaaabbbb",
"output": "aaabbaaabb"
},
{
"input": "2\naaaaaazz",
"output": "aaazaaaz"
},
{
"input": "2\naaaabbbb",
"output": "aabbaabb"
},
{
"input": "2\naabaab",
"output": "aabaab"
},
{
"input": "1\naaaaa",
"output": "aaaaa"
},
{
"input": "2\nbbaaaa",
"output": "aabaab"
},
{
"input": "2\nacaccc",
"output": "accacc"
}
] | 1,668,436,246 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | k = int(input())
s = input()
nums = set(s)
if (len(nums) != k):
print(-1)
else:
b = ""
b += "".join(str(d) for d in nums)
print(b * k) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Output Specification:
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
Demo Input:
['2\naazz\n', '3\nabcabcabz\n']
Demo Output:
['azaz\n', '-1\n']
Note:
none | ```python
k = int(input())
s = input()
nums = set(s)
if (len(nums) != k):
print(-1)
else:
b = ""
b += "".join(str(d) for d in nums)
print(b * k)
``` | 0 |
|
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "7\n7 7 7 7 7 7 7",
"output": "7"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "4"
},
{
"input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99",
"output": "49"
},
{
"input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15",
"output": "50"
},
{
"input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38",
"output": "7"
},
{
"input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87",
"output": "39"
},
{
"input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53",
"output": "37"
},
{
"input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32",
"output": "51"
},
{
"input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80",
"output": "21"
},
{
"input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81",
"output": "37"
},
{
"input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59",
"output": "28"
},
{
"input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94",
"output": "47"
},
{
"input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28",
"output": "15"
},
{
"input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42",
"output": "11"
},
{
"input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35",
"output": "33"
},
{
"input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22",
"output": "37"
},
{
"input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14",
"output": "15"
},
{
"input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77",
"output": "35"
},
{
"input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75",
"output": "42"
},
{
"input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26",
"output": "23"
},
{
"input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78",
"output": "15"
},
{
"input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78",
"output": "13"
},
{
"input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51",
"output": "17"
},
{
"input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59",
"output": "45"
},
{
"input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43",
"output": "53"
},
{
"input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8",
"output": "40"
},
{
"input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54",
"output": "53"
},
{
"input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77",
"output": "55"
},
{
"input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66",
"output": "52"
},
{
"input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89",
"output": "51"
},
{
"input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2",
"output": "53"
},
{
"input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23",
"output": "48"
},
{
"input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25",
"output": "48"
},
{
"input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71",
"output": "58"
},
{
"input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45",
"output": "53"
},
{
"input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17",
"output": "54"
},
{
"input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52",
"output": "49"
},
{
"input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31",
"output": "44"
},
{
"input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74",
"output": "46"
},
{
"input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75",
"output": "53"
},
{
"input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37",
"output": "43"
},
{
"input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82",
"output": "51"
},
{
"input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5",
"output": "47"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 1 3 2 2",
"output": "3"
}
] | 1,585,183,740 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 186 | 0 | even=0
odd=0
summ=0
n=int(input())
for i in range(n):
b=int(input())
summ+=b
if b%2==0:
even+=1
else:
odd+=1
if summ % 2 == 0:
print(even)
else :
print(odd) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Output Specification:
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
Demo Input:
['1\n1\n', '10\n1 2 2 3 4 4 4 2 2 2\n', '11\n2 2 2 2 2 2 2 2 2 2 99\n']
Demo Output:
['1\n', '8\n', '1\n']
Note:
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | ```python
even=0
odd=0
summ=0
n=int(input())
for i in range(n):
b=int(input())
summ+=b
if b%2==0:
even+=1
else:
odd+=1
if summ % 2 == 0:
print(even)
else :
print(odd)
``` | -1 |
|
388 | E | Fox and Meteor Shower | PROGRAMMING | 3,100 | [
"geometry"
] | null | null | There is a meteor shower on the sky and there are *n* meteors. The sky can be viewed as a 2D Euclid Plane and the meteor is point on this plane.
Fox Ciel looks at the sky. She finds out that the orbit of each meteor is a straight line, and each meteor has a constant velocity. Now Ciel wants to know: what is the maximum number of meteors such that any pair met at the same position at a certain time? Note that the time is not limited and can be also negative. The meteors will never collide when they appear at the same position at the same time. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains six integers: *t*1,<=*x*1,<=*y*1,<=*t*2,<=*x*2,<=*y*2 — the description of a meteor's orbit: at time *t*1, the current meteor is located at the point (*x*1, *y*1) and at time *t*2, the meteor is located at point (*x*2, *y*2) (<=-<=106<=≤<=*t*1,<=*x*1,<=*y*1,<=*t*2,<=*x*2,<=*y*2<=≤<=106; *t*1<=≠<=*t*2).
There will be no two meteors are always in the same position for any time. | Print a single integer — the maximum number of meteors such that any pair met at the same position at a certain time. | [
"2\n0 0 1 1 0 2\n0 1 0 1 2 0\n",
"3\n-1 -1 0 3 3 0\n0 2 -1 -1 3 -2\n-2 0 -1 6 0 3\n",
"4\n0 0 0 1 0 1\n0 0 1 1 1 1\n0 1 1 1 1 0\n0 1 0 1 0 0\n",
"1\n0 0 0 1 0 0\n"
] | [
"2\n",
"3\n",
"1\n",
"1\n"
] | In example 1, meteor 1 and 2 meet in *t*=-1 at (0, 0).
In example 2, meteor 1 and 2 meet in *t*=1 at (1, 0), meteor 1 and 3 meet in *t*=0 at (0, 0) and meteor 2 and 3 meet in *t*=2 at (0, 1).
In example 3, no two meteor meet.
In example 4, there is only 1 meteor, and its velocity is zero.
If your browser doesn't support animation png, please see the gif version here:
http://assets.codeforces.com/images/388e/example1.gif
http://assets.codeforces.com/images/388e/example2.gif
http://assets.codeforces.com/images/388e/example3.gif
http://assets.codeforces.com/images/388e/example4.gif | 2,500 | [] | 1,690,085,461 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def calculate_slope_and_intercept(x1, y1, x2, y2):
if x1 == x2:
return float('inf'), x1 # Infinite slope for vertical lines
slope = (y2 - y1) / (x2 - x1)
intercept = y1 - slope * x1
return slope, intercept
def maximum_meteors_with_same_position(n, meteor_descriptions):
meteor_groups = {} # Dictionary to store meteor groups by slope and intercept
for i in range(n):
t1, x1, y1, t2, x2, y2 = meteor_descriptions[i]
slope, intercept = calculate_slope_and_intercept(x1, y1, x2, y2)
if (slope, intercept) not in meteor_groups:
meteor_groups[(slope, intercept)] = 1
else:
meteor_groups[(slope, intercept)] += 1
return max(meteor_groups.values())
# Read input
n = int(input())
meteor_descriptions = [list(map(int, input().split())) for _ in range(n)]
# Calculate and print the result
result = maximum_meteors_with_same_position(n, meteor_descriptions)
print(result)
| Title: Fox and Meteor Shower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a meteor shower on the sky and there are *n* meteors. The sky can be viewed as a 2D Euclid Plane and the meteor is point on this plane.
Fox Ciel looks at the sky. She finds out that the orbit of each meteor is a straight line, and each meteor has a constant velocity. Now Ciel wants to know: what is the maximum number of meteors such that any pair met at the same position at a certain time? Note that the time is not limited and can be also negative. The meteors will never collide when they appear at the same position at the same time.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains six integers: *t*1,<=*x*1,<=*y*1,<=*t*2,<=*x*2,<=*y*2 — the description of a meteor's orbit: at time *t*1, the current meteor is located at the point (*x*1, *y*1) and at time *t*2, the meteor is located at point (*x*2, *y*2) (<=-<=106<=≤<=*t*1,<=*x*1,<=*y*1,<=*t*2,<=*x*2,<=*y*2<=≤<=106; *t*1<=≠<=*t*2).
There will be no two meteors are always in the same position for any time.
Output Specification:
Print a single integer — the maximum number of meteors such that any pair met at the same position at a certain time.
Demo Input:
['2\n0 0 1 1 0 2\n0 1 0 1 2 0\n', '3\n-1 -1 0 3 3 0\n0 2 -1 -1 3 -2\n-2 0 -1 6 0 3\n', '4\n0 0 0 1 0 1\n0 0 1 1 1 1\n0 1 1 1 1 0\n0 1 0 1 0 0\n', '1\n0 0 0 1 0 0\n']
Demo Output:
['2\n', '3\n', '1\n', '1\n']
Note:
In example 1, meteor 1 and 2 meet in *t*=-1 at (0, 0).
In example 2, meteor 1 and 2 meet in *t*=1 at (1, 0), meteor 1 and 3 meet in *t*=0 at (0, 0) and meteor 2 and 3 meet in *t*=2 at (0, 1).
In example 3, no two meteor meet.
In example 4, there is only 1 meteor, and its velocity is zero.
If your browser doesn't support animation png, please see the gif version here:
http://assets.codeforces.com/images/388e/example1.gif
http://assets.codeforces.com/images/388e/example2.gif
http://assets.codeforces.com/images/388e/example3.gif
http://assets.codeforces.com/images/388e/example4.gif | ```python
def calculate_slope_and_intercept(x1, y1, x2, y2):
if x1 == x2:
return float('inf'), x1 # Infinite slope for vertical lines
slope = (y2 - y1) / (x2 - x1)
intercept = y1 - slope * x1
return slope, intercept
def maximum_meteors_with_same_position(n, meteor_descriptions):
meteor_groups = {} # Dictionary to store meteor groups by slope and intercept
for i in range(n):
t1, x1, y1, t2, x2, y2 = meteor_descriptions[i]
slope, intercept = calculate_slope_and_intercept(x1, y1, x2, y2)
if (slope, intercept) not in meteor_groups:
meteor_groups[(slope, intercept)] = 1
else:
meteor_groups[(slope, intercept)] += 1
return max(meteor_groups.values())
# Read input
n = int(input())
meteor_descriptions = [list(map(int, input().split())) for _ in range(n)]
# Calculate and print the result
result = maximum_meteors_with_same_position(n, meteor_descriptions)
print(result)
``` | 0 |
|
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,680,020,263 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 124 | 0 | # https://codeforces.com/contest/96/problem/A
s = input()
print('YES' if '1' * 7 in s or '0' * 7 in s else 'NO')
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
# https://codeforces.com/contest/96/problem/A
s = input()
print('YES' if '1' * 7 in s or '0' * 7 in s else 'NO')
``` | 3.969 |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "YES"
},
{
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer",
"output": "NO"
},
{
"input": "30\nToBeOrNotToBeThatIsTheQuestion",
"output": "NO"
},
{
"input": "30\njackdawslovemybigsphinxofquarz",
"output": "NO"
},
{
"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY",
"output": "YES"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx",
"output": "YES"
},
{
"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ",
"output": "YES"
},
{
"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ",
"output": "YES"
},
{
"input": "25\nnxYTzLFwzNolAumjgcAboyxAj",
"output": "NO"
},
{
"input": "26\npRWdodGdxUESvcScPGbUoooZsC",
"output": "NO"
},
{
"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj",
"output": "NO"
},
{
"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa",
"output": "YES"
},
{
"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK",
"output": "NO"
},
{
"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst",
"output": "NO"
},
{
"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY",
"output": "NO"
},
{
"input": "26\npGiFluRteQwkaVoPszJyNBChxM",
"output": "NO"
},
{
"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY",
"output": "NO"
},
{
"input": "26\nLndjgvAEuICHKxPwqYztosrmBN",
"output": "NO"
},
{
"input": "26\nMdaXJrCipnOZLykfqHWEStevbU",
"output": "NO"
},
{
"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba",
"output": "NO"
},
{
"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo",
"output": "NO"
},
{
"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa",
"output": "NO"
},
{
"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO",
"output": "NO"
},
{
"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe",
"output": "NO"
},
{
"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG",
"output": "NO"
},
{
"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF",
"output": "NO"
},
{
"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu",
"output": "NO"
},
{
"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf",
"output": "NO"
},
{
"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE",
"output": "NO"
},
{
"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC",
"output": "NO"
},
{
"input": "26\necOyUkqNljFHRVXtIpWabGMLDz",
"output": "NO"
},
{
"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI",
"output": "NO"
},
{
"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA",
"output": "NO"
},
{
"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz",
"output": "NO"
},
{
"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ",
"output": "NO"
},
{
"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF",
"output": "NO"
},
{
"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB",
"output": "NO"
},
{
"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg",
"output": "NO"
},
{
"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq",
"output": "NO"
},
{
"input": "26\naAbcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl",
"output": "NO"
},
{
"input": "25\nabcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "26\nabcdefhijklmnopqrstVxyzABC",
"output": "NO"
},
{
"input": "25\nqwertyuiopasdfghjklxcvbnm",
"output": "NO"
},
{
"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog",
"output": "NO"
},
{
"input": "26\nabcdefghigklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyA",
"output": "NO"
},
{
"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog",
"output": "NO"
},
{
"input": "25\nbcdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa",
"output": "NO"
},
{
"input": "26\nabcdefghiklmnopqrstvxyzABC",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxzZ",
"output": "NO"
},
{
"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "NO"
}
] | 1,699,201,445 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n=int(input())
s=input()
p="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
q="abcdefghijklmnopqrstuvwxyz"
if s.len()>36:
k=0
for i in range(26):
if p[i] in s:
k+=1
if q[i] in s:
k+=1
if k==26:
print("YES")
else:
print("NO")
else:
print("NO") | Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output Specification:
Output "YES", if the string is a pangram and "NO" otherwise.
Demo Input:
['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
n=int(input())
s=input()
p="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
q="abcdefghijklmnopqrstuvwxyz"
if s.len()>36:
k=0
for i in range(26):
if p[i] in s:
k+=1
if q[i] in s:
k+=1
if k==26:
print("YES")
else:
print("NO")
else:
print("NO")
``` | -1 |
|
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.
For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "Still Rozdil"
},
{
"input": "4\n1000000000 100000000 1000000 1000000",
"output": "Still Rozdil"
},
{
"input": "20\n7 1 1 2 1 1 8 7 7 8 4 3 7 10 5 3 10 5 10 6",
"output": "Still Rozdil"
},
{
"input": "20\n3 3 6 9 8 2 4 1 7 3 2 9 7 7 9 7 2 6 2 7",
"output": "8"
},
{
"input": "47\n35 79 84 56 67 95 80 34 77 68 14 55 95 32 40 89 58 79 96 66 50 79 35 86 31 74 91 35 22 72 84 38 11 59 73 51 65 11 11 62 30 12 32 71 69 15 11",
"output": "Still Rozdil"
},
{
"input": "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "32"
},
{
"input": "25\n73 56 65 70 57 57 49 50 65 68 54 48 66 55 55 66 60 70 47 62 63 70 62 70 63",
"output": "19"
},
{
"input": "100\n922 938 103 689 526 118 314 496 373 47 224 544 495 656 804 754 269 356 354 536 817 597 787 178 516 659 790 993 786 169 866 779 997 350 674 437 219 546 564 893 402 449 751 628 238 686 392 951 716 439 332 563 215 146 746 311 866 773 548 675 731 183 890 802 488 944 473 25 662 559 732 534 777 144 502 593 839 692 84 337 679 718 1005 663 709 940 86 469 310 960 902 233 606 761 116 231 662 903 68 622",
"output": "68"
},
{
"input": "5\n5 5 2 3 1",
"output": "5"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "3\n7 7 4",
"output": "3"
},
{
"input": "3\n2 2 1",
"output": "3"
},
{
"input": "3\n4 4 3",
"output": "3"
},
{
"input": "2\n10000001 10000002",
"output": "1"
},
{
"input": "4\n3 3 2 1",
"output": "4"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "2\n1000000000 100000000",
"output": "2"
},
{
"input": "1\n99999999",
"output": "1"
},
{
"input": "3\n5 5 3",
"output": "3"
},
{
"input": "3\n7 7 5",
"output": "3"
},
{
"input": "3\n3 3 1",
"output": "3"
},
{
"input": "4\n10 10 10 1",
"output": "4"
}
] | 1,560,230,753 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 310 | 8,396,800 | import sys
n = int(input())
a = list(map(int, input().split()))
mi = sys.maxsize
c = 0
j = 0
for i in range(n):
if mi > a[i]:
mi = a[i]
c = 1
j = i
elif mi == a[i]:
c += 1
if c > 1:
print("Still Rozdil")
else:
print(j + 1) | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.
For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities.
Output Specification:
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
Demo Input:
['2\n7 4\n', '7\n7 4 47 100 4 9 12\n']
Demo Output:
['2\n', 'Still Rozdil\n']
Note:
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | ```python
import sys
n = int(input())
a = list(map(int, input().split()))
mi = sys.maxsize
c = 0
j = 0
for i in range(n):
if mi > a[i]:
mi = a[i]
c = 1
j = i
elif mi == a[i]:
c += 1
if c > 1:
print("Still Rozdil")
else:
print(j + 1)
``` | 3 |
|
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output": "423654797"
},
{
"input": "-623563697",
"output": "-62356367"
},
{
"input": "645894116",
"output": "645894116"
},
{
"input": "-384381709",
"output": "-38438170"
},
{
"input": "437587210",
"output": "437587210"
},
{
"input": "-297534606",
"output": "-29753460"
},
{
"input": "891773002",
"output": "891773002"
},
{
"input": "-56712976",
"output": "-5671296"
},
{
"input": "963662765",
"output": "963662765"
},
{
"input": "-272656295",
"output": "-27265625"
},
{
"input": "383441522",
"output": "383441522"
},
{
"input": "-477665112",
"output": "-47766511"
},
{
"input": "791725034",
"output": "791725034"
},
{
"input": "-812168727",
"output": "-81216872"
},
{
"input": "528894922",
"output": "528894922"
},
{
"input": "-479977172",
"output": "-47997712"
},
{
"input": "568044564",
"output": "568044564"
},
{
"input": "-392784794",
"output": "-39278474"
},
{
"input": "925596634",
"output": "925596634"
},
{
"input": "-836078769",
"output": "-83607876"
},
{
"input": "71036059",
"output": "71036059"
},
{
"input": "-337396162",
"output": "-33739612"
},
{
"input": "87129297",
"output": "87129297"
},
{
"input": "-648171877",
"output": "-64817187"
},
{
"input": "20218400",
"output": "20218400"
},
{
"input": "10",
"output": "10"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "-1000000000",
"output": "-100000000"
},
{
"input": "-102",
"output": "-10"
},
{
"input": "-120",
"output": "-10"
},
{
"input": "-20",
"output": "0"
},
{
"input": "-15",
"output": "-1"
},
{
"input": "-5575533",
"output": "-557553"
},
{
"input": "-50",
"output": "0"
},
{
"input": "-31",
"output": "-1"
},
{
"input": "-55",
"output": "-5"
},
{
"input": "-81",
"output": "-1"
},
{
"input": "-99",
"output": "-9"
},
{
"input": "-23",
"output": "-2"
},
{
"input": "-41",
"output": "-1"
},
{
"input": "-24",
"output": "-2"
},
{
"input": "46",
"output": "46"
}
] | 1,683,369,967 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | n=int(input())
if n>=0:
print(n)
else:
o=n*-1
p=o//10;
q=(o//100)*100+(o%10)
if p>=q:
print(-1*q)
else:
print(-1*p) | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
Input Specification:
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
Output Specification:
In a single line print an integer — the maximum state of the bank account that Ilya can get.
Demo Input:
['2230\n', '-10\n', '-100003\n']
Demo Output:
['2230\n', '0\n', '-10000\n']
Note:
In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | ```python
n=int(input())
if n>=0:
print(n)
else:
o=n*-1
p=o//10;
q=(o//100)*100+(o%10)
if p>=q:
print(-1*q)
else:
print(-1*p)
``` | 0 |
|
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
"output": "both"
},
{
"input": "a\na\na",
"output": "fantasy"
},
{
"input": "ab\nb\na",
"output": "backward"
},
{
"input": "aaa\naaaa\naaaa",
"output": "fantasy"
},
{
"input": "bbabbbbababbaabaabaa\nabb\nbaab",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa",
"output": "backward"
},
{
"input": "aaaa\naaa\naa",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzzzz\nzzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzz",
"output": "both"
},
{
"input": "aabaa\naab\nbaa",
"output": "fantasy"
},
{
"input": "aabaab\naba\nab",
"output": "forward"
},
{
"input": "aab\nb\naa",
"output": "backward"
},
{
"input": "abacaba\naca\nba",
"output": "both"
}
] | 1,669,724,845 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | str1 = input()
n1 = input()
n2 = input()
str2 = ''
for i in range(1, len(str1)+1):
str2 = str2 + str1[-i]
if n1 in str1 and n2 in str1:
if n1 in str2 and n2 in str2:
print('both')
else:
print('forward')
elif n1 in str2 and n2 in str2:
print('backward')
else:
print('fantasy')
| Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
Input Specification:
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output Specification:
Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
Demo Input:
['atob\na\nb\n', 'aaacaaa\naca\naa\n']
Demo Output:
['forward\n', 'both\n']
Note:
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | ```python
str1 = input()
n1 = input()
n2 = input()
str2 = ''
for i in range(1, len(str1)+1):
str2 = str2 + str1[-i]
if n1 in str1 and n2 in str1:
if n1 in str2 and n2 in str2:
print('both')
else:
print('forward')
elif n1 in str2 and n2 in str2:
print('backward')
else:
print('fantasy')
``` | 0 |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "19",
"output": "6"
},
{
"input": "40",
"output": "19"
},
{
"input": "77",
"output": "41"
},
{
"input": "222",
"output": "125"
},
{
"input": "987",
"output": "501"
},
{
"input": "1000",
"output": "508"
},
{
"input": "2000",
"output": "958"
},
{
"input": "3000",
"output": "1375"
},
{
"input": "2999",
"output": "1375"
},
{
"input": "2998",
"output": "1375"
},
{
"input": "2997",
"output": "1374"
},
{
"input": "1429",
"output": "706"
},
{
"input": "1673",
"output": "808"
},
{
"input": "1500",
"output": "732"
},
{
"input": "500",
"output": "266"
},
{
"input": "856",
"output": "439"
}
] | 1,682,459,133 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 342 | 0 | n=int(input());
primes=[2];
ans=0;
for i in range(3,n+1):
prime_divisor_count=0;
x=i;
for j in primes:
if x%j==0:
prime_divisor_count+=1;
if prime_divisor_count<3:
while x%j==0:
x//=j;
if prime_divisor_count==0:
primes.append(i);
elif prime_divisor_count==2:
ans+=1;
print(ans);
| Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive.
Input Specification:
Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000).
Output Specification:
Output the amount of almost prime numbers between 1 and *n*, inclusive.
Demo Input:
['10\n', '21\n']
Demo Output:
['2\n', '8\n']
Note:
none | ```python
n=int(input());
primes=[2];
ans=0;
for i in range(3,n+1):
prime_divisor_count=0;
x=i;
for j in primes:
if x%j==0:
prime_divisor_count+=1;
if prime_divisor_count<3:
while x%j==0:
x//=j;
if prime_divisor_count==0:
primes.append(i);
elif prime_divisor_count==2:
ans+=1;
print(ans);
``` | 3.9145 |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 1,697,106,091 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | import sys
user_input = int(sys.stdin.readline().strip())
counter = 0
for i in range(user_input):
a, b = map(int, sys.stdin.readline().strip().split())
if (b - a) >= 2:
counter += 1
print(counter)
| Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Output Specification:
Print a single integer — the number of rooms where George and Alex can move in.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n']
Demo Output:
['0\n', '2\n']
Note:
none | ```python
import sys
user_input = int(sys.stdin.readline().strip())
counter = 0
for i in range(user_input):
a, b = map(int, sys.stdin.readline().strip().split())
if (b - a) >= 2:
counter += 1
print(counter)
``` | 3 |
|
44 | B | Cola | PROGRAMMING | 1,500 | [
"implementation"
] | B. Cola | 2 | 256 | To celebrate the opening of the Winter Computer School the organizers decided to buy in *n* liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly *a* bottles 0.5 in volume, *b* one-liter bottles and *c* of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly *n* liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind. | The first line contains four integers — *n*, *a*, *b*, *c* (1<=≤<=*n*<=≤<=10000, 0<=≤<=*a*,<=*b*,<=*c*<=≤<=5000). | Print the unique number — the solution to the problem. If it is impossible to buy exactly *n* liters of cola, print 0. | [
"10 5 5 5\n",
"3 0 0 2\n"
] | [
"9\n",
"0\n"
] | none | 0 | [
{
"input": "10 5 5 5",
"output": "9"
},
{
"input": "3 0 0 2",
"output": "0"
},
{
"input": "1 0 0 0",
"output": "0"
},
{
"input": "1 1 0 0",
"output": "0"
},
{
"input": "1 2 0 0",
"output": "1"
},
{
"input": "1 0 1 0",
"output": "1"
},
{
"input": "1 0 2 0",
"output": "1"
},
{
"input": "1 0 0 1",
"output": "0"
},
{
"input": "2 2 2 2",
"output": "3"
},
{
"input": "3 3 2 1",
"output": "3"
},
{
"input": "3 10 10 10",
"output": "6"
},
{
"input": "5 2 1 1",
"output": "0"
},
{
"input": "7 2 2 2",
"output": "1"
},
{
"input": "7 3 0 5",
"output": "1"
},
{
"input": "10 20 10 5",
"output": "36"
},
{
"input": "10 0 8 10",
"output": "5"
},
{
"input": "10 19 15 100",
"output": "35"
},
{
"input": "20 1 2 3",
"output": "0"
},
{
"input": "20 10 20 30",
"output": "57"
},
{
"input": "25 10 5 10",
"output": "12"
},
{
"input": "101 10 0 50",
"output": "3"
},
{
"input": "101 10 10 50",
"output": "33"
},
{
"input": "505 142 321 12",
"output": "0"
},
{
"input": "999 999 899 299",
"output": "145000"
},
{
"input": "5 5000 5000 5000",
"output": "12"
},
{
"input": "10000 5000 5000 5000",
"output": "6253751"
},
{
"input": "10000 0 5000 5000",
"output": "2501"
},
{
"input": "10000 5000 0 5000",
"output": "1251"
},
{
"input": "10000 5000 5000 0",
"output": "0"
},
{
"input": "10000 4534 2345 4231",
"output": "2069003"
},
{
"input": "10000 5000 2500 2500",
"output": "1"
},
{
"input": "1234 645 876 1000",
"output": "141636"
},
{
"input": "8987 4000 2534 4534",
"output": "2536267"
},
{
"input": "10000 2500 2500 2500",
"output": "0"
},
{
"input": "10000 4999 2500 2500",
"output": "0"
},
{
"input": "7777 4444 3333 2222",
"output": "1236544"
},
{
"input": "5643 1524 1423 2111",
"output": "146687"
},
{
"input": "8765 2432 2789 4993",
"output": "1697715"
},
{
"input": "5000 5000 5000 5000",
"output": "4691251"
},
{
"input": "2500 5000 5000 5000",
"output": "1565001"
}
] | 1,512,558,099 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 23 | 2,000 | 5,529,600 | ans=0;
n,a,b,c=map(int,input().split())
for i in range(a+1):
for j in range(b+1):
for z in range(c+1):
if 0.5*i+j+z*2==n :
ans=ans+1
print(ans)
| Title: Cola
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
To celebrate the opening of the Winter Computer School the organizers decided to buy in *n* liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly *a* bottles 0.5 in volume, *b* one-liter bottles and *c* of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly *n* liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input Specification:
The first line contains four integers — *n*, *a*, *b*, *c* (1<=≤<=*n*<=≤<=10000, 0<=≤<=*a*,<=*b*,<=*c*<=≤<=5000).
Output Specification:
Print the unique number — the solution to the problem. If it is impossible to buy exactly *n* liters of cola, print 0.
Demo Input:
['10 5 5 5\n', '3 0 0 2\n']
Demo Output:
['9\n', '0\n']
Note:
none | ```python
ans=0;
n,a,b,c=map(int,input().split())
for i in range(a+1):
for j in range(b+1):
for z in range(c+1):
if 0.5*i+j+z*2==n :
ans=ans+1
print(ans)
``` | 0 |
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).
Your task is to check whether Limak can choose three balls that satisfy conditions above. | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose balls:
1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971. | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
"input": "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543",
"output": "NO"
},
{
"input": "50\n941 877 987 982 966 979 984 810 811 909 872 980 957 897 845 995 924 905 984 914 824 840 868 910 815 808 872 858 883 952 823 835 860 874 959 972 931 867 866 987 982 837 800 921 887 910 982 980 828 869",
"output": "YES"
},
{
"input": "3\n408 410 409",
"output": "YES"
},
{
"input": "3\n903 902 904",
"output": "YES"
},
{
"input": "3\n399 400 398",
"output": "YES"
},
{
"input": "3\n450 448 449",
"output": "YES"
},
{
"input": "3\n390 389 388",
"output": "YES"
},
{
"input": "3\n438 439 440",
"output": "YES"
},
{
"input": "11\n488 688 490 94 564 615 641 170 489 517 669",
"output": "YES"
},
{
"input": "24\n102 672 983 82 720 501 81 721 982 312 207 897 159 964 611 956 118 984 37 271 596 403 772 954",
"output": "YES"
},
{
"input": "36\n175 551 70 479 875 480 979 32 465 402 640 116 76 687 874 678 359 785 753 401 978 629 162 963 886 641 39 845 132 930 2 372 478 947 407 318",
"output": "YES"
},
{
"input": "6\n10 79 306 334 304 305",
"output": "YES"
},
{
"input": "34\n787 62 26 683 486 364 684 891 846 801 969 837 359 800 836 359 471 637 732 91 841 836 7 799 959 405 416 841 737 803 615 483 323 365",
"output": "YES"
},
{
"input": "30\n860 238 14 543 669 100 428 789 576 484 754 274 849 850 586 377 711 386 510 408 520 693 23 477 266 851 728 711 964 73",
"output": "YES"
},
{
"input": "11\n325 325 324 324 324 325 325 324 324 324 324",
"output": "NO"
},
{
"input": "7\n517 517 518 517 518 518 518",
"output": "NO"
},
{
"input": "20\n710 710 711 711 711 711 710 710 710 710 711 710 710 710 710 710 710 711 711 710",
"output": "NO"
},
{
"input": "48\n29 30 29 29 29 30 29 30 30 30 30 29 30 30 30 29 29 30 30 29 30 29 29 30 29 30 29 30 30 29 30 29 29 30 30 29 29 30 30 29 29 30 30 30 29 29 30 29",
"output": "NO"
},
{
"input": "7\n880 880 514 536 881 881 879",
"output": "YES"
},
{
"input": "15\n377 432 262 376 261 375 377 262 263 263 261 376 262 262 375",
"output": "YES"
},
{
"input": "32\n305 426 404 961 426 425 614 304 404 425 615 403 303 304 615 303 305 405 427 614 403 303 425 615 404 304 427 403 206 616 405 404",
"output": "YES"
},
{
"input": "41\n115 686 988 744 762 519 745 519 518 83 85 115 520 44 687 686 685 596 988 687 989 988 114 745 84 519 519 746 988 84 745 744 115 114 85 115 520 746 745 116 987",
"output": "YES"
},
{
"input": "47\n1 2 483 28 7 109 270 651 464 162 353 521 224 989 721 499 56 69 197 716 313 446 580 645 828 197 100 138 789 499 147 677 384 711 783 937 300 543 540 93 669 604 739 122 632 822 116",
"output": "NO"
},
{
"input": "31\n1 2 1 373 355 692 750 920 578 666 615 232 141 129 663 929 414 704 422 559 568 731 354 811 532 618 39 879 292 602 995",
"output": "NO"
},
{
"input": "50\n5 38 41 4 15 40 27 39 20 3 44 47 30 6 36 29 35 12 19 26 10 2 21 50 11 46 48 49 17 16 33 13 32 28 31 18 23 34 7 14 24 45 9 37 1 8 42 25 43 22",
"output": "YES"
},
{
"input": "50\n967 999 972 990 969 978 963 987 954 955 973 970 959 981 995 983 986 994 979 957 965 982 992 977 953 975 956 961 993 997 998 958 980 962 960 951 996 991 1000 966 971 988 976 968 989 984 974 964 985 952",
"output": "YES"
},
{
"input": "50\n850 536 761 506 842 898 857 723 583 637 536 943 895 929 890 612 832 633 696 731 553 880 710 812 665 877 915 636 711 540 748 600 554 521 813 796 568 513 543 809 798 820 928 504 999 646 907 639 550 911",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "3\n500 999 1000",
"output": "NO"
},
{
"input": "10\n101 102 104 105 107 109 110 112 113 115",
"output": "NO"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "50\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",
"output": "NO"
},
{
"input": "3\n1000 999 998",
"output": "YES"
},
{
"input": "49\n343 322 248 477 53 156 245 493 209 141 370 66 229 184 434 137 276 472 216 456 147 180 140 114 493 323 393 262 380 314 222 124 98 441 129 346 48 401 347 460 122 125 114 106 189 260 374 165 456",
"output": "NO"
},
{
"input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3",
"output": "YES"
},
{
"input": "3\n999 999 1000",
"output": "NO"
},
{
"input": "9\n2 4 5 13 25 100 200 300 400",
"output": "NO"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "NO"
},
{
"input": "3\n998 999 1000",
"output": "YES"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 2 2 4",
"output": "NO"
},
{
"input": "4\n4 3 4 5",
"output": "YES"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "NO"
},
{
"input": "3\n2 3 2",
"output": "NO"
},
{
"input": "5\n10 5 6 3 2",
"output": "NO"
},
{
"input": "3\n1 2 1",
"output": "NO"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "4\n998 999 1000 1000",
"output": "YES"
},
{
"input": "5\n2 3 9 9 4",
"output": "YES"
},
{
"input": "4\n1 2 4 4",
"output": "NO"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n2 2 3",
"output": "NO"
},
{
"input": "7\n1 2 2 2 4 5 6",
"output": "YES"
},
{
"input": "5\n1 3 10 3 10",
"output": "NO"
},
{
"input": "3\n1 2 2",
"output": "NO"
},
{
"input": "4\n1000 1000 999 998",
"output": "YES"
},
{
"input": "3\n5 3 7",
"output": "NO"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "YES"
},
{
"input": "9\n6 6 6 5 5 5 4 4 4",
"output": "YES"
},
{
"input": "7\n5 6 6 6 7 7 7",
"output": "YES"
},
{
"input": "5\n2 3 3 3 4",
"output": "YES"
},
{
"input": "5\n2 1 2 1 3",
"output": "YES"
},
{
"input": "3\n1 2 7",
"output": "NO"
},
{
"input": "3\n1000 1000 1000",
"output": "NO"
},
{
"input": "5\n1 100 2 100 3",
"output": "YES"
},
{
"input": "5\n5 4 6 5 5",
"output": "YES"
},
{
"input": "12\n1 1 1 1 2 2 2 2 3 3 3 3",
"output": "YES"
},
{
"input": "5\n9 9 1 2 3",
"output": "YES"
},
{
"input": "6\n1 2 3 1 2 3",
"output": "YES"
},
{
"input": "7\n1 1 1 1 2 3 3",
"output": "YES"
},
{
"input": "3\n13 13 13",
"output": "NO"
},
{
"input": "3\n42 42 42",
"output": "NO"
},
{
"input": "8\n1 1 1 1 2 2 2 2",
"output": "NO"
},
{
"input": "6\n1 1 1 1 2 3",
"output": "YES"
},
{
"input": "6\n1 1 2 2 6 6",
"output": "NO"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "NO"
},
{
"input": "9\n1 2 3 1 2 3 1 2 3",
"output": "YES"
},
{
"input": "4\n1 2 1 100",
"output": "NO"
},
{
"input": "5\n1 1 2 2 3",
"output": "YES"
}
] | 1,459,176,569 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 4,608,000 | n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range (n - 2):
if a[i + 1] == a[i] + 1 and a[i + 2] == a[i] + 2:
ans = 1
if ans == 0:
print('NO')
if ans == 1:
print('YES')
| Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).
Your task is to check whether Limak can choose three balls that satisfy conditions above.
Input Specification:
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Output Specification:
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
Demo Input:
['4\n18 55 16 17\n', '6\n40 41 43 44 44 44\n', '8\n5 972 3 4 1 4 970 971\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose balls:
1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971. | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range (n - 2):
if a[i + 1] == a[i] + 1 and a[i + 2] == a[i] + 2:
ans = 1
if ans == 0:
print('NO')
if ans == 1:
print('YES')
``` | 0 |
|
893 | B | Beautiful Divisors | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes.
Some examples of beautiful numbers:
- 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610).
More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1).
Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it! | The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got. | Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists. | [
"3\n",
"992\n"
] | [
"1\n",
"496\n"
] | none | 0 | [
{
"input": "3",
"output": "1"
},
{
"input": "992",
"output": "496"
},
{
"input": "81142",
"output": "1"
},
{
"input": "76920",
"output": "120"
},
{
"input": "2016",
"output": "2016"
},
{
"input": "1",
"output": "1"
},
{
"input": "6",
"output": "6"
},
{
"input": "32640",
"output": "32640"
},
{
"input": "12096",
"output": "2016"
},
{
"input": "55948",
"output": "1"
},
{
"input": "47262",
"output": "6"
},
{
"input": "22876",
"output": "28"
},
{
"input": "96120",
"output": "120"
},
{
"input": "42160",
"output": "496"
},
{
"input": "38304",
"output": "2016"
},
{
"input": "89408",
"output": "8128"
},
{
"input": "97920",
"output": "32640"
},
{
"input": "55493",
"output": "1"
},
{
"input": "38021",
"output": "1"
},
{
"input": "21445",
"output": "1"
},
{
"input": "100000",
"output": "1"
},
{
"input": "497",
"output": "1"
},
{
"input": "240",
"output": "120"
},
{
"input": "21204",
"output": "6"
},
{
"input": "65536",
"output": "1"
},
{
"input": "364",
"output": "28"
},
{
"input": "1024",
"output": "1"
},
{
"input": "36",
"output": "6"
},
{
"input": "28",
"output": "28"
},
{
"input": "14400",
"output": "120"
},
{
"input": "10080",
"output": "2016"
},
{
"input": "9",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "42",
"output": "6"
},
{
"input": "83160",
"output": "120"
},
{
"input": "65534",
"output": "1"
},
{
"input": "1026",
"output": "6"
},
{
"input": "1025",
"output": "1"
},
{
"input": "1027",
"output": "1"
},
{
"input": "2018",
"output": "1"
},
{
"input": "2020",
"output": "1"
},
{
"input": "123",
"output": "1"
},
{
"input": "150",
"output": "6"
},
{
"input": "5",
"output": "1"
},
{
"input": "66",
"output": "6"
},
{
"input": "12768",
"output": "28"
},
{
"input": "156",
"output": "6"
},
{
"input": "99990",
"output": "6"
},
{
"input": "248",
"output": "1"
}
] | 1,689,180,228 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | s=int(input())
for i in range(1,int(s**0.5)+1):
if ((2**i)-1)*(2**(i-1))<s:
c=((2**i)-1)*(2**(i-1))
else:
break
print(c) | Title: Beautiful Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes.
Some examples of beautiful numbers:
- 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610).
More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1).
Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it!
Input Specification:
The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got.
Output Specification:
Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.
Demo Input:
['3\n', '992\n']
Demo Output:
['1\n', '496\n']
Note:
none | ```python
s=int(input())
for i in range(1,int(s**0.5)+1):
if ((2**i)-1)*(2**(i-1))<s:
c=((2**i)-1)*(2**(i-1))
else:
break
print(c)
``` | 0 |
|
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City? | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,692,768,589 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 500 | 5,222,400 | n = int(input())
re = 5 ** n
print(str(re)[-2:])
| Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City?
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output Specification:
Output the last two digits of 5*n* without spaces between them.
Demo Input:
['2\n']
Demo Output:
['25']
Note:
none | ```python
n = int(input())
re = 5 ** n
print(str(re)[-2:])
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,614,235,781 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | M= int(input())
N= int(input())
if 1<=M<=N<=16:
P=N*M
print(P//2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
M= int(input())
N= int(input())
if 1<=M<=N<=16:
P=N*M
print(P//2)
``` | -1 |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{
"input": "1022 584 112",
"output": "380"
},
{
"input": "66 174 319",
"output": "184"
},
{
"input": "912 276 1748",
"output": "444"
},
{
"input": "65 156 60",
"output": "120"
},
{
"input": "1 10000 10000",
"output": "40008"
},
{
"input": "1485 55 27",
"output": "332"
},
{
"input": "152 108 4104",
"output": "528"
},
{
"input": "1656 6900 1350",
"output": "740"
},
{
"input": "12 14 42",
"output": "60"
},
{
"input": "615 18 1230",
"output": "856"
},
{
"input": "680 60 408",
"output": "336"
},
{
"input": "644 966 6",
"output": "1308"
},
{
"input": "1 432 432",
"output": "1736"
},
{
"input": "2239 2239 1",
"output": "8964"
},
{
"input": "4106 8212 2",
"output": "16436"
},
{
"input": "10000 10000 10000",
"output": "1200"
},
{
"input": "3623 3623 1",
"output": "14500"
},
{
"input": "9801 9801 9801",
"output": "1188"
},
{
"input": "10000 1 10000",
"output": "40008"
},
{
"input": "9 9 9",
"output": "36"
},
{
"input": "9801 9702 9702",
"output": "1184"
}
] | 1,607,711,524 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 216 | 0 | import sys
import math
f1,f2,f3=map(int,input().split())
c=math.sqrt(f3/(f1/f2))
b=f2/c
a=f3/c
print(int(4*(a+b+c)))
| Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input Specification:
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output Specification:
Print a single number — the sum of all edges of the parallelepiped.
Demo Input:
['1 1 1\n', '4 6 6\n']
Demo Output:
['12\n', '28\n']
Note:
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | ```python
import sys
import math
f1,f2,f3=map(int,input().split())
c=math.sqrt(f3/(f1/f2))
b=f2/c
a=f3/c
print(int(4*(a+b+c)))
``` | 3 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,670,592,131 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n,m,a=map(int , input().split())
total1=0
total2=0
if(n%a==0):
total1=total1+n//a
else:
total1=total1+n//a+1
if(m%a==0):
total2=total2+m//a
else:
total2=total2+m//a+1
print(total1*total2) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n,m,a=map(int , input().split())
total1=0
total2=0
if(n%a==0):
total1=total1+n//a
else:
total1=total1+n//a+1
if(m%a==0):
total2=total2+m//a
else:
total2=total2+m//a+1
print(total1*total2)
``` | 3.977 |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"output": "99"
},
{
"input": "gngvi",
"output": "44"
},
{
"input": "aaaaa",
"output": "0"
},
{
"input": "a",
"output": "0"
},
{
"input": "z",
"output": "1"
},
{
"input": "vyadeehhikklnoqrs",
"output": "28"
},
{
"input": "jjiihhhhgggfedcccbazyxx",
"output": "21"
},
{
"input": "fyyptqqxuciqvwdewyppjdzur",
"output": "117"
},
{
"input": "fqcnzmzmbobmancqcoalzmanaobpdse",
"output": "368"
},
{
"input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza",
"output": "8"
},
{
"input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy",
"output": "644"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss",
"output": "8"
},
{
"input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl",
"output": "421"
},
{
"input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa",
"output": "84"
},
{
"input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco",
"output": "666"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww",
"output": "22"
},
{
"input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh",
"output": "643"
},
{
"input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib",
"output": "245"
},
{
"input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro",
"output": "468"
},
{
"input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned",
"output": "523"
},
{
"input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna",
"output": "130"
},
{
"input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh",
"output": "163"
},
{
"input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb",
"output": "155"
},
{
"input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp",
"output": "57"
},
{
"input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs",
"output": "1236"
},
{
"input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx",
"output": "49"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt",
"output": "331"
},
{
"input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte",
"output": "692"
},
{
"input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh",
"output": "1293"
},
{
"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg",
"output": "16"
},
{
"input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple",
"output": "616"
},
{
"input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl",
"output": "605"
},
{
"input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud",
"output": "549"
},
{
"input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore",
"output": "688"
},
{
"input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc",
"output": "604"
},
{
"input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa",
"output": "572"
},
{
"input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp",
"output": "609"
},
{
"input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl",
"output": "223"
},
{
"input": "aa",
"output": "0"
}
] | 1,636,784,856 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 202 | 42,905,600 |
import math
import itertools
import random
s=input()
o=0
q=0
ans='abcdefghijklmnopqrstuvwxyz'
for l in s:
ans=ans[o:]+ans[:o]
a=ans.index(l)+1
o=a
p=min(len(ans)-a,a)
q+=p
if 'a' in s:
print(q-1)
else:
print(q+1)
| Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
Input Specification:
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Output Specification:
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
Demo Input:
['zeus\n', 'map\n', 'ares\n']
Demo Output:
['18\n', '35\n', '34\n']
Note:
To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | ```python
import math
import itertools
import random
s=input()
o=0
q=0
ans='abcdefghijklmnopqrstuvwxyz'
for l in s:
ans=ans[o:]+ans[:o]
a=ans.index(l)+1
o=a
p=min(len(ans)-a,a)
q+=p
if 'a' in s:
print(q-1)
else:
print(q+1)
``` | 0 |
|
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71",
"output": "51"
},
{
"input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29",
"output": "1"
},
{
"input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24",
"output": "2"
},
{
"input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6",
"output": "10"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "99"
},
{
"input": "7\n1 2 3 3 3 1 2",
"output": "3"
},
{
"input": "5\n1 2 3 4 5",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "11\n1 2 3 4 5 6 7 8 9 1 1",
"output": "3"
},
{
"input": "12\n1 2 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "14"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15"
},
{
"input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "16"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "10\n1 1 1 1 2 2 1 1 9 10",
"output": "6"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "56\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",
"output": "56"
},
{
"input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92",
"output": "6"
},
{
"input": "10\n1 2 2 3 3 3 4 4 4 4",
"output": "4"
},
{
"input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21",
"output": "3"
},
{
"input": "5\n5 5 5 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 5 2 6",
"output": "3"
},
{
"input": "3\n58 59 58",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 8",
"output": "2"
},
{
"input": "97\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",
"output": "97"
},
{
"input": "3\n95 95 4",
"output": "2"
},
{
"input": "3\n2 2 5",
"output": "2"
}
] | 1,697,005,260 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 307,200 | from collections import defaultdict
if __name__ == "__main__":
n = int(input())
a = list(map(int, input().split()))
mp = defaultdict(int)
for num in a:
mp[num] += 1
mx = max(mp.values())
print(mx) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Output Specification:
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Demo Input:
['6\n1 2 4 3 3 2\n', '1\n100\n']
Demo Output:
['2\n', '1\n']
Note:
none | ```python
from collections import defaultdict
if __name__ == "__main__":
n = int(input())
a = list(map(int, input().split()))
mp = defaultdict(int)
for num in a:
mp[num] += 1
mx = max(mp.values())
print(mx)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $y$-coordinates, and their $x$-coordinate is equal to $-100$, while the second group is positioned in such a way that they all have integer $y$-coordinates, and their $x$-coordinate is equal to $100$.
Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with $x=0$ (with not necessarily integer $y$-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 60$), the number of enemy spaceships with $x = -100$ and the number of enemy spaceships with $x = 100$, respectively.
The second line contains $n$ integers $y_{1,1}, y_{1,2}, \ldots, y_{1,n}$ ($|y_{1,i}| \le 10\,000$) — the $y$-coordinates of the spaceships in the first group.
The third line contains $m$ integers $y_{2,1}, y_{2,2}, \ldots, y_{2,m}$ ($|y_{2,i}| \le 10\,000$) — the $y$-coordinates of the spaceships in the second group.
The $y$ coordinates are not guaranteed to be unique, even within a group. | Print a single integer – the largest number of enemy spaceships that can be destroyed. | [
"3 9\n1 2 3\n1 2 3 7 8 9 11 12 13\n",
"5 5\n1 2 3 4 5\n1 2 3 4 5\n"
] | [
"9\n",
"10\n"
] | In the first example the first spaceship can be positioned at $(0, 2)$, and the second – at $(0, 7)$. This way all the enemy spaceships in the first group and $6$ out of $9$ spaceships in the second group will be destroyed.
In the second example the first spaceship can be positioned at $(0, 3)$, and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships. | 0 | [
{
"input": "3 9\n1 2 3\n1 2 3 7 8 9 11 12 13",
"output": "9"
},
{
"input": "5 5\n1 2 3 4 5\n1 2 3 4 5",
"output": "10"
},
{
"input": "50 50\n744 333 562 657 680 467 357 376 759 311 371 327 369 172 286 577 446 922 16 69 350 92 627 852 878 733 148 857 663 969 131 250 563 665 67 169 178 625 975 457 414 434 146 602 235 86 240 756 161 675\n222 371 393 634 76 268 348 294 227 429 835 534 756 67 174 704 685 462 829 561 249 148 868 512 118 232 33 450 445 420 397 129 122 74 426 441 989 892 662 727 492 702 352 818 399 968 894 297 342 405",
"output": "29"
},
{
"input": "60 60\n842 229 415 973 606 880 422 808 121 317 41 358 725 32 395 286 819 550 410 516 81 599 623 275 568 102 778 234 385 445 194 89 105 643 220 165 872 858 420 653 843 465 696 723 594 8 127 273 289 345 260 553 231 940 912 687 205 272 14 706\n855 361 529 341 602 225 922 807 775 149 212 789 547 766 813 624 236 583 207 586 516 21 621 839 259 774 419 286 537 284 685 944 223 189 358 232 495 688 877 920 400 105 968 919 543 700 538 466 739 33 729 292 891 797 707 174 799 427 321 953",
"output": "40"
},
{
"input": "1 5\n1\n1 2 3 4 5",
"output": "3"
},
{
"input": "5 1\n1 2 3 4 5\n1",
"output": "3"
},
{
"input": "2 2\n-10000 10000\n-10000 10000",
"output": "4"
},
{
"input": "8 57\n-107 1000 -238 -917 -918 668 -769 360\n124 250 601 242 189 155 688 -886 -504 39 -924 -266 -122 109 232 216 567 576 269 -349 257 589 -462 939 977 0 -808 118 -423 -856 769 954 889 21 996 -714 198 -854 981 -99 554 302 -27 454 -557 -585 465 -513 -113 714 -82 -906 522 75 -866 -942 -293",
"output": "8"
},
{
"input": "43 48\n-10 -4 -4 3 -4 3 -1 9 10 4 -2 -8 -9 -6 4 0 4 3 -1 -3 -1 7 10 -2 6 6 -4 -7 7 10 -5 -2 9 -4 -3 -1 -3 -9 0 -5 -6 -7 2\n-8 10 8 4 -3 7 2 -6 10 -1 4 -8 1 3 -8 5 2 4 8 7 -4 -7 8 -8 2 4 -2 4 2 1 -4 9 -3 -9 -1 6 -9 1 -6 -4 6 -2 3 5 5 6 -3 -3",
"output": "91"
},
{
"input": "8 9\n782 -300 482 -158 -755 809 -125 27\n0 251 593 796 371 839 -892 -954 236",
"output": "4"
},
{
"input": "54 41\n-5 9 -4 -7 8 -2 -5 -3 -10 -10 -9 2 9 1 -8 -5 -5 -3 1 -7 -2 -8 -5 -1 2 6 -2 -10 -7 5 2 -4 -9 -2 4 -6 5 5 -3 7 -5 2 7 0 -3 8 -10 5 6 -4 -7 3 -9 6\n-5 -5 10 3 2 5 -3 4 -5 -6 2 9 -7 3 0 -3 -10 -6 -5 -5 9 0 1 -6 1 0 -9 8 -10 -3 -2 -10 4 -1 -3 -10 -6 -7 -6 -3 2",
"output": "95"
},
{
"input": "46 52\n-31 11 38 -71 38 39 57 -31 -2 85 25 -85 17 -8 93 -1 75 -89 22 -61 -66 63 -91 80 -66 19 57 86 42 36 16 -65 -76 53 -21 85 -66 -96 85 45 35 29 54 18 -94 78\n-14 65 94 33 42 23 94 98 -44 -68 5 -27 -5 50 30 -56 49 -31 -61 34 9 -63 -92 48 17 99 -98 54 -13 34 46 13 -38 81 6 -58 68 -97 21 97 84 -10 5 11 99 -65 36 99 23 -20 -81 50",
"output": "53"
},
{
"input": "51 49\n-6 6 -4 -9 10 -5 1 -7 10 -7 -9 7 -6 5 -7 -5 5 6 -1 9 -10 6 -9 -7 1 7 6 -2 -6 0 -9 5 3 -9 0 8 -8 -5 -6 3 0 2 -1 -8 -3 -4 -8 0 1 -7 10\n-9 -4 10 -1 4 7 -2 5 -4 -8 0 -2 -10 10 9 9 10 -6 -8 -3 -6 -7 2 1 -4 -4 5 -5 5 2 8 -3 -7 5 10 7 2 -2 6 7 6 -3 -4 -8 -7 -3 5 -7 4",
"output": "100"
},
{
"input": "49 45\n293 126 883 638 33 -235 -591 -317 -532 -850 367 249 -470 373 -438 866 271 357 423 -972 -358 -418 531 -255 524 831 -200 -677 -424 -486 513 84 -598 86 525 -612 749 -525 -904 -773 599 170 -385 -44 40 979 -963 320 -875\n-197 47 -399 -7 605 -94 371 -752 370 459 297 775 -144 91 895 871 774 997 71 -23 301 138 241 891 -806 -990 111 -120 -233 552 557 633 -221 -804 713 -384 404 13 345 4 -759 -826 148 889 -270",
"output": "20"
},
{
"input": "59 50\n-85 -30 33 10 94 91 -53 58 -21 68 5 76 -61 -35 9 -19 -32 8 57 -75 -49 57 92 8 92 -39 98 -81 -55 -79 -9 36 19 57 -32 11 -68 60 -20 25 -65 1 -25 -59 -65 -30 93 -60 59 10 -92 -76 -83 71 -89 33 1 60 -65\n39 -57 -21 -13 9 34 -93 -11 56 0 -40 -85 18 -96 66 -29 -64 52 -61 -20 67 54 -20 83 -8 -20 75 37 75 -81 37 -67 -89 -91 -30 86 93 58 33 62 -68 -48 87 -7 72 -62 59 81 -6 30",
"output": "68"
},
{
"input": "57 57\n77 62 -5 -19 75 31 -71 29 -73 68 -4 42 -73 72 29 20 50 45 -4 28 73 -1 -25 69 -55 27 5 88 81 52 84 45 -11 -93 -4 23 -33 11 65 47 45 -83 -89 -11 -100 -26 89 41 35 -91 11 4 -23 57 38 17 -67\n68 75 5 10 -98 -17 73 68 -56 -82 69 55 62 -73 -75 -6 46 87 14 -81 -50 -69 -73 42 0 14 -82 -19 -5 40 -60 12 52 -46 97 70 45 -93 29 36 -41 61 -75 -84 -50 20 85 -33 10 80 33 50 44 -67 91 63 6",
"output": "64"
},
{
"input": "52 16\n-4770 -9663 -5578 4931 6841 2993 -9006 -1526 -7843 -6401 -3082 -1988 -790 -2443 135 3540 6817 1432 -5237 -588 2459 4466 -4806 -3125 -8135 2879 -7059 8579 5834 9838 4467 -8424 -115 -6929 3050 -9010 9686 -9669 -3200 8478 -605 4845 1800 3070 2025 3063 -3787 -2948 3255 1614 7372 1484\n8068 -5083 -2302 8047 8609 -1144 -2610 -7251 820 -9517 -7419 -1291 1444 4232 -5153 5539",
"output": "8"
},
{
"input": "8 7\n1787 -3614 8770 -5002 -7234 -8845 -585 -908\n1132 -7180 -5499 3850 352 2707 -8875",
"output": "4"
},
{
"input": "50 46\n17 29 -14 -16 -17 -54 74 -70 -43 5 80 15 82 -10 -21 -98 -98 -52 50 90 -2 97 -93 8 83 89 -31 44 -96 32 100 -4 77 36 71 28 -79 72 -18 89 -80 -3 -73 66 12 70 -78 -59 55 -44\n-10 -58 -14 -60 -6 -100 -41 -52 -67 -75 -33 -80 -98 -51 -76 92 -43 -4 -70 83 -70 28 -95 8 83 0 -54 -78 75 61 21 38 -53 -61 -95 4 -42 -43 14 60 -15 45 -73 -23 76 -73",
"output": "56"
},
{
"input": "6 8\n9115 641 -7434 1037 -612 -6061\n-8444 4031 7752 -7787 -1387 -9687 -1176 8891",
"output": "4"
},
{
"input": "60 13\n999 863 66 -380 488 494 -351 -911 -690 -341 -729 -215 -427 -286 -189 657 44 -577 655 646 731 -673 -49 -836 -768 -84 -833 -539 345 -244 562 -748 260 -765 569 -264 43 -853 -568 134 -574 -874 -64 -946 941 408 393 -741 155 -492 -994 -2 107 508 -560 15 -278 264 -875 -817\n-138 422 -958 95 245 820 -805 -27 376 121 -508 -951 977",
"output": "12"
},
{
"input": "50 58\n-7 7 10 1 4 1 10 -10 -8 2 1 5 -9 10 2 -3 -6 -7 -8 2 7 0 8 -2 -7 9 -4 8 -6 10 -9 -9 2 -8 8 0 -2 8 -10 -10 -10 2 8 -3 5 1 0 4 -9 -2\n6 6 -9 10 -2 -2 7 -5 9 -5 -7 -8 -8 5 -9 -3 -3 7 9 0 9 -1 1 5 1 0 -8 -9 -4 4 -4 5 -2 2 -7 -6 10 -1 -8 -3 6 -1 -10 -5 -10 3 9 7 5 -3 8 -7 6 9 1 10 -9 3",
"output": "108"
},
{
"input": "17 49\n17 55 -3 72 43 -91 1 -51 -5 -58 -30 -3 71 -39 44 9 7\n-38 -9 -74 -77 -14 14 78 13 -96 85 54 -83 -90 18 22 4 -61 23 -13 -38 -87 -79 -25 31 -64 47 -92 91 55 -8 -38 -34 -46 6 31 15 -72 80 -46 58 -1 90 -47 -28 53 31 -61 89 61",
"output": "27"
},
{
"input": "22 54\n484 -77 -421 -590 633 -472 -983 -396 756 -21 -320 -96 -590 -677 758 -556 -672 -798 430 -449 -213 -944\n309 -468 -484 973 -992 -385 -210 205 -318 350 468 196 802 461 286 -431 -81 984 286 -462 47 -647 -760 629 314 -388 986 507 898 287 -434 -390 95 -163 584 -67 655 -19 -756 50 215 833 -753 485 -127 62 -897 -898 1 -924 -224 30 -373 975",
"output": "17"
},
{
"input": "33 30\n-55 26 -48 -87 -87 -73 13 87 -79 -88 91 38 80 86 55 -66 72 -72 -77 -41 95 11 13 -99 -23 -66 -20 35 90 -40 59 -2 43\n-56 -23 16 51 78 -58 -61 -18 -7 -57 -8 86 -44 -47 -70 -31 -34 -80 -85 -21 53 93 -93 88 -54 -83 97 57 47 80",
"output": "28"
},
{
"input": "10 8\n8780 -6753 -8212 -1027 1193 -6328 -4260 -8031 4114 -135\n-6545 1378 6091 -4158 3612 1509 -8731 1391",
"output": "4"
},
{
"input": "10 5\n-7722 3155 -4851 -5222 -2712 4693 -3099 222 -4282 -4848\n3839 3098 -8804 4627 -7437",
"output": "4"
},
{
"input": "4 10\n1796 5110 -8430 -617\n9903 -5666 -2809 -4878 -284 -1123 5202 -3694 -789 5483",
"output": "4"
},
{
"input": "46 60\n-119 682 371 355 -473 978 -474 311 379 -311 601 -287 683 625 982 -772 -706 -995 451 -877 452 -823 -51 826 -771 -419 -215 -502 -110 -454 844 -433 942 250 155 -787 628 282 -818 -784 282 -888 200 628 -320 62\n-389 -518 341 98 -138 -816 -628 81 567 112 -220 -122 -307 -891 -85 253 -352 -244 194 779 -884 866 -23 298 -191 -497 106 -553 -612 -48 -279 847 -721 195 -397 -455 486 -572 -489 -183 -582 354 -542 -371 -330 -105 -110 -536 -559 -487 -297 -533 813 281 847 -786 8 -179 394 -734",
"output": "19"
},
{
"input": "39 31\n268 -441 -422 252 377 420 749 748 660 893 -309 722 -612 -667 363 79 650 884 -672 -880 518 -936 806 376 359 -965 -964 138 851 717 -131 316 603 -375 114 421 976 688 -527\n-989 -76 -404 971 -572 771 149 674 -471 218 -317 -225 994 10 509 719 915 -811 -57 -995 865 -486 7 -766 143 -53 699 -466 -165 -486 602",
"output": "15"
},
{
"input": "5 3\n-8452 -1472 4013 -5048 -6706\n-8387 -7493 -7090",
"output": "4"
},
{
"input": "58 58\n-2 79 3 14 40 -23 87 -86 80 -23 77 12 55 -81 59 -84 -66 89 92 -85 14 -44 -28 -75 77 -36 97 69 21 -31 -26 -13 9 83 -70 38 58 79 -34 68 -52 -50 -68 41 86 -9 -87 64 90 -88 -55 -32 35 100 76 -85 63 -29\n68 3 -18 -13 -98 -52 -90 -21 43 -63 -97 49 40 65 -96 83 15 2 76 54 50 49 4 -71 -62 53 26 -90 -38 -24 71 -69 -58 -86 66 5 31 -23 -76 -34 -79 72 7 45 -86 -97 -43 85 -51 -76 26 98 58 -28 58 44 82 -70",
"output": "79"
},
{
"input": "9 10\n-393 439 961 649 441 -536 -453 989 733\n-952 -776 674 696 -452 -700 58 -430 540 271",
"output": "8"
},
{
"input": "8 6\n-90 817 655 798 -547 -390 -828 -50\n-626 -365 426 139 513 -607",
"output": "6"
},
{
"input": "54 11\n-10 5 -4 -7 -2 10 -10 -4 6 4 9 -7 -10 8 8 6 0 -6 8 4 -6 -1 6 4 -6 1 -2 8 -5 -2 -9 -8 9 6 1 2 10 3 1 3 -3 -10 8 -2 3 9 8 3 -9 -5 -6 -2 -5 -6\n10 1 0 -9 -5 -6 8 0 -3 5 -5",
"output": "55"
},
{
"input": "6 7\n3403 -4195 5813 -1096 -9300 -959\n-4820 9153 2254 6322 -5071 6383 -687",
"output": "4"
},
{
"input": "41 56\n6 2 0 -3 3 6 0 10 -7 -5 -5 7 -5 -9 -3 -5 -2 9 5 -1 1 8 -2 1 -10 10 -4 -9 10 -8 8 7 7 7 4 4 -2 2 4 -6 -7\n9 6 -5 6 -7 2 -6 -3 -6 -1 10 -5 -5 3 10 10 4 3 0 2 8 4 -3 3 9 4 -6 0 2 6 6 -2 0 -3 -5 3 4 -2 -3 10 -10 1 3 -3 -7 2 -2 2 0 4 -6 8 -4 -1 1 -6",
"output": "97"
},
{
"input": "45 57\n-5 -3 -10 2 -3 1 10 -3 -3 -7 -9 6 6 1 8 2 -4 3 -6 9 8 10 -1 8 -2 -8 -9 -7 -8 4 -1 -10 0 -4 8 -7 3 -1 0 3 -8 -10 -6 -8 -5\n1 3 -1 7 1 10 3 -2 8 6 0 2 -3 -3 10 -10 -6 -7 10 5 9 10 3 -2 4 10 -10 0 -2 4 -6 -1 -1 -5 7 -3 -2 -7 7 -2 2 2 1 -10 -7 -8 -3 4 0 8 -5 -7 -7 9 -3 8 -5",
"output": "102"
},
{
"input": "51 39\n-10 6 -8 2 6 6 0 2 4 -3 8 10 7 1 9 -8 4 -2 3 5 8 -2 1 3 1 3 -5 0 2 2 7 -3 -10 4 9 -3 -7 5 5 10 -5 -5 9 -3 9 -1 -4 9 -7 -8 5\n-5 10 -2 -8 -10 5 -7 1 7 6 -3 -5 0 -4 0 -9 2 -9 -10 2 -6 10 0 4 -4 -8 -3 1 10 7 5 7 0 -7 1 0 9 0 -5",
"output": "90"
},
{
"input": "4 10\n3 -7 -4 -8\n7 3 -1 -8 2 -1 -5 8 -8 9",
"output": "12"
},
{
"input": "44 41\n-6 0 -2 5 5 -9 -4 -5 -2 -6 -7 -10 5 2 -6 -3 1 4 8 2 -7 6 5 0 10 -2 -9 3 -6 -3 7 5 -3 7 -10 -1 6 0 10 -6 -5 -6 -6 6\n6 -3 1 -1 8 9 6 7 -6 -4 -2 -4 -3 3 2 -1 3 1 10 -2 2 -10 -9 -3 8 -3 -1 -4 0 0 -4 7 -10 6 10 -8 5 6 2 -9 -4",
"output": "85"
},
{
"input": "52 43\n-514 -667 -511 516 -332 73 -233 -594 125 -847 -584 432 631 -673 -380 835 69 523 -568 -110 -752 -731 864 250 550 -249 525 357 8 43 -395 -328 61 -84 -151 165 -896 955 -660 -195 375 806 -160 870 143 -725 -814 494 -953 -463 704 -415\n608 -584 673 -920 -227 -442 242 815 533 -184 -502 -594 -381 -960 786 -627 -531 -579 583 -252 -445 728 902 934 -311 971 119 -391 710 -794 738 -82 774 580 -142 208 704 -745 -509 979 -236 -276 -800",
"output": "18"
},
{
"input": "51 48\n642 261 822 -266 700 18 -62 -915 39 997 564 -130 605 -141 58 426 -514 425 -310 -56 -524 860 -793 57 511 -563 -529 -140 -679 -489 -841 -326 -108 -785 599 3 -90 -52 769 -513 -328 -709 -887 736 729 -148 232 680 -589 77 531\n689 765 386 700 612 -936 -258 966 873 130 230 -78 -835 739 -755 127 -963 -282 -728 -833 345 -817 -61 680 944 -475 -46 -915 777 -789 -742 -755 325 -474 -220 544 19 828 -483 -388 -330 -150 -912 -219 185 -541 237 724",
"output": "20"
},
{
"input": "35 32\n8 3 9 -6 -6 -3 -6 2 2 3 0 -4 8 9 -10 -7 7 -6 -4 1 -9 3 -2 3 -4 -8 -8 5 -10 2 6 4 -7 -6 -1\n7 -2 1 -9 1 8 4 -4 -4 -7 5 4 0 3 5 8 9 -7 -1 -8 -1 7 2 5 6 -2 -8 -2 9 -6 8 -6",
"output": "67"
},
{
"input": "54 55\n-95 -3 -18 81 -85 -78 -76 95 -4 -91 88 98 35 88 -30 -82 -1 23 -98 82 -83 100 -47 -7 93 -87 -57 -5 -57 -46 30 -16 -27 -46 78 -58 4 87 86 -58 22 19 -40 8 -6 92 -65 10 -51 -34 -70 -69 -70 -51\n-42 75 48 -79 58 23 -8 47 48 33 -2 97 -30 -8 -87 56 22 -91 25 27 -91 -75 -10 45 -27 54 -94 60 -49 22 18 2 35 -81 8 -61 91 12 78 6 -83 76 -81 -27 -65 56 -99 -69 3 91 81 -34 9 -29 61",
"output": "63"
},
{
"input": "18 4\n81 -30 22 81 -9 -66 -39 -11 16 9 91 74 -36 40 -26 -11 -13 -22\n21 67 96 96",
"output": "8"
},
{
"input": "5 5\n9 9 -7 -4 6\n2 3 -3 -8 -1",
"output": "7"
},
{
"input": "44 49\n28 76 41 66 49 31 3 4 41 89 44 41 33 73 5 -85 57 -55 86 43 25 0 -26 -36 81 -80 -71 77 96 85 -8 -96 -91 28 3 -98 -82 -87 -50 70 -39 -99 -70 66\n-12 28 11 -25 -34 70 -4 69 9 -31 -23 -8 19 -54 -5 -24 -7 -45 -70 -71 -64 77 39 60 -63 10 -7 -92 22 4 45 75 100 49 95 -66 -96 -85 -35 92 -9 -37 -38 62 -62 24 -35 40 3",
"output": "52"
},
{
"input": "57 41\n-10 9 2 7 -1 1 -10 9 7 -9 -4 8 4 -8 -6 8 1 5 -7 9 8 -4 1 -2 -7 6 -9 -10 3 0 8 7 1 -4 -6 9 -10 8 3 -9 4 -9 6 -7 10 -4 3 -4 10 -1 -7 -7 -10 -10 0 3 -10\n-2 1 -5 6 0 -2 -4 8 2 -9 -6 7 2 6 -9 -1 -1 3 -4 -8 -4 -10 7 -1 -6 -5 -7 5 10 -5 -4 4 -7 6 -2 -9 -10 3 -7 -5 -9",
"output": "98"
},
{
"input": "9 5\n7 -5 -2 -3 -10 -3 5 4 10\n-1 6 -4 3 2",
"output": "11"
},
{
"input": "31 55\n68 -31 19 47 95 -44 67 45 32 -17 31 -14 52 -19 -75 97 88 9 -11 77 -23 74 -29 31 -42 -15 -77 30 -17 75 -9\n-63 94 98 45 -57 -41 4 34 38 67 68 69 -36 47 91 -55 58 73 77 -71 4 -89 -6 49 71 70 -64 -24 -87 -3 -96 62 -31 -56 -2 88 -80 95 -97 -91 25 -2 1 -80 -45 -96 -62 12 12 -61 -13 23 -32 6 29",
"output": "43"
},
{
"input": "50 59\n-6 -5 8 -6 7 9 2 -7 0 -9 -7 1 -5 10 -6 -2 -10 6 -6 -2 -7 -10 1 4 -4 9 2 -8 -3 -1 5 -4 2 8 -10 7 -10 4 8 7 -4 9 1 5 -10 -7 -2 3 -9 5\n-10 -1 3 9 0 8 5 10 -6 -2 -2 4 4 -1 -3 -9 4 -6 9 -5 -5 -4 -7 -2 9 6 -3 -6 -1 -9 1 9 2 -9 2 -5 3 7 -10 7 -3 -1 -10 -3 2 6 -2 -5 10 5 8 7 4 6 -7 -5 2 -2 -10",
"output": "109"
},
{
"input": "53 51\n678 -657 703 569 -524 -801 -221 -600 -95 11 -660 866 506 683 649 -842 604 -33 -929 541 379 939 -512 -347 763 697 653 844 927 488 -233 -313 357 -717 119 885 -864 738 -20 -350 -724 906 -41 324 -713 424 -432 154 173 406 29 -420 62\n-834 648 564 735 206 490 297 -968 -482 -914 -149 -312 506 56 -773 527 816 137 879 552 -224 811 -786 739 -828 -203 -873 148 -290 395 832 -845 302 -324 32 299 746 638 -684 216 392 -137 496 57 -187 477 -16 395 -325 -186 -801",
"output": "24"
},
{
"input": "51 7\n323 236 120 48 521 587 327 613 -470 -474 522 -705 320 -51 1 288 -430 -954 732 -805 -562 300 -710 190 515 280 -101 -927 77 282 198 -51 -350 -990 -435 -765 178 -934 -955 704 -565 -640 853 -27 950 170 -712 -780 620 -572 -409\n244 671 425 977 773 -294 268",
"output": "9"
},
{
"input": "9 9\n-9 -1 2 8 10 2 9 7 3\n5 8 -5 4 -4 -8 2 8 -8",
"output": "16"
},
{
"input": "50 60\n445 303 -861 -583 436 -125 312 -700 -829 -865 -276 -25 -725 -286 528 -221 757 720 -572 514 -514 359 294 -992 -838 103 611 776 830 143 -247 182 -241 -627 299 -824 635 -571 -660 924 511 -876 160 569 -570 827 75 558 708 46\n899 974 750 -138 -439 -904 -113 -761 -150 -92 -279 489 323 -649 -759 667 -600 -76 -991 140 701 -654 -276 -563 108 -301 161 -989 -852 -97 316 31 -724 848 979 -501 -883 569 925 -532 86 456 302 -985 826 79 -911 660 752 941 -464 -157 -110 433 829 -872 172 496 528 -576",
"output": "24"
},
{
"input": "7 3\n90 67 1 68 40 -100 -26\n-96 70 -74",
"output": "6"
},
{
"input": "7 4\n-8 -2 -5 -3 -8 -9 8\n-8 4 -1 10",
"output": "8"
},
{
"input": "52 48\n-552 43 -670 -163 -765 -603 -768 673 -248 337 -89 941 -676 -406 280 409 -630 -577 324 115 927 477 -242 108 -337 591 -158 -524 928 859 825 935 818 638 -51 988 -568 871 -842 889 -737 -272 234 -643 766 -422 473 -570 -1000 -735 -279 845\n963 -436 738 113 273 -374 -568 64 276 -698 -135 -748 909 -250 -740 -344 -436 414 719 119 973 -881 -576 868 -45 909 630 286 -845 458 684 -64 579 965 598 205 -318 -974 228 -596 596 -946 -198 923 571 -907 -911 -341",
"output": "21"
},
{
"input": "40 54\n-26 -98 27 -64 0 33 62 -12 -8 -10 -62 28 28 75 -5 -89 -75 -100 -63 9 -97 -20 -81 62 56 -39 87 -33 13 61 19 -97 -23 95 18 -4 -48 55 -40 -81\n-69 -71 1 -46 -58 0 -100 -82 31 43 -59 -43 77 -8 -61 -2 -36 -55 -35 -44 -59 -13 -16 14 60 -95 -61 25 76 -1 -3 9 -92 48 -92 -54 2 -7 73 -16 42 -40 36 -58 97 81 13 -64 -12 -28 65 85 -61 8",
"output": "54"
},
{
"input": "22 34\n-73 45 -81 -67 9 61 -97 0 -64 86 -9 47 -28 100 79 -53 25 -59 -80 -86 -47 24\n57 69 8 -34 -37 12 -32 -81 27 -65 87 -64 62 -44 97 34 44 -93 44 25 -72 93 14 95 -60 -65 96 -95 23 -69 28 -20 -95 74",
"output": "27"
},
{
"input": "46 48\n-710 947 515 217 26 -548 -416 494 431 -872 -616 848 -950 -138 -104 560 241 -462 -265 90 66 -331 934 -788 -815 -558 86 39 784 86 -856 879 -733 -653 104 -673 -588 -568 78 368 -226 850 195 982 140 370\n470 -337 283 460 -710 -434 739 459 -567 173 217 511 -830 644 -734 764 -211 -106 423 -356 -126 677 -454 42 680 557 -636 9 -552 877 -246 -352 -44 442 -505 -811 -100 -768 -130 588 -428 755 -904 -138 14 -253 -40 265",
"output": "20"
},
{
"input": "58 40\n120 571 -472 -980 993 -885 -546 -220 617 -697 -182 -42 128 -29 567 -615 -260 -876 -507 -642 -715 -283 495 -584 97 4 376 -131 186 -301 729 -545 8 -610 -643 233 -123 -769 -173 119 993 825 614 -503 891 426 -850 -992 -406 784 634 -294 997 127 697 -509 934 316\n630 -601 937 -544 -50 -176 -885 530 -828 556 -784 460 -422 647 347 -862 131 -76 490 -576 5 -761 922 -426 -7 -401 989 -554 688 -531 -303 -415 -507 -752 -581 -589 513 -151 -279 317",
"output": "18"
},
{
"input": "8 6\n23 -18 -94 -80 74 89 -48 61\n-84 45 -12 -9 -74 63",
"output": "7"
},
{
"input": "57 55\n-34 744 877 -4 -902 398 -404 225 -560 -600 634 180 -198 703 910 681 -864 388 394 -317 839 -95 -706 -474 -340 262 228 -196 -35 221 -689 -960 -430 946 -231 -146 741 -754 330 217 33 276 381 -734 780 -522 528 -425 -202 -19 -302 -743 53 -247 69 -314 -845\n-158 24 461 -274 -30 -58 223 -806 747 568 -59 126 56 661 8 419 -422 320 340 480 -185 905 -459 -530 -50 -484 303 366 889 404 915 -361 -985 -642 -690 -577 -80 -250 173 -740 385 908 -4 593 -559 731 326 -209 -697 490 265 -548 716 320 23",
"output": "24"
},
{
"input": "59 56\n-8 -8 -4 5 -4 4 4 -5 -10 -2 0 6 -9 -2 10 1 -8 -2 9 5 2 -1 -5 7 -7 7 2 -7 -5 2 -2 -8 4 10 5 -9 5 9 6 10 7 6 -6 -4 -8 5 9 6 1 -7 5 -9 8 10 -7 1 3 -6 8\n6 -2 -7 4 -2 -5 -9 -5 0 8 5 5 -4 -6 -5 -10 4 3 -4 -4 -8 2 -6 -10 -10 4 -3 8 -1 8 -8 -5 -2 3 7 3 -8 10 6 0 -8 0 9 -3 9 0 9 0 -3 4 -3 10 10 5 -6 4",
"output": "115"
},
{
"input": "53 30\n-4206 -1169 3492 6759 5051 -3338 4024 8267 -4651 -7685 -3346 -4958 2648 9321 6062 -3566 8118 9067 -1331 5064 148 6375 6193 -2024 -9376 -663 3837 3989 6583 6971 -146 2515 -4222 8159 -94 -4937 -8364 -6025 3566 556 -5229 3138 -9504 1383 1171 -3918 -1587 -6532 -2299 -6648 -5861 4864 9220\n-2359 7436 1682 1775 3850 2691 -4326 6670 3245 -3821 5932 -1159 6162 -2818 -5255 -7439 -6688 1778 -5132 8085 -3576 9153 -5260 -1438 9941 -4729 532 -5206 2133 -2252",
"output": "10"
},
{
"input": "4 9\n-2 3 -5 -10\n7 -7 5 5 2 4 9 -4 5",
"output": "11"
},
{
"input": "44 50\n23 -401 692 -570 264 -885 417 -355 560 -254 -468 -849 900 997 559 12 853 424 -579 485 711 67 638 771 -750 -583 294 -410 -225 -117 -262 148 385 627 610 983 -345 -236 -62 635 -421 363 88 682\n-204 -429 -74 855 533 -817 -613 205 972 941 -566 -813 79 -660 -604 661 273 -70 -70 921 -240 148 314 328 -155 -56 -793 259 -630 92 -975 -361 671 963 430 315 -94 957 465 548 -796 626 -58 -595 315 -455 -918 398 279 99",
"output": "22"
},
{
"input": "53 30\n5 10 -1 -9 7 -7 1 6 0 7 2 -2 -2 1 -9 -9 2 -7 9 10 -9 1 -1 -9 -9 -5 -8 -3 2 4 -3 -6 6 4 -2 -3 -3 -9 2 -4 9 5 6 -5 -5 6 -2 -1 10 7 4 -4 -2\n-1 10 3 -1 7 10 -2 -1 -2 0 3 -10 -6 1 -9 2 -10 9 6 -7 -9 3 -7 1 0 9 -8 2 9 7",
"output": "82"
},
{
"input": "9 9\n1 10 0 -2 9 -7 1 -4 3\n-7 -1 6 -4 8 2 6 6 -3",
"output": "15"
},
{
"input": "9 9\n5181 -7243 3653 3587 -5051 -4899 -4110 7981 -6429\n-7365 -2247 7942 9486 -7160 -1020 -8934 7733 -3010",
"output": "4"
},
{
"input": "55 43\n9 1 0 -7 4 3 4 4 -8 3 0 -7 0 -9 3 -6 0 4 7 1 -1 -10 -7 -6 -8 -8 2 -5 5 -4 -9 -7 5 -3 -7 -10 -4 -2 -7 -3 2 4 9 8 -8 9 -10 0 0 3 -6 -5 -2 9 -6\n-4 -6 9 -4 -2 5 9 6 -8 -2 -3 -7 -8 8 -8 5 1 7 9 7 -5 10 -10 -8 -3 10 0 8 8 4 8 3 10 -8 -4 -6 1 9 0 -3 -4 8 -10",
"output": "98"
},
{
"input": "53 12\n63 88 91 -69 -15 20 98 40 -70 -49 -51 -74 -34 -52 1 21 83 -14 57 40 -57 33 94 2 -74 22 86 79 9 -18 67 -31 72 31 -64 -83 83 29 50 -29 -27 97 -40 -8 -57 69 -93 18 42 68 -71 -86 22\n51 19 33 12 98 91 -83 65 -6 16 81 86",
"output": "27"
},
{
"input": "1 1\n0\n0",
"output": "2"
},
{
"input": "3 3\n1 1 1\n1 2 2",
"output": "6"
},
{
"input": "1 1\n1\n1",
"output": "2"
},
{
"input": "1 1\n0\n1",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 0",
"output": "6"
},
{
"input": "5 5\n5 5 5 5 5\n5 5 5 5 5",
"output": "10"
},
{
"input": "60 60\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59\n0 60 120 180 240 300 360 420 480 540 600 660 720 780 840 900 960 1020 1080 1140 1200 1260 1320 1380 1440 1500 1560 1620 1680 1740 1800 1860 1920 1980 2040 2100 2160 2220 2280 2340 2400 2460 2520 2580 2640 2700 2760 2820 2880 2940 3000 3060 3120 3180 3240 3300 3360 3420 3480 3540",
"output": "4"
},
{
"input": "2 2\n0 2\n0 1",
"output": "4"
},
{
"input": "1 1\n5\n5",
"output": "2"
},
{
"input": "10 10\n1 1 1 1 1 1 1 1 1 1\n-30 -30 -30 -30 40 40 40 40 40 40",
"output": "20"
}
] | 1,529,247,637 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 512,000 | from sys import stdin
line = stdin.readline().rstrip().split()
n = int(line[0])
m = int(line[1])
numbers1 = list(map(lambda x: int(x)+10000, stdin.readline().rstrip().split()))
numbers2 = list(map(lambda x: int(x)+10000, stdin.readline().rstrip().split()))
ys = {}
for i in range(n):
num = numbers1[i]
for j in range(m):
num2 = numbers2[j]
y = round((num + num2)/2, 4)
if y not in ys:
ys[y] = ([0]*n, [0]*m)
ys[y][0][i] = 1
ys[y][1][j] = 1
maxT = 0
for value1 in ys.values():
for value2 in ys.values():
list1 = [abs(((a-1)*(b-1))-1) for a,b in zip(value1[0], value2[0])]
list2 = [abs(((a-1)*(b-1))-1) for a,b in zip(value1[1], value2[1])]
cMax = sum(list1) + sum(list2)
maxT = max(cMax, maxT)
print(maxT)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $y$-coordinates, and their $x$-coordinate is equal to $-100$, while the second group is positioned in such a way that they all have integer $y$-coordinates, and their $x$-coordinate is equal to $100$.
Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with $x=0$ (with not necessarily integer $y$-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots.
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 60$), the number of enemy spaceships with $x = -100$ and the number of enemy spaceships with $x = 100$, respectively.
The second line contains $n$ integers $y_{1,1}, y_{1,2}, \ldots, y_{1,n}$ ($|y_{1,i}| \le 10\,000$) — the $y$-coordinates of the spaceships in the first group.
The third line contains $m$ integers $y_{2,1}, y_{2,2}, \ldots, y_{2,m}$ ($|y_{2,i}| \le 10\,000$) — the $y$-coordinates of the spaceships in the second group.
The $y$ coordinates are not guaranteed to be unique, even within a group.
Output Specification:
Print a single integer – the largest number of enemy spaceships that can be destroyed.
Demo Input:
['3 9\n1 2 3\n1 2 3 7 8 9 11 12 13\n', '5 5\n1 2 3 4 5\n1 2 3 4 5\n']
Demo Output:
['9\n', '10\n']
Note:
In the first example the first spaceship can be positioned at $(0, 2)$, and the second – at $(0, 7)$. This way all the enemy spaceships in the first group and $6$ out of $9$ spaceships in the second group will be destroyed.
In the second example the first spaceship can be positioned at $(0, 3)$, and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships. | ```python
from sys import stdin
line = stdin.readline().rstrip().split()
n = int(line[0])
m = int(line[1])
numbers1 = list(map(lambda x: int(x)+10000, stdin.readline().rstrip().split()))
numbers2 = list(map(lambda x: int(x)+10000, stdin.readline().rstrip().split()))
ys = {}
for i in range(n):
num = numbers1[i]
for j in range(m):
num2 = numbers2[j]
y = round((num + num2)/2, 4)
if y not in ys:
ys[y] = ([0]*n, [0]*m)
ys[y][0][i] = 1
ys[y][1][j] = 1
maxT = 0
for value1 in ys.values():
for value2 in ys.values():
list1 = [abs(((a-1)*(b-1))-1) for a,b in zip(value1[0], value2[0])]
list2 = [abs(((a-1)*(b-1))-1) for a,b in zip(value1[1], value2[1])]
cMax = sum(list1) + sum(list2)
maxT = max(cMax, maxT)
print(maxT)
``` | 0 |
|
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"output": "5"
},
{
"input": "100\n968 793 -628 -416 942 -308 977 168 728 -879 952 781 -425 -475 -480 738 -740 142 -319 -116 -701 -183 41 324 -918 -391 -176 781 763 888 475 -617 134 -802 -133 -211 855 -869 -236 503 550 387 137 -221 -957 -800 -56 -673 440 -791 -217 -959 -892 886 -593 427 890 223 -425 -342 -262 693 -137 924 860 156 -110 444 -12 703 421 -638 725 -551 597 -206 -80 393 -441 -759 617 424 -506 209 579 -685 -861 507 312 597 -81 -491 424 222 -892 629 512 743 -452 -504",
"output": "99"
}
] | 1,656,164,574 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 4,300,800 | n = int(input())
A = list(map(int, input().split()))
sm = sum(A)
print(max(n-sm%n, sm%n))
######################
######################
######################
######################
######################
######################
| Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array.
Output Specification:
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Demo Input:
['2\n2 1\n', '3\n1 4 1\n']
Demo Output:
['1\n', '3\n']
Note:
none | ```python
n = int(input())
A = list(map(int, input().split()))
sm = sum(A)
print(max(n-sm%n, sm%n))
######################
######################
######################
######################
######################
######################
``` | 0 |
|
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"input": "ABAXXXAB",
"output": "YES"
},
{
"input": "TESTABAXXABTEST",
"output": "YES"
},
{
"input": "A",
"output": "NO"
},
{
"input": "B",
"output": "NO"
},
{
"input": "X",
"output": "NO"
},
{
"input": "BA",
"output": "NO"
},
{
"input": "AB",
"output": "NO"
},
{
"input": "AA",
"output": "NO"
},
{
"input": "BB",
"output": "NO"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "AAB",
"output": "NO"
},
{
"input": "BAA",
"output": "NO"
},
{
"input": "ABB",
"output": "NO"
},
{
"input": "BBA",
"output": "NO"
},
{
"input": "AAA",
"output": "NO"
},
{
"input": "BBB",
"output": "NO"
},
{
"input": "AXBXBXA",
"output": "NO"
},
{
"input": "SKDSKDJABSDBADKFJDK",
"output": "YES"
},
{
"input": "ABAXXBBXXAA",
"output": "NO"
},
{
"input": "ABAB",
"output": "NO"
},
{
"input": "BABA",
"output": "NO"
},
{
"input": "AAAB",
"output": "NO"
},
{
"input": "AAAA",
"output": "NO"
},
{
"input": "AABA",
"output": "NO"
},
{
"input": "ABAA",
"output": "NO"
},
{
"input": "BAAA",
"output": "NO"
},
{
"input": "AABB",
"output": "NO"
},
{
"input": "BAAB",
"output": "YES"
},
{
"input": "BBAA",
"output": "NO"
},
{
"input": "BBBA",
"output": "NO"
},
{
"input": "BBAB",
"output": "NO"
},
{
"input": "BABB",
"output": "NO"
},
{
"input": "ABBB",
"output": "NO"
},
{
"input": "BBBB",
"output": "NO"
},
{
"input": "BABAB",
"output": "YES"
},
{
"input": "ABABA",
"output": "YES"
},
{
"input": "AAABAAACBBBC",
"output": "NO"
},
{
"input": "AABBBACBBBBBBAACBCCACBBAABBBBBCAACABAACABCACCBCBCCCBCBCABCBBCCBCBBAACBACAABACBBCACCBCCACCABBCBABBAAC",
"output": "YES"
},
{
"input": "CBBABDDBBADAC",
"output": "YES"
},
{
"input": "ABYFAB",
"output": "NO"
},
{
"input": "BABXXAB",
"output": "YES"
},
{
"input": "ABAXAB",
"output": "YES"
},
{
"input": "ABABXAB",
"output": "YES"
},
{
"input": "ABXABXABXABXABXBAXBAXBAXBA",
"output": "YES"
},
{
"input": "QQQQQQQQQABABQQQQQQQQ",
"output": "NO"
}
] | 1,694,986,692 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | #https://codeforces.com/problemset/problem/550/A
s=input()
lists=["AB","BA"]
lists2=["BA","AB"]
st=""
nlists=[]
for i in s:
if (i=="A" or i=="B") and i not in st:
st+=i
if st in lists:
nlists.append(st)
st=""
elif st=="A" and i!="B":
st=""
elif st=="B" and i!="A":
st=""
if nlists==lists or nlists==lists2:
print("YES")
else:
print("NO") | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Output Specification:
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
Demo Input:
['ABA\n', 'BACFAB\n', 'AXBYBXA\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | ```python
#https://codeforces.com/problemset/problem/550/A
s=input()
lists=["AB","BA"]
lists2=["BA","AB"]
st=""
nlists=[]
for i in s:
if (i=="A" or i=="B") and i not in st:
st+=i
if st in lists:
nlists.append(st)
st=""
elif st=="A" and i!="B":
st=""
elif st=="B" and i!="A":
st=""
if nlists==lists or nlists==lists2:
print("YES")
else:
print("NO")
``` | 0 |
|
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*). | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
{
"input": "70 38 66",
"output": "9"
},
{
"input": "54 4 38",
"output": "17"
},
{
"input": "3 1 69",
"output": "2"
},
{
"input": "11 9 60",
"output": "0"
},
{
"input": "71 49 65",
"output": "0"
},
{
"input": "78 55 96",
"output": "20"
},
{
"input": "2765 768 9020",
"output": "248635"
},
{
"input": "3478 1728 9727",
"output": "336578"
},
{
"input": "9678 6173 5658",
"output": "541409"
},
{
"input": "1138 570 6666",
"output": "75290"
},
{
"input": "7754 204 9038",
"output": "700603"
},
{
"input": "8403 7401 4769",
"output": "393339"
},
{
"input": "4909 2111 8860",
"output": "432827"
},
{
"input": "6571 6449 8965",
"output": "582642"
},
{
"input": "9178 2255 7996",
"output": "731618"
},
{
"input": "6151 6148 3746",
"output": "224269"
},
{
"input": "8890 5449 8734",
"output": "771004"
},
{
"input": "7879 2590 2818",
"output": "219441"
},
{
"input": "8484 6400 547",
"output": "40008"
},
{
"input": "7835 6710 1639",
"output": "121706"
},
{
"input": "2379 1436 9663",
"output": "228447"
},
{
"input": "6487 5670 8",
"output": "0"
},
{
"input": "4470 2543 6",
"output": "0"
},
{
"input": "7261 5328 10",
"output": "0"
},
{
"input": "3871 3795 7",
"output": "0"
},
{
"input": "9620 6557 6",
"output": "0"
},
{
"input": "4890 1112 5",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 1 10000",
"output": "99"
},
{
"input": "10000 1 1",
"output": "99"
},
{
"input": "10000 1 10000",
"output": "999999"
},
{
"input": "10000 10000 1",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "990000"
},
{
"input": "67 1 3",
"output": "2"
},
{
"input": "7878 4534 9159",
"output": "717013"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "3271 5 50",
"output": "1631"
}
] | 1,594,465,542 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 624 | 29,900,800 | import decimal
D = decimal.Decimal
l1 = [int(x) for x in input().split()]
n,x,y = l1[0],l1[1],l1[2]
need = n*y
have = x*100
extra = 0
i=0
while need-have>extra:
extra+=100
i+=1
print(i) | Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
Input Specification:
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*).
Output Specification:
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
Demo Input:
['10 1 14\n', '20 10 50\n', '1000 352 146\n']
Demo Output:
['1\n', '0\n', '1108\n']
Note:
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. | ```python
import decimal
D = decimal.Decimal
l1 = [int(x) for x in input().split()]
n,x,y = l1[0],l1[1],l1[2]
need = n*y
have = x*100
extra = 0
i=0
while need-have>extra:
extra+=100
i+=1
print(i)
``` | 3 |
|
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"output": "444"
},
{
"input": "1000000",
"output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "47",
"output": "44477777"
},
{
"input": "100",
"output": "4444777777777777"
},
{
"input": "700",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "485",
"output": "44447777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "111",
"output": "444447777777777777"
},
{
"input": "85",
"output": "4477777777777"
},
{
"input": "114",
"output": "444477777777777777"
},
{
"input": "474",
"output": "444777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "74",
"output": "47777777777"
},
{
"input": "1000",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "1024",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "4444",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "45784",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10000",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "9854",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "186",
"output": "477777777777777777777777777"
},
{
"input": "10416",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10417",
"output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "3840",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "100000",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "9876",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "99999",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "777777",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "854759",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "11000",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "18951",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999999",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "888887",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999998",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "40008",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10691",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "-1"
},
{
"input": "9",
"output": "-1"
},
{
"input": "8",
"output": "44"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "-1"
},
{
"input": "999997",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999996",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999990",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999980",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "800000",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "980000",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
}
] | 1,587,842,113 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 218 | 716,800 |
n=int(input())
def num(j,i=0,k=0):
if j<0:
return 0
if j==0:
return int('4'*i+'7'*k)
else:
x=num(j-4,i+1,k)
y=num(j-7,i,k+1)
if x!=0 and y!=0:
return min(x,y)
elif x==0 and y!=0:
return y
elif y==0 and x!=0:
return x
return 0
x=num(n)
if x==0:
print(-1)
else:
print(x)
| Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Output Specification:
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
Demo Input:
['11\n', '10\n']
Demo Output:
['47\n', '-1\n']
Note:
none | ```python
n=int(input())
def num(j,i=0,k=0):
if j<0:
return 0
if j==0:
return int('4'*i+'7'*k)
else:
x=num(j-4,i+1,k)
y=num(j-7,i,k+1)
if x!=0 and y!=0:
return min(x,y)
elif x==0 and y!=0:
return y
elif y==0 and x!=0:
return x
return 0
x=num(n)
if x==0:
print(-1)
else:
print(x)
``` | -1 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,695,918,542 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n = int(input())
m = int(input())
a = int(input())
x = (m // a) + 1
y = (n // a) + 1
z = x * y
print (z) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n = int(input())
m = int(input())
a = int(input())
x = (m // a) + 1
y = (n // a) + 1
z = x * y
print (z)
``` | -1 |
276 | B | Little Girl and Game | PROGRAMMING | 1,300 | [
"games",
"greedy"
] | null | null | The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second. | The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | [
"aba\n",
"abca\n"
] | [
"First\n",
"Second\n"
] | none | 1,000 | [
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"input": "xvhtcbtouuddhylxhplgjxwlo",
"output": "First"
},
{
"input": "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbomlpghjrxcgxvktgeyuhrcwgvdmppqnkdmjtxukzlzqhfbgrishuhkyggkpstvqabpxoqjuovwjwcmazmvpfpnljdgpokpatjnvwacotkvxheorzbsrazldsquijzkmtmqahakjrjvzkquvayxpqrmqqcknilpqpjapagezonfpz",
"output": "Second"
},
{
"input": "desktciwoidfuswycratvovutcgjrcyzmilsmadzaegseetexygedzxdmorxzxgiqhcuppshcsjcozkopebegfmxzxxagzwoymlghgjexcgfojychyt",
"output": "First"
},
{
"input": "gfhuidxgxpxduqrfnqrnefgtyxgmrtehmddjkddwdiayyilaknxhlxszeslnsjpcrwnoqubmbpcehiftteirkfvbtfyibiikdaxmondnawtvqccctdxrjcfxqwqhvvrqmhqflbzskrayvruqvqijrmikucwzodxvufwxpxxjxlifdjzxrttjzatafkbzsjupsiefmipdufqltedjlytphzppoevxawjdhbxgennevbvdgpoeihasycctyddenzypoprchkoioouhcexjqwjflxvkgpgjatstlmledxasecfhwvabzwviywsiaryqrxyeceefblherqjevdzkfxslqiytwzz",
"output": "First"
},
{
"input": "fezzkpyctjvvqtncmmjsitrxaliyhirspnjjngvzdoudrkkvvdiwcwtcxobpobzukegtcrwsgxxzlcphdxkbxdximqbycaicfdeqlvzboptfimkzvjzdsvahorqqhcirpkhtwjkplitpacpkpbhnxtoxuoqsxcxnhtrmzvexmpvlethbkvmlzftimjnidrzvcunbpysvukzgwghjmwrvstsunaocnoqohcsggtrwxiworkliqejajewbrtdwgnyynpupbrrvtfqtlaaq",
"output": "Second"
},
{
"input": "tsvxmeixijyavdalmrvscwohzubhhgsocdvnjmjtctojbxxpezzbgfltixwgzmkfwdnlhidhrdgyajggmrvmwaoydodjmzqvgabyszfqcuhwdncyfqvmackvijgpjyiauxljvvwgiofdxccwmybdfcfcrqppbvbagmnvvvhngxauwbpourviyfokwjweypzzrrzjcmddnpoaqgqfgglssjnlshrerfffmrwhapzknxveiqixflykjbnpivogtdpyjakwrdoklsbvbkjhdojfnuwbpcfdycwxecysbyjfvoykxsxgg",
"output": "First"
},
{
"input": "upgqmhfmfnodsyosgqswugfvpdxhtkxvhlsxrjiqlojchoddxkpsamwmuvopdbncymcgrkurwlxerexgswricuqxhvqvgekeofkgqabypamozmyjyfvpifsaotnyzqydcenphcsmplekinwkmwzpjnlapfdbhxjdcnarlgkfgxzfbpgsuxqfyhnxjhtojrlnprnxprfbkkcyriqztjeeepkzgzcaiutvbqqofyhddfebozhvtvrigtidxqmydjxegxipakzjcnenjkdroyjmxugj",
"output": "Second"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddeeeeeeeeeeffffgggghhhhiiiijjjjqqqqwwwweeeerrrrttttyyyyuuuuiiiiooooppppaaaassssddddffffgggghhhhjjjjkkkkllllzzzzxxxxccccvvvvbbbbnnnnmmmm",
"output": "First"
},
{
"input": "vnvtvnxjrtffdhrfvczzoyeokjabxcilmmsrhwuakghvuabcmfpmblyroodmhfivmhqoiqhapoglwaluewhqkunzitmvijaictjdncivccedfpaezcnpwemlohbhjjlqsonuclaumgbzjamsrhuzqdqtitygggsnruuccdtxkgbdd",
"output": "First"
},
{
"input": "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh",
"output": "First"
},
{
"input": "hxueikegwnrctlciwguepdsgupguykrntbszeqzzbpdlouwnmqgzcxejidstxyxhdlnttnibxstduwiflouzfswfikdudkazoefawm",
"output": "Second"
},
{
"input": "ershkhsywqftixappwqzoojtnamvqjbyfauvuubwpctspioqusnnivwsiyszfhlrskbswaiaczurygcioonjcndntwvrlaejyrghfnecltqytfmkvjxuujifgtujrqsisdawpwgttxynewiqhdhronamabysvpxankxeybcjqttbqnciwuqiehzyfjoedaradqnfthuuwrezwrkjiytpgwfwbslawbiezdbdltenjlaygwaxddplgseiaojndqjcopvolqbvnacuvfvirzbrnlnyjixngeevcggmirzatenjihpgnyfjhgsjgzepohbyhmzbatfwuorwutavlqsogrvcjpqziuifrhurq",
"output": "First"
},
{
"input": "qilwpsuxogazrfgfznngwklnioueuccyjfatjoizcctgsweitzofwkyjustizbopzwtaqxbtovkdrxeplukrcuozhpymldstbbfynkgsmafigetvzkxloxqtphvtwkgfjkiczttcsxkjpsoutdpzxytrsqgjtbdljjrbmkudrkodfvcwkcuggbsthxdyogeeyfuyhmnwgyuatfkvchavpzadfacckdurlbqjkthqbnirzzbpusxcenkpgtizayjmsahvobobudfeaewcqmrlxxnocqzmkessnguxkiccrxyvnxxlqnqfwuzmupk",
"output": "First"
},
{
"input": "opfokvwzpllctflkphutcrkferbjyyrasqqkrcvoymyrxwaudgsugcqveccymdplxmtlzfoptmrapfeizpnnhbzlkuyznwacnswibxhqunazbhdvrlidghisuqunstbuevjzimvlfvopgqxrvahhngnaumgywscfrfwfpnfxwhfrelbunmedvkssykwjyartxjiplerntzkpiiaalijiwhyuhxlvhxpkgfypvrpqqsacuwocdampnnhvibsbolyduvscsjfayxpldyvqzjbqojjxdvxtctwtifcdfcaoonzbgegyllngwvjivtxeezoabhsihcuvgvdsgjtzbzwovjshvwrljkxavowovzrfpdufpogdtujkerdorpboufrxhyswirjehgsxthlvjufvahdpeajidqipwaxokbeycrievgcfkyuyavaq",
"output": "Second"
},
{
"input": "a",
"output": "First"
},
{
"input": "ab",
"output": "Second"
},
{
"input": "abacaba",
"output": "First"
},
{
"input": "abazaba",
"output": "First"
},
{
"input": "zz",
"output": "First"
},
{
"input": "aassddxyz",
"output": "First"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "Second"
},
{
"input": "aabc",
"output": "Second"
},
{
"input": "abcabc",
"output": "First"
},
{
"input": "aaabbbccdd",
"output": "Second"
},
{
"input": "aabbcccc",
"output": "First"
}
] | 1,636,119,726 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 17,715,200 | n=input()
data=0
for i in n:
data+=n.count(i)%2
if data&1:
print("First")
else:
print("Second")
| Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
Input Specification:
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
Output Specification:
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
Demo Input:
['aba\n', 'abca\n']
Demo Output:
['First\n', 'Second\n']
Note:
none | ```python
n=input()
data=0
for i in n:
data+=n.count(i)%2
if data&1:
print("First")
else:
print("Second")
``` | 0 |
|
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded.
Determine the number of ways to choose a subset of participants that will receive the diplomas. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero scores cannot get anything. | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
"input": "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600",
"output": "94"
},
{
"input": "100\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600",
"output": "1"
},
{
"input": "78\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12",
"output": "13"
},
{
"input": "34\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391",
"output": "33"
},
{
"input": "100\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3",
"output": "3"
},
{
"input": "100\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55",
"output": "93"
},
{
"input": "99\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13",
"output": "13"
},
{
"input": "99\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1",
"output": "1"
},
{
"input": "99\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37",
"output": "61"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n0 600",
"output": "1"
},
{
"input": "4\n1 1 1 2",
"output": "2"
},
{
"input": "4\n0 0 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "2\n0 5",
"output": "1"
},
{
"input": "5\n1 0 0 1 2",
"output": "2"
}
] | 1,637,753,599 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 307,200 | a=int(input())
n=[]
count=0
n=input().split(" ")
b=[0]*100000
n=[int(i) for i in n]
for i in range(a):
if n[i]>0:
p=n[i]
b[p]=b[p]+1
for i in range(100000):
if b[i]>0:
count=count+1
print(count)
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded.
Determine the number of ways to choose a subset of participants that will receive the diplomas.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score.
Output Specification:
Print a single integer — the desired number of ways.
Demo Input:
['4\n1 3 3 2\n', '3\n1 1 1\n', '4\n42 0 0 42\n']
Demo Output:
['3\n', '1\n', '1\n']
Note:
There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero scores cannot get anything. | ```python
a=int(input())
n=[]
count=0
n=input().split(" ")
b=[0]*100000
n=[int(i) for i in n]
for i in range(a):
if n[i]>0:
p=n[i]
b[p]=b[p]+1
for i in range(100000):
if b[i]>0:
count=count+1
print(count)
``` | 3 |
|
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition. | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": "1000000000 1",
"output": "499999999500000000 499999999500000000"
},
{
"input": "5000000 12",
"output": "1041664166668 12499942500066"
},
{
"input": "1833 195",
"output": "7722 1342341"
},
{
"input": "1000000000 1000000000",
"output": "0 0"
},
{
"input": "1000000000 1000000",
"output": "499500000000 499000500499500000"
},
{
"input": "1000000000 32170",
"output": "15541930838100 499967831017438365"
},
{
"input": "1000000 1000",
"output": "499500000 499000999500"
},
{
"input": "1234 1123",
"output": "111 6216"
},
{
"input": "599222887 298488",
"output": "601178656545 179355218158217800"
},
{
"input": "999999999 500000000",
"output": "499999999 124999999750000000"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 2",
"output": "249999999500000000 499999998500000001"
},
{
"input": "1000000000 999999999",
"output": "1 1"
},
{
"input": "38447 383",
"output": "1910550 724453080"
},
{
"input": "100000000 99999799",
"output": "201 20301"
},
{
"input": "1 1",
"output": "0 0"
},
{
"input": "2 1",
"output": "1 1"
},
{
"input": "2 2",
"output": "0 0"
},
{
"input": "10 10",
"output": "0 0"
}
] | 1,694,281,287 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 1,536,000 | def maximo (part,times):
x = part - (times-1)
ans = 0
for i in range(x-1,0,-1):
ans+=i
return ans
def minimo(part,times):
aux = {}
ans= 0
for i in range(times):
part-=1
aux[i] = 1
while part > 0:
for i in range(times):
if part > 0:
part-=1
aux[i] +=1
for i in aux.values():
res= 0
for i in range(i-1,0,-1):
res+=i
ans+=res
return ans
n,k = map(int, input().split())
print(minimo(n,k), maximo(n,k))
| Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.
Input Specification:
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
Output Specification:
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
Demo Input:
['5 1\n', '3 2\n', '6 3\n']
Demo Output:
['10 10\n', '1 1\n', '3 6\n']
Note:
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | ```python
def maximo (part,times):
x = part - (times-1)
ans = 0
for i in range(x-1,0,-1):
ans+=i
return ans
def minimo(part,times):
aux = {}
ans= 0
for i in range(times):
part-=1
aux[i] = 1
while part > 0:
for i in range(times):
if part > 0:
part-=1
aux[i] +=1
for i in aux.values():
res= 0
for i in range(i-1,0,-1):
res+=i
ans+=res
return ans
n,k = map(int, input().split())
print(minimo(n,k), maximo(n,k))
``` | 0 |
|
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him. | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt",
"output": "NO"
},
{
"input": "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososooooo\noooosooosoooo\nooosooooosooo\noosooooooosoo\nosoooooooooso\nsooooooooooos",
"output": "YES"
},
{
"input": "3\naaa\naaa\naaa",
"output": "NO"
},
{
"input": "3\naca\noec\nzba",
"output": "NO"
},
{
"input": "15\nrxeeeeeeeeeeeer\nereeeeeeeeeeere\needeeeeeeeeeoee\neeereeeeeeeewee\neeeereeeeebeeee\nqeeeereeejedyee\neeeeeerereeeeee\neeeeeeereeeeeee\neeeeeerereeeeze\neeeeereeereeeee\neeeereeeeegeeee\neeereeeeeeereee\neereeeeeeqeeved\ncreeeeeeceeeere\nreeerneeeeeeeer",
"output": "NO"
},
{
"input": "5\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx",
"output": "NO"
},
{
"input": "5\nxxxxx\nxxxxx\nxoxxx\nxxxxx\nxxxxx",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxxxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxoox\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxaxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\noxoxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "3\nxxx\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxx\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxxx",
"output": "NO"
},
{
"input": "3\nxax\nxxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naaa\nxax",
"output": "NO"
},
{
"input": "3\naax\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxaa\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\naax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxaa",
"output": "NO"
},
{
"input": "3\nxfx\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\nafa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxaf",
"output": "NO"
},
{
"input": "3\nxox\nxxx\nxxx",
"output": "NO"
},
{
"input": "3\naxa\naax\nxxa",
"output": "NO"
},
{
"input": "3\nxox\noxx\nxox",
"output": "NO"
},
{
"input": "3\nxox\nooo\nxox",
"output": "NO"
},
{
"input": "3\naaa\naab\nbbb",
"output": "NO"
},
{
"input": "3\nxxx\nsxs\nxsx",
"output": "NO"
},
{
"input": "5\nabbba\nbabab\nbbbbb\nbaaab\nabbba",
"output": "NO"
},
{
"input": "5\nabaaa\nbbbbb\nbbabb\nbabab\nabbba",
"output": "NO"
},
{
"input": "5\nxoxox\noxoxo\nooxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nxox\noxx\nxxx",
"output": "NO"
},
{
"input": "5\nxoooo\noxooo\nooxoo\noooxo\noooox",
"output": "NO"
},
{
"input": "5\nxoooo\noxoxx\nooxoo\noxoxo\noxoox",
"output": "NO"
},
{
"input": "3\naaa\nbab\naba",
"output": "NO"
}
] | 1,595,009,363 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 124 | 7,065,600 | import sys
from collections import Counter
n=int(input())
l=[]
for i in range(n):
s=input()
a=Counter(s)
if(s[i]!=s[n-1-i] or len(a)!=2 or a[s[i]]>2):
print("NO")
sys.exit()
print("YES") | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Output Specification:
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
Demo Input:
['5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n', '3\nwsw\nsws\nwsw\n', '3\nxpx\npxp\nxpe\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
none | ```python
import sys
from collections import Counter
n=int(input())
l=[]
for i in range(n):
s=input()
a=Counter(s)
if(s[i]!=s[n-1-i] or len(a)!=2 or a[s[i]]>2):
print("NO")
sys.exit()
print("YES")
``` | 0 |
|
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,698,343,025 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | r,b = list(map(int,input().split()))
d = min(r,b)
s = (max(r,b)-d)//2
print(d,s) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
r,b = list(map(int,input().split()))
d = min(r,b)
s = (max(r,b)-d)//2
print(d,s)
``` | 3 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,593,862,511 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | s1 = input()
s2 = input()
s3 = str(int(s1) + int(s2))
s3 = s3.replace('2', '0')
print(s3.zfill(len(s1))) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
s1 = input()
s2 = input()
s3 = str(int(s1) + int(s2))
s3 = s3.replace('2', '0')
print(s3.zfill(len(s1)))
``` | 3.969 |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 1,695,125,596 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 31 | 0 | levels = int(input())
X = input().split()
Y = input().split()
array =[]
seen=[]
arrayY=[]
for i in X :
if i in seen :
continue
else :
seen.append(i)
for i in Y :
if i in seen :
continue
else :
seen.append(i)
seen.sort()
if len(seen) == levels:
print("I become the guy.")
else :
print('Oh, my keyboard!') | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input Specification:
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
Output Specification:
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
Demo Input:
['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n']
Demo Output:
['I become the guy.\n', 'Oh, my keyboard!\n']
Note:
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | ```python
levels = int(input())
X = input().split()
Y = input().split()
array =[]
seen=[]
arrayY=[]
for i in X :
if i in seen :
continue
else :
seen.append(i)
for i in Y :
if i in seen :
continue
else :
seen.append(i)
seen.sort()
if len(seen) == levels:
print("I become the guy.")
else :
print('Oh, my keyboard!')
``` | 0 |
|
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
"input": "4744000695826",
"output": "YES"
},
{
"input": "10000000004744744",
"output": "YES"
},
{
"input": "446486416781684178",
"output": "YES"
},
{
"input": "999999999",
"output": "NO"
},
{
"input": "7777",
"output": "YES"
},
{
"input": "87414417444",
"output": "NO"
},
{
"input": "111222333444555667",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "4700",
"output": "NO"
},
{
"input": "3794555488744477",
"output": "NO"
},
{
"input": "444444444444444444",
"output": "NO"
},
{
"input": "474447447774444774",
"output": "NO"
},
{
"input": "777777777777777",
"output": "NO"
},
{
"input": "34777745021000000",
"output": "NO"
},
{
"input": "963",
"output": "NO"
},
{
"input": "855474448854788540",
"output": "NO"
},
{
"input": "999999999999994744",
"output": "YES"
},
{
"input": "400000000474",
"output": "YES"
},
{
"input": "123456789123456789",
"output": "YES"
},
{
"input": "740577777584945874",
"output": "NO"
},
{
"input": "7777777",
"output": "YES"
},
{
"input": "4444000111222333",
"output": "YES"
},
{
"input": "9847745885202111",
"output": "YES"
},
{
"input": "123456000000",
"output": "NO"
},
{
"input": "4744447444444",
"output": "NO"
},
{
"input": "7477",
"output": "YES"
},
{
"input": "4747477",
"output": "YES"
},
{
"input": "777777777444444444",
"output": "NO"
}
] | 1,699,042,036 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | M=input()
count=0
for X in M:
if X=="4" or X=="7":
count=count+1
if count==len(M):
print("YES")
else:
print("NO") | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
Input Specification:
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output Specification:
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
Demo Input:
['40047\n', '7747774\n', '1000000000000000000\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | ```python
M=input()
count=0
for X in M:
if X=="4" or X=="7":
count=count+1
if count==len(M):
print("YES")
else:
print("NO")
``` | 0 |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8",
"output": "1 2 3 4 5 6 7 8 9 0"
},
{
"input": "1 1\n4\n4",
"output": "4"
},
{
"input": "3 7\n6 3 4\n4 9 0 1 7 8 6",
"output": "6 4"
},
{
"input": "10 1\n9 0 8 1 7 4 6 5 2 3\n0",
"output": "0"
},
{
"input": "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6",
"output": "6 0 3 8 1"
},
{
"input": "8 2\n7 2 9 6 1 0 3 4\n6 3",
"output": "6 3"
},
{
"input": "5 4\n7 0 1 4 9\n0 9 5 3",
"output": "0 9"
},
{
"input": "10 1\n9 6 2 0 1 8 3 4 7 5\n6",
"output": "6"
},
{
"input": "10 2\n7 1 0 2 4 6 5 9 3 8\n3 2",
"output": "2 3"
},
{
"input": "5 9\n3 7 9 2 4\n3 8 4 5 9 6 1 0 2",
"output": "3 9 2 4"
},
{
"input": "10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6",
"output": "1 2 3 8 6 5"
},
{
"input": "8 2\n7 4 8 9 2 5 6 1\n6 4",
"output": "4 6"
},
{
"input": "10 2\n1 0 3 5 8 9 4 7 6 2\n0 3",
"output": "0 3"
},
{
"input": "7 6\n9 2 8 6 1 3 7\n4 2 0 3 1 8",
"output": "2 8 1 3"
},
{
"input": "1 6\n3\n6 8 2 4 5 3",
"output": "3"
},
{
"input": "1 8\n0\n9 2 4 8 1 5 0 7",
"output": "0"
},
{
"input": "6 9\n7 3 9 4 1 0\n9 1 5 8 0 6 2 7 4",
"output": "7 9 4 1 0"
},
{
"input": "10 2\n4 9 6 8 3 0 1 5 7 2\n0 1",
"output": "0 1"
},
{
"input": "10 5\n5 2 8 0 9 7 6 1 4 3\n9 6 4 1 2",
"output": "2 9 6 1 4"
},
{
"input": "6 3\n8 3 9 2 7 6\n5 4 3",
"output": "3"
},
{
"input": "4 10\n8 3 9 6\n4 9 6 2 7 0 8 1 3 5",
"output": "8 3 9 6"
},
{
"input": "1 2\n1\n1 0",
"output": "1"
},
{
"input": "3 6\n1 2 3\n4 5 6 1 2 3",
"output": "1 2 3"
},
{
"input": "1 2\n2\n1 2",
"output": "2"
},
{
"input": "1 10\n9\n0 1 2 3 4 5 6 7 8 9",
"output": "9"
}
] | 1,642,761,874 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 93 | 0 | #!/usr/bin/env python
# coding: utf-8
# In[18]:
n, m = map(int,input().split())
x = list(map(int,input().strip().split()))[:n]
y = list(map(int,input().strip().split()))[:m]
a = []
for i in x:
for j in y:
if i == j:
a.append(j)
print(*a)
# In[ ]:
| Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
Output Specification:
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
Demo Input:
['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n']
Demo Output:
['7 1 2\n', '1 0\n']
Note:
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | ```python
#!/usr/bin/env python
# coding: utf-8
# In[18]:
n, m = map(int,input().split())
x = list(map(int,input().strip().split()))[:n]
y = list(map(int,input().strip().split()))[:m]
a = []
for i in x:
for j in y:
if i == j:
a.append(j)
print(*a)
# In[ ]:
``` | 3 |
|
735 | C | Tennis Championship | PROGRAMMING | 1,600 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help. | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament. | Print the maximum number of games in which the winner of the tournament can take part. | [
"2\n",
"3\n",
"4\n",
"10\n"
] | [
"1\n",
"2\n",
"2\n",
"4\n"
] | In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners. | 1,750 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "1000",
"output": "14"
},
{
"input": "2500",
"output": "15"
},
{
"input": "690000",
"output": "27"
},
{
"input": "3000000000",
"output": "45"
},
{
"input": "123456789123456789",
"output": "81"
},
{
"input": "5",
"output": "3"
},
{
"input": "143",
"output": "9"
},
{
"input": "144",
"output": "10"
},
{
"input": "145",
"output": "10"
},
{
"input": "232",
"output": "10"
},
{
"input": "233",
"output": "11"
},
{
"input": "234",
"output": "11"
},
{
"input": "679891637638612257",
"output": "84"
},
{
"input": "679891637638612258",
"output": "85"
},
{
"input": "679891637638612259",
"output": "85"
},
{
"input": "1000000000000000000",
"output": "85"
},
{
"input": "10235439547",
"output": "47"
},
{
"input": "1240723548",
"output": "43"
},
{
"input": "92353046212453",
"output": "66"
},
{
"input": "192403205846532",
"output": "68"
},
{
"input": "13925230525389",
"output": "62"
},
{
"input": "12048230592523",
"output": "62"
},
{
"input": "19204385325853",
"output": "63"
},
{
"input": "902353283921",
"output": "56"
},
{
"input": "793056859214355",
"output": "70"
},
{
"input": "982045466234565",
"output": "71"
},
{
"input": "126743950353465",
"output": "67"
},
{
"input": "12405430465",
"output": "47"
},
{
"input": "10238439257768",
"output": "61"
},
{
"input": "1728493055346",
"output": "58"
},
{
"input": "927553829046",
"output": "56"
},
{
"input": "62735129403",
"output": "51"
},
{
"input": "71624823950223",
"output": "65"
},
{
"input": "8902353464851212",
"output": "75"
},
{
"input": "61824012598535",
"output": "65"
},
{
"input": "1294902504603347",
"output": "71"
},
{
"input": "6",
"output": "3"
},
{
"input": "7",
"output": "3"
},
{
"input": "8",
"output": "4"
},
{
"input": "9",
"output": "4"
},
{
"input": "11",
"output": "4"
},
{
"input": "12",
"output": "4"
},
{
"input": "13",
"output": "5"
},
{
"input": "14",
"output": "5"
},
{
"input": "15",
"output": "5"
},
{
"input": "16",
"output": "5"
},
{
"input": "17",
"output": "5"
},
{
"input": "18",
"output": "5"
},
{
"input": "19",
"output": "5"
},
{
"input": "20",
"output": "5"
},
{
"input": "21",
"output": "6"
},
{
"input": "22",
"output": "6"
},
{
"input": "23",
"output": "6"
},
{
"input": "355687428096000",
"output": "69"
},
{
"input": "576460752303423488",
"output": "84"
},
{
"input": "32212254719",
"output": "49"
},
{
"input": "26388279066623",
"output": "63"
},
{
"input": "618473717761",
"output": "56"
},
{
"input": "262406072477",
"output": "54"
}
] | 1,584,946,744 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | n=int(input())
t=0
def maxmatch(x):
if x==0:
return 0
elif x==1:
return 1
elif x==2:
return 2
elif x==3:
return 4
else:
return maxmatch(x-1)+maxmatch(x-2)
while 1:
if maxmatch(t)>=n:
break
t+=1
print(t-1) | Title: Tennis Championship
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament.
Output Specification:
Print the maximum number of games in which the winner of the tournament can take part.
Demo Input:
['2\n', '3\n', '4\n', '10\n']
Demo Output:
['1\n', '2\n', '2\n', '4\n']
Note:
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners. | ```python
n=int(input())
t=0
def maxmatch(x):
if x==0:
return 0
elif x==1:
return 1
elif x==2:
return 2
elif x==3:
return 4
else:
return maxmatch(x-1)+maxmatch(x-2)
while 1:
if maxmatch(t)>=n:
break
t+=1
print(t-1)
``` | 0 |
|
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"output": "YES"
},
{
"input": "4\n1 2 3 4",
"output": "NO"
},
{
"input": "10\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "2\n4 2",
"output": "YES"
},
{
"input": "4\n1 1 4 7",
"output": "YES"
},
{
"input": "3\n99999999 1 50000000",
"output": "YES"
},
{
"input": "1\n0",
"output": "YES"
},
{
"input": "5\n0 0 0 0 0",
"output": "YES"
},
{
"input": "4\n4 2 2 1",
"output": "NO"
},
{
"input": "3\n1 4 2",
"output": "NO"
},
{
"input": "3\n1 4 100",
"output": "NO"
},
{
"input": "3\n2 5 11",
"output": "NO"
},
{
"input": "3\n1 4 6",
"output": "NO"
},
{
"input": "3\n1 2 4",
"output": "NO"
},
{
"input": "3\n1 2 7",
"output": "NO"
},
{
"input": "5\n1 1 1 4 5",
"output": "NO"
},
{
"input": "2\n100000001 100000003",
"output": "YES"
},
{
"input": "3\n7 4 5",
"output": "NO"
},
{
"input": "3\n2 3 5",
"output": "NO"
},
{
"input": "3\n1 2 5",
"output": "NO"
},
{
"input": "2\n2 3",
"output": "YES"
},
{
"input": "3\n2 100 29",
"output": "NO"
},
{
"input": "3\n0 1 5",
"output": "NO"
},
{
"input": "3\n1 3 6",
"output": "NO"
},
{
"input": "3\n2 1 3",
"output": "YES"
},
{
"input": "3\n1 5 100",
"output": "NO"
},
{
"input": "3\n1 4 8",
"output": "NO"
},
{
"input": "3\n1 7 10",
"output": "NO"
},
{
"input": "3\n5 4 1",
"output": "NO"
},
{
"input": "3\n1 6 10",
"output": "NO"
},
{
"input": "4\n1 3 4 5",
"output": "NO"
},
{
"input": "3\n1 5 4",
"output": "NO"
},
{
"input": "5\n1 2 3 3 5",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "3\n2 3 8",
"output": "NO"
},
{
"input": "3\n0 3 5",
"output": "NO"
},
{
"input": "3\n1 5 10",
"output": "NO"
},
{
"input": "3\n1 7 2",
"output": "NO"
},
{
"input": "3\n1 3 9",
"output": "NO"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "7\n1 1 1 1 1 2 4",
"output": "NO"
},
{
"input": "5\n1 4 4 4 6",
"output": "NO"
},
{
"input": "5\n1 2 2 4 4",
"output": "NO"
},
{
"input": "3\n1 9 10",
"output": "NO"
},
{
"input": "8\n1 1 1 1 1 1 2 3",
"output": "YES"
},
{
"input": "3\n1 2 100",
"output": "NO"
},
{
"input": "3\n1 3 4",
"output": "NO"
},
{
"input": "3\n1 15 14",
"output": "NO"
},
{
"input": "3\n1 3 8",
"output": "NO"
},
{
"input": "3\n1 2 10",
"output": "NO"
},
{
"input": "4\n2 2 4 5",
"output": "NO"
},
{
"input": "3\n1 3 5",
"output": "YES"
},
{
"input": "5\n3 6 7 8 9",
"output": "NO"
},
{
"input": "3\n7 6 8",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 2 2 3",
"output": "YES"
},
{
"input": "3\n4 6 7",
"output": "NO"
},
{
"input": "3\n2 0 4",
"output": "YES"
},
{
"input": "4\n10 20 21 30",
"output": "NO"
},
{
"input": "4\n0 2 3 4",
"output": "NO"
},
{
"input": "3\n3 6 12",
"output": "NO"
},
{
"input": "5\n0 0 1 3 5",
"output": "NO"
},
{
"input": "3\n3 5 8",
"output": "NO"
},
{
"input": "3\n1 4 4",
"output": "YES"
},
{
"input": "4\n2 4 5 6",
"output": "NO"
}
] | 1,657,886,466 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | from sys import stdin
def test(problem):
pass
def solve(n,l):
a=min(l);b=max(l)
tem=b-a
if tem%2==1:return "NO"
for i in range(n):
if l[i]==tem or l[i]-tem//2==tem or l[i]+tem//2==tem:
continue
else :return "NO"
return "YES"
n=int(input())
l=list(int(i) for i in stdin.readline().split())
print(solve(n,l))
| Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array.
Output Specification:
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
Demo Input:
['5\n1 3 3 2 1\n', '5\n1 2 3 4 5\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | ```python
from sys import stdin
def test(problem):
pass
def solve(n,l):
a=min(l);b=max(l)
tem=b-a
if tem%2==1:return "NO"
for i in range(n):
if l[i]==tem or l[i]-tem//2==tem or l[i]+tem//2==tem:
continue
else :return "NO"
return "YES"
n=int(input())
l=list(int(i) for i in stdin.readline().split())
print(solve(n,l))
``` | 0 |
|
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 91",
"output": "-48"
},
{
"input": "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49",
"output": "-86"
},
{
"input": "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94",
"output": "-98"
},
{
"input": "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46",
"output": "-91"
},
{
"input": "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89",
"output": "-98"
},
{
"input": "2\n-1 -1",
"output": "NO"
},
{
"input": "3\n-2 -2 -2",
"output": "NO"
},
{
"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": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "10\n40 71 -85 -85 40 -85 -85 64 -85 47",
"output": "40"
},
{
"input": "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90",
"output": "-64"
},
{
"input": "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93",
"output": "-93"
},
{
"input": "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83",
"output": "-86"
},
{
"input": "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43",
"output": "-95"
},
{
"input": "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92",
"output": "-92"
},
{
"input": "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12",
"output": "-98"
},
{
"input": "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100",
"output": "-98"
},
{
"input": "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92",
"output": "-98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "9\n99 99 99 99 100 100 100 100 100",
"output": "100"
},
{
"input": "5\n-100 -100 -100 -100 -100",
"output": "NO"
}
] | 1,662,221,615 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 184 | 5,734,400 | n = int(input())
a = input().split()
a = list(set(sorted([int(i) for i in a])))
print(a[1]) | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output Specification:
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Demo Input:
['4\n1 2 2 -4\n', '5\n1 2 3 1 1\n']
Demo Output:
['1\n', '2\n']
Note:
none | ```python
n = int(input())
a = input().split()
a = list(set(sorted([int(i) for i in a])))
print(a[1])
``` | -1 |
721 | B | Passwords | PROGRAMMING | 1,100 | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds). | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords. | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all. | 1,000 | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": "1 7"
},
{
"input": "2 2\nabc\nAbc\nabc",
"output": "1 2"
},
{
"input": "2 1\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 2\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 1\nab\nabc\nabc",
"output": "7 7"
},
{
"input": "2 2\nab\nabc\nabc",
"output": "2 2"
},
{
"input": "10 3\nOIbV1igi\no\nZS\nQM\n9woLzI\nWreboD\nQ7yl\nA5Rb\nS9Lno72TkP\nfT97o\no",
"output": "1 1"
},
{
"input": "10 3\nHJZNMsT\nLaPcH2C\nlrhqIO\n9cxw\noTC1XwjW\nGHL9Ul6\nUyIs\nPuzwgR4ZKa\nyIByoKR5\nd3QA\nPuzwgR4ZKa",
"output": "25 25"
},
{
"input": "20 5\nvSyC787KlIL8kZ2Uv5sw\nWKWOP\n7i8J3E8EByIq\nNW2VyGweL\nmyR2sRNu\nmXusPP0\nf4jgGxra\n4wHRzRhOCpEt\npPz9kybGb\nOtSpePCRoG5nkjZ2VxRy\nwHYsSttWbJkg\nKBOP9\nQfiOiFyHPPsw3GHo8J8\nxB8\nqCpehZEeEhdq\niOLjICK6\nQ91\nHmCsfMGTFKoFFnv238c\nJKjhg\ngkEUh\nKBOP9",
"output": "3 11"
},
{
"input": "15 2\nw6S9WyU\nMVh\nkgUhQHW\nhGQNOF\nUuym\n7rGQA\nBM8vLPRB\n9E\nDs32U\no\nz1aV2C5T\n8\nzSXjrqQ\n1FO\n3kIt\nBM8vLPRB",
"output": "44 50"
},
{
"input": "20 2\ni\n5Rp6\nE4vsr\nSY\nORXx\nh13C\nk6tzC\ne\nN\nKQf4C\nWZcdL\ndiA3v\n0InQT\nuJkAr\nGCamp\nBuIRd\nY\nM\nxZYx7\n0a5A\nWZcdL",
"output": "36 65"
},
{
"input": "20 2\naWLQ6\nSgQ9r\nHcPdj\n2BNaO\n3TjNb\nnvwFM\nqsKt7\nFnb6N\nLoc0p\njxuLq\nBKAjf\nEKgZB\nBfOSa\nsMIvr\nuIWcR\nIura3\nLAqSf\ntXq3G\n8rQ8I\n8otAO\nsMIvr",
"output": "1 65"
},
{
"input": "20 15\n0ZpQugVlN7\nm0SlKGnohN\nRFXTqhNGcn\n1qm2ZbB\nQXtJWdf78P\nbc2vH\nP21dty2Z1P\nm2c71LFhCk\n23EuP1Dvh3\nanwri5RhQN\n55v6HYv288\n1u5uKOjM5r\n6vg0GC1\nDAPYiA3ns1\nUZaaJ3Gmnk\nwB44x7V4Zi\n4hgB2oyU8P\npYFQpy8gGK\ndbz\nBv\n55v6HYv288",
"output": "6 25"
},
{
"input": "3 1\na\nb\naa\naa",
"output": "13 13"
},
{
"input": "6 3\nab\nac\nad\nabc\nabd\nabe\nabc",
"output": "9 11"
},
{
"input": "4 2\n1\n2\n11\n22\n22",
"output": "8 9"
},
{
"input": "2 1\n1\n12\n12",
"output": "7 7"
},
{
"input": "3 1\nab\nabc\nabd\nabc",
"output": "7 13"
},
{
"input": "2 1\na\nab\nab",
"output": "7 7"
},
{
"input": "5 2\na\nb\nc\nab\naa\naa",
"output": "9 15"
},
{
"input": "6 1\n1\n2\n11\n22\n111\n2222\n22",
"output": "13 19"
},
{
"input": "3 1\n1\n2\n11\n11",
"output": "13 13"
},
{
"input": "10 4\na\nb\nc\nd\ne\nf\nab\ncd\nac\nad\nac",
"output": "12 20"
},
{
"input": "4 2\na\nb\nc\nd\na",
"output": "1 9"
},
{
"input": "4 1\n1\n2\n3\n4\n4",
"output": "1 19"
},
{
"input": "5 1\na\nb\nc\nd\nef\nef",
"output": "25 25"
},
{
"input": "6 4\n1\n2\n22\n33\n44\n555\n555",
"output": "11 11"
},
{
"input": "5 2\na\nb\nc\nd\nab\nab",
"output": "15 15"
},
{
"input": "6 2\n1\n2\n3\n4\n5\n23\n23",
"output": "16 16"
},
{
"input": "4 2\na\nb\naa\nbb\naa",
"output": "8 9"
},
{
"input": "5 4\na\nbb\ncc\ndd\nee\nbb",
"output": "2 10"
},
{
"input": "4 1\na\nb\nc\nab\nab",
"output": "19 19"
},
{
"input": "7 100\na\nb\nc\nd\ne\ng\nab\nab",
"output": "7 7"
},
{
"input": "6 1\na\nb\nc\nd\ne\naa\naa",
"output": "31 31"
},
{
"input": "4 1\na\nas\nasd\nasde\nasde",
"output": "19 19"
},
{
"input": "5 2\n1\n2\n3\n11\n22\n22",
"output": "9 15"
},
{
"input": "10 2\na\nb\nc\nd\nee\nff\ngg\nhh\nii\njj\nii",
"output": "15 30"
},
{
"input": "3 1\na\nab\nbc\nab",
"output": "7 13"
},
{
"input": "6 4\na\nb\nc\nbb\nbc\ncc\ncc",
"output": "4 11"
}
] | 1,662,829,885 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n, k = map(int, input().split())
# if n == k:
# ans2 = k
# elif n // k == 0:
# ans2 = n
# else:
# fator = (n // k) if k != 1 else n - 1
# ans2 = (fator * 5) + n
# print(ans2)
array = []
for i in range(n):
array.append(input())
cont1, cont2 = [0,0]
# i = 0
password = input()
# print(array)
for item in array:
if (len(item) < len(password)):
cont1+=1
if (len(item) <= len(password)):
cont2+=1
print(cont1 + (cont1//k)*5 + 1, cont2 + ((cont2)//k)*5)
| Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords.
Output Specification:
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
Demo Input:
['5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n', '4 100\n11\n22\n1\n2\n22\n']
Demo Output:
['1 15\n', '3 4\n']
Note:
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all. | ```python
n, k = map(int, input().split())
# if n == k:
# ans2 = k
# elif n // k == 0:
# ans2 = n
# else:
# fator = (n // k) if k != 1 else n - 1
# ans2 = (fator * 5) + n
# print(ans2)
array = []
for i in range(n):
array.append(input())
cont1, cont2 = [0,0]
# i = 0
password = input()
# print(array)
for item in array:
if (len(item) < len(password)):
cont1+=1
if (len(item) <= len(password)):
cont2+=1
print(cont1 + (cont1//k)*5 + 1, cont2 + ((cont2)//k)*5)
``` | 0 |
|
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 1,691,935,300 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 62 | 0 | ct =0
n = int(input())
for i in range(n):
p,q = map(int,input().split())
if(p+2 <=q):
ct = ct +1
print(ct) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Output Specification:
Print a single integer — the number of rooms where George and Alex can move in.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n']
Demo Output:
['0\n', '2\n']
Note:
none | ```python
ct =0
n = int(input())
for i in range(n):
p,q = map(int,input().split())
if(p+2 <=q):
ct = ct +1
print(ct)
``` | 3 |
|
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"output": "-1"
},
{
"input": "1000000000000000 1000000000",
"output": "-1"
},
{
"input": "1000000000000000 100",
"output": "1953125"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "4 3",
"output": "4"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "9 3",
"output": "9"
},
{
"input": "21 3",
"output": "7"
},
{
"input": "67280421310721 1",
"output": "1"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "16 3",
"output": "4"
},
{
"input": "1 1000",
"output": "-1"
},
{
"input": "16 4",
"output": "8"
},
{
"input": "36 8",
"output": "18"
},
{
"input": "49 4",
"output": "-1"
},
{
"input": "9 4",
"output": "-1"
},
{
"input": "16 1",
"output": "1"
},
{
"input": "16 6",
"output": "-1"
},
{
"input": "16 5",
"output": "16"
},
{
"input": "25 4",
"output": "-1"
},
{
"input": "4010815561 2",
"output": "63331"
},
{
"input": "49 3",
"output": "49"
},
{
"input": "36 6",
"output": "9"
},
{
"input": "36 10",
"output": "-1"
},
{
"input": "25 3",
"output": "25"
},
{
"input": "22876792454961 28",
"output": "7625597484987"
},
{
"input": "1234 2",
"output": "2"
},
{
"input": "179458711 2",
"output": "179458711"
},
{
"input": "900104343024121 100000",
"output": "-1"
},
{
"input": "8 3",
"output": "4"
},
{
"input": "100 6",
"output": "20"
},
{
"input": "15500 26",
"output": "-1"
},
{
"input": "111111 1",
"output": "1"
},
{
"input": "100000000000000 200",
"output": "160000000000"
},
{
"input": "1000000000000 100",
"output": "6400000"
},
{
"input": "100 10",
"output": "-1"
},
{
"input": "1000000000039 2",
"output": "1000000000039"
},
{
"input": "64 5",
"output": "16"
},
{
"input": "999999961946176 33",
"output": "63245552"
},
{
"input": "376219076689 3",
"output": "376219076689"
},
{
"input": "999999961946176 63",
"output": "999999961946176"
},
{
"input": "1048576 12",
"output": "2048"
},
{
"input": "745 21",
"output": "-1"
},
{
"input": "748 6",
"output": "22"
},
{
"input": "999999961946176 50",
"output": "161082468097"
},
{
"input": "10 3",
"output": "5"
},
{
"input": "1099511627776 22",
"output": "2097152"
},
{
"input": "1000000007 100010",
"output": "-1"
},
{
"input": "3 1",
"output": "1"
},
{
"input": "100 8",
"output": "50"
},
{
"input": "100 7",
"output": "25"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "999999961946176 64",
"output": "-1"
},
{
"input": "20 5",
"output": "10"
},
{
"input": "999999999999989 2",
"output": "999999999999989"
},
{
"input": "100000000000000 114",
"output": "10240000"
},
{
"input": "99999640000243 3",
"output": "9999991"
},
{
"input": "999998000001 566",
"output": "333332666667"
},
{
"input": "99999820000081 2",
"output": "9999991"
},
{
"input": "49000042000009 3",
"output": "49000042000009"
},
{
"input": "151491429961 4",
"output": "-1"
},
{
"input": "32416190071 2",
"output": "32416190071"
},
{
"input": "1000 8",
"output": "25"
},
{
"input": "1999967841 15",
"output": "1999967841"
},
{
"input": "26880 26880",
"output": "-1"
},
{
"input": "151491429961 3",
"output": "151491429961"
},
{
"input": "90000000000 300",
"output": "100000000"
},
{
"input": "98765004361 10",
"output": "-1"
},
{
"input": "15 2",
"output": "3"
},
{
"input": "16 2",
"output": "2"
},
{
"input": "1996 2",
"output": "2"
},
{
"input": "1997 2",
"output": "1997"
},
{
"input": "1999 2",
"output": "1999"
},
{
"input": "1998 2",
"output": "2"
},
{
"input": "1998 1",
"output": "1"
},
{
"input": "1998 7",
"output": "27"
},
{
"input": "1998 8",
"output": "37"
},
{
"input": "100000380000361 2",
"output": "10000019"
},
{
"input": "15 1",
"output": "1"
},
{
"input": "100000000000000 226",
"output": "-1"
},
{
"input": "844030857550613 517",
"output": "-1"
},
{
"input": "4567890 14",
"output": "430"
},
{
"input": "123123123 123123123",
"output": "-1"
},
{
"input": "24 4",
"output": "4"
},
{
"input": "999999993568952 17",
"output": "31622777"
},
{
"input": "99999999994190 9",
"output": "241656799"
},
{
"input": "999997874844049 4",
"output": "-1"
},
{
"input": "99999999999931 2",
"output": "99999999999931"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "67280421310721 2",
"output": "67280421310721"
}
] | 1,595,050,802 | 2,147,483,647 | PyPy 3 | OK | TESTS | 96 | 1,700 | 23,449,600 | import math as m
n,k = map(int,input().split())
f = []
s = []
for x in range(1,int(m.sqrt(n))+1):
if n%x == 0:
f.append(x)
if n//x not in f:
s.append(n//x)
c = f+s[::-1]
try:
print(c[k-1])
except:
print(-1) | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
Output Specification:
If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*.
Demo Input:
['4 2\n', '5 3\n', '12 5\n']
Demo Output:
['2\n', '-1\n', '6\n']
Note:
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | ```python
import math as m
n,k = map(int,input().split())
f = []
s = []
for x in range(1,int(m.sqrt(n))+1):
if n%x == 0:
f.append(x)
if n//x not in f:
s.append(n//x)
c = f+s[::-1]
try:
print(c[k-1])
except:
print(-1)
``` | 3 |
|
446 | A | DZY Loves Sequences | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | 500 | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371",
"output": "19"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "2"
},
{
"input": "5\n1 2 3 4 1",
"output": "5"
},
{
"input": "10\n1 2 3 4 5 5 6 7 8 9",
"output": "6"
},
{
"input": "5\n1 1 1 1 1",
"output": "2"
},
{
"input": "5\n1 1 2 3 4",
"output": "5"
},
{
"input": "5\n1 2 3 1 6",
"output": "5"
},
{
"input": "1\n42",
"output": "1"
},
{
"input": "5\n1 2 42 3 4",
"output": "4"
},
{
"input": "5\n1 5 9 6 10",
"output": "4"
},
{
"input": "5\n5 2 3 4 5",
"output": "5"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "5\n1 2 3 3 4",
"output": "4"
},
{
"input": "8\n1 2 3 4 1 5 6 7",
"output": "5"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "3\n5 1 2",
"output": "3"
},
{
"input": "4\n1 4 3 4",
"output": "4"
},
{
"input": "6\n7 2 12 4 5 6",
"output": "5"
},
{
"input": "6\n7 2 3 1 4 5",
"output": "4"
},
{
"input": "6\n2 3 5 5 6 7",
"output": "6"
},
{
"input": "5\n2 4 7 6 8",
"output": "5"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "5\n4 1 2 3 4",
"output": "5"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6",
"output": "7"
},
{
"input": "4\n1 2 1 3",
"output": "3"
},
{
"input": "4\n4 3 1 2",
"output": "3"
},
{
"input": "6\n1 2 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 1 1 2",
"output": "3"
},
{
"input": "4\n5 1 2 3",
"output": "4"
},
{
"input": "5\n9 1 2 3 4",
"output": "5"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "5\n1 3 2 4 5",
"output": "4"
},
{
"input": "6\n1 2 1 2 4 5",
"output": "5"
},
{
"input": "10\n1 1 5 3 2 9 9 7 7 6",
"output": "3"
},
{
"input": "6\n1 2 3 100000 100 101",
"output": "6"
},
{
"input": "4\n3 3 3 4",
"output": "3"
},
{
"input": "3\n4 3 5",
"output": "3"
},
{
"input": "5\n1 3 2 3 4",
"output": "4"
},
{
"input": "10\n1 2 3 4 5 10 10 11 12 13",
"output": "10"
},
{
"input": "7\n11 2 1 2 13 4 14",
"output": "5"
},
{
"input": "3\n5 1 3",
"output": "3"
},
{
"input": "4\n1 5 3 4",
"output": "4"
},
{
"input": "10\n1 2 3 4 100 6 7 8 9 10",
"output": "10"
},
{
"input": "3\n5 3 5",
"output": "3"
},
{
"input": "5\n100 100 7 8 9",
"output": "4"
},
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "5\n1 2 4 4 5",
"output": "5"
},
{
"input": "6\n7 4 5 6 7 8",
"output": "6"
},
{
"input": "9\n3 4 1 6 3 4 5 6 7",
"output": "7"
},
{
"input": "3\n1000 1 2",
"output": "3"
},
{
"input": "3\n20 1 9",
"output": "3"
},
{
"input": "6\n7 2 3 1 4 6",
"output": "4"
},
{
"input": "3\n100 5 10",
"output": "3"
},
{
"input": "4\n2 2 2 3",
"output": "3"
},
{
"input": "6\n4 2 8 1 2 5",
"output": "4"
},
{
"input": "3\n25 1 6",
"output": "3"
},
{
"input": "10\n17 99 23 72 78 36 5 43 95 9",
"output": "5"
},
{
"input": "7\n21 16 22 21 11 13 19",
"output": "4"
},
{
"input": "5\n1 2 5 3 4",
"output": "4"
},
{
"input": "6\n2 2 2 3 4 5",
"output": "5"
},
{
"input": "5\n1 3 1 2 3",
"output": "4"
},
{
"input": "3\n81 33 64",
"output": "3"
},
{
"input": "7\n14 3 3 19 13 19 15",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 42 7 8 9",
"output": "9"
},
{
"input": "5\n2 3 7 5 6",
"output": "5"
},
{
"input": "5\n1 3 3 4 5",
"output": "5"
},
{
"input": "6\n1 5 4 3 4 5",
"output": "4"
}
] | 1,630,364,921 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 20,172,800 | n=int(input())
w=[int(k) for k in input().split()]
c=[]
mx=1
mx1=1
res=1
for j in range(1, n):
if w[j]-w[j-1]>0:
mx+=1
mx1+=1
else:
if j==n-1 or w[j+1]-w[j-1]>=2:
mx1=mx+1
else:
mx1=1
mx=1
res=max(res, mx, mx1)
print(res) | Title: DZY Loves Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
In a single line print the answer to the problem — the maximum length of the required subsegment.
Demo Input:
['6\n7 2 3 1 5 6\n']
Demo Output:
['5\n']
Note:
You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | ```python
n=int(input())
w=[int(k) for k in input().split()]
c=[]
mx=1
mx1=1
res=1
for j in range(1, n):
if w[j]-w[j-1]>0:
mx+=1
mx1+=1
else:
if j==n-1 or w[j+1]-w[j-1]>=2:
mx1=mx+1
else:
mx1=1
mx=1
res=max(res, mx, mx1)
print(res)
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,601,618,035 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 155 | 0 | from collections import Counter
z=Counter("hello")
s=input()
flag=True
if s=="hello":
flag=True
elif len(s)>len("hello"):
for i in s:
if i in z and z[i]>0:
z[i]-=1
flag=all(x==0 for x in z.values())
else:
flag=False
if flag:
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
from collections import Counter
z=Counter("hello")
s=input()
flag=True
if s=="hello":
flag=True
elif len(s)>len("hello"):
for i in s:
if i in z and z[i]>0:
z[i]-=1
flag=all(x==0 for x in z.values())
else:
flag=False
if flag:
print("YES")
else:
print("NO")
``` | 0 |
190 | D | Non-Secret Cypher | PROGRAMMING | 1,900 | [
"two pointers"
] | null | null | Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number *m*, the enemies use an array of integers *a*. The number of its subarrays, in which there are at least *k* equal numbers, equals *m*. The number *k* has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers *a* and number *k*, find the number of subarrays of the array of numbers *a*, which has at least *k* equal numbers.
Subarray *a*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) of array *a*<==<=(*a*1,<=*a*2,<=...,<=*a**n*) is an array, made from its consecutive elements, starting from the *i*-th one and ending with the *j*-th one: *a*[*i*... *j*]<==<=(*a**i*,<=*a**i*<=+<=1,<=...,<=*a**j*). | The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array. | Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 2\n1 2 1 2\n",
"5 3\n1 2 1 1 3\n",
"3 1\n1 1 1\n"
] | [
"3",
"2",
"6"
] | In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1). | 2,000 | [
{
"input": "4 2\n1 2 1 2",
"output": "3"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2"
},
{
"input": "3 1\n1 1 1",
"output": "6"
},
{
"input": "20 2\n6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10",
"output": "131"
},
{
"input": "63 2\n1 2 1 2 4 5 1 1 1 1 1 2 3 1 2 3 3 1 1 3 1 1 1 1 2 1 1 6 3 2 1 1 1 1 2 2 3 2 1 1 1 2 1 4 2 1 2 3 2 1 1 1 1 2 4 3 4 2 5 1 1 2 1",
"output": "1882"
},
{
"input": "63 5\n76826 79919 83599 93821 79919 46132 46132 46132 79919 76826 79919 79919 76826 79919 79919 76826 76826 46132 76826 40347 79919 46132 76826 83599 79919 79919 46132 46132 46132 83599 83599 79919 46132 83599 93821 76826 81314 79919 79919 83599 76826 76826 76826 76826 46132 76826 46132 79919 76826 83599 79919 40347 76826 46132 46132 93821 76826 79919 46132 83599 93821 46132 46132",
"output": "1356"
},
{
"input": "6 3\n6 6 4 4 6 2",
"output": "2"
},
{
"input": "100 1\n5 2 5 1 1 4 1 5 4 5 5 5 4 4 1 3 2 3 1 5 1 4 2 4 5 5 5 2 1 3 2 5 5 4 2 1 3 2 2 2 4 4 4 2 1 1 5 4 2 5 3 4 5 5 5 3 1 3 5 4 1 4 5 2 3 2 5 3 5 1 4 2 2 3 2 4 4 3 2 3 5 3 1 3 4 1 5 4 2 5 4 3 1 4 3 2 1 5 2 5",
"output": "5050"
},
{
"input": "1 1\n5",
"output": "1"
},
{
"input": "2 1\n42 1000000000",
"output": "3"
},
{
"input": "2 2\n193 193",
"output": "1"
},
{
"input": "2 2\n97 197",
"output": "0"
}
] | 1,688,530,142 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 64 | 3,000 | 49,971,200 | def num_subarrays_with_at_least_k_equal_elements(arr, k):
l, r, count = 0, 0, 0
freq = {}
while r < len(arr):
freq[arr[r]] = freq.get(arr[r], 0) + 1
while l <= r and max(freq.values()) >= k:
freq[arr[l]] -= 1
if freq[arr[l]] == 0:
del freq[arr[l]]
l += 1
# Increment count by the number of valid subarrays ending at the current position
count += l
r += 1
return count
n, k = map(int, input().split())
array = list(map(int, input().strip().split()))[:n]
result = num_subarrays_with_at_least_k_equal_elements(array, k)
print (result) | Title: Non-Secret Cypher
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number *m*, the enemies use an array of integers *a*. The number of its subarrays, in which there are at least *k* equal numbers, equals *m*. The number *k* has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers *a* and number *k*, find the number of subarrays of the array of numbers *a*, which has at least *k* equal numbers.
Subarray *a*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) of array *a*<==<=(*a*1,<=*a*2,<=...,<=*a**n*) is an array, made from its consecutive elements, starting from the *i*-th one and ending with the *j*-th one: *a*[*i*... *j*]<==<=(*a**i*,<=*a**i*<=+<=1,<=...,<=*a**j*).
Input Specification:
The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array.
Output Specification:
Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['4 2\n1 2 1 2\n', '5 3\n1 2 1 1 3\n', '3 1\n1 1 1\n']
Demo Output:
['3', '2', '6']
Note:
In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1). | ```python
def num_subarrays_with_at_least_k_equal_elements(arr, k):
l, r, count = 0, 0, 0
freq = {}
while r < len(arr):
freq[arr[r]] = freq.get(arr[r], 0) + 1
while l <= r and max(freq.values()) >= k:
freq[arr[l]] -= 1
if freq[arr[l]] == 0:
del freq[arr[l]]
l += 1
# Increment count by the number of valid subarrays ending at the current position
count += l
r += 1
return count
n, k = map(int, input().split())
array = list(map(int, input().strip().split()))[:n]
result = num_subarrays_with_at_least_k_equal_elements(array, k)
print (result)
``` | 0 |
|
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314",
"output": "1762894"
},
{
"input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585",
"output": "2960349"
},
{
"input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933",
"output": "99140444"
},
{
"input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686",
"output": "301124161"
},
{
"input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495",
"output": "30125295"
},
{
"input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165",
"output": "136422"
},
{
"input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348",
"output": "2578628"
},
{
"input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338",
"output": "9168707"
},
{
"input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657",
"output": "144901921"
},
{
"input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860",
"output": "809931"
},
{
"input": "a\n0\n5 1 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": "5"
},
{
"input": "lol\n3\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",
"output": "21"
}
] | 1,621,027,115 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 93 | 1,331,200 | s=input()
k=int(input())
l=list(map(int,input().split()))
t=[chr(x) for x in range(ord('a'), ord('z') + 1)]
d={}
for i in range(26):
if t[i] not in d:
d[t[i]]=l[i]
m=max(l)
i=l.index(m)
s=s+t[i]*k
r=0
for i in range(len(s)):
r=r+((i+1)*d[s[i]])
print(r) | Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input Specification:
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Output Specification:
Print a single integer — the largest possible value of the resulting string DZY could get.
Demo Input:
['abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n']
Demo Output:
['41\n']
Note:
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | ```python
s=input()
k=int(input())
l=list(map(int,input().split()))
t=[chr(x) for x in range(ord('a'), ord('z') + 1)]
d={}
for i in range(26):
if t[i] not in d:
d[t[i]]=l[i]
m=max(l)
i=l.index(m)
s=s+t[i]*k
r=0
for i in range(len(s)):
r=r+((i+1)*d[s[i]])
print(r)
``` | 3 |
|
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string. | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
},
{
"input": "5\naaaaa",
"output": "aaaaa"
},
{
"input": "3\naabaaaaabb",
"output": "-1"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "2\nbabac",
"output": "-1"
},
{
"input": "3\nbbbccc",
"output": "bcbcbc"
},
{
"input": "2\naa",
"output": "aa"
},
{
"input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece",
"output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece"
},
{
"input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa",
"output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc"
},
{
"input": "1\naaa",
"output": "aaa"
},
{
"input": "1\naabaab",
"output": "aaaabb"
},
{
"input": "2\naabbbbccccccdddddddd",
"output": "abbcccddddabbcccdddd"
},
{
"input": "3\naaaaaaaaacccdddddd",
"output": "aaacddaaacddaaacdd"
},
{
"input": "3\naaaaaaaaacccbbbbbb",
"output": "aaabbcaaabbcaaabbc"
},
{
"input": "2\naazzzz",
"output": "azzazz"
},
{
"input": "2\naaaa",
"output": "aaaa"
},
{
"input": "2\naaaazz",
"output": "aazaaz"
},
{
"input": "2\naaaabb",
"output": "aabaab"
},
{
"input": "2\naabbbb",
"output": "abbabb"
},
{
"input": "2\naaaazzzz",
"output": "aazzaazz"
},
{
"input": "2\naaazz",
"output": "-1"
},
{
"input": "2\nbbbbaa",
"output": "abbabb"
},
{
"input": "2\naaaaaabbbb",
"output": "aaabbaaabb"
},
{
"input": "2\naaaaaazz",
"output": "aaazaaaz"
},
{
"input": "2\naaaabbbb",
"output": "aabbaabb"
},
{
"input": "2\naabaab",
"output": "aabaab"
},
{
"input": "1\naaaaa",
"output": "aaaaa"
},
{
"input": "2\nbbaaaa",
"output": "aabaab"
},
{
"input": "2\nacaccc",
"output": "accacc"
}
] | 1,689,674,794 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | k = int(input())
text = input()
textSet = set(text)
if len(textSet) == k :
for _ in range(k) :
print("".join(textSet),end="")
else : print(-1) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Output Specification:
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
Demo Input:
['2\naazz\n', '3\nabcabcabz\n']
Demo Output:
['azaz\n', '-1\n']
Note:
none | ```python
k = int(input())
text = input()
textSet = set(text)
if len(textSet) == k :
for _ in range(k) :
print("".join(textSet),end="")
else : print(-1)
``` | 0 |
|
712 | B | Memory and Trident | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move one unit down.
But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in *s* with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string. | The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given. | If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. | [
"RRU\n",
"UDUR\n",
"RUUR\n"
] | [
"-1\n",
"1\n",
"2\n"
] | In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin. | 1,000 | [
{
"input": "RRU",
"output": "-1"
},
{
"input": "UDUR",
"output": "1"
},
{
"input": "RUUR",
"output": "2"
},
{
"input": "DDDD",
"output": "2"
},
{
"input": "RRRR",
"output": "2"
},
{
"input": "RRRUUD",
"output": "2"
},
{
"input": "UDURLRDURLRD",
"output": "1"
},
{
"input": "RLRU",
"output": "1"
},
{
"input": "RDDLLDLUUUDDRDRURLUUURLLDDLRLUURRLLRRLDRLLUDRLRULLDLRRLRLRLRUDUUDLULURLLDUURULURLLRRRURRRDRUUDLDRLRDRLRRDDLDLDLLUDRUDRLLLLDRDUULRUURRDLULLULDUDULRURRDDDLLUDRLUDDLDDDRRDDDULLLLDLDRLRRLRRDDRLULURRUDRDUUUULDURUDRDLDDUDUDRRURDULRRUDRLRRDLUURURDLDRLRDUDDDLDDDURURLUULRDUUULRURUDUDRRUDULLLUUUDRLLDRRDDLRUDRDRDLLRURURRRULURURRRLUUULRRRUURUUDURUDDLLDLDRLRDLDRLLDLDRDRRLRRRURUUUDRDLRLRUDRLULUUULUDDLULDLRLLRDUULLRLRURLRURULLLUDUDDLRULRDUURURLDLUURRRDURRLLDRUUDRDLLDUUDLURUDDUUUULRLLURLUDDRLRRDRURLRUDRLDDRLLL",
"output": "-1"
},
{
"input": "LDLDLDLDLDRULD",
"output": "5"
},
{
"input": "LULULURULLLU",
"output": "5"
},
{
"input": "DRDRDDRR",
"output": "4"
},
{
"input": "LR",
"output": "0"
},
{
"input": "UL",
"output": "1"
},
{
"input": "UD",
"output": "0"
},
{
"input": "R",
"output": "-1"
},
{
"input": "LU",
"output": "1"
},
{
"input": "RR",
"output": "1"
},
{
"input": "UDLR",
"output": "0"
},
{
"input": "RRRRRLLUUUUDD",
"output": "-1"
},
{
"input": "UUUUDLLLLR",
"output": "3"
},
{
"input": "LLRUD",
"output": "-1"
},
{
"input": "LLRDDU",
"output": "1"
}
] | 1,473,528,542 | 2,642 | Python 3 | OK | TESTS | 75 | 77 | 307,200 | #!/usr/bin/python3
s = input()
if len(s) % 2 != 0:
print(-1)
else:
dy = s.count('U') - s.count('D')
dx = s.count('R') - s.count('L')
print((abs(dx) + abs(dy)) // 2)
| Title: Memory and Trident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move one unit down.
But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in *s* with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.
Input Specification:
The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given.
Output Specification:
If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.
Demo Input:
['RRU\n', 'UDUR\n', 'RUUR\n']
Demo Output:
['-1\n', '1\n', '2\n']
Note:
In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin. | ```python
#!/usr/bin/python3
s = input()
if len(s) % 2 != 0:
print(-1)
else:
dy = s.count('U') - s.count('D')
dx = s.count('R') - s.count('L')
print((abs(dx) + abs(dy)) // 2)
``` | 3 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,690,809,800 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | '''
t=int(input())
ans=[]
for _ in range(t):
a,b,c=map(int,input().split())
if c>b:
d=2*(c-b)+b-1
else:d=b-1
a-=1
if a>d:ans.append(2)
elif a==d:ans.append(3)
else:ans.append(1)
print(*ans,sep='\n')'''
import math
a=6-max(map(int,input().split()))+1
b=math.gcd(a,6)
print('{}/{}'.format(a//b,6//b))
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
'''
t=int(input())
ans=[]
for _ in range(t):
a,b,c=map(int,input().split())
if c>b:
d=2*(c-b)+b-1
else:d=b-1
a-=1
if a>d:ans.append(2)
elif a==d:ans.append(3)
else:ans.append(1)
print(*ans,sep='\n')'''
import math
a=6-max(map(int,input().split()))+1
b=math.gcd(a,6)
print('{}/{}'.format(a//b,6//b))
``` | 3.954 |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126",
"output": "12"
},
{
"input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850",
"output": "36"
},
{
"input": "2 6 8\n2 1",
"output": "0"
},
{
"input": "5 15 16\n7 11 5 12 8",
"output": "2"
},
{
"input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574",
"output": "4"
},
{
"input": "5 234613 716125\n642626 494941 234613 234613 234613",
"output": "0"
},
{
"input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547",
"output": "0"
},
{
"input": "5 10 20\n10 10 10 10 1",
"output": "1"
},
{
"input": "5 10 11\n10 10 10 10 1",
"output": "2"
},
{
"input": "3 10 10\n4 3 3",
"output": "0"
},
{
"input": "3 5 5\n5 5 5",
"output": "1"
},
{
"input": "3 4 14\n5 5 5",
"output": "0"
},
{
"input": "2 7 10\n1234 1234",
"output": "0"
},
{
"input": "1 5 6\n10",
"output": "0"
},
{
"input": "3 4 6\n1 2 3",
"output": "0"
},
{
"input": "5 10 12\n13 13 13 13 13",
"output": "0"
},
{
"input": "3 4 5\n5 7 9",
"output": "0"
},
{
"input": "3 10 100\n5 5 5",
"output": "0"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "5 5 5\n5 5 5 5 5",
"output": "2"
},
{
"input": "2 2 5\n5 5",
"output": "0"
},
{
"input": "3 1 4\n2 2 2",
"output": "0"
}
] | 1,687,494,331 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 171 | 13,619,200 | # -*- coding: utf-8 -*-
"""
Created on Fri Jun 23 06:20:28 2023
@author: RadmediX
"""
(n,b,d) = tuple(map(int, input().split()))
oranges = list(map(int, input().split()))
waste = 0
emptyNum = 0
for orange in oranges:
waste += orange if orange <= b else 0
if waste > d:
emptyNum+=1
waste=0
print(emptyNum)
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
Input Specification:
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output Specification:
Print one integer — the number of times Kolya will have to empty the waste section.
Demo Input:
['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n']
Demo Output:
['1\n', '0\n', '1\n', '0\n']
Note:
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 23 06:20:28 2023
@author: RadmediX
"""
(n,b,d) = tuple(map(int, input().split()))
oranges = list(map(int, input().split()))
waste = 0
emptyNum = 0
for orange in oranges:
waste += orange if orange <= b else 0
if waste > d:
emptyNum+=1
waste=0
print(emptyNum)
``` | 3 |
|
467 | B | Fedor and New Game | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"constructive algorithms",
"implementation"
] | null | null | After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (*m*<=+<=1) players and *n* types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (*m*<=+<=1). Types of soldiers are numbered from 0 to *n*<=-<=1. Each player has an army. Army of the *i*-th player can be described by non-negative integer *x**i*. Consider binary representation of *x**i*: if the *j*-th bit of number *x**i* equal to one, then the army of the *i*-th player has soldiers of the *j*-th type.
Fedor is the (*m*<=+<=1)-th player of the game. He assume that two players can become friends if their armies differ in at most *k* types of soldiers (in other words, binary representations of the corresponding numbers differ in at most *k* bits). Help Fedor and count how many players can become his friends. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=20; 1<=≤<=*m*<=≤<=1000).
The *i*-th of the next (*m*<=+<=1) lines contains a single integer *x**i* (1<=≤<=*x**i*<=≤<=2*n*<=-<=1), that describes the *i*-th player's army. We remind you that Fedor is the (*m*<=+<=1)-th player. | Print a single integer — the number of Fedor's potential friends. | [
"7 3 1\n8\n5\n111\n17\n",
"3 3 3\n1\n2\n3\n4\n"
] | [
"0\n",
"3\n"
] | none | 1,000 | [
{
"input": "7 3 1\n8\n5\n111\n17",
"output": "0"
},
{
"input": "3 3 3\n1\n2\n3\n4",
"output": "3"
},
{
"input": "4 2 2\n5\n6\n7",
"output": "2"
},
{
"input": "4 7 4\n9\n10\n5\n12\n4\n12\n7\n10",
"output": "7"
},
{
"input": "2 7 2\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "7"
},
{
"input": "6 8 2\n46\n59\n38\n5\n13\n54\n26\n62\n18",
"output": "2"
},
{
"input": "5 6 3\n16\n9\n24\n5\n17\n27\n20",
"output": "4"
},
{
"input": "7 9 1\n27\n7\n12\n29\n51\n67\n9\n112\n62\n68",
"output": "0"
},
{
"input": "9 20 2\n197\n45\n217\n9\n156\n335\n21\n90\n33\n292\n151\n153\n289\n483\n362\n509\n234\n115\n343\n341\n50",
"output": "1"
},
{
"input": "13 27 7\n1893\n370\n7320\n5753\n4418\n2146\n2702\n5013\n5959\n1929\n7611\n7013\n540\n3454\n4271\n2887\n4724\n3520\n2111\n5845\n1868\n7659\n3040\n3775\n6507\n4917\n7506\n2515",
"output": "20"
},
{
"input": "1 1 1\n1\n1",
"output": "1"
},
{
"input": "20 1 1\n1000\n2",
"output": "0"
},
{
"input": "3 3 3\n3\n3\n3\n7",
"output": "3"
},
{
"input": "2 2 1\n2\n1\n1",
"output": "1"
},
{
"input": "3 3 2\n7\n7\n6\n2",
"output": "3"
},
{
"input": "20 1 1\n9999\n9997",
"output": "1"
},
{
"input": "5 4 1\n1\n2\n4\n8\n16",
"output": "0"
},
{
"input": "5 2 2\n9\n7\n10",
"output": "1"
}
] | 1,687,167,007 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 109 | 1,433,600 | n, m, k = map(int,input().split())
x = [int(input()) for t in range (m + 1)]
print(sum(bin(x[m]^y).count('1') <= k for y in x)-1)
| Title: Fedor and New Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (*m*<=+<=1) players and *n* types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (*m*<=+<=1). Types of soldiers are numbered from 0 to *n*<=-<=1. Each player has an army. Army of the *i*-th player can be described by non-negative integer *x**i*. Consider binary representation of *x**i*: if the *j*-th bit of number *x**i* equal to one, then the army of the *i*-th player has soldiers of the *j*-th type.
Fedor is the (*m*<=+<=1)-th player of the game. He assume that two players can become friends if their armies differ in at most *k* types of soldiers (in other words, binary representations of the corresponding numbers differ in at most *k* bits). Help Fedor and count how many players can become his friends.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=20; 1<=≤<=*m*<=≤<=1000).
The *i*-th of the next (*m*<=+<=1) lines contains a single integer *x**i* (1<=≤<=*x**i*<=≤<=2*n*<=-<=1), that describes the *i*-th player's army. We remind you that Fedor is the (*m*<=+<=1)-th player.
Output Specification:
Print a single integer — the number of Fedor's potential friends.
Demo Input:
['7 3 1\n8\n5\n111\n17\n', '3 3 3\n1\n2\n3\n4\n']
Demo Output:
['0\n', '3\n']
Note:
none | ```python
n, m, k = map(int,input().split())
x = [int(input()) for t in range (m + 1)]
print(sum(bin(x[m]^y).count('1') <= k for y in x)-1)
``` | 3 |
|
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 1,697,978,513 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 46 | 0 | n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
m = dict()
r = x[1:] + y
r.sort()
c = 0
for i in range(len(r)-1):
if r[i] != r[i+1]:
c = c + 1
if(c != n-1):
print("Oh, my keyboard!")
else:
print("I become the guy.")
| Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input Specification:
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
Output Specification:
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
Demo Input:
['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n']
Demo Output:
['I become the guy.\n', 'Oh, my keyboard!\n']
Note:
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | ```python
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
m = dict()
r = x[1:] + y
r.sort()
c = 0
for i in range(len(r)-1):
if r[i] != r[i+1]:
c = c + 1
if(c != n-1):
print("Oh, my keyboard!")
else:
print("I become the guy.")
``` | 0 |
|
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will win the match. | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
},
{
"input": "4 5 4 5",
"output": "0.833333333333"
},
{
"input": "466 701 95 721",
"output": "0.937693791148"
},
{
"input": "268 470 444 885",
"output": "0.725614009325"
},
{
"input": "632 916 713 821",
"output": "0.719292895126"
},
{
"input": "269 656 918 992",
"output": "0.428937461623"
},
{
"input": "71 657 187 695",
"output": "0.310488463257"
},
{
"input": "435 852 973 978",
"output": "0.511844133157"
},
{
"input": "518 816 243 359",
"output": "0.719734031025"
},
{
"input": "882 962 311 811",
"output": "0.966386645447"
},
{
"input": "684 774 580 736",
"output": "0.906051574446"
},
{
"input": "486 868 929 999",
"output": "0.577723252958"
},
{
"input": "132 359 996 998",
"output": "0.368154532345"
},
{
"input": "933 977 266 450",
"output": "0.972879407907"
},
{
"input": "298 833 615 872",
"output": "0.441270817024"
},
{
"input": "34 554 14 958",
"output": "0.817324099167"
},
{
"input": "836 934 800 905",
"output": "0.906105535462"
},
{
"input": "482 815 69 509",
"output": "0.914365577772"
},
{
"input": "284 423 137 521",
"output": "0.885974839378"
},
{
"input": "648 881 486 703",
"output": "0.800911421248"
},
{
"input": "450 885 755 836",
"output": "0.533901011176"
},
{
"input": "533 773 823 998",
"output": "0.729222130525"
},
{
"input": "897 957 92 898",
"output": "0.993193806364"
},
{
"input": "699 925 441 928",
"output": "0.866816866175"
},
{
"input": "64 704 148 603",
"output": "0.289486317811"
},
{
"input": "719 735 626 990",
"output": "0.986124079764"
},
{
"input": "1 1000 1 1000",
"output": "0.500250125063"
}
] | 1,373,445,779 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 78 | 102,400 | a, b, c, d = map(int, input().split())
print("{0:.10f}".format(a / b / (1 - ((1 - a / b) * (1 - c / d)))))
| Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will win the match.
Input Specification:
A single line contains four integers .
Output Specification:
Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['1 2 1 2\n']
Demo Output:
['0.666666666667']
Note:
none | ```python
a, b, c, d = map(int, input().split())
print("{0:.10f}".format(a / b / (1 - ((1 - a / b) * (1 - c / d)))))
``` | 3 |
|
813 | C | The Tag Game | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs"
] | null | null | Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree.
Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=≠<=1). The moves are made in turns, Bob goes first. In one move one can either stay at the current vertex or travel to the neighbouring one.
The game ends when Alice goes to the same vertex where Bob is standing. Alice wants to minimize the total number of moves and Bob wants to maximize it.
You should write a program which will determine how many moves will the game last. | The first line contains two integer numbers *n* and *x* (2<=≤<=*n*<=≤<=2·105, 2<=≤<=*x*<=≤<=*n*).
Each of the next *n*<=-<=1 lines contains two integer numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*) — edges of the tree. It is guaranteed that the edges form a valid tree. | Print the total number of moves Alice and Bob will make. | [
"4 3\n1 2\n2 3\n2 4\n",
"5 2\n1 2\n2 3\n3 4\n2 5\n"
] | [
"4\n",
"6\n"
] | In the first example the tree looks like this:
The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves:
B: stay at vertex 3
A: go to vertex 2
B: stay at vertex 3
A: go to vertex 3
In the second example the tree looks like this:
The moves in the optimal strategy are:
B: go to vertex 3
A: go to vertex 2
B: go to vertex 4
A: go to vertex 3
B: stay at vertex 4
A: go to vertex 4 | 0 | [
{
"input": "4 3\n1 2\n2 3\n2 4",
"output": "4"
},
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "6"
},
{
"input": "2 2\n2 1",
"output": "2"
},
{
"input": "3 3\n2 1\n3 1",
"output": "2"
},
{
"input": "3 3\n1 2\n3 2",
"output": "4"
},
{
"input": "10 4\n5 4\n8 3\n4 6\n5 3\n7 9\n1 3\n5 10\n2 9\n9 8",
"output": "8"
},
{
"input": "10 7\n8 7\n2 8\n2 3\n10 6\n4 6\n4 1\n10 5\n7 5\n9 8",
"output": "16"
},
{
"input": "8 3\n2 1\n3 1\n4 3\n5 1\n6 1\n7 1\n8 6",
"output": "4"
},
{
"input": "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 5\n9 7\n10 8\n11 7\n12 7\n13 8\n14 2\n15 10\n16 1\n17 9\n18 14\n19 1\n20 2\n21 8\n22 21\n23 9\n24 6\n25 2\n26 20\n27 5\n28 20\n29 2\n30 10\n31 14\n32 12\n33 15\n34 8",
"output": "12"
}
] | 1,605,908,881 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 409,600 | from collections import defaultdict, deque
import sys
# sys.stdin
def getNodeDepth(edges, node_to_find):
queue = deque([(1,0)])
visited = set([1])
while queue:
node, distance = queue.popleft()
for child in edges[node]:
if child == node_to_find:
return distance+1
elif child in visited:
continue
queue.append((child, distance+1))
visited.add(child)
return -1
n, x = map(int, sys.stdin.readline().split())
edges = defaultdict(list)
for edge in range(n-1):
a, b = map(int, sys.stdin.readline().split())
edges[a].append(b)
edges[b].append(a)
a_queue = deque([(1, 0)])
a_visited = set([1])
b_queue = deque([(x, 0)])
b_visited = set([x])
furthest_b_distance = -1
furthest_b_node = -1
while b_queue:
if a_queue:
a_pos, a_distance = a_queue.popleft()
for a_move in edges[a_pos]:
if a_move in a_visited:
continue
a_queue.append((a_move, a_distance+1))
a_visited.add(a_move)
b_pos, b_distance = b_queue.popleft()
if b_distance > furthest_b_distance:
furthest_b_distance = b_distance
furthest_b_node = b_pos
for b_move in edges[b_pos]:
if b_move in a_visited or b_move in b_visited:
continue
b_queue.append((b_move, b_distance+1))
b_visited.add(b_move)
#print(furthest_b_distance, furthest_b_node)
print(getNodeDepth(edges, furthest_b_node)*2)
| Title: The Tag Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree.
Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=≠<=1). The moves are made in turns, Bob goes first. In one move one can either stay at the current vertex or travel to the neighbouring one.
The game ends when Alice goes to the same vertex where Bob is standing. Alice wants to minimize the total number of moves and Bob wants to maximize it.
You should write a program which will determine how many moves will the game last.
Input Specification:
The first line contains two integer numbers *n* and *x* (2<=≤<=*n*<=≤<=2·105, 2<=≤<=*x*<=≤<=*n*).
Each of the next *n*<=-<=1 lines contains two integer numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*) — edges of the tree. It is guaranteed that the edges form a valid tree.
Output Specification:
Print the total number of moves Alice and Bob will make.
Demo Input:
['4 3\n1 2\n2 3\n2 4\n', '5 2\n1 2\n2 3\n3 4\n2 5\n']
Demo Output:
['4\n', '6\n']
Note:
In the first example the tree looks like this:
The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves:
B: stay at vertex 3
A: go to vertex 2
B: stay at vertex 3
A: go to vertex 3
In the second example the tree looks like this:
The moves in the optimal strategy are:
B: go to vertex 3
A: go to vertex 2
B: go to vertex 4
A: go to vertex 3
B: stay at vertex 4
A: go to vertex 4 | ```python
from collections import defaultdict, deque
import sys
# sys.stdin
def getNodeDepth(edges, node_to_find):
queue = deque([(1,0)])
visited = set([1])
while queue:
node, distance = queue.popleft()
for child in edges[node]:
if child == node_to_find:
return distance+1
elif child in visited:
continue
queue.append((child, distance+1))
visited.add(child)
return -1
n, x = map(int, sys.stdin.readline().split())
edges = defaultdict(list)
for edge in range(n-1):
a, b = map(int, sys.stdin.readline().split())
edges[a].append(b)
edges[b].append(a)
a_queue = deque([(1, 0)])
a_visited = set([1])
b_queue = deque([(x, 0)])
b_visited = set([x])
furthest_b_distance = -1
furthest_b_node = -1
while b_queue:
if a_queue:
a_pos, a_distance = a_queue.popleft()
for a_move in edges[a_pos]:
if a_move in a_visited:
continue
a_queue.append((a_move, a_distance+1))
a_visited.add(a_move)
b_pos, b_distance = b_queue.popleft()
if b_distance > furthest_b_distance:
furthest_b_distance = b_distance
furthest_b_node = b_pos
for b_move in edges[b_pos]:
if b_move in a_visited or b_move in b_visited:
continue
b_queue.append((b_move, b_distance+1))
b_visited.add(b_move)
#print(furthest_b_distance, furthest_b_node)
print(getNodeDepth(edges, furthest_b_node)*2)
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,695,113,787 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n,m = map(int,input().split())
if m % 2 == 0:
ans = int(m / 2) * n
else:
ans = int(m // 2) * n + int(n // 2)
print(ans) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
n,m = map(int,input().split())
if m % 2 == 0:
ans = int(m / 2) * n
else:
ans = int(m // 2) * n + int(n // 2)
print(ans)
``` | 3.977 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,663,072,842 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | a,b = map(int,input().split())
s = a*b
s = s//2
print(s) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
a,b = map(int,input().split())
s = a*b
s = s//2
print(s)
``` | 3.977 |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1. | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one. | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two. | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
"output": "1"
},
{
"input": "10 7\n1101111011",
"output": "2"
},
{
"input": "10 9\n1110000101",
"output": "1"
},
{
"input": "10 9\n1100000001",
"output": "1"
},
{
"input": "20 5\n11111111110111101001",
"output": "4"
},
{
"input": "20 11\n11100000111000011011",
"output": "2"
},
{
"input": "20 19\n10100000000000000001",
"output": "1"
},
{
"input": "50 13\n10011010100010100111010000010000000000010100000101",
"output": "5"
},
{
"input": "50 8\n11010100000011001100001100010001110000101100110011",
"output": "8"
},
{
"input": "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111",
"output": "25"
},
{
"input": "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "20"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111",
"output": "25"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111",
"output": "25"
},
{
"input": "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111",
"output": "34"
},
{
"input": "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111",
"output": "13"
},
{
"input": "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111",
"output": "15"
},
{
"input": "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111",
"output": "12"
},
{
"input": "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111",
"output": "18"
},
{
"input": "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001",
"output": "16"
},
{
"input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101",
"output": "10"
},
{
"input": "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111",
"output": "13"
},
{
"input": "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001",
"output": "18"
},
{
"input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011",
"output": "12"
},
{
"input": "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001",
"output": "9"
},
{
"input": "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101",
"output": "12"
},
{
"input": "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001",
"output": "7"
},
{
"input": "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001",
"output": "3"
},
{
"input": "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001",
"output": "3"
},
{
"input": "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001",
"output": "3"
},
{
"input": "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "99"
},
{
"input": "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111",
"output": "-1"
},
{
"input": "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111",
"output": "33"
},
{
"input": "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111",
"output": "-1"
},
{
"input": "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111",
"output": "17"
},
{
"input": "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111",
"output": "-1"
},
{
"input": "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011",
"output": "14"
},
{
"input": "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101",
"output": "11"
},
{
"input": "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001",
"output": "-1"
},
{
"input": "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111",
"output": "-1"
},
{
"input": "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101",
"output": "13"
},
{
"input": "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101",
"output": "9"
},
{
"input": "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001",
"output": "-1"
},
{
"input": "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001",
"output": "-1"
},
{
"input": "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001",
"output": "-1"
},
{
"input": "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001",
"output": "3"
},
{
"input": "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "-1"
},
{
"input": "43 30\n1001000001111111010100100100110101011101101",
"output": "2"
},
{
"input": "7 1\n1111111",
"output": "6"
},
{
"input": "9 3\n101000001",
"output": "-1"
},
{
"input": "10 3\n1100000001",
"output": "-1"
},
{
"input": "8 2\n10000101",
"output": "-1"
},
{
"input": "2 1\n11",
"output": "1"
}
] | 1,614,987,425 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,048,000 | import sys
n, d = map(int, sys.stdin.readline().split(' '))
ss = [i for i, s in sys.stdin.readline() if s == '1']
c = 0
sl = 0
el = 0
i = o
while i != len(ss):
s = ss[i]
if s - sl <= d:
el = s
i += 1
else:
if el != sl:
sl = el
c += 1
else:
print(-1)
exit()
print(c) | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
Input Specification:
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one.
Output Specification:
If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
Demo Input:
['8 4\n10010101\n', '4 2\n1001\n', '8 4\n11100101\n', '12 3\n101111100101\n']
Demo Output:
['2\n', '-1\n', '3\n', '4\n']
Note:
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two. | ```python
import sys
n, d = map(int, sys.stdin.readline().split(' '))
ss = [i for i, s in sys.stdin.readline() if s == '1']
c = 0
sl = 0
el = 0
i = o
while i != len(ss):
s = ss[i]
if s - sl <= d:
el = s
i += 1
else:
if el != sl:
sl = el
c += 1
else:
print(-1)
exit()
print(c)
``` | -1 |
|
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"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 | 500 | [
{
"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"
}
] | 1,587,527,135 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 34 | 155 | 0 | # https://codeforces.com/contest/877/problem/A
check = input()
d = "Danil"
o = "Olya"
s = "Slava"
a = "Ann"
n = "Nikita"
friends = [d,o,s,a,n]
unique_friends = 0
for friend in friends:
test = check.split(friend)
if len(test) == 2:
unique_friends += 1
if unique_friends == 1:
print("YES")
else:
print("NO") | Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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.
Input Specification:
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Output Specification:
Print "YES", if problem is from this contest, and "NO" otherwise.
Demo Input:
['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n']
Demo Output:
['NO', 'YES', 'NO']
Note:
none | ```python
# https://codeforces.com/contest/877/problem/A
check = input()
d = "Danil"
o = "Olya"
s = "Slava"
a = "Ann"
n = "Nikita"
friends = [d,o,s,a,n]
unique_friends = 0
for friend in friends:
test = check.split(friend)
if len(test) == 2:
unique_friends += 1
if unique_friends == 1:
print("YES")
else:
print("NO")
``` | 0 |
|
987 | C | Three displays | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation"
] | null | null | It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i < j < k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i < s_j < s_k$ should be held.
The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay. | The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road.
The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display. | If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i < j < k$ such that $s_i < s_j < s_k$. | [
"5\n2 4 5 4 10\n40 30 20 10 40\n",
"3\n100 101 100\n2 4 5\n",
"10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n"
] | [
"90\n",
"-1\n",
"33\n"
] | In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 < s_4 < s_5$ ($2 < 4 < 10$), and the rent cost is $40 + 10 + 40 = 90$.
In the second example you can't select a valid triple of indices, so the answer is -1. | 1,250 | [
{
"input": "5\n2 4 5 4 10\n40 30 20 10 40",
"output": "90"
},
{
"input": "3\n100 101 100\n2 4 5",
"output": "-1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13",
"output": "33"
},
{
"input": "3\n1 2 3\n100000000 100000000 100000000",
"output": "300000000"
},
{
"input": "3\n999999998 999999999 1000000000\n100000000 100000000 99999999",
"output": "299999999"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754\n23219513 68171337 12183499 5549873 73542337 66661387 79397647 34495917 31413076 50918417",
"output": "85904709"
},
{
"input": "20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499\n61699500 83254572 59454419 27833657 55743179 99661234 94729965 75591136 62937826 3626886 73906880 3664913 39990362 94385934 33153747 23840219 64514676 14746017 13062847 65187713",
"output": "72432912"
},
{
"input": "3\n1 2 3\n1 1 1",
"output": "3"
}
] | 1,617,620,424 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 280 | 10,752,000 | import bisect
n=int(input())
s=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=10**18
for mid in range(1,n-1):
l1=[c[i] for i in range(mid) if s[i]<s[mid]]+[10**18]
l2=[c[i] for i in range(mid+1,n) if s[i]>s[mid]]+[10**18]
ans=min(ans,min(l1)+c[mid]+min(l2))
if ans>=10**18:
print(-1)
else:
print(ans) | Title: Three displays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i < j < k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i < s_j < s_k$ should be held.
The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay.
Input Specification:
The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road.
The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display.
Output Specification:
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i < j < k$ such that $s_i < s_j < s_k$.
Demo Input:
['5\n2 4 5 4 10\n40 30 20 10 40\n', '3\n100 101 100\n2 4 5\n', '10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n']
Demo Output:
['90\n', '-1\n', '33\n']
Note:
In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 < s_4 < s_5$ ($2 < 4 < 10$), and the rent cost is $40 + 10 + 40 = 90$.
In the second example you can't select a valid triple of indices, so the answer is -1. | ```python
import bisect
n=int(input())
s=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=10**18
for mid in range(1,n-1):
l1=[c[i] for i in range(mid) if s[i]<s[mid]]+[10**18]
l2=[c[i] for i in range(mid+1,n) if s[i]>s[mid]]+[10**18]
ans=min(ans,min(l1)+c[mid]+min(l2))
if ans>=10**18:
print(-1)
else:
print(ans)
``` | 3 |
|
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"input": "8\n4\n1\n10\n59392",
"output": "59392"
},
{
"input": "4\n1\n8\n7\n44835",
"output": "44835"
},
{
"input": "6\n1\n7\n2\n62982",
"output": "62982"
},
{
"input": "2\n7\n4\n9\n56937",
"output": "35246"
},
{
"input": "2\n9\n8\n1\n75083",
"output": "75083"
},
{
"input": "8\n7\n7\n6\n69038",
"output": "24656"
},
{
"input": "4\n4\n2\n3\n54481",
"output": "36320"
},
{
"input": "6\n4\n9\n8\n72628",
"output": "28244"
},
{
"input": "9\n7\n8\n10\n42357",
"output": "16540"
},
{
"input": "5\n6\n4\n3\n60504",
"output": "36302"
},
{
"input": "7\n2\n3\n8\n21754",
"output": "15539"
},
{
"input": "1\n2\n10\n4\n39901",
"output": "39901"
},
{
"input": "3\n4\n7\n1\n58048",
"output": "58048"
},
{
"input": "9\n10\n4\n6\n52003",
"output": "21956"
},
{
"input": "5\n10\n9\n3\n70149",
"output": "32736"
},
{
"input": "5\n5\n5\n10\n55592",
"output": "11118"
},
{
"input": "1\n5\n2\n6\n49547",
"output": "49547"
},
{
"input": "3\n7\n7\n7\n84046",
"output": "36019"
},
{
"input": "10\n2\n1\n8\n63537",
"output": "63537"
},
{
"input": "7\n2\n10\n5\n81684",
"output": "53678"
},
{
"input": "7\n1\n6\n8\n99831",
"output": "99831"
},
{
"input": "3\n9\n3\n3\n61082",
"output": "20360"
},
{
"input": "5\n5\n8\n9\n79228",
"output": "29931"
},
{
"input": "1\n5\n5\n6\n89535",
"output": "89535"
},
{
"input": "5\n5\n2\n1\n7682",
"output": "7682"
},
{
"input": "7\n4\n8\n8\n25829",
"output": "9224"
},
{
"input": "3\n4\n3\n3\n87079",
"output": "43539"
},
{
"input": "5\n8\n4\n9\n5226",
"output": "2438"
},
{
"input": "4\n9\n6\n6\n1070",
"output": "415"
},
{
"input": "10\n10\n10\n10\n100000",
"output": "10000"
},
{
"input": "1\n1\n1\n1\n1",
"output": "1"
},
{
"input": "10\n10\n10\n10\n1",
"output": "0"
},
{
"input": "10\n10\n1\n10\n10",
"output": "10"
},
{
"input": "10\n10\n1\n10\n100",
"output": "100"
},
{
"input": "2\n2\n2\n2\n1",
"output": "0"
}
] | 1,689,583,421 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
total = 0
for i in range(d):
if (i%k==0):
total+=1
elif (i%l==0):
total+=1
elif (i%m==0):
total+=1
elif (i%n==0):
total+=1
print(total) | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input Specification:
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output Specification:
Output the number of damaged dragons.
Demo Input:
['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n']
Demo Output:
['12\n', '17\n']
Note:
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | ```python
k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
total = 0
for i in range(d):
if (i%k==0):
total+=1
elif (i%l==0):
total+=1
elif (i%m==0):
total+=1
elif (i%n==0):
total+=1
print(total)
``` | 0 |
|
300 | C | Beautiful Numbers | PROGRAMMING | 1,800 | [
"brute force",
"combinatorics"
] | null | null | Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number.
For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't.
Now Vitaly is wondering, how many excellent numbers of length exactly *n* are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109<=+<=7).
A number's length is the number of digits in its decimal representation without leading zeroes. | The first line contains three integers: *a*, *b*, *n* (1<=≤<=*a*<=<<=*b*<=≤<=9,<=1<=≤<=*n*<=≤<=106). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"1 3 3\n",
"2 3 10\n"
] | [
"1\n",
"165\n"
] | none | 2,000 | [
{
"input": "1 3 3",
"output": "1"
},
{
"input": "2 3 10",
"output": "165"
},
{
"input": "6 8 14215",
"output": "651581472"
},
{
"input": "4 9 104671",
"output": "329390901"
},
{
"input": "6 7 78755",
"output": "0"
},
{
"input": "1 8 265",
"output": "461320265"
},
{
"input": "3 9 37413",
"output": "461358757"
},
{
"input": "1 7 49055",
"output": "461364774"
},
{
"input": "3 4 11028",
"output": "461668105"
},
{
"input": "2 6 32377",
"output": "887598327"
},
{
"input": "3 5 80791",
"output": "999993599"
},
{
"input": "4 8 11857",
"output": "999991923"
},
{
"input": "1 3 10785",
"output": "999952603"
},
{
"input": "4 6 11808",
"output": "999925731"
},
{
"input": "1 2 11857",
"output": "999991923"
},
{
"input": "2 4 88193",
"output": "999976846"
},
{
"input": "1 4 37226",
"output": "999970594"
},
{
"input": "2 5 53049",
"output": "259705254"
},
{
"input": "3 6 1000000",
"output": "786609214"
},
{
"input": "7 9 999999",
"output": "53911803"
},
{
"input": "8 9 999999",
"output": "447886447"
},
{
"input": "3 8 1000000",
"output": "0"
},
{
"input": "2 8 999999",
"output": "0"
},
{
"input": "1 6 997695",
"output": "0"
},
{
"input": "1 5 997694",
"output": "0"
},
{
"input": "5 9 997693",
"output": "0"
},
{
"input": "5 8 997690",
"output": "21735480"
},
{
"input": "7 8 2",
"output": "0"
},
{
"input": "6 9 1",
"output": "2"
},
{
"input": "8 9 111111",
"output": "900401372"
},
{
"input": "8 9 1000000",
"output": "573697309"
},
{
"input": "1 2 1000000",
"output": "786609214"
}
] | 1,632,501,732 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 18 | 2,000 | 22,323,200 | from sys import *
mod=pow(10,9)+7
def power(x, y, p) :
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * power(den,p - 2, p)) % p
def check(num,a,b):
s=str(num)
if s.count(str(a))+s.count(str(b))==len(s):
return True
return False
a,b,n=map(int,stdin.readline().split())
start=a*n
end=b*n
ans=0
for i in range(start,end+1):
if check(i,a,b):
curr=i
dividend=(curr-(b*n))
divisor=a-b
if dividend%divisor==0:
tmp=dividend//divisor
if tmp<=n:
ans=((ans%mod)+(ncr(n,tmp,mod)%mod))%mod
stdout.write(str(ans)) | Title: Beautiful Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number.
For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't.
Now Vitaly is wondering, how many excellent numbers of length exactly *n* are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109<=+<=7).
A number's length is the number of digits in its decimal representation without leading zeroes.
Input Specification:
The first line contains three integers: *a*, *b*, *n* (1<=≤<=*a*<=<<=*b*<=≤<=9,<=1<=≤<=*n*<=≤<=106).
Output Specification:
Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
Demo Input:
['1 3 3\n', '2 3 10\n']
Demo Output:
['1\n', '165\n']
Note:
none | ```python
from sys import *
mod=pow(10,9)+7
def power(x, y, p) :
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * power(den,p - 2, p)) % p
def check(num,a,b):
s=str(num)
if s.count(str(a))+s.count(str(b))==len(s):
return True
return False
a,b,n=map(int,stdin.readline().split())
start=a*n
end=b*n
ans=0
for i in range(start,end+1):
if check(i,a,b):
curr=i
dividend=(curr-(b*n))
divisor=a-b
if dividend%divisor==0:
tmp=dividend//divisor
if tmp<=n:
ans=((ans%mod)+(ncr(n,tmp,mod)%mod))%mod
stdout.write(str(ans))
``` | 0 |
|
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
"input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46",
"output": "46 0"
},
{
"input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100",
"output": "700 0"
},
{
"input": "1 0\n- 526403222",
"output": "0 1"
},
{
"input": "1 897986543\n- 371188251",
"output": "526798292 0"
},
{
"input": "1 0\n+ 1",
"output": "1 0"
},
{
"input": "1 0\n- 1",
"output": "0 1"
},
{
"input": "1 10\n+ 10",
"output": "20 0"
},
{
"input": "1 3\n- 5",
"output": "3 1"
},
{
"input": "1 0\n- 5",
"output": "0 1"
},
{
"input": "1 0\n+ 5",
"output": "5 0"
}
] | 1,628,326,693 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 6,758,400 | times,ice_cream = map(int,input().split())
sad_kids = 0
for x in range(times):
sign,order = input().split()
if sign in '+':
ice_cream+= int(order)
else:
if ice_cream >= int(order):
ice_cream -= int(order)
else:
sad_kids += 1
print(ice_cream,end=' ')
print(sad_kids) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input Specification:
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Output Specification:
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
Demo Input:
['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n']
Demo Output:
['22 1\n', '3 2\n']
Note:
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | ```python
times,ice_cream = map(int,input().split())
sad_kids = 0
for x in range(times):
sign,order = input().split()
if sign in '+':
ice_cream+= int(order)
else:
if ice_cream >= int(order):
ice_cream -= int(order)
else:
sad_kids += 1
print(ice_cream,end=' ')
print(sad_kids)
``` | 3 |
|
853 | A | Planning | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are *n* flights that must depart today, the *i*-th of them is planned to depart at the *i*-th minute of the day.
Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first *k* minutes of the day, so now the new departure schedule must be created.
All *n* scheduled flights must now depart at different minutes between (*k*<=+<=1)-th and (*k*<=+<=*n*)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so — their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule.
Helen knows that each minute of delay of the *i*-th flight costs airport *c**i* burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=300<=000), here *n* is the number of flights, and *k* is the number of minutes in the beginning of the day that the flights did not depart.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=107), here *c**i* is the cost of delaying the *i*-th flight for one minute. | The first line must contain the minimum possible total cost of delaying the flights.
The second line must contain *n* different integers *t*1,<=*t*2,<=...,<=*t**n* (*k*<=+<=1<=≤<=*t**i*<=≤<=*k*<=+<=*n*), here *t**i* is the minute when the *i*-th flight must depart. If there are several optimal schedules, print any of them. | [
"5 2\n4 2 1 10 2\n"
] | [
"20\n3 6 7 4 5 \n"
] | Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)·4 + (4 - 2)·2 + (5 - 3)·1 + (6 - 4)·10 + (7 - 5)·2 = 38 burles.
However, the better schedule is shown in the sample answer, its cost is (3 - 1)·4 + (6 - 2)·2 + (7 - 3)·1 + (4 - 4)·10 + (5 - 5)·2 = 20 burles. | 750 | [
{
"input": "5 2\n4 2 1 10 2",
"output": "20\n3 6 7 4 5 "
},
{
"input": "3 2\n3 1 2",
"output": "11\n3 5 4 "
},
{
"input": "5 5\n5 5 9 100 3",
"output": "321\n9 8 7 6 10 "
},
{
"input": "1 1\n1",
"output": "1\n2 "
},
{
"input": "1 1\n10000000",
"output": "10000000\n2 "
},
{
"input": "6 4\n85666 52319 21890 51912 90704 10358",
"output": "1070345\n6 7 9 8 5 10 "
},
{
"input": "10 5\n66220 81797 38439 54881 86879 94346 8802 59094 57095 41949",
"output": "2484818\n9 8 14 12 7 6 15 10 11 13 "
},
{
"input": "8 1\n3669 11274 87693 33658 58862 78334 42958 30572",
"output": "29352\n9 2 3 4 5 6 7 8 "
},
{
"input": "2 2\n16927 73456",
"output": "124237\n4 3 "
},
{
"input": "6 6\n21673 27126 94712 82700 59725 46310",
"output": "1616325\n12 11 7 8 9 10 "
},
{
"input": "10 6\n2226 89307 11261 28772 23196 30298 10832 43119 74662 24028",
"output": "1246672\n16 7 14 11 13 10 15 8 9 12 "
},
{
"input": "9 7\n6972 18785 36323 7549 27884 14286 20795 80005 67805",
"output": "1034082\n16 13 10 15 11 14 12 8 9 "
},
{
"input": "3 1\n20230 80967 85577",
"output": "60690\n4 2 3 "
},
{
"input": "7 1\n783 77740 34830 89295 96042 14966 21810",
"output": "5481\n8 2 3 4 5 6 7 "
},
{
"input": "7 3\n94944 94750 49432 83079 89532 78359 91885",
"output": "1572031\n4 5 10 8 6 9 7 "
}
] | 1,541,770,320 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 109 | 0 | from sys import stdin, stdout
from itertools import repeat
from heapq import heappushpop, heapify
def main():
n, k = map(int, stdin.readline().split())
a = map(int, stdin.readline().split(), repeat(10, n))
q = [(-a[i], i) for i in xrange(k)]
heapify(q)
ans = 0
pos = [0] * n
for i in range(k, n):
x, j = heappushpop(q, (-a[i], i))
ans -= x * (i - j)
pos[j] = i + 1
q.sort()
for i in range(k):
x, j = q[i]
ans -= x * (i + n - j)
pos[j] = i + n + 1
print(ans)
stdout.write(" ".join(map(str, pos)))
main() | Title: Planning
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are *n* flights that must depart today, the *i*-th of them is planned to depart at the *i*-th minute of the day.
Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first *k* minutes of the day, so now the new departure schedule must be created.
All *n* scheduled flights must now depart at different minutes between (*k*<=+<=1)-th and (*k*<=+<=*n*)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so — their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule.
Helen knows that each minute of delay of the *i*-th flight costs airport *c**i* burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=300<=000), here *n* is the number of flights, and *k* is the number of minutes in the beginning of the day that the flights did not depart.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=107), here *c**i* is the cost of delaying the *i*-th flight for one minute.
Output Specification:
The first line must contain the minimum possible total cost of delaying the flights.
The second line must contain *n* different integers *t*1,<=*t*2,<=...,<=*t**n* (*k*<=+<=1<=≤<=*t**i*<=≤<=*k*<=+<=*n*), here *t**i* is the minute when the *i*-th flight must depart. If there are several optimal schedules, print any of them.
Demo Input:
['5 2\n4 2 1 10 2\n']
Demo Output:
['20\n3 6 7 4 5 \n']
Note:
Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)·4 + (4 - 2)·2 + (5 - 3)·1 + (6 - 4)·10 + (7 - 5)·2 = 38 burles.
However, the better schedule is shown in the sample answer, its cost is (3 - 1)·4 + (6 - 2)·2 + (7 - 3)·1 + (4 - 4)·10 + (5 - 5)·2 = 20 burles. | ```python
from sys import stdin, stdout
from itertools import repeat
from heapq import heappushpop, heapify
def main():
n, k = map(int, stdin.readline().split())
a = map(int, stdin.readline().split(), repeat(10, n))
q = [(-a[i], i) for i in xrange(k)]
heapify(q)
ans = 0
pos = [0] * n
for i in range(k, n):
x, j = heappushpop(q, (-a[i], i))
ans -= x * (i - j)
pos[j] = i + 1
q.sort()
for i in range(k):
x, j = q[i]
ans -= x * (i + n - j)
pos[j] = i + n + 1
print(ans)
stdout.write(" ".join(map(str, pos)))
main()
``` | -1 |
|
357 | A | Group of Students | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got 1 point, *c*2 children got 2 points, ..., *c**m* children got *m* points. Now you need to set the passing rate *k* (integer from 1 to *m*): all schoolchildren who got less than *k* points go to the beginner group and those who get at strictly least *k* points go to the intermediate group. We know that if the size of a group is more than *y*, then the university won't find a room for them. We also know that if a group has less than *x* schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from *x* to *y*, inclusive.
Help the university pick the passing rate in a way that meets these requirements. | The first line contains integer *m* (2<=≤<=*m*<=≤<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≤<=*c**i*<=≤<=100). The third line contains two space-separated integers *x* and *y* (1<=≤<=*x*<=≤<=*y*<=≤<=10000). At least one *c**i* is greater than 0. | If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them. | [
"5\n3 4 3 2 1\n6 8\n",
"5\n0 3 3 4 2\n3 10\n",
"2\n2 5\n3 6\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | 500 | [
{
"input": "5\n3 4 3 2 1\n6 8",
"output": "3"
},
{
"input": "5\n0 3 3 4 2\n3 10",
"output": "4"
},
{
"input": "2\n2 5\n3 6",
"output": "0"
},
{
"input": "3\n0 1 0\n2 10",
"output": "0"
},
{
"input": "5\n2 2 2 2 2\n5 5",
"output": "0"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1\n1 10",
"output": "10"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1\n5 5",
"output": "6"
},
{
"input": "6\n0 0 1 1 0 0\n1 6",
"output": "4"
},
{
"input": "7\n3 2 3 3 2 1 1\n5 10",
"output": "4"
},
{
"input": "4\n1 0 0 100\n1 100",
"output": "4"
},
{
"input": "100\n46 6 71 27 94 59 99 82 5 41 18 89 86 2 31 35 52 18 1 14 54 11 28 83 42 15 13 77 22 70 87 65 79 35 44 71 79 9 95 57 5 59 42 62 66 26 33 66 67 45 39 17 97 28 36 100 52 23 68 29 83 6 61 85 71 2 85 98 85 65 95 53 35 96 29 28 82 80 52 60 61 46 46 80 11 3 35 6 12 10 64 7 7 7 65 93 58 85 20 12\n2422 2429",
"output": "52"
},
{
"input": "10\n3 6 1 5 3 7 0 1 0 8\n16 18",
"output": "6"
},
{
"input": "10\n3 3 0 4 0 5 2 10 7 0\n10 24",
"output": "8"
},
{
"input": "10\n9 4 7 7 1 3 7 3 8 5\n23 31",
"output": "7"
},
{
"input": "10\n9 6 9 5 5 4 3 3 9 10\n9 54",
"output": "10"
},
{
"input": "10\n2 4 8 5 2 2 2 5 6 2\n14 24",
"output": "7"
},
{
"input": "10\n10 58 86 17 61 12 75 93 37 30\n10 469",
"output": "10"
},
{
"input": "10\n56 36 0 28 68 54 34 48 28 92\n92 352",
"output": "10"
},
{
"input": "10\n2 81 94 40 74 62 39 70 87 86\n217 418",
"output": "8"
},
{
"input": "10\n48 93 9 96 70 14 100 93 44 79\n150 496",
"output": "8"
},
{
"input": "10\n94 85 4 9 30 45 90 76 0 65\n183 315",
"output": "7"
},
{
"input": "100\n1 0 7 9 0 4 3 10 9 4 9 7 4 4 7 7 6 1 3 3 8 1 4 3 5 8 0 0 6 2 3 5 0 1 5 8 6 3 2 4 9 5 8 6 0 2 5 1 9 5 9 0 6 0 4 5 9 7 1 4 7 5 4 5 6 8 2 3 3 2 8 2 9 5 9 2 4 7 7 8 10 1 3 0 8 0 9 1 1 7 7 8 9 3 5 9 9 8 0 8\n200 279",
"output": "63"
},
{
"input": "100\n5 4 9 7 8 10 7 8 10 0 10 9 7 1 0 7 8 5 5 8 7 7 7 2 5 8 0 7 5 7 1 7 6 5 4 10 6 1 4 4 8 7 0 3 2 10 8 6 1 3 2 6 8 1 9 3 9 5 2 0 3 6 7 5 10 0 2 8 3 10 1 3 8 8 0 2 10 3 4 4 0 7 4 0 9 7 10 2 7 10 9 9 6 6 8 1 10 1 2 0\n52 477",
"output": "91"
},
{
"input": "100\n5 1 6 6 5 4 5 8 0 2 10 1 10 0 6 6 0 1 5 7 10 5 8 4 4 5 10 4 10 3 0 10 10 1 2 6 2 6 3 9 4 4 5 5 7 7 7 4 3 2 1 4 5 0 2 1 8 5 4 5 10 7 0 3 5 4 10 4 10 7 10 1 8 3 9 8 6 9 5 7 3 4 7 8 4 0 3 4 4 1 6 6 2 0 1 5 3 3 9 10\n22 470",
"output": "98"
},
{
"input": "100\n73 75 17 93 35 7 71 88 11 58 78 33 7 38 14 83 30 25 75 23 60 10 100 7 90 51 82 0 78 54 61 32 20 90 54 45 100 62 40 99 43 86 87 64 10 41 29 51 38 22 5 63 10 64 90 20 100 33 95 72 40 82 92 30 38 3 71 85 99 66 4 26 33 41 85 14 26 61 21 96 29 40 25 14 48 4 30 44 6 41 71 71 4 66 13 50 30 78 64 36\n2069 2800",
"output": "57"
},
{
"input": "100\n86 19 100 37 9 49 97 9 70 51 14 31 47 53 76 65 10 40 4 92 2 79 22 70 85 58 73 96 89 91 41 88 70 31 53 33 22 51 10 56 90 39 70 38 86 15 94 63 82 19 7 65 22 83 83 71 53 6 95 89 53 41 95 11 32 0 7 84 39 11 37 73 20 46 18 28 72 23 17 78 37 49 43 62 60 45 30 69 38 41 71 43 47 80 64 40 77 99 36 63\n1348 3780",
"output": "74"
},
{
"input": "100\n65 64 26 48 16 90 68 32 95 11 27 29 87 46 61 35 24 99 34 17 79 79 11 66 14 75 31 47 43 61 100 32 75 5 76 11 46 74 81 81 1 25 87 45 16 57 24 76 58 37 42 0 46 23 75 66 75 11 50 5 10 11 43 26 38 42 88 15 70 57 2 74 7 72 52 8 72 19 37 38 66 24 51 42 40 98 19 25 37 7 4 92 47 72 26 76 66 88 53 79\n1687 2986",
"output": "65"
},
{
"input": "100\n78 43 41 93 12 76 62 54 85 5 42 61 93 37 22 6 50 80 63 53 66 47 0 60 43 93 90 8 97 64 80 22 23 47 30 100 80 75 84 95 35 69 36 20 58 99 78 88 1 100 10 69 57 77 68 61 62 85 4 45 24 4 24 74 65 73 91 47 100 35 25 53 27 66 62 55 38 83 56 20 62 10 71 90 41 5 75 83 36 75 15 97 79 52 88 32 55 42 59 39\n873 4637",
"output": "85"
},
{
"input": "100\n12 25 47 84 72 40 85 37 8 92 85 90 12 7 45 14 98 62 31 62 10 89 37 65 77 29 5 3 21 21 10 98 44 37 37 37 50 15 69 27 19 99 98 91 63 42 32 68 77 88 78 35 13 44 4 82 42 76 28 50 65 64 88 46 94 37 40 7 10 58 21 31 17 91 75 86 3 9 9 14 72 20 40 57 11 75 91 48 79 66 53 24 93 16 58 4 10 89 75 51\n666 4149",
"output": "88"
},
{
"input": "10\n8 0 2 2 5 1 3 5 2 2\n13 17",
"output": "6"
},
{
"input": "10\n10 4 4 6 2 2 0 5 3 7\n19 24",
"output": "5"
},
{
"input": "10\n96 19 75 32 94 16 81 2 93 58\n250 316",
"output": "6"
},
{
"input": "10\n75 65 68 43 89 57 7 58 51 85\n258 340",
"output": "6"
},
{
"input": "100\n59 51 86 38 90 10 36 3 97 35 32 20 25 96 49 39 66 44 64 50 97 68 50 79 3 33 72 96 32 74 67 9 17 77 67 15 1 100 99 81 18 1 15 36 7 34 30 78 10 97 7 19 87 47 62 61 40 29 1 34 6 77 76 21 66 11 65 96 82 54 49 65 56 90 29 75 48 77 48 53 91 21 98 26 80 44 57 97 11 78 98 45 40 88 27 27 47 5 26 6\n2479 2517",
"output": "53"
},
{
"input": "100\n5 11 92 53 49 42 15 86 31 10 30 49 21 66 14 13 80 25 21 25 86 20 86 83 36 81 21 23 0 30 64 85 15 33 74 96 83 51 84 4 35 65 10 7 11 11 41 80 51 51 74 52 43 83 88 38 77 20 14 40 37 25 27 93 27 77 48 56 93 65 79 33 91 14 9 95 13 36 24 2 66 31 56 28 49 58 74 17 88 36 46 73 54 18 63 22 2 41 8 50\n2229 2279",
"output": "52"
},
{
"input": "2\n0 1\n1 1",
"output": "0"
},
{
"input": "4\n1 0 0 4\n1 3",
"output": "0"
},
{
"input": "4\n1 0 0 0\n1 10",
"output": "0"
},
{
"input": "3\n2 1 4\n3 3",
"output": "0"
},
{
"input": "5\n2 0 2 0 0\n2 2",
"output": "3"
},
{
"input": "4\n1 2 3 4\n1 7",
"output": "4"
},
{
"input": "2\n7 1\n1 6",
"output": "0"
},
{
"input": "5\n1 3 7 8 9\n4 6",
"output": "0"
},
{
"input": "2\n5 2\n5 6",
"output": "0"
},
{
"input": "2\n1 0\n1 2",
"output": "0"
},
{
"input": "4\n2 3 9 10\n5 14",
"output": "4"
},
{
"input": "3\n1 2 1\n1 1",
"output": "0"
},
{
"input": "4\n2 3 9 50\n5 30",
"output": "0"
},
{
"input": "3\n7 1 1\n6 8",
"output": "0"
},
{
"input": "6\n1 1 2 3 4 5\n3 9",
"output": "5"
},
{
"input": "3\n4 5 5\n4 9",
"output": "3"
},
{
"input": "6\n1 2 3 4 5 6\n1 3",
"output": "0"
},
{
"input": "5\n3 4 3 2 10\n6 8",
"output": "0"
},
{
"input": "5\n1 1 3 4 6\n2 2",
"output": "0"
},
{
"input": "5\n5 3 5 8 10\n2 20",
"output": "4"
},
{
"input": "4\n0 0 5 0\n3 6",
"output": "0"
},
{
"input": "8\n1 1 1 1 2 2 2 1\n3 7",
"output": "6"
},
{
"input": "3\n1 100 100\n101 200",
"output": "0"
}
] | 1,623,216,855 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 124 | 0 | #%%
r = int(input())
ins = (list(map(int, input().split(" "))))
low, high = list(map(int, input().split(" ")))
for i in range(1, len(ins)):
ins[i] += ins[i-1]
if ins[-1] > (high * 2): print(0)
else:
for i in range(len(ins)):
if low<= ins[i] <= high and low <= ins[-1] - ins[i] <= high:
print(i+2)
break
else:
print(0) | Title: Group of Students
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got 1 point, *c*2 children got 2 points, ..., *c**m* children got *m* points. Now you need to set the passing rate *k* (integer from 1 to *m*): all schoolchildren who got less than *k* points go to the beginner group and those who get at strictly least *k* points go to the intermediate group. We know that if the size of a group is more than *y*, then the university won't find a room for them. We also know that if a group has less than *x* schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from *x* to *y*, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input Specification:
The first line contains integer *m* (2<=≤<=*m*<=≤<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≤<=*c**i*<=≤<=100). The third line contains two space-separated integers *x* and *y* (1<=≤<=*x*<=≤<=*y*<=≤<=10000). At least one *c**i* is greater than 0.
Output Specification:
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Demo Input:
['5\n3 4 3 2 1\n6 8\n', '5\n0 3 3 4 2\n3 10\n', '2\n2 5\n3 6\n']
Demo Output:
['3\n', '4\n', '0\n']
Note:
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | ```python
#%%
r = int(input())
ins = (list(map(int, input().split(" "))))
low, high = list(map(int, input().split(" ")))
for i in range(1, len(ins)):
ins[i] += ins[i-1]
if ins[-1] > (high * 2): print(0)
else:
for i in range(len(ins)):
if low<= ins[i] <= high and low <= ins[-1] - ins[i] <= high:
print(i+2)
break
else:
print(0)
``` | 3 |
|
278 | A | Circle Line | PROGRAMMING | 800 | [
"implementation"
] | null | null | The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces. | Print a single number — the length of the shortest path between stations number *s* and *t*. | [
"4\n2 3 4 9\n1 3\n",
"4\n5 8 2 100\n4 1\n",
"3\n1 1 1\n3 1\n",
"3\n31 41 59\n1 1\n"
] | [
"5\n",
"15\n",
"1\n",
"0\n"
] | In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | 500 | [
{
"input": "4\n2 3 4 9\n1 3",
"output": "5"
},
{
"input": "4\n5 8 2 100\n4 1",
"output": "15"
},
{
"input": "3\n1 1 1\n3 1",
"output": "1"
},
{
"input": "3\n31 41 59\n1 1",
"output": "0"
},
{
"input": "5\n16 13 10 30 15\n4 2",
"output": "23"
},
{
"input": "6\n89 82 87 32 67 33\n4 4",
"output": "0"
},
{
"input": "7\n2 3 17 10 2 2 2\n4 2",
"output": "18"
},
{
"input": "3\n4 37 33\n3 3",
"output": "0"
},
{
"input": "8\n87 40 96 7 86 86 72 97\n6 8",
"output": "158"
},
{
"input": "10\n91 94 75 99 100 91 79 86 79 92\n2 8",
"output": "348"
},
{
"input": "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7",
"output": "0"
},
{
"input": "34\n96 65 24 99 74 76 97 93 99 69 94 82 92 91 98 83 95 97 96 81 90 95 86 87 43 78 88 86 82 62 76 99 83 96\n21 16",
"output": "452"
},
{
"input": "50\n75 98 65 75 99 89 84 65 9 53 62 61 61 53 80 7 6 47 86 1 89 27 67 1 31 39 53 92 19 20 76 41 60 15 29 94 76 82 87 89 93 38 42 6 87 36 100 97 93 71\n2 6",
"output": "337"
},
{
"input": "99\n1 15 72 78 23 22 26 98 7 2 75 58 100 98 45 79 92 69 79 72 33 88 62 9 15 87 17 73 68 54 34 89 51 91 28 44 20 11 74 7 85 61 30 46 95 72 36 18 48 22 42 46 29 46 86 53 96 55 98 34 60 37 75 54 1 81 20 68 84 19 18 18 75 84 86 57 73 34 23 43 81 87 47 96 57 41 69 1 52 44 54 7 85 35 5 1 19 26 7\n4 64",
"output": "1740"
},
{
"input": "100\n33 63 21 27 49 82 86 93 43 55 4 72 89 85 5 34 80 7 23 13 21 49 22 73 89 65 81 25 6 92 82 66 58 88 48 96 1 1 16 48 67 96 84 63 87 76 20 100 36 4 31 41 35 62 55 76 74 70 68 41 4 16 39 81 2 41 34 73 66 57 41 89 78 93 68 96 87 47 92 60 40 58 81 12 19 74 56 83 56 61 83 97 26 92 62 52 39 57 89 95\n71 5",
"output": "2127"
},
{
"input": "100\n95 98 99 81 98 96 100 92 96 90 99 91 98 98 91 78 97 100 96 98 87 93 96 99 91 92 96 92 90 97 85 83 99 95 66 91 87 89 100 95 100 88 99 84 96 79 99 100 94 100 99 99 92 89 99 91 100 94 98 97 91 92 90 87 84 99 97 98 93 100 90 85 75 95 86 71 98 93 91 87 92 95 98 94 95 94 100 98 96 100 97 96 95 95 86 86 94 97 98 96\n67 57",
"output": "932"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 97 100 100 100 100 100 99 100 100 99 99 100 99 100 100 100 100 100 100 100 100 100 97 99 98 98 100 98 98 100 99 100 100 100 100 99 100 98 100 99 98 99 98 98 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 98 100 99 99 100 96 100 96 100 99 100 100 99 100 99 100 100 100 99 100 100 100 100 98 98 97 100 100 99 98\n16 6",
"output": "997"
},
{
"input": "100\n3 6 23 4 23 1 2 14 2 3 3 9 17 8 10 5 1 14 8 5 7 4 13 8 5 6 24 3 12 3 4 9 2 8 2 1 2 1 3 2 1 6 14 23 8 6 3 5 7 8 18 9 2 5 22 6 13 16 2 4 31 20 4 3 3 6 6 1 1 18 5 11 1 14 4 16 6 37 11 1 8 3 7 11 21 14 3 3 12 2 5 1 9 16 3 1 3 4 4 2\n98 24",
"output": "195"
},
{
"input": "100\n1 1 3 1 1 2 1 2 1 1 2 2 2 1 1 1 1 1 1 3 1 1 1 3 1 3 3 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 3 3 2 1 1 1 1 1 2 2 1 3 1 1 1 2 4 1 1 2 5 2 1 1 2 1 1 1 2 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 3 1 7 3 1 3 1 2 1 2 1\n49 10",
"output": "60"
},
{
"input": "100\n75 62 31 96 62 76 93 96 72 67 88 35 67 34 60 56 95 86 82 48 64 61 74 100 56 98 76 98 78 55 53 10 12 78 58 45 86 90 93 77 69 73 88 66 92 88 33 50 95 69 89 12 93 57 93 89 59 53 71 86 15 13 61 93 24 100 58 76 46 95 76 82 50 20 79 38 5 72 99 81 55 90 90 65 85 44 63 39 6 34 98 72 88 30 59 73 84 61 25 67\n86 25",
"output": "2523"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n1 51",
"output": "5000"
},
{
"input": "4\n1 1 1 1\n2 4",
"output": "2"
},
{
"input": "4\n1 1 2 1\n2 4",
"output": "2"
}
] | 1,547,936,241 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 218 | 0 | input()
Stations = list(map(int, input().split()))
First, Second = list(map(int, input().split()))
Count1, Count2 = 0, 0
i = First - 1
while i != Second - 1:
Count1 += Stations[i]
i = (i + 1) % len(Stations)
i = (First - 2 if First - 2 >= 0 else len(Stations) - 1)
while i != Second - 1:
Count2 += Stations[i]
i = (i - 1 if i - 1 >= 0 else len(Stations) - 1)
Count2 += Stations[Second - 1]
print(min(Count2, Count1))
| Title: Circle Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output Specification:
Print a single number — the length of the shortest path between stations number *s* and *t*.
Demo Input:
['4\n2 3 4 9\n1 3\n', '4\n5 8 2 100\n4 1\n', '3\n1 1 1\n3 1\n', '3\n31 41 59\n1 1\n']
Demo Output:
['5\n', '15\n', '1\n', '0\n']
Note:
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | ```python
input()
Stations = list(map(int, input().split()))
First, Second = list(map(int, input().split()))
Count1, Count2 = 0, 0
i = First - 1
while i != Second - 1:
Count1 += Stations[i]
i = (i + 1) % len(Stations)
i = (First - 2 if First - 2 >= 0 else len(Stations) - 1)
while i != Second - 1:
Count2 += Stations[i]
i = (i - 1 if i - 1 >= 0 else len(Stations) - 1)
Count2 += Stations[Second - 1]
print(min(Count2, Count1))
``` | 3 |
|
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 3",
"output": "5001"
},
{
"input": "10000 10",
"output": "5000"
},
{
"input": "9999 3",
"output": "5001"
},
{
"input": "9999 2",
"output": "5000"
},
{
"input": "9999 10",
"output": "5000"
},
{
"input": "9999 9",
"output": "5004"
},
{
"input": "18 10",
"output": "10"
},
{
"input": "19 10",
"output": "10"
},
{
"input": "20 10",
"output": "10"
},
{
"input": "21 10",
"output": "20"
},
{
"input": "7688 5",
"output": "3845"
},
{
"input": "4608 5",
"output": "2305"
},
{
"input": "3979 2",
"output": "1990"
},
{
"input": "9985 6",
"output": "4998"
},
{
"input": "3230 8",
"output": "1616"
},
{
"input": "24 9",
"output": "18"
},
{
"input": "3275 8",
"output": "1640"
},
{
"input": "6240 7",
"output": "3122"
},
{
"input": "5227 4",
"output": "2616"
},
{
"input": "3832 6",
"output": "1920"
},
{
"input": "4 2",
"output": "2"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "10 5",
"output": "5"
},
{
"input": "3 2",
"output": "2"
},
{
"input": "6 4",
"output": "4"
},
{
"input": "5 2",
"output": "4"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "9 9",
"output": "9"
},
{
"input": "4 5",
"output": "-1"
}
] | 1,668,156,617 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n,m=map(int,input().split())
mi=10001
for i in range(2,n+1,2):
if (i//2+(n-i))%m==0:
mi=min(mi,(i//2+(n-i)))
else:
print(-1*(mi==10001)+mi*(mi!=10001)) | Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
Input Specification:
The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10).
Output Specification:
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
Demo Input:
['10 2\n', '3 5\n']
Demo Output:
['6\n', '-1\n']
Note:
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | ```python
n,m=map(int,input().split())
mi=10001
for i in range(2,n+1,2):
if (i//2+(n-i))%m==0:
mi=min(mi,(i//2+(n-i)))
else:
print(-1*(mi==10001)+mi*(mi!=10001))
``` | 0 |
|
978 | A | Remove Duplicates | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. | The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. | In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. | [
"6\n1 5 5 1 6 1\n",
"5\n2 4 2 4 4\n",
"5\n6 6 6 6 6\n"
] | [
"3\n5 6 1 \n",
"2\n2 4 \n",
"1\n6 \n"
] | In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | 0 | [
{
"input": "6\n1 5 5 1 6 1",
"output": "3\n5 6 1 "
},
{
"input": "5\n2 4 2 4 4",
"output": "2\n2 4 "
},
{
"input": "5\n6 6 6 6 6",
"output": "1\n6 "
},
{
"input": "7\n1 2 3 4 2 2 3",
"output": "4\n1 4 2 3 "
},
{
"input": "9\n100 100 100 99 99 99 100 100 100",
"output": "2\n99 100 "
},
{
"input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868",
"output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 "
},
{
"input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421",
"output": "8\n117 151 183 227 954 222 909 421 "
},
{
"input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2",
"output": "4\n62 726 903 2 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2",
"output": "6\n5 33 375 37 3 2 "
},
{
"input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6",
"output": "6\n4 3 2 5 1 6 "
},
{
"input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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\n233 1 "
},
{
"input": "47\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",
"output": "1\n1 "
},
{
"input": "2\n964 964",
"output": "1\n964 "
},
{
"input": "2\n1000 1000",
"output": "1\n1000 "
},
{
"input": "1\n1000",
"output": "1\n1000 "
},
{
"input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993",
"output": "10\n996 1000 999 992 997 991 995 998 994 993 "
},
{
"input": "6\n994 993 1000 998 991 994",
"output": "5\n993 1000 998 991 994 "
},
{
"input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999",
"output": "10\n993 996 995 991 994 997 998 992 1000 999 "
},
{
"input": "3\n6 6 3",
"output": "2\n6 3 "
},
{
"input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997",
"output": "9\n1000 995 994 993 999 996 998 991 997 "
},
{
"input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996",
"output": "10\n998 995 999 992 1000 993 994 997 991 996 "
},
{
"input": "2\n1000 999",
"output": "2\n1000 999 "
},
{
"input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000",
"output": "10\n996 999 993 994 997 995 991 992 998 1000 "
},
{
"input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992",
"output": "8\n993 997 998 994 1000 991 995 992 "
},
{
"input": "6\n1000 1 1000 2 1000 1",
"output": "3\n2 1000 1 "
},
{
"input": "6\n1000 1 1000 2 1 1000",
"output": "3\n2 1 1000 "
},
{
"input": "7\n1 1000 1 999 1000 1 2",
"output": "4\n999 1000 1 2 "
}
] | 1,682,118,349 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 62 | 0 | n = int(input())
a = list(map(int, input().split()))
c = set(a)
li = []
for i in range(len(a)-1, -1, -1):
if a[i] in li:
continue
else:
li.append(a[i])
li.reverse()
print(len(li))
print(*li) | Title: Remove Duplicates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
Output Specification:
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
Demo Input:
['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n']
Demo Output:
['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n']
Note:
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | ```python
n = int(input())
a = list(map(int, input().split()))
c = set(a)
li = []
for i in range(len(a)-1, -1, -1):
if a[i] in li:
continue
else:
li.append(a[i])
li.reverse()
print(len(li))
print(*li)
``` | 3 |
|
877 | C | Slava and tanks | PROGRAMMING | 1,600 | [
"constructive algorithms"
] | null | null | Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.
If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell *n* can only move to the cell *n*<=-<=1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.
Help Slava to destroy all tanks using as few bombs as possible. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the size of the map. | In the first line print *m* — the minimum number of bombs Slava needs to destroy all tanks.
In the second line print *m* integers *k*1,<=*k*2,<=...,<=*k**m*. The number *k**i* means that the *i*-th bomb should be dropped at the cell *k**i*.
If there are multiple answers, you can print any of them. | [
"2\n",
"3\n"
] | [
"3\n2 1 2 ",
"4\n2 1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "3\n2 1 2 "
},
{
"input": "3",
"output": "4\n2 1 3 2 "
},
{
"input": "4",
"output": "6\n2 4 1 3 2 4 "
},
{
"input": "6",
"output": "9\n2 4 6 1 3 5 2 4 6 "
},
{
"input": "10",
"output": "15\n2 4 6 8 10 1 3 5 7 9 2 4 6 8 10 "
},
{
"input": "15",
"output": "22\n2 4 6 8 10 12 14 1 3 5 7 9 11 13 15 2 4 6 8 10 12 14 "
},
{
"input": "100",
"output": "150\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 "
},
{
"input": "100000",
"output": "150000\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "55333",
"output": "82999\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "42273",
"output": "63409\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "29857",
"output": "44785\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "27687",
"output": "41530\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "25517",
"output": "38275\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "23347",
"output": "35020\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "10931",
"output": "16396\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "98514",
"output": "147771\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "6591",
"output": "9886\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 28..."
},
{
"input": "94174",
"output": "141261\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "92004",
"output": "138006\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "59221",
"output": "88831\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "46806",
"output": "70209\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "54882",
"output": "82323\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "42466",
"output": "63699\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "40296",
"output": "60444\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "27880",
"output": "41820\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "25710",
"output": "38565\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "23540",
"output": "35310\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "11124",
"output": "16686\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "8954",
"output": "13431\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2..."
},
{
"input": "85387",
"output": "128080\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "72971",
"output": "109456\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "81047",
"output": "121570\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ..."
},
{
"input": "5",
"output": "7\n2 4 1 3 5 2 4 "
}
] | 1,527,013,697 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 78 | 0 | import math
n = int(input())
if n == 2:
print(3)
print("2 1 2")
elif n == 3:
print(4)
print("2 1 3 2")
else:
print(n+math.ceil(n/2))
for even in [False, True, False]:
for i in range(n):
if (i+1) % 2 == 1 and not even:
print(i+1, end=" ")
if (i+1) % 2 == 0 and even:
print(i+1, end=" ") | Title: Slava and tanks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.
If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell *n* can only move to the cell *n*<=-<=1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.
Help Slava to destroy all tanks using as few bombs as possible.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the size of the map.
Output Specification:
In the first line print *m* — the minimum number of bombs Slava needs to destroy all tanks.
In the second line print *m* integers *k*1,<=*k*2,<=...,<=*k**m*. The number *k**i* means that the *i*-th bomb should be dropped at the cell *k**i*.
If there are multiple answers, you can print any of them.
Demo Input:
['2\n', '3\n']
Demo Output:
['3\n2 1 2 ', '4\n2 1 3 2 ']
Note:
none | ```python
import math
n = int(input())
if n == 2:
print(3)
print("2 1 2")
elif n == 3:
print(4)
print("2 1 3 2")
else:
print(n+math.ceil(n/2))
for even in [False, True, False]:
for i in range(n):
if (i+1) % 2 == 1 and not even:
print(i+1, end=" ")
if (i+1) % 2 == 0 and even:
print(i+1, end=" ")
``` | 0 |
|
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcdefghijklm"
},
{
"input": "100 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "100 10",
"output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
},
{
"input": "3 3",
"output": "abc"
},
{
"input": "6 3",
"output": "abcabc"
},
{
"input": "10 3",
"output": "abcabcabca"
},
{
"input": "50 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab"
},
{
"input": "90 2",
"output": "ababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "6 2",
"output": "ababab"
},
{
"input": "99 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
},
{
"input": "4 2",
"output": "abab"
},
{
"input": "100 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "40 22",
"output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr"
},
{
"input": "13 8",
"output": "abcdefghabcde"
},
{
"input": "16 15",
"output": "abcdefghijklmnoa"
},
{
"input": "17 17",
"output": "abcdefghijklmnopq"
},
{
"input": "19 4",
"output": "abcdabcdabcdabcdabc"
},
{
"input": "100 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
},
{
"input": "100 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy"
},
{
"input": "26 26",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "27 26",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "2 2",
"output": "ab"
},
{
"input": "26 25",
"output": "abcdefghijklmnopqrstuvwxya"
},
{
"input": "99 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababa"
},
{
"input": "99 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu"
},
{
"input": "4 4",
"output": "abcd"
},
{
"input": "5 3",
"output": "abcab"
},
{
"input": "5 4",
"output": "abcda"
},
{
"input": "5 5",
"output": "abcde"
},
{
"input": "24 22",
"output": "abcdefghijklmnopqrstuvab"
},
{
"input": "26 14",
"output": "abcdefghijklmnabcdefghijkl"
},
{
"input": "26 15",
"output": "abcdefghijklmnoabcdefghijk"
},
{
"input": "30 12",
"output": "abcdefghijklabcdefghijklabcdef"
},
{
"input": "35 4",
"output": "abcdabcdabcdabcdabcdabcdabcdabcdabc"
},
{
"input": "79 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "79 14",
"output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi"
},
{
"input": "85 13",
"output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg"
},
{
"input": "90 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno"
},
{
"input": "90 19",
"output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn"
},
{
"input": "26 24",
"output": "abcdefghijklmnopqrstuvwxab"
},
{
"input": "100 17",
"output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno"
},
{
"input": "26 2",
"output": "ababababababababababababab"
}
] | 1,694,608,115 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # # (98,122)
import random
n, k = [int(i) for i in input().split()]
def main(n, k):
letters = set(chr(random.randint(97,122)) for _ in range(k))
while len(letters) != k:
letters.add(chr(random.randint(98,122)))
letters = list(letters)
password = ''
for i in range(n):
password += letters[i%k]
return password
# print(list(set([1,2,3,4])))
# print(main(n, k))
# a = 'moahmed'
# [1,2,3]. | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
Input Specification:
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
Output Specification:
Print any password which satisfies all conditions given by Innokentiy.
Demo Input:
['4 3\n', '6 6\n', '5 2\n']
Demo Output:
['java\n', 'python\n', 'phphp\n']
Note:
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | ```python
# # (98,122)
import random
n, k = [int(i) for i in input().split()]
def main(n, k):
letters = set(chr(random.randint(97,122)) for _ in range(k))
while len(letters) != k:
letters.add(chr(random.randint(98,122)))
letters = list(letters)
password = ''
for i in range(n):
password += letters[i%k]
return password
# print(list(set([1,2,3,4])))
# print(main(n, k))
# a = 'moahmed'
# [1,2,3].
``` | 0 |
|
39 | A | C*++ Calculations | PROGRAMMING | 2,000 | [
"expression parsing",
"greedy"
] | A. C*++ Calculations | 2 | 64 | C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in C*++ that looks like this (*expression* is the main term):
- *expression* ::= *summand* | *expression*<=+<=*summand* | *expression*<=-<=*summand* - *summand* ::= *increment* | *coefficient***increment* - *increment* ::= a++ | ++a - *coefficient* ::= 0|1|2|...|1000
For example, "5*a++-3*++a+a++" is a valid expression in C*++.
Thus, we have a sum consisting of several summands divided by signs "+" or "-". Every summand is an expression "a++" or "++a" multiplied by some integer coefficient. If the coefficient is omitted, it is suggested being equal to 1.
The calculation of such sum in C*++ goes the following way. First all the summands are calculated one after another, then they are summed by the usual arithmetic rules. If the summand contains "a++", then during the calculation first the value of the "a" variable is multiplied by the coefficient, then value of "a" is increased by 1. If the summand contains "++a", then the actions on it are performed in the reverse order: first "a" is increased by 1, then — multiplied by the coefficient.
The summands may be calculated in any order, that's why sometimes the result of the calculation is completely unpredictable! Your task is to find its largest possible value. | The first input line contains an integer *a* (<=-<=1000<=≤<=*a*<=≤<=1000) — the initial value of the variable "a". The next line contains an expression in C*++ language of the described type. The number of the summands in the expression does not exceed 1000. It is guaranteed that the line describing the expression contains no spaces and tabulation. | Output a single number — the maximal possible value of the expression. | [
"1\n5*a++-3*++a+a++\n",
"3\na+++++a\n"
] | [
"11\n",
"8\n"
] | Consider the second example. Initially *a* = 3. Suppose that at first the first summand is calculated, and then the second one is. The first summand gets equal to 3, and the value of *a* is increased by 1. At the calculation of the second summand *a* is increased once more (gets equal to 5). The value of the second summand is 5, and together they give 8. If we calculate the second summand first and the first summand later, then the both summands equals to 4, and the result is 8, too. | 0 | [
{
"input": "1\n5*a++-3*++a+a++",
"output": "11"
},
{
"input": "3\na+++++a",
"output": "8"
},
{
"input": "-668\n820*a+++402*++a-482*++a",
"output": "-492358"
},
{
"input": "902\n600*++a+411*a+++20*a++-340*++a-306*++a+485*a++-776*a+++417*a+++70*a++-703*a++",
"output": "-97296"
},
{
"input": "-215\n840*++a+183*++a-975*++a+301*a+++874*a++",
"output": "-256096"
},
{
"input": "-211\n849*a++-419*a+++720*++a-543*a+++193*a++-506*++a",
"output": "-55460"
},
{
"input": "-206\n859*a++-655*a+++466*++a-786*++a+512*a+++628*a+++747*a++",
"output": "-351932"
},
{
"input": "-441\n214*++a+30*++a-390*++a-112*++a-409*++a+287*a++-660*++a-740*++a-695*a++-830*++a+554*a++",
"output": "1211971"
},
{
"input": "875\n132*a+++960*++a+510*a++-37*++a-923*++a-892*a+++427*a+++384*a++-253*a++-82*a+++506*a+++815*a+++499*++a",
"output": "1829041"
},
{
"input": "399\n469*++a-935*++a-838*++a-468*++a+79*++a-89*++a-863*++a+531*a++-523*a++-583*++a-411*++a+301*++a+201*a++-108*a+++581*a+++938*++a-16*a++-632*a+++146*a++-230*++a+151*++a-618*a+++593*a+++320*++a+750*++a+185*a++-68*++a+839*a++-853*a+++761*a++-442*a++-385*a++-487*a++-573*a++-820*a++-123*a+++792*++a+95*++a+228*++a-945*a+++126*++a-888*++a-745*++a-217*a++-883*++a-632*++a+82*a++-371*++a-14*++a+528*a++",
"output": "-2184221"
},
{
"input": "-677\n490*++a",
"output": "-331240"
},
{
"input": "-744\n672*a++-975*a++-394*a+++968*a+++222*a+++988*++a+504*++a-782*a++-321*++a+980*++a-483*a++-554*++a-347*++a-180*++a-390*a+++403*a++-617*a+++378*a+++544*++a-978*a+++952*a++-618*a++-516*++a-990*++a+540*++a-398*++a-187*++a+401*++a+829*a++-187*++a-185*a++-529*a++",
"output": "1091591"
},
{
"input": "-496\n589*a+++507*++a+59*++a-507*a+++951*++a+99*++a-651*++a-985*a++-61*a+++588*a++-412*a++-756*a+++978*a+++58*++a-230*++a-391*++a-574*a++",
"output": "408226"
},
{
"input": "217\n828*a+++340*++a-450*a++-575*++a-821*++a+89*a++-543*++a-61*++a+629*++a-956*++a-685*++a-424*a++",
"output": "-565304"
},
{
"input": "189\n360*++a+889*a++-940*a++-272*a+++437*++a-495*++a+194*++a-339*++a-503*++a+335*++a-459*a++-285*a++-738*++a-554*a++-68*++a",
"output": "-447974"
},
{
"input": "-589\n561*a++-754*++a-577*a+++393*++a-636*++a-481*++a+645*a++-931*++a+198*a++-788*a++-925*a++-580*a++-506*++a-722*a++-33*++a+743*a++-506*++a+243*a++-416*a++-438*a+++23*++a-745*++a-865*a++",
"output": "4173855"
},
{
"input": "-693\n372*++a-195*a++-542*a+++15*a++-560*a+++268*a+++266*a+++476*a++-267*a+++608*a+++766*++a-861*a++-649*a++-973*++a-840*++a+586*++a-346*++a-940*a++-177*a++-925*a++-608*++a+816*++a+150*a+++494*++a",
"output": "2186029"
},
{
"input": "7\na+++a++-a++-a+++5*a++-2*a++",
"output": "50"
},
{
"input": "1000\na++",
"output": "1000"
},
{
"input": "1000\n++a",
"output": "1001"
},
{
"input": "332\n++a",
"output": "333"
},
{
"input": "4\n0*a++",
"output": "0"
},
{
"input": "584\n7*++a",
"output": "4095"
}
] | 1,690,503,687 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1690503687.6249542")# 1690503687.624974 | Title: C*++ Calculations
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in C*++ that looks like this (*expression* is the main term):
- *expression* ::= *summand* | *expression*<=+<=*summand* | *expression*<=-<=*summand* - *summand* ::= *increment* | *coefficient***increment* - *increment* ::= a++ | ++a - *coefficient* ::= 0|1|2|...|1000
For example, "5*a++-3*++a+a++" is a valid expression in C*++.
Thus, we have a sum consisting of several summands divided by signs "+" or "-". Every summand is an expression "a++" or "++a" multiplied by some integer coefficient. If the coefficient is omitted, it is suggested being equal to 1.
The calculation of such sum in C*++ goes the following way. First all the summands are calculated one after another, then they are summed by the usual arithmetic rules. If the summand contains "a++", then during the calculation first the value of the "a" variable is multiplied by the coefficient, then value of "a" is increased by 1. If the summand contains "++a", then the actions on it are performed in the reverse order: first "a" is increased by 1, then — multiplied by the coefficient.
The summands may be calculated in any order, that's why sometimes the result of the calculation is completely unpredictable! Your task is to find its largest possible value.
Input Specification:
The first input line contains an integer *a* (<=-<=1000<=≤<=*a*<=≤<=1000) — the initial value of the variable "a". The next line contains an expression in C*++ language of the described type. The number of the summands in the expression does not exceed 1000. It is guaranteed that the line describing the expression contains no spaces and tabulation.
Output Specification:
Output a single number — the maximal possible value of the expression.
Demo Input:
['1\n5*a++-3*++a+a++\n', '3\na+++++a\n']
Demo Output:
['11\n', '8\n']
Note:
Consider the second example. Initially *a* = 3. Suppose that at first the first summand is calculated, and then the second one is. The first summand gets equal to 3, and the value of *a* is increased by 1. At the calculation of the second summand *a* is increased once more (gets equal to 5). The value of the second summand is 5, and together they give 8. If we calculate the second summand first and the first summand later, then the both summands equals to 4, and the result is 8, too. | ```python
print("_RANDOM_GUESS_1690503687.6249542")# 1690503687.624974
``` | 0 |
22 | D | Segments | PROGRAMMING | 1,900 | [
"greedy",
"sortings"
] | D. Segments | 1 | 256 | You are given *n* segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down? | The first line of the input contains single integer number *n* (1<=≤<=*n*<=≤<=1000) — amount of segments. Following *n* lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points. | The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any. | [
"2\n0 2\n2 5\n",
"5\n0 3\n4 2\n4 8\n8 10\n7 7\n"
] | [
"1\n2 ",
"3\n7 10 3\n"
] | none | 0 | [
{
"input": "2\n0 2\n2 5",
"output": "1\n2 "
},
{
"input": "5\n0 3\n4 2\n4 8\n8 10\n7 7",
"output": "3\n3 7 10 "
},
{
"input": "3\n40 -83\n52 -80\n-21 -4",
"output": "1\n-4 "
},
{
"input": "4\n67 -88\n37 -62\n-26 91\n-99 -50",
"output": "2\n-50 91 "
},
{
"input": "5\n45 58\n22 6\n-32 36\n49 -37\n43 62",
"output": "2\n22 58 "
},
{
"input": "10\n47 -85\n71 40\n-87 64\n76 73\n52 -51\n-20 -57\n-14 -77\n-45 -11\n-56 -48\n81 20",
"output": "4\n-48 -11 71 76 "
},
{
"input": "35\n-47 61\n-73 -15\n9 43\n43 -49\n13 -6\n48 -65\n49 -84\n-6 76\n40 6\n-41 11\n-63 -42\n-7 -66\n47 -98\n-17 61\n79 99\n47 -98\n61 31\n85 72\n-50 -17\n-67 45\n14 -50\n-45 61\n-6 -96\n-47 -83\n56 -58\n-69 -15\n14 20\n-95 -82\n47 93\n-4 -7\n70 9\n91 -18\n-71 31\n55 -20\n81 -8",
"output": "6\n-82 -42 -4 20 61 85 "
},
{
"input": "1\n0 0",
"output": "1\n0 "
},
{
"input": "4\n1 1\n0 0\n10000 10000\n-10000 -10000",
"output": "4\n-10000 0 1 10000 "
},
{
"input": "3\n55 55\n55 55\n55 55",
"output": "1\n55 "
},
{
"input": "4\n55 55\n55 55\n55 55\n55 56",
"output": "1\n55 "
},
{
"input": "1\n-2244 5023",
"output": "1\n5023 "
}
] | 1,694,957,263 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | arr=[]
n=int(input())
for _ in range(n):
l,r=map(int,input().split())
arr.append([l,r])
arr.sort(key=lambda x:(x[1]))
ans=0
p=-1
for el in arr:
l,r=el[0],el[1]
if l>=p:
ans+=1
p=max(p,r)
print(ans) | Title: Segments
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given *n* segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down?
Input Specification:
The first line of the input contains single integer number *n* (1<=≤<=*n*<=≤<=1000) — amount of segments. Following *n* lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
Output Specification:
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
Demo Input:
['2\n0 2\n2 5\n', '5\n0 3\n4 2\n4 8\n8 10\n7 7\n']
Demo Output:
['1\n2 ', '3\n7 10 3\n']
Note:
none | ```python
arr=[]
n=int(input())
for _ in range(n):
l,r=map(int,input().split())
arr.append([l,r])
arr.sort(key=lambda x:(x[1]))
ans=0
p=-1
for el in arr:
l,r=el[0],el[1]
if l>=p:
ans+=1
p=max(p,r)
print(ans)
``` | 0 |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"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]. | 1,750 | [
{
"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"
}
] | 1,666,877,329 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 327 | 8,601,600 | n = int(input())
a = []
for i in range(n):
a.append([int(i) for i in input().split()])
count = 0
for i in range(1,n-1):
if a[i][1]<a[i][0]-a[i-1][0] or a[i][1]<a[i+1][0]-a[i][0]:
count += 1
print(count+2)
| Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
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.
Input Specification:
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.
Output Specification:
Print a single number — the maximum number of trees that you can cut down by the given rules.
Demo Input:
['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n']
Demo Output:
['3\n', '4\n']
Note:
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]. | ```python
n = int(input())
a = []
for i in range(n):
a.append([int(i) for i in input().split()])
count = 0
for i in range(1,n-1):
if a[i][1]<a[i][0]-a[i-1][0] or a[i][1]<a[i+1][0]-a[i][0]:
count += 1
print(count+2)
``` | 0 |
|
660 | A | Co-prime Array | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers *a* and *b* are said to be co-prime if the only positive integer that divides both of them is 1. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array *a* by adding *k* elements to it.
If there are multiple answers you can print any one of them. | [
"3\n2 7 28\n"
] | [
"1\n2 7 9 28\n"
] | none | 0 | [
{
"input": "3\n2 7 28",
"output": "1\n2 7 1 28"
},
{
"input": "1\n1",
"output": "0\n1"
},
{
"input": "1\n548",
"output": "0\n548"
},
{
"input": "1\n963837006",
"output": "0\n963837006"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0\n1 1 1 1 1 1 1 1 1 1"
},
{
"input": "10\n26 723 970 13 422 968 875 329 234 983",
"output": "2\n26 723 970 13 422 1 968 875 1 329 234 983"
},
{
"input": "10\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396",
"output": "7\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396"
},
{
"input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"output": "19\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1"
},
{
"input": "100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917",
"output": "38\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917"
},
{
"input": "5\n472882027 472882027 472882027 472882027 472882027",
"output": "4\n472882027 1 472882027 1 472882027 1 472882027 1 472882027"
},
{
"input": "2\n1000000000 1000000000",
"output": "1\n1000000000 1 1000000000"
},
{
"input": "2\n8 6",
"output": "1\n8 1 6"
},
{
"input": "3\n100000000 1000000000 1000000000",
"output": "2\n100000000 1 1000000000 1 1000000000"
},
{
"input": "5\n1 2 3 4 5",
"output": "0\n1 2 3 4 5"
},
{
"input": "20\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000",
"output": "19\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000"
},
{
"input": "2\n223092870 23",
"output": "1\n223092870 1 23"
},
{
"input": "2\n100000003 100000003",
"output": "1\n100000003 1 100000003"
},
{
"input": "2\n999999937 999999937",
"output": "1\n999999937 1 999999937"
},
{
"input": "4\n999 999999937 999999937 999",
"output": "1\n999 999999937 1 999999937 999"
},
{
"input": "2\n999999929 999999929",
"output": "1\n999999929 1 999999929"
},
{
"input": "2\n1049459 2098918",
"output": "1\n1049459 1 2098918"
},
{
"input": "2\n352229 704458",
"output": "1\n352229 1 704458"
},
{
"input": "2\n7293 4011",
"output": "1\n7293 1 4011"
},
{
"input": "2\n5565651 3999930",
"output": "1\n5565651 1 3999930"
},
{
"input": "2\n997 997",
"output": "1\n997 1 997"
},
{
"input": "3\n9994223 9994223 9994223",
"output": "2\n9994223 1 9994223 1 9994223"
},
{
"input": "2\n99999998 1000000000",
"output": "1\n99999998 1 1000000000"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "2\n1000000000 1 1000000000 1 1000000000"
},
{
"input": "2\n130471 130471",
"output": "1\n130471 1 130471"
},
{
"input": "3\n1000000000 2 2",
"output": "2\n1000000000 1 2 1 2"
},
{
"input": "2\n223092870 66526",
"output": "1\n223092870 1 66526"
},
{
"input": "14\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449",
"output": "10\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449"
},
{
"input": "2\n3996017 3996017",
"output": "1\n3996017 1 3996017"
},
{
"input": "2\n999983 999983",
"output": "1\n999983 1 999983"
},
{
"input": "2\n618575685 773990454",
"output": "1\n618575685 1 773990454"
},
{
"input": "3\n9699690 3 7",
"output": "1\n9699690 1 3 7"
},
{
"input": "2\n999999999 999999996",
"output": "1\n999999999 1 999999996"
},
{
"input": "2\n99999910 99999910",
"output": "1\n99999910 1 99999910"
},
{
"input": "12\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491",
"output": "9\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491"
},
{
"input": "3\n999999937 999999937 999999937",
"output": "2\n999999937 1 999999937 1 999999937"
},
{
"input": "2\n99839 99839",
"output": "1\n99839 1 99839"
},
{
"input": "3\n19999909 19999909 19999909",
"output": "2\n19999909 1 19999909 1 19999909"
},
{
"input": "4\n1 1000000000 1 1000000000",
"output": "0\n1 1000000000 1 1000000000"
},
{
"input": "2\n64006 64006",
"output": "1\n64006 1 64006"
},
{
"input": "2\n1956955 1956955",
"output": "1\n1956955 1 1956955"
},
{
"input": "3\n1 1000000000 1000000000",
"output": "1\n1 1000000000 1 1000000000"
},
{
"input": "2\n982451707 982451707",
"output": "1\n982451707 1 982451707"
},
{
"input": "2\n999999733 999999733",
"output": "1\n999999733 1 999999733"
},
{
"input": "3\n999999733 999999733 999999733",
"output": "2\n999999733 1 999999733 1 999999733"
},
{
"input": "2\n3257 3257",
"output": "1\n3257 1 3257"
},
{
"input": "2\n223092870 181598",
"output": "1\n223092870 1 181598"
},
{
"input": "3\n959919409 105935 105935",
"output": "2\n959919409 1 105935 1 105935"
},
{
"input": "2\n510510 510510",
"output": "1\n510510 1 510510"
},
{
"input": "3\n223092870 1000000000 1000000000",
"output": "2\n223092870 1 1000000000 1 1000000000"
},
{
"input": "14\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000",
"output": "11\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000"
},
{
"input": "7\n1 982451653 982451653 1 982451653 982451653 982451653",
"output": "3\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653"
},
{
"input": "2\n100000007 100000007",
"output": "1\n100000007 1 100000007"
},
{
"input": "3\n999999757 999999757 999999757",
"output": "2\n999999757 1 999999757 1 999999757"
},
{
"input": "3\n99999989 99999989 99999989",
"output": "2\n99999989 1 99999989 1 99999989"
},
{
"input": "5\n2 4 982451707 982451707 3",
"output": "2\n2 1 4 982451707 1 982451707 3"
},
{
"input": "2\n20000014 20000014",
"output": "1\n20000014 1 20000014"
},
{
"input": "2\n99999989 99999989",
"output": "1\n99999989 1 99999989"
},
{
"input": "2\n111546435 111546435",
"output": "1\n111546435 1 111546435"
},
{
"input": "2\n55288874 33538046",
"output": "1\n55288874 1 33538046"
},
{
"input": "5\n179424673 179424673 179424673 179424673 179424673",
"output": "4\n179424673 1 179424673 1 179424673 1 179424673 1 179424673"
},
{
"input": "2\n199999978 199999978",
"output": "1\n199999978 1 199999978"
},
{
"input": "2\n1000000000 2",
"output": "1\n1000000000 1 2"
},
{
"input": "3\n19999897 19999897 19999897",
"output": "2\n19999897 1 19999897 1 19999897"
},
{
"input": "2\n19999982 19999982",
"output": "1\n19999982 1 19999982"
},
{
"input": "2\n10000007 10000007",
"output": "1\n10000007 1 10000007"
},
{
"input": "3\n999999937 999999937 2",
"output": "1\n999999937 1 999999937 2"
},
{
"input": "5\n2017 2017 2017 2017 2017",
"output": "4\n2017 1 2017 1 2017 1 2017 1 2017"
},
{
"input": "2\n19999909 39999818",
"output": "1\n19999909 1 39999818"
},
{
"input": "2\n62615533 7919",
"output": "1\n62615533 1 7919"
},
{
"input": "5\n39989 39989 33 31 29",
"output": "1\n39989 1 39989 33 31 29"
},
{
"input": "2\n1000000000 100000",
"output": "1\n1000000000 1 100000"
},
{
"input": "2\n1938 10010",
"output": "1\n1938 1 10010"
},
{
"input": "2\n199999 199999",
"output": "1\n199999 1 199999"
},
{
"input": "2\n107273 107273",
"output": "1\n107273 1 107273"
},
{
"input": "3\n49999 49999 49999",
"output": "2\n49999 1 49999 1 49999"
},
{
"input": "2\n1999966 1999958",
"output": "1\n1999966 1 1999958"
},
{
"input": "2\n86020 300846",
"output": "1\n86020 1 300846"
},
{
"input": "2\n999999997 213",
"output": "1\n999999997 1 213"
},
{
"input": "2\n200000014 200000434",
"output": "1\n200000014 1 200000434"
}
] | 1,625,572,872 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 109 | 1,331,200 | from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf, log2, sqrt, log10
from bisect import bisect_right, bisect_left
from statistics import mode
from string import ascii_uppercase
lists = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197}
num = int(input())
arr = list(map(int, input().split()))
cnt = 0
ans = [arr[0]]
for i in range(1, num):
if gcd(arr[i-1], arr[i]) != 1:
cnt += 1
for d in lists:
if gcd(arr[i-1], d) == 1 and gcd(arr[i], d) == 1:
dif = d
break
ans.append(dif)
ans.append(arr[i])
print(cnt)
print(*ans)
| Title: Co-prime Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers *a* and *b* are said to be co-prime if the only positive integer that divides both of them is 1.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
Output Specification:
Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array *a* by adding *k* elements to it.
If there are multiple answers you can print any one of them.
Demo Input:
['3\n2 7 28\n']
Demo Output:
['1\n2 7 9 28\n']
Note:
none | ```python
from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf, log2, sqrt, log10
from bisect import bisect_right, bisect_left
from statistics import mode
from string import ascii_uppercase
lists = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197}
num = int(input())
arr = list(map(int, input().split()))
cnt = 0
ans = [arr[0]]
for i in range(1, num):
if gcd(arr[i-1], arr[i]) != 1:
cnt += 1
for d in lists:
if gcd(arr[i-1], d) == 1 and gcd(arr[i], d) == 1:
dif = d
break
ans.append(dif)
ans.append(arr[i])
print(cnt)
print(*ans)
``` | 3 |
|
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126",
"output": "12"
},
{
"input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850",
"output": "36"
},
{
"input": "2 6 8\n2 1",
"output": "0"
},
{
"input": "5 15 16\n7 11 5 12 8",
"output": "2"
},
{
"input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574",
"output": "4"
},
{
"input": "5 234613 716125\n642626 494941 234613 234613 234613",
"output": "0"
},
{
"input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547",
"output": "0"
},
{
"input": "5 10 20\n10 10 10 10 1",
"output": "1"
},
{
"input": "5 10 11\n10 10 10 10 1",
"output": "2"
},
{
"input": "3 10 10\n4 3 3",
"output": "0"
},
{
"input": "3 5 5\n5 5 5",
"output": "1"
},
{
"input": "3 4 14\n5 5 5",
"output": "0"
},
{
"input": "2 7 10\n1234 1234",
"output": "0"
},
{
"input": "1 5 6\n10",
"output": "0"
},
{
"input": "3 4 6\n1 2 3",
"output": "0"
},
{
"input": "5 10 12\n13 13 13 13 13",
"output": "0"
},
{
"input": "3 4 5\n5 7 9",
"output": "0"
},
{
"input": "3 10 100\n5 5 5",
"output": "0"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "5 5 5\n5 5 5 5 5",
"output": "2"
},
{
"input": "2 2 5\n5 5",
"output": "0"
},
{
"input": "3 1 4\n2 2 2",
"output": "0"
}
] | 1,660,818,603 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 |
juiceValues = input().split()
OrnageCount = int(juiceValues[0])
maxSize = int(juiceValues[1])
whenToEmpty = int(juiceValues[2])
emptyCount =0
currentSize = 0
orangeValues = input().split()
emptyFlag = False
for orange in range(OrnageCount):
if(int(orangeValues[orange]) >= maxSize):
continue
emptyFlag = True
currentSize +=int(orangeValues[orange])
if(currentSize >= whenToEmpty):
emptyCount +=1
currentSize =0
print(emptyCount)
if(emptyFlag == True and currentSize == 0):
emptyCount +=1
print(emptyCount) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
Input Specification:
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output Specification:
Print one integer — the number of times Kolya will have to empty the waste section.
Demo Input:
['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n']
Demo Output:
['1\n', '0\n', '1\n', '0\n']
Note:
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | ```python
juiceValues = input().split()
OrnageCount = int(juiceValues[0])
maxSize = int(juiceValues[1])
whenToEmpty = int(juiceValues[2])
emptyCount =0
currentSize = 0
orangeValues = input().split()
emptyFlag = False
for orange in range(OrnageCount):
if(int(orangeValues[orange]) >= maxSize):
continue
emptyFlag = True
currentSize +=int(orangeValues[orange])
if(currentSize >= whenToEmpty):
emptyCount +=1
currentSize =0
print(emptyCount)
if(emptyFlag == True and currentSize == 0):
emptyCount +=1
print(emptyCount)
``` | 0 |
|
573 | A | Bear and Poker | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 500 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058",
"output": "No"
},
{
"input": "2\n1 1",
"output": "Yes"
},
{
"input": "2\n72 72",
"output": "Yes"
},
{
"input": "2\n49 42",
"output": "No"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "Yes"
},
{
"input": "6\n162000 96000 648000 1000 864000 432000",
"output": "Yes"
},
{
"input": "8\n600000 100000 100000 100000 900000 600000 900000 600000",
"output": "Yes"
},
{
"input": "12\n2048 1024 6144 1024 3072 3072 6144 1024 4096 2048 6144 3072",
"output": "Yes"
},
{
"input": "20\n246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246",
"output": "Yes"
},
{
"input": "50\n840868705 387420489 387420489 795385082 634350497 206851546 536870912 536870912 414927754 387420489 387420489 536870912 387420489 149011306 373106005 536870912 700746206 387420489 777952883 847215247 176645254 576664386 387420489 230876513 536870912 536870912 536870912 387420489 387420489 536870912 460495524 528643722 387420489 536870912 470369206 899619085 387420489 631148352 387420489 387420489 536870912 414666674 521349938 776784669 387420489 102428009 536870912 387420489 536870912 718311009",
"output": "No"
},
{
"input": "2\n5 6",
"output": "No"
},
{
"input": "3\n536870912 387420489 257407169",
"output": "No"
},
{
"input": "4\n2 2 5 2",
"output": "No"
},
{
"input": "2\n33554432 59049",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 387420489",
"output": "Yes"
},
{
"input": "2\n1 5",
"output": "No"
},
{
"input": "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 71",
"output": "No"
},
{
"input": "2\n1 30",
"output": "No"
},
{
"input": "3\n335544320 71744535 71744535",
"output": "Yes"
},
{
"input": "5\n1000000000 999999999 999999998 999999997 999999996",
"output": "No"
},
{
"input": "2\n25 5",
"output": "No"
},
{
"input": "4\n75 150 75 5",
"output": "No"
},
{
"input": "3\n536870912 387420489 362797056",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 89",
"output": "No"
},
{
"input": "4\n547 2606459 222763549 143466789",
"output": "No"
},
{
"input": "3\n129140163 33554432 1",
"output": "Yes"
},
{
"input": "10\n244140625 244140625 244140625 244140625 244140625 244140625 244140625 244140625 536870912 387420489",
"output": "No"
},
{
"input": "3\n5 5 1",
"output": "No"
},
{
"input": "5\n3 7 29 36760123 823996703",
"output": "No"
}
] | 1,654,686,527 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 61 | 1,945,600 | import sys
input = sys.stdin.readline
def gcd(x, y):
while(y):
x, y = y, x % y
return x
# This function computes LCM
def lcm(x, y):
lcm = (x*y)//gcd(x,y)
return lcm
import math as mt
MAXN = 100001
# stores smallest prime factor for
# every number
spf = [0 for i in range(MAXN)]
# Calculating SPF (Smallest Prime Factor)
# for every number till MAXN.
# Time Complexity : O(nloglogn)
def sieve():
spf[1] = 1
for i in range(2, MAXN):
# marking smallest prime factor
# for every number to be itself.
spf[i] = i
# separately marking spf for
# every even number as 2
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, mt.ceil(mt.sqrt(MAXN))):
# checking if i is prime
if (spf[i] == i):
# marking SPF for all numbers
# divisible by i
for j in range(i * i, MAXN, i):
# marking spf[j] if it is
# not previously marked
if (spf[j] == j):
spf[j] = i
# A O(log n) function returning prime
# factorization by dividing by smallest
# prime factor at every step
sieve()
def getFactorization(x):
ret = list()
while (x != 1):
ret.append(spf[x])
x = x // spf[x]
return ret
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
xy=0
for i in a:
ans = lcm(ans,i)
for i in range(n):
if (a[i]==ans):
continue
temp = ans//a[i]
# print(temp)
p = getFactorization(temp)
if ((len(p)==2 and (2 in p) and (3 in p)) or (len(p)==1 and ((2 in p) or (3 in p)))):
continue
else:
print("NO")
# print(a[i])
xy=1
break
if (xy==0):
print("YES") | Title: Bear and Poker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
Input Specification:
First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players.
Output Specification:
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
Demo Input:
['4\n75 150 75 50\n', '3\n100 150 250\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | ```python
import sys
input = sys.stdin.readline
def gcd(x, y):
while(y):
x, y = y, x % y
return x
# This function computes LCM
def lcm(x, y):
lcm = (x*y)//gcd(x,y)
return lcm
import math as mt
MAXN = 100001
# stores smallest prime factor for
# every number
spf = [0 for i in range(MAXN)]
# Calculating SPF (Smallest Prime Factor)
# for every number till MAXN.
# Time Complexity : O(nloglogn)
def sieve():
spf[1] = 1
for i in range(2, MAXN):
# marking smallest prime factor
# for every number to be itself.
spf[i] = i
# separately marking spf for
# every even number as 2
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, mt.ceil(mt.sqrt(MAXN))):
# checking if i is prime
if (spf[i] == i):
# marking SPF for all numbers
# divisible by i
for j in range(i * i, MAXN, i):
# marking spf[j] if it is
# not previously marked
if (spf[j] == j):
spf[j] = i
# A O(log n) function returning prime
# factorization by dividing by smallest
# prime factor at every step
sieve()
def getFactorization(x):
ret = list()
while (x != 1):
ret.append(spf[x])
x = x // spf[x]
return ret
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
xy=0
for i in a:
ans = lcm(ans,i)
for i in range(n):
if (a[i]==ans):
continue
temp = ans//a[i]
# print(temp)
p = getFactorization(temp)
if ((len(p)==2 and (2 in p) and (3 in p)) or (len(p)==1 and ((2 in p) or (3 in p)))):
continue
else:
print("NO")
# print(a[i])
xy=1
break
if (xy==0):
print("YES")
``` | -1 |
|
629 | C | Famil Door and Brackets | PROGRAMMING | 2,000 | [
"dp",
"strings"
] | null | null | As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length *n* more than any other strings!
The sequence of round brackets is called valid if and only if:
1. the total number of opening brackets is equal to the total number of closing brackets; 1. for any prefix of the sequence, the number of opening brackets is greater or equal than the number of closing brackets.
Gabi bought a string *s* of length *m* (*m*<=≤<=*n*) and want to complete it to obtain a valid sequence of brackets of length *n*. He is going to pick some strings *p* and *q* consisting of round brackets and merge them in a string *p*<=+<=*s*<=+<=*q*, that is add the string *p* at the beginning of the string *s* and string *q* at the end of the string *s*.
Now he wonders, how many pairs of strings *p* and *q* exists, such that the string *p*<=+<=*s*<=+<=*q* is a valid sequence of round brackets. As this number may be pretty large, he wants to calculate it modulo 109<=+<=7. | First line contains *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100<=000,<=*n*<=-<=*m*<=≤<=2000) — the desired length of the string and the length of the string bought by Gabi, respectively.
The second line contains string *s* of length *m* consisting of characters '(' and ')' only. | Print the number of pairs of string *p* and *q* such that *p*<=+<=*s*<=+<=*q* is a valid sequence of round brackets modulo 109<=+<=7. | [
"4 1\n(\n",
"4 4\n(())\n",
"4 3\n(((\n"
] | [
"4\n",
"1\n",
"0\n"
] | In the first sample there are four different valid pairs:
1. *p* = "(", *q* = "))" 1. *p* = "()", *q* = ")" 1. *p* = "", *q* = "())" 1. *p* = "", *q* = ")()"
In the second sample the only way to obtain a desired string is choose empty *p* and *q*.
In the third sample there is no way to get a valid sequence of brackets. | 1,750 | [
{
"input": "4 1\n(",
"output": "4"
},
{
"input": "4 4\n(())",
"output": "1"
},
{
"input": "4 3\n(((",
"output": "0"
},
{
"input": "875 50\n)))((())()))((()(())))))())))((((((()))))))()(((((",
"output": "0"
},
{
"input": "1980 464\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))(()))))))(())((())))()())()((())())()())))(())()(()))(()())()((((()))())()(())))))(()()(()(((((()(()()))(((()))(())))))()())(())))))())()()((())))))))((()(())))))()()(()((()((()()))(()))(())(()))()((((())()()))))))()(())))()(()())()())(((((()))())))())())(()))()(()))())((())((((()(()(())))(((()()))))()()()))))((()())()((())())))())))()(()(()()(((((()((((()))()(())()))))()(()))(()(((((((()((()(())))(((((())",
"output": "854368836"
},
{
"input": "1542 282\n())())()((()(()))()((())()))((())(()))))(()()))(())((()))()((()())())()))((())(((()(())((()()())((((())))((()((((()(()()))))(()(()()(())()((())())())))))()()())))(()((((()))(()(()(()(()))())((()()()()(()(()))())(((()(())()(())()()())))()))())(()))(((())()))((())()(())))))(())))()()",
"output": "631927032"
},
{
"input": "2 2\n)(",
"output": "0"
},
{
"input": "2 2\n))",
"output": "0"
}
] | 1,455,993,234 | 7,134 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 |
def makeValid(s):
l=0
r=0
left=""
right=""
ans=len(s)
for i in s:
if i==')':
l+=1
else:
r+=1
if r>l:
ans+=1
r-=1
ans=ans+l
return ans
def comb(n):
mod=1000000007
if n%2==1:
n-=1
if n==0:
return 0
if n==2:
return 1
n=n/2
k=n-1
arr=[k,k+1]
for i in range(2):
if arr[i]%2==0:
arr[i]=arr[i]/2
p=((arr[0]%mod)*(arr[1]%mod)%mod+1%mod)%mod
return p*2
inf=list(map(int,input().split()))
n=inf[0]
s=input()
val=makeValid(s)
print(val)
if val>n:
print(0)
elif val==n:
print(1)
else:
print(int(comb(n-val)*2))
| Title: Famil Door and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length *n* more than any other strings!
The sequence of round brackets is called valid if and only if:
1. the total number of opening brackets is equal to the total number of closing brackets; 1. for any prefix of the sequence, the number of opening brackets is greater or equal than the number of closing brackets.
Gabi bought a string *s* of length *m* (*m*<=≤<=*n*) and want to complete it to obtain a valid sequence of brackets of length *n*. He is going to pick some strings *p* and *q* consisting of round brackets and merge them in a string *p*<=+<=*s*<=+<=*q*, that is add the string *p* at the beginning of the string *s* and string *q* at the end of the string *s*.
Now he wonders, how many pairs of strings *p* and *q* exists, such that the string *p*<=+<=*s*<=+<=*q* is a valid sequence of round brackets. As this number may be pretty large, he wants to calculate it modulo 109<=+<=7.
Input Specification:
First line contains *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100<=000,<=*n*<=-<=*m*<=≤<=2000) — the desired length of the string and the length of the string bought by Gabi, respectively.
The second line contains string *s* of length *m* consisting of characters '(' and ')' only.
Output Specification:
Print the number of pairs of string *p* and *q* such that *p*<=+<=*s*<=+<=*q* is a valid sequence of round brackets modulo 109<=+<=7.
Demo Input:
['4 1\n(\n', '4 4\n(())\n', '4 3\n(((\n']
Demo Output:
['4\n', '1\n', '0\n']
Note:
In the first sample there are four different valid pairs:
1. *p* = "(", *q* = "))" 1. *p* = "()", *q* = ")" 1. *p* = "", *q* = "())" 1. *p* = "", *q* = ")()"
In the second sample the only way to obtain a desired string is choose empty *p* and *q*.
In the third sample there is no way to get a valid sequence of brackets. | ```python
def makeValid(s):
l=0
r=0
left=""
right=""
ans=len(s)
for i in s:
if i==')':
l+=1
else:
r+=1
if r>l:
ans+=1
r-=1
ans=ans+l
return ans
def comb(n):
mod=1000000007
if n%2==1:
n-=1
if n==0:
return 0
if n==2:
return 1
n=n/2
k=n-1
arr=[k,k+1]
for i in range(2):
if arr[i]%2==0:
arr[i]=arr[i]/2
p=((arr[0]%mod)*(arr[1]%mod)%mod+1%mod)%mod
return p*2
inf=list(map(int,input().split()))
n=inf[0]
s=input()
val=makeValid(s)
print(val)
if val>n:
print(0)
elif val==n:
print(1)
else:
print(int(comb(n-val)*2))
``` | 0 |
|
828 | B | Black Square | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet.
The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | [
"5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n",
"1 2\nBB\n",
"3 3\nWWW\nWWW\nWWW\n"
] | [
"5\n",
"-1\n",
"1\n"
] | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | 750 | [
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW",
"output": "5"
},
{
"input": "1 2\nBB",
"output": "-1"
},
{
"input": "3 3\nWWW\nWWW\nWWW",
"output": "1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB",
"output": "-1"
},
{
"input": "1 1\nW",
"output": "1"
},
{
"input": "2 4\nWWWW\nWBWW",
"output": "0"
},
{
"input": "4 5\nWWWWW\nBBWWW\nBBWWW\nWWWWW",
"output": "0"
},
{
"input": "5 4\nWWWW\nWWWW\nWWWB\nWWWW\nWWWW",
"output": "0"
},
{
"input": "10 5\nWWWWB\nWWWWW\nWWWBB\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW",
"output": "12"
},
{
"input": "5 10\nWWWWWWWWWW\nWWWWBWBBWW\nWWWWWWWWWW\nWWWWBWWWWW\nWWWWWWBWWW",
"output": "11"
},
{
"input": "20 10\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWBBWBWWWW\nWWBWWBWWWW\nWWWWBWWWWW\nWWWWBWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW",
"output": "9"
},
{
"input": "10 20\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWBW\nWWWWWWWWWWWWWWWWWBWW\nWWWWWWWWWWWWWWWWWWWW",
"output": "2"
},
{
"input": "1 1\nW",
"output": "1"
},
{
"input": "1 1\nB",
"output": "0"
},
{
"input": "2 2\nWW\nWW",
"output": "1"
},
{
"input": "2 2\nWW\nWB",
"output": "0"
},
{
"input": "2 2\nWW\nBW",
"output": "0"
},
{
"input": "2 2\nWW\nBB",
"output": "2"
},
{
"input": "2 2\nWB\nWW",
"output": "0"
},
{
"input": "2 2\nWB\nWB",
"output": "2"
},
{
"input": "2 2\nWB\nBW",
"output": "2"
},
{
"input": "2 2\nWB\nBB",
"output": "1"
},
{
"input": "2 2\nBW\nWW",
"output": "0"
},
{
"input": "2 2\nBW\nWB",
"output": "2"
},
{
"input": "2 2\nBW\nBW",
"output": "2"
},
{
"input": "2 2\nBW\nBB",
"output": "1"
},
{
"input": "2 2\nBB\nWW",
"output": "2"
},
{
"input": "2 2\nBB\nWB",
"output": "1"
},
{
"input": "2 2\nBB\nBW",
"output": "1"
},
{
"input": "2 2\nBB\nBB",
"output": "0"
},
{
"input": "1 2\nWW",
"output": "1"
},
{
"input": "1 2\nWB",
"output": "0"
},
{
"input": "1 2\nBW",
"output": "0"
},
{
"input": "2 1\nW\nW",
"output": "1"
},
{
"input": "2 1\nW\nB",
"output": "0"
},
{
"input": "2 1\nB\nW",
"output": "0"
},
{
"input": "2 1\nB\nB",
"output": "-1"
},
{
"input": "20 10\nWWBWWWBBWW\nWWWWWBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWBBBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWBWWWWWBWW\nWBWWBWWWBW\nWWBWBWWWWW\nWWWBWWBBWW\nWWBBWBWBWW\nBBWWWWWBWW\nWWBWWBBBWW\nWWWBWBBWWW\nWWWBBWBWWW\nWWWWWWWWWW\nWWWBWWWWWW\nWWWWWWWWWW",
"output": "-1"
},
{
"input": "10 20\nWWWWWWWBWWWWWWWBWWWB\nWWWBWWWBWWWWWWWWWWWW\nBWWWWWWWWWWWWWWWWWBB\nWWWWWWBWWBWWBWWWBWWW\nWWWWWWWWBWWBWWWBWWWW\nWBWWWWWWWBWWWWWWWWWW\nWWWBWBWWBWWWWWBBWWWB\nWWBBWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWBWWWWBW\nWWWWWWWWWWWWBWWBWWWB",
"output": "-1"
},
{
"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB",
"output": "0"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "-1"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB",
"output": "-1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB",
"output": "0"
},
{
"input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW",
"output": "0"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW",
"output": "0"
},
{
"input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW",
"output": "-1"
},
{
"input": "1 5\nWBBWW",
"output": "-1"
},
{
"input": "20 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nB\nB",
"output": "-1"
},
{
"input": "3 3\nWBW\nWBB\nWWW",
"output": "1"
},
{
"input": "4 6\nWWWWWW\nWWWBWW\nWWWWWB\nWWWWWW",
"output": "7"
},
{
"input": "5 5\nWBWBW\nWWWWW\nWWWWW\nWWWWW\nWWWWW",
"output": "7"
},
{
"input": "3 3\nBBB\nBBB\nBBB",
"output": "0"
},
{
"input": "5 5\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWBWW",
"output": "23"
},
{
"input": "5 4\nWWBW\nBWWB\nWWWW\nWWWW\nWWWW",
"output": "13"
},
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWWW\nWBBW",
"output": "12"
},
{
"input": "6 6\nWWBWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWBWW",
"output": "34"
},
{
"input": "3 3\nBBW\nWWW\nBWW",
"output": "6"
},
{
"input": "3 3\nBWB\nWWW\nBWW",
"output": "6"
},
{
"input": "6 6\nWBWWWW\nBWWWBW\nWWWWWW\nWWBWWW\nWWWWWW\nWWWWWW",
"output": "21"
},
{
"input": "3 3\nWWW\nWBW\nWWW",
"output": "0"
},
{
"input": "3 3\nBBB\nWWW\nWWW",
"output": "6"
},
{
"input": "5 5\nWWBWW\nWWBWW\nWBBBW\nWWBWW\nWWBWW",
"output": "18"
},
{
"input": "5 2\nWB\nWB\nWB\nWW\nWW",
"output": "-1"
},
{
"input": "4 7\nBBBBBWW\nWWWWWWW\nWWWWWWW\nWWWWWWW",
"output": "-1"
},
{
"input": "5 4\nWWWW\nWWWB\nWWWW\nWWBB\nWWWW",
"output": "6"
},
{
"input": "4 4\nWWWW\nWBWW\nWWWW\nWWWW",
"output": "0"
},
{
"input": "2 5\nWWWWW\nBBBWW",
"output": "-1"
},
{
"input": "6 6\nWWBWWW\nWWWWWW\nWWWWBW\nWWWWWW\nWWWWWW\nWWBWWW",
"output": "33"
},
{
"input": "3 3\nWBW\nWBW\nWBW",
"output": "6"
},
{
"input": "3 5\nWWBBB\nBWBBB\nWWBBB",
"output": "-1"
},
{
"input": "5 5\nWWWWB\nBWWWW\nWWWWB\nWWWWW\nWWWWW",
"output": "22"
},
{
"input": "5 5\nBWWWB\nWWWWW\nWWWWW\nWWWWW\nBWWWW",
"output": "22"
},
{
"input": "4 5\nWWWWW\nBWWWW\nBBBWW\nWWWWW",
"output": "5"
},
{
"input": "4 4\nBBBB\nWWWW\nWWWW\nWWWW",
"output": "12"
},
{
"input": "4 6\nWWWWWW\nBWWWWW\nBWWWWW\nBBBBBB",
"output": "-1"
},
{
"input": "3 6\nWWWWWW\nBBBWWW\nWWWWWW",
"output": "6"
},
{
"input": "5 2\nWW\nBW\nBW\nBB\nWW",
"output": "-1"
},
{
"input": "5 5\nWWWWW\nWWWWW\nBBBBB\nWWWWW\nWWWWW",
"output": "20"
},
{
"input": "5 5\nWWWWW\nWWWWW\nWWWWB\nWBWWW\nWWWWW",
"output": "14"
},
{
"input": "1 5\nWWBWW",
"output": "0"
},
{
"input": "1 3\nBBB",
"output": "-1"
},
{
"input": "2 4\nWWBW\nBWBW",
"output": "-1"
},
{
"input": "6 6\nBBBBBB\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW",
"output": "30"
},
{
"input": "4 4\nWWWW\nWWWW\nWWWW\nWWWW",
"output": "1"
},
{
"input": "3 3\nWWW\nWWW\nWWB",
"output": "0"
},
{
"input": "5 1\nB\nB\nW\nW\nW",
"output": "-1"
},
{
"input": "2 3\nWBW\nWBW",
"output": "2"
},
{
"input": "5 2\nWW\nWB\nWB\nWB\nWW",
"output": "-1"
},
{
"input": "5 5\nWWWWW\nBWWWW\nWWWWB\nWWWWW\nWWWWW",
"output": "23"
}
] | 1,500,319,402 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 | n,m=map(int,input().split())
minR,minC=n,m
maxR=maxC=0
cnt=0
for i in range(0,n):
s=input()
for j in range(0,m):
if s[j]=='B':
minR=min(minR,i)
minC=min(minC,j)
maxR=max(maxR,i)
maxC=max(maxC,j)
cnt+=1
#print('minR='+str(minR))
#print('minC='+str(minC))
#print('maxR='+str(maxR))
#print('maxC='+str(maxC))
if maxC-minC+1>n or maxR-minR+1>m:
print(-1)
else:
t=max(maxR-minR,maxC-minC)+1
print(t*t-cnt) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet.
The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output Specification:
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Demo Input:
['5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n', '1 2\nBB\n', '3 3\nWWW\nWWW\nWWW\n']
Demo Output:
['5\n', '-1\n', '1\n']
Note:
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | ```python
n,m=map(int,input().split())
minR,minC=n,m
maxR=maxC=0
cnt=0
for i in range(0,n):
s=input()
for j in range(0,m):
if s[j]=='B':
minR=min(minR,i)
minC=min(minC,j)
maxR=max(maxR,i)
maxC=max(maxC,j)
cnt+=1
#print('minR='+str(minR))
#print('minC='+str(minC))
#print('maxR='+str(maxR))
#print('maxC='+str(maxC))
if maxC-minC+1>n or maxR-minR+1>m:
print(-1)
else:
t=max(maxR-minR,maxC-minC)+1
print(t*t-cnt)
``` | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.