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
168
A
Wizards and Demonstration
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*).
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
[ "10 1 14\n", "20 10 50\n", "1000 352 146\n" ]
[ "1\n", "0\n", "1108\n" ]
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
500
[ { "input": "10 1 14", "output": "1" }, { "input": "20 10 50", "output": "0" }, { "input": "1000 352 146", "output": "1108" }, { "input": "68 65 20", "output": "0" }, { "input": "78 28 27", "output": "0" }, { "input": "78 73 58", "output": "0" }, { "input": "70 38 66", "output": "9" }, { "input": "54 4 38", "output": "17" }, { "input": "3 1 69", "output": "2" }, { "input": "11 9 60", "output": "0" }, { "input": "71 49 65", "output": "0" }, { "input": "78 55 96", "output": "20" }, { "input": "2765 768 9020", "output": "248635" }, { "input": "3478 1728 9727", "output": "336578" }, { "input": "9678 6173 5658", "output": "541409" }, { "input": "1138 570 6666", "output": "75290" }, { "input": "7754 204 9038", "output": "700603" }, { "input": "8403 7401 4769", "output": "393339" }, { "input": "4909 2111 8860", "output": "432827" }, { "input": "6571 6449 8965", "output": "582642" }, { "input": "9178 2255 7996", "output": "731618" }, { "input": "6151 6148 3746", "output": "224269" }, { "input": "8890 5449 8734", "output": "771004" }, { "input": "7879 2590 2818", "output": "219441" }, { "input": "8484 6400 547", "output": "40008" }, { "input": "7835 6710 1639", "output": "121706" }, { "input": "2379 1436 9663", "output": "228447" }, { "input": "6487 5670 8", "output": "0" }, { "input": "4470 2543 6", "output": "0" }, { "input": "7261 5328 10", "output": "0" }, { "input": "3871 3795 7", "output": "0" }, { "input": "9620 6557 6", "output": "0" }, { "input": "4890 1112 5", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 1 10000", "output": "99" }, { "input": "10000 1 1", "output": "99" }, { "input": "10000 1 10000", "output": "999999" }, { "input": "10000 10000 1", "output": "0" }, { "input": "10000 10000 10000", "output": "990000" }, { "input": "67 1 3", "output": "2" }, { "input": "7878 4534 9159", "output": "717013" }, { "input": "1 1 1", "output": "0" }, { "input": "3271 5 50", "output": "1631" } ]
1,591,057,204
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
186
0
a, b, c = map(int, input().split()) c/=100 a*=c a*=10 finals = 0 if a%10 > 0: a/=10 finals = round(a)+1 else: a/=10 finals = round(a) print(finals-b)
Title: Wizards and Demonstration Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. Input Specification: The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*). Output Specification: Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). Demo Input: ['10 1 14\n', '20 10 50\n', '1000 352 146\n'] Demo Output: ['1\n', '0\n', '1108\n'] Note: In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
```python a, b, c = map(int, input().split()) c/=100 a*=c a*=10 finals = 0 if a%10 > 0: a/=10 finals = round(a)+1 else: a/=10 finals = round(a) print(finals-b) ```
0
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,662,055,235
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
s = input() a = int(s[len(s)-1]) if a==0: print(s) elif a>0 and a<5: print(int(s)-a) else: print(int(s)+1)
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 s = input() a = int(s[len(s)-1]) if a==0: print(s) elif a>0 and a<5: print(int(s)-a) else: print(int(s)+1) ```
0
0
none
none
none
0
[ "none" ]
null
null
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $-100$ and $100$.
Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower).
[ "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples:
0
[ { "input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "output": "NO" }, { "input": "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8", "output": "YES" }, { "input": "2 2 4 2 4 4 2 4\n0 3 3 6 6 3 3 0", "output": "YES" }, { "input": "-5 -5 5 -5 5 5 -5 5\n-5 7 0 2 5 7 0 12", "output": "YES" }, { "input": "-5 -5 5 -5 5 5 -5 5\n-5 12 0 7 5 12 0 17", "output": "NO" }, { "input": "-5 -5 5 -5 5 5 -5 5\n6 0 0 6 -6 0 0 -6", "output": "YES" }, { "input": "-100 -100 100 -100 100 100 -100 100\n-100 0 0 -100 100 0 0 100", "output": "YES" }, { "input": "92 1 92 98 -5 98 -5 1\n44 60 56 48 44 36 32 48", "output": "YES" }, { "input": "-12 -54 -12 33 -99 33 -99 -54\n-77 -40 -86 -31 -77 -22 -68 -31", "output": "YES" }, { "input": "3 45 19 45 19 61 3 61\n-29 45 -13 29 3 45 -13 61", "output": "YES" }, { "input": "79 -19 79 15 45 15 45 -19\n-1 24 -29 52 -1 80 27 52", "output": "NO" }, { "input": "75 -57 75 -21 39 -21 39 -57\n10 -42 -32 0 10 42 52 0", "output": "NO" }, { "input": "-11 53 9 53 9 73 -11 73\n-10 9 -43 42 -10 75 23 42", "output": "YES" }, { "input": "-10 -36 -10 27 -73 27 -73 -36\n44 -28 71 -55 44 -82 17 -55", "output": "NO" }, { "input": "-63 -15 6 -15 6 54 -63 54\n15 -13 -8 10 15 33 38 10", "output": "YES" }, { "input": "47 15 51 15 51 19 47 19\n19 0 -27 46 19 92 65 46", "output": "NO" }, { "input": "87 -5 87 79 3 79 3 -5\n36 36 78 -6 36 -48 -6 -6", "output": "YES" }, { "input": "-4 56 10 56 10 70 -4 70\n-11 47 -35 71 -11 95 13 71", "output": "YES" }, { "input": "-41 6 -41 8 -43 8 -43 6\n-7 27 43 -23 -7 -73 -57 -23", "output": "NO" }, { "input": "44 -58 44 7 -21 7 -21 -58\n22 19 47 -6 22 -31 -3 -6", "output": "YES" }, { "input": "-37 -63 49 -63 49 23 -37 23\n-52 68 -21 37 -52 6 -83 37", "output": "YES" }, { "input": "93 20 93 55 58 55 58 20\n61 -17 39 5 61 27 83 5", "output": "YES" }, { "input": "-7 4 -7 58 -61 58 -61 4\n-28 45 -17 34 -28 23 -39 34", "output": "YES" }, { "input": "24 -79 87 -79 87 -16 24 -16\n-59 21 -85 47 -59 73 -33 47", "output": "NO" }, { "input": "-68 -15 6 -15 6 59 -68 59\n48 -18 57 -27 48 -36 39 -27", "output": "NO" }, { "input": "25 1 25 91 -65 91 -65 1\n24 3 15 12 24 21 33 12", "output": "YES" }, { "input": "55 24 73 24 73 42 55 42\n49 17 10 56 49 95 88 56", "output": "YES" }, { "input": "69 -65 69 -28 32 -28 32 -65\n-1 50 43 6 -1 -38 -45 6", "output": "NO" }, { "input": "86 -26 86 18 42 18 42 -26\n3 -22 -40 21 3 64 46 21", "output": "YES" }, { "input": "52 -47 52 -30 35 -30 35 -47\n49 -22 64 -37 49 -52 34 -37", "output": "YES" }, { "input": "27 -59 27 9 -41 9 -41 -59\n-10 -17 2 -29 -10 -41 -22 -29", "output": "YES" }, { "input": "-90 2 0 2 0 92 -90 92\n-66 31 -86 51 -66 71 -46 51", "output": "YES" }, { "input": "-93 -86 -85 -86 -85 -78 -93 -78\n-13 61 0 48 -13 35 -26 48", "output": "NO" }, { "input": "-3 -45 85 -45 85 43 -3 43\n-22 0 -66 44 -22 88 22 44", "output": "YES" }, { "input": "-27 -73 72 -73 72 26 -27 26\n58 11 100 -31 58 -73 16 -31", "output": "YES" }, { "input": "-40 -31 8 -31 8 17 -40 17\n0 18 -35 53 0 88 35 53", "output": "NO" }, { "input": "-15 -63 -15 7 -85 7 -85 -63\n-35 -40 -33 -42 -35 -44 -37 -42", "output": "YES" }, { "input": "-100 -100 -100 100 100 100 100 -100\n-100 0 0 100 100 0 0 -100", "output": "YES" }, { "input": "67 33 67 67 33 67 33 33\n43 11 9 45 43 79 77 45", "output": "YES" }, { "input": "14 8 9 8 9 3 14 3\n-2 -13 14 3 30 -13 14 -29", "output": "YES" }, { "input": "4 3 7 3 7 6 4 6\n7 29 20 16 7 3 -6 16", "output": "YES" }, { "input": "14 30 3 30 3 19 14 19\n19 -13 11 -5 19 3 27 -5", "output": "NO" }, { "input": "-54 3 -50 3 -50 -1 -54 -1\n3 -50 -6 -41 -15 -50 -6 -59", "output": "NO" }, { "input": "3 8 3 -10 21 -10 21 8\n-9 2 -21 -10 -9 -22 3 -10", "output": "YES" }, { "input": "-35 3 -21 3 -21 -11 -35 -11\n-8 -10 3 -21 -8 -32 -19 -21", "output": "NO" }, { "input": "-5 -23 -5 -31 3 -31 3 -23\n-7 -23 -2 -28 3 -23 -2 -18", "output": "YES" }, { "input": "3 20 10 20 10 13 3 13\n3 20 21 38 39 20 21 2", "output": "YES" }, { "input": "25 3 16 3 16 12 25 12\n21 -2 16 -7 11 -2 16 3", "output": "YES" }, { "input": "-1 18 -1 3 14 3 14 18\n14 3 19 8 14 13 9 8", "output": "YES" }, { "input": "-44 -17 -64 -17 -64 3 -44 3\n-56 15 -44 27 -32 15 -44 3", "output": "YES" }, { "input": "17 3 2 3 2 18 17 18\n22 23 2 3 -18 23 2 43", "output": "YES" }, { "input": "3 -22 3 -36 -11 -36 -11 -22\n11 -44 19 -36 11 -28 3 -36", "output": "YES" }, { "input": "3 45 3 48 0 48 0 45\n13 38 4 47 13 56 22 47", "output": "NO" }, { "input": "3 -10 2 -10 2 -9 3 -9\n38 -10 20 -28 2 -10 20 8", "output": "YES" }, { "input": "-66 3 -47 3 -47 22 -66 22\n-52 -2 -45 5 -52 12 -59 5", "output": "YES" }, { "input": "3 37 -1 37 -1 41 3 41\n6 31 9 34 6 37 3 34", "output": "NO" }, { "input": "13 1 15 1 15 3 13 3\n13 19 21 11 13 3 5 11", "output": "YES" }, { "input": "20 8 3 8 3 -9 20 -9\n2 -11 3 -10 2 -9 1 -10", "output": "NO" }, { "input": "3 41 3 21 -17 21 -17 41\n26 12 10 28 26 44 42 28", "output": "NO" }, { "input": "11 11 11 3 3 3 3 11\n-12 26 -27 11 -12 -4 3 11", "output": "YES" }, { "input": "-29 3 -29 12 -38 12 -38 3\n-35 9 -29 15 -23 9 -29 3", "output": "YES" }, { "input": "3 -32 1 -32 1 -30 3 -30\n4 -32 -16 -52 -36 -32 -16 -12", "output": "YES" }, { "input": "-16 -10 -16 9 3 9 3 -10\n-8 -1 2 9 12 -1 2 -11", "output": "YES" }, { "input": "3 -42 -5 -42 -5 -34 3 -34\n-8 -54 -19 -43 -8 -32 3 -43", "output": "YES" }, { "input": "-47 3 -37 3 -37 -7 -47 -7\n-37 3 -33 -1 -37 -5 -41 -1", "output": "YES" }, { "input": "10 3 12 3 12 5 10 5\n12 4 20 12 12 20 4 12", "output": "YES" }, { "input": "3 -41 -9 -41 -9 -53 3 -53\n18 -16 38 -36 18 -56 -2 -36", "output": "YES" }, { "input": "3 40 2 40 2 41 3 41\n22 39 13 48 4 39 13 30", "output": "NO" }, { "input": "21 26 21 44 3 44 3 26\n-20 38 -32 26 -20 14 -8 26", "output": "NO" }, { "input": "0 7 3 7 3 10 0 10\n3 9 -17 29 -37 9 -17 -11", "output": "YES" }, { "input": "3 21 3 18 6 18 6 21\n-27 18 -11 2 5 18 -11 34", "output": "YES" }, { "input": "-29 13 -39 13 -39 3 -29 3\n-36 -4 -50 -18 -36 -32 -22 -18", "output": "NO" }, { "input": "3 -26 -2 -26 -2 -21 3 -21\n-5 -37 -16 -26 -5 -15 6 -26", "output": "YES" }, { "input": "3 9 -1 9 -1 13 3 13\n-9 17 -1 9 -9 1 -17 9", "output": "YES" }, { "input": "48 8 43 8 43 3 48 3\n31 -4 43 8 55 -4 43 -16", "output": "YES" }, { "input": "-3 1 3 1 3 -5 -3 -5\n20 -22 3 -5 20 12 37 -5", "output": "YES" }, { "input": "14 3 14 -16 -5 -16 -5 3\n14 2 15 1 14 0 13 1", "output": "YES" }, { "input": "-10 12 -10 -1 3 -1 3 12\n1 10 -2 7 -5 10 -2 13", "output": "YES" }, { "input": "39 21 21 21 21 3 39 3\n27 3 47 -17 27 -37 7 -17", "output": "YES" }, { "input": "3 1 3 17 -13 17 -13 1\n17 20 10 27 3 20 10 13", "output": "NO" }, { "input": "15 -18 3 -18 3 -6 15 -6\n29 -1 16 -14 3 -1 16 12", "output": "YES" }, { "input": "41 -6 41 3 32 3 32 -6\n33 3 35 5 33 7 31 5", "output": "YES" }, { "input": "7 35 3 35 3 39 7 39\n23 15 3 35 23 55 43 35", "output": "YES" }, { "input": "19 19 35 19 35 3 19 3\n25 -9 16 -18 7 -9 16 0", "output": "NO" }, { "input": "-20 3 -20 9 -26 9 -26 3\n-19 4 -21 2 -19 0 -17 2", "output": "YES" }, { "input": "13 3 22 3 22 -6 13 -6\n26 3 22 -1 18 3 22 7", "output": "YES" }, { "input": "-4 -8 -4 -15 3 -15 3 -8\n-10 5 -27 -12 -10 -29 7 -12", "output": "YES" }, { "input": "3 15 7 15 7 19 3 19\n-12 30 -23 19 -12 8 -1 19", "output": "NO" }, { "input": "-12 3 5 3 5 -14 -12 -14\n-14 22 5 3 24 22 5 41", "output": "YES" }, { "input": "-37 3 -17 3 -17 -17 -37 -17\n-9 -41 9 -23 -9 -5 -27 -23", "output": "YES" }, { "input": "3 57 3 45 -9 45 -9 57\n8 50 21 37 8 24 -5 37", "output": "YES" }, { "input": "42 3 42 -6 33 -6 33 3\n42 4 41 3 40 4 41 5", "output": "YES" }, { "input": "3 59 3 45 -11 45 -11 59\n-2 50 -8 44 -2 38 4 44", "output": "YES" }, { "input": "-51 3 -39 3 -39 15 -51 15\n-39 14 -53 0 -39 -14 -25 0", "output": "YES" }, { "input": "-7 -15 -7 3 11 3 11 -15\n15 -1 22 -8 15 -15 8 -8", "output": "YES" }, { "input": "3 -39 14 -39 14 -50 3 -50\n17 -39 5 -27 -7 -39 5 -51", "output": "YES" }, { "input": "91 -27 91 29 35 29 35 -27\n59 39 95 3 59 -33 23 3", "output": "YES" }, { "input": "-81 -60 -31 -60 -31 -10 -81 -10\n-58 -68 -95 -31 -58 6 -21 -31", "output": "YES" }, { "input": "78 -59 78 -2 21 -2 21 -59\n48 1 86 -37 48 -75 10 -37", "output": "YES" }, { "input": "-38 -26 32 -26 32 44 -38 44\n2 -27 -44 19 2 65 48 19", "output": "YES" }, { "input": "73 -54 73 -4 23 -4 23 -54\n47 1 77 -29 47 -59 17 -29", "output": "YES" }, { "input": "-6 -25 46 -25 46 27 -6 27\n21 -43 -21 -1 21 41 63 -1", "output": "YES" }, { "input": "-17 -91 -17 -27 -81 -27 -81 -91\n-48 -21 -12 -57 -48 -93 -84 -57", "output": "YES" }, { "input": "-7 16 43 16 43 66 -7 66\n18 -7 -27 38 18 83 63 38", "output": "YES" }, { "input": "-46 11 16 11 16 73 -46 73\n-18 -8 -67 41 -18 90 31 41", "output": "YES" }, { "input": "-33 -64 25 -64 25 -6 -33 -6\n-5 -74 -51 -28 -5 18 41 -28", "output": "YES" }, { "input": "99 -100 100 -100 100 -99 99 -99\n99 -99 100 -98 99 -97 98 -98", "output": "YES" }, { "input": "-100 -100 -100 -99 -99 -99 -99 -100\n-10 -10 -9 -9 -10 -8 -11 -9", "output": "NO" }, { "input": "-4 3 -3 3 -3 4 -4 4\n0 -4 4 0 0 4 -4 0", "output": "NO" }, { "input": "0 0 10 0 10 10 0 10\n11 9 13 7 15 9 13 11", "output": "NO" }, { "input": "1 1 1 6 6 6 6 1\n5 8 8 11 11 8 8 5", "output": "NO" }, { "input": "99 99 99 100 100 100 100 99\n-100 0 0 100 100 0 0 -100", "output": "NO" }, { "input": "0 0 0 2 2 2 2 0\n5 1 9 5 5 9 1 5", "output": "NO" }, { "input": "3 2 3 3 4 3 4 2\n0 4 4 0 0 -4 -4 0", "output": "NO" }, { "input": "0 0 2 0 2 2 0 2\n4 1 7 4 4 7 1 4", "output": "NO" }, { "input": "3 6 3 8 5 8 5 6\n2 9 4 11 6 9 4 7", "output": "YES" }, { "input": "0 0 10 0 10 10 0 10\n-1 5 5 -1 11 5 5 11", "output": "YES" }, { "input": "0 0 1 0 1 1 0 1\n3 0 6 3 3 6 0 3", "output": "NO" }, { "input": "3 7 4 7 4 6 3 6\n0 0 10 10 20 0 10 -10", "output": "NO" }, { "input": "0 0 0 1 1 1 1 0\n0 3 3 6 6 3 3 0", "output": "NO" }, { "input": "0 0 0 4 4 4 4 0\n3 6 7 10 11 6 7 2", "output": "NO" }, { "input": "0 0 0 1 1 1 1 0\n0 10 10 0 20 10 10 20", "output": "NO" } ]
1,529,317,381
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
sq1 = list(map(int, input().split())) sq2 = list(map(int, input().split())) a1 = min(sq1) a2 = max(sq1) a3 = (a1 + a2) / 2 if sq2[1] == sq2[5]: if (a3 > sq2[0] and a3 > sq2[4]) or (a3 < sq2[0] and a3 < sq2[4]): print("no") elif (a3 > sq2[3] and a3 > sq2[7]) or (a3 < sq2[3] and a3 < sq2[7]): print("no") else: print("yes") else: if (a3 > sq2[1] and a3 > sq2[5]) or (a3 < sq2[1] and a3 < sq2[5]): print("no") elif (a3 > sq2[2] and a3 > sq2[6]) or (a3 < sq2[2] and a3 < sq2[6]): print("no") else: print("yes")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input Specification: The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $-100$ and $100$. Output Specification: Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Demo Input: ['0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n', '0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n', '6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples:
```python sq1 = list(map(int, input().split())) sq2 = list(map(int, input().split())) a1 = min(sq1) a2 = max(sq1) a3 = (a1 + a2) / 2 if sq2[1] == sq2[5]: if (a3 > sq2[0] and a3 > sq2[4]) or (a3 < sq2[0] and a3 < sq2[4]): print("no") elif (a3 > sq2[3] and a3 > sq2[7]) or (a3 < sq2[3] and a3 < sq2[7]): print("no") else: print("yes") else: if (a3 > sq2[1] and a3 > sq2[5]) or (a3 < sq2[1] and a3 < sq2[5]): print("no") elif (a3 > sq2[2] and a3 > sq2[6]) or (a3 < sq2[2] and a3 < sq2[6]): print("no") else: print("yes") ```
0
825
A
Binary Protocol
PROGRAMMING
1,100
[ "implementation" ]
null
null
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: - Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character. Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*. The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Print the decoded number.
[ "3\n111\n", "9\n110011101\n" ]
[ "3\n", "2031\n" ]
none
0
[ { "input": "3\n111", "output": "3" }, { "input": "9\n110011101", "output": "2031" }, { "input": "1\n1", "output": "1" }, { "input": "3\n100", "output": "100" }, { "input": "5\n10001", "output": "1001" }, { "input": "14\n11001100011000", "output": "202002000" }, { "input": "31\n1000011111111100011110111111111", "output": "100090049" }, { "input": "53\n10110111011110111110111111011111110111111110111111111", "output": "123456789" }, { "input": "89\n11111111101111111110111111111011111111101111111110111111111011111111101111111110111111111", "output": "999999999" }, { "input": "10\n1000000000", "output": "1000000000" }, { "input": "2\n10", "output": "10" }, { "input": "4\n1110", "output": "30" }, { "input": "8\n10101010", "output": "11110" } ]
1,500,217,994
494
Python 3
OK
TESTS
13
62
4,608,000
length = input() s = input() s = s.split('0') result = "" for i in s: result += str(len(i)) print(result)
Title: Binary Protocol Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: - Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character. Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number. Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*. The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'. Output Specification: Print the decoded number. Demo Input: ['3\n111\n', '9\n110011101\n'] Demo Output: ['3\n', '2031\n'] Note: none
```python length = input() s = input() s = s.split('0') result = "" for i in s: result += str(len(i)) print(result) ```
3
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,637,078,073
2,147,483,647
PyPy 3
OK
TESTS
29
77
0
import math import sys input = sys.stdin.readline output = sys.stdout.write def inList(): return(list(map(int,input().split()))) def inVar(): return map(int,input().split()) def main(): n , k = inVar() s = list(input()) s.pop() mp = {} for i in range(0 , 27): mp[i] = 0 for char in s: mp[ord(char) - ord('a') + 1] = 1 ans = 0 cur = -2 while k: flag = 0 for i in range(27): if mp[i] == 1 and cur + 1 < i: mp[i] = 0 cur = i ans += i flag = 1 break if flag == 0: break k -= 1 if k != 0: ans = -1 print(ans) main()
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 import math import sys input = sys.stdin.readline output = sys.stdout.write def inList(): return(list(map(int,input().split()))) def inVar(): return map(int,input().split()) def main(): n , k = inVar() s = list(input()) s.pop() mp = {} for i in range(0 , 27): mp[i] = 0 for char in s: mp[ord(char) - ord('a') + 1] = 1 ans = 0 cur = -2 while k: flag = 0 for i in range(27): if mp[i] == 1 and cur + 1 < i: mp[i] = 0 cur = i ans += i flag = 1 break if flag == 0: break k -= 1 if k != 0: ans = -1 print(ans) main() ```
3
583
B
Robot's Task
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to collect at least *a**i* any pieces of information from the other computers. Doc can hack the computer only if he is right next to it. The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all *n* parts of information if initially it is next to computer with number 1. It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=&lt;<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information.
[ "3\n0 2 0\n", "5\n4 2 3 0 1\n", "7\n0 3 1 0 5 2 6\n" ]
[ "1\n", "3\n", "2\n" ]
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece. In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer. In the third sample the optimal order of collecting parts from computers can look like that: 1-&gt;3-&gt;4-&gt;6-&gt;2-&gt;5-&gt;7.
1,000
[ { "input": "3\n0 2 0", "output": "1" }, { "input": "5\n4 2 3 0 1", "output": "3" }, { "input": "7\n0 3 1 0 5 2 6", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "2\n0 1", "output": "0" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "3\n0 2 1", "output": "1" }, { "input": "10\n7 1 9 3 5 8 6 0 2 4", "output": "9" }, { "input": "10\n1 3 5 7 9 8 6 4 2 0", "output": "9" }, { "input": "10\n5 0 0 1 3 2 2 2 5 7", "output": "1" }, { "input": "10\n8 6 5 3 9 7 1 4 2 0", "output": "8" }, { "input": "10\n1 2 4 5 0 1 3 7 1 4", "output": "2" }, { "input": "10\n3 4 8 9 5 1 2 0 6 7", "output": "6" }, { "input": "10\n2 2 0 0 6 2 9 0 2 0", "output": "2" }, { "input": "10\n1 7 5 3 2 6 0 8 4 9", "output": "8" }, { "input": "9\n1 3 8 6 2 4 5 0 7", "output": "7" }, { "input": "9\n1 3 5 7 8 6 4 2 0", "output": "8" }, { "input": "9\n2 4 3 1 3 0 5 4 3", "output": "3" }, { "input": "9\n3 5 6 8 7 0 4 2 1", "output": "5" }, { "input": "9\n2 0 8 1 0 3 0 5 3", "output": "2" }, { "input": "9\n6 2 3 7 4 8 5 1 0", "output": "4" }, { "input": "9\n3 1 5 6 0 3 2 0 0", "output": "2" }, { "input": "9\n2 6 4 1 0 8 5 3 7", "output": "7" }, { "input": "100\n27 20 18 78 93 38 56 2 48 75 36 88 96 57 69 10 25 74 68 86 65 85 66 14 22 12 43 80 99 34 42 63 61 71 77 15 37 54 21 59 23 94 28 30 50 84 62 76 47 16 26 64 82 92 72 53 17 11 41 91 35 83 79 95 67 13 1 7 3 4 73 90 8 19 33 58 98 32 39 45 87 52 60 46 6 44 49 70 51 9 5 29 31 24 40 97 81 0 89 55", "output": "69" }, { "input": "100\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 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 0", "output": "99" }, { "input": "100\n13 89 81 0 62 1 59 92 29 13 1 37 2 8 53 15 20 34 12 70 0 85 97 55 84 60 37 54 14 65 22 69 30 22 95 44 59 85 50 80 9 71 91 93 74 21 11 78 28 21 40 81 76 24 26 60 48 85 61 68 89 76 46 73 34 52 98 29 4 38 94 51 5 55 6 27 74 27 38 37 82 70 44 89 51 59 30 37 15 55 63 78 42 39 71 43 4 10 2 13", "output": "21" }, { "input": "100\n1 3 5 7 58 11 13 15 17 19 45 23 25 27 29 31 33 35 37 39 41 43 21 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 81 79 83 85 87 89 91 93 95 97 48 98 96 94 92 90 88 44 84 82 80 78 76 74 72 70 68 66 64 62 60 9 56 54 52 50 99 46 86 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0", "output": "96" }, { "input": "100\n32 47 74 8 14 4 12 68 18 0 44 80 14 38 6 57 4 72 69 3 21 78 74 22 39 32 58 63 34 33 23 6 39 11 6 12 18 4 0 11 20 28 16 1 22 12 57 55 13 48 43 1 50 18 87 6 11 45 38 67 37 14 7 56 6 41 1 55 5 73 78 64 38 18 38 8 37 0 18 61 37 58 58 62 86 5 0 2 15 43 34 61 2 21 15 9 69 1 11 24", "output": "4" }, { "input": "100\n40 3 55 7 6 77 13 46 17 64 21 54 25 27 91 41 1 15 37 82 23 43 42 47 26 95 53 5 11 59 61 9 78 67 69 58 73 0 36 79 60 83 2 87 63 33 71 89 97 99 98 93 56 92 19 88 86 84 39 28 65 20 34 76 51 94 66 12 62 49 96 72 24 52 48 50 44 35 74 31 38 57 81 32 22 80 70 29 30 18 68 16 14 90 10 8 85 4 45 75", "output": "75" }, { "input": "100\n34 16 42 21 84 27 11 7 82 16 95 39 36 64 26 0 38 37 2 2 16 56 16 61 55 42 26 5 61 8 30 20 19 15 9 78 5 34 15 0 3 17 36 36 1 5 4 26 18 0 14 25 7 5 91 7 43 26 79 37 17 27 40 55 66 7 0 2 16 23 68 35 2 5 9 21 1 7 2 9 4 3 22 15 27 6 0 47 5 0 12 9 20 55 36 10 6 8 5 1", "output": "3" }, { "input": "100\n35 53 87 49 13 24 93 20 5 11 31 32 40 52 96 46 1 25 66 69 28 88 84 82 70 9 75 39 26 21 18 29 23 57 90 16 48 22 95 0 58 43 7 73 8 62 63 30 64 92 79 3 6 94 34 12 76 99 67 55 56 97 14 91 68 36 44 78 41 71 86 89 47 74 4 45 98 37 80 33 83 27 42 59 72 54 17 60 51 81 15 77 65 50 10 85 61 19 38 2", "output": "67" }, { "input": "99\n89 96 56 31 32 14 9 66 87 34 69 5 92 54 41 52 46 30 22 26 16 18 20 68 62 73 90 43 79 33 58 98 37 45 10 78 94 51 19 0 91 39 28 47 17 86 3 61 77 7 15 64 55 83 65 71 97 88 6 48 24 11 8 42 81 4 63 93 50 74 35 12 95 27 53 82 29 85 84 60 72 40 36 57 23 13 38 59 49 1 75 44 76 2 21 25 70 80 67", "output": "75" }, { "input": "99\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 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 0", "output": "98" }, { "input": "99\n82 7 6 77 17 28 90 3 68 12 63 60 24 20 4 81 71 85 57 45 11 84 3 91 49 34 89 82 0 50 48 88 36 76 36 5 62 48 20 2 20 45 69 27 37 62 42 31 57 51 92 84 89 25 7 62 12 23 23 56 30 90 27 10 77 58 48 38 56 68 57 15 33 1 34 67 16 47 75 70 69 28 38 16 5 61 85 76 44 90 37 22 77 94 55 1 97 8 69", "output": "22" }, { "input": "99\n1 51 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 42 43 45 47 49 3 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 98 96 94 92 90 88 86 84 82 80 8 76 74 72 70 68 66 22 62 60 58 56 54 52 0 48 46 44 41 40 38 36 34 32 30 28 26 24 64 20 18 16 14 12 10 78 6 4 2 50", "output": "96" }, { "input": "99\n22 3 19 13 65 87 28 17 41 40 31 21 8 37 29 65 65 53 16 33 13 5 76 4 72 9 2 76 57 72 50 15 75 0 30 13 83 36 12 31 49 51 65 22 48 31 60 15 2 17 6 1 8 0 1 63 3 16 7 7 2 1 47 28 26 21 2 36 1 5 20 25 44 0 2 39 46 30 33 11 15 34 34 4 84 52 0 39 7 3 17 15 6 38 52 64 26 1 0", "output": "3" }, { "input": "99\n24 87 25 82 97 11 37 15 23 19 34 17 76 13 45 89 33 1 27 78 63 43 54 47 49 2 42 41 75 83 61 90 65 67 21 71 60 57 77 62 81 58 85 69 3 91 68 55 72 93 29 94 66 16 88 86 84 53 14 39 35 44 9 70 80 92 56 79 74 5 64 31 52 50 48 46 51 59 40 38 36 96 32 30 28 95 7 22 20 18 26 73 12 10 8 6 4 98 0", "output": "74" }, { "input": "99\n22 14 0 44 6 17 6 6 37 45 0 48 19 8 57 8 10 0 3 12 25 2 5 53 9 49 15 6 38 14 9 40 38 22 27 12 64 10 11 35 89 19 46 39 12 24 48 0 52 1 27 27 24 4 64 24 5 0 67 3 5 39 0 1 13 37 2 8 46 1 28 70 6 79 14 15 33 6 7 34 6 18 4 71 1 55 33 71 18 11 47 23 72 53 65 32 2 7 28", "output": "3" }, { "input": "99\n28 59 73 89 52 27 0 20 36 12 83 95 31 24 54 94 49 14 51 34 50 93 13 1 2 68 63 48 41 81 23 43 18 9 16 38 33 60 62 3 40 85 72 69 90 98 11 37 22 44 35 6 21 39 82 10 64 66 96 42 74 30 8 67 97 46 84 32 17 57 75 71 5 26 4 55 58 29 7 15 45 19 92 91 78 65 88 25 86 80 77 87 79 53 47 70 56 76 61", "output": "63" } ]
1,626,622,787
2,147,483,647
Python 3
OK
TESTS
56
202
6,963,200
from sys import * input = lambda:stdin.readline() int_arr = lambda : list(map(int,stdin.readline().strip().split())) str_arr = lambda :list(map(str,stdin.readline().split())) get_str = lambda : map(str,stdin.readline().strip().split()) get_int = lambda: map(int,stdin.readline().strip().split()) get_float = lambda : map(float,stdin.readline().strip().split()) mod = 1000000007 setrecursionlimit(1000) n = int(input()) arr = int_arr() ct = 0 cond = 0 tot = -1 while True: if len(set(arr)) == 1 and arr[0] == -1: break if cond % 2 == 0: cond = 1 tot += 1 for i in range(n): if arr[i] != -1 and arr[i] <= ct: ct += 1 arr[i] = -1 last = i else: cond = 2 tot += 1 for i in range(last,-1,-1): if arr[i] != -1 and arr[i] <= ct: ct += 1 arr[i] = -1 print(tot)
Title: Robot's Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to collect at least *a**i* any pieces of information from the other computers. Doc can hack the computer only if he is right next to it. The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all *n* parts of information if initially it is next to computer with number 1. It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=&lt;<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. Output Specification: Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information. Demo Input: ['3\n0 2 0\n', '5\n4 2 3 0 1\n', '7\n0 3 1 0 5 2 6\n'] Demo Output: ['1\n', '3\n', '2\n'] Note: In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece. In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer. In the third sample the optimal order of collecting parts from computers can look like that: 1-&gt;3-&gt;4-&gt;6-&gt;2-&gt;5-&gt;7.
```python from sys import * input = lambda:stdin.readline() int_arr = lambda : list(map(int,stdin.readline().strip().split())) str_arr = lambda :list(map(str,stdin.readline().split())) get_str = lambda : map(str,stdin.readline().strip().split()) get_int = lambda: map(int,stdin.readline().strip().split()) get_float = lambda : map(float,stdin.readline().strip().split()) mod = 1000000007 setrecursionlimit(1000) n = int(input()) arr = int_arr() ct = 0 cond = 0 tot = -1 while True: if len(set(arr)) == 1 and arr[0] == -1: break if cond % 2 == 0: cond = 1 tot += 1 for i in range(n): if arr[i] != -1 and arr[i] <= ct: ct += 1 arr[i] = -1 last = i else: cond = 2 tot += 1 for i in range(last,-1,-1): if arr[i] != -1 and arr[i] <= ct: ct += 1 arr[i] = -1 print(tot) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,669,146,966
2,147,483,647
Python 3
OK
TESTS
81
92
0
t=int(input()) x=[] y=[] z=[] for i in range(0,t,1): a,b,c=map(int,input().split()) x.append(a) y.append(b) z.append(c) p=sum(x) q=sum(y) z=sum(z) if(p==0 and q==0 and z==0): print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python t=int(input()) x=[] y=[] z=[] for i in range(0,t,1): a,b,c=map(int,input().split()) x.append(a) y.append(b) z.append(c) p=sum(x) q=sum(y) z=sum(z) if(p==0 and q==0 and z==0): print("YES") else: print("NO") ```
3.977
0
none
none
none
0
[ "none" ]
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.
0
[ { "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,530,557,351
2,147,483,647
Python 3
OK
TESTS
33
436
23,654,400
n=int(input()) l=list(map(int,input().split())) d1,d2={},{} for i in l: try: d1[i]+=1 except: d1.update({i:0}) d1[i]+=1 x=list(d1.keys()) f=len(x)-1 if f==0: print(l[0]) else: s=set() for i in range(n-1,-1,-1): s.add(l[i]) if len(s)==f: break print(list(set(x)-s)[0])
Title: none 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())) d1,d2={},{} for i in l: try: d1[i]+=1 except: d1.update({i:0}) d1[i]+=1 x=list(d1.keys()) f=len(x)-1 if f==0: print(l[0]) else: s=set() for i in range(n-1,-1,-1): s.add(l[i]) if len(s)==f: break print(list(set(x)-s)[0]) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,697,107,978
2,147,483,647
Python 3
OK
TESTS
102
46
0
a = str(input()) b = str(input()) n = 0 for i in a: if i != b[n]: print(1, end='') if i == b[n]: print(0, end='') n += 1
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python a = str(input()) b = str(input()) n = 0 for i in a: if i != b[n]: print(1, end='') if i == b[n]: print(0, end='') n += 1 ```
3.9885
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, { "input": "192", "output": "4 188" }, { "input": "86", "output": "4 82" }, { "input": "46220", "output": "4 46216" }, { "input": "57114", "output": "4 57110" }, { "input": "869", "output": "4 865" }, { "input": "738457", "output": "4 738453" }, { "input": "58113", "output": "6 58107" }, { "input": "4864", "output": "4 4860" }, { "input": "15", "output": "6 9" }, { "input": "74752", "output": "4 74748" }, { "input": "6073", "output": "4 6069" }, { "input": "1289", "output": "4 1285" }, { "input": "20", "output": "4 16" }, { "input": "58134", "output": "4 58130" }, { "input": "57756", "output": "4 57752" }, { "input": "765", "output": "6 759" }, { "input": "59", "output": "4 55" }, { "input": "991666", "output": "4 991662" }, { "input": "70761", "output": "4 70757" }, { "input": "13", "output": "4 9" }, { "input": "999999", "output": "4 999995" }, { "input": "17", "output": "8 9" }, { "input": "21", "output": "6 15" }, { "input": "19", "output": "4 15" }, { "input": "100007", "output": "6 100001" }, { "input": "999987", "output": "6 999981" }, { "input": "22", "output": "4 18" } ]
1,695,243,975
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
62
2,048,000
import re from os import path import sys #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: if(path.exists('INPUT.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: k = int(input()) print(k-8, k-4)
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers. Input Specification: The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). Output Specification: Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. Demo Input: ['12\n', '15\n', '23\n', '1000000\n'] Demo Output: ['4 8\n', '6 9\n', '8 15\n', '500000 500000\n'] Note: In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
```python import re from os import path import sys #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: if(path.exists('INPUT.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: k = int(input()) print(k-8, k-4) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,669,121,707
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n,m,a=map(int,input().split()) if n%a==0: n1=n/a else: n1=(n//a)+1 if m%a==0: n2=m/a else: n2=(m//a)+1 print(n1+n2)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n,m,a=map(int,input().split()) if n%a==0: n1=n/a else: n1=(n//a)+1 if m%a==0: n2=m/a else: n2=(m//a)+1 print(n1+n2) ```
0
965
A
Paper Airplanes
PROGRAMMING
800
[ "math" ]
null
null
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
[ "5 3 2 3\n", "5 3 100 1\n" ]
[ "4\n", "5\n" ]
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
500
[ { "input": "5 3 2 3", "output": "4" }, { "input": "5 3 100 1", "output": "5" }, { "input": "10000 10000 1 1", "output": "100000000" }, { "input": "1 1 10000 10000", "output": "1" }, { "input": "300 300 21 23", "output": "196" }, { "input": "300 2 37 51", "output": "6" }, { "input": "2 400 23 57", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "10000 10000 3 2", "output": "16670000" }, { "input": "1 2 1 2", "output": "1" }, { "input": "1 1 2 2", "output": "1" }, { "input": "1 1 10 10", "output": "1" }, { "input": "5324 5439 32 13", "output": "69622" }, { "input": "9000 1 2432 1", "output": "9000" }, { "input": "230 1234 9124 23", "output": "10" }, { "input": "11 1 1 1", "output": "11" }, { "input": "6246 8489 1227 9", "output": "4858" }, { "input": "9 20 5 7", "output": "6" } ]
1,525,606,844
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
7,065,600
def bmm(n,m): if m>n : k = m m = n n = k if m == 0 : return n if n%m == 0 : return m return bmm(m,n%m)
Title: Paper Airplanes Time Limit: None seconds Memory Limit: None megabytes Problem Description: To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy? Input Specification: The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. Output Specification: Print a single integer — the minimum number of packs they should buy. Demo Input: ['5 3 2 3\n', '5 3 100 1\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
```python def bmm(n,m): if m>n : k = m m = n n = k if m == 0 : return n if n%m == 0 : return m return bmm(m,n%m) ```
0
760
A
Petr and a calendar
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Print single integer: the number of columns the table should have.
[ "1 7\n", "1 1\n", "11 6\n" ]
[ "6\n", "5\n", "5\n" ]
The first example corresponds to the January 2017 shown on the picture in the statements. In the second example 1-st January is Monday, so the whole month fits into 5 columns. In the third example 1-st November is Saturday and 5 columns is enough.
500
[ { "input": "1 7", "output": "6" }, { "input": "1 1", "output": "5" }, { "input": "11 6", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "2 1", "output": "4" }, { "input": "8 6", "output": "6" }, { "input": "1 1", "output": "5" }, { "input": "1 2", "output": "5" }, { "input": "1 3", "output": "5" }, { "input": "1 4", "output": "5" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "6" }, { "input": "2 1", "output": "4" }, { "input": "2 2", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "2 4", "output": "5" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "3 1", "output": "5" }, { "input": "3 2", "output": "5" }, { "input": "3 3", "output": "5" }, { "input": "3 4", "output": "5" }, { "input": "3 5", "output": "5" }, { "input": "3 6", "output": "6" }, { "input": "3 7", "output": "6" }, { "input": "4 1", "output": "5" }, { "input": "4 2", "output": "5" }, { "input": "4 3", "output": "5" }, { "input": "4 4", "output": "5" }, { "input": "4 5", "output": "5" }, { "input": "4 6", "output": "5" }, { "input": "4 7", "output": "6" }, { "input": "5 1", "output": "5" }, { "input": "5 2", "output": "5" }, { "input": "5 3", "output": "5" }, { "input": "5 4", "output": "5" }, { "input": "5 5", "output": "5" }, { "input": "5 6", "output": "6" }, { "input": "5 7", "output": "6" }, { "input": "6 1", "output": "5" }, { "input": "6 2", "output": "5" }, { "input": "6 3", "output": "5" }, { "input": "6 4", "output": "5" }, { "input": "6 5", "output": "5" }, { "input": "6 6", "output": "5" }, { "input": "6 7", "output": "6" }, { "input": "7 1", "output": "5" }, { "input": "7 2", "output": "5" }, { "input": "7 3", "output": "5" }, { "input": "7 4", "output": "5" }, { "input": "7 5", "output": "5" }, { "input": "7 6", "output": "6" }, { "input": "7 7", "output": "6" }, { "input": "8 1", "output": "5" }, { "input": "8 2", "output": "5" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output": "5" }, { "input": "8 5", "output": "5" }, { "input": "8 6", "output": "6" }, { "input": "8 7", "output": "6" }, { "input": "9 1", "output": "5" }, { "input": "9 2", "output": "5" }, { "input": "9 3", "output": "5" }, { "input": "9 4", "output": "5" }, { "input": "9 5", "output": "5" }, { "input": "9 6", "output": "5" }, { "input": "9 7", "output": "6" }, { "input": "10 1", "output": "5" }, { "input": "10 2", "output": "5" }, { "input": "10 3", "output": "5" }, { "input": "10 4", "output": "5" }, { "input": "10 5", "output": "5" }, { "input": "10 6", "output": "6" }, { "input": "10 7", "output": "6" }, { "input": "11 1", "output": "5" }, { "input": "11 2", "output": "5" }, { "input": "11 3", "output": "5" }, { "input": "11 4", "output": "5" }, { "input": "11 5", "output": "5" }, { "input": "11 6", "output": "5" }, { "input": "11 7", "output": "6" }, { "input": "12 1", "output": "5" }, { "input": "12 2", "output": "5" }, { "input": "12 3", "output": "5" }, { "input": "12 4", "output": "5" }, { "input": "12 5", "output": "5" }, { "input": "12 6", "output": "6" }, { "input": "12 7", "output": "6" }, { "input": "1 4", "output": "5" }, { "input": "1 5", "output": "5" }, { "input": "9 7", "output": "6" }, { "input": "2 6", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "2 2", "output": "5" }, { "input": "4 7", "output": "6" }, { "input": "12 6", "output": "6" }, { "input": "12 3", "output": "5" }, { "input": "3 6", "output": "6" }, { "input": "9 6", "output": "5" }, { "input": "7 6", "output": "6" }, { "input": "11 7", "output": "6" }, { "input": "6 6", "output": "5" } ]
1,685,201,702
2,147,483,647
Python 3
OK
TESTS
104
46
0
from math import ceil m, d = map(int,input().split()) a = [31,28,31,30,31,30,31,31,30,31,30,31] n = a[m-1] print(ceil((n-(8-d))/7)+1)
Title: Petr and a calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap. Input Specification: The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). Output Specification: Print single integer: the number of columns the table should have. Demo Input: ['1 7\n', '1 1\n', '11 6\n'] Demo Output: ['6\n', '5\n', '5\n'] Note: The first example corresponds to the January 2017 shown on the picture in the statements. In the second example 1-st January is Monday, so the whole month fits into 5 columns. In the third example 1-st November is Saturday and 5 columns is enough.
```python from math import ceil m, d = map(int,input().split()) a = [31,28,31,30,31,30,31,31,30,31,30,31] n = a[m-1] print(ceil((n-(8-d))/7)+1) ```
3
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { "input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "output": "1077" }, { "input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "output": "568" }, { "input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA", "output": "70" }, { "input": "W", "output": "0" }, { "input": "DBA", "output": "0" }, { "input": "RQAWNACASAAKAGAAAAQ", "output": "10" }, { "input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA", "output": "111" }, { "input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA", "output": "411" }, { "input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ", "output": "625" }, { "input": "QORZOYAQ", "output": "1" }, { "input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA", "output": "13174" }, { "input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT", "output": "10420" }, { "input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ", "output": "12488" }, { "input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA", "output": "9114" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "35937" }, { "input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE", "output": "254" }, { "input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE", "output": "2174" }, { "input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ", "output": "2962" }, { "input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA", "output": "2482" }, { "input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ", "output": "7768" }, { "input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA", "output": "5422" }, { "input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ", "output": "3024" }, { "input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ", "output": "4527" }, { "input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH", "output": "6416" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ", "output": "13136" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA", "output": "14231" }, { "input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "15296" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA", "output": "20825" }, { "input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ", "output": "20825" }, { "input": "Q", "output": "0" }, { "input": "A", "output": "0" }, { "input": "FFF", "output": "0" }, { "input": "AAAAAA", "output": "0" } ]
1,614,586,143
2,147,483,647
Python 3
OK
TESTS
43
77
307,200
import sys word = str(sys.stdin.readline().strip()) letters = [] cnt = 0 for i in word: if i == 'A' or i == 'Q': letters.append(i) for i in range(len(letters)): if letters[i] == 'Q': for j in range(i, len(letters)): if letters[j] == 'A': for k in range(j, len(letters)): if letters[k] == 'Q': cnt += 1 print(cnt)
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. Input Specification: The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. Output Specification: Print a single integer — the number of subsequences "QAQ" in the string. Demo Input: ['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n'] Demo Output: ['4\n', '3\n'] Note: In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
```python import sys word = str(sys.stdin.readline().strip()) letters = [] cnt = 0 for i in word: if i == 'A' or i == 'Q': letters.append(i) for i in range(len(letters)): if letters[i] == 'Q': for j in range(i, len(letters)): if letters[j] == 'A': for k in range(j, len(letters)): if letters[k] == 'Q': cnt += 1 print(cnt) ```
3
742
A
Arpa’s hard exam and Mehrdad’s naive cheat
PROGRAMMING
1,000
[ "implementation", "math", "number theory" ]
null
null
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Print single integer — the last digit of 1378*n*.
[ "1\n", "2\n" ]
[ "8", "4" ]
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
500
[ { "input": "1", "output": "8" }, { "input": "2", "output": "4" }, { "input": "1000", "output": "6" }, { "input": "3", "output": "2" }, { "input": "4", "output": "6" }, { "input": "1000000000", "output": "6" }, { "input": "5", "output": "8" }, { "input": "6", "output": "4" }, { "input": "999999999", "output": "2" }, { "input": "1378", "output": "4" }, { "input": "13781378", "output": "4" }, { "input": "51202278", "output": "4" }, { "input": "999999998", "output": "4" }, { "input": "999999997", "output": "8" }, { "input": "12193721", "output": "8" }, { "input": "0", "output": "1" }, { "input": "989898989", "output": "8" }, { "input": "7", "output": "2" }, { "input": "8", "output": "6" }, { "input": "9", "output": "8" }, { "input": "10", "output": "4" }, { "input": "11", "output": "2" }, { "input": "12", "output": "6" }, { "input": "13", "output": "8" }, { "input": "14", "output": "4" }, { "input": "15", "output": "2" }, { "input": "16", "output": "6" }, { "input": "999999996", "output": "6" }, { "input": "999999995", "output": "2" }, { "input": "999999994", "output": "4" } ]
1,663,229,056
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
11,468,800
n= int(input()) x=1378 for i in range(1,n): x=1378*x s=str(x) print(s[len(s)-1])
Title: Arpa’s hard exam and Mehrdad’s naive cheat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. Input Specification: The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). Output Specification: Print single integer — the last digit of 1378*n*. Demo Input: ['1\n', '2\n'] Demo Output: ['8', '4'] Note: In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
```python n= int(input()) x=1378 for i in range(1,n): x=1378*x s=str(x) print(s[len(s)-1]) ```
0
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "output": "444" }, { "input": "1000000", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "47", "output": "44477777" }, { "input": "100", "output": "4444777777777777" }, { "input": "700", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "485", "output": "44447777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "111", "output": "444447777777777777" }, { "input": "85", "output": "4477777777777" }, { "input": "114", "output": "444477777777777777" }, { "input": "474", "output": "444777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "74", "output": "47777777777" }, { "input": "1000", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "1024", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "4444", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "45784", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10000", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9854", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "186", "output": "477777777777777777777777777" }, { "input": "10416", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10417", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "3840", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "100000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9876", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "99999", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "777777", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "854759", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "11000", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "18951", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999999", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "888887", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999998", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "40008", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10691", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "9", "output": "-1" }, { "input": "8", "output": "44" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "999997", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999996", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999990", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999980", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "800000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "980000", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." } ]
1,585,363,623
2,147,483,647
Python 3
OK
TESTS
51
342
307,200
n = input() n = int(n) four_amount = seven_amount = current_seven = 0 k = n while k >= 0: if k%4 == 0: four_amount=k//4 seven_amount = current_seven current_seven += 1 k = n - 7*current_seven if four_amount == 0 and seven_amount == 0: print(-1) else: print('4'*four_amount + '7'*seven_amount)
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. Output Specification: Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. Demo Input: ['11\n', '10\n'] Demo Output: ['47\n', '-1\n'] Note: none
```python n = input() n = int(n) four_amount = seven_amount = current_seven = 0 k = n while k >= 0: if k%4 == 0: four_amount=k//4 seven_amount = current_seven current_seven += 1 k = n - 7*current_seven if four_amount == 0 and seven_amount == 0: print(-1) else: print('4'*four_amount + '7'*seven_amount) ```
3.913928
344
A
Magnets
PROGRAMMING
800
[ "implementation" ]
null
null
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
On the single line of the output print the number of groups of magnets.
[ "6\n10\n10\n10\n01\n10\n10\n", "4\n01\n01\n10\n10\n" ]
[ "3\n", "2\n" ]
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
500
[ { "input": "6\n10\n10\n10\n01\n10\n10", "output": "3" }, { "input": "4\n01\n01\n10\n10", "output": "2" }, { "input": "1\n10", "output": "1" }, { "input": "2\n01\n10", "output": "2" }, { "input": "2\n10\n10", "output": "1" }, { "input": "3\n10\n01\n10", "output": "3" }, { "input": "1\n01", "output": "1" }, { "input": "2\n01\n01", "output": "1" }, { "input": "2\n10\n01", "output": "2" }, { "input": "3\n01\n01\n01", "output": "1" }, { "input": "3\n10\n10\n01", "output": "2" }, { "input": "3\n01\n10\n10", "output": "2" }, { "input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10", "output": "55" } ]
1,694,357,660
2,147,483,647
Python 3
OK
TESTS
31
310
7,680,000
n=int(input()) magnets=[input() for i in range(n)] groups=1 for i in range(1,n): if magnets[i]!=magnets[i-1]: groups+=1 print(groups)
Title: Magnets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. Output Specification: On the single line of the output print the number of groups of magnets. Demo Input: ['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n'] Demo Output: ['3\n', '2\n'] Note: The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
```python n=int(input()) magnets=[input() for i in range(n)] groups=1 for i in range(1,n): if magnets[i]!=magnets[i-1]: groups+=1 print(groups) ```
3
911
C
Three Garlands
PROGRAMMING
1,400
[ "brute force", "constructive algorithms" ]
null
null
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th second, then it is lit only during seconds *x*, *x*<=+<=*k**i*, *x*<=+<=2*k**i*, *x*<=+<=3*k**i* and so on. Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers *x*1, *x*2 and *x*3 (not necessarily distinct) so that he will switch on the first garland during *x*1-th second, the second one — during *x*2-th second, and the third one — during *x*3-th second, respectively, and during each second starting from *max*(*x*1,<=*x*2,<=*x*3) at least one garland will be lit. Help Mishka by telling him if it is possible to do this!
The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands.
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO.
[ "2 2 3\n", "4 2 3\n" ]
[ "YES\n", "NO\n" ]
In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what *x*<sub class="lower-index">3</sub> is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though. In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
0
[ { "input": "2 2 3", "output": "YES" }, { "input": "4 2 3", "output": "NO" }, { "input": "1499 1498 1500", "output": "NO" }, { "input": "1500 1500 1500", "output": "NO" }, { "input": "100 4 1", "output": "YES" }, { "input": "4 2 4", "output": "YES" }, { "input": "3 3 3", "output": "YES" }, { "input": "2 3 6", "output": "NO" }, { "input": "2 3 3", "output": "NO" }, { "input": "4 4 2", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "2 11 2", "output": "YES" }, { "input": "4 4 4", "output": "NO" }, { "input": "4 4 5", "output": "NO" }, { "input": "3 3 2", "output": "NO" }, { "input": "3 6 6", "output": "NO" }, { "input": "2 3 2", "output": "YES" }, { "input": "1 1 3", "output": "YES" }, { "input": "3 3 4", "output": "NO" }, { "input": "2 4 4", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "2 10 10", "output": "NO" }, { "input": "3 4 4", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "2 4 5", "output": "NO" }, { "input": "228 2 2", "output": "YES" }, { "input": "2 998 1000", "output": "NO" }, { "input": "2 6 6", "output": "NO" }, { "input": "6 4 7", "output": "NO" }, { "input": "2 5 2", "output": "YES" }, { "input": "2 100 100", "output": "NO" }, { "input": "7 7 2", "output": "NO" }, { "input": "3 3 6", "output": "NO" }, { "input": "82 3 82", "output": "NO" }, { "input": "2 3 5", "output": "NO" }, { "input": "1 218 924", "output": "YES" }, { "input": "4 4 123", "output": "NO" }, { "input": "4 4 3", "output": "NO" }, { "input": "3 4 2", "output": "NO" }, { "input": "2 2 5", "output": "YES" }, { "input": "2 10 2", "output": "YES" }, { "input": "5 2 2", "output": "YES" }, { "input": "3 3 9", "output": "NO" }, { "input": "1 5 5", "output": "YES" }, { "input": "2 4 6", "output": "NO" }, { "input": "15 3 3", "output": "NO" }, { "input": "1 5 10", "output": "YES" }, { "input": "2 3 14", "output": "NO" }, { "input": "1265 2 593", "output": "NO" }, { "input": "2 2 567", "output": "YES" }, { "input": "1 6 5", "output": "YES" }, { "input": "2 2 7", "output": "YES" }, { "input": "2 2 1500", "output": "YES" }, { "input": "3 6 9", "output": "NO" }, { "input": "1 46 79", "output": "YES" }, { "input": "4 3 3", "output": "NO" }, { "input": "2 4 8", "output": "NO" }, { "input": "1493 1489 1487", "output": "NO" }, { "input": "1 2 3", "output": "YES" }, { "input": "1 2 5", "output": "YES" }, { "input": "1 2 8", "output": "YES" }, { "input": "3 4 5", "output": "NO" }, { "input": "2 2 4", "output": "YES" }, { "input": "3 2 3", "output": "NO" }, { "input": "7 2 2", "output": "YES" }, { "input": "3 2 2", "output": "YES" }, { "input": "6 7 4", "output": "NO" } ]
1,631,018,941
841
PyPy 3
WRONG_ANSWER
TESTS
5
108
20,172,800
import sys input = sys.stdin.readline k = list(map(int, input().split())) k.sort() ans = "NO" if k[0] == 1: ans = "YES" if k[0] == k[1] == 2: ans = "YES" if k[0] == k[1] == k[2] == 3: ans = "YES" print(ans)
Title: Three Garlands Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th second, then it is lit only during seconds *x*, *x*<=+<=*k**i*, *x*<=+<=2*k**i*, *x*<=+<=3*k**i* and so on. Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers *x*1, *x*2 and *x*3 (not necessarily distinct) so that he will switch on the first garland during *x*1-th second, the second one — during *x*2-th second, and the third one — during *x*3-th second, respectively, and during each second starting from *max*(*x*1,<=*x*2,<=*x*3) at least one garland will be lit. Help Mishka by telling him if it is possible to do this! Input Specification: The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands. Output Specification: If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO. Demo Input: ['2 2 3\n', '4 2 3\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what *x*<sub class="lower-index">3</sub> is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though. In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
```python import sys input = sys.stdin.readline k = list(map(int, input().split())) k.sort() ans = "NO" if k[0] == 1: ans = "YES" if k[0] == k[1] == 2: ans = "YES" if k[0] == k[1] == k[2] == 3: ans = "YES" print(ans) ```
0
965
C
Greedy Arkady
PROGRAMMING
2,000
[ "math" ]
null
null
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies to the second person, the next $x$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $x$) will be thrown away. Arkady can't choose $x$ greater than $M$ as it is considered greedy. Also, he can't choose such a small $x$ that some person will receive candies more than $D$ times, as it is considered a slow splitting. Please find what is the maximum number of candies Arkady can receive by choosing some valid $x$.
The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.
Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $x$.
[ "20 4 5 2\n", "30 9 4 1\n" ]
[ "8\n", "4\n" ]
In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total. Note that if Arkady chooses $x = 5$, he will receive only $5$ candies, and if he chooses $x = 3$, he will receive only $3 + 3 = 6$ candies as well as the second person, the third and the fourth persons will receive $3$ candies, and $2$ candies will be thrown away. He can't choose $x = 1$ nor $x = 2$ because in these cases he will receive candies more than $2$ times. In the second example Arkady has to choose $x = 4$, because any smaller value leads to him receiving candies more than $1$ time.
1,500
[ { "input": "20 4 5 2", "output": "8" }, { "input": "30 9 4 1", "output": "4" }, { "input": "2 2 1 1", "output": "1" }, { "input": "42 20 5 29", "output": "5" }, { "input": "1000000000000000000 135 1000000000000000 1000", "output": "8325624421831635" }, { "input": "100 33 100 100", "output": "100" }, { "input": "1000000000 1000000000 1000000000 1000", "output": "1000000000" }, { "input": "1000000000 32428 1000000000 1000", "output": "1000000000" }, { "input": "1000000000 324934 1000 1000", "output": "4000" }, { "input": "1000000000000000000 32400093004 10000000 1000", "output": "40000000" }, { "input": "885 2 160 842", "output": "504" }, { "input": "216 137 202 208", "output": "202" }, { "input": "72 66 28 9", "output": "28" }, { "input": "294 4 13 8", "output": "80" }, { "input": "9 2 2 3", "output": "4" }, { "input": "31 3 2 8", "output": "10" }, { "input": "104 2 5 11", "output": "50" }, { "input": "1000000000000000000 1000000000000000000 1000 1000", "output": "1000" }, { "input": "1000000000000000000 100000000000000000 1 1000", "output": "10" }, { "input": "23925738098196565 23925738098196565 23925738098196565 1000", "output": "23925738098196565" }, { "input": "576460752303423488 576460752303423488 351082447248993993 1000", "output": "351082447248993993" }, { "input": "962768465676381898 72057594037927936 586039918340257175 256", "output": "586039918340257175" }, { "input": "1000000000000000000 1000000000000000000 10 1000", "output": "10" }, { "input": "23925738098196565 23925738098196565 1 1000", "output": "1" }, { "input": "1000000000000000000 1000000000000000000 1 1000", "output": "1" } ]
1,636,332,015
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
93
28,364,800
def process(n, k, M, D): if n <= M: return n s = 1 e = D while s+1 < e: m = (s+e)//2 x = n//(m*k-k+1) if x > M: s, e = m, e else: s, e = s, m x = min(M, n//(e*k-k+1)) return max(M, e*x) n, k, M, D = [int(x) for x in input().split()] print(process(n, k, M, D))
Title: Greedy Arkady Time Limit: None seconds Memory Limit: None megabytes Problem Description: $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies to the second person, the next $x$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $x$) will be thrown away. Arkady can't choose $x$ greater than $M$ as it is considered greedy. Also, he can't choose such a small $x$ that some person will receive candies more than $D$ times, as it is considered a slow splitting. Please find what is the maximum number of candies Arkady can receive by choosing some valid $x$. Input Specification: The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies. Output Specification: Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $x$. Demo Input: ['20 4 5 2\n', '30 9 4 1\n'] Demo Output: ['8\n', '4\n'] Note: In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total. Note that if Arkady chooses $x = 5$, he will receive only $5$ candies, and if he chooses $x = 3$, he will receive only $3 + 3 = 6$ candies as well as the second person, the third and the fourth persons will receive $3$ candies, and $2$ candies will be thrown away. He can't choose $x = 1$ nor $x = 2$ because in these cases he will receive candies more than $2$ times. In the second example Arkady has to choose $x = 4$, because any smaller value leads to him receiving candies more than $1$ time.
```python def process(n, k, M, D): if n <= M: return n s = 1 e = D while s+1 < e: m = (s+e)//2 x = n//(m*k-k+1) if x > M: s, e = m, e else: s, e = s, m x = min(M, n//(e*k-k+1)) return max(M, e*x) n, k, M, D = [int(x) for x in input().split()] print(process(n, k, M, D)) ```
0
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, { "input": "24 54 37\n60 63 6\n1 84 26", "output": "110\n101\n011" }, { "input": "23 10 40\n15 6 40\n92 80 77", "output": "101\n100\n000" }, { "input": "62 74 80\n95 74 93\n2 47 95", "output": "010\n001\n110" }, { "input": "80 83 48\n26 0 66\n47 76 37", "output": "000\n000\n010" }, { "input": "32 15 65\n7 54 36\n5 51 3", "output": "111\n101\n001" }, { "input": "22 97 12\n71 8 24\n100 21 64", "output": "100\n001\n100" }, { "input": "46 37 13\n87 0 50\n90 8 55", "output": "111\n011\n000" }, { "input": "57 43 58\n20 82 83\n66 16 52", "output": "111\n010\n110" }, { "input": "45 56 93\n47 51 59\n18 51 63", "output": "101\n011\n100" }, { "input": "47 66 67\n14 1 37\n27 81 69", "output": "001\n001\n110" }, { "input": "26 69 69\n85 18 23\n14 22 74", "output": "110\n001\n010" }, { "input": "10 70 65\n94 27 25\n74 66 30", "output": "111\n010\n100" }, { "input": "97 1 74\n15 99 1\n88 68 86", "output": "001\n011\n000" }, { "input": "36 48 42\n45 41 66\n26 64 1", "output": "001\n111\n010" }, { "input": "52 81 97\n29 77 71\n66 11 2", "output": "100\n100\n111" }, { "input": "18 66 33\n19 49 49\n48 46 26", "output": "011\n100\n000" }, { "input": "68 79 52\n51 39 100\n29 14 26", "output": "110\n000\n111" }, { "input": "91 69 77\n91 26 64\n91 88 57", "output": "001\n011\n110" }, { "input": "16 69 64\n48 21 80\n81 51 51", "output": "010\n101\n111" }, { "input": "96 14 2\n100 18 12\n65 34 89", "output": "111\n010\n010" }, { "input": "93 95 90\n8 59 42\n53 13 19", "output": "100\n001\n111" }, { "input": "71 84 18\n100 19 67\n9 76 15", "output": "010\n010\n001" }, { "input": "38 93 85\n21 88 64\n4 96 25", "output": "111\n011\n000" }, { "input": "75 20 20\n60 5 78\n77 4 69", "output": "011\n001\n000" }, { "input": "65 70 96\n19 6 83\n33 37 82", "output": "100\n000\n011" }, { "input": "11 13 60\n17 13 46\n42 21 39", "output": "000\n011\n101" }, { "input": "0 0 0\n0 0 0\n0 0 0", "output": "111\n111\n111" }, { "input": "0 0 0\n0 1 0\n0 0 0", "output": "101\n000\n101" }, { "input": "0 0 0\n0 0 0\n0 0 1", "output": "111\n110\n100" } ]
1,692,455,006
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
92
1,740,800
import copy list1=[] for i in range ( 3 ): k=list(map(int,input().split())) for i in k: if i > 1: if i % 2 == 0: k[k.index(i)] = 0 else: k[k.index(i)] = 1 list1.append(k) list1 = [[0, 0, 0]] + list1 + [[0, 0, 0]] list2 = [] for i in list1: list2.append([0] + i + [0]) l=copy.deepcopy(list2) for i in list2[1:4]: k=list2.index(i) j = 1 while j < len(i)-1: if i[j] == 1: l[k][j-1]+=1 l[k][j+1]+=1 l[k-1][j]+=1 l[k+1][j]+=1 j+=1 i=1 while i<4 : j=1 while j<4 : if l[i][j]%2==1: print(0, end="") elif l[i][j]%2==0: print(1, end="") j+=1 i+=1 print()
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. Input Specification: The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. Output Specification: Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". Demo Input: ['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n'] Demo Output: ['001\n010\n100\n', '010\n011\n100\n'] Note: none
```python import copy list1=[] for i in range ( 3 ): k=list(map(int,input().split())) for i in k: if i > 1: if i % 2 == 0: k[k.index(i)] = 0 else: k[k.index(i)] = 1 list1.append(k) list1 = [[0, 0, 0]] + list1 + [[0, 0, 0]] list2 = [] for i in list1: list2.append([0] + i + [0]) l=copy.deepcopy(list2) for i in list2[1:4]: k=list2.index(i) j = 1 while j < len(i)-1: if i[j] == 1: l[k][j-1]+=1 l[k][j+1]+=1 l[k-1][j]+=1 l[k+1][j]+=1 j+=1 i=1 while i<4 : j=1 while j<4 : if l[i][j]%2==1: print(0, end="") elif l[i][j]%2==0: print(1, end="") j+=1 i+=1 print() ```
0
629
A
Far Relative’s Birthday Cake
PROGRAMMING
800
[ "brute force", "combinatorics", "constructive algorithms", "implementation" ]
null
null
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
[ "3\n.CC\nC..\nC.C\n", "4\nCC..\nC..C\n.CC.\n.CC.\n" ]
[ "4\n", "9\n" ]
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
500
[ { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9" }, { "input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "output": "46" }, { "input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "output": "84" }, { "input": "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.", "output": "80" }, { "input": "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.CCC\nCCC.C...C\nCCCC....C\n..C..C..C", "output": "144" }, { "input": "10\n..C..C.C..\n..CC..C.CC\n.C.C...C.C\n..C.CC..CC\n....C..C.C\n...C..C..C\nCC.CC....C\n..CCCC.C.C\n..CC.CCC..\nCCCC..C.CC", "output": "190" }, { "input": "11\nC.CC...C.CC\nCC.C....C.C\n.....C..CCC\n....C.CC.CC\nC..C..CC...\nC...C...C..\nCC..CCC.C.C\n..C.CC.C..C\nC...C.C..CC\n.C.C..CC..C\n.C.C.CC.C..", "output": "228" }, { "input": "21\n...CCC.....CC..C..C.C\n..CCC...CC...CC.CCC.C\n....C.C.C..CCC..C.C.C\n....CCC..C..C.CC.CCC.\n...CCC.C..C.C.....CCC\n.CCC.....CCC..C...C.C\nCCCC.C...CCC.C...C.CC\nC..C...C.CCC..CC..C..\nC...CC..C.C.CC..C.CC.\nCC..CCCCCCCCC..C....C\n.C..CCCC.CCCC.CCC...C\nCCC...CCC...CCC.C..C.\n.CCCCCCCC.CCCC.CC.C..\n.C.C..C....C.CCCCCC.C\n...C...C.CCC.C.CC..C.\nCCC...CC..CC...C..C.C\n.CCCCC...C.C..C.CC.C.\n..CCC.C.C..CCC.CCC...\n..C..C.C.C.....CC.C..\n.CC.C...C.CCC.C....CC\n...C..CCCC.CCC....C..", "output": "2103" }, { "input": "20\nC.C.CCC.C....C.CCCCC\nC.CC.C..CCC....CCCC.\n.CCC.CC...CC.CCCCCC.\n.C...CCCC..C....CCC.\n.C..CCCCCCC.C.C.....\nC....C.C..CCC.C..CCC\n...C.C.CC..CC..CC...\nC...CC.C.CCCCC....CC\n.CC.C.CCC....C.CCC.C\nCC...CC...CC..CC...C\nC.C..CC.C.CCCC.C.CC.\n..CCCCC.C.CCC..CCCC.\n....C..C..C.CC...C.C\nC..CCC..CC..C.CC..CC\n...CC......C.C..C.C.\nCC.CCCCC.CC.CC...C.C\n.C.CC..CC..CCC.C.CCC\nC..C.CC....C....C...\n..CCC..CCC...CC..C.C\n.C.CCC.CCCCCCCCC..CC", "output": "2071" }, { "input": "17\nCCC..C.C....C.C.C\n.C.CC.CC...CC..C.\n.CCCC.CC.C..CCC.C\n...CCC.CC.CCC.C.C\nCCCCCCCC..C.CC.CC\n...C..C....C.CC.C\nCC....CCC...C.CC.\n.CC.C.CC..C......\n.CCCCC.C.CC.CCCCC\n..CCCC...C..CC..C\nC.CC.C.CC..C.C.C.\nC..C..C..CCC.C...\n.C..CCCC..C......\n.CC.C...C..CC.CC.\nC..C....CC...CC..\nC.CC.CC..C.C..C..\nCCCC...C.C..CCCC.", "output": "1160" }, { "input": "15\nCCCC.C..CCC....\nCCCCCC.CC.....C\n...C.CC.C.C.CC.\nCCCCCCC..C..C..\nC..CCC..C.CCCC.\n.CC..C.C.C.CC.C\n.C.C..C..C.C..C\n...C...C..CCCC.\n.....C.C..CC...\nCC.C.C..CC.C..C\n..CCCCC..CCC...\nCC.CC.C..CC.CCC\n..CCC...CC.C..C\nCC..C.C..CCC..C\n.C.C....CCC...C", "output": "789" }, { "input": "1\n.", "output": "0" }, { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "13\nC.C...C.C.C..\nCC.CCCC.CC..C\n.C.CCCCC.CC..\nCCCC..C...C..\n...CC.C.C...C\n.CC.CCC...CC.\nCC.CCCCCC....\n.C...C..CC..C\nCCCC.CC...C..\n.C.CCC..C.CC.\n..C...CC..C.C\n..C.CCC..CC.C\n.C...CCC.CC.C", "output": "529" }, { "input": "16\n.C.C.C.C.C...C.C\n..C..C.CCCCCC...\n..C.C.C.C..C..C.\n.CC....C.CCC..C.\n.C.CCC..C....CCC\nCC..C.CC..C.C.CC\n...C..C..CC..CC.\n.CCC..C.CC.C.C..\n.CC.C..........C\nC...C....CC..C..\nC.CCC.C..C..C...\n.CCCCCCCCCCCC..C\n..C.C.CC.CC.CCC.\nCC..C.C....C..CC\nC.CCC..C..C.C.CC\n.C.CCC.CC..CCC.C", "output": "874" }, { "input": "2\nCC\nCC", "output": "4" }, { "input": "3\nC..\nC..\nC..", "output": "3" } ]
1,593,285,065
2,147,483,647
Python 3
OK
TESTS
48
109
6,963,200
def pairs(n): return n*(n-1)//2 n = int(input()) table = [] count_col = [0 for i in range(n)] for i in range(n): table.append([x for x in input()]) for j in range(n): if table[-1][j] == 'C': count_col[j] +=1 count_row = [row.count('C') for row in table] happiness = [pairs(n) for n in count_row+count_col if n>=2] print(sum(happiness))
Title: Far Relative’s Birthday Cake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input Specification: In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Specification: Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Demo Input: ['3\n.CC\nC..\nC.C\n', '4\nCC..\nC..C\n.CC.\n.CC.\n'] Demo Output: ['4\n', '9\n'] Note: If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
```python def pairs(n): return n*(n-1)//2 n = int(input()) table = [] count_col = [0 for i in range(n)] for i in range(n): table.append([x for x in input()]) for j in range(n): if table[-1][j] == 'C': count_col[j] +=1 count_row = [row.count('C') for row in table] happiness = [pairs(n) for n in count_row+count_col if n>=2] print(sum(happiness)) ```
3
404
A
Valera and X
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him.
The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nwsw\nsws\nwsw", "output": "YES" }, { "input": "3\nxpx\npxp\nxpe", "output": "NO" }, { "input": "5\nliiil\nilili\niilii\nilili\nliiil", "output": "YES" }, { "input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt", "output": "NO" }, { "input": "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososooooo\noooosooosoooo\nooosooooosooo\noosooooooosoo\nosoooooooooso\nsooooooooooos", "output": "YES" }, { "input": "3\naaa\naaa\naaa", "output": "NO" }, { "input": "3\naca\noec\nzba", "output": "NO" }, { "input": "15\nrxeeeeeeeeeeeer\nereeeeeeeeeeere\needeeeeeeeeeoee\neeereeeeeeeewee\neeeereeeeebeeee\nqeeeereeejedyee\neeeeeerereeeeee\neeeeeeereeeeeee\neeeeeerereeeeze\neeeeereeereeeee\neeeereeeeegeeee\neeereeeeeeereee\neereeeeeeqeeved\ncreeeeeeceeeere\nreeerneeeeeeeer", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxoxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxxxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxoox\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxaxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\noxoxx\nxoxox\noxxxo", "output": "NO" }, { "input": "3\nxxx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxx\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxxx", "output": "NO" }, { "input": "3\nxax\nxxa\nxax", "output": "NO" }, { "input": "3\nxax\naaa\nxax", "output": "NO" }, { "input": "3\naax\naxa\nxax", "output": "NO" }, { "input": "3\nxaa\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\naax", "output": "NO" }, { "input": "3\nxax\naxa\nxaa", "output": "NO" }, { "input": "3\nxfx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\nafa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxaf", "output": "NO" }, { "input": "3\nxox\nxxx\nxxx", "output": "NO" }, { "input": "3\naxa\naax\nxxa", "output": "NO" }, { "input": "3\nxox\noxx\nxox", "output": "NO" }, { "input": "3\nxox\nooo\nxox", "output": "NO" }, { "input": "3\naaa\naab\nbbb", "output": "NO" }, { "input": "3\nxxx\nsxs\nxsx", "output": "NO" }, { "input": "5\nabbba\nbabab\nbbbbb\nbaaab\nabbba", "output": "NO" }, { "input": "5\nabaaa\nbbbbb\nbbabb\nbabab\nabbba", "output": "NO" }, { "input": "5\nxoxox\noxoxo\nooxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nxox\noxx\nxxx", "output": "NO" }, { "input": "5\nxoooo\noxooo\nooxoo\noooxo\noooox", "output": "NO" }, { "input": "5\nxoooo\noxoxx\nooxoo\noxoxo\noxoox", "output": "NO" }, { "input": "3\naaa\nbab\naba", "output": "NO" } ]
1,680,872,393
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
19
46
102,400
n = int(input()) a = [input() for _ in range(n)] d1 = set(a[i][i] for i in range(n)) d2 = set(a[i][n-i-1] for i in range(n)) other = set(''.join(a).replace(a[0][0], '')) if len(d1) == len(d2) == len(other) == 1 and a[0][0] != a[0][1]: print('YES') else: print('NO')
Title: Valera and X Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. Output Specification: Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. Demo Input: ['5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n', '3\nwsw\nsws\nwsw\n', '3\nxpx\npxp\nxpe\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: none
```python n = int(input()) a = [input() for _ in range(n)] d1 = set(a[i][i] for i in range(n)) d2 = set(a[i][n-i-1] for i in range(n)) other = set(''.join(a).replace(a[0][0], '')) if len(d1) == len(d2) == len(other) == 1 and a[0][0] != a[0][1]: print('YES') else: print('NO') ```
0
40
A
Find Color
PROGRAMMING
1,300
[ "constructive algorithms", "geometry", "implementation", "math" ]
A. Find Color
2
256
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black.
The first and single line contains two integers *x* and *y* — the coordinates of the hole made in the clock by the ball. Each of the numbers *x* and *y* has an absolute value that does not exceed 1000.
Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black.
[ "-2 1\n", "2 1\n", "4 3\n" ]
[ "white\n", "black\n", "black\n" ]
none
500
[ { "input": "-2 1", "output": "white" }, { "input": "2 1", "output": "black" }, { "input": "4 3", "output": "black" }, { "input": "3 3", "output": "black" }, { "input": "4 4", "output": "white" }, { "input": "-4 4", "output": "black" }, { "input": "4 -4", "output": "black" }, { "input": "-4 -4", "output": "white" }, { "input": "0 0", "output": "black" }, { "input": "0 1", "output": "black" }, { "input": "0 2", "output": "black" }, { "input": "0 1000", "output": "black" }, { "input": "1000 0", "output": "black" }, { "input": "-1000 0", "output": "black" }, { "input": "0 -1000", "output": "black" }, { "input": "1000 -1000", "output": "white" }, { "input": "12 5", "output": "black" }, { "input": "12 -5", "output": "black" }, { "input": "-12 -35", "output": "black" }, { "input": "20 -21", "output": "black" }, { "input": "-677 492", "output": "white" }, { "input": "-673 -270", "output": "white" }, { "input": "-668 970", "output": "black" }, { "input": "-220 208", "output": "white" }, { "input": "-215 -996", "output": "black" }, { "input": "-211 243", "output": "black" }, { "input": "-206 -518", "output": "white" }, { "input": "-201 278", "output": "black" }, { "input": "-196 -484", "output": "black" }, { "input": "902 479", "output": "white" }, { "input": "-441 572", "output": "white" }, { "input": "217 221", "output": "white" }, { "input": "875 -129", "output": "white" }, { "input": "-469 -36", "output": "black" }, { "input": "189 -387", "output": "white" }, { "input": "847 -294", "output": "white" }, { "input": "-496 -644", "output": "black" }, { "input": "-281 -552", "output": "white" }, { "input": "377 -902", "output": "black" }, { "input": "165 -738", "output": "white" }, { "input": "61 -175", "output": "black" }, { "input": "-42 389", "output": "black" }, { "input": "-589 952", "output": "black" }, { "input": "-693 -929", "output": "white" }, { "input": "-796 -365", "output": "white" }, { "input": "658 198", "output": "white" }, { "input": "555 319", "output": "black" }, { "input": "8 882", "output": "black" }, { "input": "-96 -556", "output": "black" }, { "input": "-129 489", "output": "black" }, { "input": "207 -224", "output": "black" }, { "input": "64 0", "output": "black" }, { "input": "17 144", "output": "black" }, { "input": "60 -448", "output": "black" }, { "input": "-399 -40", "output": "black" }, { "input": "128 -504", "output": "black" }, { "input": "0 72", "output": "black" }, { "input": "168 -26", "output": "black" }, { "input": "72 -154", "output": "black" }, { "input": "117 -44", "output": "black" }, { "input": "-72 -646", "output": "black" }, { "input": "253 -204", "output": "black" }, { "input": "-40 198", "output": "black" }, { "input": "-216 -90", "output": "black" }, { "input": "15 -8", "output": "black" }, { "input": "-180 -432", "output": "black" }, { "input": "280 342", "output": "black" }, { "input": "132 224", "output": "black" }, { "input": "-192 -256", "output": "black" }, { "input": "351 -280", "output": "black" } ]
1,637,369,426
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
92
0
x, y = list(map(int, input().split())) quadr = x*y cor = 0 if quadr >= 0: if (x % 2) == 0: if (y % 2) == 0: cor = 1 else: cor = 0 else: if (y % 2) == 0: cor = 1 else: cor = 0 else: if (x % 2) == 0: if (y % 2) == 0: cor = 0 else: cor = 1 else: if (y % 2) == 0: cor = 0 else: cor = 1 if cor == 0: print("black") else: print("white")
Title: Find Color Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input Specification: The first and single line contains two integers *x* and *y* — the coordinates of the hole made in the clock by the ball. Each of the numbers *x* and *y* has an absolute value that does not exceed 1000. Output Specification: Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Demo Input: ['-2 1\n', '2 1\n', '4 3\n'] Demo Output: ['white\n', 'black\n', 'black\n'] Note: none
```python x, y = list(map(int, input().split())) quadr = x*y cor = 0 if quadr >= 0: if (x % 2) == 0: if (y % 2) == 0: cor = 1 else: cor = 0 else: if (y % 2) == 0: cor = 1 else: cor = 0 else: if (x % 2) == 0: if (y % 2) == 0: cor = 0 else: cor = 1 else: if (y % 2) == 0: cor = 0 else: cor = 1 if cor == 0: print("black") else: print("white") ```
0
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp", "output": "0" }, { "input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH", "output": "-1" }, { "input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt", "output": "1" }, { "input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL", "output": "1" }, { "input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo", "output": "1" }, { "input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja", "output": "-1" }, { "input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy", "output": "1" }, { "input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR", "output": "1" }, { "input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd", "output": "1" }, { "input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI", "output": "-1" }, { "input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC", "output": "-1" }, { "input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl", "output": "-1" }, { "input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo", "output": "-1" }, { "input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV", "output": "-1" }, { "input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ", "output": "-1" }, { "input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK", "output": "-1" }, { "input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys", "output": "1" }, { "input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy", "output": "-1" }, { "input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK", "output": "-1" }, { "input": "UG\nak", "output": "1" }, { "input": "JZR\nVae", "output": "-1" }, { "input": "a\nZ", "output": "-1" }, { "input": "rk\nkv", "output": "1" }, { "input": "RvuT\nbJzE", "output": "1" }, { "input": "PPS\nydq", "output": "-1" }, { "input": "q\nq", "output": "0" }, { "input": "peOw\nIgSJ", "output": "1" }, { "input": "PyK\noKN", "output": "1" }, { "input": "O\ni", "output": "1" }, { "input": "NmGY\npDlP", "output": "-1" }, { "input": "nG\nZf", "output": "-1" }, { "input": "m\na", "output": "1" }, { "input": "MWyB\nWZEV", "output": "-1" }, { "input": "Gre\nfxc", "output": "1" }, { "input": "Ooq\nwap", "output": "-1" }, { "input": "XId\nlbB", "output": "1" }, { "input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF", "output": "0" }, { "input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD", "output": "0" }, { "input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA", "output": "0" }, { "input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ", "output": "0" }, { "input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG", "output": "0" }, { "input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ", "output": "0" }, { "input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ", "output": "0" }, { "input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi", "output": "0" }, { "input": "abac\nadaa", "output": "-1" }, { "input": "Bbc\nabc", "output": "1" }, { "input": "aaaba\naaaab", "output": "1" } ]
1,697,318,843
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
m = input() n = input() s1 = [ord(i) for i in m.upper()] s2 = [ord(i) for i in n.upper()] if sum(s1) > sum(s2): print(1) elif sum(s1) < sum(s2): print(-1) else: print(0)
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. Input Specification: Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. Output Specification: If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. Demo Input: ['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
```python m = input() n = input() s1 = [ord(i) for i in m.upper()] s2 = [ord(i) for i in n.upper()] if sum(s1) > sum(s2): print(1) elif sum(s1) < sum(s2): print(-1) else: print(0) ```
0
846
A
Curriculum Vitae
PROGRAMMING
1,500
[ "brute force", "implementation" ]
null
null
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one.
Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.
[ "4\n1 1 0 1\n", "6\n0 1 0 0 1 0\n", "1\n0\n" ]
[ "3\n", "4\n", "1\n" ]
none
0
[ { "input": "4\n1 1 0 1", "output": "3" }, { "input": "6\n0 1 0 0 1 0", "output": "4" }, { "input": "1\n0", "output": "1" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "100\n0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "80" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1", "output": "53" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "3\n1 0 0", "output": "2" }, { "input": "10\n1 1 0 0 0 1 1 0 0 0", "output": "6" }, { "input": "90\n1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0", "output": "52" }, { "input": "78\n0 0 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0", "output": "42" }, { "input": "4\n1 0 0 1", "output": "3" }, { "input": "2\n0 1", "output": "2" }, { "input": "5\n0 1 0 0 1", "output": "4" }, { "input": "3\n1 0 1", "output": "2" }, { "input": "3\n1 1 0", "output": "2" }, { "input": "16\n1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 1", "output": "9" } ]
1,504,624,689
789
Python 3
WRONG_ANSWER
TESTS
4
62
0
n=int(input()) l=list(input().split()) p=n i=1 j=0 while(i<n): if(l[i]=='0' and l[j]=='1'): p=p-1 i=i+1 j=j+1 print(p)
Title: Curriculum Vitae Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. Output Specification: Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. Demo Input: ['4\n1 1 0 1\n', '6\n0 1 0 0 1 0\n', '1\n0\n'] Demo Output: ['3\n', '4\n', '1\n'] Note: none
```python n=int(input()) l=list(input().split()) p=n i=1 j=0 while(i<n): if(l[i]=='0' and l[j]=='1'): p=p-1 i=i+1 j=j+1 print(p) ```
0
313
A
Ilya and Bank Account
PROGRAMMING
900
[ "implementation", "number theory" ]
null
null
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
In a single line print an integer — the maximum state of the bank account that Ilya can get.
[ "2230\n", "-10\n", "-100003\n" ]
[ "2230\n", "0\n", "-10000\n" ]
In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
500
[ { "input": "2230", "output": "2230" }, { "input": "-10", "output": "0" }, { "input": "-100003", "output": "-10000" }, { "input": "544883178", "output": "544883178" }, { "input": "-847251738", "output": "-84725173" }, { "input": "423654797", "output": "423654797" }, { "input": "-623563697", "output": "-62356367" }, { "input": "645894116", "output": "645894116" }, { "input": "-384381709", "output": "-38438170" }, { "input": "437587210", "output": "437587210" }, { "input": "-297534606", "output": "-29753460" }, { "input": "891773002", "output": "891773002" }, { "input": "-56712976", "output": "-5671296" }, { "input": "963662765", "output": "963662765" }, { "input": "-272656295", "output": "-27265625" }, { "input": "383441522", "output": "383441522" }, { "input": "-477665112", "output": "-47766511" }, { "input": "791725034", "output": "791725034" }, { "input": "-812168727", "output": "-81216872" }, { "input": "528894922", "output": "528894922" }, { "input": "-479977172", "output": "-47997712" }, { "input": "568044564", "output": "568044564" }, { "input": "-392784794", "output": "-39278474" }, { "input": "925596634", "output": "925596634" }, { "input": "-836078769", "output": "-83607876" }, { "input": "71036059", "output": "71036059" }, { "input": "-337396162", "output": "-33739612" }, { "input": "87129297", "output": "87129297" }, { "input": "-648171877", "output": "-64817187" }, { "input": "20218400", "output": "20218400" }, { "input": "10", "output": "10" }, { "input": "1000000000", "output": "1000000000" }, { "input": "-1000000000", "output": "-100000000" }, { "input": "-102", "output": "-10" }, { "input": "-120", "output": "-10" }, { "input": "-20", "output": "0" }, { "input": "-15", "output": "-1" }, { "input": "-5575533", "output": "-557553" }, { "input": "-50", "output": "0" }, { "input": "-31", "output": "-1" }, { "input": "-55", "output": "-5" }, { "input": "-81", "output": "-1" }, { "input": "-99", "output": "-9" }, { "input": "-23", "output": "-2" }, { "input": "-41", "output": "-1" }, { "input": "-24", "output": "-2" }, { "input": "46", "output": "46" } ]
1,686,806,905
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
154
0
n=int(input()) if(n>=0): print(n) else: a=n//10; b=n//100*10+n%10; if(a>b): print(b) else: print(a)
Title: Ilya and Bank Account Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input Specification: The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. Output Specification: In a single line print an integer — the maximum state of the bank account that Ilya can get. Demo Input: ['2230\n', '-10\n', '-100003\n'] Demo Output: ['2230\n', '0\n', '-10000\n'] Note: In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
```python n=int(input()) if(n>=0): print(n) else: a=n//10; b=n//100*10+n%10; if(a>b): print(b) else: print(a) ```
0
0
none
none
none
0
[ "none" ]
null
null
You are given three sticks with positive integer lengths of *a*,<=*b*, and *c* centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most *l* centimeters. In particular, it is allowed not to increase the length of any stick. Determine the number of ways to increase the lengths of some sticks so that you can form from them a non-degenerate (that is, having a positive area) triangle. Two ways are considered different, if the length of some stick is increased by different number of centimeters in them.
The single line contains 4 integers *a*,<=*b*,<=*c*,<=*l* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=3·105, 0<=≤<=*l*<=≤<=3·105).
Print a single integer — the number of ways to increase the sizes of the sticks by the total of at most *l* centimeters, so that you can make a non-degenerate triangle from it.
[ "1 1 1 2\n", "1 2 3 1\n", "10 2 1 7\n" ]
[ "4\n", "2\n", "0\n" ]
In the first sample test you can either not increase any stick or increase any two sticks by 1 centimeter. In the second sample test you can increase either the first or the second stick by one centimeter. Note that the triangle made from the initial sticks is degenerate and thus, doesn't meet the conditions.
0
[ { "input": "1 1 1 2", "output": "4" }, { "input": "1 2 3 1", "output": "2" }, { "input": "10 2 1 7", "output": "0" }, { "input": "1 2 1 5", "output": "20" }, { "input": "10 15 17 10", "output": "281" }, { "input": "5 5 5 10000", "output": "41841675001" }, { "input": "5 7 30 100", "output": "71696" }, { "input": "5 5 5 300000", "output": "1125157500250001" }, { "input": "4 2 5 28", "output": "1893" }, { "input": "2 7 8 4", "output": "25" }, { "input": "85 50 17 89", "output": "68620" }, { "input": "17 28 19 5558", "output": "7396315389" }, { "input": "5276 8562 1074 8453", "output": "49093268246" }, { "input": "9133 7818 3682 82004", "output": "38306048676255" }, { "input": "81780 54799 231699 808", "output": "0" }, { "input": "53553 262850 271957 182759", "output": "834977070873802" }, { "input": "300000 300000 300000 300000", "output": "4500090000549998" }, { "input": "1 1 300000 300000", "output": "599999" }, { "input": "300000 300000 1 300000", "output": "2250045000350001" }, { "input": "300000 300000 1 24234", "output": "1186319275394" }, { "input": "1 1 1 300000", "output": "1125022500250001" }, { "input": "3 5 7 300000", "output": "1125157499050009" }, { "input": "63 5 52 78", "output": "46502" }, { "input": "2 42 49 93", "output": "72542" }, { "input": "61 100 3 8502", "output": "27050809786" }, { "input": "30 918 702 591", "output": "14315560" }, { "input": "98406 37723 3 257918", "output": "1154347569149860" }, { "input": "552 250082 77579 278985", "output": "596240712378446" }, { "input": "183808 8 8 294771", "output": "622921327009564" }, { "input": "2958 4133 233463 259655", "output": "65797591388150" }, { "input": "300000 200000 100000 1", "output": "2" }, { "input": "300000 200000 100000 0", "output": "0" }, { "input": "100000 300000 100000 100000", "output": "0" }, { "input": "100000 300000 100000 100001", "output": "100002" }, { "input": "100000 300000 100000 100002", "output": "200005" }, { "input": "100000 300000 100000 100003", "output": "400012" }, { "input": "100000 300000 100000 100010", "output": "3000195" }, { "input": "100000 300000 100000 100100", "output": "255131325" }, { "input": "100000 300000 199999 0", "output": "0" }, { "input": "100000 300000 200001 0", "output": "1" }, { "input": "1 1 1 300000", "output": "1125022500250001" }, { "input": "3 1 29 1", "output": "0" }, { "input": "300000 300000 300000 300000", "output": "4500090000549998" } ]
1,639,871,414
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
1,945,600
a, b, c, l = list(map(int, input().split())) count = 0 for i in range(l+1): for j in range(0, l-i+1): for k in range(0, l-i-j+1): x, y, z = a+i, b+j, c+k if x+y > z and x+z>y and y+z>x: count+=1 print(count)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given three sticks with positive integer lengths of *a*,<=*b*, and *c* centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most *l* centimeters. In particular, it is allowed not to increase the length of any stick. Determine the number of ways to increase the lengths of some sticks so that you can form from them a non-degenerate (that is, having a positive area) triangle. Two ways are considered different, if the length of some stick is increased by different number of centimeters in them. Input Specification: The single line contains 4 integers *a*,<=*b*,<=*c*,<=*l* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=3·105, 0<=≤<=*l*<=≤<=3·105). Output Specification: Print a single integer — the number of ways to increase the sizes of the sticks by the total of at most *l* centimeters, so that you can make a non-degenerate triangle from it. Demo Input: ['1 1 1 2\n', '1 2 3 1\n', '10 2 1 7\n'] Demo Output: ['4\n', '2\n', '0\n'] Note: In the first sample test you can either not increase any stick or increase any two sticks by 1 centimeter. In the second sample test you can increase either the first or the second stick by one centimeter. Note that the triangle made from the initial sticks is degenerate and thus, doesn't meet the conditions.
```python a, b, c, l = list(map(int, input().split())) count = 0 for i in range(l+1): for j in range(0, l-i+1): for k in range(0, l-i-j+1): x, y, z = a+i, b+j, c+k if x+y > z and x+z>y and y+z>x: count+=1 print(count) ```
0
276
B
Little Girl and Game
PROGRAMMING
1,300
[ "games", "greedy" ]
null
null
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
[ "aba\n", "abca\n" ]
[ "First\n", "Second\n" ]
none
1,000
[ { "input": "aba", "output": "First" }, { "input": "abca", "output": "Second" }, { "input": "aabb", "output": "First" }, { "input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo", "output": "Second" }, { "input": "gevqgtaorjixsxnbcoybr", "output": "First" }, { "input": "xvhtcbtouuddhylxhplgjxwlo", "output": "First" }, { "input": "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbomlpghjrxcgxvktgeyuhrcwgvdmppqnkdmjtxukzlzqhfbgrishuhkyggkpstvqabpxoqjuovwjwcmazmvpfpnljdgpokpatjnvwacotkvxheorzbsrazldsquijzkmtmqahakjrjvzkquvayxpqrmqqcknilpqpjapagezonfpz", "output": "Second" }, { "input": "desktciwoidfuswycratvovutcgjrcyzmilsmadzaegseetexygedzxdmorxzxgiqhcuppshcsjcozkopebegfmxzxxagzwoymlghgjexcgfojychyt", "output": "First" }, { "input": "gfhuidxgxpxduqrfnqrnefgtyxgmrtehmddjkddwdiayyilaknxhlxszeslnsjpcrwnoqubmbpcehiftteirkfvbtfyibiikdaxmondnawtvqccctdxrjcfxqwqhvvrqmhqflbzskrayvruqvqijrmikucwzodxvufwxpxxjxlifdjzxrttjzatafkbzsjupsiefmipdufqltedjlytphzppoevxawjdhbxgennevbvdgpoeihasycctyddenzypoprchkoioouhcexjqwjflxvkgpgjatstlmledxasecfhwvabzwviywsiaryqrxyeceefblherqjevdzkfxslqiytwzz", "output": "First" }, { "input": "fezzkpyctjvvqtncmmjsitrxaliyhirspnjjngvzdoudrkkvvdiwcwtcxobpobzukegtcrwsgxxzlcphdxkbxdximqbycaicfdeqlvzboptfimkzvjzdsvahorqqhcirpkhtwjkplitpacpkpbhnxtoxuoqsxcxnhtrmzvexmpvlethbkvmlzftimjnidrzvcunbpysvukzgwghjmwrvstsunaocnoqohcsggtrwxiworkliqejajewbrtdwgnyynpupbrrvtfqtlaaq", "output": "Second" }, { "input": "tsvxmeixijyavdalmrvscwohzubhhgsocdvnjmjtctojbxxpezzbgfltixwgzmkfwdnlhidhrdgyajggmrvmwaoydodjmzqvgabyszfqcuhwdncyfqvmackvijgpjyiauxljvvwgiofdxccwmybdfcfcrqppbvbagmnvvvhngxauwbpourviyfokwjweypzzrrzjcmddnpoaqgqfgglssjnlshrerfffmrwhapzknxveiqixflykjbnpivogtdpyjakwrdoklsbvbkjhdojfnuwbpcfdycwxecysbyjfvoykxsxgg", "output": "First" }, { "input": "upgqmhfmfnodsyosgqswugfvpdxhtkxvhlsxrjiqlojchoddxkpsamwmuvopdbncymcgrkurwlxerexgswricuqxhvqvgekeofkgqabypamozmyjyfvpifsaotnyzqydcenphcsmplekinwkmwzpjnlapfdbhxjdcnarlgkfgxzfbpgsuxqfyhnxjhtojrlnprnxprfbkkcyriqztjeeepkzgzcaiutvbqqofyhddfebozhvtvrigtidxqmydjxegxipakzjcnenjkdroyjmxugj", "output": "Second" }, { "input": "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddeeeeeeeeeeffffgggghhhhiiiijjjjqqqqwwwweeeerrrrttttyyyyuuuuiiiiooooppppaaaassssddddffffgggghhhhjjjjkkkkllllzzzzxxxxccccvvvvbbbbnnnnmmmm", "output": "First" }, { "input": "vnvtvnxjrtffdhrfvczzoyeokjabxcilmmsrhwuakghvuabcmfpmblyroodmhfivmhqoiqhapoglwaluewhqkunzitmvijaictjdncivccedfpaezcnpwemlohbhjjlqsonuclaumgbzjamsrhuzqdqtitygggsnruuccdtxkgbdd", "output": "First" }, { "input": "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh", "output": "First" }, { "input": "hxueikegwnrctlciwguepdsgupguykrntbszeqzzbpdlouwnmqgzcxejidstxyxhdlnttnibxstduwiflouzfswfikdudkazoefawm", "output": "Second" }, { "input": "ershkhsywqftixappwqzoojtnamvqjbyfauvuubwpctspioqusnnivwsiyszfhlrskbswaiaczurygcioonjcndntwvrlaejyrghfnecltqytfmkvjxuujifgtujrqsisdawpwgttxynewiqhdhronamabysvpxankxeybcjqttbqnciwuqiehzyfjoedaradqnfthuuwrezwrkjiytpgwfwbslawbiezdbdltenjlaygwaxddplgseiaojndqjcopvolqbvnacuvfvirzbrnlnyjixngeevcggmirzatenjihpgnyfjhgsjgzepohbyhmzbatfwuorwutavlqsogrvcjpqziuifrhurq", "output": "First" }, { "input": "qilwpsuxogazrfgfznngwklnioueuccyjfatjoizcctgsweitzofwkyjustizbopzwtaqxbtovkdrxeplukrcuozhpymldstbbfynkgsmafigetvzkxloxqtphvtwkgfjkiczttcsxkjpsoutdpzxytrsqgjtbdljjrbmkudrkodfvcwkcuggbsthxdyogeeyfuyhmnwgyuatfkvchavpzadfacckdurlbqjkthqbnirzzbpusxcenkpgtizayjmsahvobobudfeaewcqmrlxxnocqzmkessnguxkiccrxyvnxxlqnqfwuzmupk", "output": "First" }, { "input": "opfokvwzpllctflkphutcrkferbjyyrasqqkrcvoymyrxwaudgsugcqveccymdplxmtlzfoptmrapfeizpnnhbzlkuyznwacnswibxhqunazbhdvrlidghisuqunstbuevjzimvlfvopgqxrvahhngnaumgywscfrfwfpnfxwhfrelbunmedvkssykwjyartxjiplerntzkpiiaalijiwhyuhxlvhxpkgfypvrpqqsacuwocdampnnhvibsbolyduvscsjfayxpldyvqzjbqojjxdvxtctwtifcdfcaoonzbgegyllngwvjivtxeezoabhsihcuvgvdsgjtzbzwovjshvwrljkxavowovzrfpdufpogdtujkerdorpboufrxhyswirjehgsxthlvjufvahdpeajidqipwaxokbeycrievgcfkyuyavaq", "output": "Second" }, { "input": "a", "output": "First" }, { "input": "ab", "output": "Second" }, { "input": "abacaba", "output": "First" }, { "input": "abazaba", "output": "First" }, { "input": "zz", "output": "First" }, { "input": "aassddxyz", "output": "First" }, { "input": "abcdefghijklmnopqrstuvwxyz", "output": "Second" }, { "input": "aabc", "output": "Second" }, { "input": "abcabc", "output": "First" }, { "input": "aaabbbccdd", "output": "Second" }, { "input": "aabbcccc", "output": "First" } ]
1,659,964,778
2,147,483,647
PyPy 3
OK
TESTS
51
156
0
s=input();c = 0 for i in s:c += s.count(i) % 2 if c==0 or c%2: print("First") else: print("Second")
Title: Little Girl and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Girl loves problems on games very much. Here's one of them. Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second. Input Specification: The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. Output Specification: In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. Demo Input: ['aba\n', 'abca\n'] Demo Output: ['First\n', 'Second\n'] Note: none
```python s=input();c = 0 for i in s:c += s.count(i) % 2 if c==0 or c%2: print("First") else: print("Second") ```
3
42
A
Guilty --- to the kitchen!
PROGRAMMING
1,400
[ "greedy", "implementation" ]
A. Guilty — to the kitchen!
2
256
It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills. According to the borscht recipe it consists of *n* ingredients that have to be mixed in proportion litres (thus, there should be *a*1<=·*x*,<=...,<=*a**n*<=·*x* litres of corresponding ingredients mixed for some non-negative *x*). In the kitchen Volodya found out that he has *b*1,<=...,<=*b**n* litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a *V* litres volume pan (which means the amount of soup cooked can be between 0 and *V* litres). What is the volume of borscht Volodya will cook ultimately?
The first line of the input contains two space-separated integers *n* and *V* (1<=≤<=*n*<=≤<=20,<=1<=≤<=*V*<=≤<=10000). The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=100). Finally, the last line contains *n* space-separated integers *b**i* (0<=≤<=*b**i*<=≤<=100).
Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10<=-<=4.
[ "1 100\n1\n40\n", "2 100\n1 1\n25 30\n", "2 100\n1 1\n60 60\n" ]
[ "40.0\n", "50.0\n", "100.0\n" ]
none
500
[ { "input": "1 100\n1\n40", "output": "40.0" }, { "input": "2 100\n1 1\n25 30", "output": "50.0" }, { "input": "2 100\n1 1\n60 60", "output": "100.0" }, { "input": "2 100\n1 1\n50 50", "output": "100.0" }, { "input": "2 100\n1 2\n33 66", "output": "99.0" }, { "input": "3 10000\n1 1 1\n100 0 100", "output": "0.0" }, { "input": "7 5100\n21 93 52 80 5 46 20\n79 37 74 54 22 15 90", "output": "103.3695652173913" }, { "input": "10 2707\n80 91 41 99 99 48 81 25 80 17\n88 79 64 78 4 54 38 92 77 61", "output": "26.70707070707071" }, { "input": "19 8111\n44 75 80 69 90 64 58 8 93 50 44 39 7 25 14 52 32 26 26\n38 57 38 23 73 24 4 49 0 34 96 93 14 26 29 89 54 12 24", "output": "0.0" }, { "input": "5 1121\n14 37 91 35 71\n17 87 48 91 13", "output": "45.40845070422535" }, { "input": "4 6054\n72 21 14 49\n43 53 42 55", "output": "93.16666666666666" }, { "input": "6 8692\n20 61 56 4 78 76\n73 83 97 45 16 7", "output": "27.171052631578945" }, { "input": "9 5583\n73 31 18 36 38 99 34 50 69\n48 24 75 78 75 69 13 74 3", "output": "19.478260869565215" }, { "input": "1 5215\n24\n85", "output": "85.0" }, { "input": "15 9559\n55 13 69 16 15 34 89 30 56 64 74 100 72 71 20\n40 73 29 12 31 5 59 5 90 13 32 75 99 7 44", "output": "76.70422535211266" }, { "input": "13 2530\n83 59 19 69 8 81 99 74 14 75 61 13 36\n26 36 77 44 10 8 8 16 81 61 29 81 50", "output": "55.83838383838385" }, { "input": "4 7672\n42 34 57 72\n56 7 24 24", "output": "42.205882352941174" }, { "input": "17 6030\n100 77 5 87 28 50 51 64 45 79 60 80 49 20 25 91 64\n12 13 58 55 3 59 8 62 69 38 69 27 50 39 5 41 30", "output": "104.46428571428571" }, { "input": "18 4842\n73 20 36 89 89 74 88 46 21 55 40 99 86 2 53 92 36 6\n24 97 23 27 31 63 29 2 23 84 86 44 68 8 63 0 50 16", "output": "0.0" }, { "input": "8 2342\n7 91 9 17 86 22 49 53\n20 76 25 24 54 78 33 90", "output": "209.72093023255815" }, { "input": "1 8987\n16\n38", "output": "38.0" }, { "input": "10 9501\n39 67 33 71 89 69 5 90 7 48\n89 91 8 68 7 54 61 66 53 51", "output": "40.74157303370786" }, { "input": "1 1966\n85\n99", "output": "99.0" }, { "input": "9 7611\n58 46 28 18 29 70 62 22 55\n53 43 51 72 52 99 18 61 91", "output": "112.64516129032259" }, { "input": "5 6739\n29 48 36 80 74\n22 37 36 54 88", "output": "180.22500000000002" }, { "input": "9 35\n27 71 41 3 9 74 16 29 95\n95 69 20 41 41 22 10 92 58", "output": "35.0" }, { "input": "13 5115\n13 51 17 24 52 4 33 4 94 17 54 82 77\n40 34 90 29 81 24 38 74 28 81 14 40 24", "output": "135.33333333333334" }, { "input": "13 9049\n58 13 53 62 41 80 38 14 6 96 23 29 41\n42 24 20 12 63 82 33 93 3 31 68 10 24", "output": "107.2258064516129" }, { "input": "2 775\n13 39\n76 35", "output": "46.66666666666667" }, { "input": "7 8690\n73 93 32 47 80 82 97\n49 49 90 43 89 43 67", "output": "264.2926829268293" }, { "input": "11 9698\n62 53 97 20 84 9 50 100 81 35 14\n18 19 39 30 26 56 41 43 24 32 28", "output": "175.6451612903226" }, { "input": "6 1090\n1 1 44 63 35 64\n29 53 64 11 32 66", "output": "36.317460317460316" }, { "input": "8 9291\n93 68 34 81 53 96 7 26\n23 64 15 47 94 66 90 92", "output": "113.26881720430106" }, { "input": "16 1718\n42 68 96 52 47 31 89 5 87 70 25 69 35 86 86 11\n35 37 51 15 33 94 18 48 91 2 4 89 73 93 47 26", "output": "25.685714285714283" }, { "input": "4 575\n24 23 16 64\n85 100 14 13", "output": "25.796875" }, { "input": "9 423\n28 88 41 71 99 24 35 68 90\n7 76 44 27 64 52 92 81 98", "output": "136.0" }, { "input": "2 1437\n66 58\n44 8", "output": "17.10344827586207" }, { "input": "18 4733\n78 53 33 72 38 76 43 51 94 18 22 21 65 60 5 71 88 40\n5 78 50 43 81 44 10 18 23 51 52 31 10 55 63 46 82 92", "output": "59.48717948717948" }, { "input": "16 7170\n17 1 48 51 28 16 41 14 59 93 25 76 46 69 74 41\n54 53 41 25 50 42 37 20 11 35 90 96 78 3 20 38", "output": "30.391304347826086" }, { "input": "14 7455\n96 38 61 34 68 91 45 49 81 87 46 60 83 16\n38 4 99 16 99 40 68 84 18 56 16 81 21 21", "output": "89.99999999999999" }, { "input": "1 9291\n97\n96", "output": "96.0" }, { "input": "14 3615\n81 79 13 94 54 69 92 5 47 98 40 64 44 88\n52 73 7 12 29 40 46 47 60 66 63 68 71 4", "output": "39.45454545454545" }, { "input": "18 6283\n50 78 16 38 44 9 23 54 58 82 59 12 69 1 10 6 77 61\n70 59 12 11 98 55 52 12 69 40 100 47 42 21 48 18 14 22", "output": "135.8181818181818" }, { "input": "9 3269\n79 88 15 74 92 33 68 64 45\n55 84 75 50 68 32 41 82 42", "output": "336.44117647058823" }, { "input": "6 1007\n93 23 35 15 25 6\n58 24 11 99 23 47", "output": "61.91428571428571" }, { "input": "11 710\n2 49 56 33 79 69 64 62 64 9 87\n94 34 90 3 13 67 76 80 69 19 41", "output": "52.18181818181819" }, { "input": "18 9292\n15 97 47 88 15 7 15 86 52 40 16 97 2 80 64 37 88 15\n39 47 94 12 34 17 45 39 98 99 19 8 94 50 87 68 31 6", "output": "71.01030927835052" }, { "input": "11 3753\n78 75 17 65 97 36 79 56 97 62 43\n18 41 17 47 14 40 7 57 58 24 98", "output": "62.46835443037974" }, { "input": "13 1407\n21 67 79 68 44 52 18 40 68 56 69 66 25\n26 39 78 93 1 57 58 5 67 49 96 15 16", "output": "15.295454545454545" }, { "input": "20 1479\n69 30 15 62 81 24 5 16 25 65 47 23 62 51 87 50 6 44 88 61\n57 47 76 68 7 57 44 98 24 44 1 79 67 31 72 83 36 65 83 42", "output": "19.382978723404253" }, { "input": "17 3856\n50 59 100 50 80 77 58 86 95 87 30 41 11 99 33 27 75\n47 47 39 62 58 91 55 18 65 47 8 97 31 80 61 87 66", "output": "221.4418604651163" }, { "input": "9 2382\n84 51 95 66 34 77 96 9 57\n3 94 56 22 61 50 23 83 45", "output": "20.32142857142857" }, { "input": "14 1751\n33 82 63 35 67 78 47 27 43 96 58 95 39 29\n42 7 15 83 95 91 60 3 85 39 7 56 39 4", "output": "67.60975609756098" }, { "input": "6 8371\n34 11 24 95 62 32\n98 50 58 46 49 93", "output": "124.92631578947369" }, { "input": "2 5181\n4 1\n6 33", "output": "7.5" }, { "input": "9 632\n51 64 25 25 60 71 56 3 31\n70 28 76 84 86 33 77 11 69", "output": "168.875" }, { "input": "3 2102\n76 15 85\n25 95 80", "output": "57.89473684210526" }, { "input": "5 5005\n5 53 65 52 99\n21 49 9 3 66", "output": "15.807692307692308" }, { "input": "17 8971\n54 62 7 47 48 70 78 96 91 34 84 23 72 75 72 60 21\n4 26 6 41 28 45 70 61 6 75 74 46 17 46 34 27 10", "output": "65.53846153846153" }, { "input": "15 5527\n22 49 56 95 86 23 15 74 38 65 52 92 88 49 54\n33 61 71 95 69 31 30 0 1 93 66 48 65 92 11", "output": "0.0" }, { "input": "20 3696\n87 22 21 83 95 31 28 96 71 25 56 40 70 79 46 87 19 19 34 25\n70 44 34 11 2 1 59 22 46 28 3 53 52 71 34 47 65 71 76 30", "output": "21.768421052631577" }, { "input": "8 5540\n5 9 88 1 74 52 32 79\n17 48 99 33 68 28 2 58", "output": "21.25" }, { "input": "15 303\n33 15 28 14 97 33 77 69 41 76 54 97 11 1 1\n83 70 63 11 71 10 48 65 5 5 82 2 6 79 19", "output": "13.340206185567009" }, { "input": "10 9401\n4 53 39 66 52 42 65 39 1 76\n9 34 16 56 78 14 43 49 95 42", "output": "145.66666666666666" }, { "input": "2 9083\n77 33\n22 22", "output": "31.42857142857143" }, { "input": "16 8826\n29 21 40 93 48 49 43 96 60 68 66 5 96 49 84 44\n94 1 79 12 76 65 99 53 37 39 3 76 15 81 51 91", "output": "40.5" }, { "input": "4 9426\n95 48 98 92\n65 40 43 90", "output": "146.1122448979592" }, { "input": "13 175\n46 77 14 16 84 80 81 36 71 13 87 69 8\n54 46 69 59 30 72 83 97 83 96 43 94 84", "output": "175.0" }, { "input": "13 5023\n11 30 92 40 26 77 33 94 71 2 70 97 50\n32 46 51 14 63 76 34 19 13 34 40 91 23", "output": "126.88732394366197" }, { "input": "18 9978\n26 3 87 84 97 53 70 97 37 57 78 23 34 40 81 62 21 92\n56 73 0 79 93 14 17 80 0 20 3 81 22 71 7 82 71 81", "output": "0.0" }, { "input": "14 8481\n64 2 90 76 49 30 88 32 98 64 20 85 40 35\n55 84 75 43 36 13 67 75 100 19 22 7 5 58", "output": "63.65882352941177" }, { "input": "2 1674\n77 23\n23 25", "output": "29.87012987012987" }, { "input": "10 2112\n45 11 32 14 82 30 34 11 42 56\n18 9 84 99 82 43 61 84 14 70", "output": "119.0" }, { "input": "6 2006\n62 4 3 71 61 10\n37 45 61 84 24 15", "output": "83.01639344262294" }, { "input": "8 3954\n80 77 64 1 50 21 89 26\n30 82 17 20 67 21 31 99", "output": "108.375" }, { "input": "18 7253\n64 77 92 9 32 66 23 34 10 71 8 7 83 9 52 97 29 65\n46 90 65 43 44 63 7 38 38 20 62 9 53 39 17 13 5 90", "output": "110.96907216494844" }, { "input": "4 4384\n42 41 85 79\n29 67 52 55", "output": "151.1058823529412" }, { "input": "7 529\n77 18 67 64 43 51 30\n35 87 17 52 1 97 84", "output": "8.139534883720929" }, { "input": "16 2915\n39 39 81 44 23 47 43 56 7 38 10 100 5 34 87 14\n10 96 34 20 62 88 46 38 29 35 2 43 26 55 31 63", "output": "133.4" }, { "input": "14 6488\n53 41 36 28 17 15 63 33 75 40 85 88 90 100\n7 35 83 2 48 76 93 2 69 56 59 7 25 24", "output": "46.30303030303031" } ]
1,669,773,563
2,147,483,647
Python 3
OK
TESTS
80
92
0
n,V=map(int,input().split(" ")) alist=[int(x) for x in input().split(" ")] blist=[int(x) for x in input().split(" ")] #empty one item from blist ans=0 minrate=100000 for i in range(n): #empty ith item from blist,see if it works rate=blist[i]/alist[i] # how many food should cook minrate=min(minrate,rate) total=0 for i in range(n): total+=alist[i]*minrate print(min(V,total))
Title: Guilty --- to the kitchen! Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills. According to the borscht recipe it consists of *n* ingredients that have to be mixed in proportion litres (thus, there should be *a*1<=·*x*,<=...,<=*a**n*<=·*x* litres of corresponding ingredients mixed for some non-negative *x*). In the kitchen Volodya found out that he has *b*1,<=...,<=*b**n* litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a *V* litres volume pan (which means the amount of soup cooked can be between 0 and *V* litres). What is the volume of borscht Volodya will cook ultimately? Input Specification: The first line of the input contains two space-separated integers *n* and *V* (1<=≤<=*n*<=≤<=20,<=1<=≤<=*V*<=≤<=10000). The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=100). Finally, the last line contains *n* space-separated integers *b**i* (0<=≤<=*b**i*<=≤<=100). Output Specification: Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10<=-<=4. Demo Input: ['1 100\n1\n40\n', '2 100\n1 1\n25 30\n', '2 100\n1 1\n60 60\n'] Demo Output: ['40.0\n', '50.0\n', '100.0\n'] Note: none
```python n,V=map(int,input().split(" ")) alist=[int(x) for x in input().split(" ")] blist=[int(x) for x in input().split(" ")] #empty one item from blist ans=0 minrate=100000 for i in range(n): #empty ith item from blist,see if it works rate=blist[i]/alist[i] # how many food should cook minrate=min(minrate,rate) total=0 for i in range(n): total+=alist[i]*minrate print(min(V,total)) ```
3.977
79
B
Colorful Field
PROGRAMMING
1,400
[ "implementation", "sortings" ]
B. Colorful Field
2
256
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: - Assume that the rows are numbered 1 to *n* from top to bottom and the columns are numbered 1 to *m* from left to right, and a cell in row *i* and column *j* is represented as (*i*,<=*j*). - First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1,<=1)<=→<=...<=→<=(1,<=*m*)<=→<=(2,<=1)<=→<=...<=→<=(2,<=*m*)<=→<=...<=→<=(*n*,<=1)<=→<=...<=→<=(*n*,<=*m*). Waste cells will be ignored. - Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. Now she is wondering how to determine the crop plants in some certain cells.
In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each *k* lines contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*n*,<=1<=≤<=*b*<=≤<=*m*), which denotes a cell (*a*,<=*b*) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each *t* lines contains two integers *i*,<=*j* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*), which is a query that asks you the kind of crop plants of a cell (*i*,<=*j*).
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
[ "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n" ]
[ "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n" ]
The sample corresponds to the figure in the statement.
1,000
[ { "input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1", "output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots" }, { "input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2", "output": "Grapes\nWaste" }, { "input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8\n9 7\n9 1\n2 3\n5 2\n21 16\n20 19\n23 14\n27 6\n25 21\n14 1\n18 14\n7 2\n19 12\n30 27\n4 27\n24 12\n25 20\n26 22\n21 17\n11 6\n5 28\n28 24\n17 30\n2 5\n30 10\n4 21", "output": "Kiwis\nCarrots\nGrapes\nGrapes" }, { "input": "39898 39898 3 1\n4567 8901\n12345 23456\n24680 35679\n29292 12121", "output": "Grapes" }, { "input": "1 1 1 1\n1 1\n1 1", "output": "Waste" }, { "input": "1 2 1 2\n1 1\n1 2\n1 1", "output": "Carrots\nWaste" }, { "input": "1 6 3 12\n1 2\n1 4\n1 6\n1 1\n1 2\n1 6\n1 2\n1 5\n1 3\n1 4\n1 5\n1 5\n1 4\n1 6\n1 3", "output": "Carrots\nWaste\nWaste\nWaste\nGrapes\nKiwis\nWaste\nGrapes\nGrapes\nWaste\nWaste\nKiwis" }, { "input": "1 10 1 3\n1 5\n1 5\n1 5\n1 5", "output": "Waste\nWaste\nWaste" }, { "input": "5 5 1 3\n2 2\n2 2\n2 2\n2 2", "output": "Waste\nWaste\nWaste" }, { "input": "3 3 3 5\n1 1\n2 2\n3 3\n1 1\n2 2\n2 2\n2 2\n3 3", "output": "Waste\nWaste\nWaste\nWaste\nWaste" }, { "input": "1 10 2 4\n1 9\n1 5\n1 5\n1 6\n1 9\n1 10", "output": "Waste\nKiwis\nWaste\nKiwis" }, { "input": "5 2 2 1\n3 2\n4 2\n5 2", "output": "Kiwis" } ]
1,661,604,714
2,147,483,647
Python 3
OK
TESTS
29
466
0
FRUITS = ['Carrots', 'Kiwis', 'Grapes'] rn, cn, wn, qn = map(int, input().split()) waste_locations = [] for _ in range(wn): r, c = map(int, input().split()) order = (r - 1) * cn + c - 1 waste_locations.append(order) # waste_locations = sorted(waste_locations) for _ in range(qn): r, c = map(int, input().split()) fruit_order = (r - 1) * cn + c - 1 if fruit_order in waste_locations: print("Waste") else: previous_waste = 0 for location in waste_locations: if location < fruit_order: previous_waste += 1 print(FRUITS[(fruit_order - previous_waste) % 3])
Title: Colorful Field Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: - Assume that the rows are numbered 1 to *n* from top to bottom and the columns are numbered 1 to *m* from left to right, and a cell in row *i* and column *j* is represented as (*i*,<=*j*). - First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1,<=1)<=→<=...<=→<=(1,<=*m*)<=→<=(2,<=1)<=→<=...<=→<=(2,<=*m*)<=→<=...<=→<=(*n*,<=1)<=→<=...<=→<=(*n*,<=*m*). Waste cells will be ignored. - Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. Now she is wondering how to determine the crop plants in some certain cells. Input Specification: In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each *k* lines contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*n*,<=1<=≤<=*b*<=≤<=*m*), which denotes a cell (*a*,<=*b*) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each *t* lines contains two integers *i*,<=*j* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*), which is a query that asks you the kind of crop plants of a cell (*i*,<=*j*). Output Specification: For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Demo Input: ['4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n'] Demo Output: ['Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n'] Note: The sample corresponds to the figure in the statement.
```python FRUITS = ['Carrots', 'Kiwis', 'Grapes'] rn, cn, wn, qn = map(int, input().split()) waste_locations = [] for _ in range(wn): r, c = map(int, input().split()) order = (r - 1) * cn + c - 1 waste_locations.append(order) # waste_locations = sorted(waste_locations) for _ in range(qn): r, c = map(int, input().split()) fruit_order = (r - 1) * cn + c - 1 if fruit_order in waste_locations: print("Waste") else: previous_waste = 0 for location in waste_locations: if location < fruit_order: previous_waste += 1 print(FRUITS[(fruit_order - previous_waste) % 3]) ```
3.8835
334
A
Candy Bags
PROGRAMMING
1,000
[ "implementation" ]
null
null
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each brother so that all brothers got the same number of candies.
The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers.
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order. It is guaranteed that the solution exists at the given limits.
[ "2\n" ]
[ "1 4\n2 3\n" ]
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
500
[ { "input": "2", "output": "1 4\n2 3" }, { "input": "4", "output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9" }, { "input": "6", "output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19" }, { "input": "8", "output": "1 64 2 63 3 62 4 61\n5 60 6 59 7 58 8 57\n9 56 10 55 11 54 12 53\n13 52 14 51 15 50 16 49\n17 48 18 47 19 46 20 45\n21 44 22 43 23 42 24 41\n25 40 26 39 27 38 28 37\n29 36 30 35 31 34 32 33" }, { "input": "10", "output": "1 100 2 99 3 98 4 97 5 96\n6 95 7 94 8 93 9 92 10 91\n11 90 12 89 13 88 14 87 15 86\n16 85 17 84 18 83 19 82 20 81\n21 80 22 79 23 78 24 77 25 76\n26 75 27 74 28 73 29 72 30 71\n31 70 32 69 33 68 34 67 35 66\n36 65 37 64 38 63 39 62 40 61\n41 60 42 59 43 58 44 57 45 56\n46 55 47 54 48 53 49 52 50 51" }, { "input": "100", "output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951\n51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 993..." }, { "input": "62", "output": "1 3844 2 3843 3 3842 4 3841 5 3840 6 3839 7 3838 8 3837 9 3836 10 3835 11 3834 12 3833 13 3832 14 3831 15 3830 16 3829 17 3828 18 3827 19 3826 20 3825 21 3824 22 3823 23 3822 24 3821 25 3820 26 3819 27 3818 28 3817 29 3816 30 3815 31 3814\n32 3813 33 3812 34 3811 35 3810 36 3809 37 3808 38 3807 39 3806 40 3805 41 3804 42 3803 43 3802 44 3801 45 3800 46 3799 47 3798 48 3797 49 3796 50 3795 51 3794 52 3793 53 3792 54 3791 55 3790 56 3789 57 3788 58 3787 59 3786 60 3785 61 3784 62 3783\n63 3782 64 3781 65 378..." }, { "input": "66", "output": "1 4356 2 4355 3 4354 4 4353 5 4352 6 4351 7 4350 8 4349 9 4348 10 4347 11 4346 12 4345 13 4344 14 4343 15 4342 16 4341 17 4340 18 4339 19 4338 20 4337 21 4336 22 4335 23 4334 24 4333 25 4332 26 4331 27 4330 28 4329 29 4328 30 4327 31 4326 32 4325 33 4324\n34 4323 35 4322 36 4321 37 4320 38 4319 39 4318 40 4317 41 4316 42 4315 43 4314 44 4313 45 4312 46 4311 47 4310 48 4309 49 4308 50 4307 51 4306 52 4305 53 4304 54 4303 55 4302 56 4301 57 4300 58 4299 59 4298 60 4297 61 4296 62 4295 63 4294 64 4293 65 4292..." }, { "input": "18", "output": "1 324 2 323 3 322 4 321 5 320 6 319 7 318 8 317 9 316\n10 315 11 314 12 313 13 312 14 311 15 310 16 309 17 308 18 307\n19 306 20 305 21 304 22 303 23 302 24 301 25 300 26 299 27 298\n28 297 29 296 30 295 31 294 32 293 33 292 34 291 35 290 36 289\n37 288 38 287 39 286 40 285 41 284 42 283 43 282 44 281 45 280\n46 279 47 278 48 277 49 276 50 275 51 274 52 273 53 272 54 271\n55 270 56 269 57 268 58 267 59 266 60 265 61 264 62 263 63 262\n64 261 65 260 66 259 67 258 68 257 69 256 70 255 71 254 72 253\n73 252 7..." }, { "input": "68", "output": "1 4624 2 4623 3 4622 4 4621 5 4620 6 4619 7 4618 8 4617 9 4616 10 4615 11 4614 12 4613 13 4612 14 4611 15 4610 16 4609 17 4608 18 4607 19 4606 20 4605 21 4604 22 4603 23 4602 24 4601 25 4600 26 4599 27 4598 28 4597 29 4596 30 4595 31 4594 32 4593 33 4592 34 4591\n35 4590 36 4589 37 4588 38 4587 39 4586 40 4585 41 4584 42 4583 43 4582 44 4581 45 4580 46 4579 47 4578 48 4577 49 4576 50 4575 51 4574 52 4573 53 4572 54 4571 55 4570 56 4569 57 4568 58 4567 59 4566 60 4565 61 4564 62 4563 63 4562 64 4561 65 4560..." }, { "input": "86", "output": "1 7396 2 7395 3 7394 4 7393 5 7392 6 7391 7 7390 8 7389 9 7388 10 7387 11 7386 12 7385 13 7384 14 7383 15 7382 16 7381 17 7380 18 7379 19 7378 20 7377 21 7376 22 7375 23 7374 24 7373 25 7372 26 7371 27 7370 28 7369 29 7368 30 7367 31 7366 32 7365 33 7364 34 7363 35 7362 36 7361 37 7360 38 7359 39 7358 40 7357 41 7356 42 7355 43 7354\n44 7353 45 7352 46 7351 47 7350 48 7349 49 7348 50 7347 51 7346 52 7345 53 7344 54 7343 55 7342 56 7341 57 7340 58 7339 59 7338 60 7337 61 7336 62 7335 63 7334 64 7333 65 7332..." }, { "input": "96", "output": "1 9216 2 9215 3 9214 4 9213 5 9212 6 9211 7 9210 8 9209 9 9208 10 9207 11 9206 12 9205 13 9204 14 9203 15 9202 16 9201 17 9200 18 9199 19 9198 20 9197 21 9196 22 9195 23 9194 24 9193 25 9192 26 9191 27 9190 28 9189 29 9188 30 9187 31 9186 32 9185 33 9184 34 9183 35 9182 36 9181 37 9180 38 9179 39 9178 40 9177 41 9176 42 9175 43 9174 44 9173 45 9172 46 9171 47 9170 48 9169\n49 9168 50 9167 51 9166 52 9165 53 9164 54 9163 55 9162 56 9161 57 9160 58 9159 59 9158 60 9157 61 9156 62 9155 63 9154 64 9153 65 9152..." }, { "input": "12", "output": "1 144 2 143 3 142 4 141 5 140 6 139\n7 138 8 137 9 136 10 135 11 134 12 133\n13 132 14 131 15 130 16 129 17 128 18 127\n19 126 20 125 21 124 22 123 23 122 24 121\n25 120 26 119 27 118 28 117 29 116 30 115\n31 114 32 113 33 112 34 111 35 110 36 109\n37 108 38 107 39 106 40 105 41 104 42 103\n43 102 44 101 45 100 46 99 47 98 48 97\n49 96 50 95 51 94 52 93 53 92 54 91\n55 90 56 89 57 88 58 87 59 86 60 85\n61 84 62 83 63 82 64 81 65 80 66 79\n67 78 68 77 69 76 70 75 71 74 72 73" }, { "input": "88", "output": "1 7744 2 7743 3 7742 4 7741 5 7740 6 7739 7 7738 8 7737 9 7736 10 7735 11 7734 12 7733 13 7732 14 7731 15 7730 16 7729 17 7728 18 7727 19 7726 20 7725 21 7724 22 7723 23 7722 24 7721 25 7720 26 7719 27 7718 28 7717 29 7716 30 7715 31 7714 32 7713 33 7712 34 7711 35 7710 36 7709 37 7708 38 7707 39 7706 40 7705 41 7704 42 7703 43 7702 44 7701\n45 7700 46 7699 47 7698 48 7697 49 7696 50 7695 51 7694 52 7693 53 7692 54 7691 55 7690 56 7689 57 7688 58 7687 59 7686 60 7685 61 7684 62 7683 63 7682 64 7681 65 7680..." }, { "input": "28", "output": "1 784 2 783 3 782 4 781 5 780 6 779 7 778 8 777 9 776 10 775 11 774 12 773 13 772 14 771\n15 770 16 769 17 768 18 767 19 766 20 765 21 764 22 763 23 762 24 761 25 760 26 759 27 758 28 757\n29 756 30 755 31 754 32 753 33 752 34 751 35 750 36 749 37 748 38 747 39 746 40 745 41 744 42 743\n43 742 44 741 45 740 46 739 47 738 48 737 49 736 50 735 51 734 52 733 53 732 54 731 55 730 56 729\n57 728 58 727 59 726 60 725 61 724 62 723 63 722 64 721 65 720 66 719 67 718 68 717 69 716 70 715\n71 714 72 713 73 712 74 7..." }, { "input": "80", "output": "1 6400 2 6399 3 6398 4 6397 5 6396 6 6395 7 6394 8 6393 9 6392 10 6391 11 6390 12 6389 13 6388 14 6387 15 6386 16 6385 17 6384 18 6383 19 6382 20 6381 21 6380 22 6379 23 6378 24 6377 25 6376 26 6375 27 6374 28 6373 29 6372 30 6371 31 6370 32 6369 33 6368 34 6367 35 6366 36 6365 37 6364 38 6363 39 6362 40 6361\n41 6360 42 6359 43 6358 44 6357 45 6356 46 6355 47 6354 48 6353 49 6352 50 6351 51 6350 52 6349 53 6348 54 6347 55 6346 56 6345 57 6344 58 6343 59 6342 60 6341 61 6340 62 6339 63 6338 64 6337 65 6336..." }, { "input": "48", "output": "1 2304 2 2303 3 2302 4 2301 5 2300 6 2299 7 2298 8 2297 9 2296 10 2295 11 2294 12 2293 13 2292 14 2291 15 2290 16 2289 17 2288 18 2287 19 2286 20 2285 21 2284 22 2283 23 2282 24 2281\n25 2280 26 2279 27 2278 28 2277 29 2276 30 2275 31 2274 32 2273 33 2272 34 2271 35 2270 36 2269 37 2268 38 2267 39 2266 40 2265 41 2264 42 2263 43 2262 44 2261 45 2260 46 2259 47 2258 48 2257\n49 2256 50 2255 51 2254 52 2253 53 2252 54 2251 55 2250 56 2249 57 2248 58 2247 59 2246 60 2245 61 2244 62 2243 63 2242 64 2241 65 224..." }, { "input": "54", "output": "1 2916 2 2915 3 2914 4 2913 5 2912 6 2911 7 2910 8 2909 9 2908 10 2907 11 2906 12 2905 13 2904 14 2903 15 2902 16 2901 17 2900 18 2899 19 2898 20 2897 21 2896 22 2895 23 2894 24 2893 25 2892 26 2891 27 2890\n28 2889 29 2888 30 2887 31 2886 32 2885 33 2884 34 2883 35 2882 36 2881 37 2880 38 2879 39 2878 40 2877 41 2876 42 2875 43 2874 44 2873 45 2872 46 2871 47 2870 48 2869 49 2868 50 2867 51 2866 52 2865 53 2864 54 2863\n55 2862 56 2861 57 2860 58 2859 59 2858 60 2857 61 2856 62 2855 63 2854 64 2853 65 285..." }, { "input": "58", "output": "1 3364 2 3363 3 3362 4 3361 5 3360 6 3359 7 3358 8 3357 9 3356 10 3355 11 3354 12 3353 13 3352 14 3351 15 3350 16 3349 17 3348 18 3347 19 3346 20 3345 21 3344 22 3343 23 3342 24 3341 25 3340 26 3339 27 3338 28 3337 29 3336\n30 3335 31 3334 32 3333 33 3332 34 3331 35 3330 36 3329 37 3328 38 3327 39 3326 40 3325 41 3324 42 3323 43 3322 44 3321 45 3320 46 3319 47 3318 48 3317 49 3316 50 3315 51 3314 52 3313 53 3312 54 3311 55 3310 56 3309 57 3308 58 3307\n59 3306 60 3305 61 3304 62 3303 63 3302 64 3301 65 330..." }, { "input": "64", "output": "1 4096 2 4095 3 4094 4 4093 5 4092 6 4091 7 4090 8 4089 9 4088 10 4087 11 4086 12 4085 13 4084 14 4083 15 4082 16 4081 17 4080 18 4079 19 4078 20 4077 21 4076 22 4075 23 4074 24 4073 25 4072 26 4071 27 4070 28 4069 29 4068 30 4067 31 4066 32 4065\n33 4064 34 4063 35 4062 36 4061 37 4060 38 4059 39 4058 40 4057 41 4056 42 4055 43 4054 44 4053 45 4052 46 4051 47 4050 48 4049 49 4048 50 4047 51 4046 52 4045 53 4044 54 4043 55 4042 56 4041 57 4040 58 4039 59 4038 60 4037 61 4036 62 4035 63 4034 64 4033\n65 403..." }, { "input": "44", "output": "1 1936 2 1935 3 1934 4 1933 5 1932 6 1931 7 1930 8 1929 9 1928 10 1927 11 1926 12 1925 13 1924 14 1923 15 1922 16 1921 17 1920 18 1919 19 1918 20 1917 21 1916 22 1915\n23 1914 24 1913 25 1912 26 1911 27 1910 28 1909 29 1908 30 1907 31 1906 32 1905 33 1904 34 1903 35 1902 36 1901 37 1900 38 1899 39 1898 40 1897 41 1896 42 1895 43 1894 44 1893\n45 1892 46 1891 47 1890 48 1889 49 1888 50 1887 51 1886 52 1885 53 1884 54 1883 55 1882 56 1881 57 1880 58 1879 59 1878 60 1877 61 1876 62 1875 63 1874 64 1873 65 187..." } ]
1,621,490,623
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
n = int(input()) for i in range(1, (n**2) + 1): if(i%n == 0): print(i, end = "\n") else: print(i, end = " ")
Title: Candy Bags Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each brother so that all brothers got the same number of candies. Input Specification: The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. Output Specification: Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order. It is guaranteed that the solution exists at the given limits. Demo Input: ['2\n'] Demo Output: ['1 4\n2 3\n'] Note: The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
```python n = int(input()) for i in range(1, (n**2) + 1): if(i%n == 0): print(i, end = "\n") else: print(i, end = " ") ```
0
296
A
Yaroslav and Permutations
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
[ "1\n1\n", "3\n1 1 2\n", "4\n7 7 7 7\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
500
[ { "input": "1\n1", "output": "YES" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "4\n7 7 7 7", "output": "NO" }, { "input": "4\n479 170 465 146", "output": "YES" }, { "input": "5\n996 437 605 996 293", "output": "YES" }, { "input": "6\n727 539 896 668 36 896", "output": "YES" }, { "input": "7\n674 712 674 674 674 674 674", "output": "NO" }, { "input": "8\n742 742 742 742 742 289 742 742", "output": "NO" }, { "input": "9\n730 351 806 806 806 630 85 757 967", "output": "YES" }, { "input": "10\n324 539 83 440 834 640 440 440 440 440", "output": "YES" }, { "input": "7\n925 830 925 98 987 162 356", "output": "YES" }, { "input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808", "output": "YES" }, { "input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94", "output": "YES" }, { "input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402", "output": "NO" }, { "input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187", "output": "YES" }, { "input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103", "output": "YES" }, { "input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925", "output": "NO" }, { "input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353", "output": "YES" }, { "input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285", "output": "NO" }, { "input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99", "output": "YES" }, { "input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26", "output": "YES" }, { "input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516", "output": "YES" }, { "input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314", "output": "NO" }, { "input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800", "output": "NO" }, { "input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317", "output": "NO" }, { "input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784", "output": "YES" }, { "input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474", "output": "YES" }, { "input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499", "output": "NO" }, { "input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816", "output": "NO" }, { "input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1000", "output": "YES" }, { "input": "12\n2 2 4 4 4 4 6 6 6 6 6 6", "output": "YES" } ]
1,633,453,472
2,147,483,647
Python 3
OK
TESTS
37
154
6,758,400
n = int(input()) m = input().split() possible = True for i in set(m): if m.count(i) >= n/2 + 1: possible = False break print('YES' if possible else 'NO')
Title: Yaroslav and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. Output Specification: In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. Demo Input: ['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
```python n = int(input()) m = input().split() possible = True for i in set(m): if m.count(i) >= n/2 + 1: possible = False break print('YES' if possible else 'NO') ```
3
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L " }, { "input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "output": "C B E Q " }, { "input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "output": "JKD WBIRAQKF YE WV " }, { "input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "output": "KSDHEMIXUJ R S H " }, { "input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB", "output": "OG X I KO " }, { "input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH", "output": "Q QQ I WW JOPJPBRH " }, { "input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB", "output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C " }, { "input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV", "output": "E IQMJNIQ GZZBQZAUHYP PMR DCV " }, { "input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB", "output": "FV BPS RXNETCJ JDMBH B V B " }, { "input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL", "output": "FBQ IDFSY CTWDM SXO QI L " }, { "input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL", "output": "I QLHD YIIKZDFQ CX U K NL " }, { "input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE", "output": "K UPDYXGOKU AGOAH IZD IY V P E " }, { "input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB", "output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ " }, { "input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB", "output": "PAMJGY XGPQM TKGSXUY E N H E " }, { "input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB", "output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB " }, { "input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM", "output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M " }, { "input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW", "output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W " }, { "input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG", "output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G " }, { "input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN", "output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N " }, { "input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG", "output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG " }, { "input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB", "output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L " }, { "input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB", "output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U " }, { "input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB", "output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ " }, { "input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB", "output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J " }, { "input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO", "output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O " }, { "input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR", "output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R " }, { "input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB", "output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM " }, { "input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB", "output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H " }, { "input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB", "output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S " }, { "input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB", "output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J " }, { "input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF", "output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F " }, { "input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY", "output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y " }, { "input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB", "output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO " }, { "input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW", "output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W " }, { "input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD", "output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D " }, { "input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB", "output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A " }, { "input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB", "output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y " }, { "input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB", "output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R " }, { "input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY", "output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y " }, { "input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE", "output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E " }, { "input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS", "output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S " }, { "input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP", "output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP " }, { "input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB", "output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y " }, { "input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL", "output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL " }, { "input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO", "output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O " }, { "input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU", "output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU " }, { "input": "A", "output": "A " }, { "input": "WUBA", "output": "A " }, { "input": "WUBWUBA", "output": "A " }, { "input": "AWUBWUBWUB", "output": "A " }, { "input": "AWUBBWUBCWUBD", "output": "A B C D " }, { "input": "WUBWWUBWUBWUBUWUBWUBBWUB", "output": "W U B " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "WUWUBBWWUBUB", "output": "WU BW UB " }, { "input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB", "output": "WUAB " }, { "input": "ZWUB", "output": "Z " }, { "input": "WU", "output": "WU " }, { "input": "UB", "output": "UB " }, { "input": "U", "output": "U " }, { "input": "WUBW", "output": "W " }, { "input": "WUBWU", "output": "WU " }, { "input": "WUWUB", "output": "WU " }, { "input": "UBWUB", "output": "UB " }, { "input": "WUWUBUBWUBUWUB", "output": "WU UB U " }, { "input": "WUBWWUBAWUB", "output": "W A " }, { "input": "WUUUUU", "output": "WUUUUU " } ]
1,677,542,171
2,147,483,647
Python 3
OK
TESTS
71
124
0
string = input() print(string.replace("WUB", ' ').strip())
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python string = input() print(string.replace("WUB", ' ').strip()) ```
3
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "output": "LIVE\nDEAD" }, { "input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "output": "DEAD\nLIVE" }, { "input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1", "output": "LIVE\nLIVE" }, { "input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3", "output": "DEAD\nDEAD" } ]
1,640,366,733
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
a=[0,0] for i in [0]*int(input()): t,x,y=map(int,input().split()) a[t-1]+=x-y for x in a: print(['LIVE','DEAD'][x<0])
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output Specification: In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format. Demo Input: ['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n'] Demo Output: ['LIVE\nLIVE\n', 'LIVE\nDEAD\n'] Note: Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
```python a=[0,0] for i in [0]*int(input()): t,x,y=map(int,input().split()) a[t-1]+=x-y for x in a: print(['LIVE','DEAD'][x<0]) ```
-1
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,695,227,278
2,147,483,647
PyPy 3-64
OK
TESTS
21
78
0
V='' T=int(input()) for i in range(1,T+1): if i%2==0: V=V+'I love' if i==T: V=V+' it' else: V=V+' that ' else: V=V+'I hate' if i==T: V=V+' it' else: V=V+' that ' print(V)
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 V='' T=int(input()) for i in range(1,T+1): if i%2==0: V=V+'I love' if i==T: V=V+' it' else: V=V+' that ' else: V=V+'I hate' if i==T: V=V+' it' else: V=V+' that ' print(V) ```
3
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp", "output": "0" }, { "input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH", "output": "-1" }, { "input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt", "output": "1" }, { "input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL", "output": "1" }, { "input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo", "output": "1" }, { "input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja", "output": "-1" }, { "input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy", "output": "1" }, { "input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR", "output": "1" }, { "input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd", "output": "1" }, { "input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI", "output": "-1" }, { "input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC", "output": "-1" }, { "input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl", "output": "-1" }, { "input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo", "output": "-1" }, { "input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV", "output": "-1" }, { "input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ", "output": "-1" }, { "input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK", "output": "-1" }, { "input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys", "output": "1" }, { "input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy", "output": "-1" }, { "input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK", "output": "-1" }, { "input": "UG\nak", "output": "1" }, { "input": "JZR\nVae", "output": "-1" }, { "input": "a\nZ", "output": "-1" }, { "input": "rk\nkv", "output": "1" }, { "input": "RvuT\nbJzE", "output": "1" }, { "input": "PPS\nydq", "output": "-1" }, { "input": "q\nq", "output": "0" }, { "input": "peOw\nIgSJ", "output": "1" }, { "input": "PyK\noKN", "output": "1" }, { "input": "O\ni", "output": "1" }, { "input": "NmGY\npDlP", "output": "-1" }, { "input": "nG\nZf", "output": "-1" }, { "input": "m\na", "output": "1" }, { "input": "MWyB\nWZEV", "output": "-1" }, { "input": "Gre\nfxc", "output": "1" }, { "input": "Ooq\nwap", "output": "-1" }, { "input": "XId\nlbB", "output": "1" }, { "input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF", "output": "0" }, { "input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD", "output": "0" }, { "input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA", "output": "0" }, { "input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ", "output": "0" }, { "input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG", "output": "0" }, { "input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ", "output": "0" }, { "input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ", "output": "0" }, { "input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi", "output": "0" }, { "input": "abac\nadaa", "output": "-1" }, { "input": "Bbc\nabc", "output": "1" }, { "input": "aaaba\naaaab", "output": "1" } ]
1,696,561,818
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
60
0
x = input() y = input() x = x.lower() y = y.lower() newx = [] newy = [] for l in x: newx.append(l) for n in y: newy.append(n) newx = list(set(newx)) newy = list(set(newy)) if newx == newy: print(0) elif len(newx) < len(newy) or len(newx) > len(newy): print(1) else: print(-1)
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. Input Specification: Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. Output Specification: If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. Demo Input: ['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
```python x = input() y = input() x = x.lower() y = y.lower() newx = [] newy = [] for l in x: newx.append(l) for n in y: newy.append(n) newx = list(set(newx)) newy = list(set(newy)) if newx == newy: print(0) elif len(newx) < len(newy) or len(newx) > len(newy): print(1) else: print(-1) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,641,737,962
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
s = str(input()) want_string = 'hello' li = list(s) cnt = 5 cnt2 = 0 for i in li: if i == want_string[cnt2]: cnt -= 1 cnt2 += 1 if cnt == 0: print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s = str(input()) want_string = 'hello' li = list(s) cnt = 5 cnt2 = 0 for i in li: if i == want_string[cnt2]: cnt -= 1 cnt2 += 1 if cnt == 0: print('YES') else: print('NO') ```
-1
379
A
New Year Candles
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Print a single integer — the number of hours Vasily can light up the room for.
[ "4 2\n", "6 3\n" ]
[ "7\n", "8\n" ]
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
500
[ { "input": "4 2", "output": "7" }, { "input": "6 3", "output": "8" }, { "input": "1000 1000", "output": "1001" }, { "input": "123 5", "output": "153" }, { "input": "1000 2", "output": "1999" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "1 4", "output": "1" }, { "input": "2 2", "output": "3" }, { "input": "3 2", "output": "5" }, { "input": "3 3", "output": "4" }, { "input": "999 2", "output": "1997" }, { "input": "1000 3", "output": "1499" }, { "input": "1000 4", "output": "1333" }, { "input": "1 1000", "output": "1" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "10 4", "output": "13" }, { "input": "4 3", "output": "5" }, { "input": "91 5", "output": "113" }, { "input": "777 17", "output": "825" }, { "input": "100 4", "output": "133" }, { "input": "5 3", "output": "7" }, { "input": "6 4", "output": "7" }, { "input": "26 8", "output": "29" }, { "input": "9 4", "output": "11" }, { "input": "20 3", "output": "29" }, { "input": "17 3", "output": "25" } ]
1,671,799,268
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
a,b = list(map(int,input().split())) c = 0 while True: c += a a = a // b if a <= 0: break print(c)
Title: New Year Candles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. Input Specification: The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). Output Specification: Print a single integer — the number of hours Vasily can light up the room for. Demo Input: ['4 2\n', '6 3\n'] Demo Output: ['7\n', '8\n'] Note: Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
```python a,b = list(map(int,input().split())) c = 0 while True: c += a a = a // b if a <= 0: break print(c) ```
0
82
A
Double Cola
PROGRAMMING
1,100
[ "implementation", "math" ]
A. Double Cola
1
256
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
[ "1\n", "6\n", "1802\n" ]
[ "Sheldon\n", "Sheldon\n", "Penny\n" ]
none
500
[ { "input": "1", "output": "Sheldon" }, { "input": "6", "output": "Sheldon" }, { "input": "1802", "output": "Penny" }, { "input": "1", "output": "Sheldon" }, { "input": "2", "output": "Leonard" }, { "input": "3", "output": "Penny" }, { "input": "4", "output": "Rajesh" }, { "input": "5", "output": "Howard" }, { "input": "10", "output": "Penny" }, { "input": "534", "output": "Rajesh" }, { "input": "5033", "output": "Howard" }, { "input": "10010", "output": "Howard" }, { "input": "500000000", "output": "Penny" }, { "input": "63", "output": "Rajesh" }, { "input": "841", "output": "Leonard" }, { "input": "3667", "output": "Penny" }, { "input": "38614", "output": "Howard" }, { "input": "282798", "output": "Rajesh" }, { "input": "9266286", "output": "Rajesh" }, { "input": "27385966", "output": "Leonard" }, { "input": "121580142", "output": "Penny" }, { "input": "5", "output": "Howard" }, { "input": "300", "output": "Howard" }, { "input": "1745", "output": "Leonard" }, { "input": "8302", "output": "Rajesh" }, { "input": "184518", "output": "Sheldon" }, { "input": "1154414", "output": "Rajesh" }, { "input": "28643950", "output": "Leonard" }, { "input": "159222638", "output": "Howard" }, { "input": "24", "output": "Penny" }, { "input": "505", "output": "Penny" }, { "input": "4425", "output": "Rajesh" }, { "input": "12079", "output": "Sheldon" }, { "input": "469726", "output": "Penny" }, { "input": "3961838", "output": "Penny" }, { "input": "57710446", "output": "Leonard" }, { "input": "80719470", "output": "Howard" }, { "input": "1000000000", "output": "Penny" }, { "input": "999999999", "output": "Penny" }, { "input": "999999998", "output": "Penny" }, { "input": "5", "output": "Howard" } ]
1,649,727,311
2,147,483,647
Python 3
OK
TESTS
41
46
0
n=int(input())-1 while n>4: n=n-5>>1 print("SLPRHheeaoeonjwlnneadaysror hdnd"[n::5])
Title: Double Cola Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input Specification: The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Specification: Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Demo Input: ['1\n', '6\n', '1802\n'] Demo Output: ['Sheldon\n', 'Sheldon\n', 'Penny\n'] Note: none
```python n=int(input())-1 while n>4: n=n-5>>1 print("SLPRHheeaoeonjwlnneadaysror hdnd"[n::5]) ```
3.977
637
B
Chat Order
PROGRAMMING
1,200
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
1,000
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "output": "ypg" }, { "input": "3\nexhll\nexhll\narruapexj", "output": "arruapexj\nexhll" }, { "input": "3\nfv\nle\nle", "output": "le\nfv" }, { "input": "8\nm\nm\nm\nm\nm\nm\nm\nm", "output": "m" }, { "input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr", "output": "r\nu\nb\nk\nw\ni" }, { "input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok", "output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne" }, { "input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe", "output": "we\nklrj" }, { "input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh", "output": "zncybqmh\naeebef\nn" }, { "input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo", "output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj" }, { "input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn", "output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy" }, { "input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg", "output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg" }, { "input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh", "output": "vhh\nfa" }, { "input": "2\naa\nbb", "output": "bb\naa" }, { "input": "2\naa\na", "output": "a\naa" }, { "input": "3\naa\naa\naa", "output": "aa" }, { "input": "5\naa\na\naa\na\naa", "output": "aa\na" }, { "input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa", "output": "aaa\naaaaaaa\naa\na\naaaa" }, { "input": "5\na\naa\naaa\naaaa\na", "output": "a\naaaa\naaa\naa" }, { "input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa", "output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa" }, { "input": "3\na\naa\naaa", "output": "aaa\naa\na" }, { "input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz", "output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz" } ]
1,656,187,092
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
4,198,400
n = int(input()) l = [] for i in range(n): lst = input() l.append(lst) l.reverse() final = set() for i in l: if i not in final: final.add(i) for i in final: print(i)
Title: Chat Order Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. Output Specification: Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. Demo Input: ['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n'] Demo Output: ['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n'] Note: In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
```python n = int(input()) l = [] for i in range(n): lst = input() l.append(lst) l.reverse() final = set() for i in l: if i not in final: final.add(i) for i in final: print(i) ```
0
492
B
Vanya and Lanterns
PROGRAMMING
1,200
[ "binary search", "implementation", "math", "sortings" ]
null
null
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "7 15\n15 5 3 7 9 14 0\n", "2 5\n2 5\n" ]
[ "2.5000000000\n", "2.0000000000\n" ]
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
1,000
[ { "input": "7 15\n15 5 3 7 9 14 0", "output": "2.5000000000" }, { "input": "2 5\n2 5", "output": "2.0000000000" }, { "input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307", "output": "22258199.5000000000" }, { "input": "2 1000000000\n0 1000000000", "output": "500000000.0000000000" }, { "input": "2 555\n200 300", "output": "255.0000000000" }, { "input": "1 1\n1", "output": "1.0000000000" }, { "input": "1 1\n0", "output": "1.0000000000" }, { "input": "1 1000000000\n0", "output": "1000000000.0000000000" }, { "input": "1 1000000000\n1000000000", "output": "1000000000.0000000000" }, { "input": "1 999999999\n499999999", "output": "500000000.0000000000" }, { "input": "4 700\n0 250 475 700", "output": "125.0000000000" }, { "input": "4 700\n0 225 450 700", "output": "125.0000000000" }, { "input": "5 1000\n0 250 500 750 1000", "output": "125.0000000000" }, { "input": "5 2000\n1001 1001 1001 1001 1001", "output": "1001.0000000000" }, { "input": "1 999\n501", "output": "501.0000000000" }, { "input": "2 1000\n400 600", "output": "400.0000000000" }, { "input": "4 15\n1 3 9 11", "output": "4.0000000000" }, { "input": "1 5\n2", "output": "3.0000000000" } ]
1,686,033,683
2,147,483,647
PyPy 3-64
OK
TESTS
32
62
0
n,l = map(int,input().split()) a = list(map(int,input().split())) a = sorted(a) ma = -1 for i in range(1,n): if (a[i] - a[i - 1])/2 > ma: ma = (a[i] - a[i - 1])/2 if a[-1] != l: if l - a[-1] > ma: ma = l - a[-1] if a[0] != 0: if a[0] > ma: ma = a[0] print("%.10f" % ma)
Title: Vanya and Lanterns Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? Input Specification: The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. Output Specification: Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. Demo Input: ['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n'] Demo Output: ['2.5000000000\n', '2.0000000000\n'] Note: Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
```python n,l = map(int,input().split()) a = list(map(int,input().split())) a = sorted(a) ma = -1 for i in range(1,n): if (a[i] - a[i - 1])/2 > ma: ma = (a[i] - a[i - 1])/2 if a[-1] != l: if l - a[-1] > ma: ma = l - a[-1] if a[0] != 0: if a[0] > ma: ma = a[0] print("%.10f" % ma) ```
3
774
K
Stepan and Vowels
PROGRAMMING
1,600
[ "*special", "implementation", "strings" ]
null
null
Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa". Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowel letters are "a", "e", "i", "o", "u" and "y". There are exceptions: if letters "e" or "o" repeat in a row exactly 2 times, like in words "feet" and "foot", the program must skip them and do not transform in one vowel. For example, the word "iiiimpleeemeentatiioon" must be converted to the word "implemeentatioon". Sergey is very busy and asks you to help him and write the required program.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of letters in the word written by Stepan. The second line contains the string *s* which has length that equals to *n* and contains only lowercase English letters — the word written by Stepan.
Print the single string — the word written by Stepan converted according to the rules described in the statement.
[ "13\npobeeeedaaaaa\n", "22\niiiimpleeemeentatiioon\n", "18\naeiouyaaeeiioouuyy\n", "24\naaaoooiiiuuuyyyeeeggghhh\n" ]
[ "pobeda\n", "implemeentatioon\n", "aeiouyaeeioouy\n", "aoiuyeggghhh\n" ]
none
0
[ { "input": "13\npobeeeedaaaaa", "output": "pobeda" }, { "input": "22\niiiimpleeemeentatiioon", "output": "implemeentatioon" }, { "input": "18\naeiouyaaeeiioouuyy", "output": "aeiouyaeeioouy" }, { "input": "24\naaaoooiiiuuuyyyeeeggghhh", "output": "aoiuyeggghhh" }, { "input": "36\naeiouyaaeeiioouuyyaaaeeeiiiooouuuyyy", "output": "aeiouyaeeioouyaeiouy" }, { "input": "100\noiyufyyyioueoudosizoryuoedatenougiuaeuouuyoiimaeigeeycewuooyovacoiyuaygfuuaiaeuahuieeafxsciylaebeufi", "output": "oiyufyioueoudosizoryuoedatenougiuaeuouyoimaeigeeycewuooyovacoiyuaygfuaiaeuahuieeafxsciylaebeufi" }, { "input": "200\nmmffggzvuuzzlkafduueqocuybiiaaeeoiioouaaurccuqoouuooooooyjjtyyxxiipneeueyuuoyxxhhkaaooooyaaauuoppzabuuoiiuuggcciissuugejjiirruummsiifaauyypauwoofiemzaeeeeeeiioozzttyyidaaaiggizzerkooooeeepueeauuppthhb", "output": "mmffggzvuzzlkafdueqocuybiaeeoioouaurccuqoouoyjjtyxxipneeueyuoyxxhhkaoyauoppzabuoiuggccissugejjirrummsifauypauwoofiemzaeioozzttyidaiggizzerkoepueeauppthhb" }, { "input": "1\no", "output": "o" }, { "input": "1\ne", "output": "e" }, { "input": "1\nf", "output": "f" }, { "input": "1\na", "output": "a" }, { "input": "2\nee", "output": "ee" }, { "input": "2\noo", "output": "oo" }, { "input": "4\neeoo", "output": "eeoo" }, { "input": "7\nooeeeee", "output": "ooe" }, { "input": "75\noiaaaiiioyoeuauieeeeyauioyaiuyueeoaiiyeauyuauuyueoioueieeaaeyiyeyyaiooouyoo", "output": "oiaioyoeuauieyauioyaiuyueeoaiyeauyuauyueoioueieeaeyiyeyaiouyoo" }, { "input": "5\noooee", "output": "oee" }, { "input": "8\neeeaaeee", "output": "eae" }, { "input": "10\noaaoooaaoo", "output": "oaoaoo" }, { "input": "5\nooeoo", "output": "ooeoo" }, { "input": "3\neoo", "output": "eoo" }, { "input": "3\nooo", "output": "o" } ]
1,607,020,187
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
124
0
import sys input = sys.stdin.readline def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return 0 return 1 def main(): n = int(input()) s=input() d={} d['a']=d['e']=d['i']=d['o']=d['u']=0 i=0 while(i<n): if s[i] in d.keys(): c=1 while(i+1<n and s[i]==s[i+1]): i+=1 c+=1 if s[i]=='e' or s[i]=='o': if c>2: print(s[i],end='') else: print(s[i]*c,end='') else: print(s[i],end='') else: print(s[i],end='') i+=1 if __name__ == "__main__": main()
Title: Stepan and Vowels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa". Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowel letters are "a", "e", "i", "o", "u" and "y". There are exceptions: if letters "e" or "o" repeat in a row exactly 2 times, like in words "feet" and "foot", the program must skip them and do not transform in one vowel. For example, the word "iiiimpleeemeentatiioon" must be converted to the word "implemeentatioon". Sergey is very busy and asks you to help him and write the required program. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of letters in the word written by Stepan. The second line contains the string *s* which has length that equals to *n* and contains only lowercase English letters — the word written by Stepan. Output Specification: Print the single string — the word written by Stepan converted according to the rules described in the statement. Demo Input: ['13\npobeeeedaaaaa\n', '22\niiiimpleeemeentatiioon\n', '18\naeiouyaaeeiioouuyy\n', '24\naaaoooiiiuuuyyyeeeggghhh\n'] Demo Output: ['pobeda\n', 'implemeentatioon\n', 'aeiouyaeeioouy\n', 'aoiuyeggghhh\n'] Note: none
```python import sys input = sys.stdin.readline def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return 0 return 1 def main(): n = int(input()) s=input() d={} d['a']=d['e']=d['i']=d['o']=d['u']=0 i=0 while(i<n): if s[i] in d.keys(): c=1 while(i+1<n and s[i]==s[i+1]): i+=1 c+=1 if s[i]=='e' or s[i]=='o': if c>2: print(s[i],end='') else: print(s[i]*c,end='') else: print(s[i],end='') else: print(s[i],end='') i+=1 if __name__ == "__main__": main() ```
0
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "input": "2 2\n20 10", "output": "1" }, { "input": "2 1\n20 1", "output": "2" }, { "input": "3 1\n1 2 3", "output": "1" }, { "input": "3 1\n2 1 3", "output": "2" }, { "input": "3 1\n3 2 1", "output": "3" }, { "input": "3 2\n1 2 3", "output": "1" }, { "input": "3 2\n3 2 1", "output": "2" }, { "input": "3 3\n1 2 3", "output": "1" }, { "input": "4 2\n9 8 11 7", "output": "1" }, { "input": "4 2\n10 1 2 3", "output": "2" }, { "input": "6 3\n56 56 56 2 1 2", "output": "4" }, { "input": "8 3\n1 1 1 1 2 60 90 1", "output": "1" }, { "input": "4 1\n1 5 2 2", "output": "1" }, { "input": "4 2\n4 6 7 4", "output": "1" }, { "input": "10 4\n1 1 1 4 4 4 4 4 4 3", "output": "1" }, { "input": "6 3\n1 2 1 3 1 1", "output": "1" }, { "input": "5 2\n100 100 100 1 1", "output": "4" } ]
1,695,610,820
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
16
61
11,878,400
n, k = map(int, input().split(' ')) arr = [int(a) for a in input().split(' ')] s = sum(arr[:k]) last = 0 idx = 0 for i in range(k,len(arr)): t = s - arr[last] + arr[i] if t < s: s = t idx = i - k + 1 last += 1 print(idx + 1)
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). Input Specification: The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence. Output Specification: Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. Demo Input: ['7 3\n1 2 6 1 1 7 1\n'] Demo Output: ['3\n'] Note: In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
```python n, k = map(int, input().split(' ')) arr = [int(a) for a in input().split(' ')] s = sum(arr[:k]) last = 0 idx = 0 for i in range(k,len(arr)): t = s - arr[last] + arr[i] if t < s: s = t idx = i - k + 1 last += 1 print(idx + 1) ```
0
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer.
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "input": "71 85 88", "output": "17" }, { "input": "30 38 99", "output": "69" }, { "input": "23 82 95", "output": "72" }, { "input": "22 41 47", "output": "25" }, { "input": "9 94 77", "output": "85" }, { "input": "1 53 51", "output": "52" }, { "input": "25 97 93", "output": "72" }, { "input": "42 53 51", "output": "11" }, { "input": "81 96 94", "output": "15" }, { "input": "21 5 93", "output": "88" }, { "input": "50 13 75", "output": "62" }, { "input": "41 28 98", "output": "70" }, { "input": "69 46 82", "output": "36" }, { "input": "87 28 89", "output": "61" }, { "input": "44 45 40", "output": "5" }, { "input": "86 97 68", "output": "29" }, { "input": "43 92 30", "output": "62" }, { "input": "16 70 1", "output": "69" }, { "input": "40 46 19", "output": "27" }, { "input": "71 38 56", "output": "33" }, { "input": "82 21 80", "output": "61" }, { "input": "75 8 35", "output": "67" }, { "input": "75 24 28", "output": "51" }, { "input": "78 23 56", "output": "55" }, { "input": "85 31 10", "output": "75" }, { "input": "76 50 9", "output": "67" }, { "input": "95 37 34", "output": "61" }, { "input": "84 61 35", "output": "49" }, { "input": "87 85 37", "output": "50" }, { "input": "1 3 2", "output": "2" }, { "input": "4 2 6", "output": "4" }, { "input": "6 9 3", "output": "6" }, { "input": "12 4 8", "output": "8" }, { "input": "15 10 5", "output": "10" }, { "input": "1 50 17", "output": "49" }, { "input": "10 5 15", "output": "10" }, { "input": "8 1 9", "output": "8" }, { "input": "3 5 4", "output": "2" }, { "input": "2 1 3", "output": "2" }, { "input": "1 8 2", "output": "7" }, { "input": "1 100 2", "output": "99" }, { "input": "1 4 6", "output": "5" } ]
1,677,677,785
2,147,483,647
PyPy 3
OK
TESTS
48
93
0
distance=list(map(int,input().split())) distance.sort() first=distance[1]-distance[0] second=distance[2]-distance[1] total=first+second print(total)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer. Input Specification: The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. Output Specification: Print one integer — the minimum total distance the friends need to travel in order to meet together. Demo Input: ['7 1 4\n', '30 20 10\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
```python distance=list(map(int,input().split())) distance.sort() first=distance[1]-distance[0] second=distance[2]-distance[1] total=first+second print(total) ```
3
78
B
Easter Eggs
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
B. Easter Eggs
2
256
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them.
[ "8\n", "13\n" ]
[ "ROYGRBIV\n", "ROYGBIVGBIVYG\n" ]
The way the eggs will be painted in the first sample is shown on the picture:
1,000
[ { "input": "8", "output": "ROYGBIVG" }, { "input": "13", "output": "ROYGBIVOYGBIV" }, { "input": "7", "output": "ROYGBIV" }, { "input": "10", "output": "ROYGBIVYGB" }, { "input": "14", "output": "ROYGBIVROYGBIV" }, { "input": "50", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "9", "output": "ROYGBIVGB" }, { "input": "11", "output": "ROYGBIVYGBI" }, { "input": "12", "output": "ROYGBIVOYGBI" }, { "input": "15", "output": "ROYGBIVROYGBIVG" }, { "input": "16", "output": "ROYGBIVROYGBIVGB" }, { "input": "17", "output": "ROYGBIVROYGBIVYGB" }, { "input": "18", "output": "ROYGBIVROYGBIVYGBI" }, { "input": "19", "output": "ROYGBIVROYGBIVOYGBI" }, { "input": "20", "output": "ROYGBIVROYGBIVOYGBIV" }, { "input": "21", "output": "ROYGBIVROYGBIVROYGBIV" }, { "input": "22", "output": "ROYGBIVROYGBIVROYGBIVG" }, { "input": "23", "output": "ROYGBIVROYGBIVROYGBIVGB" }, { "input": "24", "output": "ROYGBIVROYGBIVROYGBIVYGB" }, { "input": "25", "output": "ROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "28", "output": "ROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "29", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "34", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "43", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "61", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "79", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" }, { "input": "81", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "92", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "95", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "96", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "97", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "98", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "99", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "100", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" } ]
1,641,658,719
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n = int(input()) colors = "ROYGBIV" for i in range(n): print(colors[i%7],end='')
Title: Easter Eggs Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. Input Specification: The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). Output Specification: Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them. Demo Input: ['8\n', '13\n'] Demo Output: ['ROYGRBIV\n', 'ROYGBIVGBIVYG\n'] Note: The way the eggs will be painted in the first sample is shown on the picture:
```python n = int(input()) colors = "ROYGBIV" for i in range(n): print(colors[i%7],end='') ```
0
22
A
Second Order Statistics
PROGRAMMING
800
[ "brute force" ]
A. Second Order Statistics
2
256
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
[ "4\n1 2 2 -4\n", "5\n1 2 3 1 1\n" ]
[ "1\n", "2\n" ]
none
0
[ { "input": "4\n1 2 2 -4", "output": "1" }, { "input": "5\n1 2 3 1 1", "output": "2" }, { "input": "1\n28", "output": "NO" }, { "input": "2\n-28 12", "output": "12" }, { "input": "3\n-83 40 -80", "output": "-80" }, { "input": "8\n93 77 -92 26 21 -48 53 91", "output": "-48" }, { "input": "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49", "output": "-86" }, { "input": "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94", "output": "-98" }, { "input": "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46", "output": "-91" }, { "input": "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89", "output": "-98" }, { "input": "2\n-1 -1", "output": "NO" }, { "input": "3\n-2 -2 -2", "output": "NO" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "NO" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100", "output": "100" }, { "input": "10\n40 71 -85 -85 40 -85 -85 64 -85 47", "output": "40" }, { "input": "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90", "output": "-64" }, { "input": "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93", "output": "-93" }, { "input": "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83", "output": "-86" }, { "input": "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43", "output": "-95" }, { "input": "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92", "output": "-92" }, { "input": "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12", "output": "-98" }, { "input": "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100", "output": "-98" }, { "input": "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92", "output": "-98" }, { "input": "3\n1 2 3", "output": "2" }, { "input": "3\n1 3 2", "output": "2" }, { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 3 1", "output": "2" }, { "input": "3\n3 1 2", "output": "2" }, { "input": "3\n3 2 1", "output": "2" }, { "input": "9\n99 99 99 99 100 100 100 100 100", "output": "100" }, { "input": "5\n-100 -100 -100 -100 -100", "output": "NO" } ]
1,618,752,663
2,147,483,647
Python 3
OK
TESTS
31
124
0
n=int(input()) l=list(map(int,input().split())) l.sort() a=l[0] for i in range(n): if l[i]!=a: print(l[i]) break if i==n-1 and l[i]==a: print('NO')
Title: Second Order Statistics Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. Output Specification: If the given sequence has the second order statistics, output this order statistics, otherwise output NO. Demo Input: ['4\n1 2 2 -4\n', '5\n1 2 3 1 1\n'] Demo Output: ['1\n', '2\n'] Note: none
```python n=int(input()) l=list(map(int,input().split())) l.sort() a=l[0] for i in range(n): if l[i]!=a: print(l[i]) break if i==n-1 and l[i]==a: print('NO') ```
3.969
913
C
Party Lemonade
PROGRAMMING
1,600
[ "bitmasks", "dp", "greedy" ]
null
null
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of *n* different volumes at different costs. A single bottle of type *i* has volume 2*i*<=-<=1 liters and costs *c**i* roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least *L* liters of lemonade. How many roubles do you have to spend?
The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=30; 1<=≤<=*L*<=≤<=109) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=109) — the costs of bottles of different types.
Output a single integer — the smallest number of roubles you have to pay in order to buy at least *L* liters of lemonade.
[ "4 12\n20 30 70 90\n", "4 3\n10000 1000 100 10\n", "4 3\n10 100 1000 10000\n", "5 787787787\n123456789 234567890 345678901 456789012 987654321\n" ]
[ "150\n", "10\n", "30\n", "44981600785557577\n" ]
In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
1,000
[ { "input": "4 12\n20 30 70 90", "output": "150" }, { "input": "4 3\n10000 1000 100 10", "output": "10" }, { "input": "4 3\n10 100 1000 10000", "output": "30" }, { "input": "5 787787787\n123456789 234567890 345678901 456789012 987654321", "output": "44981600785557577" }, { "input": "30 792520535\n528145579 682850171 79476920 178914057 180053263 538638086 433143781 299775597 723428544 177615223 959893339 639448861 506106572 807471834 42398440 347390133 65783782 988164990 606389825 877178711 513188067 609539702 558894975 271129128 956393790 981348376 608410525 61890513 991440277 682151552", "output": "371343078" }, { "input": "30 719520853\n1 3 7 9 21 44 81 49 380 256 1592 1523 4711 6202 1990 48063 112547 210599 481862 1021025 2016280 643778 4325308 3603826 20964534 47383630 100267203 126018116 187142230 604840362", "output": "87393281" }, { "input": "30 604179824\n501412684 299363783 300175300 375965822 55881706 96888084 842141259 269152598 954400269 589424644 244226611 443088309 914941214 856763895 380059734 9424058 97467018 912446445 609122261 773853033 728987202 239388430 617092754 182847275 385882428 86295843 416876980 952408652 399750639 326299418", "output": "564859510" }, { "input": "1 1000000000\n1000000000", "output": "1000000000000000000" }, { "input": "1 1\n1", "output": "1" }, { "input": "30 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "2000000000" }, { "input": "5 25\n52 91 84 66 93", "output": "186" }, { "input": "10 660\n2316 3782 9667 4268 4985 2256 6854 9312 4388 9913", "output": "13164" }, { "input": "20 807689532\n499795319 630489472 638483114 54844847 209402053 71113129 931903630 213385792 726471950 950559532 396028074 711222849 458354548 937511907 247071934 160971961 333550064 4453536 857363099 464797922", "output": "27447142368" }, { "input": "30 842765745\n2 2 2 4 6 8 12 12 18 28 52 67 92 114 191 212 244 459 738 1078 1338 1716 1860 1863 2990 4502 8575 11353 12563 23326", "output": "42251" }, { "input": "1 1\n1000000000", "output": "1000000000" }, { "input": "1 1000000000\n1", "output": "1000000000" }, { "input": "30 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "30 1000000000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "30 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "1 570846883\n300888960", "output": "171761524945111680" }, { "input": "2 245107323\n357416000 761122471", "output": "87605278957368000" }, { "input": "3 624400466\n824008448 698922561 760128125", "output": "118656089186285061" }, { "input": "5 972921345\n496871039 134331253 959524096 747165691 981088452", "output": "59657618590751221" }, { "input": "8 700735368\n931293374 652764228 183746499 853268148 653623691 684604018 902322304 186452621", "output": "1020734127854016" }, { "input": "13 695896744\n495801986 946818643 421711713 151976207 616318787 713653645 893406153 42255449 871957806 865208878 547381951 478062469 516417162", "output": "87737726572314" }, { "input": "21 186982676\n261355063 273322266 663309548 981847874 432074163 204617748 86151188 381783810 725544703 947880176 870951660 226330358 680228931 959825764 972157951 874066182 208942221 587976360 749662969 377541340 841644620", "output": "134782258380" }, { "input": "29 140874704\n948286516 335531500 165926134 633474522 606947099 21370216 16126534 254131475 624116869 824903957 541685498 351709345 925541565 253434732 759289345 168754543 993046389 636985579 332772332 103110829 311797311 739860627 233674609 950017614 387656468 939870312 161573356 176555912 592529105", "output": "338129268" }, { "input": "6 566613866\n1 3 3 16 11 13", "output": "230186887" }, { "input": "11 435675771\n2 2 2 4 4 5 5 8 10 18 21", "output": "8934765" }, { "input": "13 688240686\n2 4 1 15 7 1 34 129 295 905 1442 1198 3771", "output": "21507522" }, { "input": "15 645491742\n2 2 2 2 3 3 4 8 10 14 19 37 42 74 84", "output": "3309432" }, { "input": "29 592983020\n2 3 7 8 30 45 125 132 124 61 1231 1626 7470 14538 18828 35057 34820 219967 359159 362273 1577550 2434174 1736292 15104217 17689384 39467552 50809520 13580992 414752454", "output": "61009202" }, { "input": "29 42473833\n13 18 21 32 45 72 134 203 320 342 400 565 1039 1093 2142 3383 5360 7894 13056 17053 26524 38453 63285 102775 156618 252874 304854 600862 857837", "output": "304854" }, { "input": "28 48504243\n1 1 6 1 32 37 125 212 187 676 1679 771 485 9030 1895 26084 109430 96769 257473 383668 645160 1550917 6195680 6309095 16595706 13231037 99591007 255861473", "output": "5610124" }, { "input": "28 17734553\n13 22 33 59 93 164 166 308 454 532 771 898 1312 2256 3965 5207 6791 13472 13793 26354 47030 68133 118082 199855 221897 257395 417525 536230", "output": "257395" }, { "input": "27 358801274\n2 3 6 10 2 30 124 35 249 268 79 4013 1693 3522 17730 17110 52968 235714 155787 405063 1809923 667660 2266461 14291190 15502027 54103386 14154765", "output": "27680968" }, { "input": "27 437705674\n13 13 21 21 25 31 49 83 148 243 246 263 268 282 475 867 1709 3333 4587 5947 11467 22629 25843 31715 34392 45690 47657", "output": "333599" }, { "input": "26 519355202\n2 2 6 3 4 23 124 115 312 883 526 3158 2901 14398 797 8137 127577 112515 54101 426458 877533 3978708 6725849 5496068 14408348 27866871", "output": "25264103" }, { "input": "26 707933691\n13 17 31 44 69 70 89 158 246 320 605 934 1635 2364 4351 8660 10262 11664 14090 18908 35845 51033 59963 78775 117479 179510", "output": "3829673" }, { "input": "25 269843721\n1 4 5 12 6 16 123 195 374 475 974 2303 4109 8890 16632 64699 71115 251461 476703 447854 2042296 3095451 2796629 13478163 13314670", "output": "101191398" }, { "input": "25 978161707\n13 22 24 34 66 73 145 287 289 521 693 996 1230 1486 1517 2663 3770 3776 5286 7953 15775 30877 42848 84850 114828", "output": "6718647" }, { "input": "5 304398130\n328619601 758941829 198270024 713154224 371680309", "output": "7071174590398871" }, { "input": "10 354651161\n676522959 11809337 625434179 312329830 399019943 545095979 566206452 292370104 819250687 361397475", "output": "250332233709431" }, { "input": "10 907948615\n369010656 907829481 622481545 200317148 960270397 26028213 655060035 796833494 123373353 324969455", "output": "437565141462561" }, { "input": "10 590326547\n540224591 578261545 271951966 787805881 165741203 795359732 547118852 746648763 284153835 602102300", "output": "655248513971940" }, { "input": "20 264504887\n256244331 292829612 807171068 120710 900798902 214013876 575261859 40214283 293542999 366877272 353675296 705322168 205009788 86530854 620744650 766826836 240331588 700218303 406369581 649737981", "output": "327898333295" }, { "input": "20 749478720\n148277091 195065491 92471169 473441125 104827125 387256363 959435633 241640 395794406 734016994 107553118 129783960 812331272 999596018 837854100 215240378 598412225 653614923 933185587 845929351", "output": "1209345077739" }, { "input": "20 628134337\n706690396 73852246 47785764 655257266 217430459 211108098 623632685 631391825 628008556 962083938 616573502 326152383 7023992 288143889 264733804 886206130 342256543 779010688 657787839 476634612", "output": "571078505096" }, { "input": "20 708413057\n985177466 224645388 772550594 994150052 856456221 65855795 599129505 903908498 200612104 575185982 507918207 574454347 607410366 738301336 274020952 556522307 665003603 363184479 760246523 952436964", "output": "1287105522843" }, { "input": "20 228553575\n966247381 207786628 69006100 269956897 359963312 510868514 95130877 473280024 180071136 34097367 898985854 981155909 369570614 803892852 773207504 603654899 500850166 632114017 442730466 348136258", "output": "151787408488" }, { "input": "25 975185569\n680624205 925575600 711019438 10306 879760994 355425133 204004301 536007340 585477874 216944098 296555029 104013726 892946593 309410720 689188172 687796636 375461496 689356349 680367324 137692780 879054435 925597905 677631315 592123801 742526898", "output": "43630079726" }, { "input": "30 16804972\n38413642 603358594 93465125 772633637 516421484 75369617 249460374 6747 89975200 3230679 944379663 407211965 820471861 763861258 4711346 787274019 447412797 861015104 104795044 430023687 445411345 316560503 908322702 232775431 33149898 101978638 453254685 587956325 920401353 237657930", "output": "34613997" }, { "input": "30 939625169\n799744449 316941501 911543330 868167665 272876554 951480855 826347879 102948940 684991931 833689399 277289558 186462 220073415 602419892 22234767 320279157 908288280 357866038 758158565 784960311 772460297 956631291 623631325 328145434 76400621 637950037 63094834 358429163 210185094 824743978", "output": "766068050" }, { "input": "30 649693919\n523756282 905125099 661420695 854128708 504404014 33547776 632846834 593955985 19432317 644543651 552904895 988070696 321825330 923971248 718082642 900061181 310986828 14810582 525301 623288859 578749693 424452633 901712228 411022879 757920556 825042513 796572495 544557755 747250675 987028137", "output": "1213432868" }, { "input": "30 941342434\n719914212 905507045 191898825 570606628 687781371 937025497 673960221 557202851 29071681 518803370 894863536 212709126 614432746 924724833 699415275 748075226 796159664 198063404 56538360 649136911 46540367 337023198 45896775 548611961 777908744 873523820 99863819 335685200 503317538 894159729", "output": "1443990241" }, { "input": "30 810430346\n807519316 377786333 874568334 100500951 872031247 252690899 923103133 769288634 300502982 184749135 481527896 932556233 978317077 980235169 677287 308980653 527243473 763242606 219639015 712288933 901059456 30978091 127839849 9946626 456644060 226102694 611552752 816642473 434613587 723611518", "output": "964822722" }, { "input": "30 187125289\n660214771 614231774 943973836 50780694 214277957 695192266 425421684 100830325 236002350 233594142 318777769 611117973 758216803 141783036 487402819 42225289 132824573 354540681 64152506 838447015 853800951 605421421 151364012 455396619 928950961 236389207 47829341 743089941 577129072 792900471", "output": "143488023" }, { "input": "30 129428748\n954910836 756938357 407311375 992660029 134837594 230127140 815239978 545145316 559077075 373018190 923169774 981420723 349998683 971610245 428903049 879106876 229199860 842029694 817413103 141736569 236414627 263122579 394309719 946134085 550877425 544748100 732982715 933907937 67960170 145090225", "output": "67960170" }, { "input": "30 12544876\n528459681 350718911 432940853 266976578 679316371 959899124 158423966 471112176 136348553 752311334 979696813 624253517 374825117 338804760 506350966 717644199 528671610 10427712 256677344 288800318 711338213 778230088 616184102 968447942 275963441 257842321 753599064 812398057 815035849 207576747", "output": "207576747" }, { "input": "30 7\n476599619 58464676 796410905 224866489 780155470 404375041 576176595 767831428 598766545 225605178 819316136 781962412 217423411 484904923 194288977 597593185 181464481 65918422 225080972 53705844 584415879 463767806 845989273 434760924 477902363 145682570 721445310 803966515 927906514 191883417", "output": "53705844" }, { "input": "30 9324\n205304890 806562207 36203756 437374231 230840114 828741258 227108614 937997270 74150322 673068857 353683258 757136864 274921753 418595773 638411312 307919005 304470011 439118457 402187013 371389195 981316766 26764964 293610954 177952828 49223547 718589642 982551043 395151318 564895171 138874187", "output": "26764964" }, { "input": "30 512443535\n2 10 30 20 26 9 2 4 24 25 4 27 27 9 13 30 30 5 3 24 10 4 14 14 8 3 2 22 25 25", "output": "16" }, { "input": "30 553648256\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "553648259" }, { "input": "30 536870912\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "536870913" }, { "input": "30 504365056\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "504365061" }, { "input": "30 536870913\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "536870915" }, { "input": "30 536870911\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "536870913" }, { "input": "30 571580555\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "output": "571580565" }, { "input": "1 1000000000\n1", "output": "1000000000" }, { "input": "4 8\n8 4 4 1", "output": "1" }, { "input": "2 3\n10 1", "output": "2" }, { "input": "30 915378355\n459233266 779915330 685344552 78480977 949046834 774589421 94223415 727865843 464996500 268056254 591348850 753027575 142328565 174597246 47001711 810641112 130836837 251339580 624876035 850690451 290550467 119641933 998066976 791349365 549089363 492937533 140746908 265213422 27963549 109184295", "output": "111854196" }, { "input": "3 7\n20 20 30", "output": "60" }, { "input": "1 1000000000\n1000000000", "output": "1000000000000000000" }, { "input": "5 787787787\n1 2 3 4 5", "output": "246183685" }, { "input": "2 3\n10 5", "output": "10" }, { "input": "28 146201893\n79880639 962577454 837935105 770531287 992949199 401766756 805281924 931353274 246173135 378375823 456356972 120503545 811958850 126793843 720341477 413885800 272086545 758855930 979214555 491838924 465216943 706180852 786946242 646685999 436847726 625436 360241773 620056496", "output": "3127180" }, { "input": "5 9\n2 100 100 10 13", "output": "12" }, { "input": "1 134217728\n1000000000", "output": "134217728000000000" }, { "input": "1 536870912\n1000000000", "output": "536870912000000000" }, { "input": "5 5\n34 22 21 20 30", "output": "20" }, { "input": "1 787787787\n1", "output": "787787787" }, { "input": "7 7\n34 22 21 20 30 20 20", "output": "20" }, { "input": "5 5\n34 22 21 25 30", "output": "25" }, { "input": "5 787787787\n123456789 234567890 345678901 456789012 1", "output": "49236737" }, { "input": "6 6\n34 22 21 25 30 35", "output": "25" } ]
1,665,918,956
2,147,483,647
Python 3
OK
TESTS
86
46
0
n, l = map(int, input().split()) a = list(map(int, input().split())) for i in range(0, n-1): a[i+1] = min(a[i+1], 2*a[i]) s = 0 ans = 100**100 for i in range(n-1, -1, -1): d = l // (1<<i) s += d * a[i] l -= d<<i; ans = min(ans, s+(l>0)*a[i]) print(ans)
Title: Party Lemonade Time Limit: None seconds Memory Limit: None megabytes Problem Description: A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of *n* different volumes at different costs. A single bottle of type *i* has volume 2*i*<=-<=1 liters and costs *c**i* roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least *L* liters of lemonade. How many roubles do you have to spend? Input Specification: The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=30; 1<=≤<=*L*<=≤<=109) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=109) — the costs of bottles of different types. Output Specification: Output a single integer — the smallest number of roubles you have to pay in order to buy at least *L* liters of lemonade. Demo Input: ['4 12\n20 30 70 90\n', '4 3\n10000 1000 100 10\n', '4 3\n10 100 1000 10000\n', '5 787787787\n123456789 234567890 345678901 456789012 987654321\n'] Demo Output: ['150\n', '10\n', '30\n', '44981600785557577\n'] Note: In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
```python n, l = map(int, input().split()) a = list(map(int, input().split())) for i in range(0, n-1): a[i+1] = min(a[i+1], 2*a[i]) s = 0 ans = 100**100 for i in range(n-1, -1, -1): d = l // (1<<i) s += d * a[i] l -= d<<i; ans = min(ans, s+(l>0)*a[i]) print(ans) ```
3
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10", "output": "0" }, { "input": "8 20", "output": "0" }, { "input": "2 8", "output": "0" }, { "input": "20 11", "output": "0" }, { "input": "57 447", "output": "1" }, { "input": "1 1", "output": "2" }, { "input": "66 296", "output": "1" }, { "input": "75 683", "output": "1" }, { "input": "227 975", "output": "1" }, { "input": "247 499", "output": "1" }, { "input": "266 116", "output": "1" }, { "input": "286 916", "output": "1" }, { "input": "307 341", "output": "1" }, { "input": "451 121", "output": "1" }, { "input": "471 921", "output": "1" }, { "input": "502 346", "output": "1" }, { "input": "535 59", "output": "1" }, { "input": "555 699", "output": "1" }, { "input": "747 351", "output": "1" }, { "input": "790 64", "output": "1" }, { "input": "810 704", "output": "1" }, { "input": "855 225", "output": "1" }, { "input": "902 34", "output": "1" }, { "input": "922 514", "output": "1" }, { "input": "971 131", "output": "1" }, { "input": "991 931", "output": "1" }, { "input": "840 780", "output": "0" }, { "input": "102 595", "output": "0" }, { "input": "139 433", "output": "0" }, { "input": "968 288", "output": "0" }, { "input": "563 354", "output": "0" }, { "input": "994 975", "output": "0" }, { "input": "456 221", "output": "0" }, { "input": "205 210", "output": "0" }, { "input": "1 11", "output": "0" }, { "input": "1000 1000", "output": "0" }, { "input": "3 3", "output": "0" }, { "input": "11 99", "output": "0" }, { "input": "2 2", "output": "1" }, { "input": "11 1", "output": "0" }, { "input": "6 6", "output": "1" }, { "input": "100 452", "output": "0" }, { "input": "420 380", "output": "0" }, { "input": "31 31", "output": "0" }, { "input": "2 6", "output": "0" }, { "input": "112 134", "output": "0" }, { "input": "13 13", "output": "0" }, { "input": "1 571", "output": "0" } ]
1,676,222,735
2,147,483,647
PyPy 3-64
OK
TESTS
54
124
1,945,600
k=input().split(" ") n,m = int(k[0]), int(k[1]) count = 0 for a in range(n + 1): for b in range(m + 1): if a**2 + b == n and b**2 + a == m: count += 1 print(count)
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. Input Specification: A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. Output Specification: On a single line print the answer to the problem. Demo Input: ['9 3\n', '14 28\n', '4 20\n'] Demo Output: ['1\n', '1\n', '0\n'] Note: In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
```python k=input().split(" ") n,m = int(k[0]), int(k[1]) count = 0 for a in range(n + 1): for b in range(m + 1): if a**2 + b == n and b**2 + a == m: count += 1 print(count) ```
3
51
A
Cheaterius's Problem
PROGRAMMING
1,300
[ "implementation" ]
A. Cheaterius's Problem
2
256
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throughout long nights Cheaterius glues together domino pairs with super glue to get squares 2<=×<=2 which are the Cheaterius' magic amulets! After a hard night Cheaterius made *n* amulets. Everyone of them represents a square 2<=×<=2, every quarter contains 1 to 6 dots. Now he wants sort them into piles, every pile must contain similar amulets. Two amulets are called similar if they can be rotated by 90, 180 or 270 degrees so that the following condition is met: the numbers of dots in the corresponding quarters should be the same. It is forbidden to turn over the amulets. Write a program that by the given amulets will find the number of piles on Cheaterius' desk.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000), where *n* is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
[ "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13\n", "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53\n" ]
[ "1\n", "2\n" ]
none
500
[ { "input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1" }, { "input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2" }, { "input": "4\n56\n61\n**\n31\n31\n**\n33\n11\n**\n11\n33", "output": "2" }, { "input": "4\n36\n44\n**\n32\n46\n**\n66\n41\n**\n64\n34", "output": "3" }, { "input": "3\n63\n63\n**\n66\n33\n**\n36\n36", "output": "1" }, { "input": "3\n11\n54\n**\n42\n63\n**\n42\n63", "output": "2" }, { "input": "3\n14\n54\n**\n45\n41\n**\n12\n22", "output": "2" }, { "input": "7\n21\n33\n**\n33\n12\n**\n32\n31\n**\n21\n33\n**\n33\n12\n**\n32\n31\n**\n13\n23", "output": "1" } ]
1,670,938,318
2,147,483,647
Python 3
OK
TESTS
20
92
0
n = int(input()) piles = [] for i in range(n-1): line1 = input() line2 = input() seperator = input() line1 = [int(x) for x in str(line1)] line2 = [int(x) for x in str(line2)] line1.append(line2[1]) line1.append(line2[0]) amulet = line1 amulet90 = amulet.copy() amulet90.insert(0, amulet[-1]) amulet90.pop() amulet180 = amulet90.copy() amulet180.insert(0, amulet90[-1]) amulet180.pop() amulet270 = amulet180.copy() amulet270.insert(0, amulet180[-1]) amulet270.pop() if amulet in piles: pass elif amulet90 in piles: pass elif amulet180 in piles: pass elif amulet270 in piles: pass else: piles.append(amulet) line1 = input() line2 = input() line1 = [int(x) for x in str(line1)] line2 = [int(x) for x in str(line2)] line1.append(line2[1]) line1.append(line2[0]) amulet = line1 amulet90 = amulet.copy() amulet90.insert(0, amulet[-1]) amulet90.pop() amulet180 = amulet90.copy() amulet180.insert(0, amulet90[-1]) amulet180.pop() amulet270 = amulet180.copy() amulet270.insert(0, amulet180[-1]) amulet270.pop() if amulet in piles: pass elif amulet90 in piles: pass elif amulet180 in piles: pass elif amulet270 in piles: pass else: piles.append(amulet) print(len(piles))
Title: Cheaterius's Problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throughout long nights Cheaterius glues together domino pairs with super glue to get squares 2<=×<=2 which are the Cheaterius' magic amulets! After a hard night Cheaterius made *n* amulets. Everyone of them represents a square 2<=×<=2, every quarter contains 1 to 6 dots. Now he wants sort them into piles, every pile must contain similar amulets. Two amulets are called similar if they can be rotated by 90, 180 or 270 degrees so that the following condition is met: the numbers of dots in the corresponding quarters should be the same. It is forbidden to turn over the amulets. Write a program that by the given amulets will find the number of piles on Cheaterius' desk. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000), where *n* is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located. Output Specification: Print the required number of piles. Demo Input: ['4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13\n', '4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53\n'] Demo Output: ['1\n', '2\n'] Note: none
```python n = int(input()) piles = [] for i in range(n-1): line1 = input() line2 = input() seperator = input() line1 = [int(x) for x in str(line1)] line2 = [int(x) for x in str(line2)] line1.append(line2[1]) line1.append(line2[0]) amulet = line1 amulet90 = amulet.copy() amulet90.insert(0, amulet[-1]) amulet90.pop() amulet180 = amulet90.copy() amulet180.insert(0, amulet90[-1]) amulet180.pop() amulet270 = amulet180.copy() amulet270.insert(0, amulet180[-1]) amulet270.pop() if amulet in piles: pass elif amulet90 in piles: pass elif amulet180 in piles: pass elif amulet270 in piles: pass else: piles.append(amulet) line1 = input() line2 = input() line1 = [int(x) for x in str(line1)] line2 = [int(x) for x in str(line2)] line1.append(line2[1]) line1.append(line2[0]) amulet = line1 amulet90 = amulet.copy() amulet90.insert(0, amulet[-1]) amulet90.pop() amulet180 = amulet90.copy() amulet180.insert(0, amulet90[-1]) amulet180.pop() amulet270 = amulet180.copy() amulet270.insert(0, amulet180[-1]) amulet270.pop() if amulet in piles: pass elif amulet90 in piles: pass elif amulet180 in piles: pass elif amulet270 in piles: pass else: piles.append(amulet) print(len(piles)) ```
3.977
435
B
Pasha Maximizes
PROGRAMMING
1,400
[ "greedy" ]
null
null
Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most *k* swaps.
The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100).
Print the maximum number that Pasha can get if he makes at most *k* swaps.
[ "1990 1\n", "300 0\n", "1034 2\n", "9090000078001234 6\n" ]
[ "9190\n", "300\n", "3104\n", "9907000008001234\n" ]
none
1,000
[ { "input": "1990 1", "output": "9190" }, { "input": "300 0", "output": "300" }, { "input": "1034 2", "output": "3104" }, { "input": "9090000078001234 6", "output": "9907000008001234" }, { "input": "1234 3", "output": "4123" }, { "input": "5 100", "output": "5" }, { "input": "1234 5", "output": "4312" }, { "input": "1234 6", "output": "4321" }, { "input": "9022 2", "output": "9220" }, { "input": "66838 4", "output": "86863" }, { "input": "39940894417248510 10", "output": "99984304417248510" }, { "input": "5314 4", "output": "5431" }, { "input": "1026 9", "output": "6210" }, { "input": "4529 8", "output": "9542" }, { "input": "83811284 3", "output": "88321184" }, { "input": "92153348 6", "output": "98215334" }, { "input": "5846059 3", "output": "8654059" }, { "input": "521325125110071928 4", "output": "552132125110071928" }, { "input": "39940894417248510 10", "output": "99984304417248510" }, { "input": "77172428736634377 29", "output": "87777764122363437" }, { "input": "337775999910796051 37", "output": "999997733751076051" }, { "input": "116995340392134308 27", "output": "999654331120134308" }, { "input": "10120921290110921 20", "output": "99221010120110921" }, { "input": "929201010190831892 30", "output": "999928201010103182" }, { "input": "111111111111111119 8", "output": "111111111911111111" }, { "input": "219810011901120912 100", "output": "999822211111110000" }, { "input": "191919191919119911 100", "output": "999999991111111111" }, { "input": "801211288881101019 22", "output": "982111028888110101" }, { "input": "619911311932347059 3", "output": "969111311932347059" }, { "input": "620737553540689123 2", "output": "672037553540689123" }, { "input": "621563797296514835 3", "output": "662153797296514835" }, { "input": "915277434701161 9", "output": "977541234701161" }, { "input": "15603712376708 28", "output": "87761503123670" }, { "input": "784069392990841 0", "output": "784069392990841" }, { "input": "787464780004 2", "output": "877644780004" }, { "input": "74604713975 29", "output": "97776544310" }, { "input": "901000000954321789 5", "output": "910009000054321789" }, { "input": "901000000954321789 10", "output": "991000000504321789" }, { "input": "901000000954321789 28", "output": "999100050000432178" }, { "input": "901000000954321789 40", "output": "999810000050043217" }, { "input": "901000000954321789 70", "output": "999875410000300021" }, { "input": "1234567891234567 99", "output": "9877665544332211" }, { "input": "123456789123456789 100", "output": "998877665544213123" }, { "input": "12345670123456789 100", "output": "98776655443322101" }, { "input": "12 100", "output": "21" }, { "input": "11223344556677889 47", "output": "98821213344556677" } ]
1,536,137,173
2,147,483,647
Python 3
OK
TESTS
46
124
0
a, k = [i for i in input().split()] k = int(k) a = list(a) a = [int(i) for i in a] + [-1] count = 1 while k > 0 and count < len(a): _max = max(a[count:min(len(a), k + count)]) ind = a[count:min(len(a), k + count)].index(_max) + count if _max > a[count - 1]: k = k - ind + count - 1 a.pop(ind) a.insert(count - 1, _max) count +=1 print(*a[:-1], sep='')
Title: Pasha Maximizes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most *k* swaps. Input Specification: The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100). Output Specification: Print the maximum number that Pasha can get if he makes at most *k* swaps. Demo Input: ['1990 1\n', '300 0\n', '1034 2\n', '9090000078001234 6\n'] Demo Output: ['9190\n', '300\n', '3104\n', '9907000008001234\n'] Note: none
```python a, k = [i for i in input().split()] k = int(k) a = list(a) a = [int(i) for i in a] + [-1] count = 1 while k > 0 and count < len(a): _max = max(a[count:min(len(a), k + count)]) ind = a[count:min(len(a), k + count)].index(_max) + count if _max > a[count - 1]: k = k - ind + count - 1 a.pop(ind) a.insert(count - 1, _max) count +=1 print(*a[:-1], sep='') ```
3
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,694,736
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
154
0
n = int(input()) r = n % 4 if r is 0: print ('YES') else: print('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()) r = n % 4 if r is 0: print ('YES') else: print('NO') ```
0
979
A
Pizza, Pizza, Pizza!!!
PROGRAMMING
1,000
[ "math" ]
null
null
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro. She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over. Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator. As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
A single integer — the number of straight cuts Shiro needs.
[ "3\n", "4\n" ]
[ "2", "5" ]
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
500
[ { "input": "3", "output": "2" }, { "input": "4", "output": "5" }, { "input": "10", "output": "11" }, { "input": "10000000000", "output": "10000000001" }, { "input": "1234567891", "output": "617283946" }, { "input": "7509213957", "output": "3754606979" }, { "input": "99999999999999999", "output": "50000000000000000" }, { "input": "21", "output": "11" }, { "input": "712394453192", "output": "712394453193" }, { "input": "172212168", "output": "172212169" }, { "input": "822981260158260519", "output": "411490630079130260" }, { "input": "28316250877914571", "output": "14158125438957286" }, { "input": "779547116602436424", "output": "779547116602436425" }, { "input": "578223540024979436", "output": "578223540024979437" }, { "input": "335408917861648766", "output": "335408917861648767" }, { "input": "74859962623690078", "output": "74859962623690079" }, { "input": "252509054433933439", "output": "126254527216966720" }, { "input": "760713016476190622", "output": "760713016476190623" }, { "input": "919845426262703496", "output": "919845426262703497" }, { "input": "585335723211047194", "output": "585335723211047195" }, { "input": "522842184971407769", "output": "261421092485703885" }, { "input": "148049062628894320", "output": "148049062628894321" }, { "input": "84324828731963974", "output": "84324828731963975" }, { "input": "354979173822804781", "output": "177489586911402391" }, { "input": "1312150450968413", "output": "656075225484207" }, { "input": "269587449430302150", "output": "269587449430302151" }, { "input": "645762258982631926", "output": "645762258982631927" }, { "input": "615812229161735895", "output": "307906114580867948" }, { "input": "0", "output": "0" }, { "input": "349993004923078531", "output": "174996502461539266" }, { "input": "891351282707723851", "output": "445675641353861926" }, { "input": "563324731189330734", "output": "563324731189330735" }, { "input": "520974001910286909", "output": "260487000955143455" }, { "input": "666729339802329204", "output": "666729339802329205" }, { "input": "856674611404539671", "output": "428337305702269836" }, { "input": "791809296303238499", "output": "395904648151619250" }, { "input": "711066337317063338", "output": "711066337317063339" }, { "input": "931356503492686566", "output": "931356503492686567" }, { "input": "234122432773361866", "output": "234122432773361867" }, { "input": "1000000000000000000", "output": "1000000000000000001" }, { "input": "1", "output": "1" }, { "input": "2", "output": "3" }, { "input": "7", "output": "4" }, { "input": "63", "output": "32" }, { "input": "24", "output": "25" }, { "input": "8", "output": "9" }, { "input": "15", "output": "8" } ]
1,527,376,374
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
78
0
n = float(input()) n+=1 if n == 1: print("0") elif n %2 != 0: print('%.0f' % (n)) else: print('%.0f' % (n/2))
Title: Pizza, Pizza, Pizza!!! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro. She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over. Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator. As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem? Input Specification: A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. Output Specification: A single integer — the number of straight cuts Shiro needs. Demo Input: ['3\n', '4\n'] Demo Output: ['2', '5'] Note: To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
```python n = float(input()) n+=1 if n == 1: print("0") elif n %2 != 0: print('%.0f' % (n)) else: print('%.0f' % (n/2)) ```
0
714
B
Filya and Homework
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal. Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array.
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
[ "5\n1 3 3 2 1\n", "5\n1 2 3 4 5\n" ]
[ "YES\n", "NO\n" ]
In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
1,000
[ { "input": "5\n1 3 3 2 1", "output": "YES" }, { "input": "5\n1 2 3 4 5", "output": "NO" }, { "input": "2\n1 2", "output": "YES" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "3\n1 1 1", "output": "YES" }, { "input": "2\n1 1000000000", "output": "YES" }, { "input": "4\n1 2 3 4", "output": "NO" }, { "input": "10\n1 1 1 1 1 2 2 2 2 2", "output": "YES" }, { "input": "2\n4 2", "output": "YES" }, { "input": "4\n1 1 4 7", "output": "YES" }, { "input": "3\n99999999 1 50000000", "output": "YES" }, { "input": "1\n0", "output": "YES" }, { "input": "5\n0 0 0 0 0", "output": "YES" }, { "input": "4\n4 2 2 1", "output": "NO" }, { "input": "3\n1 4 2", "output": "NO" }, { "input": "3\n1 4 100", "output": "NO" }, { "input": "3\n2 5 11", "output": "NO" }, { "input": "3\n1 4 6", "output": "NO" }, { "input": "3\n1 2 4", "output": "NO" }, { "input": "3\n1 2 7", "output": "NO" }, { "input": "5\n1 1 1 4 5", "output": "NO" }, { "input": "2\n100000001 100000003", "output": "YES" }, { "input": "3\n7 4 5", "output": "NO" }, { "input": "3\n2 3 5", "output": "NO" }, { "input": "3\n1 2 5", "output": "NO" }, { "input": "2\n2 3", "output": "YES" }, { "input": "3\n2 100 29", "output": "NO" }, { "input": "3\n0 1 5", "output": "NO" }, { "input": "3\n1 3 6", "output": "NO" }, { "input": "3\n2 1 3", "output": "YES" }, { "input": "3\n1 5 100", "output": "NO" }, { "input": "3\n1 4 8", "output": "NO" }, { "input": "3\n1 7 10", "output": "NO" }, { "input": "3\n5 4 1", "output": "NO" }, { "input": "3\n1 6 10", "output": "NO" }, { "input": "4\n1 3 4 5", "output": "NO" }, { "input": "3\n1 5 4", "output": "NO" }, { "input": "5\n1 2 3 3 5", "output": "NO" }, { "input": "3\n2 3 1", "output": "YES" }, { "input": "3\n2 3 8", "output": "NO" }, { "input": "3\n0 3 5", "output": "NO" }, { "input": "3\n1 5 10", "output": "NO" }, { "input": "3\n1 7 2", "output": "NO" }, { "input": "3\n1 3 9", "output": "NO" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "7\n1 1 1 1 1 2 4", "output": "NO" }, { "input": "5\n1 4 4 4 6", "output": "NO" }, { "input": "5\n1 2 2 4 4", "output": "NO" }, { "input": "3\n1 9 10", "output": "NO" }, { "input": "8\n1 1 1 1 1 1 2 3", "output": "YES" }, { "input": "3\n1 2 100", "output": "NO" }, { "input": "3\n1 3 4", "output": "NO" }, { "input": "3\n1 15 14", "output": "NO" }, { "input": "3\n1 3 8", "output": "NO" }, { "input": "3\n1 2 10", "output": "NO" }, { "input": "4\n2 2 4 5", "output": "NO" }, { "input": "3\n1 3 5", "output": "YES" }, { "input": "5\n3 6 7 8 9", "output": "NO" }, { "input": "3\n7 6 8", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "5\n1 2 2 2 3", "output": "YES" }, { "input": "3\n4 6 7", "output": "NO" }, { "input": "3\n2 0 4", "output": "YES" }, { "input": "4\n10 20 21 30", "output": "NO" }, { "input": "4\n0 2 3 4", "output": "NO" }, { "input": "3\n3 6 12", "output": "NO" }, { "input": "5\n0 0 1 3 5", "output": "NO" }, { "input": "3\n3 5 8", "output": "NO" }, { "input": "3\n1 4 4", "output": "YES" }, { "input": "4\n2 4 5 6", "output": "NO" } ]
1,564,723,506
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
139
9,216,000
n=int(input()) a=list(map(int,input().split())) x=list(set(a)) if (len(x)==3 and x[1]-x[0]==x[2]-x[1]) or len(x)<3: print('YES') else: print('NO')
Title: Filya and Homework Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal. Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. Output Specification: If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). Demo Input: ['5\n1 3 3 2 1\n', '5\n1 2 3 4 5\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
```python n=int(input()) a=list(map(int,input().split())) x=list(set(a)) if (len(x)==3 and x[1]-x[0]==x[2]-x[1]) or len(x)<3: print('YES') else: print('NO') ```
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,690,657,122
2,147,483,647
Python 3
OK
TESTS
81
92
0
n = int(input()) arr = [0,0,0] for _ in range(n): arr1 = list(map(int,input().split())) for i in range(3): arr[i] += arr1[i] print("YES" if arr == [0,0,0] else "NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n = int(input()) arr = [0,0,0] for _ in range(n): arr1 = list(map(int,input().split())) for i in range(3): arr[i] += arr1[i] print("YES" if arr == [0,0,0] else "NO") ```
3.977
633
A
Ebony and Ivory
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible.
The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
[ "4 6 15\n", "3 2 7\n", "6 11 6\n" ]
[ "No\n", "Yes\n", "Yes\n" ]
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
250
[ { "input": "4 6 15", "output": "No" }, { "input": "3 2 7", "output": "Yes" }, { "input": "6 11 6", "output": "Yes" }, { "input": "3 12 15", "output": "Yes" }, { "input": "5 5 10", "output": "Yes" }, { "input": "6 6 7", "output": "No" }, { "input": "1 1 20", "output": "Yes" }, { "input": "12 14 19", "output": "No" }, { "input": "15 12 26", "output": "No" }, { "input": "2 4 8", "output": "Yes" }, { "input": "4 5 30", "output": "Yes" }, { "input": "4 5 48", "output": "Yes" }, { "input": "2 17 105", "output": "Yes" }, { "input": "10 25 282", "output": "No" }, { "input": "6 34 323", "output": "No" }, { "input": "2 47 464", "output": "Yes" }, { "input": "4 53 113", "output": "Yes" }, { "input": "6 64 546", "output": "Yes" }, { "input": "1 78 725", "output": "Yes" }, { "input": "1 84 811", "output": "Yes" }, { "input": "3 100 441", "output": "Yes" }, { "input": "20 5 57", "output": "No" }, { "input": "14 19 143", "output": "No" }, { "input": "17 23 248", "output": "No" }, { "input": "11 34 383", "output": "Yes" }, { "input": "20 47 568", "output": "Yes" }, { "input": "16 58 410", "output": "Yes" }, { "input": "11 70 1199", "output": "Yes" }, { "input": "16 78 712", "output": "Yes" }, { "input": "20 84 562", "output": "No" }, { "input": "19 100 836", "output": "Yes" }, { "input": "23 10 58", "output": "No" }, { "input": "25 17 448", "output": "Yes" }, { "input": "22 24 866", "output": "Yes" }, { "input": "24 35 67", "output": "No" }, { "input": "29 47 264", "output": "Yes" }, { "input": "23 56 45", "output": "No" }, { "input": "25 66 1183", "output": "Yes" }, { "input": "21 71 657", "output": "Yes" }, { "input": "29 81 629", "output": "No" }, { "input": "23 95 2226", "output": "Yes" }, { "input": "32 4 62", "output": "No" }, { "input": "37 15 789", "output": "Yes" }, { "input": "39 24 999", "output": "Yes" }, { "input": "38 32 865", "output": "No" }, { "input": "32 50 205", "output": "No" }, { "input": "31 57 1362", "output": "Yes" }, { "input": "38 68 1870", "output": "Yes" }, { "input": "36 76 549", "output": "No" }, { "input": "35 84 1257", "output": "No" }, { "input": "39 92 2753", "output": "Yes" }, { "input": "44 1 287", "output": "Yes" }, { "input": "42 12 830", "output": "No" }, { "input": "42 27 9", "output": "No" }, { "input": "49 40 1422", "output": "No" }, { "input": "44 42 2005", "output": "No" }, { "input": "50 55 2479", "output": "No" }, { "input": "48 65 917", "output": "No" }, { "input": "45 78 152", "output": "No" }, { "input": "43 90 4096", "output": "Yes" }, { "input": "43 94 4316", "output": "Yes" }, { "input": "60 7 526", "output": "Yes" }, { "input": "53 11 735", "output": "Yes" }, { "input": "52 27 609", "output": "Yes" }, { "input": "57 32 992", "output": "Yes" }, { "input": "52 49 421", "output": "No" }, { "input": "57 52 2634", "output": "Yes" }, { "input": "54 67 3181", "output": "Yes" }, { "input": "52 73 638", "output": "No" }, { "input": "57 84 3470", "output": "No" }, { "input": "52 100 5582", "output": "No" }, { "input": "62 1 501", "output": "Yes" }, { "input": "63 17 858", "output": "Yes" }, { "input": "70 24 1784", "output": "Yes" }, { "input": "65 32 1391", "output": "Yes" }, { "input": "62 50 2775", "output": "No" }, { "input": "62 58 88", "output": "No" }, { "input": "66 68 3112", "output": "Yes" }, { "input": "61 71 1643", "output": "No" }, { "input": "69 81 3880", "output": "No" }, { "input": "63 100 1960", "output": "Yes" }, { "input": "73 6 431", "output": "Yes" }, { "input": "75 19 736", "output": "Yes" }, { "input": "78 25 247", "output": "No" }, { "input": "79 36 2854", "output": "Yes" }, { "input": "80 43 1864", "output": "Yes" }, { "input": "76 55 2196", "output": "Yes" }, { "input": "76 69 4122", "output": "Yes" }, { "input": "76 76 4905", "output": "No" }, { "input": "75 89 3056", "output": "Yes" }, { "input": "73 100 3111", "output": "Yes" }, { "input": "84 9 530", "output": "No" }, { "input": "82 18 633", "output": "No" }, { "input": "85 29 2533", "output": "Yes" }, { "input": "89 38 2879", "output": "Yes" }, { "input": "89 49 2200", "output": "Yes" }, { "input": "88 60 4140", "output": "Yes" }, { "input": "82 68 1299", "output": "No" }, { "input": "90 76 2207", "output": "No" }, { "input": "83 84 4923", "output": "Yes" }, { "input": "89 99 7969", "output": "Yes" }, { "input": "94 9 168", "output": "No" }, { "input": "91 20 1009", "output": "No" }, { "input": "93 23 2872", "output": "Yes" }, { "input": "97 31 3761", "output": "Yes" }, { "input": "99 46 1341", "output": "Yes" }, { "input": "98 51 2845", "output": "No" }, { "input": "93 66 3412", "output": "No" }, { "input": "95 76 3724", "output": "Yes" }, { "input": "91 87 6237", "output": "Yes" }, { "input": "98 97 7886", "output": "Yes" }, { "input": "12 17 15", "output": "No" }, { "input": "93 94 95", "output": "No" }, { "input": "27 43 27", "output": "Yes" }, { "input": "17 43 68", "output": "Yes" }, { "input": "44 12 12", "output": "Yes" }, { "input": "44 50 150", "output": "Yes" }, { "input": "1 1 10000", "output": "Yes" }, { "input": "2 3 10000", "output": "Yes" }, { "input": "100 1 10", "output": "Yes" }, { "input": "3 2 1", "output": "No" }, { "input": "1 1 1", "output": "Yes" }, { "input": "9 9 10000", "output": "No" }, { "input": "2 3 9995", "output": "Yes" }, { "input": "3 5 4", "output": "No" }, { "input": "99 98 100", "output": "No" }, { "input": "6 10 2", "output": "No" }, { "input": "1 6 5", "output": "Yes" }, { "input": "1 4 3", "output": "Yes" }, { "input": "3 2 3", "output": "Yes" }, { "input": "1 7 6", "output": "Yes" }, { "input": "2 3 9871", "output": "Yes" }, { "input": "10 5 5", "output": "Yes" }, { "input": "10 8 2", "output": "No" } ]
1,658,868,643
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
def find(a, b ,c): for i in range( c // (a + 2)+1): for j in range(c//(b+2)+1): if (i*a + j*b == c): return 'YES' return 'NO' a,b ,c = map(int, input().split()) print(find(a, b , c))
Title: Ebony and Ivory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible. Input Specification: The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. Output Specification: Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. Demo Input: ['4 6 15\n', '3 2 7\n', '6 11 6\n'] Demo Output: ['No\n', 'Yes\n', 'Yes\n'] Note: In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
```python def find(a, b ,c): for i in range( c // (a + 2)+1): for j in range(c//(b+2)+1): if (i*a + j*b == c): return 'YES' return 'NO' a,b ,c = map(int, input().split()) print(find(a, b , c)) ```
-1
708
A
Letters Cyclic Shift
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation", "strings" ]
null
null
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'. What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once?
The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters.
Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring.
[ "codeforces\n", "abacaba\n" ]
[ "bncdenqbdr\n", "aaacaba\n" ]
String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> &lt; *t*<sub class="lower-index">*i*</sub>.
500
[ { "input": "codeforces", "output": "bncdenqbdr" }, { "input": "abacaba", "output": "aaacaba" }, { "input": "babbbabaababbaa", "output": "aabbbabaababbaa" }, { "input": "bcbacaabcababaccccaaaabacbbcbbaa", "output": "abaacaabcababaccccaaaabacbbcbbaa" }, { "input": "cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda", "output": "babaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda" }, { "input": "a", "output": "z" }, { "input": "eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec", "output": "ddddcccbbabdaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec" }, { "input": "fddfbabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe", "output": "ecceaabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaz" }, { "input": "abbabaaaaa", "output": "aaaabaaaaa" }, { "input": "bbbbbbbbbbbb", "output": "aaaaaaaaaaaa" }, { "input": "aabaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaz" }, { "input": "abaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa", "output": "aaaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa" }, { "input": "abbbbbbbabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb", "output": "aaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb" }, { "input": "aaaaa", "output": "aaaaz" }, { "input": "aaa", "output": "aaz" }, { "input": "aa", "output": "az" } ]
1,693,128,693
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
13
46
204,800
s = input() if len(s) == 1: if s == "a": print("z") else: print(chr(ord(s[i])+1)) else: start = False end = False ans = "" for i in range(len(s)): if start: if s[i] == "a": start = False end = True ans += "a" else: ans += chr(ord(s[i])-1) else: if not end: if s[i] != "a": start = True ans += chr(ord(s[i])-1) else: ans += s[i] else: ans += s[i] print(ans)
Title: Letters Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'. What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once? Input Specification: The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters. Output Specification: Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring. Demo Input: ['codeforces\n', 'abacaba\n'] Demo Output: ['bncdenqbdr\n', 'aaacaba\n'] Note: String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> &lt; *t*<sub class="lower-index">*i*</sub>.
```python s = input() if len(s) == 1: if s == "a": print("z") else: print(chr(ord(s[i])+1)) else: start = False end = False ans = "" for i in range(len(s)): if start: if s[i] == "a": start = False end = True ans += "a" else: ans += chr(ord(s[i])-1) else: if not end: if s[i] != "a": start = True ans += chr(ord(s[i])-1) else: ans += s[i] else: ans += s[i] print(ans) ```
0
676
C
Vasya and String
PROGRAMMING
1,500
[ "binary search", "dp", "strings", "two pointers" ]
null
null
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve?
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
[ "4 2\nabba\n", "8 1\naabaabaa\n" ]
[ "4\n", "5\n" ]
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
1,500
[ { "input": "4 2\nabba", "output": "4" }, { "input": "8 1\naabaabaa", "output": "5" }, { "input": "1 0\na", "output": "1" }, { "input": "1 1\nb", "output": "1" }, { "input": "1 0\nb", "output": "1" }, { "input": "1 1\na", "output": "1" }, { "input": "10 10\nbbbbbbbbbb", "output": "10" }, { "input": "10 2\nbbbbbbbbbb", "output": "10" }, { "input": "10 1\nbbabbabbba", "output": "6" }, { "input": "10 10\nbbabbbaabb", "output": "10" }, { "input": "10 9\nbabababbba", "output": "10" }, { "input": "10 4\nbababbaaab", "output": "9" }, { "input": "10 10\naabaaabaaa", "output": "10" }, { "input": "10 10\naaaabbbaaa", "output": "10" }, { "input": "10 1\nbaaaaaaaab", "output": "9" }, { "input": "10 5\naaaaabaaaa", "output": "10" }, { "input": "10 4\naaaaaaaaaa", "output": "10" }, { "input": "100 10\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "100" }, { "input": "100 7\nbbbbabbbbbaabbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbab", "output": "93" }, { "input": "100 30\nbbaabaaabbbbbbbbbbaababababbbbbbaabaabbbbbbbbabbbbbabbbbabbbbbbbbaabbbbbbbbbabbbbbabbbbbbbbbaaaaabba", "output": "100" }, { "input": "100 6\nbaababbbaabbabbaaabbabbaabbbbbbbbaabbbabbbbaabbabbbbbabababbbbabbbbbbabbbbbbbbbaaaabbabbbbaabbabaabb", "output": "34" }, { "input": "100 45\naabababbabbbaaabbbbbbaabbbabbaabbbbbabbbbbbbbabbbbbbabbaababbaabbababbbbbbababbbbbaabbbbbbbaaaababab", "output": "100" }, { "input": "100 2\nababaabababaaababbaaaabbaabbbababbbaaabbbbabababbbabababaababaaabaabbbbaaabbbabbbbbabbbbbbbaabbabbba", "output": "17" }, { "input": "100 25\nbabbbaaababaaabbbaabaabaabbbabbabbbbaaaaaaabaaabaaaaaaaaaabaaaabaaabbbaaabaaababaaabaabbbbaaaaaaaaaa", "output": "80" }, { "input": "100 14\naabaaaaabababbabbabaaaabbaaaabaaabbbaaabaaaaaaaabaaaaabbaaaaaaaaabaaaaaaabbaababaaaababbbbbabaaaabaa", "output": "61" }, { "input": "100 8\naaaaabaaaabaabaaaaaaaabaaaabaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaabaaaababaabaaaaaaaaaaaaabbabaaaaaa", "output": "76" }, { "input": "100 12\naaaaaaaaaaaaaaaabaaabaaaaaaaaaabbaaaabbabaaaaaaaaaaaaaaaaaaaaabbaaabaaaaaaaaaaaabaaaaaaaabaaaaaaaaaa", "output": "100" }, { "input": "100 65\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "100" }, { "input": "10 0\nbbbbbbbbbb", "output": "10" }, { "input": "10 0\nbbbbabbbbb", "output": "5" }, { "input": "10 0\nbbabbbabba", "output": "3" }, { "input": "10 0\nbaabbbbaba", "output": "4" }, { "input": "10 0\naababbbbaa", "output": "4" }, { "input": "10 2\nabbbbbaaba", "output": "8" }, { "input": "10 0\nabbaaabaaa", "output": "3" }, { "input": "10 0\naabbaaabaa", "output": "3" }, { "input": "10 1\naaaaaababa", "output": "8" }, { "input": "10 0\nbaaaaaaaaa", "output": "9" }, { "input": "10 0\naaaaaaaaaa", "output": "10" }, { "input": "100 0\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "100" }, { "input": "100 0\nbbbbbbbbbbabbbbaaabbbbbbbbbbbabbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbabbbbbbbbbbbbbab", "output": "40" }, { "input": "100 11\nbaabbbbbababbbbabbbbbbbabbbbbbbbbbbbbbabbbbbbababbbbababbbbaaabbbbabbbbbabbbbbbbbabababbbabbbbbbbabb", "output": "65" }, { "input": "100 8\nbbababbbbbaabbbaaababbbbababababbbbababbabbbabbbbbaabbbabbbababbabbbbabbbabbbbaabbbbabbbaabbbbaaaabb", "output": "33" }, { "input": "100 21\nabbaaaabbbababaabbbababbbbbbbbabbaababababbbabbbaaabbaaabbbbabbabbbabbbabaababbbabbbbbabbbbbbabbbbab", "output": "65" }, { "input": "100 9\nabbbaabaabaaaaaaabbabbbababbaaabbbaaabbaabaaaaabbbbbabbaabaabbbbbaaaaababbaaabbabaabaaabababbaababbb", "output": "26" }, { "input": "100 5\naababababbaaaaaaaabbbabaaaabbabaaaabbaabaaaaabababbabaabaaabaaaaaaaabaababbabbaaabaabbabbaaaaabbabba", "output": "22" }, { "input": "100 9\naababaabaaaaaaaaabbbaabaaaaaaabaaaaaaaaaaaaabaaabaabaabbbbabbaababbabbaaaabbababaabaababaabaaaaaaaaa", "output": "49" }, { "input": "100 6\naaaaabbaaaaaaaaaaabaaaabaaaaaaaaabaaabaaaaaabaaaaaaaaaaabaabaaaabaaaaaaaaaaaaaaabaabbaaaaaaaaaaaaaaa", "output": "56" }, { "input": "100 7\nabaaabaabaabaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabbabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaba", "output": "86" }, { "input": "100 0\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "100" } ]
1,612,644,346
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
61
204,800
def I3(): n, k = [int(x) for x in input().split()] s = input() a='a' b='b' maxBeauty = 0 a_max = countLetters(s, a) b_max = countLetters(s, b) if a_max >= b_max: for i in range(s.count(b)): sample = s.replace(b, a, k) maxb = countLetters(sample, a) if maxb > maxBeauty: maxBeauty = maxb s = s.replace(b, 'c', 1) else: for i in range(s.count(a)): sample = s.replace(a, b, k) maxb = countLetters(sample, b) if maxb > maxBeauty: maxBeauty = maxb s = s.replace(a, 'c', 1) print(maxBeauty) if __name__ == '__main__': I3()
Title: Vasya and String Time Limit: None seconds Memory Limit: None megabytes Problem Description: High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve? Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. Output Specification: Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. Demo Input: ['4 2\nabba\n', '8 1\naabaabaa\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
```python def I3(): n, k = [int(x) for x in input().split()] s = input() a='a' b='b' maxBeauty = 0 a_max = countLetters(s, a) b_max = countLetters(s, b) if a_max >= b_max: for i in range(s.count(b)): sample = s.replace(b, a, k) maxb = countLetters(sample, a) if maxb > maxBeauty: maxBeauty = maxb s = s.replace(b, 'c', 1) else: for i in range(s.count(a)): sample = s.replace(a, b, k) maxb = countLetters(sample, b) if maxb > maxBeauty: maxBeauty = maxb s = s.replace(a, 'c', 1) print(maxBeauty) if __name__ == '__main__': I3() ```
-1
31
A
Worms Evolution
PROGRAMMING
1,200
[ "implementation" ]
A. Worms Evolution
2
256
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form.
Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*.
[ "5\n1 2 3 5 7\n", "5\n1 8 1 5 1\n" ]
[ "3 2 1\n", "-1\n" ]
none
500
[ { "input": "5\n1 2 3 5 7", "output": "3 2 1" }, { "input": "5\n1 8 1 5 1", "output": "-1" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "6\n86 402 133 524 405 610", "output": "6 4 1" }, { "input": "8\n217 779 418 895 996 473 3 22", "output": "5 2 1" }, { "input": "10\n858 972 670 15 662 114 33 273 53 310", "output": "2 6 1" }, { "input": "100\n611 697 572 770 603 870 128 245 49 904 468 982 788 943 549 288 668 796 803 515 999 735 912 49 298 80 412 841 494 434 543 298 17 571 271 105 70 313 178 755 194 279 585 766 412 164 907 841 776 556 731 268 735 880 176 267 287 65 239 588 155 658 821 47 783 595 585 69 226 906 429 161 999 148 7 484 362 585 952 365 92 749 904 525 307 626 883 367 450 755 564 950 728 724 69 106 119 157 96 290", "output": "1 38 25" }, { "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": "1 63 61" }, { "input": "100\n156 822 179 298 981 82 610 345 373 378 895 734 768 15 78 335 764 608 932 297 717 553 916 367 425 447 361 195 66 70 901 236 905 744 919 564 296 610 963 628 840 52 100 750 345 308 37 687 192 704 101 815 10 990 216 358 823 546 578 821 706 148 182 582 421 482 829 425 121 337 500 301 402 868 66 935 625 527 746 585 308 523 488 914 608 709 875 252 151 781 447 2 756 176 976 302 450 35 680 791", "output": "1 98 69" }, { "input": "100\n54 947 785 838 359 647 92 445 48 465 323 486 101 86 607 31 860 420 709 432 435 372 272 37 903 814 309 197 638 58 259 822 793 564 309 22 522 907 101 853 486 824 614 734 630 452 166 532 256 499 470 9 933 452 256 450 7 26 916 406 257 285 895 117 59 369 424 133 16 417 352 440 806 236 478 34 889 469 540 806 172 296 73 655 261 792 868 380 204 454 330 53 136 629 236 850 134 560 264 291", "output": "2 29 27" }, { "input": "99\n175 269 828 129 499 890 127 263 995 807 508 289 996 226 437 320 365 642 757 22 190 8 345 499 834 713 962 889 336 171 608 492 320 257 472 801 176 325 301 306 198 729 933 4 640 322 226 317 567 586 249 237 202 633 287 128 911 654 719 988 420 855 361 574 716 899 317 356 581 440 284 982 541 111 439 29 37 560 961 224 478 906 319 416 736 603 808 87 762 697 392 713 19 459 262 238 239 599 997", "output": "1 44 30" }, { "input": "98\n443 719 559 672 16 69 529 632 953 999 725 431 54 22 346 968 558 696 48 669 963 129 257 712 39 870 498 595 45 821 344 925 179 388 792 346 755 213 423 365 344 659 824 356 773 637 628 897 841 155 243 536 951 361 192 105 418 431 635 596 150 162 145 548 473 531 750 306 377 354 450 975 79 743 656 733 440 940 19 139 237 346 276 227 64 799 479 633 199 17 796 362 517 234 729 62 995 535", "output": "2 70 40" }, { "input": "97\n359 522 938 862 181 600 283 1000 910 191 590 220 761 818 903 264 751 751 987 316 737 898 168 925 244 674 34 950 754 472 81 6 37 520 112 891 981 454 897 424 489 238 363 709 906 951 677 828 114 373 589 835 52 89 97 435 277 560 551 204 879 469 928 523 231 163 183 609 821 915 615 969 616 23 874 437 844 321 78 53 643 786 585 38 744 347 150 179 988 985 200 11 15 9 547 886 752", "output": "1 23 10" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "100\n328 397 235 453 188 254 879 225 423 36 384 296 486 592 231 849 856 255 213 898 234 800 701 529 951 693 507 326 15 905 618 348 967 927 28 979 752 850 343 35 84 302 36 390 482 826 249 918 91 289 973 457 557 348 365 239 709 565 320 560 153 130 647 708 483 469 788 473 322 844 830 562 611 961 397 673 69 960 74 703 369 968 382 451 328 160 211 230 566 208 7 545 293 73 806 375 157 410 303 58", "output": "1 79 6" }, { "input": "33\n52 145 137 734 180 847 178 286 716 134 181 630 358 764 593 762 785 28 1 468 189 540 764 485 165 656 114 58 628 108 605 584 257", "output": "8 30 7" }, { "input": "57\n75 291 309 68 444 654 985 158 514 204 116 918 374 806 176 31 49 455 269 66 722 713 164 818 317 295 546 564 134 641 28 13 987 478 146 219 213 940 289 173 157 666 168 391 392 71 870 477 446 988 414 568 964 684 409 671 454", "output": "2 41 29" }, { "input": "88\n327 644 942 738 84 118 981 686 530 404 137 197 434 16 693 183 423 325 410 345 941 329 7 106 79 867 584 358 533 675 192 718 641 329 900 768 404 301 101 538 954 590 401 954 447 14 559 337 756 586 934 367 538 928 945 936 770 641 488 579 206 869 902 139 216 446 723 150 829 205 373 578 357 368 960 40 121 206 503 385 521 161 501 694 138 370 709 308", "output": "1 77 61" }, { "input": "100\n804 510 266 304 788 625 862 888 408 82 414 470 777 991 729 229 933 406 601 1 596 720 608 706 432 361 527 548 59 548 474 515 4 991 263 568 681 24 117 563 576 587 281 643 904 521 891 106 842 884 943 54 605 815 504 757 311 374 335 192 447 652 633 410 455 402 382 150 432 836 413 819 669 875 638 925 217 805 632 520 605 266 728 795 162 222 603 159 284 790 914 443 775 97 789 606 859 13 851 47", "output": "1 77 42" }, { "input": "100\n449 649 615 713 64 385 927 466 138 126 143 886 80 199 208 43 196 694 92 89 264 180 617 970 191 196 910 150 275 89 693 190 191 99 542 342 45 592 114 56 451 170 64 589 176 102 308 92 402 153 414 675 352 157 69 150 91 288 163 121 816 184 20 234 836 12 593 150 793 439 540 93 99 663 186 125 349 247 476 106 77 523 215 7 363 278 441 745 337 25 148 384 15 915 108 211 240 58 23 408", "output": "1 6 5" }, { "input": "90\n881 436 52 308 97 261 153 931 670 538 702 156 114 445 154 685 452 76 966 790 93 42 547 65 736 364 136 489 719 322 239 628 696 735 55 703 622 375 100 188 804 341 546 474 484 446 729 290 974 301 602 225 996 244 488 983 882 460 962 754 395 617 61 640 534 292 158 375 632 902 420 979 379 38 100 67 963 928 190 456 545 571 45 716 153 68 844 2 102 116", "output": "1 14 2" }, { "input": "80\n313 674 262 240 697 146 391 221 793 504 896 818 92 899 86 370 341 339 306 887 937 570 830 683 729 519 240 833 656 847 427 958 435 704 853 230 758 347 660 575 843 293 649 396 437 787 654 599 35 103 779 783 447 379 444 585 902 713 791 150 851 228 306 721 996 471 617 403 102 168 197 741 877 481 968 545 331 715 236 654", "output": "1 13 8" }, { "input": "70\n745 264 471 171 946 32 277 511 269 469 89 831 69 2 369 407 583 602 646 633 429 747 113 302 722 321 344 824 241 372 263 287 822 24 652 758 246 967 219 313 882 597 752 965 389 775 227 556 95 904 308 340 899 514 400 187 275 318 621 546 659 488 199 154 811 1 725 79 925 82", "output": "1 63 60" }, { "input": "60\n176 502 680 102 546 917 516 801 392 435 635 492 398 456 653 444 472 513 634 378 273 276 44 920 68 124 800 167 825 250 452 264 561 344 98 933 381 939 426 51 568 548 206 887 342 763 151 514 156 354 486 546 998 649 356 438 295 570 450 589", "output": "2 26 20" }, { "input": "50\n608 92 889 33 146 803 402 91 868 400 828 505 375 558 584 129 361 776 974 123 765 804 326 186 61 927 904 511 762 775 640 593 300 664 897 461 869 911 986 789 607 500 309 457 294 104 724 471 216 155", "output": "3 25 11" }, { "input": "40\n40 330 98 612 747 336 640 381 991 366 22 167 352 12 868 166 603 40 313 869 609 981 609 804 54 729 8 854 347 300 828 922 39 633 695 988 4 530 545 176", "output": "5 10 8" }, { "input": "30\n471 920 308 544 347 222 878 671 467 332 215 180 681 114 151 203 492 951 653 614 453 510 540 422 399 532 113 198 932 825", "output": "2 21 9" }, { "input": "20\n551 158 517 475 595 108 764 961 590 297 761 841 659 568 82 888 733 214 993 359", "output": "3 20 2" }, { "input": "10\n983 748 726 406 196 993 2 251 66 263", "output": "-1" }, { "input": "9\n933 266 457 863 768 257 594 136 145", "output": "-1" }, { "input": "8\n537 198 48 771 944 868 700 163", "output": "7 8 1" }, { "input": "7\n140 779 639 679 768 479 158", "output": "2 3 1" }, { "input": "6\n744 359 230 586 944 442", "output": "-1" }, { "input": "5\n700 939 173 494 120", "output": "-1" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "3\n907 452 355", "output": "-1" }, { "input": "3\n963 630 333", "output": "1 3 2" }, { "input": "3\n2 2 4", "output": "3 2 1" }, { "input": "3\n2 4 100", "output": "-1" } ]
1,696,015,455
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
0
0
n = int(input()) worm_lengths = list(map(int, input().split())) # Sort the worm lengths in ascending order worm_lengths.sort() for i in range(n): for j in range(i + 1, n): sum_of_lengths = worm_lengths[i] + worm_lengths[j] if sum_of_lengths in worm_lengths: k = worm_lengths.index(sum_of_lengths) if k != i and k != j: # Found a valid triplet print(i + 1, j + 1, k + 1) exit() # If no valid triplet is found, print -1 print(-1)
Title: Worms Evolution Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. Output Specification: Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. Demo Input: ['5\n1 2 3 5 7\n', '5\n1 8 1 5 1\n'] Demo Output: ['3 2 1\n', '-1\n'] Note: none
```python n = int(input()) worm_lengths = list(map(int, input().split())) # Sort the worm lengths in ascending order worm_lengths.sort() for i in range(n): for j in range(i + 1, n): sum_of_lengths = worm_lengths[i] + worm_lengths[j] if sum_of_lengths in worm_lengths: k = worm_lengths.index(sum_of_lengths) if k != i and k != j: # Found a valid triplet print(i + 1, j + 1, k + 1) exit() # If no valid triplet is found, print -1 print(-1) ```
0
616
A
Comparing Two Long Integers
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As 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. Don't use the function input() in Python2 instead of it use the function raw_input().
The first line contains a non-negative integer *a*. The second line contains a non-negative integer *b*. The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits.
Print the symbol "&lt;" if *a*<=&lt;<=*b* and the symbol "&gt;" if *a*<=&gt;<=*b*. If the numbers are equal print the symbol "=".
[ "9\n10\n", "11\n10\n", "00012345\n12345\n", "0123\n9\n", "0123\n111\n" ]
[ "&lt;\n", "&gt;\n", "=\n", "&gt;\n", "&gt;\n" ]
none
0
[ { "input": "9\n10", "output": "<" }, { "input": "11\n10", "output": ">" }, { "input": "00012345\n12345", "output": "=" }, { "input": "0123\n9", "output": ">" }, { "input": "0123\n111", "output": ">" }, { "input": "9\n9", "output": "=" }, { "input": "0\n0000", "output": "=" }, { "input": "1213121\n1213121", "output": "=" }, { "input": "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479", "output": ">" }, { "input": "6421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798\n8", "output": ">" }, { "input": "9\n3549746075165939381145061479392284958612916596558639332310874529760172204736013341477640605383578772", "output": "<" }, { "input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "0000000001\n2", "output": "<" }, { "input": "1000000000000000000000000000000000\n1000000000000000000000000000000001", "output": "<" }, { "input": "123456123456123456123456123456123456123456123456123456123456123456\n123456123456123456123456123456123456123456123456123456123456123456123456123456", "output": "<" }, { "input": "1111111111111111111111111111111111111111\n2222222222222222222222222222222222222222", "output": "<" }, { "input": "123456789999999\n123456789999999", "output": "=" }, { "input": "111111111111111111111111111111\n222222222222222222222222222222", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "587345873489573457357834\n47957438573458347574375348", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333", "output": "<" }, { "input": "11111111111111111111111111111111111\n44444444444444444444444444444444444", "output": "<" }, { "input": "11111111111111111111111111111111111\n22222222222222222222222222222222222", "output": "<" }, { "input": "9999999999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "<" }, { "input": "1\n2", "output": "<" }, { "input": "9\n0", "output": ">" }, { "input": "222222222222222222222222222222222222222222222222222222222\n22222222222222222222222222222222222222222222222222222222222", "output": "<" }, { "input": "66646464222222222222222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "11111111111111111111111111111111111111\n44444444444444444444444444444444444444", "output": "<" }, { "input": "01\n2", "output": "<" }, { "input": "00\n01", "output": "<" }, { "input": "99999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999", "output": "=" }, { "input": "43278947323248843213443272432\n793439250984509434324323453435435", "output": "<" }, { "input": "0\n1", "output": "<" }, { "input": "010\n011", "output": "<" }, { "input": "999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "0001001\n0001010", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "00000\n00", "output": "=" }, { "input": "999999999999999999999999999\n999999999999999999999999999", "output": "=" }, { "input": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "001\n000000000010", "output": "<" }, { "input": "01\n10", "output": "<" }, { "input": "555555555555555555555555555555555555555555555555555555555555\n555555555555555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "5555555555555555555555555555555555555555555555555\n5555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "01\n02", "output": "<" }, { "input": "001111\n0001111", "output": "=" }, { "input": "55555555555555555555555555555555555555555555555555\n55555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "1029301293019283091283091283091280391283\n1029301293019283091283091283091280391283", "output": "=" }, { "input": "001\n2", "output": "<" }, { "input": "000000000\n000000000", "output": "=" }, { "input": "000000\n10", "output": "<" }, { "input": "000000000000000\n001", "output": "<" }, { "input": "0000001\n2", "output": "<" }, { "input": "0000\n123", "output": "<" }, { "input": "951\n960", "output": "<" }, { "input": "002\n0001", "output": ">" }, { "input": "0000001\n01", "output": "=" }, { "input": "99999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "12345678901234567890123456789012345678901234567890123456789012\n12345678901234567890123456789012345678901234567890123456789012", "output": "=" }, { "input": "02\n01", "output": ">" }, { "input": "00000111111\n00000110111", "output": ">" }, { "input": "0123\n123", "output": "=" }, { "input": "123771237912798378912\n91239712798379812897389123123123123", "output": "<" }, { "input": "00001\n002", "output": "<" }, { "input": "0000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "=" }, { "input": "000000001\n00002", "output": "<" }, { "input": "00002\n00003", "output": "<" }, { "input": "000123456\n123457", "output": "<" }, { "input": "01\n00", "output": ">" }, { "input": "00\n0", "output": "=" }, { "input": "10\n11", "output": "<" }, { "input": "0011\n12", "output": "<" }, { "input": "00\n1", "output": "<" }, { "input": "0\n0", "output": "=" }, { "input": "00\n10", "output": "<" }, { "input": "011\n10", "output": ">" }, { "input": "00011111111111111111111111111111111111000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000011000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112091", "output": "<" }, { "input": "0000001\n00", "output": ">" }, { "input": "01\n1", "output": "=" }, { "input": "010\n001", "output": ">" }, { "input": "100\n111", "output": "<" }, { "input": "1\n0", "output": ">" }, { "input": "000000\n000000000000000000000", "output": "=" }, { "input": "010101\n010101", "output": "=" }, { "input": "00000000000000000001111111111111111111111111111111111111111111111111111111\n11111111111111111111111", "output": ">" }, { "input": "0000000\n0", "output": "=" }, { "input": "187923712738712879387912839182381\n871279397127389781927389718923789178923897123", "output": "<" }, { "input": "0010\n030", "output": "<" } ]
1,635,097,950
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
13
2,000
28,672,000
a = input().lstrip('0') b = input().lstrip('0') if len(a) == 0: a = '0' if len(b) == 0: b = '0' if int(a) > int(b): print('>') elif int(a) < int(b): print('<') else: print('=')
Title: Comparing Two Long Integers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As 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. Don't use the function input() in Python2 instead of it use the function raw_input(). Input Specification: The first line contains a non-negative integer *a*. The second line contains a non-negative integer *b*. The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. Output Specification: Print the symbol "&lt;" if *a*<=&lt;<=*b* and the symbol "&gt;" if *a*<=&gt;<=*b*. If the numbers are equal print the symbol "=". Demo Input: ['9\n10\n', '11\n10\n', '00012345\n12345\n', '0123\n9\n', '0123\n111\n'] Demo Output: ['&lt;\n', '&gt;\n', '=\n', '&gt;\n', '&gt;\n'] Note: none
```python a = input().lstrip('0') b = input().lstrip('0') if len(a) == 0: a = '0' if len(b) == 0: b = '0' if int(a) > int(b): print('>') elif int(a) < int(b): print('<') else: print('=') ```
0
645
B
Mischievous Mess Makers
PROGRAMMING
1,200
[ "greedy", "math" ]
null
null
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=&lt;<=*j* and *p**i*<=&gt;<=*p**j*.
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively.
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps.
[ "5 2\n", "1 10\n" ]
[ "10\n", "0\n" ]
In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible messiness is 0.
1,000
[ { "input": "5 2", "output": "10" }, { "input": "1 10", "output": "0" }, { "input": "100000 2", "output": "399990" }, { "input": "1 1", "output": "0" }, { "input": "8 3", "output": "27" }, { "input": "7 1", "output": "11" }, { "input": "100000 40000", "output": "4799960000" }, { "input": "1 1000", "output": "0" }, { "input": "100 45", "output": "4905" }, { "input": "9 2", "output": "26" }, { "input": "456 78", "output": "58890" }, { "input": "100000 50000", "output": "4999950000" }, { "input": "100000 50001", "output": "4999950000" }, { "input": "100000 50002", "output": "4999950000" }, { "input": "100000 50003", "output": "4999950000" }, { "input": "100000 49998", "output": "4999949994" }, { "input": "100000 49997", "output": "4999949985" }, { "input": "99999 49998", "output": "4999849998" }, { "input": "99999 49997", "output": "4999849991" }, { "input": "99999 49996", "output": "4999849980" }, { "input": "99999 50000", "output": "4999850001" }, { "input": "99999 50001", "output": "4999850001" }, { "input": "99999 50002", "output": "4999850001" }, { "input": "30062 9", "output": "540945" }, { "input": "13486 3", "output": "80895" }, { "input": "29614 7", "output": "414491" }, { "input": "13038 8", "output": "208472" }, { "input": "96462 6", "output": "1157466" }, { "input": "22599 93799", "output": "255346101" }, { "input": "421 36817", "output": "88410" }, { "input": "72859 65869", "output": "2654180511" }, { "input": "37916 5241", "output": "342494109" }, { "input": "47066 12852", "output": "879423804" }, { "input": "84032 21951", "output": "2725458111" }, { "input": "70454 75240", "output": "2481847831" }, { "input": "86946 63967", "output": "3779759985" }, { "input": "71128 11076", "output": "1330260828" }, { "input": "46111 64940", "output": "1063089105" }, { "input": "46111 64940", "output": "1063089105" }, { "input": "56500 84184", "output": "1596096750" }, { "input": "60108 83701", "output": "1806455778" }, { "input": "1 2", "output": "0" }, { "input": "1 3", "output": "0" }, { "input": "1 4", "output": "0" }, { "input": "1 5", "output": "0" }, { "input": "1 6", "output": "0" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "1" }, { "input": "2 4", "output": "1" }, { "input": "2 5", "output": "1" }, { "input": "3 1", "output": "3" }, { "input": "3 2", "output": "3" }, { "input": "3 3", "output": "3" }, { "input": "3 4", "output": "3" }, { "input": "3 5", "output": "3" }, { "input": "4 1", "output": "5" }, { "input": "4 2", "output": "6" }, { "input": "4 3", "output": "6" }, { "input": "4 4", "output": "6" }, { "input": "4 5", "output": "6" }, { "input": "5 1", "output": "7" }, { "input": "5 3", "output": "10" }, { "input": "5 4", "output": "10" }, { "input": "5 5", "output": "10" }, { "input": "6 1", "output": "9" }, { "input": "6 2", "output": "14" }, { "input": "6 3", "output": "15" }, { "input": "7 2", "output": "18" }, { "input": "7 3", "output": "21" }, { "input": "7 4", "output": "21" }, { "input": "10 2", "output": "30" }, { "input": "60982 2", "output": "243918" }, { "input": "23426 23", "output": "1076515" }, { "input": "444 3", "output": "2643" }, { "input": "18187 433", "output": "15374531" }, { "input": "6895 3544", "output": "23767065" }, { "input": "56204 22352", "output": "1513297456" }, { "input": "41977 5207", "output": "382917573" }, { "input": "78147 2321", "output": "351981971" }, { "input": "99742 62198", "output": "4974183411" }, { "input": "72099 38339", "output": "2599096851" }, { "input": "82532 4838", "output": "751762306" }, { "input": "79410 33144", "output": "3066847464" }, { "input": "11021 3389", "output": "51726307" }, { "input": "66900 7572", "output": "898455660" }, { "input": "99999 49999", "output": "4999850001" }, { "input": "100000 49999", "output": "4999949999" }, { "input": "100000 100000", "output": "4999950000" }, { "input": "100000 1", "output": "199997" }, { "input": "4 100", "output": "6" }, { "input": "100000 1234", "output": "243753254" } ]
1,458,323,855
4,955
Python 3
OK
TESTS
92
93
0
n, k = map(int, input().split()) h = k * 2 n -= 1 ans = 0 for i in range(h): if n == 0: break ans += n n -= 1 print(ans)
Title: Mischievous Mess Makers Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=&lt;<=*j* and *p**i*<=&gt;<=*p**j*. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. Output Specification: Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. Demo Input: ['5 2\n', '1 10\n'] Demo Output: ['10\n', '0\n'] Note: In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible messiness is 0.
```python n, k = map(int, input().split()) h = k * 2 n -= 1 ans = 0 for i in range(h): if n == 0: break ans += n n -= 1 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,678,555,717
2,147,483,647
Python 3
OK
TESTS
20
46
0
t = int(input()) for i in range(t): s = input() if len(s)<=10: print(s) else: n = len(s)-2 new = s[0]+str(n)+s[-1] print(new)
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 t = int(input()) for i in range(t): s = input() if len(s)<=10: print(s) else: n = len(s)-2 new = s[0]+str(n)+s[-1] print(new) ```
3.977
501
A
Contest
PROGRAMMING
900
[ "implementation" ]
null
null
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the contest started and Vasya submitted the problem *d* minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs *p* points *t* minutes after the contest started, you get points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.
The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round).
Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points.
[ "500 1000 20 30\n", "1000 1000 1 1\n", "1500 1000 176 177\n" ]
[ "Vasya\n", "Tie\n", "Misha\n" ]
none
500
[ { "input": "500 1000 20 30", "output": "Vasya" }, { "input": "1000 1000 1 1", "output": "Tie" }, { "input": "1500 1000 176 177", "output": "Misha" }, { "input": "1500 1000 74 177", "output": "Misha" }, { "input": "750 2500 175 178", "output": "Vasya" }, { "input": "750 1000 54 103", "output": "Tie" }, { "input": "2000 1250 176 130", "output": "Tie" }, { "input": "1250 1750 145 179", "output": "Tie" }, { "input": "2000 2000 176 179", "output": "Tie" }, { "input": "1500 1500 148 148", "output": "Tie" }, { "input": "2750 1750 134 147", "output": "Misha" }, { "input": "3250 250 175 173", "output": "Misha" }, { "input": "500 500 170 176", "output": "Misha" }, { "input": "250 1000 179 178", "output": "Vasya" }, { "input": "3250 1000 160 138", "output": "Misha" }, { "input": "3000 2000 162 118", "output": "Tie" }, { "input": "1500 1250 180 160", "output": "Tie" }, { "input": "1250 2500 100 176", "output": "Tie" }, { "input": "3500 3500 177 178", "output": "Tie" }, { "input": "3000 3250 16 34", "output": "Tie" }, { "input": "1750 3000 137 49", "output": "Vasya" }, { "input": "500 1500 179 71", "output": "Vasya" }, { "input": "1250 2000 101 180", "output": "Misha" }, { "input": "250 750 180 176", "output": "Vasya" }, { "input": "2250 2250 163 145", "output": "Vasya" }, { "input": "3000 3000 176 78", "output": "Vasya" }, { "input": "250 3500 8 178", "output": "Vasya" }, { "input": "1750 1250 179 180", "output": "Misha" }, { "input": "2750 1750 13 164", "output": "Misha" }, { "input": "1750 2250 178 53", "output": "Vasya" }, { "input": "2500 2750 73 179", "output": "Misha" }, { "input": "1000 3500 178 175", "output": "Vasya" }, { "input": "1000 500 7 162", "output": "Misha" }, { "input": "1000 250 175 48", "output": "Misha" }, { "input": "1750 500 166 177", "output": "Misha" }, { "input": "250 250 0 0", "output": "Tie" }, { "input": "250 3500 0 0", "output": "Vasya" }, { "input": "250 3500 0 180", "output": "Vasya" }, { "input": "3500 3500 180 180", "output": "Tie" }, { "input": "3500 250 0 180", "output": "Misha" } ]
1,668,015,915
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
# Wadea # m1,v1,tm1,tv1 = input().split() m1,v1,tm1,tv1 = int(m1),int(v1),int(tm1),int(tv1) m = int(m1-((m1/250)*tm1)) v = int(v1-((v1/250)*tv1)) if m > v: print("Misha") elif m < v: print("Vasya") else: print("Tie")
Title: Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the contest started and Vasya submitted the problem *d* minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs *p* points *t* minutes after the contest started, you get points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth. Input Specification: The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). Output Specification: Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points. Demo Input: ['500 1000 20 30\n', '1000 1000 1 1\n', '1500 1000 176 177\n'] Demo Output: ['Vasya\n', 'Tie\n', 'Misha\n'] Note: none
```python # Wadea # m1,v1,tm1,tv1 = input().split() m1,v1,tm1,tv1 = int(m1),int(v1),int(tm1),int(tv1) m = int(m1-((m1/250)*tm1)) v = int(v1-((v1/250)*tv1)) if m > v: print("Misha") elif m < v: print("Vasya") else: print("Tie") ```
0
593
A
2Char
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters. Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.
The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.
Print a single integer — the maximum possible total length of words in Andrew's article.
[ "4\nabb\ncacc\naaa\nbbb\n", "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n" ]
[ "9", "6" ]
In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}. In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.
250
[ { "input": "4\nabb\ncacc\naaa\nbbb", "output": "9" }, { "input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa", "output": "6" }, { "input": "1\na", "output": "1" }, { "input": "2\nz\nz", "output": "2" }, { "input": "5\nabcde\nfghij\nklmno\npqrst\nuvwxy", "output": "0" }, { "input": "6\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg", "output": "36" }, { "input": "6\naaaaaa\naaaaaa\nbbbbbb\nbbbbbb\naaabbb\nababab", "output": "36" }, { "input": "1\nabc", "output": "0" }, { "input": "2\nabc\nbca", "output": "0" }, { "input": "3\nab\nba\nzzz", "output": "4" }, { "input": "3\nab\nba\nzzzzz", "output": "5" }, { "input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "37" }, { "input": "26\nq\nw\ne\nr\nt\ny\nu\ni\no\np\na\ns\nd\nf\ng\nh\nj\nk\nl\nz\nx\nc\nv\nb\nn\nm", "output": "2" }, { "input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaaf", "output": "28" }, { "input": "7\npavel\nerika\nalexxxxxxx\ngracio\nzhenya\nsudarev\nchelyaba", "output": "0" }, { "input": "31\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml", "output": "0" }, { "input": "5\nzloyfreid\ngraciocode\nschooldiary\nkazakov\nevgesha", "output": "0" }, { "input": "4\nurkop\nvisualac\ngnutl\nwtf", "output": "0" }, { "input": "3\naa\nb\nccc", "output": "5" }, { "input": "3\na\nbd\ncaaaaaaa", "output": "9" }, { "input": "4\naa\nax\nay\nxxxx", "output": "8" }, { "input": "5\nc\nbb\ne\ndd\nf", "output": "4" }, { "input": "2\naaaaa\naaaaa", "output": "10" } ]
1,596,519,111
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
77
6,963,200
d={} s=[0]*26 for i in " "*int(input()): z=input() f=set(z) if len(f)==2: n=tuple(sorted(f)) d[n]=d.get(n,0)+len(z) if len(f)==1: s[ord(z[0])-97]+=len(z) ans=max(d.values()) l=chr(s.index(max(s))+97) l1=max(s) s[s.index(max(s))]=-1 r=chr(s.index(max(s))+97) l2=max(s) s[s.index(max(s))]=-1 print(max(ans,l1+l2+d.get((l,r),0)))
Title: 2Char Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters. Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length. Input Specification: The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input. Output Specification: Print a single integer — the maximum possible total length of words in Andrew's article. Demo Input: ['4\nabb\ncacc\naaa\nbbb\n', '5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n'] Demo Output: ['9', '6'] Note: In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}. In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.
```python d={} s=[0]*26 for i in " "*int(input()): z=input() f=set(z) if len(f)==2: n=tuple(sorted(f)) d[n]=d.get(n,0)+len(z) if len(f)==1: s[ord(z[0])-97]+=len(z) ans=max(d.values()) l=chr(s.index(max(s))+97) l1=max(s) s[s.index(max(s))]=-1 r=chr(s.index(max(s))+97) l2=max(s) s[s.index(max(s))]=-1 print(max(ans,l1+l2+d.get((l,r),0))) ```
-1
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number — the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, { "input": "1022 584 112", "output": "380" }, { "input": "66 174 319", "output": "184" }, { "input": "912 276 1748", "output": "444" }, { "input": "65 156 60", "output": "120" }, { "input": "1 10000 10000", "output": "40008" }, { "input": "1485 55 27", "output": "332" }, { "input": "152 108 4104", "output": "528" }, { "input": "1656 6900 1350", "output": "740" }, { "input": "12 14 42", "output": "60" }, { "input": "615 18 1230", "output": "856" }, { "input": "680 60 408", "output": "336" }, { "input": "644 966 6", "output": "1308" }, { "input": "1 432 432", "output": "1736" }, { "input": "2239 2239 1", "output": "8964" }, { "input": "4106 8212 2", "output": "16436" }, { "input": "10000 10000 10000", "output": "1200" }, { "input": "3623 3623 1", "output": "14500" }, { "input": "9801 9801 9801", "output": "1188" }, { "input": "10000 1 10000", "output": "40008" }, { "input": "9 9 9", "output": "36" }, { "input": "9801 9702 9702", "output": "1184" } ]
1,622,977,373
2,147,483,647
PyPy 3
OK
TESTS
27
498
409,600
from sys import * '''sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') ''' from collections import defaultdict as dd from math import * from bisect import * #sys.setrecursionlimit(10 ** 8) def sinp(): return input() def inp(): return int(sinp()) def minp(): return map(int, sinp().split()) def linp(): return list(minp()) def strl(): return list(sinp()) def pr(x): print(x) mod = int(1e9+7) a, b, c = minp() x = sqrt(a * b * c // b ** 2) y = sqrt(a * b * c // c ** 2) z = sqrt(a * b * c // a ** 2) pr(4 * int((x + y + z)))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input Specification: The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. Output Specification: Print a single number — the sum of all edges of the parallelepiped. Demo Input: ['1 1 1\n', '4 6 6\n'] Demo Output: ['12\n', '28\n'] Note: In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
```python from sys import * '''sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') ''' from collections import defaultdict as dd from math import * from bisect import * #sys.setrecursionlimit(10 ** 8) def sinp(): return input() def inp(): return int(sinp()) def minp(): return map(int, sinp().split()) def linp(): return list(minp()) def strl(): return list(sinp()) def pr(x): print(x) mod = int(1e9+7) a, b, c = minp() x = sqrt(a * b * c // b ** 2) y = sqrt(a * b * c // c ** 2) z = sqrt(a * b * c // a ** 2) pr(4 * int((x + y + z))) ```
3
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get.
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, { "input": "3\n1\n5", "output": "20" }, { "input": "6\n7\n1", "output": "48" }, { "input": "1\n8\n3", "output": "27" }, { "input": "9\n7\n2", "output": "126" }, { "input": "1\n1\n10", "output": "20" }, { "input": "9\n1\n1", "output": "18" }, { "input": "10\n5\n6", "output": "300" }, { "input": "8\n9\n7", "output": "504" }, { "input": "4\n2\n10", "output": "80" }, { "input": "2\n8\n3", "output": "48" }, { "input": "3\n5\n7", "output": "105" }, { "input": "1\n10\n1", "output": "12" }, { "input": "2\n2\n2", "output": "8" }, { "input": "5\n6\n1", "output": "35" }, { "input": "10\n1\n1", "output": "20" }, { "input": "1\n6\n1", "output": "8" }, { "input": "1\n9\n1", "output": "11" }, { "input": "2\n1\n2", "output": "6" }, { "input": "2\n6\n1", "output": "14" }, { "input": "9\n2\n1", "output": "27" }, { "input": "1\n9\n2", "output": "20" }, { "input": "1\n3\n1", "output": "5" }, { "input": "2\n1\n1", "output": "4" } ]
1,687,710,319
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
#1+2*3=7 #1*(2+3)=5 #1*2*3=6 #(1+2)*3=9 a = int(input()) b = int(input()) c = int(input()) res = a+b*c tot = a*(b+c) t = a*b*c r = (a+b)*c print(max(res,tot,t,r))
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get. Input Specification: The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). Output Specification: Print the maximum value of the expression that you can obtain. Demo Input: ['1\n2\n3\n', '2\n10\n3\n'] Demo Output: ['9\n', '60\n'] Note: none
```python #1+2*3=7 #1*(2+3)=5 #1*2*3=6 #(1+2)*3=9 a = int(input()) b = int(input()) c = int(input()) res = a+b*c tot = a*(b+c) t = a*b*c r = (a+b)*c print(max(res,tot,t,r)) ```
0
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,691,348,350
2,147,483,647
Python 3
OK
TESTS
71
92
0
s = [] s1 = 0 for _ in range(int(input())) : a , b = map(int,input().split()) s1 += b s1 -= a s.append(s1) print(max(s))
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python s = [] s1 = 0 for _ in range(int(input())) : a , b = map(int,input().split()) s1 += b s1 -= a s.append(s1) print(max(s)) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,521,888,147
2,147,483,647
Python 3
OK
TESTS
30
186
7,372,800
s = input() c, m = 0, 0 for i in s: if 65<=ord(i)<=90: c+=1 elif 97<=ord(i)<=122: m+=1 if c>m: print(s.upper()) else: print(s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python s = input() c, m = 0, 0 for i in s: if 65<=ord(i)<=90: c+=1 elif 97<=ord(i)<=122: m+=1 if c>m: print(s.upper()) else: print(s.lower()) ```
3.939767
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,647,714,336
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
n=int(input()) l=[] for i in range(3): m=list(map(int,input().split())) l.append(m) s=l[0][0]+l[1][0]+l[2][0] r=l[0][1]+l[1][1]+l[2][1] t=l[0][2]+l[1][2]+l[2][2] if s==r==t==0: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n=int(input()) l=[] for i in range(3): m=list(map(int,input().split())) l.append(m) s=l[0][0]+l[1][0]+l[2][0] r=l[0][1]+l[1][1]+l[2][1] t=l[0][2]+l[1][2]+l[2][2] if s==r==t==0: print("YES") else: print("NO") ```
0
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "output": "8" }, { "input": "774", "output": "13" }, { "input": "4", "output": "1" }, { "input": "4447747", "output": "140" }, { "input": "7747474", "output": "233" }, { "input": "4444", "output": "15" }, { "input": "4447", "output": "16" }, { "input": "7", "output": "2" }, { "input": "4", "output": "1" }, { "input": "4447744", "output": "139" }, { "input": "77474", "output": "57" }, { "input": "7747", "output": "28" }, { "input": "444", "output": "7" }, { "input": "7", "output": "2" }, { "input": "7774477", "output": "242" }, { "input": "4477774", "output": "157" }, { "input": "7444", "output": "23" }, { "input": "7474747", "output": "212" }, { "input": "77", "output": "6" }, { "input": "774477", "output": "114" }, { "input": "7", "output": "2" }, { "input": "47", "output": "4" }, { "input": "747777", "output": "110" }, { "input": "444444444", "output": "511" }, { "input": "777777777", "output": "1022" }, { "input": "477477447", "output": "728" }, { "input": "777744747", "output": "996" } ]
1,574,447,906
2,147,483,647
PyPy 3
OK
TESTS
33
156
0
import math n = int(input()) # lower_pow = int(math.log10(n)) # answer = 0 # print(lower_pow) # for i in range(0, lower_pow): # answer = 2*answer + 2 # print(answer) ans = 0 aux = 1 a = str(n) for i in range(len(a)-1, -1, -1): if(a[i] == '7'): ans = ans + 2**aux else: ans = ans + 2**aux - 2**(aux-1) aux = aux + 1 print(ans)
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back. Input Specification: The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the index of *n* among all lucky numbers. Demo Input: ['4\n', '7\n', '77\n'] Demo Output: ['1\n', '2\n', '6\n'] Note: none
```python import math n = int(input()) # lower_pow = int(math.log10(n)) # answer = 0 # print(lower_pow) # for i in range(0, lower_pow): # answer = 2*answer + 2 # print(answer) ans = 0 aux = 1 a = str(n) for i in range(len(a)-1, -1, -1): if(a[i] == '7'): ans = ans + 2**aux else: ans = ans + 2**aux - 2**(aux-1) aux = aux + 1 print(ans) ```
3
992
C
Nastya and a Wardrobe
PROGRAMMING
1,600
[ "math" ]
null
null
Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns *x* dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for *k*<=+<=1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109<=+<=7, because it is easy to see that it is always integer.
The only line contains two integers *x* and *k* (0<=≤<=*x*,<=*k*<=≤<=1018), where *x* is the initial number of dresses and *k*<=+<=1 is the number of months in a year in Byteland.
In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109<=+<=7.
[ "2 0\n", "2 1\n", "3 2\n" ]
[ "4\n", "7\n", "21\n" ]
In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
1,500
[ { "input": "2 0", "output": "4" }, { "input": "2 1", "output": "7" }, { "input": "3 2", "output": "21" }, { "input": "1 411", "output": "485514976" }, { "input": "1 692", "output": "860080936" }, { "input": "16 8", "output": "7937" }, { "input": "18 12", "output": "143361" }, { "input": "1 1000000000000000000", "output": "719476261" }, { "input": "0 24", "output": "0" }, { "input": "24 0", "output": "48" }, { "input": "1000000000000000000 1", "output": "195" }, { "input": "348612312017571993 87570063840727716", "output": "551271547" }, { "input": "314647997243943415 107188213956410843", "output": "109575135" }, { "input": "375000003 2", "output": "0" }, { "input": "451 938", "output": "598946958" }, { "input": "4 1669", "output": "185365669" }, { "input": "24 347", "output": "860029201" }, { "input": "1619 1813", "output": "481568710" }, { "input": "280 472", "output": "632090765" }, { "input": "1271 237", "output": "27878991" }, { "input": "626 560", "output": "399405853" }, { "input": "167 887", "output": "983959273" }, { "input": "1769 422", "output": "698926874" }, { "input": "160 929", "output": "752935252" }, { "input": "1075 274", "output": "476211777" }, { "input": "1332 332", "output": "47520583" }, { "input": "103872254428948073 97291596742897547", "output": "283633261" }, { "input": "157600018563121064 54027847222622605", "output": "166795759" }, { "input": "514028642164226185 95344332761644668", "output": "718282571" }, { "input": "91859547444219924 75483775868568438", "output": "462306789" }, { "input": "295961633522750187 84483303945499729", "output": "11464805" }, { "input": "8814960236468055 86463151557693391", "output": "430718856" }, { "input": "672751296745170589 13026894786355983", "output": "260355651" }, { "input": "909771081413191574 18862935031728197", "output": "800873185" }, { "input": "883717267463724670 29585639347346605", "output": "188389362" }, { "input": "431620727626880523 47616788361847228", "output": "311078131" }, { "input": "816689044159694273 6475970360049048", "output": "211796030" }, { "input": "313779810374175108 13838123840048842", "output": "438854949" }, { "input": "860936792402722414 59551033597232946", "output": "359730003" }, { "input": "332382902893992163 15483141652464187", "output": "719128379" }, { "input": "225761360057436129 49203610094504526", "output": "54291755" }, { "input": "216006901533424028 8313457244750219", "output": "362896012" }, { "input": "568001660010321225 97167523790774710", "output": "907490480" }, { "input": "904089164817530426 53747406876903279", "output": "702270335" }, { "input": "647858974461637674 18385058205826214", "output": "375141527" }, { "input": "720433754707338458 94180351080265292", "output": "273505123" }, { "input": "268086842387268316 76502855388264782", "output": "288717798" }, { "input": "488603693655520686 79239542983498430", "output": "316399174" }, { "input": "152455635055802121 50394545488662355", "output": "697051907" }, { "input": "585664029992038779 34972826534657555", "output": "699566354" }, { "input": "349532090641396787 12248820623854158", "output": "233938854" }, { "input": "353579407209009179 74469254935824590", "output": "771349161" }, { "input": "491414900908765740 49509676303815755", "output": "237095803" }, { "input": "91142854626119420 900651524977956", "output": "211575546" }, { "input": "73543340229981083 66918326344192076", "output": "710215652" }, { "input": "463958371369193376 89203995753927042", "output": "41857490" }, { "input": "911873413622533246 54684577459651780", "output": "926432198" }, { "input": "316313018463929883 78259904441946885", "output": "36284201" }, { "input": "889560480100219043 54181377424922141", "output": "281123162" }, { "input": "0 3259862395629356", "output": "0" }, { "input": "1 3", "output": "9" }, { "input": "3 1", "output": "11" }, { "input": "1000000007 1", "output": "1000000006" }, { "input": "1000000007 2", "output": "1000000004" }, { "input": "1000000007 0", "output": "0" }, { "input": "1000000007 12", "output": "999995912" }, { "input": "1000000007 70", "output": "729983755" }, { "input": "250000002 1", "output": "0" }, { "input": "1000000007 3", "output": "1000000000" }, { "input": "999999999 0", "output": "999999991" }, { "input": "1000000007 5", "output": "999999976" }, { "input": "1000000007 1000000007", "output": "1000000006" }, { "input": "10000000000000000 0", "output": "860000007" }, { "input": "1000000000000 0", "output": "999986007" }, { "input": "99999999999999999 0", "output": "600000012" }, { "input": "1000000000000000 0", "output": "986000007" } ]
1,635,689,939
2,147,483,647
PyPy 3-64
MEMORY_LIMIT_EXCEEDED
TESTS
7
1,278
268,390,400
x,k = map(int,input().split()) m = 10**9 + 7 if k == 0: print(2*x) else: y = x*(2**(k+1)) - 2**k + 1 print(y%m)
Title: Nastya and a Wardrobe Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns *x* dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for *k*<=+<=1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109<=+<=7, because it is easy to see that it is always integer. Input Specification: The only line contains two integers *x* and *k* (0<=≤<=*x*,<=*k*<=≤<=1018), where *x* is the initial number of dresses and *k*<=+<=1 is the number of months in a year in Byteland. Output Specification: In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109<=+<=7. Demo Input: ['2 0\n', '2 1\n', '3 2\n'] Demo Output: ['4\n', '7\n', '21\n'] Note: In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
```python x,k = map(int,input().split()) m = 10**9 + 7 if k == 0: print(2*x) else: y = x*(2**(k+1)) - 2**k + 1 print(y%m) ```
0
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven. Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven. In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO" }, { "input": "599 97 54 992", "output": "YES" }, { "input": "11 22 18 17", "output": "NO" }, { "input": "1 13 22 11", "output": "NO" }, { "input": "1 1 1 1", "output": "NO" }, { "input": "3 1 1 1", "output": "YES" }, { "input": "1000 1000 1000 1000", "output": "NO" }, { "input": "1000 1000 1 1", "output": "YES" }, { "input": "1000 1000 1 400", "output": "YES" }, { "input": "1000 1000 1 1000", "output": "YES" }, { "input": "1000 1000 1 999", "output": "YES" }, { "input": "53 11 3 166", "output": "YES" }, { "input": "313 2 3 385", "output": "NO" }, { "input": "214 9 9 412", "output": "NO" }, { "input": "349 9 5 268", "output": "YES" }, { "input": "611 16 8 153", "output": "YES" }, { "input": "877 13 3 191", "output": "YES" }, { "input": "340 9 9 10", "output": "YES" }, { "input": "31 8 2 205", "output": "NO" }, { "input": "519 3 2 148", "output": "YES" }, { "input": "882 2 21 219", "output": "NO" }, { "input": "982 13 5 198", "output": "YES" }, { "input": "428 13 6 272", "output": "YES" }, { "input": "436 16 14 26", "output": "YES" }, { "input": "628 10 9 386", "output": "YES" }, { "input": "77 33 18 31", "output": "YES" }, { "input": "527 36 4 8", "output": "YES" }, { "input": "128 18 2 169", "output": "YES" }, { "input": "904 4 2 288", "output": "YES" }, { "input": "986 4 3 25", "output": "YES" }, { "input": "134 8 22 162", "output": "NO" }, { "input": "942 42 3 69", "output": "YES" }, { "input": "894 4 9 4", "output": "YES" }, { "input": "953 8 10 312", "output": "YES" }, { "input": "43 8 1 121", "output": "YES" }, { "input": "12 13 19 273", "output": "NO" }, { "input": "204 45 10 871", "output": "YES" }, { "input": "342 69 50 425", "output": "NO" }, { "input": "982 93 99 875", "output": "NO" }, { "input": "283 21 39 132", "output": "YES" }, { "input": "1000 45 83 686", "output": "NO" }, { "input": "246 69 36 432", "output": "NO" }, { "input": "607 93 76 689", "output": "NO" }, { "input": "503 21 24 435", "output": "NO" }, { "input": "1000 45 65 989", "output": "NO" }, { "input": "30 21 2 250", "output": "YES" }, { "input": "1000 49 50 995", "output": "NO" }, { "input": "383 69 95 253", "output": "YES" }, { "input": "393 98 35 999", "output": "YES" }, { "input": "1000 22 79 552", "output": "NO" }, { "input": "268 294 268 154", "output": "NO" }, { "input": "963 465 706 146", "output": "YES" }, { "input": "304 635 304 257", "output": "NO" }, { "input": "4 2 1 6", "output": "NO" }, { "input": "1 51 10 50", "output": "NO" }, { "input": "5 5 4 4", "output": "YES" }, { "input": "3 2 1 1", "output": "YES" }, { "input": "3 4 3 3", "output": "NO" }, { "input": "7 3 4 1", "output": "YES" }, { "input": "101 10 1 1000", "output": "NO" }, { "input": "5 1 1 1", "output": "YES" }, { "input": "5 10 5 5", "output": "NO" }, { "input": "19 1 7 1", "output": "YES" }, { "input": "763 572 745 262", "output": "YES" }, { "input": "1 2 1 1", "output": "NO" }, { "input": "5 1 1 3", "output": "YES" }, { "input": "170 725 479 359", "output": "NO" }, { "input": "6 2 1 7", "output": "YES" }, { "input": "6 2 5 1", "output": "YES" }, { "input": "1 2 2 1", "output": "NO" }, { "input": "24 2 8 3", "output": "YES" }, { "input": "7 3 3 3", "output": "YES" }, { "input": "5 2 2 2", "output": "YES" }, { "input": "3 2 1 2", "output": "YES" }, { "input": "1000 2 200 8", "output": "NO" }, { "input": "3 100 2 100", "output": "NO" }, { "input": "2 999 1 1000", "output": "NO" }, { "input": "2 1 1 1", "output": "NO" }, { "input": "2 3 5 1", "output": "NO" }, { "input": "100 1 5 1", "output": "YES" }, { "input": "7 2 3 3", "output": "YES" }, { "input": "4 1 1 3", "output": "NO" }, { "input": "3 2 2 1", "output": "YES" }, { "input": "1 1 1 2", "output": "NO" }, { "input": "91 8 7 13", "output": "YES" }, { "input": "3 1 2 1", "output": "NO" }, { "input": "5 3 2 3", "output": "YES" }, { "input": "9 6 6 3", "output": "YES" } ]
1,658,162,660
2,147,483,647
Python 3
OK
TESTS
93
187
0
class Solution(): def is_worth_build_the_second_oven(): number_of_cakes, time_to_bake, \ cakes_baked_at_the_same_time, \ time_to_build_second_oven = map(int, input().split()) time = 0 second_oven_builded = 0 cakes_baked = 0 cakes_baked2 = 0 while cakes_baked < number_of_cakes and cakes_baked2 < number_of_cakes: time += 1 if time % time_to_bake == 0: cakes_baked += cakes_baked_at_the_same_time cakes_baked2 += cakes_baked_at_the_same_time if second_oven_builded > 0: cakes_baked2 += cakes_baked_at_the_same_time if time % time_to_build_second_oven == 0: second_oven_builded = 1 if cakes_baked >= number_of_cakes: return "NO" else: return "YES" if __name__ == '__main__': print(Solution.is_worth_build_the_second_oven())
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven. Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable. Input Specification: The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. Output Specification: If it is reasonable to build the second oven, print "YES". Otherwise print "NO". Demo Input: ['8 6 4 5\n', '8 6 4 6\n', '10 3 11 4\n', '4 2 1 4\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n', 'YES\n'] Note: In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven. In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
```python class Solution(): def is_worth_build_the_second_oven(): number_of_cakes, time_to_bake, \ cakes_baked_at_the_same_time, \ time_to_build_second_oven = map(int, input().split()) time = 0 second_oven_builded = 0 cakes_baked = 0 cakes_baked2 = 0 while cakes_baked < number_of_cakes and cakes_baked2 < number_of_cakes: time += 1 if time % time_to_bake == 0: cakes_baked += cakes_baked_at_the_same_time cakes_baked2 += cakes_baked_at_the_same_time if second_oven_builded > 0: cakes_baked2 += cakes_baked_at_the_same_time if time % time_to_build_second_oven == 0: second_oven_builded = 1 if cakes_baked >= number_of_cakes: return "NO" else: return "YES" if __name__ == '__main__': print(Solution.is_worth_build_the_second_oven()) ```
3
727
A
Transformation: from A to B
PROGRAMMING
1,000
[ "brute force", "dfs and similar", "math" ]
null
null
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*.
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them.
[ "2 162\n", "4 42\n", "100 40021\n" ]
[ "YES\n5\n2 4 8 81 162 \n", "NO\n", "YES\n5\n100 200 2001 4002 40021 \n" ]
none
1,000
[ { "input": "2 162", "output": "YES\n5\n2 4 8 81 162 " }, { "input": "4 42", "output": "NO" }, { "input": "100 40021", "output": "YES\n5\n100 200 2001 4002 40021 " }, { "input": "1 111111111", "output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 " }, { "input": "1 1000000000", "output": "NO" }, { "input": "999999999 1000000000", "output": "NO" }, { "input": "1 2", "output": "YES\n2\n1 2 " }, { "input": "1 536870912", "output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 " }, { "input": "11111 11111111", "output": "YES\n4\n11111 111111 1111111 11111111 " }, { "input": "59139 946224", "output": "YES\n5\n59139 118278 236556 473112 946224 " }, { "input": "9859 19718", "output": "YES\n2\n9859 19718 " }, { "input": "25987 51974222", "output": "YES\n5\n25987 259871 2598711 25987111 51974222 " }, { "input": "9411 188222222", "output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 " }, { "input": "25539 510782222", "output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 " }, { "input": "76259 610072", "output": "YES\n4\n76259 152518 305036 610072 " }, { "input": "92387 184774", "output": "YES\n2\n92387 184774 " }, { "input": "8515 85151111", "output": "YES\n5\n8515 85151 851511 8515111 85151111 " }, { "input": "91939 9193911", "output": "YES\n3\n91939 919391 9193911 " }, { "input": "30518 610361", "output": "YES\n3\n30518 61036 610361 " }, { "input": "46646 373168844", "output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 " }, { "input": "30070 300701", "output": "YES\n2\n30070 300701 " }, { "input": "13494 1079528", "output": "YES\n5\n13494 134941 269882 539764 1079528 " }, { "input": "96918 775344422", "output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 " }, { "input": "13046 260921", "output": "YES\n3\n13046 26092 260921 " }, { "input": "29174 5834811", "output": "YES\n4\n29174 58348 583481 5834811 " }, { "input": "79894 319576421", "output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 " }, { "input": "96022 1920442", "output": "YES\n3\n96022 960221 1920442 " }, { "input": "79446 6355681", "output": "YES\n5\n79446 158892 317784 635568 6355681 " }, { "input": "5440 27853056", "output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 " }, { "input": "250000000 705032705", "output": "NO" }, { "input": "17 35", "output": "NO" }, { "input": "1 3", "output": "NO" }, { "input": "2 11", "output": "NO" } ]
1,684,433,865
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
15
134,758,400
import sys, threading input = lambda: sys.stdin.readline().strip() def main(): st,ta=map(int,input().split()) ans=False az=[] def dfs(st,arr): nonlocal ta nonlocal az if st==ta: az=arr.copy() if st<ta: newArr1=arr.copy() newArr2=arr.copy() newArr1.append(st*2) newArr2.append(10*st+1) dfs(st*2,newArr1) dfs(10*st+1,newArr2) else: return dfs(st,[st]) sol=az if ans: print('NO') else: print('YES') print(len(sol)) print(' '.join(str(x) for x in sol)) if __name__ == '__main__': sys.setrecursionlimit(1 << 30) threading.stack_size(1 << 27) main_thread = threading.Thread(target=main) main_thread.start() main_thread.join()
Title: Transformation: from A to B Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. Input Specification: The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. Output Specification: If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them. Demo Input: ['2 162\n', '4 42\n', '100 40021\n'] Demo Output: ['YES\n5\n2 4 8 81 162 \n', 'NO\n', 'YES\n5\n100 200 2001 4002 40021 \n'] Note: none
```python import sys, threading input = lambda: sys.stdin.readline().strip() def main(): st,ta=map(int,input().split()) ans=False az=[] def dfs(st,arr): nonlocal ta nonlocal az if st==ta: az=arr.copy() if st<ta: newArr1=arr.copy() newArr2=arr.copy() newArr1.append(st*2) newArr2.append(10*st+1) dfs(st*2,newArr1) dfs(10*st+1,newArr2) else: return dfs(st,[st]) sol=az if ans: print('NO') else: print('YES') print(len(sol)) print(' '.join(str(x) for x in sol)) if __name__ == '__main__': sys.setrecursionlimit(1 << 30) threading.stack_size(1 << 27) main_thread = threading.Thread(target=main) main_thread.start() main_thread.join() ```
0
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, { "input": "24 54 37\n60 63 6\n1 84 26", "output": "110\n101\n011" }, { "input": "23 10 40\n15 6 40\n92 80 77", "output": "101\n100\n000" }, { "input": "62 74 80\n95 74 93\n2 47 95", "output": "010\n001\n110" }, { "input": "80 83 48\n26 0 66\n47 76 37", "output": "000\n000\n010" }, { "input": "32 15 65\n7 54 36\n5 51 3", "output": "111\n101\n001" }, { "input": "22 97 12\n71 8 24\n100 21 64", "output": "100\n001\n100" }, { "input": "46 37 13\n87 0 50\n90 8 55", "output": "111\n011\n000" }, { "input": "57 43 58\n20 82 83\n66 16 52", "output": "111\n010\n110" }, { "input": "45 56 93\n47 51 59\n18 51 63", "output": "101\n011\n100" }, { "input": "47 66 67\n14 1 37\n27 81 69", "output": "001\n001\n110" }, { "input": "26 69 69\n85 18 23\n14 22 74", "output": "110\n001\n010" }, { "input": "10 70 65\n94 27 25\n74 66 30", "output": "111\n010\n100" }, { "input": "97 1 74\n15 99 1\n88 68 86", "output": "001\n011\n000" }, { "input": "36 48 42\n45 41 66\n26 64 1", "output": "001\n111\n010" }, { "input": "52 81 97\n29 77 71\n66 11 2", "output": "100\n100\n111" }, { "input": "18 66 33\n19 49 49\n48 46 26", "output": "011\n100\n000" }, { "input": "68 79 52\n51 39 100\n29 14 26", "output": "110\n000\n111" }, { "input": "91 69 77\n91 26 64\n91 88 57", "output": "001\n011\n110" }, { "input": "16 69 64\n48 21 80\n81 51 51", "output": "010\n101\n111" }, { "input": "96 14 2\n100 18 12\n65 34 89", "output": "111\n010\n010" }, { "input": "93 95 90\n8 59 42\n53 13 19", "output": "100\n001\n111" }, { "input": "71 84 18\n100 19 67\n9 76 15", "output": "010\n010\n001" }, { "input": "38 93 85\n21 88 64\n4 96 25", "output": "111\n011\n000" }, { "input": "75 20 20\n60 5 78\n77 4 69", "output": "011\n001\n000" }, { "input": "65 70 96\n19 6 83\n33 37 82", "output": "100\n000\n011" }, { "input": "11 13 60\n17 13 46\n42 21 39", "output": "000\n011\n101" }, { "input": "0 0 0\n0 0 0\n0 0 0", "output": "111\n111\n111" }, { "input": "0 0 0\n0 1 0\n0 0 0", "output": "101\n000\n101" }, { "input": "0 0 0\n0 0 0\n0 0 1", "output": "111\n110\n100" } ]
1,643,535,144
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
matrix = [] for i in range(3): row = list(map(int, input().split())) matrix.append(row) initial = [[1]*3]*3 for i in range(3): for j in range(3): if matrix[i][j] % 2: initial[i][j] = not(initial[i][j]) if i > 0: initial[i-1][j] = not(initial[i-1][j]) if i < 2: initial[i+1][j] = not(initial[i+1][j]) if j > 0: initial[i][j-1] = not(initial[i][j-1]) if j < 2: initial[i][j+1] = not(initial[i][j+1]) for i in range(3): for j in range(3): print(initial[i][j], end="")
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. Input Specification: The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. Output Specification: Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". Demo Input: ['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n'] Demo Output: ['001\n010\n100\n', '010\n011\n100\n'] Note: none
```python matrix = [] for i in range(3): row = list(map(int, input().split())) matrix.append(row) initial = [[1]*3]*3 for i in range(3): for j in range(3): if matrix[i][j] % 2: initial[i][j] = not(initial[i][j]) if i > 0: initial[i-1][j] = not(initial[i-1][j]) if i < 2: initial[i+1][j] = not(initial[i+1][j]) if j > 0: initial[i][j-1] = not(initial[i][j-1]) if j < 2: initial[i][j+1] = not(initial[i][j+1]) for i in range(3): for j in range(3): print(initial[i][j], end="") ```
0
863
B
Kayaking
PROGRAMMING
1,500
[ "brute force", "greedy", "sortings" ]
null
null
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash. Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks. Help the party to determine minimum possible total instability!
The first line contains one number *n* (2<=≤<=*n*<=≤<=50). The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000).
Print minimum possible total instability.
[ "2\n1 2 3 4\n", "4\n1 3 4 6 3 4 100 200\n" ]
[ "1\n", "5\n" ]
none
0
[ { "input": "2\n1 2 3 4", "output": "1" }, { "input": "4\n1 3 4 6 3 4 100 200", "output": "5" }, { "input": "3\n305 139 205 406 530 206", "output": "102" }, { "input": "3\n610 750 778 6 361 407", "output": "74" }, { "input": "5\n97 166 126 164 154 98 221 7 51 47", "output": "35" }, { "input": "50\n1 1 2 2 1 3 2 2 1 1 1 1 2 3 3 1 2 1 3 3 2 1 2 3 1 1 2 1 3 1 3 1 3 3 3 1 1 1 3 3 2 2 2 2 3 2 2 2 2 3 1 3 3 3 3 1 3 3 1 3 3 3 3 2 3 1 3 3 1 1 1 3 1 2 2 2 1 1 1 3 1 2 3 2 1 3 3 2 2 1 3 1 3 1 2 2 1 2 3 2", "output": "0" }, { "input": "50\n5 5 5 5 4 2 2 3 2 2 4 1 5 5 1 2 4 2 4 2 5 2 2 2 2 3 2 4 2 5 5 4 3 1 2 3 3 5 4 2 2 5 2 4 5 5 4 4 1 5 5 3 2 2 5 1 3 3 2 4 4 5 1 2 3 4 4 1 3 3 3 5 1 2 4 4 4 4 2 5 2 5 3 2 4 5 5 2 1 1 2 4 5 3 2 1 2 4 4 4", "output": "1" }, { "input": "50\n499 780 837 984 481 526 944 482 862 136 265 605 5 631 974 967 574 293 969 467 573 845 102 224 17 873 648 120 694 996 244 313 404 129 899 583 541 314 525 496 443 857 297 78 575 2 430 137 387 319 382 651 594 411 845 746 18 232 6 289 889 81 174 175 805 1000 799 950 475 713 951 685 729 925 262 447 139 217 788 514 658 572 784 185 112 636 10 251 621 218 210 89 597 553 430 532 264 11 160 476", "output": "368" }, { "input": "50\n873 838 288 87 889 364 720 410 565 651 577 356 740 99 549 592 994 385 777 435 486 118 887 440 749 533 356 790 413 681 267 496 475 317 88 660 374 186 61 437 729 860 880 538 277 301 667 180 60 393 955 540 896 241 362 146 74 680 734 767 851 337 751 860 542 735 444 793 340 259 495 903 743 961 964 966 87 275 22 776 368 701 835 732 810 735 267 988 352 647 924 183 1 924 217 944 322 252 758 597", "output": "393" }, { "input": "50\n297 787 34 268 439 629 600 398 425 833 721 908 830 636 64 509 420 647 499 675 427 599 396 119 798 742 577 355 22 847 389 574 766 453 196 772 808 261 106 844 726 975 173 992 874 89 775 616 678 52 69 591 181 573 258 381 665 301 589 379 362 146 790 842 765 100 229 916 938 97 340 793 758 177 736 396 247 562 571 92 923 861 165 748 345 703 431 930 101 761 862 595 505 393 126 846 431 103 596 21", "output": "387" }, { "input": "50\n721 631 587 746 692 406 583 90 388 16 161 948 921 70 387 426 39 398 517 724 879 377 906 502 359 950 798 408 846 718 911 845 57 886 9 668 537 632 344 762 19 193 658 447 870 173 98 156 592 519 183 539 274 393 962 615 551 626 148 183 769 763 829 120 796 761 14 744 537 231 696 284 581 688 611 826 703 145 224 600 965 613 791 275 984 375 402 281 851 580 992 8 816 454 35 532 347 250 242 637", "output": "376" }, { "input": "50\n849 475 37 120 754 183 758 374 543 198 896 691 11 607 198 343 761 660 239 669 628 259 223 182 216 158 20 565 454 884 137 923 156 22 310 77 267 707 582 169 120 308 439 309 59 152 206 696 210 177 296 887 559 22 154 553 142 247 491 692 473 572 461 206 532 319 503 164 328 365 541 366 300 392 486 257 863 432 877 404 520 69 418 99 519 239 374 927 601 103 226 316 423 219 240 26 455 101 184 61", "output": "351" }, { "input": "3\n1 2 10 11 100 100", "output": "1" }, { "input": "17\n814 744 145 886 751 1000 272 914 270 529 467 164 410 369 123 424 991 12 702 582 561 858 746 950 598 393 606 498 648 686 455 873 728 858", "output": "318" }, { "input": "45\n476 103 187 696 463 457 588 632 763 77 391 721 95 124 378 812 980 193 694 898 859 572 721 274 605 264 929 615 257 918 42 493 1 3 697 349 990 800 82 535 382 816 943 735 11 272 562 323 653 370 766 332 666 130 704 604 645 717 267 255 37 470 925 941 376 611 332 758 504 40 477 263 708 434 38 596 650 990 714 662 572 467 949 799 648 581 545 828 508 636", "output": "355" }, { "input": "2\n55 5 25 51", "output": "4" }, { "input": "25\n89 50 640 463 858 301 522 241 923 378 892 822 550 17 42 66 706 779 657 840 273 222 444 459 94 925 437 159 182 727 92 851 742 215 653 891 782 533 29 128 133 883 317 475 165 994 802 434 744 973", "output": "348" }, { "input": "4\n35 48 71 44 78 79 57 48", "output": "10" }, { "input": "3\n58 89 73 15 5 47", "output": "21" }, { "input": "2\n1 20 99 100", "output": "1" } ]
1,690,394,501
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
n = int(input()) wgt = sorted([int(i) for i in input().split()]) wgt = wgt[:len(wgt) - 2] summ = 0 for i in range(int(len(wgt)/2)): summ += wgt[len(wgt) - 1 - i] - wgt[i] print(summ)
Title: Kayaking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash. Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks. Help the party to determine minimum possible total instability! Input Specification: The first line contains one number *n* (2<=≤<=*n*<=≤<=50). The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). Output Specification: Print minimum possible total instability. Demo Input: ['2\n1 2 3 4\n', '4\n1 3 4 6 3 4 100 200\n'] Demo Output: ['1\n', '5\n'] Note: none
```python n = int(input()) wgt = sorted([int(i) for i in input().split()]) wgt = wgt[:len(wgt) - 2] summ = 0 for i in range(int(len(wgt)/2)): summ += wgt[len(wgt) - 1 - i] - wgt[i] print(summ) ```
0
408
A
Line to Cashier
PROGRAMMING
900
[ "implementation" ]
null
null
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that: - the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change. Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
[ "1\n1\n1\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n" ]
[ "20\n", "100\n" ]
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
500
[ { "input": "1\n1\n1", "output": "20" }, { "input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100" }, { "input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "output": "100" }, { "input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3", "output": "125" }, { "input": "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5", "output": "480" }, { "input": "10\n9 10 10 10 9 5 9 7 8 7\n11 6 10 4 4 15 7 15 5\n3 9 11 12 11 1 13 13 1 5\n6 15 9 12 3 2 8 12 11 10\n7 1 1 6 10 2 6 1 14 2\n8 14 2 3 6 1 14 1 12\n6 10 9 3 5\n13 12 12 7 13 4 4 8 10\n5 6 4 3 14 9 13\n8 12 1 5 7 4 13 1\n1 9 5 3 5 1 4", "output": "240" }, { "input": "10\n5 5 5 5 5 5 5 5 5 5\n5 5 4 5 4\n6 5 7 7 6\n5 4 4 5 5\n4 4 5 5 5\n7 6 4 5 7\n4 6 5 4 5\n6 6 7 6 6\n4 5 4 4 7\n7 5 4 4 5\n6 6 7 4 4", "output": "190" }, { "input": "1\n1\n100", "output": "515" }, { "input": "1\n90\n90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90", "output": "41850" } ]
1,396,766,898
2,147,483,647
Python 3
OK
TESTS
20
77
0
N = int(input()) kassa = list(map(int, input().split())) i = 0 people = list([0] * N) while i != N: people[i] = list(map(int, input().split())) i += 1 min_sec = 100000000000 for human in people: sec = 0 for tovar in human: sec += tovar * 5 + 15 if min_sec > sec: min_sec = sec print(min_sec)
Title: Line to Cashier Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that: - the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change. Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has. Output Specification: Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. Demo Input: ['1\n1\n1\n', '4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n'] Demo Output: ['20\n', '100\n'] Note: In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
```python N = int(input()) kassa = list(map(int, input().split())) i = 0 people = list([0] * N) while i != N: people[i] = list(map(int, input().split())) i += 1 min_sec = 100000000000 for human in people: sec = 0 for tovar in human: sec += tovar * 5 + 15 if min_sec > sec: min_sec = sec print(min_sec) ```
3
276
C
Little Girl and Maximum Sum
PROGRAMMING
1,500
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query.
In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n" ]
[ "25\n", "33\n" ]
none
1,500
[ { "input": "3 3\n5 3 2\n1 2\n2 3\n1 3", "output": "25" }, { "input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "output": "33" }, { "input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "output": "9382" }, { "input": "16 13\n40 32 15 16 35 36 45 23 30 42 25 8 29 21 39 23\n2 9\n3 11\n8 9\n4 14\n1 6\n5 10\n5 14\n5 11\n13 13\n2 8\n9 16\n6 10\n7 8", "output": "2838" }, { "input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n13 31\n21 27\n9 25\n6 18\n6 8\n28 30\n2 4\n15 21\n1 1\n8 30\n3 31\n11 27\n28 29\n6 22\n20 22\n9 25", "output": "17471" }, { "input": "22 7\n44 41 40 41 37 42 46 16 50 47 30 7 32 6 20 14 47 25 11 1 35 12\n1 10\n10 20\n4 5\n1 8\n2 12\n8 8\n2 16", "output": "2202" }, { "input": "3 2\n1 2 3\n2 3\n1 2", "output": "9" } ]
1,654,779,468
2,147,483,647
Python 3
OK
TESTS
63
701
13,926,400
n, q = map(int, input().split()) a = list(map(int, input().split())) lst = [0]*(n+1) for i in range(q): l, r = map(int, input().split()) lst[l-1] += 1 lst[r] -= 1 p = [0]*n t = 0 for i in range(n): t += lst[i] p[i] = t p.sort(reverse = True) a.sort(reverse = True) ans = 0 for i in range(n): ans += a[i]*p[i] print(ans)
Title: Little Girl and Maximum Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum. Input Specification: The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query. Output Specification: In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3 3\n5 3 2\n1 2\n2 3\n1 3\n', '5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n'] Demo Output: ['25\n', '33\n'] Note: none
```python n, q = map(int, input().split()) a = list(map(int, input().split())) lst = [0]*(n+1) for i in range(q): l, r = map(int, input().split()) lst[l-1] += 1 lst[r] -= 1 p = [0]*n t = 0 for i in range(n): t += lst[i] p[i] = t p.sort(reverse = True) a.sort(reverse = True) ans = 0 for i in range(n): ans += a[i]*p[i] print(ans) ```
3
716
B
Complete the Word
PROGRAMMING
1,300
[ "greedy", "two pointers" ]
null
null
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?
The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.
If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them.
[ "ABC??FGHIJK???OPQR?TUVWXY?\n", "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n", "??????????????????????????\n", "AABCDEFGHIJKLMNOPQRSTUVW??M\n" ]
[ "ABCDEFGHIJKLMNOPQRZTUVWXYS", "-1", "MNBVCXZLKJHGFDSAQPWOEIRUYT", "-1" ]
In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
1,000
[ { "input": "ABC??FGHIJK???OPQR?TUVWXY?", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO", "output": "-1" }, { "input": "??????????????????????????", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "AABCDEFGHIJKLMNOPQRSTUVW??M", "output": "-1" }, { "input": "QWERTYUIOPASDFGHJKL???????", "output": "QWERTYUIOPASDFGHJKLBCMNVXZ" }, { "input": "ABABABBAB????????????ABABABABA???????????ABABABABA?????????KLCSJB?????????Z", "output": "ABABABBABAAAAAAAAAAAAABABABABAAAAAAAAAAAAABABABABADEFGHIMNOKLCSJBPQRTUVWXYZ" }, { "input": "Q?E?T?U?O?A?D?G?J?L?X?V?MMQ?E?T?U?O?A?D?G?J?L?X?V?N", "output": "QAEATAUAOAAADAGAJALAXAVAMMQBECTFUHOIAKDPGRJSLWXYVZN" }, { "input": "???????????????????????????", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZA" }, { "input": "EJMGJAXCHXYIKZSQKUGRCLSTWDLNCVZIGXGWILAVFBEIGOHWGVEPRJTHWEDQRPOVZUQOSRVTIHFFHJMCLOWGHCIGJBCAAVBJFMJEFTEGFXZFVRZOXAFOFVXRAIZEWIKILFLYDZVDADYWYWYJXAGDFGNZBQKKKTGWPINLCDBZVULROGAKEKXXTWNYKQBMLQMQRUYOWUTWMNTJVGUXENHXWMFWMSBKVNGXSNFFTRTTGEGBBHMFZTKNJQDYUQOXVDWTDHZCCQNYYIOFPMKYQIGEEYBCKBAYVCTWARVMHIENKXKFXNXEFUHUNRQPEDFUBMKNQOYCQHGTLRHLWUAVZJDRBRTSVQHBKRDJFKKYEZAJWJKATRFZLNELPYGFUIWBXLIWVTHUILJHTQKDGRNCFTFELCOQPJDBYSPYJOUDKIFRCKEMJPUXTTAMHVENEVMNTZLUYSUALQOUPPRLZHCYICXAQFFRQZAAJNFKVRJDMDXFTBRJSAAHTSVG", "output": "-1" }, { "input": "SVBWLLLPMPJUQVIGVXPCKMPEBPWMYORVTYELJOQGKEOJVCRBUJOOKQZQBYJIBCSHGSDBTIIMNGAXAQJRHHKQFAJSOJLAYRKWBASMLBQVUPPQWDGAVKDLFHEHVVWGSYQHYCPDIECHBTOIFYUFGKWIIMCKEBLECHCETBQMJPBPPGDHRLJIIMVJBZDRSDWWEJASQFRSCLOBAOLZQDPEZWDLMYTGDLUHCJMTXVURWQFCFDIGSUADTFMNGVHRYHQKWBGWWLQJQSFSWXGWIYUTSBUNZFDONBCFTGWTTQIISXJZUWSZWXXFMNB?UWPOWVWIWMBAPXYMGTRSGWMQRXULCMDTUKZS?CNMBRIYDZCUQWAKYQLLJLTXSVMUAYZHVBZFYBABBECIADQPUPZVVYHTGKOWKDNEUYPBTNUSQLLQRODUXFMSYUYIQGERINAPZWL?VKBVQJQLUJGDPFHNVXXSNOWHBZPMLOXVC?IEUMVLIBYLEATFUTILPPTP", "output": "-1" }, { "input": "DMWSBHPGSJJD?EEV?CYAXQCCGNNQWNN?OMEDD?VC?CTKNQQPYXKKJFAYMJ?FMPXXCLKOL?OTRCE", "output": "-1" }, { "input": "EOYJRKFABJIUOZILSHHCXIFQTXAVXJOVTQCDHXPNYPW?RVRKTB?OVXEL?NQHMZZXJLGSA?OTFSZQBV?SBHGKPJPCIQMLRSYDCFPYMEMXUEVHANXELHKSKNLGHGDCYMURXQRWMHEYXXCMGMUFZIPVOZQQBJGVKESTCDZCWFUCSGGIRWMXYXJLFLGUXQAWLZIKFUTVYDGKBVKBKXTICIKHXWFVJRHNMYRJZYNNYXMUOFERZPY?AJKSMUCTLOFH?LV?EHHCHKBHOJZAHFKJHHZJKZIEYAOAPDQRIUWDBMJGOOSNWN?CBKUXJCTEWVTRBDCNFMGBJUAODCCZVPZBQJNIRJVVF?QBWBV?AXOVOYNAWSKUVPHWJK?YPYOKTVFBWAGCC?JOWPPCAZDOYETAYYECWWURYHY?SJHMSJXDIMXFOTUWJLYDKCHOAPLFYPMFYFRNRKWY?CBPLQJJJ?BJYGBJT?FV?VDQEQAUFWZSOJHZFBVEALMMT?XP", "output": "-1" }, { "input": "E?BIVQUPQQEJNMINFD?NKV?IROHPTGUIPMEVYPII?LZJMRI?FTKKKBHPOVQZZSAPDDWVSPVHOBT", "output": "-1" }, { "input": "FDQHJSNDDXHJLWVZVXJZUGKVHWCZVRWVZTIURLMJNGAMCUBDGVSIDEYRJZOLDISDNTOEKLSNLBSOQZLJVPAMLEBAVUNBXNKMLZBGJJQCGCSKBFSEEDXEVSWGZHFJIZJESPZIKIONJWTFFYYZKIDBSDNPJVAUHQMRFKIJWCEGTBVZHWZEKLPHGZVKZFAFAQRNKHGACNRTSXQKKCYBMEMKNKKSURKHOSMEVUXNGOCVCLVVSKULGBKFPCEKVRAJMBWCFFFSCCNDOSEKXEFFZETTUZHMQETWCVZASTTULYOPBNMOMXMVUEEEYZHSMRPAEIHUKNPNJTARJKQKIOXDJASSQPQQHEQIQJQLVPIJRCFVOVECHBOCRYWQEDXZLJXUDZUBFTRWEWNYTSKGDBEBWFFLMUYWELNVAAXSMKYEZXQFKKHJTZKMKMYOBTVXAOVBRMAMHTBDDYMDGQYEEBYZUBMUCKLKXCZGTWVZAYJOXZVGUYNXOVAPXQVE", "output": "-1" }, { "input": "KMNTIOJTLEKZW?JALAZYWYMKWRXTLAKNMDJLICZMETAKHVPTDOLAPCGHOEYSNIUJZVLPBTZ?YSR", "output": "-1" }, { "input": "?MNURVAKIVSOGITVJZEZCAOZEFVNZERAHVNCVCYKTJVEHK?ZMDL?CROLIDFSG?EIFHYKELMQRBVLE?CERELHDVFODJ?LBGJVFPO?CVMPBW?DPGZMVA?BKPXQQCRMKHJWDNAJSGOTGLBNSWMXMKAQ?MWMXCNRSGHTL?LGLAHSDHAGZRGTNDFI?KJ?GSAWOEPOENXTJCVJGMYOFIQKKDWOCIKPGCMFEKNEUPFGBCBYQCM?EQSAX?HZ?MFKAUHOHRKZZSIVZCAKYIKBDJYOCZJRYNLSOKGAEGQRQ?TBURXXLHAFCNVGAUVWBXZILMHWSBYJTIMWPNEGATPURPTJYFWKHRL?QPYUQ?HKDDHWAHOWUSONQKSZFIYFMFUJAMIYAMPNBGVPJSDFDFSAHDWWGEAKXLHBURNTIMCUZIAFAOCVNKPJRNLNGSJVMGKQ?IFQSRHTZGKHGXFJBDGPLCUUMEWNOSCONIVCLAOAPPSFFLCPRIXTKNBSSOVM", "output": "-1" }, { "input": "MRHKVVRBFEIFWIZGWCATJPBSZWNYANEWSSEVFQUUVNJKQOKVIGYBPFSZFTBUCNQEJEYVOWSPYER", "output": "-1" }, { "input": "CNRFBWKRTQTDFOMIGPPGDBHPRNRXFASDDBCZXHORGXDRSIORLJEROJBLLEHLNBILBPX?KHQLCOUPTKUADCDNHNBWMVNUUVUFPIRXSPNUCCRLJTDSUIUDLBKNKMXSAVBJDUGWIMNBIUWJX?TCBDEBNDYUGPS?MQSSEIIUGEE?XXKW?CMFQMWUAEXTSZNNOCPHBAEAKWALYBBMUMQZXUKTQPWNMZKIDECWIZFHKQIUJZRSBZPQFUQNVKQZMYJDHXZWXFHIZ?HWPIPIWV?JMIYKEJDNPMKTTOY?NTOMZZXTNMWQENYRWFYM?WLJJFCIJSETZSJORBZZHAFWYKGQJAPYQQXUWROOZUDOJJLNCDRSGUKYAZLLENGUICGOYPLJQ?POSKHPMOFJMAOXCITWWL?LOEDKHZPQFZZCTB?JYZNXZSDREAMGGXHMCFTQNOUALEYHULSDQVOXZIWFHNNHHG?FYUOCQNKBLFGGZ?YNFNVLRMENYBDWMDSP", "output": "-1" }, { "input": "KSRVTPFVRJWNPYUZMXBRLKVXIQPPBYVSYKRQPNGKTKRPFMKLIYFACFKBIQGPAXLEUESVGPBBXLY", "output": "-1" }, { "input": "LLVYUOXHBHUZSAPUMQEKWSQAFRKSMEENXDQYOPQFXNNFXSRBGXFUIRBFJDSDKQIDMCPPTWRJOZCRHZYZPBVUJPQXHNALAOCJDTTBDZWYDBVPMNSQNVMLHHUJAOIWFSEJEJSRBYREOZKHEXTBAXPTISPGIPOYBFFEJNAKKXAEPNGKWYGEJTNEZIXAWRSCEIRTKNEWSKSGKNIKDEOVXGYVEVFRGTNDFNWIFDRZQEJQZYIWNZXCONVZAKKKETPTPPXZMIVDWPGXOFODRNJZBATKGXAPXYHTUUFFASCHOLSMVSWBIJBAENEGNQTWKKOJUYQNXWDCDXBXBJOOWETWLQMGKHAJEMGXMYNVEHRAEGZOJJQPZGYRHXRNKMSWFYDIZLIBUTSKIKGQJZLGZQFJVIMNOHNZJKWVVPFMFACVXKJKTBZRXRZDJKSWSXBBKWIKEICSZEIPTOJCKJQYYPNUPRNPQNNCVITNXPLAKQBYAIQGNAHXDUQWQLYN", "output": "-1" }, { "input": "PVCKCT?KLTFPIBBIHODCAABEQLJKQECRUJUSHSXPMBEVBKHQTIKQLBLTIRQZPOGPWMMNWWCUKAD", "output": "-1" }, { "input": "BRTYNUVBBWMFDSRXAMLNSBIN???WDDQVPCSWGJTHLRAKTPFKGVLHAKNRIEYIDDRDZLLTBRKXRVRSPBSLXIZRRBEVMHJSAFPLZAIHFVTTEKDO?DYWKILEYRM?VHSEQCBYZZRZMICVZRYA?ONCSZOPGZUMIHJQJPIFX?YJMIERCMKTSFTDZIKEZPLDEOOCJLQIZ?RPHUEQHPNNSBRQRTDGLWNSCZ?WQVIZPTOETEXYI?DRQUOMREPUTOAJKFNBGYNWMGCAOELXEPLLZEYHTVLT?ETJJXLHJMAUDQESNQ?ZCGNDGI?JSGUXQV?QAWQIYKXBKCCSWNRTGHPZF?CSWDQSAZIWQNHOWHYAEZNXRMPAZEQQPPIBQQJEDHJEDHVXNEDETEN?ZHEPJJ?VVDYGPJUWGCBMB?ANFJHJXQVAJWCAZEZXZX?BACPPXORNENMCRMQPIYKNPHX?NSKGEABWWVLHQ?ESWLJUPQJSFIUEGMGHEYVLYEDWJG?L", "output": "-1" }, { "input": "TESTEIGHTYFOUR", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXY", "output": "-1" }, { "input": "?????????????????????????", "output": "-1" }, { "input": "Q?RYJPGLNQ", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRZTUVWXYS", "output": "ABCDEFGHIJKLMNOPQRZTUVWXYS" }, { "input": "AACDEFGHIJKLMNOPQRZTUVWXYS", "output": "-1" }, { "input": "ZA?ABCDEFGHIJKLMNOPQRSTUVWXY", "output": "ZAZABCDEFGHIJKLMNOPQRSTUVWXY" }, { "input": "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXYYYZABC", "output": "-1" }, { "input": "????", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRZTUVWXYS??", "output": "ABCDEFGHIJKLMNOPQRZTUVWXYSAA" }, { "input": "A", "output": "-1" }, { "input": "NKBDABACEFGGGIJLLLLMMMOMPQWZSSRHHTTUWUWVXYY", "output": "-1" }, { "input": "AA", "output": "-1" }, { "input": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXA?CDEFGHIJKLMNOPQRSTUVWXYZ", "output": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "???DEFGHIJKL??L?PQRSTUVW???", "output": "-1" }, { "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", "output": "-1" }, { "input": "A?AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA???????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????", "output": "-1" }, { "input": "ZXXCVBNMLKJHGFDSAQWWERTYUIOP", "output": "-1" }, { "input": "ABCA???????????????????????", "output": "ABCADEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "AB", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "BCDEFGHIAJKLMNOPQARSTUVWXYZ", "output": "-1" }, { "input": "AABBCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "-1" }, { "input": "???AA????????????????????BB???", "output": "-1" }, { "input": "ABC??FGAHIJ??MNOPQRST??WXYZ", "output": "ABCDEFGAHIJKLMNOPQRSTUVWXYZ" }, { "input": "QWERTYUIOPASDFGHJKLZXCVBN", "output": "-1" }, { "input": "??????AAAAAAAAAAAAAAAAAAAABBBBB??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASSSSSSSSFFFFFFF?????????DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD??????WWWWWWWWWWEEEEEEEEEEERRRRRRRRRRRRRRRRRRRRRRRRRHHHHHHHHHH?????", "output": "-1" } ]
1,612,508,272
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
108
409,600
import collections s = input() n = len(s) if n<26: print(-1) exit() d = [0]*26 for i in range(25): if s[i]!='?': d[ord(s[i])-ord('A')]+=1 def check(): return all(d[i]<=1 for i in range(26)) b = False for i in range(25,n): if s[i]!='?': d[ord(s[i])-ord('A')] += 1 if i>=26: if s[i-26]!='?': d[ord(s[i-26])-ord('A')] -= 1 if check(): for j in range(n): if s[j]!='?': print(s[j],end="") else: if j<i-25 or j>i: print('a',end="") else: for k in range(26): if d[k]==0: print(chr(ord('A')+k),end="") d[k]=1 break exit() print(-1)
Title: Complete the Word Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input Specification: The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output Specification: If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Demo Input: ['ABC??FGHIJK???OPQR?TUVWXY?\n', 'WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n', '??????????????????????????\n', 'AABCDEFGHIJKLMNOPQRSTUVW??M\n'] Demo Output: ['ABCDEFGHIJKLMNOPQRZTUVWXYS', '-1', 'MNBVCXZLKJHGFDSAQPWOEIRUYT', '-1'] Note: In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
```python import collections s = input() n = len(s) if n<26: print(-1) exit() d = [0]*26 for i in range(25): if s[i]!='?': d[ord(s[i])-ord('A')]+=1 def check(): return all(d[i]<=1 for i in range(26)) b = False for i in range(25,n): if s[i]!='?': d[ord(s[i])-ord('A')] += 1 if i>=26: if s[i-26]!='?': d[ord(s[i-26])-ord('A')] -= 1 if check(): for j in range(n): if s[j]!='?': print(s[j],end="") else: if j<i-25 or j>i: print('a',end="") else: for k in range(26): if d[k]==0: print(chr(ord('A')+k),end="") d[k]=1 break exit() print(-1) ```
0
379
A
New Year Candles
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Print a single integer — the number of hours Vasily can light up the room for.
[ "4 2\n", "6 3\n" ]
[ "7\n", "8\n" ]
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
500
[ { "input": "4 2", "output": "7" }, { "input": "6 3", "output": "8" }, { "input": "1000 1000", "output": "1001" }, { "input": "123 5", "output": "153" }, { "input": "1000 2", "output": "1999" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "1 4", "output": "1" }, { "input": "2 2", "output": "3" }, { "input": "3 2", "output": "5" }, { "input": "3 3", "output": "4" }, { "input": "999 2", "output": "1997" }, { "input": "1000 3", "output": "1499" }, { "input": "1000 4", "output": "1333" }, { "input": "1 1000", "output": "1" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "10 4", "output": "13" }, { "input": "4 3", "output": "5" }, { "input": "91 5", "output": "113" }, { "input": "777 17", "output": "825" }, { "input": "100 4", "output": "133" }, { "input": "5 3", "output": "7" }, { "input": "6 4", "output": "7" }, { "input": "26 8", "output": "29" }, { "input": "9 4", "output": "11" }, { "input": "20 3", "output": "29" }, { "input": "17 3", "output": "25" } ]
1,649,662,824
2,147,483,647
Python 3
OK
TESTS
32
46
0
import math (a,b) = map(int,input().split()) print(a + (a-1)//(b-1))
Title: New Year Candles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. Input Specification: The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). Output Specification: Print a single integer — the number of hours Vasily can light up the room for. Demo Input: ['4 2\n', '6 3\n'] Demo Output: ['7\n', '8\n'] Note: Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
```python import math (a,b) = map(int,input().split()) print(a + (a-1)//(b-1)) ```
3
934
B
A Prosperous Lot
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside. Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony. He would like to find a positive integer *n* not greater than 1018, such that there are exactly *k* loops in the decimal representation of *n*, or determine that such *n* does not exist. A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.
The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops.
Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018.
[ "2\n", "6\n" ]
[ "462", "8080" ]
none
1,000
[ { "input": "2", "output": "8" }, { "input": "6", "output": "888" }, { "input": "3", "output": "86" }, { "input": "4", "output": "88" }, { "input": "5", "output": "886" }, { "input": "1000000", "output": "-1" }, { "input": "1", "output": "6" }, { "input": "7", "output": "8886" }, { "input": "8", "output": "8888" }, { "input": "9", "output": "88886" }, { "input": "10", "output": "88888" }, { "input": "11", "output": "888886" }, { "input": "12", "output": "888888" }, { "input": "13", "output": "8888886" }, { "input": "14", "output": "8888888" }, { "input": "15", "output": "88888886" }, { "input": "16", "output": "88888888" }, { "input": "17", "output": "888888886" }, { "input": "18", "output": "888888888" }, { "input": "19", "output": "8888888886" }, { "input": "20", "output": "8888888888" }, { "input": "21", "output": "88888888886" }, { "input": "22", "output": "88888888888" }, { "input": "23", "output": "888888888886" }, { "input": "24", "output": "888888888888" }, { "input": "25", "output": "8888888888886" }, { "input": "26", "output": "8888888888888" }, { "input": "27", "output": "88888888888886" }, { "input": "28", "output": "88888888888888" }, { "input": "29", "output": "888888888888886" }, { "input": "30", "output": "888888888888888" }, { "input": "31", "output": "8888888888888886" }, { "input": "32", "output": "8888888888888888" }, { "input": "33", "output": "88888888888888886" }, { "input": "34", "output": "88888888888888888" }, { "input": "35", "output": "888888888888888886" }, { "input": "36", "output": "888888888888888888" }, { "input": "37", "output": "-1" }, { "input": "38", "output": "-1" }, { "input": "39", "output": "-1" }, { "input": "40", "output": "-1" }, { "input": "462", "output": "-1" }, { "input": "1317", "output": "-1" }, { "input": "88", "output": "-1" }, { "input": "87", "output": "-1" } ]
1,585,131,546
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
10,649,600
n = int(input()) if n > 36: print(-1) ans = '' while n >= 2: ans += '8' n -= 2 while n >= 1: ans += '4' n -= 1 if int(ans) > 10**18: print(-1) else: print(ans)
Title: A Prosperous Lot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside. Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony. He would like to find a positive integer *n* not greater than 1018, such that there are exactly *k* loops in the decimal representation of *n*, or determine that such *n* does not exist. A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms. Input Specification: The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. Output Specification: Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. Demo Input: ['2\n', '6\n'] Demo Output: ['462', '8080'] Note: none
```python n = int(input()) if n > 36: print(-1) ans = '' while n >= 2: ans += '8' n -= 2 while n >= 1: ans += '4' n -= 1 if int(ans) > 10**18: print(-1) else: print(ans) ```
0
15
A
Cottage Village
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Cottage Village
2
64
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?
The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000).
Output the amount of possible positions of the new house.
[ "2 2\n0 4\n6 2\n", "2 2\n0 4\n5 2\n", "2 3\n0 4\n5 2\n" ]
[ "4\n", "3\n", "2\n" ]
It is possible for the *x*-coordinate of the new house to have non-integer value.
0
[ { "input": "2 2\n0 4\n6 2", "output": "4" }, { "input": "2 2\n0 4\n5 2", "output": "3" }, { "input": "2 3\n0 4\n5 2", "output": "2" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 2\n2 1", "output": "2" }, { "input": "2 1\n2 1\n1 1", "output": "2" }, { "input": "2 2\n0 4\n7 4", "output": "4" }, { "input": "4 1\n-12 1\n-14 1\n4 1\n-11 1", "output": "5" }, { "input": "6 15\n19 1\n2 3\n6 2\n-21 2\n-15 2\n23 1", "output": "2" }, { "input": "10 21\n-61 6\n55 2\n-97 1\n37 1\n-39 1\n26 2\n21 1\n64 3\n-68 1\n-28 6", "output": "6" }, { "input": "26 51\n783 54\n-850 6\n-997 59\n573 31\n-125 20\n472 52\n101 5\n-561 4\n625 35\n911 14\n-47 33\n677 55\n-410 54\n13 53\n173 31\n968 30\n-497 7\n832 42\n271 59\n-638 52\n-301 51\n378 36\n-813 7\n-206 22\n-737 37\n-911 9", "output": "35" }, { "input": "14 101\n121 88\n-452 91\n635 28\n-162 59\n-872 26\n-996 8\n468 86\n742 63\n892 89\n-249 107\n300 51\n-753 17\n-620 31\n-13 34", "output": "16" }, { "input": "3 501\n827 327\n-85 480\n-999 343", "output": "6" }, { "input": "2 999\n-999 471\n530 588", "output": "4" }, { "input": "22 54\n600 43\n806 19\n-269 43\n-384 78\n222 34\n392 10\n318 30\n488 73\n-756 49\n-662 22\n-568 50\n-486 16\n-470 2\n96 66\n864 16\n934 15\n697 43\n-154 30\n775 5\n-876 71\n-33 78\n-991 31", "output": "30" }, { "input": "17 109\n52 7\n216 24\n-553 101\n543 39\n391 92\n-904 67\n95 34\n132 14\n730 103\n952 118\n-389 41\n-324 36\n-74 2\n-147 99\n-740 33\n233 1\n-995 3", "output": "16" }, { "input": "4 512\n-997 354\n-568 216\n-234 221\n603 403", "output": "4" }, { "input": "3 966\n988 5\n15 2\n-992 79", "output": "6" }, { "input": "2 1000\n-995 201\n206 194", "output": "4" }, { "input": "50 21\n-178 1\n49 1\n-98 1\n-220 1\n152 1\n-160 3\n17 2\n77 1\n-24 1\n214 2\n-154 2\n-141 1\n79 1\n206 1\n8 1\n-208 1\n36 1\n231 3\n-2 2\n-130 2\n-14 2\n34 1\n-187 2\n14 1\n-83 2\n-241 1\n149 2\n73 1\n-233 3\n-45 1\n197 1\n145 2\n-127 2\n-229 4\n-85 1\n-66 1\n-76 2\n104 1\n175 1\n70 1\n131 3\n-108 1\n-5 4\n140 1\n33 1\n248 3\n-36 3\n134 1\n-183 1\n56 2", "output": "9" }, { "input": "50 1\n37 1\n-38 1\n7 1\n47 1\n-4 1\n24 1\n-32 1\n-23 1\n-3 1\n-19 1\n5 1\n-50 1\n11 1\n-11 1\n49 1\n-39 1\n0 1\n43 1\n-10 1\n6 1\n19 1\n1 1\n27 1\n29 1\n-47 1\n-40 1\n-46 1\n-26 1\n-42 1\n-37 1\n13 1\n-29 1\n-30 1\n3 1\n44 1\n10 1\n4 1\n-14 1\n-2 1\n34 1\n18 1\n-33 1\n-44 1\n9 1\n-36 1\n-7 1\n25 1\n22 1\n-20 1\n-41 1", "output": "43" }, { "input": "50 1\n-967 7\n696 7\n-366 4\n557 1\n978 2\n800 4\n-161 2\n-773 2\n-248 2\n134 3\n869 6\n-932 2\n-262 14\n191 3\n669 2\n72 5\n0 1\n757 8\n859 2\n-131 8\n-169 3\n543 10\n-120 2\n-87 8\n-936 6\n-620 3\n-281 11\n684 3\n886 10\n497 4\n380 4\n833 1\n-727 6\n470 11\n584 9\n66 6\n-609 12\n-661 4\n-57 8\n628 7\n635 4\n-924 3\n-982 4\n-201 7\n-9 8\n-560 9\n712 7\n-330 8\n-191 1\n-892 7", "output": "96" }, { "input": "1 1000\n0 1000", "output": "2" } ]
1,619,761,397
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
154
0
N, T = map(int, input().split()) def read_houses(): for _ in range(N): yield tuple(map(int, input().split())) houses = list(read_houses()) houses.sort() count = 2 # borders left and right for (a, x), (b, y) in zip(houses, houses[1:]): if b-a > x/2+y/2: count += 2 if b-a == x/2+y/2: count += 1 print(count)
Title: Cottage Village Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input Specification: The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000). Output Specification: Output the amount of possible positions of the new house. Demo Input: ['2 2\n0 4\n6 2\n', '2 2\n0 4\n5 2\n', '2 3\n0 4\n5 2\n'] Demo Output: ['4\n', '3\n', '2\n'] Note: It is possible for the *x*-coordinate of the new house to have non-integer value.
```python N, T = map(int, input().split()) def read_houses(): for _ in range(N): yield tuple(map(int, input().split())) houses = list(read_houses()) houses.sort() count = 2 # borders left and right for (a, x), (b, y) in zip(houses, houses[1:]): if b-a > x/2+y/2: count += 2 if b-a == x/2+y/2: count += 1 print(count) ```
0
948
A
Protect Sheep
PROGRAMMING
900
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected. The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog. Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number.
First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively. Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell.
If it is impossible to protect all sheep, output a single line with the word "No". Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf. If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs.
[ "6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n", "1 2\nSW\n", "5 5\n.S...\n...S.\nS....\n...S.\n.S...\n" ]
[ "Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n", "No\n", "Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n" ]
In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally. In the second example, there are no empty spots to put dogs that would guard the lone sheep. In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him.
500
[ { "input": "1 2\nSW", "output": "No" }, { "input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S", "output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSDDSDSDS\nSSDDDDDDDS" }, { "input": "10 10\n....W.W.W.\n...W.....S\n.S.S...S..\nW......WSS\n.W..W.....\n.W...W....\nS..S...S.S\n...WWW..S.\n..S..S.S.S\nSS.......S", "output": "No" }, { "input": "1 50\nW...S..............W.....S..S...............S...W.", "output": "Yes\nWDDDSDDDDDDDDDDDDDDWDDDDDSDDSDDDDDDDDDDDDDDDSDDDWD" }, { "input": "2 4\n...S\n...W", "output": "No" }, { "input": "4 2\n..\n..\n..\nSW", "output": "No" }, { "input": "4 2\n..\n..\n..\nWS", "output": "No" }, { "input": "2 4\n...W\n...S", "output": "No" }, { "input": "50 1\nS\n.\n.\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\n.\nS\n.\nW\n.\nS\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\nW\n.\n.\n.\nW\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.", "output": "Yes\nS\nD\nD\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nD\nS\nD\nW\nD\nS\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nW\nD\nD\nD\nW\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD" }, { "input": "4 4\nW..S\nW..S\nW..S\nW..S", "output": "Yes\nWDDS\nWDDS\nWDDS\nWDDS" }, { "input": "4 4\nSSSS\n....\n....\nWWWW", "output": "Yes\nSSSS\nDDDD\nDDDD\nWWWW" }, { "input": "4 4\nWWWW\n....\n....\nSSSS", "output": "Yes\nWWWW\nDDDD\nDDDD\nSSSS" }, { "input": "4 4\nS..W\nS..W\nS..W\nS..W", "output": "Yes\nSDDW\nSDDW\nSDDW\nSDDW" }, { "input": "1 1\n.", "output": "Yes\nD" }, { "input": "1 1\nW", "output": "Yes\nW" }, { "input": "1 1\nS", "output": "Yes\nS" }, { "input": "4 2\n..\n..\n.W\n.S", "output": "No" }, { "input": "4 2\n..\n..\n.S\n.W", "output": "No" }, { "input": "4 2\n..\n..\nW.\nS.", "output": "No" }, { "input": "4 2\n..\n..\nS.\nW.", "output": "No" }, { "input": "2 4\n....\n..SW", "output": "No" }, { "input": "2 4\n....\n..WS", "output": "No" }, { "input": "1 2\nS.", "output": "Yes\nSD" } ]
1,550,229,357
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
0
f=lambda:map(int,input().split()) r,c=f() l=[] for i in range(r): s=input().replace('.','D') l.append(s) for i in range(r): if 'SW' in l[i] or 'WS' in l[i]: exit(print('No')) for i in range(1,r): for j in range(c): print(l[i][j],l[i-1][j]) if [l[i][j],l[i-1][j]]==['W','S'] or [l[i][j],l[i-1][j]]==['S','W']: exit(print('NO')) print('Yes') for i in range(r): print(l[i])
Title: Protect Sheep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected. The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog. Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number. Input Specification: First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively. Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell. Output Specification: If it is impossible to protect all sheep, output a single line with the word "No". Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf. If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs. Demo Input: ['6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n', '1 2\nSW\n', '5 5\n.S...\n...S.\nS....\n...S.\n.S...\n'] Demo Output: ['Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n', 'No\n', 'Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n'] Note: In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally. In the second example, there are no empty spots to put dogs that would guard the lone sheep. In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him.
```python f=lambda:map(int,input().split()) r,c=f() l=[] for i in range(r): s=input().replace('.','D') l.append(s) for i in range(r): if 'SW' in l[i] or 'WS' in l[i]: exit(print('No')) for i in range(1,r): for j in range(c): print(l[i][j],l[i-1][j]) if [l[i][j],l[i-1][j]]==['W','S'] or [l[i][j],l[i-1][j]]==['S','W']: exit(print('NO')) print('Yes') for i in range(r): print(l[i]) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,692,860,876
2,147,483,647
Python 3
OK
TESTS
20
46
0
n, m, a = map(int, input().split()) # Read n, m, and a # Calculate the number of flagstones needed for each dimension flagstones_n = (n + a - 1) // a # Round up division flagstones_m = (m + a - 1) // a # Round up division # Calculate the total number of flagstones needed total_flagstones = flagstones_n * flagstones_m print(total_flagstones) # Print the result
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n, m, a = map(int, input().split()) # Read n, m, and a # Calculate the number of flagstones needed for each dimension flagstones_n = (n + a - 1) // a # Round up division flagstones_m = (m + a - 1) // a # Round up division # Calculate the total number of flagstones needed total_flagstones = flagstones_n * flagstones_m print(total_flagstones) # Print the result ```
3.977
932
A
Palindromic Supersequence
PROGRAMMING
800
[ "constructive algorithms" ]
null
null
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest". A palindrome is a string that reads the same forward or backward. The length of string *B* should be at most 104. It is guaranteed that there always exists such string. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104.
First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*.
Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them.
[ "aba\n", "ab\n" ]
[ "aba", "aabaa" ]
In the first example, "aba" is a subsequence of "aba" which is a palindrome. In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.
500
[ { "input": "aba", "output": "abaaba" }, { "input": "ab", "output": "abba" }, { "input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpa", "output": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpaapkxovfyaifzjikpcxhemrcpwhypaabnoeifgfygtiqvuoihntvuvbrlnkywutodwrmvgrumdjzqhfoenxphzrdgtwmljdm..." }, { "input": "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadco", "output": "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadcoocdafcilhkrgpvtsyrmzilywzgrtebnaldqqcmrfvsfehjkbetprwlvyscuxef..." }, { "input": "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxar", "output": "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxarraxluhthchsyjjpegbmmzflbvzbunpfhzruoghtlgtearurzueovxcivvfbqlssonqkjiybmbjbzpffixfcdwbrpwyhvzbdjmchzjfnrjdoupimgkyyhfgppveltacqczktdxkawpzdmkmyikyjtqznvjdnkkmikemtyjsgdlheyjltiwcxpfvxqtxwwvgkjcrzbkxkandsekqwxpequ..." }, { "input": "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjg", "output": "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjggjferujlznjmyalmuspib..." }, { "input": "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgm", "output": "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgmmgszzmttxopywvrbvmgavsgwqergikztssmlnktgpolmcbrropknnkeiytztyrlqthshvbosemmjbzpsvcytuzynrqygcfoqsywdkrvjftdagjdgjyynfkcdkmwaqhzfewry..." }, { "input": "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyj", "output": "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyjjycqccvmgjgqjfbxjzrdgbsqyseehcjsyxlbrettpfcjdvjerwvaixetfjxjxkdwcwlmwqkrgrhwzopjnilmonwtxsdonvyuazaqghlplvlisqdqbpvxkjpovqohbarttqoqm..." }, { "input": "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgd", "output": "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgddgmsixjxsmwpfzyxrnkjqrbrfyprvlvbegdmgsidepusixegsdukxmudmjuqqzkefrzymgkluqqrigtpmznhvswwhqbiiizogjofdvfqdrfabswiclfpkiermnozbdmxieoxornesifoiuxgffjelsvcoofviyorrpwkffvvfjaubzeuzqbdhfjgujqoejsktzfzaypaxipweiawzojidcustlgyfhkbfgwshbdkzneilwwqemqblw..." }, { "input": "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohlig", "output": "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohliggilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlw..." }, { "input": "abcab", "output": "abcabbacba" }, { "input": "baaaaaaa", "output": "baaaaaaaaaaaaaab" }, { "input": "baaaaaa", "output": "baaaaaaaaaaaab" }, { "input": "baaaaaaaaa", "output": "baaaaaaaaaaaaaaaaaab" }, { "input": "baaaaaaaa", "output": "baaaaaaaaaaaaaaaab" } ]
1,518,981,150
1,230
Python 3
OK
TESTS
48
61
5,632,000
#author @karngyan s=input() s=s+s[-1:-len(s)-1:-1] print(s)
Title: Palindromic Supersequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest". A palindrome is a string that reads the same forward or backward. The length of string *B* should be at most 104. It is guaranteed that there always exists such string. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. Input Specification: First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. Output Specification: Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. Demo Input: ['aba\n', 'ab\n'] Demo Output: ['aba', 'aabaa'] Note: In the first example, "aba" is a subsequence of "aba" which is a palindrome. In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.
```python #author @karngyan s=input() s=s+s[-1:-len(s)-1:-1] print(s) ```
3
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "output": "11 13" }, { "input": "17", "output": "8 9" }, { "input": "10", "output": "3 7" }, { "input": "69", "output": "34 35" }, { "input": "100", "output": "49 51" }, { "input": "57", "output": "28 29" }, { "input": "1000", "output": "499 501" }, { "input": "999", "output": "499 500" }, { "input": "998", "output": "497 501" }, { "input": "997", "output": "498 499" }, { "input": "996", "output": "497 499" }, { "input": "995", "output": "497 498" }, { "input": "994", "output": "495 499" }, { "input": "5", "output": "2 3" }, { "input": "6", "output": "1 5" }, { "input": "8", "output": "3 5" }, { "input": "9", "output": "4 5" }, { "input": "423", "output": "211 212" }, { "input": "876", "output": "437 439" }, { "input": "29", "output": "14 15" } ]
1,505,057,511
2,147,483,647
Python 3
OK
TESTS
26
62
0
n=int(input()) if n%2:print(int(n/2),int(n/2)+1) elif int(n/2)%2:print(int(n/2)-2,int(n/2)+2) else:print(int(n/2)-1,int(n/2)+1)
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. Input Specification: In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. Output Specification: Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. Demo Input: ['3\n', '4\n', '12\n'] Demo Output: ['1 2\n', '1 3\n', '5 7\n'] Note: none
```python n=int(input()) if n%2:print(int(n/2),int(n/2)+1) elif int(n/2)%2:print(int(n/2)-2,int(n/2)+2) else:print(int(n/2)-1,int(n/2)+1) ```
3
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "output": "19" }, { "input": "10 9", "output": "11" }, { "input": "100 100", "output": "101" }, { "input": "2 27", "output": "2" }, { "input": "99 100", "output": "99" }, { "input": "99 2", "output": "197" }, { "input": "100 3", "output": "149" }, { "input": "98 3", "output": "146" }, { "input": "4 4", "output": "5" }, { "input": "100 2", "output": "199" }, { "input": "62 4", "output": "82" }, { "input": "99 10", "output": "109" }, { "input": "100 5", "output": "124" }, { "input": "80 80", "output": "81" }, { "input": "95 16", "output": "101" }, { "input": "75 16", "output": "79" }, { "input": "99 74", "output": "100" }, { "input": "20 21", "output": "20" }, { "input": "52 96", "output": "52" }, { "input": "24 5", "output": "29" } ]
1,660,545,325
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
46
0
n,m=map(int,input().split()) x=n//m c=0 i=1 while(x>0): c+=1 x=x-1 if(i%m==0): x+=1 i+=1 print(n+c)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? Input Specification: The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['2 2\n', '9 3\n'] Demo Output: ['3\n', '13\n'] Note: In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
```python n,m=map(int,input().split()) x=n//m c=0 i=1 while(x>0): c+=1 x=x-1 if(i%m==0): x+=1 i+=1 print(n+c) ```
0
465
A
inc ARG
PROGRAMMING
900
[ "implementation" ]
null
null
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell. The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.
Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.
[ "4\n1100\n", "4\n1111\n" ]
[ "3\n", "4\n" ]
In the first sample the cell ends up with value 0010, in the second sample — with 0000.
500
[ { "input": "4\n1100", "output": "3" }, { "input": "4\n1111", "output": "4" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "1" }, { "input": "2\n01", "output": "1" }, { "input": "2\n10", "output": "2" }, { "input": "2\n11", "output": "2" }, { "input": "10\n0000000000", "output": "1" }, { "input": "20\n11111111110110001100", "output": "11" }, { "input": "50\n01011110100010000001010000100001001101001101101011", "output": "1" }, { "input": "60\n111111111101111111111111111111111111111111111111111111111111", "output": "11" }, { "input": "60\n111111111111111111111111111111111111111111111111111111111111", "output": "60" }, { "input": "66\n111111010010011001110011000111000100011110011001111110011111111101", "output": "7" }, { "input": "90\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "91\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "2" }, { "input": "92\n11111111101011111011111111111111111111111011101111111111011111111111111101111111101011111101", "output": "10" }, { "input": "100\n0001011110100011001100100010111001000001111101101001001001001011110100101101010000000110100101110010", "output": "1" }, { "input": "100\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "100" }, { "input": "100\n1011001110001000011111110011000100001110010110111101110110011011011000010100110001111100000010110010", "output": "2" }, { "input": "100\n1101111011001111111111110011110111101110111111111111111111111111111111011111111111110111111111111111", "output": "3" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "100" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110", "output": "100" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101", "output": "99" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000", "output": "96" }, { "input": "100\n1111111111111111111111111111111110011000110110001010101100100100001000010010010010000100110000010101", "output": "34" } ]
1,695,832,864
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
import math L=list(map(int,input().split())) x=int(math.pow(L[0],L[1]))//ulhkgiu y=int(math.pow(L[1],L[0])) print(x+y);
Title: inc ARG Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell. The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit. Output Specification: Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. Demo Input: ['4\n1100\n', '4\n1111\n'] Demo Output: ['3\n', '4\n'] Note: In the first sample the cell ends up with value 0010, in the second sample — with 0000.
```python import math L=list(map(int,input().split())) x=int(math.pow(L[0],L[1]))//ulhkgiu y=int(math.pow(L[1],L[0])) print(x+y); ```
-1
262
B
Roma and Changing Signs
PROGRAMMING
1,200
[ "greedy" ]
null
null
Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order.
In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes.
[ "3 2\n-1 -1 1\n", "3 1\n-1 -1 1\n" ]
[ "3\n", "1\n" ]
In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
1,000
[ { "input": "3 2\n-1 -1 1", "output": "3" }, { "input": "3 1\n-1 -1 1", "output": "1" }, { "input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343", "output": "81852" }, { "input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -8981 -8521 -8313 -8257 -8253 -7591 -7587 -7301 -7161 -7001 -6847 -6441 -6241 -5949 -5896 -5713 -5692 -5644 -5601 -5545 -5525 -5331 -5253 -5041 -5000 -4951 -4855 -4384 -4293 -4251 -4001 -3991 -3762 -3544 -3481 -3261 -2983 -2882 -2857 -2713 -2691 -2681 -2653 -2221 -2043 -2011 -1997 -1601 -1471 -1448 -1363 -1217 -1217 -1129 -961 -926 -801 -376 -327 -305 -174 -91", "output": "102443" }, { "input": "12 28\n-6652 -6621 -6471 -5559 -5326 -4551 -4401 -4326 -3294 -1175 -1069 -43", "output": "49488" }, { "input": "78 13\n-9961 -9922 -9817 -9813 -9521 -9368 -9361 -9207 -9153 -9124 -9008 -8981 -8951 -8911 -8551 -8479 -8245 -8216 -7988 -7841 -7748 -7741 -7734 -7101 -6846 -6804 -6651 -6526 -6519 -6463 -6297 -6148 -6090 -5845 -5209 -5201 -5161 -5061 -4537 -4529 -4433 -4370 -4266 -4189 -4125 -3945 -3843 -3777 -3751 -3476 -3461 -3279 -3205 -3001 -2889 -2761 -2661 -2521 -2481 -2305 -2278 -2269 -2225 -1648 -1524 -1476 -1353 -1097 -867 -785 -741 -711 -692 -440 -401 -225 -65 -41", "output": "-147832" }, { "input": "4 1\n218 3441 4901 7601", "output": "15725" }, { "input": "73 26\n-8497 -8363 -7603 -7388 -6830 -6827 -6685 -6389 -6237 -6099 -6013 -5565 -5465 -4965 -4947 -4201 -3851 -3793 -3421 -3410 -3201 -3169 -3156 -2976 -2701 -2623 -2321 -2169 -1469 -1221 -950 -926 -9 47 236 457 773 1321 1485 1545 1671 1736 2014 2137 2174 2301 2625 3181 3536 3851 4041 4685 4981 4987 5145 5163 5209 5249 6011 6337 6790 7254 7361 7407 7969 7982 8083 8251 8407 8735 9660 9855 9957", "output": "315919" }, { "input": "53 5\n-9821 -9429 -9146 -8973 -8807 -8801 -8321 -7361 -7222 -7161 -6913 -5961 -4877 -4756 -4753 -4661 -3375 -3031 -2950 -2661 -2161 -2041 -1111 -1071 -905 -697 -397 323 772 1617 1752 2736 2737 3201 3465 4029 4121 4463 4561 4637 4814 6119 6610 6641 6961 7217 7523 8045 8610 8915 9004 9265 9576", "output": "92703" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n10000", "output": "-10000" }, { "input": "1 2\n-1", "output": "-1" }, { "input": "2 1\n0 1", "output": "1" }, { "input": "2 2\n-1 0", "output": "1" }, { "input": "5 6\n-3 -2 -1 5 6", "output": "15" }, { "input": "3 3\n-50 -10 30", "output": "70" }, { "input": "4 4\n-100 -90 -80 1", "output": "269" }, { "input": "4 3\n-3 -2 1 2", "output": "6" }, { "input": "6 4\n-6 -3 -2 1 2 3", "output": "15" }, { "input": "5 6\n-10 -9 -8 1 2", "output": "28" }, { "input": "1 2\n1", "output": "1" }, { "input": "2 2\n-1 3", "output": "2" }, { "input": "4 7\n-3 -2 1 6", "output": "10" }, { "input": "4 3\n-7 -6 1 5", "output": "17" }, { "input": "4 4\n-5 -1 1 2", "output": "9" } ]
1,609,921,349
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
312
307,200
import math from collections import defaultdict as dt from sys import stdin inp = lambda : stdin.readline().strip()#input() intinp = lambda : int(inp())#int(input()) mod = int(1e9)+7 inf = float("inf") listinp= lambda : list(map(int,stdin.readline().split()))#list(input()) mapinp = lambda : map(int,stdin.readline().split())#map(input()) def ce(a,k): if(a%k==0):return a//k else:return a//k+1 ##### Code Goes hear ##################### for _ in range(1): # n,x=mapinp() n,k=mapinp() a=listinp() a.sort() i=0 while(k>0 and i<n and a[i]<=0 ): a[i]*=-1 k-=1;i+=1 i-=1 # print(a) if(k>0 and k%2==1): a[i]*=-1 # print(a) print(sum(a))
Title: Roma and Changing Signs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output Specification: In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. Demo Input: ['3 2\n-1 -1 1\n', '3 1\n-1 -1 1\n'] Demo Output: ['3\n', '1\n'] Note: In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
```python import math from collections import defaultdict as dt from sys import stdin inp = lambda : stdin.readline().strip()#input() intinp = lambda : int(inp())#int(input()) mod = int(1e9)+7 inf = float("inf") listinp= lambda : list(map(int,stdin.readline().split()))#list(input()) mapinp = lambda : map(int,stdin.readline().split())#map(input()) def ce(a,k): if(a%k==0):return a//k else:return a//k+1 ##### Code Goes hear ##################### for _ in range(1): # n,x=mapinp() n,k=mapinp() a=listinp() a.sort() i=0 while(k>0 and i<n and a[i]<=0 ): a[i]*=-1 k-=1;i+=1 i-=1 # print(a) if(k>0 and k%2==1): a[i]*=-1 # print(a) print(sum(a)) ```
0
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output": "1" }, { "input": "86", "output": "2" }, { "input": "2", "output": "0" }, { "input": "8", "output": "0" }, { "input": "34", "output": "1" }, { "input": "13", "output": "1" }, { "input": "28", "output": "2" }, { "input": "23", "output": "1" }, { "input": "57", "output": "2" }, { "input": "29", "output": "2" }, { "input": "353869285", "output": "3" }, { "input": "549548646", "output": "2" }, { "input": "858893424", "output": "2" }, { "input": "644818852", "output": "3" }, { "input": "360322525", "output": "3" }, { "input": "122937520", "output": "2" }, { "input": "288403032", "output": "2" }, { "input": "677257481", "output": "3" }, { "input": "58059561", "output": "3" }, { "input": "211288847", "output": "2" }, { "input": "339900034079539584", "output": "2" }, { "input": "784084029310269952", "output": "3" }, { "input": "774730557264864000", "output": "3" }, { "input": "478233807148352256", "output": "3" }, { "input": "165646874056812544", "output": "3" }, { "input": "477533739511673792", "output": "3" }, { "input": "660119944377002240", "output": "3" }, { "input": "448375218506078080", "output": "3" }, { "input": "77213334785795616", "output": "3" }, { "input": "165767221702271872", "output": "3" }, { "input": "1", "output": "0" }, { "input": "5", "output": "0" }, { "input": "8", "output": "0" }, { "input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561", "output": "3" }, { "input": "9", "output": "0" } ]
1,653,054,544
2,147,483,647
Python 3
OK
TESTS
51
124
1,638,400
nos = input() po = 0 while True: if len(nos) == 1: print(po) break else: nos = str(sum(list(map(int,list(nos))))) po+=1
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? Input Specification: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. Output Specification: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Demo Input: ['0\n', '10\n', '991\n'] Demo Output: ['0\n', '1\n', '3\n'] Note: In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
```python nos = input() po = 0 while True: if len(nos) == 1: print(po) break else: nos = str(sum(list(map(int,list(nos))))) po+=1 ```
3.966052
128
B
String
PROGRAMMING
2,100
[ "brute force", "constructive algorithms", "hashing", "implementation", "string suffix structures", "strings" ]
null
null
One day in the IT lesson Anna and Maria learned about the lexicographic order. String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min*(|*x*|,<=|*y*|)), that *x**i*<=&lt;<=*y**i*, and for any *j* (1<=≤<=*j*<=&lt;<=*i*) *x**j*<==<=*y**j*. Here |*a*| denotes the length of the string *a*. The lexicographic comparison of strings is implemented by operator &lt; in modern programming languages​​. The teacher gave Anna and Maria homework. She gave them a string of length *n*. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the *k*-th string from the list. Help Anna and Maria do the homework.
The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer *k* (1<=≤<=*k*<=≤<=105).
Print the string Anna and Maria need — the *k*-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than *k*, print a string saying "No such line." (without the quotes).
[ "aa\n2\n", "abc\n5\n", "abab\n7\n" ]
[ "a\n", "bc\n", "b\n" ]
In the second sample before string "bc" follow strings "a", "ab", "abc", "b".
1,500
[ { "input": "aa\n2", "output": "a" }, { "input": "abc\n5", "output": "bc" }, { "input": "abab\n7", "output": "b" }, { "input": "codeforces\n1", "output": "c" }, { "input": "cccc\n8", "output": "ccc" }, { "input": "abcdefghijklmnopqrstuvwxyz\n27", "output": "b" }, { "input": "cba\n6", "output": "cba" }, { "input": "z\n100000", "output": "No such line." }, { "input": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n17416", "output": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk" }, { "input": "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n32912", "output": "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu" }, { "input": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n84480", "output": "No such line." }, { "input": "llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll\n83252", "output": "No such line." }, { "input": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n18883", "output": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" }, { "input": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n14594", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n87315", "output": "No such line." }, { "input": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n27016", "output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" }, { "input": "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n9184", "output": "ssssssssssssssssssssssssssss" }, { "input": "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n99590", "output": "No such line." }, { "input": "aaaaaaaaaa\n90", "output": "No such line." } ]
1,462,771,880
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
17,612,800
from queue import PriorityQueue oristr = input() check = int(input()) strlen = len(oristr) result = PriorityQueue() if check > strlen * (strlen + 1)/2: print("No such line.") else: for i in range(strlen): result.put([oristr[i], i]) while check > 0: tem = result.get() check -= 1 if tem[1] < (strlen-1): temp = [tem[0] + oristr[tem[1]+1], tem[1]+1] result.put(temp) print(tem[0])
Title: String Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day in the IT lesson Anna and Maria learned about the lexicographic order. String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min*(|*x*|,<=|*y*|)), that *x**i*<=&lt;<=*y**i*, and for any *j* (1<=≤<=*j*<=&lt;<=*i*) *x**j*<==<=*y**j*. Here |*a*| denotes the length of the string *a*. The lexicographic comparison of strings is implemented by operator &lt; in modern programming languages​​. The teacher gave Anna and Maria homework. She gave them a string of length *n*. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the *k*-th string from the list. Help Anna and Maria do the homework. Input Specification: The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer *k* (1<=≤<=*k*<=≤<=105). Output Specification: Print the string Anna and Maria need — the *k*-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than *k*, print a string saying "No such line." (without the quotes). Demo Input: ['aa\n2\n', 'abc\n5\n', 'abab\n7\n'] Demo Output: ['a\n', 'bc\n', 'b\n'] Note: In the second sample before string "bc" follow strings "a", "ab", "abc", "b".
```python from queue import PriorityQueue oristr = input() check = int(input()) strlen = len(oristr) result = PriorityQueue() if check > strlen * (strlen + 1)/2: print("No such line.") else: for i in range(strlen): result.put([oristr[i], i]) while check > 0: tem = result.get() check -= 1 if tem[1] < (strlen-1): temp = [tem[0] + oristr[tem[1]+1], tem[1]+1] result.put(temp) print(tem[0]) ```
0
362
A
Two Semiknights Meet
PROGRAMMING
1,500
[ "greedy", "math" ]
null
null
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard. Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count. Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board. Please see the test case analysis.
The first line contains number *t* (1<=≤<=*t*<=≤<=50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
[ "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#\n" ]
[ "YES\nNO\n" ]
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7). On the second board the semiknights will never meet.
1,000
[ { "input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO" }, { "input": "3\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n####K#K#\n\n........\nK......K\n........\n#......#\n.#....#.\n..####..\n........\n........\n\n.#..#...\n.##.##..\n..###...\n..#K###.\n..####..\n......K.\n..#####.\n..#####.", "output": "NO\nNO\nNO" }, { "input": "1\nK.#....#\n...#..#.\n..#.....\n..#.###.\n..#.....\n...#....\n.#.....#\n.#...##K", "output": "NO" }, { "input": "2\n....#..K\n...#....\n..##.#..\n.#.#.#..\n.#.....#\n.#......\n###.....\nK#.#....\n\nK.#.....\n..#...#.\n#.....#.\n..#.#..#\n#.......\n..#..#..\n....#...\nK..##.##", "output": "NO\nNO" }, { "input": "5\n........\n...KK...\n..####..\n...##...\n........\n..####..\n.######.\n#......#\n\n........\n.K......\n..#.....\n...#....\n....#...\n.....#..\n......#.\n.......K\n\n........\n...K....\n##...##.\n#.#.#..#\n.##.###.\n#..K#..#\n.##..##.\n........\n\n........\n.K..K...\n..##....\n..####..\n.#....#.\n.#.....#\n..#####.\n........\n\nK.......\n........\n........\n........\n........\n........\n........\n.......K", "output": "NO\nNO\nYES\nNO\nNO" } ]
1,384,447,557
4,557
Python 3
RUNTIME_ERROR
PRETESTS
0
31
204,800
t=int(input())#test def mark(x,y,sq): for j in range(8): if j!=y and (y-j)%2==0: for i in range(8): if i!=x and (x-i)%2==0: sq[i][j]=1 result=[] for k in range(t): square1=[[0 for i in range(8)]for i in range(8)] square2=[[0 for i in range(8)]for i in range(8)] square3=[] flag=0 for i in range(8): s=input() s=[p for p in s] for j in range(8): if s[j]=='K': if flag==0: mark(j,i,square1) else: mark(j,i,square2) flag+=1 break square3.append(s) for i in range(8): for j in range(8): if square1[i][j] and square2[i][j]: if square3[i][j]=='.': flag=0 #print('YES') result.append('YES') break if flag==0: break if flag: #print('NO') result.append('NO') for i in range(t): print(result[t])
Title: Two Semiknights Meet Time Limit: None seconds Memory Limit: None megabytes Problem Description: A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard. Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count. Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board. Please see the test case analysis. Input Specification: The first line contains number *t* (1<=≤<=*t*<=≤<=50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line. Output Specification: For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise. Demo Input: ['2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#\n'] Demo Output: ['YES\nNO\n'] Note: Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7). On the second board the semiknights will never meet.
```python t=int(input())#test def mark(x,y,sq): for j in range(8): if j!=y and (y-j)%2==0: for i in range(8): if i!=x and (x-i)%2==0: sq[i][j]=1 result=[] for k in range(t): square1=[[0 for i in range(8)]for i in range(8)] square2=[[0 for i in range(8)]for i in range(8)] square3=[] flag=0 for i in range(8): s=input() s=[p for p in s] for j in range(8): if s[j]=='K': if flag==0: mark(j,i,square1) else: mark(j,i,square2) flag+=1 break square3.append(s) for i in range(8): for j in range(8): if square1[i][j] and square2[i][j]: if square3[i][j]=='.': flag=0 #print('YES') result.append('YES') break if flag==0: break if flag: #print('NO') result.append('NO') for i in range(t): print(result[t]) ```
-1
808
A
Lucky Year
PROGRAMMING
900
[ "implementation" ]
null
null
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland.
Output amount of years from the current year to the next lucky one.
[ "4\n", "201\n", "4000\n" ]
[ "1\n", "99\n", "1000\n" ]
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
0
[ { "input": "4", "output": "1" }, { "input": "201", "output": "99" }, { "input": "4000", "output": "1000" }, { "input": "9", "output": "1" }, { "input": "10", "output": "10" }, { "input": "1", "output": "1" }, { "input": "100000000", "output": "100000000" }, { "input": "900000000", "output": "100000000" }, { "input": "999999999", "output": "1" }, { "input": "1000000000", "output": "1000000000" }, { "input": "9999999", "output": "1" }, { "input": "100000001", "output": "99999999" }, { "input": "3660", "output": "340" }, { "input": "21", "output": "9" }, { "input": "900000001", "output": "99999999" }, { "input": "62911", "output": "7089" }, { "input": "11", "output": "9" }, { "input": "940302010", "output": "59697990" }, { "input": "91", "output": "9" }, { "input": "101", "output": "99" }, { "input": "1090", "output": "910" }, { "input": "987654321", "output": "12345679" }, { "input": "703450474", "output": "96549526" }, { "input": "1091", "output": "909" }, { "input": "89", "output": "1" }, { "input": "109", "output": "91" }, { "input": "190", "output": "10" }, { "input": "19", "output": "1" }, { "input": "8", "output": "1" }, { "input": "482", "output": "18" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "5", "output": "1" }, { "input": "6", "output": "1" }, { "input": "7", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "10", "output": "10" }, { "input": "11", "output": "9" }, { "input": "12", "output": "8" }, { "input": "13", "output": "7" }, { "input": "14", "output": "6" }, { "input": "15", "output": "5" }, { "input": "16", "output": "4" }, { "input": "17", "output": "3" }, { "input": "18", "output": "2" }, { "input": "19", "output": "1" }, { "input": "20", "output": "10" }, { "input": "21", "output": "9" }, { "input": "22", "output": "8" }, { "input": "23", "output": "7" }, { "input": "24", "output": "6" }, { "input": "25", "output": "5" }, { "input": "26", "output": "4" }, { "input": "27", "output": "3" }, { "input": "28", "output": "2" }, { "input": "29", "output": "1" }, { "input": "30", "output": "10" }, { "input": "31", "output": "9" }, { "input": "32", "output": "8" }, { "input": "33", "output": "7" }, { "input": "34", "output": "6" }, { "input": "35", "output": "5" }, { "input": "36", "output": "4" }, { "input": "37", "output": "3" }, { "input": "38", "output": "2" }, { "input": "39", "output": "1" }, { "input": "40", "output": "10" }, { "input": "41", "output": "9" }, { "input": "42", "output": "8" }, { "input": "43", "output": "7" }, { "input": "44", "output": "6" }, { "input": "45", "output": "5" }, { "input": "46", "output": "4" }, { "input": "47", "output": "3" }, { "input": "48", "output": "2" }, { "input": "49", "output": "1" }, { "input": "50", "output": "10" }, { "input": "51", "output": "9" }, { "input": "52", "output": "8" }, { "input": "53", "output": "7" }, { "input": "54", "output": "6" }, { "input": "55", "output": "5" }, { "input": "56", "output": "4" }, { "input": "57", "output": "3" }, { "input": "58", "output": "2" }, { "input": "59", "output": "1" }, { "input": "60", "output": "10" }, { "input": "61", "output": "9" }, { "input": "62", "output": "8" }, { "input": "63", "output": "7" }, { "input": "64", "output": "6" }, { "input": "65", "output": "5" }, { "input": "66", "output": "4" }, { "input": "67", "output": "3" }, { "input": "68", "output": "2" }, { "input": "69", "output": "1" }, { "input": "70", "output": "10" }, { "input": "71", "output": "9" }, { "input": "72", "output": "8" }, { "input": "73", "output": "7" }, { "input": "74", "output": "6" }, { "input": "75", "output": "5" }, { "input": "76", "output": "4" }, { "input": "77", "output": "3" }, { "input": "78", "output": "2" }, { "input": "79", "output": "1" }, { "input": "80", "output": "10" }, { "input": "81", "output": "9" }, { "input": "82", "output": "8" }, { "input": "83", "output": "7" }, { "input": "84", "output": "6" }, { "input": "85", "output": "5" }, { "input": "86", "output": "4" }, { "input": "87", "output": "3" }, { "input": "88", "output": "2" }, { "input": "89", "output": "1" }, { "input": "90", "output": "10" }, { "input": "91", "output": "9" }, { "input": "92", "output": "8" }, { "input": "93", "output": "7" }, { "input": "94", "output": "6" }, { "input": "95", "output": "5" }, { "input": "96", "output": "4" }, { "input": "97", "output": "3" }, { "input": "98", "output": "2" }, { "input": "99", "output": "1" }, { "input": "100", "output": "100" }, { "input": "100", "output": "100" }, { "input": "100", "output": "100" }, { "input": "1000", "output": "1000" }, { "input": "1000", "output": "1000" }, { "input": "1000", "output": "1000" }, { "input": "10000", "output": "10000" }, { "input": "10000", "output": "10000" }, { "input": "101", "output": "99" }, { "input": "110", "output": "90" }, { "input": "1001", "output": "999" }, { "input": "1100", "output": "900" }, { "input": "1010", "output": "990" }, { "input": "10010", "output": "9990" }, { "input": "10100", "output": "9900" }, { "input": "102", "output": "98" }, { "input": "120", "output": "80" }, { "input": "1002", "output": "998" }, { "input": "1200", "output": "800" }, { "input": "1020", "output": "980" }, { "input": "10020", "output": "9980" }, { "input": "10200", "output": "9800" }, { "input": "108", "output": "92" }, { "input": "180", "output": "20" }, { "input": "1008", "output": "992" }, { "input": "1800", "output": "200" }, { "input": "1080", "output": "920" }, { "input": "10080", "output": "9920" }, { "input": "10800", "output": "9200" }, { "input": "109", "output": "91" }, { "input": "190", "output": "10" }, { "input": "1009", "output": "991" }, { "input": "1900", "output": "100" }, { "input": "1090", "output": "910" }, { "input": "10090", "output": "9910" }, { "input": "10900", "output": "9100" }, { "input": "200", "output": "100" }, { "input": "200", "output": "100" }, { "input": "2000", "output": "1000" }, { "input": "2000", "output": "1000" }, { "input": "2000", "output": "1000" }, { "input": "20000", "output": "10000" }, { "input": "20000", "output": "10000" }, { "input": "201", "output": "99" }, { "input": "210", "output": "90" }, { "input": "2001", "output": "999" }, { "input": "2100", "output": "900" }, { "input": "2010", "output": "990" }, { "input": "20010", "output": "9990" }, { "input": "20100", "output": "9900" }, { "input": "202", "output": "98" }, { "input": "220", "output": "80" }, { "input": "2002", "output": "998" }, { "input": "2200", "output": "800" }, { "input": "2020", "output": "980" }, { "input": "20020", "output": "9980" }, { "input": "20200", "output": "9800" }, { "input": "208", "output": "92" }, { "input": "280", "output": "20" }, { "input": "2008", "output": "992" }, { "input": "2800", "output": "200" }, { "input": "2080", "output": "920" }, { "input": "20080", "output": "9920" }, { "input": "20800", "output": "9200" }, { "input": "209", "output": "91" }, { "input": "290", "output": "10" }, { "input": "2009", "output": "991" }, { "input": "2900", "output": "100" }, { "input": "2090", "output": "910" }, { "input": "20090", "output": "9910" }, { "input": "20900", "output": "9100" }, { "input": "800", "output": "100" }, { "input": "800", "output": "100" }, { "input": "8000", "output": "1000" }, { "input": "8000", "output": "1000" }, { "input": "8000", "output": "1000" }, { "input": "80000", "output": "10000" }, { "input": "80000", "output": "10000" }, { "input": "801", "output": "99" }, { "input": "810", "output": "90" }, { "input": "8001", "output": "999" }, { "input": "8100", "output": "900" }, { "input": "8010", "output": "990" }, { "input": "80010", "output": "9990" }, { "input": "80100", "output": "9900" }, { "input": "802", "output": "98" }, { "input": "820", "output": "80" }, { "input": "8002", "output": "998" }, { "input": "8200", "output": "800" }, { "input": "8020", "output": "980" }, { "input": "80020", "output": "9980" }, { "input": "80200", "output": "9800" }, { "input": "808", "output": "92" }, { "input": "880", "output": "20" }, { "input": "8008", "output": "992" }, { "input": "8800", "output": "200" }, { "input": "8080", "output": "920" }, { "input": "80080", "output": "9920" }, { "input": "80800", "output": "9200" }, { "input": "809", "output": "91" }, { "input": "890", "output": "10" }, { "input": "8009", "output": "991" }, { "input": "8900", "output": "100" }, { "input": "8090", "output": "910" }, { "input": "80090", "output": "9910" }, { "input": "80900", "output": "9100" }, { "input": "900", "output": "100" }, { "input": "900", "output": "100" }, { "input": "9000", "output": "1000" }, { "input": "9000", "output": "1000" }, { "input": "9000", "output": "1000" }, { "input": "90000", "output": "10000" }, { "input": "90000", "output": "10000" }, { "input": "901", "output": "99" }, { "input": "910", "output": "90" }, { "input": "9001", "output": "999" }, { "input": "9100", "output": "900" }, { "input": "9010", "output": "990" }, { "input": "90010", "output": "9990" }, { "input": "90100", "output": "9900" }, { "input": "902", "output": "98" }, { "input": "920", "output": "80" }, { "input": "9002", "output": "998" }, { "input": "9200", "output": "800" }, { "input": "9020", "output": "980" }, { "input": "90020", "output": "9980" }, { "input": "90200", "output": "9800" }, { "input": "908", "output": "92" }, { "input": "980", "output": "20" }, { "input": "9008", "output": "992" }, { "input": "9800", "output": "200" }, { "input": "9080", "output": "920" }, { "input": "90080", "output": "9920" }, { "input": "90800", "output": "9200" }, { "input": "909", "output": "91" }, { "input": "990", "output": "10" }, { "input": "9009", "output": "991" }, { "input": "9900", "output": "100" }, { "input": "9090", "output": "910" }, { "input": "90090", "output": "9910" }, { "input": "90900", "output": "9100" }, { "input": "92651241", "output": "7348759" } ]
1,500,370,624
2,147,483,647
Python 3
OK
TESTS
271
62
4,608,000
a=input() l=len(a) if l!=1: b=10**(l-1) print(b-int(a[1:])) else:print(1)
Title: Lucky Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year. Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland. Output Specification: Output amount of years from the current year to the next lucky one. Demo Input: ['4\n', '201\n', '4000\n'] Demo Output: ['1\n', '99\n', '1000\n'] Note: In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
```python a=input() l=len(a) if l!=1: b=10**(l-1) print(b-int(a[1:])) else:print(1) ```
3
145
A
Lucky Conversion
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits. Petya can perform operations of two types: - replace any one digit from string *a* by its opposite (i.e., replace 4 by 7 and 7 by 4); - swap any pair of digits in string *a*. Petya is interested in the minimum number of operations that are needed to make string *a* equal to string *b*. Help him with the task.
The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.
Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*.
[ "47\n74\n", "774\n744\n", "777\n444\n" ]
[ "1\n", "1\n", "3\n" ]
In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites.
500
[ { "input": "47\n74", "output": "1" }, { "input": "774\n744", "output": "1" }, { "input": "777\n444", "output": "3" }, { "input": "74747474\n77777777", "output": "4" }, { "input": "444444444444\n777777777777", "output": "12" }, { "input": "4744744447774474447474774\n4477774777444444444777447", "output": "8" }, { "input": "7\n4", "output": "1" }, { "input": "4\n7", "output": "1" }, { "input": "7777777777\n7777777774", "output": "1" }, { "input": "47777777777\n77777777774", "output": "1" }, { "input": "47747477747744447774774444444777444747474747777774\n44777444774477447777444774477777477774444477447777", "output": "14" }, { "input": "44447777447744444777777747477444777444447744444\n47444747774774744474747744447744477747777777447", "output": "13" }, { "input": "4447744774744774744747744774474474444447477477444747477444\n7477477444744774744744774774744474744447744774744477744477", "output": "14" }, { "input": "44747744777777444\n47774747747744777", "output": "6" }, { "input": "44447774444474477747774774477777474774744744477444447777477477744747477774744444744777777777747777477447744774744444747477744744\n77777474477477747774777777474474477444474777477747747777477747747744474474747774747747444777474444744744444477477777747744747477", "output": "37" }, { "input": "774774747744474477447477777447477747477474777477744744747444774474477477747474477447774444774744777\n744477444747477447477777774477447444447747477747477747774477474447474477477474444777444444447474747", "output": "27" }, { "input": "4747447477\n4747444744", "output": "3" }, { "input": "47744447444\n74477447744", "output": "4" }, { "input": "447444777744\n777747744477", "output": "6" }, { "input": "474777477774444\n774747777774477", "output": "4" }, { "input": "47744474447747744777777447\n44744747477474777744777477", "output": "7" }, { "input": "77447447444777777744744747744747774747477774777774447447777474477477774774777\n74777777444744447447474474477747747444444447447774444444747777444747474777447", "output": "28" }, { "input": "7\n7", "output": "0" }, { "input": "444\n444", "output": "0" }, { "input": "77747\n47474", "output": "3" } ]
1,585,853,830
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
248
0
a = list(input()) b = list(input()) ans = 0 c4 = abs(a.count('4') - b.count('4')) c7 = abs(a.count('7') - b.count('7')) ans += c4 ans += ((len(a) - c4)//2) print(ans)
Title: Lucky Conversion 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 has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits. Petya can perform operations of two types: - replace any one digit from string *a* by its opposite (i.e., replace 4 by 7 and 7 by 4); - swap any pair of digits in string *a*. Petya is interested in the minimum number of operations that are needed to make string *a* equal to string *b*. Help him with the task. Input Specification: The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. Output Specification: Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*. Demo Input: ['47\n74\n', '774\n744\n', '777\n444\n'] Demo Output: ['1\n', '1\n', '3\n'] Note: In the first sample it is enough simply to swap the first and the second digit. In the second sample we should replace the second digit with its opposite. In the third number we should replace all three digits with their opposites.
```python a = list(input()) b = list(input()) ans = 0 c4 = abs(a.count('4') - b.count('4')) c7 = abs(a.count('7') - b.count('7')) ans += c4 ans += ((len(a) - c4)//2) print(ans) ```
0
298
A
Snow Footprints
PROGRAMMING
1,300
[ "greedy", "implementation" ]
null
null
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them.
[ "9\n..RRLL...\n", "11\n.RRRLLLLL..\n" ]
[ "3 4\n", "7 5\n" ]
The first test sample is the one in the picture.
500
[ { "input": "11\n.RRRLLLLL..", "output": "7 5" }, { "input": "4\n.RL.", "output": "3 2" }, { "input": "3\n.L.", "output": "2 1" }, { "input": "3\n.R.", "output": "2 3" } ]
1,594,928,851
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
248
20,172,800
n = int(input()) road = input() s, t = -1, -1 for i in range(1,n): if road[i-1] == "." and road[i] == "R": s = i + 1 if s > 0: break for i in range(2,n): if road[-i + 1] == "." and road[- i] == "L": t = n - i + 1 if t > 0: break print(s, t)
Title: Snow Footprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists. Output Specification: Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. Demo Input: ['9\n..RRLL...\n', '11\n.RRRLLLLL..\n'] Demo Output: ['3 4\n', '7 5\n'] Note: The first test sample is the one in the picture.
```python n = int(input()) road = input() s, t = -1, -1 for i in range(1,n): if road[i-1] == "." and road[i] == "R": s = i + 1 if s > 0: break for i in range(2,n): if road[-i + 1] == "." and road[- i] == "L": t = n - i + 1 if t > 0: break print(s, t) ```
0
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get.
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, { "input": "3\n1\n5", "output": "20" }, { "input": "6\n7\n1", "output": "48" }, { "input": "1\n8\n3", "output": "27" }, { "input": "9\n7\n2", "output": "126" }, { "input": "1\n1\n10", "output": "20" }, { "input": "9\n1\n1", "output": "18" }, { "input": "10\n5\n6", "output": "300" }, { "input": "8\n9\n7", "output": "504" }, { "input": "4\n2\n10", "output": "80" }, { "input": "2\n8\n3", "output": "48" }, { "input": "3\n5\n7", "output": "105" }, { "input": "1\n10\n1", "output": "12" }, { "input": "2\n2\n2", "output": "8" }, { "input": "5\n6\n1", "output": "35" }, { "input": "10\n1\n1", "output": "20" }, { "input": "1\n6\n1", "output": "8" }, { "input": "1\n9\n1", "output": "11" }, { "input": "2\n1\n2", "output": "6" }, { "input": "2\n6\n1", "output": "14" }, { "input": "9\n2\n1", "output": "27" }, { "input": "1\n9\n2", "output": "20" }, { "input": "1\n3\n1", "output": "5" }, { "input": "2\n1\n1", "output": "4" } ]
1,694,015,466
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
7
62
0
a=int(input()) b=int(input()) c=int(input()) x=a*b*c y=max(a,b,c)*(min(a,b,c)+((a+b+c)-(max(a,b,c)+(min(a,b,c))))) z=a+b+c print(max(x,y,z))
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get. Input Specification: The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). Output Specification: Print the maximum value of the expression that you can obtain. Demo Input: ['1\n2\n3\n', '2\n10\n3\n'] Demo Output: ['9\n', '60\n'] Note: none
```python a=int(input()) b=int(input()) c=int(input()) x=a*b*c y=max(a,b,c)*(min(a,b,c)+((a+b+c)-(max(a,b,c)+(min(a,b,c))))) z=a+b+c print(max(x,y,z)) ```
0
276
A
Lunch Rush
PROGRAMMING
900
[ "implementation" ]
null
null
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy. Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.
The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant.
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
[ "2 5\n3 3\n4 5\n", "4 6\n5 8\n3 6\n2 3\n2 2\n", "1 5\n1 7\n" ]
[ "4\n", "3\n", "-1\n" ]
none
500
[ { "input": "2 5\n3 3\n4 5", "output": "4" }, { "input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3" }, { "input": "1 5\n1 7", "output": "-1" }, { "input": "4 9\n10 13\n4 18\n13 3\n10 6", "output": "13" }, { "input": "1 1\n1 1000000000", "output": "-999999998" }, { "input": "1 1\n1000000000 1000000000", "output": "1" }, { "input": "1 1\n1000000000 1", "output": "1000000000" }, { "input": "2 3\n1000000000 1\n2 2", "output": "1000000000" }, { "input": "2 5\n1 7\n1 1000000000", "output": "-1" } ]
1,674,938,405
2,147,483,647
PyPy 3-64
OK
TESTS
35
280
5,529,600
n, k=map(int, input().split()) ans = [] for _ in range(n): f, t=map(int, input().split()) d = abs(t-k) e = f-d if t<=k: ans.append(f) else: ans.append(e) ans.sort(reverse=True) print(ans[0])
Title: Lunch Rush Time Limit: None seconds Memory Limit: None megabytes Problem Description: Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy. Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value. Input Specification: The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant. Output Specification: In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. Demo Input: ['2 5\n3 3\n4 5\n', '4 6\n5 8\n3 6\n2 3\n2 2\n', '1 5\n1 7\n'] Demo Output: ['4\n', '3\n', '-1\n'] Note: none
```python n, k=map(int, input().split()) ans = [] for _ in range(n): f, t=map(int, input().split()) d = abs(t-k) e = f-d if t<=k: ans.append(f) else: ans.append(e) ans.sort(reverse=True) print(ans[0]) ```
3
435
B
Pasha Maximizes
PROGRAMMING
1,400
[ "greedy" ]
null
null
Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most *k* swaps.
The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100).
Print the maximum number that Pasha can get if he makes at most *k* swaps.
[ "1990 1\n", "300 0\n", "1034 2\n", "9090000078001234 6\n" ]
[ "9190\n", "300\n", "3104\n", "9907000008001234\n" ]
none
1,000
[ { "input": "1990 1", "output": "9190" }, { "input": "300 0", "output": "300" }, { "input": "1034 2", "output": "3104" }, { "input": "9090000078001234 6", "output": "9907000008001234" }, { "input": "1234 3", "output": "4123" }, { "input": "5 100", "output": "5" }, { "input": "1234 5", "output": "4312" }, { "input": "1234 6", "output": "4321" }, { "input": "9022 2", "output": "9220" }, { "input": "66838 4", "output": "86863" }, { "input": "39940894417248510 10", "output": "99984304417248510" }, { "input": "5314 4", "output": "5431" }, { "input": "1026 9", "output": "6210" }, { "input": "4529 8", "output": "9542" }, { "input": "83811284 3", "output": "88321184" }, { "input": "92153348 6", "output": "98215334" }, { "input": "5846059 3", "output": "8654059" }, { "input": "521325125110071928 4", "output": "552132125110071928" }, { "input": "39940894417248510 10", "output": "99984304417248510" }, { "input": "77172428736634377 29", "output": "87777764122363437" }, { "input": "337775999910796051 37", "output": "999997733751076051" }, { "input": "116995340392134308 27", "output": "999654331120134308" }, { "input": "10120921290110921 20", "output": "99221010120110921" }, { "input": "929201010190831892 30", "output": "999928201010103182" }, { "input": "111111111111111119 8", "output": "111111111911111111" }, { "input": "219810011901120912 100", "output": "999822211111110000" }, { "input": "191919191919119911 100", "output": "999999991111111111" }, { "input": "801211288881101019 22", "output": "982111028888110101" }, { "input": "619911311932347059 3", "output": "969111311932347059" }, { "input": "620737553540689123 2", "output": "672037553540689123" }, { "input": "621563797296514835 3", "output": "662153797296514835" }, { "input": "915277434701161 9", "output": "977541234701161" }, { "input": "15603712376708 28", "output": "87761503123670" }, { "input": "784069392990841 0", "output": "784069392990841" }, { "input": "787464780004 2", "output": "877644780004" }, { "input": "74604713975 29", "output": "97776544310" }, { "input": "901000000954321789 5", "output": "910009000054321789" }, { "input": "901000000954321789 10", "output": "991000000504321789" }, { "input": "901000000954321789 28", "output": "999100050000432178" }, { "input": "901000000954321789 40", "output": "999810000050043217" }, { "input": "901000000954321789 70", "output": "999875410000300021" }, { "input": "1234567891234567 99", "output": "9877665544332211" }, { "input": "123456789123456789 100", "output": "998877665544213123" }, { "input": "12345670123456789 100", "output": "98776655443322101" }, { "input": "12 100", "output": "21" }, { "input": "11223344556677889 47", "output": "98821213344556677" } ]
1,686,623,476
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
MOD=10**9+7 def slove(): a,k=list(map(int,input().split(' '))) s=list(str(a)) n=len(s) p=0 for w in '9876543210': i=p while i<n and s[i]==w: i+=1 p+=1 # if s[i]==w: continue while k>0 and i<n: if s[i]==w: step=i-p if step<=k: for j in range(i,p,-1): s[j]=s[j-1] s[p]=w p+=1 k-=step else: if k and p<n: q=p+1 while q<n and s[q]<=s[q-1]: q+=1 if q<n: w=s[q] for j in range(q,p,-1): s[j]=s[j-1] s[p]=w ans=''.join(s) print(ans) return i+=1 # print('asdf',''.join(s)) # if k and p<n: # q=p+1 # while q<n and s[q]<=s[q-1]: # q+=1 # if q<n: # w=s[q] # for j in range(q,p,-1): # s[j]=s[j-1] # s[p]=w ans=''.join(s) print(ans) return # t=int(input()) t=1 # M=1<<30 for _ in range(t): slove()
Title: Pasha Maximizes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most *k* swaps. Input Specification: The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100). Output Specification: Print the maximum number that Pasha can get if he makes at most *k* swaps. Demo Input: ['1990 1\n', '300 0\n', '1034 2\n', '9090000078001234 6\n'] Demo Output: ['9190\n', '300\n', '3104\n', '9907000008001234\n'] Note: none
```python MOD=10**9+7 def slove(): a,k=list(map(int,input().split(' '))) s=list(str(a)) n=len(s) p=0 for w in '9876543210': i=p while i<n and s[i]==w: i+=1 p+=1 # if s[i]==w: continue while k>0 and i<n: if s[i]==w: step=i-p if step<=k: for j in range(i,p,-1): s[j]=s[j-1] s[p]=w p+=1 k-=step else: if k and p<n: q=p+1 while q<n and s[q]<=s[q-1]: q+=1 if q<n: w=s[q] for j in range(q,p,-1): s[j]=s[j-1] s[p]=w ans=''.join(s) print(ans) return i+=1 # print('asdf',''.join(s)) # if k and p<n: # q=p+1 # while q<n and s[q]<=s[q-1]: # q+=1 # if q<n: # w=s[q] # for j in range(q,p,-1): # s[j]=s[j-1] # s[p]=w ans=''.join(s) print(ans) return # t=int(input()) t=1 # M=1<<30 for _ in range(t): slove() ```
0
461
A
Appleman and Toastman
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
[ "3\n3 1 5\n", "1\n10\n" ]
[ "26\n", "10\n" ]
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
500
[ { "input": "3\n3 1 5", "output": "26" }, { "input": "1\n10", "output": "10" }, { "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376" }, { "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082" }, { "input": "10\n1 2 2 2 4 5 6 7 8 10", "output": "376" }, { "input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002", "output": "40204082" }, { "input": "1\n397870", "output": "397870" }, { "input": "1\n1000000", "output": "1000000" }, { "input": "10\n10 8 7 6 5 4 2 2 2 1", "output": "376" }, { "input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821", "output": "40204082" }, { "input": "10\n5 2 6 10 10 10 10 2 2 5", "output": "485" }, { "input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255", "output": "36742665" }, { "input": "10\n2 2 2 5 5 6 10 10 10 10", "output": "485" }, { "input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642", "output": "36742665" }, { "input": "10\n10 10 10 10 6 5 5 2 2 2", "output": "485" }, { "input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496", "output": "36742665" }, { "input": "10\n10 10 10 10 10 10 10 10 10 10", "output": "640" }, { "input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "64000000" }, { "input": "1\n397870", "output": "397870" }, { "input": "2\n1 2", "output": "6" }, { "input": "2\n2 3", "output": "10" }, { "input": "2\n1 1", "output": "4" } ]
1,450,011,648
2,147,483,647
Python 3
OK
TESTS
36
436
21,401,600
#@author: xyj n=int(input()) a=[int(i) for i in input().split()] a=sorted(a) ans=sum(a) for i in range(len(a)-1): a[i]*=(i+1) a[n-1]*=n-1 ans+=sum(a) print(ans)
Title: Appleman and Toastman Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. Output Specification: Print a single integer — the largest possible score. Demo Input: ['3\n3 1 5\n', '1\n10\n'] Demo Output: ['26\n', '10\n'] Note: Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
```python #@author: xyj n=int(input()) a=[int(i) for i in input().split()] a=sorted(a) ans=sum(a) for i in range(len(a)-1): a[i]*=(i+1) a[n-1]*=n-1 ans+=sum(a) print(ans) ```
3
803
A
Maximal Binary Matrix
PROGRAMMING
1,400
[ "constructive algorithms" ]
null
null
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one. If there exists no such matrix then output -1.
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
If the answer exists then output resulting matrix. Otherwise output -1.
[ "2 1\n", "3 2\n", "2 5\n" ]
[ "1 0 \n0 0 \n", "1 0 0 \n0 1 0 \n0 0 0 \n", "-1\n" ]
none
0
[ { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "2 5", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "20 398", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1..." }, { "input": "20 401", "output": "-1" }, { "input": "100 3574", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10000", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10001", "output": "-1" }, { "input": "2 3", "output": "1 1 \n1 0 " }, { "input": "4 5", "output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "5 6", "output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 24", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 " }, { "input": "2 0", "output": "0 0 \n0 0 " }, { "input": "3 5", "output": "1 1 1 \n1 0 0 \n1 0 0 " }, { "input": "3 3", "output": "1 1 0 \n1 0 0 \n0 0 0 " }, { "input": "5 10", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "3 4", "output": "1 1 0 \n1 1 0 \n0 0 0 " }, { "input": "4 3", "output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "1 1000000", "output": "-1" }, { "input": "3 6", "output": "1 1 1 \n1 1 0 \n1 0 0 " }, { "input": "1 2", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "1 2", "output": "-1" }, { "input": "1 3", "output": "-1" }, { "input": "1 4", "output": "-1" }, { "input": "1 5", "output": "-1" }, { "input": "1 6", "output": "-1" }, { "input": "1 7", "output": "-1" }, { "input": "1 8", "output": "-1" }, { "input": "1 9", "output": "-1" }, { "input": "1 10", "output": "-1" }, { "input": "1 11", "output": "-1" }, { "input": "1 12", "output": "-1" }, { "input": "1 13", "output": "-1" }, { "input": "1 14", "output": "-1" }, { "input": "1 15", "output": "-1" }, { "input": "1 16", "output": "-1" }, { "input": "1 17", "output": "-1" }, { "input": "1 18", "output": "-1" }, { "input": "1 19", "output": "-1" }, { "input": "1 20", "output": "-1" }, { "input": "1 21", "output": "-1" }, { "input": "1 22", "output": "-1" }, { "input": "1 23", "output": "-1" }, { "input": "1 24", "output": "-1" }, { "input": "1 25", "output": "-1" }, { "input": "1 26", "output": "-1" }, { "input": "2 0", "output": "0 0 \n0 0 " }, { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "2 2", "output": "1 0 \n0 1 " }, { "input": "2 3", "output": "1 1 \n1 0 " }, { "input": "2 4", "output": "1 1 \n1 1 " }, { "input": "2 5", "output": "-1" }, { "input": "2 6", "output": "-1" }, { "input": "2 7", "output": "-1" }, { "input": "2 8", "output": "-1" }, { "input": "2 9", "output": "-1" }, { "input": "2 10", "output": "-1" }, { "input": "2 11", "output": "-1" }, { "input": "2 12", "output": "-1" }, { "input": "2 13", "output": "-1" }, { "input": "2 14", "output": "-1" }, { "input": "2 15", "output": "-1" }, { "input": "2 16", "output": "-1" }, { "input": "2 17", "output": "-1" }, { "input": "2 18", "output": "-1" }, { "input": "2 19", "output": "-1" }, { "input": "2 20", "output": "-1" }, { "input": "2 21", "output": "-1" }, { "input": "2 22", "output": "-1" }, { "input": "2 23", "output": "-1" }, { "input": "2 24", "output": "-1" }, { "input": "2 25", "output": "-1" }, { "input": "2 26", "output": "-1" }, { "input": "3 0", "output": "0 0 0 \n0 0 0 \n0 0 0 " }, { "input": "3 1", "output": "1 0 0 \n0 0 0 \n0 0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "3 3", "output": "1 1 0 \n1 0 0 \n0 0 0 " }, { "input": "3 4", "output": "1 1 0 \n1 1 0 \n0 0 0 " }, { "input": "3 5", "output": "1 1 1 \n1 0 0 \n1 0 0 " }, { "input": "3 6", "output": "1 1 1 \n1 1 0 \n1 0 0 " }, { "input": "3 7", "output": "1 1 1 \n1 1 0 \n1 0 1 " }, { "input": "3 8", "output": "1 1 1 \n1 1 1 \n1 1 0 " }, { "input": "3 9", "output": "1 1 1 \n1 1 1 \n1 1 1 " }, { "input": "3 10", "output": "-1" }, { "input": "3 11", "output": "-1" }, { "input": "3 12", "output": "-1" }, { "input": "3 13", "output": "-1" }, { "input": "3 14", "output": "-1" }, { "input": "3 15", "output": "-1" }, { "input": "3 16", "output": "-1" }, { "input": "3 17", "output": "-1" }, { "input": "3 18", "output": "-1" }, { "input": "3 19", "output": "-1" }, { "input": "3 20", "output": "-1" }, { "input": "3 21", "output": "-1" }, { "input": "3 22", "output": "-1" }, { "input": "3 23", "output": "-1" }, { "input": "3 24", "output": "-1" }, { "input": "3 25", "output": "-1" }, { "input": "3 26", "output": "-1" }, { "input": "4 0", "output": "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 1", "output": "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 2", "output": "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 3", "output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 4", "output": "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 5", "output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "4 6", "output": "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "4 7", "output": "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 " }, { "input": "4 8", "output": "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 " }, { "input": "4 9", "output": "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 " }, { "input": "4 10", "output": "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 " }, { "input": "4 11", "output": "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 " }, { "input": "4 12", "output": "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 " }, { "input": "4 13", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 " }, { "input": "4 14", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 " }, { "input": "4 15", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 " }, { "input": "4 16", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 " }, { "input": "4 17", "output": "-1" }, { "input": "4 18", "output": "-1" }, { "input": "4 19", "output": "-1" }, { "input": "4 20", "output": "-1" }, { "input": "4 21", "output": "-1" }, { "input": "4 22", "output": "-1" }, { "input": "4 23", "output": "-1" }, { "input": "4 24", "output": "-1" }, { "input": "4 25", "output": "-1" }, { "input": "4 26", "output": "-1" }, { "input": "5 0", "output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 1", "output": "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 2", "output": "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 3", "output": "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 4", "output": "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 5", "output": "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 6", "output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 7", "output": "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 8", "output": "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 9", "output": "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 10", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 11", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 12", "output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 13", "output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 14", "output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 " }, { "input": "5 15", "output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 " }, { "input": "5 16", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 " }, { "input": "5 17", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 " }, { "input": "5 18", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 " }, { "input": "5 19", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 " }, { "input": "5 20", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 " }, { "input": "5 21", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 " }, { "input": "5 22", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 " }, { "input": "5 23", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 " }, { "input": "5 24", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 " }, { "input": "5 25", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 " }, { "input": "5 26", "output": "-1" }, { "input": "100 0", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 2", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 3", "output": "1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 99", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 100", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 101", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 9999", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10000", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10001", "output": "-1" } ]
1,561,060,877
977
PyPy 3
WRONG_ANSWER
TESTS
3
140
0
n = [int(i) for i in input().split()] if(n[1]>n[0]*n[0]): print(-1) else: a = [[0 for i in range(n[0])] for j in range(n[0])] k = n[1] for i in range(n[0]): a[i][i] = 1 k-=1 j = i+1 while(k>1 and j<n[0]): a[i][j] = 1 a[j][i] = 1 k-=2 j+=1 if(k==1): a[i+1][i+1] = 1 k-=1 if(k<1): break for i in range(n[0]): for j in range(n[0]): print(a[i][j],end=' ') print()
Title: Maximal Binary Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one. If there exists no such matrix then output -1. Input Specification: The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). Output Specification: If the answer exists then output resulting matrix. Otherwise output -1. Demo Input: ['2 1\n', '3 2\n', '2 5\n'] Demo Output: ['1 0 \n0 0 \n', '1 0 0 \n0 1 0 \n0 0 0 \n', '-1\n'] Note: none
```python n = [int(i) for i in input().split()] if(n[1]>n[0]*n[0]): print(-1) else: a = [[0 for i in range(n[0])] for j in range(n[0])] k = n[1] for i in range(n[0]): a[i][i] = 1 k-=1 j = i+1 while(k>1 and j<n[0]): a[i][j] = 1 a[j][i] = 1 k-=2 j+=1 if(k==1): a[i+1][i+1] = 1 k-=1 if(k<1): break for i in range(n[0]): for j in range(n[0]): print(a[i][j],end=' ') print() ```
0
0
none
none
none
0
[ "none" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
0
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "output": "8043 2940 R" }, { "input": "1 1 1", "output": "1 1 L" }, { "input": "1 1 2", "output": "1 1 R" }, { "input": "1 10000 1", "output": "1 1 L" }, { "input": "1 10000 20000", "output": "1 10000 R" }, { "input": "10000 1 1", "output": "1 1 L" }, { "input": "10000 1 10000", "output": "5000 1 R" }, { "input": "10000 1 20000", "output": "10000 1 R" }, { "input": "3 2 1", "output": "1 1 L" }, { "input": "3 2 2", "output": "1 1 R" }, { "input": "3 2 3", "output": "1 2 L" }, { "input": "3 2 4", "output": "1 2 R" }, { "input": "3 2 5", "output": "2 1 L" }, { "input": "3 2 6", "output": "2 1 R" }, { "input": "3 2 7", "output": "2 2 L" }, { "input": "3 2 8", "output": "2 2 R" }, { "input": "3 2 9", "output": "3 1 L" }, { "input": "3 2 10", "output": "3 1 R" }, { "input": "3 2 11", "output": "3 2 L" }, { "input": "3 2 12", "output": "3 2 R" }, { "input": "300 2000 1068628", "output": "268 314 R" }, { "input": "300 2000 584756", "output": "147 378 R" }, { "input": "300 2000 268181", "output": "68 91 L" }, { "input": "10000 9999 186450844", "output": "9324 4745 R" }, { "input": "10000 9999 197114268", "output": "9857 6990 R" }, { "input": "10000 9999 112390396", "output": "5621 818 R" }, { "input": "10000 10000 1", "output": "1 1 L" }, { "input": "10000 10000 2", "output": "1 1 R" }, { "input": "10000 10000 100000001", "output": "5001 1 L" }, { "input": "10000 10000 199999999", "output": "10000 10000 L" }, { "input": "10000 10000 200000000", "output": "10000 10000 R" }, { "input": "1 2 1", "output": "1 1 L" }, { "input": "1 2 2", "output": "1 1 R" }, { "input": "1 2 3", "output": "1 2 L" }, { "input": "1 2 4", "output": "1 2 R" }, { "input": "2 1 1", "output": "1 1 L" }, { "input": "2 1 2", "output": "1 1 R" }, { "input": "2 1 3", "output": "2 1 L" }, { "input": "2 1 4", "output": "2 1 R" }, { "input": "4 3 7", "output": "2 1 L" }, { "input": "1 1 1", "output": "1 1 L" } ]
1,482,657,503
803
PyPy 3
OK
TESTS
46
139
23,347,200
from math import ceil n, m, k = map(int, input().split()) r = ceil(k / (m * 2)) c = k % (m * 2) c = m * 2 if c == 0 else c print(r, end = ' ') print(ceil(c / 2), end = ' ') print('L' if c % 2 else 'R')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! Input Specification: The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. Output Specification: Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. Demo Input: ['4 3 9\n', '4 3 24\n', '2 4 4\n'] Demo Output: ['2 2 L\n', '4 3 R\n', '1 2 R\n'] Note: The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
```python from math import ceil n, m, k = map(int, input().split()) r = ceil(k / (m * 2)) c = k % (m * 2) c = m * 2 if c == 0 else c print(r, end = ' ') print(ceil(c / 2), end = ' ') print('L' if c % 2 else 'R') ```
3
239
A
Two Bags of Potatoes
PROGRAMMING
1,200
[ "greedy", "implementation", "math" ]
null
null
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1.
[ "10 1 10\n", "10 6 40\n" ]
[ "-1\n", "2 8 14 20 26 \n" ]
none
500
[ { "input": "10 1 10", "output": "-1" }, { "input": "10 6 40", "output": "2 8 14 20 26 " }, { "input": "10 1 20", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "1 10000 1000000000", "output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..." }, { "input": "84817 1 33457", "output": "-1" }, { "input": "21 37 99", "output": "16 53 " }, { "input": "78 7 15", "output": "-1" }, { "input": "74 17 27", "output": "-1" }, { "input": "79 23 43", "output": "-1" }, { "input": "32 33 3", "output": "-1" }, { "input": "55 49 44", "output": "-1" }, { "input": "64 59 404", "output": "54 113 172 231 290 " }, { "input": "61 69 820", "output": "8 77 146 215 284 353 422 491 560 629 698 " }, { "input": "17 28 532", "output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 " }, { "input": "46592 52 232", "output": "-1" }, { "input": "1541 58 648", "output": "-1" }, { "input": "15946 76 360", "output": "-1" }, { "input": "30351 86 424", "output": "-1" }, { "input": "1 2 37493", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "1 3 27764", "output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..." }, { "input": "10 4 9174", "output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..." }, { "input": "33 7 4971", "output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..." }, { "input": "981 1 3387", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "386 1 2747", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "123 2 50000", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "3123 100 10000000", "output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..." }, { "input": "2 10000 1000000000", "output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..." }, { "input": "3 10000 1000000000", "output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..." }, { "input": "12312223 10000 1000000000", "output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..." }, { "input": "500000000 1000000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 1000000000", "output": "999999999 " }, { "input": "10 6 11", "output": "-1" }, { "input": "2 100 10", "output": "-1" }, { "input": "1 100000007 1000000000", "output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 " }, { "input": "1 999999999 1000000000", "output": "999999998 " }, { "input": "100000000 1000000000 1000000000", "output": "900000000 " }, { "input": "11 2 12", "output": "1 " }, { "input": "31 10 39", "output": "-1" }, { "input": "48 6 50", "output": "-1" }, { "input": "500000000 500000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 999999999", "output": "-1" }, { "input": "4 2 10", "output": "2 4 6 " }, { "input": "1000000000 1 1", "output": "-1" }, { "input": "1000000000 1 100000", "output": "-1" }, { "input": "1000000000 1 10", "output": "-1" }, { "input": "10 5 14", "output": "-1" }, { "input": "500000000 499999999 1000000000", "output": "499999998 " }, { "input": "1 999999997 1000000000", "output": "999999996 " } ]
1,633,529,888
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
6,758,400
a, b, c = map(int, input().split()) if a >= c: print(-1) else: i = 1 x = b - a % b if a + x >= c: print(-1) else: print(x, end=' ') while True: x += b if x + a < c: print(x, end=' ') else: break
Title: Two Bags of Potatoes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. Input Specification: The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). Output Specification: Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1. Demo Input: ['10 1 10\n', '10 6 40\n'] Demo Output: ['-1\n', '2 8 14 20 26 \n'] Note: none
```python a, b, c = map(int, input().split()) if a >= c: print(-1) else: i = 1 x = b - a % b if a + x >= c: print(-1) else: print(x, end=' ') while True: x += b if x + a < c: print(x, end=' ') else: break ```
0