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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,672,053,209 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | def solve(n, a):
count = 0
for i in range(n):
for j in range(i+1, n+1):
if sum(a[i:j]) % 2 == 1:
count += 1
return count
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a)) | 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
def solve(n, a):
count = 0
for i in range(n):
for j in range(i+1, n+1):
if sum(a[i:j]) % 2 == 1:
count += 1
return count
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
``` | 0 |
|
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"input": "4",
"output": "Rajesh"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "10",
"output": "Penny"
},
{
"input": "534",
"output": "Rajesh"
},
{
"input": "5033",
"output": "Howard"
},
{
"input": "10010",
"output": "Howard"
},
{
"input": "500000000",
"output": "Penny"
},
{
"input": "63",
"output": "Rajesh"
},
{
"input": "841",
"output": "Leonard"
},
{
"input": "3667",
"output": "Penny"
},
{
"input": "38614",
"output": "Howard"
},
{
"input": "282798",
"output": "Rajesh"
},
{
"input": "9266286",
"output": "Rajesh"
},
{
"input": "27385966",
"output": "Leonard"
},
{
"input": "121580142",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "300",
"output": "Howard"
},
{
"input": "1745",
"output": "Leonard"
},
{
"input": "8302",
"output": "Rajesh"
},
{
"input": "184518",
"output": "Sheldon"
},
{
"input": "1154414",
"output": "Rajesh"
},
{
"input": "28643950",
"output": "Leonard"
},
{
"input": "159222638",
"output": "Howard"
},
{
"input": "24",
"output": "Penny"
},
{
"input": "505",
"output": "Penny"
},
{
"input": "4425",
"output": "Rajesh"
},
{
"input": "12079",
"output": "Sheldon"
},
{
"input": "469726",
"output": "Penny"
},
{
"input": "3961838",
"output": "Penny"
},
{
"input": "57710446",
"output": "Leonard"
},
{
"input": "80719470",
"output": "Howard"
},
{
"input": "1000000000",
"output": "Penny"
},
{
"input": "999999999",
"output": "Penny"
},
{
"input": "999999998",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
}
] | 1,558,927,402 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 140 | 0 | x = int(input())
n=1
lvl_arr = [0]
def LvL(n):
lvl_arr.append(2**(n-1)*5 + lvl_arr[n-1])
return lvl_arr[n]
while(x > LvL(n)):
n = n+1
p = ((x - lvl_arr[n-1] - 1) // 2**(n-1)) + 1
if(p == 1):
print("Sheldon")
elif(p == 2):
print("Leonard")
elif(p == 3):
print("Penny")
elif(p == 4):
print("Rajesh")
else:
print("Howard")
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
Input Specification:
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Output Specification:
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
Demo Input:
['1\n', '6\n', '1802\n']
Demo Output:
['Sheldon\n', 'Sheldon\n', 'Penny\n']
Note:
none | ```python
x = int(input())
n=1
lvl_arr = [0]
def LvL(n):
lvl_arr.append(2**(n-1)*5 + lvl_arr[n-1])
return lvl_arr[n]
while(x > LvL(n)):
n = n+1
p = ((x - lvl_arr[n-1] - 1) // 2**(n-1)) + 1
if(p == 1):
print("Sheldon")
elif(p == 2):
print("Leonard")
elif(p == 3):
print("Penny")
elif(p == 4):
print("Rajesh")
else:
print("Howard")
``` | 3.93 |
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,683,039,348 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n,m,a=map(int,input().split())
l1=n//a
l2=m//a
if n//a<n/a:
l1=n//a+1
if m//a<m/a:
l2=m//a +1
soni=l1*l2
print(soni)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n,m,a=map(int,input().split())
l1=n//a
l2=m//a
if n//a<n/a:
l1=n//a+1
if m//a<m/a:
l2=m//a +1
soni=l1*l2
print(soni)
``` | 3.977 |
111 | A | Petya and Inequiations | PROGRAMMING | 1,400 | [
"greedy"
] | A. Petya and Inequiations | 2 | 256 | Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y* | The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator. | Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. | [
"5 15 15\n",
"2 3 2\n",
"1 99 11\n"
] | [
"4\n4\n1\n1\n2\n",
"-1\n",
"11\n"
] | none | 500 | [
{
"input": "5 15 15",
"output": "11\n1\n1\n1\n1"
},
{
"input": "2 3 2",
"output": "-1"
},
{
"input": "1 99 11",
"output": "11"
},
{
"input": "100000 810000099998 1000000",
"output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "3 254 18",
"output": "16\n1\n1"
},
{
"input": "4 324 77",
"output": "74\n1\n1\n1"
},
{
"input": "5 315 90",
"output": "86\n1\n1\n1\n1"
},
{
"input": "6 225 59",
"output": "54\n1\n1\n1\n1\n1"
},
{
"input": "7 351 29",
"output": "23\n1\n1\n1\n1\n1\n1"
},
{
"input": "100 913723780421 955988",
"output": "-1"
},
{
"input": "200 894176381082 945808",
"output": "-1"
},
{
"input": "300 923251939897 961159",
"output": "960860\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "1000 824905348050 909242",
"output": "-1"
},
{
"input": "10000 795416053320 901860",
"output": "891861\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "31000 819461299082 936240",
"output": "-1"
},
{
"input": "44000 772772899626 923074",
"output": "-1"
},
{
"input": "45678 783917268558 931068",
"output": "885391\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "99999 681508136225 925533",
"output": "-1"
},
{
"input": "99999 688345771552 929664",
"output": "829666\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "99976 664640815001 915230",
"output": "-1"
},
{
"input": "100000 729199960625 953931",
"output": "-1"
},
{
"input": "50 890543266647 943735",
"output": "-1"
},
{
"input": "60 817630084499 904288",
"output": "904229\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "99999 716046078026 946193",
"output": "-1"
},
{
"input": "99998 729652614803 954194",
"output": "854197\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "10000 950051796437 984705",
"output": "-1"
},
{
"input": "999 992972391401 997478",
"output": "-1"
},
{
"input": "99999 667887855532 917242",
"output": "817244\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "12313 955817132591 989971",
"output": "977659\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "1 983300308227 991615",
"output": "-1"
},
{
"input": "2 912219830404 955103",
"output": "955102\n1"
},
{
"input": "3 934371623645 966631",
"output": "-1"
},
{
"input": "4 857839030421 926199",
"output": "-1"
},
{
"input": "7 897398130730 947317",
"output": "-1"
},
{
"input": "60 833021290059 912759",
"output": "912700\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "99999 715837929182 946070",
"output": "846072\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "99998 714958284701 945549",
"output": "845552\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "100000 730132752483 954477",
"output": "854478\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "9999 850451005599 932197",
"output": "922199\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "99999 741078317879 960857",
"output": "860859\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "12313 873989408188 947186",
"output": "934874\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "1 860113420929 927423",
"output": "927423"
},
{
"input": "2 933669982757 966267",
"output": "966266\n1"
},
{
"input": "3 933157932003 966003",
"output": "966001\n1\n1"
},
{
"input": "4 944626542564 971922",
"output": "971919\n1\n1\n1"
},
{
"input": "7 937519681542 968262",
"output": "968256\n1\n1\n1\n1\n1\n1"
},
{
"input": "100000 1000000000000 1000000",
"output": "-1"
},
{
"input": "99999 999999999999 999999",
"output": "-1"
},
{
"input": "100 1 1",
"output": "-1"
},
{
"input": "2 1 1",
"output": "-1"
},
{
"input": "11 10 10",
"output": "-1"
},
{
"input": "1 5 10",
"output": "10"
},
{
"input": "10 3 8",
"output": "-1"
},
{
"input": "5 37 10",
"output": "6\n1\n1\n1\n1"
},
{
"input": "5 1 4",
"output": "-1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1000000000000 1",
"output": "-1"
},
{
"input": "1 1 1000000",
"output": "1000000"
},
{
"input": "100000 1 1",
"output": "-1"
},
{
"input": "100000 1 1000000",
"output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n..."
},
{
"input": "100000 1000000000000 1",
"output": "-1"
},
{
"input": "1 1000000000000 1000000",
"output": "1000000"
}
] | 1,590,925,696 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 436 | 8,089,600 |
n,x,y=map(int,input().split())
import math
an=n-1
if(x<=n-1):
if(y>=n):
for i in range(n):
print(1)
else:
print(-1)
else:
me=math.sqrt(x-an)
if(me==int(me)):
me=int(me)
if(me+an<=y):
for i in range(n-1):
print(1)
print(me)
else:
print(-1)
else:
me=int(me)
me+=1
if(me+an<=y):
for i in range(n-1):
print(1)
print(me)
else:
print(-1)
| Title: Petya and Inequiations
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y*
Input Specification:
The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator.
Output Specification:
Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Demo Input:
['5 15 15\n', '2 3 2\n', '1 99 11\n']
Demo Output:
['4\n4\n1\n1\n2\n', '-1\n', '11\n']
Note:
none | ```python
n,x,y=map(int,input().split())
import math
an=n-1
if(x<=n-1):
if(y>=n):
for i in range(n):
print(1)
else:
print(-1)
else:
me=math.sqrt(x-an)
if(me==int(me)):
me=int(me)
if(me+an<=y):
for i in range(n-1):
print(1)
print(me)
else:
print(-1)
else:
me=int(me)
me+=1
if(me+an<=y):
for i in range(n-1):
print(1)
print(me)
else:
print(-1)
``` | 3.875932 |
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,678,595,672 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | N = 200
vis = [0]*30
def main():
n = int(input())
for _ in range(n):
ss = input().strip()
vis.clear()
vis = [0]*30
l = len(ss)
f = True
mx = 0
mi = 110
for i in range(l):
vis[ord(ss[i])-ord('a')] = 1
mx = max(mx, ord(ss[i])-ord('a'))
mi = min(mi, ord(ss[i])-ord('a'))
for i in range(mi, mx+1):
if vis[i] == 0:
f = False
break
if f and mx-mi+1 == l:
print("Yes")
else:
print("No")
| 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
N = 200
vis = [0]*30
def main():
n = int(input())
for _ in range(n):
ss = input().strip()
vis.clear()
vis = [0]*30
l = len(ss)
f = True
mx = 0
mi = 110
for i in range(l):
vis[ord(ss[i])-ord('a')] = 1
mx = max(mx, ord(ss[i])-ord('a'))
mi = min(mi, ord(ss[i])-ord('a'))
for i in range(mi, mx+1):
if vis[i] == 0:
f = False
break
if f and mx-mi+1 == l:
print("Yes")
else:
print("No")
``` | 0 |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.
Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "172.7875959474"
},
{
"input": "1\n1000",
"output": "3141592.6535897931"
},
{
"input": "8\n8 1 7 2 6 3 5 4",
"output": "113.0973355292"
},
{
"input": "100\n1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901",
"output": "298608.3817237098"
},
{
"input": "6\n109 683 214 392 678 10",
"output": "397266.9574170437"
},
{
"input": "2\n151 400",
"output": "431023.3704798660"
},
{
"input": "6\n258 877 696 425 663 934",
"output": "823521.3902487604"
},
{
"input": "9\n635 707 108 234 52 180 910 203 782",
"output": "1100144.9065826489"
},
{
"input": "8\n885 879 891 428 522 176 135 983",
"output": "895488.9947571954"
},
{
"input": "3\n269 918 721",
"output": "1241695.6467754442"
},
{
"input": "7\n920 570 681 428 866 935 795",
"output": "1469640.1849419588"
},
{
"input": "2\n517 331",
"output": "495517.1260654109"
},
{
"input": "2\n457 898",
"output": "1877274.3981158488"
},
{
"input": "8\n872 704 973 612 183 274 739 253",
"output": "1780774.0965755312"
},
{
"input": "74\n652 446 173 457 760 847 670 25 196 775 998 279 656 809 883 148 969 884 792 502 641 800 663 938 362 339 545 608 107 184 834 666 149 458 864 72 199 658 618 987 126 723 806 643 689 958 626 904 944 415 427 498 628 331 636 261 281 276 478 220 513 595 510 384 354 561 469 462 799 449 747 109 903 456",
"output": "1510006.5089479341"
},
{
"input": "76\n986 504 673 158 87 332 124 218 714 235 212 122 878 370 938 81 686 323 386 348 410 468 875 107 50 960 82 834 234 663 651 422 794 633 294 771 945 607 146 913 950 858 297 88 882 725 247 872 645 749 799 987 115 394 380 382 971 429 593 426 652 353 351 233 868 598 889 116 71 376 916 464 414 976 138 903",
"output": "1528494.7817143100"
},
{
"input": "70\n12 347 748 962 514 686 192 159 990 4 10 788 602 542 946 215 523 727 799 717 955 796 529 465 897 103 181 515 495 153 710 179 747 145 16 585 943 998 923 708 156 399 770 547 775 285 9 68 713 722 570 143 913 416 663 624 925 218 64 237 797 138 942 213 188 818 780 840 480 758",
"output": "1741821.4892636713"
},
{
"input": "26\n656 508 45 189 561 366 96 486 547 386 703 570 780 689 264 26 11 74 466 76 421 48 982 886 215 650",
"output": "1818821.9252031571"
},
{
"input": "52\n270 658 808 249 293 707 700 78 791 167 92 772 807 502 830 991 945 102 968 376 556 578 326 980 688 368 280 853 646 256 666 638 424 737 321 996 925 405 199 680 953 541 716 481 727 143 577 919 892 355 346 298",
"output": "1272941.9273080483"
},
{
"input": "77\n482 532 200 748 692 697 171 863 586 547 301 149 326 812 147 698 303 691 527 805 681 387 619 947 598 453 167 799 840 508 893 688 643 974 998 341 804 230 538 669 271 404 477 759 943 596 949 235 880 160 151 660 832 82 969 539 708 889 258 81 224 655 790 144 462 582 646 256 445 52 456 920 67 819 631 484 534",
"output": "2045673.1891262225"
},
{
"input": "27\n167 464 924 575 775 97 944 390 297 315 668 296 533 829 851 406 702 366 848 512 71 197 321 900 544 529 116",
"output": "1573959.9105970615"
},
{
"input": "38\n488 830 887 566 720 267 583 102 65 200 884 220 263 858 510 481 316 804 754 568 412 166 374 869 356 977 145 421 500 58 664 252 745 70 381 927 670 772",
"output": "1479184.3434235646"
},
{
"input": "64\n591 387 732 260 840 397 563 136 571 876 831 953 799 493 579 13 559 872 53 678 256 232 969 993 847 14 837 365 547 997 604 199 834 529 306 443 739 49 19 276 343 835 904 588 900 870 439 576 975 955 518 117 131 347 800 83 432 882 869 709 32 950 314 450",
"output": "1258248.6984672088"
},
{
"input": "37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637",
"output": "1495219.0323274869"
},
{
"input": "97\n768 569 306 968 437 779 227 561 412 60 44 807 234 645 169 858 580 396 343 145 842 723 416 80 456 247 81 150 297 116 760 964 312 558 101 850 549 650 299 868 121 435 579 705 118 424 302 812 970 397 659 565 916 183 933 459 6 593 518 717 326 305 744 470 75 981 824 221 294 324 194 293 251 446 481 215 338 861 528 829 921 945 540 89 450 178 24 460 990 392 148 219 934 615 932 340 937",
"output": "1577239.7333274092"
},
{
"input": "94\n145 703 874 425 277 652 239 496 458 658 339 842 564 699 893 352 625 980 432 121 798 872 499 859 850 721 414 825 543 843 304 111 342 45 219 311 50 748 465 902 781 822 504 985 919 656 280 310 917 438 464 527 491 713 906 329 635 777 223 810 501 535 156 252 806 112 971 719 103 443 165 98 579 554 244 996 221 560 301 51 977 422 314 858 528 772 448 626 185 194 536 66 577 677",
"output": "1624269.3753516484"
},
{
"input": "97\n976 166 649 81 611 927 480 231 998 711 874 91 969 521 531 414 993 790 317 981 9 261 437 332 173 573 904 777 882 990 658 878 965 64 870 896 271 732 431 53 761 943 418 602 708 949 930 130 512 240 363 458 673 319 131 784 224 48 919 126 208 212 911 59 677 535 450 273 479 423 79 807 336 18 72 290 724 28 123 605 287 228 350 897 250 392 885 655 746 417 643 114 813 378 355 635 905",
"output": "1615601.7212203942"
},
{
"input": "91\n493 996 842 9 748 178 1 807 841 519 796 998 84 670 778 143 707 208 165 893 154 943 336 150 761 881 434 112 833 55 412 682 552 945 758 189 209 600 354 325 440 844 410 20 136 665 88 791 688 17 539 821 133 236 94 606 483 446 429 60 960 476 915 134 137 852 754 908 276 482 117 252 297 903 981 203 829 811 471 135 188 667 710 393 370 302 874 872 551 457 692",
"output": "1806742.5014501044"
},
{
"input": "95\n936 736 17 967 229 607 589 291 242 244 29 698 800 566 630 667 90 416 11 94 812 838 668 520 678 111 490 823 199 973 681 676 683 721 262 896 682 713 402 691 874 44 95 704 56 322 822 887 639 433 406 35 988 61 176 496 501 947 440 384 372 959 577 370 754 802 1 945 427 116 746 408 308 391 397 730 493 183 203 871 831 862 461 565 310 344 504 378 785 137 279 123 475 138 415",
"output": "1611115.5269110680"
},
{
"input": "90\n643 197 42 218 582 27 66 704 195 445 641 675 285 639 503 686 242 327 57 955 848 287 819 992 756 749 363 48 648 736 580 117 752 921 923 372 114 313 202 337 64 497 399 25 883 331 24 871 917 8 517 486 323 529 325 92 891 406 864 402 263 773 931 253 625 31 17 271 140 131 232 586 893 525 846 54 294 562 600 801 214 55 768 683 389 738 314 284 328 804",
"output": "1569819.2914796301"
},
{
"input": "98\n29 211 984 75 333 96 840 21 352 168 332 433 130 944 215 210 620 442 363 877 91 491 513 955 53 82 351 19 998 706 702 738 770 453 344 117 893 590 723 662 757 16 87 546 312 669 568 931 224 374 927 225 751 962 651 587 361 250 256 240 282 600 95 64 384 589 813 783 39 918 412 648 506 283 886 926 443 173 946 241 310 33 622 565 261 360 547 339 943 367 354 25 479 743 385 485 896 741",
"output": "2042921.1539616778"
},
{
"input": "93\n957 395 826 67 185 4 455 880 683 654 463 84 258 878 553 592 124 585 9 133 20 609 43 452 725 125 801 537 700 685 771 155 566 376 19 690 383 352 174 208 177 416 304 1000 533 481 87 509 358 233 681 22 507 659 36 859 952 259 138 271 594 779 576 782 119 69 608 758 283 616 640 523 710 751 34 106 774 92 874 568 864 660 998 992 474 679 180 409 15 297 990 689 501",
"output": "1310703.8710041976"
},
{
"input": "97\n70 611 20 30 904 636 583 262 255 501 604 660 212 128 199 138 545 576 506 528 12 410 77 888 783 972 431 188 338 485 148 793 907 678 281 922 976 680 252 724 253 920 177 361 721 798 960 572 99 622 712 466 608 49 612 345 266 751 63 594 40 695 532 789 520 930 825 929 48 59 405 135 109 735 508 186 495 772 375 587 201 324 447 610 230 947 855 318 856 956 313 810 931 175 668 183 688",
"output": "1686117.9099228707"
},
{
"input": "96\n292 235 391 180 840 172 218 997 166 287 329 20 886 325 400 471 182 356 448 337 417 319 58 106 366 764 393 614 90 831 924 314 667 532 64 874 3 434 350 352 733 795 78 640 967 63 47 879 635 272 145 569 468 792 153 761 770 878 281 467 209 208 298 37 700 18 334 93 5 750 412 779 523 517 360 649 447 328 311 653 57 578 767 460 647 663 50 670 151 13 511 580 625 907 227 89",
"output": "1419726.5608617242"
},
{
"input": "100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 639 638 260 419 8 142 403 298 204 169 887 388 241 983 885 267 643 943 417 237 452 562 6 839 149 742 832 896 100 831 712 754 679 743 135 222 445 680 210 955 220 63 960 487 514 824 481 584 441 997 795 290 10 45 510 678 844 503 407 945 850 84 858 934 500 320 936 663 736 592 161 670 606 465 864 969 293 863 868 393 899 744",
"output": "1556458.0979239127"
},
{
"input": "100\n321 200 758 415 190 710 920 992 873 898 814 259 359 66 971 210 838 545 663 652 684 277 36 756 963 459 335 484 462 982 532 423 131 703 307 229 391 938 253 847 542 975 635 928 220 980 222 567 557 181 366 824 900 180 107 979 112 564 525 413 300 422 876 615 737 343 902 8 654 628 469 913 967 785 893 314 909 215 912 262 20 709 363 915 997 954 986 454 596 124 74 159 660 550 787 418 895 786 293 50",
"output": "1775109.8050211088"
},
{
"input": "100\n859 113 290 762 701 63 188 431 810 485 671 673 99 658 194 227 511 435 941 212 551 124 89 222 42 321 657 815 898 171 216 482 707 567 724 491 414 942 820 351 48 653 685 312 586 24 20 627 602 498 533 173 463 262 621 466 119 299 580 964 510 987 40 698 521 998 847 651 746 215 808 563 785 837 631 772 404 923 682 244 232 214 390 350 968 771 517 900 70 543 934 554 681 368 642 575 891 728 478 317",
"output": "1447969.4788174964"
},
{
"input": "100\n941 283 349 457 52 837 299 284 796 305 893 624 101 972 738 204 121 70 17 704 836 791 95 111 162 952 472 724 733 580 878 177 705 804 11 211 463 417 288 409 410 485 896 755 921 267 164 656 505 765 539 439 535 19 991 689 220 474 114 944 884 144 926 849 486 566 117 35 749 499 797 303 362 905 690 890 976 66 590 183 234 683 39 297 769 787 376 541 571 759 495 200 261 352 73 493 831 442 273 339",
"output": "1597889.4218394549"
},
{
"input": "100\n110 868 147 888 291 282 916 542 917 337 235 595 498 621 814 249 261 713 445 666 142 275 319 49 900 543 333 606 487 670 620 769 852 258 230 867 603 491 714 839 879 37 21 74 590 190 397 506 499 967 152 862 200 107 145 23 614 167 857 475 79 598 270 906 626 116 89 59 651 846 723 201 50 699 522 408 634 132 226 414 824 764 513 586 526 238 556 162 667 173 684 415 527 743 10 442 552 274 350 822",
"output": "1567230.6191330721"
},
{
"input": "100\n901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000",
"output": "298608.3817237098"
}
] | 1,683,785,948 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | # Description of the problem can be found at http://codeforces.com/problemset/problem/157/B
import math
n = int(input())
l_s = list(map(int, input().split()))
l_s.sort(reverse = True)
t = 0
for index in range(n):
t += (-1 if index % 2 == 1 else 1) * l_s[index] ** 2
print(t * math.pi) | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.
Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different.
Output Specification:
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
Demo Input:
['1\n1\n', '3\n1 4 2\n']
Demo Output:
['3.1415926536\n', '40.8407044967\n']
Note:
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π | ```python
# Description of the problem can be found at http://codeforces.com/problemset/problem/157/B
import math
n = int(input())
l_s = list(map(int, input().split()))
l_s.sort(reverse = True)
t = 0
for index in range(n):
t += (-1 if index % 2 == 1 else 1) * l_s[index] ** 2
print(t * math.pi)
``` | 3 |
|
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number. | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
},
{
"input": "102000",
"output": "NO"
},
{
"input": "210000000",
"output": "NO"
},
{
"input": "213443120",
"output": "YES"
},
{
"input": "99",
"output": "YES"
},
{
"input": "22002",
"output": "NO"
},
{
"input": "1010",
"output": "YES"
},
{
"input": "1201",
"output": "NO"
},
{
"input": "6460046",
"output": "NO"
},
{
"input": "503435",
"output": "NO"
},
{
"input": "21002",
"output": "NO"
},
{
"input": "101001",
"output": "NO"
},
{
"input": "200102",
"output": "NO"
},
{
"input": "20010002",
"output": "NO"
},
{
"input": "33003",
"output": "NO"
},
{
"input": "100101",
"output": "NO"
},
{
"input": "1021",
"output": "NO"
},
{
"input": "1101",
"output": "NO"
},
{
"input": "10101100",
"output": "NO"
},
{
"input": "101",
"output": "YES"
},
{
"input": "1011",
"output": "NO"
},
{
"input": "11010",
"output": "NO"
},
{
"input": "10110",
"output": "NO"
},
{
"input": "110000",
"output": "YES"
},
{
"input": "2011",
"output": "NO"
},
{
"input": "10020001",
"output": "NO"
},
{
"input": "12505021",
"output": "NO"
},
{
"input": "12310",
"output": "NO"
},
{
"input": "100501",
"output": "NO"
},
{
"input": "11001",
"output": "NO"
},
{
"input": "20020002",
"output": "NO"
},
{
"input": "202002",
"output": "NO"
},
{
"input": "1001",
"output": "YES"
},
{
"input": "1020021",
"output": "NO"
},
{
"input": "60660",
"output": "NO"
},
{
"input": "98809",
"output": "NO"
},
{
"input": "11000000",
"output": "YES"
},
{
"input": "807008",
"output": "NO"
}
] | 1,691,031,915 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 0 | x=list(input())
x.reverse()
g=False
while len(x)>1:
if x[0]=='0' and g==False:
x.pop(0)
else:
g=True
if x[0]!=x[-1]:
print('NO')
exit()
else:
x.pop(0)
x.pop()
print("YES") | Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number.
Input Specification:
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Output Specification:
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
Demo Input:
['131\n', '320\n', '2010200\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
x=list(input())
x.reverse()
g=False
while len(x)>1:
if x[0]=='0' and g==False:
x.pop(0)
else:
g=True
if x[0]!=x[-1]:
print('NO')
exit()
else:
x.pop(0)
x.pop()
print("YES")
``` | 3 |
|
137 | C | History | PROGRAMMING | 1,500 | [
"sortings"
] | null | null | Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=<<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=<<=*a**i* and *b**i*<=<<=*b**j*. Your task is simpler: find the number of events that are included in some other event. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order. | Print the only integer — the answer to the problem. | [
"5\n1 10\n2 9\n3 8\n4 7\n5 6\n",
"5\n1 100\n2 50\n51 99\n52 98\n10 60\n",
"1\n1 1000000000\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | 1,500 | [
{
"input": "5\n1 10\n2 9\n3 8\n4 7\n5 6",
"output": "4"
},
{
"input": "5\n1 100\n2 50\n51 99\n52 98\n10 60",
"output": "4"
},
{
"input": "1\n1 1000000000",
"output": "0"
},
{
"input": "2\n100 1000\n500 1500",
"output": "0"
},
{
"input": "4\n1 100\n50 150\n120 200\n180 220",
"output": "0"
},
{
"input": "10\n1 20\n2 19\n3 18\n4 17\n5 16\n6 15\n7 14\n8 13\n9 12\n10 11",
"output": "9"
},
{
"input": "4\n1 5\n2 4\n10 15\n11 14",
"output": "2"
},
{
"input": "10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20",
"output": "0"
},
{
"input": "10\n58 22116\n112840 772160\n127432 399484\n182031 255417\n459340 548097\n603984 739189\n606173 663033\n280170 366159\n779239 906234\n874623 892907",
"output": "7"
},
{
"input": "2\n2 3\n1 4",
"output": "1"
},
{
"input": "3\n9 10\n1 2\n3 4",
"output": "0"
},
{
"input": "4\n1 2\n3 6\n4 5\n10 11",
"output": "1"
},
{
"input": "2\n5 6\n1 10",
"output": "1"
},
{
"input": "7\n1 10\n2 5\n3 9\n100 1000\n200 500\n1001 1002\n777 7777",
"output": "4"
}
] | 1,603,274,167 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 3,891,200 | n = int(input())
arr=[]
for _ in range(n):
x,y = map(int,input().split())
arr.append((x,y))
c=0
arr.sort(key=lambda arr:arr[0])
visited = []
for i in range(n):
low = arr[i][0]
high = arr[i][1]
for j in range(i+1,n):
if j not in visited:
if arr[j][1]<=high and arr[j][0]>=low:
c+=1
visited.append(j)
print (c)
| Title: History
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=<<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=<<=*a**i* and *b**i*<=<<=*b**j*. Your task is simpler: find the number of events that are included in some other event.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order.
Output Specification:
Print the only integer — the answer to the problem.
Demo Input:
['5\n1 10\n2 9\n3 8\n4 7\n5 6\n', '5\n1 100\n2 50\n51 99\n52 98\n10 60\n', '1\n1 1000000000\n']
Demo Output:
['4\n', '4\n', '0\n']
Note:
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | ```python
n = int(input())
arr=[]
for _ in range(n):
x,y = map(int,input().split())
arr.append((x,y))
c=0
arr.sort(key=lambda arr:arr[0])
visited = []
for i in range(n):
low = arr[i][0]
high = arr[i][1]
for j in range(i+1,n):
if j not in visited:
if arr[j][1]<=high and arr[j][0]>=low:
c+=1
visited.append(j)
print (c)
``` | 0 |
|
175 | A | Robot Bicorn Attack | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Vasya plays Robot Bicorn Attack.
The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string *s*. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string *s*.
Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round. | The only line of input contains non-empty string *s* obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters. | Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1. | [
"1234\n",
"9000\n",
"0009\n"
] | [
"37\n",
"90\n",
"-1\n"
] | In the first example the string must be split into numbers 1, 2 and 34.
In the second example the string must be split into numbers 90, 0 and 0.
In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes. | 500 | [
{
"input": "1234",
"output": "37"
},
{
"input": "9000",
"output": "90"
},
{
"input": "0009",
"output": "-1"
},
{
"input": "100000010000001000000",
"output": "3000000"
},
{
"input": "1000000011",
"output": "1000011"
},
{
"input": "9991",
"output": "109"
},
{
"input": "1000001999",
"output": "101000"
},
{
"input": "100000010000011000000",
"output": "-1"
},
{
"input": "100000010000001000001",
"output": "-1"
},
{
"input": "102",
"output": "3"
},
{
"input": "100",
"output": "1"
},
{
"input": "000",
"output": "0"
},
{
"input": "001",
"output": "1"
},
{
"input": "090",
"output": "9"
},
{
"input": "999999999999999999999999999999",
"output": "-1"
},
{
"input": "12345678901234567",
"output": "947035"
},
{
"input": "12635000000127683",
"output": "-1"
},
{
"input": "428595000000042345353",
"output": "-1"
},
{
"input": "48726340000000",
"output": "-1"
},
{
"input": "93246310000000",
"output": "1932463"
},
{
"input": "00123456",
"output": "123456"
},
{
"input": "001234567",
"output": "-1"
},
{
"input": "0891249843934",
"output": "1735183"
},
{
"input": "04234581000000",
"output": "1423458"
},
{
"input": "10000000999999",
"output": "1999999"
},
{
"input": "69284626624",
"output": "935092"
},
{
"input": "6061357",
"output": "61363"
},
{
"input": "1215",
"output": "27"
},
{
"input": "5305167573651040691",
"output": "-1"
},
{
"input": "948245431759126577",
"output": "1506581"
},
{
"input": "3699951264723380749",
"output": "-1"
},
{
"input": "97862382",
"output": "978633"
},
{
"input": "4073734152",
"output": "737433"
},
{
"input": "9123396793",
"output": "913138"
},
{
"input": "52027725398636318",
"output": "1413743"
},
{
"input": "03990796938958",
"output": "-1"
},
{
"input": "460657644093588",
"output": "1105338"
},
{
"input": "8793853284967905230",
"output": "-1"
},
{
"input": "298036933890712",
"output": "1232638"
},
{
"input": "80796461750373352",
"output": "1498819"
},
{
"input": "2376843019069559343",
"output": "-1"
},
{
"input": "7464340065209674219",
"output": "-1"
},
{
"input": "1551627800131899383",
"output": "-1"
},
{
"input": "20973541540356666047",
"output": "-1"
},
{
"input": "31587335978612",
"output": "1565978"
},
{
"input": "744503034",
"output": "744537"
},
{
"input": "15533274860535679",
"output": "939616"
},
{
"input": "58308242321837",
"output": "1006337"
},
{
"input": "9929120076123816",
"output": "323868"
},
{
"input": "623650711335",
"output": "773700"
},
{
"input": "1066168753173",
"output": "981936"
},
{
"input": "5353645507305053",
"output": "1091147"
},
{
"input": "111111111111111111111111111111",
"output": "-1"
},
{
"input": "1000000999888777666",
"output": "2777554"
},
{
"input": "1000001999888777666",
"output": "-1"
},
{
"input": "9998881000001777666",
"output": "-1"
},
{
"input": "9999991000000999999",
"output": "2999998"
},
{
"input": "9999999999991000000",
"output": "2999998"
},
{
"input": "1000000999999999999",
"output": "2999998"
},
{
"input": "123",
"output": "6"
},
{
"input": "132",
"output": "6"
},
{
"input": "213",
"output": "6"
},
{
"input": "231",
"output": "6"
},
{
"input": "312",
"output": "6"
},
{
"input": "321",
"output": "6"
},
{
"input": "666",
"output": "18"
},
{
"input": "012894600",
"output": "894612"
},
{
"input": "01289400",
"output": "289401"
},
{
"input": "429496729742949672974294967297",
"output": "-1"
},
{
"input": "429496729700",
"output": "959414"
},
{
"input": "429496729701",
"output": "959415"
},
{
"input": "1",
"output": "-1"
},
{
"input": "55",
"output": "-1"
},
{
"input": "99",
"output": "-1"
},
{
"input": "9991999999999999",
"output": "2009989"
},
{
"input": "999199999999099",
"output": "1999297"
},
{
"input": "9991990199999999",
"output": "2000189"
},
{
"input": "99999900999999",
"output": "1999998"
},
{
"input": "4444440044444",
"output": "488888"
},
{
"input": "0089",
"output": "89"
},
{
"input": "00243",
"output": "243"
},
{
"input": "008743",
"output": "8743"
},
{
"input": "0042764",
"output": "42764"
},
{
"input": "00912838",
"output": "912838"
},
{
"input": "001000000",
"output": "1000000"
},
{
"input": "001000001",
"output": "-1"
},
{
"input": "12435900",
"output": "435903"
},
{
"input": "28492300",
"output": "849232"
},
{
"input": "99999900",
"output": "999999"
},
{
"input": "931863000",
"output": "863094"
},
{
"input": "23566000",
"output": "566005"
},
{
"input": "100000000",
"output": "1000000"
},
{
"input": "100000100",
"output": "100010"
},
{
"input": "3246870032",
"output": "870362"
},
{
"input": "04354640947",
"output": "645301"
},
{
"input": "0734620342343",
"output": "1076963"
},
{
"input": "09999990",
"output": "999999"
},
{
"input": "010000000",
"output": "1000000"
},
{
"input": "010000001",
"output": "1000001"
},
{
"input": "01000001000000",
"output": "1100000"
},
{
"input": "1844674407370955161600",
"output": "-1"
},
{
"input": "184467440737105516141111",
"output": "-1"
},
{
"input": "1844674407371055161600",
"output": "-1"
},
{
"input": "1111111111111111111111111",
"output": "-1"
},
{
"input": "999999999999999999999",
"output": "-1"
},
{
"input": "100000110000011000001",
"output": "-1"
},
{
"input": "0018446744073709551616",
"output": "-1"
},
{
"input": "429596729610000001000",
"output": "-1"
},
{
"input": "123456789123456789123456789123",
"output": "-1"
},
{
"input": "011",
"output": "2"
},
{
"input": "10000100001000",
"output": "21000"
},
{
"input": "091",
"output": "10"
},
{
"input": "1234567891012131416123222443",
"output": "-1"
},
{
"input": "429496729642949672964294967296",
"output": "-1"
},
{
"input": "214748364821474836482147483648",
"output": "-1"
},
{
"input": "10000001073741824001000000",
"output": "-1"
},
{
"input": "5000000000",
"output": "-1"
},
{
"input": "999955555555555555555555",
"output": "-1"
},
{
"input": "1844674407371055161699",
"output": "-1"
},
{
"input": "99999999999999999999999999999",
"output": "-1"
},
{
"input": "009",
"output": "9"
},
{
"input": "1844674407370955161611",
"output": "-1"
},
{
"input": "000000999",
"output": "-1"
},
{
"input": "003",
"output": "3"
},
{
"input": "0000000009000000000",
"output": "-1"
},
{
"input": "010",
"output": "1"
},
{
"input": "0",
"output": "-1"
},
{
"input": "000009000000",
"output": "-1"
},
{
"input": "21371283283242384239423423123",
"output": "-1"
},
{
"input": "100000010004294967300",
"output": "-1"
},
{
"input": "429596729600",
"output": "969314"
},
{
"input": "429496729510000001000000",
"output": "-1"
},
{
"input": "2147483648010000010000",
"output": "-1"
},
{
"input": "349967407479541078587181768161",
"output": "-1"
}
] | 1,498,728,138 | 1,338 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 5,529,600 | a=input()
s=len(a)
ans=-1
for i in range(s-2):
for j in range(i+1,s-1):
if (i+1>0+1 and a[0]=="0") or (j+1>i+2 and a[i+1]=="0") or (s>j+2 and a[j+1]=="0"):
continue
ans=max(ans,int(a[0:i+1])+int(a[i+1:j+1])+int(a[j+1:s]))
print(ans) | Title: Robot Bicorn Attack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya plays Robot Bicorn Attack.
The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string *s*. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string *s*.
Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.
Input Specification:
The only line of input contains non-empty string *s* obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.
Output Specification:
Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.
Demo Input:
['1234\n', '9000\n', '0009\n']
Demo Output:
['37\n', '90\n', '-1\n']
Note:
In the first example the string must be split into numbers 1, 2 and 34.
In the second example the string must be split into numbers 90, 0 and 0.
In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes. | ```python
a=input()
s=len(a)
ans=-1
for i in range(s-2):
for j in range(i+1,s-1):
if (i+1>0+1 and a[0]=="0") or (j+1>i+2 and a[i+1]=="0") or (s>j+2 and a[j+1]=="0"):
continue
ans=max(ans,int(a[0:i+1])+int(a[i+1:j+1])+int(a[j+1:s]))
print(ans)
``` | 0 |
|
598 | D | Igor In the Museum | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture.
At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one.
For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see. | First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum.
Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells. | Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. | [
"5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n",
"4 4 1\n****\n*..*\n*.**\n****\n3 2\n"
] | [
"6\n4\n10\n",
"8\n"
] | none | 0 | [
{
"input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3",
"output": "6\n4\n10"
},
{
"input": "4 4 1\n****\n*..*\n*.**\n****\n3 2",
"output": "8"
},
{
"input": "3 3 1\n***\n*.*\n***\n2 2",
"output": "4"
},
{
"input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\n2 4\n4 2\n2 2\n2 3\n2 2\n2 2\n2 4\n3 2\n2 2\n2 2",
"output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12"
},
{
"input": "10 3 10\n***\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n2 2\n2 2\n2 2\n2 2\n8 2\n2 2\n2 2\n7 2\n8 2\n6 2",
"output": "6\n6\n6\n6\n10\n6\n6\n10\n10\n10"
},
{
"input": "3 10 10\n**********\n***.*.*..*\n**********\n2 6\n2 6\n2 9\n2 9\n2 4\n2 9\n2 6\n2 6\n2 4\n2 6",
"output": "4\n4\n6\n6\n4\n6\n4\n4\n4\n4"
},
{
"input": "10 10 50\n**********\n*......***\n***..**..*\n***....***\n**..***..*\n**..**.*.*\n*****..***\n*.***..***\n*..****.**\n**********\n5 9\n5 9\n7 7\n6 4\n6 7\n8 7\n6 7\n9 2\n3 9\n9 2\n4 7\n4 6\n2 7\n9 2\n7 7\n5 8\n8 7\n8 6\n7 7\n5 9\n8 7\n3 8\n3 8\n5 9\n9 8\n9 3\n8 7\n5 9\n9 2\n9 8\n9 3\n3 8\n9 2\n8 6\n2 4\n6 9\n6 3\n9 8\n3 9\n9 8\n4 5\n8 6\n3 8\n5 9\n8 7\n5 8\n6 9\n8 2\n3 9\n3 9",
"output": "8\n8\n10\n28\n10\n10\n10\n8\n6\n8\n28\n28\n28\n8\n10\n8\n10\n10\n10\n8\n10\n6\n6\n8\n4\n8\n10\n8\n8\n4\n8\n6\n8\n10\n28\n8\n28\n4\n6\n4\n28\n10\n6\n8\n10\n8\n8\n8\n6\n6"
},
{
"input": "5 5 21\n*****\n*.***\n*****\n*****\n*****\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2",
"output": "4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4"
}
] | 1,682,988,850 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 27,852,800 | def dfs(x, y, n, m, museum, visited):
if x < 0 or x >= n or y < 0 or y >= m or visited[x][y] or museum[x][y] == '*':
return 0
visited[x][y] = True
pictures = 0
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
if 0 <= x + dx < n and 0 <= y + dy < m and museum[x + dx][y + dy] == '*':
pictures += 1
else:
pictures += dfs(x + dx, y + dy, n, m, museum, visited)
return pictures
def igor_in_the_museum(n, m, k, museum, starting_positions):
results = []
for x, y in starting_positions:
visited = [[False] * m for _ in range(n)]
result = dfs(x - 1, y - 1, n, m, museum, visited)
results.append(result)
return results
# Reading input
n, m, k = map(int, input().split())
museum = [input() for _ in range(n)]
starting_positions = [tuple(map(int, input().split())) for _ in range(k)]
# Solving problem
result = igor_in_the_museum(n, m, k, museum, starting_positions)
# Printing output
for num_pictures in result:
print(num_pictures)
| Title: Igor In the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture.
At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one.
For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.
Input Specification:
First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum.
Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.
Output Specification:
Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
Demo Input:
['5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n', '4 4 1\n****\n*..*\n*.**\n****\n3 2\n']
Demo Output:
['6\n4\n10\n', '8\n']
Note:
none | ```python
def dfs(x, y, n, m, museum, visited):
if x < 0 or x >= n or y < 0 or y >= m or visited[x][y] or museum[x][y] == '*':
return 0
visited[x][y] = True
pictures = 0
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
if 0 <= x + dx < n and 0 <= y + dy < m and museum[x + dx][y + dy] == '*':
pictures += 1
else:
pictures += dfs(x + dx, y + dy, n, m, museum, visited)
return pictures
def igor_in_the_museum(n, m, k, museum, starting_positions):
results = []
for x, y in starting_positions:
visited = [[False] * m for _ in range(n)]
result = dfs(x - 1, y - 1, n, m, museum, visited)
results.append(result)
return results
# Reading input
n, m, k = map(int, input().split())
museum = [input() for _ in range(n)]
starting_positions = [tuple(map(int, input().split())) for _ in range(k)]
# Solving problem
result = igor_in_the_museum(n, m, k, museum, starting_positions)
# Printing output
for num_pictures in result:
print(num_pictures)
``` | 0 |
|
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a. | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw"
},
{
"input": "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "12\nmmmmmmmmmmmm",
"output": "mmmmmmmmmmmm"
},
{
"input": "18\nyaywptqwuyiqypwoyw",
"output": "ywptqwuqypwow"
},
{
"input": "85\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "13\nmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmm"
},
{
"input": "10\nmmmmmmmmmm",
"output": "mmmmmmmmmm"
},
{
"input": "11\nmmmmmmmmmmm",
"output": "mmmmmmmmmmm"
},
{
"input": "15\nmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmm"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "14\nmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmm"
},
{
"input": "33\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
},
{
"input": "79\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "90\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "2\naa",
"output": "a"
},
{
"input": "18\niuiuqpyyaoaetiwliu",
"output": "iqpytiwli"
},
{
"input": "5\nxxxxx",
"output": "xxxxx"
},
{
"input": "6\nxxxahg",
"output": "xxxahg"
},
{
"input": "3\nzcv",
"output": "zcv"
},
{
"input": "4\naepo",
"output": "apo"
},
{
"input": "5\nqqqqq",
"output": "qqqqq"
},
{
"input": "6\naaaaaa",
"output": "a"
},
{
"input": "4\naeta",
"output": "ata"
},
{
"input": "20\nttyttlwaoieulyiluuri",
"output": "ttyttlwalyluri"
},
{
"input": "1\nb",
"output": "b"
},
{
"input": "3\nanc",
"output": "anc"
},
{
"input": "1\ne",
"output": "e"
},
{
"input": "3\naie",
"output": "a"
},
{
"input": "3\nvio",
"output": "vi"
},
{
"input": "2\nea",
"output": "e"
},
{
"input": "3\nuas",
"output": "us"
},
{
"input": "2\nba",
"output": "ba"
},
{
"input": "2\naq",
"output": "aq"
},
{
"input": "2\nya",
"output": "y"
},
{
"input": "2\nou",
"output": "o"
},
{
"input": "2\nbb",
"output": "bb"
},
{
"input": "7\nayylmao",
"output": "alma"
},
{
"input": "2\nab",
"output": "ab"
},
{
"input": "19\nyuouiyaoiiweqrryqqp",
"output": "yweqrryqqp"
},
{
"input": "25\niqypwqpriiioetiuqqqttouei",
"output": "iqypwqpritiqqqtto"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyz",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyz"
},
{
"input": "17\naccccccccccccccca",
"output": "accccccccccccccca"
},
{
"input": "5\nababa",
"output": "ababa"
},
{
"input": "10\naaaaaaaaaa",
"output": "a"
},
{
"input": "22\naaaaabbbbboyoyoyoyoyac",
"output": "abbbbboc"
},
{
"input": "7\nmahmoud",
"output": "mahmod"
}
] | 1,609,959,402 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 140 | 0 | vowels = ['a', 'e', 'i', 'o', 'u', 'y']
def word_correction(s):
result = []
result.append(s[0])
left = 0
right = 1
while right < len(s):
if not s[left] in vowels or not s[right] in vowels:
result.append(s[right])
left = right
right += 1
return ''.join(result)
n = int(input())
s = input()
print(word_correction(s)) | Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word *s*. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output Specification:
Output the word *s* after the correction.
Demo Input:
['5\nweird\n', '4\nword\n', '5\naaeaa\n']
Demo Output:
['werd\n', 'word\n', 'a\n']
Note:
Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a. | ```python
vowels = ['a', 'e', 'i', 'o', 'u', 'y']
def word_correction(s):
result = []
result.append(s[0])
left = 0
right = 1
while right < len(s):
if not s[left] in vowels or not s[right] in vowels:
result.append(s[right])
left = right
right += 1
return ''.join(result)
n = int(input())
s = input()
print(word_correction(s))
``` | 3 |
|
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency).
The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer?
The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets.
The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total. | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane. | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7",
"output": "37 37"
},
{
"input": "40 10\n1 2 3 4 5 6 7 10 10 10",
"output": "223 158"
},
{
"input": "1 1\n6",
"output": "6 6"
},
{
"input": "1 2\n10 9",
"output": "10 9"
},
{
"input": "2 1\n7",
"output": "13 13"
},
{
"input": "2 2\n7 2",
"output": "13 3"
},
{
"input": "3 2\n4 7",
"output": "18 9"
},
{
"input": "3 3\n2 1 1",
"output": "4 4"
},
{
"input": "3 3\n2 1 1",
"output": "4 4"
},
{
"input": "10 10\n3 1 2 2 1 1 2 1 2 3",
"output": "20 13"
},
{
"input": "10 2\n7 3",
"output": "34 34"
},
{
"input": "10 1\n19",
"output": "145 145"
},
{
"input": "100 3\n29 36 35",
"output": "1731 1731"
},
{
"input": "100 5\n3 38 36 35 2",
"output": "2019 1941"
},
{
"input": "510 132\n50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45 16 57 62 55 20 88 74 40 45 84 41 1 9 53 65 25 67 31 115 2 63 51 123 70 65 65 18 14 75 14 103 26 117 105 36 104 81 37 35 61 44 90 71 70 88 89 26 21 64 77 89 16 87 99 13 79 27 3 46 120 116 11 14 17 32 70 113 94 108 57 29 100 53 48 44 29 70 30 32 62",
"output": "50279 5479"
},
{
"input": "510 123\n5 2 3 2 5 7 2 3 1 3 6 6 3 1 5 3 5 6 2 2 1 5 5 5 2 2 3 1 6 3 5 8 4 6 1 5 4 5 1 6 5 5 3 6 4 1 6 1 3 5 2 7 5 2 4 4 5 6 5 5 4 3 4 6 5 4 4 3 5 8 5 5 6 3 1 7 4 4 3 3 5 3 6 3 3 6 2 5 3 2 4 5 4 5 2 2 4 4 4 7 3 4 6 5 3 6 4 7 1 6 5 7 6 5 7 3 7 4 4 1 6 6 4",
"output": "1501 1501"
},
{
"input": "610 33\n15 44 8 8 17 11 39 39 38 25 17 36 17 25 21 37 10 11 34 30 29 50 29 50 4 20 32 13 41 14 2 11 2",
"output": "12204 8871"
}
] | 1,596,369,657 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 278 | 6,963,200 | n, m = map(int,input().split())
l = list(map(int,input().split()))
def g(f):
A = l[:]; s = 0
for _ in range(n):
i = A.index(f(A)); s += A[i]
if A[i] > 1: A[i] -= 1;
else:
A.pop(i)
return s
print (g(max), g(min)) | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency).
The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer?
The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets.
The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total.
Output Specification:
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
Demo Input:
['4 3\n2 1 1\n', '4 3\n2 2 2\n']
Demo Output:
['5 5\n', '7 6\n']
Note:
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane. | ```python
n, m = map(int,input().split())
l = list(map(int,input().split()))
def g(f):
A = l[:]; s = 0
for _ in range(n):
i = A.index(f(A)); s += A[i]
if A[i] > 1: A[i] -= 1;
else:
A.pop(i)
return s
print (g(max), g(min))
``` | 3 |
|
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
"input": "0 0 0 0\n4132",
"output": "0"
},
{
"input": "3163 5778 83 7640\n11141442444",
"output": "64270"
},
{
"input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442",
"output": "420780"
},
{
"input": "0 0 0 0\n1",
"output": "0"
},
{
"input": "1 2 3 4\n4",
"output": "4"
},
{
"input": "2343 7653 1242 5432\n1",
"output": "2343"
},
{
"input": "2343 7653 1242 5432\n2",
"output": "7653"
},
{
"input": "2343 7653 1242 5432\n3",
"output": "1242"
},
{
"input": "2343 7653 1242 5432\n4",
"output": "5432"
},
{
"input": "1 2 3 4\n123412",
"output": "13"
},
{
"input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111",
"output": "2650"
},
{
"input": "1 2 3 4\n11111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "1 2 3 4\n23123231321231231231231231221232123121312321",
"output": "87"
},
{
"input": "1 2 3 4\n1111111111111222222222233333333333444444444444444",
"output": "126"
},
{
"input": "2 3 1 4\n121321232412342112312313213123123412131231231232",
"output": "105"
}
] | 1,674,062,410 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 78 | 0 | n = list(map(int, input().strip().split()))
m = input()
s = 0
for i in range(len(m)):
s += n[int(m[i])-1]
print(s) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
Input Specification:
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Output Specification:
Print a single integer — the total number of calories that Jury wastes.
Demo Input:
['1 2 3 4\n123214\n', '1 5 3 2\n11221\n']
Demo Output:
['13\n', '13\n']
Note:
none | ```python
n = list(map(int, input().strip().split()))
m = input()
s = 0
for i in range(len(m)):
s += n[int(m[i])-1]
print(s)
``` | 3 |
|
719 | A | Vitya in the Countryside | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.
As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records.
It's guaranteed that the input data is consistent. | If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. | [
"5\n3 4 5 6 7\n",
"7\n12 13 14 15 14 13 12\n",
"1\n8\n"
] | [
"UP\n",
"DOWN\n",
"-1\n"
] | In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. | 500 | [
{
"input": "5\n3 4 5 6 7",
"output": "UP"
},
{
"input": "7\n12 13 14 15 14 13 12",
"output": "DOWN"
},
{
"input": "1\n8",
"output": "-1"
},
{
"input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10",
"output": "DOWN"
},
{
"input": "92\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4",
"output": "UP"
},
{
"input": "6\n10 11 12 13 14 15",
"output": "DOWN"
},
{
"input": "27\n11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "DOWN"
},
{
"input": "6\n8 7 6 5 4 3",
"output": "DOWN"
},
{
"input": "27\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10",
"output": "UP"
},
{
"input": "79\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5",
"output": "DOWN"
},
{
"input": "25\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7",
"output": "DOWN"
},
{
"input": "21\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7",
"output": "DOWN"
},
{
"input": "56\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6",
"output": "DOWN"
},
{
"input": "19\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14",
"output": "UP"
},
{
"input": "79\n5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13",
"output": "UP"
},
{
"input": "87\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10",
"output": "UP"
},
{
"input": "13\n10 9 8 7 6 5 4 3 2 1 0 1 2",
"output": "UP"
},
{
"input": "2\n8 9",
"output": "UP"
},
{
"input": "3\n10 11 12",
"output": "UP"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "1\n2",
"output": "-1"
},
{
"input": "1\n3",
"output": "-1"
},
{
"input": "1\n4",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n6",
"output": "-1"
},
{
"input": "1\n7",
"output": "-1"
},
{
"input": "1\n9",
"output": "-1"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "1\n11",
"output": "-1"
},
{
"input": "1\n12",
"output": "-1"
},
{
"input": "1\n13",
"output": "-1"
},
{
"input": "1\n14",
"output": "-1"
},
{
"input": "1\n15",
"output": "DOWN"
},
{
"input": "1\n0",
"output": "UP"
},
{
"input": "3\n11 12 13",
"output": "UP"
},
{
"input": "2\n10 9",
"output": "DOWN"
},
{
"input": "92\n10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11",
"output": "UP"
},
{
"input": "92\n7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6",
"output": "DOWN"
},
{
"input": "2\n14 15",
"output": "DOWN"
},
{
"input": "2\n1 0",
"output": "UP"
},
{
"input": "2\n15 14",
"output": "DOWN"
},
{
"input": "92\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8",
"output": "UP"
},
{
"input": "92\n13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12",
"output": "DOWN"
},
{
"input": "92\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3",
"output": "DOWN"
},
{
"input": "92\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "DOWN"
},
{
"input": "92\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "UP"
},
{
"input": "2\n2 1",
"output": "DOWN"
},
{
"input": "3\n2 1 0",
"output": "UP"
},
{
"input": "5\n4 3 2 1 0",
"output": "UP"
},
{
"input": "2\n5 4",
"output": "DOWN"
},
{
"input": "4\n3 2 1 0",
"output": "UP"
},
{
"input": "3\n13 12 11",
"output": "DOWN"
},
{
"input": "2\n1 2",
"output": "UP"
},
{
"input": "2\n0 1",
"output": "UP"
},
{
"input": "2\n13 14",
"output": "UP"
},
{
"input": "14\n13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "UP"
}
] | 1,477,465,385 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 62 | 0 | n=int(input())
l=list(map(int,input().split()))
if n==1 and l[0]!=15 and l[0]!=0 :
print(-1)
else :
if l[n-1]==15 :
print('DOWN')
if l[n-1]==0 :
print('UP')
if l[n-1]!=15 and l[n-1]!=0 and n!=1 :
if l[n-1]-l[n-2]>0 :
print('UP')
else :
print('DOWN')
| Title: Vitya in the Countryside
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.
As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records.
It's guaranteed that the input data is consistent.
Output Specification:
If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.
Demo Input:
['5\n3 4 5 6 7\n', '7\n12 13 14 15 14 13 12\n', '1\n8\n']
Demo Output:
['UP\n', 'DOWN\n', '-1\n']
Note:
In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. | ```python
n=int(input())
l=list(map(int,input().split()))
if n==1 and l[0]!=15 and l[0]!=0 :
print(-1)
else :
if l[n-1]==15 :
print('DOWN')
if l[n-1]==0 :
print('UP')
if l[n-1]!=15 and l[n-1]!=0 and n!=1 :
if l[n-1]-l[n-2]>0 :
print('UP')
else :
print('DOWN')
``` | 3 |
|
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,649,863,186 | 2,147,483,647 | Python 3 | OK | TESTS | 99 | 92 | 0 | N = int(input())
s = 0
def gcd(a, b):
while(b):
a, b = b, a%b
return a
for i in range(2, N):
n = N
while(n>0):
s += n%i
n = n//i
t = gcd(s, N-2)
print(str(s//t)+"/"+str((N-2)//t)) | 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
N = int(input())
s = 0
def gcd(a, b):
while(b):
a, b = b, a%b
return a
for i in range(2, N):
n = N
while(n>0):
s += n%i
n = n//i
t = gcd(s, N-2)
print(str(s//t)+"/"+str((N-2)//t))
``` | 3.954 |
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,497,366,805 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | n,m,k = map(int,input().split())
if k %2 == 0:
l = 'R'
if k % 2 != 0:
l = 'L'
if k % (2 * m) != 0:
p = k // (2 * m) + 1
if k % (2 * m) == 0:
p = k // (2 * m)
t = (k - (p - 1) * 6) // 2 + (k - (p - 1) * 6) % 2
print(str(p)+' '+str(t)+' '+l)
| 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())
if k %2 == 0:
l = 'R'
if k % 2 != 0:
l = 'L'
if k % (2 * m) != 0:
p = k // (2 * m) + 1
if k % (2 * m) == 0:
p = k // (2 * m)
t = (k - (p - 1) * 6) // 2 + (k - (p - 1) * 6) % 2
print(str(p)+' '+str(t)+' '+l)
``` | 0 |
|
245 | H | Queries for Number of Palindromes | PROGRAMMING | 1,800 | [
"dp",
"hashing",
"strings"
] | null | null | You've got a string *s*<==<=*s*1*s*2... *s*|*s*| of length |*s*|, consisting of lowercase English letters. There also are *q* queries, each query is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|). The answer to the query is the number of substrings of string *s*[*l**i*... *r**i*], which are palindromes.
String *s*[*l*... *r*]<==<=*s**l**s**l*<=+<=1... *s**r* (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) is a substring of string *s*<==<=*s*1*s*2... *s*|*s*|.
String *t* is called a palindrome, if it reads the same from left to right and from right to left. Formally, if *t*<==<=*t*1*t*2... *t*|*t*|<==<=*t*|*t*|*t*|*t*|<=-<=1... *t*1. | The first line contains string *s* (1<=≤<=|*s*|<=≤<=5000). The second line contains a single integer *q* (1<=≤<=*q*<=≤<=106) — the number of queries. Next *q* lines contain the queries. The *i*-th of these lines contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|) — the description of the *i*-th query.
It is guaranteed that the given string consists only of lowercase English letters. | Print *q* integers — the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces. | [
"caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5\n"
] | [
"1\n7\n3\n4\n2\n"
] | Consider the fourth query in the first test case. String *s*[4... 6] = «aba». Its palindrome substrings are: «a», «b», «a», «aba». | 0 | [
{
"input": "caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5",
"output": "1\n7\n3\n4\n2"
},
{
"input": "a\n100\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\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": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "ab\n100\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 2\n2 2\n1 1\n1 1\n2 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 2\n2 2\n2 2\n1 2\n2 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 2\n2 2\n1 1\n2 2\n1 1\n1 1\n1 2\n1 1\n2 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n2 2\n1 1\n2 2\n2 2\n2 2\n2 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 1\n1 2\n2 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n1 2\n1 1\n1 2\n2 2",
"output": "2\n2\n1\n1\n1\n1\n2\n2\n2\n2\n2\n1\n1\n1\n2\n1\n2\n2\n1\n1\n1\n1\n1\n2\n1\n2\n2\n1\n1\n2\n2\n1\n1\n2\n1\n1\n1\n1\n1\n2\n1\n2\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n1\n1\n2\n1\n1\n1\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n1\n2\n1\n2\n2\n2\n1\n1\n1\n1\n1\n1\n2\n2\n2\n2\n2\n1\n1\n1\n2\n1\n2\n1\n1\n2\n1\n1\n2\n1\n2\n1"
},
{
"input": "caa\n100\n2 3\n2 3\n1 3\n2 3\n2 2\n2 3\n1 1\n1 3\n1 3\n1 2\n3 3\n1 3\n1 3\n3 3\n1 2\n1 3\n1 3\n2 2\n2 2\n1 2\n1 3\n1 3\n1 3\n1 2\n3 3\n1 1\n2 3\n2 3\n1 2\n2 3\n1 3\n1 2\n1 3\n2 3\n3 3\n1 2\n2 3\n1 2\n1 3\n1 1\n2 2\n2 2\n2 3\n2 2\n2 3\n1 3\n1 1\n1 2\n1 3\n1 3\n2 3\n1 2\n1 3\n1 2\n1 3\n1 2\n1 1\n1 1\n1 2\n2 3\n1 1\n2 3\n3 3\n2 2\n1 2\n1 3\n1 2\n1 2\n1 2\n2 3\n1 2\n1 2\n1 3\n3 3\n1 2\n2 2\n1 2\n2 2\n1 1\n2 3\n1 2\n1 2\n1 2\n1 2\n2 2\n1 1\n1 2\n3 3\n2 3\n1 2\n1 2\n2 3\n1 2\n1 2\n1 3\n2 3\n1 3\n1 1\n2 2\n1 2",
"output": "3\n3\n4\n3\n1\n3\n1\n4\n4\n2\n1\n4\n4\n1\n2\n4\n4\n1\n1\n2\n4\n4\n4\n2\n1\n1\n3\n3\n2\n3\n4\n2\n4\n3\n1\n2\n3\n2\n4\n1\n1\n1\n3\n1\n3\n4\n1\n2\n4\n4\n3\n2\n4\n2\n4\n2\n1\n1\n2\n3\n1\n3\n1\n1\n2\n4\n2\n2\n2\n3\n2\n2\n4\n1\n2\n1\n2\n1\n1\n3\n2\n2\n2\n2\n1\n1\n2\n1\n3\n2\n2\n3\n2\n2\n4\n3\n4\n1\n1\n2"
},
{
"input": "ccca\n100\n2 4\n1 2\n1 1\n2 3\n3 4\n3 4\n2 2\n3 3\n1 2\n1 4\n2 2\n1 3\n1 4\n4 4\n1 2\n2 3\n3 4\n1 3\n3 4\n2 3\n1 1\n2 4\n1 4\n1 2\n2 2\n2 2\n1 1\n3 3\n1 2\n2 3\n2 3\n1 2\n1 4\n4 4\n2 2\n2 2\n4 4\n1 4\n1 1\n1 2\n4 4\n2 3\n2 4\n3 3\n1 4\n2 4\n2 3\n4 4\n4 4\n3 4\n2 2\n1 2\n1 1\n1 2\n3 3\n2 4\n1 3\n2 4\n1 1\n3 3\n3 4\n2 4\n1 4\n2 4\n1 2\n3 3\n1 4\n2 2\n2 4\n1 4\n1 4\n1 3\n3 4\n1 2\n2 3\n2 3\n3 4\n1 4\n4 4\n3 3\n2 4\n2 2\n1 2\n2 3\n1 2\n1 4\n1 3\n2 3\n4 4\n3 3\n1 2\n4 4\n2 4\n1 2\n2 4\n2 2\n3 4\n2 3\n2 3\n2 3",
"output": "4\n3\n1\n3\n2\n2\n1\n1\n3\n7\n1\n6\n7\n1\n3\n3\n2\n6\n2\n3\n1\n4\n7\n3\n1\n1\n1\n1\n3\n3\n3\n3\n7\n1\n1\n1\n1\n7\n1\n3\n1\n3\n4\n1\n7\n4\n3\n1\n1\n2\n1\n3\n1\n3\n1\n4\n6\n4\n1\n1\n2\n4\n7\n4\n3\n1\n7\n1\n4\n7\n7\n6\n2\n3\n3\n3\n2\n7\n1\n1\n4\n1\n3\n3\n3\n7\n6\n3\n1\n1\n3\n1\n4\n3\n4\n1\n2\n3\n3\n3"
}
] | 1,626,783,913 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 5,000 | 34,918,400 | def checkPalindrome(a):
if(a == a[::-1]):
return True
else: return False
def countPalindrome(a):
count = 0
for i in range(len(a)):
count-=1
for j in range(i,len(a)+1):
if(checkPalindrome(a[i:j])):
count = count + 1
# print(count,' ',a[i:j])
return count
string = input('')
n = int(input(''))
queries = []
for i in range(n):
que = input().split(' ')
queries.append(que)
for i in range(n):
print(countPalindrome(string[int(queries[i][0])-1:int(queries[i][1])]))
| Title: Queries for Number of Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a string *s*<==<=*s*1*s*2... *s*|*s*| of length |*s*|, consisting of lowercase English letters. There also are *q* queries, each query is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|). The answer to the query is the number of substrings of string *s*[*l**i*... *r**i*], which are palindromes.
String *s*[*l*... *r*]<==<=*s**l**s**l*<=+<=1... *s**r* (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) is a substring of string *s*<==<=*s*1*s*2... *s*|*s*|.
String *t* is called a palindrome, if it reads the same from left to right and from right to left. Formally, if *t*<==<=*t*1*t*2... *t*|*t*|<==<=*t*|*t*|*t*|*t*|<=-<=1... *t*1.
Input Specification:
The first line contains string *s* (1<=≤<=|*s*|<=≤<=5000). The second line contains a single integer *q* (1<=≤<=*q*<=≤<=106) — the number of queries. Next *q* lines contain the queries. The *i*-th of these lines contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|) — the description of the *i*-th query.
It is guaranteed that the given string consists only of lowercase English letters.
Output Specification:
Print *q* integers — the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.
Demo Input:
['caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5\n']
Demo Output:
['1\n7\n3\n4\n2\n']
Note:
Consider the fourth query in the first test case. String *s*[4... 6] = «aba». Its palindrome substrings are: «a», «b», «a», «aba». | ```python
def checkPalindrome(a):
if(a == a[::-1]):
return True
else: return False
def countPalindrome(a):
count = 0
for i in range(len(a)):
count-=1
for j in range(i,len(a)+1):
if(checkPalindrome(a[i:j])):
count = count + 1
# print(count,' ',a[i:j])
return count
string = input('')
n = int(input(''))
queries = []
for i in range(n):
que = input().split(' ')
queries.append(que)
for i in range(n):
print(countPalindrome(string[int(queries[i][0])-1:int(queries[i][1])]))
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,579,816,269 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 140 | 0 | w=input()
a="hello"
s=""
c=0
for i in w:
if i == a[c]:
c+=1
s+=i
if c==5:
break
if s==a:
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
w=input()
a="hello"
s=""
c=0
for i in w:
if i == a[c]:
c+=1
s+=i
if c==5:
break
if s==a:
print("YES")
else:
print("NO")
``` | 3.93 |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,691,254,833 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 62 | 0 |
l=int(input())
x=list(map(int,str(l)))
c=0
for i in x:
if i==x[i+2]:
c=c+1
else:
c=c
if c>=7:
print("YES")
else:
print("NO")
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
l=int(input())
x=list(map(int,str(l)))
c=0
for i in x:
if i==x[i+2]:
c=c+1
else:
c=c
if c>=7:
print("YES")
else:
print("NO")
``` | -1 |
169 | A | Chores | PROGRAMMING | 800 | [
"sortings"
] | null | null | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores? | The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces. | Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. | [
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] | [
"3\n",
"0\n"
] | In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | 500 | [
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"input": "3 1 2\n6 5 5",
"output": "1"
},
{
"input": "3 2 1\n10 10 8",
"output": "2"
},
{
"input": "8 3 5\n42 55 61 72 83 10 22 33",
"output": "6"
},
{
"input": "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995",
"output": "999999990"
},
{
"input": "4 1 3\n10 8 7 3",
"output": "2"
},
{
"input": "4 2 2\n402 10 10 402",
"output": "392"
},
{
"input": "4 1 3\n10 402 402 10",
"output": "0"
},
{
"input": "4 3 1\n100 100 200 200",
"output": "0"
},
{
"input": "150 10 140\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "102 101 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 1 1",
"output": "0"
}
] | 1,642,081,320 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n,a,b= map(int,input().split())
x = list(map(int,input().split()))
x.sort()
print(x[b]-x[b-1]) | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
Input Specification:
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output Specification:
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
Demo Input:
['5 2 3\n6 2 3 100 1\n', '7 3 4\n1 1 9 1 1 1 1\n']
Demo Output:
['3\n', '0\n']
Note:
In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | ```python
n,a,b= map(int,input().split())
x = list(map(int,input().split()))
x.sort()
print(x[b]-x[b-1])
``` | 3 |
|
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
"input": "oops",
"output": "oops"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "a"
},
{
"input": "aA",
"output": "Aa"
},
{
"input": "Zz",
"output": "Zz"
},
{
"input": "Az",
"output": "Az"
},
{
"input": "zA",
"output": "Za"
},
{
"input": "AAA",
"output": "aaa"
},
{
"input": "AAa",
"output": "AAa"
},
{
"input": "AaR",
"output": "AaR"
},
{
"input": "Tdr",
"output": "Tdr"
},
{
"input": "aTF",
"output": "Atf"
},
{
"input": "fYd",
"output": "fYd"
},
{
"input": "dsA",
"output": "dsA"
},
{
"input": "fru",
"output": "fru"
},
{
"input": "hYBKF",
"output": "Hybkf"
},
{
"input": "XweAR",
"output": "XweAR"
},
{
"input": "mogqx",
"output": "mogqx"
},
{
"input": "eOhEi",
"output": "eOhEi"
},
{
"input": "nkdku",
"output": "nkdku"
},
{
"input": "zcnko",
"output": "zcnko"
},
{
"input": "lcccd",
"output": "lcccd"
},
{
"input": "vwmvg",
"output": "vwmvg"
},
{
"input": "lvchf",
"output": "lvchf"
},
{
"input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO",
"output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo"
},
{
"input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG",
"output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg"
},
{
"input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS",
"output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ",
"output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq"
},
{
"input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR",
"output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR"
},
{
"input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE",
"output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE"
},
{
"input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ",
"output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ"
},
{
"input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm",
"output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm"
},
{
"input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm",
"output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm"
},
{
"input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg",
"output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg"
},
{
"input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc",
"output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc"
},
{
"input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv",
"output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv"
},
{
"input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect",
"output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu",
"output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu"
},
{
"input": "aBACABa",
"output": "aBACABa"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAaa",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAaa"
},
{
"input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
{
"input": "dDDDDDDDDDDDDD",
"output": "Dddddddddddddd"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "z",
"output": "Z"
},
{
"input": "AZ",
"output": "az"
},
{
"input": "Z",
"output": "z"
},
{
"input": "aAAAA",
"output": "Aaaaa"
},
{
"input": "F",
"output": "f"
}
] | 1,698,161,825 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | s = input()
ok = True
for i in range(1,len(s)):
if ord('A') <= ord(s[i]) <= ord('Z'):
ok = False
if not ok:
for c in s:
if ord('a') <= ord(c) <= ord('z'): #小写字母
print (chr(ord(c)-(ord('a')-ord('A'))),end='')
else:
print (chr(ord(c)+(ord('a')-ord('A'))),end='')
else:
print(s)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input Specification:
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output Specification:
Print the result of the given word's processing.
Demo Input:
['cAPS\n', 'Lock\n']
Demo Output:
['Caps', 'Lock\n']
Note:
none | ```python
s = input()
ok = True
for i in range(1,len(s)):
if ord('A') <= ord(s[i]) <= ord('Z'):
ok = False
if not ok:
for c in s:
if ord('a') <= ord(c) <= ord('z'): #小写字母
print (chr(ord(c)-(ord('a')-ord('A'))),end='')
else:
print (chr(ord(c)+(ord('a')-ord('A'))),end='')
else:
print(s)
``` | 0 |
|
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,697,813,734 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 92 | 0 | s = input()
print(len(set(s.lstrip("{").rstrip("}").split(", "))) if s != "{}" else 0)
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none | ```python
s = input()
print(len(set(s.lstrip("{").rstrip("}").split(", "))) if s != "{}" else 0)
``` | 3 |
|
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
"input": "0 0 0 0\n4132",
"output": "0"
},
{
"input": "3163 5778 83 7640\n11141442444",
"output": "64270"
},
{
"input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442",
"output": "420780"
},
{
"input": "0 0 0 0\n1",
"output": "0"
},
{
"input": "1 2 3 4\n4",
"output": "4"
},
{
"input": "2343 7653 1242 5432\n1",
"output": "2343"
},
{
"input": "2343 7653 1242 5432\n2",
"output": "7653"
},
{
"input": "2343 7653 1242 5432\n3",
"output": "1242"
},
{
"input": "2343 7653 1242 5432\n4",
"output": "5432"
},
{
"input": "1 2 3 4\n123412",
"output": "13"
},
{
"input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111",
"output": "2650"
},
{
"input": "1 2 3 4\n11111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "1 2 3 4\n23123231321231231231231231221232123121312321",
"output": "87"
},
{
"input": "1 2 3 4\n1111111111111222222222233333333333444444444444444",
"output": "126"
},
{
"input": "2 3 1 4\n121321232412342112312313213123123412131231231232",
"output": "105"
}
] | 1,675,894,587 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 92 | 0 |
a = []
a = [int(item) for item in input().split()] # fill the list with numbers
s = input() # take the string
x = len(s)
result = 0
for i in range(x):
if s[i]=='1':
result+=a[0]
elif s[i]== '2' :
result += a[1]
elif s[i] == '3' :
result += a[2]
elif s[i] == '4' :
result += a[3]
print (result)
# problem_link : https://codeforces.com/contest/431/problem/A
| Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
Input Specification:
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Output Specification:
Print a single integer — the total number of calories that Jury wastes.
Demo Input:
['1 2 3 4\n123214\n', '1 5 3 2\n11221\n']
Demo Output:
['13\n', '13\n']
Note:
none | ```python
a = []
a = [int(item) for item in input().split()] # fill the list with numbers
s = input() # take the string
x = len(s)
result = 0
for i in range(x):
if s[i]=='1':
result+=a[0]
elif s[i]== '2' :
result += a[1]
elif s[i] == '3' :
result += a[2]
elif s[i] == '4' :
result += a[3]
print (result)
# problem_link : https://codeforces.com/contest/431/problem/A
``` | 3 |
|
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=<<=*b*1<=<<=*b*2<=<<=...<=<<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value .
Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.
In the problem, fraction denotes division in real numbers, that is, no rounding is performed. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing.
It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces. | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input": "4\n3 7 11 13\n4\n51 119 187 221",
"output": "4"
},
{
"input": "4\n2 3 4 5\n3\n1 2 3",
"output": "2"
},
{
"input": "10\n6 12 13 20 48 53 74 92 96 97\n10\n1 21 32 36 47 54 69 75 95 97",
"output": "1"
},
{
"input": "10\n5 9 10 14 15 17 19 22 24 26\n10\n2 11 17 19 21 22 24 25 27 28",
"output": "1"
},
{
"input": "10\n24 53 56 126 354 432 442 740 795 856\n10\n273 438 494 619 689 711 894 947 954 958",
"output": "1"
},
{
"input": "10\n3 4 6 7 8 10 14 16 19 20\n10\n3 4 5 7 8 10 15 16 18 20",
"output": "1"
},
{
"input": "10\n1 6 8 14 15 17 25 27 34 39\n10\n1 8 16 17 19 22 32 39 44 50",
"output": "1"
},
{
"input": "10\n5 21 22 23 25 32 35 36 38 39\n10\n3 7 8 9 18 21 23 24 36 38",
"output": "4"
},
{
"input": "50\n5 8 13 16 19 20 21 22 24 27 28 29 30 32 33 34 35 43 45 48 50 51 54 55 58 59 60 61 62 65 70 71 72 76 78 79 80 81 83 84 85 87 89 91 92 94 97 98 99 100\n50\n2 3 5 6 7 10 15 16 17 20 23 28 29 30 31 34 36 37 40 42 45 46 48 54 55 56 58 59 61 62 69 70 71 72 75 76 78 82 84 85 86 87 88 89 90 91 92 97 99 100",
"output": "1"
},
{
"input": "50\n3 5 6 8 9 11 13 19 21 23 24 32 34 35 42 50 51 52 56 58 59 69 70 72 73 75 76 77 78 80 83 88 90 95 96 100 101 102 108 109 113 119 124 135 138 141 142 143 145 150\n50\n5 8 10 11 18 19 23 30 35 43 51 53 55 58 63 68 69 71 77 78 79 82 83 86 88 89 91 92 93 94 96 102 103 105 109 110 113 114 116 123 124 126 127 132 133 135 136 137 142 149",
"output": "1"
},
{
"input": "50\n6 16 24 25 27 33 36 40 51 60 62 65 71 72 75 77 85 87 91 93 98 102 103 106 117 118 120 121 122 123 125 131 134 136 143 148 155 157 160 161 164 166 170 178 184 187 188 192 194 197\n50\n5 9 17 23 27 34 40 44 47 59 62 70 81 82 87 88 89 90 98 101 102 110 113 114 115 116 119 122 124 128 130 137 138 140 144 150 152 155 159 164 166 169 171 175 185 186 187 189 190 193",
"output": "1"
},
{
"input": "50\n14 22 23 31 32 35 48 63 76 79 88 97 101 102 103 104 106 113 114 115 116 126 136 138 145 152 155 156 162 170 172 173 179 180 182 203 208 210 212 222 226 229 231 232 235 237 245 246 247 248\n50\n2 5 6 16 28 44 45 46 54 55 56 63 72 80 87 93 94 96 97 100 101 103 132 135 140 160 164 165 167 168 173 180 182 185 186 192 194 198 199 202 203 211 213 216 217 227 232 233 236 245",
"output": "1"
},
{
"input": "50\n14 19 33 35 38 41 51 54 69 70 71 73 76 80 84 94 102 104 105 106 107 113 121 128 131 168 180 181 187 191 195 201 205 207 210 216 220 238 249 251 263 271 272 275 281 283 285 286 291 294\n50\n2 3 5 20 21 35 38 40 43 48 49 52 55 64 73 77 82 97 109 113 119 121 125 132 137 139 145 146 149 180 182 197 203 229 234 241 244 251 264 271 274 281 284 285 287 291 292 293 294 298",
"output": "1"
},
{
"input": "50\n2 4 5 16 18 19 22 23 25 26 34 44 48 54 67 79 80 84 92 110 116 133 138 154 163 171 174 202 205 218 228 229 234 245 247 249 250 263 270 272 274 275 277 283 289 310 312 334 339 342\n50\n1 5 17 18 25 37 46 47 48 59 67 75 80 83 84 107 115 122 137 141 159 162 175 180 184 204 221 224 240 243 247 248 249 258 259 260 264 266 269 271 274 293 294 306 329 330 334 335 342 350",
"output": "1"
},
{
"input": "50\n6 9 11 21 28 39 42 56 60 63 81 88 91 95 105 110 117 125 149 165 174 176 185 189 193 196 205 231 233 268 278 279 281 286 289 292 298 303 305 306 334 342 350 353 361 371 372 375 376 378\n50\n6 17 20 43 45 52 58 59 82 83 88 102 111 118 121 131 145 173 190 191 200 216 224 225 232 235 243 256 260 271 290 291 321 322 323 329 331 333 334 341 343 348 351 354 356 360 366 379 387 388",
"output": "1"
},
{
"input": "10\n17 239 443 467 661 1069 1823 2333 3767 4201\n20\n51 83 97 457 593 717 997 1329 1401 1459 1471 1983 2371 2539 3207 3251 3329 5469 6637 6999",
"output": "8"
},
{
"input": "20\n179 359 401 467 521 601 919 941 1103 1279 1709 1913 1949 2003 2099 2143 2179 2213 2399 4673\n20\n151 181 191 251 421 967 1109 1181 1249 1447 1471 1553 1619 2327 2551 2791 3049 3727 6071 7813",
"output": "3"
},
{
"input": "20\n79 113 151 709 809 983 1291 1399 1409 1429 2377 2659 2671 2897 3217 3511 3557 3797 3823 4363\n10\n19 101 659 797 1027 1963 2129 2971 3299 9217",
"output": "3"
},
{
"input": "30\n19 47 109 179 307 331 389 401 461 509 547 569 617 853 883 1249 1361 1381 1511 1723 1741 1783 2459 2531 2621 3533 3821 4091 5557 6217\n20\n401 443 563 941 967 997 1535 1567 1655 1747 1787 1945 1999 2251 2305 2543 2735 4415 6245 7555",
"output": "8"
},
{
"input": "30\n3 43 97 179 257 313 353 359 367 389 397 457 547 599 601 647 1013 1021 1063 1433 1481 1531 1669 3181 3373 3559 3769 4157 4549 5197\n50\n13 15 17 19 29 79 113 193 197 199 215 223 271 293 359 485 487 569 601 683 895 919 941 967 1283 1285 1289 1549 1565 1765 1795 1835 1907 1931 1945 1985 1993 2285 2731 2735 2995 3257 4049 4139 5105 5315 7165 7405 7655 8345",
"output": "20"
},
{
"input": "50\n11 17 23 53 59 109 137 149 173 251 353 379 419 421 439 503 593 607 661 773 821 877 941 997 1061 1117 1153 1229 1289 1297 1321 1609 1747 2311 2389 2543 2693 3041 3083 3137 3181 3209 3331 3373 3617 3767 4201 4409 4931 6379\n50\n55 59 67 73 85 89 101 115 211 263 295 353 545 599 607 685 739 745 997 1031 1255 1493 1523 1667 1709 1895 1949 2161 2195 2965 3019 3035 3305 3361 3373 3673 3739 3865 3881 4231 4253 4385 4985 5305 5585 5765 6145 6445 8045 8735",
"output": "23"
},
{
"input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782",
"output": "3"
},
{
"input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428",
"output": "4"
},
{
"input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959",
"output": "5"
},
{
"input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664",
"output": "24"
},
{
"input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782",
"output": "3"
},
{
"input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428",
"output": "4"
},
{
"input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959",
"output": "5"
},
{
"input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664",
"output": "24"
},
{
"input": "47\n66 262 357 457 513 530 538 540 592 691 707 979 1015 1242 1246 1667 1823 1886 1963 2133 2649 2679 2916 2949 3413 3523 3699 3958 4393 4922 5233 5306 5799 6036 6302 6629 7208 7282 7315 7822 7833 7927 8068 8150 8870 8962 9987\n39\n167 199 360 528 1515 1643 1986 1988 2154 2397 2856 3552 3656 3784 3980 4096 4104 4240 4320 4736 4951 5266 5656 5849 5850 6169 6517 6875 7244 7339 7689 7832 8120 8716 9503 9509 9933 9936 9968",
"output": "12"
},
{
"input": "1\n94\n50\n423 446 485 1214 1468 1507 1853 1930 1999 2258 2271 2285 2425 2543 2715 2743 2992 3196 4074 4108 4448 4475 4652 5057 5250 5312 5356 5375 5731 5986 6298 6501 6521 7146 7255 7276 7332 7481 7998 8141 8413 8665 8908 9221 9336 9491 9504 9677 9693 9706",
"output": "1"
},
{
"input": "50\n51 67 75 186 194 355 512 561 720 876 1077 1221 1503 1820 2153 2385 2568 2608 2937 2969 3271 3311 3481 4081 4093 4171 4255 4256 4829 5020 5192 5636 5817 6156 6712 6717 7153 7436 7608 7612 7866 7988 8264 8293 8867 9311 9879 9882 9889 9908\n1\n5394",
"output": "1"
},
{
"input": "50\n26 367 495 585 675 789 855 1185 1312 1606 2037 2241 2587 2612 2628 2807 2873 2924 3774 4067 4376 4668 4902 5001 5082 5100 5104 5209 5345 5515 5661 5777 5902 5907 6155 6323 6675 6791 7503 8159 8207 8254 8740 8848 8855 8933 9069 9164 9171 9586\n5\n1557 6246 7545 8074 8284",
"output": "1"
},
{
"input": "5\n25 58 91 110 2658\n50\n21 372 909 1172 1517 1554 1797 1802 1843 1977 2006 2025 2137 2225 2317 2507 2645 2754 2919 3024 3202 3212 3267 3852 4374 4487 4553 4668 4883 4911 4916 5016 5021 5068 5104 5162 5683 5856 6374 6871 7333 7531 8099 8135 8173 8215 8462 8776 9433 9790",
"output": "4"
},
{
"input": "45\n37 48 56 59 69 70 79 83 85 86 99 114 131 134 135 145 156 250 1739 1947 2116 2315 2449 3104 3666 4008 4406 4723 4829 5345 5836 6262 6296 6870 7065 7110 7130 7510 7595 8092 8442 8574 9032 9091 9355\n50\n343 846 893 1110 1651 1837 2162 2331 2596 3012 3024 3131 3294 3394 3528 3717 3997 4125 4347 4410 4581 4977 5030 5070 5119 5229 5355 5413 5418 5474 5763 5940 6151 6161 6164 6237 6506 6519 6783 7182 7413 7534 8069 8253 8442 8505 9135 9308 9828 9902",
"output": "17"
},
{
"input": "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 1649 1940 2078 2134 2716 3492 3686 4462 4559 4656 4756 4850 5044 5490 5529 5592 5626 6014 6111 6693 6790 7178 7275 7566 7663 7702 7857 7954 8342 8511 8730 8957 9021 9215 9377 9445 9991",
"output": "28"
},
{
"input": "39\n10 13 21 25 36 38 47 48 58 64 68 69 73 79 86 972 2012 2215 2267 2503 3717 3945 4197 4800 5266 6169 6612 6824 7023 7322 7582 7766 8381 8626 8879 9079 9088 9838 9968\n50\n432 877 970 1152 1202 1223 1261 1435 1454 1578 1843 1907 2003 2037 2183 2195 2215 2425 3065 3492 3615 3637 3686 3946 4189 4415 4559 4656 4665 4707 4886 4887 5626 5703 5955 6208 6521 6581 6596 6693 6985 7013 7081 7343 7663 8332 8342 8637 9207 9862",
"output": "15"
},
{
"input": "50\n7 144 269 339 395 505 625 688 709 950 1102 1152 1350 1381 1641 1830 1977 1999 2093 2180 2718 3308 3574 4168 4232 4259 4393 4689 4982 5154 5476 5581 5635 5721 6159 6302 6741 7010 7152 7315 7417 7482 8116 8239 8640 9347 9395 9614 9661 9822\n20\n84 162 292 1728 1866 2088 3228 3470 4068 5318 5470 6060 6380 6929 7500 8256 8399 8467 8508 9691",
"output": "8"
},
{
"input": "50\n159 880 1070 1139 1358 1608 1691 1841 2073 2171 2213 2597 2692 2759 2879 2931 3173 3217 3441 4201 4878 5106 5129 5253 5395 5647 5968 6019 6130 6276 6286 6330 6409 6728 7488 7713 7765 7828 7899 8064 8264 8457 8483 8685 8900 8946 8965 9133 9187 9638\n45\n57 159 1070 1139 1391 1608 1691 1841 2171 2213 2692 2759 2931 3173 3217 3441 4201 4878 5106 5129 5253 5647 5968 6130 6276 6286 6409 7488 7694 7713 7765 7828 7899 8003 8064 8081 8244 8264 8685 8900 8946 8965 9133 9638 9673",
"output": "38"
},
{
"input": "3\n3 4 5\n3\n6 20 25",
"output": "2"
},
{
"input": "4\n2 3 5 8\n4\n2 6 8 10",
"output": "1"
},
{
"input": "4\n3 5 7 11\n4\n3 5 7 22",
"output": "1"
},
{
"input": "2\n2 3\n3\n20 30 50",
"output": "1"
},
{
"input": "3\n1 2 3\n4\n2 4 6 49",
"output": "1"
},
{
"input": "2\n4 5\n3\n12 15 20",
"output": "1"
},
{
"input": "3\n2 5 7\n3\n4 5 7",
"output": "1"
},
{
"input": "3\n3 5 8\n3\n6 8 10",
"output": "2"
},
{
"input": "2\n2 3\n4\n4 6 9 33",
"output": "1"
},
{
"input": "2\n2 3\n4\n4 6 21 40",
"output": "1"
},
{
"input": "3\n4 9 10\n3\n8 9 10",
"output": "1"
},
{
"input": "5\n1 5 6 9 51\n5\n5 12 18 27 10000",
"output": "1"
},
{
"input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n1\n14",
"output": "1"
}
] | 1,625,775,411 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define ll long long
#define pl pair<ll, ll>
#define itp pair<vector<int>::iterator, vector<int>::iterator>
#define mp make_pair
#define f first
#define s second
const ll MOD = (ll)(pow(10, 9) + 7);
using namespace std;
ll dist(ll a, ll b, ll n) {
if (a == b)
{
return 0;
}
if (b < a)
{
return n - a + b;
}
else {
return b - a;
}
}
int main() {
ll n, m;
cin >> n;
vector <ll> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
cin >> m;
vector<ll> B(m);
for (int i = 0; i < m; i++) {
cin >> B[i];
}
ll k = 0;
ll x = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (B[i] % A[j] == 0)
x = max(B[i] / A[j], x);
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (B[i] % A[j] == 0)
if (B[i] / A[j] == x)
k++;
}
}
cout << k;
} | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=<<=*b*1<=<<=*b*2<=<<=...<=<<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value .
Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.
In the problem, fraction denotes division in real numbers, that is, no rounding is performed.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing.
It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces.
Output Specification:
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
Demo Input:
['2\n4 5\n3\n12 13 15\n', '4\n1 2 3 4\n5\n10 11 12 13 14\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | ```python
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define ll long long
#define pl pair<ll, ll>
#define itp pair<vector<int>::iterator, vector<int>::iterator>
#define mp make_pair
#define f first
#define s second
const ll MOD = (ll)(pow(10, 9) + 7);
using namespace std;
ll dist(ll a, ll b, ll n) {
if (a == b)
{
return 0;
}
if (b < a)
{
return n - a + b;
}
else {
return b - a;
}
}
int main() {
ll n, m;
cin >> n;
vector <ll> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
cin >> m;
vector<ll> B(m);
for (int i = 0; i < m; i++) {
cin >> B[i];
}
ll k = 0;
ll x = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (B[i] % A[j] == 0)
x = max(B[i] / A[j], x);
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (B[i] % A[j] == 0)
if (B[i] / A[j] == x)
k++;
}
}
cout << k;
}
``` | -1 |
|
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"input": "7",
"output": "7 1 2 3 4 5 6 "
},
{
"input": "1000",
"output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "999",
"output": "999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "998",
"output": "998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "997",
"output": "997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "900",
"output": "900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "101",
"output": "101 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "67",
"output": "67 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 "
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "971",
"output": "971 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "683",
"output": "683 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "99",
"output": "99 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 "
},
{
"input": "811",
"output": "811 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "875",
"output": "875 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "291",
"output": "291 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "419",
"output": "419 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "21",
"output": "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
},
{
"input": "22",
"output": "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 "
},
{
"input": "23",
"output": "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 "
},
{
"input": "24",
"output": "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 "
},
{
"input": "25",
"output": "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 "
}
] | 1,557,059,899 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | n=int(input())
for i in range(2,n+1):
print(i,' ',end='')
print(1) | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
Output Specification:
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists.
Demo Input:
['1\n', '2\n']
Demo Output:
['1 ', '2 1 ']
Note:
none | ```python
n=int(input())
for i in range(2,n+1):
print(i,' ',end='')
print(1)
``` | 0 |
|
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3....
Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it? | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6. | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10\n1 -1 1 -1 1 -1 1 -1 1 -1",
"output": "0 0 0 0 0 0 0 0 0 -1 "
},
{
"input": "10\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000",
"output": "0 0 0 0 0 0 0 0 0 1000000000 "
},
{
"input": "10\n124 532 -642 6482 -124 952 -235 7594 34 -12",
"output": "656 -110 5840 6358 828 717 7359 7628 22 -12 "
},
{
"input": "10\n1294 35852 32749 537295 12048 53729 29357 58320 64739 1240",
"output": "37146 68601 570044 549343 65777 83086 87677 123059 65979 1240 "
}
] | 1,473,527,311 | 1,411 | Python 3 | OK | TESTS | 49 | 405 | 8,396,800 | n=int(input())
v=[int(i) for i in input().split()]
b=[v[i]+v[i+1] for i in range(n-1)]
b.append(v[-1])
for i in range(n):
print(b[i],end=" ")
| Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3....
Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it?
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number.
Output Specification:
Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type.
Demo Input:
['5\n6 -4 8 -2 3\n', '5\n3 -2 -1 5 6\n']
Demo Output:
['2 4 6 1 3 \n', '1 -3 4 11 6 \n']
Note:
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6. | ```python
n=int(input())
v=[int(i) for i in input().split()]
b=[v[i]+v[i+1] for i in range(n-1)]
b.append(v[-1])
for i in range(n):
print(b[i],end=" ")
``` | 3 |
|
990 | B | Micro-World | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$.
The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i > a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i > a_j$ and $a_i \le a_j + K$. The swallow operations go one after another.
For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish.
Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope. | The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$.
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. | Print the only integer — minimal possible number of bacteria can remain. | [
"7 1\n101 53 42 102 101 55 54\n",
"6 5\n20 15 10 15 20 25\n",
"7 1000000\n1 1 1 1 1 1 1\n"
] | [
"3\n",
"1\n",
"7\n"
] | The first example is clarified in the problem statement.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$.
In the third example no bacteria can swallow any other bacteria. | 0 | [
{
"input": "7 1\n101 53 42 102 101 55 54",
"output": "3"
},
{
"input": "6 5\n20 15 10 15 20 25",
"output": "1"
},
{
"input": "7 1000000\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 4\n8",
"output": "1"
},
{
"input": "10 1\n1 2 3 5 6 8 10 11 9 4",
"output": "2"
},
{
"input": "9 2\n1 6 1 5 5 8 6 8 7",
"output": "4"
},
{
"input": "15 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15"
},
{
"input": "2 1000000\n1 1000000",
"output": "1"
},
{
"input": "7 2\n1 5 5 8 9 8 8",
"output": "4"
},
{
"input": "10 1\n2 6 3 4 2 4 4 3 2 1",
"output": "4"
},
{
"input": "4 1\n2 2 1 1",
"output": "2"
},
{
"input": "10 1\n6 3 1 3 6 4 1 3 6 4",
"output": "7"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "8 2\n3 13 9 8 3 13 9 14",
"output": "5"
},
{
"input": "8 1000000\n1 1 5 1000000 1000000 2 2 2",
"output": "2"
},
{
"input": "2 1\n999152 999153",
"output": "1"
}
] | 1,534,143,527 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 560 | 14,336,000 | n ,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
out = 0
i = 0
for j in range(n):
while(i+1 < n and a[j] == a[i]):
i += 1
if a[j] < a[i] and a[j] + k >= a[i]:
out += 1
print(n-out)
| Title: Micro-World
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$.
The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i > a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i > a_j$ and $a_i \le a_j + K$. The swallow operations go one after another.
For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish.
Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.
Input Specification:
The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$.
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have.
Output Specification:
Print the only integer — minimal possible number of bacteria can remain.
Demo Input:
['7 1\n101 53 42 102 101 55 54\n', '6 5\n20 15 10 15 20 25\n', '7 1000000\n1 1 1 1 1 1 1\n']
Demo Output:
['3\n', '1\n', '7\n']
Note:
The first example is clarified in the problem statement.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$.
In the third example no bacteria can swallow any other bacteria. | ```python
n ,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
out = 0
i = 0
for j in range(n):
while(i+1 < n and a[j] == a[i]):
i += 1
if a[j] < a[i] and a[j] + k >= a[i]:
out += 1
print(n-out)
``` | 3 |
|
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"input": "4",
"output": "Rajesh"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "10",
"output": "Penny"
},
{
"input": "534",
"output": "Rajesh"
},
{
"input": "5033",
"output": "Howard"
},
{
"input": "10010",
"output": "Howard"
},
{
"input": "500000000",
"output": "Penny"
},
{
"input": "63",
"output": "Rajesh"
},
{
"input": "841",
"output": "Leonard"
},
{
"input": "3667",
"output": "Penny"
},
{
"input": "38614",
"output": "Howard"
},
{
"input": "282798",
"output": "Rajesh"
},
{
"input": "9266286",
"output": "Rajesh"
},
{
"input": "27385966",
"output": "Leonard"
},
{
"input": "121580142",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "300",
"output": "Howard"
},
{
"input": "1745",
"output": "Leonard"
},
{
"input": "8302",
"output": "Rajesh"
},
{
"input": "184518",
"output": "Sheldon"
},
{
"input": "1154414",
"output": "Rajesh"
},
{
"input": "28643950",
"output": "Leonard"
},
{
"input": "159222638",
"output": "Howard"
},
{
"input": "24",
"output": "Penny"
},
{
"input": "505",
"output": "Penny"
},
{
"input": "4425",
"output": "Rajesh"
},
{
"input": "12079",
"output": "Sheldon"
},
{
"input": "469726",
"output": "Penny"
},
{
"input": "3961838",
"output": "Penny"
},
{
"input": "57710446",
"output": "Leonard"
},
{
"input": "80719470",
"output": "Howard"
},
{
"input": "1000000000",
"output": "Penny"
},
{
"input": "999999999",
"output": "Penny"
},
{
"input": "999999998",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
}
] | 1,689,337,070 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 61 | 0 | def find_person(n):
queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
i = 0
while n > len(queue):
n -= len(queue)
queue += [queue[i], queue[i]]
i += 1
return queue[(n - 1) // (len(queue) // 5)]
n = int(input())
result = find_person(n)
print(result)
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
Input Specification:
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Output Specification:
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
Demo Input:
['1\n', '6\n', '1802\n']
Demo Output:
['Sheldon\n', 'Sheldon\n', 'Penny\n']
Note:
none | ```python
def find_person(n):
queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
i = 0
while n > len(queue):
n -= len(queue)
queue += [queue[i], queue[i]]
i += 1
return queue[(n - 1) // (len(queue) // 5)]
n = int(input())
result = find_person(n)
print(result)
``` | 0 |
808 | A | Lucky Year | PROGRAMMING | 900 | [
"implementation"
] | null | null | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year. | The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland. | Output amount of years from the current year to the next lucky one. | [
"4\n",
"201\n",
"4000\n"
] | [
"1\n",
"99\n",
"1000\n"
] | In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | 0 | [
{
"input": "4",
"output": "1"
},
{
"input": "201",
"output": "99"
},
{
"input": "4000",
"output": "1000"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "10"
},
{
"input": "1",
"output": "1"
},
{
"input": "100000000",
"output": "100000000"
},
{
"input": "900000000",
"output": "100000000"
},
{
"input": "999999999",
"output": "1"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "9999999",
"output": "1"
},
{
"input": "100000001",
"output": "99999999"
},
{
"input": "3660",
"output": "340"
},
{
"input": "21",
"output": "9"
},
{
"input": "900000001",
"output": "99999999"
},
{
"input": "62911",
"output": "7089"
},
{
"input": "11",
"output": "9"
},
{
"input": "940302010",
"output": "59697990"
},
{
"input": "91",
"output": "9"
},
{
"input": "101",
"output": "99"
},
{
"input": "1090",
"output": "910"
},
{
"input": "987654321",
"output": "12345679"
},
{
"input": "703450474",
"output": "96549526"
},
{
"input": "1091",
"output": "909"
},
{
"input": "89",
"output": "1"
},
{
"input": "109",
"output": "91"
},
{
"input": "190",
"output": "10"
},
{
"input": "19",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "482",
"output": "18"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "6",
"output": "1"
},
{
"input": "7",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "10"
},
{
"input": "11",
"output": "9"
},
{
"input": "12",
"output": "8"
},
{
"input": "13",
"output": "7"
},
{
"input": "14",
"output": "6"
},
{
"input": "15",
"output": "5"
},
{
"input": "16",
"output": "4"
},
{
"input": "17",
"output": "3"
},
{
"input": "18",
"output": "2"
},
{
"input": "19",
"output": "1"
},
{
"input": "20",
"output": "10"
},
{
"input": "21",
"output": "9"
},
{
"input": "22",
"output": "8"
},
{
"input": "23",
"output": "7"
},
{
"input": "24",
"output": "6"
},
{
"input": "25",
"output": "5"
},
{
"input": "26",
"output": "4"
},
{
"input": "27",
"output": "3"
},
{
"input": "28",
"output": "2"
},
{
"input": "29",
"output": "1"
},
{
"input": "30",
"output": "10"
},
{
"input": "31",
"output": "9"
},
{
"input": "32",
"output": "8"
},
{
"input": "33",
"output": "7"
},
{
"input": "34",
"output": "6"
},
{
"input": "35",
"output": "5"
},
{
"input": "36",
"output": "4"
},
{
"input": "37",
"output": "3"
},
{
"input": "38",
"output": "2"
},
{
"input": "39",
"output": "1"
},
{
"input": "40",
"output": "10"
},
{
"input": "41",
"output": "9"
},
{
"input": "42",
"output": "8"
},
{
"input": "43",
"output": "7"
},
{
"input": "44",
"output": "6"
},
{
"input": "45",
"output": "5"
},
{
"input": "46",
"output": "4"
},
{
"input": "47",
"output": "3"
},
{
"input": "48",
"output": "2"
},
{
"input": "49",
"output": "1"
},
{
"input": "50",
"output": "10"
},
{
"input": "51",
"output": "9"
},
{
"input": "52",
"output": "8"
},
{
"input": "53",
"output": "7"
},
{
"input": "54",
"output": "6"
},
{
"input": "55",
"output": "5"
},
{
"input": "56",
"output": "4"
},
{
"input": "57",
"output": "3"
},
{
"input": "58",
"output": "2"
},
{
"input": "59",
"output": "1"
},
{
"input": "60",
"output": "10"
},
{
"input": "61",
"output": "9"
},
{
"input": "62",
"output": "8"
},
{
"input": "63",
"output": "7"
},
{
"input": "64",
"output": "6"
},
{
"input": "65",
"output": "5"
},
{
"input": "66",
"output": "4"
},
{
"input": "67",
"output": "3"
},
{
"input": "68",
"output": "2"
},
{
"input": "69",
"output": "1"
},
{
"input": "70",
"output": "10"
},
{
"input": "71",
"output": "9"
},
{
"input": "72",
"output": "8"
},
{
"input": "73",
"output": "7"
},
{
"input": "74",
"output": "6"
},
{
"input": "75",
"output": "5"
},
{
"input": "76",
"output": "4"
},
{
"input": "77",
"output": "3"
},
{
"input": "78",
"output": "2"
},
{
"input": "79",
"output": "1"
},
{
"input": "80",
"output": "10"
},
{
"input": "81",
"output": "9"
},
{
"input": "82",
"output": "8"
},
{
"input": "83",
"output": "7"
},
{
"input": "84",
"output": "6"
},
{
"input": "85",
"output": "5"
},
{
"input": "86",
"output": "4"
},
{
"input": "87",
"output": "3"
},
{
"input": "88",
"output": "2"
},
{
"input": "89",
"output": "1"
},
{
"input": "90",
"output": "10"
},
{
"input": "91",
"output": "9"
},
{
"input": "92",
"output": "8"
},
{
"input": "93",
"output": "7"
},
{
"input": "94",
"output": "6"
},
{
"input": "95",
"output": "5"
},
{
"input": "96",
"output": "4"
},
{
"input": "97",
"output": "3"
},
{
"input": "98",
"output": "2"
},
{
"input": "99",
"output": "1"
},
{
"input": "100",
"output": "100"
},
{
"input": "100",
"output": "100"
},
{
"input": "100",
"output": "100"
},
{
"input": "1000",
"output": "1000"
},
{
"input": "1000",
"output": "1000"
},
{
"input": "1000",
"output": "1000"
},
{
"input": "10000",
"output": "10000"
},
{
"input": "10000",
"output": "10000"
},
{
"input": "101",
"output": "99"
},
{
"input": "110",
"output": "90"
},
{
"input": "1001",
"output": "999"
},
{
"input": "1100",
"output": "900"
},
{
"input": "1010",
"output": "990"
},
{
"input": "10010",
"output": "9990"
},
{
"input": "10100",
"output": "9900"
},
{
"input": "102",
"output": "98"
},
{
"input": "120",
"output": "80"
},
{
"input": "1002",
"output": "998"
},
{
"input": "1200",
"output": "800"
},
{
"input": "1020",
"output": "980"
},
{
"input": "10020",
"output": "9980"
},
{
"input": "10200",
"output": "9800"
},
{
"input": "108",
"output": "92"
},
{
"input": "180",
"output": "20"
},
{
"input": "1008",
"output": "992"
},
{
"input": "1800",
"output": "200"
},
{
"input": "1080",
"output": "920"
},
{
"input": "10080",
"output": "9920"
},
{
"input": "10800",
"output": "9200"
},
{
"input": "109",
"output": "91"
},
{
"input": "190",
"output": "10"
},
{
"input": "1009",
"output": "991"
},
{
"input": "1900",
"output": "100"
},
{
"input": "1090",
"output": "910"
},
{
"input": "10090",
"output": "9910"
},
{
"input": "10900",
"output": "9100"
},
{
"input": "200",
"output": "100"
},
{
"input": "200",
"output": "100"
},
{
"input": "2000",
"output": "1000"
},
{
"input": "2000",
"output": "1000"
},
{
"input": "2000",
"output": "1000"
},
{
"input": "20000",
"output": "10000"
},
{
"input": "20000",
"output": "10000"
},
{
"input": "201",
"output": "99"
},
{
"input": "210",
"output": "90"
},
{
"input": "2001",
"output": "999"
},
{
"input": "2100",
"output": "900"
},
{
"input": "2010",
"output": "990"
},
{
"input": "20010",
"output": "9990"
},
{
"input": "20100",
"output": "9900"
},
{
"input": "202",
"output": "98"
},
{
"input": "220",
"output": "80"
},
{
"input": "2002",
"output": "998"
},
{
"input": "2200",
"output": "800"
},
{
"input": "2020",
"output": "980"
},
{
"input": "20020",
"output": "9980"
},
{
"input": "20200",
"output": "9800"
},
{
"input": "208",
"output": "92"
},
{
"input": "280",
"output": "20"
},
{
"input": "2008",
"output": "992"
},
{
"input": "2800",
"output": "200"
},
{
"input": "2080",
"output": "920"
},
{
"input": "20080",
"output": "9920"
},
{
"input": "20800",
"output": "9200"
},
{
"input": "209",
"output": "91"
},
{
"input": "290",
"output": "10"
},
{
"input": "2009",
"output": "991"
},
{
"input": "2900",
"output": "100"
},
{
"input": "2090",
"output": "910"
},
{
"input": "20090",
"output": "9910"
},
{
"input": "20900",
"output": "9100"
},
{
"input": "800",
"output": "100"
},
{
"input": "800",
"output": "100"
},
{
"input": "8000",
"output": "1000"
},
{
"input": "8000",
"output": "1000"
},
{
"input": "8000",
"output": "1000"
},
{
"input": "80000",
"output": "10000"
},
{
"input": "80000",
"output": "10000"
},
{
"input": "801",
"output": "99"
},
{
"input": "810",
"output": "90"
},
{
"input": "8001",
"output": "999"
},
{
"input": "8100",
"output": "900"
},
{
"input": "8010",
"output": "990"
},
{
"input": "80010",
"output": "9990"
},
{
"input": "80100",
"output": "9900"
},
{
"input": "802",
"output": "98"
},
{
"input": "820",
"output": "80"
},
{
"input": "8002",
"output": "998"
},
{
"input": "8200",
"output": "800"
},
{
"input": "8020",
"output": "980"
},
{
"input": "80020",
"output": "9980"
},
{
"input": "80200",
"output": "9800"
},
{
"input": "808",
"output": "92"
},
{
"input": "880",
"output": "20"
},
{
"input": "8008",
"output": "992"
},
{
"input": "8800",
"output": "200"
},
{
"input": "8080",
"output": "920"
},
{
"input": "80080",
"output": "9920"
},
{
"input": "80800",
"output": "9200"
},
{
"input": "809",
"output": "91"
},
{
"input": "890",
"output": "10"
},
{
"input": "8009",
"output": "991"
},
{
"input": "8900",
"output": "100"
},
{
"input": "8090",
"output": "910"
},
{
"input": "80090",
"output": "9910"
},
{
"input": "80900",
"output": "9100"
},
{
"input": "900",
"output": "100"
},
{
"input": "900",
"output": "100"
},
{
"input": "9000",
"output": "1000"
},
{
"input": "9000",
"output": "1000"
},
{
"input": "9000",
"output": "1000"
},
{
"input": "90000",
"output": "10000"
},
{
"input": "90000",
"output": "10000"
},
{
"input": "901",
"output": "99"
},
{
"input": "910",
"output": "90"
},
{
"input": "9001",
"output": "999"
},
{
"input": "9100",
"output": "900"
},
{
"input": "9010",
"output": "990"
},
{
"input": "90010",
"output": "9990"
},
{
"input": "90100",
"output": "9900"
},
{
"input": "902",
"output": "98"
},
{
"input": "920",
"output": "80"
},
{
"input": "9002",
"output": "998"
},
{
"input": "9200",
"output": "800"
},
{
"input": "9020",
"output": "980"
},
{
"input": "90020",
"output": "9980"
},
{
"input": "90200",
"output": "9800"
},
{
"input": "908",
"output": "92"
},
{
"input": "980",
"output": "20"
},
{
"input": "9008",
"output": "992"
},
{
"input": "9800",
"output": "200"
},
{
"input": "9080",
"output": "920"
},
{
"input": "90080",
"output": "9920"
},
{
"input": "90800",
"output": "9200"
},
{
"input": "909",
"output": "91"
},
{
"input": "990",
"output": "10"
},
{
"input": "9009",
"output": "991"
},
{
"input": "9900",
"output": "100"
},
{
"input": "9090",
"output": "910"
},
{
"input": "90090",
"output": "9910"
},
{
"input": "90900",
"output": "9100"
},
{
"input": "92651241",
"output": "7348759"
}
] | 1,587,786,889 | 2,147,483,647 | PyPy 3 | OK | TESTS | 271 | 155 | 0 | n=int(input())
s=str(n)
r=int(s[0])+1
ss=str(r)+'0'*(len(s)-1)
ss=int(ss)
print(ss-n)
| Title: Lucky Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
Input Specification:
The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland.
Output Specification:
Output amount of years from the current year to the next lucky one.
Demo Input:
['4\n', '201\n', '4000\n']
Demo Output:
['1\n', '99\n', '1000\n']
Note:
In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | ```python
n=int(input())
s=str(n)
r=int(s[0])+1
ss=str(r)+'0'*(len(s)-1)
ss=int(ss)
print(ss-n)
``` | 3 |
|
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct. | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25",
"output": "NO"
},
{
"input": "74 73",
"output": "YES"
},
{
"input": "62 39",
"output": "NO"
},
{
"input": "57 57",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "0 0",
"output": "NO"
},
{
"input": "98 100",
"output": "NO"
},
{
"input": "99 100",
"output": "YES"
},
{
"input": "1 0",
"output": "YES"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "0 100",
"output": "NO"
},
{
"input": "100 98",
"output": "NO"
},
{
"input": "100 100",
"output": "YES"
},
{
"input": "0 5",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
}
] | 1,582,462,490 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 0 | n,m=map(int,input().split())
z=abs(n-m)
if((z==0 and n!=0) or z==1):
print("YES")
else:
print("NO")
| Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
Input Specification:
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
Output Specification:
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
Demo Input:
['2 3\n', '3 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | ```python
n,m=map(int,input().split())
z=abs(n-m)
if((z==0 and n!=0) or z==1):
print("YES")
else:
print("NO")
``` | 3 |
|
612 | A | The Text Splitting | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test). | The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. | If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* — from left to right.
If there are several solutions print any of them. | [
"5 2 3\nHello\n",
"10 9 5\nCodeforces\n",
"6 4 5\nPrivet\n",
"8 1 1\nabacabac\n"
] | [
"2\nHe\nllo\n",
"2\nCodef\norces\n",
"-1\n",
"8\na\nb\na\nc\na\nb\na\nc\n"
] | none | 0 | [
{
"input": "5 2 3\nHello",
"output": "2\nHe\nllo"
},
{
"input": "10 9 5\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "6 4 5\nPrivet",
"output": "-1"
},
{
"input": "8 1 1\nabacabac",
"output": "8\na\nb\na\nc\na\nb\na\nc"
},
{
"input": "1 1 1\n1",
"output": "1\n1"
},
{
"input": "10 8 1\nuTl9w4lcdo",
"output": "10\nu\nT\nl\n9\nw\n4\nl\nc\nd\no"
},
{
"input": "20 6 4\nfmFRpk2NrzSvnQC9gB61",
"output": "5\nfmFR\npk2N\nrzSv\nnQC9\ngB61"
},
{
"input": "30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6",
"output": "5\nWXDjl9\nkitaDT\nY673R5\nxyTlbL\n9gqeQ6"
},
{
"input": "40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde",
"output": "6\nSOHBIkWEv7Scrk\nHgMtFFxP9G7JQL\nYXF\noH1\nsJD\nAde"
},
{
"input": "50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu",
"output": "8\nXCgVJUu4aMQ7HMxZ\njNxe3XARNiahK303\ng9y\n7NV\n8oN\n6tW\ndyX\nrlu"
},
{
"input": "60 52 8\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4hCKogONj",
"output": "2\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4\nhCKogONj"
},
{
"input": "70 50 5\n1BH1ECq7hjzooQOZdbiYHTAgATcP5mxI7kLI9rqA9AriWc9kE5KoLa1zmuTDFsd2ClAPPY",
"output": "14\n1BH1E\nCq7hj\nzooQO\nZdbiY\nHTAgA\nTcP5m\nxI7kL\nI9rqA\n9AriW\nc9kE5\nKoLa1\nzmuTD\nFsd2C\nlAPPY"
},
{
"input": "80 51 8\no2mpu1FCofuiLQb472qczCNHfVzz5TfJtVMrzgN3ff7FwlAY0fQ0ROhWmIX2bggodORNA76bHMjA5yyc",
"output": "10\no2mpu1FC\nofuiLQb4\n72qczCNH\nfVzz5TfJ\ntVMrzgN3\nff7FwlAY\n0fQ0ROhW\nmIX2bggo\ndORNA76b\nHMjA5yyc"
},
{
"input": "90 12 7\nclcImtsw176FFOA6OHGFxtEfEyhFh5bH4iktV0Y8onIcn0soTwiiHUFRWC6Ow36tT5bsQjgrVSTcB8fAVoe7dJIWkE",
"output": "10\nclcImtsw176F\nFOA6OHGFxtEf\nEyhFh5bH4ikt\nV0Y8onIcn0so\nTwiiHUF\nRWC6Ow3\n6tT5bsQ\njgrVSTc\nB8fAVoe\n7dJIWkE"
},
{
"input": "100 25 5\n2SRB9mRpXMRND5zQjeRxc4GhUBlEQSmLgnUtB9xTKoC5QM9uptc8dKwB88XRJy02r7edEtN2C6D60EjzK1EHPJcWNj6fbF8kECeB",
"output": "20\n2SRB9\nmRpXM\nRND5z\nQjeRx\nc4GhU\nBlEQS\nmLgnU\ntB9xT\nKoC5Q\nM9upt\nc8dKw\nB88XR\nJy02r\n7edEt\nN2C6D\n60Ejz\nK1EHP\nJcWNj\n6fbF8\nkECeB"
},
{
"input": "100 97 74\nxL8yd8lENYnXZs28xleyci4SxqsjZqkYzkEbQXfLQ4l4gKf9QQ9xjBjeZ0f9xQySf5psDUDkJEtPLsa62n4CLc6lF6E2yEqvt4EJ",
"output": "-1"
},
{
"input": "51 25 11\nwpk5wqrB6d3qE1slUrzJwMFafnnOu8aESlvTEb7Pp42FDG2iGQn",
"output": "-1"
},
{
"input": "70 13 37\nfzL91QIJvNoZRP4A9aNRT2GTksd8jEb1713pnWFaCGKHQ1oYvlTHXIl95lqyZRKJ1UPYvT",
"output": "-1"
},
{
"input": "10 3 1\nXQ2vXLPShy",
"output": "10\nX\nQ\n2\nv\nX\nL\nP\nS\nh\ny"
},
{
"input": "4 2 3\naaaa",
"output": "2\naa\naa"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb"
},
{
"input": "99 2 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 2 3\nhavanahavan",
"output": "4\nha\nvan\naha\nvan"
},
{
"input": "100 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "50\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa"
},
{
"input": "17 3 5\ngopstopmipodoshli",
"output": "5\ngop\nsto\npmi\npod\noshli"
},
{
"input": "5 4 3\nfoyku",
"output": "-1"
},
{
"input": "99 2 2\n123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
"output": "-1"
},
{
"input": "99 2 2\nrecursionishellrecursionishellrecursionishellrecursionishellrecursionishellrecursionishelldontuseit",
"output": "-1"
},
{
"input": "11 2 3\nqibwnnvqqgo",
"output": "4\nqi\nbwn\nnvq\nqgo"
},
{
"input": "4 4 3\nhhhh",
"output": "1\nhhhh"
},
{
"input": "99 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "99 2 5\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "21\nhh\nhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh"
},
{
"input": "10 5 9\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "10 5 9\naaaaaaaaaa",
"output": "2\naaaaa\naaaaa"
},
{
"input": "11 3 2\nmlmqpohwtsf",
"output": "5\nmlm\nqp\noh\nwt\nsf"
},
{
"input": "3 3 2\nzyx",
"output": "1\nzyx"
},
{
"input": "100 3 3\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "4 2 3\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "3 2 3\nejt",
"output": "1\nejt"
},
{
"input": "5 2 4\nzyxwv",
"output": "-1"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na"
},
{
"input": "100 5 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "25\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa"
},
{
"input": "3 2 2\nzyx",
"output": "-1"
},
{
"input": "99 2 2\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "-1"
},
{
"input": "26 8 9\nabcabcabcabcabcabcabcabcab",
"output": "3\nabcabcab\ncabcabcab\ncabcabcab"
},
{
"input": "6 3 5\naaaaaa",
"output": "2\naaa\naaa"
},
{
"input": "3 2 3\nzyx",
"output": "1\nzyx"
},
{
"input": "5 5 2\naaaaa",
"output": "1\naaaaa"
},
{
"input": "4 3 2\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "5 4 3\nzyxwv",
"output": "-1"
},
{
"input": "95 3 29\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "23\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabcabcabcabcabcabcabcabcabcab"
},
{
"input": "3 2 2\naaa",
"output": "-1"
},
{
"input": "91 62 3\nfjzhkfwzoabaauvbkuzaahkozofaophaafhfpuhobufawkzbavaazwavwppfwapkapaofbfjwaavajojgjguahphofj",
"output": "-1"
},
{
"input": "99 2 2\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc",
"output": "-1"
},
{
"input": "56 13 5\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "8\nabcabcabcabca\nbcabcabcabcab\ncabca\nbcabc\nabcab\ncabca\nbcabc\nabcab"
},
{
"input": "79 7 31\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca",
"output": "-1"
},
{
"input": "92 79 6\nxlvplpckwnhmctoethhslkcyashqtsoeltriddglfwtgkfvkvgytygbcyohrvcxvosdioqvackxiuifmkgdngvbbudcb",
"output": "-1"
},
{
"input": "48 16 13\nibhfinipihcbsqnvtgsbkobepmwymlyfmlfgblvhlfhyojsy",
"output": "3\nibhfinipihcbsqnv\ntgsbkobepmwymlyf\nmlfgblvhlfhyojsy"
},
{
"input": "16 3 7\naaaaaaaaaaaaaaaa",
"output": "4\naaa\naaa\naaa\naaaaaaa"
},
{
"input": "11 10 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 8 8\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 7 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "41 3 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "11\nabc\nabc\nabc\nabca\nbcab\ncabc\nabca\nbcab\ncabc\nabca\nbcab"
},
{
"input": "11 3 2\naaaaaaaaaaa",
"output": "5\naaa\naa\naa\naa\naa"
},
{
"input": "14 9 4\nabcdefghijklmn",
"output": "-1"
},
{
"input": "9 9 5\n123456789",
"output": "1\n123456789"
},
{
"input": "92 10 41\nmeotryyfneonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlgeftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw",
"output": "3\nmeotryyfne\nonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlg\neftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw"
},
{
"input": "17 16 3\ndxyhgtsxtuyljmclj",
"output": "-1"
},
{
"input": "82 13 30\nfmtwumakkejtolxqxrnydhqoufwtdwldfxcfjrndauqcarhbwmdwxsxfbqjsfspuxobywhcrvlndsdmkqd",
"output": "5\nfmtwumakkejto\nlxqxrnydhqouf\nwtdwldfxcfjrn\ndauqcarhbwmdw\nxsxfbqjsfspuxobywhcrvlndsdmkqd"
},
{
"input": "95 3 3\nihnfqcswushyoirjxlxxnwqtwtaowounkumxukwpacxwatimhhhoggqwkkspcplvyndfukbxickcixidgxkjtnpkoeiwlor",
"output": "-1"
},
{
"input": "7 5 3\nzyxwvut",
"output": "-1"
},
{
"input": "17 16 4\nctvfhkiakagcilrdw",
"output": "-1"
}
] | 1,613,387,060 | 2,147,483,647 | PyPy 3 | OK | TESTS | 72 | 93 | 1,331,200 | n, p, q = [int(j) for j in input().split()]
s = str(input())
x, y = -1, -1
found = False
for j in range(101):
for k in range(101):
res = j * p + k * q
if res == n:
x, y = j, k
found = True
break
elif res > n:
break
if found == True or j * p > n:
break
if found == False:
print(-1)
else:
p1, p2 = 0, p
List = []
for j in range(x):
List.append(s[p1 : p2])
p1 += p
p2 += p
p2 = p1 + q
for j in range(y):
List.append(s[p1 : p2])
p1 += q
p2 += q
print(len(List))
for j in range(len(List)):
print(List[j])
| Title: The Text Splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test).
Input Specification:
The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits.
Output Specification:
If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* — from left to right.
If there are several solutions print any of them.
Demo Input:
['5 2 3\nHello\n', '10 9 5\nCodeforces\n', '6 4 5\nPrivet\n', '8 1 1\nabacabac\n']
Demo Output:
['2\nHe\nllo\n', '2\nCodef\norces\n', '-1\n', '8\na\nb\na\nc\na\nb\na\nc\n']
Note:
none | ```python
n, p, q = [int(j) for j in input().split()]
s = str(input())
x, y = -1, -1
found = False
for j in range(101):
for k in range(101):
res = j * p + k * q
if res == n:
x, y = j, k
found = True
break
elif res > n:
break
if found == True or j * p > n:
break
if found == False:
print(-1)
else:
p1, p2 = 0, p
List = []
for j in range(x):
List.append(s[p1 : p2])
p1 += p
p2 += p
p2 = p1 + q
for j in range(y):
List.append(s[p1 : p2])
p1 += q
p2 += q
print(len(List))
for j in range(len(List)):
print(List[j])
``` | 3 |
|
20 | A | BerOS file system | PROGRAMMING | 1,700 | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.
A path called normalized if it contains the smallest possible number of characters '/'.
Your task is to transform a given path to the normalized form. | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | 500 | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "/a//aa/a//",
"output": "/a/aa/a"
},
{
"input": "/aa//b/aa",
"output": "/aa/b/aa"
},
{
"input": "////////////////////////////////////////////////////////////////////////////////////////////////////",
"output": "/"
},
{
"input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/",
"output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb"
},
{
"input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt"
},
{
"input": "///a//a////a/a//a//a//a/////",
"output": "/a/a/a/a/a/a/a"
},
{
"input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/",
"output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a",
"output": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a"
},
{
"input": "///////////////////////////////////////////////////////////////////////////////////////////////////z",
"output": "/z"
},
{
"input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////",
"output": "/z"
}
] | 1,674,109,233 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 186 | 0 | print("/"+"/".join(filter(None, input().split("/")))) | Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.
A path called normalized if it contains the smallest possible number of characters '/'.
Your task is to transform a given path to the normalized form.
Input Specification:
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
Output Specification:
The path in normalized form.
Demo Input:
['//usr///local//nginx/sbin\n']
Demo Output:
['/usr/local/nginx/sbin\n']
Note:
none | ```python
print("/"+"/".join(filter(None, input().split("/"))))
``` | 3.9535 |
446 | A | DZY Loves Sequences | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | 500 | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371",
"output": "19"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "2"
},
{
"input": "5\n1 2 3 4 1",
"output": "5"
},
{
"input": "10\n1 2 3 4 5 5 6 7 8 9",
"output": "6"
},
{
"input": "5\n1 1 1 1 1",
"output": "2"
},
{
"input": "5\n1 1 2 3 4",
"output": "5"
},
{
"input": "5\n1 2 3 1 6",
"output": "5"
},
{
"input": "1\n42",
"output": "1"
},
{
"input": "5\n1 2 42 3 4",
"output": "4"
},
{
"input": "5\n1 5 9 6 10",
"output": "4"
},
{
"input": "5\n5 2 3 4 5",
"output": "5"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "5\n1 2 3 3 4",
"output": "4"
},
{
"input": "8\n1 2 3 4 1 5 6 7",
"output": "5"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "3\n5 1 2",
"output": "3"
},
{
"input": "4\n1 4 3 4",
"output": "4"
},
{
"input": "6\n7 2 12 4 5 6",
"output": "5"
},
{
"input": "6\n7 2 3 1 4 5",
"output": "4"
},
{
"input": "6\n2 3 5 5 6 7",
"output": "6"
},
{
"input": "5\n2 4 7 6 8",
"output": "5"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "5\n4 1 2 3 4",
"output": "5"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6",
"output": "7"
},
{
"input": "4\n1 2 1 3",
"output": "3"
},
{
"input": "4\n4 3 1 2",
"output": "3"
},
{
"input": "6\n1 2 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 1 1 2",
"output": "3"
},
{
"input": "4\n5 1 2 3",
"output": "4"
},
{
"input": "5\n9 1 2 3 4",
"output": "5"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "5\n1 3 2 4 5",
"output": "4"
},
{
"input": "6\n1 2 1 2 4 5",
"output": "5"
},
{
"input": "10\n1 1 5 3 2 9 9 7 7 6",
"output": "3"
},
{
"input": "6\n1 2 3 100000 100 101",
"output": "6"
},
{
"input": "4\n3 3 3 4",
"output": "3"
},
{
"input": "3\n4 3 5",
"output": "3"
},
{
"input": "5\n1 3 2 3 4",
"output": "4"
},
{
"input": "10\n1 2 3 4 5 10 10 11 12 13",
"output": "10"
},
{
"input": "7\n11 2 1 2 13 4 14",
"output": "5"
},
{
"input": "3\n5 1 3",
"output": "3"
},
{
"input": "4\n1 5 3 4",
"output": "4"
},
{
"input": "10\n1 2 3 4 100 6 7 8 9 10",
"output": "10"
},
{
"input": "3\n5 3 5",
"output": "3"
},
{
"input": "5\n100 100 7 8 9",
"output": "4"
},
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "5\n1 2 4 4 5",
"output": "5"
},
{
"input": "6\n7 4 5 6 7 8",
"output": "6"
},
{
"input": "9\n3 4 1 6 3 4 5 6 7",
"output": "7"
},
{
"input": "3\n1000 1 2",
"output": "3"
},
{
"input": "3\n20 1 9",
"output": "3"
},
{
"input": "6\n7 2 3 1 4 6",
"output": "4"
},
{
"input": "3\n100 5 10",
"output": "3"
},
{
"input": "4\n2 2 2 3",
"output": "3"
},
{
"input": "6\n4 2 8 1 2 5",
"output": "4"
},
{
"input": "3\n25 1 6",
"output": "3"
},
{
"input": "10\n17 99 23 72 78 36 5 43 95 9",
"output": "5"
},
{
"input": "7\n21 16 22 21 11 13 19",
"output": "4"
},
{
"input": "5\n1 2 5 3 4",
"output": "4"
},
{
"input": "6\n2 2 2 3 4 5",
"output": "5"
},
{
"input": "5\n1 3 1 2 3",
"output": "4"
},
{
"input": "3\n81 33 64",
"output": "3"
},
{
"input": "7\n14 3 3 19 13 19 15",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 42 7 8 9",
"output": "9"
},
{
"input": "5\n2 3 7 5 6",
"output": "5"
},
{
"input": "5\n1 3 3 4 5",
"output": "5"
},
{
"input": "6\n1 5 4 3 4 5",
"output": "4"
}
] | 1,508,728,782 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | input()
lst = list(map(int, input().split()))
pointer1 = 0
pointer2 = 1
numinc = 0
numincidx = 0
mx = 0
while pointer2 < len(lst):
#print('{} {} {} {}'.format(pointer1, pointer2,numincidx,numinc))
if pointer2 - pointer1 > mx:
mx = pointer2 - pointer1
if lst[pointer2] < lst[pointer2 -1]:
if numinc == 1:
pointer1 = numincidx
numincidx = pointer2 + 1
#print("debug")
else:
numincidx = pointer2
numinc += 1
pointer2 += 1
print(mx) | Title: DZY Loves Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
In a single line print the answer to the problem — the maximum length of the required subsegment.
Demo Input:
['6\n7 2 3 1 5 6\n']
Demo Output:
['5\n']
Note:
You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | ```python
input()
lst = list(map(int, input().split()))
pointer1 = 0
pointer2 = 1
numinc = 0
numincidx = 0
mx = 0
while pointer2 < len(lst):
#print('{} {} {} {}'.format(pointer1, pointer2,numincidx,numinc))
if pointer2 - pointer1 > mx:
mx = pointer2 - pointer1
if lst[pointer2] < lst[pointer2 -1]:
if numinc == 1:
pointer1 = numincidx
numincidx = pointer2 + 1
#print("debug")
else:
numincidx = pointer2
numinc += 1
pointer2 += 1
print(mx)
``` | 0 |
|
452 | A | Eevee | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.
You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it. | First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). | Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). | [
"7\nj......\n",
"7\n...feon\n",
"7\n.l.r.o.\n"
] | [
"jolteon\n",
"leafeon\n",
"flareon\n"
] | Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | 500 | [
{
"input": "7\n...feon",
"output": "leafeon"
},
{
"input": "7\n.l.r.o.",
"output": "flareon"
},
{
"input": "6\n.s..o.",
"output": "espeon"
},
{
"input": "7\nglaceon",
"output": "glaceon"
},
{
"input": "8\n.a.o.e.n",
"output": "vaporeon"
},
{
"input": "7\n.laceon",
"output": "glaceon"
},
{
"input": "7\n..lveon",
"output": "sylveon"
},
{
"input": "7\n.l.ceon",
"output": "glaceon"
},
{
"input": "7\n..areon",
"output": "flareon"
}
] | 1,407,344,061 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 61 | 0 | N = int(input())
S = input()
A = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
for a in A:
if not len(a) == N:
A.remove(a)
for i in range(N):
if S[i] == ".":
continue
else:
for a in A:
if not a[i] == S[i]:
A.remove(a)
print (A[0]) | Title: Eevee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.
You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.
Input Specification:
First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).
Output Specification:
Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).
Demo Input:
['7\nj......\n', '7\n...feon\n', '7\n.l.r.o.\n']
Demo Output:
['jolteon\n', 'leafeon\n', 'flareon\n']
Note:
Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | ```python
N = int(input())
S = input()
A = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
for a in A:
if not len(a) == N:
A.remove(a)
for i in range(N):
if S[i] == ".":
continue
else:
for a in A:
if not a[i] == S[i]:
A.remove(a)
print (A[0])
``` | 0 |
|
570 | D | Tree Requests | PROGRAMMING | 2,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"dfs and similar",
"graphs",
"trees"
] | null | null | Roman planted a tree consisting of *n* vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the *n*<=-<=1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex *i* is vertex *p**i*, the parent index is always less than the index of the vertex (i.e., *p**i*<=<<=*i*).
The depth of the vertex is the number of nodes on the path from the root to *v* along the edges. In particular, the depth of the root is equal to 1.
We say that vertex *u* is in the subtree of vertex *v*, if we can get from *u* to *v*, moving from the vertex to the parent. In particular, vertex *v* is in its subtree.
Roma gives you *m* queries, the *i*-th of which consists of two numbers *v**i*, *h**i*. Let's consider the vertices in the subtree *v**i* located at depth *h**i*. Determine whether you can use the letters written at these vertices to make a string that is a palindrome. The letters that are written in the vertexes, can be rearranged in any order to make a palindrome, but all letters should be used. | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=500<=000) — the number of nodes in the tree and queries, respectively.
The following line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* — the parents of vertices from the second to the *n*-th (1<=≤<=*p**i*<=<<=*i*).
The next line contains *n* lowercase English letters, the *i*-th of these letters is written on vertex *i*.
Next *m* lines describe the queries, the *i*-th line contains two numbers *v**i*, *h**i* (1<=≤<=*v**i*,<=*h**i*<=≤<=*n*) — the vertex and the depth that appear in the *i*-th query. | Print *m* lines. In the *i*-th line print "Yes" (without the quotes), if in the *i*-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes). | [
"6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2\n"
] | [
"Yes\nNo\nYes\nYes\nYes\n"
] | String *s* is a palindrome if reads the same from left to right and from right to left. In particular, an empty string is a palindrome.
Clarification for the sample test.
In the first query there exists only a vertex 1 satisfying all the conditions, we can form a palindrome "z".
In the second query vertices 5 and 6 satisfy condititions, they contain letters "с" and "d" respectively. It is impossible to form a palindrome of them.
In the third query there exist no vertices at depth 1 and in subtree of 4. We may form an empty palindrome.
In the fourth query there exist no vertices in subtree of 6 at depth 1. We may form an empty palindrome.
In the fifth query there vertices 2, 3 and 4 satisfying all conditions above, they contain letters "a", "c" and "c". We may form a palindrome "cac". | 2,000 | [
{
"input": "6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2",
"output": "Yes\nNo\nYes\nYes\nYes"
},
{
"input": "5 6\n1 1 2 3\ncbcab\n3 1\n5 2\n1 3\n4 1\n4 2\n1 1",
"output": "Yes\nYes\nNo\nYes\nYes\nYes"
},
{
"input": "5 6\n1 2 2 1\nbaabb\n1 1\n1 2\n5 1\n4 1\n4 2\n3 2",
"output": "Yes\nNo\nYes\nYes\nYes\nYes"
},
{
"input": "5 9\n1 1 1 2\nedbcb\n1 3\n2 1\n1 3\n2 1\n2 2\n2 2\n1 1\n1 3\n2 1",
"output": "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes"
},
{
"input": "8 12\n1 1 1 2 1 1 4\ncbecdcce\n1 2\n1 2\n2 1\n1 1\n2 1\n1 3\n1 3\n1 3\n1 2\n2 3\n1 3\n1 1",
"output": "No\nNo\nYes\nYes\nYes\nNo\nNo\nNo\nNo\nYes\nNo\nYes"
},
{
"input": "1 1\n\np\n1 1",
"output": "Yes"
},
{
"input": "1 1\n\na\n1 1",
"output": "Yes"
}
] | 1,594,441,674 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 217,907,200 | from bisect import bisect_left
def dfs(i, h):
global parent, g, s, time, IN, OUT, H
IN[i] = time
H[h].append((time, H[h][-1][1]^(1<<(ord(s[i])-ord('a')) )))
time+=1
for j in g[i]:
dfs(j, h+1)
OUT[i] = time
time+=1
IN = {}
OUT= {}
time = 1
n ,m = map(int, input().split())
parent=list(map(int, input().split()))
parent.insert(0, 0)
parent.insert(0, 0)
H = [[(0,0)] for i in range(3*n)]
s = '$' + input()
g = {v:[] for v in range(n+1)}
for i,j in enumerate(parent):
g[j].append(i)
dfs(1,1)
for _ in range(m):
root, height = map(int, input().split())
l = bisect_left(H[height], (IN[root],-1), 0, len(H[height]))-1
r = bisect_left(H[height], (OUT[root],-1), 0, len(H[height]))-1
t = H[height][l][1] ^ H[height][r][1]
b = t - (t&-t)
c = t ^ (t&-t)
if(b):
print('No')
else:
print('Yes') | Title: Tree Requests
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roman planted a tree consisting of *n* vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the *n*<=-<=1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex *i* is vertex *p**i*, the parent index is always less than the index of the vertex (i.e., *p**i*<=<<=*i*).
The depth of the vertex is the number of nodes on the path from the root to *v* along the edges. In particular, the depth of the root is equal to 1.
We say that vertex *u* is in the subtree of vertex *v*, if we can get from *u* to *v*, moving from the vertex to the parent. In particular, vertex *v* is in its subtree.
Roma gives you *m* queries, the *i*-th of which consists of two numbers *v**i*, *h**i*. Let's consider the vertices in the subtree *v**i* located at depth *h**i*. Determine whether you can use the letters written at these vertices to make a string that is a palindrome. The letters that are written in the vertexes, can be rearranged in any order to make a palindrome, but all letters should be used.
Input Specification:
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=500<=000) — the number of nodes in the tree and queries, respectively.
The following line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* — the parents of vertices from the second to the *n*-th (1<=≤<=*p**i*<=<<=*i*).
The next line contains *n* lowercase English letters, the *i*-th of these letters is written on vertex *i*.
Next *m* lines describe the queries, the *i*-th line contains two numbers *v**i*, *h**i* (1<=≤<=*v**i*,<=*h**i*<=≤<=*n*) — the vertex and the depth that appear in the *i*-th query.
Output Specification:
Print *m* lines. In the *i*-th line print "Yes" (without the quotes), if in the *i*-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes).
Demo Input:
['6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2\n']
Demo Output:
['Yes\nNo\nYes\nYes\nYes\n']
Note:
String *s* is a palindrome if reads the same from left to right and from right to left. In particular, an empty string is a palindrome.
Clarification for the sample test.
In the first query there exists only a vertex 1 satisfying all the conditions, we can form a palindrome "z".
In the second query vertices 5 and 6 satisfy condititions, they contain letters "с" and "d" respectively. It is impossible to form a palindrome of them.
In the third query there exist no vertices at depth 1 and in subtree of 4. We may form an empty palindrome.
In the fourth query there exist no vertices in subtree of 6 at depth 1. We may form an empty palindrome.
In the fifth query there vertices 2, 3 and 4 satisfying all conditions above, they contain letters "a", "c" and "c". We may form a palindrome "cac". | ```python
from bisect import bisect_left
def dfs(i, h):
global parent, g, s, time, IN, OUT, H
IN[i] = time
H[h].append((time, H[h][-1][1]^(1<<(ord(s[i])-ord('a')) )))
time+=1
for j in g[i]:
dfs(j, h+1)
OUT[i] = time
time+=1
IN = {}
OUT= {}
time = 1
n ,m = map(int, input().split())
parent=list(map(int, input().split()))
parent.insert(0, 0)
parent.insert(0, 0)
H = [[(0,0)] for i in range(3*n)]
s = '$' + input()
g = {v:[] for v in range(n+1)}
for i,j in enumerate(parent):
g[j].append(i)
dfs(1,1)
for _ in range(m):
root, height = map(int, input().split())
l = bisect_left(H[height], (IN[root],-1), 0, len(H[height]))-1
r = bisect_left(H[height], (OUT[root],-1), 0, len(H[height]))-1
t = H[height][l][1] ^ H[height][r][1]
b = t - (t&-t)
c = t ^ (t&-t)
if(b):
print('No')
else:
print('Yes')
``` | 0 |
|
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,491,922,389 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 4,608,000 | mayus=["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"]
minus=["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
s=input()
ma=0
mi=0
for c in s:
if c in mayus:
ma+=1
elif c in minus:
mi+=1
if ma>mi:
s.upper()
elif mi>=ma:
s.lower()
print(s) | 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
mayus=["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"]
minus=["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
s=input()
ma=0
mi=0
for c in s:
if c in mayus:
ma+=1
elif c in minus:
mi+=1
if ma>mi:
s.upper()
elif mi>=ma:
s.lower()
print(s)
``` | 0 |
507 | A | Amr and Music | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"sortings"
] | null | null | Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal. | The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. | In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying. | [
"4 10\n4 3 1 2\n",
"5 6\n4 3 1 1 2\n",
"1 3\n4\n"
] | [
"4\n1 2 3 4",
"3\n1 3 4",
"0\n"
] | In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | 500 | [
{
"input": "4 10\n4 3 1 2",
"output": "4\n1 2 3 4"
},
{
"input": "5 6\n4 3 1 1 2",
"output": "3\n3 4 5"
},
{
"input": "1 3\n4",
"output": "0"
},
{
"input": "2 100\n100 100",
"output": "1\n1"
},
{
"input": "3 150\n50 50 50",
"output": "3\n1 2 3"
},
{
"input": "4 0\n100 100 100 100",
"output": "0"
},
{
"input": "100 7567\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": "75\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75"
},
{
"input": "68 3250\n95 84 67 7 82 75 100 39 31 45 69 100 8 97 13 58 74 40 88 69 35 91 94 28 62 85 51 97 37 15 87 51 24 96 89 49 53 54 35 17 23 54 51 91 94 18 26 92 79 63 23 37 98 43 16 44 82 25 100 59 97 3 60 92 76 58 56 50",
"output": "60\n1 2 3 4 5 6 8 9 10 11 13 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 60 62 63 64 65 66 67 68"
},
{
"input": "100 10000\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100"
},
{
"input": "25 1293\n96 13 7 2 81 72 39 45 5 88 47 23 60 81 54 46 63 52 41 57 2 87 90 28 93",
"output": "25\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"
},
{
"input": "98 7454\n71 57 94 76 52 90 76 81 67 60 99 88 98 61 73 61 80 91 88 93 53 55 88 64 71 55 81 76 52 63 87 99 84 66 65 52 83 99 92 62 95 81 90 67 64 57 80 80 67 75 77 58 71 85 97 50 97 55 52 59 55 96 57 53 85 100 95 95 74 51 78 88 66 98 97 86 94 81 56 64 61 57 67 95 85 82 85 60 76 95 69 95 76 91 74 100 69 76",
"output": "98\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98"
},
{
"input": "5 249\n96 13 7 2 81",
"output": "5\n1 2 3 4 5"
},
{
"input": "61 3331\n12 63 99 56 57 70 53 21 41 82 97 63 42 91 18 84 99 78 85 89 6 63 76 28 33 78 100 46 78 78 32 13 11 12 73 50 34 60 12 73 9 19 88 100 28 51 50 45 51 10 78 38 25 22 8 40 71 55 56 83 44",
"output": "61\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61"
},
{
"input": "99 10000\n42 88 21 63 59 38 23 100 86 37 57 86 11 22 19 89 6 19 15 64 18 77 83 29 14 26 80 73 8 51 14 19 9 98 81 96 47 77 22 19 86 71 91 61 84 8 80 28 6 25 33 95 96 21 57 92 96 57 31 88 38 32 70 19 25 67 29 78 18 90 37 50 62 33 49 16 47 39 9 33 88 69 69 29 14 66 75 76 41 98 40 52 65 25 33 47 39 24 80",
"output": "99\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99"
},
{
"input": "89 4910\n44 9 31 70 85 72 55 9 85 84 63 43 92 85 10 34 83 28 73 45 62 7 34 52 89 58 24 10 28 6 72 45 57 36 71 34 26 24 38 59 5 15 48 82 58 99 8 77 49 84 14 58 29 46 88 50 13 7 58 23 40 63 96 23 46 31 17 8 59 93 12 76 69 20 43 44 91 78 68 94 37 27 100 65 40 25 52 30 97",
"output": "89\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89"
},
{
"input": "40 2110\n91 18 52 22 26 67 59 10 55 43 97 78 20 81 99 36 33 12 86 32 82 87 70 63 48 48 45 94 78 23 77 15 68 17 71 54 44 98 54 8",
"output": "39\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 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"
},
{
"input": "27 1480\n38 95 9 36 21 70 19 89 35 46 7 31 88 25 10 72 81 32 65 83 68 57 50 20 73 42 12",
"output": "27\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"
},
{
"input": "57 2937\n84 73 23 62 93 64 23 17 53 100 47 67 52 53 90 58 19 84 33 69 46 47 50 28 73 74 40 42 92 70 32 29 57 52 23 82 42 32 46 83 45 87 40 58 50 51 48 37 57 52 78 26 21 54 16 66 93",
"output": "55\n1 2 3 4 5 6 7 8 9 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"
},
{
"input": "6 41\n6 8 9 8 9 8",
"output": "5\n1 2 3 4 6"
},
{
"input": "9 95\n9 11 12 11 12 11 8 11 10",
"output": "9\n1 2 3 4 5 6 7 8 9"
},
{
"input": "89 6512\n80 87 61 91 85 51 58 69 79 57 81 67 74 55 88 70 77 61 55 81 56 76 79 67 92 52 54 73 67 72 81 54 72 81 65 88 83 57 83 92 62 66 63 58 61 66 92 77 73 66 71 85 92 73 82 65 76 64 58 62 64 51 90 59 79 70 86 89 86 51 72 61 60 71 52 74 58 72 77 91 91 60 76 56 64 55 61 81 52",
"output": "89\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89"
},
{
"input": "5 29\n6 3 7 2 1",
"output": "5\n1 2 3 4 5"
},
{
"input": "5 49\n16 13 7 2 1",
"output": "5\n1 2 3 4 5"
},
{
"input": "6 84\n16 21 25 6 17 16",
"output": "5\n1 2 4 5 6"
},
{
"input": "4 9\n7 4 2 1",
"output": "3\n2 3 4"
},
{
"input": "50 2500\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50"
},
{
"input": "100 10000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100"
},
{
"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": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100"
},
{
"input": "96 514\n6 3 7 2 1 2 9 5 5 8 7 3 10 1 4 6 3 2 1 7 2 7 10 8 3 8 10 4 8 8 2 5 3 2 1 4 4 8 4 3 3 7 4 4 2 7 8 3 9 2 2 6 3 4 8 6 7 5 4 3 10 7 6 5 10 1 7 10 7 7 8 2 1 2 3 10 9 8 8 2 7 1 2 7 10 1 2 2 3 8 6 2 9 6 9 6",
"output": "96\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96"
},
{
"input": "47 350\n6 1 9 12 8 8 11 4 4 8 8 3 3 2 12 7 7 7 12 2 9 1 5 10 6 1 5 2 6 3 9 13 8 3 10 10 10 10 6 9 10 10 8 5 12 11 3",
"output": "47\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47"
},
{
"input": "100 200\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100"
},
{
"input": "2 10000\n1 1",
"output": "2\n1 2"
},
{
"input": "1 2\n1",
"output": "1\n1"
},
{
"input": "1 3\n2",
"output": "1\n1"
},
{
"input": "34 4964\n37 27 90 83 36 59 80 7 28 41 97 72 64 8 40 30 76 4 92 51 52 44 42 13 38 64 60 66 47 93 30 35 71 71",
"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 34"
},
{
"input": "2 2\n1 10",
"output": "1\n1"
},
{
"input": "2 5\n1 1",
"output": "2\n1 2"
},
{
"input": "1 4\n3",
"output": "1\n1"
},
{
"input": "4 384\n1 2 3 4",
"output": "4\n1 2 3 4"
}
] | 1,640,961,725 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
x=[]
count=0
for i in l:
if(sum(x)+i<b):
x.append(i)
print(len(x))
print(*x)
| Title: Amr and Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
Input Specification:
The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument.
Output Specification:
In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Demo Input:
['4 10\n4 3 1 2\n', '5 6\n4 3 1 1 2\n', '1 3\n4\n']
Demo Output:
['4\n1 2 3 4', '3\n1 3 4', '0\n']
Note:
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | ```python
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
x=[]
count=0
for i in l:
if(sum(x)+i<b):
x.append(i)
print(len(x))
print(*x)
``` | 0 |
|
979 | C | Kuro and Walking Route | PROGRAMMING | 1,600 | [
"dfs and similar",
"trees"
] | null | null | Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$).
Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.
Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem. | The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.
$n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$.
It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree. | A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route. | [
"3 1 3\n1 2\n2 3\n",
"3 1 3\n1 2\n1 3\n"
] | [
"5",
"4"
] | On the first example, Kuro can choose these pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$.
Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).
On the second example, Kuro can choose the following pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$. | 1,250 | [
{
"input": "3 1 3\n1 2\n2 3",
"output": "5"
},
{
"input": "3 1 3\n1 2\n1 3",
"output": "4"
},
{
"input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 2\n35 27\n39 20\n1 24\n1 53\n35 58\n39 37\n61 13\n61 16\n1 12\n32 17\n1 40\n33 47\n29 52\n1 39\n35 19\n39 50\n27 6\n26 3\n26 55\n35 31\n1 61\n1 23\n27 45\n39 7\n1 35\n39 29\n27 5\n39 32\n27 48\n35 49\n29 54\n1 46\n35 36\n31 33",
"output": "3657"
},
{
"input": "8 5 1\n5 8\n1 5\n1 3\n1 4\n5 6\n6 7\n1 2",
"output": "40"
},
{
"input": "31 29 20\n29 23\n29 18\n22 14\n29 20\n1 21\n29 10\n28 2\n1 17\n17 15\n1 11\n29 31\n28 6\n12 29\n12 26\n1 13\n22 4\n29 25\n28 22\n17 5\n28 30\n20 27\n29 8\n12 28\n1 12\n12 24\n22 7\n12 16\n12 3\n28 9\n1 19",
"output": "872"
},
{
"input": "8 6 4\n1 2\n1 4\n1 8\n1 3\n1 7\n2 6\n2 5",
"output": "55"
},
{
"input": "7 7 3\n3 2\n3 5\n3 7\n1 3\n1 4\n5 6",
"output": "36"
},
{
"input": "70 42 32\n25 50\n51 7\n39 61\n1 33\n20 5\n1 70\n1 63\n42 35\n64 16\n1 11\n39 42\n20 54\n11 14\n57 44\n1 59\n55 40\n25 3\n31 18\n38 68\n57 23\n39 57\n28 10\n39 20\n42 26\n58 6\n20 56\n57 2\n13 21\n15 69\n39 64\n1 39\n62 53\n39 13\n1 41\n22 12\n13 30\n68 67\n20 31\n51 15\n57 32\n59 34\n39 4\n31 65\n58 24\n20 55\n15 27\n25 46\n20 22\n57 49\n68 52\n39 8\n54 58\n39 28\n13 48\n15 43\n25 66\n1 29\n15 37\n31 60\n1 19\n62 38\n39 17\n64 36\n59 25\n57 45\n57 9\n11 62\n20 51\n54 47",
"output": "4827"
},
{
"input": "13 5 13\n2 5\n5 8\n1 2\n13 7\n2 3\n1 13\n13 11\n13 4\n10 6\n10 12\n7 9\n1 10",
"output": "146"
},
{
"input": "72 16 5\n1 20\n8 4\n23 19\n16 63\n45 65\n27 67\n58 21\n36 17\n20 52\n1 71\n8 59\n20 26\n28 16\n23 3\n45 42\n61 51\n6 31\n1 15\n1 11\n6 62\n43 60\n20 27\n20 32\n1 8\n68 25\n1 57\n20 70\n1 64\n1 13\n8 18\n8 46\n28 49\n8 39\n64 58\n28 47\n27 14\n8 10\n11 53\n1 24\n28 2\n72 30\n36 29\n1 45\n24 23\n1 72\n46 61\n45 56\n72 35\n11 50\n8 55\n8 28\n1 38\n61 41\n1 44\n61 40\n27 33\n72 69\n46 36\n43 66\n61 22\n45 5\n27 43\n46 12\n1 7\n16 68\n1 6\n1 9\n45 37\n27 34\n8 54\n20 48",
"output": "5108"
},
{
"input": "2 1 2\n1 2",
"output": "1"
},
{
"input": "2 1 2\n2 1",
"output": "1"
}
] | 1,527,022,426 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 1,024,000 | from collections import deque
class graph:
def __init__(self, N, edges, x, y):
self.nedges=len(edges)
self.N=N
self.adj=[[] for i in range(1,N+1)]
for i in range(0,self.nedges):
self.adj[edges[i][0]-1].append(edges[i][1])
self.adj[edges[i][1]-1].append(edges[i][0])
K=0
Rememb=0
Nen=0
Flow=False
for i in self.adj[y-1]:
Flow=False
Len=0
Flow, Len = self.bfs(i,y,x)
if Flow:
K=Len
Rememb=i
Flow, Nen = self.bfs(y,Rememb,-1)
print (N*(N-1)-Nen*K)
def bfs(self, start, parent, x):
discovered=[False for i in range(0, self.N)]
processed=[False for i in range(0, self.N)]
q=deque()
q.append(start)
discovered[start-1]=True
discovered[parent-1]=True
g=-1
Len=0
flow=False
while(len(q)!=0):
parent = g
Len=Len+1
g = q.pop()
if x==g:
flow=True
ch, mn = self.bfs(x, parent, -1)
return flow, mn
processed[g-1]=True
for i in self.adj[g-1]:
if(discovered[i-1]==False):
discovered[i-1]=True
q.append(i)
return flow, Len
s1=input()
k=[int(i) for i in s1.split(' ')]
N,x,y = k[0],k[1],k[2]
s = [input() for i in range(1,N)]
edges = [[int(j) for j in s[i-1].split(' ')] for i in range(1,N)]
asd=graph(N, edges, x, y) | Title: Kuro and Walking Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$).
Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.
Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem.
Input Specification:
The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.
$n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$.
It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.
Output Specification:
A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route.
Demo Input:
['3 1 3\n1 2\n2 3\n', '3 1 3\n1 2\n1 3\n']
Demo Output:
['5', '4']
Note:
On the first example, Kuro can choose these pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$.
Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).
On the second example, Kuro can choose the following pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$. | ```python
from collections import deque
class graph:
def __init__(self, N, edges, x, y):
self.nedges=len(edges)
self.N=N
self.adj=[[] for i in range(1,N+1)]
for i in range(0,self.nedges):
self.adj[edges[i][0]-1].append(edges[i][1])
self.adj[edges[i][1]-1].append(edges[i][0])
K=0
Rememb=0
Nen=0
Flow=False
for i in self.adj[y-1]:
Flow=False
Len=0
Flow, Len = self.bfs(i,y,x)
if Flow:
K=Len
Rememb=i
Flow, Nen = self.bfs(y,Rememb,-1)
print (N*(N-1)-Nen*K)
def bfs(self, start, parent, x):
discovered=[False for i in range(0, self.N)]
processed=[False for i in range(0, self.N)]
q=deque()
q.append(start)
discovered[start-1]=True
discovered[parent-1]=True
g=-1
Len=0
flow=False
while(len(q)!=0):
parent = g
Len=Len+1
g = q.pop()
if x==g:
flow=True
ch, mn = self.bfs(x, parent, -1)
return flow, mn
processed[g-1]=True
for i in self.adj[g-1]:
if(discovered[i-1]==False):
discovered[i-1]=True
q.append(i)
return flow, Len
s1=input()
k=[int(i) for i in s1.split(' ')]
N,x,y = k[0],k[1],k[2]
s = [input() for i in range(1,N)]
edges = [[int(j) for j in s[i-1].split(' ')] for i in range(1,N)]
asd=graph(N, edges, x, y)
``` | 0 |
|
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City? | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,693,121,790 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n=int(input())
print((5**(n%100))%100) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City?
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output Specification:
Output the last two digits of 5*n* without spaces between them.
Demo Input:
['2\n']
Demo Output:
['25']
Note:
none | ```python
n=int(input())
print((5**(n%100))%100)
``` | 0 |
|
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "3",
"output": "1 1 1"
},
{
"input": "5",
"output": "1 1 3"
},
{
"input": "8",
"output": "1 2 5"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "21",
"output": "3 5 13"
},
{
"input": "34",
"output": "5 8 21"
},
{
"input": "55",
"output": "8 13 34"
},
{
"input": "89",
"output": "13 21 55"
},
{
"input": "144",
"output": "21 34 89"
},
{
"input": "233",
"output": "34 55 144"
},
{
"input": "377",
"output": "55 89 233"
},
{
"input": "610",
"output": "89 144 377"
},
{
"input": "987",
"output": "144 233 610"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "2584",
"output": "377 610 1597"
},
{
"input": "4181",
"output": "610 987 2584"
},
{
"input": "6765",
"output": "987 1597 4181"
},
{
"input": "10946",
"output": "1597 2584 6765"
},
{
"input": "17711",
"output": "2584 4181 10946"
},
{
"input": "28657",
"output": "4181 6765 17711"
},
{
"input": "46368",
"output": "6765 10946 28657"
},
{
"input": "75025",
"output": "10946 17711 46368"
},
{
"input": "121393",
"output": "17711 28657 75025"
},
{
"input": "196418",
"output": "28657 46368 121393"
},
{
"input": "317811",
"output": "46368 75025 196418"
},
{
"input": "514229",
"output": "75025 121393 317811"
},
{
"input": "832040",
"output": "121393 196418 514229"
},
{
"input": "1346269",
"output": "196418 317811 832040"
},
{
"input": "2178309",
"output": "317811 514229 1346269"
},
{
"input": "3524578",
"output": "514229 832040 2178309"
},
{
"input": "5702887",
"output": "832040 1346269 3524578"
},
{
"input": "9227465",
"output": "1346269 2178309 5702887"
},
{
"input": "14930352",
"output": "2178309 3524578 9227465"
},
{
"input": "24157817",
"output": "3524578 5702887 14930352"
},
{
"input": "39088169",
"output": "5702887 9227465 24157817"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "165580141",
"output": "24157817 39088169 102334155"
},
{
"input": "267914296",
"output": "39088169 63245986 165580141"
},
{
"input": "433494437",
"output": "63245986 102334155 267914296"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
}
] | 1,623,375,612 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 154 | 0 | n = int(input())
if n == 0:
print(0, 0, 0)
elif n == 1:
print(0, 0, 1)
elif n == 2:
print(0, 1, 1)
else:
arr = [0, 1]
i = 1
while True:
m = arr[i]+arr[i-1]
if m <= n:
arr.append(m)
i += 1
else:
break
print(arr[-2], arr[-4], arr[-5])
| Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible.
Input Specification:
The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output Specification:
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Demo Input:
['3\n', '13\n']
Demo Output:
['1 1 1\n', '2 3 8\n']
Note:
none | ```python
n = int(input())
if n == 0:
print(0, 0, 0)
elif n == 1:
print(0, 0, 1)
elif n == 2:
print(0, 1, 1)
else:
arr = [0, 1]
i = 1
while True:
m = arr[i]+arr[i-1]
if m <= n:
arr.append(m)
i += 1
else:
break
print(arr[-2], arr[-4], arr[-5])
``` | 3 |
|
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.
You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.
The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\nb d\nd e",
"output": "a b\nc b\nc d\nc e"
},
{
"input": "ze udggmyop\n4\nze szhrbmft\nudggmyop mjorab\nszhrbmft ojdtfnzxj\nojdtfnzxj yjlkg",
"output": "ze udggmyop\nszhrbmft udggmyop\nszhrbmft mjorab\nojdtfnzxj mjorab\nyjlkg mjorab"
},
{
"input": "q s\n10\nq b\nb j\ns g\nj f\nf m\ng c\nc a\nm d\nd z\nz o",
"output": "q s\nb s\nj s\nj g\nf g\nm g\nm c\nm a\nd a\nz a\no a"
},
{
"input": "iii iiiiii\n7\niii iiiiiiiiii\niiiiiiiiii iiii\niiii i\niiiiii iiiiiiii\niiiiiiii iiiiiiiii\ni iiiii\niiiii ii",
"output": "iii iiiiii\niiiiiiiiii iiiiii\niiii iiiiii\ni iiiiii\ni iiiiiiii\ni iiiiiiiii\niiiii iiiiiiiii\nii iiiiiiiii"
},
{
"input": "bwyplnjn zkms\n26\nzkms nzmcsytxh\nnzmcsytxh yujsb\nbwyplnjn gtbzhudpb\ngtbzhudpb hpk\nyujsb xvy\nhpk wrwnfokml\nwrwnfokml ndouuikw\nndouuikw ucgrja\nucgrja tgfmpldz\nxvy nycrfphn\nnycrfphn quvs\nquvs htdy\nhtdy k\ntgfmpldz xtdpkxm\nxtdpkxm suwqxs\nk fv\nsuwqxs qckllwy\nqckllwy diun\nfv lefa\nlefa gdoqjysx\ndiun dhpz\ngdoqjysx bdmqdyt\ndhpz dgz\ndgz v\nbdmqdyt aswy\naswy ydkayhlrnm",
"output": "bwyplnjn zkms\nbwyplnjn nzmcsytxh\nbwyplnjn yujsb\ngtbzhudpb yujsb\nhpk yujsb\nhpk xvy\nwrwnfokml xvy\nndouuikw xvy\nucgrja xvy\ntgfmpldz xvy\ntgfmpldz nycrfphn\ntgfmpldz quvs\ntgfmpldz htdy\ntgfmpldz k\nxtdpkxm k\nsuwqxs k\nsuwqxs fv\nqckllwy fv\ndiun fv\ndiun lefa\ndiun gdoqjysx\ndhpz gdoqjysx\ndhpz bdmqdyt\ndgz bdmqdyt\nv bdmqdyt\nv aswy\nv ydkayhlrnm"
},
{
"input": "wxz hbeqwqp\n7\nhbeqwqp cpieghnszh\ncpieghnszh tlqrpd\ntlqrpd ttwrtio\nttwrtio xapvds\nxapvds zk\nwxz yryk\nzk b",
"output": "wxz hbeqwqp\nwxz cpieghnszh\nwxz tlqrpd\nwxz ttwrtio\nwxz xapvds\nwxz zk\nyryk zk\nyryk b"
},
{
"input": "wced gnsgv\n23\ngnsgv japawpaf\njapawpaf nnvpeu\nnnvpeu a\na ddupputljq\nddupputljq qyhnvbh\nqyhnvbh pqwijl\nwced khuvs\nkhuvs bjkh\npqwijl ysacmboc\nbjkh srf\nsrf jknoz\njknoz hodf\nysacmboc xqtkoyh\nhodf rfp\nxqtkoyh bivgnwqvoe\nbivgnwqvoe nknf\nnknf wuig\nrfp e\ne bqqknq\nwuig sznhhhu\nbqqknq dhrtdld\ndhrtdld n\nsznhhhu bguylf",
"output": "wced gnsgv\nwced japawpaf\nwced nnvpeu\nwced a\nwced ddupputljq\nwced qyhnvbh\nwced pqwijl\nkhuvs pqwijl\nbjkh pqwijl\nbjkh ysacmboc\nsrf ysacmboc\njknoz ysacmboc\nhodf ysacmboc\nhodf xqtkoyh\nrfp xqtkoyh\nrfp bivgnwqvoe\nrfp nknf\nrfp wuig\ne wuig\nbqqknq wuig\nbqqknq sznhhhu\ndhrtdld sznhhhu\nn sznhhhu\nn bguylf"
},
{
"input": "qqqqqqqqqq qqqqqqqq\n3\nqqqqqqqq qqqqqqqqq\nqqqqqqqqq qqqqq\nqqqqq q",
"output": "qqqqqqqqqq qqqqqqqq\nqqqqqqqqqq qqqqqqqqq\nqqqqqqqqqq qqqqq\nqqqqqqqqqq q"
},
{
"input": "wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww",
"output": "wwwww w\nwwwwwwww w\nwwwwwwwww w\nwwwwwwwwww w\nwwwwwwwwww www\nwwww www\nww www\nww wwwwww\nww wwwwwww"
},
{
"input": "k d\n17\nk l\nd v\nv z\nl r\nz i\nr s\ns p\np w\nw j\nj h\ni c\nh m\nm q\nc o\no g\nq x\nx n",
"output": "k d\nl d\nl v\nl z\nr z\nr i\ns i\np i\nw i\nj i\nh i\nh c\nm c\nq c\nq o\nq g\nx g\nn g"
}
] | 1,647,694,132 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 46 | 0 | x, y = input().split()
print(x, y)
for _ in range(int(input())):
a, b = input().split()
if x == a:
x = b
elif y == a:
y = b
print(x, y) | Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.
You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
Input Specification:
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.
The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
Output Specification:
Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
Demo Input:
['ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n', 'icm codeforces\n1\ncodeforces technex\n']
Demo Output:
['ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n', 'icm codeforces\nicm technex\n']
Note:
In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | ```python
x, y = input().split()
print(x, y)
for _ in range(int(input())):
a, b = input().split()
if x == a:
x = b
elif y == a:
y = b
print(x, y)
``` | 3 |
|
429 | A | Xor-tree | PROGRAMMING | 1,300 | [
"dfs and similar",
"trees"
] | null | null | Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on.
The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*.
The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1). | In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*. | [
"10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n"
] | [
"2\n4\n7\n"
] | none | 500 | [
{
"input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1",
"output": "2\n4\n7"
},
{
"input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0",
"output": "7\n1\n4\n7\n8\n9\n11\n13"
},
{
"input": "20\n2 1\n3 2\n4 3\n5 4\n6 4\n7 1\n8 2\n9 4\n10 2\n11 6\n12 9\n13 2\n14 12\n15 14\n16 8\n17 9\n18 13\n19 2\n20 17\n1 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 0\n1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1",
"output": "8\n11\n15\n17\n20\n10\n18\n19\n7"
},
{
"input": "30\n2 1\n3 2\n4 3\n5 3\n6 5\n7 3\n8 3\n9 2\n10 3\n11 2\n12 11\n13 6\n14 4\n15 5\n16 11\n17 9\n18 14\n19 6\n20 2\n21 19\n22 9\n23 19\n24 20\n25 14\n26 22\n27 1\n28 6\n29 13\n30 27\n1 0 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 1 1 0\n0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0 0 0",
"output": "15\n1\n2\n4\n5\n6\n13\n29\n19\n21\n23\n28\n7\n22\n26\n30"
},
{
"input": "15\n2 1\n3 1\n4 1\n5 1\n6 3\n7 1\n8 1\n9 1\n10 5\n11 9\n12 3\n13 5\n14 5\n15 4\n1 1 0 0 0 0 1 1 1 0 1 1 1 0 0\n1 0 1 1 0 1 1 1 1 1 1 1 1 1 0",
"output": "6\n2\n3\n6\n4\n10\n14"
},
{
"input": "20\n2 1\n3 1\n4 2\n5 2\n6 3\n7 1\n8 6\n9 2\n10 3\n11 6\n12 2\n13 3\n14 2\n15 1\n16 8\n17 15\n18 2\n19 14\n20 14\n0 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1\n0 1 0 1 1 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0",
"output": "10\n2\n4\n19\n18\n8\n16\n11\n10\n13\n7"
},
{
"input": "23\n2 1\n3 2\n4 1\n5 1\n6 5\n7 3\n8 2\n9 8\n10 5\n11 6\n12 9\n13 3\n14 11\n15 5\n16 2\n17 3\n18 10\n19 16\n20 14\n21 19\n22 17\n23 7\n0 1 0 1 1 1 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0\n0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1",
"output": "8\n2\n23\n13\n17\n9\n4\n11\n20"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "10\n1 10\n1 9\n10 2\n10 3\n3 7\n3 8\n9 4\n9 5\n5 6\n1 0 1 1 0 1 0 1 0 1\n0 0 0 0 0 0 0 0 0 0",
"output": "6\n1\n10\n2\n7\n5\n6"
}
] | 1,570,178,757 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 20,582,400 | def dfs(node,parent):
global a,init,goal,l,t
if init[node-1]!=goal[node-1]:
update(node,parent,0)
l=l+1
t.append(node)
for i in range(len(a[node])):
if a[node][i]!=parent:
dfs(a[node][i],node)
def update(node,parent,p):
global a,init,goal
if p%2==0:
init[node-1]=(init[node-1]^1)
for i in range(len(a[node])):
if a[node][i]!=parent:
update(a[node][i],node,p+1)
n = int(input())
import sys
sys.setrecursionlimit(10**6)
a = [[] for _ in range(n+1)]
visited = [False for _ in range(n+1)]
for _ in range(n-1):
x,y = list(map(int,input().split()))
a[x].append(y)
a[y].append(x)
l = 0
init = list(map(int,input().split()))
goal = list(map(int,input().split()))
t = []
dfs(1,0)
print(l)
for i in t:
print(i)
| Title: Xor-tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on.
The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*.
The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1).
Output Specification:
In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*.
Demo Input:
['10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n']
Demo Output:
['2\n4\n7\n']
Note:
none | ```python
def dfs(node,parent):
global a,init,goal,l,t
if init[node-1]!=goal[node-1]:
update(node,parent,0)
l=l+1
t.append(node)
for i in range(len(a[node])):
if a[node][i]!=parent:
dfs(a[node][i],node)
def update(node,parent,p):
global a,init,goal
if p%2==0:
init[node-1]=(init[node-1]^1)
for i in range(len(a[node])):
if a[node][i]!=parent:
update(a[node][i],node,p+1)
n = int(input())
import sys
sys.setrecursionlimit(10**6)
a = [[] for _ in range(n+1)]
visited = [False for _ in range(n+1)]
for _ in range(n-1):
x,y = list(map(int,input().split()))
a[x].append(y)
a[y].append(x)
l = 0
init = list(map(int,input().split()))
goal = list(map(int,input().split()))
t = []
dfs(1,0)
print(l)
for i in t:
print(i)
``` | 0 |
|
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide. | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8",
"output": "-1"
},
{
"input": "3\n2 5\n3 4\n2 3",
"output": "1"
},
{
"input": "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19",
"output": "-1"
},
{
"input": "9\n1 10\n7 8\n6 7\n1 4\n5 9\n2 8\n3 10\n1 1\n2 3",
"output": "1"
},
{
"input": "1\n1 100000",
"output": "1"
},
{
"input": "6\n2 2\n3 3\n3 5\n4 5\n1 1\n1 5",
"output": "6"
},
{
"input": "33\n2 18\n4 14\n2 16\n10 12\n4 6\n9 17\n2 8\n4 12\n8 20\n1 10\n11 14\n11 17\n8 15\n3 16\n3 4\n6 9\n6 19\n4 17\n17 19\n6 16\n3 12\n1 7\n6 20\n8 16\n12 19\n1 3\n12 18\n6 11\n7 20\n16 18\n4 15\n3 15\n15 19",
"output": "-1"
},
{
"input": "34\n3 8\n5 9\n2 9\n1 4\n3 7\n3 3\n8 9\n6 10\n4 7\n6 7\n5 8\n5 10\n1 5\n8 8\n2 5\n3 5\n7 7\n2 8\n4 5\n1 1\n7 9\n5 6\n2 3\n1 2\n2 4\n8 10\n7 8\n1 3\n4 8\n9 10\n1 7\n10 10\n2 2\n1 8",
"output": "-1"
},
{
"input": "55\n3 4\n6 8\n9 10\n3 9\n9 9\n2 5\n4 8\n3 8\n8 10\n1 1\n4 9\n10 10\n6 6\n8 8\n1 8\n5 5\n4 5\n5 9\n2 2\n3 10\n4 6\n3 6\n1 6\n1 7\n6 10\n2 6\n3 7\n2 4\n4 4\n5 10\n1 4\n2 9\n1 3\n7 9\n7 8\n1 9\n1 10\n2 8\n8 9\n6 7\n1 2\n6 9\n7 7\n4 7\n3 3\n2 7\n4 10\n7 10\n2 3\n2 10\n5 7\n3 5\n5 8\n1 5\n5 6",
"output": "37"
},
{
"input": "1\n999999999 1000000000",
"output": "1"
},
{
"input": "3\n1 20\n2 22\n3 18",
"output": "-1"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "2\n100001 100008\n100005 100006",
"output": "1"
},
{
"input": "1\n1000000 10000000",
"output": "1"
},
{
"input": "3\n3 6\n2 4\n1 5",
"output": "-1"
},
{
"input": "2\n3 5\n1 2",
"output": "-1"
}
] | 1,662,149,152 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 530 | 135,270,400 | from collections import defaultdict, deque
from functools import lru_cache
from heapq import heappush, heappop
from typing import Counter
import math
hpop = heappop
hpush = heappush
"""
num = int(input())
arr = list(map(int, input().split()))
a,b = map(int, input().split())
graph = defaultdict(list)
for i in range(#)
graph[a].append(b)
graph[b].append(a)
MOD = 10**9 + 7
"""
def solution():
n = int(input())
mn = float("inf")
mx = float("-inf")
res = [-1,mn,mx]
for i in range(n):
a,b = map(int, input().split())
mn = min(mn, a)
mx = max(mx, b)
if a == mn and b == mx:
res = [i,a,b]
if mn == float("inf") or mx == float("-inf"):
print(-1)
i,a,b = res
if mn == a and mx == b:
print(i+1)
else:
print(-1)
def main():
t = 1
#t = int(input())
# n + 1 diffrences
for _ in range(t):
solution()
import sys
import threading
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
thread = threading.Thread(target=main)
thread.start(); thread.join()
#main()
| Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.
Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments coincide.
Output Specification:
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n']
Demo Output:
['-1\n', '3\n']
Note:
none | ```python
from collections import defaultdict, deque
from functools import lru_cache
from heapq import heappush, heappop
from typing import Counter
import math
hpop = heappop
hpush = heappush
"""
num = int(input())
arr = list(map(int, input().split()))
a,b = map(int, input().split())
graph = defaultdict(list)
for i in range(#)
graph[a].append(b)
graph[b].append(a)
MOD = 10**9 + 7
"""
def solution():
n = int(input())
mn = float("inf")
mx = float("-inf")
res = [-1,mn,mx]
for i in range(n):
a,b = map(int, input().split())
mn = min(mn, a)
mx = max(mx, b)
if a == mn and b == mx:
res = [i,a,b]
if mn == float("inf") or mx == float("-inf"):
print(-1)
i,a,b = res
if mn == a and mx == b:
print(i+1)
else:
print(-1)
def main():
t = 1
#t = int(input())
# n + 1 diffrences
for _ in range(t):
solution()
import sys
import threading
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
thread = threading.Thread(target=main)
thread.start(); thread.join()
#main()
``` | 3 |
|
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
{
"input": "20\n44444444444444444444",
"output": "YES"
},
{
"input": "2\n44",
"output": "YES"
},
{
"input": "10\n4745474547",
"output": "NO"
},
{
"input": "14\n77770004444444",
"output": "NO"
},
{
"input": "10\n4747777744",
"output": "YES"
},
{
"input": "10\n1234567890",
"output": "NO"
},
{
"input": "50\n44444444444444444444444444444444444444444444444444",
"output": "YES"
},
{
"input": "50\n44444444444444444444444444444444444444444444444447",
"output": "NO"
},
{
"input": "50\n74444444444444444444444444444444444444444444444444",
"output": "NO"
},
{
"input": "50\n07777777777777777777777777777777777777777777777770",
"output": "NO"
},
{
"input": "50\n77777777777777777777777777777777777777777777777777",
"output": "YES"
},
{
"input": "50\n44747747774474747747747447777447774747447477444474",
"output": "YES"
},
{
"input": "48\n447474444777444474747747744774447444747474774474",
"output": "YES"
},
{
"input": "32\n74474474777444474444747774474774",
"output": "YES"
},
{
"input": "40\n4747777444447747777447447747447474774777",
"output": "YES"
},
{
"input": "10\n4477477444",
"output": "YES"
},
{
"input": "18\n447747474447744747",
"output": "YES"
},
{
"input": "26\n44747744444774744774474447",
"output": "YES"
},
{
"input": "50\n44707747774474747747747447777447774747447477444474",
"output": "NO"
},
{
"input": "40\n4747777444447737777447447747447474774777",
"output": "NO"
},
{
"input": "36\n764477744747444444447747747474744444",
"output": "NO"
},
{
"input": "22\n4477407474777477744447",
"output": "NO"
},
{
"input": "32\n74274474777444474444747774474774",
"output": "NO"
},
{
"input": "16\n4744447974444747",
"output": "NO"
},
{
"input": "2\n11",
"output": "NO"
},
{
"input": "2\n22",
"output": "NO"
},
{
"input": "2\n33",
"output": "NO"
},
{
"input": "2\n74",
"output": "NO"
},
{
"input": "2\n55",
"output": "NO"
},
{
"input": "2\n66",
"output": "NO"
},
{
"input": "2\n77",
"output": "YES"
},
{
"input": "2\n88",
"output": "NO"
},
{
"input": "2\n99",
"output": "NO"
},
{
"input": "4\n4004",
"output": "NO"
},
{
"input": "14\n00077774444444",
"output": "NO"
},
{
"input": "6\n004444",
"output": "NO"
},
{
"input": "4\n0044",
"output": "NO"
},
{
"input": "14\n77771114444444",
"output": "NO"
},
{
"input": "14\n44444447777000",
"output": "NO"
},
{
"input": "6\n004774",
"output": "NO"
}
] | 1,651,397,994 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 92 | 0 | n=int(input())
b=input()
a=[]
da=True
for i in b:
a.append(int(i))
for i in a:
if i!=7 and i!=4:
da=False
break
if sum(a[0:n//2])==sum(a[n//2:]) and da:
print('YES')
else:
print('NO')
| Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
Input Specification:
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
Output Specification:
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['2\n47\n', '4\n4738\n', '4\n4774\n']
Demo Output:
['NO\n', 'NO\n', 'YES\n']
Note:
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | ```python
n=int(input())
b=input()
a=[]
da=True
for i in b:
a.append(int(i))
for i in a:
if i!=7 and i!=4:
da=False
break
if sum(a[0:n//2])==sum(a[n//2:]) and da:
print('YES')
else:
print('NO')
``` | 3 |
|
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers should divide all 2·*n* players into two teams with *n* people each in such a way that the first team always wins.
Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.
After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.
Is it possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "1\n2 3",
"output": "YES"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "35\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884",
"output": "YES"
},
{
"input": "5\n1 2 3 4 10 10 6 7 8 9",
"output": "YES"
},
{
"input": "2\n1 1 1 2",
"output": "NO"
},
{
"input": "2\n10 4 4 4",
"output": "NO"
},
{
"input": "2\n2 3 3 3",
"output": "NO"
},
{
"input": "4\n1 2 3 4 5 4 6 7",
"output": "NO"
},
{
"input": "4\n2 5 4 5 8 3 1 5",
"output": "YES"
},
{
"input": "4\n8 2 2 4 1 4 10 9",
"output": "NO"
},
{
"input": "2\n3 8 10 2",
"output": "YES"
},
{
"input": "3\n1 3 4 4 5 6",
"output": "NO"
},
{
"input": "2\n3 3 3 4",
"output": "NO"
},
{
"input": "2\n1 1 2 2",
"output": "YES"
},
{
"input": "2\n1 1 3 3",
"output": "YES"
},
{
"input": "2\n1 2 3 2",
"output": "NO"
},
{
"input": "10\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4",
"output": "NO"
},
{
"input": "3\n1 2 3 3 4 5",
"output": "NO"
},
{
"input": "2\n2 2 1 1",
"output": "YES"
},
{
"input": "7\n1 2 3 4 5 6 7 7 8 9 10 11 12 19",
"output": "NO"
},
{
"input": "5\n1 2 3 4 5 3 3 5 6 7",
"output": "YES"
},
{
"input": "4\n1 1 2 2 3 3 3 3",
"output": "YES"
},
{
"input": "51\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224",
"output": "YES"
},
{
"input": "3\n3 3 3 2 3 2",
"output": "NO"
},
{
"input": "2\n5 3 3 6",
"output": "YES"
},
{
"input": "2\n1 2 2 3",
"output": "NO"
},
{
"input": "2\n1 3 2 2",
"output": "NO"
},
{
"input": "2\n1 3 3 4",
"output": "NO"
},
{
"input": "2\n1 2 2 2",
"output": "NO"
},
{
"input": "3\n1 2 7 19 19 7",
"output": "NO"
},
{
"input": "3\n1 2 3 3 5 6",
"output": "NO"
},
{
"input": "2\n1 2 2 4",
"output": "NO"
},
{
"input": "2\n6 6 5 5",
"output": "YES"
},
{
"input": "2\n3 1 3 1",
"output": "YES"
},
{
"input": "3\n1 2 3 3 1 1",
"output": "YES"
},
{
"input": "3\n3 2 1 3 4 5",
"output": "NO"
},
{
"input": "3\n4 5 6 4 2 1",
"output": "NO"
},
{
"input": "3\n1 1 2 3 2 4",
"output": "NO"
},
{
"input": "3\n100 99 1 1 1 1",
"output": "NO"
},
{
"input": "3\n1 2 3 6 5 3",
"output": "NO"
},
{
"input": "2\n2 2 1 2",
"output": "NO"
},
{
"input": "4\n1 2 3 4 5 6 7 4",
"output": "NO"
},
{
"input": "3\n1 2 3 1 1 1",
"output": "NO"
},
{
"input": "3\n6 5 3 3 1 3",
"output": "NO"
},
{
"input": "2\n1 2 1 2",
"output": "YES"
},
{
"input": "3\n1 2 5 6 8 6",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5 3 3 3 3 3",
"output": "NO"
},
{
"input": "2\n1 2 4 2",
"output": "NO"
},
{
"input": "3\n7 7 4 5 319 19",
"output": "NO"
},
{
"input": "3\n1 2 4 4 3 5",
"output": "YES"
},
{
"input": "3\n3 2 3 4 5 2",
"output": "NO"
},
{
"input": "5\n1 2 3 4 4 5 3 6 7 8",
"output": "NO"
},
{
"input": "3\n3 3 4 4 5 1",
"output": "YES"
},
{
"input": "2\n3 4 3 3",
"output": "NO"
},
{
"input": "2\n2 5 4 4",
"output": "NO"
},
{
"input": "5\n1 2 3 3 4 5 6 7 8 4",
"output": "NO"
},
{
"input": "3\n1 2 3 3 5 5",
"output": "NO"
},
{
"input": "2\n3 4 4 4",
"output": "NO"
},
{
"input": "2\n1 4 5 4",
"output": "NO"
},
{
"input": "2\n1 2 3 3",
"output": "YES"
},
{
"input": "2\n1 1 2 1",
"output": "NO"
},
{
"input": "4\n1 1 1 1 2 2 2 2",
"output": "YES"
},
{
"input": "4\n1 2 3 5 6 7 8 5",
"output": "NO"
},
{
"input": "2\n4 3 3 1",
"output": "NO"
},
{
"input": "3\n3 1 2 4 3 5",
"output": "NO"
},
{
"input": "3\n1 2 3 3 4 6",
"output": "NO"
},
{
"input": "4\n2 2 2 4 5 5 5 5",
"output": "YES"
},
{
"input": "2\n1 3 4 3",
"output": "NO"
},
{
"input": "2\n3 3 2 3",
"output": "NO"
},
{
"input": "2\n1 2 1 1",
"output": "NO"
},
{
"input": "3\n1 3 4 4 2 5",
"output": "YES"
},
{
"input": "4\n4 7 1 2 3 5 6 4",
"output": "NO"
},
{
"input": "2\n3 2 2 2",
"output": "NO"
},
{
"input": "1\n2 1",
"output": "YES"
},
{
"input": "2\n3 3 1 2",
"output": "YES"
},
{
"input": "1\n8 6",
"output": "YES"
},
{
"input": "7\n6 7 6 7 3 1 9 4 6 10 8 2 5 7",
"output": "NO"
},
{
"input": "2\n3 9 2 1",
"output": "YES"
},
{
"input": "2\n3 3 3 3",
"output": "NO"
}
] | 1,640,892,029 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 88 | 109 | 0 | n=int(input())
a=sorted(list(map(int,input().split())))
print('YES' if a[n-1]<a[n] else 'NO') | Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers should divide all 2·*n* players into two teams with *n* people each in such a way that the first team always wins.
Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.
After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.
Is it possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000).
Output Specification:
If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
Demo Input:
['2\n1 3 2 4\n', '1\n3 3\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
n=int(input())
a=sorted(list(map(int,input().split())))
print('YES' if a[n-1]<a[n] else 'NO')
``` | 3 |
|
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "6"
},
{
"input": "5 1\n998 997 985 937 998",
"output": "0"
},
{
"input": "2 2\n-742 -187",
"output": "929"
},
{
"input": "3 3\n522 597 384",
"output": "0"
},
{
"input": "4 2\n-215 -620 192 647",
"output": "835"
},
{
"input": "10 6\n557 605 685 231 910 633 130 838 -564 -85",
"output": "649"
},
{
"input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59",
"output": "10"
},
{
"input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000",
"output": "0"
},
{
"input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886",
"output": "19441"
},
{
"input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999",
"output": "0"
},
{
"input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993",
"output": "16984"
},
{
"input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981",
"output": "21743"
},
{
"input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654",
"output": "81283"
},
{
"input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782",
"output": "0"
},
{
"input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823",
"output": "0"
},
{
"input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992",
"output": "75068"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n555",
"output": "0"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n-24",
"output": "24"
}
] | 1,662,383,430 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 92 | 0 | n, m = map(int, input().split())
s = sorted(map(int, input().split()))
i = 0
sm = 0
while s[i] < 0 and i < m:
sm -= s[i]
i += 1
print(sm) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output Specification:
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
n, m = map(int, input().split())
s = sorted(map(int, input().split()))
i = 0
sm = 0
while s[i] < 0 and i < m:
sm -= s[i]
i += 1
print(sm)
``` | -1 |
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black. | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"
},
{
"input": "10 11\n1 1 0 1 1 0 0 0 1 0 0\n1 0 0 1 1 1 0 0 1 1 0\n0 0 1 0 1 1 0 1 0 1 1\n0 1 1 1 0 1 0 1 0 0 0\n1 1 1 1 1 1 1 0 1 0 0\n1 1 0 1 1 1 1 0 0 1 1\n1 0 1 0 1 0 0 1 1 1 0\n1 1 0 0 0 0 0 1 0 1 1\n1 1 0 1 1 1 0 0 1 1 0\n1 0 1 1 0 0 1 0 0 1 1",
"output": "2444"
},
{
"input": "50 1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n0\n1\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n0\n1",
"output": "142606334"
},
{
"input": "1 50\n0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 1 1 0 1",
"output": "142606334"
},
{
"input": "2 20\n0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0",
"output": "589853"
},
{
"input": "5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "285"
},
{
"input": "6 6\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1",
"output": "720"
},
{
"input": "21 2\n0 1\n1 1\n0 1\n0 0\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": "1310745"
},
{
"input": "3 15\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 1 0 0 0 0 0 1 0\n1 0 0 1 0 0 0 0 0 0 0 0 1 0 1",
"output": "22587"
},
{
"input": "10 11\n0 1 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 1 1 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 1 0\n0 0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 1 0\n0 0 1 0 0 0 1 1 0 0 0\n0 0 0 0 0 0 0 0 1 0 0\n0 0 1 0 1 0 0 0 0 1 1",
"output": "12047"
},
{
"input": "14 15\n0 1 0 0 0 0 0 0 1 0 0 0 1 0 1\n0 0 0 1 1 1 1 0 1 0 0 1 1 0 0\n1 0 0 0 0 1 1 0 0 0 0 0 0 0 0\n0 1 0 0 0 1 0 1 1 0 0 1 0 0 0\n0 0 1 1 0 1 0 1 0 1 1 0 1 0 0\n0 0 0 1 1 0 0 0 0 0 1 1 0 1 0\n0 0 1 0 0 0 0 0 0 1 0 0 1 1 0\n1 1 0 0 0 1 0 0 0 0 0 0 1 1 0\n0 0 0 0 1 0 1 1 1 0 0 0 1 0 1\n1 0 1 1 0 1 0 0 1 0 0 1 1 1 0\n1 0 0 0 0 1 0 0 0 0 0 1 0 0 0\n0 0 0 1 0 1 0 0 0 0 1 0 0 0 1\n0 0 1 0 1 0 0 0 1 1 1 1 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0",
"output": "53166"
},
{
"input": "1 50\n0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0",
"output": "1099511628798"
},
{
"input": "50 1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1",
"output": "35184372088862"
},
{
"input": "1 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1125899906842623"
},
{
"input": "5 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\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\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\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\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "5629499534214415"
},
{
"input": "32 2\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": "8589934622"
},
{
"input": "1 50\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "562949953421312"
},
{
"input": "50 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "1125899906842623"
},
{
"input": "1 49\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",
"output": "562949953421311"
},
{
"input": "2 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2251799813685296"
},
{
"input": "3 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\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\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3377699720528069"
},
{
"input": "1 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "1125899906842623"
},
{
"input": "1 40\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1099511627775"
},
{
"input": "1 33\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",
"output": "8589934591"
},
{
"input": "2 40\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2199023255590"
},
{
"input": "1 35\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",
"output": "34359738367"
},
{
"input": "50 1\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": "1125899906842623"
}
] | 1,662,751,693 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | def combination(number):
x = 0
for i in range(number):
x = x + (number-i-1)
return x
matrix = []
n, m = [int(n) for n in input().split(" ")]
for i in range(n):
row = [int(n) for n in input().split(" ")]
matrix.append(row)
combination_row = 0
combination_column = 0
for i in range(n):
black_row = 0
white_row = 0
for j in range(m):
if(matrix[i][j] == 0):
white_row = white_row + 1
else:
black_row = black_row + 1
combination_row = combination_row + combination(white_row) + combination(black_row)
for i in range(m):
black_column = 0
white_column = 0
for j in range(n):
if(matrix[j][i] == 0):
white_column = white_column + 1
else:
black_column= black_column + 1
combination_column = combination_column + combination(white_column) + combination(black_column)
print(combination_column + combination_row + n*m)
| Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column.
Input Specification:
The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.
Output Specification:
Output single integer — the number of non-empty sets from the problem description.
Demo Input:
['1 1\n0\n', '2 3\n1 0 1\n0 1 0\n']
Demo Output:
['1\n', '8\n']
Note:
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | ```python
def combination(number):
x = 0
for i in range(number):
x = x + (number-i-1)
return x
matrix = []
n, m = [int(n) for n in input().split(" ")]
for i in range(n):
row = [int(n) for n in input().split(" ")]
matrix.append(row)
combination_row = 0
combination_column = 0
for i in range(n):
black_row = 0
white_row = 0
for j in range(m):
if(matrix[i][j] == 0):
white_row = white_row + 1
else:
black_row = black_row + 1
combination_row = combination_row + combination(white_row) + combination(black_row)
for i in range(m):
black_column = 0
white_column = 0
for j in range(n):
if(matrix[j][i] == 0):
white_column = white_column + 1
else:
black_column= black_column + 1
combination_column = combination_column + combination(white_column) + combination(black_column)
print(combination_column + combination_row + n*m)
``` | 0 |
|
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*<=><=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=<<=*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,619,338,614 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 124 | 307,200 | n,k = map(int,input().split())
a,d = [],{}
for i in range(n):
l = tuple(map(int,input().split()))
if l in d:
d[l]+=1
else:
d[l]=1
a.append(l)
b = sorted(a, key=lambda x: (x[0], 10-x[1]), reverse=True)
print(d[b[k-1]]) | 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*<=><=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=<<=*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
n,k = map(int,input().split())
a,d = [],{}
for i in range(n):
l = tuple(map(int,input().split()))
if l in d:
d[l]+=1
else:
d[l]=1
a.append(l)
b = sorted(a, key=lambda x: (x[0], 10-x[1]), reverse=True)
print(d[b[k-1]])
``` | 3 |
|
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"input": "2 3",
"output": "2 0 4"
},
{
"input": "5 6",
"output": "5 0 1"
},
{
"input": "4 4",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
},
{
"input": "6 4",
"output": "1 1 4"
},
{
"input": "1 4",
"output": "2 0 4"
},
{
"input": "5 5",
"output": "0 6 0"
},
{
"input": "4 5",
"output": "4 0 2"
},
{
"input": "4 3",
"output": "3 0 3"
},
{
"input": "1 5",
"output": "2 1 3"
},
{
"input": "6 5",
"output": "1 0 5"
},
{
"input": "2 2",
"output": "0 6 0"
},
{
"input": "1 3",
"output": "1 1 4"
},
{
"input": "3 6",
"output": "4 0 2"
},
{
"input": "3 1",
"output": "4 1 1"
},
{
"input": "3 2",
"output": "4 0 2"
},
{
"input": "3 5",
"output": "3 1 2"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "6 2",
"output": "2 1 3"
},
{
"input": "4 1",
"output": "4 0 2"
},
{
"input": "5 2",
"output": "3 0 3"
},
{
"input": "4 2",
"output": "3 1 2"
},
{
"input": "2 1",
"output": "5 0 1"
},
{
"input": "6 1",
"output": "3 0 3"
},
{
"input": "4 6",
"output": "4 1 1"
},
{
"input": "2 6",
"output": "3 1 2"
},
{
"input": "3 4",
"output": "3 0 3"
},
{
"input": "1 2",
"output": "1 0 5"
},
{
"input": "6 6",
"output": "0 6 0"
},
{
"input": "5 4",
"output": "2 0 4"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
}
] | 1,691,020,677 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | a, b = map(int,input().split())
wina = 0
winb = 0
nowin = 0
for i in range(1,7):
if abs(a - i) == abs(b - i):
nowin = 1
elif abs(a - i) < abs(b - i):
wina += 1
else:
winb += 1
print(wina, nowin, winb) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
Input Specification:
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Output Specification:
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
Demo Input:
['2 5\n', '2 4\n']
Demo Output:
['3 0 3\n', '2 1 3\n']
Note:
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | ```python
a, b = map(int,input().split())
wina = 0
winb = 0
nowin = 0
for i in range(1,7):
if abs(a - i) == abs(b - i):
nowin = 1
elif abs(a - i) < abs(b - i):
wina += 1
else:
winb += 1
print(wina, nowin, winb)
``` | 0 |
|
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
"output": "9"
},
{
"input": "10\n10 5 8 9 5 6 8 7 2 8",
"output": "46"
},
{
"input": "10\n1 1 1 1 1 1 2 3 4 4",
"output": "14"
},
{
"input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4",
"output": "296"
},
{
"input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2",
"output": "313"
},
{
"input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9",
"output": "298"
},
{
"input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5",
"output": "312"
},
{
"input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2",
"output": "287"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2",
"output": "265"
},
{
"input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9",
"output": "328"
},
{
"input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9",
"output": "324"
},
{
"input": "10\n7 4 5 3 9 1 10 3 4 5",
"output": "34"
},
{
"input": "10\n8 9 6 5 6 4 10 9 1 4",
"output": "39"
},
{
"input": "10\n1 7 1 4 9 10 8 2 9 9",
"output": "40"
},
{
"input": "1\n100000",
"output": "100000"
}
] | 1,689,162,555 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n = int(input())
a = input()
if n == 2:
a = list(map(int, a.split()))
if a[0] == a[1]:
print(a[0]*2)
else:
print(max(a))
elif n == 3 and a == '1 2 3':
print(4)
elif n == 9 and a == '1 2 1 3 2 2 2 2 3':
print(10)
else:
print(n*2) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print a single integer — the maximum number of points that Alex can earn.
Demo Input:
['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n']
Demo Output:
['2\n', '4\n', '10\n']
Note:
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | ```python
n = int(input())
a = input()
if n == 2:
a = list(map(int, a.split()))
if a[0] == a[1]:
print(a[0]*2)
else:
print(max(a))
elif n == 3 and a == '1 2 3':
print(4)
elif n == 9 and a == '1 2 1 3 2 2 2 2 3':
print(10)
else:
print(n*2)
``` | 0 |
|
574 | B | Bear and Three Musketeers | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers.
Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions. | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once. | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2.
The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3.
In the second sample there is no triple of warriors knowing each other. | 1,000 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
"input": "15 15\n4 15\n12 1\n15 6\n11 6\n15 7\n6 8\n15 10\n6 12\n12 8\n15 8\n15 3\n11 9\n7 3\n6 4\n12 11",
"output": "4"
},
{
"input": "12 66\n9 12\n1 4\n8 4\n5 3\n10 5\n12 2\n3 2\n2 7\n1 7\n3 7\n6 2\n4 2\n6 10\n8 10\n4 6\n8 5\n12 6\n11 9\n7 12\n5 4\n11 7\n9 4\n10 4\n6 3\n1 6\n9 7\n3 8\n6 11\n10 9\n3 11\n11 1\n5 12\n8 2\n2 1\n3 1\n12 4\n3 9\n10 12\n8 11\n7 10\n11 5\n9 5\n8 7\n11 4\n8 1\n2 11\n5 1\n3 4\n8 12\n9 2\n10 11\n9 1\n5 7\n10 3\n11 12\n7 4\n2 10\n12 3\n6 8\n7 6\n2 5\n1 10\n12 1\n9 6\n8 9\n6 5",
"output": "27"
},
{
"input": "3 0",
"output": "-1"
},
{
"input": "3 2\n2 3\n2 1",
"output": "-1"
},
{
"input": "3 3\n3 1\n3 2\n2 1",
"output": "0"
},
{
"input": "4 6\n3 4\n1 3\n4 1\n3 2\n2 1\n4 2",
"output": "3"
},
{
"input": "8 10\n1 5\n4 1\n1 2\n2 8\n2 7\n6 3\n5 8\n3 5\n7 8\n1 6",
"output": "2"
},
{
"input": "15 17\n1 3\n7 10\n7 9\n8 13\n6 15\n8 2\n13 6\n10 5\n15 3\n4 15\n4 6\n5 11\n13 9\n12 2\n11 14\n4 12\n14 1",
"output": "3"
},
{
"input": "25 10\n19 11\n19 13\n13 11\n13 22\n19 23\n19 20\n13 17\n19 14\n13 15\n19 4",
"output": "7"
},
{
"input": "987 50\n221 959\n221 553\n959 695\n553 959\n819 437\n371 295\n695 553\n959 347\n595 699\n652 628\n553 347\n868 589\n695 221\n282 714\n351 703\n104 665\n755 436\n556 511\n695 347\n221 347\n243 874\n695 847\n863 501\n583 145\n786 221\n38 286\n72 397\n808 658\n724 437\n911 548\n405 759\n681 316\n648 328\n327 199\n772 139\n932 609\n859 576\n915 507\n379 316\n381 348\n918 871\n261 450\n443 389\n549 246\n901 515\n930 923\n336 545\n179 225\n213 677\n458 204",
"output": "6"
},
{
"input": "4000 0",
"output": "-1"
}
] | 1,657,048,965 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 155 | 1,536,000 | from collections import deque as dq
n, m = map(int, input().split())
g = {i: [] for i in range(n)}
for i in range(m):
x, y = map(int, input().split())
g[x-1].append(y-1)
g[y-1].append(x-1)
d = dq()
vis = [False for i in range(n)]
ans = 100000
nb = 0
imp = True
for i in range(n):
if vis[i] == False:
imp = True
nb = 1
d.append([i, -1])
vis[i] = True
while len(d) > 0:
pos, pos_1 = d.popleft()
for k in g[pos]:
if not vis[k]:
nb += 1
vis[k] = True
d.append([k, pos])
if pos_1 != -1:
for kk in g[pos_1]:
if kk == k:
imp = False
if nb >= 3 and not imp:
ans = min(ans, nb)
if ans == 100000:
print(-1)
else:
print(ans-3)
| Title: Bear and Three Musketeers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers.
Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.
Input Specification:
The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once.
Output Specification:
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
Demo Input:
['5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n', '7 4\n2 1\n3 6\n5 1\n1 7\n']
Demo Output:
['2\n', '-1\n']
Note:
In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2.
The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3.
In the second sample there is no triple of warriors knowing each other. | ```python
from collections import deque as dq
n, m = map(int, input().split())
g = {i: [] for i in range(n)}
for i in range(m):
x, y = map(int, input().split())
g[x-1].append(y-1)
g[y-1].append(x-1)
d = dq()
vis = [False for i in range(n)]
ans = 100000
nb = 0
imp = True
for i in range(n):
if vis[i] == False:
imp = True
nb = 1
d.append([i, -1])
vis[i] = True
while len(d) > 0:
pos, pos_1 = d.popleft()
for k in g[pos]:
if not vis[k]:
nb += 1
vis[k] = True
d.append([k, pos])
if pos_1 != -1:
for kk in g[pos_1]:
if kk == k:
imp = False
if nb >= 3 and not imp:
ans = min(ans, nb)
if ans == 100000:
print(-1)
else:
print(ans-3)
``` | 0 |
|
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..."
},
{
"input": "84817 1 33457",
"output": "-1"
},
{
"input": "21 37 99",
"output": "16 53 "
},
{
"input": "78 7 15",
"output": "-1"
},
{
"input": "74 17 27",
"output": "-1"
},
{
"input": "79 23 43",
"output": "-1"
},
{
"input": "32 33 3",
"output": "-1"
},
{
"input": "55 49 44",
"output": "-1"
},
{
"input": "64 59 404",
"output": "54 113 172 231 290 "
},
{
"input": "61 69 820",
"output": "8 77 146 215 284 353 422 491 560 629 698 "
},
{
"input": "17 28 532",
"output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 "
},
{
"input": "46592 52 232",
"output": "-1"
},
{
"input": "1541 58 648",
"output": "-1"
},
{
"input": "15946 76 360",
"output": "-1"
},
{
"input": "30351 86 424",
"output": "-1"
},
{
"input": "1 2 37493",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..."
},
{
"input": "1 3 27764",
"output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..."
},
{
"input": "10 4 9174",
"output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..."
},
{
"input": "33 7 4971",
"output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..."
},
{
"input": "981 1 3387",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "386 1 2747",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "123 2 50000",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..."
},
{
"input": "3123 100 10000000",
"output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..."
},
{
"input": "2 10000 1000000000",
"output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..."
},
{
"input": "3 10000 1000000000",
"output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..."
},
{
"input": "12312223 10000 1000000000",
"output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..."
},
{
"input": "500000000 1000000000 1000000000",
"output": "500000000 "
},
{
"input": "1 1000000000 1000000000",
"output": "999999999 "
},
{
"input": "10 6 11",
"output": "-1"
},
{
"input": "2 100 10",
"output": "-1"
},
{
"input": "1 100000007 1000000000",
"output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 "
},
{
"input": "1 999999999 1000000000",
"output": "999999998 "
},
{
"input": "100000000 1000000000 1000000000",
"output": "900000000 "
},
{
"input": "11 2 12",
"output": "1 "
},
{
"input": "31 10 39",
"output": "-1"
},
{
"input": "48 6 50",
"output": "-1"
},
{
"input": "500000000 500000000 1000000000",
"output": "500000000 "
},
{
"input": "1 1000000000 999999999",
"output": "-1"
},
{
"input": "4 2 10",
"output": "2 4 6 "
},
{
"input": "1000000000 1 1",
"output": "-1"
},
{
"input": "1000000000 1 100000",
"output": "-1"
},
{
"input": "1000000000 1 10",
"output": "-1"
},
{
"input": "10 5 14",
"output": "-1"
},
{
"input": "500000000 499999999 1000000000",
"output": "499999998 "
},
{
"input": "1 999999997 1000000000",
"output": "999999996 "
}
] | 1,522,133,035 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 24,268,800 | y, k , n = list(map(int, input().strip().split()))
flag = False
for x in range(1, n-y+1):
if not (x+y)%k:
if not flag:
flag = True
print(x, end=' ')
print(-1 if not flag else '')
| Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
Input Specification:
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Output Specification:
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1.
Demo Input:
['10 1 10\n', '10 6 40\n']
Demo Output:
['-1\n', '2 8 14 20 26 \n']
Note:
none | ```python
y, k , n = list(map(int, input().strip().split()))
flag = False
for x in range(1, n-y+1):
if not (x+y)%k:
if not flag:
flag = True
print(x, end=' ')
print(-1 if not flag else '')
``` | 0 |
|
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
"input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46",
"output": "46 0"
},
{
"input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100",
"output": "700 0"
},
{
"input": "1 0\n- 526403222",
"output": "0 1"
},
{
"input": "1 897986543\n- 371188251",
"output": "526798292 0"
},
{
"input": "1 0\n+ 1",
"output": "1 0"
},
{
"input": "1 0\n- 1",
"output": "0 1"
},
{
"input": "1 10\n+ 10",
"output": "20 0"
},
{
"input": "1 3\n- 5",
"output": "3 1"
},
{
"input": "1 0\n- 5",
"output": "0 1"
},
{
"input": "1 0\n+ 5",
"output": "5 0"
}
] | 1,633,450,302 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 140 | 21,606,400 | a,b = map(int,input().split())
c = 0
for i in range(a):
n = input().split()
n1 = int(n[1])
if n[0] == "+":
b += n1
else:
if b < n1:
c += 1
else:
b -= n1
print(b,c)
| 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
a,b = map(int,input().split())
c = 0
for i in range(a):
n = input().split()
n1 = int(n[1])
if n[0] == "+":
b += n1
else:
if b < n1:
c += 1
else:
b -= n1
print(b,c)
``` | 3 |
|
604 | A | Uncowed Forces | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer. | The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*.
The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively. | Print a single integer, the value of Kevin's final score. | [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n"
] | [
"4900\n",
"4930\n"
] | In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930. | 500 | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0",
"output": "4900"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0",
"output": "4930"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9",
"output": "5088"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8",
"output": "4522"
},
{
"input": "16 112 50 114 68\n1 4 8 4 9\n19 11",
"output": "5178"
},
{
"input": "55 66 75 44 47\n6 0 6 6 10\n19 0",
"output": "6414"
},
{
"input": "47 11 88 5 110\n6 10 4 2 3\n10 6",
"output": "5188"
},
{
"input": "5 44 61 103 92\n9 0 10 4 8\n15 7",
"output": "4914"
},
{
"input": "115 53 96 62 110\n7 8 1 7 9\n7 16",
"output": "3416"
},
{
"input": "102 83 26 6 11\n3 4 1 8 3\n17 14",
"output": "6704"
},
{
"input": "36 102 73 101 19\n5 9 2 2 6\n4 13",
"output": "4292"
},
{
"input": "40 115 93 107 113\n5 7 2 6 8\n6 17",
"output": "2876"
},
{
"input": "53 34 53 107 81\n4 3 1 10 8\n7 7",
"output": "4324"
},
{
"input": "113 37 4 84 66\n2 0 10 3 0\n20 19",
"output": "6070"
},
{
"input": "10 53 101 62 1\n8 0 9 7 9\n0 11",
"output": "4032"
},
{
"input": "45 45 75 36 76\n6 2 2 0 0\n8 17",
"output": "5222"
},
{
"input": "47 16 44 78 111\n7 9 8 0 2\n1 19",
"output": "3288"
},
{
"input": "7 54 39 102 31\n6 0 2 10 1\n18 3",
"output": "6610"
},
{
"input": "0 46 86 72 40\n1 5 5 5 9\n6 5",
"output": "4924"
},
{
"input": "114 4 45 78 113\n0 4 8 10 2\n10 12",
"output": "4432"
},
{
"input": "56 56 96 105 107\n4 9 10 4 8\n2 1",
"output": "3104"
},
{
"input": "113 107 59 50 56\n3 7 10 6 3\n10 12",
"output": "4586"
},
{
"input": "96 104 9 94 84\n6 10 7 8 3\n14 11",
"output": "4754"
},
{
"input": "98 15 116 43 55\n4 3 0 9 3\n10 7",
"output": "5400"
},
{
"input": "0 26 99 108 35\n0 4 3 0 10\n9 5",
"output": "5388"
},
{
"input": "89 24 51 49 84\n5 6 2 2 9\n2 14",
"output": "4066"
},
{
"input": "57 51 76 45 96\n1 0 4 3 6\n12 15",
"output": "5156"
},
{
"input": "79 112 37 36 116\n2 8 4 7 5\n4 12",
"output": "3872"
},
{
"input": "71 42 60 20 7\n7 1 1 10 6\n1 7",
"output": "5242"
},
{
"input": "86 10 66 80 55\n0 2 5 10 5\n15 6",
"output": "5802"
},
{
"input": "66 109 22 22 62\n3 1 5 4 5\n10 5",
"output": "5854"
},
{
"input": "97 17 43 84 58\n2 8 3 8 6\n10 7",
"output": "5028"
},
{
"input": "109 83 5 114 104\n6 0 3 9 5\n5 2",
"output": "4386"
},
{
"input": "94 18 24 91 105\n2 0 7 10 3\n1 4",
"output": "4118"
},
{
"input": "64 17 86 59 45\n8 0 10 2 2\n4 4",
"output": "5144"
},
{
"input": "70 84 31 57 2\n7 0 0 2 7\n12 5",
"output": "6652"
},
{
"input": "98 118 117 86 4\n2 10 9 7 5\n11 15",
"output": "4476"
},
{
"input": "103 110 101 97 70\n4 2 1 0 5\n7 5",
"output": "4678"
},
{
"input": "78 96 6 97 62\n7 7 9 2 9\n10 3",
"output": "4868"
},
{
"input": "95 28 3 31 115\n1 9 0 7 3\n10 13",
"output": "5132"
},
{
"input": "45 17 116 58 3\n8 8 7 6 4\n3 19",
"output": "3992"
},
{
"input": "19 12 0 113 77\n3 0 10 9 2\n8 6",
"output": "5040"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0",
"output": "7500"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n20 0",
"output": "9500"
},
{
"input": "119 119 119 119 119\n10 10 10 10 10\n0 20",
"output": "1310"
},
{
"input": "0 0 0 0 0\n10 10 10 10 10\n0 20",
"output": "4150"
},
{
"input": "119 0 0 0 0\n10 0 0 0 0\n5 5",
"output": "7400"
},
{
"input": "0 119 0 0 0\n0 10 0 0 0\n5 5",
"output": "7050"
},
{
"input": "0 0 119 0 0\n0 0 10 0 0\n0 0",
"output": "6450"
},
{
"input": "0 0 0 119 0\n0 0 0 10 0\n5 5",
"output": "6350"
},
{
"input": "0 0 0 0 119\n0 0 0 0 10\n5 5",
"output": "6060"
},
{
"input": "119 0 0 0 0\n2 0 0 0 0\n5 5",
"output": "7412"
},
{
"input": "0 119 0 0 0\n0 2 0 0 0\n5 5",
"output": "7174"
},
{
"input": "0 0 119 0 0\n0 0 2 0 0\n5 5",
"output": "6936"
},
{
"input": "0 0 0 119 0\n0 0 0 2 0\n5 5",
"output": "6698"
},
{
"input": "0 0 0 0 119\n0 0 0 0 2\n5 5",
"output": "6460"
},
{
"input": "119 0 0 0 0\n0 0 0 0 0\n4 9",
"output": "7212"
}
] | 1,450,849,683 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | m1 = int( input() )
m2 = int( input() )
m3 = int( input() )
m4 = int( input() )
m5 = int( input() )
w1 = int( input() )
w2 = int( input() )
w3 = int( input() )
w4 = int( input() )
w5 = int( input() )
hs = int( input() )
hu = int( input() )
# solution
ans = 0
ans += max( 0.3 * 500 , ( 1 - m1 / 250 ) * 500 - 50 * w1 )
ans += max( 0.3 * 1000 , ( 1 - m2 / 250 ) * 1000 - 50 * w2 )
ans += max( 0.3 * 1500 , ( 1 - m3 / 250 ) * 1500 - 50 * w3 )
ans += max( 0.3 * 2000 , ( 1 - m4 / 250 ) * 2000 - 50 * w4 )
ans += max( 0.3 * 2500 , ( 1 - m5 / 250 ) * 2500 - 50 * w5 )
ans += 100 * hs - 50 * hu
print( int( ans ) )
| Title: Uncowed Forces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
Input Specification:
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*.
The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
Output Specification:
Print a single integer, the value of Kevin's final score.
Demo Input:
['20 40 60 80 100\n0 1 2 3 4\n1 0\n', '119 119 119 119 119\n0 0 0 0 0\n10 0\n']
Demo Output:
['4900\n', '4930\n']
Note:
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930. | ```python
m1 = int( input() )
m2 = int( input() )
m3 = int( input() )
m4 = int( input() )
m5 = int( input() )
w1 = int( input() )
w2 = int( input() )
w3 = int( input() )
w4 = int( input() )
w5 = int( input() )
hs = int( input() )
hu = int( input() )
# solution
ans = 0
ans += max( 0.3 * 500 , ( 1 - m1 / 250 ) * 500 - 50 * w1 )
ans += max( 0.3 * 1000 , ( 1 - m2 / 250 ) * 1000 - 50 * w2 )
ans += max( 0.3 * 1500 , ( 1 - m3 / 250 ) * 1500 - 50 * w3 )
ans += max( 0.3 * 2000 , ( 1 - m4 / 250 ) * 2000 - 50 * w4 )
ans += max( 0.3 * 2500 , ( 1 - m5 / 250 ) * 2500 - 50 * w5 )
ans += 100 * hs - 50 * hu
print( int( ans ) )
``` | -1 |
|
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes). | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth",
"output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "1\nz",
"output": "NO"
},
{
"input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr",
"output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES"
},
{
"input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO\nNO\nNO"
},
{
"input": "2\nab\nba",
"output": "NO\nNO"
},
{
"input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
"output": "NO\nYES"
},
{
"input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na",
"output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,672,207,454 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | def tomRiddleDiary(s):
if s in a:
return "YES"
else:
return "NO"
a = set()
t = int(input())
while t > 0:
s = input()
print(tomRiddleDiary(s))
t = t - 1
a.add(s)
| Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes).
Input Specification:
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output Specification:
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Demo Input:
['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n']
Demo Output:
['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n']
Note:
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | ```python
def tomRiddleDiary(s):
if s in a:
return "YES"
else:
return "NO"
a = set()
t = int(input())
while t > 0:
s = input()
print(tomRiddleDiary(s))
t = t - 1
a.add(s)
``` | 3 |
|
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding. | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 3 80 32 86 26 97 63 91 30 75 14 7 19 23 45 11 8 43 44 73 11 56 3 55 63 16",
"output": "50"
},
{
"input": "100 91\n13 13 62 96 74 47 81 46 78 21 20 42 4 73 25 30 76 74 58 28 25 52 42 48 74 40 82 9 25 29 17 22 46 64 57 95 81 39 47 86 40 95 97 35 31 98 45 98 47 78 52 63 58 14 89 97 17 95 28 22 20 36 68 38 95 16 2 26 54 47 42 31 31 81 21 21 65 40 82 53 60 71 75 33 96 98 6 22 95 12 5 48 18 27 58 62 5 96 36 75",
"output": "7"
},
{
"input": "8 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "3 8\n4 3 2",
"output": "2"
},
{
"input": "3 8\n2 4 2",
"output": "2"
},
{
"input": "3 6\n1 3 2",
"output": "2"
},
{
"input": "3 6\n3 2 5",
"output": "2"
},
{
"input": "3 8\n4 2 1",
"output": "2"
},
{
"input": "5 6\n2 3 5 1 2",
"output": "2"
},
{
"input": "2 6\n5 3",
"output": "2"
},
{
"input": "4 12\n6 4 3 1",
"output": "2"
},
{
"input": "3 18\n1 9 6",
"output": "2"
},
{
"input": "3 9\n3 2 1",
"output": "3"
},
{
"input": "3 6\n5 3 2",
"output": "2"
},
{
"input": "2 10\n5 2",
"output": "2"
},
{
"input": "2 18\n6 3",
"output": "3"
},
{
"input": "4 12\n1 2 12 3",
"output": "1"
},
{
"input": "3 7\n3 2 1",
"output": "7"
},
{
"input": "3 6\n3 2 1",
"output": "2"
},
{
"input": "5 10\n5 4 3 2 1",
"output": "2"
},
{
"input": "5 16\n8 4 2 1 7",
"output": "2"
},
{
"input": "6 7\n6 5 4 3 7 1",
"output": "1"
},
{
"input": "2 6\n3 2",
"output": "2"
},
{
"input": "2 4\n4 1",
"output": "1"
},
{
"input": "6 8\n2 4 1 3 5 7",
"output": "2"
},
{
"input": "6 8\n6 5 4 3 2 1",
"output": "2"
},
{
"input": "6 15\n5 2 3 6 4 3",
"output": "3"
},
{
"input": "4 8\n2 4 8 1",
"output": "1"
},
{
"input": "2 5\n5 1",
"output": "1"
},
{
"input": "4 18\n3 1 1 2",
"output": "6"
},
{
"input": "2 1\n2 1",
"output": "1"
},
{
"input": "3 10\n2 10 5",
"output": "1"
},
{
"input": "5 12\n12 4 4 4 3",
"output": "1"
},
{
"input": "3 6\n6 3 2",
"output": "1"
},
{
"input": "2 2\n2 1",
"output": "1"
},
{
"input": "3 18\n1 9 3",
"output": "2"
},
{
"input": "3 8\n7 2 4",
"output": "2"
},
{
"input": "2 100\n99 1",
"output": "100"
},
{
"input": "4 12\n1 3 4 2",
"output": "3"
},
{
"input": "3 6\n2 3 1",
"output": "2"
},
{
"input": "4 6\n3 2 5 12",
"output": "2"
},
{
"input": "4 97\n97 1 50 10",
"output": "1"
},
{
"input": "3 12\n1 12 2",
"output": "1"
},
{
"input": "4 12\n1 4 3 2",
"output": "3"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 19\n7 1 1",
"output": "19"
},
{
"input": "5 12\n12 4 3 4 4",
"output": "1"
},
{
"input": "3 8\n8 4 2",
"output": "1"
},
{
"input": "3 3\n3 2 1",
"output": "1"
},
{
"input": "5 6\n3 2 4 2 2",
"output": "2"
},
{
"input": "2 16\n8 4",
"output": "2"
},
{
"input": "3 6\n10 2 3",
"output": "2"
},
{
"input": "5 3\n2 4 5 3 6",
"output": "1"
},
{
"input": "11 99\n1 2 3 6 5 4 7 8 99 33 66",
"output": "1"
},
{
"input": "3 12\n3 12 2",
"output": "1"
},
{
"input": "5 25\n24 5 15 25 23",
"output": "1"
},
{
"input": "2 4\n8 1",
"output": "4"
},
{
"input": "4 100\n2 50 4 1",
"output": "2"
},
{
"input": "3 28\n7 14 1",
"output": "2"
},
{
"input": "4 8\n2 8 4 1",
"output": "1"
},
{
"input": "4 6\n6 1 2 3",
"output": "1"
},
{
"input": "2 12\n4 3",
"output": "3"
},
{
"input": "4 12\n1 2 4 3",
"output": "3"
},
{
"input": "5 12\n2 3 12 6 4",
"output": "1"
},
{
"input": "4 4\n1 2 2 4",
"output": "1"
},
{
"input": "3 6\n2 3 2",
"output": "2"
},
{
"input": "4 21\n21 20 21 2",
"output": "1"
},
{
"input": "3 8\n3 4 2",
"output": "2"
},
{
"input": "1 25\n25",
"output": "1"
},
{
"input": "99 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99",
"output": "1"
},
{
"input": "98 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98",
"output": "1"
},
{
"input": "79 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79",
"output": "1"
},
{
"input": "4 32\n1 1 1 1",
"output": "32"
},
{
"input": "1 100\n1",
"output": "100"
},
{
"input": "2 100\n7 1",
"output": "100"
},
{
"input": "7 24\n1 3 6 4 5 2 7",
"output": "4"
},
{
"input": "6 87\n1 2 8 4 5 7",
"output": "87"
},
{
"input": "1 88\n1",
"output": "88"
},
{
"input": "1 89\n1",
"output": "89"
}
] | 1,671,364,069 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 46 | 0 | def f():
num,k=map(int,input().split())
n=map(int, input().split())
maxi=0
ans=0
for i in n:
if(k%i==0 and i>maxi):
maxi=i
ans=int(k/i)
print(ans)
f() | Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding.
Input Specification:
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Output Specification:
Print one integer number — the minimum number of hours required to water the garden.
Demo Input:
['3 6\n2 3 5\n', '6 7\n1 2 3 4 5 6\n']
Demo Output:
['2\n', '7\n']
Note:
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | ```python
def f():
num,k=map(int,input().split())
n=map(int, input().split())
maxi=0
ans=0
for i in n:
if(k%i==0 and i>maxi):
maxi=i
ans=int(k/i)
print(ans)
f()
``` | 3 |
|
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array. | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82",
"output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0"
},
{
"input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46",
"output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0"
},
{
"input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38",
"output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0"
},
{
"input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37",
"output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37"
},
{
"input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61",
"output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61"
},
{
"input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66",
"output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0"
},
{
"input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82",
"output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0"
},
{
"input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22",
"output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20"
},
{
"input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41",
"output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0"
},
{
"input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935",
"output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0"
},
{
"input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952",
"output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961"
},
{
"input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0",
"output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673"
},
{
"input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0",
"output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182"
},
{
"input": "5\n-1 -2 -3 -4 0",
"output": "1 -1\n2 -4 -3\n2 0 -2"
},
{
"input": "3\n-101 101 0",
"output": "1 -101\n1 101\n1 0"
},
{
"input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000",
"output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000"
},
{
"input": "4\n0 -1 -2 -3",
"output": "1 -1\n2 -3 -2\n1 0"
}
] | 1,607,418,815 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 307,200 | while 1:
try:
data = int(input())
values = [int(i) for i in input().split(' ')]
negative_set = list()
positive_set = list()
zero_set = list()
# since it is guaranteed that the solution exitsts
# so i can just put 1 negative in the 1st set zeros in the 3rd set
# other can all be inside the 2nd set
check_one_negative_number = 0
for i in values:
if i == 0:
zero_set.append(i)
elif i > 0:
positive_set.append(i)
else:
if check_one_negative_number == 0:
negative_set.append(i)
check_one_negative_number = 1
else:
positive_set.append(i)
print(len(negative_set),str(negative_set[0]))
print(len(positive_set),' '.join(str(i) for i in positive_set))
print(len(zero_set),' '.join(str(i) for i in zero_set).strip())
except:
break | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array.
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
Output Specification:
In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
Demo Input:
['3\n-1 2 0\n', '4\n-1 -2 -3 0\n']
Demo Output:
['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n']
Note:
none | ```python
while 1:
try:
data = int(input())
values = [int(i) for i in input().split(' ')]
negative_set = list()
positive_set = list()
zero_set = list()
# since it is guaranteed that the solution exitsts
# so i can just put 1 negative in the 1st set zeros in the 3rd set
# other can all be inside the 2nd set
check_one_negative_number = 0
for i in values:
if i == 0:
zero_set.append(i)
elif i > 0:
positive_set.append(i)
else:
if check_one_negative_number == 0:
negative_set.append(i)
check_one_negative_number = 1
else:
positive_set.append(i)
print(len(negative_set),str(negative_set[0]))
print(len(positive_set),' '.join(str(i) for i in positive_set))
print(len(zero_set),' '.join(str(i) for i in zero_set).strip())
except:
break
``` | 0 |
|
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
"input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746",
"output": "245"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "3\n607\n684",
"output": "5"
},
{
"input": "4\n0809\n0636",
"output": "8"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762280548\n9519431339078678836940020",
"output": "72"
},
{
"input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024",
"output": "305"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8037856825987124762285484\n9519431339078678836940202",
"output": "74"
},
{
"input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831",
"output": "357"
},
{
"input": "5\n84284\n08941",
"output": "16"
},
{
"input": "25\n8378525987476228048406972\n9194339078883694020217816",
"output": "55"
},
{
"input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599",
"output": "274"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "1\n7\n7",
"output": "0"
},
{
"input": "1\n0\n5",
"output": "5"
},
{
"input": "1\n2\n7",
"output": "5"
},
{
"input": "1\n7\n9",
"output": "2"
},
{
"input": "1\n9\n7",
"output": "2"
},
{
"input": "1\n2\n9",
"output": "3"
},
{
"input": "1\n9\n2",
"output": "3"
},
{
"input": "25\n3164978461316464614169874\n9413979197249127496597357",
"output": "66"
},
{
"input": "4\n9999\n9999",
"output": "0"
},
{
"input": "2\n11\n11",
"output": "0"
}
] | 1,664,536,124 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 77 | 1,433,600 | n = int(input())
comb1 = list(map(int, ' '.join(input()).split()))
comb2 = list(map(int, ' '.join(input()).split()))
count = 0
for i in range(n):
a = abs(comb1[i] - comb2[i])
b = 10 - a
count += min(a, b)
print(count) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Output Specification:
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
Demo Input:
['5\n82195\n64723\n']
Demo Output:
['13\n']
Note:
In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
n = int(input())
comb1 = list(map(int, ' '.join(input()).split()))
comb2 = list(map(int, ' '.join(input()).split()))
count = 0
for i in range(n):
a = abs(comb1[i] - comb2[i])
b = 10 - a
count += min(a, b)
print(count)
``` | 3 |
|
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.
How many times can Artem give presents to Masha? | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"
},
{
"input": "1000000000",
"output": "666666667"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "666666666"
},
{
"input": "999999998",
"output": "666666665"
},
{
"input": "999999997",
"output": "666666665"
},
{
"input": "999999996",
"output": "666666664"
},
{
"input": "999999995",
"output": "666666663"
},
{
"input": "999999994",
"output": "666666663"
},
{
"input": "999999993",
"output": "666666662"
},
{
"input": "999999992",
"output": "666666661"
},
{
"input": "999999991",
"output": "666666661"
},
{
"input": "1000",
"output": "667"
},
{
"input": "10000",
"output": "6667"
},
{
"input": "100000",
"output": "66667"
},
{
"input": "1000000",
"output": "666667"
},
{
"input": "10000000",
"output": "6666667"
},
{
"input": "100000000",
"output": "66666667"
},
{
"input": "7",
"output": "5"
}
] | 1,632,339,994 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 109 | 20,172,800 | a = int(input())
print(a // 3 * 2 + (a % 3 > 0)) | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.
How many times can Artem give presents to Masha?
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Output Specification:
Print the maximum possible number of times Artem can give presents to Masha.
Demo Input:
['1\n', '2\n', '3\n', '4\n']
Demo Output:
['1\n', '1\n', '2\n', '3\n']
Note:
In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. | ```python
a = int(input())
print(a // 3 * 2 + (a % 3 > 0))
``` | 3 |
|
721 | C | Journey | PROGRAMMING | 1,800 | [
"dp",
"graphs"
] | null | null | Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it. | The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces. | Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them. | [
"4 3 13\n1 2 5\n2 3 7\n2 4 8\n",
"6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n",
"5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n"
] | [
"3\n1 2 4 \n",
"4\n1 2 4 6 \n",
"3\n1 3 5 \n"
] | none | 1,500 | [
{
"input": "4 3 13\n1 2 5\n2 3 7\n2 4 8",
"output": "3\n1 2 4 "
},
{
"input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1",
"output": "4\n1 2 4 6 "
},
{
"input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2",
"output": "3\n1 3 5 "
},
{
"input": "10 10 100\n1 4 1\n6 4 1\n9 3 2\n2 7 2\n5 8 11\n1 2 8\n4 10 10\n8 9 2\n7 5 8\n3 6 4",
"output": "10\n1 2 7 5 8 9 3 6 4 10 "
},
{
"input": "10 10 56\n4 8 5\n9 3 11\n2 5 5\n5 9 9\n3 6 1\n1 4 9\n8 7 7\n6 10 1\n1 6 12\n7 2 9",
"output": "3\n1 6 10 "
},
{
"input": "4 4 3\n1 2 1\n2 3 1\n3 4 1\n1 3 1",
"output": "4\n1 2 3 4 "
},
{
"input": "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1",
"output": "3\n1 3 4 "
},
{
"input": "10 45 8\n1 2 1\n1 3 1\n1 4 1\n1 5 1\n1 6 1\n1 7 1\n1 8 1\n1 9 1\n1 10 1\n2 3 1\n2 4 1\n2 5 1\n2 6 1\n2 7 1\n2 8 1\n2 9 1\n2 10 1\n3 4 1\n3 5 1\n3 6 1\n3 7 1\n3 8 1\n3 9 1\n3 10 1\n4 5 1\n4 6 1\n4 7 1\n4 8 1\n4 9 1\n4 10 1\n5 6 1\n5 7 1\n5 8 1\n5 9 1\n5 10 1\n6 7 1\n6 8 1\n6 9 1\n6 10 1\n7 8 1\n7 9 1\n7 10 1\n8 9 1\n8 10 1\n9 10 1",
"output": "9\n1 2 3 4 5 6 7 8 10 "
},
{
"input": "2 1 1\n1 2 1",
"output": "2\n1 2 "
},
{
"input": "12 12 8\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1",
"output": "6\n1 9 10 11 8 12 "
},
{
"input": "12 12 5\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1",
"output": "6\n1 9 10 11 8 12 "
},
{
"input": "12 12 4\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 2\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1",
"output": "4\n1 7 6 12 "
},
{
"input": "11 11 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1",
"output": "8\n1 4 5 6 3 7 8 11 "
},
{
"input": "11 11 7\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1",
"output": "8\n1 4 5 6 3 7 8 11 "
},
{
"input": "11 11 6\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1",
"output": "6\n1 2 3 7 8 11 "
},
{
"input": "12 12 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 12 1\n12 10 1\n10 9 1\n11 1 1",
"output": "8\n1 4 5 6 3 7 8 12 "
},
{
"input": "4 4 120\n1 2 11\n1 3 20\n2 3 10\n3 4 100",
"output": "3\n1 3 4 "
},
{
"input": "4 4 10\n2 1 1\n2 3 1\n1 3 1\n3 4 1",
"output": "3\n1 3 4 "
},
{
"input": "5 5 200\n1 2 100\n2 4 100\n1 3 1\n3 4 1\n4 5 1",
"output": "4\n1 3 4 5 "
},
{
"input": "5 5 2\n1 2 1\n1 3 1\n3 4 1\n2 5 1\n4 2 1",
"output": "3\n1 2 5 "
},
{
"input": "4 4 1000000000\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n1 4 1000000000",
"output": "2\n1 4 "
}
] | 1,605,186,218 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 171 | 4,096,000 |
n, m, T = map(int, input().split())
adj = [[] for _ in range(n+1)]
adj_w = [[] for _ in range(n+1)]
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
pv1 = [[1] for _ in range(n+1)]
pv2 = [[1] for _ in range(n+1)]
for i in range(m):
a, b, t = map(int, input().split())
adj[b].append(a)
adj_w[b].append(t)
if a == 1:
dp[b][2] = t
pv1[b].append(b)
pv2[b].append(b)
for c in range(3, n + 1):
for v in range(2, n + 1):
for i, nx in enumerate(adj[v]):
if nx == n or not dp[nx][c-1]:continue
newdistance = dp[nx][c-1] + adj_w[v][i]
if newdistance <= T and (not dp[v][c] or newdistance < dp[v][c]):
dp[v][c] = newdistance
pv1[v] = pv1[nx]
pv1[v].append(v)
if m == 98 :
print(pv1[50])
pv1[nx] = pv2[nx].copy()
print(len(pv1[n]))
print(' '.join(map(str, pv1[n])))
| Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it.
Input Specification:
The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output Specification:
Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Demo Input:
['4 3 13\n1 2 5\n2 3 7\n2 4 8\n', '6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n', '5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n']
Demo Output:
['3\n1 2 4 \n', '4\n1 2 4 6 \n', '3\n1 3 5 \n']
Note:
none | ```python
n, m, T = map(int, input().split())
adj = [[] for _ in range(n+1)]
adj_w = [[] for _ in range(n+1)]
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
pv1 = [[1] for _ in range(n+1)]
pv2 = [[1] for _ in range(n+1)]
for i in range(m):
a, b, t = map(int, input().split())
adj[b].append(a)
adj_w[b].append(t)
if a == 1:
dp[b][2] = t
pv1[b].append(b)
pv2[b].append(b)
for c in range(3, n + 1):
for v in range(2, n + 1):
for i, nx in enumerate(adj[v]):
if nx == n or not dp[nx][c-1]:continue
newdistance = dp[nx][c-1] + adj_w[v][i]
if newdistance <= T and (not dp[v][c] or newdistance < dp[v][c]):
dp[v][c] = newdistance
pv1[v] = pv1[nx]
pv1[v].append(v)
if m == 98 :
print(pv1[50])
pv1[nx] = pv2[nx].copy()
print(len(pv1[n]))
print(' '.join(map(str, pv1[n])))
``` | 0 |
|
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25",
"output": "25"
},
{
"input": "100000000\n100000000",
"output": "100000000"
},
{
"input": "7\n1234",
"output": "82"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n100000000",
"output": "0"
},
{
"input": "100000000\n1",
"output": "1"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n1",
"output": "1"
},
{
"input": "2\n2",
"output": "2"
},
{
"input": "2\n3",
"output": "3"
},
{
"input": "2\n4",
"output": "0"
},
{
"input": "2\n5",
"output": "1"
},
{
"input": "25\n33554432",
"output": "0"
},
{
"input": "26\n33554432",
"output": "33554432"
},
{
"input": "25\n67108864",
"output": "0"
},
{
"input": "26\n67108864",
"output": "0"
},
{
"input": "25\n92831989",
"output": "25723125"
},
{
"input": "26\n92831989",
"output": "25723125"
},
{
"input": "27\n92831989",
"output": "92831989"
},
{
"input": "29\n92831989",
"output": "92831989"
},
{
"input": "30\n92831989",
"output": "92831989"
},
{
"input": "31\n92831989",
"output": "92831989"
},
{
"input": "99812399\n93172892",
"output": "93172892"
},
{
"input": "67108864\n12345678",
"output": "12345678"
},
{
"input": "3\n98391849",
"output": "1"
},
{
"input": "13\n1231232",
"output": "2432"
},
{
"input": "18\n9842194",
"output": "142866"
},
{
"input": "24\n71237177",
"output": "4128313"
},
{
"input": "11\n65535",
"output": "2047"
},
{
"input": "11\n65536",
"output": "0"
},
{
"input": "12\n123",
"output": "123"
},
{
"input": "123456\n12",
"output": "12"
},
{
"input": "88\n888",
"output": "888"
},
{
"input": "888\n88",
"output": "88"
},
{
"input": "8888\n8888",
"output": "8888"
},
{
"input": "64\n128",
"output": "128"
},
{
"input": "128\n64",
"output": "64"
},
{
"input": "60\n9999999",
"output": "9999999"
},
{
"input": "200\n100000",
"output": "100000"
},
{
"input": "3\n8",
"output": "0"
},
{
"input": "10000000\n25024886",
"output": "25024886"
},
{
"input": "100\n100000",
"output": "100000"
},
{
"input": "99999999\n100000000",
"output": "100000000"
},
{
"input": "70\n12345678",
"output": "12345678"
}
] | 1,668,552,042 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 45,875,200 | n = int(input());m = int(input());q = 2**n;w = m%q;print(w) | Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108).
Output Specification:
Output a single integer — the value of .
Demo Input:
['4\n42\n', '1\n58\n', '98765432\n23456789\n']
Demo Output:
['10\n', '0\n', '23456789\n']
Note:
In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | ```python
n = int(input());m = int(input());q = 2**n;w = m%q;print(w)
``` | 0 |
|
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",
"output": "NO"
},
{
"input": "190492",
"output": "YES"
},
{
"input": "5722367",
"output": "NO"
},
{
"input": "816761542",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "2",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "NO"
},
{
"input": "9",
"output": "YES"
},
{
"input": "10",
"output": "NO"
},
{
"input": "12",
"output": "YES"
},
{
"input": "13",
"output": "YES"
},
{
"input": "14",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "16",
"output": "YES"
},
{
"input": "17",
"output": "NO"
},
{
"input": "18",
"output": "YES"
},
{
"input": "19",
"output": "NO"
},
{
"input": "20",
"output": "YES"
},
{
"input": "41",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "69",
"output": "YES"
},
{
"input": "82",
"output": "NO"
},
{
"input": "85",
"output": "NO"
},
{
"input": "736",
"output": "NO"
},
{
"input": "895",
"output": "YES"
},
{
"input": "934",
"output": "YES"
},
{
"input": "6213",
"output": "YES"
},
{
"input": "7405",
"output": "NO"
},
{
"input": "9919",
"output": "NO"
},
{
"input": "40942",
"output": "YES"
},
{
"input": "41992",
"output": "NO"
},
{
"input": "68535",
"output": "NO"
},
{
"input": "405718",
"output": "NO"
},
{
"input": "1046146",
"output": "YES"
},
{
"input": "3761248",
"output": "YES"
},
{
"input": "6195181",
"output": "YES"
},
{
"input": "35354345",
"output": "NO"
},
{
"input": "81282830",
"output": "NO"
},
{
"input": "187719774",
"output": "NO"
},
{
"input": "296798673",
"output": "NO"
},
{
"input": "938938476",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "999887464",
"output": "YES"
},
{
"input": "999111944",
"output": "NO"
},
{
"input": "999966520",
"output": "YES"
},
{
"input": "999912080",
"output": "NO"
},
{
"input": "999992017",
"output": "YES"
},
{
"input": "999990474",
"output": "NO"
},
{
"input": "999999190",
"output": "YES"
},
{
"input": "999999125",
"output": "NO"
},
{
"input": "999999940",
"output": "YES"
},
{
"input": "999999995",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "83495494",
"output": "NO"
},
{
"input": "968022000",
"output": "YES"
},
{
"input": "399980000",
"output": "YES"
},
{
"input": "4",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
}
] | 1,600,323,557 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 498 | 3,481,600 | import sys, os.path
from collections import*
from copy import*
import math
mod=10**9+7
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
def bs(left,right,x):
while(left<=right):
mid=left+(right-left)//2
b=(mid*(mid+1))//2
if(b==x):
return 1
elif(b>x):
right=mid-1
else:
left=mid+1
return 0
n=int(input())
n1=10**5
flag=0
for i in range(1,n1+1):
a=(i*(i+1))//2
if(bs(1,n1,n-a)):
flag=1
break
if(flag==0):
print('NO')
else:
print('YES')
| Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input Specification:
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Demo Input:
['256\n', '512\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | ```python
import sys, os.path
from collections import*
from copy import*
import math
mod=10**9+7
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
def bs(left,right,x):
while(left<=right):
mid=left+(right-left)//2
b=(mid*(mid+1))//2
if(b==x):
return 1
elif(b>x):
right=mid-1
else:
left=mid+1
return 0
n=int(input())
n1=10**5
flag=0
for i in range(1,n1+1):
a=(i*(i+1))//2
if(bs(1,n1,n-a)):
flag=1
break
if(flag==0):
print('NO')
else:
print('YES')
``` | 3 |
|
121 | A | Lucky Sum | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem. | The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. | In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2 7\n",
"7 7\n"
] | [
"33\n",
"7\n"
] | In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | 500 | [
{
"input": "2 7",
"output": "33"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "1 9",
"output": "125"
},
{
"input": "4 7",
"output": "25"
},
{
"input": "12 47",
"output": "1593"
},
{
"input": "6 77",
"output": "4012"
},
{
"input": "1 100",
"output": "14247"
},
{
"input": "1000000000 1000000000",
"output": "4444444444"
},
{
"input": "77 77",
"output": "77"
},
{
"input": "69 788",
"output": "452195"
},
{
"input": "474 747",
"output": "202794"
},
{
"input": "4 77777",
"output": "4070145675"
},
{
"input": "1 1000000",
"output": "1394675359387"
},
{
"input": "47 744447",
"output": "381286992761"
},
{
"input": "47444 1000000000",
"output": "1394672348253941136"
},
{
"input": "48 854888",
"output": "749733199853"
},
{
"input": "854444 985555",
"output": "582719941728"
},
{
"input": "774744 774747",
"output": "3098985"
},
{
"input": "654 987654",
"output": "1339803940266"
},
{
"input": "477777 1000000000",
"output": "1394672167300009765"
},
{
"input": "77777 777777777",
"output": "407018021649898097"
},
{
"input": "963 85555574",
"output": "7526978888069560"
},
{
"input": "47 7444",
"output": "38125896"
},
{
"input": "1 1000000000",
"output": "1394672350065645019"
},
{
"input": "474 999888555",
"output": "1394177038954402791"
},
{
"input": "777 1000000000",
"output": "1394672350065239125"
},
{
"input": "7 777777774",
"output": "407018023386632646"
},
{
"input": "369 852",
"output": "606732"
},
{
"input": "47 47",
"output": "47"
},
{
"input": "747 748",
"output": "1521"
},
{
"input": "77777440 77777444",
"output": "388887220"
},
{
"input": "987545885 999875584",
"output": "54798666661186800"
},
{
"input": "2 777777776",
"output": "407018024942188226"
},
{
"input": "1 1",
"output": "4"
},
{
"input": "1 2",
"output": "8"
},
{
"input": "999999999 1000000000",
"output": "8888888888"
},
{
"input": "777777777 1000000000",
"output": "987654325123456789"
},
{
"input": "777777778 1000000000",
"output": "987654324345679012"
},
{
"input": "5 6",
"output": "14"
},
{
"input": "49 49",
"output": "74"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "3 4",
"output": "8"
}
] | 1,684,493,735 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 102,400 | import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ ---- Input Functions ---- ############
def Lucky_Sum2():
l,r = invr()
luckyNum = [4,7]
startLuckyNum = -1
if luckyNum[0] >= l and startLuckyNum == -1:
startLuckyNum = luckyNum[0]
if luckyNum[1] >= l and startLuckyNum == -1:
startLuckyNum = luckyNum[1]
index = 0
#start = time.time()
while True:
num1 = (luckyNum[index]*10)+4
num2 = (luckyNum[index]*10)+7
if num1 >= l and startLuckyNum == -1:
startLuckyNum = num1
if num2 >= l and startLuckyNum == -1:
startLuckyNum = num2
if num1 >= r :
luckyNum.append(num1)
break
else:
luckyNum.append(num1)
if num2 >= r:
luckyNum.append(num2)
break
else:
luckyNum.append(num2)
index += 1
#end = time.time()
#print("While loop time:", (end-start))
#start = time.time()
startIndex = luckyNum.index(startLuckyNum)
#end = time.time()
#print("Indexing time:", end - start)
sum = 0
#start = time.time()
for movingIndex in range(startIndex,len(luckyNum)):
num = luckyNum[movingIndex]
if movingIndex == startIndex:
numTimesRepeated = (num - l) + 1
elif movingIndex == len(luckyNum)-1:
prevNum = luckyNum[movingIndex-1]
numTimesRepeated = (r - (prevNum+1)) + 1
else:
prevNum = luckyNum[movingIndex-1]
numTimesRepeated = num - prevNum
sum += (num*numTimesRepeated)
#end = time.time()
#print("For loop time:", end - start)
print(sum)
return
Lucky_Sum2() | Title: Lucky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem.
Input Specification:
The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits.
Output Specification:
In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
Demo Input:
['2 7\n', '7 7\n']
Demo Output:
['33\n', '7\n']
Note:
In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | ```python
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ ---- Input Functions ---- ############
def Lucky_Sum2():
l,r = invr()
luckyNum = [4,7]
startLuckyNum = -1
if luckyNum[0] >= l and startLuckyNum == -1:
startLuckyNum = luckyNum[0]
if luckyNum[1] >= l and startLuckyNum == -1:
startLuckyNum = luckyNum[1]
index = 0
#start = time.time()
while True:
num1 = (luckyNum[index]*10)+4
num2 = (luckyNum[index]*10)+7
if num1 >= l and startLuckyNum == -1:
startLuckyNum = num1
if num2 >= l and startLuckyNum == -1:
startLuckyNum = num2
if num1 >= r :
luckyNum.append(num1)
break
else:
luckyNum.append(num1)
if num2 >= r:
luckyNum.append(num2)
break
else:
luckyNum.append(num2)
index += 1
#end = time.time()
#print("While loop time:", (end-start))
#start = time.time()
startIndex = luckyNum.index(startLuckyNum)
#end = time.time()
#print("Indexing time:", end - start)
sum = 0
#start = time.time()
for movingIndex in range(startIndex,len(luckyNum)):
num = luckyNum[movingIndex]
if movingIndex == startIndex:
numTimesRepeated = (num - l) + 1
elif movingIndex == len(luckyNum)-1:
prevNum = luckyNum[movingIndex-1]
numTimesRepeated = (r - (prevNum+1)) + 1
else:
prevNum = luckyNum[movingIndex-1]
numTimesRepeated = num - prevNum
sum += (num*numTimesRepeated)
#end = time.time()
#print("For loop time:", end - start)
print(sum)
return
Lucky_Sum2()
``` | 0 |
|
453 | E | Little Pony and Lord Tirek | PROGRAMMING | 3,100 | [
"data structures"
] | null | null | Lord Tirek is a centaur and the main antagonist in the season four finale episodes in the series "My Little Pony: Friendship Is Magic". In "Twilight's Kingdom" (Part 1), Tirek escapes from Tartarus and drains magic from ponies to grow stronger.
The core skill of Tirek is called Absorb Mana. It takes all mana from a magic creature and gives them to the caster.
Now to simplify the problem, assume you have *n* ponies (numbered from 1 to *n*). Each pony has three attributes:
- *s**i* : amount of mana that the pony has at time 0; - *m**i* : maximum mana that the pony can have; - *r**i* : mana regeneration per unit time.
Lord Tirek will do *m* instructions, each of them can be described with three integers: *t**i*,<=*l**i*,<=*r**i*. The instruction means that at time *t**i*, Tirek will use Absorb Mana on ponies with numbers from *l**i* to *r**i* (both borders inclusive). We'll give you all the *m* instructions in order, count how much mana Tirek absorbs for each instruction. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of ponies. Each of the next *n* lines contains three integers *s**i*,<=*m**i*,<=*r**i* (0<=≤<=*s**i*<=≤<=*m**i*<=≤<=105; 0<=≤<=*r**i*<=≤<=105), describing a pony.
The next line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of instructions. Each of the next *m* lines contains three integers *t**i*,<=*l**i*,<=*r**i* (0<=≤<=*t**i*<=≤<=109; 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), describing an instruction of Lord Tirek. The instructions are given in strictly increasing order of *t**i* (all *t**i* are distinct). | For each instruction, output a single line which contains a single integer, the total mana absorbed in this instruction. | [
"5\n0 10 1\n0 12 1\n0 20 1\n0 12 1\n0 10 1\n2\n5 1 5\n19 1 5\n"
] | [
"25\n58\n"
] | Every pony starts with zero mana. For the first instruction, each pony has 5 mana, so you get 25 mana in total and each pony has 0 mana after the first instruction.
For the second instruction, pony 3 has 14 mana and other ponies have mana equal to their *m*<sub class="lower-index">*i*</sub>. | 2,500 | [] | 1,600,442,872 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 307,200 | pony_count = int(input())
ponies = []
for _ in range(pony_count):
ponies.append([int(i) for i in input()])
instruction_count = int(input())
for _ in range(instruction_count):
time,x,y = [int(i) for i in input()]
mana_absorbed = 0
for pony in ponies:
amount = min(pony[2]*time,pony[1])-pony[0]
mana_absorbed+=amount
print(mana_absorbed) | Title: Little Pony and Lord Tirek
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lord Tirek is a centaur and the main antagonist in the season four finale episodes in the series "My Little Pony: Friendship Is Magic". In "Twilight's Kingdom" (Part 1), Tirek escapes from Tartarus and drains magic from ponies to grow stronger.
The core skill of Tirek is called Absorb Mana. It takes all mana from a magic creature and gives them to the caster.
Now to simplify the problem, assume you have *n* ponies (numbered from 1 to *n*). Each pony has three attributes:
- *s**i* : amount of mana that the pony has at time 0; - *m**i* : maximum mana that the pony can have; - *r**i* : mana regeneration per unit time.
Lord Tirek will do *m* instructions, each of them can be described with three integers: *t**i*,<=*l**i*,<=*r**i*. The instruction means that at time *t**i*, Tirek will use Absorb Mana on ponies with numbers from *l**i* to *r**i* (both borders inclusive). We'll give you all the *m* instructions in order, count how much mana Tirek absorbs for each instruction.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of ponies. Each of the next *n* lines contains three integers *s**i*,<=*m**i*,<=*r**i* (0<=≤<=*s**i*<=≤<=*m**i*<=≤<=105; 0<=≤<=*r**i*<=≤<=105), describing a pony.
The next line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of instructions. Each of the next *m* lines contains three integers *t**i*,<=*l**i*,<=*r**i* (0<=≤<=*t**i*<=≤<=109; 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), describing an instruction of Lord Tirek. The instructions are given in strictly increasing order of *t**i* (all *t**i* are distinct).
Output Specification:
For each instruction, output a single line which contains a single integer, the total mana absorbed in this instruction.
Demo Input:
['5\n0 10 1\n0 12 1\n0 20 1\n0 12 1\n0 10 1\n2\n5 1 5\n19 1 5\n']
Demo Output:
['25\n58\n']
Note:
Every pony starts with zero mana. For the first instruction, each pony has 5 mana, so you get 25 mana in total and each pony has 0 mana after the first instruction.
For the second instruction, pony 3 has 14 mana and other ponies have mana equal to their *m*<sub class="lower-index">*i*</sub>. | ```python
pony_count = int(input())
ponies = []
for _ in range(pony_count):
ponies.append([int(i) for i in input()])
instruction_count = int(input())
for _ in range(instruction_count):
time,x,y = [int(i) for i in input()]
mana_absorbed = 0
for pony in ponies:
amount = min(pony[2]*time,pony[1])-pony[0]
mana_absorbed+=amount
print(mana_absorbed)
``` | -1 |
|
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,685,299,983 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 560 | 0 | import sys
import math
def function():
n, m = map(int, input().split())
ans = 0
for a in range(1001):
for b in range(1001):
if (a**2) + b == n and a + (b**2) == m:
ans+=1
print(ans)
return
if __name__ == '__main__':
function()
| Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | ```python
import sys
import math
def function():
n, m = map(int, input().split())
ans = 0
for a in range(1001):
for b in range(1001):
if (a**2) + b == n and a + (b**2) == m:
ans+=1
print(ans)
return
if __name__ == '__main__':
function()
``` | 3 |
|
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad. | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists. | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------",
"output": "-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------"
},
{
"input": "1 1\n-",
"output": "-"
},
{
"input": "4 2\n..\n..\n..\n..",
"output": "BW\nWB\nBW\nWB"
},
{
"input": "5 1\n.\n.\n.\n.\n.",
"output": "B\nW\nB\nW\nB"
}
] | 1,618,433,807 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | r,c = map(int,input().split())
ans = ''
turn = 'b'
for i in range(1,r+1):
b = input()
print(i,1)
if b == '':
break
for e in range(len(b)):
print(e,2)
if b[e] == '.':
if turn == 'b':
ans += 'B'
turn = 'w'
continue
elif turn == 'w':
ans += 'W'
turn = 'b'
continue
elif b[e] == '-':
ans += '-'
if turn == 'b':
turn = 'w'
continue
elif turn == 'w':
turn = 'b'
continue
ans += '\n'
if c%2 == 0:
if turn == 'b':
turn = 'w'
elif turn == 'w':
turn = 'b'
print(ans) | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
Output Specification:
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
Demo Input:
['1 1\n.\n', '2 2\n..\n..\n', '3 3\n.-.\n---\n--.']
Demo Output:
['B\n', 'BW\nWB\n', 'B-B\n---\n--B']
Note:
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | ```python
r,c = map(int,input().split())
ans = ''
turn = 'b'
for i in range(1,r+1):
b = input()
print(i,1)
if b == '':
break
for e in range(len(b)):
print(e,2)
if b[e] == '.':
if turn == 'b':
ans += 'B'
turn = 'w'
continue
elif turn == 'w':
ans += 'W'
turn = 'b'
continue
elif b[e] == '-':
ans += '-'
if turn == 'b':
turn = 'w'
continue
elif turn == 'w':
turn = 'b'
continue
ans += '\n'
if c%2 == 0:
if turn == 'b':
turn = 'w'
elif turn == 'w':
turn = 'b'
print(ans)
``` | 0 |
|
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 1,640,018,288 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | #football 43A
n_l = int(input())
team = []
for i in range(n_l):
team.append(input())
print(max(team, key = team.count)) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output Specification:
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Demo Input:
['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n']
Demo Output:
['ABC\n', 'A\n']
Note:
none | ```python
#football 43A
n_l = int(input())
team = []
for i in range(n_l):
team.append(input())
print(max(team, key = team.count))
``` | 3.977 |
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring.
String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*.
Help the bear cope with the given problem. | The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number — the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11), (6, 10), (6, 11), (7, 10), (7, 11). | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output": "4419"
},
{
"input": "bear",
"output": "1"
},
{
"input": "a",
"output": "0"
},
{
"input": "be",
"output": "0"
}
] | 1,680,920,270 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | def count_(s):
n = len(s)
count = 0
posi = []
for i in range(n - 3):
if s[i:i + 4] == "bear":
posi.append(i)
for i in posi:
l = i + 1
r = n - (i + 3) - 1
count += l * r
return count
s = input()
print(count_(s)) | Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring.
String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*.
Help the bear cope with the given problem.
Input Specification:
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['bearbtear\n', 'bearaabearc\n']
Demo Output:
['6\n', '20\n']
Note:
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11), (6, 10), (6, 11), (7, 10), (7, 11). | ```python
def count_(s):
n = len(s)
count = 0
posi = []
for i in range(n - 3):
if s[i:i + 4] == "bear":
posi.append(i)
for i in posi:
l = i + 1
r = n - (i + 3) - 1
count += l * r
return count
s = input()
print(count_(s))
``` | 0 |
|
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,661,536,477 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 0 | n,m,a=map(int,input("").split())
num1=0
num2=0
while n>=a:
num1+=1
n=n-a
while m>=a:
num2+=1
m=m-a
if n!=0:
num1+=1
if m!=0:
num2+=1
print(num1*num2) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
n,m,a=map(int,input("").split())
num1=0
num2=0
while n>=a:
num1+=1
n=n-a
while m>=a:
num2+=1
m=m-a
if n!=0:
num1+=1
if m!=0:
num2+=1
print(num1*num2)
``` | 0 |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "67",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "77",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "89",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "98",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "109",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "117",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "1",
"output": "a"
},
{
"input": "200000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "100000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "143670",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "104217",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "17879",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "131809",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "140873",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "77859",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "153022",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "179227",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "182801",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "5188",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "86539",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "12802",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "120289",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "132866",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "133377",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "31775",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "160397",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "161415",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "163623",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "22942",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "134767",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "52257",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "64905",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "183758",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "60131",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "146883",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "6",
"output": "aabbaa"
},
{
"input": "4",
"output": "aabb"
}
] | 1,607,960,318 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 108 | 409,600 | n = int(input())
k="aabb"
print(k*(n//4)+k[:n%4]) | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Output Specification:
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Demo Input:
['2\n', '3\n']
Demo Output:
['aa\n', 'bba\n']
Note:
A palindrome is a sequence of characters which reads the same backward and forward. | ```python
n = int(input())
k="aabb"
print(k*(n//4)+k[:n%4])
``` | 3 |
|
60 | B | Serial Time! | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | B. Serial Time! | 2 | 256 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.
Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes. | The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*. | The answer should contain a single number, showing in how many minutes the plate will be filled. | [
"1 1 1\n\n.\n\n1 1\n",
"2 1 1\n\n.\n\n#\n\n1 1\n",
"2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n",
"3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n",
"3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n"
] | [
"1\n",
"1\n",
"5\n",
"7\n",
"13\n"
] | none | 1,000 | [
{
"input": "1 1 1\n\n.\n\n1 1",
"output": "1"
},
{
"input": "2 1 1\n\n.\n\n#\n\n1 1",
"output": "1"
},
{
"input": "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1",
"output": "5"
},
{
"input": "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2",
"output": "7"
},
{
"input": "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1",
"output": "13"
},
{
"input": "2 2 2\n\n#.\n..\n\n.#\n#.\n\n2 1",
"output": "4"
},
{
"input": "4 7 8\n\n........\n........\n........\n........\n........\n........\n........\n\n........\n........\n........\n........\n........\n........\n........\n\n........\n........\n........\n........\n........\n........\n........\n\n........\n........\n........\n........\n........\n........\n........\n\n3 4",
"output": "224"
},
{
"input": "6 5 4\n\n####\n####\n####\n####\n.###\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n####\n####\n####\n####\n####\n\n5 1",
"output": "1"
},
{
"input": "8 2 6\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n#.####\n######\n\n......\n......\n\n1 2",
"output": "52"
},
{
"input": "9 1 9\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n1 6",
"output": "49"
},
{
"input": "6 8 4\n\n.###\n.#..\n.#..\n####\n....\n.##.\n..#.\n...#\n\n....\n##.#\n....\n....\n##..\n#.##\n#.#.\n#..#\n\n..##\n####\n#...\n..##\n###.\n#..#\n..##\n##..\n\n.##.\n##..\n#.#.\n##..\n####\n####\n.#.#\n###.\n\n#.##\n..#.\n...#\n#.##\n##.#\n##..\n####\n###.\n\n.#.#\n#.#.\n#.##\n#.##\n....\n#.##\n..##\n.##.\n\n6 4",
"output": "88"
},
{
"input": "8 1 8\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n1 3",
"output": "64"
},
{
"input": "1 8 6\n\n######\n######\n.#####\n######\n######\n######\n######\n######\n\n3 1",
"output": "1"
},
{
"input": "6 1 9\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n1 3",
"output": "30"
},
{
"input": "1 1 10\n\n..........\n\n1 6",
"output": "10"
},
{
"input": "5 2 8\n\n.##..#..\n.#.....#\n\n....##..\n#..###.#\n\n#..#.#..\n.#..#...\n\n###.#..#\n#......#\n\n#..#####\n##.....#\n\n1 7",
"output": "45"
},
{
"input": "9 2 1\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n.\n.\n\n1 1",
"output": "18"
},
{
"input": "5 8 2\n\n##\n##\n##\n#.\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n##\n##\n\n4 2",
"output": "1"
},
{
"input": "6 10 2\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n##\n#.\n##\n##\n##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n2 2",
"output": "63"
},
{
"input": "8 6 2\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n\n##\n##\n.#\n##\n##\n##\n\n3 1",
"output": "52"
},
{
"input": "4 1 3\n\n...\n\n...\n\n...\n\n...\n\n1 1",
"output": "12"
},
{
"input": "4 6 2\n\n##\n##\n##\n##\n.#\n##\n\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n\n##\n##\n##\n##\n##\n##\n\n5 1",
"output": "1"
},
{
"input": "2 9 2\n\n##\n##\n##\n##\n.#\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n5 1",
"output": "19"
},
{
"input": "10 6 5\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n2 4",
"output": "155"
},
{
"input": "2 3 6\n\n......\n#..#..\n##.#.#\n\n#.##..\n.....#\n##..##\n\n1 3",
"output": "22"
},
{
"input": "8 5 6\n\n######\n######\n######\n###.##\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n######\n######\n######\n######\n######\n\n4 4",
"output": "1"
},
{
"input": "1 3 10\n\n##########\n####.#####\n##########\n\n2 5",
"output": "1"
},
{
"input": "8 3 3\n\n...\n...\n...\n\n###\n###\n##.\n\n...\n...\n...\n\n###\n###\n##.\n\n...\n...\n...\n\n###\n###\n##.\n\n...\n...\n...\n\n###\n###\n##.\n\n3 3",
"output": "40"
},
{
"input": "5 1 4\n\n#...\n\n####\n\n#.##\n\n.###\n\n###.\n\n1 4",
"output": "3"
},
{
"input": "9 2 2\n\n##\n..\n\n##\n##\n\n#.\n#.\n\n..\n..\n\n##\n..\n\n..\n.#\n\n#.\n#.\n\n.#\n..\n\n#.\n.#\n\n2 1",
"output": "2"
},
{
"input": "1 6 2\n\n##\n..\n##\n.#\n##\n#.\n\n6 2",
"output": "1"
},
{
"input": "5 9 2\n\n##\n##\n##\n#.\n.#\n.#\n..\n##\n#.\n\n##\n..\n##\n##\n#.\n#.\n.#\n#.\n#.\n\n#.\n.#\n##\n.#\n..\n##\n##\n#.\n..\n\n#.\n..\n.#\n#.\n..\n#.\n..\n..\n##\n\n.#\n##\n..\n.#\n#.\n#.\n.#\n##\n##\n\n4 2",
"output": "1"
},
{
"input": "5 8 7\n\n.#.#...\n##.#.##\n...#..#\n#####..\n......#\n..###..\n#.#..#.\n.##..#.\n\n##.....\n.##.#..\n.##.###\n...##..\n.#.###.\n##.#..#\n##..#.#\n.##....\n\n#.#...#\n##.....\n...###.\n...##..\n..#.###\n.#.#...\n.#.#..#\n..###..\n\n#..#...\n.####..\n###.#.#\n#..#.##\n....#..\n.#.#.##\n#.#.###\n.#..###\n\n..#.#.#\n##....#\n.#.####\n#.#.##.\n.#..##.\n##..#.#\n.##.##.\n...###.\n\n4 7",
"output": "132"
},
{
"input": "4 3 2\n\n#.\n#.\n##\n\n.#\n.#\n##\n\n..\n#.\n##\n\n#.\n..\n.#\n\n1 2",
"output": "2"
},
{
"input": "4 10 10\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n8 1",
"output": "400"
},
{
"input": "4 10 10\n\n##########\n##########\n##########\n##########\n##########\n##########\n#########.\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n7 10",
"output": "1"
},
{
"input": "3 10 10\n\n#######.##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n\n#######.##\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n\n1 8",
"output": "102"
},
{
"input": "2 10 10\n\n#..#...#..\n###..#..##\n..#..#..#.\n#..#.#...#\n#####...#.\n#.####..#.\n###..##.##\n.###..#...\n##..##.##.\n..#.#.####\n\n..##..#.#.\n.##....#..\n..#.#.##..\n#.####....\n##..##.#..\n######...#\n..#...###.\n####.###.#\n#...##.#..\n##.#####.#\n\n6 7",
"output": "57"
}
] | 1,550,107,338 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 216 | 307,200 | import sys
def main():
k, n, m = input().split(" ")
num_plates = int(k)
num_lines = int(n)
num_chars = int(m)
input()
plates = []
visited = []
for layer in range(num_plates):
plate = []
visit = []
for line_num in range(num_lines):
plate.append(input().split(" "))
v = []
for c in range(num_chars):
v.append(False)
visit.append(v)
plates.append(plate)
visited.append(visit)
input()
x, y = input().split(" ")
x = int(x)
y = int(y)
print(water_flow(plates, visited, 0, x-1, y-1, num_lines, num_chars))
def water_flow(plates, visited, layer, x, y, num_lines, num_chars):
if (0 <= layer < len(plates)) and (0 <= x < num_lines) and (0 <= y < num_chars):
if not visited[layer][x][y]:
square = plates[layer][x][0]
sqr = square[y]
visited[layer][x][y] = True
if sqr == ".":
minutes = 1
minutes += water_flow(plates, visited, layer-1, x, y, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x-1, y-1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x-1, y, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x-1, y+1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x, y-1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x, y+1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x+1, y-1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x+1, y, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x+1, y+1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer+1, x, y, num_lines, num_chars)
return minutes
return 0
main()
| Title: Serial Time!
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.
Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes.
Input Specification:
The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*.
Output Specification:
The answer should contain a single number, showing in how many minutes the plate will be filled.
Demo Input:
['1 1 1\n\n.\n\n1 1\n', '2 1 1\n\n.\n\n#\n\n1 1\n', '2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n', '3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n', '3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n']
Demo Output:
['1\n', '1\n', '5\n', '7\n', '13\n']
Note:
none | ```python
import sys
def main():
k, n, m = input().split(" ")
num_plates = int(k)
num_lines = int(n)
num_chars = int(m)
input()
plates = []
visited = []
for layer in range(num_plates):
plate = []
visit = []
for line_num in range(num_lines):
plate.append(input().split(" "))
v = []
for c in range(num_chars):
v.append(False)
visit.append(v)
plates.append(plate)
visited.append(visit)
input()
x, y = input().split(" ")
x = int(x)
y = int(y)
print(water_flow(plates, visited, 0, x-1, y-1, num_lines, num_chars))
def water_flow(plates, visited, layer, x, y, num_lines, num_chars):
if (0 <= layer < len(plates)) and (0 <= x < num_lines) and (0 <= y < num_chars):
if not visited[layer][x][y]:
square = plates[layer][x][0]
sqr = square[y]
visited[layer][x][y] = True
if sqr == ".":
minutes = 1
minutes += water_flow(plates, visited, layer-1, x, y, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x-1, y-1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x-1, y, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x-1, y+1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x, y-1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x, y+1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x+1, y-1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x+1, y, num_lines, num_chars)
minutes += water_flow(plates, visited, layer, x+1, y+1, num_lines, num_chars)
minutes += water_flow(plates, visited, layer+1, x, y, num_lines, num_chars)
return minutes
return 0
main()
``` | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,687,454,094 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | s="hello"
st=str(input())
if s in st:
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s="hello"
st=str(input())
if s in st:
print("YES")
else:
print("NO")
``` | 0 |
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,680,479,950 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 5,324,800 | n, m = input().split()
m = int(m)
lista = list(map(int, input().split()))
ocorrencias = {}
for i in range(m):
index = int(input()) - 1
for j in range(index, len(lista)):
if lista[j] in ocorrencias:
ocorrencias[lista[j]] += 1
else:
ocorrencias[lista[j]] = 1
print(len(ocorrencias))
ocorrencias = {}
| 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 = input().split()
m = int(m)
lista = list(map(int, input().split()))
ocorrencias = {}
for i in range(m):
index = int(input()) - 1
for j in range(index, len(lista)):
if lista[j] in ocorrencias:
ocorrencias[lista[j]] += 1
else:
ocorrencias[lista[j]] = 1
print(len(ocorrencias))
ocorrencias = {}
``` | 0 |
|
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126",
"output": "12"
},
{
"input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850",
"output": "36"
},
{
"input": "2 6 8\n2 1",
"output": "0"
},
{
"input": "5 15 16\n7 11 5 12 8",
"output": "2"
},
{
"input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574",
"output": "4"
},
{
"input": "5 234613 716125\n642626 494941 234613 234613 234613",
"output": "0"
},
{
"input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547",
"output": "0"
},
{
"input": "5 10 20\n10 10 10 10 1",
"output": "1"
},
{
"input": "5 10 11\n10 10 10 10 1",
"output": "2"
},
{
"input": "3 10 10\n4 3 3",
"output": "0"
},
{
"input": "3 5 5\n5 5 5",
"output": "1"
},
{
"input": "3 4 14\n5 5 5",
"output": "0"
},
{
"input": "2 7 10\n1234 1234",
"output": "0"
},
{
"input": "1 5 6\n10",
"output": "0"
},
{
"input": "3 4 6\n1 2 3",
"output": "0"
},
{
"input": "5 10 12\n13 13 13 13 13",
"output": "0"
},
{
"input": "3 4 5\n5 7 9",
"output": "0"
},
{
"input": "3 10 100\n5 5 5",
"output": "0"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "5 5 5\n5 5 5 5 5",
"output": "2"
},
{
"input": "2 2 5\n5 5",
"output": "0"
},
{
"input": "3 1 4\n2 2 2",
"output": "0"
}
] | 1,612,469,279 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 6,144,000 | def getNumOfTimes(b, d, oranges):
num = 0
waste = 0
for orange in oranges:
if orange > b:
continue
if waste + orange > d:
num += 1
waste = 0
else:
waste += orange
return num
if __name__ == "__main__":
_, b, d = map(int, input().split())
oranges = map(int, input().split())
print(getNumOfTimes(b, d, oranges))
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
Input Specification:
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output Specification:
Print one integer — the number of times Kolya will have to empty the waste section.
Demo Input:
['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n']
Demo Output:
['1\n', '0\n', '1\n', '0\n']
Note:
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | ```python
def getNumOfTimes(b, d, oranges):
num = 0
waste = 0
for orange in oranges:
if orange > b:
continue
if waste + orange > d:
num += 1
waste = 0
else:
waste += orange
return num
if __name__ == "__main__":
_, b, d = map(int, input().split())
oranges = map(int, input().split())
print(getNumOfTimes(b, d, oranges))
``` | 3 |
|
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "4\nRBBR",
"output": "1"
},
{
"input": "5\nRGGBG",
"output": "1"
},
{
"input": "10\nGGBRBRGGRB",
"output": "2"
},
{
"input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB",
"output": "18"
},
{
"input": "15\nBRRBRGGBBRRRRGR",
"output": "6"
},
{
"input": "20\nRRGBBRBRGRGBBGGRGRRR",
"output": "6"
},
{
"input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB",
"output": "6"
},
{
"input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB",
"output": "9"
},
{
"input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB",
"output": "14"
},
{
"input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG",
"output": "20"
},
{
"input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG",
"output": "11"
},
{
"input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG",
"output": "17"
},
{
"input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB",
"output": "16"
},
{
"input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG",
"output": "19"
},
{
"input": "10\nGRRBRBRBGR",
"output": "1"
},
{
"input": "10\nBRBGBGRRBR",
"output": "1"
},
{
"input": "20\nGBGBGGRRRRGRBBGRGRGR",
"output": "5"
},
{
"input": "20\nRRGGRBBGBBRBGRRBRRBG",
"output": "6"
},
{
"input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB",
"output": "8"
},
{
"input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB",
"output": "11"
},
{
"input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB",
"output": "9"
},
{
"input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG",
"output": "13"
},
{
"input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG",
"output": "13"
},
{
"input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB",
"output": "12"
},
{
"input": "2\nBB",
"output": "1"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "49"
},
{
"input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "47"
},
{
"input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR",
"output": "43"
}
] | 1,694,373,234 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | # Nivel de complejidad O(n)
n = int(input())
colors = input()
def min_stone_to_change_colors(n, colors):
ans = 0
i = 0
while i < n:
j = i + 1
while j < n and colors[i] == colors[j]:
j += 1
ans += 1
i = j
return ans - 1
result = min_stone_to_change_colors(n, colors)
print(result)
| Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n']
Demo Output:
['1\n', '4\n', '0\n']
Note:
none | ```python
# Nivel de complejidad O(n)
n = int(input())
colors = input()
def min_stone_to_change_colors(n, colors):
ans = 0
i = 0
while i < n:
j = i + 1
while j < n and colors[i] == colors[j]:
j += 1
ans += 1
i = j
return ans - 1
result = min_stone_to_change_colors(n, colors)
print(result)
``` | 0 |
|
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,085,800 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | a,b,n=map(int,input().split())
borrow=0
tcost=(n*(n+1))//2 *a
borrow=tcost-b
if borrow<=0:
print(0)
else:
print(borrow) | 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
a,b,n=map(int,input().split())
borrow=0
tcost=(n*(n+1))//2 *a
borrow=tcost-b
if borrow<=0:
print(0)
else:
print(borrow)
``` | 3 |
|
268 | B | Buttons | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario. | A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has. | In a single line print the number of times Manao has to push a button in the worst-case scenario. | [
"2\n",
"3\n"
] | [
"3\n",
"7\n"
] | Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "14"
},
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "175"
},
{
"input": "2000",
"output": "1333335000"
},
{
"input": "1747",
"output": "888644743"
},
{
"input": "889",
"output": "117099969"
},
{
"input": "1999",
"output": "1331335999"
},
{
"input": "914",
"output": "127259419"
},
{
"input": "996",
"output": "164675486"
},
{
"input": "17",
"output": "833"
},
{
"input": "50",
"output": "20875"
},
{
"input": "91",
"output": "125671"
},
{
"input": "92",
"output": "129858"
},
{
"input": "256",
"output": "2796416"
},
{
"input": "512",
"output": "22370048"
},
{
"input": "666",
"output": "49235271"
},
{
"input": "667",
"output": "49457383"
},
{
"input": "314",
"output": "5160119"
},
{
"input": "1241",
"output": "318541121"
},
{
"input": "1500",
"output": "562501250"
},
{
"input": "1837",
"output": "1033182073"
},
{
"input": "1000",
"output": "166667500"
}
] | 1,691,774,191 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 92 | 0 | n = int(input())
result = 0
for i in range(1, n + 1):
result += i * (n - i) + 1
print(result)
| Title: Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has.
Output Specification:
In a single line print the number of times Manao has to push a button in the worst-case scenario.
Demo Input:
['2\n', '3\n']
Demo Output:
['3\n', '7\n']
Note:
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | ```python
n = int(input())
result = 0
for i in range(1, n + 1):
result += i * (n - i) + 1
print(result)
``` | 3 |
|
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer. | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "71 85 88",
"output": "17"
},
{
"input": "30 38 99",
"output": "69"
},
{
"input": "23 82 95",
"output": "72"
},
{
"input": "22 41 47",
"output": "25"
},
{
"input": "9 94 77",
"output": "85"
},
{
"input": "1 53 51",
"output": "52"
},
{
"input": "25 97 93",
"output": "72"
},
{
"input": "42 53 51",
"output": "11"
},
{
"input": "81 96 94",
"output": "15"
},
{
"input": "21 5 93",
"output": "88"
},
{
"input": "50 13 75",
"output": "62"
},
{
"input": "41 28 98",
"output": "70"
},
{
"input": "69 46 82",
"output": "36"
},
{
"input": "87 28 89",
"output": "61"
},
{
"input": "44 45 40",
"output": "5"
},
{
"input": "86 97 68",
"output": "29"
},
{
"input": "43 92 30",
"output": "62"
},
{
"input": "16 70 1",
"output": "69"
},
{
"input": "40 46 19",
"output": "27"
},
{
"input": "71 38 56",
"output": "33"
},
{
"input": "82 21 80",
"output": "61"
},
{
"input": "75 8 35",
"output": "67"
},
{
"input": "75 24 28",
"output": "51"
},
{
"input": "78 23 56",
"output": "55"
},
{
"input": "85 31 10",
"output": "75"
},
{
"input": "76 50 9",
"output": "67"
},
{
"input": "95 37 34",
"output": "61"
},
{
"input": "84 61 35",
"output": "49"
},
{
"input": "87 85 37",
"output": "50"
},
{
"input": "1 3 2",
"output": "2"
},
{
"input": "4 2 6",
"output": "4"
},
{
"input": "6 9 3",
"output": "6"
},
{
"input": "12 4 8",
"output": "8"
},
{
"input": "15 10 5",
"output": "10"
},
{
"input": "1 50 17",
"output": "49"
},
{
"input": "10 5 15",
"output": "10"
},
{
"input": "8 1 9",
"output": "8"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "2 1 3",
"output": "2"
},
{
"input": "1 8 2",
"output": "7"
},
{
"input": "1 100 2",
"output": "99"
},
{
"input": "1 4 6",
"output": "5"
}
] | 1,683,707,000 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | x = int(input())
y = int(input())
z = int(input())
myList = [x, y, z]
myList.sort(reverse = False)
print(abs(myList[0] - myList[1]) + abs(myList[2] - myList[1]))
| Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer.
Input Specification:
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Output Specification:
Print one integer — the minimum total distance the friends need to travel in order to meet together.
Demo Input:
['7 1 4\n', '30 20 10\n']
Demo Output:
['6\n', '20\n']
Note:
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | ```python
x = int(input())
y = int(input())
z = int(input())
myList = [x, y, z]
myList.sort(reverse = False)
print(abs(myList[0] - myList[1]) + abs(myList[2] - myList[1]))
``` | -1 |
|
682 | D | Alyona and Strings | PROGRAMMING | 1,900 | [
"dp",
"strings"
] | null | null | After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar.
Alyona has her favourite positive integer *k* and because she is too small, *k* does not exceed 10. The girl wants now to choose *k* disjoint non-empty substrings of string *s* such that these strings appear as disjoint substrings of string *t* and in the same order as they do in string *s*. She is also interested in that their length is maximum possible among all variants.
Formally, Alyona wants to find a sequence of *k* non-empty strings *p*1,<=*p*2,<=*p*3,<=...,<=*p**k* satisfying following conditions:
- *s* can be represented as concatenation *a*1*p*1*a*2*p*2... *a**k**p**k**a**k*<=+<=1, where *a*1,<=*a*2,<=...,<=*a**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - *t* can be represented as concatenation *b*1*p*1*b*2*p*2... *b**k**p**k**b**k*<=+<=1, where *b*1,<=*b*2,<=...,<=*b**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - sum of the lengths of strings in sequence is maximum possible.
Please help Alyona solve this complicated problem and find at least the sum of the lengths of the strings in a desired sequence.
A substring of a string is a subsequence of consecutive characters of the string. | In the first line of the input three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=10) are given — the length of the string *s*, the length of the string *t* and Alyona's favourite number respectively.
The second line of the input contains string *s*, consisting of lowercase English letters.
The third line of the input contains string *t*, consisting of lowercase English letters. | In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence.
It is guaranteed, that at least one desired sequence exists. | [
"3 2 2\nabc\nab\n",
"9 12 4\nbbaaababb\nabbbabbaaaba\n"
] | [
"2\n",
"7\n"
] | The following image describes the answer for the second sample case: | 2,000 | [
{
"input": "3 2 2\nabc\nab",
"output": "2"
},
{
"input": "9 12 4\nbbaaababb\nabbbabbaaaba",
"output": "7"
},
{
"input": "11 11 4\naaababbabbb\nbbbaaaabaab",
"output": "7"
},
{
"input": "15 9 4\nababaaabbaaaabb\nbbaababbb",
"output": "8"
},
{
"input": "2 7 1\nbb\nbbaabaa",
"output": "2"
},
{
"input": "13 4 3\nabbaababaaaab\naaab",
"output": "4"
},
{
"input": "2 3 2\nab\naab",
"output": "2"
},
{
"input": "13 9 1\noaflomxegekyv\nbgwwqizfo",
"output": "1"
},
{
"input": "5 9 1\nbabcb\nabbcbaacb",
"output": "3"
},
{
"input": "8 12 2\nbccbbaac\nabccbcaccaaa",
"output": "6"
},
{
"input": "11 2 2\nbcbcbbabaaa\nca",
"output": "2"
},
{
"input": "12 7 6\naabbccaccbcb\ncabcccc",
"output": "6"
},
{
"input": "15 10 1\nabbccbaaaabaabb\nbbaabaacca",
"output": "5"
},
{
"input": "127 266 4\nbaaabaababaaabbabbbbaababbbabaabbaaaaaabbababaabababaaaabaaaabbabaaababaabaabbbbbaabaabbbbbaaabbaabaabbbbaaaaababaaabaaabbaabaa\nabbababaaaabbbabbbbaabbbbaaabbabbaaaabaabaabababbbabbaabbabaaaaaabbbbbbbbaaabaababbbabababbabaaaababaabaaabaaabaaabaabbbabbbbabbaaabaaaaaabbaaabababbababaaaaaabaaabbbabbbabbbbabaabbabababbabbabbaababbbabbbbabbabaabbbaababbaaababaabbabbaaabbabbaabaabaabbaabbabaababba",
"output": "41"
},
{
"input": "132 206 2\nababaababaaaabbaabbaabaababbaaabbabababbbbabbbaaaaaaabbabaaaabbabbbbbbbbbabbbbaabbaaabaaaabbabaaaababbbbaaaaabababbbbabababbbabbabab\nabbbababbbaaababaaaababbbaababaaababbbbbbaaabbbabbbaabbbbabbbababbaaabbaaabaabababbaabbbbbaabaabaaababababaaaababbabaaaabbabaaabbbbabbbbaabbbbaaaabbabbbaababbbbaabbbbbabaabbababbaaabaabbabbbaabbabbbaabbaaab",
"output": "26"
},
{
"input": "290 182 2\nbababbbabaabbbababbaaaabbbabbababbbbbbabbbaaaaabaaabbaabbbaaabaabaaaabbbaaabbaabbbbbbbbbbabbabbabaaaaaaaabaaaabababaabbabaabaaaaababaabbbbbbabbabbbbabaababbabbaaabbbbbaaabbbbaaababaabbbbababbbabbababbabbabbbaaabaaabbbbaabaaaaabbaabbbabbbbbabbbaaaabbaaababbaabbbbbbbbbbabaaabbaaabaababbbbaaa\nbabbaababaaaaaaabbaabbabaaaaaaaabbabaabbbaabaababbaaaababaaaabaabbababbabaaabbbaaabaabababbbbababaaabbbaababbbbaabbabbaabaaaaabaaabbbbbbabaabbababbbaabbaaaaabaaaabaaabaaaabbbaabaabab",
"output": "25"
},
{
"input": "279 89 9\nbbbbaabbbbabaaaabbbababbaabbaabaaabababaabbaaaaabaababbbaababaaaaaabaababababbaaaababaaaabaaaaabaaaaaababbabaaababaaabbbabaaabaaabbbaabbaabaababbaaaaabaaabbabababababbaabbabbbaaababbbabbaaabaaabaaababaaabbaaaabababbabbabaabaabbbabbbabbbaababbabaaabaabbaabaabaaaaaaaabbbaabbbbabba\nabaaaabbabbbbaabaaaabbbbbbbbbbaaababaabaabbaaabbaabababababbbabaaabaaababbbbbbabbaabbbaba",
"output": "71"
},
{
"input": "421 53 2\nbaaaaaabaaababaaaabbabaaabaabaaaabaabbaaababababbbbbabaaaaabbabbbaabbabbbbabaabbbababbbbabaaaababaabaabbbbaabaaaabbbaaaabababbbabbbbaabbabbabbbaabaaabbbabbabbababaaaaabbbabbbbbabbaaababbaababbbbbaaaabaabbabaaababbaabaaaaabbbbaabbbbaabaabbabbaabbaababbbaabaaaaabaabbaaabbababaaaabbabbbaaaabbbaabaabbaababababababaabbaaaabababaabaabaabbbaababbbaaaabaaababaabbabbabbaaaaaaaaaabbbbbabbaabbaabbabbbbbbbaabaabbaaaaabbbabbbbbbab\naababaaabbaaaabaaabbaabbabbbaaabbbababbbbbbaababbbbaa",
"output": "22"
},
{
"input": "274 102 7\nbccabbbcbcababaacacaccbbcabbccbbacabccbaacabacacbcacaccaabacacccabbcccccabacbacbcaacacacbccaaacccaacacbbbcccccccbcaaacbcacaccbccacccacbbbbbbaabcbbbbbacbcacacaacbbbcbcbbaacacbaabcbbbaccbcccbbaacccabaabbcccccacbccbccbacbacbbbaccbabcbabbcbbccabaacccbaccaccaaaacacabcaacbabcabbc\nabbcabbabacaccacaaaabcacbbcbbaccccbcccacaacabacabccbbbbaaaaccbbccaabcabbacbabbcabbbcaccaccaabbbcabcacb",
"output": "44"
},
{
"input": "120 362 6\ncaaccbbbabbbcbaacbaccacaaccacaaababccaccaabaccacccbbaaaaababbccbbacccaacabacbaaacabbacbabcccbccbcbbcaabaaabaabcccaabacbb\nabcbbaaccbbcabbcbbcacbabaacbaaacabcbabcabbabccbcaaacaccaaabbcbaacccccbcabacaacabbbcabaabcbbccabacbaaaacbbbbbccabccccbababcbacbbbcbbaabcaabcacbaaaaaccbaabbabacbcbbbaabbbcabcaacbcccbcbbacababbcaababcbbbbbbcbbaaaababacabcbbcbbaccccbcacccabbbabccabcabacccbbbcaccaccaacacaabacaabccccaabccccaabaccbabcaabbcbbccccbbabccbbccbaacaccabbacacabbacccbbaaacaabacccbcbacbcbcaca",
"output": "43"
},
{
"input": "103 54 5\nbccabcbcabcbacbbacccbaccacacccacaaabbbabaccbcbcacbaaccaccaacabaaccbbbabccbacbcbaccbcabbbaacaabbcbbbcaab\nbabbccbcbcbbbbcabcbbccbabbbbcacbcbbbaccbbccbacaacaaaca",
"output": "27"
},
{
"input": "14 14 1\ngeoskjkdvmxlnu\nfaqyereihjimnu",
"output": "2"
},
{
"input": "8 8 3\nabbbcccd\nayyycccz",
"output": "4"
}
] | 1,473,397,036 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#define INF 1e9
#define pb push_back
using namespace std;
typedef long long int ll;
int dp[1001][1001][11][2];
int n, m, k;
string u, v;
int main(void)
{
cin>>n>>m>>k>>u>>v;
int i, s, e;
for(i=1 ; i<=n ; i++)
{
for(s=1 ; s<=m ; s++)
{
for(e=1 ; e<=k; e++)
{
if(u[i-1]==v[s-1])
{
dp[i][s][e][1]=1+max(dp[i-1][s-1][e-1][0],dp[i-1][s-1][e][1]);
}
dp[i][s][e][0]=max(dp[i][s][e][1],max(dp[i-1][s][e][0],dp[i][s-1][e][0]));
}
}
}
cout<<dp[n][m][k][0];
} | Title: Alyona and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar.
Alyona has her favourite positive integer *k* and because she is too small, *k* does not exceed 10. The girl wants now to choose *k* disjoint non-empty substrings of string *s* such that these strings appear as disjoint substrings of string *t* and in the same order as they do in string *s*. She is also interested in that their length is maximum possible among all variants.
Formally, Alyona wants to find a sequence of *k* non-empty strings *p*1,<=*p*2,<=*p*3,<=...,<=*p**k* satisfying following conditions:
- *s* can be represented as concatenation *a*1*p*1*a*2*p*2... *a**k**p**k**a**k*<=+<=1, where *a*1,<=*a*2,<=...,<=*a**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - *t* can be represented as concatenation *b*1*p*1*b*2*p*2... *b**k**p**k**b**k*<=+<=1, where *b*1,<=*b*2,<=...,<=*b**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - sum of the lengths of strings in sequence is maximum possible.
Please help Alyona solve this complicated problem and find at least the sum of the lengths of the strings in a desired sequence.
A substring of a string is a subsequence of consecutive characters of the string.
Input Specification:
In the first line of the input three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=10) are given — the length of the string *s*, the length of the string *t* and Alyona's favourite number respectively.
The second line of the input contains string *s*, consisting of lowercase English letters.
The third line of the input contains string *t*, consisting of lowercase English letters.
Output Specification:
In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence.
It is guaranteed, that at least one desired sequence exists.
Demo Input:
['3 2 2\nabc\nab\n', '9 12 4\nbbaaababb\nabbbabbaaaba\n']
Demo Output:
['2\n', '7\n']
Note:
The following image describes the answer for the second sample case: | ```python
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#define INF 1e9
#define pb push_back
using namespace std;
typedef long long int ll;
int dp[1001][1001][11][2];
int n, m, k;
string u, v;
int main(void)
{
cin>>n>>m>>k>>u>>v;
int i, s, e;
for(i=1 ; i<=n ; i++)
{
for(s=1 ; s<=m ; s++)
{
for(e=1 ; e<=k; e++)
{
if(u[i-1]==v[s-1])
{
dp[i][s][e][1]=1+max(dp[i-1][s-1][e-1][0],dp[i-1][s-1][e][1]);
}
dp[i][s][e][0]=max(dp[i][s][e][1],max(dp[i-1][s][e][0],dp[i][s-1][e][0]));
}
}
}
cout<<dp[n][m][k][0];
}
``` | -1 |
|
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6. | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26",
"output": "14"
},
{
"input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26",
"output": "12"
},
{
"input": "a\n3",
"output": "impossible"
},
{
"input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1",
"output": "0"
},
{
"input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4",
"output": "1"
},
{
"input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20",
"output": "18"
},
{
"input": "swmkwaruyv\n5",
"output": "0"
},
{
"input": "tnbqpsuhkczmejirvyfdolxwga\n22",
"output": "0"
},
{
"input": "abcde\n3",
"output": "0"
},
{
"input": "abb\n1",
"output": "0"
},
{
"input": "aaaa\n1",
"output": "0"
},
{
"input": "abcde\n2",
"output": "0"
},
{
"input": "yandex\n4",
"output": "0"
},
{
"input": "aaabbbccc\n1",
"output": "0"
},
{
"input": "abcd\n2",
"output": "0"
},
{
"input": "asdfgh\n2",
"output": "0"
},
{
"input": "aab\n1",
"output": "0"
},
{
"input": "mynameissako\n5",
"output": "0"
},
{
"input": "abcde\n1",
"output": "0"
},
{
"input": "abcd\n3",
"output": "0"
},
{
"input": "abcdef\n2",
"output": "0"
},
{
"input": "abcdefg\n4",
"output": "0"
},
{
"input": "abc\n1",
"output": "0"
},
{
"input": "asdafjsgljdllgjdgkl\n5",
"output": "0"
},
{
"input": "yaay\n3",
"output": "1"
},
{
"input": "yaay\n4",
"output": "2"
},
{
"input": "zzzzzz\n2",
"output": "1"
}
] | 1,685,309,512 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 31 | 0 | """
███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ██ ██ ██ ██ ██ ███ █████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ████ ████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ██ ██ ██ ██ ██ ███ █████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████████████████████████████████████
███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
"""
# '''______________________________________________________________________________________________'''
# '''
# 2i2r2X0S@aZB87Ma7XWaB8a2WaBaBZ0BBi80SaWWM@B;S7@;ZZ7i8B@7B8WZB0MWMWMWM8@ZWZWZWZWaSXWBMWMWMWM8WWMBM8@ZBZW8WX0080@8W8MWM8B8@8W0aZM0WBMZWWMWMWM8@0WWX r,7,
# 2XrS;S702Z8Z:WaX;B202Z;B2020202WarXW;ZZMWM8Si7S2iMaX,X2B722B2BZW8MWMWMWM0MaB202BaZX8Z@BM@MWMBM0MWM@MZ0aBZBXZaWZBZW8@BMZBZ@ZBaZZWZB0MZBBM@MWM8WZ@W; : ,
# WXSiSiZW0a@;BZS;WZBZ0i08BaBa0aB8W;B08XW@MWMZXrS2XZM00rXr0XSXBZB2B0@BM@MWMWM0WZWZW8WaWZBBMWMWMWM0@0M@MBMZBZ@ZB8WZWZW8@WMZW8M0@Z08WZW0M8MSrBM@MWMBM@a i.
# 02ir.,S@Z0X8BaiBaBZW;2ZB28ZWZWZ08SZWZZaWBMB@727S;2@M8WaZ;SrX;aa0X8Z@Z@BMWMWMWM@MBM8BZWZBZW8M@MWMWMZMWM@MWM8@8WZWZWZW8@WM8WZMB@8@8W0M0MWMr,.WWM@MWMWB .
# Z:;.:.BBX;808iBZ8aW77Z@ZZZBZBZ8XMr0ZWXBZM0M0Bi0rXi@WMa@B@Sa;7i2SZX2XW0@0MBM@M@MWMWM8WZBaBa08MWMWMWMBM0MWMWMW@aBZW8W8@0M@M8W8MW@ZWZMB@0MWMS. ir@@MWM@@
# Xr.i ZWBiZWB:08BaWX7XW82S@Z00@;BBaS@80SW0@8M8Z7B;X7MWMZB0MZWS2i2a0XX:Z0M0B8MBM@MWMWMWMBMZBZW0@BM@MWMWMBMWMWM8W8W8@8@BM@MZWZM@M0W8@0@0M@MB, . iXMWMWM
# Zir,XW0iZZM;ZZBZWZXi08ZrWZWaMaS8MSZ8WZaZWBMB@ZSa0i72MWMZB0M0@0BXSXWZai7X@0WaBZMWMWMWM@MWMWM0M8WZMWMWM@M@MWMWMWMWM8W8@8WZ@W@8W0MWM@Wa@8MBMWMWr i , rXMW
# rXX20W:XaMSX8W2W02i28ZiW8Wa@0S7M8BXMBWX8ZMWMB@aS88:S0MW@ZB0MB@8MZ8780@2Xi80@ZBZMWMWMWMWMWMWMBWaBZ@WMWMWMWMWM@MWM@MBW8WZW8MBW0@WMWMWM8W0MBMWMW2 :.; , i
# Z;SSMXai0B2ZBaB02iXZ0:Z0BZ00W:BB@Z08WZWS@0MWMBMSaBZ,Z@M@M8BBMWM8@0@28aM00;Sa@8WZBZM@MWMWM@M@MWMWWZWBMWMWM@MWMWM@MWM@M8W8M0M0@0MWMWMWMBMWMWMWMWM,,.;,;
# Za:ZSS;S80S@ZBW8;8r0;S8WZWZM2X0@ZW8WZW8W8WBMWMBM70BZ:@WM@M0BBMWMBM8WZ08@0@a2XWBMBWZ@BM@MWMWMWMWMWM8WWMWMWMWMWMWMWMWMWMZW8M8M8@WM@MWMWMWMBMBMWMBMZ: ;,i
# MX7XrrSS@SBaBB@iWXSrX2@8BZ@027M8WZ@ZW8WW@8WWMWM0WZ@08:MWMWMBW0MBMBMWM0WZW0M8BS0Z@BMB@0M@M@MWMWMWM@MBM0M@MWMWM@MBMWMWM@M0@BM0MZMWMWMWMWM@MWMWMWWrBW8 i
# SXr8:XXMa8ZBBMr80X;SrWZ@XB0@i80@B@@@ZWZM0Ba@WMWMZWB@88;MWMWMW@BM@M@MWM@M0@ZW0@ZWZW0MWMBMWMWMWMWM@M@MWMBM@MWMWMWMBMWMWMWMWMB@8WWMWM@MWM@MWM@MBMWM7r2MX:
# Sia7S:08BaBBM22BWia;8Z@Z28MZXZ@8W0MWBZBZMZBZMWM@Wa@@W80XM@MWMWMBMWMWMWMWM@MZWZWZW8W8M@MWMWM@M@M@MWMWMWMBMWMWM@M@MWMWMBMWMW@W@ZM0M@MWM@M@M@M@MWM0MBX ZS
# 7XX2;XaWZWWM02ZMrZXX0@80S@0Bi@8WZ@WMBMBWBMZBZMWMWWZMWW88ZMWMWMWMWM@M@M@M@MWMWM0W8@8WZ@0MWM@MWMWMWMWMWM@MBMWMWMBMBM@MWMWMWMWM@MWMBM@MWM@MWMWM@M@MWMWM ,
# 2iarX7@@WWMW0XM8S8X2M8MX00M2S0@8B0M@MB@ZWW@aW8MWM0W8MB@ZW0MWMWMWM@M@M@MWM@MWM@MWMWMZW8W0MWMWM@MWM@MWMWM@MWMWMWMWM@MWMWM@MWM@MWMBMWMWMWM@MWMWMWM@MWMWMX
# 7X7S;00MWMWWXWBZZ0;M8W0aZ@BZ7M0WZMBM@M0B8M@@ZW8MBM8WBMWMZWWMWMWM@MWMWM@MWMWMWMWM@MWM0@0MBMWM@MWMWM@MWMWM@MWMWM@MWMWM@MWM@MWMWMWMWMWM@MWM@MWM2aWM@MWM@M
# a;2i2000MWWa0BBSMrZ0BZB7@0MXZ0MZWB@WM@M0WBM@WZW0M@M8@WM@M8BBMWMWMWMWM@MWMWMWMWMWMWM@MWMWMB@WMWMWMWM@MWM@M@MWMWMWMWM@MWM@M@MWMWMWMWMWMWMWMWMWMX.;MWM@MW
# 22rXSBZMWMZW8M2@ZXZ@8MSZ0@BZSMBB8@8M@MWM0@@MB@ZBWMWMZMWMWM0WBMWM@M@MWM8MWM@M@MWMWMWM@MWMWMBMWMWMWMWMWM@M@MWM@MWMWMWMWM@MWMWM@MWMWMWMWM@M@M@MWMZ. ;7@WM
# 07X,MaMWM8WZM0W087M8WWaSM0MSB0MZMWMBMZMWM0MWM0@8@BMWMZM@MWMBMWMWM@MWMWMXW@MWM@MWMBMBMWMWMWMBMBMWMWMWM@MWMWMWMWMWM@M@M@MWMWMWM@M@MBMWMWMWMWMWMWM8, : ii
# :r:Z@@WMaWZWW@ZM7WBWZM;80MB8aMWWWMWMBXWM28WM@M8@8WBMW@0M@MWM@MWMWM@MWMWMX2WMWM@MBMWMWMWMWMWMWMBMWMWMWMWMWM@MWMWM@M@MWM@MWM@MWMWMWMWM@MWMWM@MWMWMZ,.r,:
# 7 i2MWMX0BB0MZWZZ@@ZMWX2M0Ma00M0MWMWB M@@ BWMWBZM8@BMW@BMWMWMWMWMWMWM@MWMXiXMWMWMWM@M@MWM@MWMWMWMWM@MWMWMWM@MWM@M@M@MWM@MWMWMWMWMWM@M@MWMWMWMWM@MS::7,
# ::i8WMXXW@8MBW808M8WWM;[email protected],.W@MW0ZM8W0MWWWMWM@MWMWM@M@MWMWM0i ZWMWMWMWMWM@MWM@MWMWM@M@MWM@MWMWMWM@MWMWMWM@M@MWMWMWM@MWMWMWM@M@M@MWM;iir
# i M@MX7XMZMBMZWZMBW0M@XZ@BM8W8M0M@MWZ 2WM.;.Z@MW2aM0M0MWMWMWMBMBMWMWMW@WM@M@a i7MWMWMBM@M@MWMWMWMWMWM@MWMWM@MWM@MWMWM@M@MWMWMWM@MWMWMWMWMWM@[email protected],
# aWM;r;ZWWBM0MBMWMZMWM;W0MBW8@WM@[email protected],7 2WM@7SMW@8MBMWMWMWMWM@MWMBZZMWMWM;: X2M@MZ@WM@MWMWMWMWMWMWMWM@MWMWMWMWMWMWMWMWMWM@MWMWMWMWMWMWMWM@MZ@WM:;
# ZWMXrrXrM8M0@8MWMWMWM@Sa@0M8@[email protected]@MWrXMW@8MWMWM@M@MWM@MWMWX;MWM@M87 i,ZWM082M@MWMWM@MWM@MWM@M@MWMWMWM@M@MWMWM@MWMWM@MWMWM@MWM@MWM@M MW8i
# WM7;;Si2@@WZW@WMWM8M@Mr0B@WM8WWMWMWMi;:iWM r:7.i8MW7:M@@ZMBMWMWM@MWMWMWMW7 SSMWMWB:;,rrB@@X2SM@MWM@MWM@M@MWMWM@M@MWMWM@MWM@MWMWMWMWMWMWMWMWMWM@MWZ MW.
# M7;iX;S7MW@:M0M@[email protected] XWr ;.i .rM@X W@M0W8M@M@M@MWM@MWMWS ;ia2MWM8S:r,r7BZZ,;rWWMWMWMWMWM@MWMWMWMWM@MWM@M@MWM@M@[email protected]
# 0aiX;2;2@MZ7@MWMWMWMWM70B@WMBMWM@MWMiXS80MWW0MZZi, W@a aWM0@0MWM@M@MBM@[email protected]:7iXX@WWr;.i.XaMaZS@8M@M@MWMWM@M@MWMWMWMWM@M@MWMWM@M@MWM@M@MWM@MWMWM:,8M
# M2XiSr2;MWZ;MWMWMWMWMW0SM8M@MBMWMWM@2,r@MiMiZWM@MW@XB@M .BMBWWMWM@MW82MWM@MW8 X;Xi; rS@ZMWMWMWM0M8MWMZMWMWMWM@MWM@M@M@MWMWMWM@MWMWMWMWMWMWMWMWMWMWa :W
# 8Z;X;SrXBM2X2MWM@MWM@M8ZB@WMWMBMWMWMX.,M;.:[email protected]@MWMWMW@[email protected]:X7MWWWM@M@MWMW0ar [email protected]@MWMWM@MWMWMWM@MWMWMWM@M@MWM@MWM2@WMWM8: 2
# @XSiX;2XMW. :WM@MWM@M0MSM0MWMWMWMWMWW X@, . B2@WMWM@MWMS8X. WWMWMWM@[email protected] 82MWM@M@M8BX: [email protected]@MWM@MWMWM@M@M@[email protected],;,
# 0Z;X78X:XM . M@MWMWMWXBB0@WMWMWMWMWM@:,M , . @ZMWM@M@ZBMX::: rWM@MWMWMWMWZ70WMWMiaZ,.,;WSMWMWMW0Bi i.iWZ,XWMWMWMWMWM@[email protected]@MWZ.:
# M2ZSZ.. r@. ,XMWMWM@M B0W0MWM@MWMWM@M;:@S , . W0MWMWW8X Mi,.: ,XMWMWMWMWMZ872SM@M0i:i .2@0M@MB@B2 . , M0r:M@MWMWMWM@MWMWMWMWMWMWM@MWMWMWMWMWM :ZM@MB.
# B0r: . , M . ,@MWMWMW.iMZMWMWMWMWM@M@W,WW. , . r;Z2a;. ;;S : : . S8MWM@M@M88rX;2ZM;: . .:aX8S8r: , . iWMX;8M@MWMWMWM@M@MWM@MWMWMWMWMWMWMWMWMWi.:BM@M ,
# ; . : : .Z: , ZWMWMWM .@WWMWMWM@MWMWM@iXMW; , . . . . .i; : i : . ,;B0M@M@M8BSS:;,i . , . . , . . . ,@M8S,BWM@MWMWMWMWM@MWMWM@MWM@MWM@MWMWMWM.;,iWMWZ
# . : : , S,. , MWM@MW: MWMBM@[email protected].. . . . iir : i i i : . XXZZM@M0ZXZXa:7 , . . . . . .,WWMr::XXM@MWMWMWM@MWMWMWMWM@M@MWM@M@MWM@MW7,7.i@MW.
# i : : : ,,X , [email protected]@MWM@MWM.. S8M@@a02B2a;i i.i.i i i i , . ;,XaMWMX7iXXBZ0SSiXiX;aS@WMW2 , ria@MWMWMWMWM@M@MWMWMWMWMWM@M@MWW8MWMSiiX 8WMX
# , : : : ,r, : .BMWM@X :WMWM@M@MWM0MWMW@ . . XX0ZBZa,: i i i i i i : : , : . raMaS:ii80M@MWMWMWMB8:: i.i:X7MWMWM@MWMWMWMWM@[email protected]:77S8M
# i : : : : X,, : ,WMWMX. @WMWMWMWMW@rM@MW2 , , . . . : : i i i i i i i i i : , . i:X,, , : i.i : , , i.r.;ia@MWMWMWMWMWM@M@M@[email protected]: Sa,0
# . : : : , X : . Z@M@Z .,[email protected] : : : : : i i i i i i i i i i.i i : : : : : , , : : : i.i.;,i,X7MWMWM@MWMWMWMWM@MWMWM@M@MWM@M8iaMWB7ri. 0.i
# i i : : : : : : . MWMZ. .BM@[email protected];r i i i i i i i i i i i i i i i i.i i i : i i i i.i.i.i.i.i,; riaWM@M@M@MWMWMWMWM@[email protected]:X,.X:
# . : : : : , : : .XM@M , :WM@MWMWM@M7. MWZ.r i i i : i i i i i i i i i i i i i.i.i i i i i :.i.i.i.;.;.i:72MWM@MWM@M@M@MWMBMWMWMWM@MWMWMXr:2WMXZ,X 2..
# i : : : : : : : , .WMW. , 0WMWMWMZMWM . B@Z : i i i i i i i i i i i i i i i i i i.i i i i i i i i.i.i.i X:MBMWMWMWM@M@MWMWWWMWMWMWM@MWMWa:S.B@2ari7ar
# . : : : : : : : , rWMi. . MWMWM@Z0MW8 . X@8 : i i i i i i i i i i i i i i i i i i.i i.i i i.i i i i.i i;2@X@MWMWM@M@MWMWMrMWMWMWMWMWMWMX7;X,MBZ7r:ZX.
# i : : : : : : : : . WWM . ,,M@MWMSX@M@, , .Xa : i i i i i i , : i i i i i i i i i i i.i i.i i i.i i i.:.7ZW,MWMWM@MWMBMWMZi@MWMWM@MWMWMWZ:SrX:@SB,7:@
# . : : : : : : : : , MW, , ,2M@M@M MWMB. : ..; i i i i i i :i: i : i : : i i i i i i i i.i.i : i i.i.i [email protected]@MWMWM@M@0WMW8 MWMWMSMWMWMWMar;S;X;22S:7;0
# i : : : : : : : : ,.. M0, , .@[email protected]. : : i i i i i i i a2. , : , , : i i i i i i i i i i.i i i i i;Zi:ZM@M@MWMWMrMWMS:BMWM8i@MWMWMWW,SrSrX,0XrirS
# , : : : : : : : : r .:M,. . ;WMWM,,WMWM . : i i i i i i i : M0r.r:7iXir , i i i i i i : i i.i.i i i :i2i:,MWMWM@MWMaSBMW8 @WMWa B@MWMWM8;rS;S;72a:Xi7
# i : : : : : : : : ,,r .7M , , 2WM@a @WMWM , i i i i i i i i . @W8iSrS;8aBXr i i i i i i i i i i i i :.X .,7@M@[email protected],aM@M:riMWMWMWM,X;S;X;W:7iX,
# . : : : : : : : : ri, .;Z : ; 0WM2.XMW8@M . i i i i i i i i , ;0S;XrSrSrS,: i i i i i i i i i i i i ; . 77MWMWMWMWZ,irM@Z @WM8;irXM@MWMWriX;X:W7riXir
# i : : : : : : : : ,,X , .,i ,,r M@W 7WM:M@M . i i i i i i i i : ,,Xr2rSi; : i : : i i i i i i i i i.i : 7,[email protected]:;WMS,BMWX:X;;ZM@MWMi7;S:Ba;iXiX,
# . : : : : : : : : r;; , , : iii,[email protected]@M . : i i i i i i.i.: , i,; , : i i i i i i i i i i i i i : i;;WMWMWMWM.7iX.M@8 MWM.X;S:[email protected]:Z
# i : : : : : : : : ,.X:, : : : 7:,aM ,WM 0WM@M,. : i i i i i i i : : : : : i : i i i i i i i i i i i i ,iriM@MWMWM;;iXirrM2,WM7;;X;X:r@M@MW;,ZZr:7:77Z
# . : : : : : : : : :iX , : : .:X,;@r Ma,:MWM@MX. :.i.i i i i : : , , , . . , , , : : i i i i i i i : ,:X 8WMWMWMaiiXiXi;@B MWriX;S;X:7WM@M77ar:X:7aZ .
# i : ; : : : : : : , r;7 : : : ii7.2iiWa ,WMWSBM0. , i.i.i.i.i.ZXZXa7arX7aXaXZSZXa7a:: i.i.i i i i : :iXiZWMZMWM@;:XiX;X,00;@a.X;X;X;X,rWM@MX;:XirZ7 .
# . ,ir , : : : : : , X;: : : : riX,r:M:r Z@M;:WMWX , : i i i i.i.;,riX,Xi7:;,;,i.ri; i i.i.i.i.i : iiXS0aMX@WM@X:X;X;S;7:0ZM.7;X;X;X;X,;ZMWW 7ir2S , ,
# : : 2X. : : : : : : , X:, : , : ::X,aa;:;,M@M BW0Za,. : i i i : : , , : , , . , : , : i i i.i i , 7i2ZB;MW:WMWZ.XiXiXiXir;MrriXi7iX;XiX:;ZMW0.;rS , :
# . :XZ : : : : : : : ,.S , ; : : ..7XX:7::0MS7 Mia727; , i i i i :.i , . . , r.: i i i i i i : :,7r8Z8ra@i;MWB 7;XiXiXiX,Sai:7i2X8XSiXi7Z7 8Wa a , i .
# i , aS. : : : : : : : ,:X ,,r , : , r:7i7.a@Xr;@2,B:S2S , i i i i irWZ020aW8M8X i i.i i i : , ;:SSWaZr;Ba MWM riXi7i7:7:r8a7828SZ;XiX;7aZ.r r7r , : :
# , i78 , : : : : : : : ,:r :ir , : , iiX:;:M7;S8ri2Z,77B;, i i i.i :,Xr272;7.: i i.i i i i , 7;Z8BXa;rX0 SWM.r:r:XraXZ208@XarX:r:X;Xir28.7i; . . , , .
# : ,.2Si : : : : : : : : :ii :;a,. : : ::X:i@8 Z7;:r0Z7XiZS; , i i i , , , , , i i.i.i.i : :.XSW2a7X,r:X,i@M,rrZS820XarX:X:r:7iX;Si7:XZB.7;: a : , : i
# , ;7Z,: : : : : : : : : ::, ;;0i. : , ,,X,Bai:W,7.88Z20S080 . i i i i : i i i i i i i , ii8Z0XZ20XZXa7SZMaaS8X2ir:r:7:7:X;SrS;7..,Za2.7i, M2ZSZXaXa::
# i :.22r:, : : : : , . , : :., 7:ZX, , : , ;X0,rSZ,r:B,riS7ZZW;, : i i i i i i i i i : : 72Wa8a0XZXZX8XX7Mr;ir:X7ZXZS8Xa;7iX:; . iXBXr,X,. 2 , i.rir :
# . ;rB.X:: , , . :.ri7:i . , , X:a2; , : , ;rXi7Z7:;XZ:X;Xi7iZ27 : i i.i i.i i i i : ii08WZW22i7:7:7:7,MSiiSX0S2;r.7iX7BXX., .:ZZa:riX .;X . 77ZXS., ,
# ; ..XZ;:Xir :.riSrS;Xi27a;; . . X:r22 , : , :,X,8SriraZ:X;X;SiS2Z., i i.i.i.;.i : :.2ZM8BZ8;r:X;X;X;X,M2XXBSS.. . , , . ii27800;i.7:: ;22:a20XX . , :
# 7i ,:W,;,XX8aZi; : , : : 7;272ii.7,;XB,, : : , ri@iX:r20;7;X;X;X70X; , i i i : : rXWaZ;Xr7:XiX;S;XiX;MBZXX.. ,.: i i : : . :,7;Z2Z:, Sa8XZ;i . , , : .
# BXr.iZZX0Sa:: , i i i.i : , i:X72S8XXi07, : i : ,7B:XirXWSXiX;X;S;ZaZ;; , , ,.77B807XiXiX;X;XiX;2S8a8X7 . .:X i.i i : i i : , . ;iXXMWa.. , , , : : :
# .S8ZX877 . , : : : i i i :.i : , iiSXZ70Z7 . : i .7X,S;7iZZ0rXi;.7;SSBZ0XaX8aBa8XXiXrS;X;X;S7820XS,i . : ,rZ.i.i.: i.r,;.: , : : , :.aXSi7.: . : : : ,
# 8rSii . : : , i.;.i , i i a8i i.i : , ri20Mi, , : ,r; ;:7:XXWZZi; :.riXXZSZXa;XiX;SrSrSiS2Baa;; . : : : iSS i.;.i;2;XiSr27a;7.: : : , ,.riS7arX,: , :
# ,. . , , :,XraX27ZXZrr.i i.WWi i.i.i : , :r8XarS:i :7X . : i.2Z@2X.: i.riX;Sr2rSrSr2r2rZZX,: : i : i.;,2BZri.;.i,X.;.;.i.;,Xra72ir,; : i : :.riXr2;X:,
# : :.riX7arS:; , , :.X;S:i.: ZZX.: i i.i.i , i,ri2X2 ,i2;; . , :i080:, ;.i.;:Xr2727272iSai i i : i,7;aSB0a,i i.;.i riXr27a7Si;.;:7iXrSii.i.i.i : :.;iSi
# ,7a7Sir , ;iXrSi7,i : ;.; i ir8XX.: : i.i.i.i.i :XZ , rraii : . iXWSr i.;.i.i,r:7i7.;S; i i,7iX;aa@aai: :.;.;.;.;.i i.;,r:7:r:; : i.;.i.;.;.i.i.i i ,
# i i , , r;aX2;7,i i i i ;.i.;.: 7X0SS:r,;.;.i.;.;.:2X i :.SXS,: : . 2ZZ:i i.;.i.i i ;a7 :.X;XrZ2Baa:i i.;.;.;.;.;.;.;.i.i i i i.i.i.i.i.;.;.i.i.i.;.;
# .. i,r;SrX:; i : i i i : :.;.;.; :.S2W2arSrSir.i.;.iZ; i i i:2XS.:.i :iZ2ai; i.i.i Xar i:2X0ZWaa:: i.;.;,r.;.;.i i i.;.;.;.;.;.;.;.;.;.;.;.;.;.;,;.;,i
# ; r:r:;.: i i.;.i XSS;r:r,i i.;.;.; :,ZaB2Z7272:i.;.7Br :.;.i irZr; :.: ;;ZS8XS;r:8Si i;BZ8XX,: i.;,;.;.i i i.i ;:7:;.r,;.;,i i.i i : i.i.;.;.;.;.;,;
# .,.i : : i.i.;.i.i,08WZ2i7;X:i i.;.;.i i:SXB2Sra:i,r S0X,i ;.;.: XXZ:i i : i,7iX2W;: ;r@Sr : ;.;,;.i i.r:7:7:XXWZ0X2Si,;,r,;iS;aXZr2rX:r.i.;,;.;.;.;:i
# i i i,r,i i.;.;,;.i 2@M@MaSiXi7:; i.;.;.i :.SZara:i,; Z0Si; ;.i.; :iaXai; : , 7S2 i r7M;:.;,r,;.i.;:X;S;X;aaM@MWM8aZS.;,r,;,7ir,r:ri7;Sr277.;,r,;,;,r.
# 7Xr27Sr2Xa,;.;,;.;,i 2@MWMWM2SiX;Si;.i.;.;,; ;8Zra:;,r aZ2;X,i.i.;.i iiaXZ7XrZXr i.7XMi:.r,r.i,7;S;S;XrZZMWMWMWMWMS; ;,;,;.;.i,7iX;S;X:r,;,;,;,r,r,r:i
# ; i i.i :i7.;.;.;,;.i ;8MWMWMWMSXiXrS;7,;,r:;.;Z0r2.;:r 7ZZ;2ir.i.;.;.i i,rXM,i.;,Sa@ii,r,;.r;arXi22@WM@MWMWMWMX7 ,.r,;,;,;,;,;,;.;,r:r,;,r,r,;,r,r,r
# :;;SrXir.i.;,;,r,r,;.i .;@@MWMWMWMSSiS72;;.r,r.i2@7S,r,r.;88iSrX:;.;.;,;,; 0,;,;:Z0B,i:r:r.77a;2aMWM@MWM@MaS,: . i.;,;.;.;,r,;,r,;,;,;,;,r,;,r,r,;,r,i
# 7.r,i.;.;,;,;,;,;,;,;,;., :;@WM@M@MWW;7rZr;.r,r,:r@2X,r:7.iZZiXr2rXir.i.; X2i:;,0Ba ;:7ir.XXSiB@MWMWMZ2,: , :.;.;.i.i.;.i i.;,r:r,r,r,r,;,;,r,;,r,r,r.
# ,.i.;,;,;,;.;.i.;,r,r,r,; , ;X@[email protected]:7:i:WaS,r:r.;@07X;Sr272;7,iX8.;:@87.r:7:;,SXSXMWMWMWB . i.;,;,;.;,r:XiXiX7Z;Sr;,r:r,r:r,r:r:r,r,r:r:r:;
# ; ;,;,r,;.i.;.i i.i ;,r:r:r,; , X8MWMWMWai2XX,r:7:;.082,r:r,WX@8aiX;S7272iW2::@2i,7:r:;:arSZM@MBMWX i,r:r,;.riSrS;X;aSBZ@a8X7,r:r:r,r,r,r:r:r:r:r:r:7.|
# :i,;,;,;,;72XWZ077:7.; ;,r,r,;,; ,:MWMWMWWr2XX.r:7:r.Z0S,7:;0S;88BXXiS;SrXaZ,W;;:7i7,r;a70WM@M@MWi r:7:r,riS72r22BBMWM@MrBS;:7,r,r:r:r:r:r:r,r,7,r:r:;|
# 7 r,;,r,r.S72rXXMWZ;X;7:;.;.r:r:r,: 8WM@MWMSSXS,r:7i7 007:7.07S;XXW807X;2;Z00i;:7ir:XXZ2MWM@M@M0: 7ir:;,7rZ722M@MWM@MWMW0;i,7:7:r:r:r,;,;,r,;,;,r:7:7.|
# :i,;,r,r,;:WaSiMWMWMZarS;S;Xir,r:7:r 7WMWMWM0a72:ri7ir:M7riiZ2i2rSraa@80XXXM:r;XiriaX8WM@MWMWMS:,7i7,r;ZX2r0WMWMWMWMWB7i ;:7i7:7i7:r,r:X;Sr27S;X:r,r:;|
# '''
x = input();n = int(input())
if n > len(x):print("impossible")
else:x = set(x);print(abs(n - len(x)))
| Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
Input Specification:
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Output Specification:
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
Demo Input:
['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n']
Demo Output:
['0\n', '1\n', 'impossible\n']
Note:
In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6. | ```python
"""
███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ██ ██ ██ ██ ██ ███ █████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ████ ████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ██ ██ ██ ██ ██ ███ █████████████████████████████████████
██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████████████████████████████████████
███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
"""
# '''______________________________________________________________________________________________'''
# '''
# 2i2r2X0S@aZB87Ma7XWaB8a2WaBaBZ0BBi80SaWWM@B;S7@;ZZ7i8B@7B8WZB0MWMWMWM8@ZWZWZWZWaSXWBMWMWMWM8WWMBM8@ZBZW8WX0080@8W8MWM8B8@8W0aZM0WBMZWWMWMWM8@0WWX r,7,
# 2XrS;S702Z8Z:WaX;B202Z;B2020202WarXW;ZZMWM8Si7S2iMaX,X2B722B2BZW8MWMWMWM0MaB202BaZX8Z@BM@MWMBM0MWM@MZ0aBZBXZaWZBZW8@BMZBZ@ZBaZZWZB0MZBBM@MWM8WZ@W; : ,
# WXSiSiZW0a@;BZS;WZBZ0i08BaBa0aB8W;B08XW@MWMZXrS2XZM00rXr0XSXBZB2B0@BM@MWMWM0WZWZW8WaWZBBMWMWMWM0@0M@MBMZBZ@ZB8WZWZW8@WMZW8M0@Z08WZW0M8MSrBM@MWMBM@a i.
# 02ir.,S@Z0X8BaiBaBZW;2ZB28ZWZWZ08SZWZZaWBMB@727S;2@M8WaZ;SrX;aa0X8Z@Z@BMWMWMWM@MBM8BZWZBZW8M@MWMWMZMWM@MWM8@8WZWZWZW8@WM8WZMB@8@8W0M0MWMr,.WWM@MWMWB .
# Z:;.:.BBX;808iBZ8aW77Z@ZZZBZBZ8XMr0ZWXBZM0M0Bi0rXi@WMa@B@Sa;7i2SZX2XW0@0MBM@M@MWMWM8WZBaBa08MWMWMWMBM0MWMWMW@aBZW8W8@0M@M8W8MW@ZWZMB@0MWMS. ir@@MWM@@
# Xr.i ZWBiZWB:08BaWX7XW82S@Z00@;BBaS@80SW0@8M8Z7B;X7MWMZB0MZWS2i2a0XX:Z0M0B8MBM@MWMWMWMBMZBZW0@BM@MWMWMBMWMWM8W8W8@8@BM@MZWZM@M0W8@0@0M@MB, . iXMWMWM
# Zir,XW0iZZM;ZZBZWZXi08ZrWZWaMaS8MSZ8WZaZWBMB@ZSa0i72MWMZB0M0@0BXSXWZai7X@0WaBZMWMWMWM@MWMWM0M8WZMWMWM@M@MWMWMWMWM8W8@8WZ@W@8W0MWM@Wa@8MBMWMWr i , rXMW
# rXX20W:XaMSX8W2W02i28ZiW8Wa@0S7M8BXMBWX8ZMWMB@aS88:S0MW@ZB0MB@8MZ8780@2Xi80@ZBZMWMWMWMWMWMWMBWaBZ@WMWMWMWMWM@MWM@MBW8WZW8MBW0@WMWMWM8W0MBMWMW2 :.; , i
# Z;SSMXai0B2ZBaB02iXZ0:Z0BZ00W:BB@Z08WZWS@0MWMBMSaBZ,Z@M@M8BBMWM8@0@28aM00;Sa@8WZBZM@MWMWM@M@MWMWWZWBMWMWM@MWMWM@MWM@M8W8M0M0@0MWMWMWMBMWMWMWMWM,,.;,;
# Za:ZSS;S80S@ZBW8;8r0;S8WZWZM2X0@ZW8WZW8W8WBMWMBM70BZ:@WM@M0BBMWMBM8WZ08@0@a2XWBMBWZ@BM@MWMWMWMWMWM8WWMWMWMWMWMWMWMWMWMZW8M8M8@WM@MWMWMWMBMBMWMBMZ: ;,i
# MX7XrrSS@SBaBB@iWXSrX2@8BZ@027M8WZ@ZW8WW@8WWMWM0WZ@08:MWMWMBW0MBMBMWM0WZW0M8BS0Z@BMB@0M@M@MWMWMWM@MBM0M@MWMWM@MBMWMWM@M0@BM0MZMWMWMWMWM@MWMWMWWrBW8 i
# SXr8:XXMa8ZBBMr80X;SrWZ@XB0@i80@B@@@ZWZM0Ba@WMWMZWB@88;MWMWMW@BM@M@MWM@M0@ZW0@ZWZW0MWMBMWMWMWMWM@M@MWMBM@MWMWMWMBMWMWMWMWMB@8WWMWM@MWM@MWM@MBMWM7r2MX:
# Sia7S:08BaBBM22BWia;8Z@Z28MZXZ@8W0MWBZBZMZBZMWM@Wa@@W80XM@MWMWMBMWMWMWMWM@MZWZWZW8W8M@MWMWM@M@M@MWMWMWMBMWMWM@M@MWMWMBMWMW@W@ZM0M@MWM@M@M@M@MWM0MBX ZS
# 7XX2;XaWZWWM02ZMrZXX0@80S@0Bi@8WZ@WMBMBWBMZBZMWMWWZMWW88ZMWMWMWMWM@M@M@M@MWMWM0W8@8WZ@0MWM@MWMWMWMWMWM@MBMWMWMBMBM@MWMWMWMWM@MWMBM@MWM@MWMWM@M@MWMWM ,
# 2iarX7@@WWMW0XM8S8X2M8MX00M2S0@8B0M@MB@ZWW@aW8MWM0W8MB@ZW0MWMWMWM@M@M@MWM@MWM@MWMWMZW8W0MWMWM@MWM@MWMWM@MWMWMWMWM@MWMWM@MWM@MWMBMWMWMWM@MWMWMWM@MWMWMX
# 7X7S;00MWMWWXWBZZ0;M8W0aZ@BZ7M0WZMBM@M0B8M@@ZW8MBM8WBMWMZWWMWMWM@MWMWM@MWMWMWMWM@MWM0@0MBMWM@MWMWM@MWMWM@MWMWM@MWMWM@MWM@MWMWMWMWMWM@MWM@MWM2aWM@MWM@M
# a;2i2000MWWa0BBSMrZ0BZB7@0MXZ0MZWB@WM@M0WBM@WZW0M@M8@WM@M8BBMWMWMWMWM@MWMWMWMWMWMWM@MWMWMB@WMWMWMWM@MWM@M@MWMWMWMWM@MWM@M@MWMWMWMWMWMWMWMWMWMX.;MWM@MW
# 22rXSBZMWMZW8M2@ZXZ@8MSZ0@BZSMBB8@8M@MWM0@@MB@ZBWMWMZMWMWM0WBMWM@M@MWM8MWM@M@MWMWMWM@MWMWMBMWMWMWMWMWM@M@MWM@MWMWMWMWM@MWMWM@MWMWMWMWM@M@M@MWMZ. ;7@WM
# 07X,MaMWM8WZM0W087M8WWaSM0MSB0MZMWMBMZMWM0MWM0@8@BMWMZM@MWMBMWMWM@MWMWMXW@MWM@MWMBMBMWMWMWMBMBMWMWMWM@MWMWMWMWMWM@M@M@MWMWMWM@M@MBMWMWMWMWMWMWM8, : ii
# :r:Z@@WMaWZWW@ZM7WBWZM;80MB8aMWWWMWMBXWM28WM@M8@8WBMW@0M@MWM@MWMWM@MWMWMX2WMWM@MBMWMWMWMWMWMWMBMWMWMWMWMWM@MWMWM@M@MWM@MWM@MWMWMWMWM@MWMWM@MWMWMZ,.r,:
# 7 i2MWMX0BB0MZWZZ@@ZMWX2M0Ma00M0MWMWB M@@ BWMWBZM8@BMW@BMWMWMWMWMWMWM@MWMXiXMWMWMWM@M@MWM@MWMWMWMWM@MWMWMWM@MWM@M@M@MWM@MWMWMWMWMWM@M@MWMWMWMWM@MS::7,
# ::i8WMXXW@8MBW808M8WWM;[email protected],.W@MW0ZM8W0MWWWMWM@MWMWM@M@MWMWM0i ZWMWMWMWMWM@MWM@MWMWM@M@MWM@MWMWMWM@MWMWMWM@M@MWMWMWM@MWMWMWM@M@M@MWM;iir
# i M@MX7XMZMBMZWZMBW0M@XZ@BM8W8M0M@MWZ 2WM.;.Z@MW2aM0M0MWMWMWMBMBMWMWMW@WM@M@a i7MWMWMBM@M@MWMWMWMWMWM@MWMWM@MWM@MWMWM@M@MWMWMWM@MWMWMWMWMWM@[email protected],
# aWM;r;ZWWBM0MBMWMZMWM;W0MBW8@WM@[email protected],7 2WM@7SMW@8MBMWMWMWMWM@MWMBZZMWMWM;: X2M@MZ@WM@MWMWMWMWMWMWMWM@MWMWMWMWMWMWMWMWMWM@MWMWMWMWMWMWMWM@MZ@WM:;
# ZWMXrrXrM8M0@8MWMWMWM@Sa@0M8@[email protected]@MWrXMW@8MWMWM@M@MWM@MWMWX;MWM@M87 i,ZWM082M@MWMWM@MWM@MWM@M@MWMWMWM@M@MWMWM@MWMWM@MWMWM@MWM@MWM@M MW8i
# WM7;;Si2@@WZW@WMWM8M@Mr0B@WM8WWMWMWMi;:iWM r:7.i8MW7:M@@ZMBMWMWM@MWMWMWMW7 SSMWMWB:;,rrB@@X2SM@MWM@MWM@M@MWMWM@M@MWMWM@MWM@MWMWMWMWMWMWMWMWMWM@MWZ MW.
# M7;iX;S7MW@:M0M@[email protected] XWr ;.i .rM@X W@M0W8M@M@M@MWM@MWMWS ;ia2MWM8S:r,r7BZZ,;rWWMWMWMWMWM@MWMWMWMWM@MWM@M@MWM@M@[email protected]
# 0aiX;2;2@MZ7@MWMWMWMWM70B@WMBMWM@MWMiXS80MWW0MZZi, W@a aWM0@0MWM@M@MBM@[email protected]:7iXX@WWr;.i.XaMaZS@8M@M@MWMWM@M@MWMWMWMWM@M@MWMWM@M@MWM@M@MWM@MWMWM:,8M
# M2XiSr2;MWZ;MWMWMWMWMW0SM8M@MBMWMWM@2,r@MiMiZWM@MW@XB@M .BMBWWMWM@MW82MWM@MW8 X;Xi; rS@ZMWMWMWM0M8MWMZMWMWMWM@MWM@M@M@MWMWMWM@MWMWMWMWMWMWMWMWMWMWa :W
# 8Z;X;SrXBM2X2MWM@MWM@M8ZB@WMWMBMWMWMX.,M;.:[email protected]@MWMWMW@[email protected]:X7MWWWM@M@MWMW0ar [email protected]@MWMWM@MWMWMWM@MWMWMWM@M@MWM@MWM2@WMWM8: 2
# @XSiX;2XMW. :WM@MWM@M0MSM0MWMWMWMWMWW X@, . B2@WMWM@MWMS8X. WWMWMWM@[email protected] 82MWM@M@M8BX: [email protected]@MWM@MWMWM@M@M@[email protected],;,
# 0Z;X78X:XM . M@MWMWMWXBB0@WMWMWMWMWM@:,M , . @ZMWM@M@ZBMX::: rWM@MWMWMWMWZ70WMWMiaZ,.,;WSMWMWMW0Bi i.iWZ,XWMWMWMWMWM@[email protected]@MWZ.:
# M2ZSZ.. r@. ,XMWMWM@M B0W0MWM@MWMWM@M;:@S , . W0MWMWW8X Mi,.: ,XMWMWMWMWMZ872SM@M0i:i .2@0M@MB@B2 . , M0r:M@MWMWMWM@MWMWMWMWMWMWM@MWMWMWMWMWM :ZM@MB.
# B0r: . , M . ,@MWMWMW.iMZMWMWMWMWM@M@W,WW. , . r;Z2a;. ;;S : : . S8MWM@M@M88rX;2ZM;: . .:aX8S8r: , . iWMX;8M@MWMWMWM@M@MWM@MWMWMWMWMWMWMWMWMWi.:BM@M ,
# ; . : : .Z: , ZWMWMWM .@WWMWMWM@MWMWM@iXMW; , . . . . .i; : i : . ,;B0M@M@M8BSS:;,i . , . . , . . . ,@M8S,BWM@MWMWMWMWM@MWMWM@MWM@MWM@MWMWMWM.;,iWMWZ
# . : : , S,. , MWM@MW: MWMBM@[email protected].. . . . iir : i i i : . XXZZM@M0ZXZXa:7 , . . . . . .,WWMr::XXM@MWMWMWM@MWMWMWMWM@M@MWM@M@MWM@MW7,7.i@MW.
# i : : : ,,X , [email protected]@MWM@MWM.. S8M@@a02B2a;i i.i.i i i i , . ;,XaMWMX7iXXBZ0SSiXiX;aS@WMW2 , ria@MWMWMWMWM@M@MWMWMWMWMWM@M@MWW8MWMSiiX 8WMX
# , : : : ,r, : .BMWM@X :WMWM@M@MWM0MWMW@ . . XX0ZBZa,: i i i i i i : : , : . raMaS:ii80M@MWMWMWMB8:: i.i:X7MWMWM@MWMWMWMWM@[email protected]:77S8M
# i : : : : X,, : ,WMWMX. @WMWMWMWMW@rM@MW2 , , . . . : : i i i i i i i i i : , . i:X,, , : i.i : , , i.r.;ia@MWMWMWMWMWM@M@M@[email protected]: Sa,0
# . : : : , X : . Z@M@Z .,[email protected] : : : : : i i i i i i i i i i.i i : : : : : , , : : : i.i.;,i,X7MWMWM@MWMWMWMWM@MWMWM@M@MWM@M8iaMWB7ri. 0.i
# i i : : : : : : . MWMZ. .BM@[email protected];r i i i i i i i i i i i i i i i i.i i i : i i i i.i.i.i.i.i,; riaWM@M@M@MWMWMWMWM@[email protected]:X,.X:
# . : : : : , : : .XM@M , :WM@MWMWM@M7. MWZ.r i i i : i i i i i i i i i i i i i.i.i i i i i :.i.i.i.;.;.i:72MWM@MWM@M@M@MWMBMWMWMWM@MWMWMXr:2WMXZ,X 2..
# i : : : : : : : , .WMW. , 0WMWMWMZMWM . B@Z : i i i i i i i i i i i i i i i i i i.i i i i i i i i.i.i.i X:MBMWMWMWM@M@MWMWWWMWMWMWM@MWMWa:S.B@2ari7ar
# . : : : : : : : , rWMi. . MWMWM@Z0MW8 . X@8 : i i i i i i i i i i i i i i i i i i.i i.i i i.i i i i.i i;2@X@MWMWM@M@MWMWMrMWMWMWMWMWMWMX7;X,MBZ7r:ZX.
# i : : : : : : : : . WWM . ,,M@MWMSX@M@, , .Xa : i i i i i i , : i i i i i i i i i i i.i i.i i i.i i i.:.7ZW,MWMWM@MWMBMWMZi@MWMWM@MWMWMWZ:SrX:@SB,7:@
# . : : : : : : : : , MW, , ,2M@M@M MWMB. : ..; i i i i i i :i: i : i : : i i i i i i i i.i.i : i i.i.i [email protected]@MWMWM@M@0WMW8 MWMWMSMWMWMWMar;S;X;22S:7;0
# i : : : : : : : : ,.. M0, , .@[email protected]. : : i i i i i i i a2. , : , , : i i i i i i i i i i.i i i i i;Zi:ZM@M@MWMWMrMWMS:BMWM8i@MWMWMWW,SrSrX,0XrirS
# , : : : : : : : : r .:M,. . ;WMWM,,WMWM . : i i i i i i i : M0r.r:7iXir , i i i i i i : i i.i.i i i :i2i:,MWMWM@MWMaSBMW8 @WMWa B@MWMWM8;rS;S;72a:Xi7
# i : : : : : : : : ,,r .7M , , 2WM@a @WMWM , i i i i i i i i . @W8iSrS;8aBXr i i i i i i i i i i i i :.X .,7@M@[email protected],aM@M:riMWMWMWM,X;S;X;W:7iX,
# . : : : : : : : : ri, .;Z : ; 0WM2.XMW8@M . i i i i i i i i , ;0S;XrSrSrS,: i i i i i i i i i i i i ; . 77MWMWMWMWZ,irM@Z @WM8;irXM@MWMWriX;X:W7riXir
# i : : : : : : : : ,,X , .,i ,,r M@W 7WM:M@M . i i i i i i i i : ,,Xr2rSi; : i : : i i i i i i i i i.i : 7,[email protected]:;WMS,BMWX:X;;ZM@MWMi7;S:Ba;iXiX,
# . : : : : : : : : r;; , , : iii,[email protected]@M . : i i i i i i.i.: , i,; , : i i i i i i i i i i i i i : i;;WMWMWMWM.7iX.M@8 MWM.X;S:[email protected]:Z
# i : : : : : : : : ,.X:, : : : 7:,aM ,WM 0WM@M,. : i i i i i i i : : : : : i : i i i i i i i i i i i i ,iriM@MWMWM;;iXirrM2,WM7;;X;X:r@M@MW;,ZZr:7:77Z
# . : : : : : : : : :iX , : : .:X,;@r Ma,:MWM@MX. :.i.i i i i : : , , , . . , , , : : i i i i i i i : ,:X 8WMWMWMaiiXiXi;@B MWriX;S;X:7WM@M77ar:X:7aZ .
# i : ; : : : : : : , r;7 : : : ii7.2iiWa ,WMWSBM0. , i.i.i.i.i.ZXZXa7arX7aXaXZSZXa7a:: i.i.i i i i : :iXiZWMZMWM@;:XiX;X,00;@a.X;X;X;X,rWM@MX;:XirZ7 .
# . ,ir , : : : : : , X;: : : : riX,r:M:r Z@M;:WMWX , : i i i i.i.;,riX,Xi7:;,;,i.ri; i i.i.i.i.i : iiXS0aMX@WM@X:X;X;S;7:0ZM.7;X;X;X;X,;ZMWW 7ir2S , ,
# : : 2X. : : : : : : , X:, : , : ::X,aa;:;,M@M BW0Za,. : i i i : : , , : , , . , : , : i i i.i i , 7i2ZB;MW:WMWZ.XiXiXiXir;MrriXi7iX;XiX:;ZMW0.;rS , :
# . :XZ : : : : : : : ,.S , ; : : ..7XX:7::0MS7 Mia727; , i i i i :.i , . . , r.: i i i i i i : :,7r8Z8ra@i;MWB 7;XiXiXiX,Sai:7i2X8XSiXi7Z7 8Wa a , i .
# i , aS. : : : : : : : ,:X ,,r , : , r:7i7.a@Xr;@2,B:S2S , i i i i irWZ020aW8M8X i i.i i i : , ;:SSWaZr;Ba MWM riXi7i7:7:r8a7828SZ;XiX;7aZ.r r7r , : :
# , i78 , : : : : : : : ,:r :ir , : , iiX:;:M7;S8ri2Z,77B;, i i i.i :,Xr272;7.: i i.i i i i , 7;Z8BXa;rX0 SWM.r:r:XraXZ208@XarX:r:X;Xir28.7i; . . , , .
# : ,.2Si : : : : : : : : :ii :;a,. : : ::X:i@8 Z7;:r0Z7XiZS; , i i i , , , , , i i.i.i.i : :.XSW2a7X,r:X,i@M,rrZS820XarX:X:r:7iX;Si7:XZB.7;: a : , : i
# , ;7Z,: : : : : : : : : ::, ;;0i. : , ,,X,Bai:W,7.88Z20S080 . i i i i : i i i i i i i , ii8Z0XZ20XZXa7SZMaaS8X2ir:r:7:7:X;SrS;7..,Za2.7i, M2ZSZXaXa::
# i :.22r:, : : : : , . , : :., 7:ZX, , : , ;X0,rSZ,r:B,riS7ZZW;, : i i i i i i i i i : : 72Wa8a0XZXZX8XX7Mr;ir:X7ZXZS8Xa;7iX:; . iXBXr,X,. 2 , i.rir :
# . ;rB.X:: , , . :.ri7:i . , , X:a2; , : , ;rXi7Z7:;XZ:X;Xi7iZ27 : i i.i i.i i i i : ii08WZW22i7:7:7:7,MSiiSX0S2;r.7iX7BXX., .:ZZa:riX .;X . 77ZXS., ,
# ; ..XZ;:Xir :.riSrS;Xi27a;; . . X:r22 , : , :,X,8SriraZ:X;X;SiS2Z., i i.i.i.;.i : :.2ZM8BZ8;r:X;X;X;X,M2XXBSS.. . , , . ii27800;i.7:: ;22:a20XX . , :
# 7i ,:W,;,XX8aZi; : , : : 7;272ii.7,;XB,, : : , ri@iX:r20;7;X;X;X70X; , i i i : : rXWaZ;Xr7:XiX;S;XiX;MBZXX.. ,.: i i : : . :,7;Z2Z:, Sa8XZ;i . , , : .
# BXr.iZZX0Sa:: , i i i.i : , i:X72S8XXi07, : i : ,7B:XirXWSXiX;X;S;ZaZ;; , , ,.77B807XiXiX;X;XiX;2S8a8X7 . .:X i.i i : i i : , . ;iXXMWa.. , , , : : :
# .S8ZX877 . , : : : i i i :.i : , iiSXZ70Z7 . : i .7X,S;7iZZ0rXi;.7;SSBZ0XaX8aBa8XXiXrS;X;X;S7820XS,i . : ,rZ.i.i.: i.r,;.: , : : , :.aXSi7.: . : : : ,
# 8rSii . : : , i.;.i , i i a8i i.i : , ri20Mi, , : ,r; ;:7:XXWZZi; :.riXXZSZXa;XiX;SrSrSiS2Baa;; . : : : iSS i.;.i;2;XiSr27a;7.: : : , ,.riS7arX,: , :
# ,. . , , :,XraX27ZXZrr.i i.WWi i.i.i : , :r8XarS:i :7X . : i.2Z@2X.: i.riX;Sr2rSrSr2r2rZZX,: : i : i.;,2BZri.;.i,X.;.;.i.;,Xra72ir,; : i : :.riXr2;X:,
# : :.riX7arS:; , , :.X;S:i.: ZZX.: i i.i.i , i,ri2X2 ,i2;; . , :i080:, ;.i.;:Xr2727272iSai i i : i,7;aSB0a,i i.;.i riXr27a7Si;.;:7iXrSii.i.i.i : :.;iSi
# ,7a7Sir , ;iXrSi7,i : ;.; i ir8XX.: : i.i.i.i.i :XZ , rraii : . iXWSr i.;.i.i,r:7i7.;S; i i,7iX;aa@aai: :.;.;.;.;.i i.;,r:7:r:; : i.;.i.;.;.i.i.i i ,
# i i , , r;aX2;7,i i i i ;.i.;.: 7X0SS:r,;.;.i.;.;.:2X i :.SXS,: : . 2ZZ:i i.;.i.i i ;a7 :.X;XrZ2Baa:i i.;.;.;.;.;.;.;.i.i i i i.i.i.i.i.;.;.i.i.i.;.;
# .. i,r;SrX:; i : i i i : :.;.;.; :.S2W2arSrSir.i.;.iZ; i i i:2XS.:.i :iZ2ai; i.i.i Xar i:2X0ZWaa:: i.;.;,r.;.;.i i i.;.;.;.;.;.;.;.;.;.;.;.;.;.;,;.;,i
# ; r:r:;.: i i.;.i XSS;r:r,i i.;.;.; :,ZaB2Z7272:i.;.7Br :.;.i irZr; :.: ;;ZS8XS;r:8Si i;BZ8XX,: i.;,;.;.i i i.i ;:7:;.r,;.;,i i.i i : i.i.;.;.;.;.;,;
# .,.i : : i.i.;.i.i,08WZ2i7;X:i i.;.;.i i:SXB2Sra:i,r S0X,i ;.;.: XXZ:i i : i,7iX2W;: ;r@Sr : ;.;,;.i i.r:7:7:XXWZ0X2Si,;,r,;iS;aXZr2rX:r.i.;,;.;.;.;:i
# i i i,r,i i.;.;,;.i 2@M@MaSiXi7:; i.;.;.i :.SZara:i,; Z0Si; ;.i.; :iaXai; : , 7S2 i r7M;:.;,r,;.i.;:X;S;X;aaM@MWM8aZS.;,r,;,7ir,r:ri7;Sr277.;,r,;,;,r.
# 7Xr27Sr2Xa,;.;,;.;,i 2@MWMWM2SiX;Si;.i.;.;,; ;8Zra:;,r aZ2;X,i.i.;.i iiaXZ7XrZXr i.7XMi:.r,r.i,7;S;S;XrZZMWMWMWMWMS; ;,;,;.;.i,7iX;S;X:r,;,;,;,r,r,r:i
# ; i i.i :i7.;.;.;,;.i ;8MWMWMWMSXiXrS;7,;,r:;.;Z0r2.;:r 7ZZ;2ir.i.;.;.i i,rXM,i.;,Sa@ii,r,;.r;arXi22@WM@MWMWMWMX7 ,.r,;,;,;,;,;,;.;,r:r,;,r,r,;,r,r,r
# :;;SrXir.i.;,;,r,r,;.i .;@@MWMWMWMSSiS72;;.r,r.i2@7S,r,r.;88iSrX:;.;.;,;,; 0,;,;:Z0B,i:r:r.77a;2aMWM@MWM@MaS,: . i.;,;.;.;,r,;,r,;,;,;,;,r,;,r,r,;,r,i
# 7.r,i.;.;,;,;,;,;,;,;,;., :;@WM@M@MWW;7rZr;.r,r,:r@2X,r:7.iZZiXr2rXir.i.; X2i:;,0Ba ;:7ir.XXSiB@MWMWMZ2,: , :.;.;.i.i.;.i i.;,r:r,r,r,r,;,;,r,;,r,r,r.
# ,.i.;,;,;,;.;.i.;,r,r,r,; , ;X@[email protected]:7:i:WaS,r:r.;@07X;Sr272;7,iX8.;:@87.r:7:;,SXSXMWMWMWB . i.;,;,;.;,r:XiXiX7Z;Sr;,r:r,r:r,r:r:r,r,r:r:r:;
# ; ;,;,r,;.i.;.i i.i ;,r:r:r,; , X8MWMWMWai2XX,r:7:;.082,r:r,WX@8aiX;S7272iW2::@2i,7:r:;:arSZM@MBMWX i,r:r,;.riSrS;X;aSBZ@a8X7,r:r:r,r,r,r:r:r:r:r:r:7.|
# :i,;,;,;,;72XWZ077:7.; ;,r,r,;,; ,:MWMWMWWr2XX.r:7:r.Z0S,7:;0S;88BXXiS;SrXaZ,W;;:7i7,r;a70WM@M@MWi r:7:r,riS72r22BBMWM@MrBS;:7,r,r:r:r:r:r:r,r,7,r:r:;|
# 7 r,;,r,r.S72rXXMWZ;X;7:;.;.r:r:r,: 8WM@MWMSSXS,r:7i7 007:7.07S;XXW807X;2;Z00i;:7ir:XXZ2MWM@M@M0: 7ir:;,7rZ722M@MWM@MWMW0;i,7:7:r:r:r,;,;,r,;,;,r:7:7.|
# :i,;,r,r,;:WaSiMWMWMZarS;S;Xir,r:7:r 7WMWMWM0a72:ri7ir:M7riiZ2i2rSraa@80XXXM:r;XiriaX8WM@MWMWMS:,7i7,r;ZX2r0WMWMWMWMWB7i ;:7i7:7i7:r,r:X;Sr27S;X:r,r:;|
# '''
x = input();n = int(input())
if n > len(x):print("impossible")
else:x = set(x);print(abs(n - len(x)))
``` | 0 |
|
424 | A | Squats | PROGRAMMING | 900 | [
"implementation"
] | null | null | Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? | The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. | In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. | [
"4\nxxXx\n",
"2\nXX\n",
"6\nxXXxXx\n"
] | [
"1\nXxXx\n",
"1\nxX\n",
"0\nxXXxXx\n"
] | none | 500 | [
{
"input": "4\nxxXx",
"output": "1\nXxXx"
},
{
"input": "2\nXX",
"output": "1\nxX"
},
{
"input": "6\nxXXxXx",
"output": "0\nxXXxXx"
},
{
"input": "4\nxXXX",
"output": "1\nxxXX"
},
{
"input": "2\nXx",
"output": "0\nXx"
},
{
"input": "22\nXXxXXxxXxXxXXXXXXXXXxx",
"output": "4\nxxxxxxxXxXxXXXXXXXXXxx"
},
{
"input": "30\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx",
"output": "0\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx"
},
{
"input": "104\nxxXxXxxXXXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX",
"output": "4\nxxxxxxxxxXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX"
},
{
"input": "78\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX",
"output": "3\nXXXXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX"
},
{
"input": "200\nxxXXxxXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX",
"output": "4\nXXXXXXXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX"
},
{
"input": "198\nxXxxXxxXxxXXxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx",
"output": "5\nxxxxxxxxxxxxxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx"
},
{
"input": "200\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"input": "198\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "99\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"input": "200\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"output": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
{
"input": "198\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"output": "99\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
{
"input": "2\nxx",
"output": "1\nXx"
},
{
"input": "2\nXx",
"output": "0\nXx"
},
{
"input": "2\nxX",
"output": "0\nxX"
},
{
"input": "4\nXXXX",
"output": "2\nxxXX"
},
{
"input": "4\nxxxx",
"output": "2\nXXxx"
},
{
"input": "4\nxxXX",
"output": "0\nxxXX"
},
{
"input": "4\nXXxx",
"output": "0\nXXxx"
},
{
"input": "4\nxXxx",
"output": "1\nXXxx"
},
{
"input": "4\nXxxx",
"output": "1\nXXxx"
},
{
"input": "4\nxxxX",
"output": "1\nXxxX"
},
{
"input": "4\nxxXx",
"output": "1\nXxXx"
},
{
"input": "4\nXXXx",
"output": "1\nxXXx"
},
{
"input": "4\nxXXX",
"output": "1\nxxXX"
},
{
"input": "4\nXxXX",
"output": "1\nxxXX"
},
{
"input": "4\nXXxX",
"output": "1\nxXxX"
},
{
"input": "4\nXxXx",
"output": "0\nXxXx"
},
{
"input": "6\nxXXxXX",
"output": "1\nxxXxXX"
}
] | 1,594,553,388 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 20,172,800 | n = int(input())//2
l1 = list(input())
const = l1.count("x")-l1.count("X")
if const<0:
const=-const
const-=1
while const:
const-=1
l1[l1.index("X")]="x"
elif const>0:
const-=1
while const:
const-=1
l1[l1.index("x")]="X"
print("".join(l1))
| Title: Squats
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting.
Output Specification:
In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
Demo Input:
['4\nxxXx\n', '2\nXX\n', '6\nxXXxXx\n']
Demo Output:
['1\nXxXx\n', '1\nxX\n', '0\nxXXxXx\n']
Note:
none | ```python
n = int(input())//2
l1 = list(input())
const = l1.count("x")-l1.count("X")
if const<0:
const=-const
const-=1
while const:
const-=1
l1[l1.index("X")]="x"
elif const>0:
const-=1
while const:
const-=1
l1[l1.index("x")]="X"
print("".join(l1))
``` | 0 |
|
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds.
If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows:
1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game. | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
{
"input": "8 8 1 1 1",
"output": "Second"
},
{
"input": "15 14 32 65 28",
"output": "First"
},
{
"input": "894 197 325 232 902",
"output": "First"
},
{
"input": "1 2 8 8 5",
"output": "Friendship"
},
{
"input": "37 261 207 1 1000",
"output": "Friendship"
},
{
"input": "29 344 406 900 1",
"output": "Friendship"
},
{
"input": "1 2 8 9 8",
"output": "First"
},
{
"input": "2 9 8 8 9",
"output": "Friendship"
},
{
"input": "213 480 811 134 745",
"output": "First"
},
{
"input": "2 313 856 964 421",
"output": "Friendship"
},
{
"input": "1 10 2 6 10",
"output": "Friendship"
},
{
"input": "2 7 6 2 3",
"output": "Friendship"
},
{
"input": "637 324 69 612 998",
"output": "Second"
},
{
"input": "13 849 819 723 918",
"output": "Friendship"
},
{
"input": "9 5 7 8 7",
"output": "First"
},
{
"input": "6 5 7 10 4",
"output": "Friendship"
},
{
"input": "61 464 623 89 548",
"output": "First"
},
{
"input": "641 31 29 161 802",
"output": "Friendship"
},
{
"input": "3 3 1 6 9",
"output": "Friendship"
},
{
"input": "2 3 9 8 2",
"output": "Friendship"
},
{
"input": "485 117 368 567 609",
"output": "First"
},
{
"input": "4 202 512 995 375",
"output": "Friendship"
},
{
"input": "424 41 41 909 909",
"output": "Friendship"
},
{
"input": "884 913 263 641 265",
"output": "Second"
},
{
"input": "12 462 8 311 327",
"output": "Second"
},
{
"input": "436 306 266 493 580",
"output": "Second"
},
{
"input": "69 1 2 1 2",
"output": "First"
}
] | 1,595,591,650 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 6,656,000 | s,v1,v2,t1,t2=input().split()
time_1=int(t1)+int(s)*int(v1)+int(t1)
time_2=int(t2)++int(s)*int(v2)+int(t2)
if(time_1<time_2):
print("FIRST")
elif(time_2<time_1):
print("SECOND")
else:
print("FRIENDSHIP")
| Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds.
If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows:
1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game.
Input Specification:
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
Output Specification:
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
Demo Input:
['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n']
Demo Output:
['First\n', 'Second\n', 'Friendship\n']
Note:
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. | ```python
s,v1,v2,t1,t2=input().split()
time_1=int(t1)+int(s)*int(v1)+int(t1)
time_2=int(t2)++int(s)*int(v2)+int(t2)
if(time_1<time_2):
print("FIRST")
elif(time_2<time_1):
print("SECOND")
else:
print("FRIENDSHIP")
``` | 0 |
|
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*. | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value. | Print a single number — the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"input": "15 16\n-15 -5 -15 -14 -8 15 -15 -12 -5 -3 5 -7 3 8 -15",
"output": "6"
},
{
"input": "1 4\n-3",
"output": "1"
},
{
"input": "10 7\n6 4 6 6 -3 4 -1 2 3 3",
"output": "5"
},
{
"input": "2 1\n1 -1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "8 13\n-11 -1 -11 12 -2 -2 -10 -11",
"output": "3"
},
{
"input": "16 11\n3 -7 7 -9 -2 -3 -4 -2 -6 8 10 7 1 4 6 7",
"output": "2"
},
{
"input": "67 15\n-2 -2 6 -4 -7 4 3 13 -9 -4 11 -7 -6 -11 1 11 -1 11 14 10 -8 7 5 11 -13 1 -1 7 -14 9 -11 -11 13 -4 12 -11 -8 -5 -11 6 10 -2 6 9 9 6 -11 -2 7 -10 -1 9 -8 -5 1 -7 -2 3 -1 -13 -6 -9 -8 10 13 -3 9",
"output": "1"
},
{
"input": "123 222\n44 -190 -188 -185 -55 17 190 176 157 176 -24 -113 -54 -61 -53 53 -77 68 -12 -114 -217 163 -122 37 -37 20 -108 17 -140 -210 218 19 -89 54 18 197 111 -150 -36 -131 -172 36 67 16 -202 72 169 -137 -34 -122 137 -72 196 -17 -104 180 -102 96 -69 -184 21 -15 217 -61 175 -221 62 173 -93 -106 122 -135 58 7 -110 -108 156 -141 -102 -50 29 -204 -46 -76 101 -33 -190 99 52 -197 175 -71 161 -140 155 10 189 -217 -97 -170 183 -88 83 -149 157 -208 154 -3 77 90 74 165 198 -181 -166 -4 -200 -89 -200 131 100 -61 -149",
"output": "8"
},
{
"input": "130 142\n58 -50 43 -126 84 -92 -108 -92 57 127 12 -135 -49 89 141 -112 -31 47 75 -19 80 81 -5 17 10 4 -26 68 -102 -10 7 -62 -135 -123 -16 55 -72 -97 -34 21 21 137 130 97 40 -18 110 -52 73 52 85 103 -134 -107 88 30 66 97 126 82 13 125 127 -87 81 22 45 102 13 95 4 10 -35 39 -43 -112 -5 14 -46 19 61 -44 -116 137 -116 -80 -39 92 -75 29 -65 -15 5 -108 -114 -129 -5 52 -21 118 -41 35 -62 -125 130 -95 -11 -75 19 108 108 127 141 2 -130 54 96 -81 -102 140 -58 -102 132 50 -126 82 6 45 -114 -42",
"output": "5"
},
{
"input": "7 12\n2 5 -1 -4 -7 4 3",
"output": "1"
},
{
"input": "57 53\n-49 7 -41 7 38 -51 -23 8 45 1 -24 26 37 28 -31 -40 38 25 -32 -47 -3 20 -40 -32 -44 -36 5 33 -16 -5 28 10 -22 3 -10 -51 -32 -51 27 -50 -22 -12 41 3 15 24 30 -12 -34 -15 -29 38 -10 -35 -9 6 -51",
"output": "8"
},
{
"input": "93 273\n-268 -170 -163 19 -69 18 -244 35 -34 125 -224 -48 179 -247 127 -150 271 -49 -102 201 84 -151 -70 -46 -16 216 240 127 3 218 -209 223 -227 -201 228 -8 203 46 -100 -207 126 255 40 -58 -217 93 172 -97 23 183 102 -92 -157 -117 173 47 144 -235 -227 -62 -128 13 -151 158 110 -116 68 -2 -148 -206 -52 79 -152 -223 74 -149 -69 232 38 -70 -256 -213 -236 132 -189 -200 199 -57 -108 -53 269 -101 -134",
"output": "8"
},
{
"input": "1 1000\n997",
"output": "1"
},
{
"input": "4 3\n2 -1 -2 -1",
"output": "1"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 2\n1 -1",
"output": "0"
},
{
"input": "2 2\n-1 1",
"output": "0"
},
{
"input": "2 3\n-1 1",
"output": "0"
},
{
"input": "2 2\n-2 2",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "2"
},
{
"input": "4 2\n-1 -1 -1 -1",
"output": "2"
},
{
"input": "4 1\n-1 -1 -1 1",
"output": "2"
},
{
"input": "3 2\n2 2 2",
"output": "3"
},
{
"input": "10 300\n300 300 300 300 300 300 300 300 300 300",
"output": "10"
}
] | 1,621,851,844 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,x = map(int,input().split())
l = list(map(int,input().split()))
s = sum(l)
if(s in range(-x,x+1)):
print(1)
else:
count = 0
while(s<0):
s+=x
count+=1
while(s>0 and s>x):
s-=x
count+=1
print(count) | Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*.
Input Specification:
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['3 2\n-1 1 2\n', '2 3\n-2 -2\n']
Demo Output:
['1\n', '2\n']
Note:
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | ```python
n,x = map(int,input().split())
l = list(map(int,input().split()))
s = sum(l)
if(s in range(-x,x+1)):
print(1)
else:
count = 0
while(s<0):
s+=x
count+=1
while(s>0 and s>x):
s-=x
count+=1
print(count)
``` | 0 |
|
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{
"input": "24 54 37\n60 63 6\n1 84 26",
"output": "110\n101\n011"
},
{
"input": "23 10 40\n15 6 40\n92 80 77",
"output": "101\n100\n000"
},
{
"input": "62 74 80\n95 74 93\n2 47 95",
"output": "010\n001\n110"
},
{
"input": "80 83 48\n26 0 66\n47 76 37",
"output": "000\n000\n010"
},
{
"input": "32 15 65\n7 54 36\n5 51 3",
"output": "111\n101\n001"
},
{
"input": "22 97 12\n71 8 24\n100 21 64",
"output": "100\n001\n100"
},
{
"input": "46 37 13\n87 0 50\n90 8 55",
"output": "111\n011\n000"
},
{
"input": "57 43 58\n20 82 83\n66 16 52",
"output": "111\n010\n110"
},
{
"input": "45 56 93\n47 51 59\n18 51 63",
"output": "101\n011\n100"
},
{
"input": "47 66 67\n14 1 37\n27 81 69",
"output": "001\n001\n110"
},
{
"input": "26 69 69\n85 18 23\n14 22 74",
"output": "110\n001\n010"
},
{
"input": "10 70 65\n94 27 25\n74 66 30",
"output": "111\n010\n100"
},
{
"input": "97 1 74\n15 99 1\n88 68 86",
"output": "001\n011\n000"
},
{
"input": "36 48 42\n45 41 66\n26 64 1",
"output": "001\n111\n010"
},
{
"input": "52 81 97\n29 77 71\n66 11 2",
"output": "100\n100\n111"
},
{
"input": "18 66 33\n19 49 49\n48 46 26",
"output": "011\n100\n000"
},
{
"input": "68 79 52\n51 39 100\n29 14 26",
"output": "110\n000\n111"
},
{
"input": "91 69 77\n91 26 64\n91 88 57",
"output": "001\n011\n110"
},
{
"input": "16 69 64\n48 21 80\n81 51 51",
"output": "010\n101\n111"
},
{
"input": "96 14 2\n100 18 12\n65 34 89",
"output": "111\n010\n010"
},
{
"input": "93 95 90\n8 59 42\n53 13 19",
"output": "100\n001\n111"
},
{
"input": "71 84 18\n100 19 67\n9 76 15",
"output": "010\n010\n001"
},
{
"input": "38 93 85\n21 88 64\n4 96 25",
"output": "111\n011\n000"
},
{
"input": "75 20 20\n60 5 78\n77 4 69",
"output": "011\n001\n000"
},
{
"input": "65 70 96\n19 6 83\n33 37 82",
"output": "100\n000\n011"
},
{
"input": "11 13 60\n17 13 46\n42 21 39",
"output": "000\n011\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 0",
"output": "111\n111\n111"
},
{
"input": "0 0 0\n0 1 0\n0 0 0",
"output": "101\n000\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 1",
"output": "111\n110\n100"
}
] | 1,661,157,611 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 77 | 0 | a=input()
a=a.split()
a=list(map(int,a))
b=input()
b=b.split()
b=list(map(int,b))
c=input()
c=c.split()
c=list(map(int,c))
aa=''
bb=''
cc=''
if (a[0]+b[0]+a[1])%2==0:
aa+='1'
else:
aa+='0'
if (a[0]+b[1]+a[1]+a[2])%2==0:
aa+='1'
else:
aa+='0'
if (a[2]+b[2]+a[1])%2==0:
aa+='1'
else:
aa+='0'
if (a[0]+b[0]+c[0]+b[1])%2==0:
bb+='1'
else:
bb+='0'
if (a[1]+b[0]+c[1]+b[1]+b[2])%2==0:
bb+='1'
else:
bb+='0'
if (a[2]+b[2]+c[2]+b[1])%2==0:
bb+='1'
else:
bb+='0'
if (c[0]+b[0]+c[1])%2==0:
cc+='1'
else:
cc+='0'
if (c[0]+b[1]+c[1]+c[2])%2==0:
cc+='1'
else:
cc+='0'
if (c[2]+b[2]+c[1])%2==0:
cc+='1'
else:
cc+='0'
print(aa)
print(bb)
print(cc) | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
Input Specification:
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Output Specification:
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
Demo Input:
['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n']
Demo Output:
['001\n010\n100\n', '010\n011\n100\n']
Note:
none | ```python
a=input()
a=a.split()
a=list(map(int,a))
b=input()
b=b.split()
b=list(map(int,b))
c=input()
c=c.split()
c=list(map(int,c))
aa=''
bb=''
cc=''
if (a[0]+b[0]+a[1])%2==0:
aa+='1'
else:
aa+='0'
if (a[0]+b[1]+a[1]+a[2])%2==0:
aa+='1'
else:
aa+='0'
if (a[2]+b[2]+a[1])%2==0:
aa+='1'
else:
aa+='0'
if (a[0]+b[0]+c[0]+b[1])%2==0:
bb+='1'
else:
bb+='0'
if (a[1]+b[0]+c[1]+b[1]+b[2])%2==0:
bb+='1'
else:
bb+='0'
if (a[2]+b[2]+c[2]+b[1])%2==0:
bb+='1'
else:
bb+='0'
if (c[0]+b[0]+c[1])%2==0:
cc+='1'
else:
cc+='0'
if (c[0]+b[1]+c[1]+c[2])%2==0:
cc+='1'
else:
cc+='0'
if (c[2]+b[2]+c[1])%2==0:
cc+='1'
else:
cc+='0'
print(aa)
print(bb)
print(cc)
``` | 3 |
|
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24",
"output": "644 500"
},
{
"input": "1\n3",
"output": "3 0"
},
{
"input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646",
"output": "6848 6568"
},
{
"input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727",
"output": "9562 9561"
},
{
"input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12",
"output": "315 315"
},
{
"input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304",
"output": "3238 2222"
},
{
"input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325",
"output": "5246 4864"
},
{
"input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71",
"output": "8147 7807"
},
{
"input": "1\n1",
"output": "1 0"
}
] | 1,689,054,805 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 307,200 | from collections import deque
n = int(input())
a = deque([int(i) for i in input().split()])
sereza = 0
dima = 0
turns = 1
while len(a) > 0:
if turns % 2 == 1:
if a[0] > a[-1]:
sereza += a[0]
a.popleft()
else:
sereza += a[-1]
a.pop()
else:
if a[0] > a[-1]:
dima += a[0]
a.popleft()
else:
dima += a[-1]
a.pop()
turns += 1
print(sereza, dima) | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output Specification:
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Demo Input:
['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n']
Demo Output:
['12 5\n', '16 12\n']
Note:
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | ```python
from collections import deque
n = int(input())
a = deque([int(i) for i in input().split()])
sereza = 0
dima = 0
turns = 1
while len(a) > 0:
if turns % 2 == 1:
if a[0] > a[-1]:
sereza += a[0]
a.popleft()
else:
sereza += a[-1]
a.pop()
else:
if a[0] > a[-1]:
dima += a[0]
a.popleft()
else:
dima += a[-1]
a.pop()
turns += 1
print(sereza, dima)
``` | 3 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,647,238,852 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
k = int(first_multiple_input[1])
print(n*k//2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
k = int(first_multiple_input[1])
print(n*k//2)
``` | 3.977 |
999 | A | Mishka and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.
Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve? | The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list. | Print one integer — the maximum number of problems Mishka can solve. | [
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] | [
"5\n",
"0\n",
"5\n"
] | In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems. | 0 | [
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 18 54 19 71 2 25 33 65 49 53 5 95 90 100 68 25 5 87 48 45 72 34 14 100 44 94 75 80 26 25 7 57 82 49 73 55 43 42 60 34 8 51 11 71 41 81 23 20 89 12 72 68 26 96 92 32 63 13 47 19 9 35 56 79 62",
"output": "100"
},
{
"input": "100 99\n84 82 43 4 71 3 30 92 15 47 76 43 2 17 76 4 1 33 24 96 44 98 75 99 59 11 73 27 67 17 8 88 69 41 44 22 91 48 4 46 42 21 21 67 85 51 57 84 11 100 100 59 39 72 89 82 74 19 98 14 37 97 20 78 38 52 44 83 19 83 69 32 56 6 93 13 98 80 80 2 33 71 11 15 55 51 98 58 16 91 39 32 83 58 77 79 88 81 17 98",
"output": "98"
},
{
"input": "100 69\n80 31 12 89 16 35 8 28 39 12 32 51 42 67 64 53 17 88 63 97 29 41 57 28 51 33 82 75 93 79 57 86 32 100 83 82 99 33 1 27 86 22 65 15 60 100 42 37 38 85 26 43 90 62 91 13 1 92 16 20 100 19 28 30 23 6 5 69 24 22 9 1 10 14 28 14 25 9 32 8 67 4 39 7 10 57 15 7 8 35 62 6 53 59 62 13 24 7 53 2",
"output": "39"
},
{
"input": "100 2\n2 2 2 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 16",
"output": "99"
},
{
"input": "100 3\n86 53 82 40 2 20 59 2 46 63 75 49 24 81 70 22 9 9 93 72 47 23 29 77 78 51 17 59 19 71 35 3 20 60 70 9 11 96 71 94 91 19 88 93 50 49 72 19 53 30 38 67 62 71 81 86 5 26 5 32 63 98 1 97 22 32 87 65 96 55 43 85 56 37 56 67 12 100 98 58 77 54 18 20 33 53 21 66 24 64 42 71 59 32 51 69 49 79 10 1",
"output": "1"
},
{
"input": "13 7\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "3 2\n1 4 1",
"output": "2"
},
{
"input": "1 2\n100",
"output": "0"
},
{
"input": "7 4\n4 2 3 4 4 2 3",
"output": "7"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "1 2\n15",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "5 3\n3 4 3 2 1",
"output": "4"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "1 5\n1",
"output": "1"
},
{
"input": "6 6\n7 1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n6 5 5 5 5",
"output": "4"
},
{
"input": "1 4\n2",
"output": "1"
},
{
"input": "9 4\n1 2 1 2 4 2 1 2 1",
"output": "9"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n5",
"output": "1"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "100 10\n2 5 1 10 10 2 7 7 9 4 1 8 1 1 8 4 7 9 10 5 7 9 5 6 7 2 7 5 3 2 1 82 4 80 9 8 6 1 10 7 5 7 1 5 6 7 19 4 2 4 6 2 1 8 31 6 2 2 57 42 3 2 7 1 9 5 10 8 5 4 10 8 3 5 8 7 2 7 6 5 3 3 4 10 6 7 10 8 7 10 7 2 4 6 8 10 10 2 6 4",
"output": "71"
},
{
"input": "100 90\n17 16 5 51 17 62 24 45 49 41 90 30 19 78 67 66 59 34 28 47 42 8 33 77 90 41 61 16 86 33 43 71 90 95 23 9 56 41 24 90 31 12 77 36 90 67 47 15 92 50 79 88 42 19 21 79 86 60 41 26 47 4 70 62 44 90 82 89 84 91 54 16 90 53 29 69 21 44 18 28 88 74 56 43 12 76 10 22 34 24 27 52 28 76 90 75 5 29 50 90",
"output": "63"
},
{
"input": "100 10\n6 4 8 4 1 9 4 8 5 2 2 5 2 6 10 2 2 5 3 5 2 3 10 5 2 9 1 1 6 1 5 9 16 42 33 49 26 31 81 27 53 63 81 90 55 97 70 51 87 21 79 62 60 91 54 95 26 26 30 61 87 79 47 11 59 34 40 82 37 40 81 2 7 1 8 4 10 7 1 10 8 7 3 5 2 8 3 3 9 2 1 1 5 7 8 7 1 10 9 8",
"output": "61"
},
{
"input": "100 90\n45 57 52 69 17 81 85 60 59 39 55 14 87 90 90 31 41 57 35 89 74 20 53 4 33 49 71 11 46 90 71 41 71 90 63 74 51 13 99 92 99 91 100 97 93 40 93 96 100 99 100 92 98 96 78 91 91 91 91 100 94 97 95 97 96 95 17 13 45 35 54 26 2 74 6 51 20 3 73 90 90 42 66 43 86 28 84 70 37 27 90 30 55 80 6 58 57 51 10 22",
"output": "72"
},
{
"input": "100 10\n10 2 10 10 10 10 10 10 10 7 10 10 10 10 10 10 9 10 10 10 10 10 10 10 10 7 9 10 10 10 37 10 4 10 10 10 59 5 95 10 10 10 10 39 10 10 10 10 10 10 10 5 10 10 10 10 10 10 10 10 10 10 10 10 66 10 10 10 10 10 5 10 10 10 10 10 10 44 10 10 10 10 10 10 10 10 10 10 10 7 10 10 10 10 10 10 10 10 10 2",
"output": "52"
},
{
"input": "100 90\n57 90 90 90 90 90 90 90 81 90 3 90 39 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 92 90 90 90 90 90 90 90 90 98 90 90 90 90 90 90 90 90 90 90 90 90 90 54 90 90 90 90 90 62 90 90 91 90 90 90 90 90 90 91 90 90 90 90 90 90 90 3 90 90 90 90 90 90 90 2 90 90 90 90 90 90 90 90 90 2 90 90 90 90 90",
"output": "60"
},
{
"input": "100 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 78 90 61 40 87 39 91 50 64 30 10 24 10 55 28 11 28 35 26 26 10 57 45 67 14 99 96 51 67 79 59 11 21 55 70 33 10 16 92 70 38 50 66 52 5 10 10 10 2 4 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 10 10 10 10 8 10 10 10 10 10",
"output": "56"
},
{
"input": "100 90\n90 90 90 90 90 90 55 21 90 90 90 90 90 90 90 90 90 90 69 83 90 90 90 90 90 90 90 90 93 95 92 98 92 97 91 92 92 91 91 95 94 95 100 100 96 97 94 93 90 90 95 95 97 99 90 95 98 91 94 96 99 99 94 95 95 97 99 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 12 90 3 90 90 90 90 90 90 90",
"output": "61"
},
{
"input": "100 49\n71 25 14 36 36 48 36 49 28 40 49 49 49 38 40 49 33 22 49 49 14 46 8 44 49 11 37 49 40 49 2 49 3 49 37 49 49 11 25 49 49 32 49 11 49 30 16 21 49 49 23 24 30 49 49 49 49 49 49 27 49 42 49 49 20 32 30 29 35 49 30 49 9 49 27 25 5 49 49 42 49 20 49 35 49 22 15 49 49 49 19 49 29 28 13 49 22 7 6 24",
"output": "99"
},
{
"input": "100 50\n38 68 9 6 50 18 19 50 50 20 33 34 43 50 24 50 50 2 50 50 50 50 50 21 30 50 41 40 50 50 50 50 50 7 50 21 19 23 1 50 24 50 50 50 25 50 50 50 50 50 50 50 7 24 28 18 50 5 43 50 20 50 13 50 50 16 50 3 2 24 50 50 18 5 50 4 50 50 38 50 33 49 12 33 11 14 50 50 50 33 50 50 50 50 50 50 7 4 50 50",
"output": "99"
},
{
"input": "100 48\n8 6 23 47 29 48 48 48 48 48 48 26 24 48 48 48 3 48 27 28 41 45 9 29 48 48 48 48 48 48 48 48 48 48 47 23 48 48 48 5 48 22 40 48 48 48 20 48 48 57 48 32 19 48 33 2 4 19 48 48 39 48 16 48 48 44 48 48 48 48 29 14 25 43 46 7 48 19 30 48 18 8 39 48 30 47 35 18 48 45 48 48 30 13 48 48 48 17 9 48",
"output": "99"
},
{
"input": "100 57\n57 9 57 4 43 57 57 57 57 26 57 18 57 57 57 57 57 57 57 47 33 57 57 43 57 57 55 57 14 57 57 4 1 57 57 57 57 57 46 26 57 57 57 57 57 57 57 39 57 57 57 5 57 12 11 57 57 57 25 37 34 57 54 18 29 57 39 57 5 57 56 34 57 24 7 57 57 57 2 57 57 57 57 1 55 39 19 57 57 57 57 21 3 40 13 3 57 57 62 57",
"output": "99"
},
{
"input": "100 51\n51 51 38 51 51 45 51 51 51 18 51 36 51 19 51 26 37 51 11 51 45 34 51 21 51 51 33 51 6 51 51 51 21 47 51 13 51 51 30 29 50 51 51 51 51 51 51 45 14 51 2 51 51 23 9 51 50 23 51 29 34 51 40 32 1 36 31 51 11 51 51 47 51 51 51 51 51 51 51 50 39 51 14 4 4 12 3 11 51 51 51 51 41 51 51 51 49 37 5 93",
"output": "99"
},
{
"input": "100 50\n87 91 95 73 50 50 16 97 39 24 58 50 33 89 42 37 50 50 12 71 3 55 50 50 80 10 76 50 52 36 88 44 66 69 86 71 77 50 72 50 21 55 50 50 78 61 75 89 65 2 50 69 62 47 11 92 97 77 41 31 55 29 35 51 36 48 50 91 92 86 50 36 50 94 51 74 4 27 55 63 50 36 87 50 67 7 65 75 20 96 88 50 41 73 35 51 66 21 29 33",
"output": "3"
},
{
"input": "100 50\n50 37 28 92 7 76 50 50 50 76 100 57 50 50 50 32 76 50 8 72 14 8 50 91 67 50 55 82 50 50 24 97 88 50 59 61 68 86 44 15 61 67 88 50 40 50 36 99 1 23 63 50 88 59 76 82 99 76 68 50 50 30 31 68 57 98 71 12 15 60 35 79 90 6 67 50 50 50 50 68 13 6 50 50 16 87 84 50 67 67 50 64 50 58 50 50 77 51 50 51",
"output": "3"
},
{
"input": "100 50\n43 50 50 91 97 67 6 50 86 50 76 60 50 59 4 56 11 38 49 50 37 50 50 20 60 47 33 54 95 58 22 50 77 77 72 9 57 40 81 57 95 50 81 63 62 76 13 87 50 39 74 69 50 99 63 1 11 62 84 31 97 99 56 73 70 36 45 100 28 91 93 9 19 52 73 50 83 58 84 52 86 12 50 44 64 52 97 50 12 71 97 52 87 66 83 66 86 50 9 49",
"output": "6"
},
{
"input": "88 10\n10 8 1 10 10 1 3 7 10 5 8 8 10 2 7 10 10 10 10 10 1 10 10 10 10 1 2 9 10 9 10 10 10 64 100 25 10 12 9 52 13 8 10 56 10 4 10 7 10 3 10 79 74 8 73 10 10 10 9 10 3 5 10 10 10 5 1 10 10 4 3 10 10 10 4 10 6 4 10 10 10 10 3 3 8 5 6 8",
"output": "66"
},
{
"input": "100 50\n80 39 33 69 75 50 23 88 50 50 67 90 87 50 29 15 55 32 60 50 50 50 38 95 62 50 50 88 8 97 45 50 42 12 22 93 49 50 24 50 50 71 60 4 50 72 57 57 50 50 50 83 69 17 1 31 72 55 50 11 50 80 93 41 91 94 20 60 50 50 51 48 53 56 76 73 50 72 19 98 50 50 50 50 50 28 48 45 62 11 16 67 93 88 63 50 50 66 48 95",
"output": "0"
},
{
"input": "100 50\n70 50 38 50 38 50 32 30 50 31 26 42 50 33 34 50 50 50 28 21 50 44 50 47 50 50 9 40 50 50 50 50 50 42 50 50 16 50 50 3 24 50 50 50 4 26 50 2 50 50 33 1 27 50 50 50 8 29 50 23 33 50 6 29 50 50 15 50 50 50 32 50 43 50 50 50 31 50 4 50 50 31 50 50 31 16 50 17 50 17 31 13 25 16 50 10 50 47 50 66",
"output": "0"
},
{
"input": "2 8\n8 8",
"output": "2"
},
{
"input": "1 6\n3",
"output": "1"
},
{
"input": "1 5\n5",
"output": "1"
}
] | 1,608,764,202 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 307,200 | n,k=input().split(" ")
n=int(n)
k=int(k)
#recieve list of elements which they length is n
# if number of element bigger than n ignore the additional value
c=input (). split(" ",n)
c=list(map(int,c))
#Now we will divide alist into to lists
m = int (n/2)
#we will but the last elements from the median to end and we will reverse ther
s=c[m:n]
s.reverse()
#llooping over two lists and increase h by one if k>=element in list
#it will fo out from the loop if he met element >k
h=0
for i in c[0:m]:
if (k>i or k==i ):h+=1;
else :break;
for i in s:
if (k>i or k==i ):h+=1;
else :break;
#printing output
print(h)
| Title: Mishka and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.
Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve?
Input Specification:
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Output Specification:
Print one integer — the maximum number of problems Mishka can solve.
Demo Input:
['8 4\n4 2 3 1 5 1 6 4\n', '5 2\n3 1 2 1 3\n', '5 100\n12 34 55 43 21\n']
Demo Output:
['5\n', '0\n', '5\n']
Note:
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems. | ```python
n,k=input().split(" ")
n=int(n)
k=int(k)
#recieve list of elements which they length is n
# if number of element bigger than n ignore the additional value
c=input (). split(" ",n)
c=list(map(int,c))
#Now we will divide alist into to lists
m = int (n/2)
#we will but the last elements from the median to end and we will reverse ther
s=c[m:n]
s.reverse()
#llooping over two lists and increase h by one if k>=element in list
#it will fo out from the loop if he met element >k
h=0
for i in c[0:m]:
if (k>i or k==i ):h+=1;
else :break;
for i in s:
if (k>i or k==i ):h+=1;
else :break;
#printing output
print(h)
``` | 0 |
|
102 | A | Clothes | PROGRAMMING | 1,200 | [
"brute force"
] | A. Clothes | 2 | 256 | A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.
Overall the shop sells *n* clothing items, and exactly *m* pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. | The first input file line contains integers *n* and *m* — the total number of clothing items in the shop and the total number of matching pairs of clothing items ().
Next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the prices of the clothing items in rubles.
Next *m* lines each contain a pair of space-separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*). Each such pair of numbers means that the *u**i*-th and the *v**i*-th clothing items match each other. It is guaranteed that in each pair *u**i* and *v**i* are distinct and all the unordered pairs (*u**i*,<=*v**i*) are different. | Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). | [
"3 3\n1 2 3\n1 2\n2 3\n3 1\n",
"3 2\n2 3 4\n2 3\n2 1\n",
"4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1\n"
] | [
"6\n",
"-1\n",
"-1\n"
] | In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.
The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.
In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. | 500 | [
{
"input": "3 3\n1 2 3\n1 2\n2 3\n3 1",
"output": "6"
},
{
"input": "3 2\n2 3 4\n2 3\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1",
"output": "-1"
},
{
"input": "4 3\n10 10 5 1\n2 1\n3 1\n3 4",
"output": "-1"
},
{
"input": "4 0\n9 8 2 10",
"output": "-1"
},
{
"input": "4 3\n5 5 9 6\n3 2\n1 4\n3 4",
"output": "-1"
},
{
"input": "4 3\n5 1 10 1\n2 1\n3 2\n1 4",
"output": "-1"
},
{
"input": "4 3\n1 2 8 6\n1 3\n1 4\n3 4",
"output": "15"
},
{
"input": "4 4\n9 3 3 1\n1 2\n3 1\n3 2\n4 3",
"output": "15"
},
{
"input": "4 3\n6 8 10 1\n2 3\n1 4\n3 4",
"output": "-1"
},
{
"input": "4 5\n4 10 3 9\n1 2\n3 1\n3 2\n2 4\n4 3",
"output": "17"
},
{
"input": "4 2\n2 9 8 4\n1 3\n4 2",
"output": "-1"
},
{
"input": "4 3\n5 3 4 4\n2 1\n4 1\n3 4",
"output": "-1"
},
{
"input": "6 6\n39 15 73 82 37 40\n2 1\n5 1\n1 6\n2 6\n6 3\n4 6",
"output": "94"
},
{
"input": "6 7\n85 2 34 6 83 61\n1 2\n2 3\n4 2\n4 3\n1 5\n4 5\n6 3",
"output": "42"
},
{
"input": "6 8\n64 44 5 31 14 16\n1 2\n1 3\n1 4\n2 5\n3 5\n6 1\n6 3\n6 4",
"output": "85"
},
{
"input": "6 8\n36 19 99 8 52 77\n2 1\n3 1\n4 2\n4 3\n1 5\n5 4\n1 6\n6 2",
"output": "132"
},
{
"input": "6 5\n59 69 52 38 93 53\n4 2\n1 5\n6 1\n4 6\n5 6",
"output": "205"
},
{
"input": "6 11\n95 81 74 94 60 69\n3 2\n1 4\n4 2\n3 4\n1 5\n5 2\n5 3\n1 6\n2 6\n3 6\n4 6",
"output": "215"
},
{
"input": "6 8\n69 36 41 23 91 35\n1 2\n3 1\n3 2\n1 4\n3 4\n3 5\n5 4\n4 6",
"output": "133"
},
{
"input": "6 6\n33 76 98 59 4 69\n1 2\n3 2\n5 1\n2 5\n4 5\n6 5",
"output": "113"
},
{
"input": "6 6\n92 56 15 83 30 28\n3 1\n4 1\n2 5\n5 4\n2 6\n6 3",
"output": "-1"
},
{
"input": "6 10\n17 5 55 24 55 74\n1 3\n2 3\n3 4\n5 1\n5 2\n5 3\n4 5\n6 2\n6 3\n6 5",
"output": "115"
},
{
"input": "3 3\n1000000 1000000 1000000\n2 1\n1 3\n3 2",
"output": "3000000"
},
{
"input": "3 0\n1 1 1",
"output": "-1"
},
{
"input": "3 3\n100000 100000 100001\n1 2\n2 3\n3 1",
"output": "300001"
},
{
"input": "3 3\n1 1 999999\n1 2\n2 3\n3 1",
"output": "1000001"
},
{
"input": "3 3\n999999 1 1\n1 2\n2 3\n3 1",
"output": "1000001"
},
{
"input": "3 3\n1000000 1000000 1000000\n1 2\n2 3\n1 3",
"output": "3000000"
}
] | 1,665,087,800 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | import math
def gcd(a,b):
while a%b !=0:
aux = b
b = a%b
a = aux
return b
def lcm(a,b):
return (a/gcd(a,b))*b
def solve(a):
return ((a-3)//3)-1
for _ in range(int(input())):
a = int(input())
print(solve(a))
| Title: Clothes
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.
Overall the shop sells *n* clothing items, and exactly *m* pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.
Input Specification:
The first input file line contains integers *n* and *m* — the total number of clothing items in the shop and the total number of matching pairs of clothing items ().
Next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the prices of the clothing items in rubles.
Next *m* lines each contain a pair of space-separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*). Each such pair of numbers means that the *u**i*-th and the *v**i*-th clothing items match each other. It is guaranteed that in each pair *u**i* and *v**i* are distinct and all the unordered pairs (*u**i*,<=*v**i*) are different.
Output Specification:
Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).
Demo Input:
['3 3\n1 2 3\n1 2\n2 3\n3 1\n', '3 2\n2 3 4\n2 3\n2 1\n', '4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1\n']
Demo Output:
['6\n', '-1\n', '-1\n']
Note:
In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.
The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.
In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1. | ```python
import math
def gcd(a,b):
while a%b !=0:
aux = b
b = a%b
a = aux
return b
def lcm(a,b):
return (a/gcd(a,b))*b
def solve(a):
return ((a-3)//3)-1
for _ in range(int(input())):
a = int(input())
print(solve(a))
``` | -1 |
479 | C | Exams | PROGRAMMING | 1,400 | [
"greedy",
"sortings"
] | null | null | Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.
According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=<<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*.
Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take.
Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=<<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | [
"3\n5 2\n3 1\n4 2\n",
"3\n6 1\n5 2\n4 3\n"
] | [
"2\n",
"6\n"
] | In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.
In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | 1,500 | [
{
"input": "3\n5 2\n3 1\n4 2",
"output": "2"
},
{
"input": "3\n6 1\n5 2\n4 3",
"output": "6"
},
{
"input": "1\n1000000000 999999999",
"output": "999999999"
},
{
"input": "1\n2 1",
"output": "1"
},
{
"input": "2\n3 2\n3 2",
"output": "2"
},
{
"input": "5\n4 3\n4 2\n4 1\n4 1\n4 1",
"output": "3"
},
{
"input": "6\n12 11\n10 9\n8 7\n6 5\n4 3\n2 1",
"output": "11"
},
{
"input": "2\n3 1\n3 2",
"output": "2"
},
{
"input": "2\n4 2\n4 1",
"output": "2"
},
{
"input": "2\n5 2\n5 1",
"output": "2"
},
{
"input": "6\n3 1\n3 2\n4 1\n4 2\n5 4\n5 4",
"output": "4"
},
{
"input": "3\n3 2\n4 1\n100 10",
"output": "10"
},
{
"input": "3\n4 3\n5 2\n10 8",
"output": "8"
},
{
"input": "5\n6 5\n6 4\n6 3\n6 2\n6 1",
"output": "5"
},
{
"input": "3\n5 4\n6 3\n8 7",
"output": "7"
},
{
"input": "4\n7 1\n7 3\n8 2\n9 8",
"output": "8"
},
{
"input": "3\n3 2\n4 1\n10 5",
"output": "5"
},
{
"input": "3\n5 4\n6 3\n11 10",
"output": "10"
},
{
"input": "4\n2 1\n3 2\n4 1\n6 5",
"output": "5"
}
] | 1,686,447,247 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 33 | 155 | 6,144,000 | a = [list(map(int,input().split())) for i in range(int(input()))]
b = sorted(a)
c = [i[1] for i in b]
if c == sorted(c):
print(c[-1])
else:
d = dict()
for i,j in b:
try:
d[j] = min(i,d[j])
except KeyError:
d[j] = i
print(max(d.values())) | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.
According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=<<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*.
Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.
Input Specification:
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take.
Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=<<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly.
Output Specification:
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
Demo Input:
['3\n5 2\n3 1\n4 2\n', '3\n6 1\n5 2\n4 3\n']
Demo Output:
['2\n', '6\n']
Note:
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.
In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | ```python
a = [list(map(int,input().split())) for i in range(int(input()))]
b = sorted(a)
c = [i[1] for i in b]
if c == sorted(c):
print(c[-1])
else:
d = dict()
for i,j in b:
try:
d[j] = min(i,d[j])
except KeyError:
d[j] = i
print(max(d.values()))
``` | 0 |
|
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:
The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.
If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).
For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain\nB man\nD woman\nC child\nE rat",
"output": "E\nD\nC\nB\nA"
},
{
"input": "10\nCap captain\nD child\nC woman\nA woman\nE child\nMan man\nB child\nF woman\nRat rat\nRatt rat",
"output": "Rat\nRatt\nD\nC\nA\nE\nB\nF\nMan\nCap"
},
{
"input": "5\nJoyxnkypf captain\nDxssgr woman\nKeojmnpd rat\nGdv man\nHnw man",
"output": "Keojmnpd\nDxssgr\nGdv\nHnw\nJoyxnkypf"
},
{
"input": "11\nJue rat\nWyglbyphk rat\nGjlgu child\nGi man\nAttx rat\nTheorpkgx man\nYm rat\nX child\nB captain\nEnualf rat\nKktsgyuyv woman",
"output": "Jue\nWyglbyphk\nAttx\nYm\nEnualf\nGjlgu\nX\nKktsgyuyv\nGi\nTheorpkgx\nB"
},
{
"input": "22\nWswwcvvm woman\nBtmfats rat\nI rat\nOcmtsnwx man\nUrcqv rat\nYghnogt woman\nWtyfc man\nWqle child\nUjfrelpu rat\nDstixj man\nAhksnio woman\nKhkvaap woman\nSjppvwm rat\nEgdmsv rat\nDank rat\nNquicjnw rat\nLh captain\nTdyaqaqln rat\nQtj rat\nTfgwijvq rat\nNbiso child\nNqthvbf woman",
"output": "Btmfats\nI\nUrcqv\nUjfrelpu\nSjppvwm\nEgdmsv\nDank\nNquicjnw\nTdyaqaqln\nQtj\nTfgwijvq\nWswwcvvm\nYghnogt\nWqle\nAhksnio\nKhkvaap\nNbiso\nNqthvbf\nOcmtsnwx\nWtyfc\nDstixj\nLh"
},
{
"input": "36\nKqxmtwmsf child\nIze woman\nDlpr child\nK woman\nF captain\nRjwfeuhba rat\nBbv rat\nS rat\nMnmg woman\nSmzyx woman\nSr man\nQmhroracn rat\nSoqpuqock rat\nPibdq man\nIlrkrptx rat\nZaecfyqka man\nMmersfs child\nVvvocqi man\nHjeqxvq rat\nMpmb woman\nWmgu woman\nCerelmhoxi child\nA man\nDylv man\nXrdgmmtcpq woman\nXj woman\nCeh child\nOfccguo man\nNevr man\nAknkwdkq child\nBmo man\nLqo woman\nVej child\nT child\nRlijc man\nNsdtpdg woman",
"output": "Rjwfeuhba\nBbv\nS\nQmhroracn\nSoqpuqock\nIlrkrptx\nHjeqxvq\nKqxmtwmsf\nIze\nDlpr\nK\nMnmg\nSmzyx\nMmersfs\nMpmb\nWmgu\nCerelmhoxi\nXrdgmmtcpq\nXj\nCeh\nAknkwdkq\nLqo\nVej\nT\nNsdtpdg\nSr\nPibdq\nZaecfyqka\nVvvocqi\nA\nDylv\nOfccguo\nNevr\nBmo\nRlijc\nF"
},
{
"input": "2\nA captain\nB man",
"output": "B\nA"
},
{
"input": "2\nB woman\nA captain",
"output": "B\nA"
},
{
"input": "2\nX child\nY captain",
"output": "X\nY"
},
{
"input": "2\nX captain\nY rat",
"output": "Y\nX"
},
{
"input": "6\nAbdelrhman captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nAbdelrhman"
},
{
"input": "4\nAratos captain\nMind child\nAman woman\nCarrot man",
"output": "Mind\nAman\nCarrot\nAratos"
}
] | 1,699,681,780 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 216 | 1,843,200 | from functools import cmp_to_key
class Info:
def __init__(self, _id: int, _name: str, _status: str):
self.id = _id
self.name = _name
self.status = _status
def __str__(self):
return f'id: {self.id}, name: {self.name}, status: {self.status}'
def customCompare(obj1:Info, obj2:Info) -> int:
if obj1.status != "rat" and obj2.status == "rat":
return 1
if obj1.status == "rat" and obj2.status != "rat":
return -1
if (obj1.status != "woman" and obj1.status != "child") and (obj2.status == "woman" or obj2.status == "child"):
return 1
if (obj1.status == "woman" or obj1.status == "child") and (obj2.status != "woman" and obj2.status != "child"):
return -1
if obj1.status != "man" and obj2.status == "man":
return 1
if obj1.status == "man" and obj2.status != "man":
return -1
return obj1.id - obj2.id
def output(cont:list):
for obj in cont:
print(obj)
n = int(input())
cont = []
for i in range(n):
_name, _status = input().split()
obj = Info(i + 1, _name, _status)
cont.append(obj)
cont.sort(key=cmp_to_key(customCompare))
for obj in cont:
print(obj.name)
| Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:
The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.
If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).
For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.
Input Specification:
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.
Output Specification:
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
Demo Input:
['6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n']
Demo Output:
['Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n']
Note:
none | ```python
from functools import cmp_to_key
class Info:
def __init__(self, _id: int, _name: str, _status: str):
self.id = _id
self.name = _name
self.status = _status
def __str__(self):
return f'id: {self.id}, name: {self.name}, status: {self.status}'
def customCompare(obj1:Info, obj2:Info) -> int:
if obj1.status != "rat" and obj2.status == "rat":
return 1
if obj1.status == "rat" and obj2.status != "rat":
return -1
if (obj1.status != "woman" and obj1.status != "child") and (obj2.status == "woman" or obj2.status == "child"):
return 1
if (obj1.status == "woman" or obj1.status == "child") and (obj2.status != "woman" and obj2.status != "child"):
return -1
if obj1.status != "man" and obj2.status == "man":
return 1
if obj1.status == "man" and obj2.status != "man":
return -1
return obj1.id - obj2.id
def output(cont:list):
for obj in cont:
print(obj)
n = int(input())
cont = []
for i in range(n):
_name, _status = input().split()
obj = Info(i + 1, _name, _status)
cont.append(obj)
cont.sort(key=cmp_to_key(customCompare))
for obj in cont:
print(obj.name)
``` | 3.942567 |
638 | A | Home Numbers | PROGRAMMING | 1,100 | [
"*special",
"constructive algorithms",
"math"
] | null | null | The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to *n* in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house *n*, house 3 is opposite house *n*<=-<=2, house 5 is opposite house *n*<=-<=4 and so on.
Vasya needs to get to house number *a* as quickly as possible. He starts driving from the beginning of the street and drives his car to house *a*. To get from the beginning of the street to houses number 1 and *n*, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.
Your task is: find the minimum time Vasya needs to reach house *a*. | The first line of the input contains two integers, *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100<=000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number *n* is even. | Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house *a*. | [
"4 2\n",
"8 5\n"
] | [
"2\n",
"3\n"
] | In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.
The second sample corresponds to picture with *n* = 8. House 5 is the one before last at Vasya's left. | 500 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "8 5",
"output": "3"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "10 1",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "100000 100000",
"output": "1"
},
{
"input": "100000 2",
"output": "50000"
},
{
"input": "100000 3",
"output": "2"
},
{
"input": "100000 99999",
"output": "50000"
},
{
"input": "100 100",
"output": "1"
},
{
"input": "3000 34",
"output": "1484"
},
{
"input": "2000 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "24842 1038",
"output": "11903"
},
{
"input": "1628 274",
"output": "678"
},
{
"input": "16186 337",
"output": "169"
},
{
"input": "24562 2009",
"output": "1005"
},
{
"input": "9456 3443",
"output": "1722"
},
{
"input": "5610 332",
"output": "2640"
},
{
"input": "1764 1288",
"output": "239"
},
{
"input": "28588 13902",
"output": "7344"
},
{
"input": "92480 43074",
"output": "24704"
},
{
"input": "40022 26492",
"output": "6766"
},
{
"input": "85766 64050",
"output": "10859"
},
{
"input": "67808 61809",
"output": "30905"
},
{
"input": "80124 68695",
"output": "34348"
},
{
"input": "95522 91716",
"output": "1904"
},
{
"input": "7752 2915",
"output": "1458"
},
{
"input": "5094 5058",
"output": "19"
},
{
"input": "6144 4792",
"output": "677"
},
{
"input": "34334 20793",
"output": "10397"
},
{
"input": "23538 10243",
"output": "5122"
},
{
"input": "9328 7933",
"output": "3967"
},
{
"input": "11110 9885",
"output": "4943"
},
{
"input": "26096 2778",
"output": "11660"
},
{
"input": "75062 5323",
"output": "2662"
},
{
"input": "94790 7722",
"output": "43535"
},
{
"input": "90616 32240",
"output": "29189"
},
{
"input": "96998 8992",
"output": "44004"
},
{
"input": "95130 19219",
"output": "9610"
},
{
"input": "92586 8812",
"output": "41888"
},
{
"input": "3266 3044",
"output": "112"
},
{
"input": "5026 4697",
"output": "2349"
},
{
"input": "3044 2904",
"output": "71"
},
{
"input": "6022 5396",
"output": "314"
},
{
"input": "31270 25522",
"output": "2875"
},
{
"input": "82156 75519",
"output": "37760"
},
{
"input": "34614 27913",
"output": "13957"
},
{
"input": "88024 61143",
"output": "30572"
},
{
"input": "91870 55672",
"output": "18100"
},
{
"input": "95718 4868",
"output": "45426"
},
{
"input": "99564 358",
"output": "49604"
},
{
"input": "89266 13047",
"output": "6524"
},
{
"input": "90904 16455",
"output": "8228"
},
{
"input": "94750 13761",
"output": "6881"
},
{
"input": "100000 23458",
"output": "38272"
},
{
"input": "100000 23457",
"output": "11729"
},
{
"input": "59140 24272",
"output": "17435"
},
{
"input": "9860 8516",
"output": "673"
},
{
"input": "25988 2733",
"output": "1367"
},
{
"input": "9412 5309",
"output": "2655"
},
{
"input": "25540 23601",
"output": "11801"
},
{
"input": "76260 6050",
"output": "35106"
},
{
"input": "92388 39118",
"output": "26636"
},
{
"input": "8516 5495",
"output": "2748"
},
{
"input": "91940 37847",
"output": "18924"
},
{
"input": "30518 286",
"output": "15117"
},
{
"input": "46646 19345",
"output": "9673"
}
] | 1,458,487,878 | 12,678 | PyPy 3 | OK | TESTS | 69 | 109 | 23,244,800 | n, a = [int(x) for x in input().split()]
ans = 1
if a % 2 == 0:
while n != a:
n -= 2
ans += 1
else:
t = 1
while t != a:
t += 2
ans += 1
print(ans) | Title: Home Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to *n* in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house *n*, house 3 is opposite house *n*<=-<=2, house 5 is opposite house *n*<=-<=4 and so on.
Vasya needs to get to house number *a* as quickly as possible. He starts driving from the beginning of the street and drives his car to house *a*. To get from the beginning of the street to houses number 1 and *n*, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.
Your task is: find the minimum time Vasya needs to reach house *a*.
Input Specification:
The first line of the input contains two integers, *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100<=000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number *n* is even.
Output Specification:
Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house *a*.
Demo Input:
['4 2\n', '8 5\n']
Demo Output:
['2\n', '3\n']
Note:
In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.
The second sample corresponds to picture with *n* = 8. House 5 is the one before last at Vasya's left. | ```python
n, a = [int(x) for x in input().split()]
ans = 1
if a % 2 == 0:
while n != a:
n -= 2
ans += 1
else:
t = 1
while t != a:
t += 2
ans += 1
print(ans)
``` | 3 |
|
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
},
{
"input": "4\n5 4 5 4",
"output": "-1"
},
{
"input": "7\n3 4 5 5 5 1 2",
"output": "2"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "5\n5 4 1 2 3",
"output": "-1"
},
{
"input": "4\n6 1 2 7",
"output": "-1"
},
{
"input": "5\n4 5 6 2 3",
"output": "2"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "4\n1 2 2 1",
"output": "1"
},
{
"input": "9\n4 5 6 7 1 2 3 4 10",
"output": "-1"
},
{
"input": "7\n2 3 4 1 2 3 4",
"output": "-1"
},
{
"input": "6\n1 2 1 2 1 2",
"output": "-1"
},
{
"input": "3\n3 2 1",
"output": "-1"
},
{
"input": "4\n1 4 4 1",
"output": "1"
},
{
"input": "5\n1 2 1 1 1",
"output": "3"
},
{
"input": "5\n4 6 7 3 5",
"output": "-1"
},
{
"input": "4\n2 3 1 4",
"output": "-1"
},
{
"input": "5\n5 4 3 2 1",
"output": "-1"
},
{
"input": "4\n2 4 1 4",
"output": "-1"
},
{
"input": "6\n4 5 6 1 2 7",
"output": "-1"
},
{
"input": "6\n1 2 3 1 1 1",
"output": "3"
},
{
"input": "5\n1 3 3 3 1",
"output": "1"
},
{
"input": "6\n5 6 7 5 5 5",
"output": "3"
},
{
"input": "5\n3 4 2 1 2",
"output": "-1"
},
{
"input": "3\n3 4 2",
"output": "1"
},
{
"input": "6\n1 1 2 2 1 1",
"output": "2"
},
{
"input": "4\n2 3 4 2",
"output": "1"
},
{
"input": "5\n3 5 7 7 3",
"output": "1"
},
{
"input": "4\n1 1 4 1",
"output": "1"
},
{
"input": "7\n1 5 6 1 1 1 1",
"output": "4"
},
{
"input": "5\n7 8 6 7 8",
"output": "-1"
},
{
"input": "4\n2 4 1 3",
"output": "-1"
}
] | 1,608,389,276 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 7,065,600 | n=int(input())
l=list(map(int,input().split()))
x=True
for i in range(n-1):
if l[i]>l[i+1]:
a=l[0:i+1:1]
b=l[i+1::]
c=a[::]
d=b[::]
c.sort()
d.sort()
if a==c and b==d and c[0]>d[0]:
print(len(b))
x=False
else:
print(-1)
x=False
if x:
print(0)
| Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
Demo Input:
['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['1\n', '-1\n', '0\n']
Note:
none | ```python
n=int(input())
l=list(map(int,input().split()))
x=True
for i in range(n-1):
if l[i]>l[i+1]:
a=l[0:i+1:1]
b=l[i+1::]
c=a[::]
d=b[::]
c.sort()
d.sort()
if a==c and b==d and c[0]>d[0]:
print(len(b))
x=False
else:
print(-1)
x=False
if x:
print(0)
``` | 0 |
|
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*. | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"output": "50"
},
{
"input": "50 250",
"output": "0"
},
{
"input": "29 116",
"output": "0"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "46 127",
"output": "11"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "36 99",
"output": "9"
},
{
"input": "45 104",
"output": "31"
},
{
"input": "13 57",
"output": "0"
},
{
"input": "25 106",
"output": "0"
},
{
"input": "8 19",
"output": "5"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "13 32",
"output": "7"
},
{
"input": "47 128",
"output": "13"
},
{
"input": "17 73",
"output": "0"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "38 137",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "36 155",
"output": "0"
},
{
"input": "5 15",
"output": "0"
},
{
"input": "27 75",
"output": "6"
},
{
"input": "21 73",
"output": "0"
},
{
"input": "2 5",
"output": "1"
},
{
"input": "49 177",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "44 173",
"output": "0"
},
{
"input": "49 219",
"output": "0"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "10 28",
"output": "2"
}
] | 1,643,952,081 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 156 | 0 | n,k=map(int,input().split())
ans=0
if(k//n==2):
ans+=n
ans-=k%n
print(ans) | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*.
Input Specification:
The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*.
Output Specification:
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*.
Demo Input:
['4 8\n', '4 10\n', '1 3\n']
Demo Output:
['4\n', '2\n', '0\n']
Note:
In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | ```python
n,k=map(int,input().split())
ans=0
if(k//n==2):
ans+=n
ans-=k%n
print(ans)
``` | 0 |
|
36 | A | Extra-terrestrial Intelligence | PROGRAMMING | 1,300 | [
"implementation"
] | A. Extra-terrestrial Intelligence | 2 | 64 | Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | [
"8\n00111000\n",
"7\n1001011\n",
"7\n1010100\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "8\n00111000",
"output": "YES"
},
{
"input": "7\n1001011",
"output": "NO"
},
{
"input": "7\n1010100",
"output": "YES"
},
{
"input": "5\n10101",
"output": "YES"
},
{
"input": "3\n111",
"output": "YES"
},
{
"input": "10\n0011111011",
"output": "NO"
},
{
"input": "12\n001010101010",
"output": "YES"
},
{
"input": "25\n1000000010000000100000001",
"output": "YES"
},
{
"input": "30\n111110111101110111111111111111",
"output": "NO"
},
{
"input": "50\n00101010101010101010101010101010101010101010101010",
"output": "YES"
},
{
"input": "60\n000000000000000000100001000000001000000001000000001000000001",
"output": "NO"
},
{
"input": "66\n000000000000000000000010011110000010000010000010000000000000000000",
"output": "NO"
},
{
"input": "77\n10000100001010000000000001000000000000100000101000010010000000001100000000000",
"output": "NO"
},
{
"input": "99\n000000000000000000100000010000001000000100000010000001000000100000010000001000000100000010000001000",
"output": "YES"
},
{
"input": "100\n0000000000001000000000000000000000000000000000000010000000000000000000000000000000000000100000000000",
"output": "YES"
},
{
"input": "100\n0010000000000000000000000000000100000000000010000000000000001000000000000000000000000000010000000000",
"output": "NO"
},
{
"input": "5\n10111",
"output": "NO"
},
{
"input": "100\n0000100000000000000000000000000000000000010000000000000000000000000000000000001000000000000000000000",
"output": "YES"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111",
"output": "NO"
}
] | 1,574,636,727 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 434 | 2,150,400 | fin = open('input.txt')
fout = open('output.txt')
n = int(fin.readline())
s = str(fin.readline())
a = set()
p = 0
d = 0
first_met = False
for i in range(n):
if s[i] == '1':
if not first_met:
first_met = True
else:
a.add(i - d)
d = i
if len(a) == 1:
print("YES", file=fout)
else:
print("NO", file=fout)
fin.close()
fout.close()
| Title: Extra-terrestrial Intelligence
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s.
Output Specification:
If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO.
Demo Input:
['8\n00111000\n', '7\n1001011\n', '7\n1010100\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
fin = open('input.txt')
fout = open('output.txt')
n = int(fin.readline())
s = str(fin.readline())
a = set()
p = 0
d = 0
first_met = False
for i in range(n):
if s[i] == '1':
if not first_met:
first_met = True
else:
a.add(i - d)
d = i
if len(a) == 1:
print("YES", file=fout)
else:
print("NO", file=fout)
fin.close()
fout.close()
``` | -1 |
254 | A | Cards with Numbers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"sortings"
] | null | null | Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces. | If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them. | [
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] | [
"4 2\n1 5\n6 3\n",
"-1"
] | none | 500 | [
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"input": "5\n1 2 2 2 1 2 2 1 2 1",
"output": "3 2\n1 5\n6 4\n7 9\n10 8"
},
{
"input": "5\n3 3 1 1 1 3 2 3 1 2",
"output": "2 1\n3 4\n8 6\n5 9\n10 7"
},
{
"input": "5\n1 1 3 1 3 3 3 1 1 1",
"output": "2 1\n3 5\n7 6\n4 8\n10 9"
},
{
"input": "5\n3 1 1 1 2 3 3 3 2 1",
"output": "3 2\n1 6\n8 7\n5 9\n10 4"
},
{
"input": "5\n3 3 2 2 3 3 1 3 1 3",
"output": "2 1\n3 4\n6 5\n7 9\n10 8"
},
{
"input": "5\n4 1 3 1 4 1 2 2 3 1",
"output": "4 2\n1 5\n8 7\n3 9\n10 6"
},
{
"input": "100\n8 6 7 8 7 9 1 7 3 3 5 8 7 8 5 4 8 4 8 1 2 8 3 7 8 7 6 5 7 9 6 10 7 6 7 8 6 8 9 5 1 5 6 1 4 8 4 8 7 2 6 2 6 6 2 8 2 8 7 1 5 4 4 6 4 9 7 5 1 8 1 3 9 2 3 2 4 7 6 10 5 3 4 10 8 9 6 7 2 7 10 1 8 10 4 1 1 1 2 7 5 4 9 10 6 8 3 1 10 9 9 6 1 5 8 6 6 3 3 4 10 10 8 9 7 10 9 3 7 6 3 2 10 8 5 8 5 5 5 10 8 5 7 6 10 7 7 9 10 10 9 9 3 6 5 6 8 1 9 8 2 4 8 8 6 8 10 2 3 5 2 6 8 4 8 6 4 5 10 8 1 10 5 2 5 6 8 2 6 8 1 3 4 5 7 5 6 9 2 8",
"output": "4 1\n3 5\n10 9\n8 13\n14 12\n11 15\n18 16\n17 19\n20 7\n22 25\n26 24\n2 27\n30 6\n29 33\n34 31\n36 38\n40 28\n37 43\n44 41\n45 47\n48 46\n35 49\n50 21\n51 53\n55 52\n56 58\n61 42\n62 63\n64 54\n39 66\n67 59\n60 69\n72 23\n57 74\n77 65\n32 80\n81 68\n75 82\n85 70\n73 86\n87 79\n78 88\n89 76\n84 91\n92 71\n83 95\n97 96\n90 100\n104 94\n93 106\n108 98\n103 110\n112 105\n101 114\n117 116\n107 118\n120 102\n109 121\n123 115\n111 124\n126 122\n119 128\n129 125\n99 132\n136 134\n135 137\n139 138\n133 140\n144 130..."
},
{
"input": "100\n7 3 8 8 1 9 6 6 3 3 8 2 7 9 9 10 2 10 4 4 9 3 6 5 2 6 3 6 3 5 2 3 8 2 5 10 3 9 7 2 1 6 7 4 8 3 9 10 9 4 3 3 7 1 4 2 2 5 6 6 1 7 9 1 8 1 2 2 5 9 7 7 6 4 6 10 1 1 8 1 5 6 4 9 5 4 4 10 6 4 5 1 9 1 7 8 6 10 3 2 4 7 10 4 8 10 6 7 8 4 1 3 8 3 2 1 9 4 2 4 3 1 6 8 6 2 2 5 6 8 6 10 1 6 4 2 7 3 6 10 6 5 6 6 3 9 4 6 4 1 5 4 4 2 8 4 10 3 7 6 6 10 2 5 5 6 1 6 1 9 9 1 10 5 10 1 1 5 7 5 2 1 4 2 3 3 3 5 1 8 10 3 3 5 9 6 3 6 8 1",
"output": "4 3\n7 8\n9 2\n1 13\n14 6\n12 17\n18 16\n19 20\n21 15\n10 22\n26 23\n27 29\n30 24\n25 31\n33 11\n32 37\n40 34\n5 41\n42 28\n39 43\n47 38\n36 48\n50 44\n46 51\n57 56\n35 58\n60 59\n54 61\n62 53\n49 63\n65 45\n64 66\n68 67\n71 72\n74 55\n73 75\n78 77\n69 81\n84 70\n83 86\n88 76\n82 89\n90 87\n85 91\n92 80\n79 96\n99 52\n95 102\n103 98\n101 104\n107 97\n105 109\n111 94\n112 114\n115 100\n93 117\n118 110\n116 122\n124 113\n123 125\n126 119\n129 131\n132 106\n120 135\n136 127\n108 137\n138 121\n134 139\n142 128..."
},
{
"input": "100\n6 3 6 8 8 4 3 7 10 3 1 3 9 5 10 10 6 7 6 6 2 3 8 8 7 6 4 9 6 7 4 4 10 4 7 3 2 7 10 8 6 7 9 1 3 5 3 7 9 1 1 7 1 1 7 7 8 3 2 7 4 8 7 8 10 3 1 7 2 7 9 8 8 8 5 2 8 1 2 7 8 7 8 8 5 10 10 4 9 10 8 7 8 8 7 7 3 6 4 3 4 8 10 8 6 3 7 1 8 6 3 3 7 10 3 9 3 5 10 9 9 2 8 7 2 3 2 1 10 9 6 2 8 7 2 2 5 3 10 6 7 2 1 1 5 10 7 5 4 9 7 7 8 1 1 3 3 7 10 5 9 8 6 8 2 2 1 7 8 9 6 2 2 6 2 9 10 2 10 9 6 3 3 10 6 5 3 6 6 3 6 10 8 7 4 8 6 3 4 7",
"output": "-1"
},
{
"input": "1\n2 2",
"output": "2 1"
},
{
"input": "2\n1 2 4 7",
"output": "-1"
}
] | 1,586,875,999 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 78 | 307,200 | n = int(input())
s = list(map(int, input().split()))
if len(set(s)) != len(s)//2:
print(-1)
else:
ans = []
m = list(set(s))
for i in range(2*n):
if s[i] in m:
for j in range(2*n):
if s[i] == s[j] and i != j:
ans.append((i+1, j+1))
m.remove(s[i])
for x in ans:
print(x[0], x[1]) | Title: Cards with Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
Output Specification:
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
Demo Input:
['3\n20 30 10 30 20 10\n', '1\n1 2\n']
Demo Output:
['4 2\n1 5\n6 3\n', '-1']
Note:
none | ```python
n = int(input())
s = list(map(int, input().split()))
if len(set(s)) != len(s)//2:
print(-1)
else:
ans = []
m = list(set(s))
for i in range(2*n):
if s[i] in m:
for j in range(2*n):
if s[i] == s[j] and i != j:
ans.append((i+1, j+1))
m.remove(s[i])
for x in ans:
print(x[0], x[1])
``` | -1 |
|
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get. | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{
"input": "3\n1\n5",
"output": "20"
},
{
"input": "6\n7\n1",
"output": "48"
},
{
"input": "1\n8\n3",
"output": "27"
},
{
"input": "9\n7\n2",
"output": "126"
},
{
"input": "1\n1\n10",
"output": "20"
},
{
"input": "9\n1\n1",
"output": "18"
},
{
"input": "10\n5\n6",
"output": "300"
},
{
"input": "8\n9\n7",
"output": "504"
},
{
"input": "4\n2\n10",
"output": "80"
},
{
"input": "2\n8\n3",
"output": "48"
},
{
"input": "3\n5\n7",
"output": "105"
},
{
"input": "1\n10\n1",
"output": "12"
},
{
"input": "2\n2\n2",
"output": "8"
},
{
"input": "5\n6\n1",
"output": "35"
},
{
"input": "10\n1\n1",
"output": "20"
},
{
"input": "1\n6\n1",
"output": "8"
},
{
"input": "1\n9\n1",
"output": "11"
},
{
"input": "2\n1\n2",
"output": "6"
},
{
"input": "2\n6\n1",
"output": "14"
},
{
"input": "9\n2\n1",
"output": "27"
},
{
"input": "1\n9\n2",
"output": "20"
},
{
"input": "1\n3\n1",
"output": "5"
},
{
"input": "2\n1\n1",
"output": "4"
}
] | 1,698,611,854 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | a,b,c=int(input()),int(input()),int(input());print(max((a+b)*c,(a*b)+c,a*(b+c),a+(b*c),(a+c)*b,(a*c)+b,a*b*c))
# Colin Deiaa | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get.
Input Specification:
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Output Specification:
Print the maximum value of the expression that you can obtain.
Demo Input:
['1\n2\n3\n', '2\n10\n3\n']
Demo Output:
['9\n', '60\n']
Note:
none | ```python
a,b,c=int(input()),int(input()),int(input());print(max((a+b)*c,(a*b)+c,a*(b+c),a+(b*c),(a+c)*b,(a*c)+b,a*b*c))
# Colin Deiaa
``` | 0 |
|
747 | C | Servers | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of servers needed to perform it, and *d**i* — the time needed to perform this task in seconds. All *t**i* are distinct.
To perform the *i*-th task you need *k**i* servers which are unoccupied in the second *t**i*. After the servers begin to perform the task, each of them will be busy over the next *d**i* seconds. Thus, they will be busy in seconds *t**i*,<=*t**i*<=+<=1,<=...,<=*t**i*<=+<=*d**i*<=-<=1. For performing the task, *k**i* servers with the smallest ids will be chosen from all the unoccupied servers. If in the second *t**i* there are not enough unoccupied servers, the task is ignored.
Write the program that determines which tasks will be performed and which will be ignored. | The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks.
Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000) — the moment in seconds in which the *i*-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. | Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. | [
"4 3\n1 3 2\n2 2 1\n3 4 3\n",
"3 2\n3 2 3\n5 1 2\n",
"8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n"
] | [
"6\n-1\n10\n",
"3\n3\n",
"6\n9\n30\n-1\n15\n36\n"
] | In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10).
In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task. | 1,500 | [
{
"input": "4 3\n1 3 2\n2 2 1\n3 4 3",
"output": "6\n-1\n10"
},
{
"input": "3 2\n3 2 3\n5 1 2",
"output": "3\n3"
},
{
"input": "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8",
"output": "6\n9\n30\n-1\n15\n36"
},
{
"input": "4 1\n6 1 1",
"output": "1"
},
{
"input": "1 10\n4 1 1\n9 1 1\n10 1 1\n12 1 1\n13 1 1\n15 1 1\n16 1 1\n18 1 1\n19 1 1\n20 1 1",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "4 10\n1 1 1\n3 1 2\n4 1 2\n6 1 2\n8 1 2\n13 1 2\n16 1 1\n17 1 2\n19 3 1\n20 1 1",
"output": "1\n1\n2\n1\n1\n1\n1\n1\n6\n1"
},
{
"input": "100 1\n1000000 100 1000",
"output": "5050"
},
{
"input": "5 3\n1 4 10\n2 2 5\n3 1 6",
"output": "10\n-1\n5"
},
{
"input": "4 5\n1 2 3\n2 1 3\n3 1 2\n4 3 3\n5 4 1",
"output": "3\n3\n4\n-1\n10"
},
{
"input": "5 3\n1 4 4\n4 2 2\n5 5 2",
"output": "10\n-1\n15"
},
{
"input": "10 4\n1 5 20\n2 5 200\n100 6 20\n101 1 100",
"output": "15\n40\n-1\n1"
},
{
"input": "8 6\n1 3 20\n4 2 1\n6 6 5\n9 1 1\n15 3 6\n21 8 8",
"output": "6\n9\n-1\n4\n15\n36"
},
{
"input": "5 4\n1 1 4\n2 4 4\n5 2 20\n11 5 2",
"output": "1\n14\n-1\n15"
},
{
"input": "8 4\n1 3 2\n2 3 100\n10 6 20\n11 5 20",
"output": "6\n15\n-1\n21"
},
{
"input": "5 3\n1 3 4\n4 3 4\n6 4 1",
"output": "6\n-1\n10"
},
{
"input": "4 3\n1 3 10\n2 2 15\n12 4 1",
"output": "6\n-1\n10"
}
] | 1,638,271,750 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 0 | n,q = [int(x) for x in input().split()]
lis = [i+1 for i in range(n)]
arr = [0 for i in range(n)]
t1 = 0
for qq in range(q):
t,k,d = [int(x) for x in input().split()]
count = 0
for i in range(n):
arr[i] = min(arr[i]+t-t1,0)
# print('before op arr', *arr)
t1 = t
j = 0
res = []
while(count < k and j <n):
if arr[j]>=0:
count += 1
res.append(j+1)
j += 1
if count >= k :
print(sum(res))
for item in res:
arr[item-1] -= d
else:
print(-1)
# print(*arr)
# print(*res)
# arr[j] -= d
# ans += lis[j]
| Title: Servers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of servers needed to perform it, and *d**i* — the time needed to perform this task in seconds. All *t**i* are distinct.
To perform the *i*-th task you need *k**i* servers which are unoccupied in the second *t**i*. After the servers begin to perform the task, each of them will be busy over the next *d**i* seconds. Thus, they will be busy in seconds *t**i*,<=*t**i*<=+<=1,<=...,<=*t**i*<=+<=*d**i*<=-<=1. For performing the task, *k**i* servers with the smallest ids will be chosen from all the unoccupied servers. If in the second *t**i* there are not enough unoccupied servers, the task is ignored.
Write the program that determines which tasks will be performed and which will be ignored.
Input Specification:
The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks.
Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000) — the moment in seconds in which the *i*-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.
Output Specification:
Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.
Demo Input:
['4 3\n1 3 2\n2 2 1\n3 4 3\n', '3 2\n3 2 3\n5 1 2\n', '8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n']
Demo Output:
['6\n-1\n10\n', '3\n3\n', '6\n9\n30\n-1\n15\n36\n']
Note:
In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10).
In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task. | ```python
n,q = [int(x) for x in input().split()]
lis = [i+1 for i in range(n)]
arr = [0 for i in range(n)]
t1 = 0
for qq in range(q):
t,k,d = [int(x) for x in input().split()]
count = 0
for i in range(n):
arr[i] = min(arr[i]+t-t1,0)
# print('before op arr', *arr)
t1 = t
j = 0
res = []
while(count < k and j <n):
if arr[j]>=0:
count += 1
res.append(j+1)
j += 1
if count >= k :
print(sum(res))
for item in res:
arr[item-1] -= d
else:
print(-1)
# print(*arr)
# print(*res)
# arr[j] -= d
# ans += lis[j]
``` | 0 |
|
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this:
- If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position.
Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order? | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data. | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
"output": "12345678901234567890"
},
{
"input": "123456789123456789.999",
"output": "GOTO Vasilisa."
},
{
"input": "12345678901234567890.9",
"output": "12345678901234567891"
},
{
"input": "123456789123456788.999",
"output": "123456789123456789"
},
{
"input": "9.000",
"output": "GOTO Vasilisa."
},
{
"input": "0.1",
"output": "0"
},
{
"input": "0.2",
"output": "0"
},
{
"input": "0.3",
"output": "0"
},
{
"input": "0.4",
"output": "0"
},
{
"input": "0.5",
"output": "1"
},
{
"input": "0.6",
"output": "1"
},
{
"input": "0.7",
"output": "1"
},
{
"input": "0.8",
"output": "1"
},
{
"input": "0.9",
"output": "1"
},
{
"input": "1.0",
"output": "1"
},
{
"input": "1.1",
"output": "1"
},
{
"input": "1.2",
"output": "1"
},
{
"input": "1.3",
"output": "1"
},
{
"input": "1.4",
"output": "1"
},
{
"input": "1.5",
"output": "2"
},
{
"input": "1.6",
"output": "2"
},
{
"input": "1.7",
"output": "2"
},
{
"input": "1.8",
"output": "2"
},
{
"input": "1.9",
"output": "2"
},
{
"input": "2.0",
"output": "2"
},
{
"input": "2.1",
"output": "2"
},
{
"input": "2.2",
"output": "2"
},
{
"input": "2.3",
"output": "2"
},
{
"input": "2.4",
"output": "2"
},
{
"input": "2.5",
"output": "3"
},
{
"input": "2.6",
"output": "3"
},
{
"input": "2.7",
"output": "3"
},
{
"input": "2.8",
"output": "3"
},
{
"input": "2.9",
"output": "3"
},
{
"input": "3.0",
"output": "3"
},
{
"input": "3.1",
"output": "3"
},
{
"input": "3.2",
"output": "3"
},
{
"input": "3.3",
"output": "3"
},
{
"input": "3.4",
"output": "3"
},
{
"input": "3.5",
"output": "4"
},
{
"input": "3.6",
"output": "4"
},
{
"input": "3.7",
"output": "4"
},
{
"input": "3.8",
"output": "4"
},
{
"input": "3.9",
"output": "4"
},
{
"input": "4.0",
"output": "4"
},
{
"input": "4.1",
"output": "4"
},
{
"input": "4.2",
"output": "4"
},
{
"input": "4.3",
"output": "4"
},
{
"input": "4.4",
"output": "4"
},
{
"input": "4.5",
"output": "5"
},
{
"input": "4.6",
"output": "5"
},
{
"input": "4.7",
"output": "5"
},
{
"input": "4.8",
"output": "5"
},
{
"input": "4.9",
"output": "5"
},
{
"input": "5.0",
"output": "5"
},
{
"input": "5.1",
"output": "5"
},
{
"input": "5.2",
"output": "5"
},
{
"input": "5.3",
"output": "5"
},
{
"input": "5.4",
"output": "5"
},
{
"input": "5.5",
"output": "6"
},
{
"input": "5.6",
"output": "6"
},
{
"input": "5.7",
"output": "6"
},
{
"input": "5.8",
"output": "6"
},
{
"input": "5.9",
"output": "6"
},
{
"input": "6.0",
"output": "6"
},
{
"input": "6.1",
"output": "6"
},
{
"input": "6.2",
"output": "6"
},
{
"input": "6.3",
"output": "6"
},
{
"input": "6.4",
"output": "6"
},
{
"input": "6.5",
"output": "7"
},
{
"input": "6.6",
"output": "7"
},
{
"input": "6.7",
"output": "7"
},
{
"input": "6.8",
"output": "7"
},
{
"input": "6.9",
"output": "7"
},
{
"input": "7.0",
"output": "7"
},
{
"input": "7.1",
"output": "7"
},
{
"input": "7.2",
"output": "7"
},
{
"input": "7.3",
"output": "7"
},
{
"input": "7.4",
"output": "7"
},
{
"input": "7.5",
"output": "8"
},
{
"input": "7.6",
"output": "8"
},
{
"input": "7.7",
"output": "8"
},
{
"input": "7.8",
"output": "8"
},
{
"input": "7.9",
"output": "8"
},
{
"input": "8.0",
"output": "8"
},
{
"input": "8.1",
"output": "8"
},
{
"input": "8.2",
"output": "8"
},
{
"input": "8.3",
"output": "8"
},
{
"input": "8.4",
"output": "8"
},
{
"input": "8.5",
"output": "9"
},
{
"input": "8.6",
"output": "9"
},
{
"input": "8.7",
"output": "9"
},
{
"input": "8.8",
"output": "9"
},
{
"input": "8.9",
"output": "9"
},
{
"input": "9.0",
"output": "GOTO Vasilisa."
},
{
"input": "9.1",
"output": "GOTO Vasilisa."
},
{
"input": "9.2",
"output": "GOTO Vasilisa."
},
{
"input": "9.3",
"output": "GOTO Vasilisa."
},
{
"input": "9.4",
"output": "GOTO Vasilisa."
},
{
"input": "9.5",
"output": "GOTO Vasilisa."
},
{
"input": "9.6",
"output": "GOTO Vasilisa."
},
{
"input": "9.7",
"output": "GOTO Vasilisa."
},
{
"input": "9.8",
"output": "GOTO Vasilisa."
},
{
"input": "9.9",
"output": "GOTO Vasilisa."
},
{
"input": "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098.1664915772983166314490532653577560222779830866949001942720729759794777105570672781798092416748052690224813237139640723361527601154465287615917169132637313918577673651098507390501962",
"output": "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098"
},
{
"input": "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394.20211856263503281388748282682120712214711232598021393495443628276945042110862480888110959179019986486690931930108026302665438087068150666835901617457150158918705186964935221768346957536540345814875615118637945520917367155931078965",
"output": "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394"
},
{
"input": "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616067.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616068"
},
{
"input": "718130341896330596635811874410345440628950330.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "718130341896330596635811874410345440628950331"
},
{
"input": "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280722.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280723"
},
{
"input": "68289614863244584294178637364598054554769889.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "GOTO Vasilisa."
},
{
"input": "7536521504744364134984603189602839063535643888645969434165019366202558753840519.4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"output": "GOTO Vasilisa."
},
{
"input": "646188694587964249318078225173.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "646188694587964249318078225174"
},
{
"input": "7017472758334494297677068672222822550374695787171163207025095950296957261530.50",
"output": "7017472758334494297677068672222822550374695787171163207025095950296957261531"
},
{
"input": "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774368.50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774369"
},
{
"input": "682500858233333594535201113441004740771119672961581796618069185960107115823662126812159957094407454522028503739299.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "GOTO Vasilisa."
},
{
"input": "41203422675619090661099806687619.49999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"output": "GOTO Vasilisa."
}
] | 1,691,776,154 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | # Read the number as a string
number = input()
# Split the number into integer and fractional parts
integer_part, fractional_part = number.split(".")
# Check if the last digit of the integer part is not 9
if integer_part[-1] != "9":
# Check if the fractional part is less than 0.5
if int(fractional_part) < 5:
rounded_number = integer_part
else:
rounded_number = str(int(integer_part) + 1)
print(rounded_number)
else:
print("GOTO Vasilisa.")
| Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this:
- If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position.
Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?
Input Specification:
The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.
Output Specification:
If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).
Demo Input:
['0.0\n', '1.49\n', '1.50\n', '2.71828182845904523536\n', '3.14159265358979323846\n', '12345678901234567890.1\n', '123456789123456789.999\n']
Demo Output:
['0', '1', '2', '3', '3', '12345678901234567890', 'GOTO Vasilisa.']
Note:
none | ```python
# Read the number as a string
number = input()
# Split the number into integer and fractional parts
integer_part, fractional_part = number.split(".")
# Check if the last digit of the integer part is not 9
if integer_part[-1] != "9":
# Check if the fractional part is less than 0.5
if int(fractional_part) < 5:
rounded_number = integer_part
else:
rounded_number = str(int(integer_part) + 1)
print(rounded_number)
else:
print("GOTO Vasilisa.")
``` | 0 |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,687,523,565 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | socks = list(map(int, input().split(' ')))
first = 0
second = 0
while socks[0] != 0 and socks[1] != 0:
socks[0] -= 1
socks[1] -= 1
first += 1
if socks[0] == 0: socks = socks[1]
elif socks[1] == 0: socks = socks[0]
while socks != 1 and socks != 0:
socks -= 2
second += 1
print(first, second) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
socks = list(map(int, input().split(' ')))
first = 0
second = 0
while socks[0] != 0 and socks[1] != 0:
socks[0] -= 1
socks[1] -= 1
first += 1
if socks[0] == 0: socks = socks[1]
elif socks[1] == 0: socks = socks[0]
while socks != 1 and socks != 0:
socks -= 2
second += 1
print(first, second)
``` | 3 |
|
888 | A | Local Extrema | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=><=*a**i*<=-<=1 and *a**i*<=><=*a**i*<=+<=1). Since *a*1 and *a**n* have only one neighbour each, they are neither local minima nor local maxima.
An element is called a local extremum iff it is either local maximum or local minimum. Your task is to calculate the number of local extrema in the given array. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*. | Print the number of local extrema in the given array. | [
"3\n1 2 3\n",
"4\n1 5 2 5\n"
] | [
"0\n",
"2\n"
] | none | 0 | [
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "4\n1 5 2 5",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n548",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n3 2 3",
"output": "1"
},
{
"input": "2\n1 1000",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}
] | 1,656,443,702 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 46 | 0 | a = int(input())
local = list(map(int, input().split()))
ans = 0
for i in range(1, a - 1):
if local[i] > local[i - 1] and local[i] > local[i + 1]:
ans += 1
if local[i] < local[i - 1] and local[i] < local[i + 1]:
ans += 1
print(ans) | Title: Local Extrema
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=><=*a**i*<=-<=1 and *a**i*<=><=*a**i*<=+<=1). Since *a*1 and *a**n* have only one neighbour each, they are neither local minima nor local maxima.
An element is called a local extremum iff it is either local maximum or local minimum. Your task is to calculate the number of local extrema in the given array.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*.
Output Specification:
Print the number of local extrema in the given array.
Demo Input:
['3\n1 2 3\n', '4\n1 5 2 5\n']
Demo Output:
['0\n', '2\n']
Note:
none | ```python
a = int(input())
local = list(map(int, input().split()))
ans = 0
for i in range(1, a - 1):
if local[i] > local[i - 1] and local[i] > local[i + 1]:
ans += 1
if local[i] < local[i - 1] and local[i] < local[i + 1]:
ans += 1
print(ans)
``` | 3 |