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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
761 | B | Dasha and friends | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"math"
] | null | null | Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length *L*, in distinct points of which there are *n* barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track.
Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the *n* barriers. Thus, each of them wrote *n* integers in the ascending order, each of them was between 0 and *L*<=-<=1, inclusively.
There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks.
Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above. | The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=50, *n*<=≤<=*L*<=≤<=100) — the number of barriers on a track and its length.
The second line contains *n* distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to *L*<=-<=1 inclusively.
The second line contains *n* distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to *L*<=-<=1 inclusively. | Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes). | [
"3 8\n2 4 6\n1 5 7\n",
"4 9\n2 3 5 8\n0 1 3 6\n",
"2 4\n1 3\n1 2\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | The first test is analyzed in the statement. | 1,000 | [
{
"input": "3 8\n2 4 6\n1 5 7",
"output": "YES"
},
{
"input": "4 9\n2 3 5 8\n0 1 3 6",
"output": "YES"
},
{
"input": "2 4\n1 3\n1 2",
"output": "NO"
},
{
"input": "5 9\n0 2 5 6 7\n1 3 6 7 8",
"output": "YES"
},
{
"input": "5 60\n7 26 27 40 59\n14 22 41 42 55",
"output": "YES"
},
{
"input": "20 29\n0 1 2 4 5 8 9 12 14 15 17 19 20 21 22 23 25 26 27 28\n0 2 4 5 6 7 8 10 11 12 13 14 15 16 18 19 22 23 26 28",
"output": "YES"
},
{
"input": "35 41\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 18 19 20 21 22 23 24 25 26 28 30 31 32 33 34 35 36 37 38 39 40\n0 1 2 3 4 5 7 8 9 10 11 12 16 17 18 19 20 21 22 23 24 26 28 29 30 31 32 33 34 35 36 37 38 39 40",
"output": "YES"
},
{
"input": "40 63\n0 2 3 4 5 6 9 10 12 15 17 19 23 25 26 27 28 29 30 31 33 34 36 37 38 39 40 43 45 49 50 52 53 54 55 57 58 60 61 62\n1 2 3 4 5 8 10 14 15 17 18 19 20 22 23 25 26 27 28 30 31 32 33 34 37 38 40 43 46 47 51 53 54 55 56 57 58 59 61 62",
"output": "NO"
},
{
"input": "50 97\n1 2 3 4 6 9 10 11 12 13 14 21 22 23 24 25 28 29 30 31 32 33 34 36 37 40 41 45 53 56 59 64 65 69 70 71 72 73 74 77 81 84 85 86 87 89 91 92 95 96\n0 1 2 3 6 10 13 14 15 16 18 20 21 24 25 27 28 29 30 33 35 36 37 38 39 40 47 48 49 50 51 54 55 56 57 58 59 60 62 63 66 67 71 79 82 85 90 91 95 96",
"output": "NO"
},
{
"input": "50 100\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98\n1 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",
"output": "YES"
},
{
"input": "1 2\n0\n0",
"output": "YES"
},
{
"input": "1 2\n0\n1",
"output": "YES"
},
{
"input": "1 2\n1\n0",
"output": "YES"
},
{
"input": "1 2\n1\n1",
"output": "YES"
},
{
"input": "1 1\n0\n0",
"output": "YES"
},
{
"input": "5 12\n2 3 4 8 10\n2 3 4 8 10",
"output": "YES"
},
{
"input": "1 18\n3\n10",
"output": "YES"
},
{
"input": "1 75\n65\n8",
"output": "YES"
},
{
"input": "2 16\n4 13\n2 11",
"output": "YES"
},
{
"input": "2 95\n45 59\n3 84",
"output": "YES"
},
{
"input": "3 53\n29 43 50\n29 43 50",
"output": "YES"
},
{
"input": "3 60\n39 46 51\n43 50 55",
"output": "YES"
},
{
"input": "4 4\n0 1 2 3\n0 1 2 3",
"output": "YES"
},
{
"input": "4 93\n45 48 50 90\n20 68 71 73",
"output": "YES"
},
{
"input": "6 18\n0 3 8 11 15 16\n2 7 10 14 15 17",
"output": "YES"
},
{
"input": "6 87\n0 1 21 31 34 66\n11 12 32 42 45 77",
"output": "YES"
},
{
"input": "7 26\n0 3 9 13 14 19 20\n4 7 13 17 18 23 24",
"output": "YES"
},
{
"input": "7 81\n0 12 19 24 25 35 59\n1 8 13 14 24 48 70",
"output": "YES"
},
{
"input": "8 20\n0 1 2 3 5 6 14 15\n1 2 10 11 16 17 18 19",
"output": "YES"
},
{
"input": "8 94\n0 8 11 27 38 54 57 89\n1 33 38 46 49 65 76 92",
"output": "YES"
},
{
"input": "9 18\n1 3 6 8 11 12 13 16 17\n0 2 5 6 7 10 11 13 15",
"output": "YES"
},
{
"input": "9 90\n10 11 27 33 34 55 63 84 87\n9 12 25 26 42 48 49 70 78",
"output": "YES"
},
{
"input": "10 42\n4 9 10 14 15 16 19 33 36 40\n0 14 17 21 27 32 33 37 38 39",
"output": "YES"
},
{
"input": "10 73\n4 5 15 19 20 25 28 42 57 58\n3 4 9 12 26 41 42 61 62 72",
"output": "YES"
},
{
"input": "11 11\n0 1 2 3 4 5 6 7 8 9 10\n0 1 2 3 4 5 6 7 8 9 10",
"output": "YES"
},
{
"input": "11 57\n1 4 27 30 31 35 37 41 50 52 56\n22 25 26 30 32 36 45 47 51 53 56",
"output": "YES"
},
{
"input": "12 73\n5 9 11 20 25 36 40 41 44 48 56 60\n12 16 18 27 32 43 47 48 51 55 63 67",
"output": "YES"
},
{
"input": "12 95\n1 37 42 46 56 58 59 62 64 71 76 80\n2 18 54 59 63 73 75 76 79 81 88 93",
"output": "YES"
},
{
"input": "13 29\n2 5 6 9 12 17 18 19 20 21 22 24 27\n0 3 6 11 12 13 14 15 16 18 21 25 28",
"output": "YES"
},
{
"input": "13 90\n9 18 23 30 31 36 39 44 58 59 74 82 87\n1 6 18 27 32 39 40 45 48 53 67 68 83",
"output": "YES"
},
{
"input": "14 29\n1 2 3 4 5 7 9 12 13 20 21 22 23 24\n0 3 4 11 12 13 14 15 21 22 23 24 25 27",
"output": "YES"
},
{
"input": "14 94\n7 8 9 21 34 35 36 37 38 43 46 52 84 93\n2 3 4 16 29 30 31 32 33 38 41 47 79 88",
"output": "YES"
},
{
"input": "15 19\n1 2 3 4 5 6 7 8 9 10 11 13 14 16 17\n0 1 2 3 4 5 6 7 8 9 10 12 13 15 16",
"output": "YES"
},
{
"input": "15 27\n2 3 4 5 6 7 8 9 10 11 12 14 17 24 26\n2 3 4 5 6 7 8 9 10 11 12 14 17 24 26",
"output": "YES"
},
{
"input": "16 28\n3 5 6 7 9 10 11 12 13 14 17 19 20 25 26 27\n0 5 6 7 11 13 14 15 17 18 19 20 21 22 25 27",
"output": "YES"
},
{
"input": "16 93\n5 6 10 11 13 14 41 43 46 61 63 70 74 79 83 92\n0 9 15 16 20 21 23 24 51 53 56 71 73 80 84 89",
"output": "YES"
},
{
"input": "17 49\n2 5 11 12 16 18 19 21 22 24 36 37 38 39 40 44 47\n1 7 8 12 14 15 17 18 20 32 33 34 35 36 40 43 47",
"output": "YES"
},
{
"input": "17 86\n16 17 25 33 39 41 50 51 54 56 66 70 72 73 77 80 85\n3 9 11 20 21 24 26 36 40 42 43 47 50 55 72 73 81",
"output": "YES"
},
{
"input": "18 20\n0 1 2 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n0 1 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19",
"output": "YES"
},
{
"input": "18 82\n0 5 10 13 14 16 21 28 29 30 44 46 61 64 69 71 77 78\n0 5 8 9 11 16 23 24 25 39 41 56 59 64 66 72 73 77",
"output": "YES"
},
{
"input": "19 25\n0 1 2 3 5 7 9 10 12 13 16 17 18 19 20 21 22 23 24\n0 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 21 22 24",
"output": "YES"
},
{
"input": "19 91\n5 17 18 20 22 25 26 31 32 33 43 47 54 61 62 64 77 80 87\n4 5 6 16 20 27 34 35 37 50 53 60 69 81 82 84 86 89 90",
"output": "YES"
},
{
"input": "20 53\n2 6 8 9 16 17 20 21 22 23 25 26 35 36 38 39 44 46 47 50\n4 5 8 9 10 11 13 14 23 24 26 27 32 34 35 38 43 47 49 50",
"output": "YES"
},
{
"input": "21 44\n0 1 3 4 6 7 8 9 10 11 12 15 17 18 21 22 27 29 34 36 42\n1 7 9 10 12 13 15 16 17 18 19 20 21 24 26 27 30 31 36 38 43",
"output": "YES"
},
{
"input": "21 94\n3 5 6 8 9 15 16 20 28 31 35 39 49 50 53 61 71 82 85 89 90\n6 17 20 24 25 32 34 35 37 38 44 45 49 57 60 64 68 78 79 82 90",
"output": "YES"
},
{
"input": "22 24\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23",
"output": "YES"
},
{
"input": "22 85\n3 5 7 14 18 21 25 32 38 41 53 58 61 62 66 70 71 73 75 76 79 83\n3 6 18 23 26 27 31 35 36 38 40 41 44 48 53 55 57 64 68 71 75 82",
"output": "YES"
},
{
"input": "23 38\n0 2 4 5 7 8 12 13 14 16 17 18 21 22 24 27 28 30 31 32 35 36 37\n0 1 2 3 5 7 8 10 11 15 16 17 19 20 21 24 25 27 30 31 33 34 35",
"output": "YES"
},
{
"input": "23 93\n1 3 5 10 19 22 26 27 30 35 39 53 55 60 66 67 75 76 77 80 82 89 90\n9 11 16 22 23 31 32 33 36 38 45 46 50 52 54 59 68 71 75 76 79 84 88",
"output": "YES"
},
{
"input": "24 37\n1 4 5 6 8 11 12 13 15 16 17 19 20 21 23 26 27 28 30 31 33 34 35 36\n0 3 4 5 7 8 10 11 12 13 15 18 19 20 22 25 26 27 29 30 31 33 34 35",
"output": "YES"
},
{
"input": "24 94\n9 10 13 14 16 18 19 22 24 29 32 35 48 55 57 63 64 69 72 77 78 85 90 92\n1 7 8 13 16 21 22 29 34 36 47 48 51 52 54 56 57 60 62 67 70 73 86 93",
"output": "YES"
},
{
"input": "25 45\n0 1 2 4 6 7 8 9 13 14 17 19 21 22 23 25 28 29 30 31 34 36 38 39 42\n1 3 4 5 7 10 11 12 13 16 18 20 21 24 27 28 29 31 33 34 35 36 40 41 44",
"output": "YES"
},
{
"input": "25 72\n1 2 6 8 9 11 15 18 19 20 26 29 31 33 34 40 41 43 45 48 58 60 68 69 71\n0 6 9 11 13 14 20 21 23 25 28 38 40 48 49 51 53 54 58 60 61 63 67 70 71",
"output": "YES"
},
{
"input": "26 47\n0 2 5 7 8 9 10 12 13 14 20 22 23 25 27 29 31 32 33 35 36 37 38 42 44 45\n0 2 4 6 8 9 10 12 13 14 15 19 21 22 24 26 29 31 32 33 34 36 37 38 44 46",
"output": "YES"
},
{
"input": "26 99\n0 1 13 20 21 22 25 26 27 28 32 39 44 47 56 58 60 62 71 81 83 87 89 93 94 98\n6 8 12 14 18 19 23 24 25 37 44 45 46 49 50 51 52 56 63 68 71 80 82 84 86 95",
"output": "YES"
},
{
"input": "27 35\n0 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 19 20 21 23 26 27 29 30 31 32 33\n0 1 2 3 5 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 24 25 26 28 31 32 34",
"output": "YES"
},
{
"input": "27 51\n1 2 4 7 8 11 13 17 20 21 23 24 25 28 29 30 34 35 37 38 40 43 45 46 47 48 50\n0 1 2 4 6 7 9 12 13 16 18 22 25 26 28 29 30 33 34 35 39 40 42 43 45 48 50",
"output": "YES"
},
{
"input": "28 38\n1 4 5 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 28 29 30 32 33 35 36 37\n0 1 2 3 4 5 6 9 10 11 13 14 16 17 18 20 23 24 26 27 28 29 30 31 33 34 35 37",
"output": "YES"
},
{
"input": "28 67\n0 1 2 3 6 9 10 15 18 22 24 25 30 35 36 38 39 47 48 49 51 53 55 56 58 62 63 64\n4 7 11 13 14 19 24 25 27 28 36 37 38 40 42 44 45 47 51 52 53 56 57 58 59 62 65 66",
"output": "YES"
},
{
"input": "29 29\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28",
"output": "YES"
},
{
"input": "29 93\n1 2 11 13 18 21 27 28 30 38 41 42 46 54 55 56 60 61 63 64 66 69 71 72 77 81 83 89 90\n2 10 11 12 16 17 19 20 22 25 27 28 33 37 39 45 46 50 51 60 62 67 70 76 77 79 87 90 91",
"output": "YES"
},
{
"input": "30 63\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58 61\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58 61",
"output": "YES"
},
{
"input": "30 91\n1 2 3 7 8 9 13 16 17 19 27 29 38 45 47 52 53 55 61 62 66 77 78 79 80 81 82 84 88 89\n3 4 5 9 12 13 15 23 25 34 41 43 48 49 51 57 58 62 73 74 75 76 77 78 80 84 85 88 89 90",
"output": "YES"
},
{
"input": "31 39\n0 1 2 3 4 5 6 7 8 10 11 13 14 17 18 20 21 23 24 25 27 28 29 30 31 33 34 35 36 37 38\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 21 22 25 26 28 29 31 32 33 35 36 37 38",
"output": "YES"
},
{
"input": "31 95\n9 12 14 15 21 23 26 28 30 36 37 42 47 51 54 56 59 62 64 65 66 70 72 74 75 79 82 85 87 91 93\n0 2 3 7 10 13 15 19 21 32 35 37 38 44 46 49 51 53 59 60 65 70 74 77 79 82 85 87 88 89 93",
"output": "YES"
},
{
"input": "32 61\n0 2 3 5 7 10 13 14 15 18 19 20 21 22 23 24 26 32 33 34 36 38 43 46 47 51 54 55 56 57 58 59\n1 2 4 6 9 12 13 14 17 18 19 20 21 22 23 25 31 32 33 35 37 42 45 46 50 53 54 55 56 57 58 60",
"output": "YES"
},
{
"input": "32 86\n5 7 9 10 13 17 18 19 25 26 28 32 33 37 38 43 45 47 50 53 57 58 60 69 73 74 75 77 80 82 83 85\n7 11 12 13 15 18 20 21 23 29 31 33 34 37 41 42 43 49 50 52 56 57 61 62 67 69 71 74 77 81 82 84",
"output": "YES"
},
{
"input": "33 44\n0 1 2 3 5 9 10 11 12 13 14 15 17 18 20 21 22 23 24 25 26 27 28 30 31 32 35 36 38 39 41 42 43\n0 2 3 4 7 8 10 11 13 14 15 16 17 18 19 21 25 26 27 28 29 30 31 33 34 36 37 38 39 40 41 42 43",
"output": "YES"
},
{
"input": "33 73\n3 6 7 8 9 10 11 13 14 15 17 19 22 23 26 27 28 31 33 34 35 37 42 44 48 52 54 57 62 63 64 67 68\n2 3 4 7 8 16 19 20 21 22 23 24 26 27 28 30 32 35 36 39 40 41 44 46 47 48 50 55 57 61 65 67 70",
"output": "YES"
},
{
"input": "34 52\n1 2 3 4 5 6 8 9 10 12 13 14 15 16 17 19 21 24 26 27 28 29 31 33 35 36 37 39 40 45 46 49 50 51\n0 1 2 3 4 6 7 8 10 11 12 13 14 15 17 19 22 24 25 26 27 29 31 33 34 35 37 38 43 44 47 48 49 51",
"output": "YES"
},
{
"input": "34 68\n0 7 9 10 11 14 15 16 20 21 22 24 26 32 34 35 37 38 40 41 42 43 44 45 47 50 53 55 57 58 59 62 64 65\n0 1 2 3 5 8 11 13 15 16 17 20 22 23 26 33 35 36 37 40 41 42 46 47 48 50 52 58 60 61 63 64 66 67",
"output": "YES"
},
{
"input": "35 90\n4 5 7 8 10 11 12 13 14 22 27 29 31 33 34 38 46 49 52 53 54 55 56 57 60 61 64 69 77 81 83 86 87 88 89\n4 7 10 11 12 13 14 15 18 19 22 27 35 39 41 44 45 46 47 52 53 55 56 58 59 60 61 62 70 75 77 79 81 82 86",
"output": "YES"
},
{
"input": "36 43\n1 2 3 4 6 7 8 9 10 11 14 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 42\n0 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 21 23 24 25 26 28 29 30 31 32 33 36 38 39 40 41 42",
"output": "YES"
},
{
"input": "36 84\n1 3 6 13 15 16 17 18 19 21 23 26 29 33 38 40 42 45 49 50 53 54 57 58 60 61 64 65 67 70 73 76 78 79 81 83\n0 2 5 8 12 17 19 21 24 28 29 32 33 36 37 39 40 43 44 46 49 52 55 57 58 60 62 64 66 69 76 78 79 80 81 82",
"output": "YES"
},
{
"input": "37 46\n0 1 3 6 7 8 9 10 12 13 14 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 39 40 41 42 43 44\n0 3 4 5 6 7 9 10 11 13 14 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 36 37 38 39 40 41 43 44",
"output": "YES"
},
{
"input": "37 97\n0 5 10 11 12 15 16 18 19 25 28 29 34 35 36 37 38 40 46 47 48 49 55 58 60 61 62 64 65 70 76 77 80 82 88 94 96\n1 7 13 15 16 21 26 27 28 31 32 34 35 41 44 45 50 51 52 53 54 56 62 63 64 65 71 74 76 77 78 80 81 86 92 93 96",
"output": "YES"
},
{
"input": "38 58\n1 2 3 4 5 8 9 11 12 13 15 16 17 22 23 24 25 26 27 29 30 31 32 33 34 36 37 40 41 43 46 47 48 52 53 55 56 57\n1 2 3 5 6 7 8 9 12 13 15 16 17 19 20 21 26 27 28 29 30 31 33 34 35 36 37 38 40 41 44 45 47 50 51 52 56 57",
"output": "YES"
},
{
"input": "38 92\n1 2 3 5 6 7 12 14 15 16 17 18 20 22 29 31 33 34 38 41 43 49 54 55 57 58 61 63 66 67 69 73 75 76 82 85 88 90\n1 3 4 10 13 16 18 21 22 23 25 26 27 32 34 35 36 37 38 40 42 49 51 53 54 58 61 63 69 74 75 77 78 81 83 86 87 89",
"output": "YES"
},
{
"input": "39 59\n0 1 2 3 5 6 7 8 9 10 11 12 13 15 16 17 19 24 25 28 29 31 32 33 35 37 38 40 41 42 43 45 46 47 49 50 53 55 56\n0 1 3 4 5 6 8 9 10 12 13 16 18 19 22 23 24 25 27 28 29 30 31 32 33 34 35 37 38 39 41 46 47 50 51 53 54 55 57",
"output": "YES"
},
{
"input": "39 67\n1 3 5 7 8 16 18 20 21 23 24 25 27 28 29 31 32 34 36 38 40 43 44 46 47 48 49 50 52 53 54 55 58 59 61 62 63 64 66\n0 1 2 4 6 8 10 12 13 21 23 25 26 28 29 30 32 33 34 36 37 39 41 43 45 48 49 51 52 53 54 55 57 58 59 60 63 64 66",
"output": "YES"
},
{
"input": "40 63\n0 2 3 4 5 6 9 10 12 15 18 19 23 25 26 27 28 29 30 31 33 34 36 37 38 39 40 43 45 49 50 52 53 54 55 57 58 60 61 62\n1 2 3 4 5 8 10 14 15 17 18 19 20 22 23 25 26 27 28 30 31 32 33 34 37 38 40 43 46 47 51 53 54 55 56 57 58 59 61 62",
"output": "YES"
},
{
"input": "40 96\n5 11 12 13 14 16 17 18 19 24 30 31 32 33 37 42 46 50 53 54 55 58 60 61 64 67 68 69 70 72 75 76 77 81 84 85 89 91 92 93\n2 7 11 15 18 19 20 23 25 26 29 32 33 34 35 37 40 41 42 46 49 50 54 56 57 58 66 72 73 74 75 77 78 79 80 85 91 92 93 94",
"output": "YES"
},
{
"input": "41 67\n0 2 3 5 8 10 11 12 13 14 15 19 20 21 22 26 29 30 31 32 34 35 37 38 40 41 44 45 46 47 49 51 52 53 54 56 57 58 59 63 66\n2 3 4 5 9 12 13 14 15 17 18 20 21 23 24 27 28 29 30 32 34 35 36 37 39 40 41 42 46 49 50 52 53 55 58 60 61 62 63 64 65",
"output": "YES"
},
{
"input": "41 72\n0 3 4 6 7 8 9 12 13 14 16 21 23 24 25 26 27 29 31 32 33 34 35 38 40 41 45 47 49 50 51 52 56 57 58 59 61 62 65 66 69\n0 1 4 5 6 8 13 15 16 17 18 19 21 23 24 25 26 27 30 32 33 37 39 41 42 43 44 48 49 50 51 53 54 57 58 61 64 67 68 70 71",
"output": "YES"
},
{
"input": "42 48\n0 1 2 3 4 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 26 27 28 29 30 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47\n0 1 2 3 4 5 6 8 9 10 11 12 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 37 38 39 40 41 42 43 45 46 47",
"output": "YES"
},
{
"input": "42 81\n0 1 3 6 7 8 11 13 17 18 19 21 22 24 29 30 31 32 34 35 38 44 46 48 49 50 51 52 53 55 59 61 62 63 65 66 67 69 70 72 77 80\n0 1 3 4 6 11 12 13 14 16 17 20 26 28 30 31 32 33 34 35 37 41 43 44 45 47 48 49 51 52 54 59 62 63 64 66 69 70 71 74 76 80",
"output": "YES"
},
{
"input": "43 55\n0 1 2 3 4 5 6 7 8 12 14 15 17 18 19 20 21 22 23 26 27 28 29 31 32 33 35 36 37 38 40 42 43 44 45 46 47 48 49 50 51 53 54\n1 2 4 5 6 7 8 9 10 13 14 15 16 18 19 20 22 23 24 25 27 29 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 49 50 54",
"output": "YES"
},
{
"input": "43 81\n2 3 4 5 6 7 9 10 12 13 18 19 20 21 23 26 27 29 30 32 34 38 39 43 46 47 48 50 51 52 54 55 58 62 64 67 69 70 71 72 73 75 80\n0 3 5 6 7 8 9 11 16 19 20 21 22 23 24 26 27 29 30 35 36 37 38 40 43 44 46 47 49 51 55 56 60 63 64 65 67 68 69 71 72 75 79",
"output": "YES"
},
{
"input": "44 54\n0 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 33 34 35 36 37 39 40 41 43 44 47 49 50 52 53\n0 1 2 3 4 5 6 7 8 10 12 13 14 15 16 18 19 20 22 23 26 28 29 31 32 33 34 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52",
"output": "YES"
},
{
"input": "44 93\n1 5 6 7 8 10 14 17 19 21 25 26 27 30 33 34 35 36 38 41 45 48 49 51 53 55 57 60 66 67 69 70 73 76 78 79 80 81 82 83 85 87 88 90\n0 2 4 8 9 10 13 16 17 18 19 21 24 28 31 32 34 36 38 40 43 49 50 52 53 56 59 61 62 63 64 65 66 68 70 71 73 77 81 82 83 84 86 90",
"output": "YES"
},
{
"input": "45 47\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 43 44 45 46\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46",
"output": "YES"
},
{
"input": "45 71\n0 2 3 7 8 11 12 13 14 15 16 17 20 21 22 23 24 26 28 30 32 37 39 41 42 43 44 45 47 48 50 52 54 55 56 57 58 59 60 61 62 64 66 68 70\n0 1 2 3 4 7 8 9 10 11 13 15 17 19 24 26 28 29 30 31 32 34 35 37 39 41 42 43 44 45 46 47 48 49 51 53 55 57 58 60 61 65 66 69 70",
"output": "YES"
},
{
"input": "46 46\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45",
"output": "YES"
},
{
"input": "46 93\n0 1 2 6 13 16 17 18 19 21 27 29 32 34 37 38 39 40 41 44 45 49 50 52 54 56 57 61 64 65 66 67 69 71 73 75 77 78 79 83 85 87 88 90 91 92\n0 2 4 5 7 8 9 10 11 12 16 23 26 27 28 29 31 37 39 42 44 47 48 49 50 51 54 55 59 60 62 64 66 67 71 74 75 76 77 79 81 83 85 87 88 89",
"output": "YES"
},
{
"input": "47 49\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 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\n0 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 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",
"output": "YES"
},
{
"input": "47 94\n0 1 3 4 5 7 8 9 14 18 19 26 30 33 34 35 37 40 42 45 46 49 50 51 52 53 55 56 60 61 62 63 64 65 66 69 71 73 75 79 84 86 87 88 90 92 93\n1 2 3 4 6 7 8 10 11 12 17 21 22 29 33 36 37 38 40 43 45 48 49 52 53 54 55 56 58 59 63 64 65 66 67 68 69 72 74 76 78 82 87 89 90 91 93",
"output": "YES"
},
{
"input": "48 65\n0 1 2 4 5 6 7 8 9 10 11 12 15 16 17 20 22 24 25 26 27 28 30 32 33 34 35 37 38 39 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 61 62 63\n0 1 4 6 8 9 10 11 12 14 16 17 18 19 21 22 23 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 45 46 47 49 50 51 53 54 55 56 57 58 59 60 61 64",
"output": "YES"
},
{
"input": "48 90\n1 3 4 5 8 9 11 13 14 15 16 18 20 21 24 26 29 30 31 33 34 36 37 38 39 40 42 43 44 46 47 48 51 52 55 58 59 61 62 63 65 66 68 78 79 81 82 89\n0 3 4 6 8 9 10 11 13 15 16 19 21 24 25 26 28 29 31 32 33 34 35 37 38 39 41 42 43 46 47 50 53 54 56 57 58 60 61 63 73 74 76 77 84 86 88 89",
"output": "YES"
},
{
"input": "49 60\n0 1 2 5 7 8 9 10 11 12 13 14 15 16 17 19 20 21 23 25 26 27 28 29 30 31 32 33 34 36 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 58 59\n0 1 2 3 4 5 6 7 8 10 11 12 14 16 17 18 19 20 21 22 23 24 25 27 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 46 49 50 51 52 53 56 58 59",
"output": "YES"
},
{
"input": "49 97\n0 1 2 3 6 8 11 14 19 23 26 29 32 34 35 37 39 41 43 44 45 46 51 53 63 64 65 66 67 70 71 72 73 76 77 78 79 81 83 84 86 87 90 91 92 93 94 95 96\n0 3 4 5 6 7 8 9 10 11 12 13 16 18 21 24 29 33 36 39 42 44 45 47 49 51 53 54 55 56 61 63 73 74 75 76 77 80 81 82 83 86 87 88 89 91 93 94 96",
"output": "YES"
},
{
"input": "50 58\n0 1 2 3 5 6 7 8 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 49 50 54 55 56 57\n0 1 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 31 32 36 37 38 39 40 41 42 43 45 46 47 48 50 51 52 53 54 55 56 57",
"output": "YES"
},
{
"input": "50 97\n1 2 3 4 7 9 10 11 12 13 14 21 22 23 24 25 28 29 30 31 32 33 34 36 37 40 41 45 53 56 59 64 65 69 70 71 72 73 74 77 81 84 85 86 87 89 91 92 95 96\n0 1 2 3 6 10 13 14 15 16 18 20 21 24 25 27 28 29 30 33 35 36 37 38 39 40 47 48 49 50 51 54 55 56 57 58 59 60 62 63 66 67 71 79 82 85 90 91 95 96",
"output": "YES"
},
{
"input": "40 96\n5 11 12 13 14 16 17 18 19 24 30 31 32 33 37 42 46 50 53 54 55 58 60 61 64 67 68 69 70 72 75 76 77 81 84 85 88 91 92 93\n2 7 11 15 18 19 20 23 25 26 29 32 33 34 35 37 40 41 42 46 49 50 54 56 57 58 66 72 73 74 75 77 78 79 80 85 91 92 93 94",
"output": "NO"
},
{
"input": "41 67\n0 2 3 5 8 10 11 12 13 14 15 19 20 21 22 25 29 30 31 32 34 35 37 38 40 41 44 45 46 47 49 51 52 53 54 56 57 58 59 63 66\n2 3 4 5 9 12 13 14 15 17 18 20 21 23 24 27 28 29 30 32 34 35 36 37 39 40 41 42 46 49 50 52 53 55 58 60 61 62 63 64 65",
"output": "NO"
},
{
"input": "41 72\n0 3 4 6 7 8 9 12 13 14 16 21 23 24 25 26 27 28 31 32 33 34 35 38 40 41 45 47 49 50 51 52 56 57 58 59 61 62 65 66 69\n0 1 4 5 6 8 13 15 16 17 18 19 21 23 24 25 26 27 30 32 33 37 39 41 42 43 44 48 49 50 51 53 54 57 58 61 64 67 68 70 71",
"output": "NO"
},
{
"input": "42 48\n0 1 2 3 4 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47\n0 1 2 3 4 5 6 8 9 10 11 12 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 37 38 39 40 41 42 43 45 46 47",
"output": "NO"
},
{
"input": "42 81\n0 1 3 6 7 8 11 13 17 18 19 20 22 24 29 30 31 32 34 35 38 44 46 48 49 50 51 52 53 55 59 61 62 63 65 66 67 69 70 72 77 80\n0 1 3 4 6 11 12 13 14 16 17 20 26 28 30 31 32 33 34 35 37 41 43 44 45 47 48 49 51 52 54 59 62 63 64 66 69 70 71 74 76 80",
"output": "NO"
},
{
"input": "43 55\n0 1 2 3 4 5 6 7 8 12 14 15 17 18 19 20 21 22 23 26 27 28 29 31 32 33 34 36 37 38 40 42 43 44 45 46 47 48 49 50 51 53 54\n1 2 4 5 6 7 8 9 10 13 14 15 16 18 19 20 22 23 24 25 27 29 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 49 50 54",
"output": "NO"
},
{
"input": "43 81\n2 3 4 5 6 7 9 10 12 13 17 19 20 21 23 26 27 29 30 32 34 38 39 43 46 47 48 50 51 52 54 55 58 62 64 67 69 70 71 72 73 75 80\n0 3 5 6 7 8 9 11 16 19 20 21 22 23 24 26 27 29 30 35 36 37 38 40 43 44 46 47 49 51 55 56 60 63 64 65 67 68 69 71 72 75 79",
"output": "NO"
},
{
"input": "44 54\n0 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 33 34 35 36 37 38 40 41 43 44 47 49 50 52 53\n0 1 2 3 4 5 6 7 8 10 12 13 14 15 16 18 19 20 22 23 26 28 29 31 32 33 34 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52",
"output": "NO"
},
{
"input": "44 93\n1 5 6 7 8 10 14 17 19 21 25 26 27 30 33 34 35 36 38 41 45 48 49 51 53 55 57 60 66 67 69 70 73 76 78 79 80 81 82 83 84 87 88 90\n0 2 4 8 9 10 13 16 17 18 19 21 24 28 31 32 34 36 38 40 43 49 50 52 53 56 59 61 62 63 64 65 66 68 70 71 73 77 81 82 83 84 86 90",
"output": "NO"
},
{
"input": "45 47\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46",
"output": "YES"
},
{
"input": "45 71\n0 2 3 7 8 11 12 13 14 15 16 17 20 21 22 23 24 26 28 30 32 37 39 40 42 43 44 45 47 48 50 52 54 55 56 57 58 59 60 61 62 64 66 68 70\n0 1 2 3 4 7 8 9 10 11 13 15 17 19 24 26 28 29 30 31 32 34 35 37 39 41 42 43 44 45 46 47 48 49 51 53 55 57 58 60 61 65 66 69 70",
"output": "NO"
},
{
"input": "46 46\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45",
"output": "YES"
},
{
"input": "46 93\n0 1 2 6 13 16 17 18 19 21 27 29 32 34 37 38 39 40 41 44 45 49 50 52 54 56 57 61 64 65 66 67 69 71 73 75 77 78 79 83 85 86 88 90 91 92\n0 2 4 5 7 8 9 10 11 12 16 23 26 27 28 29 31 37 39 42 44 47 48 49 50 51 54 55 59 60 62 64 66 67 71 74 75 76 77 79 81 83 85 87 88 89",
"output": "NO"
},
{
"input": "47 49\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 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\n0 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 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",
"output": "YES"
},
{
"input": "47 94\n0 1 3 4 5 7 8 9 14 18 19 26 30 33 34 35 37 40 42 44 46 49 50 51 52 53 55 56 60 61 62 63 64 65 66 69 71 73 75 79 84 86 87 88 90 92 93\n1 2 3 4 6 7 8 10 11 12 17 21 22 29 33 36 37 38 40 43 45 48 49 52 53 54 55 56 58 59 63 64 65 66 67 68 69 72 74 76 78 82 87 89 90 91 93",
"output": "NO"
},
{
"input": "48 65\n0 1 2 4 5 6 7 8 9 10 11 12 15 16 17 20 21 24 25 26 27 28 30 32 33 34 35 37 38 39 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 61 62 63\n0 1 4 6 8 9 10 11 12 14 16 17 18 19 21 22 23 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 45 46 47 49 50 51 53 54 55 56 57 58 59 60 61 64",
"output": "NO"
},
{
"input": "48 90\n1 3 4 5 8 9 11 13 14 15 16 17 20 21 24 26 29 30 31 33 34 36 37 38 39 40 42 43 44 46 47 48 51 52 55 58 59 61 62 63 65 66 68 78 79 81 82 89\n0 3 4 6 8 9 10 11 13 15 16 19 21 24 25 26 28 29 31 32 33 34 35 37 38 39 41 42 43 46 47 50 53 54 56 57 58 60 61 63 73 74 76 77 84 86 88 89",
"output": "NO"
},
{
"input": "49 60\n0 1 2 5 7 8 9 10 11 12 13 14 15 16 17 18 20 21 23 25 26 27 28 29 30 31 32 33 34 36 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 58 59\n0 1 2 3 4 5 6 7 8 10 11 12 14 16 17 18 19 20 21 22 23 24 25 27 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 46 49 50 51 52 53 56 58 59",
"output": "NO"
},
{
"input": "49 97\n0 1 2 3 5 8 11 14 19 23 26 29 32 34 35 37 39 41 43 44 45 46 51 53 63 64 65 66 67 70 71 72 73 76 77 78 79 81 83 84 86 87 90 91 92 93 94 95 96\n0 3 4 5 6 7 8 9 10 11 12 13 16 18 21 24 29 33 36 39 42 44 45 47 49 51 53 54 55 56 61 63 73 74 75 76 77 80 81 82 83 86 87 88 89 91 93 94 96",
"output": "NO"
},
{
"input": "50 58\n0 1 2 3 5 6 7 8 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 50 54 55 56 57\n0 1 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 31 32 36 37 38 39 40 41 42 43 45 46 47 48 50 51 52 53 54 55 56 57",
"output": "NO"
},
{
"input": "5 10\n0 1 3 5 7\n0 1 2 4 7",
"output": "NO"
},
{
"input": "5 8\n0 2 4 6 7\n0 2 3 5 7",
"output": "NO"
}
] | 1,486,745,520 | 2,147,483,647 | Python 3 | OK | TESTS | 134 | 93 | 4,608,000 | n,l = map(int,input().split())
kefa = list(map(int,input().split()))
sasha = list(map(int,input().split()))
diff1 = [kefa[i+1] - kefa[i] if i != n - 1 else l - kefa[-1] + kefa[0] for i in range(n) ]
diff2 = [sasha[i+1] - sasha[i] if i != n - 1 else l - sasha[-1] + sasha[0] for i in range(n) ]
def rotation(pos):
for i in range(n):
if diff2[(i+pos)%n] != diff1[i]:
return False
return True
for i in range(n):
if(rotation(i)):
print("YES")
exit()
print("NO")
| Title: Dasha and friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length *L*, in distinct points of which there are *n* barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track.
Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the *n* barriers. Thus, each of them wrote *n* integers in the ascending order, each of them was between 0 and *L*<=-<=1, inclusively.
There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks.
Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above.
Input Specification:
The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=50, *n*<=≤<=*L*<=≤<=100) — the number of barriers on a track and its length.
The second line contains *n* distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to *L*<=-<=1 inclusively.
The second line contains *n* distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to *L*<=-<=1 inclusively.
Output Specification:
Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes).
Demo Input:
['3 8\n2 4 6\n1 5 7\n', '4 9\n2 3 5 8\n0 1 3 6\n', '2 4\n1 3\n1 2\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
The first test is analyzed in the statement. | ```python
n,l = map(int,input().split())
kefa = list(map(int,input().split()))
sasha = list(map(int,input().split()))
diff1 = [kefa[i+1] - kefa[i] if i != n - 1 else l - kefa[-1] + kefa[0] for i in range(n) ]
diff2 = [sasha[i+1] - sasha[i] if i != n - 1 else l - sasha[-1] + sasha[0] for i in range(n) ]
def rotation(pos):
for i in range(n):
if diff2[(i+pos)%n] != diff1[i]:
return False
return True
for i in range(n):
if(rotation(i)):
print("YES")
exit()
print("NO")
``` | 3 |
|
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,495,622,660 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | iwannabethebest = ["jolteon", "flareon", "umbreon", "leafeon", "glaceon", "sylveon"]
n, s = int(input()), str(input())
if n != 7:
print("vaporeon" if n == 8 else "espeon")
else:
for pikachu in iwannabethebest:
testforthebest = True
for i in range(n):
if s[i] != '.' and s[i] != pikachu[i]:
testforthebest = False
if testforthebest:
print(pikachu)
break | 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
iwannabethebest = ["jolteon", "flareon", "umbreon", "leafeon", "glaceon", "sylveon"]
n, s = int(input()), str(input())
if n != 7:
print("vaporeon" if n == 8 else "espeon")
else:
for pikachu in iwannabethebest:
testforthebest = True
for i in range(n):
if s[i] != '.' and s[i] != pikachu[i]:
testforthebest = False
if testforthebest:
print(pikachu)
break
``` | 3 |
|
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task. | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using *k* colors, you can output any of them. | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 "
},
{
"input": "105",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 "
},
{
"input": "123",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "452",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "641",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "293",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "733",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "10",
"output": "2\n1 1 2 1 2 1 2 2 2 1 "
},
{
"input": "287",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "3202",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "728",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "3509",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "5137",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "2023",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "4890",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "8507",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1796",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "3466",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1098",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "11226",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "11731",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "11644",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "14553",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "17307",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "23189",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "6818",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1054",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "28163",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "30885",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "27673",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "11656",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "36325",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "31205",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "29958",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1696",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "44907",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "13736",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "29594",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "19283",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "15346",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "41794",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "99998",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "100000",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "100000",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "99971",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
}
] | 1,579,690,902 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 639 | 5,120,000 | N = 1000010
p=[1]*N
for i in range(2, N):
if 1 == p[i]:
for j in range(i * i, N, i):
p[j] = 2
n = int(input())
ans = p[2:n+2]
print(len(set(ans)))
print(*ans)
| Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input Specification:
The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces.
Output Specification:
The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using *k* colors, you can output any of them.
Demo Input:
['3\n', '4\n']
Demo Output:
['2\n1 1 2 ', '2\n2 1 1 2\n']
Note:
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | ```python
N = 1000010
p=[1]*N
for i in range(2, N):
if 1 == p[i]:
for j in range(i * i, N, i):
p[j] = 2
n = int(input())
ans = p[2:n+2]
print(len(set(ans)))
print(*ans)
``` | 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,595,652,889 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 310 | 21,401,600 | import sys
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
n=iinput()
a=list(map(int,input().split()))
m=iinput()
b=list(map(int,input().split()))
k=[]
for i in range(n):
for j in range(m):
l = b[j]/a[i]
if l%1==0:
k.append(l)
l=max(k)
c=k.count(l)
print(c)
| 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
import sys
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
n=iinput()
a=list(map(int,input().split()))
m=iinput()
b=list(map(int,input().split()))
k=[]
for i in range(n):
for j in range(m):
l = b[j]/a[i]
if l%1==0:
k.append(l)
l=max(k)
c=k.count(l)
print(c)
``` | 3 |
|
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,666,727,240 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 154 | 0 | t = int(input())
print(0, end = " ")
print(0, end = " ")
print(t, end = " ") | 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
t = int(input())
print(0, end = " ")
print(0, end = " ")
print(t, end = " ")
``` | 3 |
|
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal".
Note that the first and last seats are not adjacent (if $n \ne 2$). | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n0101001010101001010010010101001010100101001001001010010101010010101001001010101001001001010100101010",
"output": "Yes"
},
{
"input": "4\n0100",
"output": "No"
},
{
"input": "42\n011000100101001001101011011010100010011010",
"output": "No"
},
{
"input": "3\n001",
"output": "No"
},
{
"input": "64\n1001001010010010100101010010010100100101001001001001010100101001",
"output": "Yes"
},
{
"input": "3\n111",
"output": "No"
},
{
"input": "4\n0000",
"output": "No"
},
{
"input": "4\n0001",
"output": "No"
},
{
"input": "4\n0010",
"output": "No"
},
{
"input": "4\n0011",
"output": "No"
},
{
"input": "4\n0101",
"output": "Yes"
},
{
"input": "4\n0110",
"output": "No"
},
{
"input": "4\n0111",
"output": "No"
},
{
"input": "4\n1000",
"output": "No"
},
{
"input": "4\n1001",
"output": "Yes"
},
{
"input": "4\n1010",
"output": "Yes"
},
{
"input": "4\n1100",
"output": "No"
},
{
"input": "4\n1101",
"output": "No"
},
{
"input": "4\n1110",
"output": "No"
},
{
"input": "4\n1111",
"output": "No"
},
{
"input": "2\n00",
"output": "No"
},
{
"input": "2\n01",
"output": "Yes"
},
{
"input": "2\n10",
"output": "Yes"
},
{
"input": "2\n11",
"output": "No"
},
{
"input": "3\n000",
"output": "No"
},
{
"input": "3\n010",
"output": "Yes"
},
{
"input": "3\n011",
"output": "No"
},
{
"input": "3\n100",
"output": "No"
},
{
"input": "3\n110",
"output": "No"
},
{
"input": "100\n0111001010101110001100000010011000100101110010001100111110101110001110101010111000010010011000000110",
"output": "No"
},
{
"input": "357\n100101010010010010010100101001001010101010100100100100101001010101001010010100101001010100101001010010100100101001010101010101001001010100101010010100101001010100100100101010010010010100101010010010101001010010010101001001010010010101010100100101010010100100101001010100101001010100101001010010010010100101001010100100100100100100100101010101010010010100101",
"output": "Yes"
},
{
"input": "459\n000111000101010000100001001010111110011011010001100101111010111011101110111101111101100101100011011001100110001001111001101000111001011100110100011111011111000010000110010011100110011011111110011100001101001111000100111011001000001011111100110100001001001100101011100001110110100101011011110100100111101011000101110000100110100100010000000100001001111111000011101010010011001111010111001100000100111001010111011010000011000011100101101011101000011011000110011",
"output": "No"
},
{
"input": "3\n001",
"output": "No"
},
{
"input": "4\n0010",
"output": "No"
},
{
"input": "3\n111",
"output": "No"
},
{
"input": "4\n0110",
"output": "No"
},
{
"input": "2\n11",
"output": "No"
},
{
"input": "2\n10",
"output": "Yes"
},
{
"input": "2\n01",
"output": "Yes"
},
{
"input": "4\n1101",
"output": "No"
},
{
"input": "2\n00",
"output": "No"
},
{
"input": "4\n1111",
"output": "No"
},
{
"input": "15\n000010101010000",
"output": "No"
},
{
"input": "8\n10010100",
"output": "No"
},
{
"input": "5\n00100",
"output": "No"
},
{
"input": "6\n100100",
"output": "No"
},
{
"input": "7\n1000001",
"output": "No"
},
{
"input": "98\n10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "Yes"
}
] | 1,610,610,388 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
s=input()
if n % 2 == 0 and s.count("1") == n // 2 and "11" not in s:
print("Yes)
elif n % 2 == 1 and s.count("1") == n // 2 + 1 and "11" not in s:
print("Yes)
else:
print("No) | Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal".
Note that the first and last seats are not adjacent (if $n \ne 2$).
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating.
Output Specification:
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
Demo Input:
['3\n101\n', '4\n1011\n', '5\n10001\n']
Demo Output:
['Yes\n', 'No\n', 'No\n']
Note:
In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | ```python
n=int(input())
s=input()
if n % 2 == 0 and s.count("1") == n // 2 and "11" not in s:
print("Yes)
elif n % 2 == 1 and s.count("1") == n // 2 + 1 and "11" not in s:
print("Yes)
else:
print("No)
``` | -1 |
|
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task! | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
"input": "rxxxrrxrxxxxxrrrrrxxxxrrrrxrxxrxxrxrxrrrxrrxrrxrxxxrxrrxrrxrxrxxxxxrxxxxrrrxrxxrxxrxxxrrrrrxrrxrrxrr",
"output": "rxaxraxrxaxaxrararxaxararaxrxarxarxrxrarxraxraxrxaxrxraxraxrxrxaxaxrxaxararxrxarxarxaxrararxraxraxra"
},
{
"input": "aazz",
"output": "baza"
},
{
"input": "zz",
"output": "za"
},
{
"input": "gg",
"output": "ga"
},
{
"input": "qasdasd",
"output": "qasdasd"
},
{
"input": "aa",
"output": "ba"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "zza",
"output": "zba"
},
{
"input": "g",
"output": "g"
},
{
"input": "nnop",
"output": "naop"
},
{
"input": "xx",
"output": "xa"
}
] | 1,615,765,274 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 234 | 2,662,400 | def next_char(ch):
return chr(ord(ch) + 1 - 26 * (ord(ch) + 1 > ord('z')))
def change(x, L, R):
nxt = next_char(x[L])
if R < len(x) and (R - L) % 2 == 0 and x[R] == nxt:
nxt = next_char(nxt)
x[L + 1: R:2] = [nxt] * ((R - L) // 2)
def solution(s):
x = list(s)
idx = 1
while idx < len(x):
if x[idx] == x[idx - 1]:
L = idx - 1
while idx < len(x) and x[idx] == x[L]:
idx += 1
change(x, L, idx)
idx += 1
return ''.join(x)
s = input()
print(solution(s)) | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task!
Input Specification:
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters.
Output Specification:
Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters.
Demo Input:
['aab\n', 'caaab\n', 'zscoder\n']
Demo Output:
['bab\n', 'cabab\n', 'zscoder\n']
Note:
none | ```python
def next_char(ch):
return chr(ord(ch) + 1 - 26 * (ord(ch) + 1 > ord('z')))
def change(x, L, R):
nxt = next_char(x[L])
if R < len(x) and (R - L) % 2 == 0 and x[R] == nxt:
nxt = next_char(nxt)
x[L + 1: R:2] = [nxt] * ((R - L) // 2)
def solution(s):
x = list(s)
idx = 1
while idx < len(x):
if x[idx] == x[idx - 1]:
L = idx - 1
while idx < len(x) and x[idx] == x[L]:
idx += 1
change(x, L, idx)
idx += 1
return ''.join(x)
s = input()
print(solution(s))
``` | 3 |
|
295 | A | Greg and Array | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array.
Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg. | The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), (0<=≤<=*d**i*<=≤<=105).
Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*).
The numbers in the lines are separated by single spaces. | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | 500 | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1",
"output": "0"
}
] | 1,649,120,466 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 10 | 764 | 268,390,400 | from operator import add, sub
def read_input():
return [int(i) for i in input().split(" ")]
n, m, k = read_input()
arr = read_input()
operations = [read_input() for _ in range(m)]
queries = [read_input() for _ in range(k)]
seg_table = [[0 for _ in range(n)]]
def apply_op(op, arr):
a = arr.copy()
for idx in range(op[0]-1,op[1]):
a[idx] += op[2]
return a
for op in operations:
seg_table.append(apply_op(op, seg_table[-1]))
def elemAdd(a,b):
return list(map(add,a,b))
def elemSub(a,b):
return list(map(sub,a,b))
ans = arr
for query in queries:
if query[0] == 1:
ans = elemAdd(seg_table[query[1]], ans)
else:
diff = elemSub(seg_table[query[1]], seg_table[query[0] - 1])
ans = elemAdd(diff, ans)
print(" ".join([str(i) for i in ans])) | Title: Greg and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array.
Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg.
Input Specification:
The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), (0<=≤<=*d**i*<=≤<=105).
Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*).
The numbers in the lines are separated by single spaces.
Output Specification:
On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Demo Input:
['3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n', '1 1 1\n1\n1 1 1\n1 1\n', '4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n']
Demo Output:
['9 18 17\n', '2\n', '5 18 31 20\n']
Note:
none | ```python
from operator import add, sub
def read_input():
return [int(i) for i in input().split(" ")]
n, m, k = read_input()
arr = read_input()
operations = [read_input() for _ in range(m)]
queries = [read_input() for _ in range(k)]
seg_table = [[0 for _ in range(n)]]
def apply_op(op, arr):
a = arr.copy()
for idx in range(op[0]-1,op[1]):
a[idx] += op[2]
return a
for op in operations:
seg_table.append(apply_op(op, seg_table[-1]))
def elemAdd(a,b):
return list(map(add,a,b))
def elemSub(a,b):
return list(map(sub,a,b))
ans = arr
for query in queries:
if query[0] == 1:
ans = elemAdd(seg_table[query[1]], ans)
else:
diff = elemSub(seg_table[query[1]], seg_table[query[0] - 1])
ans = elemAdd(diff, ans)
print(" ".join([str(i) for i in ans]))
``` | 0 |
|
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
},
{
"input": "8",
"output": "1641"
},
{
"input": "9",
"output": "4920"
},
{
"input": "10",
"output": "14763"
},
{
"input": "15",
"output": "3587226"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "100",
"output": "721510432"
},
{
"input": "300",
"output": "327873818"
},
{
"input": "900",
"output": "295068084"
},
{
"input": "1500",
"output": "451187545"
},
{
"input": "3000",
"output": "645417275"
},
{
"input": "5000",
"output": "755610910"
},
{
"input": "10000",
"output": "723907367"
},
{
"input": "50000",
"output": "969527595"
},
{
"input": "90000",
"output": "548978368"
},
{
"input": "99999",
"output": "909741855"
},
{
"input": "100000",
"output": "729225554"
},
{
"input": "300000",
"output": "93822635"
},
{
"input": "800000",
"output": "178940616"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "4000000",
"output": "882155933"
},
{
"input": "9000000",
"output": "295060537"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "9999998",
"output": "576926295"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "31",
"output": "347990060"
}
] | 1,696,583,841 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 0 | MOD = 1000000007
n = int(input())
# Initialize a 2D array dp with 2 rows and 4 columns
dp = [[0] * 4 for _ in range(2)]
# Initialize the base case: the ant starts at vertex D (index 3)
dp[0][3] = 1
for step in range(1, n + 1):
# Calculate the next state using the previous state
for current_vertex in range(4):
dp[step % 2][current_vertex] = 0 # Initialize the next state
for previous_vertex in range(4):
if previous_vertex != current_vertex:
dp[step % 2][current_vertex] += dp[(step - 1) % 2][previous_vertex]
dp[step % 2][current_vertex] %= MOD
# The answer is in the last row (n % 2) and the D vertex (index 3)
print(dp[n % 2][3])
| Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Output Specification:
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '21\n']
Note:
The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | ```python
MOD = 1000000007
n = int(input())
# Initialize a 2D array dp with 2 rows and 4 columns
dp = [[0] * 4 for _ in range(2)]
# Initialize the base case: the ant starts at vertex D (index 3)
dp[0][3] = 1
for step in range(1, n + 1):
# Calculate the next state using the previous state
for current_vertex in range(4):
dp[step % 2][current_vertex] = 0 # Initialize the next state
for previous_vertex in range(4):
if previous_vertex != current_vertex:
dp[step % 2][current_vertex] += dp[(step - 1) % 2][previous_vertex]
dp[step % 2][current_vertex] %= MOD
# The answer is in the last row (n % 2) and the D vertex (index 3)
print(dp[n % 2][3])
``` | 0 |
|
656 | D | Rosetta Problem | PROGRAMMING | 2,100 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=≤<=*a*<=≤<=1<=000<=000). | Output a single integer. | [
"129\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "129",
"output": "1"
},
{
"input": "0",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "6",
"output": "0"
},
{
"input": "16",
"output": "0"
},
{
"input": "299593",
"output": "7"
},
{
"input": "398929",
"output": "4"
},
{
"input": "860076",
"output": "1"
},
{
"input": "262144",
"output": "1"
},
{
"input": "1000000",
"output": "2"
},
{
"input": "266305",
"output": "4"
},
{
"input": "456910",
"output": "2"
},
{
"input": "953086",
"output": "0"
},
{
"input": "23982",
"output": "0"
},
{
"input": "9852",
"output": "1"
},
{
"input": "569",
"output": "2"
},
{
"input": "11249",
"output": "1"
},
{
"input": "73",
"output": "3"
},
{
"input": "2122",
"output": "2"
},
{
"input": "6218",
"output": "3"
},
{
"input": "33345",
"output": "4"
},
{
"input": "42705",
"output": "2"
},
{
"input": "121",
"output": "2"
},
{
"input": "67",
"output": "1"
},
{
"input": "3593",
"output": "2"
}
] | 1,459,808,085 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 4,812,800 | n = int(input())
ans = 0
while n>0:
if n % 8 == 1:
ans += 1
n /= 8
print(ans)
| Title: Rosetta Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=1<=000<=000).
Output Specification:
Output a single integer.
Demo Input:
['129\n']
Demo Output:
['1\n']
Note:
none | ```python
n = int(input())
ans = 0
while n>0:
if n % 8 == 1:
ans += 1
n /= 8
print(ans)
``` | 0 |
||
624 | A | Save Luke | PROGRAMMING | 800 | [
"math"
] | null | null | Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive. | The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=<<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively. | Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"2 6 2 2\n",
"1 9 1 2\n"
] | [
"1.00000000000000000000\n",
"2.66666666666666650000\n"
] | In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.
In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time. | 500 | [
{
"input": "2 6 2 2",
"output": "1.00000000000000000000"
},
{
"input": "1 9 1 2",
"output": "2.66666666666666650000"
},
{
"input": "1 10000 1 1",
"output": "4999.50000000000000000000"
},
{
"input": "9999 10000 10000 10000",
"output": "0.00005000000000000000"
},
{
"input": "1023 2340 1029 3021",
"output": "0.32518518518518519000"
},
{
"input": "2173 2176 10000 9989",
"output": "0.00015008254539996998"
},
{
"input": "1 2 123 1",
"output": "0.00806451612903225780"
},
{
"input": "123 1242 12 312",
"output": "3.45370370370370370000"
},
{
"input": "2 9997 3 12",
"output": "666.33333333333337000000"
},
{
"input": "1 10000 10000 10000",
"output": "0.49995000000000001000"
},
{
"input": "3274 4728 888 4578",
"output": "0.26600804976216613000"
},
{
"input": "4600 9696 5634 8248",
"output": "0.36709407866301685000"
},
{
"input": "2255 7902 8891 429",
"output": "0.60590128755364803000"
},
{
"input": "6745 9881 2149 9907",
"output": "0.26011944260119441000"
},
{
"input": "4400 8021 6895 2089",
"output": "0.40304986642920748000"
},
{
"input": "5726 9082 7448 3054",
"output": "0.31955817939440107000"
},
{
"input": "3381 9769 4898 2532",
"output": "0.85975773889636609000"
},
{
"input": "1036 6259 5451 4713",
"output": "0.51387249114521838000"
},
{
"input": "5526 6455 197 4191",
"output": "0.21171376481312670000"
},
{
"input": "1196 4082 4071 9971",
"output": "0.20552627830793335000"
},
{
"input": "8850 9921 8816 9449",
"output": "0.05863673692855187600"
},
{
"input": "3341 7299 2074 8927",
"output": "0.35978547404781386000"
},
{
"input": "7831 8609 6820 2596",
"output": "0.08262531860662701600"
},
{
"input": "2322 7212 77 4778",
"output": "1.00720906282183310000"
},
{
"input": "9976 9996 4823 4255",
"output": "0.00220312844238819110"
},
{
"input": "7631 9769 5377 6437",
"output": "0.18097172845776197000"
},
{
"input": "8957 9525 8634 107",
"output": "0.06498112344125385500"
},
{
"input": "6612 9565 3380 2288",
"output": "0.52099505998588569000"
},
{
"input": "1103 6256 3934 9062",
"output": "0.39650661742074483000"
},
{
"input": "1854 3280 1481 2140",
"output": "0.39381386357359843000"
}
] | 1,454,607,574 | 2,074 | Python 3 | OK | TESTS | 30 | 62 | 0 | d,l,v1,v2=[int(i) for i in input().split()]
time=(l-d)/(v1+v2)
print(time)
| Title: Save Luke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.
Input Specification:
The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=<<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.
Output Specification:
Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['2 6 2 2\n', '1 9 1 2\n']
Demo Output:
['1.00000000000000000000\n', '2.66666666666666650000\n']
Note:
In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.
In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time. | ```python
d,l,v1,v2=[int(i) for i in input().split()]
time=(l-d)/(v1+v2)
print(time)
``` | 3 |
|
818 | B | Permutation Game | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | *n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it.
The game consists of *m* steps. On each step the current leader with index *i* counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.
You are given numbers *l*1,<=*l*2,<=...,<=*l**m* — indices of leaders in the beginning of each step. Child with number *l*1 is the first leader in the game.
Write a program which will restore a possible permutation *a*1,<=*a*2,<=...,<=*a**n*. If there are multiple solutions then print any of them. If there is no solution then print -1. | The first line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains *m* integer numbers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*) — indices of leaders in the beginning of each step. | Print such permutation of *n* numbers *a*1,<=*a*2,<=...,<=*a**n* that leaders in the game will be exactly *l*1,<=*l*2,<=...,<=*l**m* if all the rules are followed. If there are multiple solutions print any of them.
If there is no permutation which satisfies all described conditions print -1. | [
"4 5\n2 3 1 4 4\n",
"3 3\n3 1 2\n"
] | [
"3 1 2 4 \n",
"-1\n"
] | Let's follow leadership in the first example:
- Child 2 starts. - Leadership goes from 2 to 2 + *a*<sub class="lower-index">2</sub> = 3. - Leadership goes from 3 to 3 + *a*<sub class="lower-index">3</sub> = 5. As it's greater than 4, it's going in a circle to 1. - Leadership goes from 1 to 1 + *a*<sub class="lower-index">1</sub> = 4. - Leadership goes from 4 to 4 + *a*<sub class="lower-index">4</sub> = 8. Thus in circle it still remains at 4. | 0 | [
{
"input": "4 5\n2 3 1 4 4",
"output": "3 1 2 4 "
},
{
"input": "3 3\n3 1 2",
"output": "-1"
},
{
"input": "1 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": "1 "
},
{
"input": "6 8\n2 5 4 2 5 4 2 5",
"output": "1 3 2 4 5 6 "
},
{
"input": "100 1\n6",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "10 5\n7 7 9 9 3",
"output": "-1"
},
{
"input": "10 20\n10 1 5 7 1 2 5 3 6 3 9 4 3 4 9 6 8 4 9 6",
"output": "-1"
},
{
"input": "20 15\n11 19 1 8 17 12 3 1 8 17 12 3 1 8 17",
"output": "7 1 18 3 4 5 6 9 10 12 8 11 13 14 16 17 15 19 2 20 "
},
{
"input": "100 100\n96 73 23 74 35 44 75 13 62 50 76 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63",
"output": "1 2 3 4 5 6 7 8 10 11 12 13 49 14 15 17 18 19 20 21 22 23 51 39 24 25 27 28 16 29 30 32 33 34 9 35 36 37 40 41 42 43 44 31 79 45 46 47 48 26 52 53 54 55 56 57 58 59 60 62 63 88 66 64 65 67 68 69 70 71 72 73 50 61 38 87 74 75 76 78 80 81 82 83 84 85 86 89 90 91 92 93 94 95 96 77 97 98 99 100 "
},
{
"input": "100 100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "-1"
},
{
"input": "20 20\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11",
"output": "19 17 15 13 11 9 7 5 3 1 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "20 5\n1 20 2 19 3",
"output": "19 17 1 3 5 6 7 8 9 10 11 12 13 14 15 16 18 20 4 2 "
},
{
"input": "19 19\n1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10",
"output": "-1"
},
{
"input": "100 100\n1 99 2 98 3 97 4 96 5 95 6 94 7 93 8 92 9 91 10 90 11 89 12 88 13 87 14 86 15 85 16 84 17 83 18 82 19 81 20 80 21 79 22 78 23 77 24 76 25 75 26 74 27 73 28 72 29 71 30 70 31 69 32 68 33 67 34 66 35 65 36 64 37 63 38 62 39 61 40 60 41 59 42 58 43 57 44 56 45 55 46 54 47 53 48 52 49 51 50 50",
"output": "98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 100 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 "
},
{
"input": "51 18\n8 32 24 19 1 29 49 24 39 33 5 37 37 26 17 28 2 19",
"output": "-1"
},
{
"input": "5 5\n1 2 5 2 4",
"output": "-1"
},
{
"input": "6 6\n1 2 1 1 3 6",
"output": "-1"
},
{
"input": "4 4\n4 3 4 2",
"output": "-1"
},
{
"input": "3 3\n2 2 3",
"output": "-1"
},
{
"input": "4 6\n1 1 2 4 4 4",
"output": "-1"
},
{
"input": "9 4\n8 2 8 3",
"output": "-1"
},
{
"input": "4 6\n2 3 1 4 4 1",
"output": "-1"
},
{
"input": "2 3\n1 1 2",
"output": "-1"
},
{
"input": "5 7\n4 3 4 3 3 4 5",
"output": "-1"
},
{
"input": "2 9\n1 1 1 1 2 1 1 1 1",
"output": "-1"
},
{
"input": "4 4\n2 4 4 4",
"output": "1 2 3 4 "
},
{
"input": "3 3\n1 1 3",
"output": "-1"
},
{
"input": "2 5\n1 2 2 1 1",
"output": "-1"
},
{
"input": "4 4\n1 4 1 3",
"output": "-1"
},
{
"input": "3 4\n1 3 1 1",
"output": "-1"
},
{
"input": "4 4\n1 4 1 1",
"output": "-1"
},
{
"input": "66 67\n19 9 60 40 19 48 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5",
"output": "-1"
},
{
"input": "3 3\n3 3 2",
"output": "-1"
},
{
"input": "27 28\n8 18 27 24 20 8 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23",
"output": "-1"
},
{
"input": "4 3\n1 1 2",
"output": "-1"
},
{
"input": "4 4\n2 4 2 3",
"output": "-1"
},
{
"input": "2 3\n2 2 1",
"output": "-1"
},
{
"input": "2 2\n2 2",
"output": "1 2 "
},
{
"input": "3 4\n2 3 3 1",
"output": "-1"
},
{
"input": "5 6\n1 4 4 2 1 4",
"output": "-1"
},
{
"input": "4 3\n2 3 4",
"output": "-1"
},
{
"input": "2 3\n1 2 1",
"output": "-1"
},
{
"input": "10 4\n5 6 5 7",
"output": "-1"
},
{
"input": "3 3\n1 1 2",
"output": "-1"
},
{
"input": "4 5\n1 4 1 3 2",
"output": "-1"
},
{
"input": "6 5\n1 2 4 1 3",
"output": "-1"
}
] | 1,498,754,151 | 5,451 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 23,142,400 | n, m = map(int, input().split())
a = list(map(int, input().split()))
used = [False for _ in range(n + 1)]
ans = [0 for _ in range(n)]
f = True
for i in range(min(n, m - 1)):
d = (a[i + 1] - a[i] + n) % n
if used[d] or 0 < ans[a[i] - 1]:
f = False
break
ans[a[i] - 1] = d
used[d] = True
j = 1
for i in range(n):
while j < n and used[j]:
j += 1
if ans[i] == 0:
ans[i] = j
used[j] = True
idx = a[0] - 1
for i in range(m):
if idx + 1 != a[i]:
f = False
break
idx += ans[idx]
idx %= n
if f:
print(' '.join(list(map(str, ans))))
else:
print(-1)
| Title: Permutation Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it.
The game consists of *m* steps. On each step the current leader with index *i* counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.
You are given numbers *l*1,<=*l*2,<=...,<=*l**m* — indices of leaders in the beginning of each step. Child with number *l*1 is the first leader in the game.
Write a program which will restore a possible permutation *a*1,<=*a*2,<=...,<=*a**n*. If there are multiple solutions then print any of them. If there is no solution then print -1.
Input Specification:
The first line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains *m* integer numbers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*) — indices of leaders in the beginning of each step.
Output Specification:
Print such permutation of *n* numbers *a*1,<=*a*2,<=...,<=*a**n* that leaders in the game will be exactly *l*1,<=*l*2,<=...,<=*l**m* if all the rules are followed. If there are multiple solutions print any of them.
If there is no permutation which satisfies all described conditions print -1.
Demo Input:
['4 5\n2 3 1 4 4\n', '3 3\n3 1 2\n']
Demo Output:
['3 1 2 4 \n', '-1\n']
Note:
Let's follow leadership in the first example:
- Child 2 starts. - Leadership goes from 2 to 2 + *a*<sub class="lower-index">2</sub> = 3. - Leadership goes from 3 to 3 + *a*<sub class="lower-index">3</sub> = 5. As it's greater than 4, it's going in a circle to 1. - Leadership goes from 1 to 1 + *a*<sub class="lower-index">1</sub> = 4. - Leadership goes from 4 to 4 + *a*<sub class="lower-index">4</sub> = 8. Thus in circle it still remains at 4. | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
used = [False for _ in range(n + 1)]
ans = [0 for _ in range(n)]
f = True
for i in range(min(n, m - 1)):
d = (a[i + 1] - a[i] + n) % n
if used[d] or 0 < ans[a[i] - 1]:
f = False
break
ans[a[i] - 1] = d
used[d] = True
j = 1
for i in range(n):
while j < n and used[j]:
j += 1
if ans[i] == 0:
ans[i] = j
used[j] = True
idx = a[0] - 1
for i in range(m):
if idx + 1 != a[i]:
f = False
break
idx += ans[idx]
idx %= n
if f:
print(' '.join(list(map(str, ans))))
else:
print(-1)
``` | 0 |
|
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
"output": "1\n1 "
},
{
"input": "2\nBB",
"output": "1\n2 "
},
{
"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB",
"output": "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 "
},
{
"input": "1\nW",
"output": "0"
},
{
"input": "2\nWW",
"output": "0"
},
{
"input": "2\nWB",
"output": "1\n1 "
},
{
"input": "2\nBW",
"output": "1\n1 "
},
{
"input": "3\nBBB",
"output": "1\n3 "
},
{
"input": "3\nBWB",
"output": "2\n1 1 "
},
{
"input": "3\nWBB",
"output": "1\n2 "
},
{
"input": "3\nWWB",
"output": "1\n1 "
},
{
"input": "3\nWBW",
"output": "1\n1 "
},
{
"input": "3\nBWW",
"output": "1\n1 "
},
{
"input": "3\nWWW",
"output": "0"
},
{
"input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB",
"output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 "
},
{
"input": "5\nBBBWB",
"output": "2\n3 1 "
},
{
"input": "5\nBWWWB",
"output": "2\n1 1 "
},
{
"input": "5\nWWWWB",
"output": "1\n1 "
},
{
"input": "5\nBWWWW",
"output": "1\n1 "
},
{
"input": "5\nBBBWW",
"output": "1\n3 "
},
{
"input": "5\nWWBBB",
"output": "1\n3 "
},
{
"input": "10\nBBBBBWWBBB",
"output": "2\n5 3 "
},
{
"input": "10\nBBBBWBBWBB",
"output": "3\n4 2 2 "
},
{
"input": "20\nBBBBBWWBWBBWBWWBWBBB",
"output": "6\n5 1 2 1 1 3 "
},
{
"input": "20\nBBBWWWWBBWWWBWBWWBBB",
"output": "5\n3 2 1 1 3 "
},
{
"input": "20\nBBBBBBBBWBBBWBWBWBBB",
"output": "5\n8 3 1 1 3 "
},
{
"input": "20\nBBBWBWBWWWBBWWWWBWBB",
"output": "6\n3 1 1 2 1 2 "
},
{
"input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB",
"output": "5\n6 1 1 1 12 "
},
{
"input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB",
"output": "9\n5 1 2 1 1 4 1 1 8 "
},
{
"input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB",
"output": "7\n11 1 1 8 1 1 6 "
},
{
"input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW",
"output": "9\n5 1 1 1 1 2 2 1 1 "
},
{
"input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB",
"output": "6\n1 1 1 1 1 5 "
},
{
"input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB",
"output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB",
"output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n100 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB",
"output": "11\n20 1 1 1 2 1 1 1 1 1 20 "
},
{
"input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB",
"output": "11\n4 1 1 1 1 2 1 1 1 1 6 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "10\nWWBWWWBWBB",
"output": "3\n1 1 2 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n17 31 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n24 42 "
},
{
"input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB",
"output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 "
},
{
"input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB",
"output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 "
},
{
"input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB",
"output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 "
},
{
"input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB",
"output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 "
},
{
"input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB",
"output": "11\n1 5 3 4 3 1 1 2 1 2 4 "
}
] | 1,664,638,303 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 15 | 62 | 0 | n = int(input())
s = input()
cnt = 0
lst = []
for i in s:
if i == 'B':
cnt += 1
else:
lst.append(cnt)
cnt = 0
if s[-1] == 'B':
lst.append(cnt)
if lst.count(0) != n:
for i in lst:
if i == 0:
lst.remove(i)
print(len(lst))
print(' '.join([str(i) for i in lst]))
elif lst.count(0) == n:
print(0)
else:
print(len(lst))
print(' '.join([str(i) for i in lst])) | Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
Output Specification:
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
Demo Input:
['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n']
Demo Output:
['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 ']
Note:
The last sample case correspond to the picture in the statement. | ```python
n = int(input())
s = input()
cnt = 0
lst = []
for i in s:
if i == 'B':
cnt += 1
else:
lst.append(cnt)
cnt = 0
if s[-1] == 'B':
lst.append(cnt)
if lst.count(0) != n:
for i in lst:
if i == 0:
lst.remove(i)
print(len(lst))
print(' '.join([str(i) for i in lst]))
elif lst.count(0) == n:
print(0)
else:
print(len(lst))
print(' '.join([str(i) for i in lst]))
``` | 0 |
|
822 | C | Hacker, pack your bags! | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"implementation",
"sortings"
] | null | null | It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly *x* days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that *n* vouchers left. *i*-th voucher is characterized by three integers *l**i*, *r**i*, *cost**i* — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the *i*-th voucher is a value *r**i*<=-<=*l**i*<=+<=1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers *i* and *j* (*i*<=≠<=*j*) so that they don't intersect, sum of their durations is exactly *x* and their total cost is as minimal as possible. Two vouchers *i* and *j* don't intersect if only at least one of the following conditions is fulfilled: *r**i*<=<<=*l**j* or *r**j*<=<<=*l**i*.
Help Leha to choose the necessary vouchers! | The first line contains two integers *n* and *x* (2<=≤<=*n*,<=*x*<=≤<=2·105) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next *n* lines contains three integers *l**i*, *r**i* and *cost**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=2·105,<=1<=≤<=*cost**i*<=≤<=109) — description of the voucher. | Print a single integer — a minimal amount of money that Leha will spend, or print <=-<=1 if it's impossible to choose two disjoint vouchers with the total duration exactly *x*. | [
"4 5\n1 3 4\n1 2 5\n5 6 1\n1 2 4\n",
"3 2\n4 6 3\n2 4 1\n3 5 4\n"
] | [
"5\n",
"-1\n"
] | In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2. | 1,250 | [
{
"input": "4 5\n1 3 4\n1 2 5\n5 6 1\n1 2 4",
"output": "5"
},
{
"input": "3 2\n4 6 3\n2 4 1\n3 5 4",
"output": "-1"
},
{
"input": "2 1855\n159106 161198 437057705\n149039 158409 889963913",
"output": "-1"
},
{
"input": "15 17\n1 10 8\n5 19 1\n12 14 6\n9 19 8\n6 7 3\n5 11 9\n7 12 5\n17 20 8\n6 12 6\n11 19 4\n3 14 1\n15 19 10\n3 20 5\n5 19 9\n10 18 10",
"output": "11"
},
{
"input": "15 7\n16 18 6\n11 15 2\n5 17 3\n4 5 1\n3 11 5\n13 16 7\n8 11 6\n9 16 4\n7 8 3\n11 15 2\n2 8 6\n7 8 7\n10 12 2\n6 8 1\n6 15 1",
"output": "3"
},
{
"input": "15 24\n2 14 5\n7 14 4\n6 11 6\n3 5 6\n4 13 5\n10 11 4\n8 8 6\n5 14 4\n2 2 3\n9 14 5\n2 13 6\n14 14 4\n2 12 3\n3 14 5\n9 11 3",
"output": "-1"
},
{
"input": "15 12\n3 12 4\n2 8 1\n7 8 4\n10 11 3\n12 12 1\n11 12 4\n5 13 3\n7 13 1\n11 13 3\n2 5 2\n4 5 3\n2 11 4\n2 6 4\n8 9 4\n3 4 3",
"output": "5"
},
{
"input": "15 13\n4 10 3\n7 8 3\n5 7 1\n2 2 3\n1 6 2\n3 10 1\n6 9 2\n5 8 1\n6 8 2\n4 5 2\n3 5 2\n4 8 1\n4 9 1\n5 9 1\n5 10 2",
"output": "-1"
},
{
"input": "8 7\n10 10 3\n10 10 2\n6 7 2\n1 6 3\n1 3 2\n3 8 2\n4 6 3\n1 6 2",
"output": "4"
},
{
"input": "5 6\n18 20 2\n9 11 3\n4 7 3\n16 17 3\n12 14 1",
"output": "3"
},
{
"input": "3 5\n6 6 1\n2 4 2\n5 8 3",
"output": "-1"
},
{
"input": "3 3\n11 11 2\n3 4 3\n8 9 2",
"output": "4"
},
{
"input": "2 7\n3 6 1\n10 12 1",
"output": "2"
},
{
"input": "2 2\n200000 200000 1\n1 1 1000000000",
"output": "1000000001"
},
{
"input": "2 8\n1 4 2\n8 11 2",
"output": "4"
},
{
"input": "2 2\n1 1 1000000000\n2 2 1000000000",
"output": "2000000000"
},
{
"input": "2 3\n1 2 1000000000\n3 3 1000000000",
"output": "2000000000"
},
{
"input": "2 2\n1 1 500000000\n2 2 500000000",
"output": "1000000000"
},
{
"input": "2 4\n1 2 1000000000\n3 4 1000000000",
"output": "2000000000"
},
{
"input": "2 4\n1 2 500000000\n3 4 500000000",
"output": "1000000000"
},
{
"input": "2 2\n1 1 1000000000\n2 2 1000",
"output": "1000001000"
},
{
"input": "2 4\n1 2 999999999\n3 4 999999999",
"output": "1999999998"
},
{
"input": "2 2\n1 1 1000000000\n2 2 7",
"output": "1000000007"
},
{
"input": "2 4\n1 2 1\n2 3 2",
"output": "-1"
},
{
"input": "2 3\n1 1 1000000000\n2 3 73741824",
"output": "1073741824"
},
{
"input": "4 3\n1 1 2\n1 1 3\n2 3 3\n2 3 4",
"output": "5"
},
{
"input": "2 5\n1 3 50000000\n4 5 50000000",
"output": "100000000"
},
{
"input": "2 5\n1 3 1000000000\n4 5 1000000000",
"output": "2000000000"
},
{
"input": "2 2\n1 1 1\n1 1 1",
"output": "-1"
},
{
"input": "4 5\n1 3 900000000\n1 2 5\n5 6 900000000\n1 2 4",
"output": "1800000000"
},
{
"input": "2 4\n1 2 536870912\n3 4 536870912",
"output": "1073741824"
},
{
"input": "2 4\n1 2 500000000\n5 6 500000000",
"output": "1000000000"
},
{
"input": "2 5\n1 3 999999998\n4 5 1",
"output": "999999999"
},
{
"input": "4 3\n1 1 2\n1 1 3\n2 3 2\n1 2 3",
"output": "4"
},
{
"input": "4 5\n1 3 500000000\n1 2 500000000\n5 6 500000000\n1 2 500000000",
"output": "1000000000"
},
{
"input": "2 2\n2 2 1\n3 3 2",
"output": "3"
},
{
"input": "3 3\n3 5 2\n1 2 4\n1 3 4",
"output": "-1"
},
{
"input": "3 4\n2 3 1\n1 2 2\n3 4 2",
"output": "4"
},
{
"input": "4 5\n1 2 2\n1 2 5\n3 5 6\n3 5 8",
"output": "8"
},
{
"input": "2 4\n1 2 5\n1 3 5",
"output": "-1"
}
] | 1,699,007,355 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 614,400 | from collections import defaultdict
from itertools import accumulate
from os import path
from sys import stdin, stdout
filename = "../templates/input.txt"
if path.exists(filename):
stdin = open(filename, 'r')
def input():
return stdin.readline().rstrip()
def print(*args, sep=' ', end='\n'):
stdout.write(sep.join(map(str, args)))
stdout.write(end)
def solution():
def bsr(left: int, right: int) -> int:
"""
TTTTFFFF
|
"""
def check(mid: int) -> bool:
return r < trips[d[y][mid]][0]
while left <= right:
mid = left + (right - left) // 2
if check(mid):
left = mid + 1
else:
right = mid - 1
return left
n, x = [int(num) for num in input().split()]
INF = 10 ** 20
trips = []
for i in range(n):
trips.append([int(num) for num in input().split()])
d = defaultdict(list)
suf = defaultdict(list)
for i, (l, r, c) in enumerate(trips):
d[r - l + 1].append(i)
for y in d:
d[y].sort(key=lambda i: trips[i][0])
m = len(d[y])
suf[y] = [INF for i in range(m)]
suf[y][m - 1] = trips[d[y][m - 1]][2]
for i in range(m - 2, -1, -1):
suf[y][i] = min(suf[y][i + 1], trips[d[y][i]][2])
best = INF
for l, r, c in trips:
y = x - (r - l + 1)
if y in d:
j = bsr(0, len(d[y]) - 1)
if j < len(d[y]):
best = min(best, c + suf[y][j])
print(best if best != INF else -1)
def main():
t = 1
while t:
solution()
t -= 1
if __name__ == '__main__':
main()
| Title: Hacker, pack your bags!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly *x* days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that *n* vouchers left. *i*-th voucher is characterized by three integers *l**i*, *r**i*, *cost**i* — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the *i*-th voucher is a value *r**i*<=-<=*l**i*<=+<=1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers *i* and *j* (*i*<=≠<=*j*) so that they don't intersect, sum of their durations is exactly *x* and their total cost is as minimal as possible. Two vouchers *i* and *j* don't intersect if only at least one of the following conditions is fulfilled: *r**i*<=<<=*l**j* or *r**j*<=<<=*l**i*.
Help Leha to choose the necessary vouchers!
Input Specification:
The first line contains two integers *n* and *x* (2<=≤<=*n*,<=*x*<=≤<=2·105) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next *n* lines contains three integers *l**i*, *r**i* and *cost**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=2·105,<=1<=≤<=*cost**i*<=≤<=109) — description of the voucher.
Output Specification:
Print a single integer — a minimal amount of money that Leha will spend, or print <=-<=1 if it's impossible to choose two disjoint vouchers with the total duration exactly *x*.
Demo Input:
['4 5\n1 3 4\n1 2 5\n5 6 1\n1 2 4\n', '3 2\n4 6 3\n2 4 1\n3 5 4\n']
Demo Output:
['5\n', '-1\n']
Note:
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2. | ```python
from collections import defaultdict
from itertools import accumulate
from os import path
from sys import stdin, stdout
filename = "../templates/input.txt"
if path.exists(filename):
stdin = open(filename, 'r')
def input():
return stdin.readline().rstrip()
def print(*args, sep=' ', end='\n'):
stdout.write(sep.join(map(str, args)))
stdout.write(end)
def solution():
def bsr(left: int, right: int) -> int:
"""
TTTTFFFF
|
"""
def check(mid: int) -> bool:
return r < trips[d[y][mid]][0]
while left <= right:
mid = left + (right - left) // 2
if check(mid):
left = mid + 1
else:
right = mid - 1
return left
n, x = [int(num) for num in input().split()]
INF = 10 ** 20
trips = []
for i in range(n):
trips.append([int(num) for num in input().split()])
d = defaultdict(list)
suf = defaultdict(list)
for i, (l, r, c) in enumerate(trips):
d[r - l + 1].append(i)
for y in d:
d[y].sort(key=lambda i: trips[i][0])
m = len(d[y])
suf[y] = [INF for i in range(m)]
suf[y][m - 1] = trips[d[y][m - 1]][2]
for i in range(m - 2, -1, -1):
suf[y][i] = min(suf[y][i + 1], trips[d[y][i]][2])
best = INF
for l, r, c in trips:
y = x - (r - l + 1)
if y in d:
j = bsr(0, len(d[y]) - 1)
if j < len(d[y]):
best = min(best, c + suf[y][j])
print(best if best != INF else -1)
def main():
t = 1
while t:
solution()
t -= 1
if __name__ == '__main__':
main()
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,579,689,891 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 248 | 307,200 | def young_physicist():
v = 0
n = int(input())
while n > 0:
s = str(input())
t = [int(c) for c in s.split()]
for i in t:
v += i
n -= 1
if v == 0:
print('YES')
else:
print('NO')
if __name__ == '__main__':
young_physicist()
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
def young_physicist():
v = 0
n = int(input())
while n > 0:
s = str(input())
t = [int(c) for c in s.split()]
for i in t:
v += i
n -= 1
if v == 0:
print('YES')
else:
print('NO')
if __name__ == '__main__':
young_physicist()
``` | 0 |
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive.
Calculate the number of minutes they will be able to spend together. | The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. | Print one integer — the number of minutes Sonya and Filya will be able to spend together. | [
"1 10 9 20 1\n",
"1 100 50 200 75\n"
] | [
"2\n",
"50\n"
] | In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | 500 | [
{
"input": "1 10 9 20 1",
"output": "2"
},
{
"input": "1 100 50 200 75",
"output": "50"
},
{
"input": "6 6 5 8 9",
"output": "1"
},
{
"input": "1 1000000000 1 1000000000 1",
"output": "999999999"
},
{
"input": "5 100 8 8 8",
"output": "0"
},
{
"input": "1 1000000000000000000 2 99999999999999999 1000000000",
"output": "99999999999999997"
},
{
"input": "1 1 1 1 1",
"output": "0"
},
{
"input": "1 2 3 4 5",
"output": "0"
},
{
"input": "1 1000000000 2 999999999 3141592",
"output": "999999997"
},
{
"input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205",
"output": "0"
},
{
"input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636",
"output": "27788438422925"
},
{
"input": "11814 27385 22309 28354 23595",
"output": "5076"
},
{
"input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708",
"output": "29117730788587"
},
{
"input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082",
"output": "81604391064"
},
{
"input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178",
"output": "47247500916780901"
},
{
"input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779",
"output": "0"
},
{
"input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358",
"output": "48172141432145241"
},
{
"input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489",
"output": "99277597320376979"
},
{
"input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138",
"output": "256787461333454149"
},
{
"input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174",
"output": "37925278862451249"
},
{
"input": "1 3 3 5 3",
"output": "0"
},
{
"input": "1 5 8 10 9",
"output": "0"
},
{
"input": "1 2 4 5 10",
"output": "0"
},
{
"input": "1 2 2 3 5",
"output": "1"
},
{
"input": "2 4 3 7 3",
"output": "1"
},
{
"input": "1 2 9 10 1",
"output": "0"
},
{
"input": "5 15 1 10 5",
"output": "5"
},
{
"input": "1 4 9 20 25",
"output": "0"
},
{
"input": "2 4 1 2 5",
"output": "1"
},
{
"input": "10 1000 1 100 2",
"output": "91"
},
{
"input": "1 3 3 8 10",
"output": "1"
},
{
"input": "4 6 6 8 9",
"output": "1"
},
{
"input": "2 3 1 4 3",
"output": "1"
},
{
"input": "1 2 2 3 100",
"output": "1"
},
{
"input": "1 2 100 120 2",
"output": "0"
},
{
"input": "1 3 5 7 4",
"output": "0"
},
{
"input": "1 3 5 7 5",
"output": "0"
},
{
"input": "1 4 8 10 6",
"output": "0"
},
{
"input": "1 2 5 6 100",
"output": "0"
},
{
"input": "1 2 5 10 20",
"output": "0"
},
{
"input": "1 2 5 6 7",
"output": "0"
},
{
"input": "2 5 7 12 6",
"output": "0"
},
{
"input": "10 20 50 100 80",
"output": "0"
},
{
"input": "1 2 5 10 2",
"output": "0"
},
{
"input": "1 2 5 6 4",
"output": "0"
},
{
"input": "5 9 1 2 3",
"output": "0"
},
{
"input": "50 100 1 20 3",
"output": "0"
},
{
"input": "10 20 3 7 30",
"output": "0"
},
{
"input": "1 5 10 10 100",
"output": "0"
},
{
"input": "100 101 1 2 3",
"output": "0"
},
{
"input": "1 5 10 20 6",
"output": "0"
},
{
"input": "1 10 15 25 5",
"output": "0"
},
{
"input": "1 2 5 10 3",
"output": "0"
},
{
"input": "2 3 5 6 100",
"output": "0"
},
{
"input": "1 2 4 5 6",
"output": "0"
},
{
"input": "6 10 1 2 40",
"output": "0"
},
{
"input": "20 30 1 5 1",
"output": "0"
},
{
"input": "20 40 50 100 50",
"output": "0"
},
{
"input": "1 1 4 9 2",
"output": "0"
},
{
"input": "1 2 5 6 1",
"output": "0"
},
{
"input": "1 100 400 500 450",
"output": "0"
},
{
"input": "5 6 1 2 5",
"output": "0"
},
{
"input": "1 10 21 30 50",
"output": "0"
},
{
"input": "100 200 300 400 101",
"output": "0"
},
{
"input": "2 8 12 16 9",
"output": "0"
},
{
"input": "1 5 7 9 6",
"output": "0"
},
{
"input": "300 400 100 200 101",
"output": "0"
},
{
"input": "1 2 2 3 10",
"output": "1"
},
{
"input": "1 10 100 200 5",
"output": "0"
},
{
"input": "1 3 3 4 4",
"output": "1"
},
{
"input": "10 20 30 40 25",
"output": "0"
},
{
"input": "1 2 5 10 1",
"output": "0"
},
{
"input": "2 4 8 10 1",
"output": "0"
},
{
"input": "2 5 10 15 7",
"output": "0"
},
{
"input": "100 200 5 10 1",
"output": "0"
},
{
"input": "1 2 100 200 300",
"output": "0"
},
{
"input": "30 100 10 20 25",
"output": "0"
},
{
"input": "10 20 1 5 6",
"output": "0"
},
{
"input": "4 5 1 2 4",
"output": "0"
},
{
"input": "11 100 1 9 1000",
"output": "0"
},
{
"input": "1 1 10 10 228",
"output": "0"
},
{
"input": "5 7 10 20 15",
"output": "0"
},
{
"input": "1 3 8 9 7",
"output": "0"
},
{
"input": "1 10 2 8 8",
"output": "6"
},
{
"input": "1 5 9 15 1",
"output": "0"
},
{
"input": "1 3 5 6 12",
"output": "0"
},
{
"input": "1 100 500 1000 3",
"output": "0"
},
{
"input": "1 1 1 1 2",
"output": "1"
},
{
"input": "1 1000 100 1000 200",
"output": "900"
},
{
"input": "4 5 1 4 1",
"output": "1"
},
{
"input": "1 5 5 7 3",
"output": "1"
},
{
"input": "1 4 4 10 11",
"output": "1"
},
{
"input": "1 1 3 4 100",
"output": "0"
},
{
"input": "1 4 3 5 6",
"output": "2"
},
{
"input": "10 100 20 30 40",
"output": "11"
},
{
"input": "5 9 1 11 7",
"output": "4"
}
] | 1,595,430,205 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 6,656,000 | a,b,c,d,e=map(int,input().split())
if e>c and e<=b:
print(b-c)
else:
print(b-c+1)
| Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive.
Calculate the number of minutes they will be able to spend together.
Input Specification:
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Output Specification:
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Demo Input:
['1 10 9 20 1\n', '1 100 50 200 75\n']
Demo Output:
['2\n', '50\n']
Note:
In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | ```python
a,b,c,d,e=map(int,input().split())
if e>c and e<=b:
print(b-c)
else:
print(b-c+1)
``` | 0 |
|
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv",
"output": "NO"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "YES"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod",
"output": "NO"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl",
"output": "YES"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy",
"output": "YES"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs",
"output": "NO"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc",
"output": "YES"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd",
"output": "YES"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv",
"output": "YES"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul",
"output": "YES"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii",
"output": "NO"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq",
"output": "YES"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb",
"output": "YES"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc",
"output": "YES"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab",
"output": "YES"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia",
"output": "NO"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf",
"output": "YES"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb",
"output": "YES"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa",
"output": "NO"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo",
"output": "YES"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib",
"output": "YES"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf",
"output": "YES"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci",
"output": "YES"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn",
"output": "YES"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev",
"output": "YES"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss",
"output": "YES"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs",
"output": "NO"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc",
"output": "NO"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi",
"output": "NO"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah",
"output": "NO"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka",
"output": "YES"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq",
"output": "YES"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb",
"output": "YES"
},
{
"input": "14 5\nfssmmsfffmfmmm",
"output": "NO"
},
{
"input": "2 1\nff",
"output": "NO"
},
{
"input": "2 1\nhw",
"output": "YES"
},
{
"input": "2 2\nss",
"output": "YES"
},
{
"input": "1 1\nl",
"output": "YES"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp",
"output": "YES"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj",
"output": "YES"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj",
"output": "YES"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "YES"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq",
"output": "YES"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt",
"output": "YES"
},
{
"input": "1 2\na",
"output": "YES"
},
{
"input": "3 1\nabb",
"output": "NO"
},
{
"input": "2 1\naa",
"output": "NO"
},
{
"input": "2 1\nab",
"output": "YES"
},
{
"input": "6 2\naaaaaa",
"output": "NO"
},
{
"input": "8 4\naaaaaaaa",
"output": "NO"
},
{
"input": "4 2\naaaa",
"output": "NO"
},
{
"input": "4 3\naaaa",
"output": "NO"
},
{
"input": "1 3\na",
"output": "YES"
},
{
"input": "4 3\nzzzz",
"output": "NO"
},
{
"input": "4 1\naaaa",
"output": "NO"
},
{
"input": "3 4\nabc",
"output": "YES"
},
{
"input": "2 5\nab",
"output": "YES"
},
{
"input": "2 4\nab",
"output": "YES"
},
{
"input": "1 10\na",
"output": "YES"
},
{
"input": "5 2\nzzzzz",
"output": "NO"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO"
},
{
"input": "4 1\nabab",
"output": "NO"
},
{
"input": "4 1\nabcb",
"output": "NO"
},
{
"input": "4 2\nabbb",
"output": "NO"
},
{
"input": "5 2\nabccc",
"output": "NO"
},
{
"input": "2 3\nab",
"output": "YES"
},
{
"input": "4 3\nbbbs",
"output": "YES"
},
{
"input": "10 2\nazzzzzzzzz",
"output": "NO"
},
{
"input": "1 2\nb",
"output": "YES"
},
{
"input": "1 3\nb",
"output": "YES"
},
{
"input": "4 5\nabcd",
"output": "YES"
},
{
"input": "4 6\naabb",
"output": "YES"
},
{
"input": "5 2\naaaab",
"output": "NO"
},
{
"input": "3 5\naaa",
"output": "YES"
},
{
"input": "5 3\nazzzz",
"output": "NO"
},
{
"input": "4 100\naabb",
"output": "YES"
},
{
"input": "3 10\naaa",
"output": "YES"
},
{
"input": "3 4\naaa",
"output": "YES"
},
{
"input": "12 5\naaaaabbbbbbb",
"output": "NO"
},
{
"input": "5 2\naabbb",
"output": "NO"
},
{
"input": "10 5\nzzzzzzzzzz",
"output": "NO"
},
{
"input": "2 4\naa",
"output": "YES"
},
{
"input": "1 5\na",
"output": "YES"
},
{
"input": "10 5\naaaaaaaaaa",
"output": "NO"
},
{
"input": "6 3\naaaaaa",
"output": "NO"
},
{
"input": "7 1\nabcdeee",
"output": "NO"
},
{
"input": "18 3\naaaaaabbbbbbcccccc",
"output": "NO"
},
{
"input": "8 2\naabbccdd",
"output": "YES"
},
{
"input": "4 2\nzzzz",
"output": "NO"
},
{
"input": "4 2\nabaa",
"output": "NO"
},
{
"input": "3 2\naaa",
"output": "NO"
},
{
"input": "3 1\nzzz",
"output": "NO"
},
{
"input": "5 4\nzzzzz",
"output": "NO"
},
{
"input": "6 2\naabbbc",
"output": "NO"
},
{
"input": "3 6\naaa",
"output": "YES"
},
{
"input": "2 1\nzz",
"output": "NO"
},
{
"input": "10 3\naaaeeeeeee",
"output": "NO"
},
{
"input": "4 5\naabb",
"output": "YES"
},
{
"input": "3 1\naaa",
"output": "NO"
},
{
"input": "5 2\naazzz",
"output": "NO"
},
{
"input": "6 2\nabbbbc",
"output": "NO"
},
{
"input": "4 2\nxxxx",
"output": "NO"
},
{
"input": "6 3\nzzzzzz",
"output": "NO"
},
{
"input": "3 2\nabb",
"output": "YES"
},
{
"input": "3 2\nzzz",
"output": "NO"
},
{
"input": "6 5\nzzzzzz",
"output": "NO"
},
{
"input": "6 3\nbcaaaa",
"output": "NO"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "3 6\nabc",
"output": "YES"
}
] | 1,631,371,645 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 49 | 124 | 20,275,200 | import sys
from math import sqrt,ceil,floor,gcd
from collections import Counter
input = lambda:sys.stdin.readline()
def int_arr(): return list(map(int,input().split()))
def str_arr(): return list(map(str,input().split()))
def get_str(): return map(str,input().split())
def get_int(): return map(int,input().split())
def get_flo(): return map(float,input().split())
def lcm(a,b): return (a*b) // gcd(a,b)
mod = 1000000007
def solve(n,k,s):
if n < k:
print("NO")
return
al = [0]*26
for i in range(n):
al[ord(s[i])-97] += 1
for i in al:
if i > k:
print("NO")
return
print("YES")
# for _ in range(int(input())):
n,k = get_int()
s = str(input())[:-1]
solve(n,k,s) | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons.
Output Specification:
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Demo Input:
['4 2\naabb\n', '6 3\naacaab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | ```python
import sys
from math import sqrt,ceil,floor,gcd
from collections import Counter
input = lambda:sys.stdin.readline()
def int_arr(): return list(map(int,input().split()))
def str_arr(): return list(map(str,input().split()))
def get_str(): return map(str,input().split())
def get_int(): return map(int,input().split())
def get_flo(): return map(float,input().split())
def lcm(a,b): return (a*b) // gcd(a,b)
mod = 1000000007
def solve(n,k,s):
if n < k:
print("NO")
return
al = [0]*26
for i in range(n):
al[ord(s[i])-97] += 1
for i in al:
if i > k:
print("NO")
return
print("YES")
# for _ in range(int(input())):
n,k = get_int()
s = str(input())[:-1]
solve(n,k,s)
``` | 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,695,967,998 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 15 | 62 | 0 | k,n,w = map(int,input().split())
if (w*(w+1)//2)*k - n < 0:
print(0)
else:
print((w*(w+1)//2)*k - n) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
k,n,w = map(int,input().split())
if (w*(w+1)//2)*k - n < 0:
print(0)
else:
print((w*(w+1)//2)*k - n)
``` | 3 |
|
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 17 21 10 11 100 23 10",
"output": "1"
},
{
"input": "52\n1 12 3 11 4 5 10 6 9 7 8 2",
"output": "6"
},
{
"input": "50\n2 2 3 4 5 4 4 5 7 3 2 7",
"output": "-1"
},
{
"input": "0\n55 81 28 48 99 20 67 95 6 19 10 93",
"output": "0"
},
{
"input": "93\n85 40 93 66 92 43 61 3 64 51 90 21",
"output": "1"
},
{
"input": "99\n36 34 22 0 0 0 52 12 0 0 33 47",
"output": "2"
},
{
"input": "99\n28 32 31 0 10 35 11 18 0 0 32 28",
"output": "3"
},
{
"input": "99\n19 17 0 1 18 11 29 9 29 22 0 8",
"output": "4"
},
{
"input": "76\n2 16 11 10 12 0 20 4 4 14 11 14",
"output": "5"
},
{
"input": "41\n2 1 7 7 4 2 4 4 9 3 10 0",
"output": "6"
},
{
"input": "47\n8 2 2 4 3 1 9 4 2 7 7 8",
"output": "7"
},
{
"input": "58\n6 11 7 0 5 6 3 9 4 9 5 1",
"output": "8"
},
{
"input": "32\n5 2 4 1 5 0 5 1 4 3 0 3",
"output": "9"
},
{
"input": "31\n6 1 0 4 4 5 1 0 5 3 2 0",
"output": "9"
},
{
"input": "35\n2 3 0 0 6 3 3 4 3 5 0 6",
"output": "9"
},
{
"input": "41\n3 1 3 4 3 6 6 1 4 4 0 6",
"output": "11"
},
{
"input": "97\n0 5 3 12 10 16 22 8 21 17 21 10",
"output": "5"
},
{
"input": "100\n21 21 0 0 4 13 0 26 0 0 0 15",
"output": "6"
},
{
"input": "100\n0 0 16 5 22 0 5 0 25 0 14 13",
"output": "7"
},
{
"input": "97\n17 0 10 0 0 0 18 0 14 23 15 0",
"output": "6"
},
{
"input": "100\n0 9 0 18 7 0 0 14 33 3 0 16",
"output": "7"
},
{
"input": "95\n5 2 13 0 15 18 17 0 6 11 0 8",
"output": "9"
},
{
"input": "94\n11 13 0 9 15 8 8 16 3 7 1 3",
"output": "11"
},
{
"input": "96\n8 4 12 15 8 0 4 10 6 6 12 11",
"output": "11"
},
{
"input": "100\n5 5 3 8 6 5 0 3 3 8 1 3",
"output": "-1"
},
{
"input": "100\n1 0 0 1 1 0 1 1 1 1 2 1",
"output": "-1"
},
{
"input": "100\n6 3 2 0 4 1 2 2 2 2 1 1",
"output": "-1"
},
{
"input": "0\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "0\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "12"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 2",
"output": "12"
},
{
"input": "15\n10 1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
}
] | 1,695,637,021 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | k=int(input())
a=list(map(int,input().split()))[:12]
for i in range(12):
for j in range(12):
if a[i]>a[j]:
a[i],a[j]=a[j],a[i]
b=0
for n in range(12):
if k>0:
k-=a[n]
b+=1
else:
print(b)
break | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
Input Specification:
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
Demo Input:
['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n']
Demo Output:
['2\n', '0\n', '3\n']
Note:
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | ```python
k=int(input())
a=list(map(int,input().split()))[:12]
for i in range(12):
for j in range(12):
if a[i]>a[j]:
a[i],a[j]=a[j],a[i]
b=0
for n in range(12):
if k>0:
k-=a[n]
b+=1
else:
print(b)
break
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.
At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into *k* bacteria. After that some abnormal effects create *b* more bacteria in the test tube. Thus, if at the beginning of some second the test tube had *x* bacteria, then at the end of the second it will have *kx*<=+<=*b* bacteria.
The experiment showed that after *n* seconds there were exactly *z* bacteria and the experiment ended at this point.
For the second experiment Qwerty is going to sterilize the test tube and put there *t* bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least *z* bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment.
Help Qwerty and find the minimum number of seconds needed to get a tube with at least *z* bacteria in the second experiment. | The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly. | Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube. | [
"3 1 3 5\n",
"1 4 4 7\n",
"2 2 4 100\n"
] | [
"2",
"3",
"0"
] | none | 0 | [
{
"input": "3 1 3 5",
"output": "2"
},
{
"input": "1 4 4 7",
"output": "3"
},
{
"input": "2 2 4 100",
"output": "0"
},
{
"input": "1 2 3 100",
"output": "0"
},
{
"input": "10 10 10 123456",
"output": "6"
},
{
"input": "847 374 283 485756",
"output": "282"
},
{
"input": "37 1 283475 8347",
"output": "283473"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 1 1 1000000",
"output": "0"
},
{
"input": "1 1 1000000 1",
"output": "1000000"
},
{
"input": "1 1 1000000 1000000",
"output": "1"
},
{
"input": "1 1000000 1 1",
"output": "1"
},
{
"input": "1 1000000 1 1000000",
"output": "1"
},
{
"input": "1 1000000 1000000 1",
"output": "1000000"
},
{
"input": "1 1000000 1000000 1000000",
"output": "1000000"
},
{
"input": "1000000 1 1 1",
"output": "1"
},
{
"input": "1000000 1 1 1000000",
"output": "1"
},
{
"input": "1000000 1 1000000 1",
"output": "1000000"
},
{
"input": "1000000 1 1000000 1000000",
"output": "1000000"
},
{
"input": "1000000 1000000 1 1",
"output": "1"
},
{
"input": "1000000 1000000 1 1000000",
"output": "1"
},
{
"input": "1000000 1000000 1000000 1",
"output": "1000000"
},
{
"input": "1000000 1000000 1000000 1000000",
"output": "1000000"
},
{
"input": "1 160 748 108",
"output": "748"
},
{
"input": "1 6099 4415 2783",
"output": "4415"
},
{
"input": "1 1047 230 1199",
"output": "229"
},
{
"input": "1 82435 53193 37909",
"output": "53193"
},
{
"input": "1 96840 99008 63621",
"output": "99008"
},
{
"input": "1 250685 823830 494528",
"output": "823829"
},
{
"input": "1 421986 2348 320240",
"output": "2348"
},
{
"input": "2 8 16 397208",
"output": "1"
},
{
"input": "2 96 676 215286",
"output": "665"
},
{
"input": "2 575 321 606104",
"output": "311"
},
{
"input": "2 8048 37852 278843",
"output": "37847"
},
{
"input": "2 46658 377071 909469",
"output": "377067"
},
{
"input": "3 10 90 567680",
"output": "80"
},
{
"input": "4 4 149 609208",
"output": "141"
},
{
"input": "5 4 3204 986907",
"output": "3196"
},
{
"input": "6 5 5832 885406",
"output": "5825"
},
{
"input": "7 10 141725 219601",
"output": "141720"
},
{
"input": "38 86 441826 91486",
"output": "441824"
},
{
"input": "185 58 579474 889969",
"output": "579472"
},
{
"input": "3901 18 41607 412558",
"output": "41606"
},
{
"input": "9821 62 965712 703044",
"output": "965711"
},
{
"input": "29487 60 3239 483550",
"output": "3238"
},
{
"input": "78993 99 646044 456226",
"output": "646043"
},
{
"input": "193877 3 362586 6779",
"output": "362586"
},
{
"input": "702841 39 622448 218727",
"output": "622448"
},
{
"input": "987899 74 490126 87643",
"output": "490126"
},
{
"input": "1000000 69 296123 144040",
"output": "296123"
},
{
"input": "2 5 501022 406855",
"output": "501006"
},
{
"input": "2 2 420084 748919",
"output": "420067"
},
{
"input": "2 3 822794 574631",
"output": "822777"
},
{
"input": "2 2 968609 433047",
"output": "968592"
},
{
"input": "2 1 371319 775111",
"output": "371301"
},
{
"input": "3 2 942777 573452",
"output": "942766"
},
{
"input": "3 2 312783 882812",
"output": "312772"
},
{
"input": "3 4 715494 741228",
"output": "715483"
},
{
"input": "3 1 410364 566940",
"output": "410353"
},
{
"input": "3 2 780370 425356",
"output": "780359"
},
{
"input": "1 5 71 551204",
"output": "0"
},
{
"input": "1 10 29 409620",
"output": "0"
},
{
"input": "2 1 14 637985",
"output": "0"
},
{
"input": "2 6 73 947345",
"output": "56"
},
{
"input": "3 8 66 951518",
"output": "55"
},
{
"input": "3 3 24 293582",
"output": "14"
},
{
"input": "4 9 10 489244",
"output": "2"
},
{
"input": "4 6 16 831308",
"output": "7"
},
{
"input": "5 6 62 835481",
"output": "55"
},
{
"input": "5 2 68 144841",
"output": "61"
},
{
"input": "1 1 1000000 500000",
"output": "500001"
},
{
"input": "5 2 100 7",
"output": "99"
},
{
"input": "3 1 3 4",
"output": "2"
},
{
"input": "126480 295416 829274 421896",
"output": "829273"
},
{
"input": "999991 5 1000000 999997",
"output": "999999"
},
{
"input": "54772 1 1000000 1000000",
"output": "999999"
},
{
"input": "5 5 2 10",
"output": "1"
},
{
"input": "1 1 2 2",
"output": "1"
},
{
"input": "100000 100000 10 1000000",
"output": "9"
},
{
"input": "2 2 5 4",
"output": "4"
},
{
"input": "999997 1 100000 1000000",
"output": "99999"
},
{
"input": "5 2 100 38",
"output": "98"
},
{
"input": "1 4 1 5",
"output": "0"
},
{
"input": "1 2149 1000000 1000000",
"output": "999535"
},
{
"input": "99999 99999 10 1000000",
"output": "9"
},
{
"input": "999998 1 1000000 1000000",
"output": "999999"
},
{
"input": "1 1 10 2",
"output": "9"
},
{
"input": "1 1 100 1000",
"output": "0"
},
{
"input": "1 1 1000000 553211",
"output": "446790"
},
{
"input": "1 1 10 1",
"output": "10"
},
{
"input": "3 1 3 1",
"output": "3"
},
{
"input": "888888 2 4 999999",
"output": "3"
},
{
"input": "3 5 10 29",
"output": "8"
},
{
"input": "1 1 100 2",
"output": "99"
},
{
"input": "5 5 2 1",
"output": "2"
},
{
"input": "50000 42 1337 999999",
"output": "1336"
},
{
"input": "2 345678 908765 987654",
"output": "908764"
},
{
"input": "1 7 15 7",
"output": "15"
},
{
"input": "842717 8581 19342 851297",
"output": "19342"
},
{
"input": "5 4 1 4",
"output": "1"
},
{
"input": "2 2 5 94",
"output": "0"
},
{
"input": "2 100000 5 10",
"output": "5"
},
{
"input": "722229 410423 118215 838505",
"output": "118215"
},
{
"input": "3 1 3 13",
"output": "1"
},
{
"input": "900000 1 100 1000000",
"output": "99"
},
{
"input": "2 4 4 36",
"output": "1"
},
{
"input": "999990 1 1000000 1000000",
"output": "999999"
},
{
"input": "100000 100000 1000000 1000000",
"output": "999999"
},
{
"input": "999998 1 5 1000000",
"output": "4"
},
{
"input": "1 1 10 4",
"output": "7"
},
{
"input": "2 3 4 5",
"output": "3"
},
{
"input": "3 1 3 40",
"output": "0"
},
{
"input": "1 10 10 100",
"output": "1"
},
{
"input": "999987 123456 1000000 1",
"output": "1000000"
}
] | 1,625,754,013 | 3,913 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 9,113,600 | k,b,n,t = list(map(int, input().split()))
solz = 1
solr = t
amount = 0
for i in range(n):
solz = solz *k +b
while (solr < solz):
amount += 1
solr = solr *k + b
print(amount)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.
At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into *k* bacteria. After that some abnormal effects create *b* more bacteria in the test tube. Thus, if at the beginning of some second the test tube had *x* bacteria, then at the end of the second it will have *kx*<=+<=*b* bacteria.
The experiment showed that after *n* seconds there were exactly *z* bacteria and the experiment ended at this point.
For the second experiment Qwerty is going to sterilize the test tube and put there *t* bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least *z* bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment.
Help Qwerty and find the minimum number of seconds needed to get a tube with at least *z* bacteria in the second experiment.
Input Specification:
The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly.
Output Specification:
Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube.
Demo Input:
['3 1 3 5\n', '1 4 4 7\n', '2 2 4 100\n']
Demo Output:
['2', '3', '0']
Note:
none | ```python
k,b,n,t = list(map(int, input().split()))
solz = 1
solr = t
amount = 0
for i in range(n):
solz = solz *k +b
while (solr < solz):
amount += 1
solr = solr *k + b
print(amount)
``` | 0 |
|
383 | D | Antimatter | PROGRAMMING | 2,300 | [
"dp"
] | null | null | Iahub accidentally discovered a secret lab. He found there *n* devices ordered in a line, numbered from 1 to *n* from left to right. Each device *i* (1<=≤<=*i*<=≤<=*n*) can create either *a**i* units of matter or *a**i* units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).
You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000).
The sum *a*1<=+<=*a*2<=+<=...<=+<=*a**n* will be less than or equal to 10000. | Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109<=+<=7). | [
"4\n1 1 1 1\n"
] | [
"12\n"
] | The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "*i*+" means that the *i*-th element produces matter, and "*i*-" means that the *i*-th element produces antimatter. | 2,000 | [
{
"input": "4\n1 1 1 1",
"output": "12"
},
{
"input": "10\n16 9 9 11 10 12 9 6 10 8",
"output": "86"
},
{
"input": "50\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3",
"output": "115119382"
},
{
"input": "100\n8 3 3 7 3 6 4 6 9 4 6 5 5 5 4 3 4 2 3 5 3 6 5 3 6 5 6 6 2 6 4 5 5 4 6 4 3 2 8 5 6 6 7 4 4 9 5 6 6 3 7 1 6 2 6 5 9 3 8 6 2 6 3 2 4 4 3 5 4 7 6 5 4 6 3 5 6 8 8 6 3 7 7 1 4 6 8 6 5 3 7 8 4 7 5 3 8 5 4 4",
"output": "450259307"
},
{
"input": "250\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "533456111"
},
{
"input": "250\n6 1 4 3 3 7 4 5 3 2 4 4 2 5 4 2 1 7 6 2 4 5 3 3 4 5 3 4 5 4 6 4 6 5 3 3 1 5 4 5 3 4 2 4 2 5 1 4 3 3 3 2 6 6 4 7 2 6 5 3 3 6 5 2 1 3 3 5 2 2 3 7 3 5 6 4 7 3 5 3 4 5 5 4 11 5 1 5 3 3 3 1 4 6 4 4 5 5 5 5 2 5 5 3 2 2 5 6 10 5 4 2 5 4 2 5 5 3 4 2 5 4 3 2 4 4 2 5 4 1 5 3 9 6 4 6 3 5 4 5 3 6 7 4 5 5 3 6 2 6 3 3 4 5 6 3 3 3 5 2 4 4 4 5 4 2 5 4 6 5 3 3 6 3 1 5 6 5 4 6 2 3 4 4 5 2 1 7 4 5 5 5 2 2 7 6 1 5 3 2 7 5 8 2 2 2 3 5 2 4 4 2 2 6 4 6 3 2 8 3 4 7 3 2 7 3 5 5 3 2 2 4 5 3 4 3 5 3 5 4 3 1 2 4 7 4 2 3 3 5",
"output": "377970747"
},
{
"input": "250\n2 2 2 2 3 2 4 2 3 2 5 1 2 3 4 4 5 3 5 1 2 5 2 3 5 3 2 3 3 3 5 1 5 5 5 4 1 3 2 5 1 2 3 5 3 3 5 2 1 1 3 3 5 1 4 2 3 3 2 2 3 5 5 4 1 4 1 5 1 3 3 4 1 5 2 5 5 3 2 4 4 4 4 3 5 1 3 4 3 4 2 1 4 3 5 1 2 3 4 2 5 5 3 2 5 3 5 4 2 3 2 3 1 1 2 4 2 5 2 3 3 2 4 5 4 2 2 5 5 5 5 4 3 4 5 2 2 3 3 4 5 1 5 5 2 5 1 5 5 4 4 1 4 2 1 2 1 2 2 3 1 4 5 4 2 4 5 1 1 3 2 1 4 1 5 2 3 1 2 3 2 3 3 2 4 2 5 5 2 3 4 2 2 4 2 4 1 5 5 3 1 3 4 5 2 5 5 1 3 1 3 3 2 5 3 5 2 4 3 5 5 3 3 2 3 2 5 3 4 3 5 3 3 4 5 3 1 2 2 5 4 4 5 1 4 1 2 5 2 3",
"output": "257270797"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n1000 1000",
"output": "2"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "3\n1 2 4",
"output": "0"
},
{
"input": "3\n1 2 2",
"output": "2"
},
{
"input": "1\n1000",
"output": "0"
},
{
"input": "3\n999 999 999",
"output": "4"
}
] | 1,692,029,568 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1692029568.4273937")# 1692029568.4274104 | Title: Antimatter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub accidentally discovered a secret lab. He found there *n* devices ordered in a line, numbered from 1 to *n* from left to right. Each device *i* (1<=≤<=*i*<=≤<=*n*) can create either *a**i* units of matter or *a**i* units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).
You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000).
The sum *a*1<=+<=*a*2<=+<=...<=+<=*a**n* will be less than or equal to 10000.
Output Specification:
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109<=+<=7).
Demo Input:
['4\n1 1 1 1\n']
Demo Output:
['12\n']
Note:
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "*i*+" means that the *i*-th element produces matter, and "*i*-" means that the *i*-th element produces antimatter. | ```python
print("_RANDOM_GUESS_1692029568.4273937")# 1692029568.4274104
``` | 0 |
|
587 | A | Duff and Weight Lifting | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps. | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values. | Print the minimum number of steps in a single line. | [
"5\n1 1 2 3 3\n",
"4\n0 1 2 3\n"
] | [
"2\n",
"4\n"
] | In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two. | 500 | [
{
"input": "5\n1 1 2 3 3",
"output": "2"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "1\n120287",
"output": "1"
},
{
"input": "2\n28288 0",
"output": "2"
},
{
"input": "2\n95745 95745",
"output": "1"
},
{
"input": "13\n92 194 580495 0 10855 41704 13 96429 33 213 0 92 140599",
"output": "11"
},
{
"input": "13\n688743 688743 1975 688743 688743 688743 688743 688743 688743 0 0 688743 688743",
"output": "4"
},
{
"input": "35\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",
"output": "3"
},
{
"input": "35\n130212 3176 77075 8071 18 1369 7539 1683 80757 1847 0 1374 122 8524 4 2 21333 270264 4 9254 151921 0 1 33596 73002 54382 0 1 29233 75952 15 38892 1877 6167 4",
"output": "31"
},
{
"input": "35\n0 0 298 0 0 0 0 0 689063 65442 0 984598 2054 43668 0 369 0 2054 0 996220 0 16327 369 0 996220 0 0 0 4693 2054 348 0 118 0 0",
"output": "16"
},
{
"input": "100\n196 1681 196 0 61 93 196 196 196 196 196 0 0 96 18 1576 0 93 666463 18 93 1 1278 8939 93 196 196 1278 3 0 67416 869956 10 56489 196 745 39 783 196 8939 196 81 69634 4552 39 3 14 20 25 8 10 4 7302 0 19579 20 1140 15990 7302 0 19579 4142 11 1354 75252 93 311 1278 0 79475 10 75252 93 7302 0 81 408441 19579 10 39 19 37748 4364 31135 47700 105818 47700 10 4142 543356 3 30647 45917 60714 8939 18 22925 7302 93 75252",
"output": "59"
}
] | 1,468,342,902 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | def power_of_two(a):
return True
def main():
n = int(input())
w = list(map(int, input().split()))
flag = True
while flag:
flag = False
for i in range(1, len(w)):
if w[i-1] == w[i]:
w[i] *= 2
del w[i-1]
flag = True
break
print(len(w))
if __name__ == '__main__':
main()
| Title: Duff and Weight Lifting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input Specification:
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values.
Output Specification:
Print the minimum number of steps in a single line.
Demo Input:
['5\n1 1 2 3 3\n', '4\n0 1 2 3\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two. | ```python
def power_of_two(a):
return True
def main():
n = int(input())
w = list(map(int, input().split()))
flag = True
while flag:
flag = False
for i in range(1, len(w)):
if w[i-1] == w[i]:
w[i] *= 2
del w[i-1]
flag = True
break
print(len(w))
if __name__ == '__main__':
main()
``` | 0 |
|
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose? | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_". | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B. | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
{
"input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a",
"output": "C"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.aaaaaa\nB.aaa\nC.aaa\nD.aaa",
"output": "A"
},
{
"input": "A.aaa\nB.aaaaaa\nC.aaaaaa\nD.aaaaaa",
"output": "A"
},
{
"input": "A.a\nB.b\nC.c\nD.d",
"output": "C"
},
{
"input": "A._\nB.__\nC.____\nD.________",
"output": "C"
},
{
"input": "A.____\nB.________\nC.________\nD._______",
"output": "C"
},
{
"input": "A.h\nB.asdf\nC.asqw\nD.qwertasdfg",
"output": "C"
},
{
"input": "A.aa\nB.aaaaa\nC.aaaaaa\nD.aaaaaaaaaaaaa",
"output": "C"
},
{
"input": "A.ccc\nB.ccccccc\nC.ccc\nD.c",
"output": "C"
},
{
"input": "A.c\nB.ccc\nC.cccccccccccccccccc\nD.cccccc",
"output": "C"
},
{
"input": "A.aa\nB.bb\nC.cc\nD.ddd",
"output": "C"
},
{
"input": "A.QW\nB.WERT\nC.QWER\nD.QWERTYUI",
"output": "C"
}
] | 1,679,636,206 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 |
from sys import stdin
input=lambda :stdin.readline()[:-1]
def solve():
a=input()
b=input()
c=input()
d=input()
la,lb,lc,ld=len(a[2:]),len(b[2:]),len(c[2:]),len(d[2:])
l=[la,lb,lc,ld]
d={
0:"A",
1:"B",
2:"C",
3:"D"
}
c,ans=0,0
ll=[]
for i in range(4):
for j in range(4):
if l[i]>=2*l[j] or l[i]<=(l[j]/2):
c+=1
if c==3:
ans+=1
ll.append(l.index(l[i]))
c=0
else:
c=0
if ans==1:
print(d[ll[0]])
else:
print("C")
solve() | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose?
Input Specification:
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
Output Specification:
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
Demo Input:
['A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n', 'A.ab\nB.abcde\nC.ab\nD.abc\n', 'A.c\nB.cc\nC.c\nD.c\n']
Demo Output:
['D\n', 'C\n', 'B\n']
Note:
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B. | ```python
from sys import stdin
input=lambda :stdin.readline()[:-1]
def solve():
a=input()
b=input()
c=input()
d=input()
la,lb,lc,ld=len(a[2:]),len(b[2:]),len(c[2:]),len(d[2:])
l=[la,lb,lc,ld]
d={
0:"A",
1:"B",
2:"C",
3:"D"
}
c,ans=0,0
ll=[]
for i in range(4):
for j in range(4):
if l[i]>=2*l[j] or l[i]<=(l[j]/2):
c+=1
if c==3:
ans+=1
ll.append(l.index(l[i]))
c=0
else:
c=0
if ans==1:
print(d[ll[0]])
else:
print("C")
solve()
``` | 0 |
|
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"output": "YES"
},
{
"input": "1\n999993399999",
"output": "NO"
},
{
"input": "9\n111 121 131 111 121 131 111 121 131",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "1\n10",
"output": "NO"
},
{
"input": "1\n976197352729",
"output": "NO"
},
{
"input": "1\n1000000000000",
"output": "NO"
},
{
"input": "1\n9",
"output": "YES"
},
{
"input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n223092870 6469693230 200560490130",
"output": "NO\nNO\nNO"
},
{
"input": "2\n81 25",
"output": "NO\nYES"
},
{
"input": "1\n16",
"output": "NO"
},
{
"input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81",
"output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "1\n225",
"output": "NO"
},
{
"input": "1\n1521",
"output": "NO"
},
{
"input": "1\n81",
"output": "NO"
}
] | 1,699,333,122 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 35 | 2,000 | 14,336,000 | import math
def is_t_prime(n):
if n < 4:
return False
sqrt_n = int(math.sqrt(n))
if sqrt_n * sqrt_n == n:
for i in range(2, int(math.sqrt(sqrt_n)) + 1):
if sqrt_n % i == 0:
return False
return True
return False
n = int(input())
values = list(map(int, input().split()))
for x in values:
if is_t_prime(x):
print("YES")
else:
print("NO")
| Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
Input Specification:
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
Demo Input:
['3\n4 5 6\n']
Demo Output:
['YES\nNO\nNO\n']
Note:
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | ```python
import math
def is_t_prime(n):
if n < 4:
return False
sqrt_n = int(math.sqrt(n))
if sqrt_n * sqrt_n == n:
for i in range(2, int(math.sqrt(sqrt_n)) + 1):
if sqrt_n % i == 0:
return False
return True
return False
n = int(input())
values = list(map(int, input().split()))
for x in values:
if is_t_prime(x):
print("YES")
else:
print("NO")
``` | 0 |
|
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan. | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*. | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"input": "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77",
"output": "87"
},
{
"input": "100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93",
"output": "84"
},
{
"input": "6 100\n10 9 8 7 6 5",
"output": "0"
},
{
"input": "100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46",
"output": "78"
},
{
"input": "100 100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44",
"output": "0"
},
{
"input": "43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62",
"output": "4"
},
{
"input": "12 64\n14 87 40 24 32 36 4 41 38 77 68 71",
"output": "0"
},
{
"input": "75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1",
"output": "0"
},
{
"input": "59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27",
"output": "63"
},
{
"input": "86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22",
"output": "38"
},
{
"input": "37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83",
"output": "91"
},
{
"input": "19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14",
"output": "79"
},
{
"input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24",
"output": "91"
},
{
"input": "67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49",
"output": "83"
},
{
"input": "96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70",
"output": "94"
},
{
"input": "14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42",
"output": "43"
},
{
"input": "12 0\n100 1 100 2 100 3 100 4 100 5 100 0",
"output": "100"
},
{
"input": "3 1\n1 2 3",
"output": "0"
},
{
"input": "3 2\n3 3 3",
"output": "0"
},
{
"input": "3 3\n3 2 1",
"output": "0"
},
{
"input": "3 100\n1 2 3",
"output": "0"
},
{
"input": "2 100\n0 0",
"output": "0"
},
{
"input": "2 90\n10 5",
"output": "0"
},
{
"input": "2 5\n5 4",
"output": "0"
},
{
"input": "3 1\n19 20 1",
"output": "18"
},
{
"input": "5 1\n5 10 7 4 20",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "0"
}
] | 1,608,632,465 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 307,200 | n,c=map(int,input().split())
x=list(map(int,input().split()))
a=[]
for i in range(len(x)):
if c==0:
d=0
a.append(d)
break
elif i==len(x)-1:
d=x[-2]-x[-1]-c
a.append(d)
else:
d=x[i]-x[i+1]-c
a.append((d))
print(max(a))
| Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
Input Specification:
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['5 1\n5 10 7 3 20\n', '6 2\n100 1 10 40 10 40\n', '3 0\n1 2 3\n']
Demo Output:
['3\n', '97\n', '0\n']
Note:
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | ```python
n,c=map(int,input().split())
x=list(map(int,input().split()))
a=[]
for i in range(len(x)):
if c==0:
d=0
a.append(d)
break
elif i==len(x)-1:
d=x[-2]-x[-1]-c
a.append(d)
else:
d=x[i]-x[i+1]-c
a.append((d))
print(max(a))
``` | 0 |
|
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win. | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output": "NO"
},
{
"input": "253308697183523656 25332878317796706",
"output": "YES"
},
{
"input": "669038685745448997 501718093668307460",
"output": "YES"
},
{
"input": "116453141993601660 87060381463547965",
"output": "YES"
},
{
"input": "766959657 370931668",
"output": "NO"
},
{
"input": "255787422422806632 146884995820359999",
"output": "YES"
},
{
"input": "502007866464507926 71266379084204128",
"output": "YES"
},
{
"input": "257439908778973480 64157133126869976",
"output": "NO"
},
{
"input": "232709385 91708542",
"output": "NO"
},
{
"input": "252482458300407528 89907711721009125",
"output": "NO"
},
{
"input": "6 2",
"output": "YES"
},
{
"input": "6 3",
"output": "NO"
},
{
"input": "6 4",
"output": "YES"
},
{
"input": "6 5",
"output": "YES"
},
{
"input": "6 6",
"output": "YES"
},
{
"input": "258266151957056904 30153168463725364",
"output": "NO"
},
{
"input": "83504367885565783 52285355047292458",
"output": "YES"
},
{
"input": "545668929424440387 508692735816921376",
"output": "YES"
},
{
"input": "547321411485639939 36665750286082900",
"output": "NO"
},
{
"input": "548973893546839491 183137237979822911",
"output": "NO"
},
{
"input": "544068082 193116851",
"output": "NO"
},
{
"input": "871412474 749817171",
"output": "YES"
},
{
"input": "999999999 1247",
"output": "NO"
},
{
"input": "851941088 712987048",
"output": "YES"
},
{
"input": "559922900 418944886",
"output": "YES"
},
{
"input": "293908937 37520518",
"output": "YES"
},
{
"input": "650075786 130049650",
"output": "NO"
},
{
"input": "1000000000 1000000000",
"output": "YES"
},
{
"input": "548147654663723363 107422751713800746",
"output": "YES"
},
{
"input": "828159210 131819483",
"output": "NO"
},
{
"input": "6242634 4110365",
"output": "YES"
},
{
"input": "458601973 245084155",
"output": "YES"
},
{
"input": "349593257 18089089",
"output": "YES"
},
{
"input": "814768821 312514745",
"output": "NO"
},
{
"input": "697884949 626323363",
"output": "YES"
},
{
"input": "667011589 54866795",
"output": "NO"
},
{
"input": "1000000000000000000 2",
"output": "NO"
},
{
"input": "1000000000000000000 3",
"output": "YES"
},
{
"input": "1000000000000000000 4",
"output": "NO"
},
{
"input": "999999999999999 1",
"output": "YES"
},
{
"input": "17 4",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
},
{
"input": "1000000000000000 2",
"output": "NO"
},
{
"input": "12 4",
"output": "YES"
},
{
"input": "6 1",
"output": "NO"
},
{
"input": "2 1",
"output": "NO"
},
{
"input": "10000000005 1",
"output": "YES"
},
{
"input": "10000000000000009 2",
"output": "NO"
},
{
"input": "12457895452123 1",
"output": "YES"
},
{
"input": "999999999999999999 9",
"output": "YES"
},
{
"input": "1000000000000 3",
"output": "YES"
},
{
"input": "13099714659575475 6549849616514894",
"output": "NO"
},
{
"input": "100000000000000001 1",
"output": "YES"
},
{
"input": "825175814723458 324",
"output": "YES"
},
{
"input": "20 4",
"output": "YES"
},
{
"input": "100000176877 4",
"output": "YES"
},
{
"input": "100000 3",
"output": "YES"
},
{
"input": "946744073709551614 10",
"output": "YES"
}
] | 1,614,101,203 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = int(input())
b = int(input())
if n=1 or (a-b) % 2 == 1:
print("YES")
else:
print("NO") | Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
Output Specification:
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower).
Demo Input:
['1 1\n', '10 4\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win. | ```python
a = int(input())
b = int(input())
if n=1 or (a-b) % 2 == 1:
print("YES")
else:
print("NO")
``` | -1 |
|
283 | D | Cows and Cool Sequences | PROGRAMMING | 2,400 | [
"dp",
"math",
"number theory"
] | null | null | Bessie and the cows have recently been playing with "cool" sequences and are trying to construct some. Unfortunately they are bad at arithmetic, so they need your help!
A pair (*x*,<=*y*) of positive integers is "cool" if *x* can be expressed as the sum of *y* consecutive integers (not necessarily positive). A sequence (*a*1,<=*a*2,<=...,<=*a**n*) is "cool" if the pairs (*a*1,<=*a*2),<=(*a*2,<=*a*3),<=...,<=(*a**n*<=-<=1,<=*a**n*) are all cool.
The cows have a sequence of *n* positive integers, *a*1,<=*a*2,<=...,<=*a**n*. In one move, they may replace some *a**i* with any other positive integer (there are no other limits on the new value of *a**i*). Determine the smallest number of moves needed to make the resulting sequence cool. | The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=5000). The next line contains *n* space-separated integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1015).
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | A single integer, the minimum number of *a**i* that must be changed to make the sequence cool. | [
"3\n6 4 1\n",
"4\n20 6 3 4\n"
] | [
"0\n",
"2\n"
] | In the first sample, the sequence is already cool, so we don't need to change any elements. In the second sample, we can change *a*<sub class="lower-index">2</sub> to 5 and *a*<sub class="lower-index">3</sub> to 10 to make (20, 5, 10, 4) which is cool. This changes 2 elements. | 2,000 | [] | 1,693,387,349 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 2,867,200 | #From Jasnah bobb31
#From Jasnah bobb31
#From Jasnah bobb31
import sys
def solve():
N = int(sys.stdin.readline())
arr = [0] * 5003
dinpr = [0] * 5003
ct = [0] * 5003
dinpr[0] = 0
for i, num in enumerate(map(int, sys.stdin.readline().split()), start=1):
arr[i] = num
while arr[i] % 2 == 0:
arr[i] //= 2
ct[i] += 1
N += 1
arr[N] = 1
for i in range(1, N + 1):
dinpr[i] = i
for j in range(1, i):
if arr[j] % arr[i] == 0 and (ct[i] - ct[j] == i - j or ct[i] <= i - j - 1):
dinpr[i] = min(dinpr[i], dinpr[j] + i - j - 1)
return dinpr[N] - 1
print(solve()) | Title: Cows and Cool Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bessie and the cows have recently been playing with "cool" sequences and are trying to construct some. Unfortunately they are bad at arithmetic, so they need your help!
A pair (*x*,<=*y*) of positive integers is "cool" if *x* can be expressed as the sum of *y* consecutive integers (not necessarily positive). A sequence (*a*1,<=*a*2,<=...,<=*a**n*) is "cool" if the pairs (*a*1,<=*a*2),<=(*a*2,<=*a*3),<=...,<=(*a**n*<=-<=1,<=*a**n*) are all cool.
The cows have a sequence of *n* positive integers, *a*1,<=*a*2,<=...,<=*a**n*. In one move, they may replace some *a**i* with any other positive integer (there are no other limits on the new value of *a**i*). Determine the smallest number of moves needed to make the resulting sequence cool.
Input Specification:
The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=5000). The next line contains *n* space-separated integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1015).
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
A single integer, the minimum number of *a**i* that must be changed to make the sequence cool.
Demo Input:
['3\n6 4 1\n', '4\n20 6 3 4\n']
Demo Output:
['0\n', '2\n']
Note:
In the first sample, the sequence is already cool, so we don't need to change any elements. In the second sample, we can change *a*<sub class="lower-index">2</sub> to 5 and *a*<sub class="lower-index">3</sub> to 10 to make (20, 5, 10, 4) which is cool. This changes 2 elements. | ```python
#From Jasnah bobb31
#From Jasnah bobb31
#From Jasnah bobb31
import sys
def solve():
N = int(sys.stdin.readline())
arr = [0] * 5003
dinpr = [0] * 5003
ct = [0] * 5003
dinpr[0] = 0
for i, num in enumerate(map(int, sys.stdin.readline().split()), start=1):
arr[i] = num
while arr[i] % 2 == 0:
arr[i] //= 2
ct[i] += 1
N += 1
arr[N] = 1
for i in range(1, N + 1):
dinpr[i] = i
for j in range(1, i):
if arr[j] % arr[i] == 0 and (ct[i] - ct[j] == i - j or ct[i] <= i - j - 1):
dinpr[i] = min(dinpr[i], dinpr[j] + i - j - 1)
return dinpr[N] - 1
print(solve())
``` | 0 |
|
883 | M | Quadcopter Competition | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1).
Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside.
What is the minimal length of the quadcopter path? | The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag.
It is guaranteed that the quadcopter starting point and the flag do not coincide. | Print the length of minimal path of the quadcopter to surround the flag and return back. | [
"1 5\n5 2\n",
"0 1\n0 0\n"
] | [
"18\n",
"8\n"
] | none | 0 | [
{
"input": "1 5\n5 2",
"output": "18"
},
{
"input": "0 1\n0 0",
"output": "8"
},
{
"input": "-100 -100\n100 100",
"output": "804"
},
{
"input": "-100 -100\n-100 100",
"output": "406"
},
{
"input": "-100 -100\n100 -100",
"output": "406"
},
{
"input": "100 -100\n-100 -100",
"output": "406"
},
{
"input": "100 -100\n-100 100",
"output": "804"
},
{
"input": "100 -100\n100 100",
"output": "406"
},
{
"input": "-100 100\n-100 -100",
"output": "406"
},
{
"input": "-100 100\n100 -100",
"output": "804"
},
{
"input": "-100 100\n100 100",
"output": "406"
},
{
"input": "100 100\n-100 -100",
"output": "804"
},
{
"input": "100 100\n-100 100",
"output": "406"
},
{
"input": "100 100\n100 -100",
"output": "406"
},
{
"input": "45 -43\n45 -44",
"output": "8"
},
{
"input": "76 76\n75 75",
"output": "8"
},
{
"input": "-34 -56\n-35 -56",
"output": "8"
},
{
"input": "56 -7\n55 -6",
"output": "8"
},
{
"input": "43 -11\n43 -10",
"output": "8"
},
{
"input": "1 -3\n2 -2",
"output": "8"
},
{
"input": "55 71\n56 71",
"output": "8"
},
{
"input": "54 -87\n55 -88",
"output": "8"
},
{
"input": "22 98\n100 33",
"output": "290"
},
{
"input": "37 84\n-83 5",
"output": "402"
},
{
"input": "52 74\n-73 -39",
"output": "480"
},
{
"input": "66 51\n51 -71",
"output": "278"
},
{
"input": "-31 44\n73 86",
"output": "296"
},
{
"input": "-20 34\n-9 55",
"output": "68"
},
{
"input": "-5 19\n-91 -86",
"output": "386"
},
{
"input": "-82 5\n28 -17",
"output": "268"
},
{
"input": "-90 -100\n55 48",
"output": "590"
},
{
"input": "-75 -14\n-32 8",
"output": "134"
},
{
"input": "-53 -28\n-13 -28",
"output": "86"
},
{
"input": "-42 -46\n10 -64",
"output": "144"
},
{
"input": "55 -42\n25 2",
"output": "152"
},
{
"input": "70 -64\n-54 70",
"output": "520"
},
{
"input": "93 -78\n-32 -75",
"output": "260"
},
{
"input": "8 -93\n79 -6",
"output": "320"
},
{
"input": "50 43\n54 10",
"output": "78"
},
{
"input": "65 32\n-37 71",
"output": "286"
},
{
"input": "80 18\n-15 -58",
"output": "346"
},
{
"input": "94 92\n4 -1",
"output": "370"
},
{
"input": "-10 96\n27 64",
"output": "142"
},
{
"input": "-96 78\n-56 32",
"output": "176"
},
{
"input": "-81 64\n-37 -8",
"output": "236"
},
{
"input": "-58 49\n74 -40",
"output": "446"
},
{
"input": "-62 -55\n1 18",
"output": "276"
},
{
"input": "-51 -69\n-78 86",
"output": "368"
},
{
"input": "-29 -80\n-56 -47",
"output": "124"
},
{
"input": "-14 -94\n55 -90",
"output": "150"
},
{
"input": "83 -2\n82 83",
"output": "176"
},
{
"input": "98 -16\n-96 40",
"output": "504"
},
{
"input": "17 -34\n-86 -93",
"output": "328"
},
{
"input": "32 -48\n33 -37",
"output": "28"
},
{
"input": "74 87\n3 92",
"output": "156"
},
{
"input": "89 73\n-80 49",
"output": "390"
},
{
"input": "4 58\n-61 -80",
"output": "410"
},
{
"input": "15 48\n50 -20",
"output": "210"
},
{
"input": "-82 45\n81 46",
"output": "332"
},
{
"input": "-68 26\n-2 6",
"output": "176"
},
{
"input": "-53 4\n-92 -31",
"output": "152"
},
{
"input": "-30 94\n31 -58",
"output": "430"
},
{
"input": "-38 -11\n58 99",
"output": "416"
},
{
"input": "-27 -25\n-28 68",
"output": "192"
},
{
"input": "-5 -39\n-10 -77",
"output": "90"
},
{
"input": "-90 -54\n9 -9",
"output": "292"
},
{
"input": "7 -57\n28 61",
"output": "282"
},
{
"input": "18 -67\n-51 21",
"output": "318"
},
{
"input": "41 -82\n-33 -15",
"output": "286"
},
{
"input": "56 -8\n91 -55",
"output": "168"
},
{
"input": "-23 -13\n-24 -12",
"output": "8"
},
{
"input": "1 32\n1 33",
"output": "8"
},
{
"input": "25 76\n24 76",
"output": "8"
},
{
"input": "-29 -78\n-28 -79",
"output": "8"
},
{
"input": "-77 19\n-76 19",
"output": "8"
},
{
"input": "-53 63\n-53 62",
"output": "8"
},
{
"input": "86 12\n86 11",
"output": "8"
},
{
"input": "14 56\n13 56",
"output": "8"
},
{
"input": "63 41\n62 40",
"output": "8"
},
{
"input": "0 -4\n1 -4",
"output": "8"
},
{
"input": "24 41\n24 42",
"output": "8"
},
{
"input": "48 85\n49 86",
"output": "8"
},
{
"input": "0 0\n0 1",
"output": "8"
},
{
"input": "0 0\n1 0",
"output": "8"
},
{
"input": "0 0\n1 1",
"output": "8"
},
{
"input": "0 1\n0 0",
"output": "8"
},
{
"input": "0 1\n1 0",
"output": "8"
},
{
"input": "0 1\n1 1",
"output": "8"
},
{
"input": "1 0\n0 0",
"output": "8"
},
{
"input": "1 0\n0 1",
"output": "8"
},
{
"input": "1 0\n1 1",
"output": "8"
},
{
"input": "1 1\n0 0",
"output": "8"
},
{
"input": "1 1\n0 1",
"output": "8"
},
{
"input": "1 1\n1 0",
"output": "8"
},
{
"input": "100 100\n99 -100",
"output": "406"
},
{
"input": "100 100\n-100 99",
"output": "406"
},
{
"input": "-100 -100\n-99 100",
"output": "406"
},
{
"input": "-100 -100\n100 -99",
"output": "406"
},
{
"input": "0 0\n1 2",
"output": "10"
},
{
"input": "0 0\n2 1",
"output": "10"
}
] | 1,660,928,060 | 2,147,483,647 | PyPy 3 | OK | TESTS | 100 | 93 | 0 | x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
if y1==y2:
print(2*(2+abs(x2-x1)+1))
elif x1==x2:
print(2*(2+abs(y2-y1)+1))
elif y2<y1:
if x2>x1:
x2+=1
y2-=1
print(2*(abs(x2-x1)+abs(y2-y1)))
else:
y2-=1
x2-=1
print(2*(abs(x2-x1)+abs(y2-y1)))
else:
if x2>x1:
x2+=1
y2+=1
print(2*(abs(x2-x1)+abs(y2-y1)))
else:
y2+=1
x2-=1
print(2*(abs(x2-x1)+abs(y2-y1)))
| Title: Quadcopter Competition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1).
Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside.
What is the minimal length of the quadcopter path?
Input Specification:
The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag.
It is guaranteed that the quadcopter starting point and the flag do not coincide.
Output Specification:
Print the length of minimal path of the quadcopter to surround the flag and return back.
Demo Input:
['1 5\n5 2\n', '0 1\n0 0\n']
Demo Output:
['18\n', '8\n']
Note:
none | ```python
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
if y1==y2:
print(2*(2+abs(x2-x1)+1))
elif x1==x2:
print(2*(2+abs(y2-y1)+1))
elif y2<y1:
if x2>x1:
x2+=1
y2-=1
print(2*(abs(x2-x1)+abs(y2-y1)))
else:
y2-=1
x2-=1
print(2*(abs(x2-x1)+abs(y2-y1)))
else:
if x2>x1:
x2+=1
y2+=1
print(2*(abs(x2-x1)+abs(y2-y1)))
else:
y2+=1
x2-=1
print(2*(abs(x2-x1)+abs(y2-y1)))
``` | 3 |
|
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time? | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$. | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible. | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
},
{
"input": "6 7 5 8",
"output": "-1"
},
{
"input": "6 7 5 9",
"output": "1"
},
{
"input": "6 7 5 7",
"output": "-1"
},
{
"input": "50 50 1 100",
"output": "1"
},
{
"input": "8 3 2 12",
"output": "3"
},
{
"input": "10 19 6 25",
"output": "2"
},
{
"input": "1 0 0 99",
"output": "98"
},
{
"input": "0 1 0 98",
"output": "97"
},
{
"input": "1 1 0 97",
"output": "95"
},
{
"input": "1 1 1 96",
"output": "95"
},
{
"input": "0 0 0 0",
"output": "-1"
},
{
"input": "100 0 0 0",
"output": "-1"
},
{
"input": "0 100 0 0",
"output": "-1"
},
{
"input": "100 100 0 0",
"output": "-1"
},
{
"input": "0 0 100 0",
"output": "-1"
},
{
"input": "100 0 100 0",
"output": "-1"
},
{
"input": "0 100 100 0",
"output": "-1"
},
{
"input": "100 100 100 0",
"output": "-1"
},
{
"input": "0 0 0 100",
"output": "100"
},
{
"input": "100 0 0 100",
"output": "-1"
},
{
"input": "0 100 0 100",
"output": "-1"
},
{
"input": "100 100 0 100",
"output": "-1"
},
{
"input": "0 0 100 100",
"output": "-1"
},
{
"input": "100 0 100 100",
"output": "-1"
},
{
"input": "0 100 100 100",
"output": "-1"
},
{
"input": "100 100 100 100",
"output": "-1"
},
{
"input": "10 45 7 52",
"output": "4"
},
{
"input": "38 1 1 68",
"output": "30"
},
{
"input": "8 45 2 67",
"output": "16"
},
{
"input": "36 36 18 65",
"output": "11"
},
{
"input": "10 30 8 59",
"output": "27"
},
{
"input": "38 20 12 49",
"output": "3"
},
{
"input": "8 19 4 38",
"output": "15"
},
{
"input": "36 21 17 72",
"output": "32"
},
{
"input": "14 12 12 89",
"output": "75"
},
{
"input": "38 6 1 44",
"output": "1"
},
{
"input": "13 4 6 82",
"output": "-1"
},
{
"input": "5 3 17 56",
"output": "-1"
},
{
"input": "38 5 29 90",
"output": "-1"
},
{
"input": "22 36 18 55",
"output": "15"
},
{
"input": "13 0 19 75",
"output": "-1"
},
{
"input": "62 65 10 89",
"output": "-1"
},
{
"input": "2 29 31 72",
"output": "-1"
},
{
"input": "1 31 19 55",
"output": "-1"
},
{
"input": "1 25 28 88",
"output": "-1"
},
{
"input": "34 32 28 33",
"output": "-1"
},
{
"input": "43 36 1 100",
"output": "22"
},
{
"input": "16 39 55 70",
"output": "-1"
},
{
"input": "2 3 0 91",
"output": "86"
},
{
"input": "55 29 12 48",
"output": "-1"
},
{
"input": "7 33 20 88",
"output": "-1"
},
{
"input": "40 38 27 99",
"output": "48"
},
{
"input": "18 28 14 84",
"output": "52"
},
{
"input": "34 25 25 92",
"output": "58"
},
{
"input": "4 24 5 76",
"output": "-1"
},
{
"input": "5 22 16 96",
"output": "-1"
},
{
"input": "1 1 0 4",
"output": "2"
},
{
"input": "5 5 3 1",
"output": "-1"
},
{
"input": "0 0 0 1",
"output": "1"
},
{
"input": "2 3 0 8",
"output": "3"
},
{
"input": "5 5 2 5",
"output": "-1"
},
{
"input": "1 2 1 3",
"output": "1"
},
{
"input": "3 0 0 4",
"output": "1"
},
{
"input": "0 0 0 5",
"output": "5"
},
{
"input": "5 5 0 3",
"output": "-1"
},
{
"input": "5 6 1 7",
"output": "-1"
},
{
"input": "10 10 10 11",
"output": "1"
},
{
"input": "0 0 0 10",
"output": "10"
},
{
"input": "5 15 5 30",
"output": "15"
},
{
"input": "3 2 0 7",
"output": "2"
}
] | 1,606,210,904 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 0 | a,b,c,n = map(int,input().split())
if n+c-a-b >0:
print(n+c-a-b)
else:
print(-1) | Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input Specification:
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
Output Specification:
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.
Demo Input:
['10 10 5 20\n', '2 2 0 4\n', '2 2 2 1\n']
Demo Output:
['5', '-1', '-1']
Note:
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible. | ```python
a,b,c,n = map(int,input().split())
if n+c-a-b >0:
print(n+c-a-b)
else:
print(-1)
``` | 0 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,656,588,361 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | input()
l = input().split(" ")
c = 0
c2 = 0
d = 0
d2 = 0
for i in l:
if int(i) % 2==0:
c +=1
d = i
else:
c2 +=1
d2 = i
if c == 1:
print(d)
else:
print(d2) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
input()
l = input().split(" ")
c = 0
c2 = 0
d = 0
d2 = 0
for i in l:
if int(i) % 2==0:
c +=1
d = i
else:
c2 +=1
d2 = i
if c == 1:
print(d)
else:
print(d2)
``` | 0 |
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once. | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once. | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "169"
},
{
"input": "50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "1 1\na",
"output": "1"
},
{
"input": "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "1"
},
{
"input": "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "13 13\nuwgmkyqeiaocs",
"output": "169"
},
{
"input": "13 13\nhzdxpbfvrltnj",
"output": "182"
},
{
"input": "1 1\nn",
"output": "14"
},
{
"input": "10 8\nsmzeblyjqw",
"output": "113"
},
{
"input": "20 20\ntzmvhskkyugkuuxpvtbh",
"output": "-1"
},
{
"input": "30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav",
"output": "-1"
},
{
"input": "40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv",
"output": "-1"
},
{
"input": "50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz",
"output": "-1"
},
{
"input": "10 7\niuiukrxcml",
"output": "99"
},
{
"input": "38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa",
"output": "5"
},
{
"input": "12 6\nfwseyrarkwcd",
"output": "61"
},
{
"input": "2 2\nac",
"output": "4"
},
{
"input": "1 1\nc",
"output": "3"
},
{
"input": "2 2\nad",
"output": "5"
},
{
"input": "2 1\nac",
"output": "1"
},
{
"input": "4 3\nadjz",
"output": "15"
},
{
"input": "3 3\naoz",
"output": "42"
},
{
"input": "3 1\nzzz",
"output": "26"
},
{
"input": "2 1\nxz",
"output": "24"
},
{
"input": "5 1\naaddd",
"output": "1"
}
] | 1,655,011,304 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 512,000 | n,k = map(int , input().split())
s = input()
l =[]
for i in s:
l.append(ord(i)-96)
l.sort()
for i in range(len(l)-1):
if l[i]+1==l[i+1]:
l[i+1]=0
for i in range(l.count(0)):
l.remove(0)
l.sort()
ans = 0
if len(l)<k:
print(-1)
else:
for i in range(k):
ans += l[i]
print(ans) | Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.
Input Specification:
The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.
Output Specification:
Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
Demo Input:
['5 3\nxyabd\n', '7 4\nproblem\n', '2 2\nab\n', '12 1\nabaabbaaabbb\n']
Demo Output:
['29', '34', '-1', '1']
Note:
In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | ```python
n,k = map(int , input().split())
s = input()
l =[]
for i in s:
l.append(ord(i)-96)
l.sort()
for i in range(len(l)-1):
if l[i]+1==l[i+1]:
l[i+1]=0
for i in range(l.count(0)):
l.remove(0)
l.sort()
ans = 0
if len(l)<k:
print(-1)
else:
for i in range(k):
ans += l[i]
print(ans)
``` | 0 |
|
988 | C | Equal Sums | PROGRAMMING | 1,400 | [
"implementation",
"sortings"
] | null | null | You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$.
You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals to the sum of the changed sequence $j$ (its length will be equal to $n_j - 1$).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals $0$) sequence is $0$. | The first line contains an integer $k$ ($2 \le k \le 2 \cdot 10^5$) — the number of sequences.
Then $k$ pairs of lines follow, each pair containing a sequence.
The first line in the $i$-th pair contains one integer $n_i$ ($1 \le n_i < 2 \cdot 10^5$) — the length of the $i$-th sequence. The second line of the $i$-th pair contains a sequence of $n_i$ integers $a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$.
The elements of sequences are integer numbers from $-10^4$ to $10^4$.
The sum of lengths of all given sequences don't exceed $2 \cdot 10^5$, i.e. $n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$. | If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $i$, $x$ ($1 \le i \le k, 1 \le x \le n_i$), in the third line — two integers $j$, $y$ ($1 \le j \le k, 1 \le y \le n_j$). It means that the sum of the elements of the $i$-th sequence without the element with index $x$ equals to the sum of the elements of the $j$-th sequence without the element with index $y$.
Two chosen sequences must be distinct, i.e. $i \ne j$. You can print them in any order.
If there are multiple possible answers, print any of them. | [
"2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n",
"3\n1\n5\n5\n1 1 1 1 1\n2\n2 3\n",
"4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n"
] | [
"YES\n2 6\n1 2\n",
"NO\n",
"YES\n2 2\n4 1\n"
] | In the first example there are two sequences $[2, 3, 1, 3, 2]$ and $[1, 1, 2, 2, 2, 1]$. You can remove the second element from the first sequence to get $[2, 1, 3, 2]$ and you can remove the sixth element from the second sequence to get $[1, 1, 2, 2, 2]$. The sums of the both resulting sequences equal to $8$, i.e. the sums are equal. | 0 | [
{
"input": "2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1",
"output": "YES\n2 1\n1 4"
},
{
"input": "3\n1\n5\n5\n1 1 1 1 1\n2\n2 3",
"output": "NO"
},
{
"input": "4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2",
"output": "YES\n4 1\n2 5"
},
{
"input": "2\n2\n0 -10000\n2\n10000 0",
"output": "YES\n2 1\n1 2"
}
] | 1,697,920,960 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 108 | 7,372,800 | def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid][0] == target:
return mid # Элемент найден, возвращаем индекс
elif arr[mid][0] < target:
left = mid + 1
else:
right = mid - 1
return -1 # Элемент не найден
k = int(input())
all_sequence = []
sum_el_sequence = []
for i in range(k):
len_i = int(input())
sequence_i = [int(x) for x in input().split()]
sum_el_sequence.append(sum(sequence_i))
all_sequence.append(sequence_i)
sum_el = []
i = 0
flag = False
while i < k and not flag:
sequence_i = all_sequence[i].copy()
sequence_i.sort(reverse=True)
sum_i = []
j = 0
while j < len(sequence_i) and not flag:
if j + 1 < len(sequence_i) and sequence_i[j] == sequence_i[j+1]:
j += 1
continue
sum_i.append(
(sum_el_sequence[i]-sequence_i[j], all_sequence[i].index(sequence_i[j])))
l = 0
while l < len(sum_el) and not flag:
index = binary_search(sum_el[l], sum_i[len(sum_i)-1][0])
if index != -1:
print("YES")
print(l + 1, sum_el[l][index][1] + 1)
print(i + 1, j + 1)
flag = True
l += 1
j += 1
sum_el.append(sum_i)
i += 1
if not flag:
print("NO")
| Title: Equal Sums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$.
You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals to the sum of the changed sequence $j$ (its length will be equal to $n_j - 1$).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals $0$) sequence is $0$.
Input Specification:
The first line contains an integer $k$ ($2 \le k \le 2 \cdot 10^5$) — the number of sequences.
Then $k$ pairs of lines follow, each pair containing a sequence.
The first line in the $i$-th pair contains one integer $n_i$ ($1 \le n_i < 2 \cdot 10^5$) — the length of the $i$-th sequence. The second line of the $i$-th pair contains a sequence of $n_i$ integers $a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$.
The elements of sequences are integer numbers from $-10^4$ to $10^4$.
The sum of lengths of all given sequences don't exceed $2 \cdot 10^5$, i.e. $n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$.
Output Specification:
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $i$, $x$ ($1 \le i \le k, 1 \le x \le n_i$), in the third line — two integers $j$, $y$ ($1 \le j \le k, 1 \le y \le n_j$). It means that the sum of the elements of the $i$-th sequence without the element with index $x$ equals to the sum of the elements of the $j$-th sequence without the element with index $y$.
Two chosen sequences must be distinct, i.e. $i \ne j$. You can print them in any order.
If there are multiple possible answers, print any of them.
Demo Input:
['2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n', '3\n1\n5\n5\n1 1 1 1 1\n2\n2 3\n', '4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n']
Demo Output:
['YES\n2 6\n1 2\n', 'NO\n', 'YES\n2 2\n4 1\n']
Note:
In the first example there are two sequences $[2, 3, 1, 3, 2]$ and $[1, 1, 2, 2, 2, 1]$. You can remove the second element from the first sequence to get $[2, 1, 3, 2]$ and you can remove the sixth element from the second sequence to get $[1, 1, 2, 2, 2]$. The sums of the both resulting sequences equal to $8$, i.e. the sums are equal. | ```python
def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid][0] == target:
return mid # Элемент найден, возвращаем индекс
elif arr[mid][0] < target:
left = mid + 1
else:
right = mid - 1
return -1 # Элемент не найден
k = int(input())
all_sequence = []
sum_el_sequence = []
for i in range(k):
len_i = int(input())
sequence_i = [int(x) for x in input().split()]
sum_el_sequence.append(sum(sequence_i))
all_sequence.append(sequence_i)
sum_el = []
i = 0
flag = False
while i < k and not flag:
sequence_i = all_sequence[i].copy()
sequence_i.sort(reverse=True)
sum_i = []
j = 0
while j < len(sequence_i) and not flag:
if j + 1 < len(sequence_i) and sequence_i[j] == sequence_i[j+1]:
j += 1
continue
sum_i.append(
(sum_el_sequence[i]-sequence_i[j], all_sequence[i].index(sequence_i[j])))
l = 0
while l < len(sum_el) and not flag:
index = binary_search(sum_el[l], sum_i[len(sum_i)-1][0])
if index != -1:
print("YES")
print(l + 1, sum_el[l][index][1] + 1)
print(i + 1, j + 1)
flag = True
l += 1
j += 1
sum_el.append(sum_i)
i += 1
if not flag:
print("NO")
``` | 0 |
|
991 | B | Getting an A | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo. | The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. | Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$. | 1,000 | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
{
"input": "8\n5 4 2 5 5 2 5 5",
"output": "1"
},
{
"input": "5\n5 5 2 5 5",
"output": "1"
},
{
"input": "6\n5 5 5 5 5 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "5"
},
{
"input": "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 3 3 5 3 2 2 4 5 5 4 5 5 4 2 3 2 2 2 2 5 3 5 2 3 4",
"output": "40"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "4\n3 2 5 5",
"output": "1"
},
{
"input": "6\n4 3 3 3 3 4",
"output": "4"
},
{
"input": "8\n3 3 5 3 3 3 5 5",
"output": "3"
},
{
"input": "10\n2 4 5 5 5 5 2 3 3 2",
"output": "3"
},
{
"input": "20\n5 2 5 2 2 2 2 2 5 2 2 5 2 5 5 2 2 5 2 2",
"output": "10"
},
{
"input": "25\n4 4 4 4 3 4 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4",
"output": "13"
},
{
"input": "30\n4 2 4 2 4 2 2 4 4 4 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 2 4 2 2",
"output": "15"
},
{
"input": "52\n5 3 4 4 4 3 5 3 4 5 3 4 4 3 5 5 4 3 3 3 4 5 4 4 5 3 5 3 5 4 5 5 4 3 4 5 3 4 3 3 4 4 4 3 5 3 4 5 3 5 4 5",
"output": "14"
},
{
"input": "77\n5 3 2 3 2 3 2 3 5 2 2 3 3 3 3 5 3 3 2 2 2 5 5 5 5 3 2 2 5 2 3 2 2 5 2 5 3 3 2 2 5 5 2 3 3 2 3 3 3 2 5 5 2 2 3 3 5 5 2 2 5 5 3 3 5 5 2 2 5 2 2 5 5 5 2 5 2",
"output": "33"
},
{
"input": "55\n3 4 2 3 3 2 4 4 3 3 4 2 4 4 3 3 2 3 2 2 3 3 2 3 2 3 2 4 4 3 2 3 2 3 3 2 2 4 2 4 4 3 4 3 2 4 3 2 4 2 2 3 2 3 4",
"output": "34"
},
{
"input": "66\n5 4 5 5 4 4 4 4 4 2 5 5 2 4 2 2 2 5 4 4 4 4 5 2 2 5 5 2 2 4 4 2 4 2 2 5 2 5 4 5 4 5 4 4 2 5 2 4 4 4 2 2 5 5 5 5 4 4 4 4 4 2 4 5 5 5",
"output": "16"
},
{
"input": "99\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",
"output": "83"
},
{
"input": "100\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": "84"
},
{
"input": "99\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "75"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "75"
},
{
"input": "99\n2 2 3 3 3 3 3 2 2 3 2 3 2 3 2 2 3 2 3 2 3 3 3 3 2 2 2 2 3 2 3 3 3 3 3 2 3 3 3 3 2 3 2 3 3 3 2 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 2 2 2 3 3 2 3 2 2 2 2 2 2 2 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3",
"output": "75"
},
{
"input": "100\n3 2 3 3 2 2 3 2 2 3 3 2 3 2 2 2 2 2 3 2 2 2 3 2 3 3 2 2 3 2 2 2 2 3 2 3 3 2 2 3 2 2 3 2 3 2 2 3 2 3 2 2 3 2 2 3 3 3 3 3 2 2 3 2 3 3 2 2 3 2 2 2 3 2 2 3 3 2 2 3 3 3 3 2 3 2 2 2 3 3 2 2 3 2 2 2 2 3 2 2",
"output": "75"
},
{
"input": "99\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "50"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "50"
},
{
"input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 4 2 2 2 4 4 2 2 2 2 4 4 4 2 2 2 4 4 2 4 2 4 2 2 4 2 4 4 4 4 4 2 2 4 4 4 2 2 2 2 4 2 4 2 2 2 2 2 2 4 4 2 4 2 2 4 2 2 2 2 2 4 2 4 2 2 4 4 4",
"output": "54"
},
{
"input": "100\n4 2 4 4 2 4 2 2 4 4 4 4 4 4 4 4 4 2 4 4 2 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 2 2 4 4 2 4 2 4 4 4 2 2 2 2 2 2 2 4 2 2 2 4 4 4 2 2 2 2 4 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 4 4 4 4 2 4 2 2 4",
"output": "50"
},
{
"input": "99\n4 3 4 4 4 4 4 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 3 4 3 3 3 3 4 3 4 4 3 4 4 3 3 4 4 4 3 3 3 4 4 3 3 4 3 4 3 4 3 4 3 3 3 3 4 3 4 4 4 4 4 4 3 4 4 3 3 3 3 3 3 3 3 4 3 3 3 4 4 4 4 4 4 3 3 3 3 4 4 4 3 3 4 3",
"output": "51"
},
{
"input": "100\n3 3 4 4 4 4 4 3 4 4 3 3 3 3 4 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 3 3 3 3 3 3 3 3 4 3 4 3 3 4 3 3 3 4 4 3 4 4 3 3 4 4 4 4 4 4 3 4 4 3 4 3 3 3 4 4 3 3 4 4 3 4 4 4 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 4 3 3 4",
"output": "51"
},
{
"input": "99\n3 3 4 4 4 2 4 4 3 2 3 4 4 4 2 2 2 3 2 4 4 2 4 3 2 2 2 4 2 3 4 3 4 2 3 3 4 2 3 3 2 3 4 4 3 2 4 3 4 3 3 3 3 3 4 4 3 3 4 4 2 4 3 4 3 2 3 3 3 4 4 2 4 4 2 3 4 2 3 3 3 4 2 2 3 2 4 3 2 3 3 2 3 4 2 3 3 2 3",
"output": "58"
},
{
"input": "100\n2 2 4 2 2 3 2 3 4 4 3 3 4 4 4 2 3 2 2 3 4 2 3 2 4 3 4 2 3 3 3 2 4 3 3 2 2 3 2 4 4 2 4 3 4 4 3 3 3 2 4 2 2 2 2 2 2 3 2 3 2 3 4 4 4 2 2 3 4 4 3 4 3 3 2 3 3 3 4 3 2 3 3 2 4 2 3 3 4 4 3 3 4 3 4 3 3 4 3 3",
"output": "61"
},
{
"input": "99\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "99\n2 2 2 2 2 5 2 2 5 2 5 2 5 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 2 5 5 2 5 2 2 5 2 5 2 2 5 5 2 2 2 2 5 5 2 2 2 5 2 2 5 2 2 2 2 2 5 5 5 5 2 2 5 2 5 2 2 2 2 2 5 2 2 5 5 2 2 2 2 2 5 5 2 2 5 5 2 2 2 2 5 5 5 2 5",
"output": "48"
},
{
"input": "100\n5 5 2 2 2 2 2 2 5 5 2 5 2 2 2 2 5 2 5 2 5 5 2 5 5 2 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 5 5 5 2 5 5 5 5 5 5 2 2 5 2 2 5 5 5 5 5 2 5 2 5 2 2 2 5 2 5 2 5 5 2 5 5 2 2 5 2 5 5 2 5 2 2 5 2 2 2 5 2 2 2 2 5 5 2 5",
"output": "38"
},
{
"input": "99\n5 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 5 5 3 5 5 3 3 5 5 5 3 5 3 3 3 3 5 3 3 5 5 3 5 5 5 3 5 3 5 3 5 5 5 5 3 3 3 5 3 5 3 3 3 5 5 5 5 5 3 5 5 3 3 5 5 3 5 5 3 5 5 3 3 5 5 5 3 3 3 5 3 3 3",
"output": "32"
},
{
"input": "100\n3 3 3 5 3 3 3 3 3 3 5 5 5 5 3 3 3 3 5 3 3 3 3 3 5 3 5 3 3 5 5 5 5 5 5 3 3 5 3 3 5 3 5 5 5 3 5 3 3 3 3 3 3 3 3 3 3 3 5 5 3 5 3 5 5 3 5 3 3 5 3 5 5 5 5 3 5 3 3 3 5 5 5 3 3 3 5 3 5 5 5 3 3 3 5 3 5 5 3 5",
"output": "32"
},
{
"input": "99\n5 3 5 5 3 3 3 2 2 5 2 5 3 2 5 2 5 2 3 5 3 2 3 2 5 5 2 2 3 3 5 5 3 5 5 2 3 3 5 2 2 5 3 2 5 2 3 5 5 2 5 2 2 5 3 3 5 3 3 5 3 2 3 5 3 2 3 2 3 2 2 2 2 5 2 2 3 2 5 5 5 3 3 2 5 3 5 5 5 2 3 2 5 5 2 5 2 5 3",
"output": "39"
},
{
"input": "100\n3 5 3 3 5 5 3 3 2 5 5 3 3 3 2 2 3 2 5 3 2 2 3 3 3 3 2 5 3 2 3 3 5 2 2 2 3 2 3 5 5 3 2 5 2 2 5 5 3 5 5 5 2 2 5 5 3 3 2 2 2 5 3 3 2 2 3 5 3 2 3 5 5 3 2 3 5 5 3 3 2 3 5 2 5 5 5 5 5 5 3 5 3 2 3 3 2 5 2 2",
"output": "42"
},
{
"input": "99\n4 4 4 5 4 4 5 5 4 4 5 5 5 4 5 4 5 5 5 4 4 5 5 5 5 4 5 5 5 4 4 5 5 4 5 4 4 4 5 5 5 5 4 4 5 4 4 5 4 4 4 4 5 5 5 4 5 4 5 5 5 5 5 4 5 4 5 4 4 4 4 5 5 5 4 5 5 4 4 5 5 5 4 5 4 4 5 5 4 5 5 5 5 4 5 5 4 4 4",
"output": "0"
},
{
"input": "100\n4 4 5 5 5 5 5 5 4 4 5 5 4 4 5 5 4 5 4 4 4 4 4 4 4 4 5 5 5 5 5 4 4 4 4 4 5 4 4 5 4 4 4 5 5 5 4 5 5 5 5 5 5 4 4 4 4 4 4 5 5 4 5 4 4 5 4 4 4 4 5 5 4 5 5 4 4 4 5 5 5 5 4 5 5 5 4 4 5 5 5 4 5 4 5 4 4 5 5 4",
"output": "1"
},
{
"input": "99\n2 2 2 5 2 2 2 2 2 4 4 5 5 2 2 4 2 5 2 2 2 5 2 2 5 5 5 4 5 5 4 4 2 2 5 2 2 2 2 5 5 2 2 4 4 4 2 2 2 5 2 4 4 2 4 2 4 2 5 4 2 2 5 2 4 4 4 2 5 2 2 5 4 2 2 5 5 5 2 4 5 4 5 5 4 4 4 5 4 5 4 5 4 2 5 2 2 2 4",
"output": "37"
},
{
"input": "100\n4 4 5 2 2 5 4 5 2 2 2 4 2 5 4 4 2 2 4 5 2 4 2 5 5 4 2 4 4 2 2 5 4 2 5 4 5 2 5 2 4 2 5 4 5 2 2 2 5 2 5 2 5 2 2 4 4 5 5 5 5 5 5 5 4 2 2 2 4 2 2 4 5 5 4 5 4 2 2 2 2 4 2 2 5 5 4 2 2 5 4 5 5 5 4 5 5 5 2 2",
"output": "31"
},
{
"input": "99\n5 3 4 4 5 4 4 4 3 5 4 3 3 4 3 5 5 5 5 4 3 3 5 3 4 5 3 5 4 4 3 5 5 4 4 4 4 3 5 3 3 5 5 5 5 5 4 3 4 4 3 5 5 3 3 4 4 4 5 4 4 5 4 4 4 4 5 5 4 3 3 4 3 5 3 3 3 3 4 4 4 4 3 4 5 4 4 5 5 5 3 4 5 3 4 5 4 3 3",
"output": "24"
},
{
"input": "100\n5 4 4 4 5 5 5 4 5 4 4 3 3 4 4 4 5 4 5 5 3 5 5 4 5 5 5 4 4 5 3 5 3 5 3 3 5 4 4 5 5 4 5 5 3 4 5 4 4 3 4 4 3 3 5 4 5 4 5 3 4 5 3 4 5 4 3 5 4 5 4 4 4 3 4 5 3 4 3 5 3 4 4 4 3 4 4 5 3 3 4 4 5 5 4 3 4 4 3 5",
"output": "19"
},
{
"input": "99\n2 2 5 2 5 3 4 2 3 5 4 3 4 2 5 3 2 2 4 2 4 4 5 4 4 5 2 5 5 3 2 3 2 2 3 4 5 3 5 2 5 4 4 5 4 2 2 3 2 3 3 3 4 4 3 2 2 4 4 2 5 3 5 3 5 4 4 4 5 4 5 2 2 5 4 4 4 3 3 2 5 2 5 2 3 2 5 2 2 5 5 3 4 5 3 4 4 4 4",
"output": "37"
},
{
"input": "2\n5 2",
"output": "1"
},
{
"input": "5\n2 2 2 2 2",
"output": "5"
},
{
"input": "100\n2 3 2 2 2 3 2 3 3 3 3 3 2 3 3 2 2 3 3 2 3 2 3 2 3 4 4 4 3 3 3 3 3 4 4 3 3 4 3 2 3 4 3 3 3 3 2 3 4 3 4 3 3 2 4 4 2 4 4 3 3 3 3 4 3 2 3 4 3 4 4 4 4 4 3 2 2 3 4 2 4 4 4 2 2 4 2 2 3 2 2 4 4 3 4 2 3 3 2 2",
"output": "61"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "1"
},
{
"input": "100\n5 4 3 5 3 5 4 2 3 3 4 5 4 5 5 4 2 4 2 2 5 2 5 3 4 4 4 5 5 5 3 4 4 4 3 5 3 2 5 4 3 3 3 5 2 3 4 2 5 4 3 4 5 2 2 3 4 4 2 3 3 3 2 5 2 3 4 3 3 3 2 5 4 3 4 5 4 2 5 4 5 2 2 4 2 2 5 5 4 5 2 2 2 2 5 2 4 4 4 5",
"output": "35"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "20\n4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5",
"output": "1"
}
] | 1,632,241,548 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 77 | 6,963,200 | n=int(input())
x=sorted(list(map(int,input().split())))
if sum(x)>=4.5*n: print(0)
else:
xcount=0
for i in range(n):
if x[i]!=5: xcount+=1
for i in range(n):
x[i]=5
if sum(x)>=4.5*n:
break
ycount=0
for i in range(n):
if x[i]!=5: ycount+=1
print(xcount-ycount)
| Title: Getting an A
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo.
Input Specification:
The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works.
Output Specification:
Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$.
Demo Input:
['3\n4 4 4\n', '4\n5 4 5 5\n', '4\n5 3 3 5\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$. | ```python
n=int(input())
x=sorted(list(map(int,input().split())))
if sum(x)>=4.5*n: print(0)
else:
xcount=0
for i in range(n):
if x[i]!=5: xcount+=1
for i in range(n):
x[i]=5
if sum(x)>=4.5*n:
break
ycount=0
for i in range(n):
if x[i]!=5: ycount+=1
print(xcount-ycount)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | The country Treeland consists of *n* cities connected with *n*<=-<=1 bidirectional roads in such a way that it's possible to reach every city starting from any other city using these roads. There will be a soccer championship next year, and all participants are Santa Clauses. There are exactly 2*k* teams from 2*k* different cities.
During the first stage all teams are divided into *k* pairs. Teams of each pair play two games against each other: one in the hometown of the first team, and the other in the hometown of the other team. Thus, each of the 2*k* cities holds exactly one soccer game. However, it's not decided yet how to divide teams into pairs.
It's also necessary to choose several cities to settle players in. Organizers tend to use as few cities as possible to settle the teams.
Nobody wants to travel too much during the championship, so if a team plays in cities *u* and *v*, it wants to live in one of the cities on the shortest path between *u* and *v* (maybe, in *u* or in *v*). There is another constraint also: the teams from one pair must live in the same city.
Summarizing, the organizers want to divide 2*k* teams into pairs and settle them in the minimum possible number of cities *m* in such a way that teams from each pair live in the same city which lies between their hometowns. | The first line of input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=2*k*<=≤<=*n*) — the number of cities in Treeland and the number of pairs of teams, respectively.
The following *n*<=-<=1 lines describe roads in Treeland: each of these lines contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*) which mean that there is a road between cities *a* and *b*. It's guaranteed that there is a path between any two cities.
The last line contains 2*k* distinct integers *c*1,<=*c*2,<=...,<=*c*2*k* (1<=≤<=*c**i*<=≤<=*n*), where *c**i* is the hometown of the *i*-th team. All these numbers are distinct. | The first line of output must contain the only positive integer *m* which should be equal to the minimum possible number of cities the teams can be settled in.
The second line should contain *m* distinct numbers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) denoting the indices of the cities where the teams should be settled.
The *k* lines should follow, the *j*-th of them should contain 3 integers *u**j*, *v**j* and *x**j*, where *u**j* and *v**j* are the hometowns of the *j*-th pair's teams, and *x**j* is the city they should live in during the tournament. Each of the numbers *c*1,<=*c*2,<=...,<=*c*2*k* should occur in all *u**j*'s and *v**j*'s exactly once. Each of the numbers *x**j* should belong to {*d*1,<=*d*2,<=...,<=*d**m*}.
If there are several possible answers, print any of them. | [
"6 2\n1 2\n1 3\n2 4\n2 5\n3 6\n2 5 4 6\n"
] | [
"1\n2\n5 4 2\n6 2 2\n"
] | In the first test the orginizers can settle all the teams in the city number 2. The way to divide all teams into pairs is not important, since all requirements are satisfied anyway, because the city 2 lies on the shortest path between every two cities from {2, 4, 5, 6}. | 0 | [
{
"input": "6 2\n1 2\n1 3\n2 4\n2 5\n3 6\n2 5 4 6",
"output": "1\n2\n5 4 2\n6 2 2"
},
{
"input": "2 1\n1 2\n1 2",
"output": "1\n1\n2 1 1"
},
{
"input": "6 2\n1 6\n6 2\n6 5\n5 3\n5 4\n1 3 4 2",
"output": "1\n6\n4 2 6\n3 1 6"
},
{
"input": "10 1\n4 2\n9 2\n1 4\n4 10\n2 3\n7 10\n9 6\n4 5\n8 2\n2 9",
"output": "1\n2\n9 2 2"
},
{
"input": "10 2\n9 2\n10 8\n2 3\n1 3\n2 7\n10 7\n9 4\n2 5\n6 5\n7 8 3 6",
"output": "1\n2\n8 6 2\n7 3 2"
},
{
"input": "10 3\n6 7\n2 1\n9 5\n1 5\n10 4\n8 3\n6 5\n10 6\n3 6\n10 5 1 3 7 4",
"output": "1\n6\n4 1 6\n3 10 6\n5 7 6"
},
{
"input": "8 3\n1 3\n3 2\n3 4\n4 5\n5 6\n4 7\n7 8\n4 6 8 1 3 2",
"output": "1\n3\n8 2 3\n6 1 3\n4 3 3"
},
{
"input": "10 3\n3 4\n1 3\n5 2\n2 6\n10 1\n3 2\n2 9\n9 8\n7 5\n10 9 4 7 5 3",
"output": "1\n3\n9 10 3\n7 4 3\n5 3 3"
},
{
"input": "10 4\n8 6\n1 7\n6 1\n5 1\n10 3\n9 6\n7 2\n6 3\n4 9\n6 2 1 5 8 3 9 4",
"output": "1\n6\n5 4 6\n2 3 6\n9 1 6\n8 6 6"
},
{
"input": "10 5\n2 6\n2 1\n7 2\n4 6\n7 10\n4 3\n3 5\n9 6\n8 7\n10 9 2 7 8 5 6 1 3 4",
"output": "1\n2\n9 8 2\n5 10 2\n3 7 2\n4 1 2\n6 2 2"
},
{
"input": "10 3\n5 9\n5 6\n3 7\n8 7\n4 7\n1 2\n6 7\n10 6\n2 6\n2 5 8 7 9 10",
"output": "1\n6\n8 9 6\n2 10 6\n7 5 6"
},
{
"input": "10 3\n4 2\n8 5\n8 9\n5 6\n10 7\n3 7\n1 7\n9 2\n2 7\n1 5 9 7 6 2",
"output": "1\n2\n6 1 2\n5 7 2\n9 2 2"
},
{
"input": "7 2\n7 5\n2 6\n3 6\n4 6\n7 2\n1 7\n4 7 1 6",
"output": "1\n7\n4 1 7\n6 7 7"
},
{
"input": "10 4\n2 6\n10 7\n2 10\n2 8\n9 5\n1 5\n4 5\n6 3\n5 3\n6 8 10 9 7 4 1 3",
"output": "1\n3\n8 4 3\n7 1 3\n10 9 3\n6 3 3"
},
{
"input": "7 2\n1 7\n4 5\n2 3\n6 3\n4 1\n3 1\n5 4 7 3",
"output": "1\n1\n5 3 1\n4 7 1"
},
{
"input": "10 4\n1 10\n5 1\n10 3\n4 9\n9 2\n2 8\n4 6\n5 7\n8 7\n9 3 8 2 5 10 1 6",
"output": "1\n5\n6 3 5\n9 10 5\n2 1 5\n8 5 5"
},
{
"input": "10 4\n10 3\n10 8\n9 3\n2 5\n7 2\n1 6\n9 4\n4 5\n4 6\n2 4 9 3 1 5 8 10",
"output": "1\n4\n8 2 4\n10 1 4\n3 5 4\n9 4 4"
},
{
"input": "10 2\n2 6\n1 3\n3 8\n10 9\n6 7\n7 3\n7 4\n10 7\n7 5\n6 2 7 1",
"output": "1\n7\n2 1 7\n6 7 7"
},
{
"input": "7 2\n6 1\n6 4\n6 5\n6 7\n6 3\n2 6\n4 2 3 6",
"output": "1\n6\n2 3 6\n4 6 6"
}
] | 1,690,766,380 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1690766380.9098082")# 1690766380.9098287 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country Treeland consists of *n* cities connected with *n*<=-<=1 bidirectional roads in such a way that it's possible to reach every city starting from any other city using these roads. There will be a soccer championship next year, and all participants are Santa Clauses. There are exactly 2*k* teams from 2*k* different cities.
During the first stage all teams are divided into *k* pairs. Teams of each pair play two games against each other: one in the hometown of the first team, and the other in the hometown of the other team. Thus, each of the 2*k* cities holds exactly one soccer game. However, it's not decided yet how to divide teams into pairs.
It's also necessary to choose several cities to settle players in. Organizers tend to use as few cities as possible to settle the teams.
Nobody wants to travel too much during the championship, so if a team plays in cities *u* and *v*, it wants to live in one of the cities on the shortest path between *u* and *v* (maybe, in *u* or in *v*). There is another constraint also: the teams from one pair must live in the same city.
Summarizing, the organizers want to divide 2*k* teams into pairs and settle them in the minimum possible number of cities *m* in such a way that teams from each pair live in the same city which lies between their hometowns.
Input Specification:
The first line of input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=2*k*<=≤<=*n*) — the number of cities in Treeland and the number of pairs of teams, respectively.
The following *n*<=-<=1 lines describe roads in Treeland: each of these lines contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*) which mean that there is a road between cities *a* and *b*. It's guaranteed that there is a path between any two cities.
The last line contains 2*k* distinct integers *c*1,<=*c*2,<=...,<=*c*2*k* (1<=≤<=*c**i*<=≤<=*n*), where *c**i* is the hometown of the *i*-th team. All these numbers are distinct.
Output Specification:
The first line of output must contain the only positive integer *m* which should be equal to the minimum possible number of cities the teams can be settled in.
The second line should contain *m* distinct numbers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) denoting the indices of the cities where the teams should be settled.
The *k* lines should follow, the *j*-th of them should contain 3 integers *u**j*, *v**j* and *x**j*, where *u**j* and *v**j* are the hometowns of the *j*-th pair's teams, and *x**j* is the city they should live in during the tournament. Each of the numbers *c*1,<=*c*2,<=...,<=*c*2*k* should occur in all *u**j*'s and *v**j*'s exactly once. Each of the numbers *x**j* should belong to {*d*1,<=*d*2,<=...,<=*d**m*}.
If there are several possible answers, print any of them.
Demo Input:
['6 2\n1 2\n1 3\n2 4\n2 5\n3 6\n2 5 4 6\n']
Demo Output:
['1\n2\n5 4 2\n6 2 2\n']
Note:
In the first test the orginizers can settle all the teams in the city number 2. The way to divide all teams into pairs is not important, since all requirements are satisfied anyway, because the city 2 lies on the shortest path between every two cities from {2, 4, 5, 6}. | ```python
print("_RANDOM_GUESS_1690766380.9098082")# 1690766380.9098287
``` | 0 |
|
766 | B | Mahmoud and a Triangle | PROGRAMMING | 1,000 | [
"constructive algorithms",
"geometry",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area. | The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. | In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. | [
"5\n1 5 3 2 4\n",
"3\n4 1 2\n"
] | [
"YES\n",
"NO\n"
] | For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. | 1,000 | [
{
"input": "5\n1 5 3 2 4",
"output": "YES"
},
{
"input": "3\n4 1 2",
"output": "NO"
},
{
"input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576",
"output": "NO"
},
{
"input": "30\n229017064 335281886 247217656 670601882 743442492 615491486 544941439 911270108 474843964 803323771 177115397 62179276 390270885 754889875 881720571 902691435 154083299 328505383 761264351 182674686 94104683 357622370 573909964 320060691 33548810 247029007 812823597 946798893 813659359 710111761",
"output": "YES"
},
{
"input": "40\n740553458 532562042 138583675 75471987 487348843 476240280 972115023 103690894 546736371 915774563 35356828 819948191 138721993 24257926 761587264 767176616 608310208 78275645 386063134 227581756 672567198 177797611 87579917 941781518 274774331 843623616 981221615 630282032 118843963 749160513 354134861 132333165 405839062 522698334 29698277 541005920 856214146 167344951 398332403 68622974",
"output": "YES"
},
{
"input": "40\n155 1470176 7384 765965701 1075 4 561554 6227772 93 16304522 1744 662 3 292572860 19335 908613 42685804 347058 20 132560 3848974 69067081 58 2819 111752888 408 81925 30 11951 4564 251 26381275 473392832 50628 180819969 2378797 10076746 9 214492 31291",
"output": "NO"
},
{
"input": "3\n1 1000000000 1000000000",
"output": "YES"
},
{
"input": "4\n1 1000000000 1000000000 1000000000",
"output": "YES"
},
{
"input": "3\n1 1000000000 1",
"output": "NO"
},
{
"input": "5\n1 2 3 5 2",
"output": "YES"
},
{
"input": "41\n19 161 4090221 118757367 2 45361275 1562319 596751 140871 97 1844 310910829 10708344 6618115 698 1 87059 33 2527892 12703 73396090 17326460 3 368811 20550 813975131 10 53804 28034805 7847 2992 33254 1139 227930 965568 261 4846 503064297 192153458 57 431",
"output": "NO"
},
{
"input": "42\n4317083 530966905 202811311 104 389267 35 1203 18287479 125344279 21690 859122498 65 859122508 56790 1951 148683 457 1 22 2668100 8283 2 77467028 13405 11302280 47877251 328155592 35095 29589769 240574 4 10 1019123 6985189 629846 5118 169 1648973 91891 741 282 3159",
"output": "YES"
},
{
"input": "43\n729551585 11379 5931704 330557 1653 15529406 729551578 278663905 1 729551584 2683 40656510 29802 147 1400284 2 126260 865419 51 17 172223763 86 1 534861 450887671 32 234 25127103 9597697 48226 7034 389 204294 2265706 65783617 4343 3665990 626 78034 106440137 5 18421 1023",
"output": "YES"
},
{
"input": "44\n719528276 2 235 444692918 24781885 169857576 18164 47558 15316043 9465834 64879816 2234575 1631 853530 8 1001 621 719528259 84 6933 31 1 3615623 719528266 40097928 274835337 1381044 11225 2642 5850203 6 527506 18 104977753 76959 29393 49 4283 141 201482 380 1 124523 326015",
"output": "YES"
},
{
"input": "45\n28237 82 62327732 506757 691225170 5 970 4118 264024506 313192 367 14713577 73933 691225154 6660 599 691225145 3473403 51 427200630 1326718 2146678 100848386 1569 27 163176119 193562 10784 45687 819951 38520653 225 119620 1 3 691225169 691225164 17445 23807072 1 9093493 5620082 2542 139 14",
"output": "YES"
},
{
"input": "44\n165580141 21 34 55 1 89 144 17711 2 377 610 987 2584 13 5 4181 6765 10946 1597 8 28657 3 233 75025 121393 196418 317811 9227465 832040 1346269 2178309 3524578 5702887 1 14930352 102334155 24157817 39088169 63245986 701408733 267914296 433494437 514229 46368",
"output": "NO"
},
{
"input": "3\n1 1000000000 999999999",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1",
"output": "YES"
},
{
"input": "10\n1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000",
"output": "NO"
},
{
"input": "5\n2 3 4 10 20",
"output": "YES"
},
{
"input": "6\n18 23 40 80 160 161",
"output": "YES"
},
{
"input": "4\n5 6 7 888",
"output": "YES"
},
{
"input": "9\n1 1 2 2 4 5 10 10 20",
"output": "YES"
},
{
"input": "7\n3 150 900 4 500 1500 5",
"output": "YES"
},
{
"input": "3\n2 2 3",
"output": "YES"
},
{
"input": "7\n1 2 100 200 250 1000000 2000000",
"output": "YES"
},
{
"input": "8\n2 3 5 5 5 6 6 13",
"output": "YES"
},
{
"input": "3\n2 3 4",
"output": "YES"
},
{
"input": "6\n1 1 1 4 5 100",
"output": "YES"
},
{
"input": "13\n1 2 3 5 8 13 22 34 55 89 144 233 377",
"output": "YES"
},
{
"input": "4\n2 3 4 8",
"output": "YES"
},
{
"input": "3\n5 6 7",
"output": "YES"
},
{
"input": "5\n1 4 5 6 1000000",
"output": "YES"
},
{
"input": "4\n5 6 7 20",
"output": "YES"
},
{
"input": "6\n1 1 1 1 1 65",
"output": "YES"
},
{
"input": "4\n3 4 5 100",
"output": "YES"
},
{
"input": "3\n2 4 5",
"output": "YES"
},
{
"input": "7\n1 1 1 1 1 10 1000",
"output": "YES"
},
{
"input": "4\n1 1 2 3",
"output": "NO"
},
{
"input": "11\n1 2 5 6 7 8 9 17 18 19 100",
"output": "YES"
},
{
"input": "4\n5 16 20 200",
"output": "YES"
},
{
"input": "5\n17 6 3 3 1",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "6\n1 1 1 2 3 5",
"output": "YES"
},
{
"input": "4\n2 4 6 6",
"output": "YES"
},
{
"input": "9\n1 2 4 4 4 4 7 8 20",
"output": "YES"
},
{
"input": "9\n1 1 2 5 5 5 10 10 20",
"output": "YES"
},
{
"input": "7\n3 150 600 4 1700 6000 5",
"output": "YES"
},
{
"input": "5\n5761 20966 27841 28800 29399",
"output": "YES"
},
{
"input": "9\n1 2 3 6 7 10 11 12 24",
"output": "YES"
},
{
"input": "4\n1 2 1 1",
"output": "YES"
},
{
"input": "5\n1 1 2 3 4",
"output": "YES"
}
] | 1,665,591,942 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n=int(input())
l=[]
j=0
for i in range (0,n):
l.append(int(input()))
l.sort()
while(len(l)>=3):
if(l[2]<l[1]+l[0]):
print("YES")
j=2
break
else:
l.remove(l[2])
if(j!=2):
print("NO") | Title: Mahmoud and a Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.
Input Specification:
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
Output Specification:
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
Demo Input:
['5\n1 5 3 2 4\n', '3\n4 1 2\n']
Demo Output:
['YES\n', 'NO\n']
Note:
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. | ```python
n=int(input())
l=[]
j=0
for i in range (0,n):
l.append(int(input()))
l.sort()
while(len(l)>=3):
if(l[2]<l[1]+l[0]):
print("YES")
j=2
break
else:
l.remove(l[2])
if(j!=2):
print("NO")
``` | -1 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 0 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"input": "100 99 98 100",
"output": "-1"
},
{
"input": "100 40 30 40",
"output": "-1"
},
{
"input": "100 50 19 25",
"output": "100\n51\n25"
},
{
"input": "100 50 19 30",
"output": "100\n61\n30"
},
{
"input": "49 48 25 49",
"output": "-1"
},
{
"input": "48 47 23 46",
"output": "94\n93\n46"
},
{
"input": "37 23 16 20",
"output": "42\n41\n20"
},
{
"input": "98 2 1 1",
"output": "98\n3\n1"
},
{
"input": "99 22 13 14",
"output": "99\n29\n14"
},
{
"input": "97 95 3 2",
"output": "97\n95\n3"
},
{
"input": "27 3 2 3",
"output": "-1"
},
{
"input": "13 7 6 2",
"output": "-1"
},
{
"input": "19 17 11 6",
"output": "19\n17\n11"
},
{
"input": "15 6 4 5",
"output": "15\n11\n5"
},
{
"input": "21 3 1 3",
"output": "-1"
},
{
"input": "100 99 98 97",
"output": "196\n195\n98"
},
{
"input": "99 32 13 5",
"output": "-1"
},
{
"input": "5 4 3 1",
"output": "-1"
},
{
"input": "50 20 4 8",
"output": "50\n20\n8"
},
{
"input": "60 30 10 1",
"output": "-1"
},
{
"input": "100 50 10 1",
"output": "-1"
},
{
"input": "40 30 20 10",
"output": "40\n30\n20"
},
{
"input": "50 49 5 10",
"output": "50\n49\n10"
},
{
"input": "99 98 50 97",
"output": "196\n195\n97"
},
{
"input": "50 30 10 5",
"output": "50\n30\n10"
},
{
"input": "4 3 2 1",
"output": "4\n3\n2"
},
{
"input": "100 50 3 1",
"output": "-1"
}
] | 1,514,041,586 | 3,686 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 202 | 5,734,400 | got = True
v1, v2, v3, vm = map(int, input().split())
for v3x in range(max(vm, v3), max(vm * 2, v3 * 2) + 1):
for v2x in range(v2, v2 * 2 + 1):
for v1x in range(v1, v1 * 2 + 1):
if not (v3x > (2 * vm) or v3x > 2 * v3 or v2x > v2 * 2 or v1x > v1 * 2 or v3x < vm or v3x < v3 or v2x < v2 or v1x < v1):
print(v1x)
print(v2x)
print(v3x)
got = False
if got:
print(-1) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input Specification:
You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3.
Output Specification:
Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Demo Input:
['50 30 10 10\n', '100 50 10 21\n']
Demo Output:
['50\n30\n10\n', '-1\n']
Note:
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | ```python
got = True
v1, v2, v3, vm = map(int, input().split())
for v3x in range(max(vm, v3), max(vm * 2, v3 * 2) + 1):
for v2x in range(v2, v2 * 2 + 1):
for v1x in range(v1, v1 * 2 + 1):
if not (v3x > (2 * vm) or v3x > 2 * v3 or v2x > v2 * 2 or v1x > v1 * 2 or v3x < vm or v3x < v3 or v2x < v2 or v1x < v1):
print(v1x)
print(v2x)
print(v3x)
got = False
if got:
print(-1)
``` | 0 |
|
242 | C | King's Path | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the *i*-th row and *j*-th column as (*i*,<=*j*).
You know that some squares of the given chess field are allowed. All allowed cells of the chess field are given as *n* segments. Each segment is described by three integers *r**i*,<=*a**i*,<=*b**i* (*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed.
Your task is to find the minimum number of moves the king needs to get from square (*x*0,<=*y*0) to square (*x*1,<=*y*1), provided that he only moves along the allowed cells. In other words, the king can be located only on allowed cells on his way.
Let us remind you that a chess king can move to any of the neighboring cells in one move. Two cells of a chess field are considered neighboring if they share at least one point. | The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contain the descriptions of these segments. The *i*-th line contains three space-separated integers *r**i*,<=*a**i*,<=*b**i* (1<=≤<=*r**i*,<=*a**i*,<=*b**i*<=≤<=109,<=*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed. Note that the segments of the allowed cells can intersect and embed arbitrarily.
It is guaranteed that the king's initial and final position are allowed cells. It is guaranteed that the king's initial and the final positions do not coincide. It is guaranteed that the total length of all given segments doesn't exceed 105. | If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one. | [
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n"
] | [
"4\n",
"6\n",
"-1\n"
] | none | 1,500 | [
{
"input": "5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5",
"output": "4"
},
{
"input": "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10",
"output": "6"
},
{
"input": "1 1 2 10\n2\n1 1 3\n2 6 10",
"output": "-1"
},
{
"input": "9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10 10",
"output": "2"
},
{
"input": "6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15\n7 14 14\n8 15 15",
"output": "1"
},
{
"input": "13 16 20 10\n18\n13 16 16\n20 10 10\n19 10 10\n12 15 15\n20 10 10\n18 11 11\n19 10 10\n19 10 10\n20 10 10\n19 10 10\n20 10 10\n20 10 10\n19 10 10\n18 11 11\n13 16 16\n12 15 15\n19 10 10\n19 10 10",
"output": "-1"
},
{
"input": "89 29 88 30\n16\n87 31 31\n14 95 95\n98 88 89\n96 88 88\n14 97 97\n13 97 98\n100 88 88\n88 32 32\n99 88 89\n90 29 29\n87 31 31\n15 94 96\n89 29 29\n88 32 32\n97 89 89\n88 29 30",
"output": "1"
},
{
"input": "30 14 39 19\n31\n35 7 11\n37 11 12\n32 13 13\n37 5 6\n46 13 13\n37 14 14\n31 13 13\n43 13 19\n45 15 19\n46 13 13\n32 17 17\n41 14 19\n30 14 14\n43 13 17\n34 16 18\n44 11 19\n38 13 13\n40 12 20\n37 16 18\n46 16 18\n34 10 14\n36 9 10\n36 15 19\n38 15 19\n42 13 19\n33 14 15\n35 15 19\n33 17 18\n39 12 20\n36 5 7\n45 12 12",
"output": "9"
},
{
"input": "2 1 1 1\n2\n1 1 2\n2 1 2",
"output": "1"
},
{
"input": "1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200",
"output": "1"
},
{
"input": "1 1 1000000000 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200",
"output": "-1"
}
] | 1,635,379,544 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 654 | 29,798,400 | # Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout
# -------------- INPUT FUNCTIONS ------------------
def get_ints_in_variables(): return map(
int, sys.stdin.readline().strip().split())
def get_int(): return int(sys.stdin.readline())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return [list(
map(int, sys.stdin.readline().strip().split())) for _ in range(n)]
def get_string(): return sys.stdin.readline().strip()
# -------- SOME CUSTOMIZED FUNCTIONS-----------
def myceil(x, y): return (x + y - 1) // y
# -------------- SOLUTION FUNCTION ------------------
def Solution():
# Write Your Code Here
x0, y0, x1, y1 = get_ints_in_variables()
n = get_int()
g = {}
for _ in range(n):
r, a, b = get_ints_in_variables()
for i in range(a, b+1):
g[(r, i)] = -1
g[(x0, y0)] = 0
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [0, -1, 1, -1, 1, 0, -1, 1]
queue = [(x0, y0)]
while len(queue):
node = queue.pop(0)
for j in range(8):
v = (node[0]+dx[j], node[1]+dy[j])
# print(v, "v")
if not v in g:
continue
if v in g and g[v] != -1:
continue
g[v] = g[node]+1
queue.append(v)
print(g[(x1, y1)])
def main():
# Take input Here and Call solution function
Solution()
# calling main Function
if __name__ == '__main__':
main()
| Title: King's Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the *i*-th row and *j*-th column as (*i*,<=*j*).
You know that some squares of the given chess field are allowed. All allowed cells of the chess field are given as *n* segments. Each segment is described by three integers *r**i*,<=*a**i*,<=*b**i* (*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed.
Your task is to find the minimum number of moves the king needs to get from square (*x*0,<=*y*0) to square (*x*1,<=*y*1), provided that he only moves along the allowed cells. In other words, the king can be located only on allowed cells on his way.
Let us remind you that a chess king can move to any of the neighboring cells in one move. Two cells of a chess field are considered neighboring if they share at least one point.
Input Specification:
The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contain the descriptions of these segments. The *i*-th line contains three space-separated integers *r**i*,<=*a**i*,<=*b**i* (1<=≤<=*r**i*,<=*a**i*,<=*b**i*<=≤<=109,<=*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed. Note that the segments of the allowed cells can intersect and embed arbitrarily.
It is guaranteed that the king's initial and final position are allowed cells. It is guaranteed that the king's initial and the final positions do not coincide. It is guaranteed that the total length of all given segments doesn't exceed 105.
Output Specification:
If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one.
Demo Input:
['5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n', '3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n', '1 1 2 10\n2\n1 1 3\n2 6 10\n']
Demo Output:
['4\n', '6\n', '-1\n']
Note:
none | ```python
# Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout
# -------------- INPUT FUNCTIONS ------------------
def get_ints_in_variables(): return map(
int, sys.stdin.readline().strip().split())
def get_int(): return int(sys.stdin.readline())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return [list(
map(int, sys.stdin.readline().strip().split())) for _ in range(n)]
def get_string(): return sys.stdin.readline().strip()
# -------- SOME CUSTOMIZED FUNCTIONS-----------
def myceil(x, y): return (x + y - 1) // y
# -------------- SOLUTION FUNCTION ------------------
def Solution():
# Write Your Code Here
x0, y0, x1, y1 = get_ints_in_variables()
n = get_int()
g = {}
for _ in range(n):
r, a, b = get_ints_in_variables()
for i in range(a, b+1):
g[(r, i)] = -1
g[(x0, y0)] = 0
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [0, -1, 1, -1, 1, 0, -1, 1]
queue = [(x0, y0)]
while len(queue):
node = queue.pop(0)
for j in range(8):
v = (node[0]+dx[j], node[1]+dy[j])
# print(v, "v")
if not v in g:
continue
if v in g and g[v] != -1:
continue
g[v] = g[node]+1
queue.append(v)
print(g[(x1, y1)])
def main():
# Take input Here and Call solution function
Solution()
# calling main Function
if __name__ == '__main__':
main()
``` | 3 |
|
369 | C | Valera and Elections | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | The city Valera lives in is going to hold elections to the city Parliament.
The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired.
There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located.
Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city.
Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road.
It's guaranteed that the graph structure of the city is a tree. | In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them. | [
"5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n",
"5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n",
"5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n"
] | [
"1\n5 \n",
"1\n3 \n",
"4\n5 4 3 2 \n"
] | none | 1,500 | [
{
"input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2",
"output": "1\n5 "
},
{
"input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1",
"output": "1\n3 "
},
{
"input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2",
"output": "4\n5 4 3 2 "
},
{
"input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2",
"output": "1\n2 "
},
{
"input": "2\n1 2 1",
"output": "0"
},
{
"input": "10\n7 5 1\n2 1 2\n8 7 2\n2 4 1\n4 5 2\n9 5 1\n3 2 2\n2 10 1\n6 5 2",
"output": "3\n8 6 3 "
},
{
"input": "2\n2 1 1",
"output": "0"
},
{
"input": "2\n1 2 2",
"output": "1\n2 "
},
{
"input": "5\n3 1 1\n4 5 1\n1 4 1\n1 2 1",
"output": "0"
},
{
"input": "5\n1 3 2\n5 4 2\n2 1 2\n4 3 2",
"output": "2\n5 2 "
},
{
"input": "10\n1 9 1\n3 2 2\n1 2 2\n4 7 2\n3 5 2\n4 3 2\n10 3 2\n7 8 2\n3 6 1",
"output": "3\n8 10 5 "
},
{
"input": "10\n7 9 2\n2 6 2\n7 4 1\n5 4 2\n3 2 1\n8 5 2\n4 3 2\n7 10 1\n1 2 2",
"output": "3\n9 8 6 "
},
{
"input": "10\n3 9 1\n2 10 2\n1 7 1\n3 4 1\n7 8 2\n1 2 1\n5 3 1\n5 6 2\n2 3 2",
"output": "3\n6 10 8 "
},
{
"input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 1\n7 5 1\n6 4 1\n5 3 1\n4 2 1",
"output": "2\n7 8 "
},
{
"input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 2\n7 5 2\n6 4 2\n5 3 2\n4 2 2",
"output": "2\n3 2 "
},
{
"input": "4\n1 2 2\n2 3 1\n2 4 2",
"output": "1\n4 "
}
] | 1,661,425,915 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 21,094,400 | from collections import deque
n = int(input())
d = [None] * (n + 1)
# h = {}
g = {}
used = [False] * (n + 1)
for _ in range(n - 1):
x, y, t = map(int, input().split())
# if x not in h:
# h[x] = -1
# h[y] = x
g[x] = t
g[y] = t
if d[x] is None:
d[x] = {y}
else:
d[x].add(y)
if d[y] is None:
d[y] = {x}
else:
d[y].add(x)
# print(d)
# print(h)
q = []
for t in range(2, n + 1):
if not (d[t] is None):
if len(d[t]) == 1:
q.append(t)
# print(q)
b = set()
f = set()
for e in q:
if e not in f:
# print(used)
dec = deque()
dec.append(e)
v = False
while len(dec) > 0:
used[dec[0]] = True
if dec[0] not in f:
if (g[dec[0]] == 2) and (not v):
b.add(dec[0])
if (g[dec[0]] == 2) or v:
v = True
f.add(dec[0])
for w in d[dec[0]]:
if dec[0] in d[w]:
if w not in f:
if w != 1:
dec.append(w)
# print(dec, b)
dec.popleft()
# print(f)
print(len(b))
print(*b)
| Title: Valera and Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city Valera lives in is going to hold elections to the city Parliament.
The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired.
There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located.
Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city.
Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road.
It's guaranteed that the graph structure of the city is a tree.
Output Specification:
In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them.
Demo Input:
['5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n', '5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n', '5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n']
Demo Output:
['1\n5 \n', '1\n3 \n', '4\n5 4 3 2 \n']
Note:
none | ```python
from collections import deque
n = int(input())
d = [None] * (n + 1)
# h = {}
g = {}
used = [False] * (n + 1)
for _ in range(n - 1):
x, y, t = map(int, input().split())
# if x not in h:
# h[x] = -1
# h[y] = x
g[x] = t
g[y] = t
if d[x] is None:
d[x] = {y}
else:
d[x].add(y)
if d[y] is None:
d[y] = {x}
else:
d[y].add(x)
# print(d)
# print(h)
q = []
for t in range(2, n + 1):
if not (d[t] is None):
if len(d[t]) == 1:
q.append(t)
# print(q)
b = set()
f = set()
for e in q:
if e not in f:
# print(used)
dec = deque()
dec.append(e)
v = False
while len(dec) > 0:
used[dec[0]] = True
if dec[0] not in f:
if (g[dec[0]] == 2) and (not v):
b.add(dec[0])
if (g[dec[0]] == 2) or v:
v = True
f.add(dec[0])
for w in d[dec[0]]:
if dec[0] in d[w]:
if w not in f:
if w != 1:
dec.append(w)
# print(dec, b)
dec.popleft()
# print(f)
print(len(b))
print(*b)
``` | 0 |
|
622 | B | The Time | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedia.org/wiki/24-hour_clock). | The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes passed. | The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format. | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n"
] | none | 0 | [
{
"input": "23:59\n10",
"output": "00:09"
},
{
"input": "20:20\n121",
"output": "22:21"
},
{
"input": "10:10\n0",
"output": "10:10"
},
{
"input": "12:34\n10000",
"output": "11:14"
},
{
"input": "00:00\n10000",
"output": "22:40"
},
{
"input": "00:00\n1440",
"output": "00:00"
},
{
"input": "23:59\n8640",
"output": "23:59"
},
{
"input": "10:01\n0",
"output": "10:01"
},
{
"input": "04:05\n0",
"output": "04:05"
},
{
"input": "02:59\n1",
"output": "03:00"
},
{
"input": "05:15\n10",
"output": "05:25"
},
{
"input": "03:10\n20",
"output": "03:30"
},
{
"input": "09:11\n0",
"output": "09:11"
},
{
"input": "19:00\n0",
"output": "19:00"
},
{
"input": "23:59\n1",
"output": "00:00"
},
{
"input": "11:59\n1",
"output": "12:00"
},
{
"input": "19:34\n566",
"output": "05:00"
},
{
"input": "00:01\n59",
"output": "01:00"
},
{
"input": "03:30\n0",
"output": "03:30"
},
{
"input": "22:30\n30",
"output": "23:00"
},
{
"input": "22:50\n70",
"output": "00:00"
},
{
"input": "05:12\n0",
"output": "05:12"
},
{
"input": "09:20\n40",
"output": "10:00"
},
{
"input": "15:04\n36",
"output": "15:40"
},
{
"input": "05:37\n23",
"output": "06:00"
},
{
"input": "23:59\n59",
"output": "00:58"
},
{
"input": "21:09\n9997",
"output": "19:46"
},
{
"input": "11:00\n1",
"output": "11:01"
},
{
"input": "20:01\n2699",
"output": "17:00"
},
{
"input": "01:00\n59",
"output": "01:59"
},
{
"input": "07:09\n6538",
"output": "20:07"
},
{
"input": "00:00\n10",
"output": "00:10"
},
{
"input": "02:09\n2074",
"output": "12:43"
},
{
"input": "01:10\n1",
"output": "01:11"
},
{
"input": "23:01\n59",
"output": "00:00"
},
{
"input": "08:50\n20",
"output": "09:10"
},
{
"input": "13:18\n5121",
"output": "02:39"
},
{
"input": "18:31\n2677",
"output": "15:08"
},
{
"input": "14:17\n108",
"output": "16:05"
},
{
"input": "02:45\n5617",
"output": "00:22"
},
{
"input": "00:00\n3600",
"output": "12:00"
},
{
"input": "19:01\n59",
"output": "20:00"
},
{
"input": "19:02\n59",
"output": "20:01"
},
{
"input": "14:00\n2880",
"output": "14:00"
},
{
"input": "01:10\n44",
"output": "01:54"
},
{
"input": "02:01\n59",
"output": "03:00"
},
{
"input": "07:02\n121",
"output": "09:03"
},
{
"input": "10:00\n61",
"output": "11:01"
},
{
"input": "23:59\n61",
"output": "01:00"
},
{
"input": "00:00\n0",
"output": "00:00"
},
{
"input": "23:59\n121",
"output": "02:00"
},
{
"input": "00:00\n60",
"output": "01:00"
},
{
"input": "15:52\n60",
"output": "16:52"
},
{
"input": "00:39\n6525",
"output": "13:24"
},
{
"input": "00:30\n30",
"output": "01:00"
},
{
"input": "00:59\n1",
"output": "01:00"
},
{
"input": "00:55\n4321",
"output": "00:56"
},
{
"input": "10:05\n1",
"output": "10:06"
},
{
"input": "23:00\n60",
"output": "00:00"
}
] | 1,474,204,064 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 62 | 102,400 | st= input()
l= (st.split(':'))
x=eval(input())
sum=x+int(l[1])
h=sum//60
l[1]=sum%60
l[0]=int(l[0])
l[0]+=int(h)
ans=':'
if(len(str(l[1])) <2):
ans+='0'
ans+=str(l[1])
else:
ans+=str(l[1])
if(len(str(l[0]%24)) >=2):
ans=str(l[0]%24)+ans
else:
ans='0'+str(l[0]%24)+ans
print(ans) | Title: The Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedia.org/wiki/24-hour_clock).
Input Specification:
The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes passed.
Output Specification:
The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format.
Demo Input:
['23:59\n10\n', '20:20\n121\n', '10:10\n0\n']
Demo Output:
['00:09\n', '22:21\n', '10:10\n']
Note:
none | ```python
st= input()
l= (st.split(':'))
x=eval(input())
sum=x+int(l[1])
h=sum//60
l[1]=sum%60
l[0]=int(l[0])
l[0]+=int(h)
ans=':'
if(len(str(l[1])) <2):
ans+='0'
ans+=str(l[1])
else:
ans+=str(l[1])
if(len(str(l[0]%24)) >=2):
ans=str(l[0]%24)+ans
else:
ans='0'+str(l[0]%24)+ans
print(ans)
``` | 3 |
|
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details. | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them. | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
},
{
"input": "1\nXO|OX",
"output": "NO"
},
{
"input": "1\nOO|OO",
"output": "YES\n++|OO"
},
{
"input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO",
"output": "NO"
},
{
"input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX",
"output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX"
},
{
"input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX",
"output": "NO"
},
{
"input": "1\nOO|XX",
"output": "YES\n++|XX"
},
{
"input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX",
"output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX"
},
{
"input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO",
"output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO"
},
{
"input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX",
"output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX"
}
] | 1,614,666,683 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 62 | 307,200 | import math
def solve():
times = int(input())
check = False
rows = []
for i in range(0,times):
rows.append(input().split("|"))
for i in rows:
if i[0]=="OO":
check = True
i[0] ="++"
break
elif i[1] =="OO":
check = True
i[1] ="++"
break
if check:
print("YES")
for i in rows:
print("|".join(i))
else:
print("NO")
# for _ in range(int(input())):
solve() | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
Output Specification:
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
Demo Input:
['6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', '4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n', '5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n']
Demo Output:
['YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', 'NO\n', 'YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n']
Note:
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | ```python
import math
def solve():
times = int(input())
check = False
rows = []
for i in range(0,times):
rows.append(input().split("|"))
for i in rows:
if i[0]=="OO":
check = True
i[0] ="++"
break
elif i[1] =="OO":
check = True
i[1] ="++"
break
if check:
print("YES")
for i in rows:
print("|".join(i))
else:
print("NO")
# for _ in range(int(input())):
solve()
``` | 3 |
|
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"output": "-1"
},
{
"input": "1000000000000000 1000000000",
"output": "-1"
},
{
"input": "1000000000000000 100",
"output": "1953125"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "4 3",
"output": "4"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "9 3",
"output": "9"
},
{
"input": "21 3",
"output": "7"
},
{
"input": "67280421310721 1",
"output": "1"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "16 3",
"output": "4"
},
{
"input": "1 1000",
"output": "-1"
},
{
"input": "16 4",
"output": "8"
},
{
"input": "36 8",
"output": "18"
},
{
"input": "49 4",
"output": "-1"
},
{
"input": "9 4",
"output": "-1"
},
{
"input": "16 1",
"output": "1"
},
{
"input": "16 6",
"output": "-1"
},
{
"input": "16 5",
"output": "16"
},
{
"input": "25 4",
"output": "-1"
},
{
"input": "4010815561 2",
"output": "63331"
},
{
"input": "49 3",
"output": "49"
},
{
"input": "36 6",
"output": "9"
},
{
"input": "36 10",
"output": "-1"
},
{
"input": "25 3",
"output": "25"
},
{
"input": "22876792454961 28",
"output": "7625597484987"
},
{
"input": "1234 2",
"output": "2"
},
{
"input": "179458711 2",
"output": "179458711"
},
{
"input": "900104343024121 100000",
"output": "-1"
},
{
"input": "8 3",
"output": "4"
},
{
"input": "100 6",
"output": "20"
},
{
"input": "15500 26",
"output": "-1"
},
{
"input": "111111 1",
"output": "1"
},
{
"input": "100000000000000 200",
"output": "160000000000"
},
{
"input": "1000000000000 100",
"output": "6400000"
},
{
"input": "100 10",
"output": "-1"
},
{
"input": "1000000000039 2",
"output": "1000000000039"
},
{
"input": "64 5",
"output": "16"
},
{
"input": "999999961946176 33",
"output": "63245552"
},
{
"input": "376219076689 3",
"output": "376219076689"
},
{
"input": "999999961946176 63",
"output": "999999961946176"
},
{
"input": "1048576 12",
"output": "2048"
},
{
"input": "745 21",
"output": "-1"
},
{
"input": "748 6",
"output": "22"
},
{
"input": "999999961946176 50",
"output": "161082468097"
},
{
"input": "10 3",
"output": "5"
},
{
"input": "1099511627776 22",
"output": "2097152"
},
{
"input": "1000000007 100010",
"output": "-1"
},
{
"input": "3 1",
"output": "1"
},
{
"input": "100 8",
"output": "50"
},
{
"input": "100 7",
"output": "25"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "999999961946176 64",
"output": "-1"
},
{
"input": "20 5",
"output": "10"
},
{
"input": "999999999999989 2",
"output": "999999999999989"
},
{
"input": "100000000000000 114",
"output": "10240000"
},
{
"input": "99999640000243 3",
"output": "9999991"
},
{
"input": "999998000001 566",
"output": "333332666667"
},
{
"input": "99999820000081 2",
"output": "9999991"
},
{
"input": "49000042000009 3",
"output": "49000042000009"
},
{
"input": "151491429961 4",
"output": "-1"
},
{
"input": "32416190071 2",
"output": "32416190071"
},
{
"input": "1000 8",
"output": "25"
},
{
"input": "1999967841 15",
"output": "1999967841"
},
{
"input": "26880 26880",
"output": "-1"
},
{
"input": "151491429961 3",
"output": "151491429961"
},
{
"input": "90000000000 300",
"output": "100000000"
},
{
"input": "98765004361 10",
"output": "-1"
},
{
"input": "15 2",
"output": "3"
},
{
"input": "16 2",
"output": "2"
},
{
"input": "1996 2",
"output": "2"
},
{
"input": "1997 2",
"output": "1997"
},
{
"input": "1999 2",
"output": "1999"
},
{
"input": "1998 2",
"output": "2"
},
{
"input": "1998 1",
"output": "1"
},
{
"input": "1998 7",
"output": "27"
},
{
"input": "1998 8",
"output": "37"
},
{
"input": "100000380000361 2",
"output": "10000019"
},
{
"input": "15 1",
"output": "1"
},
{
"input": "100000000000000 226",
"output": "-1"
},
{
"input": "844030857550613 517",
"output": "-1"
},
{
"input": "4567890 14",
"output": "430"
},
{
"input": "123123123 123123123",
"output": "-1"
},
{
"input": "24 4",
"output": "4"
},
{
"input": "999999993568952 17",
"output": "31622777"
},
{
"input": "99999999994190 9",
"output": "241656799"
},
{
"input": "999997874844049 4",
"output": "-1"
},
{
"input": "99999999999931 2",
"output": "99999999999931"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "67280421310721 2",
"output": "67280421310721"
}
] | 1,659,336,552 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 0 | import math
n, k = map(int, input().split())
count = 0
count1 = 0
l = []
for i in range(1, math.floor(math.sqrt(n)) + 1):
if n % i == 0:
l.append(i)
count += 1
if math.sqrt(n) == math.floor(math.sqrt(n)):
count1 = (count - 1) * 2 + 1
else:
count1 = count * 2
if count1 < k:
print(-1)
else:
if k <= count:
print(l[k - 1])
else:
for i in range(count - 1, -1, -1):
l.append(n // l[i])
print(l[k - 1])
| Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
Output Specification:
If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*.
Demo Input:
['4 2\n', '5 3\n', '12 5\n']
Demo Output:
['2\n', '-1\n', '6\n']
Note:
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | ```python
import math
n, k = map(int, input().split())
count = 0
count1 = 0
l = []
for i in range(1, math.floor(math.sqrt(n)) + 1):
if n % i == 0:
l.append(i)
count += 1
if math.sqrt(n) == math.floor(math.sqrt(n)):
count1 = (count - 1) * 2 + 1
else:
count1 = count * 2
if count1 < k:
print(-1)
else:
if k <= count:
print(l[k - 1])
else:
for i in range(count - 1, -1, -1):
l.append(n // l[i])
print(l[k - 1])
``` | 0 |
|
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3",
"output": "0\n0\n1\n1\n0"
},
{
"input": "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5",
"output": "2\n1\n1\n1\n1\n1\n1"
},
{
"input": "#..#\n1\n1 4",
"output": "1"
},
{
"input": "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4",
"output": "2\n2\n3\n2\n1\n4\n0"
},
{
"input": "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0"
},
{
"input": "###..#...#\n2\n2 4\n1 2",
"output": "1\n1"
},
{
"input": "..\n1\n1 2",
"output": "1"
},
{
"input": "##\n1\n1 2",
"output": "1"
},
{
"input": ".#\n1\n1 2",
"output": "0"
},
{
"input": "#.\n1\n1 2",
"output": "0"
},
{
"input": "...\n2\n1 2\n1 2",
"output": "1\n1"
}
] | 1,692,258,486 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 1,496 | 5,324,800 | st = input()
if st[0] == st[1]:
arr = [1]
else:
arr = [0]
for i in range(1 , len(st) - 1):
if st[i] == st[i + 1]:
arr.append(1 + arr[i - 1])
else:
arr.append(0 + arr[i - 1])
n = int(input())
for i in range(n):
a , b = map(int , input().split())
if a == 1:
print(arr[b - 2])
else:
print(arr[b - 2] - arr[a - 2]) | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
Input Specification:
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the answers to the queries in the order in which they are given in the input.
Demo Input:
['......\n4\n3 4\n2 3\n1 6\n2 6\n', '#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n']
Demo Output:
['1\n1\n5\n4\n', '1\n1\n2\n2\n0\n']
Note:
none | ```python
st = input()
if st[0] == st[1]:
arr = [1]
else:
arr = [0]
for i in range(1 , len(st) - 1):
if st[i] == st[i + 1]:
arr.append(1 + arr[i - 1])
else:
arr.append(0 + arr[i - 1])
n = int(input())
for i in range(n):
a , b = map(int , input().split())
if a == 1:
print(arr[b - 2])
else:
print(arr[b - 2] - arr[a - 2])
``` | 3 |
|
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct. | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest. | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155",
"output": "NO"
},
{
"input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968",
"output": "NO"
},
{
"input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290",
"output": "NO"
},
{
"input": "1\na 2400 2401",
"output": "YES"
},
{
"input": "1\nfucker 4000 4000",
"output": "NO"
},
{
"input": "1\nJora 2400 2401",
"output": "YES"
},
{
"input": "1\nACA 2400 2420",
"output": "YES"
},
{
"input": "1\nAca 2400 2420",
"output": "YES"
},
{
"input": "1\nSub_d 2401 2402",
"output": "YES"
},
{
"input": "2\nHack 2400 2401\nDum 1243 555",
"output": "YES"
},
{
"input": "1\nXXX 2400 2500",
"output": "YES"
},
{
"input": "1\nfucker 2400 2401",
"output": "YES"
},
{
"input": "1\nX 2400 2500",
"output": "YES"
},
{
"input": "1\nvineet 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2500",
"output": "YES"
},
{
"input": "1\naaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nhoge 2400 2401",
"output": "YES"
},
{
"input": "1\nInfinity 2400 2468",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2401",
"output": "YES"
},
{
"input": "1\nFuck 2400 2401",
"output": "YES"
},
{
"input": "1\nfuck 2400 2401",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "YES"
},
{
"input": "1\nalex 2400 2401",
"output": "YES"
},
{
"input": "1\nA 2400 2401",
"output": "YES"
},
{
"input": "1\na 2400 2455",
"output": "YES"
},
{
"input": "1\nlol 2400 2401",
"output": "YES"
},
{
"input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214",
"output": "YES"
},
{
"input": "1\naaaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2500",
"output": "YES"
},
{
"input": "1\nds 2400 2410",
"output": "YES"
},
{
"input": "1\nas 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2401",
"output": "YES"
},
{
"input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537",
"output": "YES"
},
{
"input": "1\ncaonima 2400 2401",
"output": "YES"
},
{
"input": "1\narr 2400 2500",
"output": "YES"
},
{
"input": "1\nx 2400 2401",
"output": "YES"
},
{
"input": "1\narrr 2400 2500",
"output": "YES"
},
{
"input": "1\nabc 2400 2405",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2537",
"output": "YES"
},
{
"input": "1\nHELLO 2400 2401",
"output": "YES"
},
{
"input": "1\neatmore 2400 2500",
"output": "YES"
},
{
"input": "1\nb 2400 2401",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nApplejack 2400 2410",
"output": "YES"
},
{
"input": "1\nabacaba 2400 2451",
"output": "YES"
},
{
"input": "1\nrekt_n00b 2500 2600",
"output": "YES"
}
] | 1,564,598,521 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 93 | 0 | n=int(input())
f=0
for i in range(n):
l=list(map(str,input().split()))
if l[1]>='2400' and l[2]>l[1]:
f=1
break
if f==1:
print("YES")
else:
print("NO") | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct.
Output Specification:
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
Demo Input:
['3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n', '3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n']
Demo Output:
['YES', 'NO']
Note:
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest. | ```python
n=int(input())
f=0
for i in range(n):
l=list(map(str,input().split()))
if l[1]>='2400' and l[2]>l[1]:
f=1
break
if f==1:
print("YES")
else:
print("NO")
``` | 0 |
|
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).
Your task is to check whether Limak can choose three balls that satisfy conditions above. | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose balls:
1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971. | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
"input": "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543",
"output": "NO"
},
{
"input": "50\n941 877 987 982 966 979 984 810 811 909 872 980 957 897 845 995 924 905 984 914 824 840 868 910 815 808 872 858 883 952 823 835 860 874 959 972 931 867 866 987 982 837 800 921 887 910 982 980 828 869",
"output": "YES"
},
{
"input": "3\n408 410 409",
"output": "YES"
},
{
"input": "3\n903 902 904",
"output": "YES"
},
{
"input": "3\n399 400 398",
"output": "YES"
},
{
"input": "3\n450 448 449",
"output": "YES"
},
{
"input": "3\n390 389 388",
"output": "YES"
},
{
"input": "3\n438 439 440",
"output": "YES"
},
{
"input": "11\n488 688 490 94 564 615 641 170 489 517 669",
"output": "YES"
},
{
"input": "24\n102 672 983 82 720 501 81 721 982 312 207 897 159 964 611 956 118 984 37 271 596 403 772 954",
"output": "YES"
},
{
"input": "36\n175 551 70 479 875 480 979 32 465 402 640 116 76 687 874 678 359 785 753 401 978 629 162 963 886 641 39 845 132 930 2 372 478 947 407 318",
"output": "YES"
},
{
"input": "6\n10 79 306 334 304 305",
"output": "YES"
},
{
"input": "34\n787 62 26 683 486 364 684 891 846 801 969 837 359 800 836 359 471 637 732 91 841 836 7 799 959 405 416 841 737 803 615 483 323 365",
"output": "YES"
},
{
"input": "30\n860 238 14 543 669 100 428 789 576 484 754 274 849 850 586 377 711 386 510 408 520 693 23 477 266 851 728 711 964 73",
"output": "YES"
},
{
"input": "11\n325 325 324 324 324 325 325 324 324 324 324",
"output": "NO"
},
{
"input": "7\n517 517 518 517 518 518 518",
"output": "NO"
},
{
"input": "20\n710 710 711 711 711 711 710 710 710 710 711 710 710 710 710 710 710 711 711 710",
"output": "NO"
},
{
"input": "48\n29 30 29 29 29 30 29 30 30 30 30 29 30 30 30 29 29 30 30 29 30 29 29 30 29 30 29 30 30 29 30 29 29 30 30 29 29 30 30 29 29 30 30 30 29 29 30 29",
"output": "NO"
},
{
"input": "7\n880 880 514 536 881 881 879",
"output": "YES"
},
{
"input": "15\n377 432 262 376 261 375 377 262 263 263 261 376 262 262 375",
"output": "YES"
},
{
"input": "32\n305 426 404 961 426 425 614 304 404 425 615 403 303 304 615 303 305 405 427 614 403 303 425 615 404 304 427 403 206 616 405 404",
"output": "YES"
},
{
"input": "41\n115 686 988 744 762 519 745 519 518 83 85 115 520 44 687 686 685 596 988 687 989 988 114 745 84 519 519 746 988 84 745 744 115 114 85 115 520 746 745 116 987",
"output": "YES"
},
{
"input": "47\n1 2 483 28 7 109 270 651 464 162 353 521 224 989 721 499 56 69 197 716 313 446 580 645 828 197 100 138 789 499 147 677 384 711 783 937 300 543 540 93 669 604 739 122 632 822 116",
"output": "NO"
},
{
"input": "31\n1 2 1 373 355 692 750 920 578 666 615 232 141 129 663 929 414 704 422 559 568 731 354 811 532 618 39 879 292 602 995",
"output": "NO"
},
{
"input": "50\n5 38 41 4 15 40 27 39 20 3 44 47 30 6 36 29 35 12 19 26 10 2 21 50 11 46 48 49 17 16 33 13 32 28 31 18 23 34 7 14 24 45 9 37 1 8 42 25 43 22",
"output": "YES"
},
{
"input": "50\n967 999 972 990 969 978 963 987 954 955 973 970 959 981 995 983 986 994 979 957 965 982 992 977 953 975 956 961 993 997 998 958 980 962 960 951 996 991 1000 966 971 988 976 968 989 984 974 964 985 952",
"output": "YES"
},
{
"input": "50\n850 536 761 506 842 898 857 723 583 637 536 943 895 929 890 612 832 633 696 731 553 880 710 812 665 877 915 636 711 540 748 600 554 521 813 796 568 513 543 809 798 820 928 504 999 646 907 639 550 911",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "3\n500 999 1000",
"output": "NO"
},
{
"input": "10\n101 102 104 105 107 109 110 112 113 115",
"output": "NO"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "3\n1000 999 998",
"output": "YES"
},
{
"input": "49\n343 322 248 477 53 156 245 493 209 141 370 66 229 184 434 137 276 472 216 456 147 180 140 114 493 323 393 262 380 314 222 124 98 441 129 346 48 401 347 460 122 125 114 106 189 260 374 165 456",
"output": "NO"
},
{
"input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3",
"output": "YES"
},
{
"input": "3\n999 999 1000",
"output": "NO"
},
{
"input": "9\n2 4 5 13 25 100 200 300 400",
"output": "NO"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "NO"
},
{
"input": "3\n998 999 1000",
"output": "YES"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 2 2 4",
"output": "NO"
},
{
"input": "4\n4 3 4 5",
"output": "YES"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "NO"
},
{
"input": "3\n2 3 2",
"output": "NO"
},
{
"input": "5\n10 5 6 3 2",
"output": "NO"
},
{
"input": "3\n1 2 1",
"output": "NO"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "4\n998 999 1000 1000",
"output": "YES"
},
{
"input": "5\n2 3 9 9 4",
"output": "YES"
},
{
"input": "4\n1 2 4 4",
"output": "NO"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n2 2 3",
"output": "NO"
},
{
"input": "7\n1 2 2 2 4 5 6",
"output": "YES"
},
{
"input": "5\n1 3 10 3 10",
"output": "NO"
},
{
"input": "3\n1 2 2",
"output": "NO"
},
{
"input": "4\n1000 1000 999 998",
"output": "YES"
},
{
"input": "3\n5 3 7",
"output": "NO"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "YES"
},
{
"input": "9\n6 6 6 5 5 5 4 4 4",
"output": "YES"
},
{
"input": "7\n5 6 6 6 7 7 7",
"output": "YES"
},
{
"input": "5\n2 3 3 3 4",
"output": "YES"
},
{
"input": "5\n2 1 2 1 3",
"output": "YES"
},
{
"input": "3\n1 2 7",
"output": "NO"
},
{
"input": "3\n1000 1000 1000",
"output": "NO"
},
{
"input": "5\n1 100 2 100 3",
"output": "YES"
},
{
"input": "5\n5 4 6 5 5",
"output": "YES"
},
{
"input": "12\n1 1 1 1 2 2 2 2 3 3 3 3",
"output": "YES"
},
{
"input": "5\n9 9 1 2 3",
"output": "YES"
},
{
"input": "6\n1 2 3 1 2 3",
"output": "YES"
},
{
"input": "7\n1 1 1 1 2 3 3",
"output": "YES"
},
{
"input": "3\n13 13 13",
"output": "NO"
},
{
"input": "3\n42 42 42",
"output": "NO"
},
{
"input": "8\n1 1 1 1 2 2 2 2",
"output": "NO"
},
{
"input": "6\n1 1 1 1 2 3",
"output": "YES"
},
{
"input": "6\n1 1 2 2 6 6",
"output": "NO"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "NO"
},
{
"input": "9\n1 2 3 1 2 3 1 2 3",
"output": "YES"
},
{
"input": "4\n1 2 1 100",
"output": "NO"
},
{
"input": "5\n1 1 2 2 3",
"output": "YES"
}
] | 1,685,440,114 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n = int(input())
a = sorted(list(map(int, input().split())))
for i in range(n-2):
if a[i] + 2 == a[i+2]:
print("YES")
break
else:
print("NO") | Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).
Your task is to check whether Limak can choose three balls that satisfy conditions above.
Input Specification:
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Output Specification:
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
Demo Input:
['4\n18 55 16 17\n', '6\n40 41 43 44 44 44\n', '8\n5 972 3 4 1 4 970 971\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose balls:
1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971. | ```python
n = int(input())
a = sorted(list(map(int, input().split())))
for i in range(n-2):
if a[i] + 2 == a[i+2]:
print("YES")
break
else:
print("NO")
``` | 0 |
|
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"output": "5"
},
{
"input": "100\n968 793 -628 -416 942 -308 977 168 728 -879 952 781 -425 -475 -480 738 -740 142 -319 -116 -701 -183 41 324 -918 -391 -176 781 763 888 475 -617 134 -802 -133 -211 855 -869 -236 503 550 387 137 -221 -957 -800 -56 -673 440 -791 -217 -959 -892 886 -593 427 890 223 -425 -342 -262 693 -137 924 860 156 -110 444 -12 703 421 -638 725 -551 597 -206 -80 393 -441 -759 617 424 -506 209 579 -685 -861 507 312 597 -81 -491 424 222 -892 629 512 743 -452 -504",
"output": "99"
}
] | 1,683,258,364 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 5,427,200 | n = int(input())
array = [int(a) for a in input().split()]
sum = 0
for i in range(len(array)):
sum += array[i]
if sum % n == 0:
print(n)
else:
print(n-1)
| Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array.
Output Specification:
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Demo Input:
['2\n2 1\n', '3\n1 4 1\n']
Demo Output:
['1\n', '3\n']
Note:
none | ```python
n = int(input())
array = [int(a) for a in input().split()]
sum = 0
for i in range(len(array)):
sum += array[i]
if sum % n == 0:
print(n)
else:
print(n-1)
``` | 3 |
|
616 | D | Longest k-Good Segment | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"two pointers"
] | null | null | The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. | The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. | Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right. | [
"5 5\n1 2 3 4 5\n",
"9 3\n6 5 1 2 3 2 1 4 5\n",
"3 1\n1 2 3\n"
] | [
"1 5\n",
"3 7\n",
"1 1\n"
] | none | 0 | [
{
"input": "5 5\n1 2 3 4 5",
"output": "1 5"
},
{
"input": "9 3\n6 5 1 2 3 2 1 4 5",
"output": "3 7"
},
{
"input": "3 1\n1 2 3",
"output": "1 1"
},
{
"input": "1 1\n747391",
"output": "1 1"
},
{
"input": "5 2\n171230 171230 171230 171230 171230",
"output": "1 5"
},
{
"input": "10 3\n512008 512008 452221 512008 314256 123232 314256 512008 314256 123232",
"output": "4 10"
},
{
"input": "6 1\n1 1 2 1 1 1",
"output": "4 6"
},
{
"input": "5 4\n1 2 3 4 0",
"output": "1 4"
},
{
"input": "5 4\n2 3 4 5 0",
"output": "1 4"
},
{
"input": "2 2\n0 1",
"output": "1 2"
},
{
"input": "2 2\n0 0",
"output": "1 2"
},
{
"input": "5 4\n1 2 3 45 0",
"output": "1 4"
}
] | 1,628,786,036 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 6,963,200 | n, k = map(int, input().split())
arr = list(map(int, input().split()))
ctr = {}
sol_i, sol_j = 0, 0
i, j = 0, 0
while i < n:
while j < n and len(ctr) <= k:
ctr[arr[j]] = ctr.get(arr[j], 0) + 1
j += 1
if len(ctr) == k and j - i > sol_j - sol_i:
sol_i, sol_j = i, j
if ctr[arr[i]] == 1:
ctr.pop(arr[i])
else:
ctr[arr[i]] -= 1
i += 1
print(sol_i+1, sol_j) | Title: Longest k-Good Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input Specification:
The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Output Specification:
Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right.
Demo Input:
['5 5\n1 2 3 4 5\n', '9 3\n6 5 1 2 3 2 1 4 5\n', '3 1\n1 2 3\n']
Demo Output:
['1 5\n', '3 7\n', '1 1\n']
Note:
none | ```python
n, k = map(int, input().split())
arr = list(map(int, input().split()))
ctr = {}
sol_i, sol_j = 0, 0
i, j = 0, 0
while i < n:
while j < n and len(ctr) <= k:
ctr[arr[j]] = ctr.get(arr[j], 0) + 1
j += 1
if len(ctr) == k and j - i > sol_j - sol_i:
sol_i, sol_j = i, j
if ctr[arr[i]] == 1:
ctr.pop(arr[i])
else:
ctr[arr[i]] -= 1
i += 1
print(sol_i+1, sol_j)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and *w* is the word that Valentin said. 1. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and *w* is the word that Valentin said. 1. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and *s* is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter. | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | [
"5\n! abc\n. ad\n. b\n! cd\n? c\n",
"8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n",
"7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin pronounces the word *cd* and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is *e* or *o*. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is *e*, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks. | 0 | [
{
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1"
},
{
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2"
},
{
"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h",
"output": "0"
},
{
"input": "4\n! abcd\n! cdef\n? d\n? c",
"output": "0"
},
{
"input": "1\n? q",
"output": "0"
},
{
"input": "15\n. r\n? e\n. s\n. rw\n? y\n. fj\n. zftyd\n? r\n! wq\n? w\n? p\n. ours\n. dto\n. lbyfru\n? q",
"output": "2"
},
{
"input": "3\n. abcdefghijklmnopqrstuvwxy\n? a\n? z",
"output": "1"
},
{
"input": "3\n. abcdefghijklmnopqrstuvwxy\n! z\n? z",
"output": "1"
}
] | 1,514,053,754 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 218 | 5,939,200 | occur = [1]*26
n=int(input())
t=1
for a in range(1,n):
act, word = input().split()
t=a
if act=='!':
temp=[0]*26
for c in word:
temp[ord(c)-ord('a')]=1
for i in range(26):
occur[i]=occur[i]&temp[i]
if(sum(occur)==1):
break
else:
for c in word:
occur[ord(c)-ord('a')]=0
if(sum(occur)==1):
break
# print (t)
ans = 0
for a in range(t+1,n):
act, word = input().split()
if act!='.':
ans+=1
act, word = input().split()
print(ans)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and *w* is the word that Valentin said. 1. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and *w* is the word that Valentin said. 1. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and *s* is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.
Output Specification:
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
Demo Input:
['5\n! abc\n. ad\n. b\n! cd\n? c\n', '8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n', '7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n']
Demo Output:
['1\n', '2\n', '0\n']
Note:
In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin pronounces the word *cd* and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is *e* or *o*. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is *e*, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks. | ```python
occur = [1]*26
n=int(input())
t=1
for a in range(1,n):
act, word = input().split()
t=a
if act=='!':
temp=[0]*26
for c in word:
temp[ord(c)-ord('a')]=1
for i in range(26):
occur[i]=occur[i]&temp[i]
if(sum(occur)==1):
break
else:
for c in word:
occur[ord(c)-ord('a')]=0
if(sum(occur)==1):
break
# print (t)
ans = 0
for a in range(t+1,n):
act, word = input().split()
if act!='.':
ans+=1
act, word = input().split()
print(ans)
``` | 3 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,696,960,632 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n=int(input())
st=[i for i in range(0,n)]
for i in range(n):
st[i]=input()
if len(st[i])>10:
st[i]=st[i][0]+str(len(st[i])-2)+st[i][-1]
for i in range(n):
print(st[i])
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
n=int(input())
st=[i for i in range(0,n)]
for i in range(n):
st[i]=input()
if len(st[i])>10:
st[i]=st[i][0]+str(len(st[i])-2)+st[i][-1]
for i in range(n):
print(st[i])
``` | 3.977 |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,689,625,478 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 186 | 0 | n = int(input())
print("YES" if n%2==0 and n!=2 else "NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Specification:
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Output Specification:
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Demo Input:
['8\n']
Demo Output:
['YES\n']
Note:
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | ```python
n = int(input())
print("YES" if n%2==0 and n!=2 else "NO")
``` | 3.907 |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "10000220"
},
{
"input": ".",
"output": "0"
},
{
"input": "-.",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "..",
"output": "00"
},
{
"input": "--.",
"output": "20"
},
{
"input": ".--.",
"output": "020"
},
{
"input": ".-.-..",
"output": "0110"
},
{
"input": "----.-.",
"output": "2201"
},
{
"input": "-..--.-.",
"output": "10201"
},
{
"input": "..--..--.",
"output": "0020020"
},
{
"input": "-.-.---.--..-..-.-.-..-..-.--.",
"output": "112120010111010120"
},
{
"input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.",
"output": "21112220010101011012011011221011"
},
{
"input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------",
"output": "11020111110111222212021020002022111100201121222020012022110010222"
},
{
"input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..",
"output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110"
},
{
"input": ".-..-.-.---.-----.--.---...-.--.-.-....-..",
"output": "01011212212021001201100010"
},
{
"input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..",
"output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210"
},
{
"input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.",
"output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220"
},
{
"input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----",
"output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122"
},
{
"input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..",
"output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110"
},
{
"input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.",
"output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020"
},
{
"input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..",
"output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200"
},
{
"input": "-.---...----...--.--...-.--.----",
"output": "121002200020200012022"
},
{
"input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.",
"output": "202020212012111010201021100001021221200011222112012201012220"
}
] | 1,663,710,329 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | m = list(input())
newlist=[]
for i in range(len(m)-1):
if m[i] == ".":
m[i]="N"
newlist.append("0")
if m[i]=="-" and m[i+1]==".":
m[i] = "N"
m[i+1] = "N"
newlist.append("1")
if m[i]=="-" and m[i+1]=="-":
m[i] = "N"
m[i + 1] = "N"
newlist.append("2")
print("".join(newlist)) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input Specification:
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output Specification:
Output the decoded ternary number. It can have leading zeroes.
Demo Input:
['.-.--\n', '--.\n', '-..-.--\n']
Demo Output:
['012', '20', '1012']
Note:
none | ```python
m = list(input())
newlist=[]
for i in range(len(m)-1):
if m[i] == ".":
m[i]="N"
newlist.append("0")
if m[i]=="-" and m[i+1]==".":
m[i] = "N"
m[i+1] = "N"
newlist.append("1")
if m[i]=="-" and m[i+1]=="-":
m[i] = "N"
m[i + 1] = "N"
newlist.append("2")
print("".join(newlist))
``` | 0 |
627 | A | XOR Equation | PROGRAMMING | 1,700 | [
"dp",
"math"
] | null | null | Two positive integers *a* and *b* have a sum of *s* and a bitwise XOR of *x*. How many possible values are there for the ordered pair (*a*,<=*b*)? | The first line of the input contains two integers *s* and *x* (2<=≤<=*s*<=≤<=1012, 0<=≤<=*x*<=≤<=1012), the sum and bitwise xor of the pair of positive integers, respectively. | Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0. | [
"9 5\n",
"3 3\n",
"5 2\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2).
In the second sample, the only solutions are (1, 2) and (2, 1). | 500 | [
{
"input": "9 5",
"output": "4"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "5 2",
"output": "0"
},
{
"input": "6 0",
"output": "1"
},
{
"input": "549755813887 549755813887",
"output": "549755813886"
},
{
"input": "2 0",
"output": "1"
},
{
"input": "2 2",
"output": "0"
},
{
"input": "433864631347 597596794426",
"output": "0"
},
{
"input": "80 12",
"output": "4"
},
{
"input": "549755813888 549755813886",
"output": "274877906944"
},
{
"input": "643057379466 24429729346",
"output": "2048"
},
{
"input": "735465350041 356516240229",
"output": "32768"
},
{
"input": "608032203317 318063018433",
"output": "4096"
},
{
"input": "185407964720 148793115916",
"output": "16384"
},
{
"input": "322414792152 285840263184",
"output": "4096"
},
{
"input": "547616456703 547599679487",
"output": "68719476736"
},
{
"input": "274861129991 274861129463",
"output": "34359738368"
},
{
"input": "549688705887 549688703839",
"output": "34359738368"
},
{
"input": "412182675455 412182609919",
"output": "68719476736"
},
{
"input": "552972910589 546530328573",
"output": "17179869184"
},
{
"input": "274869346299 274869346299",
"output": "8589934590"
},
{
"input": "341374319077 341374319077",
"output": "134217726"
},
{
"input": "232040172650 232040172650",
"output": "65534"
},
{
"input": "322373798090 322373798090",
"output": "1048574"
},
{
"input": "18436 18436",
"output": "6"
},
{
"input": "137707749376 137707749376",
"output": "30"
},
{
"input": "9126813696 9126813696",
"output": "6"
},
{
"input": "419432708 419432708",
"output": "62"
},
{
"input": "1839714 248080",
"output": "128"
},
{
"input": "497110 38",
"output": "8"
},
{
"input": "1420572 139928",
"output": "64"
},
{
"input": "583545 583545",
"output": "4094"
},
{
"input": "33411 33411",
"output": "30"
},
{
"input": "66068 66068",
"output": "14"
},
{
"input": "320 320",
"output": "2"
},
{
"input": "1530587 566563",
"output": "256"
},
{
"input": "1988518 108632",
"output": "128"
},
{
"input": "915425594051 155160267299",
"output": "0"
},
{
"input": "176901202458 21535662096",
"output": "0"
},
{
"input": "865893190664 224852444148",
"output": "32768"
},
{
"input": "297044970199 121204864",
"output": "0"
},
{
"input": "241173201018 236676464482",
"output": "0"
},
{
"input": "1582116 139808",
"output": "0"
},
{
"input": "1707011 656387",
"output": "0"
},
{
"input": "169616 132704",
"output": "32"
},
{
"input": "2160101 553812",
"output": "0"
},
{
"input": "1322568 271816",
"output": "0"
},
{
"input": "228503520839 471917524248",
"output": "0"
},
{
"input": "32576550340 504864993495",
"output": "0"
},
{
"input": "910648542843 537125462055",
"output": "0"
},
{
"input": "751720572344 569387893618",
"output": "0"
},
{
"input": "629791564846 602334362179",
"output": "0"
},
{
"input": "1000000000000 1000000000000",
"output": "8190"
},
{
"input": "1000000000000 999999999999",
"output": "0"
},
{
"input": "1000000000000 4",
"output": "0"
},
{
"input": "1000000000000 4096",
"output": "2"
},
{
"input": "3 1",
"output": "0"
},
{
"input": "2097152 0",
"output": "1"
},
{
"input": "40 390",
"output": "0"
},
{
"input": "22212 39957",
"output": "0"
},
{
"input": "128 36",
"output": "0"
},
{
"input": "14 4",
"output": "0"
},
{
"input": "6 2",
"output": "0"
},
{
"input": "43 18467",
"output": "0"
},
{
"input": "7 1",
"output": "0"
},
{
"input": "7 5",
"output": "0"
},
{
"input": "251059 79687",
"output": "0"
},
{
"input": "17 7",
"output": "0"
},
{
"input": "4 6",
"output": "0"
},
{
"input": "2 4",
"output": "0"
},
{
"input": "3 7",
"output": "0"
}
] | 1,592,119,714 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 204,800 | from sys import *
def bina(n):
s=""
for i in range(31, -1, -1):
k = n >> i;
if (k & 1):
s+='1'
else:
s+='0'
return s
s,x=map(int,stdin.readline().split())
a=(s-x)//2
if(True):
x=(bina(x))
a=(bina(a))
c=1
for i in range(32):
if(x[i]=='1' and a[i]=='1'):
c=0
break
elif(x[i]=='0' and a[i]=='0'):
pass
elif(x[i]=='1' and a[i]=='0'):
c*=2
elif(x[i]=='0' and a[i]=='1'):
pass
print(c)
| Title: XOR Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two positive integers *a* and *b* have a sum of *s* and a bitwise XOR of *x*. How many possible values are there for the ordered pair (*a*,<=*b*)?
Input Specification:
The first line of the input contains two integers *s* and *x* (2<=≤<=*s*<=≤<=1012, 0<=≤<=*x*<=≤<=1012), the sum and bitwise xor of the pair of positive integers, respectively.
Output Specification:
Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0.
Demo Input:
['9 5\n', '3 3\n', '5 2\n']
Demo Output:
['4\n', '2\n', '0\n']
Note:
In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2).
In the second sample, the only solutions are (1, 2) and (2, 1). | ```python
from sys import *
def bina(n):
s=""
for i in range(31, -1, -1):
k = n >> i;
if (k & 1):
s+='1'
else:
s+='0'
return s
s,x=map(int,stdin.readline().split())
a=(s-x)//2
if(True):
x=(bina(x))
a=(bina(a))
c=1
for i in range(32):
if(x[i]=='1' and a[i]=='1'):
c=0
break
elif(x[i]=='0' and a[i]=='0'):
pass
elif(x[i]=='1' and a[i]=='0'):
c*=2
elif(x[i]=='0' and a[i]=='1'):
pass
print(c)
``` | 0 |
|
268 | C | Beautiful Sets of Points | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation"
] | null | null | Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions:
1. The coordinates of each point in the set are integers. 1. For any two points from the set, the distance between them is a non-integer.
Consider all points (*x*,<=*y*) which satisfy the inequations: 0<=≤<=*x*<=≤<=*n*; 0<=≤<=*y*<=≤<=*m*; *x*<=+<=*y*<=><=0. Choose their subset of maximum size such that it is also a beautiful set of points. | The single line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | In the first line print a single integer — the size *k* of the found beautiful set. In each of the next *k* lines print a pair of space-separated integers — the *x*- and *y*- coordinates, respectively, of a point from the set.
If there are several optimal solutions, you may print any of them. | [
"2 2\n",
"4 3\n"
] | [
"3\n0 1\n1 2\n2 0\n",
"4\n0 3\n2 1\n3 0\n4 2\n"
] | Consider the first sample. The distance between points (0, 1) and (1, 2) equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bfe16f27ebc966df6f10ba356a1547b6e7242dd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (0, 1) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (1, 2) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. | 1,500 | [
{
"input": "2 2",
"output": "3\n0 1\n1 2\n2 0"
},
{
"input": "4 3",
"output": "4\n0 3\n2 1\n3 0\n4 2"
},
{
"input": "21 21",
"output": "22\n21 0\n20 1\n19 2\n18 3\n17 4\n16 5\n15 6\n14 7\n13 8\n12 9\n11 10\n10 11\n9 12\n8 13\n7 14\n6 15\n5 16\n4 17\n3 18\n2 19\n1 20\n0 21"
},
{
"input": "10 1",
"output": "2\n1 0\n0 1"
},
{
"input": "4 4",
"output": "5\n4 0\n3 1\n2 2\n1 3\n0 4"
},
{
"input": "1 1",
"output": "2\n1 0\n0 1"
},
{
"input": "5 5",
"output": "6\n5 0\n4 1\n3 2\n2 3\n1 4\n0 5"
},
{
"input": "100 100",
"output": "101\n100 0\n99 1\n98 2\n97 3\n96 4\n95 5\n94 6\n93 7\n92 8\n91 9\n90 10\n89 11\n88 12\n87 13\n86 14\n85 15\n84 16\n83 17\n82 18\n81 19\n80 20\n79 21\n78 22\n77 23\n76 24\n75 25\n74 26\n73 27\n72 28\n71 29\n70 30\n69 31\n68 32\n67 33\n66 34\n65 35\n64 36\n63 37\n62 38\n61 39\n60 40\n59 41\n58 42\n57 43\n56 44\n55 45\n54 46\n53 47\n52 48\n51 49\n50 50\n49 51\n48 52\n47 53\n46 54\n45 55\n44 56\n43 57\n42 58\n41 59\n40 60\n39 61\n38 62\n37 63\n36 64\n35 65\n34 66\n33 67\n32 68\n31 69\n30 70\n29 71\n28 72\n27 7..."
},
{
"input": "96 96",
"output": "97\n96 0\n95 1\n94 2\n93 3\n92 4\n91 5\n90 6\n89 7\n88 8\n87 9\n86 10\n85 11\n84 12\n83 13\n82 14\n81 15\n80 16\n79 17\n78 18\n77 19\n76 20\n75 21\n74 22\n73 23\n72 24\n71 25\n70 26\n69 27\n68 28\n67 29\n66 30\n65 31\n64 32\n63 33\n62 34\n61 35\n60 36\n59 37\n58 38\n57 39\n56 40\n55 41\n54 42\n53 43\n52 44\n51 45\n50 46\n49 47\n48 48\n47 49\n46 50\n45 51\n44 52\n43 53\n42 54\n41 55\n40 56\n39 57\n38 58\n37 59\n36 60\n35 61\n34 62\n33 63\n32 64\n31 65\n30 66\n29 67\n28 68\n27 69\n26 70\n25 71\n24 72\n23 73\n..."
},
{
"input": "99 100",
"output": "100\n99 0\n98 1\n97 2\n96 3\n95 4\n94 5\n93 6\n92 7\n91 8\n90 9\n89 10\n88 11\n87 12\n86 13\n85 14\n84 15\n83 16\n82 17\n81 18\n80 19\n79 20\n78 21\n77 22\n76 23\n75 24\n74 25\n73 26\n72 27\n71 28\n70 29\n69 30\n68 31\n67 32\n66 33\n65 34\n64 35\n63 36\n62 37\n61 38\n60 39\n59 40\n58 41\n57 42\n56 43\n55 44\n54 45\n53 46\n52 47\n51 48\n50 49\n49 50\n48 51\n47 52\n46 53\n45 54\n44 55\n43 56\n42 57\n41 58\n40 59\n39 60\n38 61\n37 62\n36 63\n35 64\n34 65\n33 66\n32 67\n31 68\n30 69\n29 70\n28 71\n27 72\n26 73..."
},
{
"input": "67 58",
"output": "59\n58 0\n57 1\n56 2\n55 3\n54 4\n53 5\n52 6\n51 7\n50 8\n49 9\n48 10\n47 11\n46 12\n45 13\n44 14\n43 15\n42 16\n41 17\n40 18\n39 19\n38 20\n37 21\n36 22\n35 23\n34 24\n33 25\n32 26\n31 27\n30 28\n29 29\n28 30\n27 31\n26 32\n25 33\n24 34\n23 35\n22 36\n21 37\n20 38\n19 39\n18 40\n17 41\n16 42\n15 43\n14 44\n13 45\n12 46\n11 47\n10 48\n9 49\n8 50\n7 51\n6 52\n5 53\n4 54\n3 55\n2 56\n1 57\n0 58"
},
{
"input": "67 59",
"output": "60\n59 0\n58 1\n57 2\n56 3\n55 4\n54 5\n53 6\n52 7\n51 8\n50 9\n49 10\n48 11\n47 12\n46 13\n45 14\n44 15\n43 16\n42 17\n41 18\n40 19\n39 20\n38 21\n37 22\n36 23\n35 24\n34 25\n33 26\n32 27\n31 28\n30 29\n29 30\n28 31\n27 32\n26 33\n25 34\n24 35\n23 36\n22 37\n21 38\n20 39\n19 40\n18 41\n17 42\n16 43\n15 44\n14 45\n13 46\n12 47\n11 48\n10 49\n9 50\n8 51\n7 52\n6 53\n5 54\n4 55\n3 56\n2 57\n1 58\n0 59"
},
{
"input": "80 91",
"output": "81\n80 0\n79 1\n78 2\n77 3\n76 4\n75 5\n74 6\n73 7\n72 8\n71 9\n70 10\n69 11\n68 12\n67 13\n66 14\n65 15\n64 16\n63 17\n62 18\n61 19\n60 20\n59 21\n58 22\n57 23\n56 24\n55 25\n54 26\n53 27\n52 28\n51 29\n50 30\n49 31\n48 32\n47 33\n46 34\n45 35\n44 36\n43 37\n42 38\n41 39\n40 40\n39 41\n38 42\n37 43\n36 44\n35 45\n34 46\n33 47\n32 48\n31 49\n30 50\n29 51\n28 52\n27 53\n26 54\n25 55\n24 56\n23 57\n22 58\n21 59\n20 60\n19 61\n18 62\n17 63\n16 64\n15 65\n14 66\n13 67\n12 68\n11 69\n10 70\n9 71\n8 72\n7 73\n6 ..."
},
{
"input": "100 11",
"output": "12\n11 0\n10 1\n9 2\n8 3\n7 4\n6 5\n5 6\n4 7\n3 8\n2 9\n1 10\n0 11"
},
{
"input": "16 55",
"output": "17\n16 0\n15 1\n14 2\n13 3\n12 4\n11 5\n10 6\n9 7\n8 8\n7 9\n6 10\n5 11\n4 12\n3 13\n2 14\n1 15\n0 16"
},
{
"input": "13 71",
"output": "14\n13 0\n12 1\n11 2\n10 3\n9 4\n8 5\n7 6\n6 7\n5 8\n4 9\n3 10\n2 11\n1 12\n0 13"
},
{
"input": "30 40",
"output": "31\n30 0\n29 1\n28 2\n27 3\n26 4\n25 5\n24 6\n23 7\n22 8\n21 9\n20 10\n19 11\n18 12\n17 13\n16 14\n15 15\n14 16\n13 17\n12 18\n11 19\n10 20\n9 21\n8 22\n7 23\n6 24\n5 25\n4 26\n3 27\n2 28\n1 29\n0 30"
},
{
"input": "77 77",
"output": "78\n77 0\n76 1\n75 2\n74 3\n73 4\n72 5\n71 6\n70 7\n69 8\n68 9\n67 10\n66 11\n65 12\n64 13\n63 14\n62 15\n61 16\n60 17\n59 18\n58 19\n57 20\n56 21\n55 22\n54 23\n53 24\n52 25\n51 26\n50 27\n49 28\n48 29\n47 30\n46 31\n45 32\n44 33\n43 34\n42 35\n41 36\n40 37\n39 38\n38 39\n37 40\n36 41\n35 42\n34 43\n33 44\n32 45\n31 46\n30 47\n29 48\n28 49\n27 50\n26 51\n25 52\n24 53\n23 54\n22 55\n21 56\n20 57\n19 58\n18 59\n17 60\n16 61\n15 62\n14 63\n13 64\n12 65\n11 66\n10 67\n9 68\n8 69\n7 70\n6 71\n5 72\n4 73\n3 74\n..."
},
{
"input": "6 6",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "37 42",
"output": "38\n37 0\n36 1\n35 2\n34 3\n33 4\n32 5\n31 6\n30 7\n29 8\n28 9\n27 10\n26 11\n25 12\n24 13\n23 14\n22 15\n21 16\n20 17\n19 18\n18 19\n17 20\n16 21\n15 22\n14 23\n13 24\n12 25\n11 26\n10 27\n9 28\n8 29\n7 30\n6 31\n5 32\n4 33\n3 34\n2 35\n1 36\n0 37"
},
{
"input": "88 88",
"output": "89\n88 0\n87 1\n86 2\n85 3\n84 4\n83 5\n82 6\n81 7\n80 8\n79 9\n78 10\n77 11\n76 12\n75 13\n74 14\n73 15\n72 16\n71 17\n70 18\n69 19\n68 20\n67 21\n66 22\n65 23\n64 24\n63 25\n62 26\n61 27\n60 28\n59 29\n58 30\n57 31\n56 32\n55 33\n54 34\n53 35\n52 36\n51 37\n50 38\n49 39\n48 40\n47 41\n46 42\n45 43\n44 44\n43 45\n42 46\n41 47\n40 48\n39 49\n38 50\n37 51\n36 52\n35 53\n34 54\n33 55\n32 56\n31 57\n30 58\n29 59\n28 60\n27 61\n26 62\n25 63\n24 64\n23 65\n22 66\n21 67\n20 68\n19 69\n18 70\n17 71\n16 72\n15 73\n..."
},
{
"input": "95 99",
"output": "96\n95 0\n94 1\n93 2\n92 3\n91 4\n90 5\n89 6\n88 7\n87 8\n86 9\n85 10\n84 11\n83 12\n82 13\n81 14\n80 15\n79 16\n78 17\n77 18\n76 19\n75 20\n74 21\n73 22\n72 23\n71 24\n70 25\n69 26\n68 27\n67 28\n66 29\n65 30\n64 31\n63 32\n62 33\n61 34\n60 35\n59 36\n58 37\n57 38\n56 39\n55 40\n54 41\n53 42\n52 43\n51 44\n50 45\n49 46\n48 47\n47 48\n46 49\n45 50\n44 51\n43 52\n42 53\n41 54\n40 55\n39 56\n38 57\n37 58\n36 59\n35 60\n34 61\n33 62\n32 63\n31 64\n30 65\n29 66\n28 67\n27 68\n26 69\n25 70\n24 71\n23 72\n22 73\n..."
},
{
"input": "93 70",
"output": "71\n70 0\n69 1\n68 2\n67 3\n66 4\n65 5\n64 6\n63 7\n62 8\n61 9\n60 10\n59 11\n58 12\n57 13\n56 14\n55 15\n54 16\n53 17\n52 18\n51 19\n50 20\n49 21\n48 22\n47 23\n46 24\n45 25\n44 26\n43 27\n42 28\n41 29\n40 30\n39 31\n38 32\n37 33\n36 34\n35 35\n34 36\n33 37\n32 38\n31 39\n30 40\n29 41\n28 42\n27 43\n26 44\n25 45\n24 46\n23 47\n22 48\n21 49\n20 50\n19 51\n18 52\n17 53\n16 54\n15 55\n14 56\n13 57\n12 58\n11 59\n10 60\n9 61\n8 62\n7 63\n6 64\n5 65\n4 66\n3 67\n2 68\n1 69\n0 70"
},
{
"input": "4 6",
"output": "5\n4 0\n3 1\n2 2\n1 3\n0 4"
},
{
"input": "1 4",
"output": "2\n1 0\n0 1"
},
{
"input": "2 10",
"output": "3\n2 0\n1 1\n0 2"
},
{
"input": "6 7",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "28 28",
"output": "29\n28 0\n27 1\n26 2\n25 3\n24 4\n23 5\n22 6\n21 7\n20 8\n19 9\n18 10\n17 11\n16 12\n15 13\n14 14\n13 15\n12 16\n11 17\n10 18\n9 19\n8 20\n7 21\n6 22\n5 23\n4 24\n3 25\n2 26\n1 27\n0 28"
},
{
"input": "10 6",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "85 48",
"output": "49\n48 0\n47 1\n46 2\n45 3\n44 4\n43 5\n42 6\n41 7\n40 8\n39 9\n38 10\n37 11\n36 12\n35 13\n34 14\n33 15\n32 16\n31 17\n30 18\n29 19\n28 20\n27 21\n26 22\n25 23\n24 24\n23 25\n22 26\n21 27\n20 28\n19 29\n18 30\n17 31\n16 32\n15 33\n14 34\n13 35\n12 36\n11 37\n10 38\n9 39\n8 40\n7 41\n6 42\n5 43\n4 44\n3 45\n2 46\n1 47\n0 48"
},
{
"input": "9 6",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "2 6",
"output": "3\n2 0\n1 1\n0 2"
},
{
"input": "6 4",
"output": "5\n4 0\n3 1\n2 2\n1 3\n0 4"
},
{
"input": "6 10",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "16 5",
"output": "6\n5 0\n4 1\n3 2\n2 3\n1 4\n0 5"
},
{
"input": "7 6",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "3 4",
"output": "4\n3 0\n2 1\n1 2\n0 3"
},
{
"input": "13 18",
"output": "14\n13 0\n12 1\n11 2\n10 3\n9 4\n8 5\n7 6\n6 7\n5 8\n4 9\n3 10\n2 11\n1 12\n0 13"
},
{
"input": "5 100",
"output": "6\n5 0\n4 1\n3 2\n2 3\n1 4\n0 5"
},
{
"input": "11 9",
"output": "10\n9 0\n8 1\n7 2\n6 3\n5 4\n4 5\n3 6\n2 7\n1 8\n0 9"
},
{
"input": "13 13",
"output": "14\n13 0\n12 1\n11 2\n10 3\n9 4\n8 5\n7 6\n6 7\n5 8\n4 9\n3 10\n2 11\n1 12\n0 13"
},
{
"input": "1 5",
"output": "2\n1 0\n0 1"
},
{
"input": "3 19",
"output": "4\n3 0\n2 1\n1 2\n0 3"
},
{
"input": "10 10",
"output": "11\n10 0\n9 1\n8 2\n7 3\n6 4\n5 5\n4 6\n3 7\n2 8\n1 9\n0 10"
},
{
"input": "3 7",
"output": "4\n3 0\n2 1\n1 2\n0 3"
},
{
"input": "98 76",
"output": "77\n76 0\n75 1\n74 2\n73 3\n72 4\n71 5\n70 6\n69 7\n68 8\n67 9\n66 10\n65 11\n64 12\n63 13\n62 14\n61 15\n60 16\n59 17\n58 18\n57 19\n56 20\n55 21\n54 22\n53 23\n52 24\n51 25\n50 26\n49 27\n48 28\n47 29\n46 30\n45 31\n44 32\n43 33\n42 34\n41 35\n40 36\n39 37\n38 38\n37 39\n36 40\n35 41\n34 42\n33 43\n32 44\n31 45\n30 46\n29 47\n28 48\n27 49\n26 50\n25 51\n24 52\n23 53\n22 54\n21 55\n20 56\n19 57\n18 58\n17 59\n16 60\n15 61\n14 62\n13 63\n12 64\n11 65\n10 66\n9 67\n8 68\n7 69\n6 70\n5 71\n4 72\n3 73\n2 74\n..."
},
{
"input": "10 100",
"output": "11\n10 0\n9 1\n8 2\n7 3\n6 4\n5 5\n4 6\n3 7\n2 8\n1 9\n0 10"
}
] | 1,682,570,676 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n,m=map(int,input().split())
z=min(m,n)+1
print(z)
for i in range(z+1):
if i==z:
print(z,0)
else:
print(i,i+1) | Title: Beautiful Sets of Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions:
1. The coordinates of each point in the set are integers. 1. For any two points from the set, the distance between them is a non-integer.
Consider all points (*x*,<=*y*) which satisfy the inequations: 0<=≤<=*x*<=≤<=*n*; 0<=≤<=*y*<=≤<=*m*; *x*<=+<=*y*<=><=0. Choose their subset of maximum size such that it is also a beautiful set of points.
Input Specification:
The single line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Output Specification:
In the first line print a single integer — the size *k* of the found beautiful set. In each of the next *k* lines print a pair of space-separated integers — the *x*- and *y*- coordinates, respectively, of a point from the set.
If there are several optimal solutions, you may print any of them.
Demo Input:
['2 2\n', '4 3\n']
Demo Output:
['3\n0 1\n1 2\n2 0\n', '4\n0 3\n2 1\n3 0\n4 2\n']
Note:
Consider the first sample. The distance between points (0, 1) and (1, 2) equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bfe16f27ebc966df6f10ba356a1547b6e7242dd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (0, 1) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (1, 2) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. | ```python
n,m=map(int,input().split())
z=min(m,n)+1
print(z)
for i in range(z+1):
if i==z:
print(z,0)
else:
print(i,i+1)
``` | 0 |
|
627 | C | Package Delivery | PROGRAMMING | 2,200 | [
"data structures",
"divide and conquer",
"greedy"
] | null | null | Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point *d*.
Johnny's truck has a gas tank that holds exactly *n* liters, and his tank is initially full. As he drives, the truck consumes exactly one liter per unit distance traveled. Moreover, there are *m* gas stations located at various points along the way to the district center. The *i*-th station is located at the point *x**i* on the number line and sells an unlimited amount of fuel at a price of *p**i* dollars per liter. Find the minimum cost Johnny must pay for fuel to successfully complete the delivery. | The first line of input contains three space separated integers *d*, *n*, and *m* (1<=≤<=*n*<=≤<=*d*<=≤<=109, 1<=≤<=*m*<=≤<=200 000) — the total distance to the district center, the volume of the gas tank, and the number of gas stations, respectively.
Each of the next *m* lines contains two integers *x**i*, *p**i* (1<=≤<=*x**i*<=≤<=*d*<=-<=1, 1<=≤<=*p**i*<=≤<=106) — the position and cost of gas at the *i*-th gas station. It is guaranteed that the positions of the gas stations are distinct. | Print a single integer — the minimum cost to complete the delivery. If there is no way to complete the delivery, print -1. | [
"10 4 4\n3 5\n5 8\n6 3\n8 4\n",
"16 5 2\n8 2\n5 1\n"
] | [
"22\n",
"-1\n"
] | In the first sample, Johnny's truck holds 4 liters. He can drive 3 units to the first gas station, buy 2 liters of gas there (bringing the tank to 3 liters total), drive 3 more units to the third gas station, buy 4 liters there to fill up his tank, and then drive straight to the district center. His total cost is 2·5 + 4·3 = 22 dollars.
In the second sample, there is no way for Johnny to make it to the district center, as his tank cannot hold enough gas to take him from the latest gas station to the district center. | 1,500 | [
{
"input": "10 4 4\n3 5\n5 8\n6 3\n8 4",
"output": "22"
},
{
"input": "16 5 2\n8 2\n5 1",
"output": "-1"
},
{
"input": "400000000 400000000 3\n1 139613\n19426 13509\n246298622 343529",
"output": "0"
},
{
"input": "229 123 2\n170 270968\n76 734741",
"output": "50519939"
},
{
"input": "153 105 1\n96 83995",
"output": "4031760"
},
{
"input": "281 12 23\n178 650197\n129 288456\n34 924882\n43 472160\n207 957083\n103 724815\n167 308008\n135 906958\n74 242828\n229 146026\n85 241042\n22 39127\n62 47524\n113 760274\n156 562141\n10 209057\n50 714473\n201 164128\n97 624021\n120 102709\n147 388268\n219 933977\n190 950684",
"output": "-1"
}
] | 1,539,587,560 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | d, n, m = map(int, input().split())
def decSub(A):
p, ans = 0, [A[0]]
for i in range(len(A)):
if A[i][1] < A[p][1]:
p = i
ans.append(A[i])
return(ans)
def Ans(A):
toStart = 0
for a in A:
if n >= a[0]:
toStart += 1
if toStart == 0:
return(-1)
ans = (A[toStart][0]-n)*A[toStart-1][1]
for i in range(toStart+1, len(A)):
ans += (A[i][0]-A[i-1][0])*A[i-1][1]
return ans
A = []
for i in range(m):
x, p = map(int, input().split())
A.append((x,p))
A.append((d,0))
A.sort()
#print(A)
toVisit = decSub(A)
#print(toVisit)
print(Ans(toVisit))
| Title: Package Delivery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point *d*.
Johnny's truck has a gas tank that holds exactly *n* liters, and his tank is initially full. As he drives, the truck consumes exactly one liter per unit distance traveled. Moreover, there are *m* gas stations located at various points along the way to the district center. The *i*-th station is located at the point *x**i* on the number line and sells an unlimited amount of fuel at a price of *p**i* dollars per liter. Find the minimum cost Johnny must pay for fuel to successfully complete the delivery.
Input Specification:
The first line of input contains three space separated integers *d*, *n*, and *m* (1<=≤<=*n*<=≤<=*d*<=≤<=109, 1<=≤<=*m*<=≤<=200 000) — the total distance to the district center, the volume of the gas tank, and the number of gas stations, respectively.
Each of the next *m* lines contains two integers *x**i*, *p**i* (1<=≤<=*x**i*<=≤<=*d*<=-<=1, 1<=≤<=*p**i*<=≤<=106) — the position and cost of gas at the *i*-th gas station. It is guaranteed that the positions of the gas stations are distinct.
Output Specification:
Print a single integer — the minimum cost to complete the delivery. If there is no way to complete the delivery, print -1.
Demo Input:
['10 4 4\n3 5\n5 8\n6 3\n8 4\n', '16 5 2\n8 2\n5 1\n']
Demo Output:
['22\n', '-1\n']
Note:
In the first sample, Johnny's truck holds 4 liters. He can drive 3 units to the first gas station, buy 2 liters of gas there (bringing the tank to 3 liters total), drive 3 more units to the third gas station, buy 4 liters there to fill up his tank, and then drive straight to the district center. His total cost is 2·5 + 4·3 = 22 dollars.
In the second sample, there is no way for Johnny to make it to the district center, as his tank cannot hold enough gas to take him from the latest gas station to the district center. | ```python
d, n, m = map(int, input().split())
def decSub(A):
p, ans = 0, [A[0]]
for i in range(len(A)):
if A[i][1] < A[p][1]:
p = i
ans.append(A[i])
return(ans)
def Ans(A):
toStart = 0
for a in A:
if n >= a[0]:
toStart += 1
if toStart == 0:
return(-1)
ans = (A[toStart][0]-n)*A[toStart-1][1]
for i in range(toStart+1, len(A)):
ans += (A[i][0]-A[i-1][0])*A[i-1][1]
return ans
A = []
for i in range(m):
x, p = map(int, input().split())
A.append((x,p))
A.append((d,0))
A.sort()
#print(A)
toVisit = decSub(A)
#print(toVisit)
print(Ans(toVisit))
``` | 0 |
|
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo"
},
{
"input": "805",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1000",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1",
"output": "O"
},
{
"input": "2",
"output": "OO"
},
{
"input": "3",
"output": "OOO"
},
{
"input": "5",
"output": "OOOoO"
},
{
"input": "17",
"output": "OOOoOooOooooOoooo"
},
{
"input": "49",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo"
},
{
"input": "256",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo"
},
{
"input": "512",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "933",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "61",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo"
},
{
"input": "781",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "999",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
}
] | 1,583,905,221 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 109 | 307,200 | n = int(input())
v = [1,1]
z =[]
a,b = 1,1
for i in range(n):
a,b=b,a+b
v.append(b)
for j in range(1,n+1):
if j in v:
z.append("O")
else:
z.append("o")
print("".join(z)) | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
Input Specification:
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
Print Eleven's new name on the first and only line of output.
Demo Input:
['8\n', '15\n']
Demo Output:
['OOOoOooO\n', 'OOOoOooOooooOoo\n']
Note:
none | ```python
n = int(input())
v = [1,1]
z =[]
a,b = 1,1
for i in range(n):
a,b=b,a+b
v.append(b)
for j in range(1,n+1):
if j in v:
z.append("O")
else:
z.append("o")
print("".join(z))
``` | 3 |
|
415 | B | Mashmokh and Tokens | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"implementation",
"math"
] | null | null | Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars.
Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save. | The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109). | Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day. | [
"5 1 4\n12 6 11 9 1\n",
"3 1 2\n1 2 3\n",
"1 1 1\n1\n"
] | [
"0 2 3 1 1 ",
"1 0 1 ",
"0 "
] | none | 1,000 | [
{
"input": "5 1 4\n12 6 11 9 1",
"output": "0 2 3 1 1 "
},
{
"input": "3 1 2\n1 2 3",
"output": "1 0 1 "
},
{
"input": "1 1 1\n1",
"output": "0 "
},
{
"input": "1 1 1000000000\n1000000000",
"output": "0 "
},
{
"input": "1 1 1000000000\n999999999",
"output": "999999999 "
},
{
"input": "10 1 100000000\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999",
"output": "99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 "
}
] | 1,397,643,680 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 171 | 5,836,800 | __author__ = 'Lipen'
def main():
n, a, b = map(int, input().split())
x = list(map(int, input().split()))
answer = list(map(lambda i: round( ( x[i] * a/b - int(x[i] * a/b) ) / a*b ), range(n)))
print(' '.join(map(str, answer)))
main() | Title: Mashmokh and Tokens
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars.
Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save.
Input Specification:
The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109).
Output Specification:
Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day.
Demo Input:
['5 1 4\n12 6 11 9 1\n', '3 1 2\n1 2 3\n', '1 1 1\n1\n']
Demo Output:
['0 2 3 1 1 ', '1 0 1 ', '0 ']
Note:
none | ```python
__author__ = 'Lipen'
def main():
n, a, b = map(int, input().split())
x = list(map(int, input().split()))
answer = list(map(lambda i: round( ( x[i] * a/b - int(x[i] * a/b) ) / a*b ), range(n)))
print(' '.join(map(str, answer)))
main()
``` | 0 |
|
3 | C | Tic-tac-toe | PROGRAMMING | 1,800 | [
"brute force",
"games",
"implementation"
] | C. Tic-tac-toe | 1 | 64 | Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.
You are given a 3<=×<=3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
- illegal — if the given board layout can't appear during a valid game; - the first player won — if in the given board layout the first player has just won; - the second player won — if in the given board layout the second player has just won; - draw — if the given board layout has just let to a draw. | The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero). | Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw. | [
"X0X\n.0.\n.X.\n"
] | [
"second\n"
] | none | 0 | [
{
"input": "X0X\n.0.\n.X.",
"output": "second"
},
{
"input": "0.X\nXX.\n000",
"output": "illegal"
},
{
"input": "XXX\n.0.\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n000",
"output": "illegal"
},
{
"input": "X.X\nX..\n00.",
"output": "second"
},
{
"input": "X.X\nX.0\n0.0",
"output": "first"
},
{
"input": "XXX\nX00\nX00",
"output": "the first player won"
},
{
"input": "000\nX.X\nX.X",
"output": "illegal"
},
{
"input": "XXX\n0.0\n0..",
"output": "illegal"
},
{
"input": "X0X\n0X0\nX0X",
"output": "the first player won"
},
{
"input": "XX.\nX0X\nX..",
"output": "illegal"
},
{
"input": "X0X\n0X0\nX..",
"output": "the first player won"
},
{
"input": "XX0\n0..\n000",
"output": "illegal"
},
{
"input": "XXX\n0..\n.0.",
"output": "the first player won"
},
{
"input": "XXX\nX..\n.00",
"output": "illegal"
},
{
"input": "X00\n0.0\nXX0",
"output": "illegal"
},
{
"input": "0.0\n0XX\n..0",
"output": "illegal"
},
{
"input": ".00\nX.X\n0..",
"output": "illegal"
},
{
"input": "..0\n.00\n.0X",
"output": "illegal"
},
{
"input": "..0\n0..\n00X",
"output": "illegal"
},
{
"input": "..0\n.XX\nX..",
"output": "illegal"
},
{
"input": "0.X\n0X0\n.00",
"output": "illegal"
},
{
"input": "..X\n0X0\n0X.",
"output": "first"
},
{
"input": "0X0\nX..\nX.0",
"output": "first"
},
{
"input": ".0.\nX.X\n0..",
"output": "first"
},
{
"input": "0X0\n00X\n.00",
"output": "illegal"
},
{
"input": ".0.\n.X0\nX..",
"output": "first"
},
{
"input": "00X\n0.X\n00X",
"output": "illegal"
},
{
"input": "00X\n0XX\n0X.",
"output": "the second player won"
},
{
"input": "X00\n..0\nX.X",
"output": "first"
},
{
"input": "X00\nX00\n.X0",
"output": "illegal"
},
{
"input": "X0X\n.X0\n0..",
"output": "first"
},
{
"input": "..0\nXXX\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n.0.",
"output": "illegal"
},
{
"input": "0..\n000\nX0X",
"output": "illegal"
},
{
"input": ".00\n0X.\n0.0",
"output": "illegal"
},
{
"input": "X..\nX00\n0.0",
"output": "illegal"
},
{
"input": ".X0\nXX0\nX.X",
"output": "illegal"
},
{
"input": "X.X\n0.0\nX..",
"output": "second"
},
{
"input": "00X\n.00\n..0",
"output": "illegal"
},
{
"input": "..0\n0.X\n00.",
"output": "illegal"
},
{
"input": "0.X\nX0X\n.X0",
"output": "illegal"
},
{
"input": "0X.\n.X.\n0X0",
"output": "illegal"
},
{
"input": "00.\nX0.\n..X",
"output": "illegal"
},
{
"input": "..X\n.00\nXX.",
"output": "second"
},
{
"input": ".00\n.0.\n.X.",
"output": "illegal"
},
{
"input": "XX0\nX.0\nXX0",
"output": "illegal"
},
{
"input": "00.\n00.\nX.X",
"output": "illegal"
},
{
"input": "X00\nX.0\nX.0",
"output": "illegal"
},
{
"input": "0X.\n0XX\n000",
"output": "illegal"
},
{
"input": "00.\n00.\n.X.",
"output": "illegal"
},
{
"input": "X0X\n00.\n0.X",
"output": "illegal"
},
{
"input": "XX0\nXXX\n0X0",
"output": "illegal"
},
{
"input": "XX0\n..X\nXX0",
"output": "illegal"
},
{
"input": "0X.\n..X\nX..",
"output": "illegal"
},
{
"input": "...\nX0.\nXX0",
"output": "second"
},
{
"input": "..X\n.0.\n0..",
"output": "illegal"
},
{
"input": "00X\nXX.\n00X",
"output": "first"
},
{
"input": "..0\nXX0\n..X",
"output": "second"
},
{
"input": ".0.\n.00\nX00",
"output": "illegal"
},
{
"input": "X00\n.XX\n00.",
"output": "illegal"
},
{
"input": ".00\n0.X\n000",
"output": "illegal"
},
{
"input": "X0.\n..0\nX.0",
"output": "illegal"
},
{
"input": "X0X\n.XX\n00.",
"output": "second"
},
{
"input": "0X.\n00.\n.X.",
"output": "illegal"
},
{
"input": ".0.\n...\n0.0",
"output": "illegal"
},
{
"input": "..X\nX00\n0.0",
"output": "illegal"
},
{
"input": "0XX\n...\nX0.",
"output": "second"
},
{
"input": "X.X\n0X.\n.0X",
"output": "illegal"
},
{
"input": "XX0\nX.X\n00.",
"output": "second"
},
{
"input": ".0X\n.00\n00.",
"output": "illegal"
},
{
"input": ".XX\nXXX\n0..",
"output": "illegal"
},
{
"input": "XX0\n.X0\n.0.",
"output": "first"
},
{
"input": "X00\n0.X\nX..",
"output": "first"
},
{
"input": "X..\n.X0\nX0.",
"output": "second"
},
{
"input": ".0X\nX..\nXXX",
"output": "illegal"
},
{
"input": "X0X\nXXX\nX.X",
"output": "illegal"
},
{
"input": ".00\nX0.\n00X",
"output": "illegal"
},
{
"input": "0XX\n.X0\n0.0",
"output": "illegal"
},
{
"input": "00X\nXXX\n..0",
"output": "the first player won"
},
{
"input": "X0X\n...\n.X.",
"output": "illegal"
},
{
"input": ".X0\n...\n0X.",
"output": "first"
},
{
"input": "X..\n0X0\nX.0",
"output": "first"
},
{
"input": "..0\n.00\nX.0",
"output": "illegal"
},
{
"input": ".XX\n.0.\nX0X",
"output": "illegal"
},
{
"input": "00.\n0XX\n..0",
"output": "illegal"
},
{
"input": ".0.\n00.\n00.",
"output": "illegal"
},
{
"input": "00.\n000\nX.X",
"output": "illegal"
},
{
"input": "0X0\n.X0\n.X.",
"output": "illegal"
},
{
"input": "00X\n0..\n0..",
"output": "illegal"
},
{
"input": ".X.\n.X0\nX.0",
"output": "second"
},
{
"input": ".0.\n0X0\nX0X",
"output": "illegal"
},
{
"input": "...\nX.0\n0..",
"output": "illegal"
},
{
"input": "..0\nXX.\n00X",
"output": "first"
},
{
"input": "0.X\n.0X\nX00",
"output": "illegal"
},
{
"input": "..X\n0X.\n.0.",
"output": "first"
},
{
"input": "..X\nX.0\n.0X",
"output": "second"
},
{
"input": "X0.\n.0X\nX0X",
"output": "illegal"
},
{
"input": "...\n.0.\n.X0",
"output": "illegal"
},
{
"input": ".X0\nXX0\n0..",
"output": "first"
},
{
"input": "0X.\n...\nX..",
"output": "second"
},
{
"input": ".0.\n0.0\n0.X",
"output": "illegal"
},
{
"input": "XX.\n.X0\n.0X",
"output": "illegal"
},
{
"input": ".0.\nX0X\nX00",
"output": "illegal"
},
{
"input": "0X.\n.X0\nX..",
"output": "second"
},
{
"input": "..0\n0X.\n000",
"output": "illegal"
},
{
"input": "0.0\nX.X\nXX.",
"output": "illegal"
},
{
"input": ".X.\n.XX\nX0.",
"output": "illegal"
},
{
"input": "X.X\n.XX\n0X.",
"output": "illegal"
},
{
"input": "X.0\n0XX\n..0",
"output": "first"
},
{
"input": "X.0\n0XX\n.X0",
"output": "second"
},
{
"input": "X00\n0XX\n.X0",
"output": "first"
},
{
"input": "X00\n0XX\nXX0",
"output": "draw"
},
{
"input": "X00\n0XX\n0X0",
"output": "illegal"
},
{
"input": "XXX\nXXX\nXXX",
"output": "illegal"
},
{
"input": "000\n000\n000",
"output": "illegal"
},
{
"input": "XX0\n00X\nXX0",
"output": "draw"
},
{
"input": "X00\n00X\nXX0",
"output": "illegal"
},
{
"input": "X.0\n00.\nXXX",
"output": "the first player won"
},
{
"input": "X..\nX0.\nX0.",
"output": "the first player won"
},
{
"input": ".XX\n000\nXX0",
"output": "the second player won"
},
{
"input": "X0.\nX.X\nX00",
"output": "the first player won"
},
{
"input": "00X\nX00\nXXX",
"output": "the first player won"
},
{
"input": "XXX\n.00\nX0.",
"output": "the first player won"
},
{
"input": "XX0\n000\nXX.",
"output": "the second player won"
},
{
"input": ".X0\n0.0\nXXX",
"output": "the first player won"
},
{
"input": "0XX\nX00\n0XX",
"output": "draw"
},
{
"input": "0XX\nX0X\n00X",
"output": "the first player won"
},
{
"input": "XX0\n0XX\n0X0",
"output": "the first player won"
},
{
"input": "0X0\nX0X\nX0X",
"output": "draw"
},
{
"input": "X0X\n0XX\n00X",
"output": "the first player won"
},
{
"input": "0XX\nX0.\nX00",
"output": "the second player won"
},
{
"input": "X.0\n0X0\nXX0",
"output": "the second player won"
},
{
"input": "X0X\nX0X\n0X0",
"output": "draw"
},
{
"input": "X.0\n00X\n0XX",
"output": "the second player won"
},
{
"input": "00X\nX0X\n.X0",
"output": "the second player won"
},
{
"input": "X0X\n.00\nX0X",
"output": "the second player won"
},
{
"input": "0XX\nX00\nX0X",
"output": "draw"
},
{
"input": "000\nX0X\n.XX",
"output": "the second player won"
},
{
"input": "0.0\n0.X\nXXX",
"output": "the first player won"
},
{
"input": "X.0\nX0.\n0X.",
"output": "the second player won"
},
{
"input": "X0X\n0X0\n..X",
"output": "the first player won"
},
{
"input": "0X0\nXX0\n.X.",
"output": "the first player won"
},
{
"input": "X0.\n.X.\n0.X",
"output": "the first player won"
},
{
"input": "0XX\nX00\n.X0",
"output": "the second player won"
},
{
"input": "0.0\nXXX\n0.X",
"output": "the first player won"
},
{
"input": ".0X\n.X.\nX.0",
"output": "the first player won"
},
{
"input": "XXX\nX.0\n0.0",
"output": "the first player won"
},
{
"input": "XX0\nX..\nX00",
"output": "the first player won"
},
{
"input": "XXX\n00X\n00X",
"output": "the first player won"
},
{
"input": "X00\n00X\nXXX",
"output": "the first player won"
},
{
"input": "0X0\nX0X\n0X.",
"output": "the second player won"
},
{
"input": "XX0\nX00\n0X.",
"output": "the second player won"
},
{
"input": "..X\n0X0\nX..",
"output": "the first player won"
},
{
"input": "X0.\n00.\nXXX",
"output": "the first player won"
},
{
"input": "0.X\nX00\nXX0",
"output": "the second player won"
},
{
"input": "X0.\n0X.\n..X",
"output": "the first player won"
},
{
"input": "00X\nX0.\nXX0",
"output": "the second player won"
},
{
"input": "XX.\n000\n0XX",
"output": "the second player won"
},
{
"input": "..X\n0.X\n.0X",
"output": "the first player won"
},
{
"input": "X00\n.0X\n0XX",
"output": "the second player won"
},
{
"input": "00X\n0X.\nXX.",
"output": "the first player won"
},
{
"input": "X00\nXX.\n0.X",
"output": "the first player won"
},
{
"input": "XXX\n00X\n0X0",
"output": "the first player won"
},
{
"input": "X00\nXX0\n0XX",
"output": "the first player won"
},
{
"input": "0X0\nX00\nXXX",
"output": "the first player won"
},
{
"input": "XX0\nX00\n.X0",
"output": "the second player won"
}
] | 1,653,865,344 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 154 | 0 | s = []
cnt1 = cnt2 = 0
s.append(input())
s.append(input())
s.append(input())
for i in range(3):
for j in range(3):
if s[i][j] == 'X':
cnt1 += 1
elif s[i][j] == '0':
cnt2 += 1
def judgeRow(i):
return s[i][0] == s[i][1] and s[i][0] == s[i][2] and s[i][0] != '.'
def judgeCol(i):
return s[0][i] == s[1][i] and s[0][i] == s[2][i] and s[0][i] != '.'
def judge():
p1 = 0
p2 = 0
for i in range(3):
if judgeRow(i):
if s[i][0] == 'X':
p1 += 1
else:
p2 += 1
for i in range(3):
if judgeCol(i):
if s[0][i] == 'X':
p1 += 1
else:
p2 += 1
if s[0][0] == s[1][1] and s[1][1] == s[2][2] and s[0][0] != '.':
if s[1][1] == 'X':
p1 += 1
else:
p2 += 1
if s[0][2] == s[1][1] and s[2][0] == s[1][1] and s[1][1] != '.':
if s[1][1] == 'X':
p1 += 1
else:
p2 += 1
return [p1, p2]
res = judge()
if cnt1 < cnt2 or cnt1 - cnt2 >= 2 or (res[0] > 0 and res[1] > 0):
print('illegal')
else:
if res[0] > 0:
print('the first player won')
elif res[1] > 0:
print('the second player won')
elif cnt1 + cnt2 == 9:
print('draw')
else:
print(cnt1 > cnt2 and 'second' or 'first') | Title: Tic-tac-toe
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.
You are given a 3<=×<=3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
- illegal — if the given board layout can't appear during a valid game; - the first player won — if in the given board layout the first player has just won; - the second player won — if in the given board layout the second player has just won; - draw — if the given board layout has just let to a draw.
Input Specification:
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Output Specification:
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
Demo Input:
['X0X\n.0.\n.X.\n']
Demo Output:
['second\n']
Note:
none | ```python
s = []
cnt1 = cnt2 = 0
s.append(input())
s.append(input())
s.append(input())
for i in range(3):
for j in range(3):
if s[i][j] == 'X':
cnt1 += 1
elif s[i][j] == '0':
cnt2 += 1
def judgeRow(i):
return s[i][0] == s[i][1] and s[i][0] == s[i][2] and s[i][0] != '.'
def judgeCol(i):
return s[0][i] == s[1][i] and s[0][i] == s[2][i] and s[0][i] != '.'
def judge():
p1 = 0
p2 = 0
for i in range(3):
if judgeRow(i):
if s[i][0] == 'X':
p1 += 1
else:
p2 += 1
for i in range(3):
if judgeCol(i):
if s[0][i] == 'X':
p1 += 1
else:
p2 += 1
if s[0][0] == s[1][1] and s[1][1] == s[2][2] and s[0][0] != '.':
if s[1][1] == 'X':
p1 += 1
else:
p2 += 1
if s[0][2] == s[1][1] and s[2][0] == s[1][1] and s[1][1] != '.':
if s[1][1] == 'X':
p1 += 1
else:
p2 += 1
return [p1, p2]
res = judge()
if cnt1 < cnt2 or cnt1 - cnt2 >= 2 or (res[0] > 0 and res[1] > 0):
print('illegal')
else:
if res[0] > 0:
print('the first player won')
elif res[1] > 0:
print('the second player won')
elif cnt1 + cnt2 == 9:
print('draw')
else:
print(cnt1 > cnt2 and 'second' or 'first')
``` | 0 |
18 | D | Seller Bob | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"greedy"
] | D. Seller Bob | 2 | 128 | Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.
Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally. | The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | [
"7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n",
"3\nwin 5\nsell 6\nsell 4\n"
] | [
"1056\n",
"0\n"
] | none | 0 | [
{
"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10",
"output": "1056"
},
{
"input": "3\nwin 5\nsell 6\nsell 4",
"output": "0"
},
{
"input": "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23\nsell 23\nwin 22\nsell 22\nwin 21\nsell 21\nwin 20\nsell 20\nwin 19\nsell 19\nwin 18\nsell 18\nwin 17\nsell 17\nwin 16\nsell 16\nwin 15\nsell 15\nwin 14\nsell 14\nwin 13\nsell 13\nwin 12\nsell 12\nwin 11\nsell 11\nwin 10\nsell 10\nwin 9\nsell 9\nwin 8\nsell 8\nwin 7\nsell 7\nwin 6\nsell 6\nwin 5\nsell 5\nwin 4\nsell 4\nwin 3\nsell 3\nwin 2\nsell 2\nwin 1\nsell 1",
"output": "2147483646"
},
{
"input": "10\nsell 179\nwin 1278\nsell 1278\nwin 179\nwin 788\nsell 788\nwin 1819\nwin 1278\nsell 1454\nsell 1819",
"output": "3745951177859672748085876072016755224158263650470541376602416977749506433342393741012551962469399005106980957564747771946546075632634156222832360666586993197712597743102870994304893421406288896658113922358079050393796282759740479830789771109056742931607432542704338811780614109483471170758503563410473205320757445249359340913055427891395101189449739249593088482768598397566812797391842205760535689034164783939977837838115215972505331175064745799973957898910533590618104893265678599370512439216359131269814745054..."
},
{
"input": "10\nsell 573\nwin 1304\nsell 278\nwin 1631\nsell 1225\nsell 1631\nsell 177\nwin 1631\nwin 177\nsell 1304",
"output": "95482312335125227379668481690754940528280513838693267460502082967052005332103697568042408703168913727303170456338425853153094403747135188778307041838920404959089576368946137708987138986696495077466398994298434148881715073638178666201165545650953479735059082316661443204882826188032944866093372620219104327689636641547141835841165681118172603993695103043804276669836594061369229043451067647935298287687852302215923887110435577776767805943668204998410716005202198549540411238299513630278811648"
},
{
"input": "10\nwin 1257\nwin 1934\nsell 1934\nsell 1257\nwin 1934\nwin 1257\nsell 495\nwin 495\nwin 495\nwin 1257",
"output": "1556007242642049292787218246793379348327505438878680952714050868520307364441227819009733220897932984584977593931988662671459594674963394056587723382487766303981362587048873128400436836690128983570130687310221668877557121158055843621982630476422478413285775826498536883275291967793661985813155062733063913176306327509625594121241472451054995889483447103432414676059872469910105149496451402271546454282618581884282152530090816240540173251729211604658704990425330422792556824836640431985211146197816770068601144273..."
},
{
"input": "10\nsell 1898\nsell 173\nsell 1635\nsell 29\nsell 881\nsell 434\nsell 1236\nsell 14\nwin 29\nsell 1165",
"output": "0"
},
{
"input": "50\nwin 1591\nwin 312\nwin 1591\nwin 1277\nwin 1732\nwin 1277\nwin 312\nwin 1591\nwin 210\nwin 1591\nwin 210\nsell 1732\nwin 312\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 210\nwin 1732\nwin 1732\nwin 1591\nwin 1732\nwin 312\nwin 1732\nsell 1277\nwin 1732\nwin 210\nwin 1277\nwin 1277\nwin 312\nwin 1732\nsell 312\nsell 1591\nwin 312\nsell 210\nwin 1732\nwin 312\nwin 210\nwin 1591\nwin 1591\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 1277\nwin 1591\nwin 210\nwin 1277\nwin 1732\nwin 312",
"output": "2420764210856015331214801822295882718446835865177072936070024961324113887299407742968459201784200628346247573017634417460105466317641563795817074771860850712020768123310899251645626280515264270127874292153603360689565451372953171008749749476807656127914801962353129980445541683621172887240439496869443980760905844921588668701053404581445092887732985786593080332302468009347364906506742888063949158794894756704243685813947581549214136427388148927087858952333440295415050590550479915766637705353193400817849524933..."
},
{
"input": "50\nwin 596\nwin 1799\nwin 1462\nsell 460\nwin 731\nwin 723\nwin 731\nwin 329\nwin 838\nsell 728\nwin 728\nwin 460\nwin 723\nwin 1462\nwin 1462\nwin 460\nwin 329\nwin 1462\nwin 460\nwin 460\nwin 723\nwin 731\nwin 723\nwin 596\nwin 731\nwin 596\nwin 329\nwin 728\nwin 715\nwin 329\nwin 1799\nwin 715\nwin 723\nwin 728\nwin 1462\nwin 596\nwin 728\nsell 1462\nsell 731\nsell 723\nsell 596\nsell 1799\nwin 715\nsell 329\nsell 715\nwin 731\nwin 596\nwin 596\nwin 1799\nsell 838",
"output": "3572417428836510418020130226151232933195365572424451233484665849446779664366143933308174097508811001879673917355296871134325099594720989439804421106898301313126179907518635998806895566124222305730664245219198882158809677890894851351153171006242601699481340338225456896495739360268670655803862712132671163869311331357956008411198419420320449558787147867731519734760711196755523479867536729489438488681378976579126837971468043235641314636566999618274861697304906262004280314028540891222536060126170572182168995779..."
},
{
"input": "50\nwin 879\nwin 1153\nwin 1469\nwin 157\nwin 827\nwin 679\nsell 1229\nwin 454\nsell 879\nsell 1222\nwin 924\nwin 827\nsell 1366\nwin 879\nsell 754\nwin 1153\nwin 679\nwin 1185\nsell 1469\nsell 454\nsell 679\nsell 1153\nwin 1469\nwin 827\nwin 1469\nwin 1024\nwin 1222\nsell 157\nsell 1185\nsell 827\nwin 1469\nsell 1569\nwin 754\nsell 1024\nwin 924\nwin 924\nsell 1876\nsell 479\nsell 435\nwin 754\nwin 174\nsell 174\nsell 147\nsell 924\nwin 1469\nwin 1876\nwin 1229\nwin 1469\nwin 1222\nwin 157",
"output": "16332912310228701097717316802721870128775022868221080314403305773060286348016616983179506327297989866534783694332203603069900790667846028602603898749788769867206327097934433881603593880774778104853105937620753202513845830781396468839434689035327911539335925798473899153215505268301939672678983012311225261177070282290958328569587449928340374890197297462448526671963786572758011646874155763250281850311510811863346015732742889066278088442118144"
},
{
"input": "50\nsell 1549\nwin 1168\nsell 1120\nwin 741\nsell 633\nwin 274\nsell 1936\nwin 1168\nsell 614\nwin 33\nsell 1778\nwin 127\nsell 1168\nwin 33\nwin 633\nsell 1474\nwin 518\nwin 1685\nsell 1796\nsell 741\nsell 485\nwin 747\nsell 588\nsell 1048\nwin 1580\nwin 60\nsell 1685\nsell 1580\nsell 1535\nwin 485\nsell 31\nsell 747\nsell 1473\nsell 518\nwin 633\nsell 1313\nwin 1580\nsell 1560\nsell 127\nsell 274\nwin 123\nwin 31\nsell 123\nsell 33\nwin 1778\nsell 1834\nsell 60\nsell 1751\nsell 1287\nwin 1549",
"output": "1720056425011773151265118871077591733216276990085092619030835675616738576936900493041118761959770055340668032173576279597675976622004777210845027112875371906527379337573212312341811682481516081119925150514042583039122963732518350292624889782510925425243478590699982487521431988980734651291693696303059520879874887472437061826782122289965998009474317347011699360401227487786089319043200666474560882786695043543699741809763479940250459103751744852630592882730442346682844070898735881280272505893611419620868096"
},
{
"input": "1\nsell 2000",
"output": "0"
},
{
"input": "1\nwin 2000",
"output": "0"
},
{
"input": "2\nwin 2000\nsell 2000",
"output": "1148130695274254524232833201177681984022317702088695200477642736825766261392370313856659486316506269918445964638987462773447118960863055331425931356166653185391299891453122800006887791482400448714289269900634862447816154636463883639473170260404663539709049965581623988089446296056233116495361642219703326813441689089844585056023794848079140589009347765004290027167066258305220081322362812917612678833172065989953964181270217798584040421598531832515408894339020919205549577835896720391600819572166305827553804255..."
}
] | 1,571,819,893 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 436 | 3,584,000 | import math
def solve():
n = int(input())
ans = 0
idx = [0]*2005
dp = [0]*5005
for i in range(1,n+1):
opt, x = input().split()
x = int(x)
dp[i] = dp[i-1]
if opt == "win":
idx[x] = i
else :
if idx[x] != 0:
dp[i] = max(dp[i], dp[idx[x]-1] + 2**x)
print(dp[n])
if __name__ == '__main__':
solve()
| Title: Seller Bob
Time Limit: 2 seconds
Memory Limit: 128 megabytes
Problem Description:
Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.
Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally.
Input Specification:
The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000).
Output Specification:
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
Demo Input:
['7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n', '3\nwin 5\nsell 6\nsell 4\n']
Demo Output:
['1056\n', '0\n']
Note:
none | ```python
import math
def solve():
n = int(input())
ans = 0
idx = [0]*2005
dp = [0]*5005
for i in range(1,n+1):
opt, x = input().split()
x = int(x)
dp[i] = dp[i-1]
if opt == "win":
idx[x] = i
else :
if idx[x] != 0:
dp[i] = max(dp[i], dp[idx[x]-1] + 2**x)
print(dp[n])
if __name__ == '__main__':
solve()
``` | 3.877649 |
505 | B | Mr. Kitayuta's Colorful Graph | PROGRAMMING | 1,400 | [
"dfs and similar",
"dp",
"dsu",
"graphs"
] | null | null | Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he gives you two integers — *u**i* and *v**i*.
Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly. | The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*).
The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries.
Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*. | For each query, print the answer in a separate line. | [
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n"
] | [
"2\n1\n0\n",
"1\n1\n1\n1\n2\n"
] | Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | 1,000 | [
{
"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4",
"output": "2\n1\n0"
},
{
"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4",
"output": "1\n1\n1\n1\n2"
},
{
"input": "2 1\n1 2 1\n1\n1 2",
"output": "1"
},
{
"input": "2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2",
"output": "3"
},
{
"input": "2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2",
"output": "5"
}
] | 1,504,798,589 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 307,200 | def solution():
n,m = [int(x) for x in input().split(' ')]
graphs = {}
edges = {}
for i in range(m):
x,y,c = input().split(' ')
if c not in graphs:
graphs[c]={}
if x not in graphs[c]:
graphs[c][x] = []
if y not in graphs[c]:
graphs[c][y] = []
graphs[c][x].append(y)
graphs[c][y].append(x)
q = int(input())
queries = []
for i in range(q):
x,y = input().split(' ')
ans = 0
for c,graph in graphs.items():
ans+=1 if areConnected(x,y,graph) else 0
print(ans)
def areConnected(x,y,graph):
if x not in graph or y not in graph:
return False
queu = [x]
already = [x]
while len(queu) != 0:
current = queu[0]
if current == y:
return True
del queu[0]
already.append(current)
for i in graph[current]:
if i not in already and i not in queu:
if i == y:
return True
queu.append(i)
return False
solution() | Title: Mr. Kitayuta's Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he gives you two integers — *u**i* and *v**i*.
Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly.
Input Specification:
The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*).
The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries.
Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*.
Output Specification:
For each query, print the answer in a separate line.
Demo Input:
['4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n', '5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n']
Demo Output:
['2\n1\n0\n', '1\n1\n1\n1\n2\n']
Note:
Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | ```python
def solution():
n,m = [int(x) for x in input().split(' ')]
graphs = {}
edges = {}
for i in range(m):
x,y,c = input().split(' ')
if c not in graphs:
graphs[c]={}
if x not in graphs[c]:
graphs[c][x] = []
if y not in graphs[c]:
graphs[c][y] = []
graphs[c][x].append(y)
graphs[c][y].append(x)
q = int(input())
queries = []
for i in range(q):
x,y = input().split(' ')
ans = 0
for c,graph in graphs.items():
ans+=1 if areConnected(x,y,graph) else 0
print(ans)
def areConnected(x,y,graph):
if x not in graph or y not in graph:
return False
queu = [x]
already = [x]
while len(queu) != 0:
current = queu[0]
if current == y:
return True
del queu[0]
already.append(current)
for i in graph[current]:
if i not in already and i not in queu:
if i == y:
return True
queu.append(i)
return False
solution()
``` | 3 |
|
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game. | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that. | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "41 12 65",
"output": "1"
},
{
"input": "13 61 100",
"output": "1"
},
{
"input": "100 100 10",
"output": "0"
},
{
"input": "12 24 26",
"output": "1"
},
{
"input": "73 21 96",
"output": "1"
},
{
"input": "17 22 81",
"output": "1"
},
{
"input": "14 88 97",
"output": "1"
},
{
"input": "42 81 17",
"output": "0"
},
{
"input": "34 36 19",
"output": "1"
},
{
"input": "21 87 12",
"output": "1"
},
{
"input": "97 92 98",
"output": "1"
},
{
"input": "49 25 62",
"output": "1"
},
{
"input": "29 17 44",
"output": "1"
},
{
"input": "10 1 10",
"output": "0"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "100 100 1",
"output": "0"
},
{
"input": "11 99 55",
"output": "0"
},
{
"input": "8 13 21",
"output": "0"
},
{
"input": "34 55 89",
"output": "0"
},
{
"input": "21 34 55",
"output": "1"
},
{
"input": "13 21 34",
"output": "1"
},
{
"input": "34 21 55",
"output": "0"
},
{
"input": "10 20 84",
"output": "1"
},
{
"input": "4 2 5",
"output": "0"
},
{
"input": "3 2 3",
"output": "0"
},
{
"input": "31 23 1",
"output": "0"
},
{
"input": "100 100 100",
"output": "0"
},
{
"input": "100 1 100",
"output": "0"
},
{
"input": "1 100 100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "17 23 100",
"output": "1"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "1 1 2",
"output": "1"
},
{
"input": "2 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "2 1 2",
"output": "0"
},
{
"input": "10 10 3",
"output": "1"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "9 5 1",
"output": "0"
}
] | 1,583,333,046 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 280 | 0 | def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
a,b,n=map(int,input().split())
c=0
x=gcd(a,n)
while n>=x:
c+=1
n=n-x
x=gcd(a,n)
if c%2==1:
print('0')
else:
print('1')
| Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game.
Input Specification:
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output Specification:
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Demo Input:
['3 5 9\n', '1 1 100\n']
Demo Output:
['0', '1']
Note:
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that. | ```python
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
a,b,n=map(int,input().split())
c=0
x=gcd(a,n)
while n>=x:
c+=1
n=n-x
x=gcd(a,n)
if c%2==1:
print('0')
else:
print('1')
``` | 0 |
|
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
{
"input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB",
"output": "1"
},
{
"input": "RRGGBRGRBG\nBRRGGBBGGR",
"output": "7"
},
{
"input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG",
"output": "15"
},
{
"input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR",
"output": "8"
},
{
"input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR",
"output": "16"
},
{
"input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR",
"output": "18"
},
{
"input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG",
"output": "23"
},
{
"input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR",
"output": "14"
},
{
"input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG",
"output": "12"
},
{
"input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB",
"output": "12"
},
{
"input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR",
"output": "2"
},
{
"input": "R\nB",
"output": "1"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "50"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
},
{
"input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
}
] | 1,656,796,177 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | x = input()
y = input()
p = 0
for i in y:
if i == x[p]:
p += 1
if p == len(x):
break
print(p + 1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input Specification:
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output Specification:
Print the final 1-based position of Liss in a single line.
Demo Input:
['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n']
Demo Output:
['2\n', '3\n', '15\n']
Note:
none | ```python
x = input()
y = input()
p = 0
for i in y:
if i == x[p]:
p += 1
if p == len(x):
break
print(p + 1)
``` | 3 |
|
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
"output": "1\n1 "
},
{
"input": "2\nBB",
"output": "1\n2 "
},
{
"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB",
"output": "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 "
},
{
"input": "1\nW",
"output": "0"
},
{
"input": "2\nWW",
"output": "0"
},
{
"input": "2\nWB",
"output": "1\n1 "
},
{
"input": "2\nBW",
"output": "1\n1 "
},
{
"input": "3\nBBB",
"output": "1\n3 "
},
{
"input": "3\nBWB",
"output": "2\n1 1 "
},
{
"input": "3\nWBB",
"output": "1\n2 "
},
{
"input": "3\nWWB",
"output": "1\n1 "
},
{
"input": "3\nWBW",
"output": "1\n1 "
},
{
"input": "3\nBWW",
"output": "1\n1 "
},
{
"input": "3\nWWW",
"output": "0"
},
{
"input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB",
"output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 "
},
{
"input": "5\nBBBWB",
"output": "2\n3 1 "
},
{
"input": "5\nBWWWB",
"output": "2\n1 1 "
},
{
"input": "5\nWWWWB",
"output": "1\n1 "
},
{
"input": "5\nBWWWW",
"output": "1\n1 "
},
{
"input": "5\nBBBWW",
"output": "1\n3 "
},
{
"input": "5\nWWBBB",
"output": "1\n3 "
},
{
"input": "10\nBBBBBWWBBB",
"output": "2\n5 3 "
},
{
"input": "10\nBBBBWBBWBB",
"output": "3\n4 2 2 "
},
{
"input": "20\nBBBBBWWBWBBWBWWBWBBB",
"output": "6\n5 1 2 1 1 3 "
},
{
"input": "20\nBBBWWWWBBWWWBWBWWBBB",
"output": "5\n3 2 1 1 3 "
},
{
"input": "20\nBBBBBBBBWBBBWBWBWBBB",
"output": "5\n8 3 1 1 3 "
},
{
"input": "20\nBBBWBWBWWWBBWWWWBWBB",
"output": "6\n3 1 1 2 1 2 "
},
{
"input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB",
"output": "5\n6 1 1 1 12 "
},
{
"input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB",
"output": "9\n5 1 2 1 1 4 1 1 8 "
},
{
"input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB",
"output": "7\n11 1 1 8 1 1 6 "
},
{
"input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW",
"output": "9\n5 1 1 1 1 2 2 1 1 "
},
{
"input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB",
"output": "6\n1 1 1 1 1 5 "
},
{
"input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB",
"output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB",
"output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n100 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB",
"output": "11\n20 1 1 1 2 1 1 1 1 1 20 "
},
{
"input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB",
"output": "11\n4 1 1 1 1 2 1 1 1 1 6 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "10\nWWBWWWBWBB",
"output": "3\n1 1 2 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n17 31 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n24 42 "
},
{
"input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB",
"output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 "
},
{
"input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB",
"output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 "
},
{
"input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB",
"output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 "
},
{
"input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB",
"output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 "
},
{
"input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB",
"output": "11\n1 5 3 4 3 1 1 2 1 2 4 "
}
] | 1,573,047,970 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 124 | 0 | n=int(input())
l=[]
s=input()
q=s[0]
if q=='B':
l.append(1)
for i in range(1,len(s)):
if s[i]!=q:
if q=='W':l.append(1)
q=s[i]
elif s[i]=='B':l[-1]+=1
print(len(l))
if len(l)!=0:print(*l,sep=' ')
| Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
Output Specification:
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
Demo Input:
['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n']
Demo Output:
['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 ']
Note:
The last sample case correspond to the picture in the statement. | ```python
n=int(input())
l=[]
s=input()
q=s[0]
if q=='B':
l.append(1)
for i in range(1,len(s)):
if s[i]!=q:
if q=='W':l.append(1)
q=s[i]
elif s[i]=='B':l[-1]+=1
print(len(l))
if len(l)!=0:print(*l,sep=' ')
``` | 3 |
|
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divides *c*.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has groups of three.
Help Xenia, find the required partition or else say that it doesn't exist. | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "9\n1 3 6 6 3 1 3 1 6",
"output": "1 3 6\n1 3 6\n1 3 6"
},
{
"input": "6\n1 2 4 1 3 5",
"output": "-1"
},
{
"input": "3\n1 3 7",
"output": "-1"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "9\n1 2 4 1 2 4 1 3 6",
"output": "1 2 4\n1 2 4\n1 3 6"
},
{
"input": "12\n3 6 1 1 3 6 1 1 2 6 2 6",
"output": "1 3 6\n1 3 6\n1 2 6\n1 2 6"
},
{
"input": "9\n1 1 1 4 4 4 6 2 2",
"output": "-1"
},
{
"input": "9\n1 2 4 6 3 1 3 1 5",
"output": "-1"
},
{
"input": "15\n2 1 2 1 3 6 1 2 1 6 1 3 4 6 4",
"output": "1 2 4\n1 2 4\n1 3 6\n1 3 6\n1 2 6"
},
{
"input": "3\n2 3 6",
"output": "-1"
},
{
"input": "3\n2 4 6",
"output": "-1"
},
{
"input": "3\n2 5 6",
"output": "-1"
},
{
"input": "3\n2 4 7",
"output": "-1"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "-1"
},
{
"input": "3\n7 7 7",
"output": "-1"
},
{
"input": "6\n1 2 4 7 7 7",
"output": "-1"
},
{
"input": "6\n1 1 2 6 6 6",
"output": "-1"
},
{
"input": "9\n1 1 1 3 3 2 4 4 6",
"output": "-1"
},
{
"input": "6\n1 2 4 5 5 5",
"output": "-1"
},
{
"input": "15\n1 1 1 1 1 2 2 2 2 4 4 6 6 6 6",
"output": "-1"
},
{
"input": "6\n1 1 5 5 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 2 3 4 5 6 7",
"output": "-1"
},
{
"input": "6\n1 1 4 4 7 7",
"output": "-1"
},
{
"input": "24\n1 1 1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 4 4 4 6 6 6",
"output": "-1"
},
{
"input": "3\n1 7 6",
"output": "-1"
},
{
"input": "6\n1 1 2 4 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 7 7 7 7 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 2 3 4 6 5 5",
"output": "-1"
}
] | 1,610,442,977 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 202 | 9,625,600 | S = sorted
M = lambda : map(int,input().split())
n = int(input())
x = list(M())
a, b, c, d, e = x.count(1), x.count(2), x.count(3), x.count(4), x.count(6)
if d>b or d+e!=a or b+c!=a or a*3!=n:
print(-1)
else:
for i in range(a):
print(1, 2 if i < b else 3, 4 if i < d else 6)
| Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divides *c*.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3.
Output Specification:
If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
Demo Input:
['6\n1 1 1 2 2 2\n', '6\n2 2 1 1 4 6\n']
Demo Output:
['-1\n', '1 2 4\n1 2 6\n']
Note:
none | ```python
S = sorted
M = lambda : map(int,input().split())
n = int(input())
x = list(M())
a, b, c, d, e = x.count(1), x.count(2), x.count(3), x.count(4), x.count(6)
if d>b or d+e!=a or b+c!=a or a*3!=n:
print(-1)
else:
for i in range(a):
print(1, 2 if i < b else 3, 4 if i < d else 6)
``` | 3 |
|
818 | A | Diplomas and Certificates | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners.
You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. | The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. | Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners. | [
"18 2\n",
"9 10\n",
"1000000000000 5\n",
"1000000000000 499999999999\n"
] | [
"3 6 9\n",
"0 0 9\n",
"83333333333 416666666665 500000000002\n",
"1 499999999999 500000000000\n"
] | none | 0 | [
{
"input": "18 2",
"output": "3 6 9"
},
{
"input": "9 10",
"output": "0 0 9"
},
{
"input": "1000000000000 5",
"output": "83333333333 416666666665 500000000002"
},
{
"input": "1000000000000 499999999999",
"output": "1 499999999999 500000000000"
},
{
"input": "1 1",
"output": "0 0 1"
},
{
"input": "5 3",
"output": "0 0 5"
},
{
"input": "42 6",
"output": "3 18 21"
},
{
"input": "1000000000000 1000",
"output": "499500499 499500499000 500000000501"
},
{
"input": "999999999999 999999",
"output": "499999 499998500001 500000999999"
},
{
"input": "732577309725 132613",
"output": "2762066 366285858458 366288689201"
},
{
"input": "152326362626 15",
"output": "4760198832 71402982480 76163181314"
},
{
"input": "2 1",
"output": "0 0 2"
},
{
"input": "1000000000000 500000000000",
"output": "0 0 1000000000000"
},
{
"input": "100000000000 50000000011",
"output": "0 0 100000000000"
},
{
"input": "1000000000000 32416187567",
"output": "15 486242813505 513757186480"
},
{
"input": "1000000000000 7777777777",
"output": "64 497777777728 502222222208"
},
{
"input": "1000000000000 77777777777",
"output": "6 466666666662 533333333332"
},
{
"input": "100000000000 578485652",
"output": "86 49749766072 50250233842"
},
{
"input": "999999999999 10000000000",
"output": "49 490000000000 509999999950"
},
{
"input": "7 2",
"output": "1 2 4"
},
{
"input": "420506530901 752346673804",
"output": "0 0 420506530901"
},
{
"input": "960375521135 321688347872",
"output": "1 321688347872 638687173262"
},
{
"input": "1000000000000 1000000000000",
"output": "0 0 1000000000000"
},
{
"input": "99999999999 15253636363",
"output": "3 45760909089 54239090907"
},
{
"input": "19 2",
"output": "3 6 10"
},
{
"input": "999999999999 1000000000000",
"output": "0 0 999999999999"
},
{
"input": "1000000000000 5915587276",
"output": "84 496909331184 503090668732"
},
{
"input": "1000000000000 1000000006",
"output": "499 499000002994 500999996507"
},
{
"input": "549755813888 134217728",
"output": "2047 274743689216 275012122625"
},
{
"input": "99999999999 3333333",
"output": "14999 49996661667 50003323333"
},
{
"input": "9 1",
"output": "2 2 5"
},
{
"input": "1000000000000 250000000001",
"output": "1 250000000001 749999999998"
},
{
"input": "5 1",
"output": "1 1 3"
},
{
"input": "3107038133 596040207",
"output": "2 1192080414 1914957717"
},
{
"input": "1000000000000 73786977",
"output": "6776 499980556152 500019437072"
},
{
"input": "1000000000000 73786976",
"output": "6776 499980549376 500019443848"
},
{
"input": "1000000000000 25000000000",
"output": "19 475000000000 524999999981"
},
{
"input": "216929598879 768233755932",
"output": "0 0 216929598879"
},
{
"input": "1000000000000 250000000000",
"output": "1 250000000000 749999999999"
},
{
"input": "1000000000000 100000000001",
"output": "4 400000000004 599999999992"
},
{
"input": "100000000000 100000000001",
"output": "0 0 100000000000"
},
{
"input": "900000000000 100281800001",
"output": "4 401127200004 498872799992"
},
{
"input": "906028900004 109123020071",
"output": "4 436492080284 469536819716"
},
{
"input": "1000000000000 1",
"output": "250000000000 250000000000 500000000000"
}
] | 1,629,133,508 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 62 | 6,758,400 | n, k = [int(x) for x in input().split()]
h = n >> 1
w = h // (k + 1)
c = k * w
l = n - w - c
print(w, k * w, l) | Title: Diplomas and Certificates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners.
You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
Input Specification:
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output Specification:
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners.
Demo Input:
['18 2\n', '9 10\n', '1000000000000 5\n', '1000000000000 499999999999\n']
Demo Output:
['3 6 9\n', '0 0 9\n', '83333333333 416666666665 500000000002\n', '1 499999999999 500000000000\n']
Note:
none | ```python
n, k = [int(x) for x in input().split()]
h = n >> 1
w = h // (k + 1)
c = k * w
l = n - w - c
print(w, k * w, l)
``` | 3 |
|
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.
In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses.
The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*. | The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there is no card, that would add a zero to the current ten points. | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
},
{
"input": "22",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "6",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "9",
"output": "0"
},
{
"input": "13",
"output": "4"
},
{
"input": "14",
"output": "4"
},
{
"input": "16",
"output": "4"
},
{
"input": "17",
"output": "4"
},
{
"input": "19",
"output": "4"
},
{
"input": "21",
"output": "4"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "0"
}
] | 1,670,423,561 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | n = int(input())
if n <= 10 or n > 21:
print(0)
else:
req = n - 10
if req == 10:
print(15)
else:
print(4)
| Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.
In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses.
The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
Input Specification:
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Output Specification:
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
Demo Input:
['12\n', '20\n', '10\n']
Demo Output:
['4', '15', '0']
Note:
In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there is no card, that would add a zero to the current ten points. | ```python
n = int(input())
if n <= 10 or n > 21:
print(0)
else:
req = n - 10
if req == 10:
print(15)
else:
print(4)
``` | 3.969 |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,594,971,768 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 186 | 6,963,200 | n=int(input())
ar=list(map(int,input().split()))
di={}
for i in range(1,n):
if(abs(ar[i-1]-ar[i]) not in di):
l=[]
l.append(i)
l.append(i+1)
di[abs(ar[i-1]-ar[i])]=l
di[abs(ar[-1]-ar[0])]=[n,1]
#print(di)
ans=min(di.keys())
print(" ".join(map(str,di[ans]))) | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none | ```python
n=int(input())
ar=list(map(int,input().split()))
di={}
for i in range(1,n):
if(abs(ar[i-1]-ar[i]) not in di):
l=[]
l.append(i)
l.append(i+1)
di[abs(ar[i-1]-ar[i])]=l
di[abs(ar[-1]-ar[0])]=[n,1]
#print(di)
ans=min(di.keys())
print(" ".join(map(str,di[ans])))
``` | 3.94053 |
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which integer will Vasya round it. | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
},
{
"input": "9",
"output": "10"
},
{
"input": "1",
"output": "0"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "6",
"output": "10"
},
{
"input": "7",
"output": "10"
},
{
"input": "8",
"output": "10"
},
{
"input": "19",
"output": "20"
},
{
"input": "100",
"output": "100"
},
{
"input": "997",
"output": "1000"
},
{
"input": "9994",
"output": "9990"
},
{
"input": "10002",
"output": "10000"
},
{
"input": "100000",
"output": "100000"
},
{
"input": "99999",
"output": "100000"
},
{
"input": "999999999",
"output": "1000000000"
},
{
"input": "999999998",
"output": "1000000000"
},
{
"input": "999999995",
"output": "999999990"
},
{
"input": "999999990",
"output": "999999990"
},
{
"input": "1000000",
"output": "1000000"
},
{
"input": "1000010",
"output": "1000010"
},
{
"input": "10000010",
"output": "10000010"
},
{
"input": "100000011",
"output": "100000010"
},
{
"input": "400000003",
"output": "400000000"
},
{
"input": "234234",
"output": "234230"
},
{
"input": "675621",
"output": "675620"
},
{
"input": "43532",
"output": "43530"
},
{
"input": "4576453",
"output": "4576450"
},
{
"input": "65754674",
"output": "65754670"
},
{
"input": "3245526",
"output": "3245530"
},
{
"input": "123445",
"output": "123440"
},
{
"input": "234217",
"output": "234220"
},
{
"input": "23451218",
"output": "23451220"
},
{
"input": "1231239",
"output": "1231240"
},
{
"input": "1923140",
"output": "1923140"
},
{
"input": "307910310",
"output": "307910310"
},
{
"input": "780961030",
"output": "780961030"
},
{
"input": "103509421",
"output": "103509420"
},
{
"input": "576560141",
"output": "576560140"
},
{
"input": "48851642",
"output": "48851640"
},
{
"input": "226935072",
"output": "226935070"
},
{
"input": "844450763",
"output": "844450760"
},
{
"input": "22534183",
"output": "22534180"
},
{
"input": "640049874",
"output": "640049870"
},
{
"input": "818133304",
"output": "818133300"
},
{
"input": "730616285",
"output": "730616280"
},
{
"input": "613732415",
"output": "613732410"
},
{
"input": "380991216",
"output": "380991220"
},
{
"input": "559074636",
"output": "559074640"
},
{
"input": "176590327",
"output": "176590330"
},
{
"input": "354673757",
"output": "354673760"
},
{
"input": "267156738",
"output": "267156740"
},
{
"input": "150272868",
"output": "150272870"
},
{
"input": "62755859",
"output": "62755860"
},
{
"input": "945871979",
"output": "945871980"
},
{
"input": "46",
"output": "50"
},
{
"input": "999",
"output": "1000"
},
{
"input": "1397",
"output": "1400"
}
] | 1,592,755,329 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 109 | 0 | n=int(input())
p=int(n%10)
if(p>=5):
print(n+(10-p))
else:
print(n-p) | Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which integer will Vasya round it.
Input Specification:
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Output Specification:
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
Demo Input:
['5\n', '113\n', '1000000000\n', '5432359\n']
Demo Output:
['0\n', '110\n', '1000000000\n', '5432360\n']
Note:
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | ```python
n=int(input())
p=int(n%10)
if(p>=5):
print(n+(10-p))
else:
print(n-p)
``` | 3 |
|
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "7\n7 7 7 7 7 7 7",
"output": "7"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "4"
},
{
"input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99",
"output": "49"
},
{
"input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15",
"output": "50"
},
{
"input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38",
"output": "7"
},
{
"input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87",
"output": "39"
},
{
"input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53",
"output": "37"
},
{
"input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32",
"output": "51"
},
{
"input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80",
"output": "21"
},
{
"input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81",
"output": "37"
},
{
"input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59",
"output": "28"
},
{
"input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94",
"output": "47"
},
{
"input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28",
"output": "15"
},
{
"input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42",
"output": "11"
},
{
"input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35",
"output": "33"
},
{
"input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22",
"output": "37"
},
{
"input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14",
"output": "15"
},
{
"input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77",
"output": "35"
},
{
"input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75",
"output": "42"
},
{
"input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26",
"output": "23"
},
{
"input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78",
"output": "15"
},
{
"input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78",
"output": "13"
},
{
"input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51",
"output": "17"
},
{
"input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59",
"output": "45"
},
{
"input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43",
"output": "53"
},
{
"input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8",
"output": "40"
},
{
"input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54",
"output": "53"
},
{
"input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77",
"output": "55"
},
{
"input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66",
"output": "52"
},
{
"input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89",
"output": "51"
},
{
"input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2",
"output": "53"
},
{
"input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23",
"output": "48"
},
{
"input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25",
"output": "48"
},
{
"input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71",
"output": "58"
},
{
"input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45",
"output": "53"
},
{
"input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17",
"output": "54"
},
{
"input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52",
"output": "49"
},
{
"input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31",
"output": "44"
},
{
"input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74",
"output": "46"
},
{
"input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75",
"output": "53"
},
{
"input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37",
"output": "43"
},
{
"input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82",
"output": "51"
},
{
"input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5",
"output": "47"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 1 3 2 2",
"output": "3"
}
] | 1,554,707,975 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 280 | 0 | n = int(input())
s = list(map(int,input().split()))
num = 0
for i in range(n):
if i==0:
m = sum(s[1:])
elif i==n-1:
m = sum(s[:n-1])
else:
m = sum(s[:i])+sum(s[i+1:])
if m%2 == 0:
num += 1
print(num)
| Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Output Specification:
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
Demo Input:
['1\n1\n', '10\n1 2 2 3 4 4 4 2 2 2\n', '11\n2 2 2 2 2 2 2 2 2 2 99\n']
Demo Output:
['1\n', '8\n', '1\n']
Note:
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | ```python
n = int(input())
s = list(map(int,input().split()))
num = 0
for i in range(n):
if i==0:
m = sum(s[1:])
elif i==n-1:
m = sum(s[:n-1])
else:
m = sum(s[:i])+sum(s[i+1:])
if m%2 == 0:
num += 1
print(num)
``` | 3 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,695,334,632 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n=int(input())
for i in range(n):
wrd=input()
if (len(wrd)>=10 and type(wrd)==str):
print(wrd[0]+str(len(wrd)-2)+wrd[len(wrd)-1])
else:
print(wrd) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
n=int(input())
for i in range(n):
wrd=input()
if (len(wrd)>=10 and type(wrd)==str):
print(wrd[0]+str(len(wrd)-2)+wrd[len(wrd)-1])
else:
print(wrd)
``` | 0 |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them. | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201",
"output": "2\n100 10101 "
},
{
"input": "314159",
"output": "9\n1 1 1 1 11 1011 101011 101011 111111 "
},
{
"input": "999999",
"output": "9\n111111 111111 111111 111111 111111 111111 111111 111111 111111 "
},
{
"input": "2",
"output": "2\n1 1 "
},
{
"input": "10",
"output": "1\n10 "
},
{
"input": "21",
"output": "2\n10 11 "
},
{
"input": "98",
"output": "9\n10 11 11 11 11 11 11 11 11 "
},
{
"input": "102030",
"output": "3\n10 1010 101010 "
},
{
"input": "909090",
"output": "9\n101010 101010 101010 101010 101010 101010 101010 101010 101010 "
},
{
"input": "909823",
"output": "9\n101000 101100 101100 101100 101100 101100 101101 101111 101111 "
},
{
"input": "1000000",
"output": "1\n1000000 "
},
{
"input": "111111",
"output": "1\n111111 "
},
{
"input": "123456",
"output": "6\n1 11 111 1111 11111 111111 "
},
{
"input": "987654",
"output": "9\n100000 110000 111000 111100 111110 111111 111111 111111 111111 "
},
{
"input": "908172",
"output": "9\n100000 101000 101010 101010 101010 101010 101010 101011 101111 "
},
{
"input": "8",
"output": "8\n1 1 1 1 1 1 1 1 "
},
{
"input": "100009",
"output": "9\n1 1 1 1 1 1 1 1 100001 "
},
{
"input": "900000",
"output": "9\n100000 100000 100000 100000 100000 100000 100000 100000 100000 "
},
{
"input": "1435",
"output": "5\n1 101 111 111 1111 "
},
{
"input": "1453",
"output": "5\n10 110 111 111 1111 "
}
] | 1,546,412,429 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 109 | 0 | s = input()
mas = []
res=0
for i,x in enumerate(s):
x=int(x)
for j,y in enumerate(mas):
if x==0:
mas[j]+='0'
else:
mas[j]+='1'
x-=1
for i in range(x):
res+=1
mas.append('1')
print(res)
print(*mas) | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106).
Output Specification:
In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
Demo Input:
['9\n', '32\n']
Demo Output:
['9\n1 1 1 1 1 1 1 1 1 \n', '3\n10 11 11 \n']
Note:
none | ```python
s = input()
mas = []
res=0
for i,x in enumerate(s):
x=int(x)
for j,y in enumerate(mas):
if x==0:
mas[j]+='0'
else:
mas[j]+='1'
x-=1
for i in range(x):
res+=1
mas.append('1')
print(res)
print(*mas)
``` | 3 |
|
757 | B | Bash's Big Day | PROGRAMMING | 1,400 | [
"greedy",
"math",
"number theory"
] | null | null | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*} tend to fight among each other if *gcd*(*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*)<==<=1 (see notes for *gcd* definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself. | The input consists of two lines.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab.
The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon. | Print single integer — the maximum number of Pokemons Bash can take. | [
"3\n2 3 4\n",
"5\n2 3 4 6 7\n"
] | [
"2\n",
"3\n"
] | *gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>}.
In the first sample, we can take Pokemons with strengths {2, 4} since *gcd*(2, 4) = 2.
In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with *gcd* ≠ 1. | 1,000 | [
{
"input": "3\n2 3 4",
"output": "2"
},
{
"input": "5\n2 3 4 6 7",
"output": "3"
},
{
"input": "3\n5 6 4",
"output": "2"
},
{
"input": "8\n41 74 4 27 85 39 100 36",
"output": "4"
},
{
"input": "6\n89 20 86 81 62 23",
"output": "3"
},
{
"input": "71\n23 84 98 8 14 4 42 56 83 87 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10",
"output": "38"
},
{
"input": "95\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50",
"output": "48"
},
{
"input": "44\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684",
"output": "19"
},
{
"input": "35\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557",
"output": "20"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n10 7 9 8 3 3 10 7 3 3",
"output": "5"
},
{
"input": "9\n10 10 6 10 9 1 8 3 5",
"output": "5"
},
{
"input": "7\n9 4 2 3 3 9 8",
"output": "4"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "6\n1623 45906 37856 34727 27156 12598",
"output": "4"
},
{
"input": "30\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566",
"output": "15"
},
{
"input": "23\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16",
"output": "22"
},
{
"input": "46\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33",
"output": "27"
},
{
"input": "43\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34",
"output": "21"
},
{
"input": "25\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "2\n3 6",
"output": "2"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "5\n3 3 3 3 3",
"output": "5"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "2\n541 541",
"output": "2"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n99989 99989",
"output": "2"
},
{
"input": "3\n3 9 27",
"output": "3"
},
{
"input": "2\n1009 1009",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "6\n2 10 20 5 15 25",
"output": "5"
},
{
"input": "3\n3 3 6",
"output": "3"
},
{
"input": "3\n457 457 457",
"output": "3"
},
{
"input": "2\n34 17",
"output": "2"
},
{
"input": "3\n12 24 3",
"output": "3"
},
{
"input": "10\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991",
"output": "10"
},
{
"input": "2\n1009 2018",
"output": "2"
},
{
"input": "3\n3 3 3",
"output": "3"
},
{
"input": "7\n6 9 12 15 21 27 33",
"output": "7"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n557 557",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "5\n2 2 101 101 101",
"output": "3"
},
{
"input": "2\n122 3721",
"output": "2"
},
{
"input": "2\n49201 98402",
"output": "2"
},
{
"input": "2\n88258 44129",
"output": "2"
},
{
"input": "2\n7919 47514",
"output": "2"
},
{
"input": "5\n1 2 1 1 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "5\n1 1 1 1 2",
"output": "1"
},
{
"input": "3\n10007 20014 30021",
"output": "3"
},
{
"input": "4\n10 10 5 5",
"output": "4"
},
{
"input": "2\n6 9",
"output": "2"
},
{
"input": "3\n6 12 9",
"output": "3"
},
{
"input": "2\n14 7",
"output": "2"
},
{
"input": "2\n199 199",
"output": "2"
},
{
"input": "3\n49999 49999 99998",
"output": "3"
},
{
"input": "5\n1009 1009 1009 1009 1009",
"output": "5"
},
{
"input": "3\n17 17 17",
"output": "3"
},
{
"input": "2\n503 1509",
"output": "2"
},
{
"input": "3\n49999 99998 99998",
"output": "3"
},
{
"input": "2\n28657 28657",
"output": "2"
},
{
"input": "3\n121 22 33",
"output": "3"
},
{
"input": "2\n10079 20158",
"output": "2"
},
{
"input": "2\n6 15",
"output": "2"
},
{
"input": "4\n6 6 6 3",
"output": "4"
},
{
"input": "2\n991 1982",
"output": "2"
},
{
"input": "3\n20362 30543 50905",
"output": "3"
},
{
"input": "2\n443 886",
"output": "2"
},
{
"input": "4\n3 7 7 21",
"output": "3"
},
{
"input": "3\n3 6 9",
"output": "3"
},
{
"input": "2\n217 31",
"output": "2"
},
{
"input": "6\n10 10 10 5 5 5",
"output": "6"
},
{
"input": "4\n49441 25225 9081 4036",
"output": "4"
},
{
"input": "2\n4 9",
"output": "1"
},
{
"input": "2\n18 27",
"output": "2"
},
{
"input": "2\n13 26",
"output": "2"
},
{
"input": "4\n6 6 6 15",
"output": "4"
}
] | 1,589,885,969 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 307,200 | import math
n = int(input())
a = list(map(int, input().split()))
mp = {}
for st in a:
limit = int(math.sqrt(st)) +1
for j in range(2, limit):
if st%j == 0:
if j in mp:
mp[j] += 1
else:
mp[j] = 1
while st%j == 0:
st /= j
if st > 1:
mp[st] = 1
#print(mp)
print(max(mp.values())) | Title: Bash's Big Day
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*} tend to fight among each other if *gcd*(*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*)<==<=1 (see notes for *gcd* definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
Input Specification:
The input consists of two lines.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab.
The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon.
Output Specification:
Print single integer — the maximum number of Pokemons Bash can take.
Demo Input:
['3\n2 3 4\n', '5\n2 3 4 6 7\n']
Demo Output:
['2\n', '3\n']
Note:
*gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>}.
In the first sample, we can take Pokemons with strengths {2, 4} since *gcd*(2, 4) = 2.
In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with *gcd* ≠ 1. | ```python
import math
n = int(input())
a = list(map(int, input().split()))
mp = {}
for st in a:
limit = int(math.sqrt(st)) +1
for j in range(2, limit):
if st%j == 0:
if j in mp:
mp[j] += 1
else:
mp[j] = 1
while st%j == 0:
st /= j
if st > 1:
mp[st] = 1
#print(mp)
print(max(mp.values()))
``` | 0 |
|
656 | B | Scrambled | PROGRAMMING | 1,700 | [
"*special",
"implementation"
] | null | null | Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht *D* *mod* *M*[*i*]<==<=*R*[*i*], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo. | The first line of input contains a single integer N (1<=≤<=*N*<=≤<=16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All *M*[*i*] are positive, for each *i* *R*[*i*]<=<<=*M*[*i*]. | Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=4. | [
"1\n2\n0\n",
"2\n2 3\n1 0\n"
] | [
"0.500000\n",
"0.666667\n"
] | none | 0 | [
{
"input": "1\n2\n0",
"output": "0.500000"
},
{
"input": "2\n2 3\n1 0",
"output": "0.666667"
},
{
"input": "3\n2 4 4\n0 1 3",
"output": "1.000000"
},
{
"input": "1\n16\n15",
"output": "0.062500"
},
{
"input": "16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "1.000000"
},
{
"input": "16\n5 6 9 13 13 15 9 10 2 6 10 11 12 7 4 8\n4 3 3 5 8 3 6 5 1 4 2 6 7 4 0 1",
"output": "0.959707"
},
{
"input": "8\n15 3 7 11 14 10 16 2\n0 2 1 4 0 0 13 1",
"output": "0.826840"
},
{
"input": "1\n7\n5",
"output": "0.142857"
},
{
"input": "9\n6 12 3 10 15 14 6 9 3\n5 2 0 6 1 1 2 2 2",
"output": "0.752381"
},
{
"input": "3\n9 12 6\n0 5 0",
"output": "0.305556"
},
{
"input": "5\n3 3 13 5 10\n1 0 1 4 2",
"output": "0.784615"
},
{
"input": "7\n3 15 11 4 12 15 12\n2 9 3 0 9 13 6",
"output": "0.757576"
},
{
"input": "2\n13 3\n6 0",
"output": "0.384615"
},
{
"input": "9\n15 9 7 4 14 14 2 11 13\n2 6 2 3 11 12 0 3 3",
"output": "0.876790"
},
{
"input": "1\n15\n1",
"output": "0.066667"
},
{
"input": "1\n6\n3",
"output": "0.166667"
},
{
"input": "4\n3 8 9 4\n1 6 7 3",
"output": "0.583333"
},
{
"input": "7\n15 9 9 2 6 8 3\n10 2 7 1 3 2 0",
"output": "0.850000"
},
{
"input": "10\n9 8 7 7 16 3 10 13 5 6\n2 0 0 4 1 0 3 12 1 5",
"output": "0.832418"
},
{
"input": "4\n10 15 2 9\n8 14 0 0",
"output": "0.588889"
},
{
"input": "12\n5 16 12 3 10 15 11 14 2 3 4 11\n3 14 1 0 7 9 10 12 1 2 2 6",
"output": "0.953247"
},
{
"input": "5\n16 6 4 15 2\n13 3 0 13 0",
"output": "0.737500"
},
{
"input": "14\n12 11 7 12 2 4 14 10 7 4 15 3 5 16\n2 8 0 9 0 1 4 0 5 3 11 1 0 6",
"output": "1.000000"
},
{
"input": "12\n8 5 5 12 12 14 14 16 5 11 9 3\n1 4 0 11 10 0 2 3 1 8 8 2",
"output": "0.859307"
},
{
"input": "10\n3 16 16 9 5 16 9 7 8 2\n0 1 7 2 1 9 0 4 4 1",
"output": "0.857143"
},
{
"input": "9\n14 14 5 8 16 2 11 7 11\n9 7 0 2 7 1 10 2 4",
"output": "0.789610"
},
{
"input": "7\n13 12 4 2 7 13 8\n4 6 0 0 3 9 3",
"output": "0.728022"
},
{
"input": "5\n4 15 9 16 6\n3 9 8 14 1",
"output": "0.518056"
},
{
"input": "3\n16 13 3\n11 5 1",
"output": "0.423077"
},
{
"input": "7\n10 15 9 5 9 15 16\n2 7 2 4 0 12 13",
"output": "0.543056"
},
{
"input": "10\n16 10 16 15 12 5 4 9 3 10\n9 0 1 2 9 4 1 8 0 8",
"output": "0.811111"
},
{
"input": "14\n14 8 6 12 13 15 2 3 16 15 15 15 16 8\n10 0 5 6 1 7 0 2 1 4 2 11 14 2",
"output": "0.784615"
},
{
"input": "2\n10 14\n2 5",
"output": "0.171429"
},
{
"input": "10\n2 15 15 4 3 10 8 14 12 12\n1 8 13 0 0 6 4 2 4 5",
"output": "0.914286"
},
{
"input": "3\n6 14 7\n4 2 0",
"output": "0.333333"
},
{
"input": "13\n3 4 16 11 12 13 12 12 3 16 8 13 4\n0 1 14 5 8 5 11 7 1 6 4 1 0",
"output": "0.967949"
}
] | 1,522,262,062 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 7,065,600 | from math import *
n=int(input())
r=list(map(int,input().split()))
m=list(map(int,input().split()))
ans=r[0]
pro=r[0]
for i in range(1,n):
ans=gcd(ans,r[i])
pro*=r[i]
if n==1:
lcm=ans
else:
lcm=pro//ans
cnt=0
for i in range(lcm):
for j in range(n):
if i%r[j]==m[j]:
cnt+=1
break
print(cnt/lcm)
| Title: Scrambled
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht *D* *mod* *M*[*i*]<==<=*R*[*i*], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
Input Specification:
The first line of input contains a single integer N (1<=≤<=*N*<=≤<=16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All *M*[*i*] are positive, for each *i* *R*[*i*]<=<<=*M*[*i*].
Output Specification:
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=4.
Demo Input:
['1\n2\n0\n', '2\n2 3\n1 0\n']
Demo Output:
['0.500000\n', '0.666667\n']
Note:
none | ```python
from math import *
n=int(input())
r=list(map(int,input().split()))
m=list(map(int,input().split()))
ans=r[0]
pro=r[0]
for i in range(1,n):
ans=gcd(ans,r[i])
pro*=r[i]
if n==1:
lcm=ans
else:
lcm=pro//ans
cnt=0
for i in range(lcm):
for j in range(n):
if i%r[j]==m[j]:
cnt+=1
break
print(cnt/lcm)
``` | 0 |
|
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on. | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs. | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},
{
"input": "1 5\n5 1 1 1 1 5",
"output": "NO"
},
{
"input": "2 5\n4 3 1 4 2\n4 2 3 4 5",
"output": "YES"
},
{
"input": "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1",
"output": "YES"
},
{
"input": "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n1 26\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n0\n0\n0\n1 3\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 40\n0\n0\n0\n1 26\n0\n0\n0\n0\n0\n1 97\n0\n1 5\n0\n0\n0\n0\n0",
"output": "NO"
},
{
"input": "100 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0",
"output": "NO"
},
{
"input": "5 6\n3 1 2 6\n3 1 2 6\n1 1\n2 3 4\n3 1 5 6",
"output": "YES"
},
{
"input": "5 2\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "NO"
},
{
"input": "1 4\n3 1 2 3",
"output": "NO"
},
{
"input": "1 4\n3 2 3 4",
"output": "NO"
},
{
"input": "2 4\n3 2 3 4\n1 1",
"output": "YES"
},
{
"input": "2 4\n3 1 2 3\n1 4",
"output": "YES"
},
{
"input": "5 1\n0\n0\n0\n0\n0",
"output": "NO"
},
{
"input": "1 1\n0",
"output": "NO"
},
{
"input": "1 10\n10 1 2 3 4 5 6 7 8 9 10",
"output": "YES"
},
{
"input": "1 1\n1 1",
"output": "YES"
},
{
"input": "1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99",
"output": "NO"
},
{
"input": "1 3\n3 1 2 1",
"output": "NO"
},
{
"input": "1 100\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "YES"
}
] | 1,634,622,232 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | n,m=map(int,input().split())
bub=[0]*m
for i in range(n):
turn_on=list(map(int,input().split()))
turn_number=turn_on[0]
for j in turn_on[1::]:
bub[j-1]=1
print('YES' if bub==[1]*m else 'NO') | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
Input Specification:
The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs.
Output Specification:
If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO".
Demo Input:
['3 4\n2 1 4\n3 1 3 1\n1 2\n', '3 3\n1 1\n1 2\n1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | ```python
n,m=map(int,input().split())
bub=[0]*m
for i in range(n):
turn_on=list(map(int,input().split()))
turn_number=turn_on[0]
for j in turn_on[1::]:
bub[j-1]=1
print('YES' if bub==[1]*m else 'NO')
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | There is a rectangular grid of *n* rows of *m* initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-empty subset of columns *C**i* are chosen. For each row *r* in *R**i* and each column *c* in *C**i*, the intersection of row *r* and column *c* is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (*i*,<=*j*) (*i*<=<<=*j*) exists such that or , where denotes intersection of sets, and denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and columns of the grid, respectively.
Each of the following *n* lines contains a string of *m* characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup. | If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n",
"5 5\n..#..\n..#..\n#####\n..#..\n..#..\n",
"5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | For the first example, the desired setup can be produced by 3 operations, as is shown below.
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | 0 | [
{
"input": "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..",
"output": "Yes"
},
{
"input": "5 5\n..#..\n..#..\n#####\n..#..\n..#..",
"output": "No"
},
{
"input": "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#",
"output": "No"
},
{
"input": "1 1\n#",
"output": "Yes"
},
{
"input": "2 1\n.\n#",
"output": "Yes"
},
{
"input": "2 5\n.####\n#..##",
"output": "No"
},
{
"input": "5 2\n##\n##\n..\n##\n..",
"output": "Yes"
},
{
"input": "5 2\n#.\n##\n##\n#.\n..",
"output": "No"
},
{
"input": "4 10\n###..#..##\n...##..#..\n.##..#..#.\n.........#",
"output": "No"
},
{
"input": "4 10\n..#......#\n.....##...\n#.........\n.#.......#",
"output": "No"
},
{
"input": "10 15\n.......#.......\n.....#.........\n....#..........\n....#..........\n.....#.........\n.....#.........\n#.............#\n...#..#........\n...............\n.............#.",
"output": "Yes"
},
{
"input": "50 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#\n#\n#\n.\n.\n.\n.\n.\n#\n.\n.\n.\n#\n#\n.\n.\n#\n#\n.\n.\n#\n#\n.",
"output": "Yes"
},
{
"input": "2 50\n...#.##.###...#.#..##....##..........#.#..#.#####.\n...#.##.###...#.#..##....##..........#.#..#.#####.",
"output": "Yes"
},
{
"input": "50 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..",
"output": "No"
},
{
"input": "1 1\n.",
"output": "Yes"
},
{
"input": "2 3\n#.#\n###",
"output": "No"
},
{
"input": "2 3\n#.#\n##.",
"output": "No"
},
{
"input": "4 4\n###.\n##.#\n#.##\n.###",
"output": "No"
},
{
"input": "3 3\n.##\n#.#\n##.",
"output": "No"
},
{
"input": "2 2\n##\n#.",
"output": "No"
}
] | 1,521,907,612 | 1,912 | PyPy 3 | OK | TESTS | 50 | 124 | 21,504,000 | import re
n, m = map(int, input().split())
rows = [input() for _ in range(n)]
cols = set()
while (rows):
r = rows.pop()
# print("ROW: ", r)
if (r.find('#') >= 0):
# at least one # in line
# Check if not in columns
c = set([occ.start() for occ in re.finditer('#', r)])
if c & cols: # reusing column
print("No")
break
cols |= c
rows = [o for o in rows if o != r]
# print(" remaining: ", cols, rows)
else:
print("Yes")
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a rectangular grid of *n* rows of *m* initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-empty subset of columns *C**i* are chosen. For each row *r* in *R**i* and each column *c* in *C**i*, the intersection of row *r* and column *c* is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (*i*,<=*j*) (*i*<=<<=*j*) exists such that or , where denotes intersection of sets, and denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and columns of the grid, respectively.
Each of the following *n* lines contains a string of *m* characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output Specification:
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Demo Input:
['5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n', '5 5\n..#..\n..#..\n#####\n..#..\n..#..\n', '5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n']
Demo Output:
['Yes\n', 'No\n', 'No\n']
Note:
For the first example, the desired setup can be produced by 3 operations, as is shown below.
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | ```python
import re
n, m = map(int, input().split())
rows = [input() for _ in range(n)]
cols = set()
while (rows):
r = rows.pop()
# print("ROW: ", r)
if (r.find('#') >= 0):
# at least one # in line
# Check if not in columns
c = set([occ.start() for occ in re.finditer('#', r)])
if c & cols: # reusing column
print("No")
break
cols |= c
rows = [o for o in rows if o != r]
# print(" remaining: ", cols, rows)
else:
print("Yes")
``` | 3 |
|
833 | A | The Meaningless Game | PROGRAMMING | 1,700 | [
"math",
"number theory"
] | null | null | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n"
] | [
"Yes\nYes\nYes\nNo\nNo\nYes\n"
] | First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | 500 | [
{
"input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000",
"output": "Yes\nYes\nYes\nNo\nNo\nYes"
},
{
"input": "3\n1 1\n8 27\n1000 1331",
"output": "Yes\nNo\nNo"
},
{
"input": "1\n12004 18012002",
"output": "Yes"
},
{
"input": "1\n3331 11095561",
"output": "Yes"
},
{
"input": "1\n2 3",
"output": "No"
},
{
"input": "1\n1062961 1031",
"output": "Yes"
},
{
"input": "1\n6 12",
"output": "No"
},
{
"input": "1\n3 1",
"output": "No"
},
{
"input": "1\n3 10",
"output": "No"
},
{
"input": "1\n31159 970883281",
"output": "Yes"
},
{
"input": "1\n9907 98148649",
"output": "Yes"
},
{
"input": "1\n16 8",
"output": "No"
},
{
"input": "1\n90 72",
"output": "No"
}
] | 1,686,896,501 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 23,142,400 | # region declaration
from collections import *
from functools import *
from math import *
from heapq import *
from itertools import *
from bisect import *
# autopep8: off
def floatl(): return (list(map(float, input().split())))
def inlt(): return (list(map(int, input().split())))
def inp(): return int(input())
def ins(): return str(input())
def insr(): return list(input())
def invr(): return (map(int, input().split()))
def yesno(predicate): print("Yes" if predicate else "No")
MOD = 998244353
# autopep8: on
# endregion
cnt = [0] * (1000000+1)
def prime_sieve(n):
prime = [True] * (n+1)
upper = floor(sqrt(n))
for p in range(2, upper + 1):
if prime[p]:
for i in range(p * p, n+1, p):
prime[i] = False
return prime
sieve = prime_sieve(31700)
primes = [i for i in range(2, 31700) if sieve[i]]
def solve():
# a = S^2*P
# b = S*P^2
# a*b = (SP) ^ 3
a, b = inlt()
sp = round((a*b)**(1/3))
# print(a, b, sp, sp**3, a*b, a % sp, b % sp)
return sp**3 == a*b and a % sp == 0 and b % sp == 0
# t = 1
t = inp()
for _ in range(t):
yesno(solve())
| Title: The Meaningless Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input Specification:
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
Output Specification:
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Demo Input:
['6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n']
Demo Output:
['Yes\nYes\nYes\nNo\nNo\nYes\n']
Note:
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | ```python
# region declaration
from collections import *
from functools import *
from math import *
from heapq import *
from itertools import *
from bisect import *
# autopep8: off
def floatl(): return (list(map(float, input().split())))
def inlt(): return (list(map(int, input().split())))
def inp(): return int(input())
def ins(): return str(input())
def insr(): return list(input())
def invr(): return (map(int, input().split()))
def yesno(predicate): print("Yes" if predicate else "No")
MOD = 998244353
# autopep8: on
# endregion
cnt = [0] * (1000000+1)
def prime_sieve(n):
prime = [True] * (n+1)
upper = floor(sqrt(n))
for p in range(2, upper + 1):
if prime[p]:
for i in range(p * p, n+1, p):
prime[i] = False
return prime
sieve = prime_sieve(31700)
primes = [i for i in range(2, 31700) if sieve[i]]
def solve():
# a = S^2*P
# b = S*P^2
# a*b = (SP) ^ 3
a, b = inlt()
sp = round((a*b)**(1/3))
# print(a, b, sp, sp**3, a*b, a % sp, b % sp)
return sp**3 == a*b and a % sp == 0 and b % sp == 0
# t = 1
t = inp()
for _ in range(t):
yesno(solve())
``` | 0 |
|
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1",
"output": "3"
},
{
"input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4",
"output": "4"
},
{
"input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1",
"output": "3"
},
{
"input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0",
"output": "5"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "6 3\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "1 4\n1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "2 3\n0 0",
"output": "0"
}
] | 1,690,802,023 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 307,200 | from collections import Counter
n,k=map(int,input().split())
a=Counter(map(int,input().split()))
print(sum(a[i] for i in range (6-k))//3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | ```python
from collections import Counter
n,k=map(int,input().split())
a=Counter(map(int,input().split()))
print(sum(a[i] for i in range (6-k))//3)
``` | 3 |
|
290 | B | QR code | PROGRAMMING | 1,500 | [
"*special",
"implementation"
] | null | null | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space. | Output a single integer. | [
"1 1\n",
"3 7\n",
"13 10\n"
] | [
"0\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "1 1",
"output": "0"
},
{
"input": "3 7",
"output": "0"
},
{
"input": "13 10",
"output": "1"
},
{
"input": "6 12",
"output": "1"
},
{
"input": "14 14",
"output": "0"
},
{
"input": "19 14",
"output": "0"
},
{
"input": "21 18",
"output": "1"
},
{
"input": "29 18",
"output": "0"
},
{
"input": "0 24",
"output": "0"
},
{
"input": "16 24",
"output": "1"
},
{
"input": "20 28",
"output": "1"
},
{
"input": "23 30",
"output": "0"
},
{
"input": "23 7",
"output": "1"
},
{
"input": "27 13",
"output": "1"
},
{
"input": "0 13",
"output": "0"
},
{
"input": "12 14",
"output": "1"
},
{
"input": "21 18",
"output": "1"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "29 24",
"output": "1"
},
{
"input": "2 24",
"output": "0"
},
{
"input": "14 28",
"output": "0"
},
{
"input": "23 30",
"output": "0"
},
{
"input": "17 32",
"output": "0"
},
{
"input": "25 5",
"output": "0"
},
{
"input": "29 5",
"output": "0"
},
{
"input": "0 5",
"output": "1"
},
{
"input": "16 11",
"output": "1"
},
{
"input": "19 11",
"output": "0"
},
{
"input": "27 15",
"output": "1"
},
{
"input": "31 15",
"output": "0"
},
{
"input": "0 0",
"output": "1"
},
{
"input": "32 0",
"output": "1"
},
{
"input": "0 32",
"output": "1"
},
{
"input": "32 32",
"output": "1"
},
{
"input": "0 31",
"output": "1"
},
{
"input": "1 31",
"output": "0"
}
] | 1,667,831,607 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 92 | 0 | x,y=map(int,input().split())
s='111111101010101111100101001111111100000100000000001010110001000001101110100110110000011010001011101101110101011001001111101001011101101110101100011000111100101011101100000101010101011010000101000001111111101010101010101010101111111000000001111101111100111100000000100010111100100001011110111111001110111001111111100100001000101100011100111010000101000111010001010011110000110001111110101100000011111111111111111000111001001011000111000010111010011010011010100100101010100010110010110101010000010101100000101010001111101000000000000010100011001101000111101011010101001001111101111000101010001110101101111111000100100001110001000000010011000100110000011010000010001101101001101110010010011011000011101011010001000111101010100110111010100110011101001101000001110110001010010101111000101111111000001000111011100001010110111110000000000001110010110100010100010110111111101000101111000110101011010100000100111010101111100100011011101110101001010000101000111111000101110100011010010010111111011010101110100100011011110110101110000100000100110011001111100111100000111111101101000101001101110010001'
print(s[32*x+x+y]) | Title: QR code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space.
Output Specification:
Output a single integer.
Demo Input:
['1 1\n', '3 7\n', '13 10\n']
Demo Output:
['0\n', '0\n', '1\n']
Note:
none | ```python
x,y=map(int,input().split())
s='111111101010101111100101001111111100000100000000001010110001000001101110100110110000011010001011101101110101011001001111101001011101101110101100011000111100101011101100000101010101011010000101000001111111101010101010101010101111111000000001111101111100111100000000100010111100100001011110111111001110111001111111100100001000101100011100111010000101000111010001010011110000110001111110101100000011111111111111111000111001001011000111000010111010011010011010100100101010100010110010110101010000010101100000101010001111101000000000000010100011001101000111101011010101001001111101111000101010001110101101111111000100100001110001000000010011000100110000011010000010001101101001101110010010011011000011101011010001000111101010100110111010100110011101001101000001110110001010010101111000101111111000001000111011100001010110111110000000000001110010110100010100010110111111101000101111000110101011010100000100111010101111100100011011101110101001010000101000111111000101110100011010010010111111011010101110100100011011110110101110000100000100110011001111100111100000111111101101000101001101110010001'
print(s[32*x+x+y])
``` | 3 |
||
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,593,334,360 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 6,656,000 | n = int(input())
d = dict()
for i in range(n):
s = input()
if s not in d:
d[s] = 1
else :
d[s] += 1
m = 0
p = ''
for i in d:
if d[i] > m:
m = d[i]
p = i
print(p) | 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
n = int(input())
d = dict()
for i in range(n):
s = input()
if s not in d:
d[s] = 1
else :
d[s] += 1
m = 0
p = ''
for i in d:
if d[i] > m:
m = d[i]
p = i
print(p)
``` | 3.933102 |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition. | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": "1000000000 1",
"output": "499999999500000000 499999999500000000"
},
{
"input": "5000000 12",
"output": "1041664166668 12499942500066"
},
{
"input": "1833 195",
"output": "7722 1342341"
},
{
"input": "1000000000 1000000000",
"output": "0 0"
},
{
"input": "1000000000 1000000",
"output": "499500000000 499000500499500000"
},
{
"input": "1000000000 32170",
"output": "15541930838100 499967831017438365"
},
{
"input": "1000000 1000",
"output": "499500000 499000999500"
},
{
"input": "1234 1123",
"output": "111 6216"
},
{
"input": "599222887 298488",
"output": "601178656545 179355218158217800"
},
{
"input": "999999999 500000000",
"output": "499999999 124999999750000000"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 384842119",
"output": "845473643 189209609585784021"
},
{
"input": "1000000000 2",
"output": "249999999500000000 499999998500000001"
},
{
"input": "1000000000 999999999",
"output": "1 1"
},
{
"input": "38447 383",
"output": "1910550 724453080"
},
{
"input": "100000000 99999799",
"output": "201 20301"
},
{
"input": "1 1",
"output": "0 0"
},
{
"input": "2 1",
"output": "1 1"
},
{
"input": "2 2",
"output": "0 0"
},
{
"input": "10 10",
"output": "0 0"
}
] | 1,645,018,879 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 512,000 | def solve(n,m):
ans=''
if n%m==0 :
q=n//m
ans_min= (m*q*(q-1))//2
q=n-m+1
ans_max =(q*(q-1))//2
return f'{ans_min} {ans_max}'
else :
q1=n//m + 1
q2=m//m
rem = n%2
ans_min = (rem*q1*(q1-1))//2 + (m-rem)*(rem*q2*(q2-1))//2
q=n-m+1
ans_max =(q*(q-1))//2
return f'{ans_min} {ans_max}'
from sys import stdin
input = stdin.readline
n,m=[int(x) for x in input().split()]
print(solve(n,m)) | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.
Input Specification:
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
Output Specification:
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
Demo Input:
['5 1\n', '3 2\n', '6 3\n']
Demo Output:
['10 10\n', '1 1\n', '3 6\n']
Note:
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people. | ```python
def solve(n,m):
ans=''
if n%m==0 :
q=n//m
ans_min= (m*q*(q-1))//2
q=n-m+1
ans_max =(q*(q-1))//2
return f'{ans_min} {ans_max}'
else :
q1=n//m + 1
q2=m//m
rem = n%2
ans_min = (rem*q1*(q1-1))//2 + (m-rem)*(rem*q2*(q2-1))//2
q=n-m+1
ans_max =(q*(q-1))//2
return f'{ans_min} {ans_max}'
from sys import stdin
input = stdin.readline
n,m=[int(x) for x in input().split()]
print(solve(n,m))
``` | 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,685,372,977 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | data = input()
data = [i for i in data.split(",")]
print(len(set(data))) | 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
data = input()
data = [i for i in data.split(",")]
print(len(set(data)))
``` | 0 |
|
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output": "I hate that I love that I hate that I love that I hate it"
},
{
"input": "10",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "18",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "19",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "76",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "77",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "81",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "82",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "85",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "86",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "99",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "98",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "33",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "34",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "57",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
}
] | 1,697,721,182 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
if (n%2)==0 and n>=1 and n<=100:
print("I hate it")
elif(n%2)==1:
print(" I love it") | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Output Specification:
Print Dr.Banner's feeling in one line.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n']
Note:
none | ```python
n = int(input())
if (n%2)==0 and n>=1 and n<=100:
print("I hate it")
elif(n%2)==1:
print(" I love it")
``` | 0 |
|
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive. | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
},
{
"input": "Danil_and_part_time_job",
"output": "YES"
},
{
"input": "Ann_and_books",
"output": "YES"
},
{
"input": "Olya",
"output": "YES"
},
{
"input": "Nikita",
"output": "YES"
},
{
"input": "Slava",
"output": "YES"
},
{
"input": "Vanya",
"output": "NO"
},
{
"input": "I_dont_know_what_to_write_here",
"output": "NO"
},
{
"input": "danil_and_work",
"output": "NO"
},
{
"input": "Ann",
"output": "YES"
},
{
"input": "Batman_Nananananananan_Batman",
"output": "NO"
},
{
"input": "Olya_Nikita_Ann_Slava_Danil",
"output": "NO"
},
{
"input": "its_me_Mario",
"output": "NO"
},
{
"input": "A",
"output": "NO"
},
{
"input": "Wake_up_Neo",
"output": "NO"
},
{
"input": "Hardest_problem_ever",
"output": "NO"
},
{
"input": "Nikita_Nikita",
"output": "NO"
},
{
"input": "____________________________________________________________________________________________________",
"output": "NO"
},
{
"input": "Nikitb",
"output": "NO"
},
{
"input": "Unn",
"output": "NO"
},
{
"input": "oLya_adn_smth",
"output": "NO"
},
{
"input": "FloorISLava",
"output": "NO"
},
{
"input": "ann",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "AAnnnnn",
"output": "YES"
},
{
"input": "AnnAnn",
"output": "NO"
},
{
"input": "Annn",
"output": "YES"
},
{
"input": "Dilzhan",
"output": "NO"
},
{
"input": "Danilaaa",
"output": "YES"
},
{
"input": "AndAnn",
"output": "YES"
},
{
"input": "OlyaAnnAnn",
"output": "NO"
},
{
"input": "DanilDanilOlya",
"output": "NO"
},
{
"input": "DDanil",
"output": "YES"
},
{
"input": "AnnAnnDanil",
"output": "NO"
},
{
"input": "And_Danil",
"output": "YES"
},
{
"input": "abcddddDanil",
"output": "YES"
},
{
"input": "DanilOlyaOlya",
"output": "NO"
},
{
"input": "Nikitaaa",
"output": "YES"
},
{
"input": "aaabbba",
"output": "NO"
},
{
"input": "Ann_Ann_Danil",
"output": "NO"
},
{
"input": "Danil_Danil_Nikita",
"output": "NO"
},
{
"input": "AlexaaaaaaBBBBBOlyaDDDDD",
"output": "YES"
},
{
"input": "IloveDaniland",
"output": "YES"
},
{
"input": "AnAnn",
"output": "YES"
},
{
"input": "Danil_Danil_Olya",
"output": "NO"
},
{
"input": "DanilDanilSlava",
"output": "NO"
},
{
"input": "DanilDanil",
"output": "NO"
},
{
"input": "OlyOlya",
"output": "YES"
},
{
"input": "NikitaNikitb",
"output": "YES"
},
{
"input": "ababaca",
"output": "NO"
},
{
"input": "AnnNikitaNikitaNikitaNikita__good_luck",
"output": "NO"
}
] | 1,517,851,532 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 62 | 5,632,000 | def main():
s = input()
S = len(s)
ct = 0
for f in ['Danil', 'Olya', 'Slava', 'Ann', 'Nikita']:
F = len(f)
for i in range(S-F+1):
t = s[i:i+F]
if f == t:
ct += 1
if ct == 1:
return 'YES'
return 'NO'
if __name__ == '__main__':
print(main())
| Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive.
Input Specification:
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Output Specification:
Print "YES", if problem is from this contest, and "NO" otherwise.
Demo Input:
['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n']
Demo Output:
['NO', 'YES', 'NO']
Note:
none | ```python
def main():
s = input()
S = len(s)
ct = 0
for f in ['Danil', 'Olya', 'Slava', 'Ann', 'Nikita']:
F = len(f)
for i in range(S-F+1):
t = s[i:i+F]
if f == t:
ct += 1
if ct == 1:
return 'YES'
return 'NO'
if __name__ == '__main__':
print(main())
``` | 3 |
|
280 | B | Maximum Xor Secondary | PROGRAMMING | 1,800 | [
"data structures",
"implementation",
"two pointers"
] | null | null | Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=><=1) is such maximum element *x**j*, that the following inequality holds: .
The lucky number of the sequence of distinct positive integers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=><=1) is the number that is equal to the bitwise excluding OR of the maximum element of the sequence and the second maximum element of the sequence.
You've got a sequence of distinct positive integers *s*1,<=*s*2,<=...,<=*s**n* (*n*<=><=1). Let's denote sequence *s**l*,<=*s**l*<=+<=1,<=...,<=*s**r* as *s*[*l*..*r*] (1<=≤<=*l*<=<<=*r*<=≤<=*n*). Your task is to find the maximum number among all lucky numbers of sequences *s*[*l*..*r*].
Note that as all numbers in sequence *s* are distinct, all the given definitions make sence. | The first line contains integer *n* (1<=<<=*n*<=≤<=105). The second line contains *n* distinct integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=109). | Print a single integer — the maximum lucky number among all lucky numbers of sequences *s*[*l*..*r*]. | [
"5\n5 2 1 4 3\n",
"5\n9 8 3 5 7\n"
] | [
"7\n",
"15\n"
] | For the first sample you can choose *s*[4..5] = {4, 3} and its lucky number is (4 *xor* 3) = 7. You can also choose *s*[1..2].
For the second sample you must choose *s*[2..5] = {8, 3, 5, 7}. | 1,000 | [
{
"input": "5\n5 2 1 4 3",
"output": "7"
},
{
"input": "5\n9 8 3 5 7",
"output": "15"
},
{
"input": "10\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446",
"output": "128869996"
},
{
"input": "10\n4547989 39261040 94929326 38131456 26174500 7152864 71295827 77784626 89898294 68006331",
"output": "134189790"
},
{
"input": "10\n30301275 19973434 63004643 54007648 93722492 91677384 58694045 41546981 15552151 5811338",
"output": "112066588"
},
{
"input": "10\n47606126 65484553 142643 35352821 26622058 5603080 7296801 53938188 34750256 97196502",
"output": "131671782"
},
{
"input": "10\n82942694 74816699 72957520 1634864 60842992 60103606 61079517 41624114 13932450 24035648",
"output": "133874061"
},
{
"input": "10\n73622246 45316865 2066146 61168230 1258786 69603039 64470479 72811017 72683016 97992629",
"output": "133280528"
},
{
"input": "10\n29272229 8752316 10025994 52398694 57994948 49609605 28150935 66061676 44865054 87041483",
"output": "127710165"
},
{
"input": "10\n3106954 3413954 3854371 85952704 17834583 20954227 58810981 7460648 97908613 97965110",
"output": "111078053"
},
{
"input": "3\n11 10 8",
"output": "2"
},
{
"input": "2\n5 6",
"output": "3"
},
{
"input": "2\n16 17",
"output": "1"
},
{
"input": "3\n8 9 10",
"output": "3"
}
] | 1,573,646,593 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 139 | 1,536,000 | ll = [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,
107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223,
227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347,
349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743,
751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883,
887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031,
1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153,
1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289,
1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433,
1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553,
1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669,
1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823,
1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979,
1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099,
2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251,
2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381,
2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539,
2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683,
2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797,
2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953,
2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109,
3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259,
3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407,
3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547,
3557, 3559, 3571
]
a = int(input())
b = [int(x) for x in input().split()]
flg = False
for i in range(a):
flg = False
for j in range(500):
if ll[j]**2 == b[i]:
flg = True
print('YES' if flg is True else 'NO')
| Title: Maximum Xor Secondary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=><=1) is such maximum element *x**j*, that the following inequality holds: .
The lucky number of the sequence of distinct positive integers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=><=1) is the number that is equal to the bitwise excluding OR of the maximum element of the sequence and the second maximum element of the sequence.
You've got a sequence of distinct positive integers *s*1,<=*s*2,<=...,<=*s**n* (*n*<=><=1). Let's denote sequence *s**l*,<=*s**l*<=+<=1,<=...,<=*s**r* as *s*[*l*..*r*] (1<=≤<=*l*<=<<=*r*<=≤<=*n*). Your task is to find the maximum number among all lucky numbers of sequences *s*[*l*..*r*].
Note that as all numbers in sequence *s* are distinct, all the given definitions make sence.
Input Specification:
The first line contains integer *n* (1<=<<=*n*<=≤<=105). The second line contains *n* distinct integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=109).
Output Specification:
Print a single integer — the maximum lucky number among all lucky numbers of sequences *s*[*l*..*r*].
Demo Input:
['5\n5 2 1 4 3\n', '5\n9 8 3 5 7\n']
Demo Output:
['7\n', '15\n']
Note:
For the first sample you can choose *s*[4..5] = {4, 3} and its lucky number is (4 *xor* 3) = 7. You can also choose *s*[1..2].
For the second sample you must choose *s*[2..5] = {8, 3, 5, 7}. | ```python
ll = [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,
107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223,
227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347,
349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743,
751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883,
887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031,
1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153,
1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289,
1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433,
1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553,
1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669,
1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823,
1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979,
1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099,
2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251,
2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381,
2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539,
2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683,
2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797,
2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953,
2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109,
3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259,
3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407,
3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547,
3557, 3559, 3571
]
a = int(input())
b = [int(x) for x in input().split()]
flg = False
for i in range(a):
flg = False
for j in range(500):
if ll[j]**2 == b[i]:
flg = True
print('YES' if flg is True else 'NO')
``` | 0 |
|
592 | B | The Monster and the Squirrel | PROGRAMMING | 1,100 | [
"math"
] | null | null | Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2,<=3,<=...,<=*n* (in this particular order). And then she puts a walnut in each region inside the polygon.
Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.
Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts? | The first and only line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=54321) - the number of vertices of the regular polygon drawn by Ari. | Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after. | [
"5\n",
"3\n"
] | [
"9\n",
"1\n"
] | One of the possible solutions for the first sample is shown on the picture above. | 1,000 | [
{
"input": "5",
"output": "9"
},
{
"input": "3",
"output": "1"
},
{
"input": "54321",
"output": "2950553761"
},
{
"input": "4",
"output": "4"
},
{
"input": "6",
"output": "16"
},
{
"input": "7",
"output": "25"
},
{
"input": "8",
"output": "36"
},
{
"input": "9",
"output": "49"
},
{
"input": "10",
"output": "64"
},
{
"input": "54320",
"output": "2950445124"
},
{
"input": "54319",
"output": "2950336489"
},
{
"input": "54318",
"output": "2950227856"
},
{
"input": "54317",
"output": "2950119225"
},
{
"input": "54316",
"output": "2950010596"
},
{
"input": "54315",
"output": "2949901969"
},
{
"input": "54314",
"output": "2949793344"
},
{
"input": "8153",
"output": "66438801"
},
{
"input": "51689",
"output": "2671545969"
},
{
"input": "16659",
"output": "277455649"
},
{
"input": "47389",
"output": "2245527769"
},
{
"input": "314",
"output": "97344"
},
{
"input": "23481",
"output": "551263441"
},
{
"input": "20380",
"output": "415262884"
},
{
"input": "1994",
"output": "3968064"
}
] | 1,494,763,719 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | print(int(input()-2*2) | Title: The Monster and the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2,<=3,<=...,<=*n* (in this particular order). And then she puts a walnut in each region inside the polygon.
Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.
Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?
Input Specification:
The first and only line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=54321) - the number of vertices of the regular polygon drawn by Ari.
Output Specification:
Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.
Demo Input:
['5\n', '3\n']
Demo Output:
['9\n', '1\n']
Note:
One of the possible solutions for the first sample is shown on the picture above. | ```python
print(int(input()-2*2)
``` | -1 |
|
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose? | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_". | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B. | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
{
"input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a",
"output": "C"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.aaaaaa\nB.aaa\nC.aaa\nD.aaa",
"output": "A"
},
{
"input": "A.aaa\nB.aaaaaa\nC.aaaaaa\nD.aaaaaa",
"output": "A"
},
{
"input": "A.a\nB.b\nC.c\nD.d",
"output": "C"
},
{
"input": "A._\nB.__\nC.____\nD.________",
"output": "C"
},
{
"input": "A.____\nB.________\nC.________\nD._______",
"output": "C"
},
{
"input": "A.h\nB.asdf\nC.asqw\nD.qwertasdfg",
"output": "C"
},
{
"input": "A.aa\nB.aaaaa\nC.aaaaaa\nD.aaaaaaaaaaaaa",
"output": "C"
},
{
"input": "A.ccc\nB.ccccccc\nC.ccc\nD.c",
"output": "C"
},
{
"input": "A.c\nB.ccc\nC.cccccccccccccccccc\nD.cccccc",
"output": "C"
},
{
"input": "A.aa\nB.bb\nC.cc\nD.ddd",
"output": "C"
},
{
"input": "A.QW\nB.WERT\nC.QWER\nD.QWERTYUI",
"output": "C"
}
] | 1,616,436,327 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("welcome tp our world ") | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose?
Input Specification:
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
Output Specification:
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
Demo Input:
['A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n', 'A.ab\nB.abcde\nC.ab\nD.abc\n', 'A.c\nB.cc\nC.c\nD.c\n']
Demo Output:
['D\n', 'C\n', 'B\n']
Note:
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B. | ```python
print("welcome tp our world ")
``` | 0 |
|
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions. | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "3"
},
{
"input": "5\n1 4 5 2 3",
"output": "4"
},
{
"input": "6\n4 6 3 5 2 1",
"output": "5"
},
{
"input": "7\n1 5 3 6 2 4 7",
"output": "6"
},
{
"input": "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53 73 10 26 80 15 32 8 81 3 95 44 46 72 6 33 11 21 85 4 30 24 51 49 96 87 55 14 31 12 60 45 9 29 22 58 18 88 2 50 59 20 86 23 41 100 39 62 68 69 97 78 43 25 89 65 75",
"output": "94"
},
{
"input": "8\n4 5 3 8 6 7 1 2",
"output": "6"
},
{
"input": "9\n6 8 5 3 4 7 9 2 1",
"output": "8"
},
{
"input": "10\n8 7 10 1 2 3 4 6 5 9",
"output": "7"
},
{
"input": "11\n5 4 6 9 10 11 7 3 1 2 8",
"output": "8"
},
{
"input": "12\n3 6 7 8 9 10 12 5 4 2 11 1",
"output": "11"
},
{
"input": "13\n8 4 3 7 5 11 9 1 10 2 13 12 6",
"output": "10"
},
{
"input": "14\n6 10 13 9 7 1 12 14 3 2 5 4 11 8",
"output": "8"
},
{
"input": "15\n3 14 13 12 7 2 4 11 15 1 8 6 5 10 9",
"output": "9"
},
{
"input": "16\n11 6 9 8 7 14 12 13 10 15 2 5 3 1 4 16",
"output": "15"
},
{
"input": "17\n13 12 5 3 9 16 8 14 2 4 10 1 6 11 7 15 17",
"output": "16"
},
{
"input": "18\n8 6 14 17 9 11 15 13 5 3 18 1 2 7 12 16 4 10",
"output": "11"
},
{
"input": "19\n12 19 3 11 15 6 18 14 5 10 2 13 9 7 4 8 17 16 1",
"output": "18"
},
{
"input": "20\n15 17 10 20 7 2 16 9 13 6 18 5 19 8 11 14 4 12 3 1",
"output": "19"
},
{
"input": "21\n1 9 14 18 13 12 11 20 16 2 4 19 15 7 6 17 8 5 3 10 21",
"output": "20"
},
{
"input": "22\n8 3 17 4 16 21 14 11 10 15 6 18 13 12 22 20 5 2 9 7 19 1",
"output": "21"
},
{
"input": "23\n1 23 11 20 9 3 12 4 7 17 5 15 2 10 18 16 8 22 14 13 19 21 6",
"output": "22"
},
{
"input": "24\n2 10 23 22 20 19 18 16 11 12 15 17 21 8 24 13 1 5 6 7 14 3 9 4",
"output": "16"
},
{
"input": "25\n12 13 22 17 1 18 14 5 21 2 10 4 3 23 11 6 20 8 24 16 15 19 9 7 25",
"output": "24"
},
{
"input": "26\n6 21 20 16 26 17 11 2 24 4 1 12 14 8 25 7 15 10 22 5 13 18 9 23 19 3",
"output": "21"
},
{
"input": "27\n20 14 18 10 5 3 9 4 24 22 21 27 17 15 26 2 23 7 12 11 6 8 19 25 16 13 1",
"output": "26"
},
{
"input": "28\n28 13 16 6 1 12 4 27 22 7 18 3 21 26 25 11 5 10 20 24 19 15 14 8 23 17 9 2",
"output": "27"
},
{
"input": "29\n21 11 10 25 2 5 9 16 29 8 17 4 15 13 6 22 7 24 19 12 18 20 1 3 23 28 27 14 26",
"output": "22"
},
{
"input": "30\n6 19 14 22 26 17 27 8 25 3 24 30 4 18 23 16 9 13 29 20 15 2 5 11 28 12 1 10 21 7",
"output": "26"
},
{
"input": "31\n29 13 26 27 9 28 2 16 30 21 12 11 3 31 23 6 22 20 1 5 14 24 19 18 8 4 10 17 15 25 7",
"output": "18"
},
{
"input": "32\n15 32 11 3 18 23 19 14 5 8 6 21 13 24 25 4 16 9 27 20 17 31 2 22 7 12 30 1 26 10 29 28",
"output": "30"
},
{
"input": "33\n22 13 10 33 8 25 15 14 21 28 27 19 26 24 1 12 5 11 32 20 30 31 18 4 6 23 7 29 16 2 17 9 3",
"output": "29"
},
{
"input": "34\n34 30 7 16 6 1 10 23 29 13 15 25 32 26 18 11 28 3 14 21 19 5 31 33 4 17 8 9 24 20 27 22 2 12",
"output": "33"
},
{
"input": "35\n24 33 20 8 34 11 31 25 2 4 18 13 9 35 16 30 23 32 17 1 14 22 19 21 28 26 3 15 5 12 27 29 10 6 7",
"output": "21"
},
{
"input": "36\n1 32 27 35 22 7 34 15 18 36 31 28 13 2 10 21 20 17 16 4 3 24 19 29 11 12 25 5 33 26 14 6 9 23 30 8",
"output": "35"
},
{
"input": "37\n24 1 12 23 11 6 30 15 4 21 13 20 25 17 5 8 36 19 32 26 14 9 7 18 10 29 37 35 16 2 22 34 3 27 31 33 28",
"output": "35"
},
{
"input": "38\n9 35 37 28 36 21 10 25 19 4 26 5 22 7 27 18 6 14 15 24 1 17 11 34 20 8 2 16 3 23 32 31 13 12 38 33 30 29",
"output": "34"
},
{
"input": "39\n16 28 4 33 26 36 25 23 22 30 27 7 12 34 17 6 3 38 10 24 13 31 29 39 14 32 9 20 35 11 18 21 8 2 15 37 5 19 1",
"output": "38"
},
{
"input": "40\n35 39 28 11 9 31 36 8 5 32 26 19 38 33 2 22 23 25 6 37 12 7 3 10 17 24 20 16 27 4 34 15 40 14 18 13 29 21 30 1",
"output": "39"
},
{
"input": "41\n24 18 7 23 3 15 1 17 25 5 30 10 34 36 2 14 9 21 41 40 20 28 33 35 12 22 11 8 19 16 31 27 26 32 29 4 13 38 37 39 6",
"output": "34"
},
{
"input": "42\n42 15 24 26 4 34 19 29 38 32 31 33 14 41 21 3 11 39 25 6 5 20 23 10 16 36 18 28 27 1 7 40 22 30 9 2 37 17 8 12 13 35",
"output": "41"
},
{
"input": "43\n43 24 20 13 22 29 28 4 30 3 32 40 31 8 7 9 35 27 18 5 42 6 17 19 23 12 41 21 16 37 33 34 2 14 36 38 25 10 15 39 26 11 1",
"output": "42"
},
{
"input": "44\n4 38 6 40 29 3 44 2 30 35 25 36 34 10 11 31 21 7 14 23 37 19 27 18 5 22 1 16 17 9 39 13 15 32 43 8 41 26 42 12 24 33 20 28",
"output": "37"
},
{
"input": "45\n45 29 24 2 31 5 34 41 26 44 33 43 15 3 4 11 21 37 27 12 14 39 23 42 16 6 13 19 8 38 20 9 25 22 40 17 32 35 18 10 28 7 30 36 1",
"output": "44"
},
{
"input": "46\n29 3 12 33 45 40 19 17 25 27 28 1 16 23 24 46 31 8 44 15 5 32 22 11 4 36 34 10 35 26 21 7 14 2 18 9 20 41 6 43 42 37 38 13 39 30",
"output": "34"
},
{
"input": "47\n7 3 8 12 24 16 29 10 28 38 1 20 37 40 21 5 15 6 45 23 36 44 25 43 41 4 11 42 18 35 32 31 39 33 27 30 22 34 14 13 17 47 19 9 46 26 2",
"output": "41"
},
{
"input": "48\n29 26 14 18 34 33 13 39 32 1 37 20 35 19 28 48 30 23 46 27 5 22 24 38 12 15 8 36 43 45 16 47 6 9 31 40 44 17 2 41 11 42 25 4 21 3 10 7",
"output": "38"
},
{
"input": "49\n16 7 42 32 11 35 15 8 23 41 6 20 47 24 9 45 49 2 37 48 25 28 5 18 3 19 12 4 22 33 13 14 10 36 44 17 40 38 30 26 1 43 29 46 21 34 27 39 31",
"output": "40"
},
{
"input": "50\n31 45 3 34 13 43 32 4 42 9 7 8 24 14 35 6 19 46 44 17 18 1 25 20 27 41 2 16 12 10 11 47 38 21 28 49 30 15 50 36 29 26 22 39 48 5 23 37 33 40",
"output": "38"
},
{
"input": "51\n47 29 2 11 43 44 27 1 39 14 25 30 33 21 38 45 34 51 16 50 42 31 41 46 15 48 13 19 6 37 35 7 22 28 20 4 17 10 5 8 24 40 9 36 18 49 12 26 23 3 32",
"output": "43"
},
{
"input": "52\n16 45 23 7 15 19 43 20 4 32 35 36 9 50 5 26 38 46 13 33 12 2 48 37 41 31 10 28 8 42 3 21 11 1 17 27 34 30 44 40 6 51 49 47 25 22 18 24 52 29 14 39",
"output": "48"
},
{
"input": "53\n53 30 50 22 51 31 32 38 12 7 39 43 1 23 6 8 24 52 2 21 34 13 3 35 5 15 19 11 47 18 9 20 29 4 36 45 27 41 25 48 16 46 44 17 10 14 42 26 40 28 33 37 49",
"output": "52"
},
{
"input": "54\n6 39 17 3 45 52 16 21 23 48 42 36 13 37 46 10 43 27 49 7 38 32 31 30 15 25 2 29 8 51 54 19 41 44 24 34 22 5 20 14 12 1 33 40 4 26 9 35 18 28 47 50 11 53",
"output": "41"
},
{
"input": "55\n26 15 31 21 32 43 34 51 7 12 5 44 17 54 18 25 48 47 20 3 41 24 45 2 11 22 29 39 37 53 35 28 36 9 50 10 30 38 19 13 4 8 27 1 42 6 49 23 55 40 33 16 46 14 52",
"output": "48"
},
{
"input": "56\n6 20 38 46 10 11 40 19 5 1 47 33 4 18 32 36 37 45 56 49 48 52 12 26 31 14 2 9 24 3 16 51 41 43 23 17 34 7 29 50 55 25 39 44 22 27 54 8 28 35 30 42 13 53 21 15",
"output": "46"
},
{
"input": "57\n39 28 53 36 3 6 12 56 55 20 50 19 43 42 18 40 24 52 38 17 33 23 22 41 14 7 26 44 45 16 35 1 8 47 31 5 30 51 32 4 37 25 13 34 54 21 46 10 15 11 2 27 29 48 49 9 57",
"output": "56"
},
{
"input": "58\n1 26 28 14 22 33 57 40 9 42 44 37 24 19 58 12 48 3 34 31 49 4 16 47 55 52 27 23 46 18 20 32 56 6 39 36 41 38 13 43 45 21 53 54 29 17 5 10 25 30 2 35 11 7 15 51 8 50",
"output": "57"
},
{
"input": "59\n1 27 10 37 53 9 14 49 46 26 50 42 59 11 47 15 24 56 43 45 44 38 5 8 58 30 52 12 23 32 22 3 31 41 2 25 29 6 54 16 35 33 18 55 4 51 57 28 40 19 13 21 7 39 36 48 34 17 20",
"output": "58"
},
{
"input": "60\n60 27 34 32 54 55 33 12 40 3 47 44 50 39 38 59 11 25 17 15 16 30 21 31 10 52 5 23 4 48 6 26 36 57 14 22 8 56 58 9 24 7 37 53 42 43 20 49 51 19 2 46 28 18 35 13 29 45 41 1",
"output": "59"
},
{
"input": "61\n61 11 26 29 31 40 32 30 35 3 18 52 9 53 42 4 50 54 20 58 28 49 22 12 2 19 16 15 57 34 51 43 7 17 25 41 56 47 55 60 46 14 44 45 24 27 33 1 48 13 59 23 38 39 6 5 36 10 8 37 21",
"output": "60"
},
{
"input": "62\n21 23 34 38 11 61 55 30 37 48 54 51 46 47 6 56 36 49 1 35 12 28 29 20 43 42 5 8 22 57 44 4 53 10 58 33 27 25 16 45 50 40 18 15 3 41 39 2 7 60 59 13 32 24 52 31 14 9 19 26 17 62",
"output": "61"
},
{
"input": "63\n2 5 29 48 31 26 21 16 47 24 43 22 61 28 6 39 60 27 14 52 37 7 53 8 62 56 63 10 50 18 44 13 4 9 25 11 23 42 45 41 59 12 32 36 40 51 1 35 49 54 57 20 19 34 38 46 33 3 55 15 30 58 17",
"output": "46"
},
{
"input": "64\n23 5 51 40 12 46 44 8 64 31 58 55 45 24 54 39 21 19 52 61 30 42 16 18 15 32 53 22 28 26 11 25 48 56 27 9 29 41 35 49 59 38 62 7 34 1 20 33 60 17 2 3 43 37 57 14 6 36 13 10 50 4 63 47",
"output": "55"
},
{
"input": "65\n10 11 55 43 53 25 35 26 16 37 41 38 59 21 48 2 65 49 17 23 18 30 62 36 3 4 47 15 28 63 57 54 31 46 44 12 51 7 29 13 56 52 14 22 39 19 8 27 45 5 6 34 32 61 20 50 9 24 33 58 60 40 1 42 64",
"output": "62"
},
{
"input": "66\n66 39 3 2 55 53 60 54 12 49 10 30 59 26 32 46 50 56 7 13 43 36 24 28 11 8 6 21 35 25 42 57 23 45 64 5 34 61 27 51 52 9 15 1 38 17 63 48 37 20 58 14 47 19 22 41 31 44 33 65 4 62 40 18 16 29",
"output": "65"
},
{
"input": "67\n66 16 2 53 35 38 49 28 18 6 36 58 21 47 27 5 50 62 44 12 52 37 11 56 15 31 25 65 17 29 59 41 7 42 4 43 39 10 1 40 24 13 20 54 19 67 46 60 51 45 64 30 8 33 26 9 3 22 34 23 57 48 55 14 63 61 32",
"output": "45"
},
{
"input": "68\n13 6 27 21 65 23 59 14 62 43 33 31 38 41 67 20 16 25 42 4 28 40 29 9 64 17 2 26 32 58 60 53 46 48 47 54 44 50 39 19 30 57 61 1 11 18 37 24 55 15 63 34 8 52 56 7 10 12 35 66 5 36 45 49 68 22 51 3",
"output": "64"
},
{
"input": "69\n29 49 25 51 21 35 11 61 39 54 40 37 60 42 27 33 59 53 34 10 46 2 23 69 8 47 58 36 1 38 19 12 7 48 13 3 6 22 18 5 65 24 50 41 66 44 67 57 4 56 62 43 9 30 14 15 28 31 64 26 16 55 68 17 32 20 45 52 63",
"output": "45"
},
{
"input": "70\n19 12 15 18 36 16 61 69 24 7 11 13 3 48 55 21 37 17 43 31 41 22 28 32 27 63 38 49 59 56 30 25 67 51 52 45 50 44 66 57 26 60 5 46 33 6 23 34 8 40 2 68 14 39 65 64 62 42 47 54 10 53 9 1 70 58 20 4 29 35",
"output": "64"
},
{
"input": "71\n40 6 62 3 41 52 31 66 27 16 35 5 17 60 2 15 51 22 67 61 71 53 1 64 8 45 28 18 50 30 12 69 20 26 10 37 36 49 70 32 33 11 57 14 9 55 4 58 29 25 44 65 39 48 24 47 19 46 56 38 34 42 59 63 54 23 7 68 43 13 21",
"output": "50"
},
{
"input": "72\n52 64 71 40 32 10 62 21 11 37 38 13 22 70 1 66 41 50 27 20 42 47 25 68 49 12 15 72 44 60 53 5 23 14 43 29 65 36 51 54 35 67 7 19 55 48 58 46 39 24 33 30 61 45 57 2 31 3 18 59 6 9 4 63 8 16 26 34 28 69 17 56",
"output": "57"
},
{
"input": "73\n58 38 47 34 39 64 69 66 72 57 9 4 67 22 35 13 61 14 28 52 56 20 31 70 27 24 36 1 62 17 10 5 12 33 16 73 18 49 63 71 44 65 23 30 40 8 50 46 60 25 11 26 37 55 29 68 42 2 3 32 59 7 15 43 41 48 51 53 6 45 54 19 21",
"output": "45"
},
{
"input": "74\n19 51 59 34 8 40 42 55 65 16 74 26 49 63 64 70 35 72 7 12 43 18 61 27 47 31 13 32 71 22 25 67 9 1 48 50 33 10 21 46 11 45 17 37 28 60 69 66 38 2 30 3 39 15 53 68 57 41 6 36 24 73 4 23 5 62 44 14 20 29 52 54 56 58",
"output": "63"
},
{
"input": "75\n75 28 60 19 59 17 65 26 32 23 18 64 8 62 4 11 42 16 47 5 72 46 9 1 25 21 2 50 33 6 36 68 30 12 20 40 53 45 34 7 37 39 38 44 63 61 67 3 66 51 29 73 24 57 70 27 10 56 22 55 13 49 35 15 54 41 14 74 69 48 52 31 71 43 58",
"output": "74"
},
{
"input": "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 35 61 72 74 73 19 30 5 29 6 15 28 21 27 51 55 50 9 65 8 67 39 76 42 31 34 16 2 36 11 26 44 22 45 75 18 69 68",
"output": "75"
},
{
"input": "77\n10 20 57 65 53 69 59 45 58 32 28 72 4 14 1 33 40 47 7 5 51 76 37 16 41 61 42 2 21 26 38 74 35 64 43 77 71 50 39 48 27 63 73 44 52 66 9 18 23 54 25 6 8 56 13 67 36 22 15 46 62 75 55 11 31 17 24 29 60 68 12 30 3 70 49 19 34",
"output": "62"
},
{
"input": "78\n7 61 69 47 68 42 65 78 70 3 32 59 49 51 23 71 11 63 22 18 43 34 24 13 27 16 19 40 21 46 48 77 28 66 54 67 60 15 75 62 9 26 52 58 4 25 8 37 41 76 1 6 30 50 44 36 5 14 29 53 17 12 2 57 73 35 64 39 56 10 33 20 45 74 31 55 38 72",
"output": "70"
},
{
"input": "79\n75 79 43 66 72 52 29 65 74 38 24 1 5 51 13 7 71 33 4 61 2 36 63 47 64 44 34 27 3 21 17 37 54 53 49 20 28 60 39 10 16 76 6 77 73 22 50 48 78 30 67 56 31 26 40 59 41 11 18 45 69 62 15 23 32 70 19 55 68 57 35 25 12 46 14 42 9 8 58",
"output": "77"
},
{
"input": "80\n51 20 37 12 68 11 28 52 76 21 7 5 3 16 64 34 25 2 6 40 60 62 75 13 45 17 56 29 32 47 79 73 49 72 15 46 30 54 80 27 43 24 74 18 42 71 14 4 44 63 65 33 1 77 55 57 41 59 58 70 69 35 19 67 10 36 26 23 48 50 39 61 9 66 38 8 31 22 53 78",
"output": "52"
},
{
"input": "81\n63 22 4 41 43 74 64 39 10 35 20 81 11 28 70 67 53 79 16 61 68 52 27 37 58 9 50 49 18 30 72 47 7 60 78 51 23 48 73 66 44 13 15 57 56 38 1 76 25 45 36 34 42 8 75 26 59 14 71 21 6 77 5 17 2 32 40 54 46 24 29 3 31 19 65 62 33 69 12 80 55",
"output": "69"
},
{
"input": "82\n50 24 17 41 49 18 80 11 79 72 57 31 21 35 2 51 36 66 20 65 38 3 45 32 59 81 28 30 70 55 29 76 73 6 33 39 8 7 19 48 63 1 77 43 4 13 78 54 69 9 40 46 74 82 60 71 16 64 12 14 47 26 44 5 10 75 53 25 27 15 56 42 58 34 23 61 67 62 68 22 37 52",
"output": "53"
},
{
"input": "83\n64 8 58 17 67 46 3 82 23 70 72 16 53 45 13 20 12 48 40 4 6 47 76 60 19 44 30 78 28 22 75 15 25 29 63 74 55 32 14 51 35 31 62 77 27 42 65 71 56 61 66 41 68 49 7 34 2 83 36 5 33 26 37 80 59 50 1 9 54 21 18 24 38 73 81 52 10 39 43 79 57 11 69",
"output": "66"
},
{
"input": "84\n75 8 66 21 61 63 72 51 52 13 59 25 28 58 64 53 79 41 34 7 67 11 39 56 44 24 50 9 49 55 1 80 26 6 73 74 27 69 65 37 18 43 36 17 30 3 47 29 76 78 32 22 12 68 46 5 42 81 57 31 33 83 54 48 14 62 10 16 4 20 71 70 35 15 45 19 60 77 2 23 84 40 82 38",
"output": "80"
},
{
"input": "85\n1 18 58 8 22 76 3 61 12 33 54 41 6 24 82 15 10 17 38 64 26 4 62 28 47 14 66 9 84 75 2 71 67 43 37 32 85 21 69 52 55 63 81 51 74 59 65 34 29 36 30 45 27 53 13 79 39 57 5 70 19 40 7 42 68 48 16 80 83 23 46 35 72 31 11 44 73 77 50 56 49 25 60 20 78",
"output": "84"
},
{
"input": "86\n64 56 41 10 31 69 47 39 37 36 27 19 9 42 15 6 78 59 52 17 71 45 72 14 2 54 38 79 4 18 16 8 46 75 50 82 44 24 20 55 58 86 61 43 35 32 33 40 63 30 28 60 13 53 12 57 77 81 76 66 73 84 85 62 68 22 51 5 49 7 1 70 80 65 34 48 23 21 83 11 74 26 29 67 25 3",
"output": "70"
},
{
"input": "87\n14 20 82 47 39 75 71 45 3 37 63 19 32 68 7 41 48 76 27 46 84 49 4 44 26 69 17 64 1 18 58 33 11 23 21 86 67 52 70 16 77 78 6 74 15 87 10 59 13 34 22 2 65 38 66 61 51 57 35 60 81 40 36 80 31 43 83 56 79 55 29 5 12 8 50 30 53 72 54 9 24 25 42 62 73 28 85",
"output": "58"
},
{
"input": "88\n1 83 73 46 61 31 39 86 57 43 16 29 26 80 82 7 36 42 13 20 6 64 19 40 24 12 47 87 8 34 75 9 69 3 11 52 14 25 84 59 27 10 54 51 81 74 65 77 70 17 60 35 23 44 49 2 4 88 5 21 41 32 68 66 15 55 48 58 78 53 22 38 45 33 30 50 85 76 37 79 63 18 28 62 72 56 71 67",
"output": "87"
},
{
"input": "89\n68 40 14 58 56 25 8 44 49 55 9 76 66 54 33 81 42 15 59 17 21 30 75 60 4 48 64 6 52 63 61 27 12 57 72 67 23 86 77 80 22 13 43 73 26 78 50 51 18 62 1 29 82 16 74 2 87 24 3 41 11 46 47 69 10 84 65 39 35 79 70 32 34 31 20 19 53 71 36 28 83 88 38 85 7 5 37 45 89",
"output": "88"
},
{
"input": "90\n2 67 26 58 9 49 76 22 60 30 77 20 13 7 37 81 47 16 19 12 14 45 41 68 85 54 28 24 46 1 27 43 32 89 53 35 59 75 18 51 17 64 66 80 31 88 87 90 38 72 55 71 42 11 73 69 62 78 23 74 65 79 84 4 86 52 10 6 3 82 56 5 48 33 21 57 40 29 61 63 34 36 83 8 15 44 50 70 39 25",
"output": "60"
},
{
"input": "91\n91 69 56 16 73 55 14 82 80 46 57 81 22 71 63 76 43 37 77 75 70 3 26 2 28 17 51 38 30 67 41 47 54 62 34 25 84 11 87 39 32 52 31 36 50 19 21 53 29 24 79 8 74 64 44 7 6 18 10 42 13 9 83 58 4 88 65 60 20 90 66 49 86 89 78 48 5 27 23 59 61 15 72 45 40 33 68 85 35 12 1",
"output": "90"
},
{
"input": "92\n67 57 76 78 25 89 6 82 11 16 26 17 59 48 73 10 21 31 27 80 4 5 22 13 92 55 45 85 63 28 75 60 54 88 91 47 29 35 7 87 1 39 43 51 71 84 83 81 46 9 38 56 90 24 37 41 19 86 50 61 79 20 18 14 69 23 62 65 49 52 58 53 36 2 68 64 15 42 30 34 66 32 44 40 8 33 3 77 74 12 70 72",
"output": "67"
},
{
"input": "93\n76 35 5 87 7 21 59 71 24 37 2 73 31 74 4 52 28 20 56 27 65 86 16 45 85 67 68 70 47 72 91 88 14 32 62 69 78 41 15 22 57 18 50 13 39 58 17 83 64 51 25 11 38 77 82 90 8 26 29 61 10 43 79 53 48 6 23 55 63 49 81 92 80 44 89 60 66 30 1 9 36 33 19 46 75 93 3 12 42 84 40 54 34",
"output": "85"
},
{
"input": "94\n29 85 82 78 61 83 80 63 11 38 50 43 9 24 4 87 79 45 3 17 90 7 34 27 1 76 26 39 84 47 22 41 81 19 44 23 56 92 35 31 72 62 70 53 40 88 13 14 73 2 59 86 46 94 15 12 77 57 89 42 75 48 18 51 32 55 71 30 49 91 20 60 5 93 33 64 21 36 10 28 8 65 66 69 74 58 6 52 25 67 16 37 54 68",
"output": "69"
},
{
"input": "95\n36 73 18 77 15 71 50 57 79 65 94 88 9 69 52 70 26 66 78 89 55 20 72 83 75 68 32 28 45 74 19 22 54 23 84 90 86 12 42 58 11 81 39 31 85 47 60 44 59 43 21 7 30 41 64 76 93 46 87 48 10 40 3 14 38 49 29 35 2 67 5 34 13 37 27 56 91 17 62 80 8 61 53 95 24 92 6 82 63 33 51 25 4 16 1",
"output": "94"
},
{
"input": "96\n64 3 47 83 19 10 72 61 73 95 16 40 54 84 8 86 28 4 37 42 92 48 63 76 67 1 59 66 20 35 93 2 43 7 45 70 34 33 26 91 85 89 13 29 58 68 44 25 87 75 49 71 41 17 55 36 32 31 74 22 52 79 30 88 50 78 38 39 65 27 69 77 81 94 82 53 21 80 57 60 24 46 51 9 18 15 96 62 6 23 11 12 90 5 14 56",
"output": "86"
},
{
"input": "97\n40 63 44 64 84 92 38 41 28 91 3 70 76 67 94 96 35 79 29 22 78 88 85 8 21 1 93 54 71 80 37 17 13 26 62 59 75 87 69 33 89 49 77 61 12 39 6 36 58 18 73 50 82 45 74 52 11 34 95 7 23 30 15 32 31 16 55 19 20 83 60 72 10 53 51 14 27 9 68 47 5 2 81 46 57 86 56 43 48 66 24 25 4 42 65 97 90",
"output": "95"
},
{
"input": "98\n85 94 69 86 22 52 27 79 53 91 35 55 33 88 8 75 76 95 64 54 67 30 70 49 6 16 2 48 80 32 25 90 98 46 9 96 36 81 10 92 28 11 37 97 15 41 38 40 83 44 29 47 23 3 31 61 87 39 78 20 68 12 17 73 59 18 77 72 43 51 84 24 89 65 26 7 74 93 21 19 5 14 50 42 82 71 60 56 34 62 58 57 45 66 13 63 4 1",
"output": "97"
},
{
"input": "99\n33 48 19 41 59 64 16 12 17 13 7 1 9 6 4 92 61 49 60 25 74 65 22 97 30 32 10 62 14 55 80 66 82 78 31 23 87 93 27 98 20 29 88 84 77 34 83 96 79 90 56 89 58 72 52 47 21 76 24 70 44 94 5 39 8 18 57 36 40 68 43 75 3 2 35 99 63 26 67 73 15 11 53 28 42 46 69 50 51 95 38 37 54 85 81 91 45 86 71",
"output": "87"
},
{
"input": "100\n28 30 77 4 81 67 31 25 66 56 88 73 83 51 57 34 21 90 38 76 22 99 53 70 91 3 64 54 6 94 8 5 97 80 50 45 61 40 16 95 36 98 9 2 17 44 72 55 18 58 47 12 87 24 7 32 14 23 65 41 63 48 62 39 92 27 43 19 46 13 42 52 96 84 26 69 100 79 93 49 35 60 71 59 68 15 10 29 20 1 78 33 75 86 11 85 74 82 89 37",
"output": "89"
},
{
"input": "100\n100 97 35 55 45 3 46 98 77 64 94 85 73 43 49 79 72 9 70 62 80 88 29 58 61 20 89 83 66 86 82 15 6 87 42 96 90 75 63 38 81 40 5 23 4 18 41 19 99 60 8 12 76 51 39 93 53 26 21 50 47 28 13 30 68 59 34 54 24 56 31 27 65 16 32 10 36 52 44 91 22 14 33 25 7 78 67 17 57 37 92 11 2 69 84 95 74 71 48 1",
"output": "99"
},
{
"input": "100\n83 96 73 70 30 25 7 77 58 89 76 85 49 82 45 51 14 62 50 9 31 32 16 15 97 64 4 37 20 93 24 10 80 71 100 39 75 72 78 74 8 29 53 86 79 48 3 68 90 99 56 87 63 94 36 1 40 65 6 44 43 84 17 52 34 95 38 47 60 57 98 59 33 41 46 81 23 27 19 2 54 91 55 35 26 12 92 18 28 66 69 21 5 67 13 11 22 88 61 42",
"output": "65"
},
{
"input": "100\n96 80 47 60 56 9 78 20 37 72 68 15 100 94 51 26 65 38 50 19 4 70 25 63 22 30 13 58 43 69 18 33 5 66 39 73 12 55 95 92 97 1 14 83 10 28 64 31 46 91 32 86 74 54 29 52 89 53 90 44 62 40 16 24 67 81 36 34 7 23 79 87 75 98 84 3 41 77 76 42 71 35 49 61 2 27 59 82 99 85 21 11 45 6 88 48 17 57 8 93",
"output": "87"
},
{
"input": "100\n5 6 88 37 97 51 25 81 54 17 57 98 99 44 67 24 30 93 100 36 8 38 84 42 21 4 75 31 85 48 70 77 43 50 65 94 29 32 68 86 56 39 69 47 20 60 52 53 10 34 79 2 95 40 89 64 71 26 22 46 1 62 91 76 83 41 9 78 16 63 13 3 28 92 27 49 7 12 96 72 80 23 14 19 18 66 59 87 90 45 73 82 33 74 35 61 55 15 58 11",
"output": "81"
},
{
"input": "100\n100 97 92 12 62 17 19 58 37 26 30 95 31 35 87 10 13 43 98 61 28 89 76 1 23 21 11 22 50 56 91 74 3 24 96 55 64 67 14 4 71 16 18 9 77 68 51 81 32 82 46 88 86 60 29 66 72 85 70 7 53 63 33 45 83 2 25 94 52 93 5 69 20 47 49 54 57 39 34 27 90 80 78 59 40 42 79 6 38 8 48 15 65 73 99 44 41 84 36 75",
"output": "99"
},
{
"input": "100\n22 47 34 65 69 5 68 78 53 54 41 23 80 51 11 8 2 85 81 75 25 58 29 73 30 49 10 71 17 96 76 89 79 20 12 15 55 7 46 32 19 3 82 35 74 44 38 40 92 14 6 50 97 63 45 93 37 18 62 77 87 36 83 9 90 61 57 28 39 43 52 42 24 56 21 84 26 99 88 59 33 70 4 60 98 95 94 100 13 48 66 72 16 31 64 91 1 86 27 67",
"output": "96"
},
{
"input": "100\n41 67 94 18 14 83 59 12 19 54 13 68 75 26 15 65 80 40 23 30 34 78 47 21 63 79 4 70 3 31 86 69 92 10 61 74 97 100 9 99 32 27 91 55 85 52 16 17 28 1 64 29 58 76 98 25 84 7 2 96 20 72 36 46 49 82 93 44 45 6 38 87 57 50 53 35 60 33 8 89 39 42 37 48 62 81 73 43 95 11 66 88 90 22 24 77 71 51 5 56",
"output": "62"
},
{
"input": "100\n1 88 38 56 62 99 39 80 12 33 57 24 28 84 37 42 10 95 83 58 8 40 20 2 30 78 60 79 36 71 51 31 27 65 22 47 6 19 61 94 75 4 74 35 15 23 92 9 70 13 11 59 90 18 66 81 64 72 16 32 34 67 46 91 21 87 77 97 82 41 7 86 26 43 45 3 93 17 52 96 50 63 48 5 53 44 29 25 98 54 49 14 73 69 89 55 76 85 68 100",
"output": "99"
},
{
"input": "100\n22 59 25 77 68 79 32 45 20 28 61 60 38 86 33 10 100 15 53 75 78 39 67 13 66 34 96 4 63 23 73 29 31 35 71 55 16 14 72 56 94 97 17 93 47 84 57 8 21 51 54 85 26 76 49 81 2 92 62 44 91 87 11 24 95 69 5 7 99 6 65 48 70 12 41 18 74 27 42 3 80 30 50 98 58 37 82 89 83 36 40 52 19 9 88 46 43 1 90 64",
"output": "97"
},
{
"input": "100\n12 1 76 78 97 82 59 80 48 8 91 51 54 74 16 10 89 99 83 63 93 90 55 25 30 33 29 6 9 65 92 79 44 39 15 58 37 46 32 19 27 3 75 49 62 71 98 42 69 50 26 81 96 5 7 61 60 21 20 36 18 34 40 4 47 85 64 38 22 84 2 68 11 56 31 66 17 14 95 43 53 35 23 52 70 13 72 45 41 77 73 87 88 94 28 86 24 67 100 57",
"output": "98"
},
{
"input": "100\n66 100 53 88 7 73 54 41 31 42 8 46 65 90 78 14 94 30 79 39 89 5 83 50 38 61 37 86 22 95 60 98 34 57 91 10 75 25 15 43 23 17 96 35 93 48 87 47 56 13 19 9 82 62 67 80 11 55 99 70 18 26 58 85 12 44 16 45 4 49 20 71 92 24 81 2 76 32 6 21 84 36 52 97 59 63 40 51 27 64 68 3 77 72 28 33 29 1 74 69",
"output": "98"
},
{
"input": "100\n56 64 1 95 72 39 9 49 87 29 94 7 32 6 30 48 50 25 31 78 90 45 60 44 80 68 17 20 73 15 75 98 83 13 71 22 36 26 96 88 35 3 85 54 16 41 92 99 69 86 93 33 43 62 77 46 47 37 12 10 18 40 27 4 63 55 28 59 23 34 61 53 76 42 51 91 21 70 8 58 38 19 5 66 84 11 52 24 81 82 79 67 97 65 57 74 2 89 100 14",
"output": "98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "4\n1 2 3 4",
"output": "3"
},
{
"input": "4\n1 2 4 3",
"output": "3"
},
{
"input": "4\n1 3 2 4",
"output": "3"
},
{
"input": "4\n1 3 4 2",
"output": "3"
},
{
"input": "4\n1 4 2 3",
"output": "3"
},
{
"input": "4\n1 4 3 2",
"output": "3"
},
{
"input": "4\n2 1 3 4",
"output": "3"
},
{
"input": "4\n2 1 4 3",
"output": "2"
},
{
"input": "4\n2 4 1 3",
"output": "2"
},
{
"input": "4\n2 4 3 1",
"output": "3"
},
{
"input": "4\n3 1 2 4",
"output": "3"
},
{
"input": "4\n3 1 4 2",
"output": "2"
},
{
"input": "4\n3 2 1 4",
"output": "3"
},
{
"input": "4\n3 2 4 1",
"output": "3"
},
{
"input": "4\n3 4 1 2",
"output": "2"
},
{
"input": "4\n3 4 2 1",
"output": "3"
},
{
"input": "4\n4 1 2 3",
"output": "3"
},
{
"input": "4\n4 1 3 2",
"output": "3"
},
{
"input": "4\n4 2 1 3",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "3"
},
{
"input": "4\n4 3 1 2",
"output": "3"
},
{
"input": "4\n4 3 2 1",
"output": "3"
},
{
"input": "8\n2 5 6 4 8 3 1 7",
"output": "6"
},
{
"input": "5\n2 3 1 5 4",
"output": "3"
},
{
"input": "6\n2 5 3 6 4 1",
"output": "5"
},
{
"input": "6\n5 4 2 6 1 3",
"output": "4"
},
{
"input": "6\n4 2 3 1 6 5",
"output": "4"
},
{
"input": "6\n5 4 2 1 6 3",
"output": "4"
},
{
"input": "9\n7 2 3 4 5 6 1 9 8",
"output": "7"
},
{
"input": "6\n3 2 1 4 6 5",
"output": "4"
},
{
"input": "6\n2 3 4 1 6 5",
"output": "4"
},
{
"input": "10\n5 2 3 4 1 6 7 8 10 9",
"output": "8"
},
{
"input": "6\n5 2 3 1 6 4",
"output": "4"
},
{
"input": "10\n2 9 3 4 1 10 5 6 7 8",
"output": "5"
},
{
"input": "10\n2 3 4 5 6 7 1 8 10 9",
"output": "8"
},
{
"input": "8\n2 3 4 5 1 6 8 7",
"output": "6"
},
{
"input": "6\n2 1 3 4 5 6",
"output": "5"
}
] | 1,638,311,900 | 2,147,483,647 | PyPy 3 | OK | TESTS | 159 | 77 | 0 | n = int(input())
a = [int(c) for c in input().split()]
id_mn = a.index(min(a))
id_mx = a.index(max(a))
print(max(id_mn,id_mx,n-id_mn-1,n-id_mx-1))
| Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Output Specification:
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Demo Input:
['5\n4 5 1 3 2\n', '7\n1 6 5 3 4 7 2\n', '6\n6 5 4 3 2 1\n']
Demo Output:
['3\n', '6\n', '5\n']
Note:
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. | ```python
n = int(input())
a = [int(c) for c in input().split()]
id_mn = a.index(min(a))
id_mx = a.index(max(a))
print(max(id_mn,id_mx,n-id_mn-1,n-id_mx-1))
``` | 3 |
|
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz",
"output": "105"
},
{
"input": "199\no A r v H e J q k J k v w Q F p O R y R Z o a K R L Z E H t X y X N y y p b x B m r R S q i A x V S u i c L y M n N X c C W Z m S j e w C w T r I S X T D F l w o k f t X u n W w p Z r A k I Y E h s g",
"output": "1"
},
{
"input": "200\nhCyIdivIiISmmYIsCLbpKcTyHaOgTUQEwnQACXnrLdHAVFLtvliTEMlzBVzTesQbhXmcqvwPDeojglBMIjOXANfyQxCSjOJyO SIqOTnRzVzseGIDDYNtrwIusScWSuEhPyEmgQIVEzXofRptjeMzzhtUQxJgcUWILUhEaaRmYRBVsjoqgmyPIKwSajdlNPccOOtWrez",
"output": "50"
},
{
"input": "1\ne",
"output": "0"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "200\nABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU VWXYZABCDE KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KZ",
"output": "10"
},
{
"input": "200\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "200"
},
{
"input": "200\nffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "24\nHarbour Space UniversitY",
"output": "2"
},
{
"input": "5\naA AA",
"output": "2"
},
{
"input": "10\nas AS ASDA",
"output": "4"
},
{
"input": "10\nas AS ASDZ",
"output": "4"
},
{
"input": "3\na A",
"output": "1"
},
{
"input": "24\nHarbour space UniversitY",
"output": "2"
},
{
"input": "10\nas AS ASAa",
"output": "3"
},
{
"input": "15\naAb ABCDFGRHTJS",
"output": "11"
},
{
"input": "53\nsdfAZEZR AZE dfdf dsdRFGSDF ZZDZSD dfsd ERBGF dsfsdfR",
"output": "6"
},
{
"input": "10\nABC ABc AB",
"output": "3"
},
{
"input": "10\nA c de CDE",
"output": "3"
},
{
"input": "4\nA AB",
"output": "2"
},
{
"input": "18\nHARbour Space UNIV",
"output": "4"
},
{
"input": "13\na b c d e f A",
"output": "1"
},
{
"input": "6\nA B CA",
"output": "2"
},
{
"input": "4\naa A",
"output": "1"
},
{
"input": "3\nA a",
"output": "1"
}
] | 1,501,859,564 | 164 | Python 3 | OK | TESTS | 29 | 62 | 4,608,000 | input()
a = input().split()
ans = -1
for s in a:
cur = 0
for c in s:
if ord('A') <= ord(c) <= ord('Z'):
cur += 1
ans = max(ans, cur)
print(ans) | Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Output Specification:
Print one integer number — volume of text.
Demo Input:
['7\nNonZERO\n', '24\nthis is zero answer text\n', '24\nHarbour Space University\n']
Demo Output:
['5\n', '0\n', '1\n']
Note:
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | ```python
input()
a = input().split()
ans = -1
for s in a:
cur = 0
for c in s:
if ord('A') <= ord(c) <= ord('Z'):
cur += 1
ans = max(ans, cur)
print(ans)
``` | 3 |
|
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8",
"output": "1 2 3 4 5 6 7 8 9 0"
},
{
"input": "1 1\n4\n4",
"output": "4"
},
{
"input": "3 7\n6 3 4\n4 9 0 1 7 8 6",
"output": "6 4"
},
{
"input": "10 1\n9 0 8 1 7 4 6 5 2 3\n0",
"output": "0"
},
{
"input": "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6",
"output": "6 0 3 8 1"
},
{
"input": "8 2\n7 2 9 6 1 0 3 4\n6 3",
"output": "6 3"
},
{
"input": "5 4\n7 0 1 4 9\n0 9 5 3",
"output": "0 9"
},
{
"input": "10 1\n9 6 2 0 1 8 3 4 7 5\n6",
"output": "6"
},
{
"input": "10 2\n7 1 0 2 4 6 5 9 3 8\n3 2",
"output": "2 3"
},
{
"input": "5 9\n3 7 9 2 4\n3 8 4 5 9 6 1 0 2",
"output": "3 9 2 4"
},
{
"input": "10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6",
"output": "1 2 3 8 6 5"
},
{
"input": "8 2\n7 4 8 9 2 5 6 1\n6 4",
"output": "4 6"
},
{
"input": "10 2\n1 0 3 5 8 9 4 7 6 2\n0 3",
"output": "0 3"
},
{
"input": "7 6\n9 2 8 6 1 3 7\n4 2 0 3 1 8",
"output": "2 8 1 3"
},
{
"input": "1 6\n3\n6 8 2 4 5 3",
"output": "3"
},
{
"input": "1 8\n0\n9 2 4 8 1 5 0 7",
"output": "0"
},
{
"input": "6 9\n7 3 9 4 1 0\n9 1 5 8 0 6 2 7 4",
"output": "7 9 4 1 0"
},
{
"input": "10 2\n4 9 6 8 3 0 1 5 7 2\n0 1",
"output": "0 1"
},
{
"input": "10 5\n5 2 8 0 9 7 6 1 4 3\n9 6 4 1 2",
"output": "2 9 6 1 4"
},
{
"input": "6 3\n8 3 9 2 7 6\n5 4 3",
"output": "3"
},
{
"input": "4 10\n8 3 9 6\n4 9 6 2 7 0 8 1 3 5",
"output": "8 3 9 6"
},
{
"input": "1 2\n1\n1 0",
"output": "1"
},
{
"input": "3 6\n1 2 3\n4 5 6 1 2 3",
"output": "1 2 3"
},
{
"input": "1 2\n2\n1 2",
"output": "2"
},
{
"input": "1 10\n9\n0 1 2 3 4 5 6 7 8 9",
"output": "9"
}
] | 1,586,390,103 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 109 | 307,200 | info = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]
kWp = [int(i) for i in input().split()]
code = list()
for i in range(info[0]):
for k in range(info[1]):
if numbers[i] == kWp[k]:
code.append(kWp[k])
for i in range(len(code)):
print(str(code[i])) | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
Output Specification:
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
Demo Input:
['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n']
Demo Output:
['7 1 2\n', '1 0\n']
Note:
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | ```python
info = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]
kWp = [int(i) for i in input().split()]
code = list()
for i in range(info[0]):
for k in range(info[1]):
if numbers[i] == kWp[k]:
code.append(kWp[k])
for i in range(len(code)):
print(str(code[i]))
``` | 3 |
|
145 | B | Lucky Number 2 | PROGRAMMING | 1,800 | [
"constructive algorithms"
] | 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 long lucky numbers very much. He is interested in the minimum lucky number *d* that meets some condition. Let *cnt*(*x*) be the number of occurrences of number *x* in number *d* as a substring. For example, if *d*<==<=747747, then *cnt*(4)<==<=2, *cnt*(7)<==<=4, *cnt*(47)<==<=2, *cnt*(74)<==<=2. Petya wants the following condition to fulfil simultaneously: *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. Petya is not interested in the occurrences of other numbers. Help him cope with this task. | The single line contains four integers *a*1, *a*2, *a*3 and *a*4 (1<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=106). | On the single line print without leading zeroes the answer to the problem — the minimum lucky number *d* such, that *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. If such number does not exist, print the single number "-1" (without the quotes). | [
"2 2 1 1\n",
"4 7 3 1\n"
] | [
"4774\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 1 1",
"output": "4774"
},
{
"input": "4 7 3 1",
"output": "-1"
},
{
"input": "4 7 4 7",
"output": "-1"
},
{
"input": "1 1 1 1",
"output": "-1"
},
{
"input": "2 2 1 2",
"output": "7474"
},
{
"input": "2 1 2 1",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "4747"
},
{
"input": "3 3 1 1",
"output": "447774"
},
{
"input": "3 2 1 2",
"output": "74474"
},
{
"input": "2 1 3 1",
"output": "-1"
},
{
"input": "7 7 1 1",
"output": "44444477777774"
},
{
"input": "4 7 2 1",
"output": "44474777777"
},
{
"input": "3 3 2 2",
"output": "474774"
},
{
"input": "4 3 2 1",
"output": "4447477"
},
{
"input": "4 4 2 2",
"output": "44747774"
},
{
"input": "1000000 1000000 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "10 10 3 5",
"output": "-1"
},
{
"input": "10 10 3 7",
"output": "-1"
},
{
"input": "1 7 1 1",
"output": "74777777"
},
{
"input": "8 3 2 1",
"output": "44444447477"
},
{
"input": "1000000 1000000 1000000 1000000",
"output": "-1"
},
{
"input": "4584 45854 25 685",
"output": "-1"
},
{
"input": "1 1 1 2",
"output": "-1"
},
{
"input": "3 1000000 3 1",
"output": "-1"
},
{
"input": "4 58458 2 1",
"output": "4447477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "845 8549 54 8",
"output": "-1"
},
{
"input": "1000000 1000000 100000 100000",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 499 500",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 100000 100001",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "845488 44884 9945 9944",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "7 7 4 5",
"output": "74447474747774"
},
{
"input": "7 8 5 4",
"output": "444747474747777"
},
{
"input": "1000000 1000000 400000 400001",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "4585 4588 98 99",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 2 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "2 100000 1 2",
"output": "7477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "86451 754 85 84",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "98654 4844 1001 1000",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "5 5 1 2",
"output": "7444477774"
},
{
"input": "5 5 2 1",
"output": "4444747777"
},
{
"input": "4 4 1 1",
"output": "44477774"
},
{
"input": "4 4 2 2",
"output": "44747774"
},
{
"input": "4 4 3 3",
"output": "47474774"
},
{
"input": "10 9 4 5",
"output": "7444444747474777774"
},
{
"input": "100 100 4 5",
"output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447474747777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "1000000 1000000 1 2",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 47 46",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 999999 1000000",
"output": "7474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747..."
},
{
"input": "54585 4584 458 954",
"output": "-1"
},
{
"input": "6 6 1 3",
"output": "-1"
},
{
"input": "6 6 2 3",
"output": "744447477774"
},
{
"input": "6 10 2 1",
"output": "4444474777777777"
},
{
"input": "7 3 1 1",
"output": "4444447774"
},
{
"input": "47 74 8 9",
"output": "7444444444444444444444444444444444444444747474747474747777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "458445 445 6 7",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 10000 10001",
"output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "1000000 1000000 978 977",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "7 1000 1 2",
"output": "7444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "1 10 1 1",
"output": "74777777777"
},
{
"input": "70 60 20 21",
"output": "7444444444444444444444444444444444444444444444444447474747474747474747474747474747474747477777777777777777777777777777777777777774"
},
{
"input": "57 59 3 4",
"output": "74444444444444444444444444444444444444444444444444444447474777777777777777777777777777777777777777777777777777777774"
},
{
"input": "10 10 5 5",
"output": "44444747474747777774"
},
{
"input": "69 84 25 24",
"output": "444444444444444444444444444444444444444444444747474747474747474747474747474747474747474747474777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "25 94 11 12",
"output": "74444444444444474747474747474747474777777777777777777777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "1 1000000 4 5",
"output": "-1"
},
{
"input": "7 1000000 2 3",
"output": "7444447477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "1000000 1 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "45 65 31 32",
"output": "74444444444444474747474747474747474747474747474747474747474747474747474747477777777777777777777777777777777774"
},
{
"input": "31 32 30 31",
"output": "747474747474747474747474747474747474747474747474747474747474774"
},
{
"input": "1 1000000 1 1",
"output": "7477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "2 1000000 1 1",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "50000 1000000 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "74544 1 1 1",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..."
},
{
"input": "2 2 3 4",
"output": "-1"
},
{
"input": "1 1000 2 1",
"output": "-1"
},
{
"input": "1 10 1 2",
"output": "-1"
},
{
"input": "1000000 1000000 1000000 999999",
"output": "4747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474..."
},
{
"input": "1 2 1 1",
"output": "747"
},
{
"input": "2 1 1 1",
"output": "474"
},
{
"input": "2 2 2 1",
"output": "4747"
},
{
"input": "2 2 2 2",
"output": "-1"
},
{
"input": "1 3 1 1",
"output": "7477"
},
{
"input": "1 4 1 1",
"output": "74777"
},
{
"input": "2 3 2 2",
"output": "74747"
},
{
"input": "2 5 2 2",
"output": "7474777"
},
{
"input": "1 2 2 1",
"output": "-1"
},
{
"input": "10 100 2 2",
"output": "44444444747777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "3 4 3 3",
"output": "7474747"
},
{
"input": "30 30 29 29",
"output": "474747474747474747474747474747474747474747474747474747474774"
},
{
"input": "10 10 1 2",
"output": "74444444447777777774"
},
{
"input": "999999 1000000 999999 999999",
"output": "7474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747..."
},
{
"input": "10 11 1 1",
"output": "444444444777777777774"
},
{
"input": "10 10 2 2",
"output": "44444444747777777774"
},
{
"input": "100 200 5 5",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447474747477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774"
},
{
"input": "10 11 10 10",
"output": "747474747474747474747"
},
{
"input": "5 10 2 3",
"output": "744474777777774"
},
{
"input": "6 8 1 1",
"output": "44444777777774"
},
{
"input": "1 9 2 2",
"output": "-1"
}
] | 1,651,673,966 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 280 | 7,270,400 | import abc
import itertools
import math
from builtins import input
from math import gcd as gcd
import sys
import queue
import itertools
from heapq import heappop, heappush
import random
def solve():
a1, a2, a3, a4 = map(int, input().split())
if abs(a3 - a4) > 1:
print(-1)
return
if min(a1, a2) < max(a3, a4):
print(-1)
return
if a3 == a4:
if a1 > a3:
print("4" * (a1 - a3) + "74" * (a3 - 1) + "7" * (a2 - a3 + 1) + "4")
elif a2 > a3:
print("7" * (a2 - a3) + "47" * (a3 - 1) + "4" * (a1 - a3 + 1) + "7")
else:
print(-1)
elif a3 > a4:
print("4" * (a1 - a3) + "47" * a3 + "7" * (a2 - a3))
else:
print("74" * (a4 - 1) + "7" * (a2 - a4 + 1) + "4" * (a1 - a4 + 1))
if __name__ == '__main__':
multi_test = 0
if multi_test == 1:
t = int(sys.stdin.readline())
for _ in range(t):
solve()
else:
solve()
| Title: Lucky Number 2
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 long lucky numbers very much. He is interested in the minimum lucky number *d* that meets some condition. Let *cnt*(*x*) be the number of occurrences of number *x* in number *d* as a substring. For example, if *d*<==<=747747, then *cnt*(4)<==<=2, *cnt*(7)<==<=4, *cnt*(47)<==<=2, *cnt*(74)<==<=2. Petya wants the following condition to fulfil simultaneously: *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
Input Specification:
The single line contains four integers *a*1, *a*2, *a*3 and *a*4 (1<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=106).
Output Specification:
On the single line print without leading zeroes the answer to the problem — the minimum lucky number *d* such, that *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. If such number does not exist, print the single number "-1" (without the quotes).
Demo Input:
['2 2 1 1\n', '4 7 3 1\n']
Demo Output:
['4774\n', '-1\n']
Note:
none | ```python
import abc
import itertools
import math
from builtins import input
from math import gcd as gcd
import sys
import queue
import itertools
from heapq import heappop, heappush
import random
def solve():
a1, a2, a3, a4 = map(int, input().split())
if abs(a3 - a4) > 1:
print(-1)
return
if min(a1, a2) < max(a3, a4):
print(-1)
return
if a3 == a4:
if a1 > a3:
print("4" * (a1 - a3) + "74" * (a3 - 1) + "7" * (a2 - a3 + 1) + "4")
elif a2 > a3:
print("7" * (a2 - a3) + "47" * (a3 - 1) + "4" * (a1 - a3 + 1) + "7")
else:
print(-1)
elif a3 > a4:
print("4" * (a1 - a3) + "47" * a3 + "7" * (a2 - a3))
else:
print("74" * (a4 - 1) + "7" * (a2 - a4 + 1) + "4" * (a1 - a4 + 1))
if __name__ == '__main__':
multi_test = 0
if multi_test == 1:
t = int(sys.stdin.readline())
for _ in range(t):
solve()
else:
solve()
``` | 0 |
|
869 | C | The Intriguing Obsession | PROGRAMMING | 1,800 | [
"combinatorics",
"dp",
"math"
] | null | null | — This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of *a*, *b* and *c* distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998<=244<=353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other. | The first and only line of input contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=5<=000) — the number of islands in the red, blue and purple clusters, respectively. | Output one line containing an integer — the number of different ways to build bridges, modulo 998<=244<=353. | [
"1 1 1\n",
"1 2 2\n",
"1 3 5\n",
"6 2 9\n"
] | [
"8\n",
"63\n",
"3264\n",
"813023575\n"
] | In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 2<sup class="upper-index">3</sup> = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively. | 1,500 | [
{
"input": "1 1 1",
"output": "8"
},
{
"input": "1 2 2",
"output": "63"
},
{
"input": "1 3 5",
"output": "3264"
},
{
"input": "6 2 9",
"output": "813023575"
},
{
"input": "7 3 7",
"output": "807577560"
},
{
"input": "135 14 39",
"output": "414849507"
},
{
"input": "5000 5000 5000",
"output": "986778560"
},
{
"input": "2 1 1",
"output": "18"
},
{
"input": "1 1 3",
"output": "32"
},
{
"input": "1 2 3",
"output": "156"
},
{
"input": "4 1 2",
"output": "315"
},
{
"input": "5 9 4",
"output": "661093467"
},
{
"input": "4 2 5",
"output": "326151"
},
{
"input": "9 4 10",
"output": "391175867"
},
{
"input": "16 8 29",
"output": "349763770"
},
{
"input": "17 46 45",
"output": "518654435"
},
{
"input": "28 47 1",
"output": "517406193"
},
{
"input": "94 87 10",
"output": "846321893"
},
{
"input": "84 29 61",
"output": "391253501"
},
{
"input": "179 856 377",
"output": "518957210"
},
{
"input": "1925 1009 273",
"output": "207866159"
},
{
"input": "1171 2989 2853",
"output": "234725427"
},
{
"input": "3238 2923 4661",
"output": "636587126"
},
{
"input": "1158 506 4676",
"output": "6109065"
},
{
"input": "4539 2805 2702",
"output": "356944655"
},
{
"input": "4756 775 3187",
"output": "56242066"
},
{
"input": "4998 4998 4998",
"output": "259368717"
},
{
"input": "4996 1 5000",
"output": "196902859"
},
{
"input": "2048 4096 1024",
"output": "445542375"
},
{
"input": "5000 1 1",
"output": "50020002"
}
] | 1,507,786,195 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 826 | 1,331,200 | # -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
"""
created by shhuan at 2017/10/6 22:19
"""
t0 = time.time()
# a, b, c = map(int, input().split())
a = random.randint(4500, 5000)
b = random.randint(4500, 5000)
c = random.randint(4500, 5000)
MOD = 998244353
MAXN = 5001
def ct(a, b):
if a > b:
a, b = b, a
L=998244353
s=1
sx=1
for k in range(1,a+1):
s = s*(a+1-k)*(b+1-k)//k
sx += s % L
return sx
L=998244353
print(ct(a,b)*ct(a,c)*ct(b,c)%L)
# print(time.time()-t0)
# p = [[0 for _ in range(MAXN)] for _ in range(MAXN)]
# for i in range(1, MAXN):
# p[i][0] = 1
# for j in range(1, i+1):
# p[i][j] = (p[i-1][j-1]+p[i-1][j]) % MOD
# print(time.time() - t0)
# pre = [0] * MAXN
# pre[0] = 1
# for i in range(1, MAXN):
# pre[i] = (i*pre[i-1]) % MOD
#
#
# def solve(x, y):
# ans = 0
# for k in range(min(x, y)+1):
# d = pre[k]
# d = (d*p[x][k]) % MOD
# d = (d*p[y][k]) % MOD
# ans = (ans+d) % MOD
#
# return ans
#
# ans = 1
# ans = (ans * solve(a, b)) % MOD
# ans = (ans * solve(b, c)) % MOD
# ans = (ans * solve(a, c)) % MOD
# print(ans)
#
# print(time.time() - t0) | Title: The Intriguing Obsession
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of *a*, *b* and *c* distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998<=244<=353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
Input Specification:
The first and only line of input contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=5<=000) — the number of islands in the red, blue and purple clusters, respectively.
Output Specification:
Output one line containing an integer — the number of different ways to build bridges, modulo 998<=244<=353.
Demo Input:
['1 1 1\n', '1 2 2\n', '1 3 5\n', '6 2 9\n']
Demo Output:
['8\n', '63\n', '3264\n', '813023575\n']
Note:
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 2<sup class="upper-index">3</sup> = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively. | ```python
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
"""
created by shhuan at 2017/10/6 22:19
"""
t0 = time.time()
# a, b, c = map(int, input().split())
a = random.randint(4500, 5000)
b = random.randint(4500, 5000)
c = random.randint(4500, 5000)
MOD = 998244353
MAXN = 5001
def ct(a, b):
if a > b:
a, b = b, a
L=998244353
s=1
sx=1
for k in range(1,a+1):
s = s*(a+1-k)*(b+1-k)//k
sx += s % L
return sx
L=998244353
print(ct(a,b)*ct(a,c)*ct(b,c)%L)
# print(time.time()-t0)
# p = [[0 for _ in range(MAXN)] for _ in range(MAXN)]
# for i in range(1, MAXN):
# p[i][0] = 1
# for j in range(1, i+1):
# p[i][j] = (p[i-1][j-1]+p[i-1][j]) % MOD
# print(time.time() - t0)
# pre = [0] * MAXN
# pre[0] = 1
# for i in range(1, MAXN):
# pre[i] = (i*pre[i-1]) % MOD
#
#
# def solve(x, y):
# ans = 0
# for k in range(min(x, y)+1):
# d = pre[k]
# d = (d*p[x][k]) % MOD
# d = (d*p[y][k]) % MOD
# ans = (ans+d) % MOD
#
# return ans
#
# ans = 1
# ans = (ans * solve(a, b)) % MOD
# ans = (ans * solve(b, c)) % MOD
# ans = (ans * solve(a, c)) % MOD
# print(ans)
#
# print(time.time() - t0)
``` | 0 |
|
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43",
"output": "NO"
},
{
"input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "5\n2 1 4 5 3",
"output": "YES"
},
{
"input": "5\n5 4 5 5 2",
"output": "YES"
}
] | 1,614,059,383 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n=int(input())
li=[int(i) for i in input().split()]
s=set(li)
if len(s)>=3:
print('YES')
else:
print('NO') | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output Specification:
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case.
Demo Input:
['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | ```python
n=int(input())
li=[int(i) for i in input().split()]
s=set(li)
if len(s)>=3:
print('YES')
else:
print('NO')
``` | 0 |
|
577 | B | Modulo Sum | PROGRAMMING | 1,900 | [
"combinatorics",
"data structures",
"dp",
"two pointers"
] | null | null | You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*.
Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*. | The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist. | [
"3 5\n1 2 3\n",
"1 6\n5\n",
"4 6\n3 1 1 3\n",
"6 6\n5 5 5 5 5 5\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | 1,250 | [
{
"input": "3 5\n1 2 3",
"output": "YES"
},
{
"input": "1 6\n5",
"output": "NO"
},
{
"input": "4 6\n3 1 1 3",
"output": "YES"
},
{
"input": "6 6\n5 5 5 5 5 5",
"output": "YES"
},
{
"input": "4 5\n1 1 1 1",
"output": "NO"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "YES"
},
{
"input": "4 7\n1 2 3 3",
"output": "YES"
},
{
"input": "1 47\n0",
"output": "YES"
},
{
"input": "2 47\n1 0",
"output": "YES"
},
{
"input": "9 11\n8 8 8 8 8 8 8 8 5",
"output": "NO"
},
{
"input": "10 11\n8 8 8 8 8 8 8 8 7 8",
"output": "YES"
},
{
"input": "3 5\n2 1 3",
"output": "YES"
},
{
"input": "100 968\n966 966 967 966 967 967 967 967 966 966 966 967 966 966 966 967 967 966 966 967 967 967 967 966 967 967 967 967 563 967 967 967 600 967 967 966 967 966 967 966 967 966 967 966 966 966 967 966 967 966 966 967 967 193 966 966 967 966 967 967 967 966 967 966 966 580 966 967 966 966 967 966 966 966 967 967 967 967 966 967 967 966 966 966 967 967 966 966 967 966 966 966 967 966 966 967 966 967 966 966",
"output": "YES"
},
{
"input": "100 951\n950 949 949 949 949 950 950 949 949 950 950 949 949 949 496 949 950 949 950 159 950 949 949 950 950 949 950 949 949 950 949 950 949 949 950 949 950 950 950 950 949 949 949 949 949 950 950 950 950 950 950 950 949 950 949 949 950 949 950 950 949 950 950 950 949 950 949 950 950 950 950 949 949 950 950 949 950 950 950 950 949 950 950 949 949 635 612 949 949 949 949 949 949 949 950 949 949 950 949 950",
"output": "YES"
},
{
"input": "100 940\n1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 1 2 2 1 1 1 2 2 2 2 1 1 1 1 2 2 1 403 2 2 1 1 1 2 2 2 1 2 2 1 1 2 2 1 1 1 1 2 1 2 691 1 2 1 1 1 1 1 2 2 2 2 2 1 2 1 1 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 1 1 2 2 1 1 2 786 1",
"output": "YES"
},
{
"input": "100 917\n2 1 2 2 2 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1 1 2 1 2 340 2 399 2 1 2 2 2 2 178 1 1 2 1 1 1 2 2 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 1 2 2 1 1 2 2 2 1 2 2 2 2 1 2 1 2 2 2 2 2 1 1 2 2 2 2",
"output": "YES"
},
{
"input": "1 2\n1000000000",
"output": "YES"
}
] | 1,668,884,535 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | n, m = map(int, input().split())
arr = list(map(int, input().split()))
dp = [0 for _ in range(n+1)]
def recurr(i, score):
if score % m == 0 and score:
return 1
if i >= n:
return 0
if dp[i]:
return 1
take = recurr(i+1, score+arr[i])
notTake = recurr(i+1, score)
dp[i] = take + notTake
return dp[i]
print(("NO", "YES")[min(1, recurr(0, 0))])
| Title: Modulo Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*.
Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*.
Input Specification:
The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output Specification:
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Demo Input:
['3 5\n1 2 3\n', '1 6\n5\n', '4 6\n3 1 1 3\n', '6 6\n5 5 5 5 5 5\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'YES\n']
Note:
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | ```python
n, m = map(int, input().split())
arr = list(map(int, input().split()))
dp = [0 for _ in range(n+1)]
def recurr(i, score):
if score % m == 0 and score:
return 1
if i >= n:
return 0
if dp[i]:
return 1
take = recurr(i+1, score+arr[i])
notTake = recurr(i+1, score)
dp[i] = take + notTake
return dp[i]
print(("NO", "YES")[min(1, recurr(0, 0))])
``` | 0 |
|
538 | A | Cutting Banner | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES. | The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES. | Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes). | [
"CODEWAITFORITFORCES\n",
"BOTTOMCODER\n",
"DECODEFORCES\n",
"DOGEFORCES\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "CODEWAITFORITFORCES",
"output": "YES"
},
{
"input": "BOTTOMCODER",
"output": "NO"
},
{
"input": "DECODEFORCES",
"output": "YES"
},
{
"input": "DOGEFORCES",
"output": "NO"
},
{
"input": "ABACABA",
"output": "NO"
},
{
"input": "CODEFORCE",
"output": "NO"
},
{
"input": "C",
"output": "NO"
},
{
"input": "NQTSMZEBLY",
"output": "NO"
},
{
"input": "CODEFZORCES",
"output": "YES"
},
{
"input": "EDYKHVZCNTLJUUOQGHPTIOETQNFLLWEKZOHIUAXELGECABVSBIBGQODQXVYFKBYJWTGBYHVSSNTINKWSINWSMALUSIWNJMTCOOVF",
"output": "NO"
},
{
"input": "OCECFDSRDE",
"output": "NO"
},
{
"input": "MDBUWCZFFZKFMJTTJFXRHTGRPREORKDVUXOEMFYSOMSQGHUKGYCRCVJTNDLFDEWFS",
"output": "NO"
},
{
"input": "CODEFYTORCHES",
"output": "NO"
},
{
"input": "BCODEFORCES",
"output": "YES"
},
{
"input": "CVODEFORCES",
"output": "YES"
},
{
"input": "COAKDEFORCES",
"output": "YES"
},
{
"input": "CODFMWEFORCES",
"output": "YES"
},
{
"input": "CODEVCSYRFORCES",
"output": "YES"
},
{
"input": "CODEFXHHPWCVQORCES",
"output": "YES"
},
{
"input": "CODEFORQWUFJLOFFXTXRCES",
"output": "YES"
},
{
"input": "CODEFORBWFURYIDURNRKRDLHCLXZCES",
"output": "YES"
},
{
"input": "CODEFORCQSYSLYKCDFFUPSAZCJIAENCKZUFJZEINQIES",
"output": "YES"
},
{
"input": "CODEFORCEVENMDBQLSVPQIIBGSHBVOPYZXNWVSTVWDRONUREYJJIJIPMEBPQDCPFS",
"output": "YES"
},
{
"input": "CODEFORCESCFNNPAHNHDIPPBAUSPKJYAQDBVZNLSTSDCREZACVLMRFGVKGVHHZLXOHCTJDBQKIDWBUXDUJARLWGFGFCTTXUCAZB",
"output": "YES"
},
{
"input": "CODJRDPDEFOROES",
"output": "NO"
},
{
"input": "CODEFOGSIUZMZCMWAVQHNYFEKIEZQMAZOVEMDRMOEDBHAXPLBLDYYXCVTOOSJZVSQAKFXTBTZFWAYRZEMDEMVDJTDRXXAQBURCES",
"output": "YES"
},
{
"input": "CODEMKUYHAZSGJBQLXTHUCZZRJJJXUSEBOCNZASOKDZHMSGWZSDFBGHXFLABVPDQBJYXSHHAZAKHSTRGOKJYHRVSSUGDCMFOGCES",
"output": "NO"
},
{
"input": "CODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCES",
"output": "YES"
},
{
"input": "CCODEFORCESODECODEFORCCODEFORCESODCODEFORCESEFCODEFORCESORCODEFORCESCESCESFORCODEFORCESCES",
"output": "NO"
},
{
"input": "CCODEFORCESC",
"output": "NO"
},
{
"input": "CODEAFORBCES",
"output": "NO"
},
{
"input": "CODERRRRRFORCRRRRES",
"output": "NO"
},
{
"input": "CODELFORCELS",
"output": "NO"
},
{
"input": "CPOPDPEPFPOPRPCPEPS",
"output": "NO"
},
{
"input": "COXDEXFORXCEXS",
"output": "NO"
},
{
"input": "CODAAAAAFORCES",
"output": "NO"
},
{
"input": "CAOADEFORCES",
"output": "NO"
},
{
"input": "FORCESXCODE",
"output": "NO"
},
{
"input": "FORCESACODE",
"output": "NO"
},
{
"input": "ACAOADAEFORCES",
"output": "NO"
},
{
"input": "CCODEFORCESS",
"output": "NO"
},
{
"input": "ZCODEFORCEZ",
"output": "NO"
},
{
"input": "CODXEFORXCES",
"output": "NO"
},
{
"input": "CODEFORCEZ",
"output": "NO"
},
{
"input": "CODEFORCEST",
"output": "YES"
},
{
"input": "AXODEFORCES",
"output": "NO"
},
{
"input": "RCODEFORCESR",
"output": "NO"
},
{
"input": "CODECODEFORCESFORCES",
"output": "YES"
},
{
"input": "TTTWWWCODEFORCES",
"output": "YES"
},
{
"input": "CODEFORRCEST",
"output": "NO"
},
{
"input": "UJYTYUCODEFORCES",
"output": "YES"
},
{
"input": "CODEXXXXXXXXXXXXXXXXXXCODEFORCESXXXXXXXXXXXXXXXXXXXXXFORCES",
"output": "YES"
},
{
"input": "COXEDYFORCES",
"output": "NO"
},
{
"input": "UJYTYCODEFORCES",
"output": "YES"
},
{
"input": "UJYTCODEFORCES",
"output": "YES"
}
] | 1,663,217,331 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 29 | 62 | 0 | s=input()
res="CODEFORCES"
lst=list()
flag=0
for idx in range(10):lst.append((res[:idx+1],res[idx+1:10]))
for i in lst:
f1=s.find(i[0])
f2=s.rfind(i[1])
if f1!=-1 and f2!=-1 and f2>f1:
if f2==f1+len(i[0]):flag=1; break
if f1==0 and f2+len(i[1])==len(s):flag=1; break
if flag:print("YES")
else:print("NO") | Title: Cutting Banner
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
Input Specification:
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
Output Specification:
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
Demo Input:
['CODEWAITFORITFORCES\n', 'BOTTOMCODER\n', 'DECODEFORCES\n', 'DOGEFORCES\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
none | ```python
s=input()
res="CODEFORCES"
lst=list()
flag=0
for idx in range(10):lst.append((res[:idx+1],res[idx+1:10]))
for i in lst:
f1=s.find(i[0])
f2=s.rfind(i[1])
if f1!=-1 and f2!=-1 and f2>f1:
if f2==f1+len(i[0]):flag=1; break
if f1==0 and f2+len(i[1])==len(s):flag=1; break
if flag:print("YES")
else:print("NO")
``` | 0 |
|
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive. | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
},
{
"input": "Danil_and_part_time_job",
"output": "YES"
},
{
"input": "Ann_and_books",
"output": "YES"
},
{
"input": "Olya",
"output": "YES"
},
{
"input": "Nikita",
"output": "YES"
},
{
"input": "Slava",
"output": "YES"
},
{
"input": "Vanya",
"output": "NO"
},
{
"input": "I_dont_know_what_to_write_here",
"output": "NO"
},
{
"input": "danil_and_work",
"output": "NO"
},
{
"input": "Ann",
"output": "YES"
},
{
"input": "Batman_Nananananananan_Batman",
"output": "NO"
},
{
"input": "Olya_Nikita_Ann_Slava_Danil",
"output": "NO"
},
{
"input": "its_me_Mario",
"output": "NO"
},
{
"input": "A",
"output": "NO"
},
{
"input": "Wake_up_Neo",
"output": "NO"
},
{
"input": "Hardest_problem_ever",
"output": "NO"
},
{
"input": "Nikita_Nikita",
"output": "NO"
},
{
"input": "____________________________________________________________________________________________________",
"output": "NO"
},
{
"input": "Nikitb",
"output": "NO"
},
{
"input": "Unn",
"output": "NO"
},
{
"input": "oLya_adn_smth",
"output": "NO"
},
{
"input": "FloorISLava",
"output": "NO"
},
{
"input": "ann",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "AAnnnnn",
"output": "YES"
},
{
"input": "AnnAnn",
"output": "NO"
},
{
"input": "Annn",
"output": "YES"
},
{
"input": "Dilzhan",
"output": "NO"
},
{
"input": "Danilaaa",
"output": "YES"
},
{
"input": "AndAnn",
"output": "YES"
},
{
"input": "OlyaAnnAnn",
"output": "NO"
},
{
"input": "DanilDanilOlya",
"output": "NO"
},
{
"input": "DDanil",
"output": "YES"
},
{
"input": "AnnAnnDanil",
"output": "NO"
},
{
"input": "And_Danil",
"output": "YES"
},
{
"input": "abcddddDanil",
"output": "YES"
},
{
"input": "DanilOlyaOlya",
"output": "NO"
},
{
"input": "Nikitaaa",
"output": "YES"
},
{
"input": "aaabbba",
"output": "NO"
},
{
"input": "Ann_Ann_Danil",
"output": "NO"
},
{
"input": "Danil_Danil_Nikita",
"output": "NO"
},
{
"input": "AlexaaaaaaBBBBBOlyaDDDDD",
"output": "YES"
},
{
"input": "IloveDaniland",
"output": "YES"
},
{
"input": "AnAnn",
"output": "YES"
},
{
"input": "Danil_Danil_Olya",
"output": "NO"
},
{
"input": "DanilDanilSlava",
"output": "NO"
},
{
"input": "DanilDanil",
"output": "NO"
},
{
"input": "OlyOlya",
"output": "YES"
},
{
"input": "NikitaNikitb",
"output": "YES"
},
{
"input": "ababaca",
"output": "NO"
},
{
"input": "AnnNikitaNikitaNikitaNikita__good_luck",
"output": "NO"
}
] | 1,540,975,832 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 109 | 0 | d = 'Danil'
o = 'Olya'
s = 'Slava'
a = 'Ann'
n = 'Nikita'
st = input()
m = st.count(d) + st.count(o) + st.count(s) + st.count(a) + st.count(n)
if m == 1:
print('YES')
else:
print('NO') | Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive.
Input Specification:
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Output Specification:
Print "YES", if problem is from this contest, and "NO" otherwise.
Demo Input:
['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n']
Demo Output:
['NO', 'YES', 'NO']
Note:
none | ```python
d = 'Danil'
o = 'Olya'
s = 'Slava'
a = 'Ann'
n = 'Nikita'
st = input()
m = st.count(d) + st.count(o) + st.count(s) + st.count(a) + st.count(n)
if m == 1:
print('YES')
else:
print('NO')
``` | 3 |
|
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000 1000",
"output": "100"
},
{
"input": "8\n200000 1 200000 1 200000 1 200000 2",
"output": "1"
},
{
"input": "5\n20000 1 2 3 4",
"output": "20000"
},
{
"input": "2\n200000 1",
"output": "200000"
},
{
"input": "3\n2 100 2",
"output": "100"
},
{
"input": "2\n10 1",
"output": "10"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n5 5 5",
"output": "5"
},
{
"input": "2\n5 1",
"output": "5"
}
] | 1,594,921,375 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 20,992,000 | n = int(input())
l = list(map(int,input().split()))
if n == 1 :
print(*l)
else:
a = []
st = set(l)
m = len(st)
c = 0
for i in range(n-1 , 0 , -1):
if l[i] not in a :
a.append(l[i])
c +=1
if c == m - 1 :
break
#print(a)
for j in range(n):
if l[j] not in a :
print(l[j])
break
| Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input Specification:
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output Specification:
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Demo Input:
['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n']
Demo Output:
['3\n', '2\n']
Note:
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | ```python
n = int(input())
l = list(map(int,input().split()))
if n == 1 :
print(*l)
else:
a = []
st = set(l)
m = len(st)
c = 0
for i in range(n-1 , 0 , -1):
if l[i] not in a :
a.append(l[i])
c +=1
if c == m - 1 :
break
#print(a)
for j in range(n):
if l[j] not in a :
print(l[j])
break
``` | 0 |
|
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose? | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_". | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B. | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
{
"input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a",
"output": "C"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____",
"output": "C"
},
{
"input": "A.G_R__iT_ow_Y__Sm_al__u_____l_ltK\nB.CWRe__h__cbCF\nC._QJ_dVHCL_g_WBsMO__LC____hMNE_DoO__xea_ec\nD.___Zh_",
"output": "D"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.ejQ_E_E_G_e_SDjZ__lh_f_K__Z_i_B_U__S__S_EMD_ZEU_Sq\nB.o_JpInEdsrAY_T__D_S\nC.E_Vp_s\nD.a_AU_h",
"output": "A"
},
{
"input": "A.PN_m_P_qgOAMwDyxtbH__Yc__bPOh_wYH___n_Fv_qlZp_\nB._gLeDU__rr_vjrm__O_jl_R__DG___u_XqJjW_\nC.___sHLQzdTzT_tZ_Gs\nD.sZNcVa__M_To_bz_clFi_mH_",
"output": "C"
},
{
"input": "A.bR___cCYJg_Wbt____cxfXfC____c_O_\nB.guM\nC.__bzsH_Of__RjG__u_w_i__PXQL_U_Ow_U_n\nD._nHIuZsu_uU_stRC_k___vD_ZOD_u_z_c_Zf__p_iF_uD_Hdg",
"output": "B"
},
{
"input": "A.x_\nB.__RSiDT_\nC.Ci\nD.KLY_Hc_YN_xXg_DynydumheKTw_PFHo_vqXwm_DY_dA___OS_kG___",
"output": "D"
},
{
"input": "A.yYGJ_C__NYq_\nB.ozMUZ_cKKk_zVUPR_b_g_ygv_HoM__yAxvh__iE\nC.sgHJ___MYP__AWejchRvjSD_o\nD.gkfF_GiOqW_psMT_eS",
"output": "C"
},
{
"input": "A._LYm_nvl_E__RCFZ_IdO\nB.k__qIPO_ivvZyIG__L_\nC.D_SabLm_R___j_HS_t__\nD._adj_R_ngix____GSe_aw__SbOOl_",
"output": "C"
},
{
"input": "A.h_WiYTD_C_h___z_Gn_Th_uNh__g___jm\nB.__HeQaudCJcYfVi__Eg_vryuQrDkb_g__oy_BwX_Mu_\nC._MChdMhQA_UKrf_LGZk_ALTo_mnry_GNNza_X_D_u____ueJb__Y_h__CNUNDfmZATck_ad_XTbG\nD.NV___OoL__GfP_CqhD__RB_____v_T_xi",
"output": "C"
},
{
"input": "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_ysvPNmbrF__",
"output": "C"
},
{
"input": "A.aaaaaa\nB.aaa\nC.aaa\nD.aaa",
"output": "A"
},
{
"input": "A.aaa\nB.aaaaaa\nC.aaaaaa\nD.aaaaaa",
"output": "A"
},
{
"input": "A.a\nB.b\nC.c\nD.d",
"output": "C"
},
{
"input": "A._\nB.__\nC.____\nD.________",
"output": "C"
},
{
"input": "A.____\nB.________\nC.________\nD._______",
"output": "C"
},
{
"input": "A.h\nB.asdf\nC.asqw\nD.qwertasdfg",
"output": "C"
},
{
"input": "A.aa\nB.aaaaa\nC.aaaaaa\nD.aaaaaaaaaaaaa",
"output": "C"
},
{
"input": "A.ccc\nB.ccccccc\nC.ccc\nD.c",
"output": "C"
},
{
"input": "A.c\nB.ccc\nC.cccccccccccccccccc\nD.cccccc",
"output": "C"
},
{
"input": "A.aa\nB.bb\nC.cc\nD.ddd",
"output": "C"
},
{
"input": "A.QW\nB.WERT\nC.QWER\nD.QWERTYUI",
"output": "C"
}
] | 1,406,857,107 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | MC=['A', 'B', 'C', 'D']
lengths=[]
for t in range(4):
lengths.append(len(input())-2)
lengths2=lengths[:]
lengths.sort()
if lengths[0]*2<=lengths[1]:
print(MC[lengths2.index(lengths[0])])
elif lengths[-1]*2>=lengths[-2]:
print(MC[lengths2.index(lengths[-1])])
else:
print("C")
| Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose?
Input Specification:
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
Output Specification:
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
Demo Input:
['A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n', 'A.ab\nB.abcde\nC.ab\nD.abc\n', 'A.c\nB.cc\nC.c\nD.c\n']
Demo Output:
['D\n', 'C\n', 'B\n']
Note:
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B. | ```python
MC=['A', 'B', 'C', 'D']
lengths=[]
for t in range(4):
lengths.append(len(input())-2)
lengths2=lengths[:]
lengths.sort()
if lengths[0]*2<=lengths[1]:
print(MC[lengths2.index(lengths[0])])
elif lengths[-1]*2>=lengths[-2]:
print(MC[lengths2.index(lengths[-1])])
else:
print("C")
``` | 0 |
|
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. | Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -239 826 318 811 20 -732 -91 460 551 -610 555 -493 -154 442 -141 946 -913 -104 704 -380 699 32 106 -455 -518 214 -464 -861 243 -798 -472 559 529 -844 -32 871 -459 236 387 626 -318 -580 -611 -842 790 486 64 951 81 78 -693 403 -731 309 678 696 891 846 -106 918 212 -44 994 606 -829 -454 243 -477 -402 -818 -819 -310 -837 -209 736 424",
"output": "64"
},
{
"input": "2\n-1 0",
"output": "-1"
},
{
"input": "48\n-777 -767 -764 -713 -688 -682 -606 -586 -585 -483 -465 -440 -433 -397 -390 -377 -299 -252 -159 -147 -96 -29 -15 15 52 109 124 129 142 218 231 314 320 339 442 496 505 548 575 576 594 624 694 827 891 979 981 981",
"output": "15"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "4\n-1 -1 0 1",
"output": "-1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 1000000000",
"output": "0"
},
{
"input": "2\n1 -1",
"output": "-1"
},
{
"input": "2\n100 50",
"output": "50"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n606194955 -856471310 117647402",
"output": "117647402"
},
{
"input": "2\n615002717 -843553590",
"output": "-843553590"
},
{
"input": "2\n-1 2",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "5\n-638512131 348325781 -550537933 -618161835 -567935532",
"output": "-567935532"
},
{
"input": "1\n120",
"output": "120"
},
{
"input": "2\n-1000000000 1000000000",
"output": "-1000000000"
},
{
"input": "1\n618309368",
"output": "618309368"
}
] | 1,671,129,667 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | def start():
a=int(input())
b=list(map(int,input().split()))
b.sort()
print(b[a//2-1])
start()
| Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points.
Output Specification:
Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Demo Input:
['4\n1 2 3 4\n']
Demo Output:
['2\n']
Note:
none | ```python
def start():
a=int(input())
b=list(map(int,input().split()))
b.sort()
print(b[a//2-1])
start()
``` | 0 |
|
74 | A | Room Leader | PROGRAMMING | 1,000 | [
"implementation"
] | A. Room Leader | 2 | 256 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five problems, *A*, *B*, *C*, *D* and *E*. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.
You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems *A*, *B*, *C*, *D*, *E* correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers:
- 0<=≤<=*plus**i*,<=*minus**i*<=≤<=50; - 150<=≤<=*a**i*<=≤<=500 or *a**i*<==<=0, if problem *A* is not solved; - 300<=≤<=*b**i*<=≤<=1000 or *b**i*<==<=0, if problem *B* is not solved; - 450<=≤<=*c**i*<=≤<=1500 or *c**i*<==<=0, if problem *C* is not solved; - 600<=≤<=*d**i*<=≤<=2000 or *d**i*<==<=0, if problem *D* is not solved; - 750<=≤<=*e**i*<=≤<=2500 or *e**i*<==<=0, if problem *E* is not solved.
All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | Print on the single line the handle of the room leader. | [
"5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n"
] | [
"tourist"
] | The number of points that each participant from the example earns, are as follows:
- Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R — - 350 - some_participant — 2220
Thus, the leader of the room is tourist. | 500 | [
{
"input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0",
"output": "tourist"
},
{
"input": "1\nA 0 0 200 0 0 0 0",
"output": "A"
},
{
"input": "2\n12345678901234567890 1 0 200 0 0 0 0\n_ 1 0 201 0 0 0 0",
"output": "_"
},
{
"input": "5\nAb 0 0 481 900 1200 1600 2000\nCd 0 0 480 899 1200 1600 2000\nEf 0 0 480 900 1200 1600 2000\ngH 0 0 480 900 1200 1599 2000\nij 0 0 480 900 1199 1600 2001",
"output": "Ab"
},
{
"input": "4\nF1 0 0 150 0 0 0 0\nF2 0 1 0 0 0 0 0\nF3 0 2 0 0 0 0 0\nF4 0 3 0 0 0 0 0",
"output": "F1"
},
{
"input": "2\nA87h 5 0 199 0 0 0 0\nBcfg 7 0 0 0 0 0 0",
"output": "Bcfg"
},
{
"input": "10\nKh 40 26 0 0 0 0 1243\nn 46 50 500 0 910 1912 0\nU 18 1 182 0 457 0 0\nFth6A0uT6i 38 30 0 787 0 1121 0\nC5l 24 38 0 689 1082 0 0\nN 47 25 0 0 1065 0 1538\nznyL 9 24 0 315 0 0 0\nJ0kU 27 47 445 0 0 0 0\nlT0rwiD2pg 46 13 0 818 0 0 0\nuJzr 29 14 0 0 0 0 2387",
"output": "N"
},
{
"input": "2\nminus_one 0 4 199 0 0 0 0\nminus_two 0 4 198 0 0 0 0",
"output": "minus_one"
},
{
"input": "10\nW22kb1L1 0 39 0 465 0 1961 865\n1MCXiVYmu5ys0afl 0 38 0 0 0 1982 1241\nCxg706kUJtQ 0 23 211 0 0 1785 1056\nmzEY 0 16 0 0 0 1988 1404\nv8JUjmam5SFP 0 48 0 788 1199 1426 0\n7giq 0 21 0 780 1437 1363 1930\nsXsUGbAulj6Lbiq 0 32 205 0 0 603 0\nRepIrY1Er4PgK 0 13 381 872 927 1488 0\nleKBdKHLnLFz 0 29 220 0 0 1006 889\nD 0 26 497 0 0 0 1815",
"output": "7giq"
},
{
"input": "1\nZ 0 0 0 0 0 0 0",
"output": "Z"
},
{
"input": "3\nAbcd 0 4 189 0 0 0 0\nDefg 0 5 248 0 0 0 0\nGhh 1 3 0 0 0 0 0",
"output": "Defg"
},
{
"input": "3\ndf 0 6 0 0 0 0 0\njnm 1 8 300 0 0 0 0\n_ub_ 3 20 300 310 0 0 0",
"output": "jnm"
},
{
"input": "1\njhgcyt 0 50 0 0 0 0 0",
"output": "jhgcyt"
},
{
"input": "2\njhv 0 50 500 1000 1500 2000 2500\nPetr 2 1 489 910 1100 1300 1000",
"output": "jhv"
},
{
"input": "3\nufu 0 50 0 0 0 0 0\nhzEr65f 1 50 0 0 0 0 0\nytdttjfhfd 0 50 150 0 0 0 0",
"output": "ytdttjfhfd"
},
{
"input": "5\nufuf 0 50 0 0 0 0 0\nyfycy 50 0 500 1000 1500 2000 2500\n__u77 6 7 490 999 1456 1976 1356\n0 1 2 0 0 0 0 2452\ngu7fF 50 0 500 1000 1500 2000 2499",
"output": "yfycy"
},
{
"input": "2\nhfy 0 50 0 0 0 0 2500\nugug 0 50 0 0 0 0 2499",
"output": "hfy"
},
{
"input": "8\nA 0 0 0 0 0 0 0\nb 0 0 0 0 0 0 0\nc 0 0 0 0 0 0 0\nD 0 0 0 0 0 0 0\nE 1 0 0 0 0 0 0\nF 0 0 0 0 0 0 0\ng 0 0 0 0 0 0 0\nH 0 0 0 0 0 0 0",
"output": "E"
},
{
"input": "2\nyyyc 50 50 0 0 0 0 0\nydd 0 0 0 0 0 0 2499",
"output": "yyyc"
},
{
"input": "2\ntom 0 2 0 0 0 0 0\nmac 0 1 0 0 0 0 0",
"output": "mac"
},
{
"input": "1\ncool 0 10 0 0 0 0 0",
"output": "cool"
}
] | 1,673,687,529 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,867,200 | i=0
sum=-2501
leader='null'
n=int(input())
while i<n:
handle=str(input())
plus=int(input())
minus=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
x=plus*100+minus*50+a+b+c+d+e
if x>sum:
sum=x
leader=handle
i+=1
print(leader)
| Title: Room Leader
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five problems, *A*, *B*, *C*, *D* and *E*. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.
You are suggested to determine the leader for some room; the leader is a participant who has maximum points.
Input Specification:
The first line contains an integer *n*, which is the number of contestants in the room (1<=≤<=*n*<=≤<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" — it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems *A*, *B*, *C*, *D*, *E* correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers:
- 0<=≤<=*plus**i*,<=*minus**i*<=≤<=50; - 150<=≤<=*a**i*<=≤<=500 or *a**i*<==<=0, if problem *A* is not solved; - 300<=≤<=*b**i*<=≤<=1000 or *b**i*<==<=0, if problem *B* is not solved; - 450<=≤<=*c**i*<=≤<=1500 or *c**i*<==<=0, if problem *C* is not solved; - 600<=≤<=*d**i*<=≤<=2000 or *d**i*<==<=0, if problem *D* is not solved; - 750<=≤<=*e**i*<=≤<=2500 or *e**i*<==<=0, if problem *E* is not solved.
All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points).
Output Specification:
Print on the single line the handle of the room leader.
Demo Input:
['5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n']
Demo Output:
['tourist']
Note:
The number of points that each participant from the example earns, are as follows:
- Petr — 3860 - tourist — 4140 - Egor — 4030 - c00lH4x0R — - 350 - some_participant — 2220
Thus, the leader of the room is tourist. | ```python
i=0
sum=-2501
leader='null'
n=int(input())
while i<n:
handle=str(input())
plus=int(input())
minus=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
x=plus*100+minus*50+a+b+c+d+e
if x>sum:
sum=x
leader=handle
i+=1
print(leader)
``` | -1 |
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem. | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}. | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",
"output": "2"
},
{
"input": "51 52",
"output": "2"
},
{
"input": "47 52",
"output": "2"
},
{
"input": "38 98",
"output": "2"
},
{
"input": "30 37",
"output": "2"
},
{
"input": "56 92",
"output": "2"
},
{
"input": "900000000 1000000000",
"output": "2"
},
{
"input": "37622224 162971117",
"output": "2"
},
{
"input": "760632746 850720703",
"output": "2"
},
{
"input": "908580370 968054552",
"output": "2"
},
{
"input": "951594860 953554446",
"output": "2"
},
{
"input": "347877978 913527175",
"output": "2"
},
{
"input": "620769961 988145114",
"output": "2"
},
{
"input": "820844234 892579936",
"output": "2"
},
{
"input": "741254764 741254768",
"output": "2"
},
{
"input": "80270976 80270977",
"output": "2"
},
{
"input": "392602363 392602367",
"output": "2"
},
{
"input": "519002744 519002744",
"output": "519002744"
},
{
"input": "331900277 331900277",
"output": "331900277"
},
{
"input": "419873015 419873018",
"output": "2"
},
{
"input": "349533413 349533413",
"output": "349533413"
},
{
"input": "28829775 28829776",
"output": "2"
},
{
"input": "568814539 568814539",
"output": "568814539"
},
{
"input": "720270740 720270743",
"output": "2"
},
{
"input": "871232720 871232722",
"output": "2"
},
{
"input": "305693653 305693653",
"output": "305693653"
},
{
"input": "634097178 634097179",
"output": "2"
},
{
"input": "450868287 450868290",
"output": "2"
},
{
"input": "252662256 252662260",
"output": "2"
},
{
"input": "575062045 575062049",
"output": "2"
},
{
"input": "273072892 273072894",
"output": "2"
},
{
"input": "770439256 770439256",
"output": "770439256"
},
{
"input": "2 1000000000",
"output": "2"
},
{
"input": "6 8",
"output": "2"
},
{
"input": "2 879190747",
"output": "2"
},
{
"input": "5 5",
"output": "5"
},
{
"input": "999999937 999999937",
"output": "999999937"
},
{
"input": "3 3",
"output": "3"
},
{
"input": "5 100",
"output": "2"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 18",
"output": "2"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "39916801 39916801",
"output": "39916801"
},
{
"input": "3 8",
"output": "2"
},
{
"input": "13 13",
"output": "13"
},
{
"input": "4 8",
"output": "2"
},
{
"input": "3 12",
"output": "2"
},
{
"input": "6 12",
"output": "2"
},
{
"input": "999999103 999999103",
"output": "999999103"
},
{
"input": "100000007 100000007",
"output": "100000007"
},
{
"input": "3 99",
"output": "2"
},
{
"input": "999999733 999999733",
"output": "999999733"
},
{
"input": "5 10",
"output": "2"
},
{
"input": "982451653 982451653",
"output": "982451653"
},
{
"input": "999900001 1000000000",
"output": "2"
},
{
"input": "999727999 999727999",
"output": "999727999"
},
{
"input": "2 999999999",
"output": "2"
},
{
"input": "242 244",
"output": "2"
},
{
"input": "3 10",
"output": "2"
},
{
"input": "15 27",
"output": "2"
},
{
"input": "998244353 998244353",
"output": "998244353"
},
{
"input": "5 15",
"output": "2"
},
{
"input": "999999797 999999797",
"output": "999999797"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "999999929 999999929",
"output": "999999929"
},
{
"input": "3 111111",
"output": "2"
},
{
"input": "12 18",
"output": "2"
},
{
"input": "479001599 479001599",
"output": "479001599"
},
{
"input": "10000019 10000019",
"output": "10000019"
},
{
"input": "715827883 715827883",
"output": "715827883"
},
{
"input": "999992977 999992977",
"output": "999992977"
},
{
"input": "11 11",
"output": "11"
},
{
"input": "29 29",
"output": "29"
},
{
"input": "1000003 1000003",
"output": "1000003"
},
{
"input": "6 15",
"output": "2"
},
{
"input": "1200007 1200007",
"output": "1200007"
},
{
"input": "3 1000000000",
"output": "2"
},
{
"input": "990000023 990000023",
"output": "990000023"
},
{
"input": "1717 1717",
"output": "1717"
},
{
"input": "141650963 141650963",
"output": "141650963"
},
{
"input": "1002523 1002523",
"output": "1002523"
},
{
"input": "900000011 900000011",
"output": "900000011"
},
{
"input": "104729 104729",
"output": "104729"
},
{
"input": "4 12",
"output": "2"
},
{
"input": "100003 100003",
"output": "100003"
},
{
"input": "17 17",
"output": "17"
},
{
"input": "10 100",
"output": "2"
}
] | 1,618,410,797 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 0 | def most_frequent(List):
counter = 0
num = List[0]
for i in List:
curr_frequency = List.count(i)
if(curr_frequency> counter):
counter = curr_frequency
num = i
return num
l,r=map(int, input().split())
s=[]
for i in range(l,r+1):
for j in range(2,i+1):
if i%j==0:
s.append(j)
k=most_frequent(s)
print(k) | Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem.
Input Specification:
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Output Specification:
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
Demo Input:
['19 29\n', '3 6\n']
Demo Output:
['2\n', '3\n']
Note:
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}. | ```python
def most_frequent(List):
counter = 0
num = List[0]
for i in List:
curr_frequency = List.count(i)
if(curr_frequency> counter):
counter = curr_frequency
num = i
return num
l,r=map(int, input().split())
s=[]
for i in range(l,r+1):
for j in range(2,i+1):
if i%j==0:
s.append(j)
k=most_frequent(s)
print(k)
``` | 0 |
|
415 | B | Mashmokh and Tokens | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"implementation",
"math"
] | null | null | Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars.
Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save. | The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109). | Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day. | [
"5 1 4\n12 6 11 9 1\n",
"3 1 2\n1 2 3\n",
"1 1 1\n1\n"
] | [
"0 2 3 1 1 ",
"1 0 1 ",
"0 "
] | none | 1,000 | [
{
"input": "5 1 4\n12 6 11 9 1",
"output": "0 2 3 1 1 "
},
{
"input": "3 1 2\n1 2 3",
"output": "1 0 1 "
},
{
"input": "1 1 1\n1",
"output": "0 "
},
{
"input": "1 1 1000000000\n1000000000",
"output": "0 "
},
{
"input": "1 1 1000000000\n999999999",
"output": "999999999 "
},
{
"input": "10 1 100000000\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999",
"output": "99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 "
}
] | 1,613,745,583 | 943 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 217 | 10,035,200 | n,a,b= map(int,input().split())
x = list(map(int,input().split()))
ans = []
for i in range(n):
d = (x[i]*a) // b
ans.append(x[i]*a - d*b)
print(*ans) | Title: Mashmokh and Tokens
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars.
Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save.
Input Specification:
The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109).
Output Specification:
Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day.
Demo Input:
['5 1 4\n12 6 11 9 1\n', '3 1 2\n1 2 3\n', '1 1 1\n1\n']
Demo Output:
['0 2 3 1 1 ', '1 0 1 ', '0 ']
Note:
none | ```python
n,a,b= map(int,input().split())
x = list(map(int,input().split()))
ans = []
for i in range(n):
d = (x[i]*a) // b
ans.append(x[i]*a - d*b)
print(*ans)
``` | 0 |
|
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"input": "sunday\nsaturday",
"output": "NO"
},
{
"input": "monday\nmonday",
"output": "YES"
},
{
"input": "monday\nwednesday",
"output": "YES"
},
{
"input": "monday\nthursday",
"output": "YES"
},
{
"input": "monday\nfriday",
"output": "NO"
},
{
"input": "monday\nsaturday",
"output": "NO"
},
{
"input": "monday\nsunday",
"output": "NO"
},
{
"input": "tuesday\nmonday",
"output": "NO"
},
{
"input": "tuesday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nwednesday",
"output": "NO"
},
{
"input": "tuesday\nfriday",
"output": "YES"
},
{
"input": "tuesday\nsaturday",
"output": "NO"
},
{
"input": "tuesday\nsunday",
"output": "NO"
},
{
"input": "wednesday\nmonday",
"output": "NO"
},
{
"input": "wednesday\ntuesday",
"output": "NO"
},
{
"input": "wednesday\nwednesday",
"output": "YES"
},
{
"input": "wednesday\nthursday",
"output": "NO"
},
{
"input": "wednesday\nfriday",
"output": "YES"
},
{
"input": "wednesday\nsaturday",
"output": "YES"
},
{
"input": "wednesday\nsunday",
"output": "NO"
},
{
"input": "thursday\nmonday",
"output": "NO"
},
{
"input": "thursday\ntuesday",
"output": "NO"
},
{
"input": "thursday\nwednesday",
"output": "NO"
},
{
"input": "thursday\nthursday",
"output": "YES"
},
{
"input": "thursday\nfriday",
"output": "NO"
},
{
"input": "thursday\nsaturday",
"output": "YES"
},
{
"input": "thursday\nsunday",
"output": "YES"
},
{
"input": "friday\nmonday",
"output": "YES"
},
{
"input": "friday\ntuesday",
"output": "NO"
},
{
"input": "friday\nthursday",
"output": "NO"
},
{
"input": "friday\nsaturday",
"output": "NO"
},
{
"input": "friday\nsunday",
"output": "YES"
},
{
"input": "saturday\nmonday",
"output": "YES"
},
{
"input": "saturday\nwednesday",
"output": "NO"
},
{
"input": "saturday\nthursday",
"output": "NO"
},
{
"input": "saturday\nfriday",
"output": "NO"
},
{
"input": "saturday\nsaturday",
"output": "YES"
},
{
"input": "saturday\nsunday",
"output": "NO"
},
{
"input": "sunday\nmonday",
"output": "NO"
},
{
"input": "sunday\ntuesday",
"output": "YES"
},
{
"input": "sunday\nwednesday",
"output": "YES"
},
{
"input": "sunday\nthursday",
"output": "NO"
},
{
"input": "sunday\nfriday",
"output": "NO"
},
{
"input": "friday\nfriday",
"output": "YES"
},
{
"input": "friday\nsunday",
"output": "YES"
},
{
"input": "monday\nmonday",
"output": "YES"
},
{
"input": "friday\ntuesday",
"output": "NO"
},
{
"input": "thursday\nsaturday",
"output": "YES"
},
{
"input": "tuesday\nfriday",
"output": "YES"
},
{
"input": "sunday\nwednesday",
"output": "YES"
},
{
"input": "monday\nthursday",
"output": "YES"
},
{
"input": "saturday\nsunday",
"output": "NO"
},
{
"input": "friday\nmonday",
"output": "YES"
},
{
"input": "thursday\nthursday",
"output": "YES"
},
{
"input": "wednesday\nfriday",
"output": "YES"
},
{
"input": "thursday\nmonday",
"output": "NO"
},
{
"input": "wednesday\nsunday",
"output": "NO"
},
{
"input": "thursday\nfriday",
"output": "NO"
},
{
"input": "monday\nfriday",
"output": "NO"
},
{
"input": "wednesday\nsaturday",
"output": "YES"
},
{
"input": "thursday\nsunday",
"output": "YES"
},
{
"input": "saturday\nfriday",
"output": "NO"
},
{
"input": "saturday\nmonday",
"output": "YES"
}
] | 1,586,507,008 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def main():
from sys import stdin, stdout
dayNum={"saturday" : 0, "sunday" : 1, "monday" : 2, "tuesday" : 3, "wednesday" : 4, "thursday" : 5, "friday" : 6}
day1, day2=tuple(stdin.read().split())
day1=dayNum[day1]
day2=dayNum[day2]
stdout.write("YES\n" if (day1+28)%7==day2 or or (day1+30)%7 == day2 or (day1+31)%7 == day2 else "NO\n")
if __name__=='__main__':
main() | Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Input Specification:
The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Output Specification:
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).
Demo Input:
['monday\ntuesday\n', 'sunday\nsunday\n', 'saturday\ntuesday\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n']
Note:
In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | ```python
def main():
from sys import stdin, stdout
dayNum={"saturday" : 0, "sunday" : 1, "monday" : 2, "tuesday" : 3, "wednesday" : 4, "thursday" : 5, "friday" : 6}
day1, day2=tuple(stdin.read().split())
day1=dayNum[day1]
day2=dayNum[day2]
stdout.write("YES\n" if (day1+28)%7==day2 or or (day1+30)%7 == day2 or (day1+31)%7 == day2 else "NO\n")
if __name__=='__main__':
main()
``` | -1 |