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
753
A
Santa Claus and Candies
PROGRAMMING
1,000
[ "dp", "greedy", "math" ]
null
null
Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has.
The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has.
Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them.
[ "5\n", "9\n", "2\n" ]
[ "2\n2 3\n", "3\n3 5 1\n", "1\n2 \n" ]
none
500
[ { "input": "5", "output": "2\n1 4 " }, { "input": "9", "output": "3\n1 2 6 " }, { "input": "2", "output": "1\n2 " }, { "input": "1", "output": "1\n1 " }, { "input": "3", "output": "2\n1 2 " }, { "input": "1000", "output": "44\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 54 " }, { "input": "4", "output": "2\n1 3 " }, { "input": "6", "output": "3\n1 2 3 " }, { "input": "7", "output": "3\n1 2 4 " }, { "input": "8", "output": "3\n1 2 5 " }, { "input": "10", "output": "4\n1 2 3 4 " }, { "input": "11", "output": "4\n1 2 3 5 " }, { "input": "12", "output": "4\n1 2 3 6 " }, { "input": "13", "output": "4\n1 2 3 7 " }, { "input": "14", "output": "4\n1 2 3 8 " }, { "input": "15", "output": "5\n1 2 3 4 5 " }, { "input": "16", "output": "5\n1 2 3 4 6 " }, { "input": "20", "output": "5\n1 2 3 4 10 " }, { "input": "21", "output": "6\n1 2 3 4 5 6 " }, { "input": "22", "output": "6\n1 2 3 4 5 7 " }, { "input": "27", "output": "6\n1 2 3 4 5 12 " }, { "input": "28", "output": "7\n1 2 3 4 5 6 7 " }, { "input": "29", "output": "7\n1 2 3 4 5 6 8 " }, { "input": "35", "output": "7\n1 2 3 4 5 6 14 " }, { "input": "36", "output": "8\n1 2 3 4 5 6 7 8 " }, { "input": "37", "output": "8\n1 2 3 4 5 6 7 9 " }, { "input": "44", "output": "8\n1 2 3 4 5 6 7 16 " }, { "input": "45", "output": "9\n1 2 3 4 5 6 7 8 9 " }, { "input": "46", "output": "9\n1 2 3 4 5 6 7 8 10 " }, { "input": "230", "output": "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 40 " }, { "input": "231", "output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 " }, { "input": "232", "output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 " }, { "input": "239", "output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 29 " }, { "input": "629", "output": "34\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 68 " }, { "input": "630", "output": "35\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 " }, { "input": "631", "output": "35\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 36 " }, { "input": "945", "output": "42\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 84 " }, { "input": "946", "output": "43\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 " }, { "input": "947", "output": "43\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 44 " }, { "input": "989", "output": "43\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 86 " }, { "input": "990", "output": "44\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 " }, { "input": "991", "output": "44\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 45 " }, { "input": "956", "output": "43\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 53 " }, { "input": "981", "output": "43\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 78 " }, { "input": "867", "output": "41\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 47 " }, { "input": "906", "output": "42\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 45 " }, { "input": "999", "output": "44\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 53 " }, { "input": "100", "output": "13\n1 2 3 4 5 6 7 8 9 10 11 12 22 " }, { "input": "126", "output": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 21 " } ]
1,680,016,483
2,147,483,647
PyPy 3-64
OK
TESTS
49
62
0
def sol(n): k = int( (2*n + 0.25)**0.5 - 0.5) t = k * (k+1) // 2 if n == t: print(k) print(" ".join(str(x+1) for x in range(k))) else: print(k) t = k * (k-1) // 2 res = [str(x+1) for x in range(k-1)] res.append(str(n-t)) print(" ".join(res)) n = int(input()) sol(n)
Title: Santa Claus and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. Input Specification: The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. Output Specification: Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them. Demo Input: ['5\n', '9\n', '2\n'] Demo Output: ['2\n2 3\n', '3\n3 5 1\n', '1\n2 \n'] Note: none
```python def sol(n): k = int( (2*n + 0.25)**0.5 - 0.5) t = k * (k+1) // 2 if n == t: print(k) print(" ".join(str(x+1) for x in range(k))) else: print(k) t = k * (k-1) // 2 res = [str(x+1) for x in range(k-1)] res.append(str(n-t)) print(" ".join(res)) n = int(input()) sol(n) ```
3
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,647,738
2,147,483,647
Python 3
OK
TESTS
43
124
0
n,m=map(int,input().split()) l=[0] * n for i in range(m): a,b=map(int,input().split()) l[a-1]=1;l[b-1]=1 v=l.index(0)+1 print(n-1) for i in range(1,n+1) : if i!=v : print(v,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 n,m=map(int,input().split()) l=[0] * n for i in range(m): a,b=map(int,input().split()) l[a-1]=1;l[b-1]=1 v=l.index(0)+1 print(n-1) for i in range(1,n+1) : if i!=v : print(v,i) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,672,258,672
2,147,483,647
PyPy 3-64
OK
TESTS
30
124
0
str1 = str(input()) count_1 = count_2 = 0 for i in range (len(str1)): if ord(str1[i]) < ord('a'): count_1 += 1 else: count_2 += 1 if (count_1 <= count_2): str1 = str1.lower() else: str1 = str1.upper() print(str1)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python str1 = str(input()) count_1 = count_2 = 0 for i in range (len(str1)): if ord(str1[i]) < ord('a'): count_1 += 1 else: count_2 += 1 if (count_1 <= count_2): str1 = str1.lower() else: str1 = str1.upper() print(str1) ```
3.969
876
B
Divisiblity of Differences
PROGRAMMING
1,300
[ "implementation", "math", "number theory" ]
null
null
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the numbers in the multiset.
If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them.
[ "3 2 3\n1 8 4\n", "3 3 3\n1 8 4\n", "4 3 5\n2 7 7 7\n" ]
[ "Yes\n1 4 ", "No", "Yes\n2 7 7 " ]
none
1,000
[ { "input": "3 2 3\n1 8 4", "output": "Yes\n1 4 " }, { "input": "3 3 3\n1 8 4", "output": "No" }, { "input": "4 3 5\n2 7 7 7", "output": "Yes\n2 7 7 " }, { "input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825", "output": "Yes\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825 " }, { "input": "15 8 10\n216175135 15241965 611723934 987180005 151601897 403701727 533996295 207637446 875331635 46172555 604086315 350146655 401084142 156540458 982110455", "output": "Yes\n216175135 15241965 987180005 533996295 875331635 46172555 604086315 350146655 " }, { "input": "2 2 100000\n0 1", "output": "No" }, { "input": "101 25 64\n451 230 14 53 7 520 709 102 678 358 166 870 807 230 230 279 166 230 765 176 742 358 924 976 647 806 870 473 976 994 750 146 802 224 503 801 105 614 882 203 390 338 29 587 214 213 405 806 102 102 621 358 521 742 678 205 309 871 796 326 162 693 268 486 68 627 304 829 806 623 748 934 714 672 712 614 587 589 846 260 593 85 839 257 711 395 336 358 472 133 324 527 599 5 845 920 989 494 358 70 882", "output": "Yes\n230 102 678 358 166 870 230 230 166 230 742 358 806 870 614 806 102 102 358 742 678 486 806 934 614 " }, { "input": "108 29 72\n738 619 711 235 288 288 679 36 785 233 706 71 216 144 216 781 338 583 495 648 144 432 72 720 541 288 158 328 154 202 10 533 635 176 707 216 314 397 440 142 326 458 568 701 745 144 61 634 520 720 744 144 409 127 526 476 101 469 72 432 738 432 235 641 695 276 144 144 231 555 630 9 109 319 437 288 288 317 453 432 601 0 449 576 743 352 333 504 504 369 228 288 381 142 500 72 297 359 230 773 216 576 144 244 437 772 483 51", "output": "Yes\n288 288 216 144 216 648 144 432 72 720 288 216 144 720 144 72 432 432 144 144 288 288 432 0 576 504 504 288 72 " }, { "input": "8 2 6\n750462183 165947982 770714338 368445737 363145692 966611485 376672869 678687947", "output": "Yes\n165947982 363145692 " }, { "input": "12 2 1\n512497388 499105388 575265677 864726520 678272195 667107176 809432109 439696443 770034376 873126825 690514828 541499950", "output": "Yes\n512497388 499105388 " }, { "input": "9 3 1\n506004039 471451660 614118177 518013571 43210072 454727076 285905913 543002174 298515615", "output": "Yes\n506004039 471451660 614118177 " }, { "input": "8 4 6\n344417267 377591123 938158786 682031413 804153975 89006697 275945670 735510539", "output": "No" }, { "input": "8 8 1\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253", "output": "Yes\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253 " }, { "input": "7 7 1\n0 0 0 0 0 0 0", "output": "Yes\n0 0 0 0 0 0 0 " }, { "input": "11 4 3\n0 1 0 1 1 0 0 0 0 0 0", "output": "Yes\n0 0 0 0 " }, { "input": "13 4 4\n1 1 0 3 2 4 1 0 3 4 2 4 3", "output": "Yes\n0 4 0 4 " }, { "input": "5 5 1\n6 4 6 0 4", "output": "Yes\n6 4 6 0 4 " }, { "input": "3 2 3\n1 2 3", "output": "No" }, { "input": "6 3 4\n5 9 10 6 7 8", "output": "No" }, { "input": "4 4 3\n4 7 2 5", "output": "No" }, { "input": "4 2 6\n5 5 5 5", "output": "Yes\n5 5 " }, { "input": "4 3 3\n5 1 4 7", "output": "Yes\n1 4 7 " }, { "input": "4 3 10\n0 1 11 11", "output": "Yes\n1 11 11 " }, { "input": "5 2 4\n1 2 2 2 2", "output": "Yes\n2 2 " }, { "input": "5 5 9\n8 17 26 35 44", "output": "Yes\n8 17 26 35 44 " }, { "input": "3 2 2\n1 2 4", "output": "Yes\n2 4 " }, { "input": "5 4 2\n1 3 6 10 12", "output": "No" }, { "input": "3 2 4\n1 2 3", "output": "No" }, { "input": "8 3 5\n1 2 3 4 1 2 3 4", "output": "No" }, { "input": "5 2 9\n8 8 8 8 8", "output": "Yes\n8 8 " }, { "input": "3 3 3\n1 3 6", "output": "No" }, { "input": "5 2 10\n4 5 6 19 29", "output": "Yes\n19 29 " }, { "input": "5 3 3\n3 6 4 7 10", "output": "Yes\n4 7 10 " } ]
1,508,311,753
2,147,483,647
Python 3
OK
TESTS
63
421
14,438,400
n, k, m = list(map(int, input().split(' '))) arr = list(map(int, input().split(' '))) modN = [[] for i in range(100001)] for i in arr: modN[i % m].append(i) for o in modN: if len(o) >= k: print('Yes') for i in range(k): print(o[i]) exit(0) print('No')
Title: Divisiblity of Differences Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input Specification: First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the numbers in the multiset. Output Specification: If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them. Demo Input: ['3 2 3\n1 8 4\n', '3 3 3\n1 8 4\n', '4 3 5\n2 7 7 7\n'] Demo Output: ['Yes\n1 4 ', 'No', 'Yes\n2 7 7 '] Note: none
```python n, k, m = list(map(int, input().split(' '))) arr = list(map(int, input().split(' '))) modN = [[] for i in range(100001)] for i in arr: modN[i % m].append(i) for o in modN: if len(o) >= k: print('Yes') for i in range(k): print(o[i]) exit(0) print('No') ```
3
25
B
Phone numbers
PROGRAMMING
1,100
[ "implementation" ]
B. Phone numbers
2
256
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups.
Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.
[ "6\n549871\n", "7\n1198733\n" ]
[ "54-98-71", "11-987-33\n" ]
none
0
[ { "input": "6\n549871", "output": "54-98-71" }, { "input": "7\n1198733", "output": "119-87-33" }, { "input": "2\n74", "output": "74" }, { "input": "2\n33", "output": "33" }, { "input": "3\n074", "output": "074" }, { "input": "3\n081", "output": "081" }, { "input": "4\n3811", "output": "38-11" }, { "input": "5\n21583", "output": "215-83" }, { "input": "8\n33408349", "output": "33-40-83-49" }, { "input": "9\n988808426", "output": "988-80-84-26" }, { "input": "10\n0180990956", "output": "01-80-99-09-56" }, { "input": "15\n433488906230138", "output": "433-48-89-06-23-01-38" }, { "input": "22\n7135498415686025907059", "output": "71-35-49-84-15-68-60-25-90-70-59" }, { "input": "49\n2429965524999668169991253653390090510755018570235", "output": "242-99-65-52-49-99-66-81-69-99-12-53-65-33-90-09-05-10-75-50-18-57-02-35" }, { "input": "72\n491925337784111770500147619881727525570039735507439360627744863794794290", "output": "49-19-25-33-77-84-11-17-70-50-01-47-61-98-81-72-75-25-57-00-39-73-55-07-43-93-60-62-77-44-86-37-94-79-42-90" }, { "input": "95\n32543414456047900690980198395035321172843693417425457554204776648220562494524275489599199209210", "output": "325-43-41-44-56-04-79-00-69-09-80-19-83-95-03-53-21-17-28-43-69-34-17-42-54-57-55-42-04-77-66-48-22-05-62-49-45-24-27-54-89-59-91-99-20-92-10" }, { "input": "97\n9362344595153688016434451101547661156123505108492010669557671355055642365998461003851354321478898", "output": "936-23-44-59-51-53-68-80-16-43-44-51-10-15-47-66-11-56-12-35-05-10-84-92-01-06-69-55-76-71-35-50-55-64-23-65-99-84-61-00-38-51-35-43-21-47-88-98" }, { "input": "98\n65521815795893886057122984634320900545031770769333931308009346017867969790810907868670369236928568", "output": "65-52-18-15-79-58-93-88-60-57-12-29-84-63-43-20-90-05-45-03-17-70-76-93-33-93-13-08-00-93-46-01-78-67-96-97-90-81-09-07-86-86-70-36-92-36-92-85-68" }, { "input": "99\n455213856470326729480192345541970106407563996625458559297407682539801838244443866898560852503660390", "output": "455-21-38-56-47-03-26-72-94-80-19-23-45-54-19-70-10-64-07-56-39-96-62-54-58-55-92-97-40-76-82-53-98-01-83-82-44-44-38-66-89-85-60-85-25-03-66-03-90" }, { "input": "100\n4004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224", "output": "40-04-22-31-24-94-27-30-64-02-35-38-32-44-43-82-57-61-45-81-53-43-20-35-60-60-98-72-41-65-97-84-24-95-51-11-01-65-03-47-19-44-33-27-65-95-10-64-42-24" } ]
1,481,565,527
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
cantidad = int(raw_input()) array = raw_input() out = "" if cantidad%2 == 1: out += array[0]+ array[1]+ array[2] for i in range (3, cantidad, 2): out+="-"+array[i]+array[i+1] else: out += array[0]+ array[1] for i in range (2, cantidad, 2): out+="-"+array[i]+array[i+1] print(out)
Title: Phone numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. Output Specification: Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. Demo Input: ['6\n549871\n', '7\n1198733\n'] Demo Output: ['54-98-71', '11-987-33\n'] Note: none
```python cantidad = int(raw_input()) array = raw_input() out = "" if cantidad%2 == 1: out += array[0]+ array[1]+ array[2] for i in range (3, cantidad, 2): out+="-"+array[i]+array[i+1] else: out += array[0]+ array[1] for i in range (2, cantidad, 2): out+="-"+array[i]+array[i+1] print(out) ```
-1
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,546,431,188
2,147,483,647
Python 3
OK
TESTS
81
248
0
n=int(input());s=input().split();x=int(s[0]);y=int(s[1]);z=int(s[2]) for i in range(1,n): s=input().split() if int(s[0])<0: x-=abs(int(s[0])) else: x+=abs(int(s[0])) if int(s[1])<0: y-=abs(int(s[1])) else: y+=abs(int(s[1])) if int(s[2])<0: z-=abs(int(s[2])) else: z+=abs(int(s[2])) if x==0 and y==0 and z==0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n=int(input());s=input().split();x=int(s[0]);y=int(s[1]);z=int(s[2]) for i in range(1,n): s=input().split() if int(s[0])<0: x-=abs(int(s[0])) else: x+=abs(int(s[0])) if int(s[1])<0: y-=abs(int(s[1])) else: y+=abs(int(s[1])) if int(s[2])<0: z-=abs(int(s[2])) else: z+=abs(int(s[2])) if x==0 and y==0 and z==0: print('YES') else: print('NO') ```
3.938
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,586,589,669
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
248
0
y,w=map(int,input().split()) n=abs(7 - max(y,w)) z=6/n print("{}/{}".format(1,z))
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()) n=abs(7 - max(y,w)) z=6/n print("{}/{}".format(1,z)) ```
0
0
none
none
none
0
[ "none" ]
null
null
You are given a tree (a graph with *n* vertices and *n*<=-<=1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or determine that it is impossible.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — number of vertices in a tree. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=*n*). If *p**i*<=≠<=0 there is an edge between vertices *i* and *p**i*. It is guaranteed that the given graph is a tree.
If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next *n* lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.
[ "5\n0 1 2 1 2\n", "4\n0 1 2 3\n" ]
[ "YES\n1\n2\n3\n5\n4\n", "NO\n" ]
In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
0
[]
1,523,986,979
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
92
7,168,000
n=int(input()) d={} def add(x,y): if x in d: d[x].append(y) else: d[x]=[y] if y in d: d[y].append(x) else: d[y]=[x] ns=[int(x) for x in input().split()] for i in range(n): if ns[i]==0: continue x=i+1 y=ns[i] add(x,y) add(0,1) d2={} def d2add(x,y): if x in d2: d2[x].append(y) else: d2[x]=[y] start=[] done = [False] * (n + 1) def post(i,f): if len(d[i])==1: ans=1 else: need=0 for x in d[i]: if x==f: continue need+=post(x,i) ans = 1 - need%2 if ans==1: d2add(f, i) else: start.append(i) done[i]=True d2add(i, f) return ans def order(): global start,done if done[1]==True: done[1]=False start=[x for x in start if x!=1] else: done[1]=True start.append(1) while len(start)>0: next=[] for i in start: print(i,end=' ') if i not in d2: continue for x in d2[i]: if done[x]==False: next.append(x) start=next if post(1,0)==1: print("YES") order() else: print('NO')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tree (a graph with *n* vertices and *n*<=-<=1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or determine that it is impossible. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — number of vertices in a tree. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=*n*). If *p**i*<=≠<=0 there is an edge between vertices *i* and *p**i*. It is guaranteed that the given graph is a tree. Output Specification: If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next *n* lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any. Demo Input: ['5\n0 1 2 1 2\n', '4\n0 1 2 3\n'] Demo Output: ['YES\n1\n2\n3\n5\n4\n', 'NO\n'] Note: In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
```python n=int(input()) d={} def add(x,y): if x in d: d[x].append(y) else: d[x]=[y] if y in d: d[y].append(x) else: d[y]=[x] ns=[int(x) for x in input().split()] for i in range(n): if ns[i]==0: continue x=i+1 y=ns[i] add(x,y) add(0,1) d2={} def d2add(x,y): if x in d2: d2[x].append(y) else: d2[x]=[y] start=[] done = [False] * (n + 1) def post(i,f): if len(d[i])==1: ans=1 else: need=0 for x in d[i]: if x==f: continue need+=post(x,i) ans = 1 - need%2 if ans==1: d2add(f, i) else: start.append(i) done[i]=True d2add(i, f) return ans def order(): global start,done if done[1]==True: done[1]=False start=[x for x in start if x!=1] else: done[1]=True start.append(1) while len(start)>0: next=[] for i in start: print(i,end=' ') if i not in d2: continue for x in d2[i]: if done[x]==False: next.append(x) start=next if post(1,0)==1: print("YES") order() else: print('NO') ```
0
670
D1
Magic Powder - 1
PROGRAMMING
1,400
[ "binary search", "brute force", "implementation" ]
null
null
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only. Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs *n* ingredients, and for each ingredient she knows the value *a**i* — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all *n* ingredients. Apollinaria has *b**i* gram of the *i*-th ingredient. Also she has *k* grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the *n* ingredients and can be used for baking cookies. Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.
The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, needed to bake one cookie. The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, which Apollinaria has.
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
[ "3 1\n2 1 4\n11 3 16\n", "4 3\n4 3 5 6\n11 12 14 20\n" ]
[ "4\n", "3\n" ]
In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies. In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.
1,000
[ { "input": "3 1\n2 1 4\n11 3 16", "output": "4" }, { "input": "4 3\n4 3 5 6\n11 12 14 20", "output": "3" }, { "input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000", "output": "137" }, { "input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 898 965 807 786 670 626 873 968 745 878 359 760 781 829 882 777 740 907 779", "output": "150" }, { "input": "30 300\n1 4 2 1 2 5 6 4 1 3 2 1 1 1 1 1 2 3 1 3 4 2 2 3 2 2 2 1 1 1\n997 817 767 860 835 809 817 565 630 804 586 953 977 356 905 890 958 916 740 583 902 945 313 956 871 729 976 707 516 788", "output": "164" }, { "input": "40 538\n1 3 3 1 4 1 1 1 1 5 3 3 4 1 4 2 7 1 4 1 1 2 2 1 1 1 1 4 1 4 2 3 3 3 1 3 4 1 3 5\n975 635 795 835 982 965 639 787 688 796 988 779 839 942 491 696 396 995 718 810 796 879 957 783 844 765 968 783 647 214 995 868 318 453 989 889 504 962 945 925", "output": "104" }, { "input": "50 530\n2 3 3 1 1 1 3 4 4 2 4 2 5 1 3 1 2 6 1 1 2 5 3 2 1 5 1 3 3 2 1 1 1 1 2 1 1 2 2 1 4 2 1 3 1 2 1 1 4 2\n959 972 201 990 675 679 972 268 976 886 488 924 795 959 647 994 969 862 898 646 763 797 978 763 995 641 923 856 829 921 934 883 904 986 728 980 1000 775 716 745 833 832 999 651 571 626 827 456 636 795", "output": "133" }, { "input": "60 735\n3 1 4 7 1 7 3 1 1 5 4 7 3 3 3 2 5 3 1 2 3 6 1 1 1 1 1 2 5 3 2 1 3 5 2 1 2 2 2 2 1 3 3 3 6 4 3 5 1 3 2 2 1 3 1 1 1 7 1 2\n596 968 975 493 665 571 598 834 948 941 737 649 923 848 950 907 929 865 227 836 956 796 861 801 746 667 539 807 405 355 501 879 994 890 573 848 597 873 130 985 924 426 999 550 586 924 601 807 994 878 410 817 922 898 982 525 611 685 806 847", "output": "103" }, { "input": "1 1\n1\n1", "output": "2" }, { "input": "70 130\n2 1 2 2 3 3 2 5 2 2 3 3 3 1 1 4 3 5 3 2 1 3 7 1 2 7 5 2 1 6 3 4 1 2 1 1 1 1 3 6 4 2 2 8 2 2 4 1 4 2 1 4 4 3 5 1 1 1 1 1 2 3 1 5 1 3 3 4 2 2\n473 311 758 768 797 572 656 898 991 534 989 702 934 767 777 799 1000 655 806 727 718 948 834 965 832 778 706 861 799 874 745 970 772 967 984 886 835 795 832 837 950 952 475 891 947 952 903 929 689 478 725 945 585 943 771 631 729 887 557 738 824 758 999 786 669 992 918 762 964 941", "output": "119" }, { "input": "80 979\n2 1 1 1 2 1 1 1 3 1 4 4 2 1 1 3 1 1 2 1 4 1 1 2 5 4 8 1 3 6 5 7 2 3 4 1 2 2 6 1 2 2 4 1 1 2 3 2 8 1 1 3 3 4 1 1 2 1 4 4 1 4 3 2 6 5 2 1 4 1 2 3 2 1 3 3 1 2 1 3\n498 976 513 869 917 914 664 656 957 893 981 947 985 693 576 958 987 822 981 718 884 729 295 683 485 998 730 894 731 975 739 854 906 740 987 976 606 689 990 775 522 994 920 893 529 651 989 799 643 215 946 987 297 868 425 810 694 908 736 903 970 751 625 904 955 945 839 777 977 974 905 900 666 680 799 873 565 919 536 686", "output": "128" }, { "input": "1 1000\n1000\n1000", "output": "2" }, { "input": "1 1000\n1\n1000", "output": "2000" }, { "input": "1 1\n4\n6", "output": "1" }, { "input": "1 1\n10\n2", "output": "0" }, { "input": "2 1\n2 2\n1 1", "output": "0" }, { "input": "2 6\n1 3\n6 2", "output": "2" } ]
1,661,442,812
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
31
0
n,k =map(int,input().split()) need=list(map(int,input().split())) have=list(map(int,input().split())) st=0 en =sum(have) mx =0 while(st<=en): mid =st+(en-st)//2 dif =0 for i in range(n): k1=mid*need[i] if have[i]>k1: dif+=0 else: dif+=k1-have[i] if dif<=k: if mid>mx: mx=mid st=mid+1 elif dif>k: en=mid-1 print(mx)
Title: Magic Powder - 1 Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only. Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs *n* ingredients, and for each ingredient she knows the value *a**i* — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all *n* ingredients. Apollinaria has *b**i* gram of the *i*-th ingredient. Also she has *k* grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the *n* ingredients and can be used for baking cookies. Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder. Input Specification: The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, needed to bake one cookie. The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, which Apollinaria has. Output Specification: Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. Demo Input: ['3 1\n2 1 4\n11 3 16\n', '4 3\n4 3 5 6\n11 12 14 20\n'] Demo Output: ['4\n', '3\n'] Note: In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies. In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.
```python n,k =map(int,input().split()) need=list(map(int,input().split())) have=list(map(int,input().split())) st=0 en =sum(have) mx =0 while(st<=en): mid =st+(en-st)//2 dif =0 for i in range(n): k1=mid*need[i] if have[i]>k1: dif+=0 else: dif+=k1-have[i] if dif<=k: if mid>mx: mx=mid st=mid+1 elif dif>k: en=mid-1 print(mx) ```
0
656
G
You're a Professional
PROGRAMMING
1,900
[ "*special" ]
null
null
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user. Output the number of items in the list liked by at least *T* of user's friends.
The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*). The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise.
Output an integer — the number of items liked by at least *T* of user's friends.
[ "3 3 2\nYYY\nNNN\nYNY\n", "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n" ]
[ "2\n", "4\n" ]
none
0
[ { "input": "3 3 2\nYYY\nNNN\nYNY", "output": "2" }, { "input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN", "output": "4" }, { "input": "3 5 2\nNYNNY\nYNNNN\nNNYYN", "output": "0" }, { "input": "1 10 1\nYYYNYNNYNN", "output": "5" }, { "input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\nN\nN", "output": "0" }, { "input": "10 10 1\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN", "output": "0" }, { "input": "10 10 10\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY", "output": "10" }, { "input": "8 9 1\nNYNNYYYYN\nNNNYNYNNY\nYYNYNYNNN\nNYYYNYNNN\nYNYNYNYYN\nYYNNYYYYY\nYYYYNYNYY\nNYYNNYYYY", "output": "9" }, { "input": "5 2 3\nNN\nNY\nYY\nNN\nNY", "output": "1" }, { "input": "6 4 5\nYNNY\nNYYY\nNNNY\nYNYN\nYYYN\nYNNY", "output": "0" }, { "input": "6 1 3\nY\nY\nY\nY\nY\nN", "output": "1" }, { "input": "6 2 2\nYN\nNN\nYN\nNN\nYN\nNN", "output": "1" }, { "input": "2 4 2\nNYNY\nNYNY", "output": "2" }, { "input": "9 6 3\nNYYYYN\nNNNYYN\nYYYYYY\nNYNNNN\nYNNYNY\nNNNNNY\nYNNYNN\nYYYYNY\nNNYYYY", "output": "6" }, { "input": "6 9 6\nYYYYNYNNN\nYNNYNNNYN\nNYYYNNNYY\nNYYYNNNNY\nYYNYNNNYY\nYYYNYYNNN", "output": "0" }, { "input": "9 7 8\nYNNNNYN\nNNNYYNN\nNNYYYNY\nNYYNYYY\nNNYYNYN\nNYYYNNY\nYYNYNYY\nNYYYYYY\nNNYYNYN", "output": "0" }, { "input": "9 1 6\nN\nN\nY\nN\nY\nY\nY\nY\nY", "output": "1" }, { "input": "7 7 2\nNNYNNYN\nNNNYYNY\nNNNYYNY\nYNNNNNY\nNNYNYYY\nYYNNYYN\nNNYYYNY", "output": "6" }, { "input": "8 4 2\nYNYY\nYNYY\nYNNN\nNNNN\nNYNN\nYNNN\nNNYN\nNYNN", "output": "4" }, { "input": "9 10 7\nNNYNNYYYYY\nYNYYNYYNYN\nNYNYYNNNNY\nYYYYYYYYYN\nYYNYNYYNNN\nYYYNNYYYYY\nNYYYYYNNNN\nNYNNYYYYNN\nYYYYYNNYYY", "output": "2" }, { "input": "6 4 2\nNNNN\nNYYY\nNYNN\nNYNN\nYNNY\nNNNN", "output": "2" }, { "input": "3 1 1\nN\nY\nN", "output": "1" }, { "input": "7 1 3\nY\nY\nY\nN\nY\nY\nY", "output": "1" }, { "input": "9 8 7\nNYYNNNYY\nYYYNYNNN\nYNYNYNNY\nNYYYNNNY\nNYYYYNYN\nNNNNYYNN\nYNYYYYYY\nNNYNYNYY\nNYYNNYYY", "output": "1" }, { "input": "9 5 9\nYYYYN\nYYYNN\nNNYNN\nNNYYY\nYNNNN\nNYNNN\nYYYYN\nYNYYN\nNNNYN", "output": "0" }, { "input": "8 4 1\nYYYN\nNNNN\nNYNY\nYNNY\nYNYY\nYNYN\nYNNY\nNNYN", "output": "4" }, { "input": "7 9 5\nYNNYYYYNN\nYNYYYNNYY\nYNYYYYYNN\nYYNYYNYYN\nNNYYNNNYY\nYYNYNYYNN\nYYNNYYNYN", "output": "3" }, { "input": "5 8 3\nNYYYNNNN\nYNNNNNYY\nYNYYYNYY\nNNNNNYNN\nYYYYYYYY", "output": "5" }, { "input": "5 10 4\nYYYYNNNNYN\nYYYNYYYNNY\nNNNYNYNYNY\nYNYNNNNNNY\nNNYNYNYNYY", "output": "2" }, { "input": "6 9 6\nNYYNNYNYN\nYNYNYNNNN\nNNYNNYYYY\nNNYNNNYNY\nNYYYNNYNY\nNNYYNNNYN", "output": "1" }, { "input": "4 4 1\nYNYY\nNNNY\nYNNN\nNNYN", "output": "3" }, { "input": "1 3 1\nYYN", "output": "2" }, { "input": "10 4 5\nNNYN\nYYNY\nYYNY\nNYYN\nYNYY\nYNYY\nYYNN\nYNYN\nYYYY\nYYNY", "output": "4" } ]
1,459,532,712
6,312
PyPy 3
WRONG_ANSWER
TESTS
0
0
0
n,m,k = map(int, input().split()) a = [input() for i in range(n)] print(sum(sum(int(a[i][j]=='Y') for i in range(n)) >= k for j in range(m)))
Title: You're a Professional Time Limit: None seconds Memory Limit: None megabytes Problem Description: A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user. Output the number of items in the list liked by at least *T* of user's friends. Input Specification: The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*). The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise. Output Specification: Output an integer — the number of items liked by at least *T* of user's friends. Demo Input: ['3 3 2\nYYY\nNNN\nYNY\n', '4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n'] Demo Output: ['2\n', '4\n'] Note: none
```python n,m,k = map(int, input().split()) a = [input() for i in range(n)] print(sum(sum(int(a[i][j]=='Y') for i in range(n)) >= k for j in range(m))) ```
0
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "output": "13" }, { "input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "output": "3" }, { "input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "output": "31" }, { "input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "output": "0" }, { "input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "output": "412" }, { "input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "output": "938" }, { "input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "output": "937" }, { "input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "output": "0" }, { "input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "output": "12" }, { "input": "40 50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "0" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "output": "31" }, { "input": "2 2\n1000 4", "output": "996" }, { "input": "2 3\n4 502 1000", "output": "498" }, { "input": "3 3\n4 1000 4", "output": "996" } ]
1,671,536,177
2,147,483,647
PyPy 3-64
OK
TESTS
18
122
0
n,m = map(int,input().strip().split()) l = list(map(int,input().strip().split())) l.sort() ans = l[n - 1] - l[0] for i in range(1,(m-n) + 1): ans = min(ans,l[i+n-1] - l[i]) print(ans)
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python n,m = map(int,input().strip().split()) l = list(map(int,input().strip().split())) l.sort() ans = l[n - 1] - l[0] for i in range(1,(m-n) + 1): ans = min(ans,l[i+n-1] - l[i]) print(ans) ```
3
382
A
Ksenia and Pan Scales
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale. The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet. It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them.
[ "AC|T\nL\n", "|ABC\nXYZ\n", "W|T\nF\n", "ABC|\nD\n" ]
[ "AC|TL\n", "XYZ|ABC\n", "Impossible\n", "Impossible\n" ]
none
500
[ { "input": "AC|T\nL", "output": "AC|TL" }, { "input": "|ABC\nXYZ", "output": "XYZ|ABC" }, { "input": "W|T\nF", "output": "Impossible" }, { "input": "ABC|\nD", "output": "Impossible" }, { "input": "A|BC\nDEF", "output": "ADF|BCE" }, { "input": "|\nABC", "output": "Impossible" }, { "input": "|\nZXCVBANMIO", "output": "XVAMO|ZCBNI" }, { "input": "|C\nA", "output": "A|C" }, { "input": "|\nAB", "output": "B|A" }, { "input": "A|XYZ\nUIOPL", "output": "Impossible" }, { "input": "K|B\nY", "output": "Impossible" }, { "input": "EQJWDOHKZRBISPLXUYVCMNFGT|\nA", "output": "Impossible" }, { "input": "|MACKERIGZPVHNDYXJBUFLWSO\nQT", "output": "Impossible" }, { "input": "ERACGIZOVPT|WXUYMDLJNQS\nKB", "output": "ERACGIZOVPTB|WXUYMDLJNQSK" }, { "input": "CKQHRUZMISGE|FBVWPXDLTJYN\nOA", "output": "CKQHRUZMISGEA|FBVWPXDLTJYNO" }, { "input": "V|CMOEUTAXBFWSK\nDLRZJGIYNQHP", "output": "VDLRZJGIYNQHP|CMOEUTAXBFWSK" }, { "input": "QWHNMALDGKTJ|\nPBRYVXZUESCOIF", "output": "QWHNMALDGKTJF|PBRYVXZUESCOI" }, { "input": "|\nFXCVMUEWZAHNDOSITPRLKQJYBG", "output": "XVUWANOIPLQYG|FCMEZHDSTRKJB" }, { "input": "IB|PCGHZ\nFXWTJQNEKAUM", "output": "Impossible" }, { "input": "EC|IWAXQ\nJUHSRKGZTOMYN", "output": "ECJUHRGTMN|IWAXQSKZOY" }, { "input": "VDINYMA|UQKWBCLRHZJ\nXEGOF", "output": "Impossible" }, { "input": "ZLTPSIQUBAR|XFDEMYC\nHNOJWG", "output": "ZLTPSIQUBARG|XFDEMYCHNOJW" }, { "input": "R|FLZOTJNU\nGIYHKVX", "output": "RGIYHKVX|FLZOTJNU" }, { "input": "W|TL\nQROFSADYPKHEJNMXBZVUCIG", "output": "WQOSDPHJMBVCG|TLRFAYKENXZUI" }, { "input": "NRDFQSEKLAYMOT|ZH\nGUXIBJCVPW", "output": "Impossible" }, { "input": "FGRT|\nAC", "output": "Impossible" }, { "input": "|FGRT\nAC", "output": "Impossible" }, { "input": "A|\nB", "output": "A|B" }, { "input": "|A\nB", "output": "B|A" }, { "input": "|\nA", "output": "Impossible" }, { "input": "|\nQWERTYUIOPASDFGHJKLZXCVBNM", "output": "WRYIPSFHKZCBM|QETUOADGJLXVN" }, { "input": "QWERTYUIOPASDFGHJKLZXCVBN|\nM", "output": "Impossible" }, { "input": "QWERTY|VBN\nUIOPASDFGHJKLZXC", "output": "Impossible" }, { "input": "ABC|D\nKSL", "output": "Impossible" }, { "input": "A|BCDEF\nGH", "output": "Impossible" }, { "input": "|ABC\nD", "output": "Impossible" }, { "input": "A|BC\nDE", "output": "Impossible" }, { "input": "|ASD\nX", "output": "Impossible" }, { "input": "AB|CDEF\nXYZRT", "output": "Impossible" } ]
1,551,975,144
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
93
307,200
s = list(input()) z = list(input()) x = list() for i in range(len(s)): if s[i] == '|': inx = i x = s[0:inx] for i in range(inx+1): del s[0] if (min(len(s), len(x)) + len(z)) == max(len(s), len(x)): if len(s) > len(x): for i in range(len(x)): print(x[i], end='') for i in range(len(z)): print(z[i], end='') print('|', end='') for i in range(len(s)): print(s[i], end='') else: for i in range(len(x)): print(x[i], end='') print('|', end='') for i in range(len(s)): print(s[i], end='') for i in range(len(z)): print(z[i], end='') else: print("Impossible")
Title: Ksenia and Pan Scales Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan. Input Specification: The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale. The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet. It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters. Output Specification: If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them. Demo Input: ['AC|T\nL\n', '|ABC\nXYZ\n', 'W|T\nF\n', 'ABC|\nD\n'] Demo Output: ['AC|TL\n', 'XYZ|ABC\n', 'Impossible\n', 'Impossible\n'] Note: none
```python s = list(input()) z = list(input()) x = list() for i in range(len(s)): if s[i] == '|': inx = i x = s[0:inx] for i in range(inx+1): del s[0] if (min(len(s), len(x)) + len(z)) == max(len(s), len(x)): if len(s) > len(x): for i in range(len(x)): print(x[i], end='') for i in range(len(z)): print(z[i], end='') print('|', end='') for i in range(len(s)): print(s[i], end='') else: for i in range(len(x)): print(x[i], end='') print('|', end='') for i in range(len(s)): print(s[i], end='') for i in range(len(z)): print(z[i], end='') else: print("Impossible") ```
0
652
C
Foe Pairs
PROGRAMMING
1,800
[ "combinatorics", "sortings", "two pointers" ]
null
null
You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Your task is to count the number of different intervals (*x*,<=*y*) (1<=≤<=*x*<=≤<=*y*<=≤<=*n*) that do not contain any foe pairs. So you shouldn't count intervals (*x*,<=*y*) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: *p*<==<=[1,<=3,<=2,<=4] and foe pairs are {(3,<=2),<=(4,<=2)}. The interval (1,<=3) is incorrect because it contains a foe pair (3,<=2). The interval (1,<=4) is also incorrect because it contains two foe pairs (3,<=2) and (4,<=2). But the interval (1,<=2) is correct because it doesn't contain any foe pair.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the length of the permutation *p* and the number of foe pairs. The second line contains *n* distinct integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation *p*. Each of the next *m* lines contains two integers (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — the *i*-th foe pair. Note a foe pair can appear multiple times in the given list.
Print the only integer *c* — the number of different intervals (*x*,<=*y*) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "4 2\n1 3 2 4\n3 2\n2 4\n", "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n" ]
[ "5\n", "20\n" ]
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
0
[ { "input": "4 2\n1 3 2 4\n3 2\n2 4", "output": "5" }, { "input": "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7", "output": "20" }, { "input": "2 1\n1 2\n1 2", "output": "2" }, { "input": "10 3\n4 10 5 1 6 8 9 2 3 7\n10 5\n2 10\n4 1", "output": "39" }, { "input": "50 10\n41 15 17 1 5 31 7 38 30 39 43 35 2 26 20 42 48 25 19 32 50 4 8 10 44 12 9 18 13 36 28 6 27 23 40 24 3 14 29 11 49 47 45 46 34 21 37 16 22 33\n13 48\n24 12\n2 32\n36 7\n19 20\n9 45\n35 47\n10 16\n4 49\n46 2", "output": "608" }, { "input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43\n58 26\n10 52\n26 75\n51 9\n49 33\n55 6\n52 62\n82 53\n90 24\n12 7", "output": "1589" }, { "input": "3 8\n1 2 3\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n2 3", "output": "3" }, { "input": "3 4\n1 2 3\n1 3\n1 2\n1 3\n2 3", "output": "3" } ]
1,459,099,955
2,147,483,647
Python 3
OK
TESTS
24
779
38,707,200
def main(): from sys import stdin n, m = map(int, input().split()) n += 1 aa, pos, duo = [0] * n, [0] * n, [0] * n for i, a in enumerate(map(int, input().split()), 1): aa[i] = a pos[a] = i for s in stdin.read().splitlines(): x, y = map(int, s.split()) px, py = pos[x], pos[y] if px > py: if duo[x] < py: duo[x] = py else: if duo[y] < px: duo[y] = px res = mx = 0 for i, a in enumerate(aa): if mx < duo[a]: mx = duo[a] res += i - mx print(res) if __name__ == '__main__': main()
Title: Foe Pairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Your task is to count the number of different intervals (*x*,<=*y*) (1<=≤<=*x*<=≤<=*y*<=≤<=*n*) that do not contain any foe pairs. So you shouldn't count intervals (*x*,<=*y*) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: *p*<==<=[1,<=3,<=2,<=4] and foe pairs are {(3,<=2),<=(4,<=2)}. The interval (1,<=3) is incorrect because it contains a foe pair (3,<=2). The interval (1,<=4) is also incorrect because it contains two foe pairs (3,<=2) and (4,<=2). But the interval (1,<=2) is correct because it doesn't contain any foe pair. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the length of the permutation *p* and the number of foe pairs. The second line contains *n* distinct integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation *p*. Each of the next *m* lines contains two integers (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — the *i*-th foe pair. Note a foe pair can appear multiple times in the given list. Output Specification: Print the only integer *c* — the number of different intervals (*x*,<=*y*) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Demo Input: ['4 2\n1 3 2 4\n3 2\n2 4\n', '9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n'] Demo Output: ['5\n', '20\n'] Note: In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
```python def main(): from sys import stdin n, m = map(int, input().split()) n += 1 aa, pos, duo = [0] * n, [0] * n, [0] * n for i, a in enumerate(map(int, input().split()), 1): aa[i] = a pos[a] = i for s in stdin.read().splitlines(): x, y = map(int, s.split()) px, py = pos[x], pos[y] if px > py: if duo[x] < py: duo[x] = py else: if duo[y] < px: duo[y] = px res = mx = 0 for i, a in enumerate(aa): if mx < duo[a]: mx = duo[a] res += i - mx print(res) if __name__ == '__main__': main() ```
3
271
A
Beautiful Year
PROGRAMMING
800
[ "brute force" ]
null
null
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
[ "1987\n", "2013\n" ]
[ "2013\n", "2014\n" ]
none
500
[ { "input": "1987", "output": "2013" }, { "input": "2013", "output": "2014" }, { "input": "1000", "output": "1023" }, { "input": "1001", "output": "1023" }, { "input": "1234", "output": "1235" }, { "input": "5555", "output": "5601" }, { "input": "9000", "output": "9012" }, { "input": "1111", "output": "1203" }, { "input": "8999", "output": "9012" }, { "input": "4572", "output": "4573" }, { "input": "6666", "output": "6701" }, { "input": "2001", "output": "2013" }, { "input": "3000", "output": "3012" }, { "input": "7712", "output": "7801" }, { "input": "8088", "output": "8091" }, { "input": "1594", "output": "1596" }, { "input": "6016", "output": "6017" }, { "input": "8800", "output": "8901" }, { "input": "3331", "output": "3401" }, { "input": "5090", "output": "5091" }, { "input": "2342", "output": "2345" }, { "input": "2334", "output": "2340" }, { "input": "1123", "output": "1203" }, { "input": "8989", "output": "9012" }, { "input": "8977", "output": "9012" }, { "input": "6869", "output": "6870" }, { "input": "8999", "output": "9012" } ]
1,695,562,610
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
year = list(input()) for i in range(int("".join(year)) + 1, 9000): i = list(str(i)) if i[0] != i[1] and i[0] != i[2] and i[0] != i[3] and i[1] != i[2] and i[1] != i[3] and i[2] != i[3]: print("".join(i)) break
Title: Beautiful Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. Input Specification: The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. Output Specification: Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. Demo Input: ['1987\n', '2013\n'] Demo Output: ['2013\n', '2014\n'] Note: none
```python year = list(input()) for i in range(int("".join(year)) + 1, 9000): i = list(str(i)) if i[0] != i[1] and i[0] != i[2] and i[0] != i[3] and i[1] != i[2] and i[1] != i[3] and i[2] != i[3]: print("".join(i)) break ```
0
992
C
Nastya and a Wardrobe
PROGRAMMING
1,600
[ "math" ]
null
null
Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns *x* dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for *k*<=+<=1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109<=+<=7, because it is easy to see that it is always integer.
The only line contains two integers *x* and *k* (0<=≤<=*x*,<=*k*<=≤<=1018), where *x* is the initial number of dresses and *k*<=+<=1 is the number of months in a year in Byteland.
In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109<=+<=7.
[ "2 0\n", "2 1\n", "3 2\n" ]
[ "4\n", "7\n", "21\n" ]
In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
1,500
[ { "input": "2 0", "output": "4" }, { "input": "2 1", "output": "7" }, { "input": "3 2", "output": "21" }, { "input": "1 411", "output": "485514976" }, { "input": "1 692", "output": "860080936" }, { "input": "16 8", "output": "7937" }, { "input": "18 12", "output": "143361" }, { "input": "1 1000000000000000000", "output": "719476261" }, { "input": "0 24", "output": "0" }, { "input": "24 0", "output": "48" }, { "input": "1000000000000000000 1", "output": "195" }, { "input": "348612312017571993 87570063840727716", "output": "551271547" }, { "input": "314647997243943415 107188213956410843", "output": "109575135" }, { "input": "375000003 2", "output": "0" }, { "input": "451 938", "output": "598946958" }, { "input": "4 1669", "output": "185365669" }, { "input": "24 347", "output": "860029201" }, { "input": "1619 1813", "output": "481568710" }, { "input": "280 472", "output": "632090765" }, { "input": "1271 237", "output": "27878991" }, { "input": "626 560", "output": "399405853" }, { "input": "167 887", "output": "983959273" }, { "input": "1769 422", "output": "698926874" }, { "input": "160 929", "output": "752935252" }, { "input": "1075 274", "output": "476211777" }, { "input": "1332 332", "output": "47520583" }, { "input": "103872254428948073 97291596742897547", "output": "283633261" }, { "input": "157600018563121064 54027847222622605", "output": "166795759" }, { "input": "514028642164226185 95344332761644668", "output": "718282571" }, { "input": "91859547444219924 75483775868568438", "output": "462306789" }, { "input": "295961633522750187 84483303945499729", "output": "11464805" }, { "input": "8814960236468055 86463151557693391", "output": "430718856" }, { "input": "672751296745170589 13026894786355983", "output": "260355651" }, { "input": "909771081413191574 18862935031728197", "output": "800873185" }, { "input": "883717267463724670 29585639347346605", "output": "188389362" }, { "input": "431620727626880523 47616788361847228", "output": "311078131" }, { "input": "816689044159694273 6475970360049048", "output": "211796030" }, { "input": "313779810374175108 13838123840048842", "output": "438854949" }, { "input": "860936792402722414 59551033597232946", "output": "359730003" }, { "input": "332382902893992163 15483141652464187", "output": "719128379" }, { "input": "225761360057436129 49203610094504526", "output": "54291755" }, { "input": "216006901533424028 8313457244750219", "output": "362896012" }, { "input": "568001660010321225 97167523790774710", "output": "907490480" }, { "input": "904089164817530426 53747406876903279", "output": "702270335" }, { "input": "647858974461637674 18385058205826214", "output": "375141527" }, { "input": "720433754707338458 94180351080265292", "output": "273505123" }, { "input": "268086842387268316 76502855388264782", "output": "288717798" }, { "input": "488603693655520686 79239542983498430", "output": "316399174" }, { "input": "152455635055802121 50394545488662355", "output": "697051907" }, { "input": "585664029992038779 34972826534657555", "output": "699566354" }, { "input": "349532090641396787 12248820623854158", "output": "233938854" }, { "input": "353579407209009179 74469254935824590", "output": "771349161" }, { "input": "491414900908765740 49509676303815755", "output": "237095803" }, { "input": "91142854626119420 900651524977956", "output": "211575546" }, { "input": "73543340229981083 66918326344192076", "output": "710215652" }, { "input": "463958371369193376 89203995753927042", "output": "41857490" }, { "input": "911873413622533246 54684577459651780", "output": "926432198" }, { "input": "316313018463929883 78259904441946885", "output": "36284201" }, { "input": "889560480100219043 54181377424922141", "output": "281123162" }, { "input": "0 3259862395629356", "output": "0" }, { "input": "1 3", "output": "9" }, { "input": "3 1", "output": "11" }, { "input": "1000000007 1", "output": "1000000006" }, { "input": "1000000007 2", "output": "1000000004" }, { "input": "1000000007 0", "output": "0" }, { "input": "1000000007 12", "output": "999995912" }, { "input": "1000000007 70", "output": "729983755" }, { "input": "250000002 1", "output": "0" }, { "input": "1000000007 3", "output": "1000000000" }, { "input": "999999999 0", "output": "999999991" }, { "input": "1000000007 5", "output": "999999976" }, { "input": "1000000007 1000000007", "output": "1000000006" }, { "input": "10000000000000000 0", "output": "860000007" }, { "input": "1000000000000 0", "output": "999986007" }, { "input": "99999999999999999 0", "output": "600000012" }, { "input": "1000000000000000 0", "output": "986000007" } ]
1,646,326,442
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
46
0
MOD = 10**9 + 7 x,k=map(int,input().split()) a1=pow(2,k+1,MOD) b1=pow(2,k,MOD) print((a1*x - b1 +1)%MOD)
Title: Nastya and a Wardrobe Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns *x* dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for *k*<=+<=1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109<=+<=7, because it is easy to see that it is always integer. Input Specification: The only line contains two integers *x* and *k* (0<=≤<=*x*,<=*k*<=≤<=1018), where *x* is the initial number of dresses and *k*<=+<=1 is the number of months in a year in Byteland. Output Specification: In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109<=+<=7. Demo Input: ['2 0\n', '2 1\n', '3 2\n'] Demo Output: ['4\n', '7\n', '21\n'] Note: In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
```python MOD = 10**9 + 7 x,k=map(int,input().split()) a1=pow(2,k+1,MOD) b1=pow(2,k,MOD) print((a1*x - b1 +1)%MOD) ```
0
799
B
T-shirt buying
PROGRAMMING
1,400
[ "data structures", "implementation" ]
null
null
A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and *b**i* are integers from 1 to 3. *m* buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the *j*-th buyer we know his favorite color *c**j*. A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served. You are to compute the prices each buyer will pay for t-shirts.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of t-shirts. The following line contains sequence of integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1<=000<=000<=000), where *p**i* equals to the price of the *i*-th t-shirt. The following line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3), where *a**i* equals to the front color of the *i*-th t-shirt. The following line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=3), where *b**i* equals to the back color of the *i*-th t-shirt. The next line contains single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of buyers. The following line contains sequence *c*1,<=*c*2,<=...,<=*c**m* (1<=≤<=*c**j*<=≤<=3), where *c**j* equals to the favorite color of the *j*-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.
Print to the first line *m* integers — the *j*-th integer should be equal to the price of the t-shirt which the *j*-th buyer will buy. If the *j*-th buyer won't buy anything, print -1.
[ "5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n", "2\n1000000000 1\n1 1\n1 2\n2\n2 1\n" ]
[ "200 400 300 500 911 -1 \n", "1 1000000000 \n" ]
none
1,000
[ { "input": "5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1", "output": "200 400 300 500 911 -1 " }, { "input": "2\n1000000000 1\n1 1\n1 2\n2\n2 1", "output": "1 1000000000 " }, { "input": "10\n251034796 163562337 995167403 531046374 341924810 828969071 971837553 183763940 857690534 687685084\n3 2 1 3 2 3 1 3 2 1\n2 3 3 1 2 3 2 3 3 2\n10\n1 3 2 3 2 3 3 1 2 3", "output": "531046374 163562337 251034796 183763940 341924810 828969071 857690534 687685084 971837553 995167403 " }, { "input": "20\n414468312 20329584 106106409 584924603 666547477 670032002 726095027 276840253 368277336 940941705 531635095 213813062 440421387 959075599 240727854 495316522 838268432 786936631 586382273 806443734\n3 1 2 3 3 2 2 1 3 2 3 2 3 3 3 2 1 3 1 2\n3 1 2 2 2 2 3 1 2 3 2 1 1 2 3 1 2 3 3 2\n40\n1 1 2 1 3 2 3 1 3 3 1 2 3 1 1 1 2 3 3 1 3 1 3 1 2 2 3 3 1 2 1 2 3 2 2 1 2 1 2 2", "output": "20329584 213813062 106106409 276840253 240727854 368277336 414468312 440421387 531635095 584924603 495316522 666547477 586382273 838268432 -1 -1 670032002 726095027 786936631 -1 940941705 -1 959075599 -1 806443734 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 " }, { "input": "1\n529469903\n1\n3\n1\n3", "output": "529469903 " } ]
1,697,357,567
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
5
3,000
23,756,800
import sys input = sys.stdin.readline # flush = sys.stdout.flush() # from math import gcd, isqrt, ceil, log2 # from collections import defaultdict, deque, Counter # import bisect #-->For bisect.bisect_left=lower_bound and bisect_right=upper_bound t = 1 # t = int(input()) for _ in range(t): n = int(input()) p = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) d = {1: [], 2: [], 3:[]} for i in range(n): if p[i] not in d[a[i]]: d[a[i]].append(p[i]) for i in range(n): if p[i] not in d[b[i]]: d[b[i]].append(p[i]) d[1].sort(reverse=True) d[2].sort(reverse=True) d[3].sort(reverse=True) m = int(input()) c = list(map(int, input().split())) for i in c: if d[i]: x = d[i].pop() print(x, end = " ") if x in d[1]: d[1].remove(x) if x in d[2]: d[2].remove(x) if x in d[3]: d[3].remove(x) else: print("-1", end = " ")
Title: T-shirt buying Time Limit: None seconds Memory Limit: None megabytes Problem Description: A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and *b**i* are integers from 1 to 3. *m* buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the *j*-th buyer we know his favorite color *c**j*. A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served. You are to compute the prices each buyer will pay for t-shirts. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of t-shirts. The following line contains sequence of integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1<=000<=000<=000), where *p**i* equals to the price of the *i*-th t-shirt. The following line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3), where *a**i* equals to the front color of the *i*-th t-shirt. The following line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=3), where *b**i* equals to the back color of the *i*-th t-shirt. The next line contains single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of buyers. The following line contains sequence *c*1,<=*c*2,<=...,<=*c**m* (1<=≤<=*c**j*<=≤<=3), where *c**j* equals to the favorite color of the *j*-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served. Output Specification: Print to the first line *m* integers — the *j*-th integer should be equal to the price of the t-shirt which the *j*-th buyer will buy. If the *j*-th buyer won't buy anything, print -1. Demo Input: ['5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n', '2\n1000000000 1\n1 1\n1 2\n2\n2 1\n'] Demo Output: ['200 400 300 500 911 -1 \n', '1 1000000000 \n'] Note: none
```python import sys input = sys.stdin.readline # flush = sys.stdout.flush() # from math import gcd, isqrt, ceil, log2 # from collections import defaultdict, deque, Counter # import bisect #-->For bisect.bisect_left=lower_bound and bisect_right=upper_bound t = 1 # t = int(input()) for _ in range(t): n = int(input()) p = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) d = {1: [], 2: [], 3:[]} for i in range(n): if p[i] not in d[a[i]]: d[a[i]].append(p[i]) for i in range(n): if p[i] not in d[b[i]]: d[b[i]].append(p[i]) d[1].sort(reverse=True) d[2].sort(reverse=True) d[3].sort(reverse=True) m = int(input()) c = list(map(int, input().split())) for i in c: if d[i]: x = d[i].pop() print(x, end = " ") if x in d[1]: d[1].remove(x) if x in d[2]: d[2].remove(x) if x in d[3]: d[3].remove(x) else: print("-1", end = " ") ```
0
0
none
none
none
0
[ "none" ]
null
null
An atom of element X can exist in *n* distinct states with energies *E*1<=&lt;<=*E*2<=&lt;<=...<=&lt;<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states *i*, *j* and *k* are selected, where *i*<=&lt;<=*j*<=&lt;<=*k*. After that the following process happens: 1. initially the atom is in the state *i*,1. we spend *E**k*<=-<=*E**i* energy to put the atom in the state *k*,1. the atom emits a photon with useful energy *E**k*<=-<=*E**j* and changes its state to the state *j*,1. the atom spontaneously changes its state to the state *i*, losing energy *E**j*<=-<=*E**i*,1. the process repeats from step 1. Let's define the energy conversion efficiency as , i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that *E**k*<=-<=*E**i*<=≤<=*U*. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*. The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=&lt;<=*E*2...<=&lt;<=*E**n*<=≤<=109). It is guaranteed that all *E**i* are given in increasing order.
If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "4 4\n1 3 5 7\n", "10 8\n10 13 15 16 17 19 20 22 24 25\n", "3 1\n2 5 10\n" ]
[ "0.5\n", "0.875\n", "-1\n" ]
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f68f268de4eb2242167e6ec64e6b8aa60a5703ae.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
0
[ { "input": "4 4\n1 3 5 7", "output": "0.5" }, { "input": "10 8\n10 13 15 16 17 19 20 22 24 25", "output": "0.875" }, { "input": "3 1\n2 5 10", "output": "-1" }, { "input": "5 3\n4 6 8 9 10", "output": "0.5" }, { "input": "10 128\n110 121 140 158 174 188 251 271 272 277", "output": "0.86554621848739499157" }, { "input": "20 17\n104 107 121 131 138 140 143 144 178 192 193 198 201 206 238 242 245 248 255 265", "output": "0.92857142857142860315" }, { "input": "30 23\n102 104 105 107 108 109 110 111 116 118 119 122 127 139 140 142 145 157 166 171 173 174 175 181 187 190 191 193 195 196", "output": "0.95652173913043481157" }, { "input": "50 64\n257 258 350 375 1014 1017 1051 1097 1169 1177 1223 1836 1942 1983 2111 2131 2341 2418 2593 2902 2948 3157 3243 3523 3566 4079 4499 4754 5060 5624 6279 6976 7011 7071 7278 7366 7408 7466 7526 7837 7934 8532 8577 8680 9221 9271 9327 9411 9590 9794", "output": "0.91891891891891896993" }, { "input": "5 2\n4 6 8 9 10", "output": "0.5" }, { "input": "10 2\n110 121 140 158 174 188 251 271 272 277", "output": "-1" }, { "input": "30 5\n102 104 105 107 108 109 110 111 116 118 119 122 127 139 140 142 145 157 166 171 173 174 175 181 187 190 191 193 195 196", "output": "0.80000000000000004441" }, { "input": "10 6\n110 121 140 158 174 188 251 271 272 277", "output": "0.83333333333333337034" }, { "input": "20 4\n104 107 121 131 138 140 143 144 178 192 193 198 201 206 238 242 245 248 255 265", "output": "0.25" }, { "input": "3 1000000000\n1 2 1000000000", "output": "0.99999999900000002828" }, { "input": "3 1\n1 2 3", "output": "-1" }, { "input": "5 1000000000\n1 2 3 999999999 1000000000", "output": "0.99999999900000002828" }, { "input": "10 199\n1 3 190 191 193 195 196 197 199 200", "output": "0.98994974874371854945" }, { "input": "10 300\n80 100 103 140 146 159 392 393 396 398", "output": "0.98993288590604022747" }, { "input": "10 92\n44 119 252 281 303 323 351 363 377 392", "output": "0.77528089887640450062" }, { "input": "4 2\n1 3 5 7", "output": "-1" }, { "input": "8 2\n1 3 7 9 15 17 23 25", "output": "-1" }, { "input": "3 5\n1 2 10", "output": "-1" }, { "input": "4 7\n1 5 8 9", "output": "0.42857142857142854764" } ]
1,521,909,454
3,754
Python 3
WRONG_ANSWER
PRETESTS
4
78
7,065,600
n, u = map(int, input().split()) x = list(map(int, input().split())) minimum, index = (10 ** 9) + 1, -1 ind1 = False vozm = [] for i in range(1, n): if i != n - 1 and (x[i] - x[i - 1] < minimum) and (x[i + 1] - x[i - 1] <= u): minimum = x[i] - x[i - 1] vozm = [i] if i != n - 1 and (x[i] - x[i - 1] == minimum) and (x[i + 1] - x[i - 1] <= u): vozm.append(i) if i >= 2 and x[i] - x[i - 2] <= u: ind1 = True if not ind1: print(-1) else: maximum = 0 for index in vozm: q = n - 1 while x[q] - x[index - 1] > u: q -= 1 if ((x[q] - x[index]) / (x[q] - x[index - 1])) > maximum: maximum = ((x[q] - x[index]) / (x[q] - x[index - 1])) print(maximum)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: An atom of element X can exist in *n* distinct states with energies *E*1<=&lt;<=*E*2<=&lt;<=...<=&lt;<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states *i*, *j* and *k* are selected, where *i*<=&lt;<=*j*<=&lt;<=*k*. After that the following process happens: 1. initially the atom is in the state *i*,1. we spend *E**k*<=-<=*E**i* energy to put the atom in the state *k*,1. the atom emits a photon with useful energy *E**k*<=-<=*E**j* and changes its state to the state *j*,1. the atom spontaneously changes its state to the state *i*, losing energy *E**j*<=-<=*E**i*,1. the process repeats from step 1. Let's define the energy conversion efficiency as , i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that *E**k*<=-<=*E**i*<=≤<=*U*. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input Specification: The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*. The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=&lt;<=*E*2...<=&lt;<=*E**n*<=≤<=109). It is guaranteed that all *E**i* are given in increasing order. Output Specification: If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . Demo Input: ['4 4\n1 3 5 7\n', '10 8\n10 13 15 16 17 19 20 22 24 25\n', '3 1\n2 5 10\n'] Demo Output: ['0.5\n', '0.875\n', '-1\n'] Note: In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f68f268de4eb2242167e6ec64e6b8aa60a5703ae.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python n, u = map(int, input().split()) x = list(map(int, input().split())) minimum, index = (10 ** 9) + 1, -1 ind1 = False vozm = [] for i in range(1, n): if i != n - 1 and (x[i] - x[i - 1] < minimum) and (x[i + 1] - x[i - 1] <= u): minimum = x[i] - x[i - 1] vozm = [i] if i != n - 1 and (x[i] - x[i - 1] == minimum) and (x[i + 1] - x[i - 1] <= u): vozm.append(i) if i >= 2 and x[i] - x[i - 2] <= u: ind1 = True if not ind1: print(-1) else: maximum = 0 for index in vozm: q = n - 1 while x[q] - x[index - 1] > u: q -= 1 if ((x[q] - x[index]) / (x[q] - x[index - 1])) > maximum: maximum = ((x[q] - x[index]) / (x[q] - x[index - 1])) print(maximum) ```
0
858
B
Which floor?
PROGRAMMING
1,500
[ "brute force", "implementation" ]
null
null
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat *n*?
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory. *m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*f**i* (1<=≤<=*k**i*<=≤<=100, 1<=≤<=*f**i*<=≤<=100), which means that the flat *k**i* is on the *f**i*-th floor. All values *k**i* are distinct. It is guaranteed that the given information is not self-contradictory.
Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
[ "10 3\n6 2\n2 1\n7 3\n", "8 4\n3 1\n6 2\n5 2\n2 1\n" ]
[ "4\n", "-1\n" ]
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
750
[ { "input": "10 3\n6 2\n2 1\n7 3", "output": "4" }, { "input": "8 4\n3 1\n6 2\n5 2\n2 1", "output": "-1" }, { "input": "8 3\n7 2\n6 2\n1 1", "output": "2" }, { "input": "4 2\n8 3\n3 1", "output": "2" }, { "input": "11 4\n16 4\n11 3\n10 3\n15 4", "output": "3" }, { "input": "16 6\n3 1\n16 4\n10 3\n9 3\n19 5\n8 2", "output": "4" }, { "input": "1 0", "output": "1" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 2\n1 1\n2 2", "output": "1" }, { "input": "2 2\n2 1\n1 1", "output": "1" }, { "input": "2 0", "output": "-1" }, { "input": "2 1\n3 3", "output": "2" }, { "input": "3 2\n1 1\n3 3", "output": "3" }, { "input": "3 3\n1 1\n3 3\n2 2", "output": "3" }, { "input": "3 0", "output": "-1" }, { "input": "1 1\n2 1", "output": "1" }, { "input": "2 2\n2 1\n1 1", "output": "1" }, { "input": "2 3\n3 2\n1 1\n2 1", "output": "1" }, { "input": "3 0", "output": "-1" }, { "input": "3 1\n1 1", "output": "-1" }, { "input": "2 2\n1 1\n3 1", "output": "1" }, { "input": "1 3\n1 1\n2 1\n3 1", "output": "1" }, { "input": "81 0", "output": "-1" }, { "input": "22 1\n73 73", "output": "22" }, { "input": "63 2\n10 10\n64 64", "output": "63" }, { "input": "88 3\n37 37\n15 15\n12 12", "output": "88" }, { "input": "29 4\n66 66\n47 47\n62 62\n2 2", "output": "29" }, { "input": "9 40\n72 72\n47 47\n63 63\n66 66\n21 21\n94 94\n28 28\n45 45\n93 93\n25 25\n100 100\n43 43\n49 49\n9 9\n74 74\n26 26\n42 42\n50 50\n2 2\n92 92\n76 76\n3 3\n78 78\n44 44\n69 69\n36 36\n65 65\n81 81\n13 13\n46 46\n24 24\n96 96\n73 73\n82 82\n68 68\n64 64\n41 41\n31 31\n29 29\n10 10", "output": "9" }, { "input": "50 70\n3 3\n80 80\n23 23\n11 11\n87 87\n7 7\n63 63\n61 61\n67 67\n53 53\n9 9\n43 43\n55 55\n27 27\n5 5\n1 1\n99 99\n65 65\n37 37\n60 60\n32 32\n38 38\n81 81\n2 2\n34 34\n17 17\n82 82\n26 26\n71 71\n4 4\n16 16\n19 19\n39 39\n51 51\n6 6\n49 49\n64 64\n83 83\n10 10\n56 56\n30 30\n76 76\n90 90\n42 42\n47 47\n91 91\n21 21\n52 52\n40 40\n77 77\n35 35\n88 88\n75 75\n95 95\n28 28\n15 15\n69 69\n22 22\n48 48\n66 66\n31 31\n98 98\n73 73\n25 25\n97 97\n18 18\n13 13\n54 54\n72 72\n29 29", "output": "50" }, { "input": "6 0", "output": "-1" }, { "input": "32 1\n9 5", "output": "16" }, { "input": "73 2\n17 9\n21 11", "output": "37" }, { "input": "6 3\n48 24\n51 26\n62 31", "output": "3" }, { "input": "43 4\n82 41\n52 26\n88 44\n41 21", "output": "22" }, { "input": "28 40\n85 43\n19 10\n71 36\n39 20\n57 29\n6 3\n15 8\n11 6\n99 50\n77 39\n79 40\n31 16\n35 18\n24 12\n54 27\n93 47\n90 45\n72 36\n63 32\n22 11\n83 42\n5 3\n12 6\n56 28\n94 47\n25 13\n41 21\n29 15\n36 18\n23 12\n1 1\n84 42\n55 28\n58 29\n9 5\n68 34\n86 43\n3 2\n48 24\n98 49", "output": "14" }, { "input": "81 70\n55 28\n85 43\n58 29\n20 10\n4 2\n47 24\n42 21\n28 14\n26 13\n38 19\n9 5\n83 42\n7 4\n72 36\n18 9\n61 31\n41 21\n64 32\n90 45\n46 23\n67 34\n2 1\n6 3\n27 14\n87 44\n39 20\n11 6\n21 11\n35 18\n48 24\n44 22\n3 2\n71 36\n62 31\n34 17\n16 8\n99 50\n57 29\n13 7\n79 40\n100 50\n53 27\n89 45\n36 18\n43 22\n92 46\n98 49\n75 38\n40 20\n97 49\n37 19\n68 34\n30 15\n96 48\n17 9\n12 6\n45 23\n65 33\n76 38\n84 42\n23 12\n91 46\n52 26\n8 4\n32 16\n77 39\n88 44\n86 43\n70 35\n51 26", "output": "41" }, { "input": "34 0", "output": "-1" }, { "input": "63 1\n94 24", "output": "16" }, { "input": "4 2\n38 10\n48 12", "output": "1" }, { "input": "37 3\n66 17\n89 23\n60 15", "output": "10" }, { "input": "71 4\n15 4\n13 4\n4 1\n70 18", "output": "18" }, { "input": "77 40\n49 13\n66 17\n73 19\n15 4\n36 9\n1 1\n41 11\n91 23\n51 13\n46 12\n39 10\n42 11\n56 14\n61 16\n70 18\n92 23\n65 17\n54 14\n97 25\n8 2\n87 22\n33 9\n28 7\n38 10\n50 13\n26 7\n7 2\n31 8\n84 21\n47 12\n27 7\n53 14\n19 5\n93 24\n29 8\n3 1\n77 20\n62 16\n9 3\n44 11", "output": "20" }, { "input": "18 70\n51 13\n55 14\n12 3\n43 11\n42 11\n95 24\n96 24\n29 8\n65 17\n71 18\n18 5\n62 16\n31 8\n100 25\n4 1\n77 20\n56 14\n24 6\n93 24\n97 25\n79 20\n40 10\n49 13\n86 22\n21 6\n46 12\n6 2\n14 4\n23 6\n20 5\n52 13\n88 22\n39 10\n70 18\n94 24\n13 4\n37 10\n41 11\n91 23\n85 22\n83 21\n89 23\n33 9\n64 16\n67 17\n57 15\n47 12\n36 9\n72 18\n81 21\n76 19\n35 9\n80 20\n34 9\n5 2\n22 6\n84 21\n63 16\n74 19\n90 23\n68 17\n98 25\n87 22\n2 1\n92 23\n50 13\n38 10\n28 7\n8 2\n60 15", "output": "5" }, { "input": "89 0", "output": "-1" }, { "input": "30 1\n3 1", "output": "-1" }, { "input": "63 2\n48 6\n17 3", "output": "8" }, { "input": "96 3\n45 6\n25 4\n35 5", "output": "12" }, { "input": "37 4\n2 1\n29 4\n27 4\n47 6", "output": "5" }, { "input": "64 40\n40 5\n92 12\n23 3\n75 10\n71 9\n2 1\n54 7\n18 3\n9 2\n74 10\n87 11\n11 2\n90 12\n30 4\n48 6\n12 2\n91 12\n60 8\n35 5\n13 2\n53 7\n46 6\n38 5\n59 8\n97 13\n32 4\n6 1\n36 5\n43 6\n83 11\n81 11\n99 13\n69 9\n10 2\n21 3\n78 10\n31 4\n27 4\n57 8\n1 1", "output": "8" }, { "input": "17 70\n63 8\n26 4\n68 9\n30 4\n61 8\n84 11\n39 5\n53 7\n4 1\n81 11\n50 7\n91 12\n59 8\n90 12\n20 3\n21 3\n83 11\n94 12\n37 5\n8 1\n49 7\n34 5\n19 3\n44 6\n74 10\n2 1\n73 10\n88 11\n43 6\n36 5\n57 8\n64 8\n76 10\n40 5\n71 9\n95 12\n15 2\n41 6\n89 12\n42 6\n96 12\n1 1\n52 7\n38 5\n45 6\n78 10\n82 11\n16 2\n48 6\n51 7\n56 7\n28 4\n87 11\n93 12\n46 6\n29 4\n97 13\n54 7\n35 5\n3 1\n79 10\n99 13\n13 2\n55 7\n100 13\n11 2\n75 10\n24 3\n33 5\n22 3", "output": "3" }, { "input": "9 0", "output": "-1" }, { "input": "50 1\n31 2", "output": "-1" }, { "input": "79 2\n11 1\n22 2", "output": "-1" }, { "input": "16 3\n100 7\n94 6\n3 1", "output": "1" }, { "input": "58 4\n73 5\n52 4\n69 5\n3 1", "output": "4" }, { "input": "25 40\n70 5\n28 2\n60 4\n54 4\n33 3\n21 2\n51 4\n20 2\n44 3\n79 5\n65 5\n1 1\n52 4\n23 2\n38 3\n92 6\n63 4\n3 1\n91 6\n5 1\n64 4\n34 3\n25 2\n97 7\n89 6\n61 4\n71 5\n88 6\n29 2\n56 4\n45 3\n6 1\n53 4\n57 4\n90 6\n76 5\n8 1\n46 3\n73 5\n87 6", "output": "2" }, { "input": "78 70\n89 6\n52 4\n87 6\n99 7\n3 1\n25 2\n46 3\n78 5\n35 3\n68 5\n85 6\n23 2\n60 4\n88 6\n17 2\n8 1\n15 1\n67 5\n95 6\n59 4\n94 6\n31 2\n4 1\n16 1\n10 1\n97 7\n42 3\n2 1\n24 2\n34 3\n37 3\n70 5\n18 2\n41 3\n48 3\n58 4\n20 2\n38 3\n72 5\n50 4\n49 4\n40 3\n61 4\n6 1\n45 3\n28 2\n13 1\n27 2\n96 6\n56 4\n91 6\n77 5\n12 1\n11 1\n53 4\n76 5\n74 5\n82 6\n55 4\n80 5\n14 1\n44 3\n7 1\n83 6\n79 5\n92 6\n66 5\n36 3\n73 5\n100 7", "output": "5" }, { "input": "95 0", "output": "-1" }, { "input": "33 1\n30 1", "output": "-1" }, { "input": "62 2\n14 1\n15 1", "output": "-1" }, { "input": "3 3\n6 1\n25 1\n38 2", "output": "1" }, { "input": "44 4\n72 3\n80 3\n15 1\n36 2", "output": "2" }, { "input": "34 40\n25 1\n28 1\n78 3\n5 1\n13 1\n75 3\n15 1\n67 3\n57 2\n23 1\n26 1\n61 2\n22 1\n48 2\n85 3\n24 1\n82 3\n83 3\n53 2\n38 2\n19 1\n33 2\n69 3\n17 1\n79 3\n54 2\n77 3\n97 4\n20 1\n35 2\n14 1\n18 1\n71 3\n21 1\n36 2\n56 2\n44 2\n63 2\n72 3\n32 1", "output": "2" }, { "input": "83 70\n79 3\n49 2\n2 1\n44 2\n38 2\n77 3\n86 3\n31 1\n83 3\n82 3\n35 2\n7 1\n78 3\n23 1\n39 2\n58 2\n1 1\n87 3\n72 3\n20 1\n48 2\n14 1\n13 1\n6 1\n70 3\n55 2\n52 2\n25 1\n11 1\n61 2\n76 3\n95 3\n32 1\n66 3\n29 1\n9 1\n5 1\n3 1\n88 3\n59 2\n96 3\n10 1\n63 2\n40 2\n42 2\n34 2\n43 2\n19 1\n89 3\n94 3\n24 1\n98 4\n12 1\n30 1\n69 3\n17 1\n50 2\n8 1\n93 3\n16 1\n97 4\n54 2\n71 3\n18 1\n33 2\n80 3\n15 1\n99 4\n75 3\n4 1", "output": "3" }, { "input": "2 0", "output": "-1" }, { "input": "36 1\n96 1", "output": "1" }, { "input": "73 2\n34 1\n4 1", "output": "-1" }, { "input": "6 3\n37 1\n22 1\n70 1", "output": "1" }, { "input": "47 4\n66 1\n57 1\n85 1\n47 1", "output": "1" }, { "input": "9 40\n73 1\n21 1\n37 1\n87 1\n33 1\n69 1\n49 1\n19 1\n35 1\n93 1\n71 1\n43 1\n79 1\n85 1\n29 1\n72 1\n76 1\n47 1\n17 1\n67 1\n95 1\n41 1\n54 1\n88 1\n42 1\n80 1\n98 1\n96 1\n10 1\n24 1\n78 1\n18 1\n3 1\n91 1\n2 1\n15 1\n5 1\n60 1\n36 1\n46 1", "output": "1" }, { "input": "63 70\n82 1\n53 1\n57 1\n46 1\n97 1\n19 1\n36 1\n90 1\n23 1\n88 1\n68 1\n45 1\n2 1\n70 1\n86 1\n8 1\n83 1\n40 1\n99 1\n42 1\n32 1\n52 1\n81 1\n50 1\n77 1\n37 1\n54 1\n75 1\n4 1\n49 1\n73 1\n22 1\n21 1\n98 1\n18 1\n51 1\n14 1\n76 1\n92 1\n80 1\n78 1\n33 1\n79 1\n89 1\n67 1\n9 1\n44 1\n60 1\n64 1\n55 1\n29 1\n100 1\n16 1\n87 1\n10 1\n12 1\n25 1\n85 1\n30 1\n63 1\n39 1\n38 1\n31 1\n5 1\n26 1\n91 1\n43 1\n72 1\n48 1\n94 1", "output": "1" }, { "input": "2 0", "output": "-1" } ]
1,505,660,631
7,131
Python 3
WRONG_ANSWER
PRETESTS
2
46
4,608,000
n,m = (int(i) for i in input().split()) home = {} fPer = 0 res = -1 for i in range(m): k,f = (int(i) for i in input().split()) home[f] = sorted(home.get(f,[])+[k]) stages = sorted(list(home.keys())) for i in range(1,len(stages)): if stages[i]-stages[i-1] == 1: if home[stages[i]][0] - home[stages[i-1]][-1] == 1: if home[stages[i-1]][-1]%stages[i-1]==0: fPer = home[stages[i-1]][-1]//stages[i-1] break if fPer!=0: if n%fPer != 0: print(n//fPer+1) else: print(n//fPer) else: print(res)
Title: Which floor? Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat *n*? Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory. *m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*f**i* (1<=≤<=*k**i*<=≤<=100, 1<=≤<=*f**i*<=≤<=100), which means that the flat *k**i* is on the *f**i*-th floor. All values *k**i* are distinct. It is guaranteed that the given information is not self-contradictory. Output Specification: Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Demo Input: ['10 3\n6 2\n2 1\n7 3\n', '8 4\n3 1\n6 2\n5 2\n2 1\n'] Demo Output: ['4\n', '-1\n'] Note: In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
```python n,m = (int(i) for i in input().split()) home = {} fPer = 0 res = -1 for i in range(m): k,f = (int(i) for i in input().split()) home[f] = sorted(home.get(f,[])+[k]) stages = sorted(list(home.keys())) for i in range(1,len(stages)): if stages[i]-stages[i-1] == 1: if home[stages[i]][0] - home[stages[i-1]][-1] == 1: if home[stages[i-1]][-1]%stages[i-1]==0: fPer = home[stages[i-1]][-1]//stages[i-1] break if fPer!=0: if n%fPer != 0: print(n//fPer+1) else: print(n//fPer) else: print(res) ```
0
832
A
Sasha and Sticks
PROGRAMMING
800
[ "games", "math" ]
null
null
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower).
[ "1 1\n", "10 4\n" ]
[ "YES\n", "NO\n" ]
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
500
[ { "input": "1 1", "output": "YES" }, { "input": "10 4", "output": "NO" }, { "input": "251656215122324104 164397544865601257", "output": "YES" }, { "input": "963577813436662285 206326039287271924", "output": "NO" }, { "input": "1000000000000000000 1", "output": "NO" }, { "input": "253308697183523656 25332878317796706", "output": "YES" }, { "input": "669038685745448997 501718093668307460", "output": "YES" }, { "input": "116453141993601660 87060381463547965", "output": "YES" }, { "input": "766959657 370931668", "output": "NO" }, { "input": "255787422422806632 146884995820359999", "output": "YES" }, { "input": "502007866464507926 71266379084204128", "output": "YES" }, { "input": "257439908778973480 64157133126869976", "output": "NO" }, { "input": "232709385 91708542", "output": "NO" }, { "input": "252482458300407528 89907711721009125", "output": "NO" }, { "input": "6 2", "output": "YES" }, { "input": "6 3", "output": "NO" }, { "input": "6 4", "output": "YES" }, { "input": "6 5", "output": "YES" }, { "input": "6 6", "output": "YES" }, { "input": "258266151957056904 30153168463725364", "output": "NO" }, { "input": "83504367885565783 52285355047292458", "output": "YES" }, { "input": "545668929424440387 508692735816921376", "output": "YES" }, { "input": "547321411485639939 36665750286082900", "output": "NO" }, { "input": "548973893546839491 183137237979822911", "output": "NO" }, { "input": "544068082 193116851", "output": "NO" }, { "input": "871412474 749817171", "output": "YES" }, { "input": "999999999 1247", "output": "NO" }, { "input": "851941088 712987048", "output": "YES" }, { "input": "559922900 418944886", "output": "YES" }, { "input": "293908937 37520518", "output": "YES" }, { "input": "650075786 130049650", "output": "NO" }, { "input": "1000000000 1000000000", "output": "YES" }, { "input": "548147654663723363 107422751713800746", "output": "YES" }, { "input": "828159210 131819483", "output": "NO" }, { "input": "6242634 4110365", "output": "YES" }, { "input": "458601973 245084155", "output": "YES" }, { "input": "349593257 18089089", "output": "YES" }, { "input": "814768821 312514745", "output": "NO" }, { "input": "697884949 626323363", "output": "YES" }, { "input": "667011589 54866795", "output": "NO" }, { "input": "1000000000000000000 2", "output": "NO" }, { "input": "1000000000000000000 3", "output": "YES" }, { "input": "1000000000000000000 4", "output": "NO" }, { "input": "999999999999999 1", "output": "YES" }, { "input": "17 4", "output": "NO" }, { "input": "2 2", "output": "YES" }, { "input": "1000000000000000 2", "output": "NO" }, { "input": "12 4", "output": "YES" }, { "input": "6 1", "output": "NO" }, { "input": "2 1", "output": "NO" }, { "input": "10000000005 1", "output": "YES" }, { "input": "10000000000000009 2", "output": "NO" }, { "input": "12457895452123 1", "output": "YES" }, { "input": "999999999999999999 9", "output": "YES" }, { "input": "1000000000000 3", "output": "YES" }, { "input": "13099714659575475 6549849616514894", "output": "NO" }, { "input": "100000000000000001 1", "output": "YES" }, { "input": "825175814723458 324", "output": "YES" }, { "input": "20 4", "output": "YES" }, { "input": "100000176877 4", "output": "YES" }, { "input": "100000 3", "output": "YES" }, { "input": "946744073709551614 10", "output": "YES" } ]
1,608,400,722
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
78
0
arr = [int(x) for x in input().split()] a = arr[0] b = arr[1] total = a/b if total%2==0: print("NO") else: print("YES")
Title: Sasha and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. Output Specification: If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower). Demo Input: ['1 1\n', '10 4\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
```python arr = [int(x) for x in input().split()] a = arr[0] b = arr[1] total = a/b if total%2==0: print("NO") else: print("YES") ```
0
296
A
Yaroslav and Permutations
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
[ "1\n1\n", "3\n1 1 2\n", "4\n7 7 7 7\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
500
[ { "input": "1\n1", "output": "YES" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "4\n7 7 7 7", "output": "NO" }, { "input": "4\n479 170 465 146", "output": "YES" }, { "input": "5\n996 437 605 996 293", "output": "YES" }, { "input": "6\n727 539 896 668 36 896", "output": "YES" }, { "input": "7\n674 712 674 674 674 674 674", "output": "NO" }, { "input": "8\n742 742 742 742 742 289 742 742", "output": "NO" }, { "input": "9\n730 351 806 806 806 630 85 757 967", "output": "YES" }, { "input": "10\n324 539 83 440 834 640 440 440 440 440", "output": "YES" }, { "input": "7\n925 830 925 98 987 162 356", "output": "YES" }, { "input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808", "output": "YES" }, { "input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94", "output": "YES" }, { "input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402", "output": "NO" }, { "input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187", "output": "YES" }, { "input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103", "output": "YES" }, { "input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925", "output": "NO" }, { "input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353", "output": "YES" }, { "input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285", "output": "NO" }, { "input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99", "output": "YES" }, { "input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26", "output": "YES" }, { "input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516", "output": "YES" }, { "input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314", "output": "NO" }, { "input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800", "output": "NO" }, { "input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317", "output": "NO" }, { "input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784", "output": "YES" }, { "input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474", "output": "YES" }, { "input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499", "output": "NO" }, { "input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816", "output": "NO" }, { "input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "99\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1000", "output": "YES" }, { "input": "12\n2 2 4 4 4 4 6 6 6 6 6 6", "output": "YES" } ]
1,567,069,669
169
Python 3
OK
TESTS
37
218
0
n = int(input()) a = list(map(int, input().split())) for q in a: if a.count(q) > (n+1)//2: print("NO") break else: print("YES")
Title: Yaroslav and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. Output Specification: In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. Demo Input: ['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
```python n = int(input()) a = list(map(int, input().split())) for q in a: if a.count(q) > (n+1)//2: print("NO") break else: print("YES") ```
3
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,694,973,007
2,147,483,647
Python 3
OK
TESTS
15
46
0
k, n, w = map(int, input().split()) c = 0 for i in range (1, w+1): c = c + i*k if n > c: print(0) else: print(c-n)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python k, n, w = map(int, input().split()) c = 0 for i in range (1, w+1): c = c + i*k if n > c: print(0) else: print(c-n) ```
3
659
A
Round House
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk.
[ "6 2 -5\n", "5 1 3\n", "3 2 7\n" ]
[ "3\n", "4\n", "3\n" ]
The first example is illustrated by the picture in the statements.
500
[ { "input": "6 2 -5", "output": "3" }, { "input": "5 1 3", "output": "4" }, { "input": "3 2 7", "output": "3" }, { "input": "1 1 0", "output": "1" }, { "input": "1 1 -1", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "100 1 -1", "output": "100" }, { "input": "100 54 100", "output": "54" }, { "input": "100 37 -100", "output": "37" }, { "input": "99 41 0", "output": "41" }, { "input": "97 37 -92", "output": "42" }, { "input": "99 38 59", "output": "97" }, { "input": "35 34 1", "output": "35" }, { "input": "48 1 -1", "output": "48" }, { "input": "87 65 -76", "output": "76" }, { "input": "76 26 29", "output": "55" }, { "input": "100 65 0", "output": "65" }, { "input": "2 1 100", "output": "1" }, { "input": "3 2 -100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "1 1 -100", "output": "1" }, { "input": "3 1 -100", "output": "3" }, { "input": "4 3 -100", "output": "3" }, { "input": "3 2 -12", "output": "2" }, { "input": "2 2 -100", "output": "2" }, { "input": "3 2 -90", "output": "2" }, { "input": "6 2 -10", "output": "4" }, { "input": "3 3 -100", "output": "2" }, { "input": "5 2 4", "output": "1" }, { "input": "6 4 5", "output": "3" }, { "input": "3 2 -6", "output": "2" }, { "input": "5 1 -99", "output": "2" }, { "input": "6 2 5", "output": "1" }, { "input": "10 1 -100", "output": "1" }, { "input": "2 2 1", "output": "1" }, { "input": "3 3 1", "output": "1" }, { "input": "6 4 4", "output": "2" }, { "input": "17 17 2", "output": "2" }, { "input": "6 6 1", "output": "1" }, { "input": "5 3 -2", "output": "1" }, { "input": "6 2 -100", "output": "4" }, { "input": "5 3 -100", "output": "3" }, { "input": "5 4 3", "output": "2" }, { "input": "3 2 2", "output": "1" }, { "input": "5 5 2", "output": "2" }, { "input": "3 2 5", "output": "1" }, { "input": "5 5 -1", "output": "4" }, { "input": "5 3 3", "output": "1" }, { "input": "4 2 3", "output": "1" }, { "input": "88 76 74", "output": "62" } ]
1,564,540,124
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
124
0
n, a, b = map(int, input().split()) if b > 0: pos = (a + b) % n if pos == 0: pos = n elif b == 0: pos = b else: remain = abs(b) % n b = n - remain pos = (a + b) % n if pos == 0: pos = n print(pos)
Title: Round House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk. Input Specification: The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. Output Specification: Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. Demo Input: ['6 2 -5\n', '5 1 3\n', '3 2 7\n'] Demo Output: ['3\n', '4\n', '3\n'] Note: The first example is illustrated by the picture in the statements.
```python n, a, b = map(int, input().split()) if b > 0: pos = (a + b) % n if pos == 0: pos = n elif b == 0: pos = b else: remain = abs(b) % n b = n - remain pos = (a + b) % n if pos == 0: pos = n print(pos) ```
0
558
A
Lala Land and Apple Trees
PROGRAMMING
1,100
[ "brute force", "implementation", "sortings" ]
null
null
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing. What is the maximum number of apples he can collect?
The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land. The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it. It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output the maximum number of apples Amr can collect.
[ "2\n-1 5\n1 5\n", "3\n-2 2\n1 4\n-1 3\n", "3\n1 9\n3 5\n7 10\n" ]
[ "10", "9", "9" ]
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples. In the second sample test the optimal solution is to go left to *x* =  - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* =  - 2. In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
500
[ { "input": "2\n-1 5\n1 5", "output": "10" }, { "input": "3\n-2 2\n1 4\n-1 3", "output": "9" }, { "input": "3\n1 9\n3 5\n7 10", "output": "9" }, { "input": "1\n1 1", "output": "1" }, { "input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000", "output": "300000" }, { "input": "1\n-1 1", "output": "1" }, { "input": "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 67531\n-70083 26921\n-86333 50029\n48924 8036\n-27228 5349\n6022 10691\n-13840 56735\n50398 58794\n-63258 45557\n-27792 77057\n98295 1203\n-51294 18757\n35037 61941\n-30112 13076\n82334 20463", "output": "1036452" }, { "input": "18\n-18697 44186\n56333 51938\n-75688 49735\n77762 14039\n-43996 81060\n69700 49107\n74532 45568\n-94476 203\n-92347 90745\n58921 44650\n57563 63561\n44630 8486\n35750 5999\n3249 34202\n75358 68110\n-33245 60458\n-88148 2342\n87856 85532", "output": "632240" }, { "input": "28\n49728 91049\n-42863 4175\n-89214 22191\n77977 16965\n-42960 87627\n-84329 97494\n89270 75906\n-13695 28908\n-72279 13607\n-97327 87062\n-58682 32094\n39108 99936\n29304 93784\n-63886 48237\n-77359 57648\n-87013 79017\n-41086 35033\n-60613 83555\n-48955 56816\n-20568 26802\n52113 25160\n-88885 45294\n22601 42971\n62693 65662\n-15985 5357\n86671 8522\n-59921 11271\n-79304 25044", "output": "891593" }, { "input": "25\n5704 67795\n6766 31836\n-41715 89987\n76854 9848\n11648 90020\n-79763 10107\n96971 92636\n-64205 71937\n87997 38273\n-9782 57187\n22186 6905\n-41130 40258\n-28403 66579\n19578 43375\n35735 52929\n-52417 89388\n-89430 1939\n9401 43491\n-11228 10112\n-86859 16024\n-51486 33467\n-80578 65080\n-52820 98445\n-89165 7657\n-97106 79422", "output": "1109655" }, { "input": "16\n-41732 47681\n44295 28942\n-75194 99827\n69982 18020\n-75378 22026\n80032 22908\n-34879 41113\n36257 48574\n-35882 84333\n29646 71151\n-86214 80886\n72724 39364\n-42529 60880\n29150 29921\n-8471 80781\n79387 70834", "output": "847241" }, { "input": "3\n-94146 4473\n28707 99079\n-4153 8857", "output": "112409" }, { "input": "3\n-3 3\n-2 2\n-1 1", "output": "1" }, { "input": "2\n100000 3\n-100000 9", "output": "12" }, { "input": "2\n-100000 100000\n100000 99999", "output": "199999" } ]
1,583,938,450
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
108
307,200
n = int(input()) l =[] for i in range(n): l.append(list(map(int,input().split()))) #print(l) l = list(sorted(l)) #print(l) pos = [] neg = [] for i in range(n): if l[i][0] < 0 : neg.append(l[i][1]) else: pos.append(l[i][1]) #print(neg) #print(pos) #neg = list(reversed(neg)) #pos = list(reversed(pos)) #print(len(neg) , len(pos)) if len(neg) == len(pos): print(sum(neg) + sum(pos)) elif len(neg) > len(pos): print(sum(pos) + sum(neg[:len(pos)+1])) else: print(sum(neg) + sum(pos[:len(neg) + 1]))
Title: Lala Land and Apple Trees Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing. What is the maximum number of apples he can collect? Input Specification: The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land. The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it. It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0. Output Specification: Output the maximum number of apples Amr can collect. Demo Input: ['2\n-1 5\n1 5\n', '3\n-2 2\n1 4\n-1 3\n', '3\n1 9\n3 5\n7 10\n'] Demo Output: ['10', '9', '9'] Note: In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples. In the second sample test the optimal solution is to go left to *x* =  - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* =  - 2. In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
```python n = int(input()) l =[] for i in range(n): l.append(list(map(int,input().split()))) #print(l) l = list(sorted(l)) #print(l) pos = [] neg = [] for i in range(n): if l[i][0] < 0 : neg.append(l[i][1]) else: pos.append(l[i][1]) #print(neg) #print(pos) #neg = list(reversed(neg)) #pos = list(reversed(pos)) #print(len(neg) , len(pos)) if len(neg) == len(pos): print(sum(neg) + sum(pos)) elif len(neg) > len(pos): print(sum(pos) + sum(neg[:len(pos)+1])) else: print(sum(neg) + sum(pos[:len(neg) + 1])) ```
0
255
A
Greg's Workout
PROGRAMMING
800
[ "implementation" ]
null
null
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
[ "2\n2 8\n", "3\n5 1 10\n", "7\n3 3 2 7 9 6 8\n" ]
[ "biceps\n", "back\n", "chest\n" ]
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
500
[ { "input": "2\n2 8", "output": "biceps" }, { "input": "3\n5 1 10", "output": "back" }, { "input": "7\n3 3 2 7 9 6 8", "output": "chest" }, { "input": "4\n5 6 6 2", "output": "chest" }, { "input": "5\n8 2 2 6 3", "output": "chest" }, { "input": "6\n8 7 2 5 3 4", "output": "chest" }, { "input": "8\n7 2 9 10 3 8 10 6", "output": "chest" }, { "input": "9\n5 4 2 3 4 4 5 2 2", "output": "chest" }, { "input": "10\n4 9 8 5 3 8 8 10 4 2", "output": "biceps" }, { "input": "11\n10 9 7 6 1 3 9 7 1 3 5", "output": "chest" }, { "input": "12\n24 22 6 16 5 21 1 7 2 19 24 5", "output": "chest" }, { "input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24", "output": "chest" }, { "input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7", "output": "back" }, { "input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12", "output": "chest" }, { "input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8", "output": "biceps" }, { "input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19", "output": "chest" }, { "input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21", "output": "back" }, { "input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24", "output": "chest" }, { "input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20", "output": "chest" }, { "input": "1\n10", "output": "chest" }, { "input": "2\n15 3", "output": "chest" }, { "input": "3\n21 11 19", "output": "chest" }, { "input": "4\n19 24 13 15", "output": "chest" }, { "input": "5\n4 24 1 9 19", "output": "biceps" }, { "input": "6\n6 22 24 7 15 24", "output": "back" }, { "input": "7\n10 8 23 23 14 18 14", "output": "chest" }, { "input": "8\n5 16 8 9 17 16 14 7", "output": "biceps" }, { "input": "9\n12 3 10 23 6 4 22 13 12", "output": "chest" }, { "input": "10\n1 9 20 18 20 17 7 24 23 2", "output": "back" }, { "input": "11\n22 25 8 2 18 15 1 13 1 11 4", "output": "biceps" }, { "input": "12\n20 12 14 2 15 6 24 3 11 8 11 14", "output": "chest" }, { "input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18", "output": "back" }, { "input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22", "output": "biceps" }, { "input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6", "output": "back" }, { "input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14", "output": "chest" }, { "input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10", "output": "biceps" }, { "input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17", "output": "chest" }, { "input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14", "output": "back" }, { "input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6", "output": "back" }, { "input": "1\n19", "output": "chest" }, { "input": "2\n1 7", "output": "biceps" }, { "input": "3\n18 18 23", "output": "back" }, { "input": "4\n12 15 1 13", "output": "chest" }, { "input": "5\n11 14 25 21 21", "output": "biceps" }, { "input": "6\n11 9 12 11 22 18", "output": "biceps" }, { "input": "7\n11 1 16 20 21 25 20", "output": "chest" }, { "input": "8\n1 2 20 9 3 22 17 4", "output": "back" }, { "input": "9\n19 2 10 19 15 20 3 1 13", "output": "back" }, { "input": "10\n11 2 11 8 21 16 2 3 19 9", "output": "back" }, { "input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24", "output": "chest" }, { "input": "12\n4 24 21 3 13 24 22 13 12 21 1 15", "output": "back" }, { "input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3", "output": "biceps" }, { "input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11", "output": "biceps" }, { "input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17", "output": "back" }, { "input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17", "output": "chest" }, { "input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8", "output": "chest" }, { "input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22", "output": "chest" }, { "input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24", "output": "chest" }, { "input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23", "output": "biceps" }, { "input": "1\n19", "output": "chest" }, { "input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22", "output": "biceps" } ]
1,655,024,374
2,147,483,647
Python 3
OK
TESTS
61
92
0
c = 0 b = 0 ba = 0 nope = input() user = [int(i) for i in input().split(" ")] for num in range(len(user)) : if num % 3 == 0 : c = c + user[num] elif num % 3 == 1 : b = b + user[num] else : ba = ba + user[num] if c > b and c > ba : print("chest") elif b > c and b > ba : print("biceps") else : print("back")
Title: Greg's Workout Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. Output Specification: Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous. Demo Input: ['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n'] Demo Output: ['biceps\n', 'back\n', 'chest\n'] Note: In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
```python c = 0 b = 0 ba = 0 nope = input() user = [int(i) for i in input().split(" ")] for num in range(len(user)) : if num % 3 == 0 : c = c + user[num] elif num % 3 == 1 : b = b + user[num] else : ba = ba + user[num] if c > b and c > ba : print("chest") elif b > c and b > ba : print("biceps") else : print("back") ```
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,560,131,321
2,147,483,647
Python 3
OK
TESTS
36
218
0
n1, n2 = map(int, input().split()) m = max(n1, n2) chislitel = 7-m znam = 6 if chislitel%2 == 0: chislitel = chislitel//2 znam = znam//2 if chislitel%3 == 0: chislitel = chislitel//3 znam = znam//3 print(chislitel, znam, sep='/')
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 n1, n2 = map(int, input().split()) m = max(n1, n2) chislitel = 7-m znam = 6 if chislitel%2 == 0: chislitel = chislitel//2 znam = znam//2 if chislitel%3 == 0: chislitel = chislitel//3 znam = znam//3 print(chislitel, znam, sep='/') ```
3.891
810
A
Straight <<A>>
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark *k*. Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
[ "2 10\n8 9\n", "3 5\n4 4 4\n" ]
[ "4", "3" ]
Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation. In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
500
[ { "input": "2 10\n8 9", "output": "4" }, { "input": "3 5\n4 4 4", "output": "3" }, { "input": "3 10\n10 8 9", "output": "3" }, { "input": "2 23\n21 23", "output": "2" }, { "input": "5 10\n5 10 10 9 10", "output": "7" }, { "input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12", "output": "712" }, { "input": "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6", "output": "482" }, { "input": "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28", "output": "6469" }, { "input": "100 38\n30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31", "output": "1340" }, { "input": "33 69\n60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61", "output": "329" }, { "input": "39 92\n19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16", "output": "5753" }, { "input": "68 29\n29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29", "output": "0" }, { "input": "75 30\n22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25", "output": "851" }, { "input": "78 43\n2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4", "output": "5884" }, { "input": "82 88\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1", "output": "14170" }, { "input": "84 77\n28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30", "output": "6650" }, { "input": "94 80\n21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20", "output": "11786" }, { "input": "96 41\n13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28", "output": "3182" }, { "input": "1 26\n26", "output": "0" }, { "input": "99 39\n25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26", "output": "1807" }, { "input": "100 12\n7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4", "output": "946" }, { "input": "100 18\n1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2", "output": "3164" }, { "input": "100 27\n16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16", "output": "1262" }, { "input": "100 29\n20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18", "output": "2024" }, { "input": "100 30\n16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15", "output": "1984" }, { "input": "100 59\n56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55", "output": "740" }, { "input": "100 81\n6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4", "output": "14888" }, { "input": "100 100\n30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40", "output": "13118" }, { "input": "100 100\n71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76", "output": "3030" }, { "input": "100 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": "19700" }, { "input": "100 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": "0" }, { "input": "100 100\n1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "19696" }, { "input": "100 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 99", "output": "0" }, { "input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 100 100 100 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": "0" }, { "input": "100 100\n95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100", "output": "2" }, { "input": "100 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 1 1 1 1", "output": "0" }, { "input": "100 2\n2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1", "output": "16" }, { "input": "3 5\n5 5 5", "output": "0" }, { "input": "7 7\n1 1 1 1 1 1 1", "output": "77" }, { "input": "1 1\n1", "output": "0" }, { "input": "100 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": "19700" }, { "input": "4 10\n10 10 10 10", "output": "0" }, { "input": "1 10\n10", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3 10\n10 10 10", "output": "0" }, { "input": "2 4\n3 4", "output": "0" }, { "input": "1 2\n2", "output": "0" }, { "input": "3 4\n4 4 4", "output": "0" }, { "input": "3 2\n2 2 1", "output": "0" }, { "input": "5 5\n5 5 5 5 5", "output": "0" }, { "input": "3 3\n3 3 3", "output": "0" }, { "input": "2 9\n8 9", "output": "0" }, { "input": "3 10\n9 10 10", "output": "0" }, { "input": "1 3\n3", "output": "0" }, { "input": "2 2\n1 2", "output": "0" }, { "input": "2 10\n10 10", "output": "0" }, { "input": "23 14\n7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14", "output": "0" }, { "input": "2 10\n9 10", "output": "0" }, { "input": "2 2\n2 2", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 5 5 4", "output": "0" }, { "input": "3 5\n4 5 5", "output": "0" }, { "input": "5 4\n4 4 4 4 4", "output": "0" }, { "input": "2 10\n10 9", "output": "0" }, { "input": "4 5\n3 5 5 5", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "3 10\n10 10 9", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "4 10\n9 10 10 10", "output": "0" }, { "input": "5 2\n2 2 2 2 2", "output": "0" }, { "input": "2 5\n4 5", "output": "0" }, { "input": "5 10\n10 10 10 10 10", "output": "0" }, { "input": "2 6\n6 6", "output": "0" }, { "input": "2 9\n9 9", "output": "0" }, { "input": "3 10\n10 9 10", "output": "0" }, { "input": "4 40\n39 40 40 40", "output": "0" }, { "input": "3 4\n3 4 4", "output": "0" }, { "input": "9 9\n9 9 9 9 9 9 9 9 9", "output": "0" }, { "input": "1 4\n4", "output": "0" }, { "input": "4 7\n1 1 1 1", "output": "44" }, { "input": "1 5\n5", "output": "0" }, { "input": "3 1\n1 1 1", "output": "0" }, { "input": "1 100\n100", "output": "0" }, { "input": "2 7\n3 5", "output": "10" }, { "input": "3 6\n6 6 6", "output": "0" }, { "input": "4 2\n1 2 2 2", "output": "0" }, { "input": "4 5\n4 5 5 5", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "35" }, { "input": "66 2\n1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1", "output": "0" }, { "input": "2 2\n2 1", "output": "0" }, { "input": "5 5\n5 5 5 4 5", "output": "0" }, { "input": "3 7\n1 1 1", "output": "33" }, { "input": "2 5\n5 5", "output": "0" }, { "input": "1 7\n1", "output": "11" }, { "input": "6 7\n1 1 1 1 1 1", "output": "66" }, { "input": "99 97\n15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64", "output": "10077" }, { "input": "8 7\n1 1 1 1 1 1 1 1", "output": "88" }, { "input": "3 2\n2 2 2", "output": "0" }, { "input": "6 5\n5 5 5 5 5 5", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 4 1 1", "output": "8" }, { "input": "1 5\n1", "output": "7" }, { "input": "10 10\n10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "2 3\n2 3", "output": "0" }, { "input": "1 9\n9", "output": "0" }, { "input": "74 2\n2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2", "output": "0" }, { "input": "5 5\n5 5 5 5 4", "output": "0" } ]
1,589,248,764
2,147,483,647
Python 3
OK
TESTS
106
124
0
#Tony thought about the code again, using inspiration from CodeForces import time marks =[] n,k = map(int,input().split()) marks = input().split() marks = list(map(int,marks)) extra = 0 while sum(marks)+extra*k-(extra+len(marks))*(k-0.5)<0: extra+=1 print(extra)
Title: Straight <<A>> Time Limit: None seconds Memory Limit: None megabytes Problem Description: Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark *k*. Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. Output Specification: Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. Demo Input: ['2 10\n8 9\n', '3 5\n4 4 4\n'] Demo Output: ['4', '3'] Note: Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation. In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
```python #Tony thought about the code again, using inspiration from CodeForces import time marks =[] n,k = map(int,input().split()) marks = input().split() marks = list(map(int,marks)) extra = 0 while sum(marks)+extra*k-(extra+len(marks))*(k-0.5)<0: extra+=1 print(extra) ```
3
350
A
TL
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
If there is a valid TL value, print it. Otherwise, print -1.
[ "3 6\n4 5 2\n8 9 6 10 7 11\n", "3 1\n3 4 5\n6\n" ]
[ "5", "-1\n" ]
none
500
[ { "input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5" }, { "input": "3 1\n3 4 5\n6", "output": "-1" }, { "input": "2 5\n45 99\n49 41 77 83 45", "output": "-1" }, { "input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50", "output": "49" }, { "input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2", "output": "-1" }, { "input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90", "output": "46" }, { "input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66", "output": "14" }, { "input": "1 1\n4\n9", "output": "8" }, { "input": "1 1\n2\n4", "output": "-1" }, { "input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58", "output": "-1" }, { "input": "1 1\n50\n100", "output": "-1" }, { "input": "1 1\n49\n100", "output": "98" }, { "input": "1 1\n100\n100", "output": "-1" }, { "input": "1 1\n99\n100", "output": "-1" }, { "input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100", "output": "99" }, { "input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2", "output": "-1" }, { "input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75", "output": "2" }, { "input": "3 3\n2 3 4\n8 9 10", "output": "4" }, { "input": "2 1\n2 3\n15", "output": "4" }, { "input": "2 1\n2 4\n4", "output": "-1" }, { "input": "2 3\n4 5\n10 11 12", "output": "8" }, { "input": "3 1\n2 3 3\n5", "output": "4" }, { "input": "2 1\n9 10\n100", "output": "18" }, { "input": "3 3\n3 12 15\n7 8 9", "output": "-1" }, { "input": "2 2\n3 5\n7 8", "output": "6" }, { "input": "3 3\n4 5 6\n10 11 12", "output": "8" }, { "input": "3 5\n2 3 3\n6 6 6 6 2", "output": "-1" }, { "input": "3 6\n4 5 3\n8 9 7 10 7 11", "output": "6" }, { "input": "3 6\n4 5 2\n8 9 6 10 7 4", "output": "-1" }, { "input": "2 1\n4 6\n10", "output": "8" }, { "input": "1 2\n1\n3 1", "output": "-1" }, { "input": "2 1\n5 6\n20", "output": "10" }, { "input": "2 1\n1 5\n5", "output": "-1" }, { "input": "3 2\n10 20 30\n30 40", "output": "-1" }, { "input": "2 2\n5 6\n7 100", "output": "-1" }, { "input": "2 1\n2 5\n7", "output": "5" }, { "input": "1 1\n5\n20", "output": "10" }, { "input": "2 1\n10 11\n100", "output": "20" }, { "input": "1 1\n1\n10", "output": "2" }, { "input": "1 1\n10\n100", "output": "20" } ]
1,653,802,059
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) max_a = max(a) if(m == 1): print(-1) else: sort_b = sorted(b) if(sort_b[-2] - max_a == 0): print(-1) else: print(sort_b[-2] - max_a)
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. Output Specification: If there is a valid TL value, print it. Otherwise, print -1. Demo Input: ['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n'] Demo Output: ['5', '-1\n'] Note: none
```python n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) max_a = max(a) if(m == 1): print(-1) else: sort_b = sorted(b) if(sort_b[-2] - max_a == 0): print(-1) else: print(sort_b[-2] - max_a) ```
0
755
A
PolandBall and Hypothesis
PROGRAMMING
800
[ "brute force", "graphs", "math", "number theory" ]
null
null
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number". Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any *n*.
The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis.
Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists.
[ "3\n", "4\n" ]
[ "1", "2" ]
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. For the first sample testcase, 3·1 + 1 = 4. We can output 1. In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not a prime number.
500
[ { "input": "3", "output": "1" }, { "input": "4", "output": "2" }, { "input": "10", "output": "2" }, { "input": "153", "output": "1" }, { "input": "1000", "output": "1" }, { "input": "1", "output": "3" }, { "input": "2", "output": "4" }, { "input": "5", "output": "1" }, { "input": "6", "output": "4" }, { "input": "7", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "11", "output": "1" }, { "input": "998", "output": "1" }, { "input": "996", "output": "3" }, { "input": "36", "output": "4" }, { "input": "210", "output": "4" }, { "input": "270", "output": "4" }, { "input": "306", "output": "4" }, { "input": "330", "output": "5" }, { "input": "336", "output": "4" }, { "input": "600", "output": "4" }, { "input": "726", "output": "4" }, { "input": "988", "output": "1" }, { "input": "12", "output": "2" }, { "input": "987", "output": "1" }, { "input": "13", "output": "1" }, { "input": "986", "output": "1" }, { "input": "14", "output": "1" }, { "input": "985", "output": "1" }, { "input": "15", "output": "1" }, { "input": "984", "output": "1" }, { "input": "16", "output": "2" }, { "input": "983", "output": "1" }, { "input": "17", "output": "1" }, { "input": "982", "output": "2" }, { "input": "18", "output": "3" }, { "input": "981", "output": "1" }, { "input": "19", "output": "1" }, { "input": "980", "output": "1" }, { "input": "20", "output": "1" }, { "input": "979", "output": "1" }, { "input": "21", "output": "1" }, { "input": "978", "output": "1" }, { "input": "22", "output": "2" }, { "input": "977", "output": "1" }, { "input": "23", "output": "1" }, { "input": "976", "output": "2" }, { "input": "24", "output": "1" }, { "input": "975", "output": "1" }, { "input": "25", "output": "1" }, { "input": "2", "output": "4" }, { "input": "6", "output": "4" }, { "input": "996", "output": "3" }, { "input": "8", "output": "1" }, { "input": "998", "output": "1" }, { "input": "330", "output": "5" }, { "input": "18", "output": "3" }, { "input": "12", "output": "2" }, { "input": "24", "output": "1" }, { "input": "999", "output": "1" }, { "input": "726", "output": "4" }, { "input": "876", "output": "3" } ]
1,683,795,678
2,147,483,647
PyPy 3-64
OK
TESTS
63
62
0
""" LINK: https://codeforces.com/problemset/problem/755/A Since (n * m + 1) (say x) as not very large, we find primes till x and then find m with brute-force such that x is not a prime COMPLEXITY: TC - O(nloglogn + m) for sieve + finding m SC - O(n*1000) for 'is_prime' """ def get_num1(n): max_val = n * 1000 + 1 is_prime = [True] * max_val for i in range(2, max_val): if not is_prime[i]: continue for j in range(i * i, max_val, i): is_prime[j] = False # Find m such that (n * m + 1) is not prime for m in range(1, 1001): if not is_prime[n * m + 1]: return m return -1 def get_num(n): if n == 1: return 3 if n == 2: return 4 return n - 2 print(get_num(int(input())))
Title: PolandBall and Hypothesis Time Limit: None seconds Memory Limit: None megabytes Problem Description: PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number". Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any *n*. Input Specification: The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. Output Specification: Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. Demo Input: ['3\n', '4\n'] Demo Output: ['1', '2'] Note: A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. For the first sample testcase, 3·1 + 1 = 4. We can output 1. In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not a prime number.
```python """ LINK: https://codeforces.com/problemset/problem/755/A Since (n * m + 1) (say x) as not very large, we find primes till x and then find m with brute-force such that x is not a prime COMPLEXITY: TC - O(nloglogn + m) for sieve + finding m SC - O(n*1000) for 'is_prime' """ def get_num1(n): max_val = n * 1000 + 1 is_prime = [True] * max_val for i in range(2, max_val): if not is_prime[i]: continue for j in range(i * i, max_val, i): is_prime[j] = False # Find m such that (n * m + 1) is not prime for m in range(1, 1001): if not is_prime[n * m + 1]: return m return -1 def get_num(n): if n == 1: return 3 if n == 2: return 4 return n - 2 print(get_num(int(input()))) ```
3
5
C
Longest Regular Bracket Sequence
PROGRAMMING
1,900
[ "constructive algorithms", "data structures", "dp", "greedy", "sortings", "strings" ]
C. Longest Regular Bracket Sequence
2
256
This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".
[ ")((())))(()())\n", "))(\n" ]
[ "6 2\n", "0 1\n" ]
none
0
[ { "input": ")((())))(()())", "output": "6 2" }, { "input": "))(", "output": "0 1" }, { "input": "()(())()", "output": "8 1" }, { "input": "((((()(((", "output": "2 1" }, { "input": "))))()())))", "output": "4 1" }, { "input": "(()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())()(((()())()(()((())()(())(()))", "output": "28 1" }, { "input": ")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))", "output": "68 1" }, { "input": "())(((((())())((((()))(())))())())(((()(()()()())(())()))((()(())())()()))()(()())))))(()))((())((((", "output": "80 1" }, { "input": "))(((((((()((((())(((((((((()()))))(()())()((())())))((((()))(()()()))))(()()))())))))((())())()))((", "output": "92 1" } ]
1,676,995,092
2,147,483,647
PyPy 3-64
OK
TESTS
43
746
82,227,200
s = input() res1, res2 = 0, 1 from collections import defaultdict hm = defaultdict(lambda:-2) hm[0] = -1 cur = 0 for i in range(len(s)): if s[i] == ')': cur -= 1 else: cur += 1 if hm[cur + 1] != -2: hm[cur + 1] = -2 if hm[cur] != -2: tmp = i - hm[cur] if tmp > res1: res1 = tmp res2 = 1 elif tmp == res1: res2 += 1 else: hm[cur] = i print(res1, res2)
Title: Longest Regular Bracket Sequence Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well. Input Specification: The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. Output Specification: Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". Demo Input: [')((())))(()())\n', '))(\n'] Demo Output: ['6 2\n', '0 1\n'] Note: none
```python s = input() res1, res2 = 0, 1 from collections import defaultdict hm = defaultdict(lambda:-2) hm[0] = -1 cur = 0 for i in range(len(s)): if s[i] == ')': cur -= 1 else: cur += 1 if hm[cur + 1] != -2: hm[cur + 1] = -2 if hm[cur] != -2: tmp = i - hm[cur] if tmp > res1: res1 = tmp res2 = 1 elif tmp == res1: res2 += 1 else: hm[cur] = i print(res1, res2) ```
3.66034
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,689,191,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
i = list(map(int, input().split(' '))) n, m, a = i[0], i[1], i[2] print(n * m / pow(a,2))
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 i = list(map(int, input().split(' '))) n, m, a = i[0], i[1], i[2] print(n * m / pow(a,2)) ```
0
544
B
Sea and Islands
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island). Find a way to cover some cells with sand so that exactly *k* islands appear on the *n*<=×<=*n* map, or determine that no such way exists.
The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form.
If the answer doesn't exist, print "NO" (without the quotes) in a single line. Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal *n*. If there are multiple answers, you may print any of them. You should not maximize the sizes of islands.
[ "5 2\n", "5 25\n" ]
[ "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n", "NO\n" ]
none
1,000
[ { "input": "5 2", "output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS" }, { "input": "5 25", "output": "NO" }, { "input": "82 6047", "output": "NO" }, { "input": "6 5", "output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS" }, { "input": "10 80", "output": "NO" }, { "input": "48 1279", "output": "NO" }, { "input": "40 1092", "output": "NO" }, { "input": "9 12", "output": "YES\nLSLSLSLSL\nSLSLSLSLS\nLSLSLSSSS\nSSSSSSSSS\nSSSSSSSSS\nSSSSSSSSS\nSSSSSSSSS\nSSSSSSSSS\nSSSSSSSSS" }, { "input": "43 146", "output": "YES\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSS..." }, { "input": "100 5000", "output": "YES\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS..." }, { "input": "100 4999", "output": "YES\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS..." }, { "input": "100 5001", "output": "NO" }, { "input": "99 4901", "output": "YES\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nS..." }, { "input": "99 4900", "output": "YES\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nS..." }, { "input": "99 4902", "output": "NO" }, { "input": "99 9801", "output": "NO" }, { "input": "99 10", "output": "YES\nLSLSLSLSLSLSLSLSLSLSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nS..." }, { "input": "99 1", "output": "YES\nLSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nS..." }, { "input": "100 10000", "output": "NO" }, { "input": "100 10", "output": "YES\nLSLSLSLSLSLSLSLSLSLSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS..." }, { "input": "50 1200", "output": "YES\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL..." }, { "input": "50 1438", "output": "NO" }, { "input": "50 2447", "output": "NO" }, { "input": "49 1719", "output": "NO" }, { "input": "51 1996", "output": "NO" }, { "input": "51 1981", "output": "NO" }, { "input": "34 1060", "output": "NO" }, { "input": "74 3901", "output": "NO" }, { "input": "65 617", "output": "YES\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS..." }, { "input": "89 497", "output": "YES\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS\nLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSL\nSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLS..." }, { "input": "34 621", "output": "NO" }, { "input": "1 0", "output": "YES\nS" }, { "input": "10 0", "output": "YES\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS" }, { "input": "11 0", "output": "YES\nSSSSSSSSSSS\nSSSSSSSSSSS\nSSSSSSSSSSS\nSSSSSSSSSSS\nSSSSSSSSSSS\nSSSSSSSSSSS\nSSSSSSSSSSS\nSSSSSSSSSSS\nSSSSSSSSSSS\nSSSSSSSSSSS\nSSSSSSSSSSS" }, { "input": "99 0", "output": "YES\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nS..." }, { "input": "100 0", "output": "YES\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS..." }, { "input": "1 1", "output": "YES\nL" }, { "input": "2 1", "output": "YES\nLS\nSS" }, { "input": "2 0", "output": "YES\nSS\nSS" }, { "input": "2 2", "output": "YES\nLS\nSL" }, { "input": "2 3", "output": "NO" }, { "input": "2 4", "output": "NO" } ]
1,431,819,383
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
__author__ = 'emcenrue' from math import pow n, k = list(map(int, input().split())) if k < pow(n, 2)/2: print("YES") for i in range(n): for j in range(n): if i%2 == 0 and j%2 == 0: print("S", end='') elif i%2 == 0 and j%2 == 1: print("L", end='') elif i%2 == 1 and j%2 == 0: print("L", end='') elif i%2 == 1 and j%2 == 1: print("S", end='') print() else: print("NO")
Title: Sea and Islands Time Limit: None seconds Memory Limit: None megabytes Problem Description: A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island). Find a way to cover some cells with sand so that exactly *k* islands appear on the *n*<=×<=*n* map, or determine that no such way exists. Input Specification: The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. Output Specification: If the answer doesn't exist, print "NO" (without the quotes) in a single line. Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal *n*. If there are multiple answers, you may print any of them. You should not maximize the sizes of islands. Demo Input: ['5 2\n', '5 25\n'] Demo Output: ['YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n', 'NO\n'] Note: none
```python __author__ = 'emcenrue' from math import pow n, k = list(map(int, input().split())) if k < pow(n, 2)/2: print("YES") for i in range(n): for j in range(n): if i%2 == 0 and j%2 == 0: print("S", end='') elif i%2 == 0 and j%2 == 1: print("L", end='') elif i%2 == 1 and j%2 == 0: print("L", end='') elif i%2 == 1 and j%2 == 1: print("S", end='') print() else: print("NO") ```
0
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task.
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": ".g.g.d.v.q" }, { "input": "pumesz", "output": ".p.m.s.z" }, { "input": "g", "output": ".g" }, { "input": "zjuotps", "output": ".z.j.t.p.s" }, { "input": "jzbwuehe", "output": ".j.z.b.w.h" }, { "input": "tnkgwuugu", "output": ".t.n.k.g.w.g" }, { "input": "kincenvizh", "output": ".k.n.c.n.v.z.h" }, { "input": "xattxjenual", "output": ".x.t.t.x.j.n.l" }, { "input": "ktajqhpqsvhw", "output": ".k.t.j.q.h.p.q.s.v.h.w" }, { "input": "xnhcigytnqcmy", "output": ".x.n.h.c.g.t.n.q.c.m" }, { "input": "jfmtbejyilxcec", "output": ".j.f.m.t.b.j.l.x.c.c" }, { "input": "D", "output": ".d" }, { "input": "ab", "output": ".b" }, { "input": "Ab", "output": ".b" }, { "input": "aB", "output": ".b" }, { "input": "AB", "output": ".b" }, { "input": "ba", "output": ".b" }, { "input": "bA", "output": ".b" }, { "input": "Ba", "output": ".b" }, { "input": "BA", "output": ".b" }, { "input": "aab", "output": ".b" }, { "input": "baa", "output": ".b" }, { "input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM", "output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m" }, { "input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN", "output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n" }, { "input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ", "output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j" }, { "input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea", "output": ".w.z.t.c.v.v.v.v.z.v" }, { "input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl", "output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l" }, { "input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg", "output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g" }, { "input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ", "output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q" }, { "input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg", "output": ".l.t.g.m.g" }, { "input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy", "output": ".k.z.d.x.f" }, { "input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ", "output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q" }, { "input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY", "output": ".m.r.c.g.p" }, { "input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx", "output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x" }, { "input": "YB", "output": ".b" }, { "input": "fly", "output": ".f.l" }, { "input": "YyyYYYyyYxdwdawdDAWDdaddYYYY", "output": ".x.d.w.d.w.d.d.w.d.d.d.d" } ]
1,696,248,746
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
60
0
s=input() v=["A","E","I","O","U","a","e","i","o","u","Y","y"] s1='' for i in s: if i not in v: s1=s1+"."+i print(s1)
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task. Input Specification: The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. Output Specification: Print the resulting string. It is guaranteed that this string is not empty. Demo Input: ['tour\n', 'Codeforces\n', 'aBAcAba\n'] Demo Output: ['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n'] Note: none
```python s=input() v=["A","E","I","O","U","a","e","i","o","u","Y","y"] s1='' for i in s: if i not in v: s1=s1+"."+i print(s1) ```
0
372
A
Counting Kangaroos is Fun
PROGRAMMING
1,600
[ "binary search", "greedy", "sortings", "two pointers" ]
null
null
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.
The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105).
Output a single integer — the optimal number of visible kangaroos.
[ "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "8\n9\n1\n6\n2\n6\n5\n8\n3\n" ]
[ "5\n", "5\n" ]
none
500
[ { "input": "8\n2\n5\n7\n6\n9\n8\n4\n2", "output": "5" }, { "input": "8\n9\n1\n6\n2\n6\n5\n8\n3", "output": "5" }, { "input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52", "output": "7" }, { "input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9", "output": "6" }, { "input": "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n267\n791\n595\n465\n8\n327\n855\n174\n339\n946\n184\n250\n807\n422\n679\n980\n64\n530\n312\n351\n676\n911\n803\n991\n669\n50\n293\n841\n545\n598\n737\n894\n231\n754\n588\n83\n873\n767\n833\n482\n905\n903\n970\n571\n715\n59\n777\n697\n537\n861\n339\n212\n149\n889\n905\n70\n970\n307\n830\n465\n968\n291\n430\n317\n942\n944\n330\n235\n814\n880\n415\n76", "output": "58" }, { "input": "100\n154\n60\n97\n638\n139\n150\n570\n579\n601\n647\n804\n237\n245\n549\n288\n347\n778\n282\n916\n441\n974\n145\n957\n886\n655\n702\n930\n618\n132\n520\n972\n48\n94\n54\n682\n433\n896\n134\n845\n636\n242\n842\n125\n141\n240\n130\n409\n666\n948\n938\n604\n110\n474\n484\n364\n40\n807\n271\n438\n288\n201\n814\n754\n589\n341\n576\n146\n952\n819\n923\n222\n535\n336\n83\n314\n911\n303\n911\n384\n601\n249\n330\n735\n271\n142\n204\n405\n783\n775\n449\n590\n139\n109\n276\n45\n205\n454\n836\n82\n841", "output": "50" }, { "input": "1\n1", "output": "1" }, { "input": "4\n1\n1\n1\n2", "output": "3" }, { "input": "5\n1\n2\n4\n8\n16", "output": "3" }, { "input": "7\n1\n2\n4\n8\n16\n32\n64", "output": "4" }, { "input": "3\n1\n2\n4", "output": "2" } ]
1,500,895,949
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
124
23,142,400
n = int(input()) s = [] for i in range(n): s.append(int(input())) s = sorted(s) x = len(s) - 1 z = x - 1 while(z != 0): if(s[x]/2 > s[z]): x -= 1 z -= 1 print(x)
Title: Counting Kangaroos is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input Specification: The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). Output Specification: Output a single integer — the optimal number of visible kangaroos. Demo Input: ['8\n2\n5\n7\n6\n9\n8\n4\n2\n', '8\n9\n1\n6\n2\n6\n5\n8\n3\n'] Demo Output: ['5\n', '5\n'] Note: none
```python n = int(input()) s = [] for i in range(n): s.append(int(input())) s = sorted(s) x = len(s) - 1 z = x - 1 while(z != 0): if(s[x]/2 > s[z]): x -= 1 z -= 1 print(x) ```
0
570
A
Elections
PROGRAMMING
1,100
[ "implementation" ]
null
null
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections.
The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively. Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes the number of votes for candidate *j* in city *i*. It is guaranteed that the total number of people in all the cities does not exceed 109.
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
[ "3 3\n1 2 3\n2 3 1\n1 2 1\n", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n" ]
[ "2", "1" ]
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
500
[ { "input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2" }, { "input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1" }, { "input": "1 3\n5\n3\n2", "output": "1" }, { "input": "3 1\n1 2 3", "output": "3" }, { "input": "3 1\n100 100 100", "output": "1" }, { "input": "2 2\n1 2\n2 1", "output": "1" }, { "input": "2 2\n2 1\n2 1", "output": "1" }, { "input": "2 2\n1 2\n1 2", "output": "2" }, { "input": "3 3\n0 0 0\n1 1 1\n2 2 2", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "5 5\n1 2 3 4 5\n2 3 4 5 6\n3 4 5 6 7\n4 5 6 7 8\n5 6 7 8 9", "output": "5" }, { "input": "4 4\n1 3 1 3\n3 1 3 1\n2 0 0 2\n0 1 1 0", "output": "1" }, { "input": "4 4\n1 4 1 3\n3 1 2 1\n1 0 0 2\n0 1 10 0", "output": "1" }, { "input": "4 4\n1 4 1 300\n3 1 2 1\n5 0 0 2\n0 1 10 100", "output": "1" }, { "input": "5 5\n15 45 15 300 10\n53 15 25 51 10\n5 50 50 2 10\n1000 1 10 100 10\n10 10 10 10 10", "output": "1" }, { "input": "1 100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "1" }, { "input": "100 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 1 1 1 1", "output": "1" }, { "input": "1 100\n859\n441\n272\n47\n355\n345\n612\n569\n545\n599\n410\n31\n720\n303\n58\n537\n561\n730\n288\n275\n446\n955\n195\n282\n153\n455\n996\n121\n267\n702\n769\n560\n353\n89\n990\n282\n801\n335\n573\n258\n722\n768\n324\n41\n249\n125\n557\n303\n664\n945\n156\n884\n985\n816\n433\n65\n976\n963\n85\n647\n46\n877\n665\n523\n714\n182\n377\n549\n994\n385\n184\n724\n447\n99\n766\n353\n494\n747\n324\n436\n915\n472\n879\n582\n928\n84\n627\n156\n972\n651\n159\n372\n70\n903\n590\n480\n184\n540\n270\n892", "output": "1" }, { "input": "100 1\n439 158 619 538 187 153 973 781 610 475 94 947 449 531 220 51 788 118 189 501 54 434 465 902 280 635 688 214 737 327 682 690 683 519 261 923 254 388 529 659 662 276 376 735 976 664 521 285 42 147 187 259 407 977 879 465 522 17 550 701 114 921 577 265 668 812 232 267 135 371 586 201 608 373 771 358 101 412 195 582 199 758 507 882 16 484 11 712 916 699 783 618 405 124 904 257 606 610 230 718", "output": "54" }, { "input": "1 99\n511\n642\n251\n30\n494\n128\n189\n324\n884\n656\n120\n616\n959\n328\n411\n933\n895\n350\n1\n838\n996\n761\n619\n131\n824\n751\n707\n688\n915\n115\n244\n476\n293\n986\n29\n787\n607\n259\n756\n864\n394\n465\n303\n387\n521\n582\n485\n355\n299\n997\n683\n472\n424\n948\n339\n383\n285\n957\n591\n203\n866\n79\n835\n980\n344\n493\n361\n159\n160\n947\n46\n362\n63\n553\n793\n754\n429\n494\n523\n227\n805\n313\n409\n243\n927\n350\n479\n971\n825\n460\n544\n235\n660\n327\n216\n729\n147\n671\n738", "output": "1" }, { "input": "99 1\n50 287 266 159 551 198 689 418 809 43 691 367 160 664 86 805 461 55 127 950 576 351 721 493 972 560 934 885 492 92 321 759 767 989 883 7 127 413 404 604 80 645 666 874 371 718 893 158 722 198 563 293 134 255 742 913 252 378 859 721 502 251 839 284 133 209 962 514 773 124 205 903 785 859 911 93 861 786 747 213 690 69 942 697 211 203 284 961 351 137 962 952 408 249 238 850 944 40 346", "output": "34" }, { "input": "100 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 1 1 1 2", "output": "100" }, { "input": "1 1\n0", "output": "1" }, { "input": "2 1\n0 0", "output": "1" }, { "input": "2 2\n0 0\n0 0", "output": "1" }, { "input": "2 2\n1 2\n0 0", "output": "1" }, { "input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "1" }, { "input": "2 3\n0 0\n0 0\n0 1", "output": "1" }, { "input": "3 2\n1 1 3\n0 0 0", "output": "1" }, { "input": "3 4\n1 10 3\n0 0 0\n0 0 0\n0 0 0", "output": "1" }, { "input": "2 4\n2 1\n1 2\n0 0\n1 2", "output": "1" }, { "input": "2 2\n0 1\n0 1", "output": "2" }, { "input": "2 3\n1 2\n0 0\n2 1", "output": "1" }, { "input": "2 2\n0 0\n4 5", "output": "1" }, { "input": "3 2\n10 15 20\n0 0 0", "output": "1" }, { "input": "3 4\n0 0 0\n0 0 0\n0 0 0\n1 2 3", "output": "1" }, { "input": "3 3\n0 0 0\n0 0 0\n0 0 1", "output": "1" }, { "input": "3 3\n0 0 0\n1 2 3\n1 3 2", "output": "1" }, { "input": "3 1\n0 0 0", "output": "1" }, { "input": "3 3\n0 0 1\n0 0 0\n0 0 0", "output": "1" } ]
1,512,963,036
2,147,483,647
Python 3
OK
TESTS
62
62
5,632,000
n,m = map(int,input().split()) count = [0]*n for i in range(m): vote = list(map(int,input().split())) count[vote.index(max(vote))] += 1 print(count.index(max(count))+1)
Title: Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input Specification: The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively. Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes the number of votes for candidate *j* in city *i*. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Specification: Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Demo Input: ['3 3\n1 2 3\n2 3 1\n1 2 1\n', '3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n'] Demo Output: ['2', '1'] Note: Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
```python n,m = map(int,input().split()) count = [0]*n for i in range(m): vote = list(map(int,input().split())) count[vote.index(max(vote))] += 1 print(count.index(max(count))+1) ```
3
825
B
Five-In-a-Row
PROGRAMMING
1,600
[ "brute force", "implementation" ]
null
null
Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.
You are given matrix 10<=×<=10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won.
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
[ "XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X", "output": "NO" }, { "input": "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.", "output": "NO" }, { "input": "..O..X.X..\n.O..X...O.\n........O.\n...O..O...\nX.XX....X.\n..O....O.X\n..X.X....O\n......X..X\nO.........\n..X.O...OO", "output": "NO" }, { "input": "..........\n..........\n..........\n..........\n..........\nX.........\n.........X\n..........\n..O.......\n.O...X...O", "output": "NO" }, { "input": ".OXXOOOXXO\nXOX.O.X.O.\nXX.X...OXX\nOOOX......\nX.OX.X.O..\nX.O...O.O.\n.OXOXOO...\nOO.XOOX...\nO..XX...XX\nXX.OXXOOXO", "output": "YES" }, { "input": ".OX.XX.OOO\n..OXXOXOO.\nX..XXXOO.X\nXOX.O.OXOX\nO.O.X.XX.O\nOXXXOXXOXX\nO.OOO...XO\nO.X....OXX\nXO...XXO.O\nXOX.OOO.OX", "output": "YES" }, { "input": "....X.....\n...X......\n..........\n.X........\nX.........\n..........\n..........\n..........\n..........\n......OOOO", "output": "YES" }, { "input": "..........\n..........\n..........\n..........\n..........\n....X.....\n...X.....O\n.........O\n.X.......O\nX........O", "output": "YES" }, { "input": "OOOO......\n..........\n..........\n..........\n..........\n..........\n......X...\n.......X..\n........X.\n.........X", "output": "YES" }, { "input": "..........\n..........\n..........\n..........\n..........\n..........\n......X...\nOOOO...X..\n........X.\n.........X", "output": "YES" }, { "input": "..........\n.........X\n........X.\n.......X..\n......X...\n..........\n..........\n..........\n..........\n......OOOO", "output": "YES" }, { "input": "..........\n......OOO.\n..........\n..........\n..........\n.....O....\n......X...\n.......X..\n........X.\n.........X", "output": "NO" }, { "input": ".........X\n........X.\n.......X..\n......X...\n..........\n..........\n..........\n..........\n..........\n......OOOO", "output": "YES" }, { "input": "..........\n..........\n..........\n.....X....\n....X.....\n...X......\n.........O\n.X.......O\n.........O\n.........O", "output": "YES" }, { "input": ".X........\n..........\n...X......\n....X.....\n.....X....\n..........\n..........\n..........\n..........\n......OOOO", "output": "YES" }, { "input": "O.........\nOO........\nOOO.......\nOOO.......\n..........\n......O.OO\n.....OXXXX\n.....OXXXX\n.....OXXXX\n.....OXXXX", "output": "YES" }, { "input": ".XX.....X.\n.X...O.X..\n.O........\n.....X....\n.X..XO.O..\n.X........\n.X.......O\n.........O\n..O.......\n..O....O.O", "output": "YES" }, { "input": ".........X\n........X.\n.......X..\n..........\n.....X....\n..........\n..........\n..........\n..........\n......OOOO", "output": "YES" }, { "input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n.........X\n.........X\n.........X\n.........X", "output": "YES" }, { "input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n......X...\n.......X..\n........X.\n.........X", "output": "YES" }, { "input": ".XX.....X.\n.X...O.X.X\n.O........\n.....X....\n.X..XO.O..\n.X........\n.X.......O\nO........O\n..O.......\n..O....O.O", "output": "YES" }, { "input": "..........\n..........\n..........\n..........\n..........\n..O......X\n..O......X\n..O.......\n..O......X\n.........X", "output": "YES" }, { "input": "..........\n..........\n..O.......\n...O......\n....O.....\n.....O....\n......X...\n.......X..\n........X.\n.........X", "output": "NO" }, { "input": "OOO...O...\n.X...X.O..\n...O.XXX.O\n.O..XOX.X.\n..O.XXX.O.\n..X.OO.O..\n.OOXXOXXO.\n.OOX.OX.X.\n.XXX....XX\n.OO...OXO.", "output": "YES" }, { "input": "..........\n.........O\n.........O\n.........O\n.........O\n..........\n.........X\n.........X\n.........X\n.........X", "output": "YES" }, { "input": ".....OXXXX\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n......OOO.", "output": "NO" }, { "input": "..........\n.....OOOO.\n.......OO.\n..........\n..........\n..........\n..........\n.......X..\n........X.\n......XXXX", "output": "YES" }, { "input": "X.XX..XXXX\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\nOOO.O.O.OO", "output": "YES" }, { "input": ".....OXXXX\n..........\n..........\n..........\n..........\n.....O....\nOOO...X...\nOOOO...X..\n........X.\n....X....X", "output": "NO" }, { "input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n......XXXX", "output": "YES" }, { "input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n...X.X.X.X", "output": "NO" }, { "input": ".....O....\n....X..O.O\n...X.....O\n..X.......\n.X.......O\n..........\n..........\n..........\n..........\n.........X", "output": "YES" }, { "input": "....X.....\n...X......\n..X.......\n.X........\n..........\n..........\n..........\n..........\n..........\n......OOOO", "output": "YES" }, { "input": ".......XXX\nX.........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n......OOOO", "output": "NO" } ]
1,516,691,216
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
12
62
5,632,000
t = [] for i in range(10): t.append(input()) for i in range(10): s = '' for j in range(10): s = s + t[i][j] t.append(s) for i in range(6): s = '' for j in range(10 - i): s = s + t[i + j][j] t.append(s) for i in range(1, 6): s = '' for j in range(10 - i): s = s + t[j][i + j] t.append(s) for i in range(6): s = '' for j in range(10 - i): s = s + t[i + j][9 - j] t.append(s) for i in range(1, 6): s = '' for j in range(10 - i): s = s + t[j][9 - j - i] t.append(s) for line in t: x, o, dot, f = 0, 0, 0, 0 for i in range(5): if line[i] == 'X': x += 1 elif line[i] == 'O': o += 1 elif line[i] == '.': dot += 1 if x == 4 and dot == 1: print('YES') f = 1 break for i in range(5, len(line)): if line[i - 5] == 'X': x -= 1 elif line[i - 5] == 'O': o -= 1 elif line[i - 5] == '.': dot -= 1 if line[i] == 'X': x += 1 elif line[i] == 'O': o += 1 elif line[i] == '.': dot += 1 if x == 4 and dot == 1: print('YES') f = 1 break if f: break if not f: print('NO')
Title: Five-In-a-Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. Input Specification: You are given matrix 10<=×<=10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. Output Specification: Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. Demo Input: ['XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n', 'XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python t = [] for i in range(10): t.append(input()) for i in range(10): s = '' for j in range(10): s = s + t[i][j] t.append(s) for i in range(6): s = '' for j in range(10 - i): s = s + t[i + j][j] t.append(s) for i in range(1, 6): s = '' for j in range(10 - i): s = s + t[j][i + j] t.append(s) for i in range(6): s = '' for j in range(10 - i): s = s + t[i + j][9 - j] t.append(s) for i in range(1, 6): s = '' for j in range(10 - i): s = s + t[j][9 - j - i] t.append(s) for line in t: x, o, dot, f = 0, 0, 0, 0 for i in range(5): if line[i] == 'X': x += 1 elif line[i] == 'O': o += 1 elif line[i] == '.': dot += 1 if x == 4 and dot == 1: print('YES') f = 1 break for i in range(5, len(line)): if line[i - 5] == 'X': x -= 1 elif line[i - 5] == 'O': o -= 1 elif line[i - 5] == '.': dot -= 1 if line[i] == 'X': x += 1 elif line[i] == 'O': o += 1 elif line[i] == '.': dot += 1 if x == 4 and dot == 1: print('YES') f = 1 break if f: break if not f: print('NO') ```
0
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "input": "H", "output": "YES" }, { "input": "+", "output": "NO" }, { "input": "~", "output": "NO" }, { "input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "output": "YES" }, { "input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "output": "YES" }, { "input": "@F%K2=%RyL/", "output": "NO" }, { "input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "output": "YES" }, { "input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)", "output": "YES" }, { "input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C", "output": "YES" }, { "input": "p-UXsbd&f", "output": "NO" }, { "input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_", "output": "YES" }, { "input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]", "output": "YES" }, { "input": "}do5RU<(w<q[\"-NR)IAH_HyiD{", "output": "YES" }, { "input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8", "output": "YES" }, { "input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv", "output": "YES" }, { "input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`", "output": "YES" }, { "input": "OKBB5z7ud81[Tn@P\"nDUd,>@", "output": "NO" }, { "input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv", "output": "YES" }, { "input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh", "output": "YES" }, { "input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp", "output": "NO" }, { "input": "!3YPv@2JQ44@)R2O_4`GO", "output": "YES" }, { "input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\", "output": "YES" }, { "input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L", "output": "NO" }, { "input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&", "output": "YES" }, { "input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}", "output": "YES" }, { "input": "Uh3>ER](J", "output": "NO" }, { "input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,", "output": "YES" }, { "input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!", "output": "YES" }, { "input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@", "output": "YES" }, { "input": "'jdL(vX", "output": "NO" }, { "input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5", "output": "YES" }, { "input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s", "output": "YES" }, { "input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]", "output": "YES" }, { "input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU", "output": "YES" }, { "input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->", "output": "YES" }, { "input": "&ppw0._:\\p-PuWM@l}%%=", "output": "NO" }, { "input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr", "output": "YES" }, { "input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q", "output": "YES" }, { "input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0", "output": "YES" }, { "input": "VXB&r9Z)IlKOJ:??KDA", "output": "YES" }, { "input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R", "output": "YES" }, { "input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C", "output": "YES" }, { "input": "O.&=qt(`z(", "output": "NO" }, { "input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@", "output": "YES" }, { "input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp", "output": "YES" }, { "input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8", "output": "YES" }, { "input": "!0WKT:$O", "output": "NO" }, { "input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)", "output": "YES" }, { "input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly", "output": "YES" }, { "input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(", "output": "NO" }, { "input": "Qv)X8", "output": "YES" }, { "input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F", "output": "YES" }, { "input": "e{}2vQ+/r@p0}cLKNe4MCk", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH", "output": "YES" }, { "input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "1H1", "output": "YES" }, { "input": "+Q", "output": "YES" }, { "input": "1ab", "output": "NO" }, { "input": "!", "output": "NO" }, { "input": "0+", "output": "NO" }, { "input": "+H", "output": "YES" }, { "input": "cH", "output": "YES" }, { "input": "+8", "output": "NO" }, { "input": "8+", "output": "NO" }, { "input": "++++++++++++++++++++++++++", "output": "NO" }, { "input": "(+)", "output": "NO" }, { "input": "H+", "output": "YES" }, { "input": "a!", "output": "NO" }, { "input": "++++++++++++++", "output": "NO" }, { "input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "HQ9", "output": "YES" }, { "input": "+++H", "output": "YES" }, { "input": "++++++++++", "output": "NO" }, { "input": "HHHHHHH", "output": "YES" }, { "input": "abacabaH", "output": "YES" }, { "input": "+G", "output": "NO" } ]
1,687,794,025
2,147,483,647
PyPy 3-64
OK
TESTS
85
124
0
a=input() l=['H','Q','9'] s=0 for i in a: if i in l: print("YES") s+=1 break if(s==0): print("NO")
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. Input Specification: The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. Output Specification: Output "YES", if executing the program will produce any output, and "NO" otherwise. Demo Input: ['Hi!\n', 'Codeforces\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
```python a=input() l=['H','Q','9'] s=0 for i in a: if i in l: print("YES") s+=1 break if(s==0): print("NO") ```
3
678
C
Joty and Chocolate
PROGRAMMING
1,600
[ "implementation", "math", "number theory" ]
null
null
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue. After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue. Note that she can paint tiles in any order she wants. Given the required information, find the maximum number of chocolates Joty can get.
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109).
Print the only integer *s* — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "5 2 3 12 15\n", "20 2 3 3 5\n" ]
[ "39\n", "51\n" ]
none
0
[ { "input": "5 2 3 12 15", "output": "39" }, { "input": "20 2 3 3 5", "output": "51" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "1 2 2 2 2", "output": "0" }, { "input": "2 1 3 3 3", "output": "6" }, { "input": "3 1 1 3 3", "output": "9" }, { "input": "4 1 5 4 3", "output": "16" }, { "input": "8 8 1 1 1", "output": "8" }, { "input": "15 14 32 65 28", "output": "65" }, { "input": "894 197 325 232 902", "output": "2732" }, { "input": "8581 6058 3019 2151 4140", "output": "10431" }, { "input": "41764 97259 54586 18013 75415", "output": "0" }, { "input": "333625 453145 800800 907251 446081", "output": "0" }, { "input": "4394826 2233224 609367 3364334 898489", "output": "9653757" }, { "input": "13350712 76770926 61331309 8735000 9057368", "output": "0" }, { "input": "142098087 687355301 987788392 75187408 868856364", "output": "0" }, { "input": "1000000000 1 3 1000000000 999999999", "output": "1000000000000000000" }, { "input": "6 6 2 8 2", "output": "12" }, { "input": "500 8 4 4 5", "output": "625" }, { "input": "20 4 6 2 3", "output": "17" }, { "input": "10 3 9 1 2", "output": "4" }, { "input": "120 18 6 3 5", "output": "100" }, { "input": "30 4 6 2 2", "output": "20" }, { "input": "1000000000 7171 2727 191 272", "output": "125391842" }, { "input": "5 2 2 4 1", "output": "8" }, { "input": "1000000000 2 2 3 3", "output": "1500000000" }, { "input": "24 4 6 5 7", "output": "48" }, { "input": "216 6 36 10 100", "output": "900" }, { "input": "100 12 6 1 10", "output": "160" }, { "input": "1000 4 8 3 5", "output": "1000" }, { "input": "10 2 4 3 6", "output": "21" }, { "input": "1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "10 5 10 2 3", "output": "5" }, { "input": "100000 3 9 1 2", "output": "44444" }, { "input": "10 2 4 1 100", "output": "203" }, { "input": "20 6 4 2 3", "output": "19" }, { "input": "1200 4 16 2 3", "output": "675" }, { "input": "7 2 4 7 9", "output": "23" }, { "input": "24 6 4 15 10", "output": "100" }, { "input": "50 2 8 15 13", "output": "375" }, { "input": "100 4 6 12 15", "output": "444" }, { "input": "56756 9 18 56 78", "output": "422502" }, { "input": "10000 4 6 10 12", "output": "36662" }, { "input": "20 2 4 3 5", "output": "40" }, { "input": "24 4 6 10 100", "output": "440" }, { "input": "12 2 4 5 6", "output": "33" }, { "input": "100 2 4 1 100", "output": "2525" }, { "input": "1000 4 6 50 50", "output": "16650" }, { "input": "60 12 6 12 15", "output": "150" }, { "input": "1000 2 4 5 6", "output": "2750" }, { "input": "1000000000 1 1 9999 5555", "output": "9999000000000" }, { "input": "50 2 2 4 5", "output": "125" }, { "input": "14 4 2 2 3", "output": "21" }, { "input": "100 3 9 1 2", "output": "44" }, { "input": "1000000000 4 6 1 1000000000", "output": "166666666166666667" }, { "input": "12 3 3 45 4", "output": "180" }, { "input": "12 2 4 5 9", "output": "42" }, { "input": "1000000000 2 2 1000000000 1000000000", "output": "500000000000000000" }, { "input": "50 4 8 5 6", "output": "66" }, { "input": "32 4 16 6 3", "output": "48" }, { "input": "10000 2 4 1 1", "output": "5000" }, { "input": "8 2 4 100 1", "output": "400" }, { "input": "20 4 2 10 1", "output": "55" }, { "input": "5 2 2 12 15", "output": "30" }, { "input": "20 2 12 5 6", "output": "51" }, { "input": "10 2 4 1 2", "output": "7" }, { "input": "32 4 16 3 6", "output": "30" }, { "input": "50 2 8 13 15", "output": "337" }, { "input": "12 6 4 10 9", "output": "38" }, { "input": "1000000000 999999998 999999999 999999998 999999999", "output": "1999999997" }, { "input": "20 2 4 10 20", "output": "150" }, { "input": "13 4 6 12 15", "output": "54" }, { "input": "30 3 6 5 7", "output": "60" }, { "input": "7 2 4 2 1", "output": "6" }, { "input": "100000 32 16 2 3", "output": "18750" }, { "input": "6 2 6 1 1", "output": "3" }, { "input": "999999999 180 192 46642017 28801397", "output": "399129078526502" }, { "input": "12 4 6 1 1", "output": "4" }, { "input": "10 2 4 10 5", "output": "50" }, { "input": "1000000 4 6 12 14", "output": "4333328" }, { "input": "2000 20 30 3 5", "output": "531" }, { "input": "1000000000 1 2 1 1", "output": "1000000000" }, { "input": "30 3 15 10 3", "output": "100" }, { "input": "1000 2 4 1 100", "output": "25250" }, { "input": "6 3 3 12 15", "output": "30" }, { "input": "24 4 6 1 1", "output": "8" }, { "input": "20 2 12 4 5", "output": "41" }, { "input": "1000000000 9 15 10 10", "output": "1555555550" }, { "input": "16 2 4 1 2", "output": "12" }, { "input": "100000 4 6 12 14", "output": "433328" }, { "input": "24 6 4 1 1", "output": "8" }, { "input": "1000000 4 6 12 15", "output": "4499994" }, { "input": "100 2 4 5 6", "output": "275" }, { "input": "10 3 9 12 15", "output": "39" }, { "input": "1000000000 1 1 999999999 999999999", "output": "999999999000000000" }, { "input": "6 2 4 2 3", "output": "7" }, { "input": "2 2 2 2 2", "output": "2" }, { "input": "6 6 2 1 1", "output": "3" }, { "input": "100 2 4 3 7", "output": "250" }, { "input": "1000000 32 16 2 5", "output": "312500" }, { "input": "100 20 15 50 25", "output": "375" }, { "input": "1000000000 100000007 100000013 10 3", "output": "117" }, { "input": "1000000000 9999999 99999998 3 3", "output": "330" }, { "input": "10077696 24 36 10 100", "output": "30792960" }, { "input": "392852503 148746166 420198270 517065752 906699795", "output": "1034131504" }, { "input": "536870912 60000 72000 271828 314159", "output": "4369119072" }, { "input": "730114139 21550542 204644733 680083361 11353255", "output": "22476810678" }, { "input": "538228881 766493289 791886544 468896052 600136703", "output": "0" }, { "input": "190 20 50 84 172", "output": "1188" }, { "input": "1000 5 10 80 90", "output": "17000" }, { "input": "99999999 999999998 1 271828 314159", "output": "31415899685841" }, { "input": "22 3 6 1243 1", "output": "8701" }, { "input": "15 10 5 2 2", "output": "6" }, { "input": "1000000000 1000000000 1 1000000000 1000000000", "output": "1000000000000000000" }, { "input": "62 62 42 78 124", "output": "202" }, { "input": "2 2 2 2 1", "output": "2" }, { "input": "864351351 351 313 531 11", "output": "1337898227" }, { "input": "26 3 6 1244 1", "output": "9952" }, { "input": "1000 4 6 7 3", "output": "1999" }, { "input": "134312 3 6 33333 1", "output": "1492318410" }, { "input": "100 4 6 17 18", "output": "577" }, { "input": "6 2 4 5 6", "output": "16" }, { "input": "8 2 4 10 1", "output": "40" }, { "input": "10 2 4 3 3", "output": "15" }, { "input": "1000 1000 1000 1000 1000", "output": "1000" }, { "input": "123123 3 6 34312 2", "output": "1408198792" }, { "input": "1000000000 25 5 999 999", "output": "199800000000" }, { "input": "100 4 2 5 12", "output": "600" }, { "input": "50 2 4 4 5", "output": "112" }, { "input": "24 4 6 100 333", "output": "1732" }, { "input": "216 24 36 10 100", "output": "660" }, { "input": "50 6 4 3 8", "output": "108" }, { "input": "146 76 2 178 192", "output": "14016" }, { "input": "55 8 6 11 20", "output": "224" }, { "input": "5 2 4 6 16", "output": "22" }, { "input": "54 2 52 50 188", "output": "1488" }, { "input": "536870912 60000000 72000000 271828 314159", "output": "4101909" }, { "input": "1000000000 1000000000 1 1 100", "output": "100000000000" }, { "input": "50 4 2 4 5", "output": "125" }, { "input": "198 56 56 122 118", "output": "366" }, { "input": "5 1000000000 1 12 15", "output": "75" }, { "input": "1000 6 12 5 6", "output": "913" }, { "input": "50 3 6 12 15", "output": "216" }, { "input": "333 300 300 300 300", "output": "300" }, { "input": "1 1000000000 1 1 2", "output": "2" }, { "input": "188 110 110 200 78", "output": "200" }, { "input": "100000 20 10 3 2", "output": "25000" }, { "input": "100 2 4 1 10", "output": "275" }, { "input": "1000000000 2 1000000000 1 1000000", "output": "500999999" }, { "input": "20 3 6 5 7", "output": "36" }, { "input": "50 4 6 4 5", "output": "72" }, { "input": "96 46 4 174 156", "output": "3936" }, { "input": "5 2 4 12 15", "output": "27" }, { "input": "12 3 6 100 1", "output": "400" }, { "input": "100 4 2 10 32", "output": "1600" }, { "input": "1232 3 6 30000 3", "output": "12300000" }, { "input": "20 3 6 5 4", "output": "30" }, { "input": "100 6 15 11 29", "output": "317" }, { "input": "10000000 4 8 100 200", "output": "375000000" }, { "input": "1000000000 12 24 2 4", "output": "249999998" }, { "input": "123 3 6 3000 1", "output": "123000" }, { "input": "401523968 1536 2664 271828 314159", "output": "117768531682" }, { "input": "9 2 4 3 5", "output": "16" }, { "input": "999999999 724362018 772432019 46201854 20017479", "output": "66219333" }, { "input": "100 2 4 1 1000", "output": "25025" }, { "input": "50 2 4 1 1000", "output": "12013" }, { "input": "1000000000 2 1 2 1", "output": "1500000000" }, { "input": "1000000000 2005034 2005046 15 12", "output": "13446" }, { "input": "1000000000 999999999 1000000000 1 1", "output": "2" }, { "input": "999999999 500000000 1 100 1000", "output": "999999999000" }, { "input": "50 8 6 3 4", "output": "44" }, { "input": "1000000000 1 1 1000000000 1000000000", "output": "1000000000000000000" }, { "input": "1000000000 999999862 999999818 15 12", "output": "27" }, { "input": "1000000000 10000019 10000019 21 17", "output": "2079" }, { "input": "20 6 4 8 2", "output": "32" }, { "input": "1000000000 1000000000 1 1 1", "output": "1000000000" }, { "input": "1000000000 12345678 123456789 1000000000 999999999", "output": "88999999992" }, { "input": "1000000000 2 999999937 100000000 100000000", "output": "50000000100000000" }, { "input": "1000000000 1 1 1000000000 999999999", "output": "1000000000000000000" }, { "input": "1000000000 50001 100003 10 10", "output": "299980" }, { "input": "1000000000 1000000000 3 1 1", "output": "333333334" }, { "input": "10000 44 49 114 514", "output": "130278" }, { "input": "30 5 15 2 1", "output": "12" }, { "input": "20 2 4 1 1", "output": "10" }, { "input": "100 8 12 5 6", "output": "88" } ]
1,477,589,175
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
liste = input().split(" ") n = int(liste[0]) a = int(liste[1]) b = int(liste[2]) p = int(liste[3]) q = int(liste[4]) m = max(p,q) res = 0 for i in range (1,n+1) : auxa = False auxb = False if i % a == 0 : auxa = True if i % b == 0 : auxb = True if auxa and auxb : res += m else : if auxa : res += p elif auxb : res += q print(i,res) print(res)
Title: Joty and Chocolate Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue. After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue. Note that she can paint tiles in any order she wants. Given the required information, find the maximum number of chocolates Joty can get. Input Specification: The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). Output Specification: Print the only integer *s* — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Demo Input: ['5 2 3 12 15\n', '20 2 3 3 5\n'] Demo Output: ['39\n', '51\n'] Note: none
```python liste = input().split(" ") n = int(liste[0]) a = int(liste[1]) b = int(liste[2]) p = int(liste[3]) q = int(liste[4]) m = max(p,q) res = 0 for i in range (1,n+1) : auxa = False auxb = False if i % a == 0 : auxa = True if i % b == 0 : auxb = True if auxa and auxb : res += m else : if auxa : res += p elif auxb : res += q print(i,res) print(res) ```
0
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n1305" }, { "input": "100\n901\n712\n3\n677\n652\n757\n963\n134\n205\n888\n847\n283\n591\n984\n1\n61\n540\n986\n950\n729\n104\n244\n500\n461\n251\n685\n631\n803\n526\n600\n1000\n899\n411\n219\n597\n342\n771\n348\n507\n775\n454\n102\n486\n333\n580\n431\n537\n355\n624\n23\n429\n276\n84\n704\n96\n536\n855\n653\n72\n718\n776\n658\n802\n777\n995\n285\n328\n405\n184\n555\n956\n410\n846\n853\n525\n983\n65\n549\n839\n929\n620\n725\n635\n303\n201\n878\n580\n139\n182\n69\n400\n788\n985\n792\n103\n248\n570\n839\n253\n417", "output": "404305\n251782\n0\n227457\n210832\n284857\n462120\n8535\n20605\n392670\n357082\n39164\n172890\n482574\n-1\n1765\n144024\n484545\n449679\n264039\n5206\n29380\n124228\n105469\n31116\n232909\n197350\n320760\n136555\n178254\n498454\n402504\n83644\n23580\n176457\n57631\n295560\n59704\n127756\n298654\n102263\n4999\n117319\n54589\n166444\n92074\n142407\n62168\n192954\n214\n91213\n37204\n3316\n246114\n4402\n141870\n363894\n211485\n2374\n256075\n299430\n214765\n319957\n300207\n493464\n39733\n52934\n81193\n16510\n15..." }, { "input": "1\n16", "output": "74" }, { "input": "60\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457", "output": "144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875..." }, { "input": "13\n1\n19\n31\n19\n19\n92\n74\n69\n32\n32\n91\n42\n73", "output": "-1\n128\n434\n128\n128\n4024\n2521\n2161\n402\n402\n3932\n777\n2447" }, { "input": "1\n16383", "output": "134176770" }, { "input": "16\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100", "output": "5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908" }, { "input": "1\n414234", "output": "85794061921" }, { "input": "1\n414232", "output": "85793233454" }, { "input": "3\n414231\n414231\n414231", "output": "85792819222\n85792819222\n85792819222" }, { "input": "1\n121", "output": "7127" } ]
1,671,632,528
2,147,483,647
PyPy 3-64
OK
TESTS
21
92
1,536,000
from math import log2 as log for _ in range(int(input())): n = int(input()) s = ((1 + n) * n) // 2 count_of2 = int(log(n)) # print(s) for i in range(0, count_of2 + 1): # print(s) s -= 2 * (2 ** i) print(s)
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*. Input Specification: The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the requested sum for each of *t* integers *n* given in the input. Demo Input: ['2\n4\n1000000000\n'] Demo Output: ['-4\n499999998352516354\n'] Note: The answer for the first sample is explained in the statement.
```python from math import log2 as log for _ in range(int(input())): n = int(input()) s = ((1 + n) * n) // 2 count_of2 = int(log(n)) # print(s) for i in range(0, count_of2 + 1): # print(s) s -= 2 * (2 ** i) print(s) ```
3
811
A
Vladik and Courtesy
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
[ "1 1\n", "7 6\n" ]
[ "Valera\n", "Vladik\n" ]
Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "1 1", "output": "Valera" }, { "input": "7 6", "output": "Vladik" }, { "input": "25 38", "output": "Vladik" }, { "input": "8311 2468", "output": "Valera" }, { "input": "250708 857756", "output": "Vladik" }, { "input": "957985574 24997558", "output": "Valera" }, { "input": "999963734 999994456", "output": "Vladik" }, { "input": "1000000000 1000000000", "output": "Vladik" }, { "input": "946 879", "output": "Valera" }, { "input": "10819 45238", "output": "Vladik" }, { "input": "101357 236928", "output": "Vladik" }, { "input": "1033090 7376359", "output": "Vladik" }, { "input": "9754309 9525494", "output": "Valera" }, { "input": "90706344 99960537", "output": "Vladik" }, { "input": "965161805 908862070", "output": "Valera" }, { "input": "9 11", "output": "Valera" }, { "input": "3 2", "output": "Vladik" }, { "input": "6 6", "output": "Vladik" }, { "input": "4 4", "output": "Valera" }, { "input": "5 5", "output": "Valera" }, { "input": "5 4", "output": "Valera" }, { "input": "12345680 1", "output": "Valera" }, { "input": "9 10", "output": "Valera" }, { "input": "678 76687", "output": "Vladik" }, { "input": "1 678", "output": "Vladik" }, { "input": "45 1678", "output": "Vladik" }, { "input": "3 3", "output": "Vladik" }, { "input": "10 11", "output": "Valera" }, { "input": "2 1", "output": "Valera" }, { "input": "1 2", "output": "Vladik" }, { "input": "2 2", "output": "Vladik" }, { "input": "4 5", "output": "Valera" }, { "input": "9 6", "output": "Valera" }, { "input": "1 5", "output": "Vladik" }, { "input": "7 8", "output": "Vladik" }, { "input": "1000000000 999982505", "output": "Valera" }, { "input": "12 12", "output": "Vladik" }, { "input": "1000 950", "output": "Valera" }, { "input": "10 9", "output": "Valera" }, { "input": "100 9", "output": "Valera" }, { "input": "1000 996", "output": "Vladik" }, { "input": "9 5", "output": "Valera" } ]
1,624,522,945
2,147,483,647
Python 3
OK
TESTS
42
62
0
a , b = map(int,input().split()) i = 1 while 1: if(i&1): if(a >= i): a -= i else : print("Vladik") break else : if( b >= i): b -= i else : print("Valera") break i +=1
Title: Vladik and Courtesy Time Limit: None seconds Memory Limit: None megabytes Problem Description: At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Specification: Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. Output Specification: Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Demo Input: ['1 1\n', '7 6\n'] Demo Output: ['Valera\n', 'Vladik\n'] Note: Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python a , b = map(int,input().split()) i = 1 while 1: if(i&1): if(a >= i): a -= i else : print("Vladik") break else : if( b >= i): b -= i else : print("Valera") break i +=1 ```
3
259
B
Little Elephant and Magic Square
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes.
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions.
[ "0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n" ]
[ "1 1 1\n1 1 1\n1 1 1\n", "6 3 6\n5 5 5\n4 7 4\n" ]
none
1,000
[ { "input": "0 1 1\n1 0 1\n1 1 0", "output": "1 1 1\n1 1 1\n1 1 1" }, { "input": "0 3 6\n5 0 5\n4 7 0", "output": "6 3 6\n5 5 5\n4 7 4" }, { "input": "0 4 4\n4 0 4\n4 4 0", "output": "4 4 4\n4 4 4\n4 4 4" }, { "input": "0 54 48\n36 0 78\n66 60 0", "output": "69 54 48\n36 57 78\n66 60 45" }, { "input": "0 17 14\n15 0 15\n16 13 0", "output": "14 17 14\n15 15 15\n16 13 16" }, { "input": "0 97 56\n69 0 71\n84 43 0", "output": "57 97 56\n69 70 71\n84 43 83" }, { "input": "0 1099 1002\n1027 0 1049\n1074 977 0", "output": "1013 1099 1002\n1027 1038 1049\n1074 977 1063" }, { "input": "0 98721 99776\n99575 0 99123\n98922 99977 0", "output": "99550 98721 99776\n99575 99349 99123\n98922 99977 99148" }, { "input": "0 6361 2304\n1433 0 8103\n7232 3175 0", "output": "5639 6361 2304\n1433 4768 8103\n7232 3175 3897" }, { "input": "0 99626 99582\n99766 0 99258\n99442 99398 0", "output": "99328 99626 99582\n99766 99512 99258\n99442 99398 99696" }, { "input": "0 99978 99920\n99950 0 99918\n99948 99890 0", "output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964" }, { "input": "0 840 666\n612 0 948\n894 720 0", "output": "834 840 666\n612 780 948\n894 720 726" }, { "input": "0 28 10\n12 0 24\n26 8 0", "output": "16 28 10\n12 18 24\n26 8 20" }, { "input": "0 120 83\n98 0 90\n105 68 0", "output": "79 120 83\n98 94 90\n105 68 109" }, { "input": "0 86900 85807\n85836 0 86842\n86871 85778 0", "output": "86310 86900 85807\n85836 86339 86842\n86871 85778 86368" }, { "input": "0 74 78\n78 0 74\n74 78 0", "output": "76 74 78\n78 76 74\n74 78 76" }, { "input": "0 505 681\n605 0 657\n581 757 0", "output": "707 505 681\n605 631 657\n581 757 555" }, { "input": "0 662 918\n822 0 854\n758 1014 0", "output": "934 662 918\n822 838 854\n758 1014 742" }, { "input": "0 93 95\n93 0 97\n95 97 0", "output": "97 93 95\n93 95 97\n95 97 93" }, { "input": "0 709 712\n719 0 695\n702 705 0", "output": "700 709 712\n719 707 695\n702 705 714" }, { "input": "0 7 6\n9 0 1\n4 3 0", "output": "2 7 6\n9 5 1\n4 3 8" }, { "input": "0 9 2\n3 0 7\n8 1 0", "output": "4 9 2\n3 5 7\n8 1 6" }, { "input": "0 1 43\n13 0 61\n31 73 0", "output": "67 1 43\n13 37 61\n31 73 7" }, { "input": "0 100000 100000\n100000 0 100000\n100000 100000 0", "output": "100000 100000 100000\n100000 100000 100000\n100000 100000 100000" } ]
1,595,431,241
2,147,483,647
PyPy 3
OK
TESTS
24
310
20,172,800
a=[] for i in range(3): a.append(list(map(int,input().split()))) r1=sum(a[0]) r2=sum(a[1]) r3=sum(a[2]) a[0][0]=(r3+r2-r1)//2 a[1][1]=a[0][0]+(r1-r2) a[2][2]=a[0][0]+(r1-r3) for i in range(3): print(*a[i])
Title: Little Elephant and Magic Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input Specification: The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Specification: Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Demo Input: ['0 1 1\n1 0 1\n1 1 0\n', '0 3 6\n5 0 5\n4 7 0\n'] Demo Output: ['1 1 1\n1 1 1\n1 1 1\n', '6 3 6\n5 5 5\n4 7 4\n'] Note: none
```python a=[] for i in range(3): a.append(list(map(int,input().split()))) r1=sum(a[0]) r2=sum(a[1]) r3=sum(a[2]) a[0][0]=(r3+r2-r1)//2 a[1][1]=a[0][0]+(r1-r2) a[2][2]=a[0][0]+(r1-r3) for i in range(3): print(*a[i]) ```
3
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,499,796,650
5,150
Python 3
OK
TESTS
128
77
5,632,000
n,m = map(int,input().split()) data = [ input() for _ in range(n)] rmax=cmax=-1 rmin=1000 cmin=1000 for i in range(n): for j in range(m): if data[i][j]=='B': cmin=min(cmin,i) cmax=max(cmax,i) rmin=min(rmin,j) rmax=max(rmax,j) row = rmax-rmin+1 column = cmax-cmin+1 side = max(row,column) if rmax==-1 and cmax==-1: print(1) else: if side<=n and side<=m: w=0 for i in range(column): for j in range(row): if data[i+cmin][j+rmin]=='W': w+=1 if column>row: w+=column*(column-row) elif row>column: w+=row*(row-column) print(w) else: print(-1)
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()) data = [ input() for _ in range(n)] rmax=cmax=-1 rmin=1000 cmin=1000 for i in range(n): for j in range(m): if data[i][j]=='B': cmin=min(cmin,i) cmax=max(cmax,i) rmin=min(rmin,j) rmax=max(rmax,j) row = rmax-rmin+1 column = cmax-cmin+1 side = max(row,column) if rmax==-1 and cmax==-1: print(1) else: if side<=n and side<=m: w=0 for i in range(column): for j in range(row): if data[i+cmin][j+rmin]=='W': w+=1 if column>row: w+=column*(column-row) elif row>column: w+=row*(row-column) print(w) else: print(-1) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,672,315,826
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
n = int(input ()) a= [0,0,0] for i in range(n): b = [int(j) for j in input().split() ] a += b if a == [0,0,0] : print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n = int(input ()) a= [0,0,0] for i in range(n): b = [int(j) for j in input().split() ] a += b if a == [0,0,0] : print("YES") else: print("NO") ```
0
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$.
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels.
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3 4 5 7 8 10 11 12 13 14 15 16 17 19 21 22 23 24 25 26 27 28 30 32 33 36 39 40 41 42 46 48 53 54 55 59 60 61 63 65 68 70 71 74 75 76 79 80 81 82 84 88 89 90 91 93 94 96 97 98 100 101 102 105 106 107 108 109 110 111 113 114 115 116 117 118 120 121 122 125 126 128 131 132 133 134 135 137 138 139 140 143 144 146 147 148 149", "output": "47" }, { "input": "1 1000000000\n-1000000000", "output": "2" }, { "input": "2 1000000000\n-1000000000 1000000000", "output": "3" }, { "input": "100 2\n1 3 5 6 8 9 12 13 14 17 18 21 22 23 24 25 26 27 29 30 34 35 36 39 41 44 46 48 52 53 55 56 57 59 61 63 64 66 68 69 70 71 72 73 75 76 77 79 80 81 82 87 88 91 92 93 94 95 96 97 99 100 102 103 104 106 109 110 111 112 113 114 115 117 118 119 120 122 124 125 127 128 129 130 131 132 133 134 136 137 139 140 141 142 143 145 146 148 149 150", "output": "6" }, { "input": "100 3\n0 1 3 6 7 8 9 10 13 14 16 17 18 20 21 22 24 26 27 30 33 34 35 36 37 39 42 43 44 45 46 48 53 54 55 56 57 58 61 63 64 65 67 69 70 72 73 76 77 78 79 81 82 83 85 86 87 88 90 92 93 95 96 97 98 99 100 101 104 105 108 109 110 113 114 115 116 118 120 121 123 124 125 128 130 131 132 133 134 135 136 137 139 140 141 142 146 147 148 150", "output": "2" }, { "input": "1 1000000000\n1000000000", "output": "2" }, { "input": "10 2\n-93 -62 -53 -42 -38 11 57 58 87 94", "output": "17" }, { "input": "2 500000000\n-1000000000 1000000000", "output": "4" }, { "input": "100 10\n-489 -476 -445 -432 -430 -421 -420 -418 -412 -411 -404 -383 -356 -300 -295 -293 -287 -276 -265 -263 -258 -251 -249 -246 -220 -219 -205 -186 -166 -157 -143 -137 -136 -130 -103 -86 -80 -69 -67 -55 -43 -41 -40 -26 -19 -9 16 29 41 42 54 76 84 97 98 99 101 115 134 151 157 167 169 185 197 204 208 226 227 232 234 249 259 266 281 282 293 298 300 306 308 313 319 328 331 340 341 344 356 362 366 380 390 399 409 411 419 444 455 498", "output": "23" }, { "input": "1 1000000000\n999999999", "output": "2" }, { "input": "1 1\n-5", "output": "2" }, { "input": "2 1\n-1000000000 1000000000", "output": "4" }, { "input": "1 2\n1", "output": "2" }, { "input": "4 5\n0 20 40 60", "output": "8" }, { "input": "1 1\n-10", "output": "2" }, { "input": "1 1\n-1000000000", "output": "2" }, { "input": "1 1000000000\n0", "output": "2" }, { "input": "1 2\n-10", "output": "2" }, { "input": "1 1\n2", "output": "2" }, { "input": "1 5\n-100", "output": "2" }, { "input": "2 1000000000\n999999999 1000000000", "output": "2" }, { "input": "2 2\n0 5", "output": "4" }, { "input": "1 2\n-5", "output": "2" }, { "input": "1 1\n1", "output": "2" }, { "input": "1 5\n-20", "output": "2" }, { "input": "2 100000000\n-1000000000 1000000000", "output": "4" }, { "input": "1 1000000000\n147483641", "output": "2" }, { "input": "3 3\n1 8 9", "output": "4" }, { "input": "2 1\n1 1000000000", "output": "4" }, { "input": "1 2\n-4", "output": "2" }, { "input": "2 1\n-1000000000 -1", "output": "4" } ]
1,530,809,830
1,330
Python 3
RUNTIME_ERROR
PRETESTS
0
93
0
def go(): n = int(input()) a = [int(i) for i in input().split(' ')] if n < 2: return -1 if n == 2 and a[0] == a[1]: return -1 s = sum(a) for i in range(len(a)): if s - a[i] != a[i]: return '{}\n{}'.format(1, i + 1) return -1 print(go())
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$. Input Specification: The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels. Output Specification: Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. Demo Input: ['4 3\n-3 2 9 16\n', '5 2\n4 8 11 18 19\n'] Demo Output: ['6\n', '5\n'] Note: In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
```python def go(): n = int(input()) a = [int(i) for i in input().split(' ')] if n < 2: return -1 if n == 2 and a[0] == a[1]: return -1 s = sum(a) for i in range(len(a)): if s - a[i] != a[i]: return '{}\n{}'.format(1, i + 1) return -1 print(go()) ```
-1
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game.
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": "Anton" }, { "input": "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD", "output": "Friendship" }, { "input": "1\nA", "output": "Anton" }, { "input": "1\nD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "4\nDADA", "output": "Friendship" }, { "input": "4\nDAAD", "output": "Friendship" }, { "input": "3\nADD", "output": "Danik" }, { "input": "3\nDAD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA", "output": "Anton" } ]
1,695,993,717
2,147,483,647
Python 3
OK
TESTS
25
46
102,400
d=0 a=0 v=int(input()) x=input() for i in x: if i=="D": d=d+1 else: a=a+1 if d==a: print("Friendship") elif a>d: print("Anton") else: print("Danik")
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. Output Specification: If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). Demo Input: ['6\nADAAAA\n', '7\nDDDAADA\n', '6\nDADADA\n'] Demo Output: ['Anton\n', 'Danik\n', 'Friendship\n'] Note: In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
```python d=0 a=0 v=int(input()) x=input() for i in x: if i=="D": d=d+1 else: a=a+1 if d==a: print("Friendship") elif a>d: print("Anton") else: print("Danik") ```
3
0
none
none
none
0
[ "none" ]
null
null
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=&lt;<=*j* and *p**i*<=&gt;<=*p**j*.
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively.
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps.
[ "5 2\n", "1 10\n" ]
[ "10\n", "0\n" ]
In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible messiness is 0.
0
[ { "input": "5 2", "output": "10" }, { "input": "1 10", "output": "0" }, { "input": "100000 2", "output": "399990" }, { "input": "1 1", "output": "0" }, { "input": "8 3", "output": "27" }, { "input": "7 1", "output": "11" }, { "input": "100000 40000", "output": "4799960000" }, { "input": "1 1000", "output": "0" }, { "input": "100 45", "output": "4905" }, { "input": "9 2", "output": "26" }, { "input": "456 78", "output": "58890" }, { "input": "100000 50000", "output": "4999950000" }, { "input": "100000 50001", "output": "4999950000" }, { "input": "100000 50002", "output": "4999950000" }, { "input": "100000 50003", "output": "4999950000" }, { "input": "100000 49998", "output": "4999949994" }, { "input": "100000 49997", "output": "4999949985" }, { "input": "99999 49998", "output": "4999849998" }, { "input": "99999 49997", "output": "4999849991" }, { "input": "99999 49996", "output": "4999849980" }, { "input": "99999 50000", "output": "4999850001" }, { "input": "99999 50001", "output": "4999850001" }, { "input": "99999 50002", "output": "4999850001" }, { "input": "30062 9", "output": "540945" }, { "input": "13486 3", "output": "80895" }, { "input": "29614 7", "output": "414491" }, { "input": "13038 8", "output": "208472" }, { "input": "96462 6", "output": "1157466" }, { "input": "22599 93799", "output": "255346101" }, { "input": "421 36817", "output": "88410" }, { "input": "72859 65869", "output": "2654180511" }, { "input": "37916 5241", "output": "342494109" }, { "input": "47066 12852", "output": "879423804" }, { "input": "84032 21951", "output": "2725458111" }, { "input": "70454 75240", "output": "2481847831" }, { "input": "86946 63967", "output": "3779759985" }, { "input": "71128 11076", "output": "1330260828" }, { "input": "46111 64940", "output": "1063089105" }, { "input": "46111 64940", "output": "1063089105" }, { "input": "56500 84184", "output": "1596096750" }, { "input": "60108 83701", "output": "1806455778" }, { "input": "1 2", "output": "0" }, { "input": "1 3", "output": "0" }, { "input": "1 4", "output": "0" }, { "input": "1 5", "output": "0" }, { "input": "1 6", "output": "0" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "1" }, { "input": "2 4", "output": "1" }, { "input": "2 5", "output": "1" }, { "input": "3 1", "output": "3" }, { "input": "3 2", "output": "3" }, { "input": "3 3", "output": "3" }, { "input": "3 4", "output": "3" }, { "input": "3 5", "output": "3" }, { "input": "4 1", "output": "5" }, { "input": "4 2", "output": "6" }, { "input": "4 3", "output": "6" }, { "input": "4 4", "output": "6" }, { "input": "4 5", "output": "6" }, { "input": "5 1", "output": "7" }, { "input": "5 3", "output": "10" }, { "input": "5 4", "output": "10" }, { "input": "5 5", "output": "10" }, { "input": "6 1", "output": "9" }, { "input": "6 2", "output": "14" }, { "input": "6 3", "output": "15" }, { "input": "7 2", "output": "18" }, { "input": "7 3", "output": "21" }, { "input": "7 4", "output": "21" }, { "input": "10 2", "output": "30" }, { "input": "60982 2", "output": "243918" }, { "input": "23426 23", "output": "1076515" }, { "input": "444 3", "output": "2643" }, { "input": "18187 433", "output": "15374531" }, { "input": "6895 3544", "output": "23767065" }, { "input": "56204 22352", "output": "1513297456" }, { "input": "41977 5207", "output": "382917573" }, { "input": "78147 2321", "output": "351981971" }, { "input": "99742 62198", "output": "4974183411" }, { "input": "72099 38339", "output": "2599096851" }, { "input": "82532 4838", "output": "751762306" }, { "input": "79410 33144", "output": "3066847464" }, { "input": "11021 3389", "output": "51726307" }, { "input": "66900 7572", "output": "898455660" }, { "input": "99999 49999", "output": "4999850001" }, { "input": "100000 49999", "output": "4999949999" }, { "input": "100000 100000", "output": "4999950000" }, { "input": "100000 1", "output": "199997" }, { "input": "4 100", "output": "6" }, { "input": "100000 1234", "output": "243753254" } ]
1,465,943,680
2,147,483,647
Python 3
OK
TESTS
92
93
4,812,800
n,k=[int(i)for i in input().split()] out=0 while n>1 and k>0: out+=2*n-3 n-=2 k-=1 print(out)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=&lt;<=*j* and *p**i*<=&gt;<=*p**j*. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. Output Specification: Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. Demo Input: ['5 2\n', '1 10\n'] Demo Output: ['10\n', '0\n'] Note: In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible messiness is 0.
```python n,k=[int(i)for i in input().split()] out=0 while n>1 and k>0: out+=2*n-3 n-=2 k-=1 print(out) ```
3
614
B
Gena's Code
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000.
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
[ "3\n5 10 1\n", "4\n1 1 10 11\n", "5\n0 3 1 100 1\n" ]
[ "50", "110", "0" ]
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
1,000
[ { "input": "3\n5 10 1", "output": "50" }, { "input": "4\n1 1 10 11", "output": "110" }, { "input": "5\n0 3 1 100 1", "output": "0" }, { "input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100", "output": "1824868942000000000000000000000000000000000000000000000000000" }, { "input": "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000", "output": "6643573784000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1", "output": "1" }, { "input": "1\n9", "output": "9" }, { "input": "2\n10 50", "output": "500" }, { "input": "3\n500 1 10", "output": "5000" } ]
1,653,742,545
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
14
500
9,113,600
n=int(input()) a=list(map(int,input().rstrip().split())) p=1 for i in a: p*=i print(p)
Title: Gena's Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case. Input Specification: The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000. Output Specification: Print a single number without leading zeroes — the product of the number of tanks presented by each country. Demo Input: ['3\n5 10 1\n', '4\n1 1 10 11\n', '5\n0 3 1 100 1\n'] Demo Output: ['50', '110', '0'] Note: In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
```python n=int(input()) a=list(map(int,input().rstrip().split())) p=1 for i in a: p*=i print(p) ```
0
2
B
The least round way
PROGRAMMING
2,000
[ "dp", "math" ]
B. The least round way
2
64
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109).
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
[ "3\n1 2 3\n4 5 6\n7 8 9\n" ]
[ "0\nDDRR\n" ]
none
0
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "0\nDDRR" }, { "input": "2\n7 6\n3 8", "output": "0\nDR" }, { "input": "3\n4 10 5\n10 9 4\n6 5 3", "output": "1\nDRRD" }, { "input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5", "output": "0\nDDDRRR" }, { "input": "5\n8 3 2 1 4\n3 7 2 4 8\n9 2 8 9 10\n2 3 6 10 1\n8 2 2 8 4", "output": "0\nDDDDRRRR" }, { "input": "6\n5 5 4 10 5 5\n7 10 8 7 6 6\n7 1 7 9 7 8\n5 5 3 3 10 9\n5 8 10 6 3 8\n3 10 5 4 3 4", "output": "1\nDDRRDRDDRR" }, { "input": "7\n2 9 8 2 7 4 8\n9 5 4 4 8 5 3\n5 7 2 10 8 1 8\n2 7 10 7 5 7 7\n9 2 7 6 4 8 4\n7 2 4 7 4 1 8\n9 5 3 10 1 6 2", "output": "0\nRRDRRDRDDDDR" }, { "input": "8\n1 1 10 1 8 4 8 7\n9 3 3 2 2 6 2 4\n7 4 3 5 10 3 5 1\n8 4 4 10 4 5 9 4\n5 5 5 2 6 7 1 8\n4 10 1 3 2 4 8 3\n8 1 10 2 8 2 2 4\n2 10 6 8 10 2 8 4", "output": "0\nDRRRRRRRDDDDDD" }, { "input": "9\n8 3 3 3 10 3 10 5 6\n2 1 6 1 8 1 9 1 6\n6 1 5 4 2 2 10 4 9\n1 9 1 3 10 6 10 5 5\n1 10 5 4 7 2 5 9 10\n6 6 1 3 1 9 4 9 9\n5 3 7 6 4 6 2 10 2\n9 3 3 10 5 6 7 6 4\n4 9 6 7 4 3 7 6 5", "output": "1\nDDDDDRDDDRRRRRRR" }, { "input": "10\n10 8 6 5 9 8 2 5 3 2\n3 1 8 6 8 10 5 5 7 8\n5 9 7 7 4 9 7 2 5 2\n5 9 9 5 4 2 6 6 8 1\n10 6 9 9 10 5 6 3 5 9\n6 7 10 3 1 4 3 6 7 6\n10 10 4 7 4 4 8 6 7 4\n10 5 8 2 2 7 4 4 1 4\n8 4 6 10 10 6 1 3 3 1\n9 9 7 2 9 5 1 8 6 3", "output": "1\nDRDDDRRDDDRRDRDRRR" } ]
1,529,323,338
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
77
0
""" Codeforces 2B - The least round way http://codeforces.com/problemset/problem/2/B Héctor González Belver 18/06/2018 """ import sys cost = [] tc = [] def factor_2_5(n): num = int(n) num_factor_2 = 0 num_factor_5 = 0 if num == 0: return 999999999 while num%2==0: num = num//2 num_factor_2 += 1 while num%5==0: num = num//5 num_factor_5 += 1 return(min(num_factor_2, num_factor_5)) def total_cost(rows, columns): global tc tc = [[0]*columns for j in range(rows)] tc[0][0] = cost[0][0] for i in range(1, rows): tc[i][0] = tc[i-1][0] + cost[i][0] for j in range(1, columns): tc[0][j] = tc[0][j-1] + cost[0][j] for i in range(1, rows): for j in range(1, columns): tc[i][j] = min(tc[i-1][j],tc[i][j-1]) + cost[i][j] def min_path(rows, columns): row_idx = rows-1 column_idx = columns-1 moves = '' for _ in range(row_idx + column_idx): if row_idx == 0: moves += 'R' column_idx += -1 continue if column_idx == 0: moves += 'D' row_idx += -1 continue if tc[row_idx][column_idx-1]>tc[row_idx-1][column_idx]: moves += 'D' row_idx += -1 else: moves += 'R' column_idx += -1 return moves[::-1] def main(): n = int(sys.stdin.readline().strip()) global cost cost = [[factor_2_5(i) for i in sys.stdin.readline().strip().split()] for j in range(n)] total_cost(n,n) sys.stdout.write(str(tc[n-1][n-1]) + '\n') sys.stdout.write(min_path(n,n) + '\n') if __name__ == '__main__': main()
Title: The least round way Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros. Input Specification: The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). Output Specification: In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. Demo Input: ['3\n1 2 3\n4 5 6\n7 8 9\n'] Demo Output: ['0\nDDRR\n'] Note: none
```python """ Codeforces 2B - The least round way http://codeforces.com/problemset/problem/2/B Héctor González Belver 18/06/2018 """ import sys cost = [] tc = [] def factor_2_5(n): num = int(n) num_factor_2 = 0 num_factor_5 = 0 if num == 0: return 999999999 while num%2==0: num = num//2 num_factor_2 += 1 while num%5==0: num = num//5 num_factor_5 += 1 return(min(num_factor_2, num_factor_5)) def total_cost(rows, columns): global tc tc = [[0]*columns for j in range(rows)] tc[0][0] = cost[0][0] for i in range(1, rows): tc[i][0] = tc[i-1][0] + cost[i][0] for j in range(1, columns): tc[0][j] = tc[0][j-1] + cost[0][j] for i in range(1, rows): for j in range(1, columns): tc[i][j] = min(tc[i-1][j],tc[i][j-1]) + cost[i][j] def min_path(rows, columns): row_idx = rows-1 column_idx = columns-1 moves = '' for _ in range(row_idx + column_idx): if row_idx == 0: moves += 'R' column_idx += -1 continue if column_idx == 0: moves += 'D' row_idx += -1 continue if tc[row_idx][column_idx-1]>tc[row_idx-1][column_idx]: moves += 'D' row_idx += -1 else: moves += 'R' column_idx += -1 return moves[::-1] def main(): n = int(sys.stdin.readline().strip()) global cost cost = [[factor_2_5(i) for i in sys.stdin.readline().strip().split()] for j in range(n)] total_cost(n,n) sys.stdout.write(str(tc[n-1][n-1]) + '\n') sys.stdout.write(min_path(n,n) + '\n') if __name__ == '__main__': main() ```
0
918
B
Radio Station
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Print *m* lines, the commands in the configuration file after Dustin did his task.
[ "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n" ]
[ "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n" ]
none
1,000
[ { "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main" }, { "input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;", "output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server" }, { "input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;", "output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm" }, { "input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;", "output": "zygoumbmx 185.32.99.2; #ervbfot" }, { "input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;", "output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y" }, { "input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;", "output": "zbtjzzue 203.115.124.110; #tdwmshz" }, { "input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;", "output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t" }, { "input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;", "output": "command 11.1.1.1; #get" }, { "input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;", "output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn" }, { "input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;", "output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica" }, { "input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;", "output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica" }, { "input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;", "output": "block 255.255.255.255; #server" }, { "input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;", "output": "block 22.222.30.10; #alp" } ]
1,594,152,893
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
139
20,172,800
#Radio Station n,m = map(int,input().split()) d1,d2 = {},{} for i in range(n): name,ip = map(str,input().split()) d1[ip] = name for i in range(m): command,ip = map(str,input().split()) d2[command] = ip for i,j in d2.items(): j1 = j[:-1] print(i+' '+j+' #'+d1[j1]) '''print(i,'a') print(j,'b') print(d1[j1],'c')'''
Title: Radio Station Time Limit: None seconds Memory Limit: None megabytes Problem Description: As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input Specification: The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers. Output Specification: Print *m* lines, the commands in the configuration file after Dustin did his task. Demo Input: ['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n'] Demo Output: ['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n'] Note: none
```python #Radio Station n,m = map(int,input().split()) d1,d2 = {},{} for i in range(n): name,ip = map(str,input().split()) d1[ip] = name for i in range(m): command,ip = map(str,input().split()) d2[command] = ip for i,j in d2.items(): j1 = j[:-1] print(i+' '+j+' #'+d1[j1]) '''print(i,'a') print(j,'b') print(d1[j1],'c')''' ```
0
14
B
Young Photographer
PROGRAMMING
1,000
[ "implementation" ]
B. Young Photographer
2
64
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2 What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*).
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
[ "3 3\n0 7\n14 2\n4 6\n" ]
[ "1\n" ]
none
0
[ { "input": "3 3\n0 7\n14 2\n4 6", "output": "1" }, { "input": "1 1\n0 10", "output": "0" }, { "input": "2 2\n1 2\n3 2", "output": "0" }, { "input": "3 2\n1 2\n2 3\n3 4", "output": "-1" }, { "input": "2 4\n10 4\n1 5", "output": "0" }, { "input": "1 10\n1 9", "output": "1" }, { "input": "1 10\n123 12", "output": "2" }, { "input": "1 17\n10 17", "output": "0" }, { "input": "1 22\n22 33", "output": "0" }, { "input": "1 3\n1 2", "output": "1" }, { "input": "2 5\n0 3\n2 1", "output": "3" }, { "input": "3 3\n7 3\n6 4\n3 7", "output": "1" }, { "input": "4 9\n8 6\n11 5\n5 11\n8 3", "output": "1" }, { "input": "2 4\n1 4\n4 0", "output": "0" }, { "input": "3 7\n5 8\n7 5\n4 7", "output": "0" }, { "input": "4 7\n8 2\n5 7\n8 2\n5 8", "output": "0" }, { "input": "2 3\n4 1\n4 1", "output": "0" }, { "input": "3 8\n7 2\n3 7\n5 2", "output": "3" }, { "input": "4 0\n9 1\n8 1\n8 4\n4 5", "output": "4" }, { "input": "4 7\n2 5\n3 6\n3 5\n7 4", "output": "2" }, { "input": "10 16\n4 18\n6 19\n22 1\n23 0\n1 22\n9 22\n4 19\n0 14\n6 14\n0 16", "output": "2" }, { "input": "20 1\n35 8\n40 6\n49 5\n48 18\n46 16\n45 16\n44 10\n16 44\n8 46\n2 45\n38 3\n42 1\n13 35\n35 18\n12 33\n32 11\n31 3\n50 20\n47 6\n38 2", "output": "19" }, { "input": "30 43\n17 72\n75 26\n23 69\n83 30\n15 82\n4 67\n83 27\n33 62\n26 83\n70 26\n69 25\n16 67\n77 26\n66 33\n7 88\n70 9\n10 79\n76 9\n30 77\n77 28\n21 68\n81 14\n13 72\n88 15\n60 29\n87 28\n16 58\n6 58\n71 9\n83 18", "output": "0" }, { "input": "40 69\n29 109\n28 87\n52 106\n101 34\n32 92\n91 60\n90 47\n62 102\n33 72\n27 87\n45 78\n103 37\n94 33\n56 98\n38 79\n31 83\n105 53\n47 89\n50 83\n93 62\n96 49\n47 75\n89 47\n89 61\n93 54\n46 100\n110 41\n103 28\n101 57\n100 62\n71 37\n65 80\n86 28\n73 42\n96 44\n33 111\n98 39\n87 55\n108 65\n31 101", "output": "0" }, { "input": "50 77\n95 55\n113 33\n101 17\n109 56\n117 7\n77 12\n14 84\n57 101\n96 28\n108 22\n105 12\n17 114\n51 115\n18 112\n104 25\n50 115\n14 111\n55 113\n124 20\n101 37\n18 121\n41 90\n77 41\n117 16\n8 83\n92 45\n48 86\n16 84\n13 98\n40 107\n14 94\n23 111\n36 121\n50 100\n35 90\n103 37\n96 51\n109 15\n13 117\n117 42\n112 45\n88 36\n51 121\n127 49\n112 15\n9 95\n122 46\n126 40\n57 93\n56 88", "output": "0" }, { "input": "5 12\n2 7\n7 5\n3 10\n11 3\n2 11", "output": "5" }, { "input": "15 15\n12 37\n40 4\n38 8\n5 36\n11 31\n21 33\n9 37\n4 38\n8 33\n5 39\n7 39\n38 16\n16 41\n38 9\n5 32", "output": "6" }, { "input": "25 40\n66 26\n56 19\n64 38\n64 23\n25 49\n51 26\n67 20\n65 35\n33 66\n28 63\n27 57\n40 56\n59 26\n35 56\n39 67\n30 63\n69 22\n21 63\n67 22\n20 66\n26 65\n64 26\n44 57\n57 41\n35 50", "output": "4" }, { "input": "50 77\n24 119\n43 119\n102 22\n117 30\n127 54\n93 19\n120 9\n118 27\n98 16\n17 105\n22 127\n109 52\n115 40\n11 121\n12 120\n113 30\n13 108\n33 124\n31 116\n112 39\n37 108\n127 28\n127 39\n120 29\n19 114\n103 18\n106 16\n24 121\n93 10\n36 112\n104 40\n39 100\n36 97\n83 9\n14 114\n126 12\n85 47\n25 84\n105 29\n35 113\n102 19\n8 110\n111 28\n94 12\n11 115\n40 124\n39 85\n47 93\n94 31\n17 121", "output": "0" }, { "input": "1 21\n973 373", "output": "352" }, { "input": "2 212\n831 551\n810 753", "output": "541" }, { "input": "3 404\n690 728\n820 260\n186 402", "output": "-1" }, { "input": "4 906\n548 906\n830 457\n228 638\n464 167", "output": "-1" }, { "input": "5 97\n97 393\n840 965\n269 183\n596 49\n975 62", "output": "-1" }, { "input": "3 183\n416 335\n773 648\n434 198", "output": "-1" }, { "input": "3 868\n251 927\n862 464\n157 756", "output": "112" }, { "input": "3 242\n397 208\n951 279\n570 622", "output": "-1" }, { "input": "3 618\n543 800\n38 94\n293 179", "output": "-1" }, { "input": "3 993\n378 81\n127 911\n16 737", "output": "615" }, { "input": "5 12\n11 1\n9 6\n1 11\n3 8\n874 842", "output": "-1" }, { "input": "15 16\n11 40\n5 32\n5 31\n36 10\n34 9\n43 6\n28 6\n34 8\n43 15\n9 28\n14 34\n34 6\n7 31\n31 14\n68 478", "output": "-1" }, { "input": "25 57\n47 31\n64 21\n43 56\n47 19\n70 27\n28 61\n41 61\n39 45\n46 21\n55 35\n70 22\n22 69\n30 67\n55 42\n37 58\n50 28\n57 42\n35 48\n68 40\n38 50\n62 20\n31 52\n38 70\n64 35\n666 393", "output": "-1" }, { "input": "50 118\n83 55\n101 33\n89 17\n97 56\n105 7\n65 12\n14 72\n57 89\n84 28\n96 22\n93 12\n17 102\n51 103\n18 100\n92 25\n50 103\n14 99\n55 101\n112 20\n89 37\n18 109\n41 78\n65 41\n105 16\n8 71\n80 45\n48 74\n16 72\n13 86\n40 95\n14 82\n23 99\n36 109\n50 88\n35 78\n91 37\n84 51\n97 15\n13 105\n105 42\n100 45\n76 36\n51 109\n115 49\n100 15\n9 83\n110 46\n114 40\n57 81\n528 348", "output": "-1" }, { "input": "1 21\n0 1000", "output": "0" } ]
1,604,347,922
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
218
0
n, x = map(int, input().split()) _min = 0 _max = 10**4 for i in range(n): a, b = map(int, input().split()) _min = max(_min, min(a, b)) _max = min(_max, max(a, b)) print(min(abs(x-_min), abs(x-_max)))
Title: Young Photographer Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2 What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack. Input Specification: The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). Output Specification: Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. Demo Input: ['3 3\n0 7\n14 2\n4 6\n'] Demo Output: ['1\n'] Note: none
```python n, x = map(int, input().split()) _min = 0 _max = 10**4 for i in range(n): a, b = map(int, input().split()) _min = max(_min, min(a, b)) _max = min(_max, max(a, b)) print(min(abs(x-_min), abs(x-_max))) ```
0
753
A
Santa Claus and Candies
PROGRAMMING
1,000
[ "dp", "greedy", "math" ]
null
null
Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has.
The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has.
Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them.
[ "5\n", "9\n", "2\n" ]
[ "2\n2 3\n", "3\n3 5 1\n", "1\n2 \n" ]
none
500
[ { "input": "5", "output": "2\n1 4 " }, { "input": "9", "output": "3\n1 2 6 " }, { "input": "2", "output": "1\n2 " }, { "input": "1", "output": "1\n1 " }, { "input": "3", "output": "2\n1 2 " }, { "input": "1000", "output": "44\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 54 " }, { "input": "4", "output": "2\n1 3 " }, { "input": "6", "output": "3\n1 2 3 " }, { "input": "7", "output": "3\n1 2 4 " }, { "input": "8", "output": "3\n1 2 5 " }, { "input": "10", "output": "4\n1 2 3 4 " }, { "input": "11", "output": "4\n1 2 3 5 " }, { "input": "12", "output": "4\n1 2 3 6 " }, { "input": "13", "output": "4\n1 2 3 7 " }, { "input": "14", "output": "4\n1 2 3 8 " }, { "input": "15", "output": "5\n1 2 3 4 5 " }, { "input": "16", "output": "5\n1 2 3 4 6 " }, { "input": "20", "output": "5\n1 2 3 4 10 " }, { "input": "21", "output": "6\n1 2 3 4 5 6 " }, { "input": "22", "output": "6\n1 2 3 4 5 7 " }, { "input": "27", "output": "6\n1 2 3 4 5 12 " }, { "input": "28", "output": "7\n1 2 3 4 5 6 7 " }, { "input": "29", "output": "7\n1 2 3 4 5 6 8 " }, { "input": "35", "output": "7\n1 2 3 4 5 6 14 " }, { "input": "36", "output": "8\n1 2 3 4 5 6 7 8 " }, { "input": "37", "output": "8\n1 2 3 4 5 6 7 9 " }, { "input": "44", "output": "8\n1 2 3 4 5 6 7 16 " }, { "input": "45", "output": "9\n1 2 3 4 5 6 7 8 9 " }, { "input": "46", "output": "9\n1 2 3 4 5 6 7 8 10 " }, { "input": "230", "output": "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 40 " }, { "input": "231", "output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 " }, { "input": "232", "output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 " }, { "input": "239", "output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 29 " }, { "input": "629", "output": "34\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 68 " }, { "input": "630", "output": "35\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 " }, { "input": "631", "output": "35\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 36 " }, { "input": "945", "output": "42\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 84 " }, { "input": "946", "output": "43\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 " }, { "input": "947", "output": "43\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 44 " }, { "input": "989", "output": "43\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 86 " }, { "input": "990", "output": "44\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 " }, { "input": "991", "output": "44\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 45 " }, { "input": "956", "output": "43\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 53 " }, { "input": "981", "output": "43\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 78 " }, { "input": "867", "output": "41\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 47 " }, { "input": "906", "output": "42\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 45 " }, { "input": "999", "output": "44\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 53 " }, { "input": "100", "output": "13\n1 2 3 4 5 6 7 8 9 10 11 12 22 " }, { "input": "126", "output": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 21 " } ]
1,483,038,480
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
4,608,000
n = int(input()) aux = n sol = [] c = 1 while aux >= 0: sol.append(c) aux = aux - c c = c+1 sol.pop(0) print(len(sol)) print(*sol)
Title: Santa Claus and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. Input Specification: The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. Output Specification: Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them. Demo Input: ['5\n', '9\n', '2\n'] Demo Output: ['2\n2 3\n', '3\n3 5 1\n', '1\n2 \n'] Note: none
```python n = int(input()) aux = n sol = [] c = 1 while aux >= 0: sol.append(c) aux = aux - c c = c+1 sol.pop(0) print(len(sol)) print(*sol) ```
0
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string.
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss", "output": "1" }, { "input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs", "output": "2" }, { "input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi", "output": "2" }, { "input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn", "output": "1" }, { "input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti", "output": "2" }, { "input": "rmeetriiitijmrenmeiijt", "output": "0" }, { "input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne", "output": "1" }, { "input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer", "output": "2" }, { "input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim", "output": "2" }, { "input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm", "output": "3" }, { "input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn", "output": "3" }, { "input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni", "output": "1" }, { "input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm", "output": "2" }, { "input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet", "output": "3" }, { "input": "jrjshtjstteh", "output": "0" }, { "input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn", "output": "2" }, { "input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn", "output": "2" }, { "input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei", "output": "1" }, { "input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin", "output": "2" }, { "input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin", "output": "1" }, { "input": "rnsrsmretjiitrjthhritniijhjmm", "output": "0" }, { "input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj", "output": "3" }, { "input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni", "output": "0" }, { "input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis", "output": "2" }, { "input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh", "output": "3" }, { "input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei", "output": "3" }, { "input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs", "output": "1" }, { "input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj", "output": "1" }, { "input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj", "output": "2" }, { "input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii", "output": "1" }, { "input": "iihienhirmnihh", "output": "0" }, { "input": "ismtthhshjmhisssnmnhe", "output": "0" }, { "input": "rhsmnrmhejshinnjrtmtsssijimimethnm", "output": "0" }, { "input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj", "output": "3" }, { "input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes", "output": "2" }, { "input": "ssrmjmjeeetrnimemrhimes", "output": "0" }, { "input": "n", "output": "0" }, { "input": "ni", "output": "0" }, { "input": "nine", "output": "0" }, { "input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen", "output": "13" }, { "input": "ninetee", "output": "0" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd", "output": "0" }, { "input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch", "output": "0" }, { "input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq", "output": "0" }, { "input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz", "output": "13" }, { "input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee", "output": "3" }, { "input": "ttttiiiieeeeeeeeeeeennnnnnnnn", "output": "4" }, { "input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn", "output": "3" }, { "input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt", "output": "4" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn", "output": "3" }, { "input": "nineeen", "output": "0" }, { "input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii", "output": "0" }, { "input": "nineteenieteenieteenieteenieteenieteenieteen", "output": "4" }, { "input": "nineteenineteenineteenineteenineteen", "output": "5" } ]
1,563,106,906
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
109
0
def count1(self,s): m=[] for i in range(0,len(self)) : if len(self[i:i+len(s)])==len(s) and self[i:i+len(s)]==s: m.append(self[i:i+len(s)]) return m.count(s) s=input() s1={} slist=[count1(s,'nineteen')] slist1=[] for i in 'niet': s1[i]=count1(s,i) if s1['n']<3 or s1['e']<3 or s1['i']<1 or s1['t']<1: print(0) else: slist1.append(s1['n']//3) slist1.append(s1['n']//3) slist1.append(s1['t']) slist1.append(s1['i']) slist.append(min(slist1)) print(max(slist))
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. Input Specification: The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. Output Specification: Print a single integer — the maximum number of "nineteen"s that she can get in her string. Demo Input: ['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n'] Demo Output: ['2', '2', '2'] Note: none
```python def count1(self,s): m=[] for i in range(0,len(self)) : if len(self[i:i+len(s)])==len(s) and self[i:i+len(s)]==s: m.append(self[i:i+len(s)]) return m.count(s) s=input() s1={} slist=[count1(s,'nineteen')] slist1=[] for i in 'niet': s1[i]=count1(s,i) if s1['n']<3 or s1['e']<3 or s1['i']<1 or s1['t']<1: print(0) else: slist1.append(s1['n']//3) slist1.append(s1['n']//3) slist1.append(s1['t']) slist1.append(s1['i']) slist.append(min(slist1)) print(max(slist)) ```
0
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, { "input": "789 101112 131415", "output": "203802" }, { "input": "27485716 99999999 35182", "output": "55041796" }, { "input": "1 293548 5", "output": "12" }, { "input": "12059 259855 5874875", "output": "543828" }, { "input": "46981 105809 585858", "output": "305580" }, { "input": "9889 1221 2442", "output": "7326" }, { "input": "100500 200600 300700", "output": "601800" }, { "input": "318476 318476 318476", "output": "955428" }, { "input": "23985 3353 75633", "output": "54676" }, { "input": "120 1298 2222", "output": "2836" }, { "input": "98437 23487 666672", "output": "243848" }, { "input": "100000000 100000000 100000000", "output": "300000000" }, { "input": "2 5 2", "output": "8" }, { "input": "1 1000 1", "output": "4" }, { "input": "1 100000000 1", "output": "4" } ]
1,603,915,069
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
d1, d2, d3 = map(int, input().split()) P1 = d1 + d2 + d3 P2 = d1 * 2 + d2 * 2 print(min(P1, P2))
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. Input Specification: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. Output Specification: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Demo Input: ['10 20 30\n', '1 1 5\n'] Demo Output: ['60\n', '4\n'] Note: The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
```python d1, d2, d3 = map(int, input().split()) P1 = d1 + d2 + d3 P2 = d1 * 2 + d2 * 2 print(min(P1, P2)) ```
0
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0.
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output": "1\n1 2 3" }, { "input": "12\n3 3 3 3 3 3 3 3 1 3 3 2", "output": "1\n9 12 2" }, { "input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2", "output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47" }, { "input": "12\n3 1 1 1 1 1 1 2 1 1 1 1", "output": "1\n3 8 1" }, { "input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2", "output": "1\n18 2 11" }, { "input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3", "output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36" }, { "input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1", "output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200" }, { "input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3", "output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64" }, { "input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1", "output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44" }, { "input": "5\n1 2 2 3 3", "output": "1\n1 3 4" } ]
1,684,639,891
2,147,483,647
Python 3
OK
TESTS
41
46
307,200
n = int(input()) x = input().split() lst_1,lst_2,lst_3 = [],[],[] if len(set(x)) != 3: print('0') else: for idx in range(n): if x[idx] == "1": lst_1.append(idx+1) for idx in range(n): if x[idx] == "2": lst_2.append(idx+1) for idx in range(n): if x[idx] == "3": lst_3.append(idx+1) l = min(len(lst_1), len(lst_2), len(lst_3)) print(l) for i in range(l): print(lst_1[i] , lst_2[i] , lst_3[i])
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. Output Specification: In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0. Demo Input: ['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n'] Demo Output: ['2\n3 5 2\n6 7 4\n', '0\n'] Note: none
```python n = int(input()) x = input().split() lst_1,lst_2,lst_3 = [],[],[] if len(set(x)) != 3: print('0') else: for idx in range(n): if x[idx] == "1": lst_1.append(idx+1) for idx in range(n): if x[idx] == "2": lst_2.append(idx+1) for idx in range(n): if x[idx] == "3": lst_3.append(idx+1) l = min(len(lst_1), len(lst_2), len(lst_3)) print(l) for i in range(l): print(lst_1[i] , lst_2[i] , lst_3[i]) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,683,748,621
2,147,483,647
Python 3
OK
TESTS
20
46
0
n = int (input('')) for i in range (0,n) : my_string = str(input('')) length = len(my_string) if (length > 10) : print(my_string[0], end='') print(length-2 , end='' ) print(my_string[-1]) else: print(my_string)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python n = int (input('')) for i in range (0,n) : my_string = str(input('')) length = len(my_string) if (length > 10) : print(my_string[0], end='') print(length-2 , end='' ) print(my_string[-1]) else: print(my_string) ```
3.977
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,564,080,514
2,147,483,647
PyPy 3
OK
TESTS
36
624
7,270,400
from fractions import gcd n,m=map(int,input().split()) num=6-max(n,m)+1 den=6 g=gcd(num,den) print(str(num//g)+'/'+str(den//g))
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 from fractions import gcd n,m=map(int,input().split()) num=6-max(n,m)+1 den=6 g=gcd(num,den) print(str(num//g)+'/'+str(den//g)) ```
3.633831
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "input": "1000\n999", "output": "1" }, { "input": "1000\n1", "output": "250000" }, { "input": "2\n1", "output": "1" }, { "input": "2\n999", "output": "249001" }, { "input": "2\n998", "output": "248502" }, { "input": "999\n2", "output": "249001" }, { "input": "998\n2", "output": "248502" }, { "input": "2\n1000", "output": "249500" }, { "input": "1000\n2", "output": "249500" }, { "input": "1\n999", "output": "249500" }, { "input": "999\n1", "output": "249500" }, { "input": "188\n762", "output": "82656" }, { "input": "596\n777", "output": "8281" }, { "input": "773\n70", "output": "123904" }, { "input": "825\n729", "output": "2352" }, { "input": "944\n348", "output": "89102" }, { "input": "352\n445", "output": "2209" }, { "input": "529\n656", "output": "4096" }, { "input": "19\n315", "output": "22052" }, { "input": "138\n370", "output": "13572" }, { "input": "546\n593", "output": "576" }, { "input": "285\n242", "output": "484" }, { "input": "773\n901", "output": "4160" }, { "input": "892\n520", "output": "34782" }, { "input": "864\n179", "output": "117649" }, { "input": "479\n470", "output": "25" }, { "input": "967\n487", "output": "57840" }, { "input": "648\n106", "output": "73712" }, { "input": "58\n765", "output": "125316" }, { "input": "235\n56", "output": "8100" }, { "input": "285\n153", "output": "4422" }, { "input": "943\n13", "output": "216690" }, { "input": "675\n541", "output": "4556" }, { "input": "4\n912", "output": "206570" } ]
1,597,429,337
2,147,483,647
Python 3
OK
TESTS
40
108
307,200
a = int(input()) b = int(input()) d = max(a-b,b-a) if d%2 == 0: y = int(d/2) else: y = int(d/2)+1 f1 = 0 for i in range(1,int(d/2)+1): f1 += i f2 = 0 for i in range(1,y+1): f2 += i if d == 1: print(1) else: print(f1+f2)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input Specification: The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*. Output Specification: Print the minimum possible total tiredness if the friends meet in the same point. Demo Input: ['3\n4\n', '101\n99\n', '5\n10\n'] Demo Output: ['1\n', '2\n', '9\n'] Note: In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
```python a = int(input()) b = int(input()) d = max(a-b,b-a) if d%2 == 0: y = int(d/2) else: y = int(d/2)+1 f1 = 0 for i in range(1,int(d/2)+1): f1 += i f2 = 0 for i in range(1,y+1): f2 += i if d == 1: print(1) else: print(f1+f2) ```
3
887
A
Div. 64
PROGRAMMING
1,000
[ "implementation" ]
null
null
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.
In the only line given a non-empty binary string *s* with length up to 100.
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
[ "100010001\n", "100\n" ]
[ "yes", "no" ]
In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system. You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system)
500
[ { "input": "100010001", "output": "yes" }, { "input": "100", "output": "no" }, { "input": "0000001000000", "output": "yes" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "no" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111", "output": "no" }, { "input": "0111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "no" }, { "input": "1111011111111111111111111111110111110111111111111111111111011111111111111110111111111111111111111111", "output": "no" }, { "input": "1111111111101111111111111111111111111011111111111111111111111101111011111101111111111101111111111111", "output": "yes" }, { "input": "0110111111111111111111011111111110110111110111111111111111111111111111111111111110111111111111111111", "output": "yes" }, { "input": "1100110001111011001101101000001110111110011110111110010100011000100101000010010111100000010001001101", "output": "yes" }, { "input": "000000", "output": "no" }, { "input": "0001000", "output": "no" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "no" }, { "input": "1000000", "output": "yes" }, { "input": "0", "output": "no" }, { "input": "1", "output": "no" }, { "input": "10000000000", "output": "yes" }, { "input": "0000000000", "output": "no" }, { "input": "0010000", "output": "no" }, { "input": "000000011", "output": "no" }, { "input": "000000000", "output": "no" }, { "input": "00000000", "output": "no" }, { "input": "000000000011", "output": "no" }, { "input": "0000000", "output": "no" }, { "input": "00000000011", "output": "no" }, { "input": "000000001", "output": "no" }, { "input": "000000000000000000000000000", "output": "no" }, { "input": "0000001", "output": "no" }, { "input": "00000001", "output": "no" }, { "input": "00000000100", "output": "no" }, { "input": "00000000000000000000", "output": "no" }, { "input": "0000000000000000000", "output": "no" }, { "input": "00001000", "output": "no" }, { "input": "0000000000010", "output": "no" }, { "input": "000000000010", "output": "no" }, { "input": "000000000000010", "output": "no" }, { "input": "0100000", "output": "no" }, { "input": "00010000", "output": "no" }, { "input": "00000000000000000", "output": "no" }, { "input": "00000000000", "output": "no" }, { "input": "000001000", "output": "no" }, { "input": "000000000000", "output": "no" }, { "input": "100000000000000", "output": "yes" }, { "input": "000010000", "output": "no" }, { "input": "00000100", "output": "no" }, { "input": "0001100000", "output": "no" }, { "input": "000000000000000000000000001", "output": "no" }, { "input": "000000100", "output": "no" }, { "input": "0000000000001111111111", "output": "no" }, { "input": "00000010", "output": "no" }, { "input": "0001110000", "output": "no" }, { "input": "0000000000000000000000", "output": "no" }, { "input": "000000010010", "output": "no" }, { "input": "0000100", "output": "no" }, { "input": "0000000001", "output": "no" }, { "input": "000000111", "output": "no" }, { "input": "0000000000000", "output": "no" }, { "input": "000000000000000000", "output": "no" }, { "input": "0000000000000000000000000", "output": "no" }, { "input": "000000000000000", "output": "no" }, { "input": "0010000000000100", "output": "yes" }, { "input": "0000001000", "output": "no" }, { "input": "00000000000000000001", "output": "no" }, { "input": "100000000", "output": "yes" }, { "input": "000000000001", "output": "no" }, { "input": "0000011001", "output": "no" }, { "input": "000", "output": "no" }, { "input": "000000000000000000000", "output": "no" }, { "input": "0000000000011", "output": "no" }, { "input": "0000000000000000", "output": "no" }, { "input": "00000000000000001", "output": "no" }, { "input": "00000000000000", "output": "no" }, { "input": "0000000000000000010", "output": "no" }, { "input": "00000000000000000000000000000000000000000000000000000000", "output": "no" }, { "input": "000011000", "output": "no" }, { "input": "00000011", "output": "no" }, { "input": "0000000000001100", "output": "no" }, { "input": "00000", "output": "no" }, { "input": "000000000000000000000000000111111111111111", "output": "no" }, { "input": "000000010", "output": "no" }, { "input": "00000000111", "output": "no" }, { "input": "000000000000001", "output": "no" }, { "input": "0000000000000011111111111111111", "output": "no" }, { "input": "0000000010", "output": "no" }, { "input": "0000000000000000000000000000000000000000000000000", "output": "no" }, { "input": "00000000010", "output": "no" }, { "input": "101000000000", "output": "yes" }, { "input": "00100000", "output": "no" }, { "input": "00000000000001", "output": "no" }, { "input": "0000000000100", "output": "no" }, { "input": "0000", "output": "no" }, { "input": "00000000000111", "output": "no" }, { "input": "0000000000000011", "output": "no" }, { "input": "0000000000000000000000000000000000000000", "output": "no" }, { "input": "0000000000000010", "output": "no" }, { "input": "0010101010", "output": "no" }, { "input": "0000000000000001", "output": "no" }, { "input": "1010101", "output": "no" } ]
1,568,221,917
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
s=input() s=list(s) c=0 for i in s: if(i=='0'): c+=1 if(c>=6 && s[0]=='1'): print("yes") else: print("no")
Title: Div. 64 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system. Input Specification: In the only line given a non-empty binary string *s* with length up to 100. Output Specification: Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. Demo Input: ['100010001\n', '100\n'] Demo Output: ['yes', 'no'] Note: In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system. You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system)
```python s=input() s=list(s) c=0 for i in s: if(i=='0'): c+=1 if(c>=6 && s[0]=='1'): print("yes") else: print("no") ```
-1
748
A
Santa Claus and a Place in a Class
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
500
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "output": "8043 2940 R" }, { "input": "1 1 1", "output": "1 1 L" }, { "input": "1 1 2", "output": "1 1 R" }, { "input": "1 10000 1", "output": "1 1 L" }, { "input": "1 10000 20000", "output": "1 10000 R" }, { "input": "10000 1 1", "output": "1 1 L" }, { "input": "10000 1 10000", "output": "5000 1 R" }, { "input": "10000 1 20000", "output": "10000 1 R" }, { "input": "3 2 1", "output": "1 1 L" }, { "input": "3 2 2", "output": "1 1 R" }, { "input": "3 2 3", "output": "1 2 L" }, { "input": "3 2 4", "output": "1 2 R" }, { "input": "3 2 5", "output": "2 1 L" }, { "input": "3 2 6", "output": "2 1 R" }, { "input": "3 2 7", "output": "2 2 L" }, { "input": "3 2 8", "output": "2 2 R" }, { "input": "3 2 9", "output": "3 1 L" }, { "input": "3 2 10", "output": "3 1 R" }, { "input": "3 2 11", "output": "3 2 L" }, { "input": "3 2 12", "output": "3 2 R" }, { "input": "300 2000 1068628", "output": "268 314 R" }, { "input": "300 2000 584756", "output": "147 378 R" }, { "input": "300 2000 268181", "output": "68 91 L" }, { "input": "10000 9999 186450844", "output": "9324 4745 R" }, { "input": "10000 9999 197114268", "output": "9857 6990 R" }, { "input": "10000 9999 112390396", "output": "5621 818 R" }, { "input": "10000 10000 1", "output": "1 1 L" }, { "input": "10000 10000 2", "output": "1 1 R" }, { "input": "10000 10000 100000001", "output": "5001 1 L" }, { "input": "10000 10000 199999999", "output": "10000 10000 L" }, { "input": "10000 10000 200000000", "output": "10000 10000 R" }, { "input": "1 2 1", "output": "1 1 L" }, { "input": "1 2 2", "output": "1 1 R" }, { "input": "1 2 3", "output": "1 2 L" }, { "input": "1 2 4", "output": "1 2 R" }, { "input": "2 1 1", "output": "1 1 L" }, { "input": "2 1 2", "output": "1 1 R" }, { "input": "2 1 3", "output": "2 1 L" }, { "input": "2 1 4", "output": "2 1 R" }, { "input": "4 3 7", "output": "2 1 L" }, { "input": "1 1 1", "output": "1 1 L" } ]
1,676,523,563
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
11
62
0
n, m, k = map(int, input().split()) i = (k + m * 2 - 1) // (m * 2) k %= m * 2 if k == 0: print(n, m, "R") else: j = (k + 1) // 2 k %= 2 ar = ["R", "L"] print(i, j, ar[k])
Title: Santa Claus and a Place in a Class Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! Input Specification: The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. Output Specification: Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. Demo Input: ['4 3 9\n', '4 3 24\n', '2 4 4\n'] Demo Output: ['2 2 L\n', '4 3 R\n', '1 2 R\n'] Note: The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
```python n, m, k = map(int, input().split()) i = (k + m * 2 - 1) // (m * 2) k %= m * 2 if k == 0: print(n, m, "R") else: j = (k + 1) // 2 k %= 2 ar = ["R", "L"] print(i, j, ar[k]) ```
0
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "output": "19" }, { "input": "10 9", "output": "11" }, { "input": "100 100", "output": "101" }, { "input": "2 27", "output": "2" }, { "input": "99 100", "output": "99" }, { "input": "99 2", "output": "197" }, { "input": "100 3", "output": "149" }, { "input": "98 3", "output": "146" }, { "input": "4 4", "output": "5" }, { "input": "100 2", "output": "199" }, { "input": "62 4", "output": "82" }, { "input": "99 10", "output": "109" }, { "input": "100 5", "output": "124" }, { "input": "80 80", "output": "81" }, { "input": "95 16", "output": "101" }, { "input": "75 16", "output": "79" }, { "input": "99 74", "output": "100" }, { "input": "20 21", "output": "20" }, { "input": "52 96", "output": "52" }, { "input": "24 5", "output": "29" } ]
1,646,458,725
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
n, m = map(int,input().split()) if m > n: print(n) else: c = n x, y = 1, n+1 while y-x>0: t = 0 for i in range(x, y): if i%m==0: ans += 1 t += 1 x = y y = y+t+1 print(c)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? Input Specification: The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['2 2\n', '9 3\n'] Demo Output: ['3\n', '13\n'] Note: In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
```python n, m = map(int,input().split()) if m > n: print(n) else: c = n x, y = 1, n+1 while y-x>0: t = 0 for i in range(x, y): if i%m==0: ans += 1 t += 1 x = y y = y+t+1 print(c) ```
-1
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1", "output": "4" }, { "input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "output": "3" } ]
1,697,280,804
2,147,483,647
Python 3
OK
TESTS
25
92
0
import math Rows = 5 Columns = 4 matrix = [] for i in range(Rows): single_row = list(map(int, input().split())) matrix.append(single_row) def find(element, mat ): for i in range(len(mat)): for j in range(len(mat[i])): if mat[i][j] == element: return (i, j) res=find(1,matrix) print(abs(res[1]-2)+abs(res[0]-2))
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. Input Specification: The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. Output Specification: Print a single integer — the minimum number of moves needed to make the matrix beautiful. Demo Input: ['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n'] Demo Output: ['3\n', '1\n'] Note: none
```python import math Rows = 5 Columns = 4 matrix = [] for i in range(Rows): single_row = list(map(int, input().split())) matrix.append(single_row) def find(element, mat ): for i in range(len(mat)): for j in range(len(mat[i])): if mat[i][j] == element: return (i, j) res=find(1,matrix) print(abs(res[1]-2)+abs(res[0]-2)) ```
3
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces. All five kinds of polyhedrons are shown on the picture below: Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron", "output": "256" }, { "input": "1\nTetrahedron", "output": "4" }, { "input": "1\nCube", "output": "6" }, { "input": "1\nOctahedron", "output": "8" }, { "input": "1\nDodecahedron", "output": "12" }, { "input": "1\nIcosahedron", "output": "20" }, { "input": "28\nOctahedron\nDodecahedron\nOctahedron\nOctahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nDodecahedron\nDodecahedron\nCube\nDodecahedron\nCube\nTetrahedron\nCube\nCube\nTetrahedron\nDodecahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nIcosahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron", "output": "340" } ]
1,693,809,991
2,147,483,647
Python 3
OK
TESTS
30
202
0
v = {'Tetrahedron': 4,'Cube': 6,'Octahedron': 8,'Dodecahedron': 12,'Icosahedron': 20} n = int(input()) ans = 0 for i in range(0, n): ans += v[input()] print(ans)
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces. All five kinds of polyhedrons are shown on the picture below: Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number! Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron. Output Specification: Output one number — the total number of faces in all the polyhedrons in Anton's collection. Demo Input: ['4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n', '3\nDodecahedron\nOctahedron\nOctahedron\n'] Demo Output: ['42\n', '28\n'] Note: In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
```python v = {'Tetrahedron': 4,'Cube': 6,'Octahedron': 8,'Dodecahedron': 12,'Icosahedron': 20} n = int(input()) ans = 0 for i in range(0, n): ans += v[input()] print(ans) ```
3
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n1 1\n1 1", "output": "maybe" }, { "input": "2\n4126 4126\n4126 4126", "output": "maybe" }, { "input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423", "output": "rated" }, { "input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110", "output": "unrated" }, { "input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143", "output": "maybe" }, { "input": "2\n3936 3936\n2967 2967", "output": "maybe" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 1\n1 2", "output": "rated" }, { "input": "2\n2967 2967\n3936 3936", "output": "unrated" }, { "input": "3\n1200 1200\n1200 1200\n1300 1300", "output": "unrated" }, { "input": "3\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "3\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "2\n3 2\n3 2", "output": "rated" }, { "input": "3\n5 5\n4 4\n3 4", "output": "rated" }, { "input": "3\n200 200\n200 200\n300 300", "output": "unrated" }, { "input": "3\n1 1\n2 2\n3 3", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699", "output": "maybe" }, { "input": "2\n10 10\n8 8", "output": "maybe" }, { "input": "3\n1500 1500\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "3\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n100 100\n100 100\n70 70\n80 80", "output": "unrated" }, { "input": "2\n1 2\n2 1", "output": "rated" }, { "input": "3\n5 5\n4 3\n3 3", "output": "rated" }, { "input": "3\n1600 1650\n1500 1550\n1400 1450", "output": "rated" }, { "input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700", "output": "unrated" }, { "input": "2\n1600 1600\n1400 1400", "output": "maybe" }, { "input": "2\n3 1\n9 8", "output": "rated" }, { "input": "2\n2 1\n1 1", "output": "rated" }, { "input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670", "output": "unrated" }, { "input": "2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n10 11\n5 4", "output": "rated" }, { "input": "2\n15 14\n13 12", "output": "rated" }, { "input": "2\n2 1\n2 2", "output": "rated" }, { "input": "3\n2670 2670\n3670 3670\n4106 4106", "output": "unrated" }, { "input": "3\n4 5\n3 3\n2 2", "output": "rated" }, { "input": "2\n10 9\n10 10", "output": "rated" }, { "input": "3\n1011 1011\n1011 999\n2200 2100", "output": "rated" }, { "input": "2\n3 3\n5 5", "output": "unrated" }, { "input": "2\n1500 1500\n3000 2000", "output": "rated" }, { "input": "2\n5 6\n5 5", "output": "rated" }, { "input": "3\n2000 2000\n1500 1501\n500 500", "output": "rated" }, { "input": "2\n2 3\n2 2", "output": "rated" }, { "input": "2\n3 3\n2 2", "output": "maybe" }, { "input": "2\n1 2\n1 1", "output": "rated" }, { "input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n15 14\n14 13", "output": "rated" }, { "input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900", "output": "unrated" }, { "input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884", "output": "rated" }, { "input": "2\n100 99\n100 100", "output": "rated" }, { "input": "4\n2 2\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "3\n100 101\n100 100\n100 100", "output": "rated" }, { "input": "4\n1000 1001\n900 900\n950 950\n890 890", "output": "rated" }, { "input": "2\n2 3\n1 1", "output": "rated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n3 2\n2 2", "output": "rated" }, { "input": "2\n3 2\n3 3", "output": "rated" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "3\n3 2\n3 3\n3 3", "output": "rated" }, { "input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "3\n1000 1000\n500 500\n400 300", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000", "output": "unrated" }, { "input": "2\n1 1\n2 3", "output": "rated" }, { "input": "2\n6 2\n6 2", "output": "rated" }, { "input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246", "output": "unrated" }, { "input": "2\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699", "output": "maybe" }, { "input": "2\n20 30\n10 5", "output": "rated" }, { "input": "3\n1 1\n2 2\n1 1", "output": "unrated" }, { "input": "2\n1 2\n3 3", "output": "rated" }, { "input": "5\n5 5\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 2\n2 1", "output": "rated" }, { "input": "2\n100 100\n90 89", "output": "rated" }, { "input": "2\n1000 900\n2000 2000", "output": "rated" }, { "input": "2\n50 10\n10 50", "output": "rated" }, { "input": "2\n200 200\n100 100", "output": "maybe" }, { "input": "3\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "3\n1000 1000\n300 300\n100 100", "output": "maybe" }, { "input": "4\n2 2\n2 2\n3 3\n4 4", "output": "unrated" }, { "input": "2\n5 3\n6 3", "output": "rated" }, { "input": "2\n1200 1100\n1200 1000", "output": "rated" }, { "input": "2\n5 5\n4 4", "output": "maybe" }, { "input": "2\n5 5\n3 3", "output": "maybe" }, { "input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100", "output": "unrated" }, { "input": "5\n10 10\n9 9\n8 8\n7 7\n6 6", "output": "maybe" }, { "input": "3\n1000 1000\n300 300\n10 10", "output": "maybe" }, { "input": "5\n6 6\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "2\n3 3\n1 1", "output": "maybe" }, { "input": "4\n2 2\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n1000 1000\n700 700", "output": "maybe" }, { "input": "2\n4 3\n5 3", "output": "rated" }, { "input": "2\n1000 1000\n1100 1100", "output": "unrated" }, { "input": "4\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "3\n1 1\n2 3\n2 2", "output": "rated" }, { "input": "2\n1 2\n1 3", "output": "rated" }, { "input": "2\n3 3\n1 2", "output": "rated" }, { "input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "5\n1 1\n2 2\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "2\n10 10\n1 2", "output": "rated" }, { "input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900", "output": "unrated" }, { "input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699", "output": "unrated" }, { "input": "2\n100 100\n110 110", "output": "unrated" }, { "input": "3\n3 3\n3 3\n4 4", "output": "unrated" }, { "input": "3\n3 3\n3 2\n4 4", "output": "rated" }, { "input": "3\n5 2\n4 4\n3 3", "output": "rated" }, { "input": "4\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n1 1\n3 2", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699", "output": "unrated" }, { "input": "3\n3 3\n3 3\n3 4", "output": "rated" }, { "input": "3\n1 2\n2 2\n3 3", "output": "rated" }, { "input": "3\n1 2\n1 2\n1 2", "output": "rated" }, { "input": "2\n2 1\n2 1", "output": "rated" }, { "input": "2\n1 2\n3 4", "output": "rated" }, { "input": "2\n3 2\n2 3", "output": "rated" }, { "input": "3\n1500 1500\n1600 1600\n1600 1600", "output": "unrated" }, { "input": "3\n1 1\n3 3\n4 4", "output": "unrated" }, { "input": "3\n1 1\n2 2\n2 2", "output": "unrated" }, { "input": "2\n10 12\n8 8", "output": "rated" }, { "input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500", "output": "unrated" }, { "input": "2\n1 2\n2 2", "output": "rated" }, { "input": "3\n1500 1400\n1200 1200\n1100 1100", "output": "rated" }, { "input": "2\n10 12\n10 10", "output": "rated" }, { "input": "3\n1500 1500\n1400 1400\n1300 1300", "output": "maybe" }, { "input": "3\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "3\n2 6\n3 5\n4 4", "output": "rated" }, { "input": "2\n5 6\n4 6", "output": "rated" }, { "input": "4\n10 10\n10 10\n7 7\n8 8", "output": "unrated" }, { "input": "2\n4 4\n3 3", "output": "maybe" } ]
1,579,869,298
2,147,483,647
Python 3
OK
TESTS
150
124
307,200
from math import inf def solve(): unrated = False for i in range(n): if rates[i][0] != rates[i][1]: return 'rated' if i - 1 >= 0 and rates[i-1] < rates[i]: unrated = True return 'unrated' if unrated else 'maybe' def main(): global rates, n n = int(input()) rates = [list(map(int, input().split())) for _ in range(n)] print(solve()) main()
Title: Is it rated? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. Output Specification: If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". Demo Input: ['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n'] Demo Output: ['rated\n', 'unrated\n', 'maybe\n'] Note: In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
```python from math import inf def solve(): unrated = False for i in range(n): if rates[i][0] != rates[i][1]: return 'rated' if i - 1 >= 0 and rates[i-1] < rates[i]: unrated = True return 'unrated' if unrated else 'maybe' def main(): global rates, n n = int(input()) rates = [list(map(int, input().split())) for _ in range(n)] print(solve()) main() ```
3
592
D
Super M
PROGRAMMING
2,200
[ "dfs and similar", "dp", "graphs", "trees" ]
null
null
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of *n* cities, connected by *n*<=-<=1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go from any city to any other city using only the given roads. There are *m* cities being attacked by humans. So Ari... we meant Super M have to immediately go to each of the cities being attacked to scare those bad humans. Super M can pass from one city to another only using the given roads. Moreover, passing through one road takes her exactly one kron - the time unit used in Byteforces. However, Super M is not on Byteforces now - she is attending a training camp located in a nearby country Codeforces. Fortunately, there is a special device in Codeforces that allows her to instantly teleport from Codeforces to any city of Byteforces. The way back is too long, so for the purpose of this problem teleportation is used exactly once. You are to help Super M, by calculating the city in which she should teleport at the beginning in order to end her job in the minimum time (measured in krons). Also, provide her with this time so she can plan her way back to Codeforces.
The first line of the input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=123456) - the number of cities in Byteforces, and the number of cities being attacked respectively. Then follow *n*<=-<=1 lines, describing the road system. Each line contains two city numbers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) - the ends of the road *i*. The last line contains *m* distinct integers - numbers of cities being attacked. These numbers are given in no particular order.
First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number. Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons. Note that the correct answer is always unique.
[ "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7\n", "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6\n" ]
[ "2\n3\n", "2\n4\n" ]
In the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/93d3c0306b529e9c2324f68158ca2156587473a2.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df80aa84591eaa7b9f52c88cc43b5f7da5bfead3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. However, you should choose the first one as it starts in the city with the lower number.
2,000
[ { "input": "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7", "output": "2\n3" }, { "input": "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6", "output": "2\n4" }, { "input": "2 1\n2 1\n1", "output": "1\n0" }, { "input": "1 1\n1", "output": "1\n0" }, { "input": "10 2\n6 9\n6 2\n1 6\n4 10\n3 7\n9 4\n9 5\n6 7\n2 8\n7 6", "output": "6\n1" }, { "input": "15 2\n7 12\n13 11\n6 8\n2 15\n10 9\n5 1\n13 5\n5 4\n14 3\n8 9\n8 4\n4 7\n12 14\n5 2\n7 4", "output": "4\n1" }, { "input": "20 2\n1 16\n12 5\n15 19\n18 9\n8 4\n10 16\n9 16\n20 15\n14 19\n7 4\n18 12\n17 12\n2 20\n6 14\n3 19\n7 19\n18 15\n19 13\n9 11\n12 18", "output": "12\n1" }, { "input": "4 2\n4 3\n3 1\n1 2\n3 4", "output": "3\n1" }, { "input": "8 5\n2 5\n1 8\n6 7\n3 4\n6 8\n8 5\n5 3\n1 6 7 3 8", "output": "3\n6" }, { "input": "16 8\n16 12\n16 15\n15 9\n15 13\n16 3\n15 2\n15 10\n1 2\n6 16\n5 15\n2 7\n15 4\n14 15\n11 16\n8 5\n5 10 14 6 8 3 1 9", "output": "1\n16" }, { "input": "32 28\n30 12\n30 27\n24 32\n6 13\n11 5\n4 30\n8 28\n9 20\n8 20\n7 20\n5 30\n18 5\n20 14\n23 20\n17 20\n8 26\n20 1\n15 2\n20 13\n24 20\n22 24\n25 16\n2 3\n19 5\n16 10\n31 2\n29 5\n20 16\n2 20\n5 21\n5 20\n32 11 6 12 22 30 23 21 14 13 1 20 7 25 9 29 10 27 5 19 24 31 15 26 8 3 28 17", "output": "3\n53" }, { "input": "10 3\n10 5\n3 2\n6 8\n1 5\n10 4\n6 1\n9 8\n2 9\n7 3\n3 9 1", "output": "1\n5" }, { "input": "7 5\n6 4\n5 6\n6 7\n2 3\n5 2\n2 1\n4 6 1 7 3", "output": "1\n8" }, { "input": "15 7\n5 4\n12 5\n7 13\n10 11\n3 8\n6 12\n3 15\n1 3\n5 14\n7 9\n1 10\n6 1\n12 7\n10 2\n4 10 8 13 1 7 9", "output": "4\n14" }, { "input": "31 16\n3 25\n8 1\n1 9\n1 23\n16 15\n10 6\n25 30\n20 29\n2 24\n3 7\n19 22\n2 12\n16 4\n7 26\n31 10\n17 13\n25 21\n7 18\n28 2\n6 27\n19 5\n13 3\n17 31\n10 16\n20 14\n8 19\n6 11\n28 20\n13 28\n31 8\n31 27 25 20 26 8 28 15 18 17 10 23 4 16 30 22", "output": "4\n34" }, { "input": "63 20\n35 26\n54 5\n32 56\n56 53\n59 46\n37 31\n46 8\n4 1\n2 47\n59 42\n55 11\n62 6\n30 7\n60 24\n41 36\n34 22\n24 34\n21 2\n12 52\n8 44\n60 21\n24 30\n48 35\n48 25\n32 57\n20 37\n11 54\n11 62\n42 58\n31 43\n12 23\n55 48\n51 55\n41 27\n25 33\n21 18\n42 12\n4 15\n51 60\n62 39\n46 41\n57 9\n30 61\n31 4\n58 13\n34 29\n37 32\n18 16\n57 45\n2 49\n40 51\n43 17\n40 20\n20 59\n8 19\n58 10\n43 63\n54 50\n18 14\n25 38\n56 28\n35 3\n41 36 18 28 54 22 20 6 23 38 33 52 48 44 29 56 63 4 27 50", "output": "6\n66" }, { "input": "4 2\n2 3\n2 1\n2 4\n3 4", "output": "3\n2" }, { "input": "13 11\n4 11\n2 7\n4 13\n8 12\n8 9\n8 6\n3 8\n4 1\n2 10\n2 5\n3 4\n3 2\n10 4 5 6 1 2 3 9 13 7 12", "output": "1\n18" }, { "input": "7 5\n1 5\n4 1\n1 3\n7 1\n1 6\n1 2\n2 4 1 3 7", "output": "2\n6" }, { "input": "12 9\n11 12\n1 10\n1 7\n5 6\n8 7\n9 8\n4 5\n1 4\n2 3\n1 2\n10 11\n4 9 11 3 5 12 8 6 7", "output": "6\n16" }, { "input": "56 34\n7 31\n47 6\n13 4\n51 29\n13 12\n10 52\n10 41\n1 47\n47 54\n9 1\n4 27\n4 40\n49 19\n21 26\n24 33\n56 49\n41 56\n7 23\n41 48\n16 34\n35 9\n56 51\n5 43\n44 46\n10 25\n49 2\n1 21\n9 32\n33 20\n16 5\n5 35\n55 50\n55 53\n37 44\n43 15\n4 55\n8 10\n8 24\n21 42\n37 8\n39 13\n49 38\n39 16\n50 3\n55 7\n51 45\n21 11\n51 28\n50 18\n50 30\n5 37\n7 17\n35 22\n47 36\n35 14\n3 38 47 22 34 10 54 50 9 52 36 1 21 29 28 6 13 39 4 40 53 51 35 55 45 18 44 20 42 31 11 46 41 12", "output": "3\n70" }, { "input": "26 22\n20 16\n2 7\n7 19\n5 9\n20 23\n22 18\n24 3\n8 22\n16 10\n5 2\n7 15\n22 14\n25 4\n25 11\n24 13\n8 24\n13 1\n20 8\n22 6\n7 26\n16 12\n16 5\n13 21\n25 17\n2 25\n16 4 7 24 10 12 2 23 20 1 26 14 8 9 3 6 21 13 11 18 22 17", "output": "1\n37" }, { "input": "43 13\n7 28\n17 27\n39 8\n21 3\n17 20\n17 2\n9 6\n35 23\n43 22\n7 41\n5 24\n26 11\n21 43\n41 17\n16 5\n25 15\n39 10\n18 7\n37 33\n39 13\n39 16\n10 12\n1 21\n2 25\n14 36\n12 7\n16 34\n24 4\n25 40\n5 29\n37 31\n3 32\n22 14\n16 35\n5 37\n10 38\n25 19\n9 1\n26 42\n43 26\n10 30\n33 9\n28 6 42 38 27 32 8 11 36 7 41 29 19", "output": "19\n41" }, { "input": "21 20\n16 9\n7 11\n4 12\n2 17\n17 7\n5 2\n2 8\n4 10\n8 19\n6 15\n2 6\n12 18\n16 5\n20 16\n6 14\n5 3\n5 21\n20 1\n17 13\n6 4\n6 4 18 11 14 1 19 15 10 8 9 17 16 3 20 13 2 5 12 21", "output": "1\n32" }, { "input": "29 6\n16 9\n20 13\n24 3\n24 28\n22 12\n10 11\n10 26\n22 4\n10 27\n5 1\n2 23\n23 5\n16 7\n8 24\n7 19\n19 17\n8 10\n20 16\n20 25\n24 20\n23 15\n22 29\n2 8\n7 22\n2 21\n23 14\n19 18\n19 6\n19 17 18 27 29 4", "output": "4\n16" }, { "input": "31 29\n10 14\n16 6\n23 22\n25 23\n2 27\n24 17\n20 8\n5 2\n8 24\n16 5\n10 26\n8 7\n5 29\n20 16\n13 9\n13 21\n24 30\n13 1\n10 15\n23 3\n25 10\n2 25\n20 13\n25 11\n8 12\n30 28\n20 18\n5 4\n23 19\n16 31\n13 14 3 30 5 6 26 22 25 1 23 7 31 12 16 28 17 2 8 18 24 4 20 21 15 11 9 29 10", "output": "3\n46" }, { "input": "54 8\n33 9\n39 36\n22 14\n24 13\n8 50\n34 52\n47 2\n35 44\n16 54\n34 25\n1 3\n39 11\n9 17\n43 19\n10 40\n47 38\n5 37\n21 47\n37 12\n16 6\n37 7\n32 26\n39 42\n44 10\n1 18\n37 8\n9 1\n8 24\n10 33\n33 53\n5 4\n21 30\n9 31\n24 28\n24 49\n16 5\n34 35\n21 48\n47 43\n13 34\n39 16\n10 27\n22 32\n43 22\n13 46\n33 23\n44 15\n1 21\n8 41\n43 45\n5 29\n35 20\n13 51\n40 50 33 14 48 25 44 9", "output": "14\n21" }, { "input": "17 12\n5 2\n4 3\n8 17\n2 4\n2 8\n17 12\n8 10\n6 11\n16 7\n4 14\n15 13\n6 9\n4 6\n15 16\n16 5\n9 1\n4 8 1 9 3 12 15 10 13 6 14 16", "output": "1\n20" }, { "input": "28 6\n25 21\n9 18\n25 1\n16 5\n9 11\n28 19\n5 2\n20 16\n20 13\n2 23\n5 25\n8 24\n14 27\n3 15\n24 28\n8 10\n22 14\n14 17\n13 9\n3 22\n22 26\n16 7\n2 8\n25 3\n3 12\n14 4\n9 6\n28 27 22 24 20 16", "output": "27\n13" }, { "input": "10 9\n3 9\n4 8\n10 1\n2 3\n5 6\n4 3\n1 2\n5 4\n6 7\n9 1 5 8 7 3 4 6 10", "output": "7\n11" }, { "input": "9 6\n1 6\n3 4\n9 7\n3 2\n8 7\n2 1\n6 7\n3 5\n2 5 1 6 3 9", "output": "5\n6" }, { "input": "19 11\n8 9\n10 13\n16 15\n6 4\n3 2\n17 16\n4 7\n1 14\n10 11\n15 14\n4 3\n10 12\n4 5\n2 1\n16 19\n8 1\n10 9\n18 16\n10 14 18 12 17 11 19 8 1 3 9", "output": "11\n18" }, { "input": "36 5\n36 33\n11 12\n14 12\n25 24\n27 26\n23 24\n20 19\n1 2\n3 2\n17 18\n33 34\n23 1\n32 31\n12 15\n25 26\n4 5\n5 8\n5 6\n26 29\n1 9\n35 33\n33 32\n16 1\n3 4\n31 30\n16 17\n19 21\n1 30\n7 5\n9 10\n13 12\n19 18\n10 11\n22 19\n28 26\n29 12 11 17 33", "output": "12\n21" }, { "input": "10 2\n5 1\n1 3\n3 4\n4 2\n5 10\n1 9\n3 8\n4 7\n2 6\n3 4", "output": "3\n1" }, { "input": "53 30\n41 42\n27 24\n13 11\n10 11\n32 33\n34 33\n37 40\n21 22\n21 20\n46 47\n2 1\n31 30\n29 30\n11 14\n42 43\n50 51\n34 35\n36 35\n24 23\n48 47\n41 1\n28 29\n45 44\n16 15\n5 4\n6 5\n18 19\n9 8\n37 38\n11 12\n39 37\n49 48\n50 49\n43 44\n50 53\n3 4\n50 52\n24 25\n7 6\n46 45\n2 3\n17 18\n31 32\n19 20\n7 8\n15 1\n36 37\n23 22\n9 10\n17 16\n24 26\n28 1\n38 52 41 35 53 43 3 29 36 4 23 20 46 5 40 30 49 25 16 48 17 27 21 9 45 44 15 13 14 2", "output": "13\n74" }, { "input": "10 4\n2 3\n4 2\n8 9\n6 5\n8 1\n5 1\n8 10\n7 5\n1 2\n4 10 2 5", "output": "4\n6" }, { "input": "10 5\n4 5\n9 1\n1 2\n7 1\n5 1\n10 1\n7 3\n6 3\n5 8\n5 2 7 10 1", "output": "2\n6" }, { "input": "10 4\n8 7\n7 6\n1 2\n3 2\n3 4\n6 5\n10 7\n7 9\n5 4\n9 5 10 4", "output": "4\n6" }, { "input": "5 4\n2 3\n2 1\n3 5\n4 3\n4 2 5 1", "output": "1\n5" }, { "input": "5 1\n1 2\n2 3\n3 4\n4 5\n4", "output": "4\n0" } ]
1,446,380,910
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; const int maxn = 123456 + 5; vector<int> G[maxn]; int n, m; int cnt; bool On[maxn]; int A[maxn]; int tar, d; int dis[maxn]; bool vis[maxn]; bool dfs1(int s) { vis[s] = true; bool flag = false; for(int i = 0; i < G[s].size(); i++) { int u = G[s][i]; if(!vis[u]) { dis[u] = dis[s] + 1; flag |= dfs1(u); } } if(A[s]) { flag = true; if(dis[s] > d || (dis[s] == d && s < tar)) { d = dis[s]; tar = s; } } if(flag) { On[s] = true; cnt++; } return flag; } void dfs2(int s) { vis[s] = true; for(int i = 0; i < G[s].size(); i++) { int u = G[s][i]; if(!vis[u]) { dis[u] = dis[s] + 1; if(dis[u] > d || (dis[u] == d && u < tar)) { d = dis[u]; tar = u; } dfs2(u); } } } int main() { scanf("%d%d", &n, &m); for(int i = 0; i < n - 1; i++) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } for(int i = 0; i < m; i++) { int x; scanf("%d", &x); A[x] = true; tar = x; } fill(dis, dis + n + 1, -1); fill(vis, vis + n + 1, false); d = 0; dis[tar] = 0; dfs1(tar); int k1 = tar; fill(dis, dis + n + 1, -1); fill(vis, vis + n + 1, false); d = 0; dis[tar] = 0; dfs2(tar); int ans = min(k1, tar); printf("%d\n%d", ans, 2*(cnt-1) - d); return 0; }
Title: Super M Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of *n* cities, connected by *n*<=-<=1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go from any city to any other city using only the given roads. There are *m* cities being attacked by humans. So Ari... we meant Super M have to immediately go to each of the cities being attacked to scare those bad humans. Super M can pass from one city to another only using the given roads. Moreover, passing through one road takes her exactly one kron - the time unit used in Byteforces. However, Super M is not on Byteforces now - she is attending a training camp located in a nearby country Codeforces. Fortunately, there is a special device in Codeforces that allows her to instantly teleport from Codeforces to any city of Byteforces. The way back is too long, so for the purpose of this problem teleportation is used exactly once. You are to help Super M, by calculating the city in which she should teleport at the beginning in order to end her job in the minimum time (measured in krons). Also, provide her with this time so she can plan her way back to Codeforces. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=123456) - the number of cities in Byteforces, and the number of cities being attacked respectively. Then follow *n*<=-<=1 lines, describing the road system. Each line contains two city numbers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) - the ends of the road *i*. The last line contains *m* distinct integers - numbers of cities being attacked. These numbers are given in no particular order. Output Specification: First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number. Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons. Note that the correct answer is always unique. Demo Input: ['7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7\n', '6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6\n'] Demo Output: ['2\n3\n', '2\n4\n'] Note: In the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/93d3c0306b529e9c2324f68158ca2156587473a2.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df80aa84591eaa7b9f52c88cc43b5f7da5bfead3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. However, you should choose the first one as it starts in the city with the lower number.
```python #include <bits/stdc++.h> using namespace std; const int maxn = 123456 + 5; vector<int> G[maxn]; int n, m; int cnt; bool On[maxn]; int A[maxn]; int tar, d; int dis[maxn]; bool vis[maxn]; bool dfs1(int s) { vis[s] = true; bool flag = false; for(int i = 0; i < G[s].size(); i++) { int u = G[s][i]; if(!vis[u]) { dis[u] = dis[s] + 1; flag |= dfs1(u); } } if(A[s]) { flag = true; if(dis[s] > d || (dis[s] == d && s < tar)) { d = dis[s]; tar = s; } } if(flag) { On[s] = true; cnt++; } return flag; } void dfs2(int s) { vis[s] = true; for(int i = 0; i < G[s].size(); i++) { int u = G[s][i]; if(!vis[u]) { dis[u] = dis[s] + 1; if(dis[u] > d || (dis[u] == d && u < tar)) { d = dis[u]; tar = u; } dfs2(u); } } } int main() { scanf("%d%d", &n, &m); for(int i = 0; i < n - 1; i++) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } for(int i = 0; i < m; i++) { int x; scanf("%d", &x); A[x] = true; tar = x; } fill(dis, dis + n + 1, -1); fill(vis, vis + n + 1, false); d = 0; dis[tar] = 0; dfs1(tar); int k1 = tar; fill(dis, dis + n + 1, -1); fill(vis, vis + n + 1, false); d = 0; dis[tar] = 0; dfs2(tar); int ans = min(k1, tar); printf("%d\n%d", ans, 2*(cnt-1) - d); return 0; } ```
-1
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,588,683,065
365
Python 3
OK
TESTS
34
109
0
from sys import stdin #n=int(stdin.readline().strip()) n,m=map(int,stdin.readline().strip().split()) #s=list(map(int,stdin.readline().strip().split())) x=0 for i in range(n): a,b=stdin.readline().strip().split() b=int(b) if a=="+": m+=int(b) else: if m>=b: m-=b else: x+=1 print(m,x)
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 from sys import stdin #n=int(stdin.readline().strip()) n,m=map(int,stdin.readline().strip().split()) #s=list(map(int,stdin.readline().strip().split())) x=0 for i in range(n): a,b=stdin.readline().strip().split() b=int(b) if a=="+": m+=int(b) else: if m>=b: m-=b else: x+=1 print(m,x) ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,525,264,083
2,147,483,647
Python 3
OK
TESTS
32
186
7,065,600
x=int(input()) s=list(map(int,input().split())) p="" q="" for n in range(x): if s[n]%2==0: p=p+str(n+1) else: q=q+str(n+1) if len(p)>len(q): print(q) else: print(p)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python x=int(input()) s=list(map(int,input().split())) p="" q="" for n in range(x): if s[n]%2==0: p=p+str(n+1) else: q=q+str(n+1) if len(p)>len(q): print(q) else: print(p) ```
3.940339
615
A
Bulbs
PROGRAMMING
800
[ "implementation" ]
null
null
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs.
If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO".
[ "3 4\n2 1 4\n3 1 3 1\n1 2\n", "3 3\n1 1\n1 2\n1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
500
[ { "input": "3 4\n2 1 4\n3 1 3 1\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 2\n1 1", "output": "NO" }, { "input": "3 4\n1 1\n1 2\n1 3", "output": "NO" }, { "input": "1 5\n5 1 2 3 4 5", "output": "YES" }, { "input": "1 5\n5 4 4 1 2 3", "output": "NO" }, { "input": "1 5\n5 1 1 1 1 5", "output": "NO" }, { "input": "2 5\n4 3 1 4 2\n4 2 3 4 5", "output": "YES" }, { "input": "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1", "output": "YES" }, { "input": "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n1 26\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n0\n0\n0\n1 3\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 40\n0\n0\n0\n1 26\n0\n0\n0\n0\n0\n1 97\n0\n1 5\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "100 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "5 6\n3 1 2 6\n3 1 2 6\n1 1\n2 3 4\n3 1 5 6", "output": "YES" }, { "input": "5 2\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "NO" }, { "input": "1 4\n3 1 2 3", "output": "NO" }, { "input": "1 4\n3 2 3 4", "output": "NO" }, { "input": "2 4\n3 2 3 4\n1 1", "output": "YES" }, { "input": "2 4\n3 1 2 3\n1 4", "output": "YES" }, { "input": "5 1\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "1 1\n0", "output": "NO" }, { "input": "1 10\n10 1 2 3 4 5 6 7 8 9 10", "output": "YES" }, { "input": "1 1\n1 1", "output": "YES" }, { "input": "1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99", "output": "NO" }, { "input": "1 3\n3 1 2 1", "output": "NO" }, { "input": "1 100\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "YES" } ]
1,677,871,983
2,147,483,647
Python 3
OK
TESTS
45
46
0
def HARD_WAY(): n,m=map(int,input().split()) l=[] while n: c=map(int,input().split()) c=list(c) for x in c[1:]: if x not in l: l.append(x) n-=1 l=set(l) i=1 while i<=m: if i not in l: return "NO" i+=1 return "YES" print(HARD_WAY())
Title: Bulbs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on. Input Specification: The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs. Output Specification: If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". Demo Input: ['3 4\n2 1 4\n3 1 3 1\n1 2\n', '3 3\n1 1\n1 2\n1 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
```python def HARD_WAY(): n,m=map(int,input().split()) l=[] while n: c=map(int,input().split()) c=list(c) for x in c[1:]: if x not in l: l.append(x) n-=1 l=set(l) i=1 while i<=m: if i not in l: return "NO" i+=1 return "YES" print(HARD_WAY()) ```
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,692,615,032
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
61
0
n,m,a=input().split() if(int(n)==int(m)==int(a)): print(1) elif(int(n)<int(a)<=int(m)): number_of_flagstone=int(n)//int(a) print(number_of_flagstone+1) elif(int(m)<int(a)<=int(n)): number_of_flagstone=int(m)//int(a) print(number_of_flagstone+1) elif((int(n)==int(m))>int(a)): number_of_flagstone=int(m)//int(a) print(2*(number_of_flagstone+1)) elif(int(a)<(int(n)==int(m))): print(1)
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=input().split() if(int(n)==int(m)==int(a)): print(1) elif(int(n)<int(a)<=int(m)): number_of_flagstone=int(n)//int(a) print(number_of_flagstone+1) elif(int(m)<int(a)<=int(n)): number_of_flagstone=int(m)//int(a) print(number_of_flagstone+1) elif((int(n)==int(m))>int(a)): number_of_flagstone=int(m)//int(a) print(2*(number_of_flagstone+1)) elif(int(a)<(int(n)==int(m))): print(1) ```
0
513
A
Game
PROGRAMMING
800
[ "constructive algorithms", "math" ]
null
null
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally.
The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output "First" if the first player wins and "Second" otherwise.
[ "2 2 1 2\n", "2 1 1 1\n" ]
[ "Second\n", "First\n" ]
Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.
3
[ { "input": "2 2 1 2", "output": "Second" }, { "input": "2 1 1 1", "output": "First" }, { "input": "5 7 4 1", "output": "Second" }, { "input": "5 7 1 4", "output": "Second" }, { "input": "5 7 10 10", "output": "Second" }, { "input": "5 7 1 10", "output": "Second" }, { "input": "1 1 1 1", "output": "Second" }, { "input": "50 50 50 50", "output": "Second" }, { "input": "50 49 1 2", "output": "First" }, { "input": "50 48 3 1", "output": "First" }, { "input": "48 50 12 11", "output": "Second" }, { "input": "49 50 11 12", "output": "Second" }, { "input": "49 49 4 1", "output": "Second" }, { "input": "49 49 3 3", "output": "Second" }, { "input": "1 50 1 50", "output": "Second" }, { "input": "1 50 50 50", "output": "Second" }, { "input": "50 1 1 1", "output": "First" }, { "input": "50 1 1 50", "output": "First" }, { "input": "32 31 10 9", "output": "First" }, { "input": "32 4 17 3", "output": "First" } ]
1,600,632,807
2,147,483,647
Python 3
OK
TESTS
20
109
0
n=str(input()).split() n1=int(n[0]) n2=int(n[1]) if n1<=n2: print('Second') elif n1>n2: print('First')
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally. Input Specification: The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission. Output Specification: Output "First" if the first player wins and "Second" otherwise. Demo Input: ['2 2 1 2\n', '2 1 1 1\n'] Demo Output: ['Second\n', 'First\n'] Note: Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.
```python n=str(input()).split() n1=int(n[0]) n2=int(n[1]) if n1<=n2: print('Second') elif n1>n2: print('First') ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,573,633,996
2,147,483,647
Python 3
OK
TESTS
30
248
0
''' Hariom_Pandey 13.11.2019 ''' import math as mt import sys as sy class abc: def mkl(self,): li=[] word = input() u = [x for x in word if x.isupper()] l = [x for x in word if x.islower()] if len(u)<len(l): print(word.lower()) elif len(l)<len(u): print(word.upper()) elif len(u)==len(l): print(word.lower()) b=abc() b.mkl()
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python ''' Hariom_Pandey 13.11.2019 ''' import math as mt import sys as sy class abc: def mkl(self,): li=[] word = input() u = [x for x in word if x.isupper()] l = [x for x in word if x.islower()] if len(u)<len(l): print(word.lower()) elif len(l)<len(u): print(word.upper()) elif len(u)==len(l): print(word.lower()) b=abc() b.mkl() ```
3.938
13
A
Numbers
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Numbers
1
64
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.
Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000).
Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.
[ "5\n", "3\n" ]
[ "7/3\n", "2/1\n" ]
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
0
[ { "input": "5", "output": "7/3" }, { "input": "3", "output": "2/1" }, { "input": "1000", "output": "90132/499" }, { "input": "927", "output": "155449/925" }, { "input": "260", "output": "6265/129" }, { "input": "131", "output": "3370/129" }, { "input": "386", "output": "857/12" }, { "input": "277", "output": "2864/55" }, { "input": "766", "output": "53217/382" }, { "input": "28", "output": "85/13" }, { "input": "406", "output": "7560/101" }, { "input": "757", "output": "103847/755" }, { "input": "6", "output": "9/4" }, { "input": "239", "output": "10885/237" }, { "input": "322", "output": "2399/40" }, { "input": "98", "output": "317/16" }, { "input": "208", "output": "4063/103" }, { "input": "786", "output": "55777/392" }, { "input": "879", "output": "140290/877" }, { "input": "702", "output": "89217/700" }, { "input": "948", "output": "7369/43" }, { "input": "537", "output": "52753/535" }, { "input": "984", "output": "174589/982" }, { "input": "934", "output": "157951/932" }, { "input": "726", "output": "95491/724" }, { "input": "127", "output": "3154/125" }, { "input": "504", "output": "23086/251" }, { "input": "125", "output": "3080/123" }, { "input": "604", "output": "33178/301" }, { "input": "115", "output": "2600/113" }, { "input": "27", "output": "167/25" }, { "input": "687", "output": "85854/685" }, { "input": "880", "output": "69915/439" }, { "input": "173", "output": "640/19" }, { "input": "264", "output": "6438/131" }, { "input": "785", "output": "111560/783" }, { "input": "399", "output": "29399/397" }, { "input": "514", "output": "6031/64" }, { "input": "381", "output": "26717/379" }, { "input": "592", "output": "63769/590" }, { "input": "417", "output": "32002/415" }, { "input": "588", "output": "62723/586" }, { "input": "852", "output": "131069/850" }, { "input": "959", "output": "5059/29" }, { "input": "841", "output": "127737/839" }, { "input": "733", "output": "97598/731" }, { "input": "692", "output": "87017/690" }, { "input": "69", "output": "983/67" }, { "input": "223", "output": "556/13" }, { "input": "93", "output": "246/13" }, { "input": "643", "output": "75503/641" }, { "input": "119", "output": "2833/117" }, { "input": "498", "output": "1459/16" }, { "input": "155", "output": "4637/153" }, { "input": "305", "output": "17350/303" }, { "input": "454", "output": "37893/452" }, { "input": "88", "output": "1529/86" }, { "input": "850", "output": "32645/212" }, { "input": "474", "output": "20581/236" }, { "input": "309", "output": "17731/307" }, { "input": "762", "output": "105083/760" }, { "input": "591", "output": "63761/589" }, { "input": "457", "output": "38317/455" }, { "input": "141", "output": "3832/139" }, { "input": "385", "output": "27232/383" }, { "input": "387", "output": "27628/385" }, { "input": "469", "output": "40306/467" }, { "input": "624", "output": "35285/311" }, { "input": "330", "output": "487/8" }, { "input": "31", "output": "222/29" }, { "input": "975", "output": "171679/973" }, { "input": "584", "output": "62183/582" }, { "input": "668", "output": "81127/666" }, { "input": "331", "output": "20297/329" }, { "input": "189", "output": "6789/187" }, { "input": "251", "output": "11939/249" }, { "input": "876", "output": "69196/437" }, { "input": "615", "output": "68987/613" }, { "input": "451", "output": "37258/449" }, { "input": "499", "output": "45727/497" }, { "input": "699", "output": "89117/697" }, { "input": "619", "output": "70019/617" }, { "input": "413", "output": "10515/137" }, { "input": "197", "output": "7399/195" }, { "input": "794", "output": "14281/99" }, { "input": "659", "output": "79403/657" }, { "input": "653", "output": "77695/651" }, { "input": "23", "output": "45/7" }, { "input": "430", "output": "16985/214" }, { "input": "249", "output": "11659/247" }, { "input": "837", "output": "126869/835" }, { "input": "258", "output": "12373/256" }, { "input": "995", "output": "59665/331" }, { "input": "102", "output": "504/25" }, { "input": "989", "output": "177124/987" }, { "input": "376", "output": "13008/187" }, { "input": "657", "output": "15715/131" }, { "input": "746", "output": "50509/372" }, { "input": "602", "output": "13177/120" } ]
1,683,467,698
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def gcd(a, b): if b == 0: return a return gcd(b, a % b) def simplify_fraction(numerator, denominator): gcd_val = gcd(numerator, denominator) return numerator // gcd_val, denominator // gcd_val A = int(input()) sum_digits = 0 num_bases = A - 2 for base in range(2, A): n = A digits_sum = 0 while n > 0: digits_sum += n % base n //= base sum_digits += digits_sum avg_digits = sum_digits / num_bases numerator, denominator = simplify_fraction(avg_digits, 1) print(f"{numerator}/{denominator}")
Title: Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10. Input Specification: Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). Output Specification: Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. Demo Input: ['5\n', '3\n'] Demo Output: ['7/3\n', '2/1\n'] Note: In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
```python def gcd(a, b): if b == 0: return a return gcd(b, a % b) def simplify_fraction(numerator, denominator): gcd_val = gcd(numerator, denominator) return numerator // gcd_val, denominator // gcd_val A = int(input()) sum_digits = 0 num_bases = A - 2 for base in range(2, A): n = A digits_sum = 0 while n > 0: digits_sum += n % base n //= base sum_digits += digits_sum avg_digits = sum_digits / num_bases numerator, denominator = simplify_fraction(avg_digits, 1) print(f"{numerator}/{denominator}") ```
0
660
C
Hard Process
PROGRAMMING
1,600
[ "binary search", "dp", "two pointers" ]
null
null
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*).
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*.
On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones. On the second line print *n* integers *a**j* — the elements of the array *a* after the changes. If there are multiple answers, you can print any one of them.
[ "7 1\n1 0 0 1 1 0 1\n", "10 2\n1 0 0 1 0 1 0 1 0 1\n" ]
[ "4\n1 0 0 1 1 1 1\n", "5\n1 0 0 1 1 1 1 1 0 1\n" ]
none
0
[ { "input": "7 1\n1 0 0 1 1 0 1", "output": "4\n1 0 0 1 1 1 1" }, { "input": "10 2\n1 0 0 1 0 1 0 1 0 1", "output": "5\n1 0 0 1 1 1 1 1 0 1" }, { "input": "1 0\n0", "output": "0\n0" }, { "input": "1 0\n0", "output": "0\n0" }, { "input": "7 0\n0 1 0 0 0 1 0", "output": "1\n0 1 0 0 0 1 0" }, { "input": "7 2\n1 0 1 1 0 0 0", "output": "5\n1 1 1 1 1 0 0" }, { "input": "7 3\n1 0 0 0 0 1 0", "output": "4\n1 1 1 1 0 1 0" }, { "input": "3 0\n1 1 1", "output": "3\n1 1 1" }, { "input": "1 0\n1", "output": "1\n1" }, { "input": "2 0\n0 1", "output": "1\n0 1" }, { "input": "1 1\n0", "output": "1\n1" }, { "input": "3 1\n0 0 1", "output": "2\n0 1 1" }, { "input": "2 0\n0 0", "output": "0\n0 0" }, { "input": "3 1\n0 0 0", "output": "1\n1 0 0" }, { "input": "7 7\n1 0 1 0 0 0 0", "output": "7\n1 1 1 1 1 1 1" }, { "input": "1 1\n1", "output": "1\n1" }, { "input": "3 0\n0 0 0", "output": "0\n0 0 0" }, { "input": "7 3\n1 1 1 1 1 1 1", "output": "7\n1 1 1 1 1 1 1" }, { "input": "10 3\n0 0 1 0 0 1 0 0 1 1", "output": "6\n0 0 1 0 1 1 1 1 1 1" }, { "input": "2 1\n0 0", "output": "1\n1 0" }, { "input": "2 2\n1 0", "output": "2\n1 1" } ]
1,470,142,053
2,147,483,647
Python 3
OK
TESTS
38
358
14,438,400
n,k=map(int,input().split()) ara=list(map(int,input().split())) max=0 zero=0 value=0 end=0 for i in range(0,n): if ara[i]==0: zero+=1 if zero<=k: max+=1 end=i else: if ara[value]==0 : zero-= 1 value+= 1 print(max) for i in range(end-max+1,end+1): ara[i]=1 print(" ".join(map(str,ara)))
Title: Hard Process Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. Output Specification: On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones. On the second line print *n* integers *a**j* — the elements of the array *a* after the changes. If there are multiple answers, you can print any one of them. Demo Input: ['7 1\n1 0 0 1 1 0 1\n', '10 2\n1 0 0 1 0 1 0 1 0 1\n'] Demo Output: ['4\n1 0 0 1 1 1 1\n', '5\n1 0 0 1 1 1 1 1 0 1\n'] Note: none
```python n,k=map(int,input().split()) ara=list(map(int,input().split())) max=0 zero=0 value=0 end=0 for i in range(0,n): if ara[i]==0: zero+=1 if zero<=k: max+=1 end=i else: if ara[value]==0 : zero-= 1 value+= 1 print(max) for i in range(end-max+1,end+1): ara[i]=1 print(" ".join(map(str,ara))) ```
3
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,662,458,612
2,147,483,647
PyPy 3
OK
TESTS
52
154
0
n=int(input()) a=list(map(int,input().split())) k=sum(a)%2 c=0 for i in range(n): if a[i]%2==k: c+=1 print(c)
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())) k=sum(a)%2 c=0 for i in range(n): if a[i]%2==k: c+=1 print(c) ```
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,687,622,458
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
216
19,865,600
n1 = int(input()) n2 = int(input()) n3 = int(input()) n4 = int(input()) n_dragons = int(input()) print(len(set(range(1, n_dragons + 1, n1)) | set(range(1, n_dragons + 1, n2)) | set(range(1, n_dragons + 1, n3)) | set(range(1, n_dragons + 1, n4))))
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 n1 = int(input()) n2 = int(input()) n3 = int(input()) n4 = int(input()) n_dragons = int(input()) print(len(set(range(1, n_dragons + 1, n1)) | set(range(1, n_dragons + 1, n2)) | set(range(1, n_dragons + 1, n3)) | set(range(1, n_dragons + 1, n4)))) ```
0
811
A
Vladik and Courtesy
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
[ "1 1\n", "7 6\n" ]
[ "Valera\n", "Vladik\n" ]
Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "1 1", "output": "Valera" }, { "input": "7 6", "output": "Vladik" }, { "input": "25 38", "output": "Vladik" }, { "input": "8311 2468", "output": "Valera" }, { "input": "250708 857756", "output": "Vladik" }, { "input": "957985574 24997558", "output": "Valera" }, { "input": "999963734 999994456", "output": "Vladik" }, { "input": "1000000000 1000000000", "output": "Vladik" }, { "input": "946 879", "output": "Valera" }, { "input": "10819 45238", "output": "Vladik" }, { "input": "101357 236928", "output": "Vladik" }, { "input": "1033090 7376359", "output": "Vladik" }, { "input": "9754309 9525494", "output": "Valera" }, { "input": "90706344 99960537", "output": "Vladik" }, { "input": "965161805 908862070", "output": "Valera" }, { "input": "9 11", "output": "Valera" }, { "input": "3 2", "output": "Vladik" }, { "input": "6 6", "output": "Vladik" }, { "input": "4 4", "output": "Valera" }, { "input": "5 5", "output": "Valera" }, { "input": "5 4", "output": "Valera" }, { "input": "12345680 1", "output": "Valera" }, { "input": "9 10", "output": "Valera" }, { "input": "678 76687", "output": "Vladik" }, { "input": "1 678", "output": "Vladik" }, { "input": "45 1678", "output": "Vladik" }, { "input": "3 3", "output": "Vladik" }, { "input": "10 11", "output": "Valera" }, { "input": "2 1", "output": "Valera" }, { "input": "1 2", "output": "Vladik" }, { "input": "2 2", "output": "Vladik" }, { "input": "4 5", "output": "Valera" }, { "input": "9 6", "output": "Valera" }, { "input": "1 5", "output": "Vladik" }, { "input": "7 8", "output": "Vladik" }, { "input": "1000000000 999982505", "output": "Valera" }, { "input": "12 12", "output": "Vladik" }, { "input": "1000 950", "output": "Valera" }, { "input": "10 9", "output": "Valera" }, { "input": "100 9", "output": "Valera" }, { "input": "1000 996", "output": "Vladik" }, { "input": "9 5", "output": "Valera" } ]
1,554,129,642
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
512,000
from random import choice s = ["Vladik","Valera"] a = input() print(choice(s))
Title: Vladik and Courtesy Time Limit: None seconds Memory Limit: None megabytes Problem Description: At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Specification: Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. Output Specification: Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Demo Input: ['1 1\n', '7 6\n'] Demo Output: ['Valera\n', 'Vladik\n'] Note: Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python from random import choice s = ["Vladik","Valera"] a = input() print(choice(s)) ```
0
488
A
Giga Tower
PROGRAMMING
1,100
[ "brute force" ]
null
null
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?). Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number.
The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109).
Print the minimum *b* in a line.
[ "179\n", "-1\n", "18\n" ]
[ "1\n", "9\n", "10\n" ]
For the first sample, he has to arrive at the floor numbered 180. For the second sample, he will arrive at 8. Note that *b* should be positive, so the answer for the third sample is 10, not 0.
500
[ { "input": "179", "output": "1" }, { "input": "-1", "output": "9" }, { "input": "18", "output": "10" }, { "input": "-410058385", "output": "1" }, { "input": "-586825624", "output": "1" }, { "input": "852318890", "output": "1" }, { "input": "919067153", "output": "5" }, { "input": "690422411", "output": "7" }, { "input": "-408490162", "output": "1" }, { "input": "-8", "output": "16" }, { "input": "-6", "output": "14" }, { "input": "-4", "output": "12" }, { "input": "-2", "output": "10" }, { "input": "0", "output": "8" }, { "input": "2", "output": "6" }, { "input": "4", "output": "4" }, { "input": "6", "output": "2" }, { "input": "8", "output": "10" }, { "input": "1000000000", "output": "8" }, { "input": "-1000000000", "output": "2" }, { "input": "88888", "output": "1" }, { "input": "89", "output": "9" }, { "input": "-80000000", "output": "2" }, { "input": "-8888", "output": "1" }, { "input": "-17", "output": "9" }, { "input": "78", "output": "2" }, { "input": "-19", "output": "1" }, { "input": "-999999998", "output": "9" }, { "input": "-999999997", "output": "8" }, { "input": "999999997", "output": "1" }, { "input": "811111111", "output": "1" }, { "input": "-8", "output": "16" }, { "input": "-5", "output": "13" }, { "input": "-7", "output": "15" }, { "input": "1000000000", "output": "8" } ]
1,548,384,713
2,147,483,647
Python 3
OK
TESTS
35
109
0
n=input() x=1 while '8' not in str(int(n)+x): x+=1 print(x)
Title: Giga Tower Time Limit: None seconds Memory Limit: None megabytes Problem Description: Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?). Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number. Input Specification: The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). Output Specification: Print the minimum *b* in a line. Demo Input: ['179\n', '-1\n', '18\n'] Demo Output: ['1\n', '9\n', '10\n'] Note: For the first sample, he has to arrive at the floor numbered 180. For the second sample, he will arrive at 8. Note that *b* should be positive, so the answer for the third sample is 10, not 0.
```python n=input() x=1 while '8' not in str(int(n)+x): x+=1 print(x) ```
3
651
A
Joysticks
PROGRAMMING
1,100
[ "dp", "greedy", "implementation", "math" ]
null
null
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
[ "3 5\n", "4 4\n" ]
[ "6\n", "5\n" ]
In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
500
[ { "input": "3 5", "output": "6" }, { "input": "4 4", "output": "5" }, { "input": "100 100", "output": "197" }, { "input": "1 100", "output": "98" }, { "input": "100 1", "output": "98" }, { "input": "1 4", "output": "2" }, { "input": "1 1", "output": "0" }, { "input": "8 8", "output": "13" }, { "input": "7 2", "output": "7" }, { "input": "24 15", "output": "36" }, { "input": "19 30", "output": "47" }, { "input": "15 31", "output": "44" }, { "input": "14 15", "output": "27" }, { "input": "58 33", "output": "89" }, { "input": "15 25", "output": "38" }, { "input": "59 45", "output": "102" }, { "input": "3 73", "output": "74" }, { "input": "48 1", "output": "47" }, { "input": "100 25", "output": "122" }, { "input": "40 49", "output": "86" }, { "input": "85 73", "output": "155" }, { "input": "29 1", "output": "28" }, { "input": "74 25", "output": "97" }, { "input": "24 57", "output": "78" }, { "input": "23 12", "output": "33" }, { "input": "2 99", "output": "99" }, { "input": "98 2", "output": "97" }, { "input": "2 97", "output": "97" }, { "input": "30 54", "output": "81" }, { "input": "32 53", "output": "82" }, { "input": "32 54", "output": "84" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "1 3", "output": "2" }, { "input": "3 1", "output": "2" }, { "input": "1 4", "output": "2" }, { "input": "2 3", "output": "3" }, { "input": "3 2", "output": "3" } ]
1,569,824,280
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
108
0
a, b = map(int, input().split()) counter = 0 while a > 0 and b > 0: if a > b: b += 1 a += -2 counter += 1 else: a += 1 b += -2 counter += 1 print(counter)
Title: Joysticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent. Input Specification: The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. Output Specification: Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. Demo Input: ['3 5\n', '4 4\n'] Demo Output: ['6\n', '5\n'] Note: In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
```python a, b = map(int, input().split()) counter = 0 while a > 0 and b > 0: if a > b: b += 1 a += -2 counter += 1 else: a += 1 b += -2 counter += 1 print(counter) ```
0
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob?
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "4" }, { "input": "1 6", "output": "5" }, { "input": "1 7", "output": "5" }, { "input": "1 8", "output": "6" }, { "input": "1 9", "output": "6" }, { "input": "1 10", "output": "6" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "2 4", "output": "2" }, { "input": "2 5", "output": "3" }, { "input": "2 6", "output": "3" }, { "input": "2 7", "output": "4" }, { "input": "2 8", "output": "4" }, { "input": "2 9", "output": "4" }, { "input": "2 10", "output": "4" }, { "input": "3 3", "output": "1" }, { "input": "3 4", "output": "1" }, { "input": "3 5", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "3 7", "output": "3" }, { "input": "3 8", "output": "3" }, { "input": "3 9", "output": "3" }, { "input": "3 10", "output": "3" }, { "input": "4 4", "output": "1" }, { "input": "4 5", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "4 7", "output": "2" }, { "input": "4 8", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "4 10", "output": "3" }, { "input": "5 5", "output": "1" }, { "input": "5 6", "output": "1" }, { "input": "5 7", "output": "1" }, { "input": "5 8", "output": "2" }, { "input": "5 9", "output": "2" }, { "input": "5 10", "output": "2" }, { "input": "6 6", "output": "1" }, { "input": "6 7", "output": "1" }, { "input": "6 8", "output": "1" }, { "input": "6 9", "output": "2" }, { "input": "6 10", "output": "2" }, { "input": "7 7", "output": "1" }, { "input": "7 8", "output": "1" }, { "input": "7 9", "output": "1" }, { "input": "7 10", "output": "1" }, { "input": "8 8", "output": "1" }, { "input": "8 9", "output": "1" }, { "input": "8 10", "output": "1" }, { "input": "9 9", "output": "1" }, { "input": "9 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "1 2", "output": "2" } ]
1,696,827,690
2,147,483,647
Python 3
OK
TESTS
62
46
0
a,b=map(int,input().split()) i=1 while i>0: a=a*3 b=b*2 if a>b: print(i) break i+=1
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob? Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. Output Specification: Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. Demo Input: ['4 7\n', '4 9\n', '1 1\n'] Demo Output: ['2\n', '3\n', '1\n'] Note: In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
```python a,b=map(int,input().split()) i=1 while i>0: a=a*3 b=b*2 if a>b: print(i) break i+=1 ```
3
149
A
Business trip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
[ "5\n1 1 1 1 2 2 3 2 2 1 1 1\n", "0\n0 0 0 0 0 0 0 1 1 2 3 0\n", "11\n1 1 4 1 1 5 1 1 4 1 1 1\n" ]
[ "2\n", "0\n", "3\n" ]
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all.
500
[ { "input": "5\n1 1 1 1 2 2 3 2 2 1 1 1", "output": "2" }, { "input": "0\n0 0 0 0 0 0 0 1 1 2 3 0", "output": "0" }, { "input": "11\n1 1 4 1 1 5 1 1 4 1 1 1", "output": "3" }, { "input": "15\n20 1 1 1 1 2 2 1 2 2 1 1", "output": "1" }, { "input": "7\n8 9 100 12 14 17 21 10 11 100 23 10", "output": "1" }, { "input": "52\n1 12 3 11 4 5 10 6 9 7 8 2", "output": "6" }, { "input": "50\n2 2 3 4 5 4 4 5 7 3 2 7", "output": "-1" }, { "input": "0\n55 81 28 48 99 20 67 95 6 19 10 93", "output": "0" }, { "input": "93\n85 40 93 66 92 43 61 3 64 51 90 21", "output": "1" }, { "input": "99\n36 34 22 0 0 0 52 12 0 0 33 47", "output": "2" }, { "input": "99\n28 32 31 0 10 35 11 18 0 0 32 28", "output": "3" }, { "input": "99\n19 17 0 1 18 11 29 9 29 22 0 8", "output": "4" }, { "input": "76\n2 16 11 10 12 0 20 4 4 14 11 14", "output": "5" }, { "input": "41\n2 1 7 7 4 2 4 4 9 3 10 0", "output": "6" }, { "input": "47\n8 2 2 4 3 1 9 4 2 7 7 8", "output": "7" }, { "input": "58\n6 11 7 0 5 6 3 9 4 9 5 1", "output": "8" }, { "input": "32\n5 2 4 1 5 0 5 1 4 3 0 3", "output": "9" }, { "input": "31\n6 1 0 4 4 5 1 0 5 3 2 0", "output": "9" }, { "input": "35\n2 3 0 0 6 3 3 4 3 5 0 6", "output": "9" }, { "input": "41\n3 1 3 4 3 6 6 1 4 4 0 6", "output": "11" }, { "input": "97\n0 5 3 12 10 16 22 8 21 17 21 10", "output": "5" }, { "input": "100\n21 21 0 0 4 13 0 26 0 0 0 15", "output": "6" }, { "input": "100\n0 0 16 5 22 0 5 0 25 0 14 13", "output": "7" }, { "input": "97\n17 0 10 0 0 0 18 0 14 23 15 0", "output": "6" }, { "input": "100\n0 9 0 18 7 0 0 14 33 3 0 16", "output": "7" }, { "input": "95\n5 2 13 0 15 18 17 0 6 11 0 8", "output": "9" }, { "input": "94\n11 13 0 9 15 8 8 16 3 7 1 3", "output": "11" }, { "input": "96\n8 4 12 15 8 0 4 10 6 6 12 11", "output": "11" }, { "input": "100\n5 5 3 8 6 5 0 3 3 8 1 3", "output": "-1" }, { "input": "100\n1 0 0 1 1 0 1 1 1 1 2 1", "output": "-1" }, { "input": "100\n6 3 2 0 4 1 2 2 2 2 1 1", "output": "-1" }, { "input": "0\n0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0", "output": "-1" }, { "input": "0\n100 100 100 100 100 100 100 100 100 100 100 100", "output": "0" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100", "output": "1" }, { "input": "12\n1 1 1 1 1 1 1 1 1 1 1 1", "output": "12" }, { "input": "13\n1 1 1 1 1 1 1 1 1 1 1 2", "output": "12" }, { "input": "15\n10 1 1 1 1 1 1 1 1 1 1 1", "output": "6" }, { "input": "1\n0 0 0 0 0 0 0 0 0 0 0 0", "output": "-1" } ]
1,673,752,027
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
a = int(input()) q = list(reversed(sorted(map(int, input().split())))) l = [] d = 0 for i in range(len(q)): c = 0 for j in range(len(q)-i): c += 1 d += q[j] if d >= a: l.append(c) q.remove(q[0]) d = 0 break print(min(l))
Title: Business trip Time Limit: None seconds Memory Limit: None megabytes Problem Description: What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. Input Specification: The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). Output Specification: Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. Demo Input: ['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n'] Demo Output: ['2\n', '0\n', '3\n'] Note: Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all.
```python a = int(input()) q = list(reversed(sorted(map(int, input().split())))) l = [] d = 0 for i in range(len(q)): c = 0 for j in range(len(q)-i): c += 1 d += q[j] if d >= a: l.append(c) q.remove(q[0]) d = 0 break print(min(l)) ```
0
5
A
Chat Servers Outgoing Traffic
PROGRAMMING
1,000
[ "implementation" ]
A. Chat Server's Outgoing Traffic
1
64
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: - Include a person to the chat ('Add' command). - Remove a person from the chat ('Remove' command). - Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands. Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends *l* bytes to each participant of the chat, where *l* is the length of the message. As Polycarp has no time, he is asking for your help in solving this problem.
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: - +&lt;name&gt; for 'Add' command. - -&lt;name&gt; for 'Remove' command. - &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
Print a single number — answer to the problem.
[ "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n" ]
[ "9\n", "14\n" ]
none
0
[ { "input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "output": "9" }, { "input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate", "output": "14" }, { "input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM\nDmitry:And digits too\nDmitry:1234567890 0987654321\n-Dmitry", "output": "224" }, { "input": "+Dmitry\n+Mike\n+Kate\nDmitry:", "output": "0" }, { "input": "+Dmitry\nDmitry:No phrases with spaces at the beginning and at the end\n+Mike\nDmitry:spaces spaces\n-Dmitry", "output": "86" }, { "input": "+XqD\n+aT537\nXqD:x6ZPjMR1DDKG2\nXqD:lLCriywPnB\n-XqD", "output": "46" }, { "input": "+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8UjgAJ\n+zdi\n-zdi", "output": "14" }, { "input": "+6JPKkgXDrA\n+j6JHjv70An\n+QGtsceK0zJ\n6JPKkgXDrA:o4\n+CSmwi9zDra\nQGtsceK0zJ:Zl\nQGtsceK0zJ:0\nj6JHjv70An:7\nj6JHjv70An:B\nQGtsceK0zJ:OO", "output": "34" }, { "input": "+1aLNq9S7uLV\n-1aLNq9S7uLV\n+O9ykq3xDJv\n-O9ykq3xDJv\n+54Yq1xJq14F\n+0zJ5Vo0RDZ\n-54Yq1xJq14F\n-0zJ5Vo0RDZ\n+lxlH7sdolyL\n-lxlH7sdolyL", "output": "0" }, { "input": "+qlHEc2AuYy\nqlHEc2AuYy:YYRwD0 edNZgpE nGfOguRWnMYpTpGUVM aXDKGXo1Gv1tHL9\nqlHEc2AuYy:yvh3GsPcImqrvoUcBNQcP6ezwpU0 xAVltaKZp94VKiNao\nqlHEc2AuYy:zuCO6Opey L eu7lTwysaSk00zjpv zrDfbt8l hpHfu\n+pErDMxgVgh\nqlHEc2AuYy:I1FLis mmQbZtd8Ui7y 1vcax6yZBMhVRdD6Ahlq7MNCw\nqlHEc2AuYy:lz MFUNJZhlqBYckHUDlNhLiEkmecRh1o0t7alXBvCRVEFVx\npErDMxgVgh:jCyMbu1dkuEj5TzbBOjyUhpfC50cL8R900Je3R KxRgAI dT\nqlHEc2AuYy:62b47eabo2hf vSUD7KioN ZHki6WB6gh3u GKv5rgwyfF\npErDMxgVgh:zD5 9 ympl4wR gy7a7eAGAn5xVdGP9FbL6hRCZAR6O4pT6zb", "output": "615" }, { "input": "+adabacaba0", "output": "0" }, { "input": "+acabadab\n+caba0aba", "output": "0" }, { "input": "+dabaca\n-dabaca\n+aba0ab", "output": "0" }, { "input": "+cab\n+abac\n-abac\n+baca", "output": "0" }, { "input": "+cabadabac\n-cabadabac\n+abacaba1ab\n-abacaba1ab\n+ba0abaca", "output": "0" }, { "input": "+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad", "output": "4" }, { "input": "+acabadab\n-acabadab\n+aba0abacab\n+baca\n+abacaba0ab\n-baca\n-abacaba0ab\n-aba0abacab\n+cab\n-cab\n+abacabada\n-abacabada\n+badabaca\n-badabaca\n+badaba", "output": "0" }, { "input": "+badabac\nbadabac:abacabad\n-badabac\n+0ab\n-0ab\n+dabacab\n-dabacab\n+a0ab\n-a0ab\n+0abaca\n-0abaca\n+dabac\n-dabac\n+abaca\n-abaca\n+bacabada\n-bacabada\n+aca\n-aca\n+abadabaca\n-abadabaca\n+acaba\n-acaba\n+abacabadab\n-abacabadab", "output": "8" } ]
1,405,051,606
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
import sys participants = [] ans = 0 for s in sys.stdin: if not s: break if s[0] == "+": participants.append(s[1:]) elif s[0] == "-": participants.remove(s[1:]) else: ans += (len(s) - s.find(':') - 1) * len(participants) print(ans)
Title: Chat Servers Outgoing Traffic Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: - Include a person to the chat ('Add' command). - Remove a person from the chat ('Remove' command). - Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands. Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends *l* bytes to each participant of the chat, where *l* is the length of the message. As Polycarp has no time, he is asking for your help in solving this problem. Input Specification: Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: - +&lt;name&gt; for 'Add' command. - -&lt;name&gt; for 'Remove' command. - &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive. Output Specification: Print a single number — answer to the problem. Demo Input: ['+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n', '+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n'] Demo Output: ['9\n', '14\n'] Note: none
```python import sys participants = [] ans = 0 for s in sys.stdin: if not s: break if s[0] == "+": participants.append(s[1:]) elif s[0] == "-": participants.remove(s[1:]) else: ans += (len(s) - s.find(':') - 1) * len(participants) print(ans) ```
0
30
A
Accounting
PROGRAMMING
1,400
[ "brute force", "math" ]
A. Accounting
2
256
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation: Surely, the king is not going to do this job by himself, and demands you to find such number *X*. It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative.
The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10).
Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.
[ "2 18 2\n", "-1 8 3\n", "0 0 10\n", "1 16 5\n" ]
[ "3", "-2", "5", "No solution" ]
none
500
[ { "input": "2 18 2", "output": "3" }, { "input": "-1 8 3", "output": "-2" }, { "input": "0 0 10", "output": "5" }, { "input": "1 16 5", "output": "No solution" }, { "input": "0 1 2", "output": "No solution" }, { "input": "3 0 4", "output": "0" }, { "input": "1 1000 1", "output": "1000" }, { "input": "7 896 7", "output": "2" }, { "input": "4 972 1", "output": "243" }, { "input": "-1 -1 5", "output": "1" }, { "input": "-1 0 4", "output": "0" }, { "input": "-7 0 1", "output": "0" }, { "input": "-5 -5 3", "output": "1" }, { "input": "-5 -5 9", "output": "1" }, { "input": "-5 -5 6", "output": "1" }, { "input": "-4 0 1", "output": "0" }, { "input": "-5 0 3", "output": "0" }, { "input": "-4 4 9", "output": "-1" }, { "input": "10 0 6", "output": "0" }, { "input": "-5 3 4", "output": "No solution" }, { "input": "0 3 6", "output": "No solution" }, { "input": "3 6 10", "output": "No solution" }, { "input": "-3 7 5", "output": "No solution" }, { "input": "-526 526 1", "output": "-1" }, { "input": "-373 373 3", "output": "-1" }, { "input": "-141 0 8", "output": "0" }, { "input": "7 175 1", "output": "25" }, { "input": "-5 -560 1", "output": "112" }, { "input": "-1 -512 10", "output": "No solution" }, { "input": "-3 -768 8", "output": "2" }, { "input": "-3 -768 7", "output": "No solution" }, { "input": "-3 -768 9", "output": "No solution" }, { "input": "-3 -768 4", "output": "4" }, { "input": "4 972 4", "output": "No solution" }, { "input": "4 972 5", "output": "3" }, { "input": "4 972 6", "output": "No solution" }, { "input": "4 972 1", "output": "243" }, { "input": "4 972 2", "output": "No solution" }, { "input": "1 1000 1", "output": "1000" }, { "input": "1 961 2", "output": "31" }, { "input": "1 1000 3", "output": "10" }, { "input": "1 625 4", "output": "5" }, { "input": "4 972 5", "output": "3" }, { "input": "1 729 6", "output": "3" }, { "input": "7 896 7", "output": "2" }, { "input": "3 768 8", "output": "2" }, { "input": "1 512 9", "output": "2" }, { "input": "1 1000 1", "output": "1000" }, { "input": "1 961 2", "output": "31" }, { "input": "1 1000 3", "output": "10" }, { "input": "1 625 4", "output": "5" }, { "input": "4 972 5", "output": "3" }, { "input": "1 729 6", "output": "3" }, { "input": "7 896 7", "output": "2" }, { "input": "3 768 8", "output": "2" }, { "input": "1 512 9", "output": "2" }, { "input": "1 1000 1", "output": "1000" }, { "input": "1 961 2", "output": "31" }, { "input": "1 1000 3", "output": "10" }, { "input": "1 625 4", "output": "5" }, { "input": "4 972 5", "output": "3" }, { "input": "1 729 6", "output": "3" }, { "input": "7 896 7", "output": "2" }, { "input": "3 768 8", "output": "2" }, { "input": "1 512 9", "output": "2" }, { "input": "1 1 5", "output": "1" }, { "input": "1 1 4", "output": "1" }, { "input": "1 -1 1", "output": "-1" } ]
1,666,178,893
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
62
0
A,B,n = map(int,input().split()) if A != 0: X = (B/A)**(1/n) if X - int(X) == 0: print(int(X)) else: print('No solution') elif A == 0: if B == 0: print(1) else: print('No solution')
Title: Accounting Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation: Surely, the king is not going to do this job by himself, and demands you to find such number *X*. It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative. Input Specification: The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). Output Specification: Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. Demo Input: ['2 18 2\n', '-1 8 3\n', '0 0 10\n', '1 16 5\n'] Demo Output: ['3', '-2', '5', 'No solution'] Note: none
```python A,B,n = map(int,input().split()) if A != 0: X = (B/A)**(1/n) if X - int(X) == 0: print(int(X)) else: print('No solution') elif A == 0: if B == 0: print(1) else: print('No solution') ```
-1
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "111010010111", "output": "11110010111" }, { "input": "11110111011100000000", "output": "1111111011100000000" }, { "input": "11110010010100001110110101110011110110100111101", "output": "1111010010100001110110101110011110110100111101" }, { "input": "1001011111010010100111111", "output": "101011111010010100111111" }, { "input": "1111111111", "output": "111111111" }, { "input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101", "output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101" }, { "input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100", "output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100" }, { "input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011", "output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011" }, { "input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011", "output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011" }, { "input": "11", "output": "1" }, { "input": "111", "output": "11" }, { "input": "111111", "output": "11111" }, { "input": "11111", "output": "1111" }, { "input": "1111", "output": "111" } ]
1,642,451,107
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
62
0
s=list(input()) if '0' in s: ind = s.index('0') print(''.join(s[:ind])+''.join(s[ind+1:])) else: print(''.join(s[:-2]))
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input Specification: The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output Specification: In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Demo Input: ['101\n', '110010\n'] Demo Output: ['11\n', '11010\n'] Note: In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
```python s=list(input()) if '0' in s: ind = s.index('0') print(''.join(s[:ind])+''.join(s[ind+1:])) else: print(''.join(s[:-2])) ```
0
52
C
Circular RMQ
PROGRAMMING
2,200
[ "data structures" ]
C. Circular RMQ
1
256
You are given circular array *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. There are two types of operations with it: - *inc*(*lf*,<=*rg*,<=*v*) — this operation increases each element on the segment [*lf*,<=*rg*] (inclusively) by *v*; - *rmq*(*lf*,<=*rg*) — this operation returns minimal value on the segment [*lf*,<=*rg*] (inclusively). Assume segments to be circular, so if *n*<==<=5 and *lf*<==<=3,<=*rg*<==<=1, it means the index sequence: 3,<=4,<=0,<=1. Write program to process given sequence of operations.
The first line contains integer *n* (1<=≤<=*n*<=≤<=200000). The next line contains initial state of the array: *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=106<=≤<=*a**i*<=≤<=106), *a**i* are integer. The third line contains integer *m* (0<=≤<=*m*<=≤<=200000), *m* — the number of operartons. Next *m* lines contain one operation each. If line contains two integer *lf*,<=*rg* (0<=≤<=*lf*,<=*rg*<=≤<=*n*<=-<=1) it means *rmq* operation, it contains three integers *lf*,<=*rg*,<=*v* (0<=≤<=*lf*,<=*rg*<=≤<=*n*<=-<=1;<=-<=106<=≤<=*v*<=≤<=106) — *inc* operation.
For each *rmq* operation write result for it. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
[ "4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1\n" ]
[ "1\n0\n0\n" ]
none
1,500
[ { "input": "4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1", "output": "1\n0\n0" }, { "input": "1\n-1\n10\n0 0 -1\n0 0\n0 0 1\n0 0\n0 0 1\n0 0\n0 0 0\n0 0\n0 0 -1\n0 0 1", "output": "-2\n-1\n0\n0" }, { "input": "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1", "output": "-1\n-1\n0\n-1" } ]
1,603,203,188
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
1,325
28,569,600
from typing import TypeVar, Generic, Callable, List import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') T = TypeVar('T') S = TypeVar('S') class StarrySkyTree(Generic[T, S]): __slots__ = ['size', 'node', 'lazy', 'unit', 'lazy_unit', 'op', 'upd', 'lazy_upd', 'subt_size'] def __init__(self, size: int, default: T, unit: T, lazy_unit: S, op: Callable[[T, T], T]) -> None: self.size = size2 = 1 << (len(bin(size)) - 2) self.unit, self.lazy_unit = unit, lazy_unit self.node = [default] * (size2 * 2) self.lazy = [lazy_unit] * (size2 * 2) self.op = op self.subt_size = subt = [0] * size2 + [1] * size + [0] * (size2 - size) for i in range(size2 * 2 - 1, 1, -1): subt[i >> 1] += subt[i] def build(self, a: List[T]) -> None: node = self.node node[self.size:self.size + len(a)] = a for i in range(self.size - 1, 0, -1): node[i] = self.op(node[i << 1], node[(i << 1) + 1]) def find(self, left: int, right: int) -> T: left, right = left + self.size, right + self.size node, lazy = self.node, self.lazy self.__propagate(self.__enum_index(left, right)) result = self.unit while left < right: if left & 1: if lazy[left] == self.lazy_unit: result = self.op(node[left], result) else: # node + lazy result = self.op(node[left] + lazy[left], result) left += 1 if right & 1: if lazy[right - 1] == self.lazy_unit: result = self.op(node[right - 1], result) else: # node + lazy result = self.op(node[right - 1] + lazy[right - 1], result) left, right = left >> 1, right >> 1 return result def update(self, left: int, right: int, value: S) -> None: left, right = left + self.size, right + self.size node, lazy, l_unit = self.node, self.lazy, self.lazy_unit _l, _r = left, right while _l < _r: if _l & 1: # update lazy lazy[_l] += value _l += 1 if _r & 1: # update lazy lazy[_r - 1] += value _l, _r = _l >> 1, _r >> 1 for i in self.__enum_index(left, right): node[i] = self.op( node[i * 2] if lazy[i * 2] == l_unit else node[i * 2] + lazy[i * 2], node[i * 2 + 1] if lazy[i * 2 + 1] == l_unit else node[i * 2 + 1] + lazy[i * 2 + 1]) def __enum_index(self, left: int, right: int) -> List[int]: flag, idx = 0, [] while left < right: if flag & 1: idx.append(left) if flag & 2: idx.append(right) flag |= (left & 1) | ((right & 1) * 2) left, right = left >> 1, right >> 1 while left: idx.append(left) left >>= 1 return idx def __propagate(self, index_list): node, lazy, l_unit = self.node, self.lazy, self.lazy_unit for i in reversed(index_list): if lazy[i] != l_unit: # refresh node node[i] += lazy[i] if i < self.size: # update lazy lazy[i * 2] += lazy[i] lazy[i * 2 + 1] += lazy[i] lazy[i] = l_unit n = int(input()) segt = StarrySkyTree[int, int](n, 10**8, 10**8, 0, min) segt.build(list(map(int, input().split()))) t = int(input()) ans = [] for _ in range(t): q = tuple(map(int, input().split())) if len(q) == 3: if q[0] > q[1]: segt.update(q[0], n + 1, q[2]) segt.update(0, q[1] + 1, q[2]) else: segt.update(q[0], q[1] + 1, q[2]) else: if q[0] > q[1]: ans.append(min(segt.find(q[0], n + 1), segt.find(0, q[1] + 1))) else: ans.append(segt.find(q[0], q[1] + 1)) print(*ans, sep='\n')
Title: Circular RMQ Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: You are given circular array *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. There are two types of operations with it: - *inc*(*lf*,<=*rg*,<=*v*) — this operation increases each element on the segment [*lf*,<=*rg*] (inclusively) by *v*; - *rmq*(*lf*,<=*rg*) — this operation returns minimal value on the segment [*lf*,<=*rg*] (inclusively). Assume segments to be circular, so if *n*<==<=5 and *lf*<==<=3,<=*rg*<==<=1, it means the index sequence: 3,<=4,<=0,<=1. Write program to process given sequence of operations. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=200000). The next line contains initial state of the array: *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=106<=≤<=*a**i*<=≤<=106), *a**i* are integer. The third line contains integer *m* (0<=≤<=*m*<=≤<=200000), *m* — the number of operartons. Next *m* lines contain one operation each. If line contains two integer *lf*,<=*rg* (0<=≤<=*lf*,<=*rg*<=≤<=*n*<=-<=1) it means *rmq* operation, it contains three integers *lf*,<=*rg*,<=*v* (0<=≤<=*lf*,<=*rg*<=≤<=*n*<=-<=1;<=-<=106<=≤<=*v*<=≤<=106) — *inc* operation. Output Specification: For each *rmq* operation write result for it. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). Demo Input: ['4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1\n'] Demo Output: ['1\n0\n0\n'] Note: none
```python from typing import TypeVar, Generic, Callable, List import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') T = TypeVar('T') S = TypeVar('S') class StarrySkyTree(Generic[T, S]): __slots__ = ['size', 'node', 'lazy', 'unit', 'lazy_unit', 'op', 'upd', 'lazy_upd', 'subt_size'] def __init__(self, size: int, default: T, unit: T, lazy_unit: S, op: Callable[[T, T], T]) -> None: self.size = size2 = 1 << (len(bin(size)) - 2) self.unit, self.lazy_unit = unit, lazy_unit self.node = [default] * (size2 * 2) self.lazy = [lazy_unit] * (size2 * 2) self.op = op self.subt_size = subt = [0] * size2 + [1] * size + [0] * (size2 - size) for i in range(size2 * 2 - 1, 1, -1): subt[i >> 1] += subt[i] def build(self, a: List[T]) -> None: node = self.node node[self.size:self.size + len(a)] = a for i in range(self.size - 1, 0, -1): node[i] = self.op(node[i << 1], node[(i << 1) + 1]) def find(self, left: int, right: int) -> T: left, right = left + self.size, right + self.size node, lazy = self.node, self.lazy self.__propagate(self.__enum_index(left, right)) result = self.unit while left < right: if left & 1: if lazy[left] == self.lazy_unit: result = self.op(node[left], result) else: # node + lazy result = self.op(node[left] + lazy[left], result) left += 1 if right & 1: if lazy[right - 1] == self.lazy_unit: result = self.op(node[right - 1], result) else: # node + lazy result = self.op(node[right - 1] + lazy[right - 1], result) left, right = left >> 1, right >> 1 return result def update(self, left: int, right: int, value: S) -> None: left, right = left + self.size, right + self.size node, lazy, l_unit = self.node, self.lazy, self.lazy_unit _l, _r = left, right while _l < _r: if _l & 1: # update lazy lazy[_l] += value _l += 1 if _r & 1: # update lazy lazy[_r - 1] += value _l, _r = _l >> 1, _r >> 1 for i in self.__enum_index(left, right): node[i] = self.op( node[i * 2] if lazy[i * 2] == l_unit else node[i * 2] + lazy[i * 2], node[i * 2 + 1] if lazy[i * 2 + 1] == l_unit else node[i * 2 + 1] + lazy[i * 2 + 1]) def __enum_index(self, left: int, right: int) -> List[int]: flag, idx = 0, [] while left < right: if flag & 1: idx.append(left) if flag & 2: idx.append(right) flag |= (left & 1) | ((right & 1) * 2) left, right = left >> 1, right >> 1 while left: idx.append(left) left >>= 1 return idx def __propagate(self, index_list): node, lazy, l_unit = self.node, self.lazy, self.lazy_unit for i in reversed(index_list): if lazy[i] != l_unit: # refresh node node[i] += lazy[i] if i < self.size: # update lazy lazy[i * 2] += lazy[i] lazy[i * 2 + 1] += lazy[i] lazy[i] = l_unit n = int(input()) segt = StarrySkyTree[int, int](n, 10**8, 10**8, 0, min) segt.build(list(map(int, input().split()))) t = int(input()) ans = [] for _ in range(t): q = tuple(map(int, input().split())) if len(q) == 3: if q[0] > q[1]: segt.update(q[0], n + 1, q[2]) segt.update(0, q[1] + 1, q[2]) else: segt.update(q[0], q[1] + 1, q[2]) else: if q[0] > q[1]: ans.append(min(segt.find(q[0], n + 1), segt.find(0, q[1] + 1))) else: ans.append(segt.find(q[0], q[1] + 1)) print(*ans, sep='\n') ```
0
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, { "input": "192", "output": "4 188" }, { "input": "86", "output": "4 82" }, { "input": "46220", "output": "4 46216" }, { "input": "57114", "output": "4 57110" }, { "input": "869", "output": "4 865" }, { "input": "738457", "output": "4 738453" }, { "input": "58113", "output": "6 58107" }, { "input": "4864", "output": "4 4860" }, { "input": "15", "output": "6 9" }, { "input": "74752", "output": "4 74748" }, { "input": "6073", "output": "4 6069" }, { "input": "1289", "output": "4 1285" }, { "input": "20", "output": "4 16" }, { "input": "58134", "output": "4 58130" }, { "input": "57756", "output": "4 57752" }, { "input": "765", "output": "6 759" }, { "input": "59", "output": "4 55" }, { "input": "991666", "output": "4 991662" }, { "input": "70761", "output": "4 70757" }, { "input": "13", "output": "4 9" }, { "input": "999999", "output": "4 999995" }, { "input": "17", "output": "8 9" }, { "input": "21", "output": "6 15" }, { "input": "19", "output": "4 15" }, { "input": "100007", "output": "6 100001" }, { "input": "999987", "output": "6 999981" }, { "input": "22", "output": "4 18" } ]
1,679,834,713
2,147,483,647
Python 3
OK
TESTS
33
46
0
x=int(input()) if (x-6)%2==0: print(8,x-8) else: print(9,x-9)
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers. Input Specification: The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). Output Specification: Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. Demo Input: ['12\n', '15\n', '23\n', '1000000\n'] Demo Output: ['4 8\n', '6 9\n', '8 15\n', '500000 500000\n'] Note: In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
```python x=int(input()) if (x-6)%2==0: print(8,x-8) else: print(9,x-9) ```
3
166
A
Rank List
PROGRAMMING
1,100
[ "binary search", "implementation", "sortings" ]
null
null
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place.
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces.
In the only line print the sought number of teams that got the *k*-th place in the final results' table.
[ "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n" ]
[ "3\n", "4\n" ]
The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
500
[ { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "output": "3" }, { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1", "output": "4" }, { "input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2", "output": "2" }, { "input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5", "output": "1" }, { "input": "5 5\n3 1\n10 2\n2 2\n1 10\n10 2", "output": "1" }, { "input": "3 2\n3 3\n3 3\n3 3", "output": "3" }, { "input": "4 3\n10 3\n6 10\n5 2\n5 2", "output": "2" }, { "input": "5 3\n10 10\n10 10\n1 1\n10 10\n4 3", "output": "3" }, { "input": "3 1\n2 1\n1 1\n1 2", "output": "1" }, { "input": "1 1\n28 28", "output": "1" }, { "input": "2 2\n1 2\n1 2", "output": "2" }, { "input": "5 3\n2 3\n4 2\n5 3\n2 4\n3 5", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 6\n11 20\n18 13\n1 13\n3 11\n4 17\n15 10\n15 8\n9 16\n11 17\n16 3\n3 20\n14 13\n12 15\n9 10\n14 2\n12 12\n13 17\n6 10\n20 9\n2 8\n13 7\n7 20\n15 3\n1 20\n2 13\n2 5\n14 7\n10 13\n15 12\n15 5\n17 6\n9 11\n18 5\n10 1\n15 14\n3 16\n6 12\n4 1\n14 9\n7 14\n8 17\n17 13\n4 6\n19 16\n5 6\n3 15\n4 19\n15 20\n2 10\n20 10", "output": "1" }, { "input": "50 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "50" }, { "input": "50 28\n2 2\n1 1\n2 1\n1 2\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n2 2\n2 1\n2 1\n2 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n2 2\n2 2\n2 2\n2 2", "output": "13" }, { "input": "50 40\n2 3\n3 1\n2 1\n2 1\n2 1\n3 1\n1 1\n1 2\n2 3\n1 3\n1 3\n2 1\n3 1\n1 1\n3 1\n3 1\n2 2\n1 1\n3 3\n3 1\n3 2\n2 3\n3 3\n3 1\n1 3\n2 3\n2 1\n3 2\n3 3\n3 1\n2 1\n2 2\n1 3\n3 3\n1 1\n3 2\n1 2\n2 3\n2 1\n2 2\n3 2\n1 3\n3 1\n1 1\n3 3\n2 3\n2 1\n2 3\n2 3\n1 2", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 32\n6 6\n4 2\n5 5\n1 1\n2 4\n6 5\n2 3\n6 5\n2 3\n6 3\n1 4\n1 6\n3 3\n2 4\n3 2\n6 2\n4 1\n3 3\n3 1\n5 5\n1 2\n2 1\n5 4\n3 1\n4 4\n5 6\n4 1\n2 5\n3 1\n4 6\n2 3\n1 1\n6 5\n2 6\n3 3\n2 6\n2 3\n2 6\n3 4\n2 6\n4 5\n5 4\n1 6\n3 2\n5 1\n4 1\n4 6\n4 2\n1 2\n5 2", "output": "1" }, { "input": "50 48\n5 1\n6 4\n3 2\n2 1\n4 7\n3 6\n7 1\n7 5\n6 5\n5 6\n4 7\n5 7\n5 7\n5 5\n7 3\n3 5\n4 3\n5 4\n6 2\n1 6\n6 3\n6 5\n5 2\n4 2\n3 1\n1 1\n5 6\n1 3\n6 5\n3 7\n1 5\n7 5\n6 5\n3 6\n2 7\n5 3\n5 3\n4 7\n5 2\n6 5\n5 7\n7 1\n2 3\n5 5\n2 6\n4 1\n6 2\n6 5\n3 3\n1 6", "output": "1" }, { "input": "50 8\n5 3\n7 3\n4 3\n7 4\n2 2\n4 4\n5 4\n1 1\n7 7\n4 8\n1 1\n6 3\n1 5\n7 3\n6 5\n4 5\n8 6\n3 6\n2 1\n3 2\n2 5\n7 6\n5 8\n1 3\n5 5\n8 4\n4 5\n4 4\n8 8\n7 2\n7 2\n3 6\n2 8\n8 3\n3 2\n4 5\n8 1\n3 2\n8 7\n6 3\n2 3\n5 1\n3 4\n7 2\n6 3\n7 3\n3 3\n6 4\n2 2\n5 1", "output": "3" }, { "input": "20 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "20" }, { "input": "20 20\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n2 1\n1 1\n1 2\n2 2\n1 2\n1 2\n2 2\n2 2\n1 2\n2 1\n2 1\n1 2\n2 2", "output": "6" }, { "input": "30 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "30" }, { "input": "30 22\n2 1\n1 2\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n2 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 2\n2 2\n1 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n2 2\n1 2\n2 2\n2 1\n1 1", "output": "13" }, { "input": "30 22\n1 1\n1 3\n2 3\n3 1\n2 3\n3 1\n1 2\n3 3\n2 1\n2 1\n2 2\n3 1\n3 2\n2 3\n3 1\n1 3\n2 3\n3 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 2\n1 3\n3 3\n3 3\n3 3\n3 3\n3 1", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 22\n29 15\n18 10\n6 23\n38 28\n34 40\n40 1\n16 26\n22 33\n14 30\n26 7\n15 16\n22 40\n14 15\n6 28\n32 27\n33 3\n38 22\n40 17\n16 27\n21 27\n34 26\n5 15\n34 9\n38 23\n7 36\n17 6\n19 37\n40 1\n10 28\n9 14\n8 31\n40 8\n14 2\n24 16\n38 33\n3 37\n2 9\n21 21\n40 26\n28 33\n24 31\n10 12\n27 27\n17 4\n38 5\n21 31\n5 12\n29 7\n39 12\n26 14", "output": "1" }, { "input": "50 14\n4 20\n37 50\n46 19\n20 25\n47 10\n6 34\n12 41\n47 9\n22 28\n41 34\n47 40\n12 42\n9 4\n15 15\n27 8\n38 9\n4 17\n8 13\n47 7\n9 38\n30 48\n50 7\n41 34\n23 11\n16 37\n2 32\n18 46\n37 48\n47 41\n13 9\n24 50\n46 14\n33 49\n9 50\n35 30\n49 44\n42 49\n39 15\n33 42\n3 18\n44 15\n44 28\n9 17\n16 4\n10 36\n4 22\n47 17\n24 12\n2 31\n6 30", "output": "2" }, { "input": "2 1\n50 50\n50 50", "output": "2" }, { "input": "2 2\n50 50\n50 50", "output": "2" }, { "input": "2 1\n50 50\n50 49", "output": "1" }, { "input": "2 2\n50 50\n50 49", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50", "output": "50" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n49 50", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 49", "output": "49" }, { "input": "10 1\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "1" }, { "input": "4 3\n1 1\n1 2\n2 1\n2 2", "output": "1" }, { "input": "4 2\n1 2\n1 3\n1 5\n1 2", "output": "2" }, { "input": "6 1\n4 3\n4 2\n5 1\n5 2\n5 3\n5 3", "output": "1" }, { "input": "5 3\n2 1\n1 3\n1 2\n1 1\n1 1", "output": "2" }, { "input": "3 1\n1 1\n1 2\n1 3", "output": "1" }, { "input": "10 10\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "4" }, { "input": "5 1\n5 5\n5 6\n5 7\n5 8\n5 5", "output": "2" }, { "input": "4 1\n1 1\n1 1\n1 2\n1 3", "output": "2" } ]
1,682,706,056
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
15
124
1,638,400
nteams,rank=map(int,input().split()) freq = [0]*5052 lst = [] lst2 = [] for i in range(nteams): ques,time=map(int,input().split()) team = str(ques)+str(time) freq[int(team)]+=1 for i in freq: if i!=0: lst2.append(i) s = 0 for q in lst2[::-1]: s+=q if s>=rank: print(q) break
Title: Rank List Time Limit: None seconds Memory Limit: None megabytes Problem Description: Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces. Output Specification: In the only line print the sought number of teams that got the *k*-th place in the final results' table. Demo Input: ['7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n', '5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n'] Demo Output: ['3\n', '4\n'] Note: The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
```python nteams,rank=map(int,input().split()) freq = [0]*5052 lst = [] lst2 = [] for i in range(nteams): ques,time=map(int,input().split()) team = str(ques)+str(time) freq[int(team)]+=1 for i in freq: if i!=0: lst2.append(i) s = 0 for q in lst2[::-1]: s+=q if s>=rank: print(q) break ```
0
934
B
A Prosperous Lot
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside. Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony. He would like to find a positive integer *n* not greater than 1018, such that there are exactly *k* loops in the decimal representation of *n*, or determine that such *n* does not exist. A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.
The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops.
Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018.
[ "2\n", "6\n" ]
[ "462", "8080" ]
none
1,000
[ { "input": "2", "output": "8" }, { "input": "6", "output": "888" }, { "input": "3", "output": "86" }, { "input": "4", "output": "88" }, { "input": "5", "output": "886" }, { "input": "1000000", "output": "-1" }, { "input": "1", "output": "6" }, { "input": "7", "output": "8886" }, { "input": "8", "output": "8888" }, { "input": "9", "output": "88886" }, { "input": "10", "output": "88888" }, { "input": "11", "output": "888886" }, { "input": "12", "output": "888888" }, { "input": "13", "output": "8888886" }, { "input": "14", "output": "8888888" }, { "input": "15", "output": "88888886" }, { "input": "16", "output": "88888888" }, { "input": "17", "output": "888888886" }, { "input": "18", "output": "888888888" }, { "input": "19", "output": "8888888886" }, { "input": "20", "output": "8888888888" }, { "input": "21", "output": "88888888886" }, { "input": "22", "output": "88888888888" }, { "input": "23", "output": "888888888886" }, { "input": "24", "output": "888888888888" }, { "input": "25", "output": "8888888888886" }, { "input": "26", "output": "8888888888888" }, { "input": "27", "output": "88888888888886" }, { "input": "28", "output": "88888888888888" }, { "input": "29", "output": "888888888888886" }, { "input": "30", "output": "888888888888888" }, { "input": "31", "output": "8888888888888886" }, { "input": "32", "output": "8888888888888888" }, { "input": "33", "output": "88888888888888886" }, { "input": "34", "output": "88888888888888888" }, { "input": "35", "output": "888888888888888886" }, { "input": "36", "output": "888888888888888888" }, { "input": "37", "output": "-1" }, { "input": "38", "output": "-1" }, { "input": "39", "output": "-1" }, { "input": "40", "output": "-1" }, { "input": "462", "output": "-1" }, { "input": "1317", "output": "-1" }, { "input": "88", "output": "-1" }, { "input": "87", "output": "-1" } ]
1,575,808,085
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
5
124
0
k=int(input()) if k>36: print (-1) else: out="" n = k%2 if k%2: out+="4" for i in range(int(k/2)): out += "8" print(out)
Title: A Prosperous Lot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside. Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony. He would like to find a positive integer *n* not greater than 1018, such that there are exactly *k* loops in the decimal representation of *n*, or determine that such *n* does not exist. A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms. Input Specification: The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. Output Specification: Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. Demo Input: ['2\n', '6\n'] Demo Output: ['462', '8080'] Note: none
```python k=int(input()) if k>36: print (-1) else: out="" n = k%2 if k%2: out+="4" for i in range(int(k/2)): out += "8" print(out) ```
-1
35
C
Fire Again
PROGRAMMING
1,500
[ "brute force", "dfs and similar", "shortest paths" ]
C. Fire Again
2
64
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation. The burning began in *K* points simultaneously, which means that initially *K* trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1. Find the tree that will be the last to start burning. If there are several such trees, output any.
The first input line contains two integers *N*,<=*M* (1<=≤<=*N*,<=*M*<=≤<=2000) — the size of the forest. The trees were planted in all points of the (*x*,<=*y*) (1<=≤<=*x*<=≤<=*N*,<=1<=≤<=*y*<=≤<=*M*) type, *x* and *y* are integers. The second line contains an integer *K* (1<=≤<=*K*<=≤<=10) — amount of trees, burning in the beginning. The third line contains *K* pairs of integers: *x*1,<=*y*1,<=*x*2,<=*y*2,<=...,<=*x**k*,<=*y**k* (1<=≤<=*x**i*<=≤<=*N*,<=1<=≤<=*y**i*<=≤<=*M*) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide.
Output a line with two space-separated integers *x* and *y* — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any.
[ "3 3\n1\n2 2\n", "3 3\n1\n1 1\n", "3 3\n2\n1 1 3 3\n" ]
[ "1 1\n", "3 3\n", "2 2" ]
none
1,500
[ { "input": "3 3\n1\n2 2", "output": "1 1" }, { "input": "3 3\n1\n1 1", "output": "3 3" }, { "input": "3 3\n2\n1 1 3 3", "output": "1 3" }, { "input": "1 1\n1\n1 1", "output": "1 1" }, { "input": "2 2\n1\n2 2", "output": "1 1" }, { "input": "2 2\n2\n1 1 2 1", "output": "1 2" }, { "input": "2 2\n3\n1 2 2 1 1 1", "output": "2 2" }, { "input": "2 2\n4\n2 1 2 2 1 1 1 2", "output": "1 1" }, { "input": "10 10\n1\n5 5", "output": "10 10" }, { "input": "10 10\n2\n7 8 1 9", "output": "3 1" }, { "input": "10 10\n3\n3 9 6 3 3 5", "output": "10 7" }, { "input": "10 10\n4\n5 3 4 7 7 5 8 5", "output": "10 10" }, { "input": "10 10\n5\n2 7 10 6 5 3 9 5 2 9", "output": "1 1" }, { "input": "10 10\n6\n5 1 4 6 3 9 9 9 5 7 7 2", "output": "1 3" }, { "input": "10 10\n7\n5 8 4 6 4 1 6 2 1 10 3 2 7 10", "output": "10 5" }, { "input": "10 10\n8\n9 4 9 10 5 8 6 5 1 3 2 5 10 6 2 1", "output": "1 10" }, { "input": "10 10\n9\n10 1 10 4 8 4 6 6 1 9 10 10 7 7 6 5 7 10", "output": "1 1" }, { "input": "10 10\n10\n7 2 1 9 5 8 6 10 9 4 10 8 6 8 8 7 4 1 9 5", "output": "1 3" }, { "input": "100 100\n1\n44 3", "output": "100 100" }, { "input": "100 100\n2\n79 84 76 63", "output": "1 1" }, { "input": "100 100\n3\n89 93 99 32 32 82", "output": "1 1" }, { "input": "100 100\n4\n72 12 1 66 57 67 25 67", "output": "100 100" }, { "input": "100 100\n5\n22 41 82 16 6 3 20 6 69 78", "output": "1 100" }, { "input": "100 100\n6\n92 32 90 80 32 40 24 19 36 37 39 13", "output": "1 100" }, { "input": "100 100\n7\n30 32 29 63 86 78 88 2 86 50 41 60 54 28", "output": "1 100" }, { "input": "100 100\n8\n40 43 96 8 17 63 61 59 16 69 4 95 30 62 12 91", "output": "100 100" }, { "input": "100 100\n9\n18 16 41 71 25 1 43 38 78 92 77 70 99 8 33 54 76 78", "output": "1 100" }, { "input": "100 100\n10\n58 98 33 62 75 13 94 86 81 42 14 53 12 66 7 14 3 63 87 37", "output": "40 1" }, { "input": "2000 2000\n1\n407 594", "output": "2000 2000" }, { "input": "2000 2000\n2\n1884 43 1235 1111", "output": "1 2000" }, { "input": "2000 2000\n3\n1740 1797 1279 1552 329 756", "output": "2000 1" }, { "input": "2000 2000\n4\n1844 1342 171 1810 1558 1141 1917 1999", "output": "530 1" }, { "input": "2000 2000\n5\n1846 327 1911 1534 134 1615 1664 682 1982 1112", "output": "346 1" }, { "input": "2000 2000\n6\n1744 1102 852 723 409 179 89 1085 997 1433 1082 1680", "output": "2000 1" }, { "input": "2000 2000\n7\n1890 22 288 1729 383 831 1192 1206 721 1376 969 492 510 1699", "output": "2000 2000" }, { "input": "2000 2000\n8\n286 381 572 1849 1703 1574 622 1047 1507 941 871 663 1930 120 1084 1830", "output": "1 1423" }, { "input": "2000 2000\n9\n226 531 56 138 722 405 1082 608 1355 1426 83 544 275 1268 683 412 1880 1049", "output": "1701 1" }, { "input": "2000 2000\n10\n763 851 1182 571 1758 389 247 1907 730 881 531 1970 1430 667 169 765 1729 120 129 967", "output": "2000 1793" }, { "input": "2000 2000\n10\n655 95 1640 1656 1344 79 666 1677 968 1180 522 1394 1850 1568 336 130 412 920 29 1664", "output": "2000 570" }, { "input": "10 1\n10\n4 1 6 1 10 1 9 1 1 1 7 1 5 1 2 1 8 1 3 1", "output": "1 1" }, { "input": "1 10\n10\n1 10 1 4 1 3 1 7 1 6 1 1 1 8 1 2 1 9 1 5", "output": "1 1" }, { "input": "1 100\n10\n1 68 1 18 1 43 1 12 1 64 1 34 1 23 1 70 1 46 1 33", "output": "1 100" }, { "input": "100 1\n10\n62 1 63 1 57 1 76 1 35 1 69 1 73 1 95 1 96 1 21 1", "output": "1 1" }, { "input": "1 2000\n10\n1 1730 1 1374 1 831 1 1076 1 580 1 914 1 123 1 668 1 1288 1 160", "output": "1 2000" }, { "input": "2000 1\n10\n1058 1 1779 1 1995 1 1398 1 96 1 1599 1 1496 1 1659 1 385 1 1485 1", "output": "721 1" }, { "input": "5 5\n1\n1 1", "output": "5 5" }, { "input": "2 5\n10\n1 1 1 2 1 3 1 4 1 5 2 1 2 2 2 3 2 4 2 5", "output": "1 1" }, { "input": "1 10\n9\n1 1 1 2 1 3 1 4 1 6 1 7 1 8 1 9 1 10", "output": "1 5" }, { "input": "3 3\n5\n1 1 1 3 2 2 3 1 3 3", "output": "1 2" }, { "input": "999 999\n4\n1 499 499 1 499 999 999 499", "output": "500 500" } ]
1,668,438,512
2,147,483,647
PyPy 3-64
MEMORY_LIMIT_EXCEEDED
TESTS
28
1,526
67,072,000
import sys input = open('input.txt', 'r').readline n, m = map(int, input().split()) k = int(input()) a = list(map(int, input().split())) p = [] burned = set() for i in range(1,2*k,2): burned.add((a[i-1],a[i])) p.append([a[i-1],a[i]]) while p: q = [] for i,j in p: if (i-1)>=1 and (i-1,j) not in burned: q.append([i-1,j]) burned.add((i-1,j)) if (i+1)<=n and (i+1,j) not in burned: q.append([i+1,j]) burned.add((i+1,j)) if (j-1)>=1 and (i,j-1) not in burned: q.append([i,j-1]) burned.add((i,j-1)) if (j+1)<=m and (i,j+1) not in burned: q.append([i,j+1]) burned.add((i,j+1)) if not q: break p = q t = open('output.txt','w') print(p[0][0],p[0][1],file=t)
Title: Fire Again Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation. The burning began in *K* points simultaneously, which means that initially *K* trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1. Find the tree that will be the last to start burning. If there are several such trees, output any. Input Specification: The first input line contains two integers *N*,<=*M* (1<=≤<=*N*,<=*M*<=≤<=2000) — the size of the forest. The trees were planted in all points of the (*x*,<=*y*) (1<=≤<=*x*<=≤<=*N*,<=1<=≤<=*y*<=≤<=*M*) type, *x* and *y* are integers. The second line contains an integer *K* (1<=≤<=*K*<=≤<=10) — amount of trees, burning in the beginning. The third line contains *K* pairs of integers: *x*1,<=*y*1,<=*x*2,<=*y*2,<=...,<=*x**k*,<=*y**k* (1<=≤<=*x**i*<=≤<=*N*,<=1<=≤<=*y**i*<=≤<=*M*) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide. Output Specification: Output a line with two space-separated integers *x* and *y* — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. Demo Input: ['3 3\n1\n2 2\n', '3 3\n1\n1 1\n', '3 3\n2\n1 1 3 3\n'] Demo Output: ['1 1\n', '3 3\n', '2 2'] Note: none
```python import sys input = open('input.txt', 'r').readline n, m = map(int, input().split()) k = int(input()) a = list(map(int, input().split())) p = [] burned = set() for i in range(1,2*k,2): burned.add((a[i-1],a[i])) p.append([a[i-1],a[i]]) while p: q = [] for i,j in p: if (i-1)>=1 and (i-1,j) not in burned: q.append([i-1,j]) burned.add((i-1,j)) if (i+1)<=n and (i+1,j) not in burned: q.append([i+1,j]) burned.add((i+1,j)) if (j-1)>=1 and (i,j-1) not in burned: q.append([i,j-1]) burned.add((i,j-1)) if (j+1)<=m and (i,j+1) not in burned: q.append([i,j+1]) burned.add((i,j+1)) if not q: break p = q t = open('output.txt','w') print(p[0][0],p[0][1],file=t) ```
0
194
B
Square
PROGRAMMING
1,200
[ "math" ]
null
null
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (*n*<=+<=1) meters, he draws a cross (see picture for clarifications). John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw?
The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases. The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample.
For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\n4 8 100\n" ]
[ "17\n33\n401\n" ]
none
1,000
[ { "input": "3\n4 8 100", "output": "17\n33\n401" }, { "input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13", "output": "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27" }, { "input": "3\n13 17 21", "output": "27\n35\n43" } ]
1,538,547,145
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
t=int(input()) l1=[] for _ in range(t): n=int(input()) l1.append(n*4+1) for i in l1: print(i)
Title: Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (*n*<=+<=1) meters, he draws a cross (see picture for clarifications). John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw? Input Specification: The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases. The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample. Output Specification: For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3\n4 8 100\n'] Demo Output: ['17\n33\n401\n'] Note: none
```python t=int(input()) l1=[] for _ in range(t): n=int(input()) l1.append(n*4+1) for i in l1: print(i) ```
-1
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4 4 4 2" }, { "input": "1\n2000", "output": "1" }, { "input": "2\n2000 2000", "output": "1 1" }, { "input": "3\n500 501 502", "output": "3 2 1" }, { "input": "10\n105 106 1 1 1 11 1000 999 1000 999", "output": "6 5 8 8 8 7 1 3 1 3" }, { "input": "6\n1 2 3 4 5 6", "output": "6 5 4 3 2 1" }, { "input": "7\n6 5 4 3 2 1 1", "output": "1 2 3 4 5 6 6" }, { "input": "8\n153 100 87 14 10 8 6 5", "output": "1 2 3 4 5 6 7 8" }, { "input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10", "output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63" }, { "input": "5\n1 2000 1 1 2000", "output": "3 1 3 3 1" } ]
1,550,803,733
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
n = int(input()) a = list(map(int, input().split())) temp = sorted(a, reverse = True) for i in range (n): for j in range (n): if a[i] == temp[j]: a[i] = j + 1 break print(a)
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). Output Specification: In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. Demo Input: ['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n'] Demo Output: ['3 1 1\n', '1\n', '4 1 4 3 1\n'] Note: In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
```python n = int(input()) a = list(map(int, input().split())) temp = sorted(a, reverse = True) for i in range (n): for j in range (n): if a[i] == temp[j]: a[i] = j + 1 break print(a) ```
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,694,728,979
2,147,483,647
Python 3
OK
TESTS
30
124
6,656,000
n=int(input()) a=list(map(int,input().split())) j=sum(a)//n man=0 mos=0 for i in range(0,len(a)) : if j-a[i]<0 : man+=abs(j-a[i]) elif j-a[i]>0 : mos+=j-a[i] if man==mos : print(n) else : print(n-1)
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())) j=sum(a)//n man=0 mos=0 for i in range(0,len(a)) : if j-a[i]<0 : man+=abs(j-a[i]) elif j-a[i]>0 : mos+=j-a[i] if man==mos : print(n) else : print(n-1) ```
3
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3" }, { "input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "output": "7\n7" }, { "input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "output": "7" }, { "input": "2 2\n8 4\n1\n1", "output": "2\n2" }, { "input": "1 5\n5\n1\n1\n1\n1\n1", "output": "1\n1\n1\n1\n1" }, { "input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4", "output": "1\n4\n3\n2\n3\n1\n1" }, { "input": "4 3\n9 1 7 1\n1\n4\n2", "output": "3\n1\n2" }, { "input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7", "output": "4\n3\n2" }, { "input": "1 1\n1\n1", "output": "1" } ]
1,681,006,472
2,147,483,647
Python 3
OK
TESTS
30
810
7,372,800
n,m = map(int,input().split()) a = list(map(int,input().split())) s = set() for i in range(n-1,-1,-1): s.add(a[i]) a[i] = len(s) for k in range(m): vv = int(input())-1 print(a[vv])
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). Output Specification: Print *m* lines — on the *i*-th line print the answer to the number *l**i*. Demo Input: ['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n'] Demo Output: ['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n'] Note: none
```python n,m = map(int,input().split()) a = list(map(int,input().split())) s = set() for i in range(n-1,-1,-1): s.add(a[i]) a[i] = len(s) for k in range(m): vv = int(input())-1 print(a[vv]) ```
3
764
B
Timofey and cubes
PROGRAMMING
900
[ "constructive algorithms", "implementation" ]
null
null
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1. After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order.
Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
[ "7\n4 3 7 6 9 1 2\n", "8\n6 1 4 2 5 6 9 2\n" ]
[ "2 3 9 6 7 1 4", "2 1 6 2 5 4 9 6" ]
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4].
1,000
[ { "input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4" }, { "input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6" }, { "input": "1\n1424", "output": "1424" }, { "input": "9\n-7 9 -4 9 -6 11 15 2 -10", "output": "-10 9 15 9 -6 11 -4 2 -7" }, { "input": "2\n21968 5686", "output": "5686 21968" }, { "input": "5\n241218936 -825949895 -84926813 491336344 -872198236", "output": "-872198236 -825949895 -84926813 491336344 241218936" }, { "input": "42\n-557774624 828320986 -345782722 -62979938 -681259411 -945983652 -139095040 832293378 -82572118 432027535 88438103 568183540 961782904 73543295 615958219 -5050584 322982437 -146046730 759453379 129267920 -819827396 -348156048 805080102 390723009 -771277251 -79011872 -592313207 528489973 656201270 -127795621 17284747 145139617 -565641608 83452176 -223074608 545811186 -657981923 -204657836 154779765 -476867246 180386291 202782486", "output": "202782486 828320986 -476867246 -62979938 -204657836 -945983652 545811186 832293378 83452176 432027535 145139617 568183540 -127795621 73543295 528489973 -5050584 -79011872 -146046730 390723009 129267920 -348156048 -819827396 805080102 759453379 -771277251 322982437 -592313207 615958219 656201270 961782904 17284747 88438103 -565641608 -82572118 -223074608 -139095040 -657981923 -681259411 154779765 -345782722 180386291 -557774624" }, { "input": "2\n1 2", "output": "2 1" }, { "input": "6\n1 2 3 4 5 6", "output": "6 2 4 3 5 1" }, { "input": "4\n0 1 2 3", "output": "3 1 2 0" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10 2 8 4 6 5 7 3 9 1" }, { "input": "2\n4 5", "output": "5 4" }, { "input": "2\n1 5", "output": "5 1" }, { "input": "2\n2 5", "output": "5 2" }, { "input": "2\n3 4", "output": "4 3" }, { "input": "2\n10 0", "output": "0 10" }, { "input": "66\n8229 5299 5562 1259 2258 1126 5026 8796 3497 7111 6680 1180 1426 4821 3322 3502 400 2951 4187 417 5234 1266 7525 7648 417 9297 174 670 1790 4121 9737 938 4616 3402 2009 2461 474 3728 327 3353 9773 6818 8781 874 2209 1260 1647 6126 9287 9638 5049 1256 4459 863 1835 4822 6809 348 5053 7784 6927 2140 9173 7817 5095 4184", "output": "4184 5299 7817 1259 2140 1126 7784 8796 348 7111 4822 1180 863 4821 1256 3502 9638 2951 6126 417 1260 1266 874 7648 6818 9297 3353 670 3728 4121 2461 938 3402 4616 2009 9737 474 1790 327 174 9773 417 8781 7525 2209 5234 1647 4187 9287 400 5049 3322 4459 1426 1835 6680 6809 3497 5053 5026 6927 2258 9173 5562 5095 8229" } ]
1,486,421,788
2,147,483,647
Python 3
OK
TESTS
34
139
19,148,800
a =input() k =input() k =k.split(' ') l =len(k) i = 0 while i<l//2: k[i],k[-(i+1)]=k[-(i+1)],k[i] i+=2 print(' '.join(k))
Title: Timofey and cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1. After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. Output Specification: Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique. Demo Input: ['7\n4 3 7 6 9 1 2\n', '8\n6 1 4 2 5 6 9 2\n'] Demo Output: ['2 3 9 6 7 1 4', '2 1 6 2 5 4 9 6'] Note: Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4].
```python a =input() k =input() k =k.split(' ') l =len(k) i = 0 while i<l//2: k[i],k[-(i+1)]=k[-(i+1)],k[i] i+=2 print(' '.join(k)) ```
3
637
B
Chat Order
PROGRAMMING
1,200
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
1,000
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "output": "ypg" }, { "input": "3\nexhll\nexhll\narruapexj", "output": "arruapexj\nexhll" }, { "input": "3\nfv\nle\nle", "output": "le\nfv" }, { "input": "8\nm\nm\nm\nm\nm\nm\nm\nm", "output": "m" }, { "input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr", "output": "r\nu\nb\nk\nw\ni" }, { "input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok", "output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne" }, { "input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe", "output": "we\nklrj" }, { "input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh", "output": "zncybqmh\naeebef\nn" }, { "input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo", "output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj" }, { "input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn", "output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy" }, { "input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg", "output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg" }, { "input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh", "output": "vhh\nfa" }, { "input": "2\naa\nbb", "output": "bb\naa" }, { "input": "2\naa\na", "output": "a\naa" }, { "input": "3\naa\naa\naa", "output": "aa" }, { "input": "5\naa\na\naa\na\naa", "output": "aa\na" }, { "input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa", "output": "aaa\naaaaaaa\naa\na\naaaa" }, { "input": "5\na\naa\naaa\naaaa\na", "output": "a\naaaa\naaa\naa" }, { "input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa", "output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa" }, { "input": "3\na\naa\naaa", "output": "aaa\naa\na" }, { "input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz", "output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz" } ]
1,598,722,535
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
3,000
1,228,800
# -*- coding: utf-8 -*- n = int(input()) l = [] for i in range(n): s = input() if(s in l): l.remove(s) l.append(s) else: l.append(s) for i in reversed(l): print(i)
Title: Chat Order Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. Output Specification: Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. Demo Input: ['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n'] Demo Output: ['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n'] Note: In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
```python # -*- coding: utf-8 -*- n = int(input()) l = [] for i in range(n): s = input() if(s in l): l.remove(s) l.append(s) else: l.append(s) for i in reversed(l): print(i) ```
0
484
B
Maximum Value
PROGRAMMING
2,100
[ "binary search", "math", "sortings", "two pointers" ]
null
null
You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*.
The first line contains integer *n* — the length of the sequence (1<=≤<=*n*<=≤<=2·105). The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=106).
Print the answer to the problem.
[ "3\n3 4 5\n" ]
[ "2\n" ]
none
1,000
[ { "input": "3\n3 4 5", "output": "2" }, { "input": "3\n1 2 4", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "2\n1000000 999999", "output": "1" }, { "input": "12\n4 4 10 13 28 30 41 43 58 61 70 88", "output": "30" }, { "input": "7\n2 13 22 32 72 91 96", "output": "27" }, { "input": "5\n5 11 12 109 110", "output": "10" } ]
1,419,139,792
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
17,715,200
from bisect import bisect_left def main(): input() aa = sorted(set(map(int, input().split()))) n, mx = len(aa), max(aa) * 2 x = 0 for aj in aa: for ajj in range(aj * 2, mx, aj): i = bisect_left(aa, ajj) if i == n: ai = aa[-1] t = ai % aj if x < t: x = t break ai = aa[i] t = ai % aj if not t: t = aa[i - 1] % aj if x < t: x = t print(x) if __name__ == '__main__': main()
Title: Maximum Value Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*. Input Specification: The first line contains integer *n* — the length of the sequence (1<=≤<=*n*<=≤<=2·105). The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=106). Output Specification: Print the answer to the problem. Demo Input: ['3\n3 4 5\n'] Demo Output: ['2\n'] Note: none
```python from bisect import bisect_left def main(): input() aa = sorted(set(map(int, input().split()))) n, mx = len(aa), max(aa) * 2 x = 0 for aj in aa: for ajj in range(aj * 2, mx, aj): i = bisect_left(aa, ajj) if i == n: ai = aa[-1] t = ai % aj if x < t: x = t break ai = aa[i] t = ai % aj if not t: t = aa[i - 1] % aj if x < t: x = t print(x) if __name__ == '__main__': main() ```
0
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "input": "H", "output": "YES" }, { "input": "+", "output": "NO" }, { "input": "~", "output": "NO" }, { "input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "output": "YES" }, { "input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "output": "YES" }, { "input": "@F%K2=%RyL/", "output": "NO" }, { "input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "output": "YES" }, { "input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)", "output": "YES" }, { "input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C", "output": "YES" }, { "input": "p-UXsbd&f", "output": "NO" }, { "input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_", "output": "YES" }, { "input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]", "output": "YES" }, { "input": "}do5RU<(w<q[\"-NR)IAH_HyiD{", "output": "YES" }, { "input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8", "output": "YES" }, { "input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv", "output": "YES" }, { "input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`", "output": "YES" }, { "input": "OKBB5z7ud81[Tn@P\"nDUd,>@", "output": "NO" }, { "input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv", "output": "YES" }, { "input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh", "output": "YES" }, { "input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp", "output": "NO" }, { "input": "!3YPv@2JQ44@)R2O_4`GO", "output": "YES" }, { "input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\", "output": "YES" }, { "input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L", "output": "NO" }, { "input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&", "output": "YES" }, { "input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}", "output": "YES" }, { "input": "Uh3>ER](J", "output": "NO" }, { "input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,", "output": "YES" }, { "input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!", "output": "YES" }, { "input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@", "output": "YES" }, { "input": "'jdL(vX", "output": "NO" }, { "input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5", "output": "YES" }, { "input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s", "output": "YES" }, { "input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]", "output": "YES" }, { "input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU", "output": "YES" }, { "input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->", "output": "YES" }, { "input": "&ppw0._:\\p-PuWM@l}%%=", "output": "NO" }, { "input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr", "output": "YES" }, { "input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q", "output": "YES" }, { "input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0", "output": "YES" }, { "input": "VXB&r9Z)IlKOJ:??KDA", "output": "YES" }, { "input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R", "output": "YES" }, { "input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C", "output": "YES" }, { "input": "O.&=qt(`z(", "output": "NO" }, { "input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@", "output": "YES" }, { "input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp", "output": "YES" }, { "input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8", "output": "YES" }, { "input": "!0WKT:$O", "output": "NO" }, { "input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)", "output": "YES" }, { "input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly", "output": "YES" }, { "input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(", "output": "NO" }, { "input": "Qv)X8", "output": "YES" }, { "input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F", "output": "YES" }, { "input": "e{}2vQ+/r@p0}cLKNe4MCk", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH", "output": "YES" }, { "input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "1H1", "output": "YES" }, { "input": "+Q", "output": "YES" }, { "input": "1ab", "output": "NO" }, { "input": "!", "output": "NO" }, { "input": "0+", "output": "NO" }, { "input": "+H", "output": "YES" }, { "input": "cH", "output": "YES" }, { "input": "+8", "output": "NO" }, { "input": "8+", "output": "NO" }, { "input": "++++++++++++++++++++++++++", "output": "NO" }, { "input": "(+)", "output": "NO" }, { "input": "H+", "output": "YES" }, { "input": "a!", "output": "NO" }, { "input": "++++++++++++++", "output": "NO" }, { "input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "HQ9", "output": "YES" }, { "input": "+++H", "output": "YES" }, { "input": "++++++++++", "output": "NO" }, { "input": "HHHHHHH", "output": "YES" }, { "input": "abacabaH", "output": "YES" }, { "input": "+G", "output": "NO" } ]
1,694,405,904
2,147,483,647
PyPy 3-64
OK
TESTS
85
124
0
p=input() l=['H','Q','9'] flag=0 for i in p: if i in l: flag=1 break if flag==1: print("YES") else: print("NO")
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. Input Specification: The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. Output Specification: Output "YES", if executing the program will produce any output, and "NO" otherwise. Demo Input: ['Hi!\n', 'Codeforces\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
```python p=input() l=['H','Q','9'] flag=0 for i in p: if i in l: flag=1 break if flag==1: print("YES") else: print("NO") ```
3
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$.
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels.
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3 4 5 7 8 10 11 12 13 14 15 16 17 19 21 22 23 24 25 26 27 28 30 32 33 36 39 40 41 42 46 48 53 54 55 59 60 61 63 65 68 70 71 74 75 76 79 80 81 82 84 88 89 90 91 93 94 96 97 98 100 101 102 105 106 107 108 109 110 111 113 114 115 116 117 118 120 121 122 125 126 128 131 132 133 134 135 137 138 139 140 143 144 146 147 148 149", "output": "47" }, { "input": "1 1000000000\n-1000000000", "output": "2" }, { "input": "2 1000000000\n-1000000000 1000000000", "output": "3" }, { "input": "100 2\n1 3 5 6 8 9 12 13 14 17 18 21 22 23 24 25 26 27 29 30 34 35 36 39 41 44 46 48 52 53 55 56 57 59 61 63 64 66 68 69 70 71 72 73 75 76 77 79 80 81 82 87 88 91 92 93 94 95 96 97 99 100 102 103 104 106 109 110 111 112 113 114 115 117 118 119 120 122 124 125 127 128 129 130 131 132 133 134 136 137 139 140 141 142 143 145 146 148 149 150", "output": "6" }, { "input": "100 3\n0 1 3 6 7 8 9 10 13 14 16 17 18 20 21 22 24 26 27 30 33 34 35 36 37 39 42 43 44 45 46 48 53 54 55 56 57 58 61 63 64 65 67 69 70 72 73 76 77 78 79 81 82 83 85 86 87 88 90 92 93 95 96 97 98 99 100 101 104 105 108 109 110 113 114 115 116 118 120 121 123 124 125 128 130 131 132 133 134 135 136 137 139 140 141 142 146 147 148 150", "output": "2" }, { "input": "1 1000000000\n1000000000", "output": "2" }, { "input": "10 2\n-93 -62 -53 -42 -38 11 57 58 87 94", "output": "17" }, { "input": "2 500000000\n-1000000000 1000000000", "output": "4" }, { "input": "100 10\n-489 -476 -445 -432 -430 -421 -420 -418 -412 -411 -404 -383 -356 -300 -295 -293 -287 -276 -265 -263 -258 -251 -249 -246 -220 -219 -205 -186 -166 -157 -143 -137 -136 -130 -103 -86 -80 -69 -67 -55 -43 -41 -40 -26 -19 -9 16 29 41 42 54 76 84 97 98 99 101 115 134 151 157 167 169 185 197 204 208 226 227 232 234 249 259 266 281 282 293 298 300 306 308 313 319 328 331 340 341 344 356 362 366 380 390 399 409 411 419 444 455 498", "output": "23" }, { "input": "1 1000000000\n999999999", "output": "2" }, { "input": "1 1\n-5", "output": "2" }, { "input": "2 1\n-1000000000 1000000000", "output": "4" }, { "input": "1 2\n1", "output": "2" }, { "input": "4 5\n0 20 40 60", "output": "8" }, { "input": "1 1\n-10", "output": "2" }, { "input": "1 1\n-1000000000", "output": "2" }, { "input": "1 1000000000\n0", "output": "2" }, { "input": "1 2\n-10", "output": "2" }, { "input": "1 1\n2", "output": "2" }, { "input": "1 5\n-100", "output": "2" }, { "input": "2 1000000000\n999999999 1000000000", "output": "2" }, { "input": "2 2\n0 5", "output": "4" }, { "input": "1 2\n-5", "output": "2" }, { "input": "1 1\n1", "output": "2" }, { "input": "1 5\n-20", "output": "2" }, { "input": "2 100000000\n-1000000000 1000000000", "output": "4" }, { "input": "1 1000000000\n147483641", "output": "2" }, { "input": "3 3\n1 8 9", "output": "4" }, { "input": "2 1\n1 1000000000", "output": "4" }, { "input": "1 2\n-4", "output": "2" }, { "input": "2 1\n-1000000000 -1", "output": "4" } ]
1,530,855,804
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
140
0
n, d = list(map(int,input().split())) l = list(map(int,input().split())) l = [-1000000000] + l l.append(1000000000) t = [] s = 0 for i in range(1,n+1): if l[i]-l[i-1] >= 2*d: x = l[i] - d if l[i] - x <= x - l[i-1] and (not x in t): t.append(x) if l[i+1]-l[i] >= 2*d: x = l[i] + d if x - l[i] <= l[i+1] - x and (not x in t): t.append(x) print(len(t))
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$. Input Specification: The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels. Output Specification: Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. Demo Input: ['4 3\n-3 2 9 16\n', '5 2\n4 8 11 18 19\n'] Demo Output: ['6\n', '5\n'] Note: In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
```python n, d = list(map(int,input().split())) l = list(map(int,input().split())) l = [-1000000000] + l l.append(1000000000) t = [] s = 0 for i in range(1,n+1): if l[i]-l[i-1] >= 2*d: x = l[i] - d if l[i] - x <= x - l[i-1] and (not x in t): t.append(x) if l[i+1]-l[i] >= 2*d: x = l[i] + d if x - l[i] <= l[i+1] - x and (not x in t): t.append(x) print(len(t)) ```
0
114
A
Cifera
PROGRAMMING
1,000
[ "math" ]
null
null
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
[ "5\n25\n", "3\n8\n" ]
[ "YES\n1\n", "NO\n" ]
none
500
[ { "input": "5\n25", "output": "YES\n1" }, { "input": "3\n8", "output": "NO" }, { "input": "123\n123", "output": "YES\n0" }, { "input": "99\n970300", "output": "NO" }, { "input": "1000\n6666666", "output": "NO" }, { "input": "59\n3571", "output": "NO" }, { "input": "256\n16777217", "output": "NO" }, { "input": "4638\n21511044", "output": "YES\n1" }, { "input": "24\n191102976", "output": "YES\n5" }, { "input": "52010\n557556453", "output": "NO" }, { "input": "61703211\n1750753082", "output": "NO" }, { "input": "137\n2571353", "output": "YES\n2" }, { "input": "8758\n1746157336", "output": "NO" }, { "input": "2\n64", "output": "YES\n5" }, { "input": "96\n884736", "output": "YES\n2" }, { "input": "1094841453\n1656354409", "output": "NO" }, { "input": "1154413\n1229512809", "output": "NO" }, { "input": "2442144\n505226241", "output": "NO" }, { "input": "11548057\n1033418098", "output": "NO" }, { "input": "581\n196122941", "output": "YES\n2" }, { "input": "146\n1913781536", "output": "NO" }, { "input": "945916\n1403881488", "output": "NO" }, { "input": "68269\n365689065", "output": "NO" }, { "input": "30\n900", "output": "YES\n1" }, { "input": "6\n1296", "output": "YES\n3" }, { "input": "1470193122\n1420950405", "output": "NO" }, { "input": "90750\n1793111557", "output": "NO" }, { "input": "1950054\n1664545956", "output": "NO" }, { "input": "6767692\n123762320", "output": "NO" }, { "input": "1437134\n1622348229", "output": "NO" }, { "input": "444103\n1806462642", "output": "NO" }, { "input": "2592\n6718464", "output": "YES\n1" }, { "input": "50141\n366636234", "output": "NO" }, { "input": "835\n582182875", "output": "YES\n2" }, { "input": "156604\n902492689", "output": "NO" }, { "input": "27385965\n1742270058", "output": "NO" }, { "input": "3\n9", "output": "YES\n1" }, { "input": "35\n1838265625", "output": "YES\n5" }, { "input": "8\n4096", "output": "YES\n3" }, { "input": "85955\n945811082", "output": "NO" }, { "input": "54958832\n956670209", "output": "NO" }, { "input": "1475381\n1348159738", "output": "NO" }, { "input": "7313241\n413670642", "output": "NO" }, { "input": "582470\n2116368165", "output": "NO" }, { "input": "26859739\n595086170", "output": "NO" }, { "input": "249766393\n1582130", "output": "NO" }, { "input": "11734\n137686756", "output": "YES\n1" }, { "input": "925093\n1098566745", "output": "NO" }, { "input": "40\n1600", "output": "YES\n1" }, { "input": "2147483647\n2147483647", "output": "YES\n0" }, { "input": "2147483646\n2147483647", "output": "NO" }, { "input": "2147483647\n2147483646", "output": "NO" }, { "input": "2\n2147483647", "output": "NO" }, { "input": "2\n1073741825", "output": "NO" }, { "input": "2\n1073741824", "output": "YES\n29" }, { "input": "10000\n10", "output": "NO" }, { "input": "10\n10000", "output": "YES\n3" }, { "input": "10\n2000000000", "output": "NO" }, { "input": "10\n1000000000", "output": "YES\n8" }, { "input": "5\n1808548329", "output": "NO" }, { "input": "2\n2147483646", "output": "NO" }, { "input": "25\n125", "output": "NO" }, { "input": "6\n18", "output": "NO" }, { "input": "5\n30", "output": "NO" } ]
1,615,547,904
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
0
from math import * def checkPowerOfn(n,k): # find `log8(n)` i = log(n) / log(k) # return true if `log8(n)` is an integer return i - floor(i) < 0.000001 k=int(input()) l=int(input()) ''' m=l/k k=0 k2=1 k3=2 k4=3 k5=4 k6= ''' if checkPowerOfn(l,k): print("YES") print(int(log(l)/log(k)-1)) else: print("NO")
Title: Cifera Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. Input Specification: The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). Output Specification: You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. Demo Input: ['5\n25\n', '3\n8\n'] Demo Output: ['YES\n1\n', 'NO\n'] Note: none
```python from math import * def checkPowerOfn(n,k): # find `log8(n)` i = log(n) / log(k) # return true if `log8(n)` is an integer return i - floor(i) < 0.000001 k=int(input()) l=int(input()) ''' m=l/k k=0 k2=1 k3=2 k4=3 k5=4 k6= ''' if checkPowerOfn(l,k): print("YES") print(int(log(l)/log(k)-1)) else: print("NO") ```
0
867
A
Between the Offices
PROGRAMMING
800
[ "implementation" ]
null
null
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower).
[ "4\nFSSF\n", "2\nSF\n", "10\nFFFFFFFFFF\n", "10\nSSFFSFFSFF\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n" ]
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you stayed the whole period in San Francisco, so the answer is "NO". In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
500
[ { "input": "4\nFSSF", "output": "NO" }, { "input": "2\nSF", "output": "YES" }, { "input": "10\nFFFFFFFFFF", "output": "NO" }, { "input": "10\nSSFFSFFSFF", "output": "YES" }, { "input": "20\nSFSFFFFSSFFFFSSSSFSS", "output": "NO" }, { "input": "20\nSSFFFFFSFFFFFFFFFFFF", "output": "YES" }, { "input": "20\nSSFSFSFSFSFSFSFSSFSF", "output": "YES" }, { "input": "20\nSSSSFSFSSFSFSSSSSSFS", "output": "NO" }, { "input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF", "output": "NO" }, { "input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF", "output": "YES" }, { "input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS", "output": "NO" }, { "input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS", "output": "NO" }, { "input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS", "output": "NO" }, { "input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS", "output": "NO" }, { "input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS", "output": "NO" }, { "input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS", "output": "NO" }, { "input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", "output": "NO" }, { "input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "YES" }, { "input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "YES" }, { "input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF", "output": "YES" }, { "input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF", "output": "YES" }, { "input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF", "output": "YES" }, { "input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF", "output": "YES" }, { "input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF", "output": "YES" }, { "input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF", "output": "YES" }, { "input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF", "output": "YES" }, { "input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF", "output": "YES" }, { "input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF", "output": "YES" }, { "input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF", "output": "YES" }, { "input": "2\nSS", "output": "NO" } ]
1,551,452,489
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
s = input(); print('NYOE S'[s[1] != s[0] == 'S'::2])
Title: Between the Offices Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. Input Specification: The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. Output Specification: Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n', 'YES\n'] Note: In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you stayed the whole period in San Francisco, so the answer is "NO". In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
```python s = input(); print('NYOE S'[s[1] != s[0] == 'S'::2]) ```
-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,653,830,564
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
n,m =map(int,input().split()) ans=(n*m)//2 print(ans)
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 =map(int,input().split()) ans=(n*m)//2 print(ans) ```
-1
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat.
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry.
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "0" }, { "input": "10 10\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS", "output": "0" }, { "input": "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS", "output": "30" }, { "input": "10 10\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..", "output": "80" }, { "input": "9 5\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS", "output": "0" }, { "input": "9 9\n...S.....\nS.S.....S\n.S....S..\n.S.....SS\n.........\n..S.S..S.\n.SS......\n....S....\n..S...S..", "output": "17" }, { "input": "5 6\nSSSSSS\nSSSSSS\nSSSSSS\nSS.S..\nS.S.SS", "output": "0" }, { "input": "9 8\n........\n.......S\n........\nS.......\n........\n........\nS.......\n........\n.......S", "output": "64" }, { "input": "9 7\n......S\n......S\nS.S.S..\n.......\n.......\n.S.....\n.S....S\n..S....\n.S....S", "output": "28" }, { "input": "10 10\n.....S....\n....SS..S.\n.S...S....\n........SS\n.S.......S\nSS..S.....\n.SS.....SS\nS..S......\n.......SSS\nSSSSS....S", "output": "10" }, { "input": "6 7\n..S.SS.\n......S\n....S.S\nSS..S..\nS..SS.S\n.....S.", "output": "0" }, { "input": "10 6\n.SSSSS\nSSS.SS\nSSSSSS\nS.SSSS\nSSSSS.\nS.SSSS\nSS.SSS\n.SSS.S\n.SSS..\nSS..SS", "output": "0" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "3 2\nS.\n.S\nS.", "output": "0" }, { "input": "3 2\nS.\n.S\nS.", "output": "0" }, { "input": "4 3\n.S.\nS.S\n.S.\nS.S", "output": "0" }, { "input": "2 3\n...\nSSS", "output": "3" }, { "input": "2 4\nS.SS\nS.SS", "output": "2" }, { "input": "2 2\n..\n.S", "output": "3" }, { "input": "3 2\n.S\n.S\nSS", "output": "0" }, { "input": "2 4\nSS.S\n..S.", "output": "0" }, { "input": "2 3\n...\nS..", "output": "5" } ]
1,659,491,327
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
n,m=map(int,input().split()) l=[] for i in range(n): l.append(list(input())) k=m y=r=c=0 for j in range(len(l[0])): x=[] for i in range(len(l)): x.append(l[i][j]) if len(set(x))==1: y+=len(x) c+=1 for i in l: if len(set(i))==1: y+=len(i) r+=1 print(y-c)
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat. Input Specification: The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry. Output Specification: Output the maximum number of cake cells that the cakeminator can eat. Demo Input: ['3 4\nS...\n....\n..S.\n'] Demo Output: ['8\n'] Note: For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
```python n,m=map(int,input().split()) l=[] for i in range(n): l.append(list(input())) k=m y=r=c=0 for j in range(len(l[0])): x=[] for i in range(len(l)): x.append(l[i][j]) if len(set(x))==1: y+=len(x) c+=1 for i in l: if len(set(i))==1: y+=len(i) r+=1 print(y-c) ```
0
0
none
none
none
0
[ "none" ]
null
null
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system. Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova.
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order.
[ "21\n", "20\n" ]
[ "1\n15\n", "0\n" ]
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
0
[ { "input": "21", "output": "1\n15" }, { "input": "20", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "1\n1" }, { "input": "3", "output": "0" }, { "input": "100000001", "output": "2\n99999937\n100000000" }, { "input": "1000000000", "output": "1\n999999932" }, { "input": "999999979", "output": "2\n999999899\n999999908" }, { "input": "9", "output": "0" }, { "input": "10", "output": "1\n5" }, { "input": "11", "output": "1\n10" }, { "input": "39", "output": "1\n33" }, { "input": "66", "output": "1\n60" }, { "input": "75", "output": "0" }, { "input": "100", "output": "1\n86" }, { "input": "101", "output": "2\n91\n100" }, { "input": "2014", "output": "2\n1988\n2006" }, { "input": "999999994", "output": "0" } ]
1,514,393,388
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
5,529,600
import itertools as t m=int(input()) n=list(str(m)) ans=[] lst=[] def convert(x): ex=0 for i in range(len(x)): ex+=int(x[i])*10**(len(x)-i-1) return ex def javab(x): y=list(str(x)) ans=[] for i in range(1,len(y)+1): h=t.combinations(y,i) for k in h : ans.append(k) for i in range(len(ans)): ans[i]=convert(ans[i]) return sum(ans) for i in range(m): if javab(i)==m : ans.append(i) print(len(ans)) for i in ans : print(i)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system. Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order. Demo Input: ['21\n', '20\n'] Demo Output: ['1\n15\n', '0\n'] Note: In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
```python import itertools as t m=int(input()) n=list(str(m)) ans=[] lst=[] def convert(x): ex=0 for i in range(len(x)): ex+=int(x[i])*10**(len(x)-i-1) return ex def javab(x): y=list(str(x)) ans=[] for i in range(1,len(y)+1): h=t.combinations(y,i) for k in h : ans.append(k) for i in range(len(ans)): ans[i]=convert(ans[i]) return sum(ans) for i in range(m): if javab(i)==m : ans.append(i) print(len(ans)) for i in ans : print(i) ```
0